I have recebntly started a project where I need to connect an arduino and another device through serial. And I have setup a simple serial connection betwee python and arduino. I can setup the connection through the python terminal and it works just fine. When I type : arduino.write("1"), It receives the data only once. However, When I run this code:

import serial

arduino = serial.Serial('/dev/ttyACM0', 115200, timeout=.1)

while True:

it writes properly, howver when I stop it using Ctrl-C, it doesn't stop sending and keeps sending to the arduino. Stops sending when I open a serial. connection using the python terminal again.

I have no idea what is causing this or how I can fiz it. Would reallly appreciate some help. Thanks in advance:

  • 1
    PC side programming is off-topic here. – gre_gor Jun 27 '18 at 19:52

Your python code is sending "1"'s to the serial port at a blinding speed. Way faster than they can go out over the serial line. So when you stop your python code the serial port is still sending trying to get all the "1"'s out of its buffer. When you open the connection again you clear that buffer and it stops sending.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.