SlideShare a Scribd company logo
Globalcode – Open4education
Trilha – Arduino e Makers
Relsi Maron
Programando o ESP8266 com Python
Globalcode – Open4education
Quem?
- Programador
- 7 Anos no teclado
- 3 Anos num relacionamento sério com Python
- http://github.com/relsi
- http://pt.slideshare.net/relsi
- http://linkedin.com/in/relsi
- http://ikebanacw.com
Globalcode – Open4education
Para quem?
Globalcode – Open4education
Por que Python?
Globalcode – Open4education
Por que Python?
Globalcode – Open4education
Por que Python?
Globalcode – Open4education
Por que Python?
Bonito é melhor que feio.
Explícito é melhor que implícito.
Simples é melhor que complexo.
Complexo é melhor que complicado.
Linear é melhor do que aninhado.
Esparso é melhor que denso.
Legibilidade conta.
Casos especiais não são especiais o bastante para quebrar as regras.
Ainda que praticidade vença a pureza.
Erros nunca devem passar silenciosamente.
A menos que sejam explicitamente silenciados.
Diante da ambigüidade, recuse a tentação de adivinhar.
Deveria haver um — e preferencialmente só um — modo óbvio para fazer algo.
Embora esse modo possa não ser óbvio a princípio a menos que você seja holandês.
Agora é melhor que nunca.
Embora nunca freqüentemente seja melhor que *já*.
Se a implementação é difícil de explicar, é uma má idéia.
Se a implementação é fácil de explicar, pode ser uma boa idéia.
Namespaces são uma grande idéia — vamos ter mais dessas!
Globalcode – Open4education
Por que Python?
Globalcode – Open4education
Por que Python?
Globalcode – Open4education
Por que Python?
- Linguagem de altíssimo nível (VHLL)
- Criada por Guido van Rossum em 1991
- Interpretada e interativa
- Multiplataforma
- Multipropósito
- Muito Foda
Globalcode – Open4education
ESP8266
- 32-bit RISC CPU 80 MHz
- 64 KiB RAM, 96 KiB of data RAM
- External QSPI flash - 512 KiB to 4 MiB
- IEEE 802.11 b/g/n Wi-Fi
- WEP/WPA/WPA2
- 16 GPIO pins
- SPI, I²C,
- UART
Globalcode – Open4education
ESP8266
Globalcode – Open4education
Por que ESP8266?
Globalcode – Open4education
Por que ESP8266?
Globalcode – Open4education
Por que ESP8266?
Globalcode – Open4education
Porque roda Python! =D
Globalcode – Open4education
Micropython
MicroPython is a lean
and efficient implementation
of the Python 3
programming language
that includes a small subset
of the Python standard library
and is optimised to run on microcontrollers
and in constrained environments.
http://www.micropython.org/
Globalcode – Open4education
MicroPython
- STM32F405RG microcontroller
- 168 MHz Cortex M4 CPU
- 1024KiB flash ROM and 192KiB RAM
- Micro USB connector
- Micro SD card slot
- 3-axis accelerometer (MMA7660)
- Real time clock with optional battery backup
- 24 GPIO on left and right edges
- 5 GPIO on bottom row
- 3x 12-bit analog to digital converters
- 2x 12-bit digital to analog (DAC) converters
- 4 LEDs (red, green, yellow and blue)
- 1 reset and 1 user switch
- On-board 3.3V LDO voltage regulator,
capable of supplying up to 250mA,
input voltage range 3.6V to 16V
- DFU bootloader in ROM
Globalcode – Open4education
- array – arrays of numeric data
- Builtin Functions
- gc – control the garbage collector
- math – mathematical functions
- sys – system specific functions
- ubinascii – binary/ASCII conversions
- ucollections – collection and container types
- uhashlib – hashing algorithm
- uheapq – heap queue algorithm
- uio – input/output streams
- ujson – JSON encoding and decoding
- uos – basic “operating system” services
- ure – regular expressions
- usocket – socket module
- ussl – ssl module
- ustruct – pack and unpack primitive data types
- utime – time related functions
- uzlib – zlib decompression
MicroPython
Standard libraries
https://goo.gl/w1Q3Yy
Globalcode – Open4education
- machine — functions related to the board
- micropython – access and control MicroPython internals
- network — network configuration
- uctypes – access binary data in a structured way
- esp — functions related to the ESP8266
MicroPython
Specific libraries
https://goo.gl/w1Q3Yy
Globalcode – Open4education
import machine
machine.freq() # get the current frequency of the CPU
machine.freq(160000000) # set the CPU frequency to 160 MHz
MicroPython
Módulo machine
https://goo.gl/8hCppg
Globalcode – Open4education
from machine import Pin
p0 = Pin(0, Pin.OUT) # create output pin on GPIO0
p0.high() # set pin to high
p0.low() # set pin to low
p0.value(1) # set pin to high
p2 = Pin(2, Pin.IN) # create input pin on GPIO2
print(p2.value()) # get value, 0 or 1
p4 = Pin(4, Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor
p5 = Pin(5, Pin.OUT, value = 1) # set pin high on creation
MicroPython
Módulo machine
https://goo.gl/8hCppg
Globalcode – Open4education
import network
wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(True) # activate the interface
wlan.scan() # scan for access points
wlan.isconnected() # check if the station is connected to an AP
wlan.connect('essid', 'password') # connect to an AP
wlan.config('mac') # get MAC adddress
wlan.ifconfig() # get the interface's
#IP/netmask/gw/DNS
MicroPython
Módulo network
https://goo.gl/8hCppg
Globalcode – Open4education
import network
ap = network.WLAN(network.AP_IF) # create access-point interface
ap.active(True) # activate the interface
ap.config(essid='ESP-AP') # set the ESSID of the access point
MicroPython
Módulo network
https://goo.gl/8hCppg
Globalcode – Open4education
ESP8266 + MicroPython
Preparando o Terreno
Globalcode – Open4education
ESP8266 + MicroPython
Globalcode – Open4education
ESP8266 + MicroPython
Globalcode – Open4education
ESP8266 + MicroPython
http://pedrominatel.com.br/arduino/utilizando-o-arduino-para-programar-o-esp/
Globalcode – Open4education
ESP8266 + MicroPython
https://goo.gl/FtgaJ7
Globalcode – Open4education
ESP8266 + MicroPython
Gravando o firmware
Globalcode – Open4education
ESP8266 + MicroPython
Gravando o firmware
Verificar a porta do dispositivo
$ lsusb
Bus 001 Device 006: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART...
$ dmesg | grep USB
usb 1-1: cp210x converter now attached to ttyUSB0
Instalar o esptool
$ pip install esptool
Ou
$ git clone https://github.com/themadinventor/esptool.git
Python 2.7
Globalcode – Open4education
ESP8266 + MicroPython
Gravando o firmware
Apagar o firmware atual
$ esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py v1.1
Connecting...
Erasing flash (this may take a while)...
$ esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=8m -fm
dio 0 esp8266-20160909-v1.8.4.bin
Connecting...
Running Cesanta flasher stub...
Flash params set to 0x0220
Writing 565248 @ 0x0... 565248 (100 %)
Wrote 565248 bytes at 0x0 in 12.7 seconds (357.1 kbit/s)...
Leaving...
Globalcode – Open4education
ESP8266 + MicroPython
Acessando
Globalcode – Open4education
https://github.com/micropython/webrepl
ESP8266 + MicroPython
Acessando
Globalcode – Open4education
ESP8266 + MicroPython
Acessando
Globalcode – Open4education
ESP8266 + MicroPython
Acessando
Globalcode – Open4education
ESP8266 + MicroPython
Acessando
http://esp8266.ru/esplorer/
Globalcode – Open4education
ESP8266 + MicroPython
Hello World
def blink():
import time
import machine
pin = machine.Pin(5, machine.Pin.OUT)
while True:
pin.high()
time.sleep(1)
pin.low()
time.sleep(1)
Globalcode – Open4education
ESP8266 + MicroPython
Controlando
def lampada(estado):
import machine
pin = machine.Pin(5, machine.Pin.OUT)
if estado == 1:
pin.high()
elif estado == 0:
pin.low()
Globalcode – Open4education
ESP8266 + MicroPython
Monitorando
def medida(tipo):
import dht
import machine
d = dht.DHT11(machine.Pin(4))
d.measure()
if tipo == 't':
r = d.temperature()
print(str(r) + ' °C')
elif tipo == 'h':
r = d.humidity()
print(str(r) + ' %RH')
Globalcode – Open4education
Ajuda
Referência
Tutorial
https://goo.gl/LVKXn9
https://goo.gl/Fw9wPD
Biblioteca
https://goo.gl/9s6DS8
Fórum
http://forum.micropython.org/
Globalcode – Open4education
Perguntas?
Obrigado pela atenção! :)
- http://github.com/relsi
- http://pt.slideshare.net/relsi
- http://linkedin.com/in/relsi
- http://ikebanacw.com

More Related Content

PDF
ESP8266 and IOT
PDF
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
PDF
lwM2M OTA for ESP8266
PDF
Adafruit Huzzah Esp8266 WiFi Board
PPTX
Esp8266 Workshop
PPTX
Esp8266 - Intro for dummies
PDF
NodeMCU with Blynk and Firebase
PDF
Esp8266 hack sonoma county 4/8/2015
ESP8266 and IOT
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
lwM2M OTA for ESP8266
Adafruit Huzzah Esp8266 WiFi Board
Esp8266 Workshop
Esp8266 - Intro for dummies
NodeMCU with Blynk and Firebase
Esp8266 hack sonoma county 4/8/2015

What's hot (19)

PDF
Cassiopeia Ltd - ESP8266+Arduino workshop
PDF
lesson1 - Getting Started with ESP8266
PDF
WiFi SoC ESP8266
PPTX
Esp8266 NodeMCU
PPTX
Build WiFi gadgets using esp8266
PPTX
Nodemcu - introduction
PDF
NodeMCU ESP8266 workshop 1
PDF
How to Install ESP8266 WiFi Web Server using Arduino IDE
PDF
Esp8266 basics
PDF
Node MCU Fun
PDF
Home automation-in-the-cloud-with-the-esp8266-and-adafruit-io
PPTX
Remote tanklevelmonitor
PDF
lesson2 - Nodemcu course - NodeMCU dev Board
PDF
Introduction to ESP32 Programming [Road to RIoT 2017]
PPTX
Programming esp8266
PPTX
Arduino & NodeMcu
PDF
Home Automation by ESP8266
PPTX
IoT Hands-On-Lab, KINGS, 2019
PDF
Making wearables with NodeMCU - FOSDEM 2017
Cassiopeia Ltd - ESP8266+Arduino workshop
lesson1 - Getting Started with ESP8266
WiFi SoC ESP8266
Esp8266 NodeMCU
Build WiFi gadgets using esp8266
Nodemcu - introduction
NodeMCU ESP8266 workshop 1
How to Install ESP8266 WiFi Web Server using Arduino IDE
Esp8266 basics
Node MCU Fun
Home automation-in-the-cloud-with-the-esp8266-and-adafruit-io
Remote tanklevelmonitor
lesson2 - Nodemcu course - NodeMCU dev Board
Introduction to ESP32 Programming [Road to RIoT 2017]
Programming esp8266
Arduino & NodeMcu
Home Automation by ESP8266
IoT Hands-On-Lab, KINGS, 2019
Making wearables with NodeMCU - FOSDEM 2017
Ad

Viewers also liked (20)

PDF
Transforme ideias em realidade com python e web2py
PDF
Multirão Python - introdução ao py serial com gtk3 e arduino
PDF
Desenvolvimento web com python e web2py
PDF
Desenvolvimento de Jogos com Software Livre
PDF
Produção Audiovisual com Software Livre
PDF
Automação Residencial com Python e Arduino - PySM 2015
PDF
Desenvolvimento web ágil com python e web2py
PDF
Arduino + Python: produtividade ao extremo
PDF
Apresentando a Godot Game Engine no FISL 16
PDF
Apunte c a_bajo_nivel
PDF
Memoria dinámica en el lenguaje de programación c
PPTX
Basededatosicompleto 091122141836-phpapp02
PPT
Isaac Asimov
PDF
Desenvolvendo games com ferramentas livres
ODP
Desenvolvendo aplicações web com python e web2py
PDF
Programação ara não programadores com python e web2py
PPSX
robotics and its components
PDF
Desenvolvimento web com python e web2py
PDF
AVR_Course_Day5 avr interfaces
Transforme ideias em realidade com python e web2py
Multirão Python - introdução ao py serial com gtk3 e arduino
Desenvolvimento web com python e web2py
Desenvolvimento de Jogos com Software Livre
Produção Audiovisual com Software Livre
Automação Residencial com Python e Arduino - PySM 2015
Desenvolvimento web ágil com python e web2py
Arduino + Python: produtividade ao extremo
Apresentando a Godot Game Engine no FISL 16
Apunte c a_bajo_nivel
Memoria dinámica en el lenguaje de programación c
Basededatosicompleto 091122141836-phpapp02
Isaac Asimov
Desenvolvendo games com ferramentas livres
Desenvolvendo aplicações web com python e web2py
Programação ara não programadores com python e web2py
robotics and its components
Desenvolvimento web com python e web2py
AVR_Course_Day5 avr interfaces
Ad

Similar to Programando o ESP8266 com Python (20)

PDF
Getting Started with Embedded Python: MicroPython and CircuitPython
PDF
Micropython on MicroControllers
PDF
PyCon_India_2017_MicroPython_Ayan
PPTX
Python-in-Embedded-systems.pptx
PDF
Iot Bootcamp - abridged - part 1
PDF
MicroPython Introduction PUSG July 2017
PDF
Intro to the raspberry pi board
ODP
MicroPython&electronics prezentācija
PDF
Get Starte with MicroPython ESP32
PDF
Get Started with MicroPython ESP32
PDF
Micropython for the iot
PDF
Hardware Open Source
DOCX
Bcs ii revised syllabus 2022 modified
PPTX
Raspberry_Pi_4B for robotics, home automation
PPTX
Raspberry pi overview
PDF
Smart Projects With Arduino And Esp32 Integrating Artificial Intelligence Abd...
PDF
Introduction to Raspberry Pi
PDF
Raspberry Pi - best friend for all your GPIO needs
PPTX
Arduino
PDF
Arduino bộ vi điều khiển cho tất cả chúng ta part 1
Getting Started with Embedded Python: MicroPython and CircuitPython
Micropython on MicroControllers
PyCon_India_2017_MicroPython_Ayan
Python-in-Embedded-systems.pptx
Iot Bootcamp - abridged - part 1
MicroPython Introduction PUSG July 2017
Intro to the raspberry pi board
MicroPython&electronics prezentācija
Get Starte with MicroPython ESP32
Get Started with MicroPython ESP32
Micropython for the iot
Hardware Open Source
Bcs ii revised syllabus 2022 modified
Raspberry_Pi_4B for robotics, home automation
Raspberry pi overview
Smart Projects With Arduino And Esp32 Integrating Artificial Intelligence Abd...
Introduction to Raspberry Pi
Raspberry Pi - best friend for all your GPIO needs
Arduino
Arduino bộ vi điều khiển cho tất cả chúng ta part 1

Recently uploaded (20)

PPTX
ERP good ERP good ERP good ERP good good ERP good ERP good
PPTX
Final Draft Presentation for dtaa and direct tax
PPTX
sample 1mathssscpreprationfor basics.PPTX
PDF
Core Components of IoT, The elements need for IOT
PDF
YKS Chrome Plated Brass Safety Valve Product Catalogue
PPTX
udi-benefits-ggggggggfor-healthcare.pptx
PPTX
VERB TO BE_SERPA YORDY.pptxvhyjjkjjjjjjuuj
PDF
DOC-20250802-WA0013._20250802_161719_0000.pdf
PPT
L1-Intro.ppt nhfjkhghjjnnnmkkjhigtyhhjjj
PPT
Welcome-to-Information-Technology.pptx.ppt
PPTX
Eco-DROPLETS (1).pptx {watering smarter,not harder
PPTX
dhcp concept.pptxfeegrvewfegrgerhtrhtrhredew
PPTX
title _yeOPC_Poisoning_Presentation.pptx
PPTX
Disorders of the anterior horn cells.pptx
PPTX
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
PPTX
English grade 10 st augusitne eoeoknkklm
PPTX
INFERTILITY (FEMALE FACTORS).pptxgvcghhfcg
PPTX
sdn_based_controller_for_mobile_network_traffic_management1.pptx
PPT
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
PPTX
ATL_Arduino_Complete_Presentation_AI_Visuals.pptx
ERP good ERP good ERP good ERP good good ERP good ERP good
Final Draft Presentation for dtaa and direct tax
sample 1mathssscpreprationfor basics.PPTX
Core Components of IoT, The elements need for IOT
YKS Chrome Plated Brass Safety Valve Product Catalogue
udi-benefits-ggggggggfor-healthcare.pptx
VERB TO BE_SERPA YORDY.pptxvhyjjkjjjjjjuuj
DOC-20250802-WA0013._20250802_161719_0000.pdf
L1-Intro.ppt nhfjkhghjjnnnmkkjhigtyhhjjj
Welcome-to-Information-Technology.pptx.ppt
Eco-DROPLETS (1).pptx {watering smarter,not harder
dhcp concept.pptxfeegrvewfegrgerhtrhtrhredew
title _yeOPC_Poisoning_Presentation.pptx
Disorders of the anterior horn cells.pptx
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
English grade 10 st augusitne eoeoknkklm
INFERTILITY (FEMALE FACTORS).pptxgvcghhfcg
sdn_based_controller_for_mobile_network_traffic_management1.pptx
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
ATL_Arduino_Complete_Presentation_AI_Visuals.pptx

Programando o ESP8266 com Python