Pages: [1]   Go Down

Author Topic: Arrays and eeprom reading and wrinting in Arduino  (Read 30456 times)

N5KBP

  • Member
  • Posts: 363
Arrays and eeprom reading and wrinting in Arduino
« on: November 23, 2016, 01:16:02 PM »

I am trying to learn the Arduino platform and as a practical learning tool I am working on a YC-601 clone for the yaesu radios using the Arduino and a tm1638 display module. I need to be able to save an array of long integers to the eeprom upon power down and retrieve it upon initialization. My main question is can I read and write the entire array as one chunk or do I have to do it one array element at a time. I have looked at using the EEprom object but I have also seen the eeprom.update function in order to minimize writes to the eeprom. Or would it be better to create a structure and R/W it to the eeprom at once?  Also as far as the power down write. I plan on using one of the analog pins to sense the input voltage prior to the 5V regulator and initiate the write if it drops below a preset level. Is this doable?  My experience has been in Visual Basic 6 so I am negotiating the C learning curve. Any enlightenment would be appreciated.

N5KBP
« Last Edit: November 23, 2016, 01:18:54 PM by N5KBP »
Logged

VK4HAT

  • Member
  • Posts: 508
    • HomeURL
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #1 on: November 23, 2016, 04:54:48 PM »

Ok, if i am reading your questions correctly, limiting the read write to eprom is a good thing, they only have limited read write cycles anyway, so less here is more.

Next, if you are limiting when you write to eprom to only say on bootup and on shutdown, then doing it all in one call is a good thing, this becomes 1 write cycle to eprom

Code: [Select]
MyFunc(var_1, var_2, var_3);
and this while functionally the same is 3 writes,

Code: [Select]
MyFunc(var_1);
MyFunc(var_2);
MyFunc(var_3);

Now depending on how long your data string is, you might need to break it up into a couple of calls anyway, if you are hitting the memory limits and the like. Also, if you really need to read and write to file often, you might need to add an sd card to your project and read and write to file rather than eprom.

Hope I followed your questions correctly as was helpful.

rob.
Logged

KG4RUL

  • Posts: 3781
    • HomeURL
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #2 on: November 24, 2016, 06:17:17 AM »

The EEPROM is good for an average of 100,000 write/erase cycles. 

You can only write one byte of data at a time to the eeprom with a write cycle time of 3.3 ms.  It is good practice to then read the location to verify the data.

If you are attempting to save data in a power loss situation, be sure that you can maintain adequate voltage to complete all required data writes/verifies.
Logged

KD0REQ

  • Member
  • Posts: 2644
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #3 on: November 24, 2016, 07:59:50 AM »

or just put on a SD card shield and write that.  if you believe the spec reflects fact, 100,000 r/w cycles, four times a day perhaps (start and shutdown twice a day), is 25,000 / 365 = 68 years. divide by the size of the array in bytes, and that's your reliability target.  there aren't all that many bytes on the board, so the array can't be ginormous.  if it is, add a shield and replace the SD card periodically after startup.
Logged

N5KBP

  • Member
  • Posts: 363
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #4 on: November 26, 2016, 11:27:16 AM »

Thanks for all the replays. I will be writing and unsigned long array of about 15 elements, so about 60 bytes at a time. The array will contain the offset values for 11 bands and last band, mode etc. used info. This will be read at startup. What my plans are is to power it 12v from the shack supply or wall wort. I will sense the 12v rail for a slip below 10v then write the array to eprom. I plan on having enough filter capacity to allow for the write before the 5v regulator drops out on the Uno board.  I might use a lm7808 between the 12v rail and the uno to keep dissipation of the 7805 on the uno down if it needs it. What do you guys think?
Marty
N5KBP
Logged

KD0REQ

  • Member
  • Posts: 2644
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #5 on: November 27, 2016, 11:36:03 AM »

the one interesting thing is if there is another cycle running, and you corrupt the write on power down.  I'd keep an A and B array, so there is always something there to fall back onto.  call the A "backup" and the B "active," or whatever flavor you prefer.  looks like you ought to have enough memory for this, and a short transfer routine.  pass parameters so if you choose to refresh the A from B, you don't have the overhead of writing the same routine over again, but backwards.
Logged

VK4HAT

  • Member
  • Posts: 508
    • HomeURL
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #6 on: November 27, 2016, 04:25:13 PM »

I might use a lm7808 between the 12v rail and the uno to keep dissipation of the 7805 on the uno down if it needs it. What do you guys think?
Marty
N5KBP


Just use a 7805 and feed the Vin with 5v, its what I do on all my arduino based boards.
Logged

WD4ED

  • Member
  • Posts: 49
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #7 on: June 09, 2018, 08:44:51 PM »

I hope some of you are still following this old thread.

But I have recently run into a similar problem.  I'm working on an antenna tuner where I want to store an array tying frequency (directly read), Inductor and capacitor positions from analog inputs.

28500000,4095,4095
28600000,2048,2048
28700000,1024,1024

Reading and writing these to an SD card is actually fairly easy.  Here's the problem.  Each memory have a "bandwidth" or tolerance to it.  So that the bandwidth of the RF network tuning can be taken advantage of.  This isn't really much of an issue either.  But it complicates the situation.  When checking a new frequency for a possible existing tuning solution, if there is a match or near match (the previously mentioned tolerance) where the tuning solution already exists that previously existing record should be deleted or  updated.

At the moment my conclusion is that storing data in a text file is not the most flexible way to store data.  It's create or append.  Short of reading the entire file and managing it in memory and rewriting the file in it's entirety.  I reserve the right to be wrong, but this doesn't seem very efficient or effective.  So if you are simply storing data for power cycling the SD card is an easy way to go.  But it's also not super fool proof.  But I've used both SD cards and EEPROM for this type of use. 

These issues have me looking at multi-dimensional arrays into EEPROM.  While I have yet to do this, I think it could be done.  Others have I'm sure.  It will be a new area of coding for me.  Of course there are the previously stated downsides of using EEPROM. 

Am I under some type of mis-understanding about this?  Alternate methods?  I'd like to hear some other suggestions to consider.

Thanks,

Ed
WD4ED
Logged

WO7R

  • Member
  • Posts: 6041
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #8 on: July 12, 2018, 03:28:58 PM »

This may sound a bit like overkill, but requirements like this lead me away from storing the data on the Arduino and having it output the data over the USB port to a waiting device like, say, a Raspberry Pi.

The Pi can handle this kind of problem six ways from sunday.  It is a simple configuration issue, for instance, to store this kind of data into a RAM disk and then (say) every hour or four hours offload it to an SSD.  You have a great trade-off between reliability and SSD read/write cycles, plus the ability to (e.g.) make the information easily accessible on the web and all kinds of things.  History keeping becomes trivial as well.

Most of this would not even require much in the way of programming either.  A lot of it can be done with "cat" and "cron" jobs.

Meanwhile, it is also easy to instruct the Arduino from the Pi with the serial interface, which keeps the Arduino programming quite simple and basic.

You could also replace the Pi with an ordinary Windows machine and, again, the programming involved is not very significant, yet you get the ability to offload what the Arduino can barely do, with a drastic ability to easily upgrade the functionality.

Essentially, I like my Arduinos to be stateless or nearly so and take instruction elsewhere when persistent data enters the picture.
« Last Edit: July 12, 2018, 03:35:50 PM by WO7R »
Logged

AD5GH

  • Member
  • Posts: 8
RE: Arrays and eeprom reading and wrinting in Arduino
« Reply #9 on: August 08, 2018, 09:25:50 AM »

Take a look at this

https://github.com/RodNewHampshire/LoRa-IOT-Home-Environment-Monitoring-System/blob/master/LoRa_Gateway_v1.5.0.ino

This code includes routines for reading and writing a data structure to eeprom on Arduino using the EEPROMex.h library. The updateBlock function writes only the elements of the data structure that have changed.
Logged
Pages: [1]   Go Up