#65 Arduino EEPROM Basics - easy to do and useful to implement

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ก.ค. 2024
  • New! ralphbacon.blog
    Storing data into non-volatile EEPROM memory (that does not lose that information when the Arduino is switched off) can be very useful, whether that's for remembering some configuration settings or the high score of your latest game.
    Best of all, it's so easy to do these days as you don't have to know how long the data is for the data-type you're trying to store (nor do you have to switch the high and low end bytes around either - see what I mean?)
    So don't forget the last value you calculated; use the EEPROM instead of an SD card - you can write to the same cell 100,000 times so you might not need an SD card at all in certain data logging situations.
    Knowing how to do this is all part of the Arduino learning experience and here I actually implement an improvement to one of my existing projects (in daily [well, nightly] use) to make using it just that tad easier.
    The sketch I'm using builds upon an earlier sketch for the project I have now enhanced but it will be child's play to use those lines in your code.
    I've included the sketch used in the video here just for completeness:
    bit.ly/EEPROM_basics
    Background C# 'struct' information
    playground.arduino.cc/Code/Struct
    Writing ANY data type to EEPROM background (now part of standard EEPROM library):
    playground.arduino.cc/Code/EEP...
    The standard EEPROM library functions:
    www.arduino.cc/en/Reference/E...
    For advanced users, the extended EEPROM library (includes bit writing)
    playground.arduino.cc/Code/EEP...
    If you like this video please give it a thumbs up, share it and if you're not already subscribed please do so :)
    My channel is here:
    ------------------------------------------------------------------
    / ralphbacon
    ------------------------------------------------------------------
    How can I remember this? Memory tip: "See" Ralph Bacon, geddit?
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 158

  • @hoppynaki
    @hoppynaki 6 ปีที่แล้ว

    Another great video to assist me to complete my projects. Thanks Ralph

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Thanks for your post, hoppynaki.

  • @josip1881
    @josip1881 3 ปีที่แล้ว

    You are the best Ralph when it comes to this topics, thanks! Was amazed how many old EEPROMs one can find in old tech from 90-is and early 2000, in old monitors and TV's there is tons of useful stuff, good for first experiments :)

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      Glad you enjoyed it!

  • @JonHeckendorf
    @JonHeckendorf 3 ปีที่แล้ว

    I'm needing to store and recall values for a project I'm working on and found this video about using the Arduino EEPROM (never needed until now) which prompted me to write this. I subbed your channel many years ago and liked this video many years ago as well. But, I never get tired of your presentations and detailed explanations. I hope you never stop. Thank you for being here for us, DIY experimenters.

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว +1

      Glad it was helpful, Jon! A bit of a pause right now whilst I move house... eventually... but I'm still working on future video ideas.

  • @maxximumb
    @maxximumb 7 ปีที่แล้ว

    I've salvaged so many EEPROMs from different old circuit boards, now I have a couple of ideas on projects to use them.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Excellent! I'll be using EEPROM where I can too as it's easy to do.

  • @demetriosdemetriou1114
    @demetriosdemetriou1114 6 ปีที่แล้ว +1

    RALF YOU ARE ALWAYS BUT ALWAYS FANTASTIC WELL SPOKEN AND EXPLAIN SO BRIGHT

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Thanks for your post, demetrios demetriou, good to hear from you.

  • @squalazzo
    @squalazzo 7 ปีที่แล้ว +1

    great video as always, keep on doing them! :)

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว +1

      Thanks for the feedback, great to hear. And, yes, I intend to keep doing them!

  • @seditiousmonkeyart
    @seditiousmonkeyart 2 ปีที่แล้ว

    Hello Ralph, I'm just beginning my adventure into using the EEPROM feature on the Arduino, and of course, you were my first port of call. As always I was not disappointed.
    I served in the Royal Australian Navy as a Stoker (engine and boiler room stuff). We also used red light when the ship went into action or damage control stations. Not only for the reason you gave that red light does not travel far, but also because it preserves your night vision should you need to venture out into the dark of outside the citadel (the closed of internal areas of the ship).
    Thank you for the great introduction. I am about to send you an email anyway with the latest project.

    • @RalphBacon
      @RalphBacon  2 ปีที่แล้ว

      Did you send that email, Adrian? Nothing here yet!

  • @pekkagronfors7304
    @pekkagronfors7304 7 ปีที่แล้ว

    Very good information picked up. Thanks.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Glad it helped you Pekka, I hope the other videos are equally useful! Thanks for posting, good to hear from you.

  • @chillzwinter
    @chillzwinter 3 ปีที่แล้ว +4

    So if you change the brightness from 0 to 255, you press the up button 255 times, and it writes to the eprom 255 times. Maybe only write to the eprom after the value has not changed for more than 20 seconds using the millis() command - will potentially extend the life of the eprom address by a couple hundred times. PS. Love the debugPrint() command - gonna use that.

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      I already do what you suggest in the sketch, check it out!

    • @chillzwinter
      @chillzwinter 3 ปีที่แล้ว

      @@RalphBacon In the loop I see:
      while (digitalRead(swDown))
      {
      analogWrite(pwmPin, fadeVal);
      fadeVal = fadeVal > 0 ? fadeVal - 1 : 0;
      delay(200);
      debugPrint(fadeVal, true);
      EEPROM.put(0, fadeVal);
      }
      Unless I'm overlooking something, that appears to write the change to the eprom every 200mS while pressing the brightness down button. Does it take 200mS x 255 (or 51 seconds) to change from full brightness to zero brightness? Moreover, that code seems to write to the eprom with every value change from 255 down to 0.
      Either way you have earnt 1 x like and 1 x sub.

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว +1

      Thanks for the like and sub!
      Apologies, I was thinking of the Digital Volume Control sketch, where I definitely delay writing to the EEPROM until the adjustment has finished. In this sketch I obviously write to it immediately (just for demo purposes, you understand). TBH I can't remember the ins and outs of that video (it's getting a bit long in the tooth) but I'm sure I must mention the limited lifespan of EEPROM so I hope viewers *don't* copy my demo code verbatim!

    • @chillzwinter
      @chillzwinter 3 ปีที่แล้ว +2

      @@RalphBacon Cheers - I'm building a door unlock project with change-able (save-able to eeprom) unlock codes, so I'm sure I'll be checking out many more of your uploads for various tips and tricks. Thanks again.

  • @gamedinnah
    @gamedinnah 6 หลายเดือนก่อน +1

    7 years later… how’s the EEPROM? Excellent info, thank you 👊🏼

    • @RalphBacon
      @RalphBacon  6 หลายเดือนก่อน +1

      It's good! Although these days I'm using ESP32s (in pseudo-Arduino mode) that doesn't even have EEPROM, as such, but is emulated (and works just fine, BTW).

  • @stephenbarlin2314
    @stephenbarlin2314 ปีที่แล้ว

    Useful idea for improving my menu code.

    • @RalphBacon
      @RalphBacon  ปีที่แล้ว

      Glad it was helpful!

  • @mukageegee
    @mukageegee 19 ชั่วโมงที่ผ่านมา

    Thanks again Ralph. What a really easy way of linking remotes to Arduino. I have a 12 way remote set with keypad type control. Now...where is that Mega?😂

  • @AnimilesYT
    @AnimilesYT 5 ปีที่แล้ว +1

    Well.. Thanks, I guess. Now I have even more to implement into my binary clock. All of these things I've been discovering along the way really add up to the amount of work I have to do. This might be one of the most useful discoveries I've made though xD
    Thank you very much!

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      I'm glad you're finding the Arduinite journey so interesting & rewarding! Thanks for posting.

  • @stephenbarlin2314
    @stephenbarlin2314 ปีที่แล้ว

    Truly awesome

  • @RJParky100
    @RJParky100 7 ปีที่แล้ว

    All i can say is thank you!

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Well, Rob, you could say "I'll buy you a Ferrari" but I guess that was not your first choice of comment! Seriously, thank you for taking the time and trouble to say anything at all and I'm really glad you liked the video. Good to hear from you.

  • @BerndFelsche
    @BerndFelsche 7 ปีที่แล้ว

    Uninitialised, the get will set the fade value with 2 bytes of 255; i.e. 65535 as unsigned integer. this is easy to detect as uninitialised and you should put a default (factory) value into eeprom when detected.
    I usually write a "magic" value to a fixed address and a firmware version, so that the firmware doesn't get confused when the data storage layout changes.
    Factory-setting is done in a separate function that's called when appropriate by setup() or somewhere else as needed. Default values set by defines. If there's space, initialise a "buffer" using those defines (just takes compiler cycles) to simplicate the code for factory-set. Alternatively, store factory defaults elsewhere in eeprom, then use get and put to set run values.
    avrdude, which programs onto the arduino, can also initialise eeprom with custom values. Very useful! And, depending on fuse settings, it can read eeprom.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      This is an excellent way of detecting "new" EEPROM, Bernd. I like your idea of writing a magic number to a fixed point in the EEPROM that tells you whether it's ever been used. Regarding initialising EEPROM values with custom values at compile time, how do you do that if you're compiling with the Arduino IDE? Can it be done? It would indeed be useful! Thanks for posting, good material.

    • @BerndFelsche
      @BerndFelsche 7 ปีที่แล้ว

      Sadly, it seems that neither the Arduino IDE nor Eclipse provide for initialising data into EEPROM. :-(
      It should be possible but will probably take some IDE modification; including the ability to "compile" a suitable hex file from a C/C++ initialising statements. Worthy of a feature request?
      I used a Makefile that would invoke avrdude if it detected a change in "factory settings" of a rather complex Arduino application that I wrote in 2012; which needed lots of settings as it is a network-based application with web-based "dashboard" and a serial command console. It's been a while but I do recall having to "bash" the hex file of factory settings and its checksum.
      The code on the microcontroller would detect if the factory settings were "newer" than the previous "active settings" -- or if not initialised at all; and sit, waiting for a serial console user to confirm the reset to "factory" settings. The check to see if it was newer was to compare the version byte in EEPROM for "active" and factory; as well as the version of the software.
      If the software and factory version.release didn't match, then the software
      My development rule was to increment the version byte every time that the EEPROM layout changed and only the release byte if there was only a software change.
      Using avrdude to "burn" around 50 factory values saved more than 2 kilobytes of (program) flash space because the defaults didn't have to be stored for saving to eeprom by program. Running low on space, I had the option of managing a separate "defaults loader" program, flashing and letting that run, before flashing the proper application; or to initialise EEPROM with avrdude. The consequences of forgetting to first flash the defaults loader (i.e. potentially shipping a brick) induced me to use avrdude; which would always, even after flashing the big application, allow me to initialise factory defaults.
      Alas, the call for more features forced me onto a Mega anyway.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Well that is sad, although not entirely unexpected given the target audience for Arduinos - you seem to be pushing the boundaries and have a rather sophisticated mechanism which I think is quite neat.
      To include EEPROM initialisation code into a sketch that will only ever be run once does seem a bit wasteful, so using a separate program to do that gets around that problem rather nicely.
      I hope your post is read by others as there at least two viewers on this channel that use their own sophisticated upload programs for the Arduino. Thanks for posting, very interesting.

  • @billglass5160
    @billglass5160 2 ปีที่แล้ว

    Lots of good info, Ralph. Thanks! I avoided writing/reading from the same address by letting my home-brew library manage the addresses. The address increments in a circular mode every time I write/read a new string. For now, I'm only processing strings of any length from 1 to 255 bytes. Maybe I'll modify my library for structures too.

    • @RalphBacon
      @RalphBacon  2 ปีที่แล้ว

      Sounds good. We can write a lot of data to EEPROM without realising it. Do you also check that what you've written is actually there (ie read it back?).

    • @billglass5160
      @billglass5160 2 ปีที่แล้ว

      @@RalphBacon No. For a 1Kx8 EEPROM, I figured that, if I write a 1-byte string, my MTBF should be about 100M. Was wondering if my great great grandson will be interested enough in micro-controllers to change my Nano.

    • @RalphBacon
      @RalphBacon  2 ปีที่แล้ว +1

      Oh, he'll be there, hacking the ridiculously antiquated but quaint Nano as he studies Ancient Technology at his university (virtually, of course).

  • @willofirony
    @willofirony 7 ปีที่แล้ว +1

    A great presentation and very enlightening (sic). I heard you say that the eclipse with Arduino plug-in IDE was perhaps ott for the average hobbyist. Nevertheless, I have been meaning to ask you to do a presentation on your set up. I am used to the "intellisense" of Visual Studio and find the arduino somewhat basic (its aversion to true static libraries is a pain too, particularly in memory sensitive situations). I think many of your subscribers would find it educational to have the library code exposed in such a user friendly manner. Yes, I know there has been a recent release of a VS plugin for the Arduino family but, alas, I am moving my development environment over to Ubuntu , so no more VS or AVR Studio for me (sob!). Thanks for your presentations, they are a treat. Merry Christmas Ralph.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Greetings, Michael, and thanks for your kind words about my videos. Now about the Eclipse development environment. If you use VS then you are already way ahead of most hobbyists and would probably benefit from Eclipse, not least because of its Intellisense. But it did take me two attempts and probably 3 hours and even then there was some back-end tweaking that you only discover after using it for a bit. I'll take on board your suggestion and ruminate and cogitate a bit and see where that leads me. I do suspect I would lose 99% of my viewers though if I tried this. Perhaps an additional video with lots of suggestions and links might be enough... we shall see but thanks very much for registering your interest in Eclipse and I truly will consider it. Now I must catch the bartender's attention as I'm on holiday 5,000 miles away! Hasta luego mae (a clue on my whereabouts)!

    • @willofirony
      @willofirony 7 ปีที่แล้ว

      Ralph further to our exchanges on the Eclipse IDE solution. A Code Project article has just been posted describing a "Debugger for Arduino". This to is an add-inn for Eclipse so you might find it of interest. Find it at: www.codeproject.com/Articles/1037057/Debugger-for-Arduino

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      That's interesting. I tried to read the article on my phone but gave up - I'll read it properly tonight. Needless to say, if this works it will be just great. Hardware debuggers aside, I always thought software debuggers just inserted code at various debugging points to show the value etc but this promises to allow line-by-line stepping through code. Thanks so much for posting this, I shall see how (and how well) it works later :)

  • @BigDaddy_MRI
    @BigDaddy_MRI 6 ปีที่แล้ว

    Excellent tutorial. And the EEPROM encoding/decoding video one also. I watched all the Tiny85 videos. Now, wondering if there’s enough memory in a Tiny85 for a GPS disciplined clock. I2C for the 4 LED Displays you can get from the Eastern locations, I2C display LED driver included for 4 displays, and 9600 baud serial for the GPS module. A Tiny85 project on breadboard. Maybe start with an UNO, then optimize the code and bit bang the Tiny85 to run the whole show. Only would need 4 pins, right? So RESET can stay as is and a left over pin for auto dimming using a photoresistor! Sound like a fun project? Might be to much code for the I2C AND serial coms on the Tiny85. Anyway, just a thought. Thanks for the GREAT videos. Just outstanding. Cheers.

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Thanks for your kind words, Harry. You might be pushing a Tiny85 with all that, but there's no harm in trying. As you say, get it all working on a Nano or Uno and then try and port it over. Good luck!

  • @geoffreyjbrown
    @geoffreyjbrown 4 ปีที่แล้ว

    One idea for something to cover would be delving into how an Arduino Library works. One good example you could use is the EEPROM.h in the arduino/lib/EEPROM folder for the normal Arduino IDE. This would enable viewers to make the linkage between the use of an include in the code and how this is mapped out. It would help to demistify the complexity of the compiler and libraries.

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      I did do a video on how to _create_ a library, whilst being oh-so-careful not to let on we were actually creating an object to be consumed!
      th-cam.com/video/fE3Dw0slhIc/w-d-xo.html
      Is there really more you would like to see said? Let me know!

  • @tonyeezi7315
    @tonyeezi7315 6 ปีที่แล้ว

    I think if you're concerned about the reliability of the internal EEPROM then a SD card and Arduino compatible reader can be bought for pennies, and should give much more reliability as the SD controller will tend to store data in different parts of the memory chip.
    The EEPROM is great though for data that never changes throughout the life of the Arduino like reference data, etc, so memory cells are less likely to fail as they're only written once , but read many (WORM).

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      A good idea, Tony, especially as you say the SD card has wear-levelling algorithms built in. That said, unless you're writing LOTS of data to the EEPROM it is unlikely to wear out (100K writes to the same cell). In this particular project (still in daily use) because it only updates the EEPROM if the LED light level is adjusted (not a daily or even weekly occurrence) I suspect I will be in the Arduino cloud in the sky before that chip fails! Good that you mentioned that the EEPROM data is great for data that rarely changes (if ever). Thanks for posting.

  • @oncledan282
    @oncledan282 4 ปีที่แล้ว

    Hey, Ralph!
    Very interesting information, you got there in this video. I was looking for a way to store the time my Laser was firing and I was considering purchasing a memory module for my NANO controlled Laser Exhaust Fan Controller, but I think it's gonna be even simpler that I thought.
    More info to come via personal email, soon. Have a great day and God bless !!

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      Yes, EEPROM use is very simple on the Arduino!

  • @renezwart3201
    @renezwart3201 หลายเดือนก่อน +1

    Really interesting, thanks! Would it be possible to comment at how to combine a few 'fields'? Like following a menu choise (0 to 9) you'd have the 'name' reflected in the menu, being the first field in the EEPROM address, but then you have 4 (or more) data fields attached to that choise, which are then used in functions. Something like 'Name'; up to 10 characters, 'Height'; numeral, 'Time'; numeral, 'Count'; numeral, "Comment'; up to 10 characters. I appreciate you could start the addresses with 10, 20, 30 etc. but wonder if there is a smart way to create this. Bit like an arrae structure I guess. Any comments appreciated, thanks! Cheers, Rene

    • @RalphBacon
      @RalphBacon  หลายเดือนก่อน

      Yes, you could create a "struct" with all the fields inside it, then save that struct (which is just a sequence of bytes but the struct ensures it has meaning).

    • @renezwart3201
      @renezwart3201 หลายเดือนก่อน +1

      @@RalphBacon Thanks!! Really appreciate your quick response. Will readup on "struct". Cheers, Rene
      Found it in your #65 - Great info!!

  • @jeffreymelanson9230
    @jeffreymelanson9230 6 ปีที่แล้ว

    A good tutorial on using an EEPROM to store usernames and passwords to lock and unlock a circuit would be very interesting and useful. :)

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      The trouble with storing sensitive data like this is that it must be encrypted. Anything you (or I) as a non-security expert can think of can be hacked. But we can most certainly obfuscate the data and make it difficult for someone to determine the data (or even that there is data there in the first place). I shall ponder on this interesting subject some more, thanks for the suggestion, Jeffrey.

  • @pantac4493
    @pantac4493 6 ปีที่แล้ว

    great video. very well explained. if I have two, six digit numbers to be saved, do I start at address 0 for the first one and then 6 for the second or is the library smart enough to allocate it on its own if I just use 0 and 1? thanks

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว +1

      I'm afraid that the organisation of the EEPROM is totally down to you, Pan Tac! Which means you are correct inasmuch that you start at 0 for the first six-digit number (I'm assuming this is a 6-character string?) and then the next one starts at position 6. It's easy enough to do if they all have fixed, identical sizes, not so easy if you have all various sizes of variables that you're storing. In the latter case you would probably put a byte at the start of the value indicating its length with a null terminator (or something similar), just so you could find them again reasonably easily. Memory management is a bit of an art!

  • @MyBigThing2010
    @MyBigThing2010 7 ปีที่แล้ว +1

    red light is used by military because it allows operation, equipment manipulation and map reading without disturbing the soldier's night vision that takes a while to develop (when your eyes adjust to the darkness) and it's easily destroyed by other wavelengths causing you to have to wait for your eyes to readjust to the dark so you can see properly again...it also doesn't spot your eyes when you blink...like when you look into the sun and then see a blackness when you blink where your field of vision was overloaded resulting in black dots for a while that are effectively blind spots. not good to have at night when your life is on the line...I hope that jiberish typing makes sense ..

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว +1

      It does make sense because I was told this independently that red light is used by the armed forces for the reasons that you cite. I didn't know all that but I did discover form my DJ-ing days (yes, really) that red light is dim but good enough to see by (not bump into things) and I developed my Red Night Light on that basis. Works like a dream, and used every night. Nice that you have confirmed and taught me some extra bits along the way. Thanks!

    • @MyBigThing2010
      @MyBigThing2010 7 ปีที่แล้ว +1

      Ralph S Bacon cool, I still use it to this day while out afield. it helps to navigate through the dark woods and not kill myself on unseen objects while still being able to watch my compass, map and able to see my environment and movement/shapes in the dark. I actually took apart a fairly nice headlamp, salvaged the cool white LEDs n replaced them with a nice red cob style LED chip and other bits to make a looooong running, low mah but bright red head lamp...that of which is not available to buy on the market anywhere....I looked for years until I got the right combination of smart, fed up and spunky on the same day n hacked away. ...it was totally worth it and I have something you can't buy that everyone that sees it wants to buy off of me...n I've been offered ridiculous amounts for it......oh and I have a pir sensor hooked to an rgb set on red hooked on the toilet lol

    • @whitefields5595
      @whitefields5595 6 ปีที่แล้ว

      We yachtsmen also make use of red light when sailing at night. When on deck our eyes get used to the darkness and we can make out shades of grey, distant lights, etc. When we go below decks to check the chart table, make a cup of tea etc we always use red light. If we use white light, or someone accidentally turns it on, then we lose our night vision when we go back on deck. It can be very dangerous since it takes around 20 minutes to re-establish our night vision and it can be lost in an instant of white light. Temporarily blinded navigators are as useful as an ashtray on a motorbike.
      White light bleaches rhodopsin 'visual purple' in our eyes (see a biology book)

  • @davidmarks509
    @davidmarks509 6 ปีที่แล้ว

    great video really enjoyed it

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Thanks for your feedback David, appreciated.

  • @thepvporg
    @thepvporg 6 ปีที่แล้ว

    What about negative values?
    Would it store the 255 as a signed data type so it will show as 255 but internally it sees it as -255 to differentiate between never written to or written to?

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Not quite, Mark. Remember that it's just a bit pattern that is stored. How you *interpret* that bit pattern is entirely up to you. So if you were to write FF to a byte, does that represent 255 or -1? Only the person who stored that bit pattern knows this.
      So I'm afraid that 255 (or -1, depending on your point of view) cannot be differentiated. That's why it's so important to declare variables as signed char and unsigned char (or int or whatever) so that the C# compiler interprets the value correctly.
      Get it wrong and you will wonder why your "int testVar" suddenly goes negative s you add a further value to it! (int = signed int by default).
      In fact you can declare a signed integer as "signed testVar" (without a type of int) and it's the same. The 'int' is optional here). Crazy! Hence, I try as far as possible to *always* declare signed or unsigned and the type too on my variables to be absolutely clear.

    • @thepvporg
      @thepvporg 6 ปีที่แล้ว

      There must be a way to get from the system some information like a count of the number of writes to that cell. Thats the only way I can think of that would allow a chip to monitor wear and report bad data bits.

  • @JasonMasters
    @JasonMasters 7 ปีที่แล้ว

    It occurred to me that for an application where you might realistically "wear out" a particular location by writing to it, you could program a work-around thus:
    1. Have one 2-byte location initially programmed with a pointer to the location of the value you wish to store.
    2. On each write to the pointed-to location, do a verify to be sure you saved what you intended to save.
    3. If the verify fails, increment (or decrement if you're starting from the top of RAM) the value stored in the first location by the appropriate amount (2, in the case of 2-byte integers) to point to the next free location and save it, then re-try the write using the new location.
    Logically, this would mean you can use the whole of an EEPROM, since the first location will never be written to 100k times because you'll run out of EEPROM locations well before that occurs, so you'll be able to write 100k times to each location multiplied by the number of locations.
    For a 1024 byte EEPROM, using 2-byte integers, that means you'd be able to write 51199998 times before the whole of the EEPROM is worn out (I subtracted 2 because we'd be using one 2-byte location to keep track of where we're writing to). At 20 writes per day, that comes out to over 7000 years. That's some baby! ;)
    Even writing once per second gives a total life of about 59 years using the above method.
    This could of course be adjusted to work with any value which had a consistent size.
    Realistically, you'd get more writes than I've calculated because the value of 100k writes is just a guaranteed minimum, not an absolute limit. Just how long do you expect to live for? :D

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      This is excellent thinking, Jason. Just to prove your theory I've set off a sketch last night, how much longer has it got to run to prove you right? Ha ha! I don't think I have that many years left on this planet anyway. That is truly a great idea and I might just "borrow" your idea in one of my videos and claim all the credit - just kidding, claim *most* of the credit!!! Thanks for posting, great idea.

    • @JasonMasters
      @JasonMasters 7 ปีที่แล้ว +1

      Hah! You can use it so long as you credit me. :)
      Seriously, I'm what has sometimes been called a "Real Programmer!"
      I like to "roll-yer-own" when I write a program. My programs generally end up smaller, faster and far less buggy than the hacked-together library-based kiddie scripting which passes for programming these days. I'll use libraries, but only when I really understand what they're doing.
      I practically cut my eye teeth on the 8080 CPU and I've since advanced through the Z80 and various other CPUs and found my way into microcontrollers only a short time ago.
      Fortunately the same principles apply to any type of programming:
      1. Make it easy to use.
      2. Back-stop everything so your program always does something sensible even with the most wildly unexpected input possible.
      3. Murphy was an optimist! ;)

  • @m0gga
    @m0gga 7 ปีที่แล้ว

    My aquarium controller project is racing along. I have developed my menu based IDE for the 20x4 LCD, where I can input the on and off times for controlling the relays for my lights and pumps and my real time clock is functioning and the time can be displayed and dismissed at will whilst the button scanning function is running in the background, and I can switch on and off several relays at given times based on the schedules I have input using the IDE with four buttons.
    So far my sketch (or should I say landscape) contains over 2300 lines of code and I am far from finished, next I shall be using temperature sensors to switch on and off the heaters.
    Seeing your video on EEPROM usage got me thinking! Whilst I am still developing my sketch it is becoming a pain having to input all the timing schedules over and over again each time I upload the sketch to the Mega. I am a little rusty from my Z80 programming days and in your tutorial you dealt with storing and retrieving a single value. You said that a memory address can store a value

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Hey Fred, that's fantastic news, you're really diving in the deep end!
      When using EEPROM, the methods I've shown you will *automatically* use the correct number of bytes to store the variable type (eg, it will use 2 bytes to store an integer value). You must keep track of the number of bytes being used though, as you tell it where to start storing those bytes and you don't want it overwriting other values due to miscounting!
      What you're suggesting is a variant of "binary coded decimal" (BCD) where you store an integer value in one half byte, and the next in another half byte (4 bits, up to value 15) and is commonly used in digital clocks so it is easy to map two digits (eg "12") into a single byte rather than mapping 12 into two bytes ("1" for the first digit, then "2" for the second one). This is described in video #8 (audio quality a bit variable but OK).
      What you are suggesting would work but you would then need to compute tens and units to know how to display that value on an LCD. With BCD, you would one byte to store "12" with "1" in the first half and "2" in the second half of a single byte. Ditto for the "4" and "5" in the next byte. So you've used just 2 bytes to store 1245 and each half byte represents exactly the number you need.
      Hope this helps, keep going!

    • @m0gga
      @m0gga 7 ปีที่แล้ว

      Hi Ralph,
      I was only using binary numbers in my comment as an example of how a single integer is stored in memory, I won't actually be storing my data using binary logic, I presume that all that is done in the background by the compiler when using the EEPROM library.
      Am I right in saying that the number 12 would be stored as first byte in location 0 (0000) and second byte in memory location 1 (01100). Integers are always stored as two bytes even if the number being stored was zero (00000000)?
      All this is so I can get a handle on how to retrieve the data, e.g. 12 from memory location 0 and 45 from memory location 2.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Hey Fred!
      If you use the command EEPROM.Put(0, myIntVariable) that just happens to hold the value 12, then the library will place the value in EEPROM locations 0 and 1 because integers are two bytes long as you know. But, no, it won't put the "1" in the first byte and the "2" in the second byte. If you think how integers are held, internally, as binary representations, it would be 000000000001100.
      So the first byte (MSB, first 8 bits) would be all zeros and the second byte (LSB) would contain 12. If your values will *never* exceed 255 (which, in your time example above will not) then you could just use a single byte for each (eg one byte for the hour and one byte for the minutes) and store them in in EEPROM byte each, separately.
      If you're not worrying about space in the EEPROM (you have 1K) I'd personally just let Arduino do its own thing with the EEPROM.put command!
      I'm not sure if I'm answering your question. Let me know!

    • @m0gga
      @m0gga 7 ปีที่แล้ว

      Yes, thanks Ralph, and I will be using the EEPROM library. So when retrieving successive values using EEPROM.get you would increment the address read location by two to get the next number?

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Absolutely correct.
      You, as developer, are responsible for knowing how large the variables are that you're storing but the improved EEPROM library will do all the hard work of actually storing them for you. Get it wrong though and you'll be overwriting one byte (or more) of an integer with (part of) another variable. Could be tricky to debug! If you only have a couple of values it will be easy enough. If you have many then I'd probably store the start address of the variable in a table and use that instead of a hard-coded address value... Just suggestin'!
      Get it working first though! Good luck - and thanks for the query, others will be reading this and may have their own queries now answered. :)

  • @danielroibert5631
    @danielroibert5631 7 ปีที่แล้ว

    Hello, Thank-you for this nice video. What IDE do you use there ? Thank-you in advance.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Hi Daniel, great to hear from you. I (usually) use the Eclipse IDE with Arduino plug-in. However, unless you have a lot of patience I would say look at my video #69 on the Sublime Text Editor with 'Stino' plug in. Or read the comments below that video (by others) who suggest a lot of alternatives they say are good. We are spoiled for choice! Thanks for posting, good to hear from an Arduinite viewer.

  • @joeblow2109
    @joeblow2109 6 ปีที่แล้ว

    I'm going to have to watch this video a few more times for it to sink in.... I'm a little slow :( Here's a dumb question..... so is EEPROM the same as flash memory, but on a eg.(Atmega) chip? Thanks for the great videos....... you explain at just the right speed.

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว +1

      Yes, that's a good way of looking at it, Joe Blow, EEPROM is indeed flash memory like a tiny hard drive or USB stick but it's included *within* the microcontroller itself; you can add further EEPROM if you need it, and it's accessed by the I2C or SPI bus. But 2K of EEPROM is usually enough for simple Arduino projects! The fact that this non-volatile memory is included within the microcontroller chip is just one of the things that makes it a microcontroller not a microprocessor.

  • @MrBobWareham
    @MrBobWareham 7 ปีที่แล้ว

    Hi, Ralph that was most interesting with EPROM memory being added as you say most useful to store information. As I am new to Arduino why do you not recommend Eclipse and to stay with Arduino ide? when you changed over to Eclipse there was so much more information on the code I know it is more complex being C but is that not the way to go
    Thanks Bob-UK

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      C++ code is no more complex with Eclipse, Bob, than the standard IDE, but setting up (and using) Eclipse requires a certain perseverance and level of computer knowledge that I think Arduinite novices would easily be put off by.
      If you already (regularly) use Microsoft's Visual Studio then Eclipse is a good choice for Arduino work. If not, then Sublime Text with Stino is probably an *easier* choice that still offers more than the standard IDE but is not so demanding in terms of installation. You can see my video #69 on the Sublime Text Editor.
      The reason Arduino.cc developed the Arduino IDE is to let beginners start coding almost immediately so that they would be enthralled, get stuff built and thereby hooked. If they had offered Eclipse as the 'standard' IDE there would no Arduino movement, except for a poor few geeks like me! But give it a try if you're keen and see whether it floats your boat, no harm in trying. Runs on all platforms too.

    • @MrBobWareham
      @MrBobWareham 7 ปีที่แล้ว

      Hi Ralph thanks will have a look at 69 to see what it is all about I have a spare Stainless steel rain sensor if you want one to play with it is the least I can do as you are so helpful Bob

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว +1

      If you can let me know what sort of rain sensor you have there, Bob, I'll read up on it to see whether I can put it to some use. Thanks for the kind offer anyway :)

    • @MrBobWareham
      @MrBobWareham 7 ปีที่แล้ว +1

      Hi, Ralph, no problem will send you a picture next week so you can have a look there is no charge will send it free as well but tied up for a few days as my daughter is getting married this weekend. all the best Bob

  • @alanpowell328
    @alanpowell328 7 ปีที่แล้ว

    Hi Ralph,
    I've noticed that on the DS3231 RTC boards I use there is an I2C EEPROM, on a separate I2C address. As I'm just getting back into Arduino, I tend to use the bits and pieces I pick up in videos, yours and others, and stuff from Adafruit and Instructables and during my trolling around, more than one presenter has noted "the DS3231 also has an EEPROM but we won't be using it" . Not for much longer! more storage space for me.
    Regards
    Alan

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว +1

      Yes, I had forgotten about that good call. The EEPROM is not contained within the DS3231 itself but usually supplied by AT24C32N giving 32K. I suspect this is added to the modules to enable storing of data to a local EEPROM (you could then swap out the module and retrieve the data in the comfort of a lab or something). Whatever the reason it's all added value and I'm glad you raised this (and jogged my memory). Let us all know what you find to store in it!

    • @alanpowell328
      @alanpowell328 7 ปีที่แล้ว

      My biggest problem is finding the time to implement, in projects, all that I'm learning from your site and others - Julian Illett, Big Clive, Kevin Darrah etc, there are soooo many . Still, there is nothing wrong with knowledge for knowledges sake :-) although I prefer the practical side.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Time? Hah! I proposed a 30-hour day some time ago but it was never adopted! Hang on Alan, you watch *other* channels too? Who are these young whipper-snappers? Never heard of them, heh heh!
      The thing about having an appreciation of electronics, Arduinos, C++ and everything else that goes with them is that at least when you need to use it you know that you read something about that thing you're trying to do so you know it's possible and the information is out there. Finding it is now the challenge!
      But you are 100% correct about one thing: you only get *experience* through actually doing, not reading about something. "Those who can, do. Those who can't teach." Hopefully I do both!

  • @MultiRdh
    @MultiRdh 6 ปีที่แล้ว

    hi ralph i just buy 24lc512 EEPROM ........ i have to program EEPROM before using like uploading boot-loader in atmega 328p or just use it by using i2c method???

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      You don't have to 'program' an EEPROM - it just contains data, not programs. So connect it up and use any method you have available (I2C is fine) to write to the individual cells. They have value 255 if they have never been written to before.

    • @MultiRdh
      @MultiRdh 6 ปีที่แล้ว

      Ralph S Bacon thanks

  • @__--JY-Moe--__
    @__--JY-Moe--__ 2 ปีที่แล้ว

    💪

    • @RalphBacon
      @RalphBacon  2 ปีที่แล้ว

      Glad you liked it!

  • @Tetramorium
    @Tetramorium 7 ปีที่แล้ว

    What is the lifespan of the Arduino eeprom? how many writes can you do until it "dies"?

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Hey there Tetramorium! The official line is that you can write 100,000 times to the Arduino EEPROM. This is why it's a good idea to use the "put" command, as it only writes to an EEPROM cell if the value is different to what you want to store. Additionally, you can implement a basic wear-levelling technique to reduce multiple writes to the same cells, over and over again. That's a bit of a catch-22 though, as you have to know where to read the data from. And if that information is stored in the EEPROM... Good question, thanks for posting!

  • @shaseeb692
    @shaseeb692 6 ปีที่แล้ว

    hey ralph can you make some tutorial video for led/relay on off with save data in SD-card like save data in EEPROM?? because EEPROM write only 100k times and SD-card have infinite writes

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      If you look at video #22, syed, it contains lots of info about using an SD card (to log data). Combine that with video #18 all about relays and you have more than enough information to do what you want! Go on, have a go!

  • @mukageegee
    @mukageegee 4 ปีที่แล้ว

    Another zilllion years :-))))

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      At the very least, I would say!

  • @PerchEagle
    @PerchEagle 5 ปีที่แล้ว +1

    What's this cool IDE? Could you tell us what's the name of it and where can we download it?

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว +1

      It's the Sloeber Eclipse. Not for the faint-hearted. If you know Microsoft Visual Studio you will get on with it quite well, otherwise be prepared for a bit of a learning curve.
      eclipse.baeyens.it

    • @PerchEagle
      @PerchEagle 5 ปีที่แล้ว

      @@RalphBacon I worked with Atmel Studio 7, is that enough?

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      Yes that will help quite a bit, go for it. But remember to install DIRECTLY into a folder on your C: (or root) drive not any subfolder as otherwise you will have problems with folder paths being too long. There is quite a bit of help on his site but he assumes you are familiar with some concepts and terms.

  • @TechMan-sl5gf
    @TechMan-sl5gf 7 ปีที่แล้ว

    Was hoping this was on flashing it. Well, maybe when I need to I'll sort it out.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Hey Techman, do you mean you were hoping this was on flashing the EEPROM but was *not*? If so, do you mean flashing the bootloader? Let me know your thoughts as I'm always keen to put projects on my backlog that viewers actually have personal interest in.

    • @TechMan-sl5gf
      @TechMan-sl5gf 7 ปีที่แล้ว +1

      Yes, mean the boot loader. At some point I will have to design and have a card build..The prototypes will be the default card in some test configuration. But once the circuit design has been tested and finished I will have to send off the circuit somewhere to be build. When I get it back I will have to flash the thing with something to get it working. So, the initial code and the code I wrote. I'll sort it out.

  • @xDR1TeK
    @xDR1TeK 4 ปีที่แล้ว +1

    How you don't have at least half a million subs by now just blows my mind. You know what also blows my mind? That damn tiny chip, with all that progress from the open source community libraries.

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว +2

      I think it is quite difficult to get large numbers of subscribers, but I appreciate the sentiment! Yes, the Open Source movement is alive and kicking!

  • @livetohash6152
    @livetohash6152 2 หลายเดือนก่อน

    I'm 7 years late to this 😮
    ... So could I store a clock setting n keep it in eeprom every minute say, so if the watchdog resets, I can reload the time? Say I synch with a server via Ethernet... Then I don't need an RTC 🤔

    • @RalphBacon
      @RalphBacon  2 หลายเดือนก่อน

      Fraid not. If you don't have WiFi connected then your Arduino has no idea of the time. Storing a value in EEPROM doesn't help, how will the Arduino know how much things has passed since it stored the value there? If you have WiFi then it all works auto magically via an NTP server anyway. Without WiFi you need an RTC device.

  • @Venkatmas
    @Venkatmas 4 ปีที่แล้ว

    How to use eeprom in home automation projects please give some code for me ?

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว +1

      The demo sketch for the LED light uses EEPROM and can be found here:
      www.dropbox.com/sh/qfslqukkg5xrzq1/AACwbPLflxVrHbqpK50yG7d2a?dl=0

    • @pwkoert6594
      @pwkoert6594 3 ปีที่แล้ว +1

      I was about to ask the same question... 8-) btw. just found a video about 24Cxx I2C EEPROMs
      th-cam.com/video/M4-1FqxVJjw/w-d-xo.html
      KiloBytes of storage with just 2 pins...

    • @Venkatmas
      @Venkatmas 3 ปีที่แล้ว

      @@pwkoert6594 thanks

  • @alanpowell328
    @alanpowell328 7 ปีที่แล้ว +1

    Hi Ralph,
    I downloaded the code mainly to look at the conditional debug stuff ( and possibly steal/use the code in my own projects.) Unfortunately, Arduino IDE 1.8.1 tells me it "Could not create the sketch". I know this occasionally happens if the name has odd characters in it but the download seems OK. If you get a chance could you have a look at it please.
    File name 1W_LED_NightLight_PWM.ino is invalid: ignored
    java.io.IOException: No valid code files found
    Regards Alan

    • @alanpowell328
      @alanpowell328 7 ปีที่แล้ว

      Meanwhile I'll chuck into a text editor

    • @alanpowell328
      @alanpowell328 7 ปีที่แล้ว

      which worked.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Well, Alan, I'm glad it worked but don't know why it failed (yet). I'll take a look tomorrow (possibly something to do with the IDE I was using, just guessing at this stage). But certainly use the conditional debug stuff, that's what it's there for! Thanks for bringing this to my attention.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว +1

      Alan, I've discovered the reason (although I don't understand the restriction):
      The sketch name had to be modified. Sketch names can only consist
      of ASCII characters and numbers (but cannot start with a number).
      They should also be less than 64 characters long.
      If you try and save a sketch starting with a number it automatically prepends an underscore. As this was developed in the Eclipse IDE this restriction was not in force. I shall take note and ensure my sketch names are Arduino IDE compatible in the future. And I've renamed it in the dropbox folder with an underscore. Thanks for letting me know this, live and learn!

  • @errolsternberg8185
    @errolsternberg8185 3 ปีที่แล้ว

    HI Ralph. I would like to know if you help your subscribers with projects if you have the time available. In South Africa it is a bit difficult to find someone that tinkers with the Arduino environment. I need to integrate two pieces of code. One is the (eeprom) which is already set up, and the other simple code setup already. Bring them together is my problem.

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว +1

      And that's the problem everyone has if they did not write the code in the first place (or, at least, fully dissect and understand the code). It's a challenge but it's _your_ challenge to work this out. No shortcuts, I'm afraid, Errol, start slow and experiment with everything.

    • @errolsternberg8185
      @errolsternberg8185 3 ปีที่แล้ว

      Thank you for your reply Ralph.

  • @demetriosdemetriou1114
    @demetriosdemetriou1114 6 ปีที่แล้ว +1

    YOU ARE SO WELCOMED DEAR RALF GOD BLESS AND FAMILY. I HAVE YOU AS A MODEL. HOPE ONE DAY WE MEET.

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Thanks for that, demetrios demetriou, nice to hear from you.

  • @joeblow2109
    @joeblow2109 6 ปีที่แล้ว

    Ralph......Thanks for your reply/s ...... say hello to Benny for me:)

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Will do Joe, thanks for posting!

  • @joeblow2109
    @joeblow2109 6 ปีที่แล้ว

    It's hard to get a simple answer these days..... so can we say the EEPROM is a small hard drive on an Arduino chip? read-write to it.

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      See my (more complete) answer to your other post here, Joe, and yes it can be seen as that!

  • @procactus9109
    @procactus9109 7 ปีที่แล้ว +1

    I was about to thumbs up, But there is no counter.
    So you miss out, sorry :\
    edit: Problem fixed, Thumb is given :)

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Oh, ProCactus, TH-cam will count every thumbs up even if TH-cam has chosen not to show a counter. I feel deprived. Sad. Unloved.

    • @procactus9109
      @procactus9109 7 ปีที่แล้ว

      Yes it will, And you are kind of right.
      But since I got your attention :), Can you help me understand the thinking of not making that number public ?
      And since I am back here, Ill tell you I don't even watch videos that cant be commented on. I know its not going to change the world and I am a minority in this regard. But I like to comment and rate.
      Cheers anyway. Good video.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      I've checked all my TH-cam settings and I allow absolutely everything to be seen. So I guess TH-cam have their reasons but they're not telling! But you can of course comment on my videos as you have done so maybe that's enough for now?

    • @procactus9109
      @procactus9109 7 ปีที่แล้ว

      TH-cam has for what ever reason made this decision for you ?
      You prolly should look into that.
      Am I correct in saying you had no idea it was not showing ?

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      It shows up in the Dashboard for my channel (that only I can see) but on the video itself I see nothing except the up/down thumb. I will check out a couple of other channels to see what they show.
      Update: I found the setting but it means that by default it was switched off. Now I have to edit each of my videos and manually switch it on. In future all videos will have a default setting applied. Advanced settings, apparently. Thanks Google Search. Who knew? (Well, you did, but I didn't!). Thanks for the heads up!