Your problem is that you aren't sending the values from python in bytes. A more reliable way is to send the data in bytes like dat.write(b'1') and then receive it on the Arduino using Serial.readString(). I also had many issues with this and this is the best solution. "https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/#:~:text=The%20easiest%20way%20is%20to,Arduino%20IDE)"
If not, you can us the i2c interface. Just be careful, the logic level if your python is running on a Raspberry Pi.
DragonflyRobotics
- 313
- 1
- 4
- 20