How to send numbers to Arduino UNO via Python 3 and the module serial
Parsing on the Arduino can be slow and time-consuming (which is bad if you use clock prescaling or have time-critical tasks), so let's do it in Python.

The problem is that you're sending the numbers as ASCII whereas you need to be sending them as raw binary. This is where struct comes in.

3&gt;&gt; import struct
3&gt;&gt; print(struct.pack('&gt;B', 0))
b'\x00'
3&gt;&gt; print(struct.pack('&gt;B', 255))
b'\xff'
3&gt;&gt; print(struct.pack('&gt;2B', 255, 0))
b'\xff\x00'
3&gt;&gt; print(struct.pack('&gt;H', 9000))
b'#('


So what you really want is:

data = arduino.write(struct.pack('&gt;B', valueToWrite))


or something to that effect.