Micropython el sílice y la serpiente
-
Upload
jose-lucas-grillo-lorenzo -
Category
Technology
-
view
87 -
download
2
Transcript of Micropython el sílice y la serpiente
![Page 1: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/1.jpg)
MicropythonEl sílice y la serpiente
Por J. Lucas Grillo Lorenzo (aka @enenNN)
![Page 2: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/2.jpg)
¿Qué es micropython?
“Es una implementación del lenguaje de programación Python 3, que está optimizada para ejecutarse en
microcontroladores.” Wikipedia
micropython.org
![Page 3: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/3.jpg)
¿Qué librerías incluye?Librerías importables con micropython
● machine Pin, PWM, ADC, UART, Timer, I2C, SPI, WDT● network (Conectividad WiFi)● time sleep_ms, etc.● esp (ESP8266)
![Page 4: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/4.jpg)
Hardware: el hábitat de la pitónida enanaPyBoard
Arduino
BBC Micro bit (2016)
FiPy / GPy (pre-order apr. 2017)
ESP8266
ESP32 (WiFi+BLE)
![Page 5: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/5.jpg)
ESP8266: el hábitat de nuestra pitónida enana
Las placas electrónicas de prototipado Wemos D1 ESP8266 WiFi
Bajo coste - ~4-7€
Bajo consumo - ideal con baterías
Con conectividad WiFi
![Page 6: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/6.jpg)
ESP8266: el hábitat de nuestra pitónida enana
Guía de referencia rápida para los ESP8266
![Page 7: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/7.jpg)
La terminal REPL (Read Evaluate Print Loop)● “Flashear” Wemos D1 mini con imagen de micropython (1.8.7)● Comunicación por cable serial ttyUSB● Interfaz interactiva mediante minicom● Carga de programas main.py con mpfshell
![Page 8: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/8.jpg)
La terminal REPL (Read Evaluate Print Loop)● Mediante minicom ● Conecta al puerto /dev/ttyUSB0 ● Debe aparecer el prompt de micropython al pulsar <ENTER>:
Welcome to minicom 2.7
OPCIONES: I18nCompilado en Feb 7 2016, 13:37:27.Port /dev/ttyUSB0, 13:02:10
Presione CTRL-A Z para obtener ayuda sobre teclas especiales
>>>
minicom -D /dev/ttyUSB0
![Page 9: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/9.jpg)
Sistema de ficheros interno● Usando vfs (<TAB> autocompleta)● Los ESPs con >1MB incluyen un pequeño FS
>>> vfs.mkfs open listdir mkdirrmdir chdir getcwd removerename stat statvfs umount
![Page 10: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/10.jpg)
Previo a ejercicios: subir programas uPythonInstala la herramienta mpfshell:
virtualenv microenvsource microenv/bin/activatepip3 install pyserialpip3 install coloramapip3 install websocket_client
![Page 11: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/11.jpg)
Previo a ejercicios: subir programas uPythonCarga fichero main.py con mpfshell:
Compruébalo:
mpfshell -n -c "open ttyUSB0; put myscript.py main.py"
mpfshell -n -c "open ttyUSB0"mpfshell> ls main.py
![Page 12: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/12.jpg)
Básicas sobre una interfaz GPIOhttps://docs.micropython.org/en/latest/esp8266/library/machine.html
D0 IO 16
D1 IO 5
D2 IO 4
D3 IO, 0
D4 IO, LED 2
D5 IO, CLK 14
D6 IO, MISO 12
D7 IO, RX, MOSI 13
D8 IO, TX, CS 15
A0 Analog input A0
![Page 13: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/13.jpg)
Interfaz hardware: digital / analógica
from machine import Pin, ADCled = Pin(5, Pin.OUT)boton = Pin(4, Pin.IN, Pin.PULL_UP)sensor = ADC(0)while True:
print("sensor de luz: {}".format(sensor))if sensor.read() < 512:
led.low() if boton.value()else:
led.high()
![Page 14: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/14.jpg)
Regulación de voltaje con modulación PWMModulación de pulsos cuadrados PWM
![Page 15: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/15.jpg)
Extras: Flasheando una Wemos D1 mini
Tutorial oficial para programar una placa ESP8266 mediante cable USB
![Page 16: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/16.jpg)
Más detalles en:Tutorial oficial de micropython ESP8266
● Una terminal mediante WiFi con WebREPL● Reduciendo consumo● Dispositivos periféricos 1-wire, I2C● Optimización de código
![Page 17: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/17.jpg)
Ejercicio: Para quienes deseen optar a ECTS● Usando micros compatibles que consigas ó http://micropython.org/live/● Escribe un programa original que haga uso de al menos 3 de las
siguientes características:○ Salida de mensajes por la termina +1○ Uno o más dispositivos de salida digital (u opcionalmente usando PWM) +2○ Al menos:
■ O bien, uno o varios dispositivos de entrada (digital o analógico) +1■ O un periférico, por ejemplo usando I2C, SPI, 1-wire, etc. +2
○ Al menos:■ O bien, Timers +1■ O, RTC u otras funciones de sleep +3
● Extras opcionales: funciones de red,
![Page 18: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/18.jpg)
Turno para preguntas
Gracias por tu atención
![Page 19: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/19.jpg)
Gracias por su atención
![Page 20: Micropython el sílice y la serpiente](https://reader033.fdocument.pub/reader033/viewer/2022050800/58d0e7f71a28abba558b55a9/html5/thumbnails/20.jpg)
Algunas referencias● Tutorial de micropython ESP8266● Cargar ficheros y ejecutar código (Guía de Adafruit)
○ mpfshell para ESP8266