I try to light up an led strip with Python sending the information to the USB port that has an Arduino and led strip on it. I am having problems with the USB port. I don't know which one is the right one and how can I translate this port to Python language.
I found this python code and modified it:
import serial
r = "255"
g = "0"
b = "0"
i = "255"
data = r + "," + g +"," + b + "," + i print(data)
ser = serial.Serial(port='/dev/ttyUSB0',baudrate =
9600,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS,timeout=1)
ser.write(data)
ser.close()
So the problem is I don't know if it is the USB0 I tried from 0 to 3 and didn't work.
I tried lsusb and I can see the Arduino:
Bus 001 Device 005: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
So it should be the 01? but it was not working then I tried this command: python -m serial.tools.list_ports
and I get these ports
/dev/ttyACM0
/dev/ttyAMA0
Tried to put them in place of port='/dev/ttyUSB0' and get permission error:
Error could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0'
solution
sudo chmod 666 /dev/ttyAMA0
And after doing it again I got:
raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: '255,0,0,255'
Before I even continue I am not sure that this is the right USB port. So can someone tell me how can I detect them for example like the lsusb and understand how can I translate it to Python code.
Thank you all.
SOLUTION See last device with this linux command
dmesg | grep "tty"
[ 8.150923] cdc_acm 1-1.1:1.0: ttyACM0: USB ACM device