Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Python with Raspberry Pi

Similar presentations


Presentation on theme: "Introduction to Python with Raspberry Pi"— Presentation transcript:

1 Introduction to Python with Raspberry Pi
Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

2 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
History Raspberry Pi first came onto the scene in 2012.  As the story goes, Eben Upton, director of studies at St. John's College, Cambridge inthe UK, and colleagues came up with the Raspberry Pi as a tool to improve education. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

3 WHAT MAKES RASPBERRY Pi SO COOL?
Part of what makes Raspberry Pi such a neat device is it's a powerful computer packed onto a small board and it's cheap.  It can do anything a stand alone computer can do.  The other feature is that you can control things like motors and interface it directly with circuits.  This is why the Raspberry Pi has been embraced by the maker community.  What distinguishes makers is that they build devices that, just a few years ago, could only realistically be built by companies. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

4 WE'RE GOING TO START A REVOLUTION
I don't think it's hyperbole to say that we're on the edge of another technology evolution.  Engineering majors certainly do learn about microcontrollers and electric machines, but they usually don't learn about those things until their junior year.  And too often, those classes get bogged down in theory to the detriment of learning how to actually build and control machines.  Theory's very, very important, of course, but you also want to be able to build things right out of the gate too.  And the other great aspect of Raspberry Pi is that you can build useful devices and systems without getting swamped in theory. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

5 SOME KINDS OF RASPBERRY Pis
Let's next take a look at the Raspberry Pi hardware: 1) Raspberry Pi 3 came on the market in ) Pi 2 has a slower processor and no built in wireless support. There is not a huge difference between the Pi 3's and the Pi 2's. 3) There is also a Raspberry Pi Zero, which is an even cheaper model, but it of course has less memory, a less powerful processor, and fewer features. It is good for dedicated projects and experimenting. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

6 RASPBERRY Pi 2 AND Pi 3 INTERNALS
Raspberry Pi 2: RAM: 1GB System on Chip(SoC): BCM CPU: QUAD Core ARM 7 runs at 800MHz, but has been clocked at 1GHz GPU: Video Core IV 250 MHz Raspberry Pi 3: RAM: 1GB System on Chip(SoC): BCM CPU: 1.2 GHz ARM Cortex A53 GPU: Video Core IV 400 MHz Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

7 RASPBERRY Pi 2 AND Pi 3 INTERNALS
The Pi 2 and Pi 3 look physically almost the same, save for the built in WiFi and Bluetooth. Both of these have four USB ports: you connect up a keyboard and mouse to two of these ports.  And you could hook up a USB drive to one of the other ports, and you've got a fourth port for whatever. There's an Ethernet connection on both.  The Pi 3 also has WiFI and Bluetooth connectivity built in.  You can use WiFi on the Pi 2 but you'd need a WiFi dongle. There's an HDMI connector so you can connect a monitor or a TV. There's a 3.5mm audio/video jack. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

8 RASPBERRY Pi 2 AND Pi 3 INTERNALS
There's a standard micro USB connector for power input.  You could use a cell phone charger, one for an Android phone would probably work. I'm just using the Raspberry Pi official charger. There's the micro SD card slot. The micro SD card is where you store the operating system and your files. There are 40 GPIOs (General Purpose Input/Output), and these are what enable you to connect the Raspberry Pi to external hardware. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

9 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Raspberry Pi 3 B Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

10 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Raspberry Pi 3 A+ Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

11 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Pi ZERO Specs Super Cheap! Five Bucks! RAM: 512MB System on Chip(SoC): BCM CPU: ARM 11 clocked at 1GHz It has 40 GPIOs, but the header pins are missing. You need to solder on any connections. Sparse ports: Has only one micro USB port, which requires an adaptor to connect to standard USB devices or a USB hub. Has a mini HDMI port, which requires an adaptor to connect to HDMI connector. Micro SD port is present, but push-click locking mechanism has been removed to save space and reduce cost. No built in Ethernet connectivity, but Ethernet connectivity can be added. Target: If you need a bunch of Raspberry Pis for whatever it is you're building.  Not suitable for learning how to use Raspberry Pi. Basically, it's for people who already know Raspberry Pi, and are building things like robots or security systems. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

12 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Pi ZERO Specs Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

13 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
SAME COMPUTER... Basically, the same computer.  They run the same operating system software.  The differences are in the price, processor, RAM, and connectivity. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

14 MICRO SD SPECIFICATIONS
_______________________________________ Class 2        2MB/sec Class 4        4MB/sec Class 6        6MB/sec Class 10    10MB/sec The minimum memory for Raspberry Pi is 4GB.  However, you really need at least 8GB, and 16GB is an even better choice.  The 16GB SD card is, in my opinion, the best choice because it's more than enough memory to do the kinds of projects we'll be doing in class.  Large capacity SD cards are available up to 200 GB, but those expensive and not necessary unless ….. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

15 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

16 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Operating Systems You can buy the micro SD cards with the operating system pre-loaded or you can buy a micro SD card and install the operating system yourself.  The Raspian is the OS that is pre-loaded. 1) Raspian: Recommended. It's a Linux distribution based on Debian. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

17 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Operating Systems 2) Arch: For experienced users.  No built in desktop. 3) OpenELEC: Ubuntu distribution for multimedia, supports Codi. 4) RaspBMC: media-centric distribution; blends XBOX with Raspian 5) Ubuntu MATE for the Raspberry Pi 2 and Raspberry Pi 3 6) Kali Linux for Raspberry Pi 7) Windows 10 IoT Core Some other operating systems: Pidora (Fedora for the Pi), but it probably won't be updated, since the data partition is awkward, Raspian (boot to Scratch) is really for kids, and RetroPie for gaming. There is also RISC OS, which is not Linux based. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

18 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
GPIOs Pi 2, Pi 3, and Pi Zero all have 40 GPIOs.  Older Raspberry Pis only had 26 GPIOs.  This is the feature that enables you to hook up external boards and circuits to the Raspberry Pi. You can actually breadboard a circuit and hook the circuit directly up to the Raspberry Pi and have the Raspberry Pi control the circuit. This is really useful for people who design and develop circuits.  You do have to be a little careful if you use the Pi this way because it is possible to fry the Pi. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

19 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

20 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Do not fry your Pi! Connect the USB keyboard and USB first Connect the HMDI connector Turn on the monitor Plug in the power cable Do not plug in a HAT on a Pi that is plugged in and booted into Raspian. Plug in the HAT before plugging in the power cable. Connect the GND last when connecting circuits to the pins Disconnect the GND first when connecting circuits to the pins Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

21 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Do not fry your Pi! Input no more that 3.3V to a GPIO Use GPIO.cleanup() to set the GPIO pins back to a safe state; input only This will ensure that you do not accidently make a short circuit or other errors Current load should be less than 16mA on any one GPIO pin Current load should be less than 100mA for all GPIO pins Do not connect a motor directly to the Pi's GPIO, the back EMF(Electromotive Force) will fry the Pi; Use a transistor Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

22 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
HATs HAT stands for Hardware Attached on Top.  These are external boards you can purchase that plug right into the GPIOs.  The Raspberry Pi designers made the Pis backwards compatible, so newer Raspberry Pis can use older boards.  The RaspiRobot HAT has 26 pins; it was designed to work with older Raspberry Pis, but it still works with the newer Pis. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

23 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
HAT Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

24 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Sense HAT temperature, pressure, humidity sensors accelerometer, compass detects yaw, roll, and pitch joystick Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

25 Creating Python 3 Scripts
Menu → Programming → Python 3 (IDLE) IDLE = Integrated Developers Environment File → New File Run → Run Module or press F5 to run Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

26 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Python Code from sense_hat import SenseHat sense = SenseHat() sense.show_message("Welcome to Python with Raspberry Pi", scroll_speed = 0.1,text_colour=[0,255,255]) Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

27 Getting Help on Classes
help(SenseHat) Use the help function to find information on the properties and functions associated with the class. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

28 Scrolling Text on the SenseHat
from sense_hat import SenseHat from time import sleep sense = SenseHat() t = sense.get_temperature() # access the temperature t = round(t,1) # round to one decimal point p = sense.get_pressure() # access the pressure p = round(p,1) h = sense.get_humidity() # access the humidity h = round(h,3) # round to three decimal points Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

29 Scrolling Text on the SenseHat
msg = "Temperature: "+str(t)+" Pressure "+str(p)+" Humidity "+str(h) str() converts to a string sense.show_message(msg,0.1,[0,0,230],[0,255,255]) msg is text_string, scroll_speed=0.1, text_colour=[255, 255, 255], back_colour=[255, 0, 0] Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

30 Displaying one character
from sense_hat import SenseHat from time import sleep sense = SenseHat() sense.show_letter("H",text_colour=[20,255,80]) text_colour = [red,green,blue] 0 (no color) to 255 (saturation) sleep(3) Sleep for 3 seconds; pause the execution of the code sense.show_letter("i",text_colour=[20,255,80]) sense.clear() clear the SenseHat Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

31 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Set a pixel from sense_hat import SenseHat from time import sleep sense = SenseHat() sense.set_pixel(0,2,255,0,0) (x,y,red,green,blue) x coordinate 0 to 7 and y coordinate 0 to 7 Red pixel at coordinate x = 0, y = 2 sleep(0.5) sleep for 0.5 second Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

32 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Set a pixel sense.set_pixel(7,7,0,0,255) Blue pixel at coordinate x = 7, y = 7 sleep(0.5) sense.clear() Clear the SenseHat Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath

33 Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath
Update and Upgrade Go to the Terminal sudo apt-get update sudo apt-get upgrade Do not interrupt either of these commands. The second command will take between 30 minutes and two hours depending upon your network connection. Text Copyright (c) 2017 by Dr. Elizabeth I. Horvath


Download ppt "Introduction to Python with Raspberry Pi"

Similar presentations


Ads by Google