For some spectroscopic experiment I read out encoder positions with the arduino uno and I want to sometimes query those positions by computer. If the computer or my software restarts, I still want to get the correct 'absolute' position, but the initialization of serial communication resets the arduino, hence the position is lost.
I see a few solutions to keep/recover the last position, can somebody point me to the right direction among those?
I might store the last position in some eeprom bytes. But the encoder is moving a lot, so the specified 100'000 eeprom writes don't seem like a lot (http://www.arduino.cc/en/Reference/EEPROMWrite).
I might start fiddling with SD storage, but that seems like an overkill for some 4 bytes of data.
I might try to read back the last position number on a HD44780 lcd display after the reset. But reading from the display is unfortunately not part of the LCD library, so this would require some hacking.
I might circumvent the USB port and instead use serial communication.
Any feedback is welcome.
Greetings,
Thomas
P.S.: Thank you for your comment, Grumpy_Mike. Unfortunately, the encoder is part of a Sony optical linear scale, not replaceable and not an absolute encoder. The position is controlled by a PI linear stage, if we turn the power off, the stage won't move.
The suggestion by liudr about the DS1307 sounds interesting. Have to read a little about that option.
Please... do not edit your original post as a reply to the previous posts. It is confusing and we still have plenty of space on the interwebz to keep your replies in separate posts.
Will you know when will the power be off? Otherwise, everytime the wheel moves, you'll have to write to memory. This is all pretty, up to a certain speed... after that it stops working. Plus the read/write memory cycles would go up really quick.
Reading from the display suffers the same problem as reading from Arduinos memory. The LCD has RAM, not ROM... so if you cut the power to Arduino, I suspect you cut power to the LCD and there goes your memory.
You can bypass the reset signal from the USB chip. Seeeduino has a switch for that.
To be honest, and as much as I can understand the "cool" factor you want to include in your application, if power is cycled your system should find itself and then start working and not remembering its position as this can be a safety issue.
No it is a minimum guarantee. Any one individual chip may, and probably will, work for much longer so that post is no surprise. However this is no way to design anything on the result of one test.
As a first quick fix, I saved the encoder position to eeprom after a few minutes of inactivity. The setup routine loads the last saved position, hence the chance for losing the position is much reduced.
In the meantime, I got an HD447780 display and wrote a read/write program for it, so I can use the last displayed position as startup value. I still save to EEPROM after a while and toggle a flag to note if the EEPROM position is up-to-date.
P.S.:
Answer to Bubulindo: I don't worry about power-outages, but about the software crashing and resetting the communication with the Arduino. We do some quite elaborate data acquisition (running time-of-flight measurement with ns resolution at kHz repetition rate, collecting data for thousands of encoder positions over the course of a day or so). So other elements of the experiment may require a reset as the controlling Labview software is not too friendly.