EEPROM on the Nano Flip and Making an Example Application
Introduction
The Nano Flip is based on the ATmega328P microcontroller, the same chip that powers the classic and popular Uno microcontroller development board. One of the built-in features of this chip is EEPROM (Electrically Erasable Programmable Read-Only Memory). EEPROM is non-volatile, meaning that the stored data is preserved even when the board is powered off. This makes it ideal for applications where data must survive resets, power outages, or battery swaps.
In this tutorial, we will:
- Explain what EEPROM is and how it works on the Nano Flip.
- Show a practical example using EEPROM to store a button press counter and displaying the results on an I2C connected LCD.
- Demonstrate how to expand the concept to other applications.
What is EEPROM?
EEPROM is a type of memory that allows small amounts of data to be stored permanently. Unlike RAM, which is cleared when the device loses power, EEPROM retains its values. On the ATmega328P, there are 1024 bytes (1 KB) of EEPROM available. This can hold:
- 1024 bytes
- 512 integers (2 bytes each)
- 256 longs or floats (4 bytes each)
This makes EEPROM useful for storing configuration settings, counters, calibration values, or user preferences.
Benefits of EEPROM
- Non-volatile storage: Keeps your data safe even if power is lost.
- Flexibility: Store any type of data in byte form, from single values to structured records.
- Reliability: Use functions like EEPROM.update() to reduce wear by only writing when the value changes.
Example Project Button Press Logger
In this example, we use a button connected to the Nano Flip to increment or decrement a counter. The counter is stored in EEPROM. The value is displayed on an I2C LCD using the PTSolns_I2CBackpack library.
Features
- Short press: Adds +1 to the counter.
- Long press (3s): Resets the counter to zero but keeps the current mode.
- LCD output: Shows the counter value.
Hardware Setup
For this setup we will use the NTEA-LG to connect all of the pieces together easily and quickly. The user can use a breadboard instead as well. We will also use the PTSolns I2C Backpack soldered onto a 1602 LCD (or a 2004 works equally well).
- Connect a button (any button will do) to digital pin D2 and ground pins on the NTEA-LG
- Connect the power pins and the I2C bus pins (SADA=A4, SCL=A5) of the I2C LCD to the NTEA-LG
- Sit the Nano Flip into the NTEA-LG (ensure proper orientiaton by confirming the labels)
Software Setup
Attached is an Arduino IDE sketch. Simply upload this to the Nano Flip. Ensure that you have the CH340 driver installed (one time setup).
Why Use EEPROM Here?
Normally, if you count button presses in RAM, the value would be lost if the board is reset or power is removed. By storing the value in EEPROM, the counter and mode persist. When the Nano Flip is powered back on, it continues where it left off.
Applications Beyond This Example
While this project shows a simple counter, EEPROM can be used for many applications:
- Storing configuration settings (e.g., Wi-Fi SSID and password on other boards)
- Saving user preferences (brightness, volume, mode selection)
- Logging sensor readings (limited by EEPROM write endurance)
- Calibration constants for sensors or actuators
- Maintaining runtime statistics (uptime, error counts, usage history)
Conclusion
EEPROM is a powerful feature of the ATmega328P that allows your Nano Flip projects to remember data across resets and power cycles. In this tutorial, we demonstrated how to use it for a button press logger, but the same approach can be extended to store any kind of persistent data.
If you are building projects where keeping data is important such as meters, loggers, or devices with adjustable settings, EEPROM is your go-to storage option.
Resources
- PTSolns website: https://ptsolns.com
- PTSolns Documentation Repository: https://docs.ptsolns.com
- PTSolns Newsletter: http://eepurl.com/hnESjL