Serial.write(some_byte) writes a byte on the serial output. The
Arduino serial monitor tries to interpret the bytes it receives as text:
0x11 is a control character, displayed as “□”
0x22 is the ASCII code for the double quote (")
0x33 is the ASCII code for the digit 3.
0x44 is the ASCII code for the uppercase letter “D”
To store a 2 character string you need a 3 byte array, not a 2 byte array. This is because in C a string consists of the actual string data and a zero ("NULL") byte at the end to indicate where the end of the string is.
So you would need:
so it can store, for the number 0x69: 69\0. Otherwise you overrun the array and corrupt ...
You can use .indexOf to find characters in a String. It returns a -1 if a match is not found. See https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/indexof/
while (mySerial.available() > 0 )
str = mySerial.readString();
You will save yourself a lot of headaches by sending the data in ASCII
instead of binary:
Of course, you will then have to parse the data stream on the Python
If you really want to send binary data, then be aware that the write()
method you are using is intended for ...
For your needs you don't need actual UARTs. You can do it all with normal GPIO pins and one (or more) interrupts.
UART communication is characterised by having a "start bit" at the beginning of all bytes. That is, in TTL terms, a transition from HIGH to LOW. You just need to look out for that transition.
Use Pin Change interrupts on 6 ...