You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
11 KiB

  1. < [Configuration guide](configuration.md) | [Index](../README.md) | [Known issues](known_issues.md) >
  2. # Flashing guide
  3. Table of contents:
  4. * [Warning](#warning)
  5. * [Tools needed](#tools-needed)
  6. * [Opening the lamp, to expose the PCB](#)
  7. * [Solder wires to the board](#)
  8. * [Connect the wires to your serial to USB adapter](#)
  9. * [When you only have one GND pin on your USB Adapter](#)
  10. * [Make a backup of the current firmware](#)
  11. * [How to restore the backed up firmware](#)
  12. * [Flash new ESPHome firmware](#)
  13. * [Troubleshooting flash](#)
  14. ## Warning
  15. We have writen these instructions with care, but we will give absolutely no
  16. warranty. Perhaps you will destroy your lamp and your computer.
  17. ## Tools needed
  18. * Allen key (2mm, 5/64") or torx (T8) screw driver
  19. * Soldering Iron
  20. * A serial to USB adapter (FTDI)
  21. * Some wires
  22. * Optional: sticky tape, hot glue gun, magnifying glass
  23. ## Opening the lamp, to expose the PCB
  24. Remove the rubber pads from the botton of the lamp, to get access to 4
  25. screws that attach the bottom to the rest of the lamp.
  26. <img src="images/01_unboxed.jpg" width="200"><img src="images/02_remove_rubber_pads.jpg" width="200">
  27. Note that you don't have to remove these pads fully. Once you can access
  28. the screws, you've gone far enough.
  29. <img src="images/03_bolts_overview.jpg" width="200">
  30. Unbolt the 4 screws which were hidden under the rubber pads.
  31. <img src="images/04_remove_bolts.jpg" width="200"><img src="images/05_bolts.jpg" width="200">
  32. Detach the bottom from the rest of the lamp, exposing the PCB. This might
  33. take a bit of force. Just pull it off bit by bit, until it pops loose.
  34. <img src="images/06_pull_off_the_bottom.jpg" width="200"><img src="images/07_bottom_removed.jpg" width="200">
  35. <img src="images/08_board_exposed.jpg" width="400">
  36. ## Solder wires to the board
  37. The wires will be connected to the debug pads that are shown in the following image.
  38. <img src="images/09_debug_pads_for_soldering.jpg" width="400">
  39. Many of the serial to USB adapter have some header pins to which you can
  40. connect the wires of a device (no soldering required). Therefore, it might be
  41. useful to use dupont wire. Cut off one end, strip the wire, tin the wire and
  42. solder it to the board.
  43. *Note: Whether to use male or female dupont wires depends on how you want to connect
  44. the serial adapter. In this example, I have used male wires, so I could plug them
  45. into a breadbord.*
  46. <img src="images/10_stripped_dupont_wires.jpg" width="200">
  47. Solder the wires to the `RX`, `TX`, `GND` and `GPIO0` debug pads.
  48. *Note: The board has a debug pad that exposes 3.3V. Do not use this pad to power
  49. the board from your serial adapter. Always power the lamp using its own power supply.*
  50. A few tips:
  51. - Depending on the quality of your eyes, you might want to use a magnifying glass for the
  52. soldering work. Use one that is mounted on a stand, or you will quickly be left wishing
  53. that you could grow a third arm.
  54. - You could use some sticky tape to fixate the cables before soldering.
  55. - When you want to keep the wires attached after flashing the new firmware (e.g. for
  56. serial logging or for future firmware flashing), then you might want to apply some
  57. hot glue to fixate the wires. This prevents the wires from breaking off, due to
  58. excessive movement.
  59. <img src="images/11_soldered_wires.jpg" width="200"><img src="images/12_optional_hot_glue.jpg" width="200">
  60. ## Connect the wires to your serial to USB adapter
  61. The wires must be connected as follows:
  62. | Soldering point| Serial USB Adapter name |
  63. | -------------- |:------------------------:|
  64. | GND | GND |
  65. | TX | RX |
  66. | RX | TX |
  67. | GPIO0 | GND |
  68. To be able to flash the lamp, `GPIO0` must be connected to ground while the lamp boots up.
  69. Therefore, connect these wires *before* plugging in the lamp's power supply.
  70. Flashing will *not* work if you connect these wires *after* the lamp has already been booted up.
  71. ## When you only have one GND pin on your USB Adapter
  72. If your USB Adapter does not have multiple `GND` pins, then you'll have to
  73. find another way to attach `GPIO0` to ground. Some options:
  74. - **Use a breadbord**, so you can connect the USB Adapter `GND` pin to a row on
  75. the bread bord, and connect the `GND` and `GPIO0` wires of the lamp's
  76. board to that same row. The rest of this guide will show this method.
  77. [example image](images/13_connect_to_serial_to_usb_adapter.jpg)
  78. - **Solder a button on the board** that connects `GPIO0` to `GND` when pressed.
  79. Then you can hold down this button while plugging in the lamp's power
  80. supply. After booting up, you can release the button (the serial console
  81. will also mention that flash mode is now enabled). This is not the most
  82. practical solution for most people (since only one such flash operation is
  83. needed, from then on OTA - Over The Air - updates are possible), but it
  84. was a great help to me during the initial reverse engineering and firmware
  85. development.
  86. [example image](images/13_connect_to_serial_with_button.jpg)
  87. - **Manually hold a wire connected** to both a GND surface (e.g. the silver pad
  88. on the left of the board) and the `GPIO0` debug pad, while plugging in the
  89. power supply. After booting, the wire can be removed. This is very fiddly
  90. way of doing it (a third hand would be very welcome with this), but it can
  91. be done.
  92. - **Temporarily solder a lead between `GND` and `GPIO0` on the board**,
  93. making `GPIO0` pulled to ground permanently. It is a bit less flexible than
  94. some other options, but if you only need to do the initial backup and firmware
  95. flash of the lamp, then this can be all that you need. Remove the lead after
  96. flashing is done, otherwise the lamp won't boot in normal mode.
  97. [example image](images/13_connect_to_serial_with_soldered_gnd.jpg)
  98. In the following images, you will see the first solution, using a breadboard.
  99. <img src="images/13_connect_to_serial_to_usb_adapter.jpg" width="400">
  100. In close up:
  101. <img src="images/14_connect_to_serial_to_usb_adapter_close_up.jpg" width="400">
  102. You can now connect the serial to USB adapter to you computer. Pay special attention
  103. to the cross-over of the TX/RX pair (TX connects to RX and vice versa).
  104. Start the [esphome-flasher tool](https://github.com/esphome/esphome-flasher) and
  105. select the COM port to use. Then click on "View logs".
  106. Now, plug in the lamp's power supply to boot up the lamp.
  107. <img src="images/15_power_up_for_flashing.jpg" width="400">
  108. Because GPIO0 is connected to GND, the device should start up in flashing mode.
  109. If all went well, the log output in esphome-flasher looks somewhat like this:
  110. <img src="images/16_serial_showing_download_mode.png" width="400">
  111. ## Make a backup of the current firmware
  112. Backing up the firmware makes it possible to revert to the original firmware,
  113. in case you have problems with the ESPHome firmware. The backup can be
  114. created using "esptool". Installation instructures can be found here:
  115. https://github.com/espressif/esptool/blob/master/README.md#installation--dependencies
  116. Here's an example on how to backup the original firmware from Linux.
  117. First, unplug your lamp's power supply, then start the esptool read_flash command:
  118. ```
  119. python esptool.py -p /dev/ttyUSB0 read_flash 0x0 0x400000 original-firmware.bin
  120. ```
  121. `/dev/ttyUSB0` is the port of the USB adaper on Linux. You can find what
  122. port is used by the adapter by running `dmesg` after plugging in the USB
  123. device. On Windows this is often `COM1`, `COM2` or `COM3`.
  124. Now plug back in the power supply. The output of esptool should now show that it
  125. connects to the lamp and downloads the firmware from it.
  126. **Caution**: You will find the WLAN SSID and Password of the last used
  127. WiFi network in this file. Therefore, keep this backup in a safe place.
  128. ## How to restore the backed up firmware
  129. In case you need to rollback to the lamp's original firmware at some
  130. point, here's an example of how to restore the original firmware from
  131. Windows, by fully flashing it back onto the lamp.
  132. First, unplug your lamp's power supply, then start the esptool write_flash command:
  133. ```
  134. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x00 original-firmware.bin
  135. ```
  136. Make sure that `GPIO0` is connected to GND and plug in the power supply.
  137. The output of esptool should now show that it connects to the lamp and
  138. uploads the firmware to it.
  139. Be patient after the upload reaches 100%. The output is silent while
  140. esptool tool is verifying that the firmware was uploaded correctly.
  141. After the firmware upload completes, unplug the power, disconnect `GPIO0`
  142. from GND and reconnect the power supply to boot into the restored firmware.
  143. ## Flash new ESPHome firmware
  144. Setup an ESPHome Project (see [README.md](../README.md)), compile the firmware
  145. for the lamp and download the `firmware.bin` file to the device to which
  146. the serial adapter is connected.
  147. You can flash the lamp using esphome or esptool. I would strongly recommend using
  148. the [esphome-flasher](https://github.com/esphome/esphome-flasher) tool. This is
  149. a very easy to use GUI utility app for flashing ESPHome devices and for viewing
  150. serial console logging.
  151. - In the app, select the COM port of your serial adapter.
  152. - Then select the firmware.bin file to flash onto the lamp.
  153. - Power up the lamp with `GPIO0` connected to GND.
  154. - Click the "Flash ESP" button to flash the firmware.
  155. If all went well, the final log output in esphome-flasher looks somewhat like this:
  156. <img src="images/17_flash_ready.png" width="400">
  157. If you want to flash with esptool, you can use:
  158. ```
  159. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x1000 <path\to\yourfirmware.bin>
  160. ```
  161. After flashing, power down the lamp, disconnect `GPIO0` from GND and
  162. reconnect the power to boot into the new ESPHome firmware.
  163. <img src="images/18_disconnect_GPIO0.jpg" width="200">
  164. From here on, it is possible to flash the lamp OTA (over the air, which
  165. means that the firmware is uploaded over WiFi) from ESPHome. Therefore, it
  166. is now time to tuck away or remove those soldered wires and add the bottom
  167. cover back on.
  168. <img src="images/19_test_run.jpg" width="200"><img src="images/20_tuck_away_wires.jpg" width="200"><img src="images/21_reassemble_and_enjoy.jpg" width="200">
  169. ## Troubleshooting flash
  170. If you have **A fatal error occurred: MD5 of file does not match data in flash!**,
  171. then make sure you are powering the board using the lamp's own power adapter.
  172. We've seen these errors when trying to power the board using the 3.3V debug pad.
  173. After seeing this error, user @tabacha was able to successfully flash his
  174. lamp using the regular power adapter.
  175. < [Configuration guide](configuration.md) | [Index](../README.md) | [Known issues](known_issues.md) >