Hot answers tagged

13 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 ...
Majenko's user avatar
  • 105k
12 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 ...
Majenko's user avatar
  • 105k
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 ...
Swedgin's user avatar
  • 241
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 ...
Peter Green's user avatar
10 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" ...
WestfW's user avatar
  • 116
10 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 ...
RSM's user avatar
  • 1,457
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 ...
Majenko's user avatar
  • 105k
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 ...
Majenko's user avatar
  • 105k
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 ...
Majenko's user avatar
  • 105k
8 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 ...
Majenko's user avatar
  • 105k
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 ...
IOB Toolkit Team's user avatar
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

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 ...
Edgar Bonet's user avatar
  • 42.3k
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,277
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, ...
Edgar Bonet's user avatar
  • 42.3k
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 ...
Edgar Bonet's user avatar
  • 42.3k
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
  • 42.3k
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 ...
Jot's user avatar
  • 3,216
6 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 ...
Edgar Bonet's user avatar
  • 42.3k
6 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, ...
JRobert's user avatar
  • 15.1k
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 ...
Majenko's user avatar
  • 105k
6 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 ...
Majenko's user avatar
  • 105k
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 ...
Majenko's user avatar
  • 105k
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 ...
stpaulchuck's user avatar
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 ...
DarthRubik's user avatar
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.
Ignacio Vazquez-Abrams's user avatar
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
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 ...
Nick Gammon's user avatar
  • 37.9k

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