Hot answers tagged

12 votes
Accepted

int VS uint8_t VS uint16_t

You can decipher most of them yourself. A u prefix means unsigned. The number is the number of bits used. There's 8 bits to the byte. The _t means it's a typedef. So a uint8_t is an unsigned 8 bit ...
  • 103k
12 votes

Same structure taking different memory space on Uno and NodeMCU ESP8266, leading to data corruption when transferring via nRF24L01+

int, long, etc have different sizes depended on the compiler and target. Use explicit sizes to make sure you're variables have the size you want. Eg. uint8_t, int16_t or int32_t, ... (as @Mat ...
  • 240
12 votes
Accepted

Same structure taking different memory space on Uno and NodeMCU ESP8266, leading to data corruption when transferring via nRF24L01+

There are three main issues you may need to deal with when passing structures between systems that use different processors. The first is that data types vary in size between architectures. You can ...
11 votes
Accepted

When to use PROGMEM?

Say you have a string of 1000 characters in Flash, and you want to print it to Serial. Yes, you need to load it into RAM in order to pass that data around the place for printing. But, do you need to ...
  • 103k
9 votes

What is using up all the RAM in my program?

There is a lot you are missing. Such as: SoftwareSerial is using RAM. The system stack is using RAM. The Arduino core software is using RAM. There's plenty more going on than just your sketch. For ...
  • 103k
9 votes
Accepted

Can you access the EEPROM of an ATtiny with Arduino Code?

The Arduino EEPROM library is compatible with the ATTiny range of AVR microcontrollers as the library itself is built on the standard Atmel AVR avr/eeprom.h 'library' so it is compatible with all the ...
  • 1,437
9 votes
Accepted

How much code can an Arduino board run?

There are several "Arduinos" with memory capacities ranging from slightly less than 32k/2k/16MHz (Flash/RAM/CPUClock) ("Uno") to 512k/96k/84MHz ("Due".) In addition, there are "mostly compatible" ...
  • 106
9 votes

Same structure taking different memory space on Uno and NodeMCU ESP8266, leading to data corruption when transferring via nRF24L01+

In addition to the rule of always using fixed and predictable sizes across different architectures, it's also a good idea to pack your structs. This prevents the compiler from padding smaller ...
  • 103k
8 votes
Accepted

Most memory efficient way to program

That is an incredibly hard question to give a definitive answer to. In general using OO consumes more memory, but that is the price you pay for greater flexibility and ease of use. The difference is ...
  • 103k
7 votes
Accepted

Simple memory chip for Arduino?

There is no DRAM, SRAM nor flash interface in ATmega, so you can't extend your chip memory. You can only connect serial (SPI, I2C) or parallel memory (usind GPIO). Neither SPI nor I2C require any ...
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 ...
  • 103k
7 votes
Accepted

How do string pointers work in Arduino?

String is not a simple type like an int or a char. It is a class with many member functions and, more importantly, operators. When you create the object it allocates room for that object either on ...
  • 103k
7 votes
Accepted

Does the compiled binary of a sketch include uncalled functions from a library?

In general only the functions actually used by your code are included in the final linkage of the binary. However it's not always possible for the compiler to know what is used and what isn't. In the ...
  • 103k
7 votes
Accepted

1 global variable consuming 19% of memory

A few things that count towards the “global variables” that you may not think of: all your literal strings, unless encapsulated within the F() macro; you have quite a few of them The Serial object, ...
  • 37.2k
6 votes
Accepted

Is the a low memory alternative to SoftwareSerial?

Simplest thing would probably be to edit your copy of SoftwareSerial.h and replace #define _SS_MAX_RX_BUFF 64 on line 42 by something smaller. If your loop() runs fast enough (no delays, no blocking ...
  • 37.2k
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 ...
  • 103k
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 ...
  • 37.2k
6 votes

CPU information on Arduino Serial Monitor

CPU temperature Some Arduino boards have a microcontroller with a temperature sensor inside. For example the Arduino Uno can measure the temperature inside the microcontroller. As far as I know, no ...
  • 3,107
6 votes

Spiffs vs Eeprom on esp8266

On the ESP8266 there's very little to choose from between the two. It all really boils down to what you want to store and how you best want to access it. EEPROM emulation is ideal for small bits of ...
  • 103k
6 votes

How can a function/method determine if a const array passed in is PROGMEM (flash) or not (RAM)?

I am afraid there is no good solution to this problem. One option I do like is to use the __flash qualifier instead of PROGMEM: const uint8_t ram_array[] = { 1, 2, 3, 4 }; __flash const uint8_t ...
  • 37.2k
6 votes

Not enough memory error using OneSheeld.h

Including the whole library, which is what you are doing, does not work on small boards like yours. Instead you have to only use the parts of the library that you need. Fortunately the OneSheeld ...
  • 103k
5 votes

Simple memory chip for Arduino?

Personally I like the Amtel 24C256 chip/module. It is I2C enabled and the standard Wire library is all you need to talk to it. It is 256 bits or 32K 8 bit bytes in size. Data is sent and read in byte ...
5 votes
Accepted

EEPROM - Storing Static Data

Some things I noticed in your code: You are writing everything to the same address (is that intentional?) You are only writing the first 6 six bytes of your arrays (I am pretty sure that is ...
5 votes

Simple memory chip for Arduino?

No. There is no external memory interface on the ATmega328P, so all external memory requires some sort of library to use.
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, ...
  • 103k
5 votes
Accepted

How to read main code inside main code in Arduino?

Interesting. If you want hex you have to tell it to print in hex. If I change your display line to: Serial.println(displayInt, HEX); Then I get: 940C 3594 35 C00 940C Compare this to what the ...
  • 35.3k
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= {...
5 votes

Memory chip for arduino

You can quite easily connect multiple 128kB SPI ram chips to an Arduino. 4 of them together would give you 512kB of extra SPI-connected SRAM. Access isn't super fast. Another option is to use a ...
  • 103k
5 votes
Accepted

How to find out the maximum used stack space?

Knowing the stack size is pretty easy: the stack pointer is initially set to RAMEND and goes down as the stack grows. Thus: static inline size_t stack_size() { return RAMEND - SP; } should I ...
  • 37.2k
5 votes

How to find out the maximum used stack space?

Initialize the entire SRAM space from the top of the heap to the bottom of the stack, either during setup, or in a modified version of the Arduino-provided main() function, with some unlikely pattern, ...
  • 14.5k

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