Actions

Difference between revisions of "MircoPython"

From Chalmers Robotics

(Created page with "=NodeMCU Devkit= File:Nodemcu.jpg [https://docs.micropython.org/en/latest/pyboard/] =Install= http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/intro.html#d...")
 
Line 1: Line 1:
 
=NodeMCU Devkit=
 
=NodeMCU Devkit=
 
[[File:Nodemcu.jpg]]
 
[[File:Nodemcu.jpg]]
 +
*ESP8266 a microcontroller from Espressif
 +
*Integrated WiFi
 +
*80MHz clock speed
  
[https://docs.micropython.org/en/latest/pyboard/]
+
=MicroPython=
 +
[https://docs.micropython.org/en/latest/pyboard/ https://docs.micropython.org/en/latest/pyboard/]
  
 
=Install=
 
=Install=
http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/intro.html#deploying-the-firmware
+
[http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/intro.html#deploying-the-firmware http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/intro.html#deploying-the-firmware]
  
http://micropython.org/download#esp8266
+
[http://micropython.org/download#esp8266 http://micropython.org/download#esp8266]
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
wget http://micropython.org/resources/firmware/esp8266-20171101-v1.9.3.bin
 
wget http://micropython.org/resources/firmware/esp8266-20171101-v1.9.3.bin
Line 29: Line 33:
  
 
=Connect to WiFi=
 
=Connect to WiFi=
http://docs.micropython.org/en/v1.8.7/esp8266/esp8266/tutorial/network_basics.html
+
[http://docs.micropython.org/en/v1.8.7/esp8266/esp8266/tutorial/network_basics.html http://docs.micropython.org/en/v1.8.7/esp8266/esp8266/tutorial/network_basics.html]
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 57: Line 61:
  
 
=WS2812=
 
=WS2812=
http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/neopixel.html
+
[http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/neopixel.html http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/neopixel.html]
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
from machine import Pin
 
from machine import Pin
 
 
from neopixel import NeoPixel
 
from neopixel import NeoPixel
  
Line 72: Line 75:
  
 
=GPIO=
 
=GPIO=
[https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/pins.html]
+
[https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/pins.html https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/pins.html]
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
from machine import Pin
 
from machine import Pin
Line 83: Line 86:
  
 
=File system on flash=
 
=File system on flash=
 +
<syntaxhighlight lang="bash">
 
import os
 
import os
 
os.listdir()
 
os.listdir()
Line 89: Line 93:
  
 
=Connect through websocket=
 
=Connect through websocket=
[https://micropython.org/webrepl/]
+
[https://micropython.org/webrepl/ https://micropython.org/webrepl/]
[https://learn.adafruit.com/micropython-basics-esp8266-webrepl/access-webrepl]
+
[https://learn.adafruit.com/micropython-basics-esp8266-webrepl/access-webrepl https://learn.adafruit.com/micropython-basics-esp8266-webrepl/access-webrepl]
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
import webrepl_setup
 
import webrepl_setup
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 04:18, 22 April 2018

NodeMCU Devkit

Nodemcu.jpg

  • ESP8266 a microcontroller from Espressif
  • Integrated WiFi
  • 80MHz clock speed

MicroPython

https://docs.micropython.org/en/latest/pyboard/

Install

http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/intro.html#deploying-the-firmware

http://micropython.org/download#esp8266

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
esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m 0 esp8266-20171101-v1.9.3.bin

Connect through serial

screen /dev/ttyUSB0 115200

Stäng screen: Ctrl+A, k, y

Connect to WiFi

http://docs.micropython.org/en/v1.8.7/esp8266/esp8266/tutorial/network_basics.html

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')
sta_if.ifconfig()

HTTP GET

import urequests
response = urequests.get("http://tim.gremalm.se/hello")
response.text
response.close()


WS2812

http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/neopixel.html

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()

GPIO

https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/pins.html

from machine import Pin
button = Pin(0)
button = Pin(0, machine.Pin.IN, machine.Pin.PULL_UP)
pin.value()

[1] NodeMCUPinout.png

File system on flash

import os
os.listdir()
os.remove('filename')

Connect through websocket

https://micropython.org/webrepl/ https://learn.adafruit.com/micropython-basics-esp8266-webrepl/access-webrepl

import webrepl_setup