I am building a counter using the Arduino. The counter is working and the serial interface is working.
My issue is that I want to detach and reattach the serial port of my computer to the counter at anytime with out losing the count. I want the Arduino to keep on counting.
Every time I close the serial connection and reestablish the serial connection the counter is reset. Just like the program restarts.
The power to the Arduino is not lost during the change from serial connect to serial disconnect.
So is there a way to retain the count variable when the serial is reattached to the Arduino? Or does the serial disconnect and reconnect reset the program and there is no way around it?
I am using Serial.begin and Serial.println commands.
The opening and closing of the serial port on the PC causes the Arduino to reset because of the auto-reset feature on the Arduino board. This is so the Arduino IDE can force a reset to enable uploading of new sketchs to the board.
You have two choice to work around this 'feature'
Defeat the auto-reset feature with either hardware changes to the board or depending on what PC OS you use defeat the DTR signal in the PC serial software handler. If you search this forum for auto-reset you should find plenty of confusing ways to accomplish this.
The AVR processor chip has built in EEPROM memory where you can write and later read back data values stored in it. http://www.arduino.cc/en/Reference/EEPROM
Not hard to read the saved count value after a reset or power up cycle to restore the variable. The trick part is how to detect an upcoming reset or power down condition so that you can write the current count value into the EEPROM before the chip powers down or resets ??
The opening and closing of the serial port on the PC causes the Arduino to reset because of the auto-reset feature on the Arduino board. This is so the Arduino IDE can force a reset to enable uploading of new sketchs to the board.
That might need to be qualified to when using the arduino USB serial interface. It may not apply when using other methods of connecting a pc serial port to the arduino.
That might need to be qualified to when using the arduino USB serial interface. It may not apply when using other methods of connecting a pc serial port to the arduino.
ok I have a serial port arduino and it does the same thing, I dont think it really matters what stuff is tween the pc and the arduino, they both act like standard TTL serial ports at the important end, and if you have DTR hooked up to the reset its gonna reset
[edit]and if you have DTR hooked up to the reset its gonna reset [/edit]
That is the truth. That was one of the reasons I selected a Seeeduino board as my last clone purchase. Their boards have a built in little switch so one can easily turn on or off the auto-reset function.