Hot answers tagged

34 votes

How to read and write EEPROM in ESP8266

While EEPROM.read and EEPROM.write are valid methods, it's like mopping the floor with a toothbrush. Use EEPROM.put and EEPROM.get instead. For example: #include <EEPROM.h> void setup() { ...
user avatar
  • 441
20 votes

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

I have taken a look at the algorithm used by malloc(), from avr-libc, and there seems to be a few usage patterns that are safe from the point of view of heap fragmentation: 1. Allocate only long-...
user avatar
  • 36.9k
10 votes

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

I disagree with people who think you shouldn't use it or it is generally unnecessary. I believe it can be dangerous if you don't know the ins and outs of it, but it is useful. I do have cases where I ...
user avatar
9 votes
Accepted

Is it possible to run a binary from EEPROM?

Short answer: No; From the atmega328's data sheet (though it applies to all AVR's): AVR uses a Harvard architecture – with separate memories and buses for program and data. Instructions in the ...
user avatar
  • 4,309
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 ...
user avatar
  • 1,437
9 votes

EEPROM bytes preset to 255 while programming

In flash and eeprom memory an erased value is 255. It's all about how flash memory works. If you want something other than 255 in there you will have to write something other than 255 in there.
user avatar
  • 103k
8 votes

Run code once after programming

This is a X->Y problem. Here is a solution for X: Bit 3 of high fuse of the ATmega328p controls if EEPROM memory is preserved through the chip erase. You can change the high fuse setting in boards....
user avatar
  • 16.4k
7 votes

EEPROM endurance and page size

Testing a single byte write I ran some test code overnight to try to get to the bottom of this. Somewhat surprisingly perhaps, I got up to over 11 million writes before a read-back failed: Current ...
user avatar
  • 35.3k
7 votes
Accepted

Arduino digitalWrite 1 or 0 instead of HIGH or LOW

Yes, that is fine. LOW is 0 and HIGH is 1. digitalWrite() sets the output to off if it receives a 0 and on if it receives anything of 1 or more. That means that these are all equivalent: ...
user avatar
  • 103k
7 votes

How to increase life of EEPROM?

The other answer mentioned some general ideas; here are a couple of more-specific notes. • You can direct your writes of single bytes through a routine that reads the EEPROM cell before writing to it,...
user avatar
7 votes
Accepted

EEPROM.get returns bad data

You are saving a String object in EEPROM, which is useless. A string object does not store the contents of your string. Instead, it just stores: the memory address where the actual contents (the ...
user avatar
  • 36.9k
7 votes
Accepted

How can I read the data stored in EEPROM although is powered OFF based on the simple code I wrote?

increase is a global variable and will implicitly initialized with the value zero. Then you are reading the EEPROM data into the variable storagedata in setup(). And then in loop() you are increasing ...
user avatar
  • 13.9k
6 votes

How to remember variable values after rebooting an Arduino Uno R3 board?

The internal RAM of the Arduino will be reset when you repower the chip, so if you want to keep your data, you need to store it in EEPROM. If you are worried about the limited write/erase cycles, ...
user avatar
6 votes
Accepted

How can configuration values be stored on an ESP8266?

Thanks to Jaromanda X and Juraj for the SPIFFS recommendation. I was able to use this block of SPIFFS code as an example and safely store settings in my project outside of the compiled source. To ...
user avatar
  • 201
6 votes

Which EEPROM has a long lifecycle?

You can cycle through all the addresses in the EEPROM like a ring buffer. You'll need to reserve a bit so you can binary search for the head of the buffer during startup. You can also reduce how ...
user avatar
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 ...
user avatar
  • 103k
5 votes

Is it possible to run a binary from EEPROM?

No. The foundation of a Harvard architecture such as AVR is to only allow code that exists within program space to be executed, and EEPROM is not within program space. It is possible, however, to ...
user avatar
5 votes

How is stack memory used for fuctions and local variables?

The AVR (the microcontroller family traditionally used on Arduino boards) is a Harvard Architecture, meaning that executable code and variables are in two separate memories - in this case flash and ...
user avatar
  • 1,353
5 votes

How is stack memory used for fuctions and local variables?

Local variables and function parameters are stored on the stack. However, that is not a reason not to use them. Computers are designed to work that way. Stack memory is only in use while a function ...
user avatar
  • 5,509
5 votes
Accepted

How do you write to a free location on an external EEPROM?

The trick you are looking to implement here is the ability to look through the EEPROM and say "This is the last place I wrote to - I will write to the next place now." There's two ways of doing it, ...
user avatar
  • 103k
5 votes
Accepted

Most efficient way to store number in EEPROM?

My best off-the-top-of-my-head figure is 6 bytes. 4 bytes for the timestamp (assuming a 32-bit value). Two byte for -32768 to +32767. Multiply the temperature by 100 to make it into the integer ...
user avatar
  • 103k
5 votes
Accepted

What is the best way to get more RAM for a sound buffer?

A simple SPI SRAM chip. Available up to 128KB, such as the 23LC1024: http://www.microchip.com/wwwproducts/en/23LC1024
user avatar
  • 103k
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 ...
user avatar
5 votes

EEPROM put and get not working on ESP8266 (NodeMCU)

The ESP8266 doesn't have any EEPROM. Instead it emulates it using Flash. In order not to wear out your flash you have to "commit" changes to the flash once they have been queued for writing - ...
user avatar
  • 103k
5 votes
Accepted

How to increase life of EEPROM?

I can think of a few: don't power it on unless you have to; don't write to it unless you have to; write as little data to you as you can - compress the data; only write to it during brown out or ...
user avatar
  • 2,680
5 votes

EEPROM - Arduino

(1) How many locations are there in EEPROM? (For ARDUINO UNO & MEGA) Read the datasheet for the chip on the board. It tells you how many bytes or kilobytes the chip has for EEPROM. For instance ...
user avatar
  • 103k
5 votes

Is it possible to use extra AVR Flash memory as non-volatile EEPROM-like Flash memory storage?

Yes you can. This Arduino IDE add on lets you make calls to code store in the bootload of memory so you can make changes to the flash memory. https://majek.sh/en/writing-to-internal-flash-on-arduino/ ...
user avatar
  • 2,340
5 votes
Accepted

Is it possible to use extra AVR Flash memory as non-volatile EEPROM-like Flash memory storage?

The answer is "yes, you can use extra AVR Flash memory as non-volatile EEPROM-like Flash memory storage, very similar to an STM32 microcontroller." One of these days I'm going to write an Arduino ...
user avatar
5 votes
Accepted

Write faster on AT24C32

after writing a value to EEPROM, and terminating the I2C connection with a STOP, the EEPROM enters a self writing mode to write what you have sent to it, to it's internal memory. (you don't actually ...
user avatar

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