Difference between revisions of "MicroPython"
TimGremalm (talk | contribs) (Created page with "=MicroPython= <blockquote>a software implementation of the Python 3 programming language, written in C, that is optimized to run on a microcontroller</blockquote> File:Micro...") |
TimGremalm (talk | contribs) |
||
Line 94: | Line 94: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Connect through websocket= | =Connect through WEBrepl (websocket)= | ||
[https://micropython.org/webrepl/ https://micropython.org/webrepl/] | [https://micropython.org/webrepl/ https://micropython.org/webrepl/] | ||
Line 102: | Line 102: | ||
import webrepl_setup | import webrepl_setup | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=ampy= | |||
[https://github.com/adafruit/ampy https://github.com/adafruit/ampy] | |||
a file utility tool for MicroPython on ESP8266 | |||
=Workshop resources= | |||
*[http://tim.gremalm.se/twitter.php http://tim.gremalm.se/twitter.php] | |||
*[http://tim.gremalm.se/random.php http://tim.gremalm.se/random.php] |
Revision as of 06:27, 22 April 2018
MicroPython
a software implementation of the Python 3 programming language, written in C, that is optimized to run on a microcontroller
https://docs.micropython.org/en/latest/pyboard/
NodeMCU Devkit
- ESP8266 a microcontroller from Espressif
- Integrated WiFi
- 80MHz clock speed
Install
http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/intro.html#deploying-the-firmware
http://micropython.org/download#esp8266 <syntaxhighlight lang="bash"> wget http://micropython.org/resources/firmware/esp8266-20171101-v1.9.3.bin pip install esptool esptool.py --port /dev/ttyUSB0 write_flash 0 esp8266-20171101-v1.9.3.bin </syntaxhighlight>
<syntaxhighlight lang="bash"> esptool.py --port /dev/ttyUSB0 erase_flash </syntaxhighlight>
<syntaxhighlight lang="bash"> esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m 0 esp8266-20171101-v1.9.3.bin </syntaxhighlight>
Connect through serial
<syntaxhighlight lang="bash"> screen /dev/ttyUSB0 115200 </syntaxhighlight> Stäng screen: Ctrl+A, k, y
Connect to WiFi
http://docs.micropython.org/en/v1.8.7/esp8266/esp8266/tutorial/network_basics.html
<syntaxhighlight lang="bash"> import network
ap_if = network.WLAN(network.AP_IF) ap_if.disconnect()
sta_if = network.WLAN(network.STA_IF) sta_if.active(True)
sta_if.connect('SSID', 'password') </syntaxhighlight>
<syntaxhighlight lang="bash"> sta_if.ifconfig() </syntaxhighlight>
HTTP GET
<syntaxhighlight lang="bash"> import urequests response = urequests.get("http://tim.gremalm.se/hello") response.text response.close() </syntaxhighlight>
WS2812
http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/neopixel.html <syntaxhighlight lang="bash"> from machine import Pin from neopixel import NeoPixel
np = neopixel.NeoPixel(machine.Pin(2), 3)
np[0] = (255, 0, 0) np[1] = (0, 128, 0) np[2] = (0, 0, 64) np.write() </syntaxhighlight>
GPIO
https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/pins.html <syntaxhighlight lang="bash"> from machine import Pin button = Pin(0) button = Pin(0, machine.Pin.IN, machine.Pin.PULL_UP) pin.value() </syntaxhighlight> [1]
File system on flash
<syntaxhighlight lang="bash"> import os os.listdir() os.remove('filename') </syntaxhighlight>
Connect through WEBrepl (websocket)
https://micropython.org/webrepl/
https://learn.adafruit.com/micropython-basics-esp8266-webrepl/access-webrepl
<syntaxhighlight lang="bash"> import webrepl_setup </syntaxhighlight>
ampy
https://github.com/adafruit/ampy
a file utility tool for MicroPython on ESP8266