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

Meeting w3 chapter 2 part 1
Meeting w3   chapter 2 part 1Meeting w3   chapter 2 part 1
Meeting w3 chapter 2 part 1mkazree
 
digital electronics Design of 101 sequence detector without overlapping for...
digital  electronics Design of 101 sequence detector without  overlapping for...digital  electronics Design of 101 sequence detector without  overlapping for...
digital electronics Design of 101 sequence detector without overlapping for...sanjay kumar pediredla
 
Loops Basics
Loops BasicsLoops Basics
Loops BasicsMushiii
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019Samir Mohanty
 
Synchronous Loadable Up and Down Counter
Synchronous Loadable Up and Down Counter Synchronous Loadable Up and Down Counter
Synchronous Loadable Up and Down Counter Digital System Design
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxNimrahafzal1
 
조음 Goodness-Of-Pronunciation 자질을 이용한 영어 학습자의 조음 오류 진단
조음 Goodness-Of-Pronunciation 자질을 이용한 영어 학습자의 조음 오류 진단조음 Goodness-Of-Pronunciation 자질을 이용한 영어 학습자의 조음 오류 진단
조음 Goodness-Of-Pronunciation 자질을 이용한 영어 학습자의 조음 오류 진단NAVER Engineering
 
EM3 mini project Laplace Transform
EM3 mini project Laplace TransformEM3 mini project Laplace Transform
EM3 mini project Laplace TransformAditi523129
 
Laplace Transform of Periodic Function
Laplace Transform of Periodic FunctionLaplace Transform of Periodic Function
Laplace Transform of Periodic FunctionDhaval Shukla
 

What's hot (20)

Meeting w3 chapter 2 part 1
Meeting w3   chapter 2 part 1Meeting w3   chapter 2 part 1
Meeting w3 chapter 2 part 1
 
digital electronics Design of 101 sequence detector without overlapping for...
digital  electronics Design of 101 sequence detector without  overlapping for...digital  electronics Design of 101 sequence detector without  overlapping for...
digital electronics Design of 101 sequence detector without overlapping for...
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
Python for loop
Python for loopPython for loop
Python for loop
 
Exceptions in python
Exceptions in pythonExceptions in python
Exceptions in python
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
 
Signal flow graph
Signal flow graphSignal flow graph
Signal flow graph
 
Control chap2
Control chap2Control chap2
Control chap2
 
Synchronous Loadable Up and Down Counter
Synchronous Loadable Up and Down Counter Synchronous Loadable Up and Down Counter
Synchronous Loadable Up and Down Counter
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
조음 Goodness-Of-Pronunciation 자질을 이용한 영어 학습자의 조음 오류 진단
조음 Goodness-Of-Pronunciation 자질을 이용한 영어 학습자의 조음 오류 진단조음 Goodness-Of-Pronunciation 자질을 이용한 영어 학습자의 조음 오류 진단
조음 Goodness-Of-Pronunciation 자질을 이용한 영어 학습자의 조음 오류 진단
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Function in C program
Function in C programFunction in C program
Function in C program
 
EM3 mini project Laplace Transform
EM3 mini project Laplace TransformEM3 mini project Laplace Transform
EM3 mini project Laplace Transform
 
Python decision making
Python   decision makingPython   decision making
Python decision making
 
Branching in C
Branching in CBranching in C
Branching in C
 
Control systems
Control systemsControl systems
Control systems
 
Laplace Transform of Periodic Function
Laplace Transform of Periodic FunctionLaplace Transform of Periodic Function
Laplace Transform of Periodic Function
 

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

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesSanjay Willie
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

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