SlideShare uma empresa Scribd logo
Authors: Le Chi Tuyen
Python in Embedded Systems
TRAINING
7/8/2020 Signal Processing and Radio Communications Lab 2
Content
1. Why Python
2. Raspberry Pi
i. Structure
ii. Installation
iii.GPIO pins
iv.PWM
3. ESP32
i. Structure
ii. Micropython
iii.Installation
iv.GPIO pins
v. PWM
4. Books & Courses
3
Device control and debugging
● Easy in analyzing bus traffic such as USB, SPI or I2C.
● Many bus analyzer and communication tools have user friendly interfaces that can be used to control the tool.
Automating testing
● The ability to control tools that can send and receive messages from an embedded system through Python
opens up the possibility for using Python to create automated tests that include regression testing.
Data analysis
● There are many freely available and powerful libraries.
Real-time Software
● A version for real-time is the Micropython port that is designed to run on microcontrollers.( ARM Cortex-M3/4).
Learning object oriented programming
● Free programming language ,easy to learn.
● Has the ability to be structured in a free-form script type manner or as a sophisticated object oriented
architecture.
1. Why Python ?
4
RASPBERRY PI
3B+
5
Raspberry Pi 3 B+ Hardware
● Broadcom BCM2837 SoC
○ 1.4GHz, 1Gb SRAM
● Quad Core
● 40 GPIO pins
● 4 USB ports
● Micro SD card slot
● Bluetooth 4.2/BLE
● Integrated Wi-Fi
● Power over Ethernet(PoE)
More:
https://www.raspberrypi.org/pr
oducts/raspberry-pi-3-model-b-
plus/
2.1 Structure of Raspberry Pi
6
Step 1:
Plug in a monitor (via HDMI) and a keyboard and mouse
(via USB).
● Need an interface to the device.
Step 2: Get an operating system.
● Raspberry Pi needs an OS.
● OS image must be present on the micro SD card.
Refer : https://youtu.be/y45hsd2AOpw
2.2 Installation
7
Installing an Operating System
Use New Out- Of-Box Software (NOOBS)
● Normally comes preinstalled on micro SD bundled with Raspberry Pi boards.
● Otherwise, download it for free from https://projects.raspberrypi.org/en/projects/noobs-install.
● If NOOBS is not preinstalled on micro SD, you’ll need to:
1. Format the micro SD(need an SD reader)
2. Extract the NOOBS download
3. Put it on the micro SD
8
● From this pop up window user can select
any OS , but most recommended one is
Raspbian.
● Like this way NOOBS will install an
operating system on your microSD card.
9
Raspi- Configuration
● Raspi- config is a tool which lets you set up various setup/boot options for the Raspberry
PI.
● It will run automatically when you boot the Raspberry Pi with a new micro SD card for the
first time.
10
❖ Expand Filesystem - Reformats your micro SD card filesystem to allow access to all the memory.
❖ Change User Password - Raspberry Pi starts with one user account ( username: “pi”) with a
default password (“raspberry”).
❖ Enable boot to Desktop/Scratch
● Console is default boot option.
● Desktop is the graphic interface.
● Scratch is a programming environment for kids.
If you use desktop you can invoke console too. But you use console , then you can only get
console.
11
● There are 40 pins in Raspberry Pi 3 B+ model.
● Basically there are,
○ power and ground pins
○ GPIO pins
○ Other multi functional pins
● Anyhow there are 2 ways to number these
pins.
1. GPIO.BOARD
Number of pins in their order on the
board.(as shown under Pin#)
1. GPIO.BCM
The Broadcom SoC number.(
No.shown after GPIO)
● In here we used board numbering system.
https://datasheets.raspberrypi.org/cm/cm3-
plus-datasheet.pdf
2.3 Pins
12
Set pin mode
➔ Set a pin to act as an INPUT or OUTPUT pin.
◆ GPIO.set up (pin no, GPIO.OUT)
Ex: GPIO.set up (13, GPIO.OUT)
◆ GPIO.set up (pin no, GPIO.IN)
Ex: GPIO.set up (13, GPIO.IN)
Pin Direction
➔ Assign a value to pins set as OUTPUT pins. (3.3v / 0 v)
◆ GPIO.output(pin no, True)
Ex:GPIO.output(13, True)
◆ GPIO.output(pin no, False)
Ex:GPIO.output(13, False)
Let’s begin with GPIO pins
7/8/2020 Signal Processing and Radio Communications Lab confidential 13
Blinking an LED
https://youtu.be/PU7i7TSYF40
Reading an input pins
GPIO.setup( pin no , GPIO.IN)
value = GPIO.input(pin no.)
● This can read value on input pin.
● But in Raspberry pi there is no analog to digital converter. So it can only read digital
values.
7/8/2020 Signal Processing and Radio Communications Lab confidential 14
15
Period (T) = time for one cycle
Freequency (f) = number of cycles per second
2.4 Pulse Width Modulation (PWM)
f = 1 / T
16
● Pulse - one cycle
● pulse width - HIGH/ON period of pulse
● Raspberry Pi generates only digital signals as high or low. But there are some devices,
which respond to analog. But we can't generate analog from this. So, one way to deal with
that is to send a pulse width modulated signal. User can make the signal go from high
to low really fast.
Duty Cycle = Pulse width / Period * 100%
17
● Imagine these are duty
cycles of pulses for three
iLEDs. In here the pulses
have with same frequency
as well as same time period.
● Only difference is their duty
cycles. It make differences in
LEDs intensity as follows:
L2>L1>L3
https://youtu.be/1fKH5PU9ec
k
1
2
3
18
PWM Initialization
● Mark pin for PWM.
pwm_obj = GPIO.PWM( pin no ,
frequency)
● Start generating PWM signal
according to given duty cycle(0-100).
pwm_obj.start(duty cycle)
PWM Control
● Assign new duty cycle.
pwm_obj.ChangeDutyCycle(50)
Frequency Control
● Need to do it manually.
while True:
GPIO.output( pin no. , True)
time.sleep(0.5)
GPIO.output( pin no. , False)
time.sleep(0.5)
● This will give a 1Hz pulse.
19
Example for PWM
20
ESP32
21
More : http://esp32.net/
The ESP32 include:
● 18 Analog-to-Digital Converter
(ADC) channels
● 3 SPI interfaces
● 3 UART interfaces
● 2 I2C interfaces
● 16 PWM output channels
● 2 Digital-to-Analog Converters
(DAC)
● 2 I2S interfaces
● 10 Capacitive sensing GPIOs
3.1 Structure of ESP32
22
● A compact implementation of
python 3.
● Created for usage in
microcontrollers.
● Originally Created by Australian
programmer Damien George.
● Only include subset of python
libraries.
➔ Basically it’s a stripped and trimmed
version of python in order to work
with embedded devices with limited
resources.
➔ Support many devices like ESP32,
ESP8266, PyBoard, Wipy-pycom
3.2 What is micro python?
23
Points to note….
math – mathematical functions (e.g.
sin, pi)
Python standard
lib
MicroPython Libraries
MicroPython and
ESP32 specific lib
sys – system specific functions (e.g.
sys.argv)
machine – functions related to
processor itself
esp – functions related to the board
24
1. Download the Thonny Python IDE at: https://thonny.org/
1. Download the MicroPython firmware from: MicroPython.org
1. Download the ESP32 USB driver at: CP210x USB to UART Bridge VCP Drivers
1. Install Thonny Python
1. Install the ESP32 USB driver
1. Flash a new firmware to ESP32 using the Thonny Python.
Refer this video : https://youtu.be/elBtWZ_fOZU
3.3 Installation
25
Link to data sheet :
https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf
3.4 Pin Layout
26
Pins which can use as
I/O.
● OK
● OK (keep
attention)
● Don’t
7/8/2020 Signal Processing and Radio Communications Lab confidential 27
Set pin mode
➔ Set a pin to act as an INPUT or OUTPUT pin.
Ex: p0 = Pin(0, Pin.OUT)
p0 = Pin(0, Pin.IN)
Pin Direction
➔ Assign a value to pins set as OUTPUT pins. (3.3v / 0 v)
Ex: p0.on() / p0.value(1)
p0.off() / p0.value(0)
Let’s begin with GPIO pins
28
Blinking an LED
More : https://youtu.be/w_fbN4jpgE4
29
Reading an input pins
1. Reading Digital values
P2= Pin (0, Pin.IN) #create input pin on GPIO2
print(P2.value()) #get value, 0 or 1
1. Reading Analog values
● ADC functionality available on pins 32-39.
from machine import ADC
adc = ADC(Pin(32)) # create ADC object on ADC pin
adc.read() # read value, 0-4095 across voltage range 0.0v - 1.0v
adc.atten(ADC.ATTN_11DB) # set 11dB input attenuation (voltage range roughly 0.0v - 3.6v)
adc.width(ADC.WIDTH_9BIT) # set 9 bit return values (returned range 0-511)
adc.read() # read value using the newly configured attenuation and width
30
ADC.atten(attenuation)
This method allows for the setting of the amount of
attenuation on the input of the ADC. The possible
attenuation options are:
● ADC.ATTN_0DB: 0dB attenuation, gives
a maximum input voltage of 1.00v - this
is the default configuration
● ADC.ATTN_2_5DB: 2.5dB attenuation,
gives a maximum input voltage of
approximately 1.34v
● ADC.ATTN_6DB: 6dB attenuation, gives
a maximum input voltage of
approximately 2.00v
● ADC.ATTN_11DB: 11dB attenuation,
gives a maximum input voltage of
approximately 3.6v
ADC.width(width)
This method allows for the setting of the number of
bits to be utilised and returned during ADC reads.
Possible width options are:
● ADC.WIDTH_9BIT: 9 bit data
● ADC.WIDTH_10BIT: 10 bit data
● ADC.WIDTH_11BIT: 11 bit data
● ADC.WIDTH_12BIT: 12 bit data - this is
the default configuration
31
Reading potentiometer values
for circuit : https://youtu.be/UHhl4T_dZWk
32
● PWM can be enabled on all output-enabled pins.
● Currently the duty cycle has to be in the range of 0-1023.
from machine import Pin, PWM
pwm0 = PWM(Pin(0)) # create PWM object from a pin
pwm0.freq() # get current frequency
pwm0.freq(1000) # set frequency
pwm0.duty() # get current duty cycle
pwm0.duty(200) # set duty cycle
pwm0.deinit() # turn off PWM on the pin
pwm2 = PWM(Pin(2), freq=20000, duty=512) # create and configure in one go
3.5 Pulse Width Modulation (PWM)
33
EXAMPLE
Refer : https://youtu.be/-ZIig_fEkZg
34
4. Books and courses
Books and videos
https://www.raspberrypi.org/
https://www.espressif.com/en/products/socs/esp32
https://micropython.org/
https://youtu.be/TKh6MxfRWlw
https://youtu.be/UUOCh0Cbty8
Courses
https://www.udemy.com/course/micropython-for-everyone-using-esp32/
https://techexplorations.com/so/micropython-with-the-esp32/
https://www.udemy.com/course/complete-python-raspberry-pi-and-iot-bootcamp/
35
THANK YOU!

Mais conteúdo relacionado

Semelhante a Python-in-Embedded-systems.pptx

Raspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application DevelopmentRaspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application Development
Corley S.r.l.
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
Codemotion
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
Raghav Shetty
 
Microcontroladores: Programación con microcontrolador PIC
Microcontroladores: Programación con microcontrolador PICMicrocontroladores: Programación con microcontrolador PIC
Microcontroladores: Programación con microcontrolador PIC
SANTIAGO PABLO ALBERTO
 
Introduction to Raspberry Pi
Introduction to Raspberry PiIntroduction to Raspberry Pi
Introduction to Raspberry Pi
Isuru Jayarathne
 
Arduino: Arduino starter kit
Arduino: Arduino starter kitArduino: Arduino starter kit
Arduino: Arduino starter kit
SANTIAGO PABLO ALBERTO
 
Raspberry pi technical documentation
Raspberry pi technical documentationRaspberry pi technical documentation
Raspberry pi technical documentation
GR Techno Solutions
 
Tac Presentation October 72014- Raspberry PI
Tac Presentation October 72014- Raspberry PITac Presentation October 72014- Raspberry PI
Tac Presentation October 72014- Raspberry PI
Cliff Samuels Jr.
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Tomomi Imura
 
Physical prototyping lab1-input_output (2)
Physical prototyping lab1-input_output (2)Physical prototyping lab1-input_output (2)
Physical prototyping lab1-input_output (2)
Tony Olsson.
 
Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
vishal choudhary
 
Computer Programming and MCUs Assembly Language STM32Cu.pdf
Computer Programming and MCUs  Assembly Language  STM32Cu.pdfComputer Programming and MCUs  Assembly Language  STM32Cu.pdf
Computer Programming and MCUs Assembly Language STM32Cu.pdf
ableelectronics
 
Embedded application development
Embedded application developmentEmbedded application development
Embedded application development
Aakash Raj
 
Introduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSPIntroduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSP
Pantech ProLabs India Pvt Ltd
 
Multipilot pres-ufficiale alpago 2011
Multipilot pres-ufficiale alpago 2011Multipilot pres-ufficiale alpago 2011
Multipilot pres-ufficiale alpago 2011
Roberto Navoni
 
Introduction to Arduino.pptx
Introduction to Arduino.pptxIntroduction to Arduino.pptx
Introduction to Arduino.pptx
Akshat Bijronia
 
Multipilot pres-ufficiale def
Multipilot pres-ufficiale defMultipilot pres-ufficiale def
Multipilot pres-ufficiale def
Roberto Navoni
 
Arduino Microcontroller
Arduino MicrocontrollerArduino Microcontroller
Arduino Microcontroller
Shyam Mohan
 
Presentation
PresentationPresentation
Presentation
Abhijit Das
 
What is arduino
What is arduinoWhat is arduino
What is arduino
vivek kumar
 

Semelhante a Python-in-Embedded-systems.pptx (20)

Raspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application DevelopmentRaspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application Development
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
 
Microcontroladores: Programación con microcontrolador PIC
Microcontroladores: Programación con microcontrolador PICMicrocontroladores: Programación con microcontrolador PIC
Microcontroladores: Programación con microcontrolador PIC
 
Introduction to Raspberry Pi
Introduction to Raspberry PiIntroduction to Raspberry Pi
Introduction to Raspberry Pi
 
Arduino: Arduino starter kit
Arduino: Arduino starter kitArduino: Arduino starter kit
Arduino: Arduino starter kit
 
Raspberry pi technical documentation
Raspberry pi technical documentationRaspberry pi technical documentation
Raspberry pi technical documentation
 
Tac Presentation October 72014- Raspberry PI
Tac Presentation October 72014- Raspberry PITac Presentation October 72014- Raspberry PI
Tac Presentation October 72014- Raspberry PI
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
 
Physical prototyping lab1-input_output (2)
Physical prototyping lab1-input_output (2)Physical prototyping lab1-input_output (2)
Physical prototyping lab1-input_output (2)
 
Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
 
Computer Programming and MCUs Assembly Language STM32Cu.pdf
Computer Programming and MCUs  Assembly Language  STM32Cu.pdfComputer Programming and MCUs  Assembly Language  STM32Cu.pdf
Computer Programming and MCUs Assembly Language STM32Cu.pdf
 
Embedded application development
Embedded application developmentEmbedded application development
Embedded application development
 
Introduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSPIntroduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSP
 
Multipilot pres-ufficiale alpago 2011
Multipilot pres-ufficiale alpago 2011Multipilot pres-ufficiale alpago 2011
Multipilot pres-ufficiale alpago 2011
 
Introduction to Arduino.pptx
Introduction to Arduino.pptxIntroduction to Arduino.pptx
Introduction to Arduino.pptx
 
Multipilot pres-ufficiale def
Multipilot pres-ufficiale defMultipilot pres-ufficiale def
Multipilot pres-ufficiale def
 
Arduino Microcontroller
Arduino MicrocontrollerArduino Microcontroller
Arduino Microcontroller
 
Presentation
PresentationPresentation
Presentation
 
What is arduino
What is arduinoWhat is arduino
What is arduino
 

Último

原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 

Último (20)

原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 

Python-in-Embedded-systems.pptx

  • 1. Authors: Le Chi Tuyen Python in Embedded Systems TRAINING
  • 2. 7/8/2020 Signal Processing and Radio Communications Lab 2 Content 1. Why Python 2. Raspberry Pi i. Structure ii. Installation iii.GPIO pins iv.PWM 3. ESP32 i. Structure ii. Micropython iii.Installation iv.GPIO pins v. PWM 4. Books & Courses
  • 3. 3 Device control and debugging ● Easy in analyzing bus traffic such as USB, SPI or I2C. ● Many bus analyzer and communication tools have user friendly interfaces that can be used to control the tool. Automating testing ● The ability to control tools that can send and receive messages from an embedded system through Python opens up the possibility for using Python to create automated tests that include regression testing. Data analysis ● There are many freely available and powerful libraries. Real-time Software ● A version for real-time is the Micropython port that is designed to run on microcontrollers.( ARM Cortex-M3/4). Learning object oriented programming ● Free programming language ,easy to learn. ● Has the ability to be structured in a free-form script type manner or as a sophisticated object oriented architecture. 1. Why Python ?
  • 5. 5 Raspberry Pi 3 B+ Hardware ● Broadcom BCM2837 SoC ○ 1.4GHz, 1Gb SRAM ● Quad Core ● 40 GPIO pins ● 4 USB ports ● Micro SD card slot ● Bluetooth 4.2/BLE ● Integrated Wi-Fi ● Power over Ethernet(PoE) More: https://www.raspberrypi.org/pr oducts/raspberry-pi-3-model-b- plus/ 2.1 Structure of Raspberry Pi
  • 6. 6 Step 1: Plug in a monitor (via HDMI) and a keyboard and mouse (via USB). ● Need an interface to the device. Step 2: Get an operating system. ● Raspberry Pi needs an OS. ● OS image must be present on the micro SD card. Refer : https://youtu.be/y45hsd2AOpw 2.2 Installation
  • 7. 7 Installing an Operating System Use New Out- Of-Box Software (NOOBS) ● Normally comes preinstalled on micro SD bundled with Raspberry Pi boards. ● Otherwise, download it for free from https://projects.raspberrypi.org/en/projects/noobs-install. ● If NOOBS is not preinstalled on micro SD, you’ll need to: 1. Format the micro SD(need an SD reader) 2. Extract the NOOBS download 3. Put it on the micro SD
  • 8. 8 ● From this pop up window user can select any OS , but most recommended one is Raspbian. ● Like this way NOOBS will install an operating system on your microSD card.
  • 9. 9 Raspi- Configuration ● Raspi- config is a tool which lets you set up various setup/boot options for the Raspberry PI. ● It will run automatically when you boot the Raspberry Pi with a new micro SD card for the first time.
  • 10. 10 ❖ Expand Filesystem - Reformats your micro SD card filesystem to allow access to all the memory. ❖ Change User Password - Raspberry Pi starts with one user account ( username: “pi”) with a default password (“raspberry”). ❖ Enable boot to Desktop/Scratch ● Console is default boot option. ● Desktop is the graphic interface. ● Scratch is a programming environment for kids. If you use desktop you can invoke console too. But you use console , then you can only get console.
  • 11. 11 ● There are 40 pins in Raspberry Pi 3 B+ model. ● Basically there are, ○ power and ground pins ○ GPIO pins ○ Other multi functional pins ● Anyhow there are 2 ways to number these pins. 1. GPIO.BOARD Number of pins in their order on the board.(as shown under Pin#) 1. GPIO.BCM The Broadcom SoC number.( No.shown after GPIO) ● In here we used board numbering system. https://datasheets.raspberrypi.org/cm/cm3- plus-datasheet.pdf 2.3 Pins
  • 12. 12 Set pin mode ➔ Set a pin to act as an INPUT or OUTPUT pin. ◆ GPIO.set up (pin no, GPIO.OUT) Ex: GPIO.set up (13, GPIO.OUT) ◆ GPIO.set up (pin no, GPIO.IN) Ex: GPIO.set up (13, GPIO.IN) Pin Direction ➔ Assign a value to pins set as OUTPUT pins. (3.3v / 0 v) ◆ GPIO.output(pin no, True) Ex:GPIO.output(13, True) ◆ GPIO.output(pin no, False) Ex:GPIO.output(13, False) Let’s begin with GPIO pins
  • 13. 7/8/2020 Signal Processing and Radio Communications Lab confidential 13 Blinking an LED https://youtu.be/PU7i7TSYF40
  • 14. Reading an input pins GPIO.setup( pin no , GPIO.IN) value = GPIO.input(pin no.) ● This can read value on input pin. ● But in Raspberry pi there is no analog to digital converter. So it can only read digital values. 7/8/2020 Signal Processing and Radio Communications Lab confidential 14
  • 15. 15 Period (T) = time for one cycle Freequency (f) = number of cycles per second 2.4 Pulse Width Modulation (PWM) f = 1 / T
  • 16. 16 ● Pulse - one cycle ● pulse width - HIGH/ON period of pulse ● Raspberry Pi generates only digital signals as high or low. But there are some devices, which respond to analog. But we can't generate analog from this. So, one way to deal with that is to send a pulse width modulated signal. User can make the signal go from high to low really fast. Duty Cycle = Pulse width / Period * 100%
  • 17. 17 ● Imagine these are duty cycles of pulses for three iLEDs. In here the pulses have with same frequency as well as same time period. ● Only difference is their duty cycles. It make differences in LEDs intensity as follows: L2>L1>L3 https://youtu.be/1fKH5PU9ec k 1 2 3
  • 18. 18 PWM Initialization ● Mark pin for PWM. pwm_obj = GPIO.PWM( pin no , frequency) ● Start generating PWM signal according to given duty cycle(0-100). pwm_obj.start(duty cycle) PWM Control ● Assign new duty cycle. pwm_obj.ChangeDutyCycle(50) Frequency Control ● Need to do it manually. while True: GPIO.output( pin no. , True) time.sleep(0.5) GPIO.output( pin no. , False) time.sleep(0.5) ● This will give a 1Hz pulse.
  • 21. 21 More : http://esp32.net/ The ESP32 include: ● 18 Analog-to-Digital Converter (ADC) channels ● 3 SPI interfaces ● 3 UART interfaces ● 2 I2C interfaces ● 16 PWM output channels ● 2 Digital-to-Analog Converters (DAC) ● 2 I2S interfaces ● 10 Capacitive sensing GPIOs 3.1 Structure of ESP32
  • 22. 22 ● A compact implementation of python 3. ● Created for usage in microcontrollers. ● Originally Created by Australian programmer Damien George. ● Only include subset of python libraries. ➔ Basically it’s a stripped and trimmed version of python in order to work with embedded devices with limited resources. ➔ Support many devices like ESP32, ESP8266, PyBoard, Wipy-pycom 3.2 What is micro python?
  • 23. 23 Points to note…. math – mathematical functions (e.g. sin, pi) Python standard lib MicroPython Libraries MicroPython and ESP32 specific lib sys – system specific functions (e.g. sys.argv) machine – functions related to processor itself esp – functions related to the board
  • 24. 24 1. Download the Thonny Python IDE at: https://thonny.org/ 1. Download the MicroPython firmware from: MicroPython.org 1. Download the ESP32 USB driver at: CP210x USB to UART Bridge VCP Drivers 1. Install Thonny Python 1. Install the ESP32 USB driver 1. Flash a new firmware to ESP32 using the Thonny Python. Refer this video : https://youtu.be/elBtWZ_fOZU 3.3 Installation
  • 25. 25 Link to data sheet : https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf 3.4 Pin Layout
  • 26. 26 Pins which can use as I/O. ● OK ● OK (keep attention) ● Don’t
  • 27. 7/8/2020 Signal Processing and Radio Communications Lab confidential 27 Set pin mode ➔ Set a pin to act as an INPUT or OUTPUT pin. Ex: p0 = Pin(0, Pin.OUT) p0 = Pin(0, Pin.IN) Pin Direction ➔ Assign a value to pins set as OUTPUT pins. (3.3v / 0 v) Ex: p0.on() / p0.value(1) p0.off() / p0.value(0) Let’s begin with GPIO pins
  • 28. 28 Blinking an LED More : https://youtu.be/w_fbN4jpgE4
  • 29. 29 Reading an input pins 1. Reading Digital values P2= Pin (0, Pin.IN) #create input pin on GPIO2 print(P2.value()) #get value, 0 or 1 1. Reading Analog values ● ADC functionality available on pins 32-39. from machine import ADC adc = ADC(Pin(32)) # create ADC object on ADC pin adc.read() # read value, 0-4095 across voltage range 0.0v - 1.0v adc.atten(ADC.ATTN_11DB) # set 11dB input attenuation (voltage range roughly 0.0v - 3.6v) adc.width(ADC.WIDTH_9BIT) # set 9 bit return values (returned range 0-511) adc.read() # read value using the newly configured attenuation and width
  • 30. 30 ADC.atten(attenuation) This method allows for the setting of the amount of attenuation on the input of the ADC. The possible attenuation options are: ● ADC.ATTN_0DB: 0dB attenuation, gives a maximum input voltage of 1.00v - this is the default configuration ● ADC.ATTN_2_5DB: 2.5dB attenuation, gives a maximum input voltage of approximately 1.34v ● ADC.ATTN_6DB: 6dB attenuation, gives a maximum input voltage of approximately 2.00v ● ADC.ATTN_11DB: 11dB attenuation, gives a maximum input voltage of approximately 3.6v ADC.width(width) This method allows for the setting of the number of bits to be utilised and returned during ADC reads. Possible width options are: ● ADC.WIDTH_9BIT: 9 bit data ● ADC.WIDTH_10BIT: 10 bit data ● ADC.WIDTH_11BIT: 11 bit data ● ADC.WIDTH_12BIT: 12 bit data - this is the default configuration
  • 31. 31 Reading potentiometer values for circuit : https://youtu.be/UHhl4T_dZWk
  • 32. 32 ● PWM can be enabled on all output-enabled pins. ● Currently the duty cycle has to be in the range of 0-1023. from machine import Pin, PWM pwm0 = PWM(Pin(0)) # create PWM object from a pin pwm0.freq() # get current frequency pwm0.freq(1000) # set frequency pwm0.duty() # get current duty cycle pwm0.duty(200) # set duty cycle pwm0.deinit() # turn off PWM on the pin pwm2 = PWM(Pin(2), freq=20000, duty=512) # create and configure in one go 3.5 Pulse Width Modulation (PWM)
  • 34. 34 4. Books and courses Books and videos https://www.raspberrypi.org/ https://www.espressif.com/en/products/socs/esp32 https://micropython.org/ https://youtu.be/TKh6MxfRWlw https://youtu.be/UUOCh0Cbty8 Courses https://www.udemy.com/course/micropython-for-everyone-using-esp32/ https://techexplorations.com/so/micropython-with-the-esp32/ https://www.udemy.com/course/complete-python-raspberry-pi-and-iot-bootcamp/