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:

closed as off-topic by gre_gor, MatsK, sempaiscuba, Delta_G, VE7JRO Jun 27 '18 at 21:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – gre_gor, MatsK, sempaiscuba, Delta_G, VE7JRO
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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.

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