Updated Flash Sonoff using Raspberry Pi (markdown)

Michael Ingraham 2019-10-05 16:34:36 -04:00
parent 2d02cca7bc
commit 35d01d1b19
1 changed files with 98 additions and 106 deletions

@ -1,55 +1,52 @@
If you have no USB-to-TTL serial converter available, but a Raspberry Pi, you can use this for flashing your Sonoff switch. If you don't have a USB-to-TTL serial adapter available, but you have a Raspberry Pi, you can use this procedure for flashing your device.
All is basically described here, but it is a little outdated: [Tutorial](https://www.sigmdel.ca/michel/ha/sonoff/flashing_sonoff_en.html) (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 ;) Summarizing the process and needed connections based on the above blog, please refer there for a more detailed explanation :wink:
# Preparation of the Raspberry: # Preparation of the Raspberry Pi
1. Install esptool (pip needed) 1. Install esptool (pip needed)
`sudo pip install esptool`
`sudo pip install esptool`
2. Prepare serial connection. 2. Prepare serial connection.
_Note: Use the correct serial connection as per your version of the Raspberry Pi._
_Note: Use the correct serial connection as per your version of the Raspberry Pi._ | Device | Serial Connection |
| ------------- |---------------|
| RaspberryPi 1/2/3 (BT disabled or miniuart) | /dev/ttyAMA0 |
| RaspberryPi 3 | /dev/ttyS0 |
| Device | Serial Connection | `sudo systemctl stop serial-getty@ttyS0.service`
| ------------- |---------------|
| RaspberryPi 1/2/3 (BT disabled or miniuart) | /dev/ttyAMA0 |
| RaspberryPi 3 | /dev/ttyS0 |
`sudo systemctl stop serial-getty@ttyS0.service` `sudo systemctl disable serial-getty@ttyS0.service`
`sudo systemctl disable serial-getty@ttyS0.service` `sudo cp /boot/cmdline.txt /boot/cmdline.bak` (This backups the file ;))
`sudo cp /boot/cmdline.txt /boot/cmdline.bak` (This backups the file ;)) `sudo nano /boot/cmdline.txt`
-> delete "console=serial0,115200" option
`sudo nano /boot/cmdline.txt` 3. I dont know if this is necessary, but I did it as it was mentioned here:
-> delete "console=serial0,115200" option https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/
3. I dont 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`
`sudo nano /boot/config.txt` -> add the line (at the bottom):
`enable_uart=1`
-> add the line (at the bottom): Please note following overlays setting port to `/dev/ttyAMA0`
`enable_uart=1`
Please note following overlays setting port to `/dev/ttyAMA0` * `pi3-miniuart-bt`
* `pi3-disable-bt`
* `pi3-miniuart-bt`
* `pi3-disable-bt`
4. Reboot your Pi 4. Reboot your Pi
# Connections
# Wire RaspberryPi:
Connect GND, RX->TX and TX->RX as shown below. Connect GND, RX->TX and TX->RX as shown below.
**If you power the Sonoff with the 3.3v power from the RPi it will cause it to reboot when connecting.** You can still enter flash mode if you power up the RPi with the 3.3v connected and pressing the button on Sonoff simultaneously. It's recommended to use either an external power supply for this or use the 5V GPIO and a 3.3V Voltage Regulator. **If you power the device with the 3.3V power from the RPi it will cause it to reboot when connecting.** You can still enter flash mode if you power up the RPi with the 3.3v connected and pressing the connecting GPIO0 to ground (e.g., pressing the button on the Sonoff Basic) simultaneously. It's recommended to use either an external power supply for this or use the 5V GPIO and a 3.3V Voltage Regulator.
([issue #4807](https://github.com/arendst/Sonoff-Tasmota/issues/4807)) ([issue #4807](https://github.com/arendst/Sonoff-Tasmota/issues/4807))
**Do not connect 3,3V yet!** **Do not connect 3.3V yet!**
https://www.sigmdel.ca/michel/ha/sonoff/flashing_sonoff_en.html https://www.sigmdel.ca/michel/ha/sonoff/flashing_sonoff_en.html
![Wiring](https://www.sigmdel.ca/michel/ha/sonoff/img/sonoff-rpi.jpg) ![Wiring](https://www.sigmdel.ca/michel/ha/sonoff/img/sonoff-rpi.jpg)
@ -61,99 +58,94 @@ This is how it looks in real-life 😆
# Flashing the firmware # Flashing the firmware
1. Erase flash memory: 1. Erase flash memory:
Connect 3,3V while button pressed for about 10 seconds to enter flash-mode. Then release and run: Connect 3.3V while button pressed for about 10 seconds to enter flash-mode. Then release and run:
```bash ```bash
# if using Raspberry Pi 1/2 use # if using Raspberry Pi 1/2 use
# esptool.py --port /dev/ttyAMA0 erase_flash # esptool.py --port /dev/ttyAMA0 erase_flash
# if using Raspberry Pi 3 use # if using Raspberry Pi 3 use
esptool.py --port /dev/ttyS0 erase_flash esptool.py --port /dev/ttyS0 erase_flash
``` ```
You should see output like this: You should see output like this:
```bash ```bash
➜ ~ esptool.py --port /dev/ttyAMA0 erase_flash ➜ ~ esptool.py --port /dev/ttyAMA0 erase_flash
esptool.py v2.5.1 esptool.py v2.5.1
Serial port /dev/ttyAMA0 Serial port /dev/ttyAMA0
Connecting.... Connecting....
Detecting chip type... ESP8266 Detecting chip type... ESP8266
Chip is ESP8285 Chip is ESP8285
Features: WiFi, Embedded Flash Features: WiFi, Embedded Flash
MAC: dc:4f:22:ab:5e:dc MAC: dc:4f:22:ab:5e:dc
Uploading stub... Uploading stub...
Running stub... Running stub...
Stub running... Stub running...
Erasing flash (this may take a while)... Erasing flash (this may take a while)...
Chip erase completed successfully in 3.3s Chip erase completed successfully in 3.3s
Hard resetting via RTS pin... Hard resetting via RTS pin...
➜ ~ ➜ ~
``` ```
2. Flash .bin, which you can download from the [release-section](https://github.com/arendst/Sonoff-Tasmota/releases): 2. Flash .bin, which you can download from the [release-section](https://github.com/arendst/Sonoff-Tasmota/releases):
Again connect 3,3V while pressing button for 10 seconds. Then release and run: Again connect 3.3V while pressing button for 10 seconds. Then release and run:
```bash ```bash
# if using Raspberry Pi 1/2 use # if using Raspberry Pi 1/2 use
# esptool.py --port /dev/ttyAMA0 write_flash -fm dout 0x0 /path/to/downloaded/sonoff.bin # esptool.py --port /dev/ttyAMA0 write_flash -fm dout 0x0 /path/to/downloaded/sonoff.bin
# if using Raspberry Pi 3 use # if using Raspberry Pi 3 use
esptool.py --port /dev/ttyS0 write_flash -fm dout 0x0 /path/to/downloaded/sonoff.bin esptool.py --port /dev/ttyS0 write_flash -fm dout 0x0 /path/to/downloaded/sonoff.bin
``` ```
You should see output like this: You should see output like this:
```bash ```bash
➜ ~ esptool.py --port /dev/ttyAMA0 write_flash -fm dout 0x0 sonoff.bin ➜ ~ esptool.py --port /dev/ttyAMA0 write_flash -fm dout 0x0 sonoff.bin
esptool.py v2.5.1 esptool.py v2.5.1
Serial port /dev/ttyAMA0 Serial port /dev/ttyAMA0
Connecting..... Connecting.....
Detecting chip type... ESP8266 Detecting chip type... ESP8266
Chip is ESP8285 Chip is ESP8285
Features: WiFi, Embedded Flash Features: WiFi, Embedded Flash
MAC: dc:4f:22:ab:5e:dc MAC: dc:4f:22:ab:5e:dc
Uploading stub... Uploading stub...
Running stub... Running stub...
Stub running... Stub running...
Configuring flash size... Configuring flash size...
Auto-detected Flash size: 1MB Auto-detected Flash size: 1MB
Compressed 456000 bytes to 312426... Compressed 456000 bytes to 312426...
Wrote 456000 bytes (312426 compressed) at 0x00000000 in 29.2 seconds (effective 124.8 kbit/s)... Wrote 456000 bytes (312426 compressed) at 0x00000000 in 29.2 seconds (effective 124.8 kbit/s)...
Hash of data verified. Hash of data verified.
Leaving... Leaving...
Hard resetting via RTS pin... Hard resetting via RTS pin...
➜ ~ ➜ ~
``` ```
7. Setup Wifi: 3. Setup Wi-Fi:
Connect with an external device to the wifi and configure over the browser. - Connect with an external device to the `sonoff-xxxx` Wi-Fi AP and configure over the browser.
Alternativ: Reboot your sonoff after flashing(toggle power wire) and connect to serial console via miniterm: - Alternative: Reboot your device after flashing (toggle power wire) and connect to the serial console via miniterm:
```bash ```bash
# if using Raspberry Pi 1/2 use # if using Raspberry Pi 1/2 use
# miniterm.py /dev/ttyAMA0 115200 -e # miniterm.py /dev/ttyAMA0 115200 -e
# if using Raspberry Pi 3 use # if using Raspberry Pi 3 use
miniterm.py /dev/ttyS0 115200 -e miniterm.py /dev/ttyS0 115200 -e
``` ```
You will see some output, after pressing enter. You will see some output, after pressing enter.
Now just type in, your SSID, press enter and then type the password… Now just type in, your SSID, press enter and then type the password…
`ssid yourSSID` `Backlog ssid yourSSID; password yourPassword`
wait until sonoff stops outputting messages (~3 seconds) and type
`password yourPassword` # Thats it :smiley:
# Thats it :)
Feel free to edit, if I forgot something or changes are necessary in the future!
Sources: Sources:
https://github.com/arendst/Sonoff-Tasmota/wiki/Esptool (flashing commands) [Flashing commands](https://github.com/arendst/Sonoff-Tasmota/wiki/Esptool)
https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/ https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/