I am using Python 3 to send bytes to an Arduino over serial, receive them back (and print them in my python monitor). They go through the micro controller and it seems there is some weird behavior applied to it during this path. For instance, when I do:
a = b'\7'
op(board).send(a) #This is syntax specific to the program that runs Python
(which sends a byte value of 7 to the board) and:
It prints out b'7' as expected. However, when I try the same code but with a = b'8' it prints out: b'9265' and I have no idea what the difference is.
Similarly, for anyone who has experience using Arduino and Python, is there any explanation as to what format I could use to easily send Serial data to / from the Arduino? It seems as though I can only send bytes objects, but I am not sure how these are interpreted by the Arduino. It looks as though the byte value is converted to its utf-8 "symbol" value (i.e. as a string) then sent to the Arduino, which reads it is a binary value.
However, when I send this read value back to Python, it then sends a byte object with the decimal value. Since this is the case and I may be receiving a stream of values (from an analog pin for instance) what is the best way to rapidly decode these byte values into decimals
In other words, this would be fine except I would have to call chr(val) on every value. If I pass in the value b'151' (meaning I want a decimal value of 151 the arduino echoes back b'495349' and using int(chr(val)) does not work.
The real problem is that I want to be able to easily send values from the GUI of my program, (for instance, an analog write value). I am not sure how I should format the bytes object when I send it.