Blog 2Smart (EN)

Flashing ESPHome Firmware on ESP32 Microcontroller Linux workflow

Flashing ESPHome Firmware on ESP32 Microcontroller Linux workflow
The following instructions will show vendors how to install the ESPHome firmware on the ESP32 microcontroller using a PC or laptop running Linux. They will be required for the first time during product testing when the test firmware is installed on the prototype.

You can use one of two tools to install the firmware on the microcontroller: Python or Docker.

Flashing a ESP32 device with esptool


1. Python 3.8.10 is already installed by defau lt in Ubuntu 20.04. Install Python or upgrade it to version 3.8.10 or higher if you don't have the proper version on your device.

To flash the board, the pip3 package manager should be installed. To accomplish this, use the following command to update the package list:

sudo apt update

After this, install the package manager:

sudo apt-get -y install python3-pip

2. Unzip the firmware file and navigate to the directory containing the archive's contents in the terminal.

The firmware archive's content

3. Connect the microcontroller to the PC utilizing a USB cable. Enter the following command and hit Tab:

/dev/ttyUSB0

Please note that you may be utilizing the ttyUSB1 port rather than the ttyUSB0 port, for example. Bear this in mind as you proceed through the current and next steps.

4. Set file permissions by running the following command:

sudo chown $USER:$USER /dev/ttyUSB0

Setting permissions

5. Install the necessary libraries to work with the “2smart.sh” script using the following command:

pip3 install -r requirements.txt

Installing libraries

Installing libraries

6. Clean up the microcontroller memory by running the following command:

./2smart.sh --device /dev/ttyUSB0 erase_flash

Cleaning the microcontroller memory

If the memory cleaning stops at the “Connecting ….___….___” step, press the Boot button on the DevKit board:

Cleaning the microcontroller memory

7. Run the “2smart.sh” script to flash the microcontroller:

./2smart.sh --device /dev/ttyUSB0 write

If the flashing stops at the “Connecting ….___….___” step, press the Boot button on the DevKit board.

Flashing the microcontroller

8. After a successful flash, you will see the “Leaving… Hard resetting via RTS pin…” notification.

Flashing the microcontroller


9. After flashing is completed, return to your 2Smart Cloud account and wait until the device is detected by the platform. If this does not happen within one to two minutes, unplug your device and plug it back in the PC.

The device's "Ready" status indicates that the prototype has been successfully connected to the platform.

Indicator of device status with the test firmware

Flashing a device with Docker


1. Install the appropriate Docker Engine for your system. All versions can be found on the developer's website.

Check if you already have Docker installed. Run the following command:

docker -v

Checking to see whether Docker is installed on the system

You can also install Docker from the ubuntu repository with the following command:

sudo apt install docker.io

2. Unzip the firmware file and navigate to the directory containing the archive's contents in the terminal.

3. Connect the microcontroller to the PC utilizing a USB cable. Enter the following command in the terminal and hit Tab:

/dev/ttyUSB0

This step is required to verify that the microcontroller is connected to the USB port.

Please note that you may be utilizing the ttyUSB1 port rather than the ttyUSB0 port, for example. Bear this in mind as you proceed through the current and next steps.

4 . Set the permissions to the USB port by running the command:

sudo chown $USER:$USER /dev/ttyUSB0

5. Use the following command to make the user Docker accessible:

sudo usermod -aG docker $USER

After adding the user to the Docker group, log out and log back in for the changes to take effect.

6. Clean up the microcontroller memory. If the esptool images have not been downloaded, they will be downloaded automatically. Run the following command:

./2smart_docker.sh --device /dev/ttyUSB0 erase_flash

Cleaning the microcontroller memory

If the memory cleaning stops at the “Connecting ….___….___” step, press the Boot button on the DevKit board:

Cleaning up microcontroller memory

7. Run the “2smart_docker.sh” script to flash the microcontroller.

./2smart_docker.sh --device /dev/ttyUSB0 write

If flashing stops at the “Connecting ….___….___” step, press the Boot button on the DevKit board.

Microcontroller flashing

8. After a successful flash, you will see the “Leaving… Hard resetting via RTS pin…” notification.

Flashing the microcontroller

9. After flashing is completed, return to your 2Smart Cloud account and wait until the device is detected by the platform. If this does not happen within one to two minutes, unplug your device and plug it back in the PC. The device's "Ready" status indicates that the prototype has been successfully connected to the platform.

Indicator of device status with the test firmware

When getting confirmation that your connection to the prototype platform with test firmware was successful, you can continue working on your product. A similar approach is used to install the production firmware on finished devices.
Made on
Tilda