Using EEPROM with Arduino - Internal & External

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we're working with EE proms I'll show you how to use both internal and external EE prompts to add non-volatile storage gear Arduino projects or makin memories today so welcome to the workshop [Music] hello and welcome to the workshop today we are going to be working with a eeproms electrically erasable read only memories now this is a form of non-volatile memory in other words this memory will retain its data even when you remove the power from your circuit now non-volatile memory has a lot of use in designs for example if you're rebuilding a controller for let's say a CNC machine or a 3d printer you probably have a calibration routine that you need to go through before you can first use it and it would be very annoying to have to do that every time you started the project up the calibration values could be held in a EEPROM and they would be available every time that you powered the machine up another use might be something like a digital radio if you are using an Arduino as a front end for a digital tuner you would want to be able to store some of your favorite radio stations and again you certainly wouldn't want to have to reset that every time that you powered your project up so a gain non-volatile memory would be the answer to that now we've worked with another form of non-volatile memory before of course we have used SD and micro SD cards and they could be used for both of the applications I just described however it's a bit of an overkill first of all there's the cost you would need to add a card reader onto your circuit and while they're not expensive it's a couple of dollars and then the card itself which is a few more dollars plus it's a bit of an overkill for the two applications I just mentioned those applications just require you to hold a few bytes of memory whereas the micro SD or SD card can hold gigabytes of memory so it's a bit of a waste non-volatile memory like a EEPROM is inexpensive and as you're going to see it's fairly easy to use in fact you may not even have to spend a dime to get non-volatile memory in your Arduino project because the Arduino itself actually has some EE prom built into it and I will show you that in a few moments so what we're going to do is we're going to start learn a bit about a EEPROM and where it fits in with the family of different memory chips and then we're going to start working with it with our Dino projects an ee prom is an electrically erasable read-only memory this is non-volatile memory in other words this memory retains data when the power is removed originally developed in 1973 ee proms were patented by NEC in 1975 these devices consists of two floating gate transistors per bit because they use two transistors per bit the density of EE proms is not as great as technology such as RAM they're available with a serial or a parallel data bus connection many microcontrollers like the 80 mega 3:28 have internal EEPROM let's see where iiep rumps fit into the memory family a ROM is a read-only memory now wrong chips are pre-programmed at the factory and the user cannot alter their contents an EEPROM is an erasable programmable read-only memory eeproms our user programmed and can be erased by using ultraviolet light EEPROM chips of a small window on them to allow you to do that these generally require a special EEPROM burner device the e EEPROM are electrically erasable read-only memory our user programmed and that can be erased with electric pulses there's no special burner required and they can be programmed right in circuit now for all their advantages ie proms also have a couple of disadvantages the main disadvantage is that EE prom support a limited number of rewrites although they can be read infinitely a hundred thousand to two million rewrites are typical values for an EE prom another thing with EE problems is they don't retain data forever it's typically retained for at least 10 years at room temperature so now let's start using props now as I mentioned at the beginning of the video the Arduino does indeed have some built in EE prom and the amount of EE prom depends upon which model of Arduino you have and Arduino Uno has one kill a bit of EE prom now EE prom is measured in bits not bytes so if you divide that by eight you'll find out you've got a hundred and twenty eight bytes of available EE prom and an Arduino Uno if you've got a mega you've got four times that for kilobits or 512 bytes and for many applications this is going to be sufficient now this memory should not be confused with the other memory within your Arduino the Arduino also has some RAM which is used just for operations holding variables etc and it also has memory that stores both the bootloader and the program that you've uploaded to the device the e EEPROM is separate memory from that now if this isn't enough e prom you can also use an external eg prom and as you're going to see they're very easy to use the EE prom I will be showing you is a I to see device it connects very easily to the Arduino and there are several third-party libraries you can use in order to interface with it and we're going to be looking at both these types of EE prom now when you're using EE prom you have to remember there are some limitations specifically limitations in the amount of times that you can write to it as I mentioned in the presentation you can read an infinite number of times in the EE prom but there are only a number of times you can write to it with the Arduino that's about a hundred thousand operations now $100,000 it really isn't for some applications if you were to write to your EE prom once every second it would only take you a couple of weeks before you have completely exhausted the device and it cannot be used anymore if you are going to be writing to it however occasionally a hundred thousand is certainly sufficient so keep that in mind when you're designing your code only write to the e EEPROM when it is absolutely necessary so let's get started with the internal EE prom in the Arduino what we're going to need for this experiment is simply an Arduino Uno I'm going to hold a couple of extra components up to it just so we can demonstrate the effectiveness of our EE prom so I'm going to move over to the workbench now I'll show you how to hook this up show you a simple sketch and then we'll run the demonstration now here is what we're going to need in order to run our internal EE prom experiments we will need an Arduino Uno and we'll need a potentiometer now I'm using a 10k linear pot but you can use any value over 5k and it will work fine we'll start by connecting one side of the potentiometer to the 5 volt output on the Arduino the center or wiper of the pot will be connected to the analog a 0 input on the Arduino and finally the other side of the pot will be connected to the Arduino x'g round and this completes the connections we need for our internal EE prom experiments now working with the internal EE prom is quite simple because Arduino has kindly provided an EE prom library and this is included with your Arduino IDE so you can go up to file and go into examples and you will see that the library has a number of different examples 8 of them to be exact we've got EE prom clear CRC get iteration put read update and right so basically all of the different methods you would ever be required to use to work with an e EEPROM are displayed in these examples and so let's go and look at one of the examples right now and I'm gonna choose the update one and maximize it now you might think that right would be the first one that I would logically choose after all I want to write data to the EE prom but update is actually a better method and the reason is if you recall the EE prom has a limited number of write cycles and so every time you write to the EE prom you're using up one of those write cycles with the update method a read is done first and if the location contains the same data as it's about to be written it excludes their writing so it only writes data whenever there is a difference it doesn't write it if it's the same thing and this can reduce the number of times that you have to write to the EE prom now the code itself is quite simple first of course we include the EE prom library and then we take a look at the address of the EE prom like the address within the e prom remember every space in the memory has an address we're going to start at 0 and there's nothing in the setup right now the loop is also very simple now as you recall we have a potentiometer connected to pin zero of the analog input so we do an analogue read and we divide it by 4 and that's because the analog input will give you a value of 0 to 1024 and we needed value a 0 to 255 and so we divide everything by 4 now you could have used a map command as well for this and it would perform essentially the same function and then basically we just do an ee prom update to that address and that value will go down here and we'll add 1 to the address to increment it and then we'll check the EPROM length now the length is the size of the EEPROM the number of bytes that it can store now remember different arduino z' will have different lengths and so instead of putting a fixed value we use length and as long as the address is below the length we'll incremented by 1 if the equals the length will it back to zero will delay over here and that will basically be the end of the loop we'll go back in over and over and do it again so once we've gone through all the addresses we'll go back to zero and start doing it all over again so very simple we're going to write the value from the pot into the different ee problem location so let's upload this to the arduino and go and do that now now i'll have to admit this is not a particularly visually exciting demonstration but what i'm going to do is upload the update sketch which i've done right now and here's my potentiometer on my arduino and i'm just going to turn the pot into a number of random locations i'm going to sweep it end-to-end over here and give it a couple of extra values and remember every time i move the pot the value is being read on the analog pin and that value is being written into the internal a EEPROM so now that i've done that let's go see how we can read that data now this is the e EEPROM read sketch which of course reads all the values in the internal EEPROM it's a simple sketch as well it starts off by including the e EEPROM library and then we set up an integer to represent the address with an EEPROM that we'll be using we also define a byte that we call value and that will represent the data value at that address now in this setup we initialize our serial monitor and then we go into our loop and in the loop we do an EE prom read at the address that we've defined and then we print the address we print a tab character and then we print the value in a decimal format and we do a print Lyne in order to make a new line after that we increment the address by 1 and once again we look at the EE prom length to make certain that we aren't exceeding the number of address locations in the EE prom if we are we go back to zero and then delay for half a second and do it again so this should basically be printing out the use on our serial monitor of what we have in the EEPROM so let's go take a look at the serial monitor right now and it starts off we have some values of 159 some there we go it's starting to move right now and this is because I was moving two potentiometers so here we go it's decreasing down to zero so we're at the very end now we're going up again now it's incrementing and it gets all the way up to 255 at the other end and goes down again and this was of course because I was moving the potentiometer back and forth so as you can see it's also quite easy to read the values from the internal EEPROM now this is the e EEPROM clear sketch this is a sketch you can use to set all the values in the EEPROM to zero and thus clear it so that you can use it again and it's a very simple sketch it includes the e EEPROM library there's no other variables defined then when we go into the setup we set up pin 13 as an output now as will recall the arduino uno and many other arduino x' have an LED attack - pin 13 and we're going to be using that LED just to indicate that the job has been completed and then we just basically in go through an iteration which is still in the setup by the way for the integer equals 1/2 the EEPROM length and we incremental we do an EEPROM right of that value and 0 so we'll go through all the address values up until the length limit of the e EEPROM and we'll write a 0 and then we will turn the LED high to indicate that we're done and that's it there is no code in the loop so let's upload that to our Arduino and it'll run right now and that's pin 13 on my Arduino so it is done and so now what we can do is we can go back into the read sketch that we had before and we'll upload that and we'll go and take a look at our serial monitor now and as you can see now all of the values in our a EEPROM are set to zero so using these example sketches that come with the e EEPROM library you can do all of the basic functions that you would ever need to do with the e EEPROM memory that's built into your Arduino so now that we've seen how to use the internal a EEPROM on the Arduino let's take a look at an external one now the tip that I'm going to be using is an extremely popular one it's called the 82 4 C 2 5 6 and it has 256 kilobits of EEPROM which translates the 32 kilobytes this is an i2c device and you can set the i2c address up yourself and for that reason you can use multiple tips so if 32 kilobytes of the EEPROM isn't enough you can add additional tips now you can get this tip by itself but it's also commonly available on a number of breakout modules with the i2c connections and with either dip switches or jumpers in order to set the i2c address I'm going to be using one of the modules but I'll also show you how you can use the chip individually if you'd prefer to do that so let's go and take a look at this little module and then I'll show you how to hook it up and how to program for it the 82 for LC to 5/6 is a 256 kilobit he prom this is a serial ie prominent uses the i2c interface to communicate making interfacing very easy it has three i2c address lines which will allow up to eight different devices on the same i2c bus this device is rated as being good for over 1 million rewrites now here's the pin out of the 8 pin dip package of the 82 for L 2 5 6 pins one through three are the three i2c address lines pin 7 is the write-protect line in normal operation this pin is grounded however if you bring it high it will prevent writing to the e EEPROM pins five and six are the i2c SDA and SCL connections and pins 4 and 8 are the ground and positive 5 volt VCC in addition to being available as an individual tip the 82 for LC 256 is commonly available in breakout modules making wiring and experimenting even easier and we'll be using these modules in our experiments now here are a couple of modules that are based on the 80 LC 2 5 6 EE prom and these are a bit easier to work with than by using the chip itself but of course you can use a chip itself and everything will work fine these simplify things though because they allow you to set the i2c address and connect very easily to the Arduino with a couple of jumper cables and so on this module for example we've got some pin outs on the side these are the pin ups for the i2c connection this one actually has a tiny LED on it so that'll just glow whenever the power is applied to it and it's got some jumpers on this side and the jumpers on it are being used in order to set the right protect and the three jumpers for the i2c address now on this module we have a similar arrangement this doesn't have a built in LED but it's got the four pins again in order to connect the i2c and on this one there's a very tiny little dip switch and again it's got four positions one for write-protect and the other three to set the i2c address so you may want to consider using these modules instead of the individual chip they already have the pull-up resistors for the i2c etc but of course you can use the chip itself as well for our external ee prom experiment we're going to need the following parts an arduino uno an 82 for LC 256 a EEPROM module you can also use the individual chip if you wish but you'll have to make sure to wire it and include some pull-up resistors a potentiometer I used a 10k linear taper pot but anything of 5k or above will suffice a small servo motor I used a standard SD 90 and a power supply for the servo motor which can be 5 to 6 volts now you can also power the from the Arduino supply if you wish if you do I would recommend adding an electrolytic capacitor across the supply lines to keep the motor noise from disturbing the Arduino will start by connecting the modules SDA to the a4 pin on the Arduino will connect the modules SCL to the a5 pin the modules VCC will be connected to the 5 volts from the Arduino and the ground will be connected to the arduino x' ground next a potentiometer will connect one side of this to the arduino x' 5 volt output the wiper of the pot will be connected to the analog a 0 input on the Arduino and the other side of the pot will be connected to ground the control line from the servo motor will be connected to pin 9 on the Arduino the servo ground will be connected to the ground on the power supply which also needs to be connected to the ground on the Arduino do not forget this connection finally the servo power will be connected to the power supply for the servo motor now that we have this hooked up let's take a look at the code we'll use for our experiment now here is the sketch that we're going to be using for our external ee prom demonstration now first before I show you this sketch I should explain what is going to do as you recall we have both a potentiometer and a servo motor hooked up to our Arduino and of course we're going to be using the pot to position the servo motor we're going to record those positions into the e EEPROM and then we're going to play them back and so we're going to start off our sketch by including the wire library which is the i2c library now this is built into your Arduino IDE as is this library the servo library for the servo motor now note that we are not using a separate library for the external ee prom although there are several libraries we could use including a popular one called ext EE prom just going to write functions to read and write the memory instead now the next thing we need to do is provide the i2c address of our module and this is the i2c address in hexadecimal you'll notice that's what the 0x at the front of it is and this is the address you will get if you ground all three pins on the tip the next thing we're going to do is define an integer which represents the potentiometer the pin that is on and it's on analog pin a zero we are going to also have an integer that holds the potentiometer value we're going to call that Val and initialize that as zero and another one to have the value we read back from the EEPROM it's called read ballots also initialized as zero then we have an integer the hold the number of addresses were going to fill now the e EEPROM has over 32,000 a dresses but if we were to record all of this it would take about 12 minutes to record and another 12 to playback so in order to save time I've just set the max address at 1500 then we're going to create an object for the servo or calling that my servo now we go on to the functions that I've defined in order to write and read the e prom the first one writes through the EE prom I call it right EE problem is only enough and it takes parameters of the address within the EEPROM that we want to write to the value we want to write and the i2c address of the e EEPROM itself we start off by beginning the transmission to the EE prom one so we do that with begin transmission to the address and then we need to send the memory address within the device that we want to read now this needs to be set as 2 bytes and we need to send them independently so first we'll send the most significant byte over here and then we send the least significant byte after that we're going to send the value that needs to be store so we're going to do a write of the value itself and then we end the transmission then we add a 5 millisecond delay this is required by the EE prom between writes the next function reads from the EEPROM I've naturally called that read e and the parameters it takes are the address within de from plus de eproms i to see address now we define a bite for the received data and then we begin the transmission again once again we send the to memory we send the memory addresses two bytes excuse me and then we end the transmission of what that will do is it will cause the e EEPROM to put the data at that location onto its buffer ready to be read so we do a request to get a byte of data from the i2c address so we request from the i2c address and the one indicates that we want one byte of data and then we'll read that byte of data and then we will return that as the output of the function now the set up is where all the activity happens in this program because we only want everything to happen once so we're not going to do anything in the loop we start off with a wire beginning because we give it no parameter that tells us that this is the i2c master we're also going to set up our serial monitor so we can monitor the activity up over there and we'll attack the servo motor to the BI servo object on pin 9 of the Arduino then we're going to print to our serial monitor to indicate that we're starting the recording and now we go into a for next loop to go through all 1500 addresses so we go through the for next loop on an each address we read the pot value and use a map command to map it to a value of 0 to 180 which is what the servo motor needs then we write that out to the servo motor and we delay 15 milliseconds this allows the servo to settle into position especially if it's going from one extreme to the other then we're going to record that position into the e EEPROM so we call the write a EEPROM function we just defined and we send it the address that we're sending that's the memory address we send it the value that we're sending and we also know which I to see EEPROM address were connecting to and then we just print all of this to the serial monitor so we'll print address equals or addr equals we'll print the address this is a tab character over here formats it nicely then we'll do a print line' to print the value and do a carriage return and then after we've gone through this 1,500 times will print the serial monitor that we finished recording and we're going to insert a five-second delay after that and then we'll print again to the monitor to say that we're beginning playback and once again we go through a similar for loop over here from the address 0 to an art case Mac's address which is 1500 and we do a read this time so we have read Val assigned to the value of reading the EEPROM at that specific address and then we write that value over to the servo again delaying it for 15 milliseconds to allowing it to settle and we print everything to the serial monitor finally once that loop is finished we go when we print playback finished and then we exit the setup now there is nothing in the loop because everything in this program happens in the setup so now that you've seen this let's load it up to word we know and watch it work all right I'm ready to run my experiment now here's my setup it's a bit scattered but I think you can see all the major parts the Arduino of course here's the EEPROM module the potentiometer and I bought my servo over here and my connection to my power supply is back here again make certain when you're using an external power supply that you tie the ground of that power supply to the ground of the Arduino or it simply won't work I'm going to reset this and start it and we can take a look at the serial monitor and as you can see the monitors displaying the positions and I'm moving the plot around and at one extreme it's at zero and the other extreme 180 and then every value in between so I'm just gonna randomly move this around a bit we can watch the servo move and watch the serial monitor as we increment now remember we're going to 1500 you know oK we've hit 1,500 it's finished recording it's no longer responding to this and now it's playing back after the delay and as you can see the serial monitors rep reducing the numbers and the servomotor is represents that we've used so we've recorded all of that data now into the e EEPROM and that's what's playing it back and we could rewrite the code if we wanted to just to simply play it back from now on and repeat this motion every time the Arduino has started all right so that wraps up our look at E prom for today I hope that you've enjoyed it that you learn something and that you're now inspired to use non-volatile memory in your next Arduino project now if you need the sketches that I've used today or you need a bit more information you can check out the article that goes along with this video and you will find a link to that below the video and while you're on the drone bots workshop website if you haven't subscribed to the newsletter please do I send you out the occasional email just to let you know what's going on in the workshop and I promise I am NOT going to try to sell you anything now if you want to discuss everything that we've done today the best way to do that is to get on to the forum you'll also find a link to the forum at forum dr. own bought workshop comm and there are a lot of brilliant people who are on the forum every day having great discussions about all aspects of Arduino robotics automation and pretty well everything that you can think of so it's a great gang and if you're not a member of the forum yet please join up and participate in the discussion and finally of course if you have not subscribed to the YouTube channel I would be very thrilled if you would I always appreciate getting new subscribers and it's the nicest way to say thank you for the videos so if you haven't subscribed yet just hit the subscribe button below the video or click on that little robot in the bottom corner and he'll do the job for you so until we meet again take care of yourselves have fun working with your EE Proms and I hope to see you again very soon here in the Dermott workshop goodbye for now [Music]
Info
Channel: DroneBot Workshop
Views: 170,817
Rating: undefined out of 5
Keywords: non-volatile memory, external eeprom, eeprom chip, Arduino, Arduino EEPROM, using eeprom with arduino, arduino memory, arduino external memory, internal eeprom, arduino tutorial
Id: ShqvATqXA7g
Channel Id: undefined
Length: 31min 53sec (1913 seconds)
Published: Sun Oct 13 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.