Go Down

Topic: Wierd Data on Serial.reald() (Read 217 times) previous topic - next topic

AdmiralCrunch

Hi,

for my project, I am sending strings like

  t1:22;

from a Axoloti to a Arduino Nano.

On the Axoloti I do:

Code: [Select]

        char data[] = "t1:222;";
char data2[] = "t2:444;";


sdWrite(&SD2, (uint8_t *) data, strlen(data));
sdWrite(&SD2, (uint8_t *) data2, strlen(data2));


while on Arduino I do:

Code: [Select]

   if(Serial.available()) {       
     
       cmd = Serial.readStringUntil(';');
       Serial.println(cmd);
   }


.. it works but I get really wierd output:

Code: [Select]
SERIAL LOADED..
2t1:222
t2:444
t1:222
t2:444
t1:222
t2:444
t1:222
t2:444
t1:222
t2:444
:222
t2t1:222
44
t1:2:444
t1t2:444
22
t2:4:222
t2
t1:22244
t1:22:444
t2:444
t222t1:222
t24
t1:222
44
2:444
t1:2:4
t2:444
t2
t2:444
t:222
t21:222
t2:44
t1:44
t1:2444:444
tt2:444
t2:444

t2
t2:444t2:4442:444
t1444
t14
t1:2t1:222
t2:44t2:444
t
t1:222tt1:2:444
t1:222
t2:4422
t2:
t1:2:444


what could cause this? I really dont know if the problem is on arduino-side or on axoloti-side.

wildbill

Don't forget that readStringUntil has a timeout. It's hard to say without seeing all your code, but you may get odd results if there are delays on the transmission side.

Try a simpler sketch that reads character by character and just echoes what's coming in.

groundFungus

#2
Jun 20, 2019, 06:36 pm Last Edit: Jun 20, 2019, 06:37 pm by groundFungus
The serial input basics tutorial shows how to do reliable non-blocking serial communication.  Using start and end markers frames the data for more robust programs.  The readStringUntil funnction can block execution leading to non responsive programs.

wvmarle

You posted just some snippets. That almost certainly means the problem is in the part you didn't post (such as the part where the transmitting side writes stuff to the Serial output).
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up