SlideShare a Scribd company logo
MicroPython
with LoPy
Getting started workshop @ MakeZurich
2.2.2017
Christian Fässler
What is MicroPython
• Python for Microcontrollers
• Lean implementation of Python 3
• Subset of standard lib
• Needs
• 256k code space
• 16k RAM
What is a LoPy
• ESP32 Board
• 160 MHz CPU
• 512k RAM
• 4 MB Flash for user code
• I2C, SPI, UART, I2C
• SD Card
• 8 ADC Channels
• 24 GPIOs
• RTC
• WS2812 LED
• Wireless connectivity
• Bluetooth 4.2 (BLE & Classic)
• LoRa (Semtech’s SX1272)
• WiFi
Tooling
• Batteries included!
• Firmware upgrade tool
• PyMakr IDE
• PyMate mobile App
• Based on MQTT
• Soon: cloud service
• Code upload via
• Built-in FTP/telnet Server
• Serial connection
First thing to do
• Install Pycom updater
• https://www.pycom.io/support/supportdownloads
• Firmware Upgrade!
• Almost weekly releases
with new features
• Check http://forum.pycom.io
Announcement topic
Connect to Device REPL
• PyMaker IDE
• Settings/Preferences/Pycom Device
• Directly via serial port
• 8N1 / 115200 Baud
• screen /dev/tty... 115200
• putty
• WiFi
• SSID: lopy-wlan-XXXX
• Password: www.pycom.io
• Telnet 192.168.4.1
Hello World!
>>>  import pycom
>>>  pycom.heartbeat(False)
>>>  pycom.rgbled(0xFF0000)
>>>  print(‘Hello World’)
• REPL (read-evaluate-print-loop)
• Interactive interpreter (>>>)
• pycom.rgbled(0xRRGGBB)
Primer on Python
• Variables
• Functions
text =  ‘Dont forget your towel!’
number =  42
floatingnumber =  13.37
def print_text(name,  age):
text =  "My name is {0}  and I’m {1}  years old"
print(text.format(name,  age))
Primer on Python (math)
• Addition, Subtraction, Division, Multiplication,
exponentiation
12+34
3*3
16/2
(3+1)*(4+5)
5**2  #5  to the power  of 2
‘spam’*3  #spamspamspam
Primer on Python (useful built-ins)
• print(text)  – Print text
• int(text)  – «cast» text to int
• type(obj)  – Get type of object
• input(prompt)  – Read from stdin return value as string
Primer on Python (containers)
• Lists
• mylist =  [1,2,3,4]
• mylist.append(5)
• mylist.remove(2)
• Dictionaries
• mydict =  {‘name’:  ‘zaphod beeblebrox’,  ‘heads’:1}
• mydict[‘heads’]  =  2
Primer on Python (control structs)
if value ==  True:
print(‘value is true’)
else:
print(‘value is false’)
while True:
do_whatever_is_to_do()
for i  in  range(10):
print(‘{0}-­‐th run’.format(i))
Time Module
import time
time.sleep(10)  #sleep 10  seconds
time.sleep_ms(200)  #sleep 200  milliseconds
Exercises
• Create a function which changes the LED
color from red to blue every 1s
• Create a function which asks for your
weight and your body size and calculates
BMI = weight (kg) divided by size2 (m)
Primer on Python (modules)
• Files are treated as modules
• Stuff is imported from modules
• Stuff needs to be imported to be used
• File lib.py contains function connect()
#  use lib
from lib import print_name
print_name()
#  lib.py
def print_name(name):
print(‘-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐’)
print(name)
print(‘-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐’)
More on Python
• Lots of tutorials
• https://docs.pycom.io
• https://learnpythonthehardway.org/
• http://docs.python-guide.org/en/latest/
GPIO output
from machine import Pin
#  initialize ``P9``  in  gpio mode and make it an  output
p_out =  Pin('P9',  mode=Pin.OUT)
p_out.value(1)
p_out.value(0)
GPIO input
from machine import Pin
#  initialize ``P10``  in  gpio mode and make it an  input
p_in =  Pin('P10',  mode=Pin.IN,  pull=Pin.PULL_UP)
p_in.value()  #  get  value,  0  or  1
GPIO with interrupts
from machine import Pin
#  initialize ``P10``  in  gpio mode and make it an  input
p_in =  Pin('P10',  mode=Pin.IN,  pull=Pin.PULL_UP)
p_in.callback(Pin.IRQ_HIGH_LEVEL,  lambda  pin:  print(“ON”))
p_in.callback(Pin.IRQ_LOW_LEVEL,  lambda  pin:  print(“OFF”))
#  Pin.IRQ_HIGH_LEVEL |  Pin.IRQ_LOW_LEVEL also  possible
GPIO numbering
#  Numbering with expansion board
Pin.exp_board.G16
led =  Pin(Pin.exp_board.G16,  mode=Pin.OUT)
#  Numbering without expansion board
#  P10  is mapped to the Button
Pin.module.P9
led =  Pin(Pin.module.P9,  mode=Pin.OUT)
Pin Diagramms
• Expansion board
https://www.pycom.io/wp-
content/uploads/2016/11/expansion_v02_pi
nout.pdf
• LoPy
https://www.pycom.io/wp-
content/uploads/2016/11/lopy_pinout.pdf
Exercise
• React to button presses on P10 and turn
on/off on P9
• Do the same with interrupts!
Boot process
• /flash/boot.py
• /flash/main.py
Nice to know
• Deploy your scripts via
• telnet
• FTP
• Safe boot mode
• Firmware recovery
Hello ThingsNetwork!
• https://docs.pycom.io/pycom_esp32/pycom
_esp32/tutorial/includes/lora-abp.html
from network import LoRa
import socket
#  Initialize  LoRa in  LORAWAN  mode.
lora =  LoRa(mode=LoRa.LORAWAN)
#  join a  network using ABP  (Activation By Personalization)
lora.join(activation=LoRa.ABP,  auth=(dev_addr,  nwk_swkey,  app_swkey))
#  create a  LoRa socket
s  =  socket.socket(socket.AF_LORA,  socket.SOCK_RAW)
#  make the socket  blocking
#  (waits for the data to be sent and for the 2  receive windows to expire)
s.setblocking(True)
#  send  some data
s.send(bytes([0x01,  0x02,  0x03]))
#  make the socket  non-­‐blocking
#  (because if there's no data received it will  block  forever...)
s.setblocking(False)
#  get any data received (if any...)
data =  s.recv(64)
print(data)
Get DeviceEUI
import binascii
from network import LoRa
lora =  LoRa(mode=LoRa.LORAWAN)
devEUI =  binascii.hexlify(lora.mac())
Libraries
• https://github.com/micropython/micropython-lib
• Useful things
• urllib
• urequests
• MQTT client
What is there?
• https://docs.pycom.io/pycom_esp32/library/index.html
• I2C
• ADC / DAC
• OneWire
• PWM
• SPI
• Watchdog (WDT)
• SD Card
• Timers
• RTC
• Bluetooth GATT
• Multithreading
Thanks!
• Hope I could whet your appetite J
• If you have any questions please contact me
Our online shop with pycom products
• http://shop.adnexo.ch
Code & slides
• https://github.com/adnexo-GmbH/lopy_ws
Contact
• christian.faessler@adnexo.ch
• www.adnexo.ch
• http://twitter.com/adnexo_gmbh

More Related Content

What's hot

Network security
Network securityNetwork security
Network security
Estiak Khan
 
Token Passing in Data Communication DC25
Token Passing in Data Communication DC25Token Passing in Data Communication DC25
Token Passing in Data Communication DC25
koolkampus
 
Next generation firewall(ngfw)feature and benefits
Next generation firewall(ngfw)feature and benefitsNext generation firewall(ngfw)feature and benefits
Next generation firewall(ngfw)feature and benefits
Anthony Daniel
 
IPSec and VPN
IPSec and VPNIPSec and VPN
IPSec and VPN
Abdullaziz Tagawy
 
TLS - Transport Layer Security
TLS - Transport Layer SecurityTLS - Transport Layer Security
TLS - Transport Layer Security
ByronKimani
 
TCP/IP and UDP protocols
TCP/IP and UDP protocolsTCP/IP and UDP protocols
TCP/IP and UDP protocols
Dawood Faheem Abbasi
 
SSL & TLS Architecture short
SSL & TLS Architecture shortSSL & TLS Architecture short
SSL & TLS Architecture short
Avirot Mitamura
 
SSL/TLS
SSL/TLSSSL/TLS
SSL/TLS
Sirish Kumar
 
Tcp presentation
Tcp presentationTcp presentation
Tcp presentation
Ramla Sheikh
 
Bittorrent final seminar
Bittorrent final seminarBittorrent final seminar
Bittorrent final seminar
Chirodeep Das
 
Acl cisco
Acl ciscoAcl cisco
Acl cisco
Tapan Khilar
 
Adapting to evolving user, security, and business needs with aruba clear pass
Adapting to evolving user, security, and business needs with aruba clear passAdapting to evolving user, security, and business needs with aruba clear pass
Adapting to evolving user, security, and business needs with aruba clear pass
Aruba, a Hewlett Packard Enterprise company
 
Quality of Service
Quality of ServiceQuality of Service
Quality of Service
Abhishek Wadhwa
 
200 301-ccna
200 301-ccna200 301-ccna
200 301-ccna
Jasser Kouki
 
Kerberos
KerberosKerberos
Kerberos
Rahul Pundir
 
Secure socket layer
Secure socket layerSecure socket layer
Secure socket layer
Nishant Pahad
 
Configuring Wired 802.1x Authentication on Windows Server 2012.pdf
Configuring Wired 802.1x Authentication on Windows Server 2012.pdfConfiguring Wired 802.1x Authentication on Windows Server 2012.pdf
Configuring Wired 802.1x Authentication on Windows Server 2012.pdf
djameleddine2015
 
VPN Network
VPN NetworkVPN Network
VPN Network
Wani Zahoor
 
Difference between Routing & Routed Protocol
Difference between Routing & Routed ProtocolDifference between Routing & Routed Protocol
Difference between Routing & Routed Protocol
Netwax Lab
 
Chapter 31
Chapter 31Chapter 31
Chapter 31
Faisal Mehmood
 

What's hot (20)

Network security
Network securityNetwork security
Network security
 
Token Passing in Data Communication DC25
Token Passing in Data Communication DC25Token Passing in Data Communication DC25
Token Passing in Data Communication DC25
 
Next generation firewall(ngfw)feature and benefits
Next generation firewall(ngfw)feature and benefitsNext generation firewall(ngfw)feature and benefits
Next generation firewall(ngfw)feature and benefits
 
IPSec and VPN
IPSec and VPNIPSec and VPN
IPSec and VPN
 
TLS - Transport Layer Security
TLS - Transport Layer SecurityTLS - Transport Layer Security
TLS - Transport Layer Security
 
TCP/IP and UDP protocols
TCP/IP and UDP protocolsTCP/IP and UDP protocols
TCP/IP and UDP protocols
 
SSL & TLS Architecture short
SSL & TLS Architecture shortSSL & TLS Architecture short
SSL & TLS Architecture short
 
SSL/TLS
SSL/TLSSSL/TLS
SSL/TLS
 
Tcp presentation
Tcp presentationTcp presentation
Tcp presentation
 
Bittorrent final seminar
Bittorrent final seminarBittorrent final seminar
Bittorrent final seminar
 
Acl cisco
Acl ciscoAcl cisco
Acl cisco
 
Adapting to evolving user, security, and business needs with aruba clear pass
Adapting to evolving user, security, and business needs with aruba clear passAdapting to evolving user, security, and business needs with aruba clear pass
Adapting to evolving user, security, and business needs with aruba clear pass
 
Quality of Service
Quality of ServiceQuality of Service
Quality of Service
 
200 301-ccna
200 301-ccna200 301-ccna
200 301-ccna
 
Kerberos
KerberosKerberos
Kerberos
 
Secure socket layer
Secure socket layerSecure socket layer
Secure socket layer
 
Configuring Wired 802.1x Authentication on Windows Server 2012.pdf
Configuring Wired 802.1x Authentication on Windows Server 2012.pdfConfiguring Wired 802.1x Authentication on Windows Server 2012.pdf
Configuring Wired 802.1x Authentication on Windows Server 2012.pdf
 
VPN Network
VPN NetworkVPN Network
VPN Network
 
Difference between Routing & Routed Protocol
Difference between Routing & Routed ProtocolDifference between Routing & Routed Protocol
Difference between Routing & Routed Protocol
 
Chapter 31
Chapter 31Chapter 31
Chapter 31
 

Similar to Getting Started with MicroPython and LoPy

LCA2018 Open Hardware MiniConference: LoliBot Software
LCA2018 Open Hardware MiniConference: LoliBot SoftwareLCA2018 Open Hardware MiniConference: LoliBot Software
LCA2018 Open Hardware MiniConference: LoliBot Software
Andy Gelme
 
Iot bootcamp abridged - part 2
Iot bootcamp   abridged - part 2Iot bootcamp   abridged - part 2
Iot bootcamp abridged - part 2
Marcus Tarquinio
 
PyCourse - Self driving python course
PyCourse - Self driving python coursePyCourse - Self driving python course
PyCourse - Self driving python course
Eran Shlomo
 
Io t basic-exercises
Io t basic-exercisesIo t basic-exercises
Io t basic-exercises
Fermin Galan
 
Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)
Sebastian Witowski
 
SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgi
Takuya ASADA
 
Project Basecamp: News From Camp 4
Project Basecamp: News From Camp 4Project Basecamp: News From Camp 4
Project Basecamp: News From Camp 4
Digital Bond
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
SugumarSarDurai
 
Federated Identity for IoT with OAuth2
Federated Identity for IoT with OAuth2Federated Identity for IoT with OAuth2
Federated Identity for IoT with OAuth2
Paul Fremantle
 
Wait, IPython can do that?
Wait, IPython can do that?Wait, IPython can do that?
Wait, IPython can do that?
Sebastian Witowski
 
Iot Bootcamp - abridged - part 1
Iot Bootcamp - abridged - part 1Iot Bootcamp - abridged - part 1
Iot Bootcamp - abridged - part 1
Marcus Tarquinio
 
Python testing like a pro by Keith Yang
Python testing like a pro by Keith YangPython testing like a pro by Keith Yang
Python testing like a pro by Keith Yang
PYCON MY PLT
 
Gcrc talk
Gcrc talkGcrc talk
Gcrc talk
Tejas Dinkar
 
Porting a legacy app to python 3
Porting a legacy app to python 3Porting a legacy app to python 3
Porting a legacy app to python 3
Mark Rees
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
p3castro
 
Re: 제로부터시작하는텐서플로우
Re: 제로부터시작하는텐서플로우Re: 제로부터시작하는텐서플로우
Re: 제로부터시작하는텐서플로우
Mario Cho
 
NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1
Andy Gelme
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
Henry Schreiner
 
An Introduction to PyPy
An Introduction to PyPyAn Introduction to PyPy
An Introduction to PyPy
Michael Hudson-Doyle
 
2018 02 20-jeg_index
2018 02 20-jeg_index2018 02 20-jeg_index
2018 02 20-jeg_index
Chester Chen
 

Similar to Getting Started with MicroPython and LoPy (20)

LCA2018 Open Hardware MiniConference: LoliBot Software
LCA2018 Open Hardware MiniConference: LoliBot SoftwareLCA2018 Open Hardware MiniConference: LoliBot Software
LCA2018 Open Hardware MiniConference: LoliBot Software
 
Iot bootcamp abridged - part 2
Iot bootcamp   abridged - part 2Iot bootcamp   abridged - part 2
Iot bootcamp abridged - part 2
 
PyCourse - Self driving python course
PyCourse - Self driving python coursePyCourse - Self driving python course
PyCourse - Self driving python course
 
Io t basic-exercises
Io t basic-exercisesIo t basic-exercises
Io t basic-exercises
 
Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)
 
SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgi
 
Project Basecamp: News From Camp 4
Project Basecamp: News From Camp 4Project Basecamp: News From Camp 4
Project Basecamp: News From Camp 4
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Federated Identity for IoT with OAuth2
Federated Identity for IoT with OAuth2Federated Identity for IoT with OAuth2
Federated Identity for IoT with OAuth2
 
Wait, IPython can do that?
Wait, IPython can do that?Wait, IPython can do that?
Wait, IPython can do that?
 
Iot Bootcamp - abridged - part 1
Iot Bootcamp - abridged - part 1Iot Bootcamp - abridged - part 1
Iot Bootcamp - abridged - part 1
 
Python testing like a pro by Keith Yang
Python testing like a pro by Keith YangPython testing like a pro by Keith Yang
Python testing like a pro by Keith Yang
 
Gcrc talk
Gcrc talkGcrc talk
Gcrc talk
 
Porting a legacy app to python 3
Porting a legacy app to python 3Porting a legacy app to python 3
Porting a legacy app to python 3
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
 
Re: 제로부터시작하는텐서플로우
Re: 제로부터시작하는텐서플로우Re: 제로부터시작하는텐서플로우
Re: 제로부터시작하는텐서플로우
 
NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
 
An Introduction to PyPy
An Introduction to PyPyAn Introduction to PyPy
An Introduction to PyPy
 
2018 02 20-jeg_index
2018 02 20-jeg_index2018 02 20-jeg_index
2018 02 20-jeg_index
 

Recently uploaded

Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
APNIC
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
APNIC
 
HistorySrSec2024 daahi sadhin sgg-25.pdf
HistorySrSec2024 daahi sadhin sgg-25.pdfHistorySrSec2024 daahi sadhin sgg-25.pdf
HistorySrSec2024 daahi sadhin sgg-25.pdf
AdiySgh
 
The Principal Up-and-Coming Risks to Cloud-Based Security!
The Principal Up-and-Coming Risks to Cloud-Based Security!The Principal Up-and-Coming Risks to Cloud-Based Security!
The Principal Up-and-Coming Risks to Cloud-Based Security!
Alec Kassir cozmozone
 
Bangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
Bangalore Call Girls 9079923931 With -Cuties' Hot Call GirlsBangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
Bangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
narwatsonia7
 
peru primero de la alianza con el pacifico
peru primero de la alianza con el pacificoperu primero de la alianza con el pacifico
peru primero de la alianza con el pacifico
FernandoGuevaraVentu2
 
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
Web Inspire
 
DocSplit Subsequent Implementation Activation.pptx
DocSplit Subsequent Implementation Activation.pptxDocSplit Subsequent Implementation Activation.pptx
DocSplit Subsequent Implementation Activation.pptx
AmitTuteja9
 
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
Febless Hernane
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
thezot
 
Lesson6 in spreadsheet 2024 for g12..ppt
Lesson6 in spreadsheet 2024 for g12..pptLesson6 in spreadsheet 2024 for g12..ppt
Lesson6 in spreadsheet 2024 for g12..ppt
ReyLouieSedigo1
 
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
uqbyfm
 
KubeCon & CloudNative Con 2024 Artificial Intelligent
KubeCon & CloudNative Con 2024 Artificial IntelligentKubeCon & CloudNative Con 2024 Artificial Intelligent
KubeCon & CloudNative Con 2024 Artificial Intelligent
Emre Gündoğdu
 
cyber crime.pptx..........................
cyber crime.pptx..........................cyber crime.pptx..........................
cyber crime.pptx..........................
GNAMBIKARAO
 
Unlimited Fun With Call Girls Hyderabad ✅ 7737669865 💘 FULL CASH PAYMENT
Unlimited Fun With Call Girls Hyderabad ✅ 7737669865 💘 FULL CASH PAYMENTUnlimited Fun With Call Girls Hyderabad ✅ 7737669865 💘 FULL CASH PAYMENT
Unlimited Fun With Call Girls Hyderabad ✅ 7737669865 💘 FULL CASH PAYMENT
keshavtiwari584
 
IPv6: Unlocking the Potential, presented by Paul Wilson at CommunicAsia 2024
IPv6: Unlocking the Potential, presented by Paul Wilson at CommunicAsia 2024IPv6: Unlocking the Potential, presented by Paul Wilson at CommunicAsia 2024
IPv6: Unlocking the Potential, presented by Paul Wilson at CommunicAsia 2024
APNIC
 
India Cyber Threat Report of 2024 with year
India Cyber Threat Report of 2024 with yearIndia Cyber Threat Report of 2024 with year
India Cyber Threat Report of 2024 with year
AkashKumar1733
 
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENTUnlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
rajesh344555
 
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. ITNetwork Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Sarthak Sobti
 
Decentralized Justice in Gaming and Esports
Decentralized Justice in Gaming and EsportsDecentralized Justice in Gaming and Esports
Decentralized Justice in Gaming and Esports
Federico Ast
 

Recently uploaded (20)

Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
 
HistorySrSec2024 daahi sadhin sgg-25.pdf
HistorySrSec2024 daahi sadhin sgg-25.pdfHistorySrSec2024 daahi sadhin sgg-25.pdf
HistorySrSec2024 daahi sadhin sgg-25.pdf
 
The Principal Up-and-Coming Risks to Cloud-Based Security!
The Principal Up-and-Coming Risks to Cloud-Based Security!The Principal Up-and-Coming Risks to Cloud-Based Security!
The Principal Up-and-Coming Risks to Cloud-Based Security!
 
Bangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
Bangalore Call Girls 9079923931 With -Cuties' Hot Call GirlsBangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
Bangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
 
peru primero de la alianza con el pacifico
peru primero de la alianza con el pacificoperu primero de la alianza con el pacifico
peru primero de la alianza con el pacifico
 
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
 
DocSplit Subsequent Implementation Activation.pptx
DocSplit Subsequent Implementation Activation.pptxDocSplit Subsequent Implementation Activation.pptx
DocSplit Subsequent Implementation Activation.pptx
 
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
 
Lesson6 in spreadsheet 2024 for g12..ppt
Lesson6 in spreadsheet 2024 for g12..pptLesson6 in spreadsheet 2024 for g12..ppt
Lesson6 in spreadsheet 2024 for g12..ppt
 
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
 
KubeCon & CloudNative Con 2024 Artificial Intelligent
KubeCon & CloudNative Con 2024 Artificial IntelligentKubeCon & CloudNative Con 2024 Artificial Intelligent
KubeCon & CloudNative Con 2024 Artificial Intelligent
 
cyber crime.pptx..........................
cyber crime.pptx..........................cyber crime.pptx..........................
cyber crime.pptx..........................
 
Unlimited Fun With Call Girls Hyderabad ✅ 7737669865 💘 FULL CASH PAYMENT
Unlimited Fun With Call Girls Hyderabad ✅ 7737669865 💘 FULL CASH PAYMENTUnlimited Fun With Call Girls Hyderabad ✅ 7737669865 💘 FULL CASH PAYMENT
Unlimited Fun With Call Girls Hyderabad ✅ 7737669865 💘 FULL CASH PAYMENT
 
IPv6: Unlocking the Potential, presented by Paul Wilson at CommunicAsia 2024
IPv6: Unlocking the Potential, presented by Paul Wilson at CommunicAsia 2024IPv6: Unlocking the Potential, presented by Paul Wilson at CommunicAsia 2024
IPv6: Unlocking the Potential, presented by Paul Wilson at CommunicAsia 2024
 
India Cyber Threat Report of 2024 with year
India Cyber Threat Report of 2024 with yearIndia Cyber Threat Report of 2024 with year
India Cyber Threat Report of 2024 with year
 
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENTUnlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
 
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. ITNetwork Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
 
Decentralized Justice in Gaming and Esports
Decentralized Justice in Gaming and EsportsDecentralized Justice in Gaming and Esports
Decentralized Justice in Gaming and Esports
 

Getting Started with MicroPython and LoPy

  • 1. MicroPython with LoPy Getting started workshop @ MakeZurich 2.2.2017 Christian Fässler
  • 2. What is MicroPython • Python for Microcontrollers • Lean implementation of Python 3 • Subset of standard lib • Needs • 256k code space • 16k RAM
  • 3. What is a LoPy • ESP32 Board • 160 MHz CPU • 512k RAM • 4 MB Flash for user code • I2C, SPI, UART, I2C • SD Card • 8 ADC Channels • 24 GPIOs • RTC • WS2812 LED • Wireless connectivity • Bluetooth 4.2 (BLE & Classic) • LoRa (Semtech’s SX1272) • WiFi
  • 4. Tooling • Batteries included! • Firmware upgrade tool • PyMakr IDE • PyMate mobile App • Based on MQTT • Soon: cloud service • Code upload via • Built-in FTP/telnet Server • Serial connection
  • 5. First thing to do • Install Pycom updater • https://www.pycom.io/support/supportdownloads • Firmware Upgrade! • Almost weekly releases with new features • Check http://forum.pycom.io Announcement topic
  • 6. Connect to Device REPL • PyMaker IDE • Settings/Preferences/Pycom Device • Directly via serial port • 8N1 / 115200 Baud • screen /dev/tty... 115200 • putty • WiFi • SSID: lopy-wlan-XXXX • Password: www.pycom.io • Telnet 192.168.4.1
  • 7. Hello World! >>>  import pycom >>>  pycom.heartbeat(False) >>>  pycom.rgbled(0xFF0000) >>>  print(‘Hello World’) • REPL (read-evaluate-print-loop) • Interactive interpreter (>>>) • pycom.rgbled(0xRRGGBB)
  • 8. Primer on Python • Variables • Functions text =  ‘Dont forget your towel!’ number =  42 floatingnumber =  13.37 def print_text(name,  age): text =  "My name is {0}  and I’m {1}  years old" print(text.format(name,  age))
  • 9. Primer on Python (math) • Addition, Subtraction, Division, Multiplication, exponentiation 12+34 3*3 16/2 (3+1)*(4+5) 5**2  #5  to the power  of 2 ‘spam’*3  #spamspamspam
  • 10. Primer on Python (useful built-ins) • print(text)  – Print text • int(text)  – «cast» text to int • type(obj)  – Get type of object • input(prompt)  – Read from stdin return value as string
  • 11. Primer on Python (containers) • Lists • mylist =  [1,2,3,4] • mylist.append(5) • mylist.remove(2) • Dictionaries • mydict =  {‘name’:  ‘zaphod beeblebrox’,  ‘heads’:1} • mydict[‘heads’]  =  2
  • 12. Primer on Python (control structs) if value ==  True: print(‘value is true’) else: print(‘value is false’) while True: do_whatever_is_to_do() for i  in  range(10): print(‘{0}-­‐th run’.format(i))
  • 13. Time Module import time time.sleep(10)  #sleep 10  seconds time.sleep_ms(200)  #sleep 200  milliseconds
  • 14. Exercises • Create a function which changes the LED color from red to blue every 1s • Create a function which asks for your weight and your body size and calculates BMI = weight (kg) divided by size2 (m)
  • 15. Primer on Python (modules) • Files are treated as modules • Stuff is imported from modules • Stuff needs to be imported to be used • File lib.py contains function connect() #  use lib from lib import print_name print_name() #  lib.py def print_name(name): print(‘-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐’) print(name) print(‘-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐’)
  • 16. More on Python • Lots of tutorials • https://docs.pycom.io • https://learnpythonthehardway.org/ • http://docs.python-guide.org/en/latest/
  • 17. GPIO output from machine import Pin #  initialize ``P9``  in  gpio mode and make it an  output p_out =  Pin('P9',  mode=Pin.OUT) p_out.value(1) p_out.value(0)
  • 18. GPIO input from machine import Pin #  initialize ``P10``  in  gpio mode and make it an  input p_in =  Pin('P10',  mode=Pin.IN,  pull=Pin.PULL_UP) p_in.value()  #  get  value,  0  or  1
  • 19. GPIO with interrupts from machine import Pin #  initialize ``P10``  in  gpio mode and make it an  input p_in =  Pin('P10',  mode=Pin.IN,  pull=Pin.PULL_UP) p_in.callback(Pin.IRQ_HIGH_LEVEL,  lambda  pin:  print(“ON”)) p_in.callback(Pin.IRQ_LOW_LEVEL,  lambda  pin:  print(“OFF”)) #  Pin.IRQ_HIGH_LEVEL |  Pin.IRQ_LOW_LEVEL also  possible
  • 20. GPIO numbering #  Numbering with expansion board Pin.exp_board.G16 led =  Pin(Pin.exp_board.G16,  mode=Pin.OUT) #  Numbering without expansion board #  P10  is mapped to the Button Pin.module.P9 led =  Pin(Pin.module.P9,  mode=Pin.OUT)
  • 21. Pin Diagramms • Expansion board https://www.pycom.io/wp- content/uploads/2016/11/expansion_v02_pi nout.pdf • LoPy https://www.pycom.io/wp- content/uploads/2016/11/lopy_pinout.pdf
  • 22. Exercise • React to button presses on P10 and turn on/off on P9 • Do the same with interrupts!
  • 24. Nice to know • Deploy your scripts via • telnet • FTP • Safe boot mode • Firmware recovery
  • 25. Hello ThingsNetwork! • https://docs.pycom.io/pycom_esp32/pycom _esp32/tutorial/includes/lora-abp.html from network import LoRa import socket #  Initialize  LoRa in  LORAWAN  mode. lora =  LoRa(mode=LoRa.LORAWAN) #  join a  network using ABP  (Activation By Personalization) lora.join(activation=LoRa.ABP,  auth=(dev_addr,  nwk_swkey,  app_swkey)) #  create a  LoRa socket s  =  socket.socket(socket.AF_LORA,  socket.SOCK_RAW) #  make the socket  blocking #  (waits for the data to be sent and for the 2  receive windows to expire) s.setblocking(True) #  send  some data s.send(bytes([0x01,  0x02,  0x03])) #  make the socket  non-­‐blocking #  (because if there's no data received it will  block  forever...) s.setblocking(False) #  get any data received (if any...) data =  s.recv(64) print(data)
  • 26. Get DeviceEUI import binascii from network import LoRa lora =  LoRa(mode=LoRa.LORAWAN) devEUI =  binascii.hexlify(lora.mac())
  • 27. Libraries • https://github.com/micropython/micropython-lib • Useful things • urllib • urequests • MQTT client
  • 28. What is there? • https://docs.pycom.io/pycom_esp32/library/index.html • I2C • ADC / DAC • OneWire • PWM • SPI • Watchdog (WDT) • SD Card • Timers • RTC • Bluetooth GATT • Multithreading
  • 29. Thanks! • Hope I could whet your appetite J • If you have any questions please contact me Our online shop with pycom products • http://shop.adnexo.ch Code & slides • https://github.com/adnexo-GmbH/lopy_ws Contact • christian.faessler@adnexo.ch • www.adnexo.ch • http://twitter.com/adnexo_gmbh