Arduino SRAM

My first post here. I just bought myself an arduino duemilnova and I have a couple of basic questions that I need to get of my chest.

Firstly, my arduino has 2kB of SRAM and I am currently developing an application where I need to monitor windspeed and wind direction. I am planning to sample the conditions every 3 seconds and send them to the PC once every 10 minutes. I want to store the samples on the arduino. initially I was looking at the EEPROM as it had some nice functions which seemed to make it easy, but with the limited 100,000 writes I thought it better to use the SRAM.

Anyway my question is, how do I access the SRAM. I couldn’t get much help online. Initially I though there would be functions but now I am thinking that any variable would occupy some RAM and that by initializing an array I could hold the values. WOuld it be correct to say that this will use some of the 2kB of SRAM?
Also is there a way of keeping a track of how much RAM is being used? as I wont have the full 2kB free to hold the sampled data if the program uses some of it?

One final (silly) question. The arduino is programmed in C? If the libraries for EEPROM and serial port etc are utililized is this still considered to be programming in C?

Many thanks for any help

You can store each sample in two byte assuming that your wind speed values are not higher than 255 and you are happy with direction to the nearest 2 degrees (your measurements are unlikely to be more accurate then this anyway).

So 20 sample per minute for ten minutes is 400 bytes of RAM, leaving plenty for the rest of your code.

You can have an array values as follows:

byte speed[200];
byte direction[200];

and use a counter to fill up the array. if the counter starts at 0 then when it gets to 199 you can send the data to your computer and reset the counter to start over.

Not sure if matters, but yes, you are still programming in the C languge (actually its a subset of C++) when using libraries.

As I understand it, the program itself is stored in FLASH memory, giving the whole 2K of SRAM to store variables. Looks like MEM has done the math, and the 2K should be enough for you.

You can also store variables in FLASH, but it seems to be an advanced topic.

giving the whole 2K of SRAM to store variables

Just to clarify: The stack is also in SRAM so most of the 2K is available for variables but not all of it.

  • Brian

Thank you all for the replies and clearing a few things up.

One thing, if for example I am doing something more complicated like doing some formula, does the arduino use the RAM to store intermediate results (for example if I have to do ((a+b)/(c+d))) would it store lets say a+b in RAM once calculated while it is calculating c+d?) What I am getting at is, would these types of operations use more RAM or would they be independent.

Its just that, as well as storing wind speed and direction, I need to write code to measure temperature, pressure, rainfall and humidity. I was just a bit worried that possibly I may run out of resources on the Arduino when I finally put everythimg together.

Thanks again.

does the arduino use the RAM to store intermediate results

The formula would have to be very long and very complex. Most intermediate results are stored in registers (the processor has lots) and, with very few exceptions, the compiler generates code that reduces the number of intermediate values. When the equation you posted is evaluated, no SRAM is used; only registers.

What I am getting at is, would these types of operations use more RAM

Very very rarely.

  • Brian

Thank you very much for the answers. Things are much clearer now