Hardware serial communication

I am using an arduino uno with an hc-05 in a self balancing robot and i want to send different velocity set points to each stepper continuously but i have no clue how to do so.
My question is what happens if i keep sending the 2 setpoints one after the other will the second value be stored somewhere till the arduino reaches the line (received.variable=serial.read() ) in the next loop cycle or will it be lost and whatever data that was sent last will be stored in the received variable.
Ideally i should be able to receive the angle and velocity back from arduino at the end of each loop, i have no idea how to manage such data, any ideas? TIA

Serial data is received in a (software) buffer (size is 64 bytes); Serial.read() will read from that buffer. If that buffer is full and you send more, you will start loosing data.

1 Like

So if for example 2 float numbers were in that buffer when the line of serial.read is executed will it read the first number then the other in the next loop or will it combine them into a string or something

That depends on ...

If you send the floats as binary, you will need a synchronisation mechanism which is not impossible but can make life more complicated.

If you send them as text, life becomes easier; I suggest that you study Robin's updated serial input basics topic. Example 5 will probably be the best choice; it demonstrates a sync mechanism based on < and > and how to parse multiple comma separated values in a received text.

Once you have the receive side in place, you can implement the sender to match what the receiver expects.

2 Likes

Ok will check it out thanks for your time

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.