Last active
December 21, 2020 00:04
-
-
Save TakehikoShimojima/9d0d7dfc332302a91b86da86a0d65cfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* TFMini-SをシリアルモードからI2Cモードにする | |
*/ | |
#include <M5StickC.h> | |
uint8_t setI2Ccmd[] = {0x5A, 0x05, 0x0A, 0x01}; | |
uint8_t saveSettingcmd[] = {0x5A, 0x04, 0x11}; | |
int sendCmd(Stream* streamPtr, uint8_t *cmd, int len, bool response) { | |
uint8_t checksum = 0; | |
for (int i = 0; i < len; i++) { | |
Serial.printf("%02x ", *cmd); | |
streamPtr->write(*cmd); | |
checksum += *cmd; | |
cmd++; | |
} | |
streamPtr->write(checksum); | |
if (response) { | |
Serial.printf("response: "); | |
while (!streamPtr->available()) { | |
} | |
while (streamPtr->available()) { | |
int response = streamPtr->read(); | |
Serial.printf("%02x ", response); | |
} | |
Serial.printf("\r\n"); | |
} | |
} | |
void setup() { | |
M5.begin(); | |
Serial1.begin(115200, SERIAL_8N1, 26, 0); | |
M5.Lcd.setTextSize(2); | |
M5.Lcd.setRotation(3); | |
M5.Lcd.setCursor(0, 0); | |
M5.Lcd.println("set I2C mode"); | |
sendCmd(&Serial1, setI2Ccmd, sizeof(setI2Ccmd), false); | |
delay(1000); | |
M5.Lcd.println("save settings"); | |
sendCmd(&Serial1, saveSettingcmd, sizeof(saveSettingcmd), false); | |
delay(1000); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment