How to upload Sonoff Tasmota firmware to Sonoff’s products

How to upload Sonoff Tasmota firmware to Sonoff’s products

Summary:

One of the most interesting things about Sonoff products is the ability to upload alternative software to your device. Today, we’ll show you what to do with one of the most popular Sonoff-Tasmota firmware.

Difficult: Hard

Sonoff-Tasmota is one of alternative firmware that can be uploaded to Sonoff’s products. I will describe how to do it for the most basic product – Sonoff basic. In general uploading to others (no only) Sonoff’s products are very similar and possible differences will be described in articles for the specific product.

? One of an alternative to alternative firmware Sonoff Tasmota is younger project ESPHome that has been growing fastly these days. Will be described soon in another article.

Don’t worry if uploading firmware is new to you. I’ve tried to write down the detailed manual, but if you get stuck on something then feel free to ask in comment.

Steps

  1. Opening Sonoff Basic box
  2. PIN header soldering
  3. Connection between USB serial module and board’s PIN header
  4. Driver installation for USB serial module
  5. Reboot in Flash Mode
  6. Download or build your custom Sonoff-Tasmota firmware
  7. Upload firmware to Sonoff Basic

And we will describe all the steps in detail now.

1. Opening Sonoff Basic box

It’s not necessary to screw anything. We will cut off warranty seal and squeeze the bottom part of box carefully.

Sonoff Basic - open box
Sonoff Basic – open box

2. PIN header soldering

You will need at least basic soldering skills. For starters, you will certainly need a basic soldering iron.

I can recommend this handle MX-DEMEL 60W Electric Soldering Iron at a cost of approximately $ 4.5.

Basic soldering Iron - MX-DEMEL 60W
Basic soldering Iron – MX-DEMEL 60W

We will also need a 4 or 5 pin PIN header – the last fifth is optional – we will not need it for firmware upload.

You can easily find a place for a 5-pin header on the board and solder the header.

3. Connection between USB serial module and board’s PIN header

Now we need to connect the PIN header with the USB serial programming module – UART device, which then plugs into the computer USB port and serves to upload the new firmware itself.

If you do not have a UART device yet I can recommend Aluminum shell CP2102 USB 2.0 to TTL UART – it looks nice, works great and the price is less than $ 3.

USB serial programming module - CP2102
USB serial programming module – CP2102

? Do not connect Sonoff to the mains via its inputs (up to 220V), but should only be powered by UART when uploading firmware.

On the UART itself we have individual PINs described and we will map the PIN header Sonoff board (PCB) – the order is from the black pin:

Sonoff basic - Pinout description

1️⃣ PIN1 – 3V3
2️⃣ RX (TDX for USB)
3️⃣ TX (RDX for USB)
4️⃣ Ground (GND)
5️⃣ Not connected

4. Driver installation for USB serial module

Installation is slightly different according your operation system, but in general you will need to install driver for your own specific USB module and operation system.

For CP210x you can visit Silabs webpage and download driver for Windows, Mac OS or Linux.

In Windows it should be installed as COM port – check Device manager for port number. You will see item Silicon Labs CP210x USB to UART Bridge (COMx) in Ports list.

In Mac/Linux it will be visible as dev/tty device and you can search a name by command:

ls /dev/tty.*

The name of port device should be /dev/tty.SLAB_USBtoUART.

? Make sure you have a USB module connected before you start searching for a name.

5. Reboot in Flash Mode

Sonoff module needs to be put into Flash Mode before the Sonoff-Tasmota firmware can be transferred.

This is done by pulling the GPIO0 pin to GND while the device is booting.

On most devices the installed control button is connected to GPIO0 and GND, making entering Flash Mode very easy – this is the case of Sonoff Basic described here.

On other devices you will need to connect pins on the PCB.

For Sonoff Basic the following order should be followed

  1. Disconnect serial programmer and power
  2. Connect GPIO0 and GND by pressing the on-board button
  3. Connect the serial programmer back
  4. Release button after one-two seconds
  5. Device is in Flash Mode now

6. Download or build your custom Sonoff-Tasmota firmware

The simplest way how to get firmware is to download pre-compiled binary file from Sonoff-Tasmota webpage. In most cases, the default configuration should be sufficient for us.

For initial upload recommend to start with sonoff-minimal.bin and after success connection to your Wifi reupload some bigger version according to your requirement – for Sonoff Basic the sonoff.bin should best fit.

? Don’t download firmware from non-official sites. You never know what’s inside.

Second option how to get firmware is to build it by yourself from source code. You should not need this option for Sonoff products, so we will skip it for now and describe later for more complex devices.

7. Upload firmware to Sonoff Basic

The last step is finally here – we will upload downloaded or prepared binary file to Sonoff Basic.

Before initial uploading I recommend to make a backup of the current firmware version using the esptool utility.

Esptool needs Python 2.7 or 3.4 or newer, so make sure you have it installed. Tool itself will be installed by command:

pip install esptool

When tool is installed connect USB module to Sonoff Basic and don’t forget to press the button for Flash Mode.

To make a backup we need run command:

esptool.py read_flash 0x00000 0x100000 image1M.bin

and we should see something as that:

esptool.py v2.5.1
Found 2 serial ports
Serial port COM4
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: 84:f3:eb:4b:4e:e8
Uploading stub...
Running stub...
Stub running...
1048576 (100 %)
1048576 (100 %)
Read 1048576 bytes at 0x0 in 95.4 seconds (87.9 kbit/s)...
Hard resetting via RTS pin...

? After backup Flash Mode will be disabled again and need to be switched to this mode before uploading the new version – by reconnecting USB module and holding down the button.

We use same utility for upload as for backup, but with different parameters:

esptool.py write_flash -fs 1MB -fm dout 0x0 sonoff-minimal.bin

The last parameter is name of binary file, so replace it according to your choose if you need.

And we should see something as that:

esptool.py v2.5.1
Found 2 serial ports
Serial port COM4
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: 84:f3:eb:4b:4e:e8
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Compressed 1048576 bytes to 661082...
Wrote 1048576 bytes (661082 compressed) at 0x00000000 in 59.0 seconds (effective 142.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

That’s it – you could reconnect USB module now and type IP address of Sonoff device into browser and you should see web interface for configuration.

If you don’t have your own Sonoff Basic yet, you can buy it on the Internet:

?‍♂️ Let me know in comments when you have any issues during flashing.

Join the discussion