Flash sonoff devices with a raspberry pi 3
tAfter a long frustrating session yesterday trying to flash my sonoff basic and sonoff pow, i finally got a stable approach.
My main source for flashing the sonof basic is the link below, but it is is outdated.
http://www.sigmdel.ca/michel/ha/sonoff/flashing_sonoff_en.html
I took my iobroker raspberry pi 3 and used it to flash all devices.
Preparing the Raspberry Pi
sudo systemctl stop [email protected] sudo systemctl disable [email protected] sudo cp /boot/cmdline.txt /boot/cmdline.bak sudo nano /boot/cmdline.txtÂ
In the last step, use the editor to remove the console=serial0,115200 option from the file.
Install pip or pip3
sudo apt-get install python-pip sudo pip install esptoolÂ
Swapping the Serial Ports
sudo nano /boot/config.txt
add the following line and save it
dtoverlay=pi3-miniuart-btÂ
check if your serial port 0 is ttyAMA0
ls -l /dev/serial*
Download firmware
wget https://github.com/arendst/Sonoff-Tasmota/releases/download/v6.1.1/sonoff.bin
Connecting a Sonoff and a Raspberry Pi 3
Do not connect AC power (sonoff) and the serial connection at the same time!!! If you do so, you will destroy your sonoff and raspberrypi!
This example is for the sonoff basic and raspberry pi 3.
Ground will be found on the last pin on the left, the 39th pin.
Flashing the Firmware
It is necessary to ensure that the power supply is sufficient for the needs of Raspberry Pi, connected peripherals (in my case a USB-WiFi adapter) and Sonoff. I often lost the SSH connection with the Raspberry Pi when I put the Sonoff into programming mode.
There are two solutions:
A. Check the source link above.
B. See below
1. Power down your raspberry pi, connect all wires (also the red one) and boot the RapsberryPI AND the sonoff at the same time. To set the Sonoff in flashing mode, keep its tactile switch depressed as both devices powered up. Once the Sonoff is powered up, release the tactile button. Nothing happens, the LED remains off which is the signal that the Sonoff is in flashing mode, but which is a bit disconcerting the first few times.
sudo systemctl stop [email protected] sudo systemctl disable [email protected]
2. Erase the content of the flash memory
sudo esptool.py --port /dev/ttyAMA0 erase_flash
After the successfull command... repeat step 1. (with the two commands)
3. Flash firmware
sudo esptool.py --port /dev/ttyAMA0 --baud 115200 --no-stub write_flash -fm dout 0x0 sonoff.bin
Done!Â
Your flashed sonoff device will search for a WPS Wifi connection automatically. If you have a router which support WPS press the button after the sonoff device booted up by 3V power or already by AC if you want. Before connecting AC close the remove all wires and close the device.










