aboutsummaryrefslogtreecommitdiff
path: root/content/posts/2020-09-06-esp-and-micropython.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/2020-09-06-esp-and-micropython.md')
-rw-r--r--content/posts/2020-09-06-esp-and-micropython.md58
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
10A while ago I bought some [ESP8266](https://www.espressif.com/en/products/socs/esp8266) 10A while ago I bought some
11and [ESP32](https://www.espressif.com/en/products/socs/esp32) dev boards to 11[ESP8266](https://www.espressif.com/en/products/socs/esp8266) and
12play 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
13around with and I finally found a project to try it out.
13 14
14For my project, I used [ESP32](https://www.espressif.com/en/products/socs/esp32) 15For my project, I used [ESP32](https://www.espressif.com/en/products/socs/esp32)
15but I could easily choose [ESP8266](https://www.espressif.com/en/products/socs/esp8266). 16but I could easily choose
16This 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
17for [ESP8266](https://www.espressif.com/en/products/socs/esp8266). 18contains 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![ESP8266 and ESP32 boards](/assets/esp8366-micropython/boards.jpg) 21![ESP8266 and ESP32 boards](/assets/esp8366-micropython/boards.jpg)
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
32Plug your ESP8266 to USB port and check if the device was recognized with 34Plug your ESP8266 to USB port and check if the device was recognized with
33executing `dmesg | grep ch341-uart`. 35executing `dmesg | grep ch341-uart`.
34 36
35Then check if the device is available under `/dev/` by running `ls /dev/ttyUSB*`. 37Then 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
41After these conditions are meet go to the navigate to [https://micropython.org/download/esp8266/](https://micropython.org/download/esp8266/) 44After these conditions are meet go to the navigate to
45[https://micropython.org/download/esp8266/](https://micropython.org/download/esp8266/)
42and download `esp8266-20200902-v1.13.bin`. 46and download `esp8266-20200902-v1.13.bin`.
43 47
44```sh 48```sh
@@ -48,14 +52,15 @@ cd esp8266-test
48wget https://micropython.org/resources/firmware/esp8266-20200902-v1.13.bin 52wget https://micropython.org/resources/firmware/esp8266-20200902-v1.13.bin
49``` 53```
50 54
51After obtaining firmware we will need some tooling to flash the firmware to 55After obtaining firmware we will need some tooling to flash the firmware to the
52the board. 56board.
53 57
54```sh 58```sh
55sudo pip3 install esptool 59sudo pip3 install esptool
56``` 60```
57 61
58You can read more about `esptool` at [https://github.com/espressif/esptool/](https://github.com/espressif/esptool/). 62You can read more about `esptool` at
63[https://github.com/espressif/esptool/](https://github.com/espressif/esptool/).
59 64
60Before flashing the firmware we need to erase the flash on device. Substitute 65Before 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.
70esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20200902-v1.13.bin 75esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20200902-v1.13.bin
71``` 76```
72 77
73If everything went ok you can try accessing MicroPython REPL with ` 78If everything went ok you can try accessing MicroPython REPL with ` screen
74screen /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
86This should output a number representing a frequency of the CPU (mine was 91This should output a number representing a frequency of the CPU (mine was
87`80000000`). 92`80000000`).
88 93
89When you are in `screen` or `picocom` these can help you a bit. 94When 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
133Even though `ampy` is a cool tool I opted with `rshell` in the end since it's 138Even though `ampy` is a cool tool I opted with `rshell` in the end since it's
134much more polished and feature rich. 139much 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.
144rshell --buffer-size=30 -p /dev/ttyUSB0 -a 149rshell --buffer-size=30 -p /dev/ttyUSB0 -a
145``` 150```
146 151
147This will open a shell inside bash and from here you can execute multiple 152This will open a shell inside bash and from here you can execute multiple
148commands. You can check what is supported with `help` once you are inside of 153commands. You can check what is supported with `help` once you are inside of a
149a shell. 154shell.
150 155
151```bash 156```bash
152m@turing ~/Junk/esp8266-test 157m@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
180To avoid copying files all the time I used `rsync` function from the 185To avoid copying files all the time I used `rsync` function from the inside of
181inside of `rshell`. 186`rshell`.
182 187
183```bash 188```bash
184rsync . /pyboard 189rsync . /pyboard
@@ -186,11 +191,11 @@ rsync . /pyboard
186 191
187#### Executing scripts 192#### Executing scripts
188 193
189It is a pain to continuously reboot the device to trigger `/pyboard/boot.py` 194It is a pain to continuously reboot the device to trigger `/pyboard/boot.py` and
190and there is a better way of testing local scripts on remote device. 195there is a better way of testing local scripts on remote device.
191 196
192Lets assume we have `src/freq.py` file that displays CPU frequency of a 197Lets assume we have `src/freq.py` file that displays CPU frequency of a remote
193remote device. 198device.
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