SlideShare a Scribd company logo
1 of 25
Download to read offline
Intro to Electronics in Python
Anna Gerber
Intro to Electronics in Python
Electricity
•  Electricity is a form of energy
•  We can connect components that convert
electrical energy into other forms of energy:
light, sound, movement, heat etc, into a circuit
•  In a Direct Current (DC) circuit,

electrical energy flows from 

the positive side of a 

power source to the

negative side, i.e. from 

+ (power) to – (ground) 
Anna Gerber
Intro to Electronics in Python
Electrical concepts
•  Current (Amps): measures the flow of electrical
energy through a circuit
•  Voltage (Volts): measures difference in potential
energy between the positive and negative sides
of a circuit
•  Resistance (Ohms): measures a material's
opposition to the flow of energy
•  Power (Watts): the rate at which energy is
converted from one form to another
Anna Gerber
Intro to Electronics in Python
Ohm's Law
Current = Voltage / Resistance
•  Increase the voltage, and the current will
increase (i.e. speed up)
•  Increase the resistance and the current will
decrease
Anna Gerber
Intro to Electronics in Python
Sensors
•  Environmental	
  condi/ons	
  	
  	
  
(e.g.	
  temperature,	
  humidity,	
  smoke)	
  
•  Magne/c	
  (e.g.	
  hall	
  effect	
  sensor)	
  
•  Light	
  (e.g.	
  photo	
  resistor)	
  
•  Sound	
  (e.g.	
  microphone)	
  
•  Mo/on	
  (e.g.	
  accelerometer,	
  /lt,	
  pressure)	
  
•  User	
  /	
  Physical	
  Input	
  (e.g.	
  buDon)	
  
Anna Gerber
Intro to Electronics in Python
Actuators
•  Light	
  &	
  Displays	
  (e.g.	
  LED,	
  LCD)	
  
•  Sound	
  (e.g.	
  Piezo	
  buzzer)	
  
•  Mo/on	
  (e.g.	
  Servo,	
  DC	
  Motor,	
  Solenoid)	
  
•  Power	
  (e.g.	
  Relay)	
  
Anna Gerber
Intro to Electronics in Python
Digital vs Analog
•  Digital
–  discrete values (0 or 1)(LOW or HIGH)
–  Examples: tilt sensor, push button, relay, servo
•  Analog
–  continuous values
–  Examples: photo resistor, DC motor
•  Some sensors support both digital and analog
outputs
Anna Gerber
Intro to Electronics in Python
Using a Breadboard
Anna Gerber
Intro to Electronics in Python
•  Use to prototype circuits without soldering by
plugging in components and jumper wires
•  Letters and numbers for reference
•  Numbered rows are connected
•  Some have power bus along the sides
Resistors
•  Introduces resistance, so restricts the amount of
current that can flow through a circuit
•  Coloured bands indicate resistance
•  Can be connected in either direction
Anna Gerber
Intro to Electronics in Python
LEDs
•  Light Emitting Diode
•  Polarized: diodes act like one way valves so
must be connected in a certain direction
•  Emits light when a current passes through
Anna Gerber
Intro to Electronics in Python
Anode	
  (+)	
  	
  
longer	
  lead	
  
connects	
  to	
  power	
  
Cathode	
  (-­‐)	
  	
  
connects	
  to	
  ground	
  
Control
•  Arduino-compatible
Microcontroller co-
ordinates robot inputs
(sensors) and outputs
(actuators)
•  See http://arduino.cc/ 
Anna Gerber
Intro to Electronics in Python
PyFirmata
•  https://github.com/tino/pyFirmata
•  Communicates with the Arduino using the Firmata
protocol
Install using pip:
pip	
  install	
  pyfirmata	
  
Anna Gerber
Intro to Electronics in Python
Loading Firmata onto the Arduino
•  Once-off setup to prepare our Arduino for use
with PyFirmata:
–  Connect the microcontroller board via USB
–  Launch Arduino IDE and open the Firmata sketch
via the menu: File	
  >	
  Examples	
  >	
  Firmata	
  >	
  
StandardFirmata	
  
–  Select your board type (e.g. Arduino Nano w/
ATmega328) via Tools	
  >	
  Board	
  
–  Select the port for your board via Tools	
  >	
  
Serial	
  Port	
  > (the port of your Arduino) 

e.g. /dev/tty.usbserial-A9GF3L9D
–  Upload the program by clicking on Upload	
  
–  Close the IDE
Anna Gerber
Intro to Electronics in Python
BLINKING AN LED
Anna Gerber
Intro to Electronics in Python
Connecting an LED to the Arduino
•  Unplug the Arduino!
•  Attach long lead of
LED to pin 13 of
Arduino
•  Connect resistor to
cathode of resistor
and ground rail of
breadboard
•  Connect GND pin of
Arduino to ground
rail of breadboard
using a jumper wire
Anna Gerber
Intro to Electronics in Python
Creating the program
1.  Create a Python program file (e.g. blink.py)
2.  Edit it using a text editor e.g. SublimeText
3.  At the start of your program import the library

import	
  pyfirmata	
  
Anna Gerber
Intro to Electronics in Python
Creating the board
We create a Board object which corresponds to our
Arduino-compatible microcontroller board and store it
in a variable. 
We need to provide the port as a parameter:
board	
  =	
  pyfirmata.Arduino("/dev/tty.usbserial-­‐A9QPTF37")	
  
Anna Gerber
Intro to Electronics in Python
Controlling the LED
•  Then we can control the LED via the pin it is
connected to (in this case, pin 13)
•  Use a variable for the pin number to make it easier to
change later
–  PIN	
  =	
  13	
  
•  Turn on LED on pin 13
–  board.digital[PIN].write(1)	
  
•  Turn off LED on pin 13
–  board.digital[PIN].write(0)	
  
Anna Gerber
Intro to Electronics in Python
Delayed behaviour
•  Use the pass_time function to delay functions
by a certain number of seconds e.g. blink LED
on then off after one second:
	
  	
  board.digital[PIN].write(0)	
  
	
  	
  board.pass_time(1)	
  
	
  	
  board.digital[PIN].write(1)	
  
Anna Gerber
Intro to Electronics in Python
Repeating behaviour (loops)
Use a while loop to blink indefinitely:
while	
  True	
  :	
  
board.digital[PIN].write(0)	
  
board.pass_time(1)	
  
board.digital[PIN].write(1)	
  
board.pass_time(1)	
  
Anna Gerber
Intro to Electronics in Python
The entire blink program
import	
  pyfirmata	
  
PORT	
  =	
  "/dev/tty.usbserial-­‐A9QPTF37"	
  
PIN	
  =	
  13	
  
board	
  =	
  pyfirmata.Arduino(PORT)	
  
while	
  True:	
  
	
  	
  	
  	
  board.digital[PIN].write(0)	
  
	
  	
  	
  	
  board.pass_time(1)	
  
	
  	
  	
  	
  board.digital[PIN].write(1)	
  
	
  	
  	
  	
  board.pass_time(1)	
  
Anna Gerber
Intro to Electronics in Python
Running the program from Terminal
•  Open the Terminal app
•  Change directory to the location where you have
saved your code e.g. 

	
  >	
  cd	
  ~/Desktop/code/	
  
•  Run your program using Python e.g.

	
  >	
  python blink.py

•  Hit control-C to stop the program
Anna Gerber
Intro to Electronics in Python
Connecting to iPython Notebook
•  We will use iPython Notebook running on
Raspberry Pi
•  Plug into Raspberry Pi via ethernet (connect to
DHCP server on Pi)
•  Open 192.168.1.1:8888 in your browser
Anna Gerber
Intro to Electronics in Python
How to setup the software at home
•  Install Arduino IDE 
–  Optional, only required if you want to load
Firmata again or experiment with programming
the Arduino using C++
•  Install Python
•  Install PyFirmata	
  
• 	
   Install a code editor e.g. Atom (Mac only),
SublimeText if you don't already have one or
install iPython Notebook
Anna Gerber
Intro to Electronics in Python
Where to find out more
•  Electricity
–  https://www.khanacademy.org/science/physics/
electricity-and-magnetism/v/circuits--part-1
•  Arduino Playground 

–  http://playground.arduino.cc/interfacing/python
•  Sample code for Freetronics kit
–  https://gist.github.com/AnnaGerber/
26decdf2aa53150f7515
Anna Gerber
Intro to Electronics in Python

More Related Content

What's hot

Internet of Things ( IoT ) Training
Internet of Things ( IoT ) TrainingInternet of Things ( IoT ) Training
Internet of Things ( IoT ) TrainingTonex
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash CourseHaim Michael
 
Intro to Discrete Mathematics
Intro to Discrete MathematicsIntro to Discrete Mathematics
Intro to Discrete Mathematicsasad faraz
 
IoT advatage and disadvantage
IoT advatage and disadvantageIoT advatage and disadvantage
IoT advatage and disadvantageRubel Biswas
 
IoT - IT 423 ppt
IoT - IT 423 pptIoT - IT 423 ppt
IoT - IT 423 pptMhae Lyn
 
Iot presentation
Iot presentationIot presentation
Iot presentationhuma742446
 
Predicates and quantifiers
Predicates and quantifiersPredicates and quantifiers
Predicates and quantifiersIstiak Ahmed
 
Internet of Things: A Hands-On Approach
Internet of Things: A Hands-On ApproachInternet of Things: A Hands-On Approach
Internet of Things: A Hands-On ApproachArshdeep Bahga
 
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB)
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB) Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB)
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB) Redwan Ferdous
 
Discrete Structures. Lecture 1
 Discrete Structures. Lecture 1  Discrete Structures. Lecture 1
Discrete Structures. Lecture 1 Ali Usman
 
Advantages of Python Learning | Why Python
Advantages of Python Learning | Why PythonAdvantages of Python Learning | Why Python
Advantages of Python Learning | Why PythonEvoletTechnologiesCo
 
Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Mandeesh Singh
 
introduction to python
 introduction to python introduction to python
introduction to pythonJincy Nelson
 
Types of cyber crime
Types of cyber crimeTypes of cyber crime
Types of cyber crimeInshaLakhani
 

What's hot (20)

Internet of Things ( IoT ) Training
Internet of Things ( IoT ) TrainingInternet of Things ( IoT ) Training
Internet of Things ( IoT ) Training
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash Course
 
Introduction to the Python
Introduction to the PythonIntroduction to the Python
Introduction to the Python
 
Intro to Discrete Mathematics
Intro to Discrete MathematicsIntro to Discrete Mathematics
Intro to Discrete Mathematics
 
IoT advatage and disadvantage
IoT advatage and disadvantageIoT advatage and disadvantage
IoT advatage and disadvantage
 
IoT: An introduction
IoT: An introductionIoT: An introduction
IoT: An introduction
 
security and privacy-Internet of things
security and privacy-Internet of thingssecurity and privacy-Internet of things
security and privacy-Internet of things
 
IoT - IT 423 ppt
IoT - IT 423 pptIoT - IT 423 ppt
IoT - IT 423 ppt
 
Iot presentation
Iot presentationIot presentation
Iot presentation
 
Introduction to ChatGPT and Overview of its capabilities and functionality.pdf
Introduction to ChatGPT and Overview of its capabilities and functionality.pdfIntroduction to ChatGPT and Overview of its capabilities and functionality.pdf
Introduction to ChatGPT and Overview of its capabilities and functionality.pdf
 
Predicates and quantifiers
Predicates and quantifiersPredicates and quantifiers
Predicates and quantifiers
 
Python
PythonPython
Python
 
Internet of Things: A Hands-On Approach
Internet of Things: A Hands-On ApproachInternet of Things: A Hands-On Approach
Internet of Things: A Hands-On Approach
 
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB)
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB) Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB)
Arduino Simulation_Basic_Day-3 (Tinkercad+Proteus PCB)
 
Discrete Structures. Lecture 1
 Discrete Structures. Lecture 1  Discrete Structures. Lecture 1
Discrete Structures. Lecture 1
 
Advantages of Python Learning | Why Python
Advantages of Python Learning | Why PythonAdvantages of Python Learning | Why Python
Advantages of Python Learning | Why Python
 
Internet of things
Internet of thingsInternet of things
Internet of things
 
Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)
 
introduction to python
 introduction to python introduction to python
introduction to python
 
Types of cyber crime
Types of cyber crimeTypes of cyber crime
Types of cyber crime
 

Viewers also liked

MicroPython&electronics prezentācija
MicroPython&electronics prezentācija MicroPython&electronics prezentācija
MicroPython&electronics prezentācija CRImier
 
International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)Anna Gerber
 
JavaScript Robotics
JavaScript RoboticsJavaScript Robotics
JavaScript RoboticsAnna Gerber
 
Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009Mark Jaquith
 
"Serverless" express
"Serverless" express"Serverless" express
"Serverless" expressAnna Gerber
 
Basics of Automation, PLC and SCADA
Basics of Automation, PLC and SCADABasics of Automation, PLC and SCADA
Basics of Automation, PLC and SCADAIndira Kundu
 

Viewers also liked (9)

Python for-microcontrollers
Python for-microcontrollersPython for-microcontrollers
Python for-microcontrollers
 
MicroPython&electronics prezentācija
MicroPython&electronics prezentācija MicroPython&electronics prezentācija
MicroPython&electronics prezentācija
 
Python Flavors
Python FlavorsPython Flavors
Python Flavors
 
International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)
 
JavaScript Robotics
JavaScript RoboticsJavaScript Robotics
JavaScript Robotics
 
Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009
 
Iot 101
Iot 101Iot 101
Iot 101
 
"Serverless" express
"Serverless" express"Serverless" express
"Serverless" express
 
Basics of Automation, PLC and SCADA
Basics of Automation, PLC and SCADABasics of Automation, PLC and SCADA
Basics of Automation, PLC and SCADA
 

Similar to Intro to Electronics in Python

Similar to Intro to Electronics in Python (20)

ArduinoSectionI-slides.ppt
ArduinoSectionI-slides.pptArduinoSectionI-slides.ppt
ArduinoSectionI-slides.ppt
 
Intro_to_Arduino_-_v30.pptx
Intro_to_Arduino_-_v30.pptxIntro_to_Arduino_-_v30.pptx
Intro_to_Arduino_-_v30.pptx
 
Instructor background
Instructor backgroundInstructor background
Instructor background
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
Presentation S4A
Presentation S4A Presentation S4A
Presentation S4A
 
Presentation
PresentationPresentation
Presentation
 
SCSA1407.pdf
SCSA1407.pdfSCSA1407.pdf
SCSA1407.pdf
 
Lab2ppt
Lab2pptLab2ppt
Lab2ppt
 
c ppt.pptx
c ppt.pptxc ppt.pptx
c ppt.pptx
 
Sensor and Actuators using Rasberry Pi controller
Sensor and Actuators using Rasberry Pi controllerSensor and Actuators using Rasberry Pi controller
Sensor and Actuators using Rasberry Pi controller
 
Arduino
ArduinoArduino
Arduino
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptxteststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
 
Making things sense - Day 1 (May 2011)
Making things sense - Day 1 (May 2011)Making things sense - Day 1 (May 2011)
Making things sense - Day 1 (May 2011)
 
10 11_gen_revision_notes_term_3
10  11_gen_revision_notes_term_310  11_gen_revision_notes_term_3
10 11_gen_revision_notes_term_3
 
Sensor Lecture Interfacing
 Sensor Lecture Interfacing Sensor Lecture Interfacing
Sensor Lecture Interfacing
 
Computer hardware
Computer hardware Computer hardware
Computer hardware
 
480 sensors
480 sensors480 sensors
480 sensors
 
Arduino
Arduino Arduino
Arduino
 
Arduino Comic-Jody Culkin-2011
Arduino Comic-Jody Culkin-2011Arduino Comic-Jody Culkin-2011
Arduino Comic-Jody Culkin-2011
 
Arduino comic v0004
Arduino comic v0004Arduino comic v0004
Arduino comic v0004
 

More from Anna Gerber

Internet of Things (IoT) Intro
Internet of Things (IoT) IntroInternet of Things (IoT) Intro
Internet of Things (IoT) IntroAnna Gerber
 
How the Web works
How the Web worksHow the Web works
How the Web worksAnna Gerber
 
Do you want to build a robot
Do you want to build a robotDo you want to build a robot
Do you want to build a robotAnna Gerber
 
Adding Electronics to 3D Printed Action Heroes
Adding Electronics to 3D Printed Action HeroesAdding Electronics to 3D Printed Action Heroes
Adding Electronics to 3D Printed Action HeroesAnna Gerber
 
3D Printing Action Heroes
3D Printing Action Heroes3D Printing Action Heroes
3D Printing Action HeroesAnna Gerber
 
3D Sculpting Action Heroes
3D Sculpting Action Heroes3D Sculpting Action Heroes
3D Sculpting Action HeroesAnna Gerber
 
Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)Anna Gerber
 
Supporting Open Scholarly Annotation
Supporting Open Scholarly AnnotationSupporting Open Scholarly Annotation
Supporting Open Scholarly AnnotationAnna Gerber
 
Supporting Web-based Scholarly Annotation
Supporting Web-based Scholarly AnnotationSupporting Web-based Scholarly Annotation
Supporting Web-based Scholarly AnnotationAnna Gerber
 
Annotations Supporting Scholarly Editing (OA European Roll Out)
Annotations Supporting Scholarly Editing (OA European Roll Out)Annotations Supporting Scholarly Editing (OA European Roll Out)
Annotations Supporting Scholarly Editing (OA European Roll Out)Anna Gerber
 
Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)Anna Gerber
 
Intro to data visualisation
Intro to data visualisationIntro to data visualisation
Intro to data visualisationAnna Gerber
 
Annotations Supporting Scholarly Editing
Annotations Supporting Scholarly EditingAnnotations Supporting Scholarly Editing
Annotations Supporting Scholarly EditingAnna Gerber
 
Getting started with the Trove API
Getting started with the Trove APIGetting started with the Trove API
Getting started with the Trove APIAnna Gerber
 
HackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover BrisbaneHackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover BrisbaneAnna Gerber
 
Using Yahoo Pipes
Using Yahoo PipesUsing Yahoo Pipes
Using Yahoo PipesAnna Gerber
 

More from Anna Gerber (17)

Internet of Things (IoT) Intro
Internet of Things (IoT) IntroInternet of Things (IoT) Intro
Internet of Things (IoT) Intro
 
How the Web works
How the Web worksHow the Web works
How the Web works
 
Do you want to build a robot
Do you want to build a robotDo you want to build a robot
Do you want to build a robot
 
Adding Electronics to 3D Printed Action Heroes
Adding Electronics to 3D Printed Action HeroesAdding Electronics to 3D Printed Action Heroes
Adding Electronics to 3D Printed Action Heroes
 
3D Printing Action Heroes
3D Printing Action Heroes3D Printing Action Heroes
3D Printing Action Heroes
 
3D Sculpting Action Heroes
3D Sculpting Action Heroes3D Sculpting Action Heroes
3D Sculpting Action Heroes
 
Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)
 
Supporting Open Scholarly Annotation
Supporting Open Scholarly AnnotationSupporting Open Scholarly Annotation
Supporting Open Scholarly Annotation
 
Supporting Web-based Scholarly Annotation
Supporting Web-based Scholarly AnnotationSupporting Web-based Scholarly Annotation
Supporting Web-based Scholarly Annotation
 
Annotations Supporting Scholarly Editing (OA European Roll Out)
Annotations Supporting Scholarly Editing (OA European Roll Out)Annotations Supporting Scholarly Editing (OA European Roll Out)
Annotations Supporting Scholarly Editing (OA European Roll Out)
 
Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)
 
Intro to data visualisation
Intro to data visualisationIntro to data visualisation
Intro to data visualisation
 
Annotations Supporting Scholarly Editing
Annotations Supporting Scholarly EditingAnnotations Supporting Scholarly Editing
Annotations Supporting Scholarly Editing
 
Getting started with the Trove API
Getting started with the Trove APIGetting started with the Trove API
Getting started with the Trove API
 
Intro to Java
Intro to JavaIntro to Java
Intro to Java
 
HackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover BrisbaneHackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover Brisbane
 
Using Yahoo Pipes
Using Yahoo PipesUsing Yahoo Pipes
Using Yahoo Pipes
 

Recently uploaded

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Intro to Electronics in Python

  • 1. Intro to Electronics in Python Anna Gerber Intro to Electronics in Python
  • 2. Electricity •  Electricity is a form of energy •  We can connect components that convert electrical energy into other forms of energy: light, sound, movement, heat etc, into a circuit •  In a Direct Current (DC) circuit,
 electrical energy flows from 
 the positive side of a 
 power source to the
 negative side, i.e. from 
 + (power) to – (ground) Anna Gerber Intro to Electronics in Python
  • 3. Electrical concepts •  Current (Amps): measures the flow of electrical energy through a circuit •  Voltage (Volts): measures difference in potential energy between the positive and negative sides of a circuit •  Resistance (Ohms): measures a material's opposition to the flow of energy •  Power (Watts): the rate at which energy is converted from one form to another Anna Gerber Intro to Electronics in Python
  • 4. Ohm's Law Current = Voltage / Resistance •  Increase the voltage, and the current will increase (i.e. speed up) •  Increase the resistance and the current will decrease Anna Gerber Intro to Electronics in Python
  • 5. Sensors •  Environmental  condi/ons       (e.g.  temperature,  humidity,  smoke)   •  Magne/c  (e.g.  hall  effect  sensor)   •  Light  (e.g.  photo  resistor)   •  Sound  (e.g.  microphone)   •  Mo/on  (e.g.  accelerometer,  /lt,  pressure)   •  User  /  Physical  Input  (e.g.  buDon)   Anna Gerber Intro to Electronics in Python
  • 6. Actuators •  Light  &  Displays  (e.g.  LED,  LCD)   •  Sound  (e.g.  Piezo  buzzer)   •  Mo/on  (e.g.  Servo,  DC  Motor,  Solenoid)   •  Power  (e.g.  Relay)   Anna Gerber Intro to Electronics in Python
  • 7. Digital vs Analog •  Digital –  discrete values (0 or 1)(LOW or HIGH) –  Examples: tilt sensor, push button, relay, servo •  Analog –  continuous values –  Examples: photo resistor, DC motor •  Some sensors support both digital and analog outputs Anna Gerber Intro to Electronics in Python
  • 8. Using a Breadboard Anna Gerber Intro to Electronics in Python •  Use to prototype circuits without soldering by plugging in components and jumper wires •  Letters and numbers for reference •  Numbered rows are connected •  Some have power bus along the sides
  • 9. Resistors •  Introduces resistance, so restricts the amount of current that can flow through a circuit •  Coloured bands indicate resistance •  Can be connected in either direction Anna Gerber Intro to Electronics in Python
  • 10. LEDs •  Light Emitting Diode •  Polarized: diodes act like one way valves so must be connected in a certain direction •  Emits light when a current passes through Anna Gerber Intro to Electronics in Python Anode  (+)     longer  lead   connects  to  power   Cathode  (-­‐)     connects  to  ground  
  • 11. Control •  Arduino-compatible Microcontroller co- ordinates robot inputs (sensors) and outputs (actuators) •  See http://arduino.cc/ Anna Gerber Intro to Electronics in Python
  • 12. PyFirmata •  https://github.com/tino/pyFirmata •  Communicates with the Arduino using the Firmata protocol Install using pip: pip  install  pyfirmata   Anna Gerber Intro to Electronics in Python
  • 13. Loading Firmata onto the Arduino •  Once-off setup to prepare our Arduino for use with PyFirmata: –  Connect the microcontroller board via USB –  Launch Arduino IDE and open the Firmata sketch via the menu: File  >  Examples  >  Firmata  >   StandardFirmata   –  Select your board type (e.g. Arduino Nano w/ ATmega328) via Tools  >  Board   –  Select the port for your board via Tools  >   Serial  Port  > (the port of your Arduino) 
 e.g. /dev/tty.usbserial-A9GF3L9D –  Upload the program by clicking on Upload   –  Close the IDE Anna Gerber Intro to Electronics in Python
  • 14. BLINKING AN LED Anna Gerber Intro to Electronics in Python
  • 15. Connecting an LED to the Arduino •  Unplug the Arduino! •  Attach long lead of LED to pin 13 of Arduino •  Connect resistor to cathode of resistor and ground rail of breadboard •  Connect GND pin of Arduino to ground rail of breadboard using a jumper wire Anna Gerber Intro to Electronics in Python
  • 16. Creating the program 1.  Create a Python program file (e.g. blink.py) 2.  Edit it using a text editor e.g. SublimeText 3.  At the start of your program import the library import  pyfirmata   Anna Gerber Intro to Electronics in Python
  • 17. Creating the board We create a Board object which corresponds to our Arduino-compatible microcontroller board and store it in a variable. We need to provide the port as a parameter: board  =  pyfirmata.Arduino("/dev/tty.usbserial-­‐A9QPTF37")   Anna Gerber Intro to Electronics in Python
  • 18. Controlling the LED •  Then we can control the LED via the pin it is connected to (in this case, pin 13) •  Use a variable for the pin number to make it easier to change later –  PIN  =  13   •  Turn on LED on pin 13 –  board.digital[PIN].write(1)   •  Turn off LED on pin 13 –  board.digital[PIN].write(0)   Anna Gerber Intro to Electronics in Python
  • 19. Delayed behaviour •  Use the pass_time function to delay functions by a certain number of seconds e.g. blink LED on then off after one second:    board.digital[PIN].write(0)      board.pass_time(1)      board.digital[PIN].write(1)   Anna Gerber Intro to Electronics in Python
  • 20. Repeating behaviour (loops) Use a while loop to blink indefinitely: while  True  :   board.digital[PIN].write(0)   board.pass_time(1)   board.digital[PIN].write(1)   board.pass_time(1)   Anna Gerber Intro to Electronics in Python
  • 21. The entire blink program import  pyfirmata   PORT  =  "/dev/tty.usbserial-­‐A9QPTF37"   PIN  =  13   board  =  pyfirmata.Arduino(PORT)   while  True:          board.digital[PIN].write(0)          board.pass_time(1)          board.digital[PIN].write(1)          board.pass_time(1)   Anna Gerber Intro to Electronics in Python
  • 22. Running the program from Terminal •  Open the Terminal app •  Change directory to the location where you have saved your code e.g. 
  >  cd  ~/Desktop/code/   •  Run your program using Python e.g.
  >  python blink.py
 •  Hit control-C to stop the program Anna Gerber Intro to Electronics in Python
  • 23. Connecting to iPython Notebook •  We will use iPython Notebook running on Raspberry Pi •  Plug into Raspberry Pi via ethernet (connect to DHCP server on Pi) •  Open 192.168.1.1:8888 in your browser Anna Gerber Intro to Electronics in Python
  • 24. How to setup the software at home •  Install Arduino IDE –  Optional, only required if you want to load Firmata again or experiment with programming the Arduino using C++ •  Install Python •  Install PyFirmata   •    Install a code editor e.g. Atom (Mac only), SublimeText if you don't already have one or install iPython Notebook Anna Gerber Intro to Electronics in Python
  • 25. Where to find out more •  Electricity –  https://www.khanacademy.org/science/physics/ electricity-and-magnetism/v/circuits--part-1 •  Arduino Playground –  http://playground.arduino.cc/interfacing/python •  Sample code for Freetronics kit –  https://gist.github.com/AnnaGerber/ 26decdf2aa53150f7515 Anna Gerber Intro to Electronics in Python