Slide 1

Slide 1 text

Teach, Learn and Make with Raspberry Pi Ben Nuttall Raspberry Pi Foundation UK Charity 1129409

Slide 2

Slide 2 text

Raspberry Pi Foundation ● Registered UK charity 1129409 ● Founded in 2009 to aid computing education ● On general sale since 2012, available to all worldwide – Sold to education, industry and hobbyists – Sold 6 million to date ● Free learning resources for makers and educators ● Free teacher training - Picademy (currently UK, soon USA)

Slide 3

Slide 3 text

Ben Nuttall ● Education Developer Advocate at the Raspberry Pi Foundation – Software & project development – Learning resources & teacher training – Outreach ● Hobbyist turned employee ● Based in Cambridge, UK ● @ben_nuttall on Twitter

Slide 4

Slide 4 text

Raspberry Pi ● Sonic Pi ● Python ● Physical computing ● Minecraft: Pi Edition ● Picamera ● Astro Pi

Slide 5

Slide 5 text

Sonic Pi ● Sound synthesiser for creating music ● Audible computing ● Uses simple syntax text-based programming language Ruby ● Used for compositions and live coding performances ● Introduce computing concepts through music ● Created especially for education

Slide 6

Slide 6 text

Python ● Powerful extensible programming language ● Easy to read and write ● Make software, games, GUIs, websites, robots and more ● Ideal for physical computing ● Extensive library of additional modules for Raspberry Pi hardware ● Recommended for education

Slide 7

Slide 7 text

Physical computing ● Flashy lights ● Motors & robots ● Photo & video ● Sensors ● Internet of Things ● Engaging and empowering

Slide 8

Slide 8 text

3V3 = always on

Slide 9

Slide 9 text

GPIO = user controllable

Slide 10

Slide 10 text

Flash LED with Python from RPi import GPIO from time import sleep GPIO.setmode(GPIO.BCM) led = 2 GPIO.setup(led, GPIO.OUT) while True: GPIO.output(led, True) sleep(1) GPIO.output(led, False) sleep(1)

Slide 11

Slide 11 text

Traffic Lights from RPi import GPIO from time import sleep GPIO.setmode(GPIO.BCM) red = 9 yellow = 10 green = 11 leds = [red, yellow, green] for led in leds: GPIO.setup(led, GPIO.OUT) GPIO.output(green, True) GPIO.output(yellow, False) GPIO.output(red, False)

Slide 12

Slide 12 text

Traffic Lights while True: sleep(10) GPIO.output(green, False) GPIO.output(yellow, True) sleep(1) GPIO.output(yellow, False) GPIO.output(red, True) sleep(10) GPIO.output(yellow, True) sleep(1) GPIO.output(green, True) GPIO.output(yellow, False) GPIO.output(red, False)

Slide 13

Slide 13 text

An alternative approach class LED(object): def __init__(self, pin): self.pin = pin GPIO.setup(pin, GPIO.OUT) def on(self): GPIO.output(self.pin, True) def off(self): GPIO.output(self.pin, False) red = LED(9) yellow = LED(10) green = LED(11)

Slide 14

Slide 14 text

An alternative approach green.on() yellow.off() red.off() while True: sleep(10) green.off() yellow.on() sleep(1) yellow.off() red.on() sleep(10) yellow.on() sleep(1) green.on() yellow.off() red.off()

Slide 15

Slide 15 text

Traffic Lights green.on() yellow.off() red.off() sleep(10)

Slide 16

Slide 16 text

Traffic Lights green.off() yellow.on() sleep(1)

Slide 17

Slide 17 text

Traffic Lights yellow.off() red.on() sleep(10)

Slide 18

Slide 18 text

Traffic Lights yellow.on() sleep(1)

Slide 19

Slide 19 text

Traffic Lights green.on() yellow.off() red.off()

Slide 20

Slide 20 text

Minecraft: Pi Edition ● Free version of Minecraft on Raspberry Pi ● Python programming interface ● Learn Python by building things and making games in Minecraft ● Creative computing

Slide 21

Slide 21 text

Flowers from mcpi.minecraft import Minecraft from time import sleep mc = Minecraft.create() flower = 38 while True: x, y, z = mc.player.getPos() mc.setBlock(x, y, z, flower) sleep(0.1)

Slide 22

Slide 22 text

Planting flowers grass = 2 flower = 38 while True: x, y, z = mc.player.getPos() # player position (x, y, z) block_beneath = mc.getBlock(x, y­1, z) # block ID if block_beneath == grass: mc.setBlock(x, y, z, flower) else: mc.setBlock(x, y­1, z, grass) sleep(0.1)

Slide 23

Slide 23 text

Picamera ● Official Raspberry Pi camera module ● Command line interface for basic use ● Python programming interface for projects ● Still pictures, video, time- lapse

Slide 24

Slide 24 text

Camera preview ● Open Terminal window ● raspistill -k

Slide 25

Slide 25 text

Python – take a selfie from picamera import PiCamera from time import sleep with picamera.PiCamera() as camera: camera.start_preview() sleep(5) camera.capture('/home/pi/image.jpg') camera.stop_preview()

Slide 26

Slide 26 text

Python – stop motion with picamera.PiCamera() as camera: camera.start_preview() frame = 1 while True: next = input('Press Enter to continue...') camera.capture('/home/pi/animation/frame%03d.jpg' % frame) frame += 1

Slide 27

Slide 27 text

Astro Pi

Slide 28

Slide 28 text

Sense HAT ● 8x8 RGB LED matrix ● Mini joystick ● Gyroscope ● Accelerometer ● Magnetometer ● Temperature sensor ● Barometric pressure sensor ● Humidity sensor

Slide 29

Slide 29 text

Sense HAT - Python from sense_hat import SenseHat sense = SenseHat() sense.show_message('Hello world!')

Slide 30

Slide 30 text

More examples https://github.com/RPi­Distro/python­sense­ hat/tree/master/examples https://github.com/bennuttall/sense­hat­examples

Slide 31

Slide 31 text

Resources https://www.raspberrypi.org/resources/

Slide 32

Slide 32 text

Teach, Learn and Make with Raspberry Pi Ben Nuttall Raspberry Pi Foundation UK Charity 1129409