I'm finding that opening a COM port to talk to my Arduino
causes it to be reset, but from there on it works fine.
I have a setup which is using an Arduino (actually a Freeduino)
connected by USB to my PC running Windows, for which the USB
is also the power to the device.
I've uploaded a sketch to the Arduino which enables it to have
a conversation through the serial port (using the FTDI driver
on PC and the Serial library on the Arudino). Specifically,
when I give it a number through the serial, it will light the LED
on the board for that many seconds.
I'm finding that when I open the COM port that the Arduino is on,
it resets the board. Even just clicking on 'Serial Monitor' in the IDE
causes the LED on the board (which was set by a timer ticking in my
sketch) to go out (looks like a reset to me).
Strange thing is, I'm sure this all worked fine a few weeks ago.
That is, I could open and close the connection without it resetting
the Arudino (I did it lots) and I can't figure out what's changed.
I think I'm using the same sketch on the board, and it's the same
software on the PC. I might have reinstalled Windows since then
(don't recall if the last test was before or after that) but
could there be any Windows setting to affect it?
Well I'm still new to Arduino but it sounds like the auto reset feature is at the root of what you are seeing. When a COM port is opened on your PC it is probably asserting DTR or RTS (or both). The latest Arduino boards couple those signals via a small cap to the reset pin on the board causing a reset to occur. This is a feature so that a sketch can be downloaded to the board from the IDE without having to manually press the reset button. However that doesn't explain why just activating the serial monitor on the IDE would cause a reset as I would think the COM port would already be opened. I'm sure the more experianced user here can help you get to the bottom of what you are seeing.
When a COM port is opened on your PC it is probably asserting DTR or RTS (or both). .... However that doesn't explain why just activating the serial monitor on the IDE would cause a reset.
This is the explanation. I believe the port is not opened until the serial monitor is started. In fact, changing the connection speed within the monitor also triggers a reset, because (I think) the port is closed and reopened.
Thanks for the feedback. I'm sure I had this all working, and was able to send multiple commands to the Ard without it getting reset.
I've also tried this with a Windows app I'm developing, using CreateFile to open the COM3 port. Every time I call CreateFile it resets the Ard board.
Is this really by design? It seems strangely limiting to have a serial connection but be unable to have a sketch reading the port while it gets disconnected/reconnected.
I wonder if I've inadvertently put it into a mode causing it to work this way (if it really didn't previously) or if I've changed the CreateFile arguments in a subtle way which has changed this behaviour. Or could it be a 'feature' of the FTDI driver?
Wow thanks very much Mikal, that's done the trick!
Strange business, if my app sets that flag once then I can restart the app and reopen the connection without resetting the Ard - guess it's setting a flag in the comm driver which persists.