Extending Arduino Uno RAM

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I want to use this Arduino Uno to do some data logging around my house but with only 2k of ram memory I'm afraid I'm gonna run out of space and lose some data what to do well maybe with the help of this chip we can solve our problem so let's find out today on this episode of the newer versions of the Arduino Uno use an atmel 80 mega 328p 8-bit microcontroller well this microcontroller contains 2 kilobytes of RAM memory that is shared for program variables as well as data that you record for your application so it's a precious resource and you can run out of information or space to put your information very quickly so we can solve this situation by adding an additional Ram chip such as the one that's shown to my right on the vil Ross board it is an 8 pin microchip 23 LC 1024 memory chip that has a 128 kilobyte capacity and communicates with the Arduino Uno via the serial peripheral interface the second half of the solution for today's problem is a software program an example of which you can see behind me that will communicate to the RAM chip whenever we need to either read or write data from our program so first we will discuss how the hardware is wired then we will discuss the software program and at the end of that we'll see an example of how the program works so let's get started so let's talk about the hardware that we're going to using this solution for our problem to my right you can see on the vil Ross board there is a ram chip that's soldered on an Arduino proto shield that is mounted on an Arduino Uno board you can look at it and see the placement of the components and how its wired and how it's connected to the headers connecting the signal lines to the Arduino Uno immediately above me is a schematic and we'll go through that a little bit in detail so that you can see what's involved in actually wiring one up for yourself so the chip itself is eight pins pin one is the chip select pin it is the pin that will enable or disable the RAM chip from operation it is low true so when that chip select line is low the RAM chip will operate we can transfer data to and from it when it's high it will not transfer data it will just retain what's already there it is the chip select line that is connected to pin 10 in this case of the Arduino Uno pin 10 is just a digital output pin that we will bring low when we want to read or write and we will leave it high when we want to deactivate the chip the second pin on the RAM chip is the serial out that is the pin on the chip that will transmit the data out of the chip and to the Arduino Uno through the Uno's mi s o signal line on pin 12 Mis o stands for master in slave out on the serial peripheral interface the third pin that's of interest to us is pin six on the RAM chip it is the serial clock that synchronizes the data transfer to and from the serial Ram chip it is pin six on the RAM chip and it is also connected to pin 13 on the Arduino Uno now the last signal pin that we're going to talk about is the pin five of the RAM chip which is the serial data in or si on the RAM it's connected to the MOS I signal on the Arduino Uno which is pin 11 mo si is master out slave in so remember that for the serial peripheral interface on the uno pins eleven twelve and thirteen are the ones that are dedicated to the serial peripheral interface and any other digital output pin can be used for the chip select so in this case we've wired it to pin ten so the other pins the pin seven on the RAM chip and pin three on the RAM chip are two signal lines we're not using the pin 7 is a hold pin that will allow us to just stop data transfer exactly where it is which we're not going to use and then the other pin and you is not used but these pins need to be held high so that they don't inadvertently go low and turn the system off so what we will do is pull them high through to 10k pull-up resistors and that will solve that problem the last pull-up resistor that you can see is connected to the chip select line and even though the chip select is connected to a digital output on the uno there are times when an inadvertent high can happen and are inadvertent low can happen and turn the chip on when we don't want it to so that's discussed in the document that we link to in the description below and you can read it for yourself and see exactly in detail how the chip works so that's the hardware now let's discuss the software here you can see we've got a standard Arduino program in the Arduino IDE a copy of this program is linked in the description below so that you can download it at home and run it yourself but we'll go through it quickly and see what the program does there's some functions that actually communicate to the chip that I won't go into too much detail here it is discussed in a document that is linked to in the description below so here's the program at top of course we have some comments to tell you exactly what's going on the first thing we do is have to include the serial peripheral interface library so we can communicate with the chip and then we have a series of named constants that we define so that it's easier for us to communicate or with the program or to remember what we're doing in the program they're basically just names that are more meaningful for us than the numbers would be we have a read mode register and a write mode register that will we will write numbers too in those functions that will set the program to either read or write and then of course we've got a reset we've got read and write commands and actually to retrieve the data or to write the data and then we've got two modes that we will talk about today one is a byte mode where we will write an individual byte at a time and then the other one is a sequential mode where we will use a burst mode to write a series of bytes at one time to make it a little bit more efficient to communicate to the RAM chip itself now this section is not required for normal Arduino programs but I've included it here for clarity and it's more or less standard in other C compilers where you need to define things before you actually use them these are the five functions that are defined in this program to make it easy for to communicate to the RAM chip itself the first function called set mode will select either between the single byte mode or the sequential byte mode for us to communicate the information that we need in our program the next four functions are the functions that we will use to read and write the data to the RAM chip itself either in a read byte or a reader a write byte or writer a mode so you'll see how this all goes together here in the program shortly the next thing we need to create a little bit of data for us to use for the demonstration purposes I've got to reap two arrays to find the first array is an array called X and it basically just has the first twenty characters of the alphabet in it to use as data to write to the memory chip we have an empty twenty character array that is called read data and that's there to receive information in a sequential mode that we read from the RAM chip itself and then I've got a counter for a loop that we will be using in the next part of the program now for this demonstration we'll just use functions in the setup portion of the Arduino shell program we will not be using the loop portion in this we're just going to do things once and then end our program alright so what do we do in the setup portion the first thing we have to do is to create a variable to hold an address to which we will either write data to the RAM chip or read data from now this address is a 32-bit variable it has to be 32 bits because the address itself is actually 17 bits long now 17 bits is two bytes and one extra bit but since we don't have a three by tarea belen c language we'll have to go to a four byte variable and use the least significant 17 bits of that for our address now the functions know that and will transmit to the the chip itself the required part of that data to set up the address so we've got a 32 bit address we'll be using that every time we want to read or write something we have to tell it where to get that from and that's what that's all about I've got two variables here value and data that will either hold data to transmit to the chip or to receive the information coming from the chip and then we have to turn on our chip select which we already talked about it's pin 10 of the Arduino Uno we set it up as a digital output and we use the named variable CS to do that the next two things are basically for us to the serial peripheral are the serial begin we'll turn on the monitor for us to see what's going on and the SPI began we'll set up the serial peripheral interface for us to communicate to the gym so now we've got everything set up ready to go let's do four things in this program we will write five bytes to memory one byte at a time and then immediately read those back and then the next two parts of the program we will write a complete array at one time to memory and then read it right back so we're gonna do those four things and then we'll see how the both of the modes work so the first thing we'll print a prompt to the serial monitor so that we know where we are in the program and it says writing data bytes individually so this will write an individual byte to a specific address each time that we call it alright so the first thing we have to do is make sure that the mode of the chip is set so that it will receive one byte at a time or transmit 1 byte it's time so we call our set mode function that does that for us and we tell it to set it to byte mode so once that's done the chip is all set up for us to do it we can now start to write data to it one byte at a time now the basic process to writing anything to this chip for example let's talk about the bytes if you want to write a byte to the chip you will take the chip select line low to enable the chip so that it listens to us then we send it at address then after we send it the address we send it the byte of data and then we take the chip select high now that takes care of writing a byte to the memory chip if we want to read it it's the same thing we take the chip select low to enable to the chip we then tell it we want to read we send it the address we then get the information back and then we take the chip select high again to turn it off so those are the two things reading and writing that we will be doing so here's the writing part of it we take data I'm going to initialize the data to zero and then we will use a for loop to write the 5 bytes of data now I'm going to use the for loop counter as the address so when we enter the for loop we start with a loop counter of 0 we then go to address 0 in the memory chip and we tell it to write at address 0 data which is currently 0 okay so at memory address 0 it writes a 0 then we increment data by two so now its value is two the program increments I the loop counter to one so we set our address now to 1 and then we tell it to write at address 1 the data which is now 2 and then we continue that process until all 5 bytes of data or written to the memory chip so after that's done the next thing we do is immediately read back what we wrote so here's reading each device or each data byte individually that will be a prompt that shows up on the serial monitor and then we do the same process we set the mode to byte mode just to make sure that it's set for us and then we enter into a loop using the loop counter as the address that we want to read the data from and then we call the read byte function and we give it an address the read bite function will then tell the chip to go to that address which in the first iteration of the loop is 0 and it will return the value that's stored there and put it in the variable called value and then we just print that value out on the serial monitor so that we can see what's going on and we continue in that loop doing all 5 of those values which should be 0 2 4 6 8 and 10 now the next part of the program is where we begin to transmit data sequentially in burst mode so that we can write a complete array at a time so the first thing we do is we print a prompt to the screen the ethereal monitor to tell us where we are in the program then we set the bite mode to sequential so that the RAM chip now knows that we're going to be sending a starting address followed by a series of bytes and then we call the function right arrey now the right array function requires three pieces of information in order to do its job it needs a starting address in memory where we want to start writing the array we need the name of the array that we want to transfer to memory and we need to tell it how big the array is how many bytes of data we want to send that's all we have to include in our case we send it memory address zero because we want to start at memory address zero send it the array named X because that's got the first 20 characters of the alphabet in it and then we will send it 20 because that is the size of the array the number of characters that are contained in it so that will then take that full array right into memory and we will then immediately read it back from memory so we can see that what we did actually work so in order to keep our place in the program we print a prompt to the serial monitor telling us where we are then to be sure that we're set properly we set the mode to sequential so that it now knows for sure that it's going to be sending a lot of bytes at a time and then we make one function call to read array now read array needs three pieces of information also just like write array first of all it needs an address in RAM memory to start reading the information from in our case it's 0 that's where we wrote the array called X before then we need to have the name of an array in our program which is going to receive the data transmitted back from the memory chip and then we need to tell it how many bytes of memory we want to read back in this case it's 20 to match the size of the ray X that we wrote before now reading the array from memory doesn't tell us anything for sure it puts the program or the information in our program but in order for us to see it we need to get into a loop and use the serial print function for us to get the data from that array and display it in the serial monitor for us to actually see that it happened all right so the remainder of the program is the loop part of the program which we're not using so that's just an empty loop and then the following are the complete programs of the functions that we use in order to interface with the memory chip itself you can see that we've got the the set mode function defined first it's only four lines or four commands long but it will set the mode for us on the chip and then we've got the read byte function followed by the right byte function then we have the read array or right array function and then the read array function defined in the program so for privity sake to keep this video a little bit shorter I won't discuss these in detail they are described in detail in the document that we've got a link to in the description below so you can download that and read it to fully understand what's going on all right so that's our program to demonstrate the program I've already loaded it into the Arduino and brought up the monitor it's already run but to just demonstrate how it works I'm going to recompile and load it and then look at what's causing the output of the monitor so here we're compiling and loading you can see at the bottom here what's going on and now the program is run so to make our linkages to the program you can see that the very first prompt writing data bytes individually was printed there that's this part of the program where we went through the for loop to write five bytes of data and then we read the data immediately right back in this part of the program which is this prompt right there now when we read the data back using the for loop we read and printed this data which is 0 2 4 6 8 and 10 which is the loop counter incremented by 2 each time so the next part of the program where we write an array you can see that the prompt is writing and erase ik when chily which we do right here it is the one function call it writes to the array and it does not write anything to the serial monitor but we do that in the next part of the program where we read the array from memory and then we print it with a loop to the serial monitor which is right here so that is the functioning program you can see how to read and write data to the memory chip in either mode that you need to do for your program so with a little bit of wiring an 8 pin chip and some programming you can now significantly increase the memory capacity of your Arduino Uno [Music] [Music]
Info
Channel: Byte Me
Views: 26,449
Rating: 4.826087 out of 5
Keywords: Arduino, Arduino Uno, Serial RAM, Arduino RAM Expansion, More Arduino Uno RAM
Id: eIP_w5uizNw
Channel Id: undefined
Length: 24min 48sec (1488 seconds)
Published: Fri Aug 05 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.