views:

421

answers:

4

Alright so I am positive my Arduino circuit is correct and the code for it. I know this because when I use the serial monitor built into Arduino IDE and send 'H' an LED lights up, when I send 'L' that LED turns off.

Now I made a python program

import serial
ser = serial.Serial("COM4",9600)
ser.write("H")

When I run the code the LED blinks on for a second then goes back off. However when I do each of these lines seperatly in the shell it works just like it is supposed to.

Any ideas?

+1  A: 
  • Are the baudrate / parity / stopbits settings correct?
  • What happens if you place a long sleep after the write?
Eli Bendersky
+1, I'm almost certain a sleep will work :)
Nadia Alramli
The settings would have to be right or it wouldn't work in the shell, right?Same thing happens when I place a sleep.
dotlol
it's hard to say without more information, then. Try to install a virtual COM port loopback (like com0com) and verify that exactly the same bytes get sent in both cases with the different behavior
Eli Bendersky
A: 

I'm having the exact same problem, did you ever figure out a solution!?

sciguy14
A: 

I just ran into the exact same problem, when trying to run very similar code. Just to bump this post, would love to understand why this is happening. If I send data to the arduino from its serial monitor, it works. When I send serial data to the arduino from the Processing language, it works. But with pySerial it only works in the interactive shell, not in an executed module. :(

Eric Pavey
You can click the star above to favorite the question and get notified of updates. This isn't an answer and should be in a comment.
Daenyth
A: 

I had the same problem and it works if I add a delay of about 2 seconds from opening the serial connection to writing on it, 1 second was not enough.

Daniel Karling