Hello everyone,
First off, I don't even know if this is possible, but here goes: I want to copy the contents of one Mega's EEPROM to another Mega via the serial monitor. I am using the EEPROMex library [GitHub - thijse/Arduino-EEPROMEx: Extended EEPROM library for Arduino](https://EEPROMex Library) to store a combination of bytes, ints, floats and longs.
Am I correct in assuming that if I can do a byte-to-byte copy from each EEPROM address, that the original data will be intact, ie: if address 100 has a float value, if I copy the bytes at address 100, 101, 102, and 103 to the same addresses on the new board, that EEPROMex can access the original float value at the 100 address?
Edit Never mind the above question, I will find out for myself later. The real issue is the transfer via serial monitor process.
If that is correct, my thought was to create a byte array from the EEPROM contents of the source board, transfer the array values to the serial monitor, and then write those values to an array on the target board. There would be 412 individual bytes, BTW
I have no problem creating the array on the source, and writing the array into EEPROM on the target, but I am hung up on the transfer process. Is there a better way to do this, perhaps?
Any pointers or help appreciated. Thank you!
The forum search yielded some related topics that were helpful somewhat, but I need to store that source array on the monitor while I unplug the source board and plug in the target board, then transfer the array to the target. Sorry for the long post...
Why not connect the 2 Megas with a serial link on one of their many serial interfaces then read a byte from Mega1 EEPROM, send it to Mega2 by serial link and on receipt save it to EEPROM ?
Why mess about with an array ?
Why are you using the EEPROMex library when the standard EEPROM library is probably easier to use ?
Definitely possible to send data from one MCU to another via a serial connetcion. Just be careful about your terminology... the "Serial Monitor" is not quite the same thing as a serial connection. The Serial Monitor receives data over a serial connection and displays it on the screen... I think you actually mean a serial connection in your question?
If you are using a Mega then is has multiple serial ports available... that means you can leave port 0 free for talking to the serial monitor (for debugging). Let's assume you use Serial1.
The commands you will likely need...
On the sender...
Serial1.begin() - opens the connection. Need to specify a baud rate. 115200 is fine.
Serial1.send(byte) - send a single byte... this will be the data from your EEPROM. You want this in a loop to send each byte from the EEPROM. If it's always 412 byte, a for loop would seem appropriate.
On the receiver...
Serial1.begin() - opens the connection. Baud rate to match the sender
Serial1.available(). Check this is >0... that means some data is ready to read.
Serial1.read(byte) - read a single byte... you can then store this in the EEPROM.
You will need the receiving code in a loop to get all 412 bytes that were sent. A very simple version of this (with no validation or error handling) below...
Without any programming you can probably use avrdude to read the eeprom from the first MEGA and using avrdude again write the eeprom of the second one (never tried)
Thank you! That was helpful. I also happened upon Robin2's serial input basics tutorial, which is also helpful.
I didn't want my first post to be too long, so I left out some information that may be helpful. The Mega is part of an integrated control system, and gives new meaning to the word 'embedded'. I have an external USB port on the control panel, but cannot directly connect the embedded Mega to another board, otherwise, I'd just use a Serial2 or 3 connection. The purpose of this project is to make a backup of the non-volatile data in case the embedded board fails and needs to be replaced.
Another poster asked what the serial monitor has to do with it, so to answer that, I was thinking of writing the series of bytes to the monitor, then copy/paste them to a text editor to save to a local file, then reverse the process at a later date to restore the values to a new board. I hope that makes sense. To make all this even more interesting, I'd like to do all this with my Android phone, since the whole shebang is in a remote location that I hate to lug a laptop to.
As I said, I didn't want the first post too long. I have noticed that very long posts tend to go unanswered, understandably. That may not have been an optimal decision in retrospect.
Your linked topic implies the use of a programmer It will not work over the Mega's USB port accessing the bootloader; reading does not give the expected data in the output file and writing fails with a verification error.
I tested with an Uno (no reason to believe that the Mega will differ) and adjusted the baudrate to 115200 to access the bootloader. OS is Antix.
Thank you sincerely for the information, but the snark was unnecessary. I had no idea avrdude could be used this way, hence it never occurred to me to search for it. Your tutorial was the first thing I saw when I used J-M-L's reference to do a search. Not even Google can help when one has no idea something exists.
Well, I got as far as trying to copy the data back to the target. At first, it seemed to be random numbers written back to the target board, but then it occured that what was happening was that the byte 231, for instance, was converted into ASCI for 2-3-1, or 505149, plus there was a start-of-heading and a null, or 10 that started the string. I haven't used atoi or strtok for quite awhile, but it seems some conversions are needed at either/both ends....nothing with serial is ever as simple as one would hope. lol