I am trying to send an int number from Python to an Arduino using PySerial, using .write([data]) to send with Python and Serial.read() or Serial.readString() to recieve on the Arduino, then .setPixelColor() and .show() to light a LED on a matrix which position corresponds to the int sent by the arduino (I am using the Duinofun Neopixel Shield). But It does not seem to work properly, and I can't use the Serial Monitor as I am sending my data as the port would be busy. I have tried to input a number myself using Serial.readString() then converting the string to an int and finally putting in into my function that displays the LED. It does work properly when I do this, but when I send some data over, all the previously lit LEDs suddenly switch off which can only be caused by a reset of the Arduino board as far as I know. This is the python code, it simply sends an int chosen by the user
import serial a = int(input('Enter pixel position : ')) ser = serial.Serial("COM16", 9600) ser.write([a])
And this is the part of the Arduino program that reads the incoming data.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(40, 6, NEO_GRB + NEO_KHZ800); void setup() < // put your setup code here, to run once: pixels.begin(); Serial.begin(9600); >void loop()
All the LED switch off when I send some data, except the first LED which position corresponds to a 0 used in the .setPixelColor() function. Problem is, the LED should light to the corresponding int sent by Python (e.g light the fifth LED for an int of 4).