Equipment Used: Arduio Uno
USB connection between Arduino and PC using the following code.
Convert the string "123" from the PC to bytes and send it to Arduino. Arduino replies the data as it is and receives it on the PC side.
Python (PC) side:
At this time, if the baud rate (bps) is 9600, 14400, 57600, it can normally be received as b'1', b'2', b'3', but if the baud rate is 300, 19200, 115200, data such as b'\xff' and b'x0c' are mixed at the beginning.
Below are the results of each baud rate.python3 arduino serial-communication
The presentation code is typical of "uninstructed communication."In other words, the recipient = Arduino does not know where the telegram starts and ends.Therefore, there is a possibility that you will receive it from the middle of the telegram, and then it will look like a ghost.It happens that the baud rate is disguised or not (do you need a more detailed explanation of the "spooky principle"?)
So please decide the procedure (start + end commitment).This is called a protocol.
If it's the first one, the recipient is
When STXarrives, receive
ETX(Considering the possibility that the sender is bugging, be careful not to cause buffer overflow)
Return to initial state when ETXarrives
The first one is thrown away, but it can't be helped.
To ensure the validity of the data sent and received, it would be better to add a check code such as "checksum" or "CRC".
© 2022 OneMinuteCode. All rights reserved.