Out of Memory on Mega, Have an extra uno, Combine?

I am out of Sram on my Mega, Yes I already used the F(marco) as much as I could. I also have used a little over 80% of the dynamic memory. I’m considering purchasing the Due, but am a little worried everything might not work at 3.3 Volts.

I have an extra uno laying around, am I’m curious if it’s possible to take the memory from the uno, and add it to the Mega somehow?

Any suggestions will be appreciated.
Thanks.

No it’s not. Although it’s possible to share the load I think it would be better to post your code (along with details of what it’s supposed to achieve). It’s likely that someone will see something obvious that can be rewritten more efficiently.

Are you using Strings?

Although it's possible to share the load

Excellent, so in theory if I get the due, I can use the due for the heavy lifting, and the mega for the shields and other fun stuff. Would that be through wire? Is there an example out there that shows how to share the load?

I am using a few strings (less than a dozen) for time stamping information and other stuff that I want saved to an sd card. Would it help to clear the strings String= ""; as soon as I write it to the sd card?

It would help to use char arrays instead of the String class.

Thomas499: I am using a few strings (less than a dozen) for time stamping information and other stuff that I want saved to an sd card. Would it help to clear the strings String= ""; as soon as I write it to the sd card?

I bet you don't have to use strings at all. I submit the only time you have to use a string is when you are sending data to some external device that demands one. I have only seen that a couple of times.

Here is the time stamp string

TS = String(year()) + "/" + String(month()) + "/" + String(day()) + "," + String(hour()) + ":" + String(minute()) + ":" + String(second()); That allows me to store the data in an excel sheet that looks like 1/29/2015 in the first cell, and 10:45:00 Pm in the second cell. Then in the third, forth, and fifth cell other data from sensors are stored.

So I should keep each as a char to save memory?

I'm very interested in figuring out how to make two arduinos share the load.

A simple example for sending time and data to CSV is here. By virtue of the type of file, the commas do the vital assignment to the cells. No string assembly is required, and no char either. The method for sending data to SD is essentially the same as that to serial and display.

 k=k+1;  

  if (k>9 )
  {  
           myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(hour);
  myFile.print(":");
  myFile.print(minute);
  myFile.print(":");
  myFile.print(second);
  myFile.print(",");

  myFile.print(InTemp);
  myFile.print(",");
  myFile.print(OutTemp);
  myFile.print(",");
  myFile.print(DrainTemp);
  myFile.print(",");
  myFile.print(diff);
  myFile.println();
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE     
      k=0;
  }

The only reason why you could possibly be interested in using two Arduinos is that you refuse to do a proper job using one and, in the unlikely event that you successfully bring a Uno into the game, the best memory increase you can expect is about 10%, which was probably never worth the effort. I rather suspect that, if you ever run out of memory with a Mega, you probably need to be using something other than an Arduino.

Thomas499: Excellent, so in theory if I get the due, I can use the due for the heavy lifting, and the mega for the shields and other fun stuff. Would that be through wire? Is there an example out there that shows how to share the load?

I wonder if a Raspberry PI (or a cheap laptop) would be a better companion for your Mega? Just use the Mega for the stuff an Arduino is good at.

...R

Thomas499: I have an extra uno laying around, am I'm curious if it's possible to take the memory from the uno, and add it to the Mega somehow?

Unfortunately not.

I must say I have no experience with it, but you can... apparently add ram to an mega2560 using a quadram - shield/module It should give you 512KB of RAM and a smaller one, mega-ram with 128KB is available as well.

The only reason why you could possibly be interested in using two Arduinos is that you refuse to do a proper job using one and, in the unlikely event that you successfully bring a Uno into the game, the best memory increase you can expect is about 10%, which was probably never worth the effort. I rather suspect that, if you ever run out of memory with a Mega, you probably need to be using something other than an Arduino.

Let me explain in more detail. I have plenty of memory left of the mega, I am just short on the sram memory. I've used, the F()macro as much as I can, but when it comes to using the aruino as a server, using the client.print(F()); results in everything not being printed because it takes to long to pull from whatever memory bank F uses. As a result, if you wanted a full page to show up, it stops at half page. So you can't use the F() macro, the same appears to apply for writing to an sd card.

So I was thinking trying it out with the uno, because I have an extra laying around, and if I can get a simple one boolean command to work i'll purchase the due, which I am confident will be more than adequate, So I can use the mega for the shields, and boolean calculations, then send the boolean results to the due, which the due will then work as the server. If I can get the due to work with a wi-fi shield that is. The due should add an additional noticeable amount of memory. Of course, I have no idea how to go by making them talk to each other to share the load.

What I really need is a super computer server, like the one Nick Gammon uses to host his video game. My resources are limited though, and I'd like to figure out how to do everything on an arduino before trying to learn how to program a sever though. With any luck i'll try to get my hands on one in the next two years.

I wonder if a Raspberry PI (or a cheap laptop) would be a better companion for your Mega? Just use the Mega for the stuff an Arduino is good at.

I've looked into getting a raspberry pi a little. I'm still getting use to arduino technology and the pi appears to be much more complicated. Do you ever use the pi? I'm curious how I would go by using a laptop to share the load with the arduino? That would be all the memory and processing power I would need.

I must say I have no experience with it, but you can... apparently add ram to an mega2560 using a quadram - shield/module It should give you 512KB of RAM and a smaller one, mega-ram with 128KB is available as well.

This seems like a possible fix as well. Has anyone used a shield like this before?

Are you certain you can't combine SRAM variables, or break things into subroutines and allocate the SRAM in a function? I have some pretty complex programs, and I don't use nearly all the SRAM available in my Mega 2560.

If you are willing to post your code, maybe someone will be able to help you use your SRAM more efficiently.

I don't think the variables are the issue, i think it's what I want printed.

Say for example I wanted "Grandma fell down the steps" printed on on the sd card, and on the webserver. The two booleans would be Steps = HIGH; and Grandma = HIGH; Those are the variables right? The sentence that I want printed seems to take up the memory, and I can't use the F()Macro because then it wouldn't print everything. I could probably include a lot of delays so that everything would print, but I really really don't like using delays.

The sentence that I want printed seems to take up the memory, and I can't use the F()Macro because then it wouldn't print everything.

Well, yes, it has to take up memory, there being no other place for it to be, but I don't understand your comment about it not printing everything.

Please post your code (the whole thing) if you want help on how to reduce it's sram usage. Otherwise we're all blindfolded in a sea of unknown code trying to play marco-polo with sram use

Re: memory expanders: I had no idea that the Mega could get it's memory expanded like that; that's really neat - it looks like it's got direct hardware support baked into the ATMEGA2560.

I don’t think the variables are the issue, i think it’s what I want printed.

Then I guess you are on your own. But I will give you a word of advice. Go through your global variables and see if there aren’t some arrays you could combine or allocate in functions.

Just as an example, I use one character array to print pretty much everything in my code. Normally I refer to this array as tBuffer or tBuf in each function, and print everything into it with sprintf or strcpy/strcat as much as practical. That way when the function exits (returns), that array memory is released.

Look at this example. It is one of my most complex sketches on the playground.
http://playground.arduino.cc/Code/WebServerST
Note how the arrays are allocated in the checkServer function. When that function exits, all that memory is released for use in the myStuff function, even though the myStuff function doesn’t do much of anything in that example sketch. It is there if you need it.

Thomas499: I've looked into getting a raspberry pi a little. I'm still getting use to arduino technology and the pi appears to be much more complicated. Do you ever use the pi? I'm curious how I would go by using a laptop to share the load with the arduino? That would be all the memory and processing power I would need.

You have not actually told us what your project is intended to do. The advice would be a lot more relevant if you tell us.

I assumed from Reply #2 that part of the project involves collecting data from sensors and another part of it involves sending that data somewhere to add to a database, or to display for a user. A cheap laptop would be ideal for the storage or presentation as it has no practical limits on the size of Strings or of data.

A RaspberryPI is just like a laptop without a screen, keyboard or power supply and on a very small circuit board. If you have to buy a screen, keyboard and power supply a small used laptop might be much the same price. The RaspberryPI uses the Linux operating system.

...R

I assumed from Reply #2 that part of the project involves collecting data from sensors and another part of it involves sending that data somewhere to add to a database, or to display for a user. A cheap laptop would be ideal for the storage or presentation as it has no practical limits on the size of Strings or of data.

A RaspberryPI is just like a laptop without a screen, keyboard or power supply and on a very small circuit board. If you have to buy a screen, keyboard and power supply a small used laptop might be much the same price. The RaspberryPI uses the Linux operating system.

Can anyone show me an example code that uses a lap top, or raspberry pi to do the storage or presentation?

Is there a way to tell the difference between needing more processing power, and needing more sram memory?

Thomas499: Is there a way to tell the difference between needing more processing power, and needing more sram memory?

Pop this function somewhere in your sketch

int get_free_memory()
{
 extern int __heap_start, *__brkval;
 int v;
 return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

Then at some strategic points in your sketch

Serial.print( F("Free memory ") );
Serial.println( get_free_memory() );

Thomas499: Can anyone show me an example code that uses a lap top, or raspberry pi to do the storage or presentation?

For that you probably need to try a Raspi or laptop forum, but I doubt that you will get much help since you are so secretive about what you want to do and the Arduino code you might already have.

I also assume from Reply #2 that part of the project involves collecting data from sensors and another part of it involves sending that data somewhere to add to a database, or to display for a user. This sounds pretty ordinary and is quite likely something done easily on an Arduino, just like thousands of others routinely do, but I guess nobody will ever know because you aren't telling - and there really isn't much point in guessing.

As for reply #17 you may find there is no need for more processing power, or more sram, you just need some sensible code.