Skip to main content
9 votes

Sizeof variables and Due's RAM

sizeof doesn't return the number of elements. It returns the number of bytes. Since they are uint16_t arrays each element is 2 bytes - hence twice the size. The reason your last number is only 40928 ...
Majenko's user avatar
  • 105k
7 votes
Accepted

Executing machine code at runtime Uno

The microcontroller is executing one command at a time from..where? Flash memory directly. The AVR core can only execute instructions from Flash memory. It uses a two-bus system known as Harvard ...
Majenko's user avatar
  • 105k
7 votes

Serial printing from flash memory (F() macro, PROGMEM, sprintf_P, SPTR)

First, the freeMemory() function that you used from Adafruit was originated from a GitHub repository. I don't know about the __arm__ implementation, but for the AVR one, it is incomplete for handling ...
hcheung's user avatar
  • 1,416
6 votes
Accepted

Arduino constant vs Microchip PIC constant

const means different things in different contexts as far as storage goes. For a simple numeric value the compiler will generally replace the constant with the literal value. Any mathematics using ...
Majenko's user avatar
  • 105k
6 votes

Locally declared variable takes up global variable space in dynamic memory/SRAM

Isn't the space taken up by the local variable supposed to be freed up from the SRAM once the functions runs because I have declared the variable locally? This is correct. The local arrays you ...
Edgar Bonet's user avatar
  • 43.3k
5 votes

Is there any way I can connect the RAM of a computer to Arduino?

No, you can't connect your normal desktop computer memory to your Arduino. For a number of reasons: Computer memory (at least for the past 20 years) is DDR SDRAM. That's Synchronous Dynamic RAM. It ...
Majenko's user avatar
  • 105k
5 votes
Accepted

Does the StringObject.reserve() function prevent memory fragmentation/leaks?

Reserving space will help reduce memory fragmentation, but much of what else you are doing is swamping that small improvement you have made. The biggest area of concern is your cutString function, ...
Majenko's user avatar
  • 105k
5 votes

Locally declared variable takes up global variable space in dynamic memory/SRAM

You must declare the array in global space or static, and make sure the function you pass the buffer pointer to knows it is in PROGMEM. void send22() { static unsigned int irSignal[] PROGMEM= {...
ratchet freak's user avatar
5 votes
Accepted

Is there a way to add external RAM (let's say 100 MB or 200 MB) in this audio buffer mixing context?

There are SRAM ICs / boards, however, don't expect 100 MB, more like 1 MB (with the pin numbers and connectivity / protocols that an Arduino offers). With Flash you can get much further, but it can ...
Michel Keijzers's user avatar
5 votes
Accepted

Does the bootloader use some SRAM?

You did not specify what type of Arduino you are using. My answer is for the AVR-based ones. The bootloader does use RAM while it is running. However, once it handles control to your program, the ...
Edgar Bonet's user avatar
  • 43.3k
4 votes

Is using malloc() and free() a really bad idea on Arduino?

Is it a really bad idea to use malloc() and free() with Arduino? The short answer is yes. Below are the reasons why: It is all about understanding what an MPU is and how to program within the ...
Mikael Patel's user avatar
  • 7,979
4 votes

Confusion with storage of declared variables and volatile

That's just plain incorrect. The volatile keyword tells the compiler that the value of that variable may change at any time, and that therefore it must re-read the value every time you use it in your ...
Mark Smith's user avatar
  • 2,181
4 votes
Accepted

Which library to use for 23LC1024 SRAM 1 Mbit

SPI RAM has two modes of operation: single byte and "page mode". In single-byte mode you first send the read or write command followed by the (typically 3-byte) address and then read a byte. That's 5 ...
Majenko's user avatar
  • 105k
4 votes

Sizeof variables and Due's RAM

The sizeof operator's result is number of bytes, not number of array elements. Your arrays in the program above have two bytes per element, hence twice as many bytes as elements. If you want to ...
James Waldby - jwpat7's user avatar
4 votes

Can I make existing libraries use external SRAM for the Arduino

Making a library use external SRAM is not an easy task. It can be cone, but it takes quite a bit of work. The best start would be to abstract the SRAM into a library that provides simple access to it....
Majenko's user avatar
  • 105k
4 votes
Accepted

Is SRAM erased when putting Arduino into sleep_mode_pwr_down?

Generally, Atmega sleep modes do not erase RAM. Their memory is static and as long as voltage (above 2.7V I believe) is applied, data is held. However, this also depends on how you plan to wake up ...
mystery's user avatar
  • 321
3 votes
Accepted

Can I make existing libraries use external SRAM for the Arduino

What did programmers do back in the 80-ies when they run out of memory? There is an old technique called overlays. The same area of memory is used for different phases/steps of a program. Results are ...
Mikael Patel's user avatar
  • 7,979
3 votes

Which library to use for 23LC1024 SRAM 1 Mbit

This was an excellent challenge for an SPI bus manager and device driver support library I have been working on. Below are some performance results for the SRAM (23LC1024) device driver (Arduino Uno @ ...
Mikael Patel's user avatar
  • 7,979
3 votes
Accepted

Local variable usage in SRAM not counted

Why is the local variable not counted? Let us start with the function availableMemory(), what does it do? int availableMemory() { extern int __heap_start, *__brkval; int v; return (int) &...
Mikael Patel's user avatar
  • 7,979
3 votes

Inherent delay running EEPROM.read()

When I store it in the EEPROM, the extra time required to find it in EEPROM, pull it through the sketch, and then push it through to the db corrupts the data sourced from EEPROM and posts a jumbled ...
Majenko's user avatar
  • 105k
3 votes

Serial printing from flash memory (F() macro, PROGMEM, sprintf_P, SPTR)

explain in detail what exactly does each of the keywords F(), (PGM_P)F, PSTR, const PROGMEM. F() wraps the string literal in PSTR(...) and then casts it to __FlashStringHelper. This forces it to ...
Majenko's user avatar
  • 105k
3 votes
Accepted

Writing a 1Mb bitmap to an SDcard with only 96kB RAM

You can write the file in chunks. As suggested by ocrdu in a comment, writing line by line is a good strategy. In order to keep the complexity of the code manageable, I would put the logic of deciding ...
Edgar Bonet's user avatar
  • 43.3k
3 votes

How can i reduce my global variable use? Attiny85

FastLED needs to keep the colors of all the pixel in RAM, so that is using a lot of RAM. To get around this, you could use a strategy that generates the pixel data on the fly as you send it out to the ...
bigjosh's user avatar
  • 1,553
2 votes

How much can I recurse? How much can I recurse? How much ca!@#QFSD@$RFW

I had this exact same question as I was reading Jumping into C++ by Alex Allain, Ch 16: Recursion, p.230, so I ran some tests. TLDR; My Arduino Nano (ATmega328 mcu) can do 211 recursive function ...
Gabriel Staples's user avatar
2 votes
Accepted

Arduino Due SRAM

Size of int in arduino due is 4Bytes. If you're trying to create array of 32768 integers, it means you need 128kB of free space.
KIIV's user avatar
  • 4,752
2 votes
Accepted

Question about configuration EEPROM or Flash

Somehow let end users use the computer application to store the setup file they created into the Arduino's extended EEPROM (I will add a 64KB EEPROM for this). However I don't know if a computer ...
Majenko's user avatar
  • 105k
2 votes
Accepted

Resistors/capacitor used in connecting 23LC1024 SRAM 1 Mbit

It's better to use external pull-up resistor at least on CS. It's because MCU pins are configured as INPUTs without pull-ups just after the startup/restart before it gets into the setup(). Also I'd ...
KIIV's user avatar
  • 4,752
2 votes
Accepted

What shift register would I need for input OR output?

since you already have input, use an 74HC165 8-bit parallel-in/serial out shift register. They are cheap. another cheap option with I/O is an expander like the PCF8574, which are almost cheap
dandavis's user avatar
  • 1,037
2 votes

Current available SRAM?

If you set "Show verbose output during compilation" in your IDE preferences, you'll see a message like the following in the IDE window's lower pane. The part I bolded is the amount of SRAM assigned: ...
JRobert's user avatar
  • 15.3k
2 votes

Is it ok to declare variables inside timer interrupts?

The problem is i need more arrays like this... you probably want to take a look at your processing flow to see if you need all of them at the same time. if you do, well, there is no alternative but ...
dannyf's user avatar
  • 2,770

Only top scored, non community-wiki answers of a minimum length are eligible