Flash Sonoff using Raspberry Pi - RTurala/Sonoff-Tasmota GitHub Wiki

If you have no USB-to-TTL serial converter available, but a Raspberry Pi, you can use this for flashing your Sonoff switch.

All is basically described here, but it is a little outdated: https://www.sigmdel.ca/michel/ha/sonoff/flashing_sonoff_en.html

So, I will summarize the process and needed adoptions based on the above blog, please refer there for a more detailed explanation ;)

Preparation of the Raspberry:

  1. Install esptool (pip needed)

sudo pip install esptool

  1. Prepare serial connection (This is adopted for RaspberryPi 3, before it was ttyAMA0)

sudo systemctl stop [email protected]

sudo systemctl disable [email protected]

sudo cp /boot/cmdline.txt /boot/cmdline.bak (This backups the file ;))

sudo nano /boot/cmdline.txt -> delete "console=serial0,115200" option

  1. I don’t know if this is necessary, but I did it as it was mentioned here: https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/

sudo nano /boot/config.txt

-> add the line (at the bottom): enable_uart=1

  1. Reboot your Pi

Wire RaspberryPi:

Connect GND, RX->TX and TX->RX as shown below. Do not connect 3,3V yet!

https://www.sigmdel.ca/michel/ha/sonoff/flashing_sonoff_en.html Wiring

(For RaspberryPi 3 (40 GPIO pins) GND is the last pin on the left, the 39th pin.)

This is how it looks in real-life 😆 Wiring2

Flashing the firmware

  1. Erase flash memory: Connect 3,3V while button pressed to enter flash-mode:

esptool.py --port /dev/ttyS0 erase_flash

  1. Flash .bin, which you can download from the release-section:

Again connect 3,3V while pressing button:

esptool.py --port /dev/ttyS0 write_flash -fm dout 0x0 /path/to/downloaded/sonoff.bin

  1. Setup Wifi: Reboot your sonoff after flashing(toggle power wire) and run a command

miniterm.py /dev/ttyS0 115200 -e

You will see some output, after pressing enter.

Now just type in, your SSID, press enter and then type the password…

ssid yourSSID

wait until sonoff stops outputting messages (~3 seconds) and type

password yourPassword

That’s it :)

Feel free to edit, if I forgot something or changes are necessary in the future!

Sources: https://github.com/arendst/Sonoff-Tasmota/wiki/Esptool (flashing commands) https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/