Sometimes I run out of space of the program size for the embedded C program that I want to put on an arduino. So what chip do I need to expand the program memory of the arduino so that I can use bigger C programs with my arduino?
-
1Considering that a fellow by the name of Petri Häkkinen put an arcade-style game on an Atmega328P, maybe you should look at saving space in your code? If that isn't practical, as some of the answers say, you can get a bigger chip with more program memory. The Atmega644, for example, comes in a DIP-chip package, amongst others.– Nick Gammon ♦Commented Aug 28, 2016 at 7:05
-
See also forum.arduino.cc/index.php?topic=226465.0– Mikael PatelCommented Aug 28, 2016 at 7:29
-
can you please explain a bit more your answer ? 2) The Arduino has SPI, so an SD card can be accessed. Any code on the SD card would need to be loaded into executable memory. This is complicated and not for beginners... You mean that you can change or re-program de instruction memory while the program is running ? Can the running program call the bootloader and load new instructions on a different addresses ? Won´t this age the program memory ? A different solution may be identify rutines in your program and all the "call´s" stored whith the data on a spi external memory... Thanks !– DiegoJRCommented Nov 3, 2019 at 12:22
5 Answers
An ATmega2560 is the chip to add for more memory when you run out of program memory on an Uno. Referring to the Memory webpage at arduino.cc, you'll see that it has Flash=256KB, SRAM=8KB, EEPROM=4KB, where the ATmega328 chip on the Uno has Flash=32KB, SRAM=2KB, EEPROM=1KB.
When you run out of program memory on an Uno, you have about three choices that are practical: make the program smaller; remove the bootloader (to free up one or two KB); use a different board with a more-capable processor. The CPU on an Uno board doesn't have a way to access program bytes from places other than the on-chip 32KB flash. The CPU on a Mega2560 board starts out with 8 times as much flash, so it can hold bigger programs than an Uno can.
If you remove the bootloader, you could instead program using a USBASP board, as described in a “Program AVR chip using a USBASP with 10 pin cable” article at learningaboutelectronics.com.
-
but if you free up the bootloader then how would i use the arduino IDE to program? Commented Aug 28, 2016 at 5:17
-
@qwerty10, see last paragraph of edit. Arduino IDE supports USBASP ok. Commented Aug 28, 2016 at 5:21
-
Wouldnt it work with any programmer that can upload code to ATMEGA? Instead of only a USBASP. As I understand it itns not actually using 10 pins but a subset of those pins. Commented Aug 28, 2016 at 5:26
-
4Current Unos use the very compact optiboot bootloader. Removing it will only free 512 bytes. Commented Aug 28, 2016 at 6:33
-
1@qwerty10: There are versions of the USBASP with a 6 pin connector. The 10 pin connector has 4 redundant pins. Commented Aug 28, 2016 at 6:35
Another way (other than MCU with more memory) is not using Arduino framework and its libraries. Such level of abstraction is expensive in both ways - memory usage and speed. But that's much harder way. If you need some library, you have to port it (if you haven't found native one) or at least provide required functions from Arduino.
For example in Arduino IDE 1.6.11 empty sketch is using up 444 Bytes of flash. Using one pinMode
and digitalWrite(13, ! digitalRead(13));
+ delay(500);
means 964 Bytes. Of course, these are most likely one-timers. If you use six more pins and toggle it, it uses much less program memory than using first one (1192B). But it still grows really fast.
In pure C empty program is about 134 Bytes long. Same functionality (toggling one pin every 500ms) takes 158 Bytes (and it's way faster).
But for hobby project i would go for ATMega2560 or ATMega644/1284 instead.
And you can use direct access to hardware too. Toggle pin sketch with using registers directly and _delay_ms from avr libraries uses 468 Bytes instead of 964B. With delay from Arduino core libraries it's 602B.
-
1
-
1This has the added benefit of actually learning about the mcu that you're using. The AVRs on these Arduinos are much more capable than the "standard library" would have you believe. ++ Commented Aug 29, 2016 at 1:40
When asking a broad question, it is helpful to include some details. Like how much memory you need and why you think you need it.
I once specified a processor at 2 KB program space, 64 bytes RAM and 1 KIPS. The engineer asked, "MIPS?", and I explained thousands per second. He replied, "They don't come that slow". At the end of the project, a huge UI was added and memory got tight... but it still fit with no problem.
So, consider being more thoughtful about the resources being used.
To answer the question:
The Arduino does not provide a convenient bus to fetch memory over. So, there is no way to plug in a chip to get more memory.
The Arduino has SPI, so an SD card can be accessed. Any code on the SD card would need to be loaded into executable memory. This is complicated and not for beginners...
As suggested, tighten up you code. This is probably a good way to learn.
Move to a larger Arduino.
There are different Arduino processors. Some in the ACR line, others in the ARM line. Going to a different device in the same family is a relatively modest change and can provide up to 368 Bytes of program FLASH. But these are not Arduino boards exactly.
The Arduino ARM based devices are very different and use different libraries.
Check out the Arduino Mega 2560 it is very similar to the Uno, has a similar footprint, code should port relatively easily and is inexpensive.
There are also larger devices in the AVR family.
Note, the AVR32 is a different processor and the peripherals are enough different that it is a different device.
If you want to get into very large programs (gigabytes of memory) check out the Beagleboard. It has a full linux, with virtual memory (see #2 above) and has more powerful I/O mechanisms.
-
Perhaps fix some typos, like Wen, 3, and differnt Commented Oct 3, 2017 at 16:26
-
I mean, if you fix those typos, someone might vote up your answer... Commented Jan 11, 2019 at 3:10
What about a raspberry pi zero? I have a couple and use them quite often as arduinos.
-
Other architectures should indeed be considered, but an embedded linux system with mandatory SD card booting like the pi adds a lot of complexity and is fragile in unique ways, even if not more expensive. There are a lot of boards based on smaller, more highly intergrated ARM MCUs which are much more similar to an Arduino in terms of applications, while being drastically more capable. But if you need a lot of processing, or megabytes of memory, then yes, these complexities start to be worthwhile. Commented Aug 28, 2016 at 14:28
-
I also prefer the zero because it is so flexible. You can add more storage or embed it in projects while also having a large enough processor to do pretty much anything.– dalearnCommented Aug 28, 2016 at 20:28
You could also look into other platforms. For instance, a Teensy 3.2 is Arduino compatible and has a 2KB eeprom and 64KB of RAM.