Micropython 01 start: Difference between revisions
From artserver wiki
(Created page with "# Board: ESP8266 * [uPython esp8266/quickref http://docs.micropython.org/en/latest/esp8266/quickref.html] ## Flash uPython * uPython firmware: http://micropython.org/downloa...") |
m (Text replacement - "Code_Notes" to "Code Notes") Tag: Manual revert |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Board: ESP8266 = | |||
* [uPython esp8266/quickref http://docs.micropython.org/en/latest/esp8266/quickref.html] | * [uPython esp8266/quickref http://docs.micropython.org/en/latest/esp8266/quickref.html] | ||
== Flash uPython == | |||
* uPython firmware: http://micropython.org/download#esp8266 download latest stable | * uPython firmware: http://micropython.org/download#esp8266 download latest stable | ||
* install esptool.py to flash the board <code>pip install esptool</code> | * install esptool.py to flash the board <code>pip install esptool</code> | ||
Line 11: | Line 11: | ||
* write firmware <code?esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0</code> | * write firmware <code?esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0</code> | ||
== REPL over serial port == | |||
REPL(Read Evaluate Print Loop) AKA the interactive MicroPython prompt. | |||
* <code> stty < /dev/ttyUSB0 </code> | * <code> stty < /dev/ttyUSB0 </code> | ||
<pre> | <pre> | ||
Line 23: | Line 27: | ||
* connect to REPL <code>screen /dev/ttyUSB0 115200 </code> | * connect to REPL <code>screen /dev/ttyUSB0 115200 </code> | ||
* Ctl-A will exit screen | * Ctl-A will exit screen | ||
== Load files and run code on a uPython == | |||
Tools available: | |||
* Adafruit [https://github.com/pycampers/ampy ampy] python module | |||
* [https://github.com/dhylands/rshell rshell] remote Shell for MicroPython | |||
* [https://github.com/wendlers/mpfshell mpfshell] remote Shell specially for ESP8266-based boards and the WiPy board | |||
===Using ampy=== | |||
In the ESP8266 file system there are the files: | |||
* <code>boot.py</code> is executed first (if it exists) | |||
* <code>main.py</code> is executed once boot.py is finished executing | |||
So What will do is save the following script as <codeblink_led.py</code> | |||
<source lang="python"> | |||
from time import sleep | |||
from machine import Pin | |||
p2 = Pin(2, Pin.OUT) | |||
while True: | |||
p2.value(not p2.value()) | |||
sleep(0.5) | |||
</source> | |||
create a syslink between blink_led.py and main.py <code>ln blink_led.py main.py</code> | |||
Use ampy to put the script (main.py) on the board | |||
<code>ampy --port /dev/ttyUSB0 put main.py</code> | |||
Reset: either by pressing the reset button, or disconnecting and connecting to power, '''for the new main.py to be compiled.''' | |||
[[Section::Code Notes]] | |||
[[Date::2019]] |
Latest revision as of 13:54, 25 August 2022
Board: ESP8266
- [uPython esp8266/quickref http://docs.micropython.org/en/latest/esp8266/quickref.html]
Flash uPython
- uPython firmware: http://micropython.org/download#esp8266 download latest stable
- install esptool.py to flash the board
pip install esptool
Flash squence:
- connect board to usb
- erase the flash
esptool.py --port /dev/ttyUSB0 erase_flash
- write firmware <code?esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0
REPL over serial port
REPL(Read Evaluate Print Loop) AKA the interactive MicroPython prompt.
stty < /dev/ttyUSB0
speed 115200 baud; line = 0; min = 100; time = 2; -icrnl -imaxbel -opost -onlcr -isig -icanon -echo
- connect to REPL
screen /dev/ttyUSB0 115200
- Ctl-A will exit screen
Load files and run code on a uPython
Tools available:
- Adafruit ampy python module
- rshell remote Shell for MicroPython
- mpfshell remote Shell specially for ESP8266-based boards and the WiPy board
Using ampy
In the ESP8266 file system there are the files:
boot.py
is executed first (if it exists)main.py
is executed once boot.py is finished executing
So What will do is save the following script as <codeblink_led.py
from time import sleep
from machine import Pin
p2 = Pin(2, Pin.OUT)
while True:
p2.value(not p2.value())
sleep(0.5)
create a syslink between blink_led.py and main.py ln blink_led.py main.py
Use ampy to put the script (main.py) on the board
ampy --port /dev/ttyUSB0 put main.py
Reset: either by pressing the reset button, or disconnecting and connecting to power, for the new main.py to be compiled.
Code Notes
2019
... more about "Micropython 01 start"