diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-06-27 14:50:20 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-06-27 14:50:20 +0200 |
| commit | 8697555125c57ae64a0c9b78514b4aac4fd523de (patch) | |
| tree | a699df53a7c35a4425f30bca86982c4341f6de40 /content/posts/2020-09-06-esp-and-micropython.md | |
| parent | 33b2615a5038bc85036081e8b5e0da8584d88097 (diff) | |
| download | mitjafelicijan.com-8697555125c57ae64a0c9b78514b4aac4fd523de.tar.gz | |
Massive formatting and added figcaption
Diffstat (limited to 'content/posts/2020-09-06-esp-and-micropython.md')
| -rw-r--r-- | content/posts/2020-09-06-esp-and-micropython.md | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/content/posts/2020-09-06-esp-and-micropython.md b/content/posts/2020-09-06-esp-and-micropython.md index ac79a6d..91a04ad 100644 --- a/content/posts/2020-09-06-esp-and-micropython.md +++ b/content/posts/2020-09-06-esp-and-micropython.md | |||
| @@ -7,14 +7,16 @@ draft: false | |||
| 7 | 7 | ||
| 8 | ## Introduction | 8 | ## Introduction |
| 9 | 9 | ||
| 10 | A while ago I bought some [ESP8266](https://www.espressif.com/en/products/socs/esp8266) | 10 | A while ago I bought some |
| 11 | and [ESP32](https://www.espressif.com/en/products/socs/esp32) dev boards to | 11 | [ESP8266](https://www.espressif.com/en/products/socs/esp8266) and |
| 12 | play around with and I finally found a project to try it out. | 12 | [ESP32](https://www.espressif.com/en/products/socs/esp32) dev boards to play |
| 13 | around with and I finally found a project to try it out. | ||
| 13 | 14 | ||
| 14 | For my project, I used [ESP32](https://www.espressif.com/en/products/socs/esp32) | 15 | For my project, I used [ESP32](https://www.espressif.com/en/products/socs/esp32) |
| 15 | but I could easily choose [ESP8266](https://www.espressif.com/en/products/socs/esp8266). | 16 | but I could easily choose |
| 16 | This guide contains which tools I use and how I prepared my workspace to code | 17 | [ESP8266](https://www.espressif.com/en/products/socs/esp8266). This guide |
| 17 | for [ESP8266](https://www.espressif.com/en/products/socs/esp8266). | 18 | contains which tools I use and how I prepared my workspace to code for |
| 19 | [ESP8266](https://www.espressif.com/en/products/socs/esp8266). | ||
| 18 | 20 | ||
| 19 |  | 21 |  |
| 20 | 22 | ||
| @@ -29,16 +31,18 @@ mine and once I replaced it everything started to work. | |||
| 29 | 31 | ||
| 30 | ## Flashing the SOC | 32 | ## Flashing the SOC |
| 31 | 33 | ||
| 32 | Plug your ESP8266 to USB port and check if the device was recognized with | 34 | Plug your ESP8266 to USB port and check if the device was recognized with |
| 33 | executing `dmesg | grep ch341-uart`. | 35 | executing `dmesg | grep ch341-uart`. |
| 34 | 36 | ||
| 35 | Then check if the device is available under `/dev/` by running `ls /dev/ttyUSB*`. | 37 | Then check if the device is available under `/dev/` by running `ls |
| 38 | /dev/ttyUSB*`. | ||
| 36 | 39 | ||
| 37 | > **Linux users**: if a device is not available be sure you are in `dialout` | 40 | > **Linux users**: if a device is not available be sure you are in `dialout` |
| 38 | > group. You can check this by executing `groups $USER`. You can add a user to | 41 | > group. You can check this by executing `groups $USER`. You can add a user to |
| 39 | > `dialout` group with `sudo adduser $USER dialout`. | 42 | > `dialout` group with `sudo adduser $USER dialout`. |
| 40 | 43 | ||
| 41 | After these conditions are meet go to the navigate to [https://micropython.org/download/esp8266/](https://micropython.org/download/esp8266/) | 44 | After these conditions are meet go to the navigate to |
| 45 | [https://micropython.org/download/esp8266/](https://micropython.org/download/esp8266/) | ||
| 42 | and download `esp8266-20200902-v1.13.bin`. | 46 | and download `esp8266-20200902-v1.13.bin`. |
| 43 | 47 | ||
| 44 | ```sh | 48 | ```sh |
| @@ -48,14 +52,15 @@ cd esp8266-test | |||
| 48 | wget https://micropython.org/resources/firmware/esp8266-20200902-v1.13.bin | 52 | wget https://micropython.org/resources/firmware/esp8266-20200902-v1.13.bin |
| 49 | ``` | 53 | ``` |
| 50 | 54 | ||
| 51 | After obtaining firmware we will need some tooling to flash the firmware to | 55 | After obtaining firmware we will need some tooling to flash the firmware to the |
| 52 | the board. | 56 | board. |
| 53 | 57 | ||
| 54 | ```sh | 58 | ```sh |
| 55 | sudo pip3 install esptool | 59 | sudo pip3 install esptool |
| 56 | ``` | 60 | ``` |
| 57 | 61 | ||
| 58 | You can read more about `esptool` at [https://github.com/espressif/esptool/](https://github.com/espressif/esptool/). | 62 | You can read more about `esptool` at |
| 63 | [https://github.com/espressif/esptool/](https://github.com/espressif/esptool/). | ||
| 59 | 64 | ||
| 60 | Before flashing the firmware we need to erase the flash on device. Substitute | 65 | Before flashing the firmware we need to erase the flash on device. Substitute |
| 61 | `USB0` with the device listed in output of `ls /dev/ttyUSB*`. | 66 | `USB0` with the device listed in output of `ls /dev/ttyUSB*`. |
| @@ -70,8 +75,8 @@ If flash was successfully erased it is now time to flash the new firmware to it. | |||
| 70 | esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20200902-v1.13.bin | 75 | esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20200902-v1.13.bin |
| 71 | ``` | 76 | ``` |
| 72 | 77 | ||
| 73 | If everything went ok you can try accessing MicroPython REPL with ` | 78 | If everything went ok you can try accessing MicroPython REPL with ` screen |
| 74 | screen /dev/ttyUSB0 115200` or `picocom /dev/ttyUSB0 -b115200`. | 79 | /dev/ttyUSB0 115200` or `picocom /dev/ttyUSB0 -b115200`. |
| 75 | 80 | ||
| 76 | > Sometimes you will need to press `ENTER` in `screen` or `picocom` to access | 81 | > Sometimes you will need to press `ENTER` in `screen` or `picocom` to access |
| 77 | > REPL. | 82 | > REPL. |
| @@ -83,7 +88,7 @@ When you are in REPL you can test if all is working properly following steps. | |||
| 83 | > machine.freq() | 88 | > machine.freq() |
| 84 | ``` | 89 | ``` |
| 85 | 90 | ||
| 86 | This should output a number representing a frequency of the CPU (mine was | 91 | This should output a number representing a frequency of the CPU (mine was |
| 87 | `80000000`). | 92 | `80000000`). |
| 88 | 93 | ||
| 89 | When you are in `screen` or `picocom` these can help you a bit. | 94 | When you are in `screen` or `picocom` these can help you a bit. |
| @@ -130,7 +135,7 @@ ampy --delay 2 --port /dev/ttyUSB0 cat boot.py | |||
| 130 | 135 | ||
| 131 | ### rshell | 136 | ### rshell |
| 132 | 137 | ||
| 133 | Even though `ampy` is a cool tool I opted with `rshell` in the end since it's | 138 | Even though `ampy` is a cool tool I opted with `rshell` in the end since it's |
| 134 | much more polished and feature rich. | 139 | much more polished and feature rich. |
| 135 | 140 | ||
| 136 | ```bash | 141 | ```bash |
| @@ -144,9 +149,9 @@ Now that `rshell` is installed we can connect to the board. | |||
| 144 | rshell --buffer-size=30 -p /dev/ttyUSB0 -a | 149 | rshell --buffer-size=30 -p /dev/ttyUSB0 -a |
| 145 | ``` | 150 | ``` |
| 146 | 151 | ||
| 147 | This will open a shell inside bash and from here you can execute multiple | 152 | This will open a shell inside bash and from here you can execute multiple |
| 148 | commands. You can check what is supported with `help` once you are inside of | 153 | commands. You can check what is supported with `help` once you are inside of a |
| 149 | a shell. | 154 | shell. |
| 150 | 155 | ||
| 151 | ```bash | 156 | ```bash |
| 152 | m@turing ~/Junk/esp8266-test | 157 | m@turing ~/Junk/esp8266-test |
| @@ -177,8 +182,8 @@ Use Control-D (or the exit command) to exit rshell. | |||
| 177 | 182 | ||
| 178 | #### Moving files to flash | 183 | #### Moving files to flash |
| 179 | 184 | ||
| 180 | To avoid copying files all the time I used `rsync` function from the | 185 | To avoid copying files all the time I used `rsync` function from the inside of |
| 181 | inside of `rshell`. | 186 | `rshell`. |
| 182 | 187 | ||
| 183 | ```bash | 188 | ```bash |
| 184 | rsync . /pyboard | 189 | rsync . /pyboard |
| @@ -186,11 +191,11 @@ rsync . /pyboard | |||
| 186 | 191 | ||
| 187 | #### Executing scripts | 192 | #### Executing scripts |
| 188 | 193 | ||
| 189 | It is a pain to continuously reboot the device to trigger `/pyboard/boot.py` | 194 | It is a pain to continuously reboot the device to trigger `/pyboard/boot.py` and |
| 190 | and there is a better way of testing local scripts on remote device. | 195 | there is a better way of testing local scripts on remote device. |
| 191 | 196 | ||
| 192 | Lets assume we have `src/freq.py` file that displays CPU frequency of a | 197 | Lets assume we have `src/freq.py` file that displays CPU frequency of a remote |
| 193 | remote device. | 198 | device. |
| 194 | 199 | ||
| 195 | ```py | 200 | ```py |
| 196 | # src/freq.py | 201 | # src/freq.py |
| @@ -218,4 +223,3 @@ repl | |||
| 218 | 223 | ||
| 219 | - https://randomnerdtutorials.com/getting-started-micropython-esp32-esp8266/ | 224 | - https://randomnerdtutorials.com/getting-started-micropython-esp32-esp8266/ |
| 220 | - http://docs.micropython.org/en/latest/esp8266/quickref.html | 225 | - http://docs.micropython.org/en/latest/esp8266/quickref.html |
| 221 | |||
