EEPROM Memory - Store Anything - Arduino101

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to another episode of the arduino 101 series remember that in this video series we are going topic by topic into more depth of the arduino programming arduino coding can be quite easy but when you get into timers registers internal hardware and c programming that could get a bit difficult and that's what we are learning in this video series today's topic is the eeprom memory what is it how to use it how to write large values on multiple memory addresses and so on so guys let's get started [Music] these pcbs were manufactured by pcb way and the finish quality is very good especially with these gold-plated pads if you want to finish your product faster you could also ask pcbway to make a panelized order where you receive multiple pcbs on a single panel together with this you can also order the smd stencil from pcbway and use it to add solder paste and then solder all the components at once and by that you save time and effort all the orders are high quality and you could select a lot of settings such as the thickness flexible pcbs the color of the solder mask the amount of layers the material the surface finish and more so upload the gerber files directly on pcbway.com and make the order in just a couple of minutes what's up my friends welcome back this here is the arduino uno and remember that this board is using the atmega328 microcontroller inside a microcontroller at the microscopic level we have sometimes a cpu maybe the adc converters or the dac converters we have oscillators serial buses and so on but we also have memory usually we have three types of memory sram flash and eeprom the arduino uno and the nano which are using that mega 328 have 1024 bytes of apron memory but the arduino mega for example on the other side has 4096 bytes so different microcontrollers could have a different amount of memory but what is the eeprom memory anyway well it stands for electrically erasable programmable read-only memory and yeah that's a long name so why do we have to mention that it's electrically erasable since any memory could be raised right well that's because we first have the eprom which was kind of the same but you had to put a chip below uv light in order to erase it and then put it back on the board but the eeprom can be erased using electrical signals to store the data this memory is using a lot of mosfet transistors so each transistor can store a one or a zero which is basic binary actually for each beat the eeprom needs two transistors and 8 bits will create a byte so for 1024 bytes we need more or less 16 384 transistors which is not that much if you think about it for example this is a cross-section of the e-bra mosfet this transistor also has a floating gate so this is how we store a 1 or a 0. to program it we apply a positive at the gate so the charge will go upwards filling the floating gate at the same time but since we have insulators the charge will stay here and that represents a one but on the other side to erase it we place zero volts at the gate so that charge will go away and no charge represents a zero usually eeprom memories have a nice currency or maybe an sp communication in order to get the data in or out but that is for external memories for example this rtc module here also has this ic and this is an external eeprom memory the at24c32 but the arduino microcontroller already has such a memory inside it and we can use it very easy so we could imagine this memory as a string of data where each cell is one byte or eight bits to write something we have to send the address of that cell and the value that we want to write but to read something we only have to send the address and it will give us the value these addresses will go from 0 to 1023 for the arduino uno as you can see we can only write one byte at a time with binary values which will go from this to this so basically we can store a number from 0 to 255 on each cell the datasheet of the microcontroller tells us that the lifespan of these memory cells could be of around 100 000 read writes and it will take around 3.3 milliseconds to write the data to the cell and i know that sounds fast but this is actually a very slow memory compared to others also by default the cell has a data of a full byte which is 255 in decimal okay so now connect your arduino to your pc and let's see how to use the eeprom memory with the arduino for that we need to import the eeprom library using this line in the code this library will have these functions but let's start with the eprom.read inside of the parentheses we have to mention the address of the memory cell that we want to read from 0 to 1023 for this example i make these lines and i equal this brightness variable to the eprom.read and the address 0. and then i print that value to the monitor i connect my arduino and upload the code i run the monitor and as you can see i read 255 because that is the default value of a new memory but now let's use the eprom.write function to change the value on position 0. so this time between the parentheses we must add first the address and then the value and remember very important the value must be between 0 and 255 because each address represents a cell of 8 bits so we can't write higher values than that if you try to write for example the value 300 it will have an overflow and it will actually write 300 minus 255 so it will write 45 instead of 300. anyway i type this line of code and i place it here in the void setup in order to only run it once e prime dot right 0 for the address and let's say 25 for the value and then in the void loop i use once again the eprom.read to get the value on position 0. so upload the code and run the monitor and as you can see this time we'll read 25 instead of 255 so we have successfully write something to the memory and also read it but this is the interesting part i disconnect the arduino from the usb so everything is powered off but i connect it back and run the monitor once again and the value is still there that's why we use this memory in order to store the values that we need every time the arduino is unplugged we can store a value basically forever for example with my portable soldering iron project the user was able to change the default temperature so you must store that on the eeprom memory because otherwise each time the user will turn off the iron the valve will go back to its initial state also for my homemade esc i was also storing the configuration on the eeprom memory in order to use it anytime and these are just a few examples where you could use the eeprom memory and you can also use these other functions as you can see here for example the eeprom.clear will empty the entire memory with the eprom.update we can update a value only if that value is different and like that we can increase the memory life okay so now we know the basics on how to write and read from the arduino eeprom but is it possible to write an integer or a fault value to this memory because those variables will occupy two bytes or four bytes but we can only write one at a time so for that we use these functions the eeprom.put or get let's start with the eprom.get inside of the parentheses we must place the address where the data will start and the second part is the data variable where we want to store the received value so if this variable is an integer type this function will automatically know to read two bytes instead of just one byte but if this variable is defined as a float it will read 4 bytes and so on so you don't have to care about the data length so i create an integer variable and i name it brightness for example and then let's imagine that previously using the eprom.put function we have written the value 828 starting on address 0. so now i use the function eprom.get and for the address i add a 0 and for the data i write the brightness variable that i've created before so this function will read two bytes starting from address zero and store the received data inside of the brightness variable so if i run this program as you can see the brightness data is now 828 so we have successfully read the data which in this case is an integer and occupies two bytes but in the same way we write data of more than one byte but we use eprom.put inside of the parenthesis we first write the starting address and then the value to write for example i create a float value and i give it the name sensor read and i equal it to 70 000. now i write that value on address 0 using the eprom.put now once again i use the eprom.get function and add the address 0 and the flow type variable named brightness i run this code and now i read 70 000 which is a flow type and occupies 4 bytes and the same will work in the case of a decimal point variable such as this one here for example i can also write a value of 56.7 if i want the function will automatically detect that for me because it knows that i'm working with a float variable as you can see this time i read the float number so it's very important to correctly define the variable before you run the function we can also write a string of characters for example i create a string variable and equal it to this text i write it on the address 22 for example and then using this code i can read the text from the memory for more examples in the arduino ide you can go to file examples eeprom and read all these example codes you can also find a tutorial on electrodes.com with text code bits and more explanation also if you don't want to use the eprom.put or get functions you can create your own functions something like this i found this example online and these functions are called eprom write anything or read anything basically it will first measure the length of the data that you want to write or read and then it uses a normal eprom.read or write function in order to get or write a longer data than just one byte you can get this code from below and test it out also remember that you can always buy an e-pro memory ic in order to have more external memory since 1024 bytes is not that much but this memory is very useful and i use it in pretty much all my projects i hope that you now know what is the eeprom memory and how to use it with the arduino if you have learned something new give me a like or comment below thanks again and see you later guys hey guys so that was the video for this week i hope that you like it and as always the most important part for me is that you have learned something new and i would like to thank you to all of you who are supporting me on patreon because that for me is huge and by the way if you would like to support my project you have all my links below for this patreon page for my social media for my shop and so on so thanks again and see you later guys
Info
Channel: Electronoobs
Views: 101,611
Rating: undefined out of 5
Keywords: EEPROM, write, anything, Arduino, byte, int, float, read, tutorial, how to, class, memory, store, basic, i2c, SPI
Id: Sus96TzvjT4
Channel Id: undefined
Length: 13min 15sec (795 seconds)
Published: Sun Mar 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.