In this tutorial, we will delve into the utilization of a config file on a Micro SD Card. The tutorial will cover the following aspects:
Saving a config.txt file on the Micro SD Card, which includes key-value pairs.
Reading the configuration from the Micro SD Card and storing it into an int variable.
Reading the configuration from the Micro SD Card and storing it into a float variable.
Reading the configuration from the Micro SD Card and storing it into a String variable.
This tutorial enables you to manage configuration settings through a file stored on the Micro SD Card, offering flexibility for various data types such as integers, floats, and strings.
This tutorial shows how to program the ESP32 using the Arduino language (C/C++) via the Arduino IDE. If you’d like to learn how to program the ESP32 with MicroPython, visit this ESP32 MicroPython - Read Config from SD Card tutorial.
Disclosure: Some of the links in this section are Amazon affiliate links, meaning we may earn a commission at no additional cost to you if you make a purchase through them. Additionally, some links direct you to products from our own brand, DIYables .
Introduction to Micro SD Card Module
Unfamiliar with Micro SD Card Module, including their pinouts, functionality, and programming? learn about them in the ESP32 - Micro SD Card tutorial.
How It Works
The key-value pairs are pre-stored on the Micro SD Card according to the following format:
Each key-value pair is on one line. In another word, each key-value pair is separated from others by a newline character
The key and value are separated by a = character
ESP32 code will search the key and find the corresponding value, and save the value to a variable. The variable type can be int, float, or String
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
If you use an Ethernet shield or any shield that has a Micro SD Card Holder, you do not need to use the Micro SD Card Module. You just need to insert the Micro SD Card to the Micro SD Card Holder on the shield.
The Serial Monitor shows the values from variables that is identical to the values saved on the micro SD Card
Now you can modify the code to add more variables.
※ NOTE THAT:
The above code does not care about the order of key-value pairs. It will search for the key from the beginning to the end of the file until the key is matched.
Video Tutorial
Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.
Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!