Everything: ESP32
this post will be updated progressively.
basically this post is a kind of a living notebook for everything about ESP32 (which i learn) — it could include how to, setup, trick, errors (if any), that small minor and easily forget-able things, also maybe some minor details which i think interesting.
this note might not be a perfect guide but a collection of observation which i happen to stumble upon.
so... this is an ESP32

a very cute little piece of silicon that somehow ended up inside a surprising number of things around the world. Drones, vacuum robots, smart fridges, IoT gadgets, random smart lights… chances are high that at least one device near you right now has an ESP32 quietly running inside it.
it’s tiny, cheap, powerful enough for most embedded experiments, and somehow still manages to include Wi-Fi and Bluetooth. Which means it’s basically a playground for anyone who likes building things.
i'm actually more of a raspberry person but, i hold zero anything toward ESP32 and kinda like it tho.
this page will slowly collect notes about:
- how to set it up
- useful tricks
- debugging weird problems
- power optimization
- networking
- random experiments
whenever something interesting shows up, it goes here.
first thing first, how to interact with ESP32?
mainly i used and really prefer a tool called esptool the script is made with python and offer pretty much complete features to interact with the ESP32.
to install it simply run one of the below command:pip install esptool (if run from virtual environment or willing to break system packages)pipx install esptool (if don't want to use virtual environment while at the same time doesn't break the system packages)
below is the help page of esptool

after looking into the tools next question arises.. how to interact properly with the ESP32, as the ESP32 is actually unplugged and not running, how to actually interact with it using esptool?
just plug the ESP32 to a laptop or any power source but to interact with esptool it is recommended to plug it into laptop or PC so it can be programmed (make sure the USB cable used support file transfer not the charging only cable). once plugged in and it's turning on, ESP32 will have this red led turning on too so its easy to know if its alive.

since the ESP32 is plugged in, before interacting with the ESP the port to where it connect need to be determined first (this step is optional, i have found out that esptool seems to be capable of finding it out. but it wont hurt to learn the manual way right? especially if there is multiple ESP32 plugged in.)
to find the port by using the command ls /dev/tty* | grep -E "USB|ACM"

although the same thing can be achieved with esptool as i stated before "esptool is capable of finding it out themselves" using either esptool flash-id or esptool chip-id both of the command output the same header (information about the ESP32)

i'm not exactly sure if its more than 1, i do have an ESP32-CAM module, the connection uses micro USB which i can't find the cable, so this section will be updated about esptool capabilities on detecting more than one ESP plugged in. in the future (if i remember)all the above command shows a same port for the ESP32 which is /dev/ttyUSB0 (not always the case)
the ESP32 is now set, first of all... there's a (probably) important thing to be discussed... in embedded and its derivatives and similar, there's a terminology called flash, what is flash and why it's important to discus it now.
flashis a fancier term of sayinginstallorsave
as an embedded it must be able to run independently without continuous user interaction, which mean once the ESP32 is given power it should do what it is programmed to, but how do the ESP32 know what should it do? the answer to that lies in the flash, which a program that does thing(s), compiled, then flashed to this small 4MB memory and the program will stay there, so that once the ESP32 is powered on it will start reading the program and does what is instructed there.
below is a very simple program in C that output "hello world" and start counting to 10.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void app_main(void) {
printf("hello world\n");
for(int i = 0; i <= 10; i++) {
printf("count: %d\n", i);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
while(1) {
vTaskDelay(portMAX_DELAY);
}
}i'm using platformio to compile and making the firmware, the note will come later in another post along with a note for writing c program for embeddedonce the code is compiled, usually it will comes in 3 main files bootloader.bin, partitions.bin, firmware.bin. each of this files has their own places in the memory structure of the ESP32, the most basic and default is as simple as below.
- 0x0 - 0x1000: used if secure boot is enabled, this section will stores the IV and digest
- 0x1000 - 0x8000: the place for the bootloader.bin, this section is where the ESP32 will expect a bootloader entry
- 0x8000 - 0x10000: the place for the partition.bin, this section is where the ESP32 will expect a partitions entry
- 0x10000 - 0x40000 (or the rest of the memory): the place for the program.bin, this section is where the ESP32 will expect the instruction to be run are placed
above is the default memory segment of where each files are expected, a short google led to the hypothetical answer that the address above can be changed (i.e bootloader occupying 0x1000 - 0x9000), this requires further test as i can't imagine a bootloader being larger than what it has been
memory is covered, now to flash the firmware there's actually 2 option available, the manual way (esptool) and the auto way (platformio)