micropython

esptools / ampy

pip install esptool
pip install adafruit-ampy

identify

esptool.py chip_id

esp8266

download micropython from http://micropython.org/download#esp8266

wget http://micropython.org/resources/firmware/esp8266-20171101-v1.9.3.bin

erase (optional ?) and upload

esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20171101-v1.9.3.bin

access from serial over USB

sudo apt install picocom
picocom /dev/ttyUSB0 -b115200

network wifi STA

import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('<your ESSID>', '<your password>')
sta_if.ifconfig()
('192.168.2.32', '255.255.255.0', '192.168.2.1', '192.168.2.1')

enable webrepl

import webrepl_setup

reboot and connect to webrepl using http://micropython.org/webrepl/

main

ampy -p /dev/ttyUSB0 put blink.py /main.py

led

from machine import Pin
from time import sleep
# GPIO16 (D0) is the internal LED for NodeMCU
led = Pin(16, Pin.OUT)
# The internal LED turn on when the pin is LOW
while True:
led.value(not led.value())
#led.on()
sleep(1)
#led.off()
#sleep(1)

jupyter

sudo apt install python3-venv
mkdir <path_to_project>
cd <path_to_project>
python3 -mvenv lib
source lib/bin/activate
pip install -U pip wheel jupyter

tensor flow

pip install tensorflow

daily job

cd <path_to_project>
source lib/bin/activate
jupyter notebook

https://github.com/goatchurchprime/jupyter_micropython_kernel/

git clone https://github.com/goatchurchprime/jupyter_micropython_kernel.git
pip install -e jupyter_micropython_kernel
python -m jupyter_micropython_kernel.install

widgets

pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension

turtle docs

pip install https://github.com/takluyver/mobilechelonian/archive/master.zip

run jupyter

jupyter notebook