Arduino Workshop - Chapter 4 - Using EEPROM

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] at this point in the Arduino workshop you may have noticed the elephant in the room we've been talking so much about information and data but so far everything you do on an Arduino is light as soon as power is disconnected so how do you go about storing information so that it isn't lost after a reset we use EEPROM Iran is a form of solid-state non-volatile memory which is commonly used in systems to store small amounts of data for microcontrollers it's like a quick tiny hard drive embedded on the chip most EEPROM units use low-level communication protocols such as I squared C by all unwire which makes them easy to integrate into projects bear in mind that the typical size of an EPROM chip is between 512 bytes and 4 kilobytes so it only allows a small amount of data to be stored at a time storing information in the EEPROM is simple you specify the address you wish to access and perform the desired function via reading writing or erasing some chips may come with their own built in EEPROM such as the ATM X 3 to 8 it has been built in Iran whereas others do not and require an external EPROM chip however you can always add more EEPROM to your projects using the appropriate communication protocol the Arduino you know has 1,024 bytes or 1 kilobyte of on-board EEPROM to use and can be easily accessed using the Arduino EEPROM libraries something to keep in mind when using EEPROM is that it has a rated life expectancy because of the way the EEPROM units function you can only write to each address a certain amount of time before it will start to fail and become unreliable the 18 mega three to eight EEPROM one board that it is rated at 100,000 write cycles some units may see this however Atmel only guarantees 100,000 if I sound like a lot but if you're constantly updating information for a project that is constantly running it won't be long before that EEPROM starts to fail depending on how often you're writing to it because the life cycle applies to individual bite size addresses you can counter this using a process known as wear leveling wear leveling involves keeping track of the number of times that you have written to an address and then when it reaches the limit you change to refresh a fresh address unless you're using large numbers of addresses this approach can greatly extend the life of your April now that we've discussed what a prompt is let's take a look at how we can store data using the AC major three to eight EEPROM on the Arduino you know we'll be using a standard push button as shown in previous sections to increment a counter and then storing that in EEPROM and we're going to be using a library which we haven't looked at before but we're going to take a more in-depth look at it in the next chapter however library is simply a module a bit of code that we can import into our program and it gives us a whole bunch of extra functionality and built-in functions that we can use to supplement and perform operations or functions that will be otherwise long and tedious to write up again and again there's no point reinventing the wheel right so we can use a library to do relatively simple and standard applications so let's take a look at the code here at the very start we're using cash include which puts the EEPROM etch header file and the library is as part of our code then we've got some pin definitions just our LED pin and button pin with an onboard led just of some visual feedback and then we're actually using pretty much most of this is just the total button function that we roll code that we wrote when we were taking a look at if statement that's all exactly the same we've got the last button state last press the bounce time only this time we've got this variable called counter which we'll get to in a moment first of all we set up our pin modes we initialize the serial ports get some feedback and now we say counter is equal to e prime dot R is an EEPROM dot read takes one argument the address of the EPROM chip that you wish to read so everything from address 0 is a very first address on board the EEPROM so in our void setup counter will equals EEPROM read so it will read whatever value is last put in there and update counts up so that we can keep our counter incrementing even after it's been powered off then after that this is the slightly tricky bit is we use EEPROM dot right now Efram don't write much like digital range digital right it takes two arguments it needs an address to write to and it needs a value to rest during the month as the addresses are only advice there are only eight bits to be careful not to exceed that otherwise you're going to get some random issues so we're writing to address zero the value zero which seems to be weird because we've just taken counter and said that we want to read that from EEPROM three but what this allows us to is later on we're going to be saying that counter is equal to a value and they're writing that to address zero but at the moment we have no way to actually reset this counter and reset the values that's in address zero so by putting that line in there but before we redefine counter it means if we reset our board or disconnect power it's going to set counter to whatever the EEPROM read is and then it's going to arrays or set to zero the first bit of the EEPROM address zero so when we reset again when it powers back up counselor will be read from the EEPROM which is zero and counter therefore will equal zero and it will reset however after a single reset that has no effect because of the logic how the code is written so we now loop as you know with the if statements will go so this bit a little bit of be covered in a previous section on ear statement we're checking to see the button state then we're performing some debouncing updating our last button set the important parts here is the counter that we're incrementing by one every time it's pressed where every time we detect a press on the button increment counter by one then we're writing to address zero about EEPROM and we're writing the value of counter so it's going to increment each time and each time we press it it will write that value to the EEPROM to save it to store it there so that it's power is disconnected we can access that value again and keep going from where we left off then we write to the LED just as some visual recognition and that's that and then we're going to print the value of counter to the zero one it up and then all we do if it is a release is to turn the LED block for visual feedback let's take a look we're going to plug this into our Arduino and take a look see that you guys can see that very good so now we need to upload the code to our board make sure you've got the correct for comport selected like I did not as given by the error and then it will upload to your board and the reason we using the serial monitor is whilst we can write to the EEPROM all well and good if you've got a more flex piece of code where it's hard to see exactly what's going where often you can lose track and you might not actually be writing correctly to the EPROM address so by printing out to Sarah monitor we can physically see what's been written to the address so when we upload this sketch and connect power to the board we can open up the serial monitor and see that when we push the button the council will increment those of 24 fantastic 25 26 27 28 which means that I've actually tested this out on the board before hand and incremented a few times to make sure that everything is running well and it's remembered that so quick it resets on our board once it's powered up again we can see it will continue where it left off we've disconnected power that's what reset does but it hasn't forgotten that variable because it's been stored in the EEPROM and our plant is powering up again it reads the value from the EEPROM and updates counter but as I said if we reset it and then reset it again we can see the dual clear counter because of that logic we've built into the setup and you will increment again it from 0 1 2 3 to 4 and so on and so forth so it's really easy to use the EEPROM at before as a similar format as the digital read or analog read digital write and analog write where you have if you're reading you simply read from a place in this case it is the address and the address will be the number of addresses are available on the EPROM chip so if you have 1024 possible addresses then you're going to need to nominate those between 0 and 1020 3 or 10 bit addresses so then we can take a look and we can just see that EEPROM rate is really really simple working through the address and we're giving the value to write much the same as digital right or analogue rate so that wraps up a prom and that concludes this chapter where we've taken a look at using arrays using operators bitwise logic and EEPROM and it's a shorter shorter chapter with fewer sections in it but there's a whole lot to cover and understanding all of these concepts can take a few different projects and using getting hands-on with the Arduino to use some of these concepts and functions so I encourage you to build some of your own projects using what we've worked here and we'll see you again at chapter 5
Info
Channel: Core Electronics
Views: 91,217
Rating: 4.8861208 out of 5
Keywords: arduino workshop, arduino eeprom, how to use arduino eeprom, arduino eeprom tutorial, what is arduino eeprom
Id: hH9WalIMaeM
Channel Id: undefined
Length: 8min 46sec (526 seconds)
Published: Sat Mar 11 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.