I'm using Python 3.10 to send an Arduino Uno integers to light up LEDs on a FastLED WS2812B strip. I can get the code to light the correct LED if between 0 and 9 (inclusive). However, anything above that fails.
Actually you are sending "characters" because your Arduino program has to convert them to integers. Did you notice that sometimes the Python program sends TWO characters, like when you enter "10"? But your Arduino program only reads and process just ONE character, so the second character is lost.
You should use 'ascii' instead of 'utf-8'.
In this case it may not be important but it can cause problems in other projects.
Better get used to the fact that you have to use ASCII encoding (because arduino does not "understand" UTF-8 encoding).
I had problems sending/receiving in UTF-8 from Python and it was hard for me to understand what the problem was, but that being the case, it may have been my mistake.
Thanks for the clarification.
Regards
@isawittoo The Python serial write method needs an object with the buffer protocol for example a character array or a byte array, there are several ways to do that here is an example with a function containing a one element bytearray
def send_data(value):
data = bytearray(1)
data[0] = value
ser.write(data)