Next, you’ll need to restart your Raspberry Pi. Open the Terminal and execute these commands:
sudo apt-get install python-serial sudo pip install pyserial
Connect your Arduino to your Raspberry Pi
Execute
ls /dev/tty*
Then find a line with /dev/ttyACM0 or something like /dev/ttyACM1 etc.,
check for an ACM with any number 0,1,2 etc.Open Python again and change ser=serial.Serial(“dev/ttyACM1”,9600) to the ACM number you found.
So if in your case, in your case you got ACM0 then the line should look like ser=serial.Serial(“dev/ttyACM0”,9600)