methods to save RAM?

Hi,
compiling my sketch using two libraries results in a warning that less than 25% of RAM is free which might cause problems. I have a Mega2560 with 8 kB RAM. Using a controller with more RAM (e.g. Zero or Due) would pose a lot of hardware changes. Therefore I am looking for methods to save RAM.

Methods I see:

  • use local variables in functions -> less constant RAM but more RAM for the stack
  • no deep function calls -> less RAM for the stack
  • what else?
  • what about replacing classes and their instantiations by just defining the functions?

SupArdu

No Strings.
F() macro is your friend.

  • what about replacing classes and their instantiations by just defining the functions?

Unless you leave out variables or functionality, no savings.

SupArdu:
I have a Mega2560 with 8 kB RAM. Using a controller with more RAM (e.g. Zero or Due) would pose a lot of hardware changes.

How does this follow?

Unless you're dependent upon a library written in assembler, and, or has endian dependancies, better MCU's (faster clock and more RAM/ROM ) with Mega pin compatibilities/board size are available.

lloyddean:
How does this follow?

Unless you're dependent upon a library written in assembler, and, or has endian dependancies, better MCU's (faster clock and more RAM/ROM ) with Mega pin compatibilities/board size are available.

Mega and Due are NOT electrically compatible. The Mega operates at 5V, while the Due operates at 3.3V. Connect Due I/Os to any 5V peripherals, and you will irreparably damage the Due.
Regards,
Ray L.

Arduino/Atmel boards aren't the only Arduino API compatible devices on the market.

http://store.digilentinc.com/chipkit-max32-microcontroller-board-with-mega-r3-headers/

PIC32MX7xx
512KB Flash
128KB RAM
80 MHz operating speed
Four SPI and five I2C connectors
16 channel 10-bit ADC, five compare/PWM outputs
Dual CAN controllers
83 available I/O pins
3.3V operating voltage
16 analog inputs
Connects to a PC using a USB A to mini-B cable (not included)
USB 2.0 OTG controller
10/100 Ethernet MAC
User LED
Programmable with MPIDE
Also programmable with MPLAB IDE (with the addition of the PICkit3 in-system programmer/debugger)

5V Compatibility
The PIC32 microcontroller operates at 3.3V. The original Arduino boards operate at 5V, as do many Arduino shields.
There are two issues to consider when dealing with 5V compatibility for 3.3V logic. The first is protection of 3.3V inputs from damage caused by 5V signals. The second is whether the 3.3V output is high enough to be recognized as a logic high value by a 5V input.
The digital I/O pins on the PIC32 microcontroller are 5V tolerant. The analog capable I/O pins are not 5V tolerant. To provide 5V tolerance on those pins, the Max32 contains clamp diodes and current-limiting resistors to protect them from 5V input voltages.