ESP32 – Hello world!

Environment setup

In my development I use currently MacOS. I have set up environment using  guide from Read the Docs. Jump to this page and check for update, I put quick list which is copy of their list

  1. Instal pip package manager
    sudo easy_install pip
  2. Install pyserial for accessing serial port
    sudo pip install pyserial
  3. Download ESP32 toolchain from Espressif website and extract to esp directory

    cd
    curl -O https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-61-gab8375a-5.2.0.tar.gz
    mkdir -p ~/esp
    cd ~/esp
    tar -xzf ~/xtensa-esp32-elf-osx-1.22.0-61-gab8375a-5.2.0.tar.gz
  4. Update your PATH variable either by creating alias or setting updating .profile file
    export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin
  5. Get ESP32 API and libraries from Espressif’s ESP-IDF repository.
    cd ~/esp
    git clone --recursive https://github.com/espressif/esp-idf.git
  6. Set IDF_PATH variable so toolchain has access to ESP-IDF
    export IDF_PATH=~/esp/esp-idf
  7. Check device name of serial connection to ESP32. As I am using Mac I run the command below twice – with unplugged and plugged board to identify correct device
    ESP32 connected to Mac
    ls /dev/tty.*
    /dev/tty.usbserial-DN01DXXH

    Note name of the port as it will be needed later.

  8. When plugged check if chip is working using for example screen command
    screen /dev/tty.usbserial-DN01DXXH 115200

    Output should be similiar to

    Example output of serial from ESP32

Getting Hello World

ESP-IDF comes with several example projects, here we start traditionally with Hello World. Let’s copy it to esp directory to test it.

cd ~/esp
cp -r $IDF_PATH/examples/get-started/hello_world .

Jump to the directory and using make command execute configuration utility menuconfig.

cd ~/esp/hello_world
make menuconfig
Main menu of menuconfig

Set serial port to correct one for your machine.

Serial port configuration in menuconfig utility

Now just build, flash and see if it works

make flash
Flashing binaries to serial port /dev/tty.usbserial-DN01DXXH (app at offset 0x10000)...
esptool.py v2.0-beta3
Connecting......
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0220
Compressed 15824 bytes to 9221...
Wrote 15824 bytes (9221 compressed) at 0x00001000 in 0.8 seconds (effective 152.2 kbit/s)...
Hash of data verified.
Compressed 355088 bytes to 167202...
Wrote 355088 bytes (167202 compressed) at 0x00010000 in 14.9 seconds (effective 191.1 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 82...
Wrote 3072 bytes (82 compressed) at 0x00008000 in 0.0 seconds (effective 1548.1 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting...

and if everything went fine

make monitor

I (1143) cpu_start: Starting scheduler on PRO CPU.
Hello world!
I (202) cpu_start: Starting scheduler on APP CPU.
This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 0, 4MB external flash
Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
Restarting in 3 seconds...
Restarting in 2 seconds...

What next

Definitely important reading is project and components structure. I will try and address it during next exercises.

Furthermore some more reading on memory and partitions and application entry points.

void app_main()
{
    printf("Hello world!\n");
    /* Print chip information */
    esp_chip_info_t chip_info;
    esp_chip_info(&chip_info);

It is app_main.

Coming back to reading, flashing and hopefully I’ll manage to explain it more and better.

/Rook

One thought on “ESP32 – Hello world!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.