im sending via uart data from stm32 like this:
sprintf(buffer, "%d %d %d %d %d %d %d %d %d %d %d %f;", (int32_t)ir_average, (int32_t)red_average, (int32_t)dcFilterIRresult, (int32_t)dcFilterRedresult, (int32_t)chebyshevResult2, (int32_t)elipticResult2, (int32_t)wyjscie, (int32_t)bpm_up, (int32_t)fftbmp, (int32_t)currentSaO2Value, (int32_t)spo2Calib, temp);
HAL_UART_Transmit(&huart4, buffer, 100, 1000);
how should i read it from esp8266 side in arduino ide? maybe i should do it differently? i wanted to send a packet od data and split it after reading full packet on esp8266
CodePudding user response:
Generally in arduino you read using Serial.read() which returns char. Form a string out of it.
String resp;
char _char;
while(Serial.available()){
_char = Serial.read();
resp = _char;
}
to convert it to int use .toInt()
to separate individual numbers use .indexOf
CodePudding user response:
To read bytes from the UART in arduino IDE: Serial.read() (in a loop) or Serial.ReadString().
Generally speaking, prefer using snprintf to sprintf to avoid buffer overflows.