Odd serial behaviour

Hello

My arduino is programmed to receive commands via /dev/ttyACM0 from my PI.

However, everytime I upload a change in the program to the arduino, I need to connect using "picocom --omap crlf /dev/ttyACM0", and then manually send a command.

After that, I exit picocom, and run the python script; then the Arduino replies normally. if I dont do that, my python code will just timeout.

Here is a portion of the python code to connect.

......
# coneccion serial
dispositivo = "/dev/ttyACM0"
ser = serial.Serial(dispositivo, 9600, timeout=10)


try:

        ser.flushInput()
        ser.write("2\n") # request data from arduino....
        time.sleep(0.03)
        linea = ser.readline()
.......

Any ideas what could be wrong?

Thanks!

You may need to change the setting for DTR or RTS (or similar - I've forgotten exactly what it is called) in pySerial. The default may not be suitable.

What Arduino are you using?

...R

I am using a MEGA...

Krantz:
I am using a MEGA…

You did not say whether you tried my suggestion or whether it solved the problem. I think it is called serial.rtscts

…R

I tried using rtscts -- same thing :(

Krantz: I tried using rtscts -- same thing :(

Post your latest code. Without that it is impossible to know what may be causing the problem.

Are you allowing time for the Arduino to reset when your Python code opens the Serial port.

Have a look at this Python - Arduino demo

...R