SlideShare a Scribd company logo
1 of 35
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!

More Related Content

Similar to 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 DevelopmentCorley 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 PICSANTIAGO PABLO ALBERTO
 
Introduction to Raspberry Pi
Introduction to Raspberry PiIntroduction to Raspberry Pi
Introduction to Raspberry PiIsuru Jayarathne
 
Raspberry pi technical documentation
Raspberry pi technical documentationRaspberry pi technical documentation
Raspberry pi technical documentationGR Techno Solutions
 
Tac Presentation October 72014- Raspberry PI
Tac Presentation October 72014- Raspberry PITac Presentation October 72014- Raspberry PI
Tac Presentation October 72014- Raspberry PICliff 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.
 
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.pdfableelectronics
 
Embedded application development
Embedded application developmentEmbedded application development
Embedded application developmentAakash Raj
 
Multipilot pres-ufficiale alpago 2011
Multipilot pres-ufficiale alpago 2011Multipilot pres-ufficiale alpago 2011
Multipilot pres-ufficiale alpago 2011Roberto Navoni
 
Introduction to Arduino.pptx
Introduction to Arduino.pptxIntroduction to Arduino.pptx
Introduction to Arduino.pptxAkshat Bijronia
 
Multipilot pres-ufficiale def
Multipilot pres-ufficiale defMultipilot pres-ufficiale def
Multipilot pres-ufficiale defRoberto Navoni
 
Arduino Microcontroller
Arduino MicrocontrollerArduino Microcontroller
Arduino MicrocontrollerShyam Mohan
 

Similar to 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
 

Recently uploaded

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 

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/