|
大神好, 最近按照Robin2大神的教程->https://forum.arduino.cc/index.php?topic=288234.0 在ESP8266 调用 atoi 或 atof 时 ESP8266老是死机重启,死机重启.不知道大神们有没有尝试过用ESP8266调用atoi或者atof函数?
以下是从Robin2 大神的《Serial Input Basic》中复制下来的代码.
经过排查,只要运行atoi 或者 atof 就不断地重启.
我不是高手才学编程的菜鸟一枚, 求回答谢谢.
[mw_shl_code=arduino,true]// simple parse demo
char receivedChars[] = "This is a test, 1234, 45.3" ;
char messageFromPC[32] = {0};
int integerFromPC = 0;
float floatFromPC = 0.0;
char recvChar;
char endMarker = '>';
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
parseData();
showParsedData();
}
void loop() {
}
void parseData() {
// split the data into its parts
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(receivedChars,","); // get the first part - the string
strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ",");
floatFromPC = atof(strtokIndx); // convert this part to a float
}
void showParsedData() {
Serial.print("Message ");
Serial.println(messageFromPC);
Serial.print("Integer ");
Serial.println(integerFromPC);
Serial.print("Float ");
Serial.println(floatFromPC);
}[/mw_shl_code]
|
|