SlideShare a Scribd company logo
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

Viewers also liked

Python for-microcontrollers
Python for-microcontrollersPython for-microcontrollers
Python for-microcontrollers
BabuSubashChandar Chandra Mohan
 
MicroPython&electronics prezentācija
MicroPython&electronics prezentācija MicroPython&electronics prezentācija
MicroPython&electronics prezentācija
CRImier
 
Python Flavors
Python FlavorsPython Flavors
Python Flavors
Geison Goes
 
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 Robotics
Anna 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 2009
Mark Jaquith
 
Iot 101
Iot 101Iot 101
Iot 101
Anna Gerber
 
"Serverless" express
"Serverless" express"Serverless" express
"Serverless" express
Anna Gerber
 
Basics of Automation, PLC and SCADA
Basics of Automation, PLC and SCADABasics of Automation, PLC and SCADA
Basics of Automation, PLC and SCADA
Indira 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

ArduinoSectionI-slides.ppt
ArduinoSectionI-slides.pptArduinoSectionI-slides.ppt
ArduinoSectionI-slides.ppt
Lam Hung
 
Intro_to_Arduino_-_v30.pptx
Intro_to_Arduino_-_v30.pptxIntro_to_Arduino_-_v30.pptx
Intro_to_Arduino_-_v30.pptx
CephasMpandikaKalemb
 
Instructor background
Instructor backgroundInstructor background
Instructor background
SERC at Carleton College
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
Qtechknow
 
Presentation
PresentationPresentation
Presentation
Edson Silva
 
Presentation S4A
Presentation S4A Presentation S4A
Presentation S4A
Pedro González Romero
 
SCSA1407.pdf
SCSA1407.pdfSCSA1407.pdf
SCSA1407.pdf
TYMEB130SANKETWALE
 
Lab2ppt
Lab2pptLab2ppt
Lab2ppt
Zhentao Xu
 
c ppt.pptx
c ppt.pptxc ppt.pptx
c ppt.pptx
RajHingar
 
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
ArsalanAthar
 
Arduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagramArduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagram
ArifatunNesa
 
Arduino
ArduinoArduino
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptxteststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
ethannguyen1618
 
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)
markumoto
 
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
CDI Aljeer
 
Sensor Lecture Interfacing
 Sensor Lecture Interfacing Sensor Lecture Interfacing
Sensor Lecture Interfacing
utpal sarkar
 
Computer hardware
Computer hardware Computer hardware
Computer hardware
umardanjumamaiwada
 
480 sensors
480 sensors480 sensors
480 sensors
Aditya Sharma
 
Arduino
Arduino Arduino
Arduino Comic-Jody Culkin-2011
Arduino Comic-Jody Culkin-2011Arduino Comic-Jody Culkin-2011
Arduino Comic-Jody Culkin-2011
ΚΔΑΠ Δήμου Θέρμης
 

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
PresentationPresentation
Presentation
 
Presentation S4A
Presentation S4A Presentation S4A
Presentation S4A
 
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 microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagramArduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagram
 
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
 

More from Anna Gerber

Internet of Things (IoT) Intro
Internet of Things (IoT) IntroInternet of Things (IoT) Intro
Internet of Things (IoT) Intro
Anna Gerber
 
How the Web works
How the Web worksHow the Web works
How the Web works
Anna 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 robot
Anna 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 Heroes
Anna Gerber
 
3D Printing Action Heroes
3D Printing Action Heroes3D Printing Action Heroes
3D Printing Action Heroes
Anna Gerber
 
3D Sculpting Action Heroes
3D Sculpting Action Heroes3D Sculpting Action Heroes
3D Sculpting Action Heroes
Anna 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 Annotation
Anna Gerber
 
Supporting Web-based Scholarly Annotation
Supporting Web-based Scholarly AnnotationSupporting Web-based Scholarly Annotation
Supporting Web-based Scholarly Annotation
Anna 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 visualisation
Anna Gerber
 
Annotations Supporting Scholarly Editing
Annotations Supporting Scholarly EditingAnnotations Supporting Scholarly Editing
Annotations Supporting Scholarly Editing
Anna Gerber
 
Getting started with the Trove API
Getting started with the Trove APIGetting started with the Trove API
Getting started with the Trove API
Anna Gerber
 
Intro to Java
Intro to JavaIntro to Java
Intro to Java
Anna Gerber
 
HackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover BrisbaneHackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover Brisbane
Anna Gerber
 
Using Yahoo Pipes
Using Yahoo PipesUsing Yahoo Pipes
Using Yahoo Pipes
Anna 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

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 

Recently uploaded (20)

Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 

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