Memory problems - Seeking help - I think I need a Mega...

Hi guys,
I was new to the Arduino thing about 2 weeks ago, prior to that I hadn’t even heard of an Arduino.

Firstly, if this is posted in the wrong place, mods please move to the correct place.

By way of background Im restoring an old car and wanted a temporary logging system that would show live engine (EGT & rpm from W terminal on alternator via a PC817), GPS, outside temperature data on a display and log to an SD card.

After a lot of googling around and making a long story short, this is my setup:

  • Arduino R3
  • Nokia 5110 Display - SPI
  • Adafruit Ultimate GPS - SPI
  • Adafruit BMP280 Temp & pressure sensor - I2C
  • Adafruit MAX31850 Thermocouple amplifier - 1-Wire
  • DFRobot SD Card - SPI
  • PC817 octocoupler
  • power supply and Sparkfun 5V <–> 3V shifters

If I ignore the SD card logging function and remove SD.h from the sketch I can make everything work just as I want, i.e. collate the data from the sensors and display on the screen. Ive even managed to get a momentary switch wired in to change the display for 10s and revert back to the primary screen. Very happy!

Now, when I add SD.h into the equation I run straight out of memory (110%). Ive rationalised the code as much as my inexperience will allow.

To try and develop this further I created another sketch based on Jeremy Blum’s GPS logging tutorial (No 15). This gets the GPS data logging to the SD card. I can also include the BMP280 sensor and get that printing the data to the serial monitor and include my LCD5110_Basic.h. At this point I run into two problems:

  1. No more memory so cant include my remaining sensors
  2. The sketch won’t write to the card once I initialise the Nokia display - I think this is because Ive needed to share some pins between the SD card and the display (CS are different). I had to share them because I ran out of digital pins on the UNO.

As I see it, even though my sketch is a collection of bits that Ive cobbled together from others and then rationalised a little, I cant see how I can get enough memory to be able to write to the SD card - assuming I could get the shared (Nokia & SD Card) pin control sorted.

I know the Mega has more pins and more memory, so assume this would solve my problem by keeping the display and SD card on completely seperate pins and allowing me more programming space.

Any thoughts of words of wisdom from this newbie:)

I can supply code if needed but not sure what the protocol is!

Thanks
Jon

Do you know about the “F” trick with debug statements?

Serial.print(F(", motor # "));

When you text which isn’t changed by the program, you add the “F” like above and the text is placed in program memory instead of dynamic memory.

Read the “How to use this forum” post and learn about posting code. It seems like posting your code would be a good idea.

DuaneDegn: Do you know about the "F" trick with debug statements?

Serial.print(F(", motor # "));

When you text which isn't changed by the program, you add the "F" like above and the text is placed in program memory instead of dynamic memory.

Read the "How to use this forum" post and learn about posting code. It seems like posting your code would be a good idea.

Wow - Quick response, many thanks. Yes Ive done the "F" trick, that saved a lot of space.

I'll post the code that works (with the SD Card stuff commented out) separately.

Thanks. Jon

Further to the previous post, attached is my sketch - Couldn’t use the “Code” option as its longer than 9000 characters.

It currently (without the SD Card functionality) uses 29,038 bytes of program storage space and 66% of dynamic memory.

Simply adding SD.h takes the program storage space to 33,040 bytes (102%) and Global variables take up 1,971 (96%) of available space, this is before the SD code gets added.

Any and all advice welcomed:)

Thanks
Jon

LR_Logo.c (3.17 KB)

LCD5110_Basic_Bitmap.ino (11.2 KB)

Any thoughts on this people? Im not after help with the code, but a once over to see if I have any chance of squeezing everything into an UNO would be appreciated.

If its way too much then I'll order a Mega.

Thx J

Well, you could replace the GPS library with NeoGPS and save 285 bytes of RAM and some program space. It would also be faster and more reliable.

Because you want to use so many other devices, it would help if the GPS could run off the RX interrupts, not polling in loop(). NeoSWSerial et al can help there, and you could also delete the RX buffer (64 bytes RAM). SoftwareSerial is [u]terrible[/u] when you've got other interrupts to service -- it blocks during the receipt of every character. You will almost certainly need to use something else.

Also, the LCD library does not have print methods that take PROGMEM strings. Writing your own or modifying the library would save all the RAM used for the string literals like these:

[nobbc]       myGLCD.print("~C", 6*4, 0);
       myGLCD.print("m Altitude", RIGHT, 8);[/nobbc]

From a quick look at your INO, that might be 100 bytes more.

ACK! I see this library supports the dreaded String. I see you're not using it, but without examining a link map, I can't tell if String is being linked in. If it is, you could save 1600 bytes of program space and a little more RAM by deleting those methods and references.

Cheers, /dev