members
Basics: Project 076a ESP32 Development board - Flash Memory
of Acoptex.com in ESP8266 ESP-32
Basics: Project 076a
Project name: ESP32 Development board - Flash Memory
Tags: EESP32 Dev Module, ESP32 development board, ESP32 Development board with WiFi and Bluetooth, ESP32-DevKitC V4 development board, ESP-WROOM-32 module with ESP32‑D0WDQ6 chip, Espressif Systems, ESP32-based development board, ESP32 modules, ESP32-WROOM-32, ESP32-WROOM-32U, ESP32-WROOM-32D, ESP32-SOLO-1, USB-UART bridge, IOT, ESP-WROOM-32 Dev Module, ESP32 DEVKITV1, Installing the ESP32 Board in Arduino IDE, Uploading sketch, ESP32 Development board, Store Permanent Data,Write,Read,Flash Memory
Attachments: sketch
In this project, you need these parts :
1. ESP32 development board with WiFi and Bluetooth and USB A / micro USB B cable 1 pc
2. Arduino IDE ( you can download it from here )
3.Jumper cables F-M, M-M
4. Resistor 2 pcs (220 Ohm-1 pc and 10 KOhm-1 pc)
5.LED 1 pc (can be of different color)
6. Breadboard 1 pc
7. Momentary switch (Pushbutton) 1 pc
General
We will learn how to store and read values from the ESP32 development board flash memory using Arduino IDE.
The data saved in the flash memory remains there even when the ESP32 development board resets or when power is removed. In this project we will show you how to save the last GPIO state.
The flash memory is very similar to the EEPROM. Both are non-volatile memories.
Saving data in the flash memory is specially useful to:
- remember the last state of a variable;
- save settings;
- save how many times an appliance was activated;
- or any other type of data that you need to have saved permanently.
One limitation with flash memory is the number of times you can write data to it. Data can be read from flash as many times as you want, but most devices are designed for about 100,000 to 1,000,000 write operations.
With the ESP32 development board and the EEPROM library you can use up to 512 bytes in the flash memory. This means you have 512 different addresses, and you can save a value between 0 and 255 in each address position.
To show you how to save data in the ESP32 development board flash memory, we will save the last state of an output, for example the LED. If you normally use it and it is switched on but suddenly ESP32 development board will loose the power. When the power comes back, the LED will stay off as it doesn’t keep the last state.
We don’t want this to happen. If we want the ESP32 development board to remember what was happening before losing power and return to the last state, we need to save the LED's state in the flash memory. Then you need to add a condition at the beginning of your sketch to check the last LED state and turn the LED on or off accordingly.
Understanding the ESP32 Development board with WiFi and Bluetooth
You can read more about it here.
Signals and connections of the ESP32 Development board with WiFi and Bluetooth
You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board (made by Espresiff Systems) by pressing Getting started link close to each board here.
Let's check our development board - ESP32 DEVKITV1with ESP-WROOM-32 module from Espressif Systems:
Pinout diagram for the ESP Wroom 32 breakout:
ESP32-WROOM-32 - ESP32-WROOM-32 module soldered to the development board. Optionally ESP32-WROOM-32D, ESP32-WROOM-32U or ESP32-SOLO-1 module may be soldered instead of the ESP32-WROOM-32.
USB-UART Bridge - A single chip USB-UART bridge provides up to 3 Mbps transfers rates.
BOOT button - Download button: holding down the Boot button and pressing the EN button initiates the firmware download mode. Then user can download firmware through the serial port.
EN button - Reset button: pressing this button resets the system.
Micro USB Port - USB interface. It functions as the power supply for the board and the communication interface between PC and the ESP module.
TX0, TX2 - transmit pin. GPIO pin
RX0, RX2 - receive pin. GPIO pin
3V3 (or 3V or 3.3V) - power supply pin (3-3.6V).
GND - ground pin.
EN - Chip enable. Keep it on high (3.3V) for normal operation.
Vin - External power supply 5VDC.
Wiring
The ESP32 is currently being integrated with the Arduino IDE like it was done for the ESP8266. There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language.
1. Installing ESP32 add-on in the Arduino IDE (Windows 10 OS)
- Download and install the latest Arduino IDE Windows Installer from arduino.cc
- Download and install Git and Git GUI from git-scm.com
- Search for Git GUI, right-click the icon and select “Run as administrator“
- Select the Clone Existing Repository option.
- Select source and destination. Source Location: https://github.com/espressif/arduino-esp32.git
- Target Directory:C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32
- Do not create the espressif/esp32 folders, because they will be created automatically.
- Click Clone to start cloning the repository.Wait a few seconds while the repository is being cloned.
- Open the folder: C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32/tools
- Right-click the get.exe file and select “Run as administrator“.
- You will see that necessary files will be downloaded and upzipped. It will take some time.
- When get.exe finishes, you should see the following files in the directory.
2. Uploading files
- Do wiring.
- Plug the ESP32 development board to your PC and wait for the drivers to install (or install manually any that might be required).
- Open Boards manager. Go to Tools -> Board -> Boards Manager… (in our case it’s the DOIT ESP32 DEVKIT V1)
- Select COM port that the board is attached to (if you don’t see the COM Port in your Arduino IDE, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers)
- Compile sketch and upload it to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
- Press the ESP32 on-board EN button to reboot it.
- Open the Serial Monitor at a baud rate of 115200.
- When your ESP32 development board restarts press the momentary switch to turn the LED on and off. The ESP32 development board should keep the last LED state after resetting or removing power.
Code
EEPROM library:
To write data to the flash memory, use the EEPROM.write() function that accepts as arguments the location or address where you want to save the data, and the value (a byte variable) which you want to save: EEPROM.write(address, value); For example, to write 4 on address 1, you’ll have:
EEPROM.write(1, 4);
EEPROM.commit();//for the changes to take effect
To read a byte from the flash memory use the EEPROM.read() function. This function takes the address of the byte you want to read as an argument: EEPROM.read(address); For example, to read the byte stored previously in address 1, use:
EEPROM.read(1);
This would return 4, which is the value we stored in address 1.
project sketch:
First we need to include the EEPROM library. Then we define the EEPROM size. This is the number of bytes we want to access in the flash memory. In this project, we’ll just save the LED state, so the EEPROM size is set to 1. We also define other variables that are required for project to work. In the setup() we initialize the EEPROM with the predefined size. To make sure that the code initializes with the latest LED state in the setup() we should read the last LED state from the flash memory. It is stored on address 0. Then we just need to turn the LED ON or OFF accordingly to the value read from the flash memory. The loop() checks if the pushbutton was pressed and changes the ledState variable every time we press the pushbutton. To make sure we don’t get false positives we use a timer.
We simply need to save the LED state in the flash memory every time the LED state changes.
We check if the state of the GPIO is different from the ledState variable. If yes, we’ll change the LED state using the digitalWrite() function. After that we save the current state in the flash memory using EEPROM.write() and pass as arguments the address position, in this case 0, and the value to be saved, in this case the ledState variable. And we use the EEPROM.commit() for the changes to take effect.
Summary
We have learnt how to store and read values from the ESP32 development board flash memory using Arduino IDE.
Libraries
- EEPROM library included in Arduino IDE
Sketch
- See attachments on the begining of this project
Other projects of Acoptex.com










jobs.viewed