SlideShare a Scribd company logo
Introduction to the Raspberry Pi
Jani Kalasniemi
Agenda
• FIRST STEPS
• What is a Raspberry Pi?
• Setting up your Raspberry Pi
• Using your Raspberry Pi as a Desktop
Computer
• PROGRAMMING WITH PYTHON
• Start Programming in Python
• Write your own Function
• Using GPIO to drive outputs and read inputs
• MAKINGADESKTOPAPPLICATION
• Learn about event-driven programming
• Create a simple Graphical User Interface(GUI)
FIRST STEPS
• A credit-card-sized computer
• Runs on several operating systems
Raspbian WE WILLUSE RASPBIAN
Windows 10 IoT Core
RetroPie
OpenElec
• Possible to connect with a variety
of sensors to interact with the
physical world.
• Make decisions based on processing of
gathered sensor data
What is a Raspberry Pi?
Getting started with your Raspberry Pi
Basic 1-2-3
1. Connect the Raspberry Pi
to the keyboard, mouse
and the screen.
2. Plug in the power and wait
for it to boot.
3. Username : pi
Password : raspberry
(should not be needed)
Using you Raspberry Pi as a Desktop Computer
• Try to access the internet through your Raspberry Pi and find a
picture that reflects your group. Hands up when you are done, for
help if needed!
• Save this picture to the desktop.
Communicating through the terminal
• Start the terminal by going to
Accessories and then clicking
on the Terminal program.
• Run through the commands
and get a feel for how to
change directories, and list its
contents.
PROGRAMMING WITH PYTHON
Programming in Python3
• General-purpose programming language used for scientific and
numerical applications as well as desktop and web applications.
• Open source language that has a lot of online resources for problems
you might come across.
• We are using Thonny IDE for programming with Python3 in our
Raspberry Pi 3 Model B
• https://stackoverflow.com is your best friend for programming
troubles
The GPIO
layout
General
Purpose
Input /
Output
Use the GPIO to drive outputs and read inputs
• Build the circuit in the figure.
Use 470 Ohm resistor
• Next we will make a program
that makes one LED blink on
and off, and the other dim up
and down in idensity when the
Button is pressed.
Use the GPIO to drive outputs and read inputs
Use the GPIO to drive outputs and read inputs
Common errors and debugging
• Python is sensetive to intendation.
• Make sure that the variables and the functions have the same exact
writing. Watch out for small and Capital letters!
• Remember that python starts counting from zero.
i.e when using loops.
Test your program and what you have made!
Questions?
Write you own Functions
Making a sin(x) function to get some output
Should return something like this
Using a sensor with the Raspberry Pi
• The GPIO on the Raspberry Pi can only handle a maximum of 3.3V,
but many of the available sensors can return a signal of 5V to the
GPIO. This will damage the Raspberry Pi.
• How do we deal with this?
• Resistors connected as voltage dividers.
• Important to be aware of this.
MeasuringDistancewitha UltrasonicSensor:HC-SR04
• The Trigger sends a burst of
sound that bounces and hits the
Echo.
• If we measure the time it takes
from sending to receiving we can
calculate the distance.
• NOTE: Two different resistors
here
Setting up the Raspberry Pi
Now we need a function to calculate the distance
• With the sensor we can measure the time it takes for a signal to be
sent out and reflected back.
• We need to convert the elapsed time to distance by using the speed
of sound in air and multiplying it with the time divided by two
(Because it travels to the object, and back).
The distance function
Making it loop until we tell it to stop
If the program is not giving any measurements
• Check the wiring!
• Check you code one more time.
• Check the resistors
• Check the wiring!
Questions?
MAKING A DESKTOP APPLICATION
Introducing Tkinter :AGUI Toolkit for Python
• De facto standard GUI for Python
• Toolkit for GUI programming in Python. Not the only one, but the most
commonly used one.
• Enables you to build GUI’s with buttons, sliders, drop downs, and
other interactions for the user of the program/device you build.
Event driven programming.
• When creating a GUI you use event driven programming.
• In the GUI all buttons, sliders, etc, are known as Widgets.
• When a widget is used it make an event in you code start.
• We will create a GUI
that enables us to
turn the LED on and
off with a button in a
GUI.
• Use the 470 Ohm
resistor in the circuit.
Create a simple Graphical User Interface(GUI)
Building the code for this GUI
Building the GUI
Building the GUI
• Now we need do decide what the GUI will actually do.
1. We will create a button that will switch the LED on and off
2. We also have to make an exit button so that when we exit the
program the LED turns off, and the GPIO port is reset to default as
input ports.
Creating the widget triggered event : ledToggle()
Creating the widget triggered event : close()
Creting the toggle button, aka a Widget
Creating the exit button
What happensif we exit the programthrough the window
exit?
This exit
Making sure that we have a clean exit
What happensif you run your program and pressa GUI
button?
Making the program run after we exit it on purpose
Will the last line be printed? If so, when?
Test your program and what you have made!
Questions?
Summary – What have we done?
• Introduced the Raspberry Pi and used it as a computer
• Learned simple commands to use in terminal
• Introduced the GPIO and how to get inputs from the physical world,
interpret them, and create output from input
• Used a XX sensor to read and evaluate data from your environment
• Introduced the Tkinter package and created a simple, event-driven,
GUI
Resources
• Raspberry Pi GPIO examples:
https://sourceforge.net/p/raspberry-gpio-python/wiki/Examples/
• Python Documentation:
https://www.python.org/doc/
• Tkinter Documentation:
https://www.tutorialspoint.com/python/python_gui_programming.htm
RaspberryPi_Workshop and Programming with python.

More Related Content

Similar to RaspberryPi_Workshop and Programming with python. (20)

Not so hard hardware
Not so hard hardwareNot so hard hardware
Not so hard hardware
richardgault
 
RaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMING
RaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMINGRaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMING
RaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMING
Asif Iqbal
 
Up and running with Raspberry Pi
Up and running with Raspberry PiUp and running with Raspberry Pi
Up and running with Raspberry Pi
Shahed Mehbub
 
IoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdfIoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdf
GVNSK Sravya
 
4. GPIO Access
4. GPIO Access4. GPIO Access
4. GPIO Access
Mayank Joneja
 
Raspberry Pi ppt.pptx
Raspberry Pi ppt.pptxRaspberry Pi ppt.pptx
Raspberry Pi ppt.pptx
ushabharathisb1
 
Raspberry Pi ppt.pptx
Raspberry Pi ppt.pptxRaspberry Pi ppt.pptx
Raspberry Pi ppt.pptx
ushabharathisb1
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
Tom Paulus
 
ScratchGPIO, Raspberry Pi & BerryClip
ScratchGPIO, Raspberry Pi & BerryClipScratchGPIO, Raspberry Pi & BerryClip
ScratchGPIO, Raspberry Pi & BerryClip
David Dryden
 
Raspberry Pi 4.pdf
Raspberry Pi 4.pdfRaspberry Pi 4.pdf
Raspberry Pi 4.pdf
Engineering Funda
 
manual_2020_Cyber Physical System.pdf
manual_2020_Cyber Physical System.pdfmanual_2020_Cyber Physical System.pdf
manual_2020_Cyber Physical System.pdf
ssuserc5ee4c
 
Exploring the abc's of raspberry pi and python(day 2)
Exploring the abc's of raspberry pi and python(day 2)Exploring the abc's of raspberry pi and python(day 2)
Exploring the abc's of raspberry pi and python(day 2)
Shahed Mehbub
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
ABHIJITPATRA23
 
Raspberry Pi 4 2020 Beginners Guide A Complete 2020 Manual To Get Started Wit...
Raspberry Pi 4 2020 Beginners Guide A Complete 2020 Manual To Get Started Wit...Raspberry Pi 4 2020 Beginners Guide A Complete 2020 Manual To Get Started Wit...
Raspberry Pi 4 2020 Beginners Guide A Complete 2020 Manual To Get Started Wit...
astraelysatv
 
Raspberry Pi - Unlocking New Ideas for Your Library
Raspberry Pi - Unlocking New Ideas for Your LibraryRaspberry Pi - Unlocking New Ideas for Your Library
Raspberry Pi - Unlocking New Ideas for Your Library
Brian Pichman
 
M.Tech Internet of Things Unit - III.pptx
M.Tech Internet of Things Unit - III.pptxM.Tech Internet of Things Unit - III.pptx
M.Tech Internet of Things Unit - III.pptx
AvinashAvuthu2
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptx
TuynLCh
 
embedded report
embedded reportembedded report
embedded report
Gopikanth.M Tatavarthi
 
Raspberry pi overview
Raspberry pi overview Raspberry pi overview
Raspberry pi overview
Matthew Karas
 
My presentation raspberry pi
My presentation raspberry piMy presentation raspberry pi
My presentation raspberry pi
HusainBhaldar21
 
Not so hard hardware
Not so hard hardwareNot so hard hardware
Not so hard hardware
richardgault
 
RaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMING
RaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMINGRaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMING
RaspberryPI PPT WITH ALL THE DETAILS OF PROGRAMMING
Asif Iqbal
 
Up and running with Raspberry Pi
Up and running with Raspberry PiUp and running with Raspberry Pi
Up and running with Raspberry Pi
Shahed Mehbub
 
IoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdfIoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdf
GVNSK Sravya
 
Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
Tom Paulus
 
ScratchGPIO, Raspberry Pi & BerryClip
ScratchGPIO, Raspberry Pi & BerryClipScratchGPIO, Raspberry Pi & BerryClip
ScratchGPIO, Raspberry Pi & BerryClip
David Dryden
 
manual_2020_Cyber Physical System.pdf
manual_2020_Cyber Physical System.pdfmanual_2020_Cyber Physical System.pdf
manual_2020_Cyber Physical System.pdf
ssuserc5ee4c
 
Exploring the abc's of raspberry pi and python(day 2)
Exploring the abc's of raspberry pi and python(day 2)Exploring the abc's of raspberry pi and python(day 2)
Exploring the abc's of raspberry pi and python(day 2)
Shahed Mehbub
 
Raspberry Pi 4 2020 Beginners Guide A Complete 2020 Manual To Get Started Wit...
Raspberry Pi 4 2020 Beginners Guide A Complete 2020 Manual To Get Started Wit...Raspberry Pi 4 2020 Beginners Guide A Complete 2020 Manual To Get Started Wit...
Raspberry Pi 4 2020 Beginners Guide A Complete 2020 Manual To Get Started Wit...
astraelysatv
 
Raspberry Pi - Unlocking New Ideas for Your Library
Raspberry Pi - Unlocking New Ideas for Your LibraryRaspberry Pi - Unlocking New Ideas for Your Library
Raspberry Pi - Unlocking New Ideas for Your Library
Brian Pichman
 
M.Tech Internet of Things Unit - III.pptx
M.Tech Internet of Things Unit - III.pptxM.Tech Internet of Things Unit - III.pptx
M.Tech Internet of Things Unit - III.pptx
AvinashAvuthu2
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptx
TuynLCh
 
Raspberry pi overview
Raspberry pi overview Raspberry pi overview
Raspberry pi overview
Matthew Karas
 
My presentation raspberry pi
My presentation raspberry piMy presentation raspberry pi
My presentation raspberry pi
HusainBhaldar21
 

Recently uploaded (20)

Presentation SoftwareNOTES AND USES..pdf
Presentation SoftwareNOTES AND USES..pdfPresentation SoftwareNOTES AND USES..pdf
Presentation SoftwareNOTES AND USES..pdf
bathyates
 
Jadual Waktu dan Jadual Bertugas kelas.pptx
Jadual Waktu dan Jadual Bertugas kelas.pptxJadual Waktu dan Jadual Bertugas kelas.pptx
Jadual Waktu dan Jadual Bertugas kelas.pptx
roslan17
 
Types of Information Sources (Primary, Secondary, and Tertiary Sources)
Types of Information Sources (Primary, Secondary, and Tertiary Sources)Types of Information Sources (Primary, Secondary, and Tertiary Sources)
Types of Information Sources (Primary, Secondary, and Tertiary Sources)
jenicahmendoza1
 
Assesement_PPT Designer -----------Final
Assesement_PPT Designer -----------FinalAssesement_PPT Designer -----------Final
Assesement_PPT Designer -----------Final
RajeshKumarKumre
 
Bob Stewart Acts 17 Study 06 11 2025.pptx
Bob Stewart Acts 17 Study 06 11 2025.pptxBob Stewart Acts 17 Study 06 11 2025.pptx
Bob Stewart Acts 17 Study 06 11 2025.pptx
FamilyWorshipCenterD
 
كتاب تتتتتماين من انتااا كليه علوم حلوان
كتاب تتتتتماين من انتااا كليه علوم حلوانكتاب تتتتتماين من انتااا كليه علوم حلوان
كتاب تتتتتماين من انتااا كليه علوم حلوان
ziadwaleed55op
 
Food Truck Business Plan | Sakthi Sundar.pptx
Food Truck Business Plan | Sakthi Sundar.pptxFood Truck Business Plan | Sakthi Sundar.pptx
Food Truck Business Plan | Sakthi Sundar.pptx
Sakthi Sundar
 
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
Caribbean Development Bank
 
ART INTAGRATED PROJECT in chemistry about resources
ART INTAGRATED PROJECT in chemistry about resourcesART INTAGRATED PROJECT in chemistry about resources
ART INTAGRATED PROJECT in chemistry about resources
mcarchana74
 
Sample work (PL Product Research) Joseph_Juntilla.pdf
Sample work (PL Product Research) Joseph_Juntilla.pdfSample work (PL Product Research) Joseph_Juntilla.pdf
Sample work (PL Product Research) Joseph_Juntilla.pdf
Joseph Juntilla
 
Pentecost Sunday A Promise of Power.pptx
Pentecost Sunday A Promise of Power.pptxPentecost Sunday A Promise of Power.pptx
Pentecost Sunday A Promise of Power.pptx
FamilyWorshipCenterD
 
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
Bryan K. O'Rourke
 
presentacion de Inspire Power Point.pptx
presentacion de Inspire Power Point.pptxpresentacion de Inspire Power Point.pptx
presentacion de Inspire Power Point.pptx
teamspro
 
Diddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptxDiddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptx
RanitMal
 
2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx
Dale Wells
 
The Love of a Father 06 15 2025.pptx
The  Love  of  a  Father 06 15 2025.pptxThe  Love  of  a  Father 06 15 2025.pptx
The Love of a Father 06 15 2025.pptx
FamilyWorshipCenterD
 
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEWTHE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
rspyamin
 
Road safety presentation for high school
Road safety presentation for high schoolRoad safety presentation for high school
Road safety presentation for high school
nikhithavarghese77
 
From Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon PerformanceFrom Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon Performance
outsystemspuneusergr
 
Retail Store Scavenger Hunt experience!!
Retail Store Scavenger Hunt experience!!Retail Store Scavenger Hunt experience!!
Retail Store Scavenger Hunt experience!!
Samally Dávila
 
Presentation SoftwareNOTES AND USES..pdf
Presentation SoftwareNOTES AND USES..pdfPresentation SoftwareNOTES AND USES..pdf
Presentation SoftwareNOTES AND USES..pdf
bathyates
 
Jadual Waktu dan Jadual Bertugas kelas.pptx
Jadual Waktu dan Jadual Bertugas kelas.pptxJadual Waktu dan Jadual Bertugas kelas.pptx
Jadual Waktu dan Jadual Bertugas kelas.pptx
roslan17
 
Types of Information Sources (Primary, Secondary, and Tertiary Sources)
Types of Information Sources (Primary, Secondary, and Tertiary Sources)Types of Information Sources (Primary, Secondary, and Tertiary Sources)
Types of Information Sources (Primary, Secondary, and Tertiary Sources)
jenicahmendoza1
 
Assesement_PPT Designer -----------Final
Assesement_PPT Designer -----------FinalAssesement_PPT Designer -----------Final
Assesement_PPT Designer -----------Final
RajeshKumarKumre
 
Bob Stewart Acts 17 Study 06 11 2025.pptx
Bob Stewart Acts 17 Study 06 11 2025.pptxBob Stewart Acts 17 Study 06 11 2025.pptx
Bob Stewart Acts 17 Study 06 11 2025.pptx
FamilyWorshipCenterD
 
كتاب تتتتتماين من انتااا كليه علوم حلوان
كتاب تتتتتماين من انتااا كليه علوم حلوانكتاب تتتتتماين من انتااا كليه علوم حلوان
كتاب تتتتتماين من انتااا كليه علوم حلوان
ziadwaleed55op
 
Food Truck Business Plan | Sakthi Sundar.pptx
Food Truck Business Plan | Sakthi Sundar.pptxFood Truck Business Plan | Sakthi Sundar.pptx
Food Truck Business Plan | Sakthi Sundar.pptx
Sakthi Sundar
 
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
Caribbean Development Bank
 
ART INTAGRATED PROJECT in chemistry about resources
ART INTAGRATED PROJECT in chemistry about resourcesART INTAGRATED PROJECT in chemistry about resources
ART INTAGRATED PROJECT in chemistry about resources
mcarchana74
 
Sample work (PL Product Research) Joseph_Juntilla.pdf
Sample work (PL Product Research) Joseph_Juntilla.pdfSample work (PL Product Research) Joseph_Juntilla.pdf
Sample work (PL Product Research) Joseph_Juntilla.pdf
Joseph Juntilla
 
Pentecost Sunday A Promise of Power.pptx
Pentecost Sunday A Promise of Power.pptxPentecost Sunday A Promise of Power.pptx
Pentecost Sunday A Promise of Power.pptx
FamilyWorshipCenterD
 
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
Bryan K. O'Rourke
 
presentacion de Inspire Power Point.pptx
presentacion de Inspire Power Point.pptxpresentacion de Inspire Power Point.pptx
presentacion de Inspire Power Point.pptx
teamspro
 
Diddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptxDiddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptx
RanitMal
 
2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx
Dale Wells
 
The Love of a Father 06 15 2025.pptx
The  Love  of  a  Father 06 15 2025.pptxThe  Love  of  a  Father 06 15 2025.pptx
The Love of a Father 06 15 2025.pptx
FamilyWorshipCenterD
 
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEWTHE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
rspyamin
 
Road safety presentation for high school
Road safety presentation for high schoolRoad safety presentation for high school
Road safety presentation for high school
nikhithavarghese77
 
From Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon PerformanceFrom Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon Performance
outsystemspuneusergr
 
Retail Store Scavenger Hunt experience!!
Retail Store Scavenger Hunt experience!!Retail Store Scavenger Hunt experience!!
Retail Store Scavenger Hunt experience!!
Samally Dávila
 
Ad

RaspberryPi_Workshop and Programming with python.

  • 1. Introduction to the Raspberry Pi Jani Kalasniemi
  • 2. Agenda • FIRST STEPS • What is a Raspberry Pi? • Setting up your Raspberry Pi • Using your Raspberry Pi as a Desktop Computer • PROGRAMMING WITH PYTHON • Start Programming in Python • Write your own Function • Using GPIO to drive outputs and read inputs • MAKINGADESKTOPAPPLICATION • Learn about event-driven programming • Create a simple Graphical User Interface(GUI)
  • 4. • A credit-card-sized computer • Runs on several operating systems Raspbian WE WILLUSE RASPBIAN Windows 10 IoT Core RetroPie OpenElec • Possible to connect with a variety of sensors to interact with the physical world. • Make decisions based on processing of gathered sensor data What is a Raspberry Pi?
  • 5. Getting started with your Raspberry Pi Basic 1-2-3 1. Connect the Raspberry Pi to the keyboard, mouse and the screen. 2. Plug in the power and wait for it to boot. 3. Username : pi Password : raspberry (should not be needed)
  • 6. Using you Raspberry Pi as a Desktop Computer • Try to access the internet through your Raspberry Pi and find a picture that reflects your group. Hands up when you are done, for help if needed! • Save this picture to the desktop.
  • 7. Communicating through the terminal • Start the terminal by going to Accessories and then clicking on the Terminal program. • Run through the commands and get a feel for how to change directories, and list its contents.
  • 9. Programming in Python3 • General-purpose programming language used for scientific and numerical applications as well as desktop and web applications. • Open source language that has a lot of online resources for problems you might come across. • We are using Thonny IDE for programming with Python3 in our Raspberry Pi 3 Model B • https://stackoverflow.com is your best friend for programming troubles
  • 11. Use the GPIO to drive outputs and read inputs • Build the circuit in the figure. Use 470 Ohm resistor • Next we will make a program that makes one LED blink on and off, and the other dim up and down in idensity when the Button is pressed.
  • 12. Use the GPIO to drive outputs and read inputs
  • 13. Use the GPIO to drive outputs and read inputs
  • 14. Common errors and debugging • Python is sensetive to intendation. • Make sure that the variables and the functions have the same exact writing. Watch out for small and Capital letters! • Remember that python starts counting from zero. i.e when using loops.
  • 15. Test your program and what you have made! Questions?
  • 16. Write you own Functions
  • 17. Making a sin(x) function to get some output
  • 19. Using a sensor with the Raspberry Pi • The GPIO on the Raspberry Pi can only handle a maximum of 3.3V, but many of the available sensors can return a signal of 5V to the GPIO. This will damage the Raspberry Pi. • How do we deal with this? • Resistors connected as voltage dividers. • Important to be aware of this.
  • 20. MeasuringDistancewitha UltrasonicSensor:HC-SR04 • The Trigger sends a burst of sound that bounces and hits the Echo. • If we measure the time it takes from sending to receiving we can calculate the distance. • NOTE: Two different resistors here
  • 21. Setting up the Raspberry Pi
  • 22. Now we need a function to calculate the distance • With the sensor we can measure the time it takes for a signal to be sent out and reflected back. • We need to convert the elapsed time to distance by using the speed of sound in air and multiplying it with the time divided by two (Because it travels to the object, and back).
  • 24. Making it loop until we tell it to stop
  • 25. If the program is not giving any measurements • Check the wiring! • Check you code one more time. • Check the resistors • Check the wiring!
  • 27. MAKING A DESKTOP APPLICATION
  • 28. Introducing Tkinter :AGUI Toolkit for Python • De facto standard GUI for Python • Toolkit for GUI programming in Python. Not the only one, but the most commonly used one. • Enables you to build GUI’s with buttons, sliders, drop downs, and other interactions for the user of the program/device you build.
  • 29. Event driven programming. • When creating a GUI you use event driven programming. • In the GUI all buttons, sliders, etc, are known as Widgets. • When a widget is used it make an event in you code start.
  • 30. • We will create a GUI that enables us to turn the LED on and off with a button in a GUI. • Use the 470 Ohm resistor in the circuit. Create a simple Graphical User Interface(GUI)
  • 31. Building the code for this GUI
  • 33. Building the GUI • Now we need do decide what the GUI will actually do. 1. We will create a button that will switch the LED on and off 2. We also have to make an exit button so that when we exit the program the LED turns off, and the GPIO port is reset to default as input ports.
  • 34. Creating the widget triggered event : ledToggle()
  • 35. Creating the widget triggered event : close()
  • 36. Creting the toggle button, aka a Widget
  • 38. What happensif we exit the programthrough the window exit? This exit
  • 39. Making sure that we have a clean exit
  • 40. What happensif you run your program and pressa GUI button?
  • 41. Making the program run after we exit it on purpose Will the last line be printed? If so, when?
  • 42. Test your program and what you have made! Questions?
  • 43. Summary – What have we done? • Introduced the Raspberry Pi and used it as a computer • Learned simple commands to use in terminal • Introduced the GPIO and how to get inputs from the physical world, interpret them, and create output from input • Used a XX sensor to read and evaluate data from your environment • Introduced the Tkinter package and created a simple, event-driven, GUI
  • 44. Resources • Raspberry Pi GPIO examples: https://sourceforge.net/p/raspberry-gpio-python/wiki/Examples/ • Python Documentation: https://www.python.org/doc/ • Tkinter Documentation: https://www.tutorialspoint.com/python/python_gui_programming.htm