 Good morning, everyone. Welcome, great to be back at Yorah Python. This is my talk, Physical Computing with Python and the Raspberry Pi. My name is Ben Nussle. I'm from the Raspberry Pi Foundation. We've got a series of talks today, so we've just had Karyan's brilliant keynote, and we've got a few talks lined up in this track related to education. It's the Education Summit that expands to this weekend as well. We've got some sprints and education stuff trying to crack on with Karyan's list that she's given us all to do. So a bit about me to start. I'm an education developer advocate at the Raspberry Pi Foundation. I do software and projects, kind of develop stuff internally, and do some, I write learning resources that go on our website, the free and Creative Commons learning platform we have there. We run teacher training courses with something called Pi Academy, and I do a lot of outreach, go to a lot of conferences and stuff. We're based in Cambridge in the UK. That's me on Twitter, Ben Nussle. If you were at EuroPython, Pycon UK, PIS, Pycon Island, or EurosidePy last year, you may have seen me speak. So just a quick update. Since I was here last year, the news is it relates to hardware. We've now got the Raspberry Pi 2, second-generation Raspberry Pi. It's now a 900 MHz quad-core on V7 with a gig of RAM. Its back was compatible in exactly the same shape and size as the previous model, the B-plus. We kept it at the same price, which is $35, and reduced the old ones down to 25, and the A-plus is 20. So we are an educational charity, as Cary Ann's just been talking about. It's not something that kind of came afterwards and kind of bolted onto a computer company or a hardware company. The idea was originally to help education, and that's why we wanted to create something to empower young people and give them a possibility to learn programming skills and learn about computing from an early age in a kind of sandbox environment. They've been on general sale since 2012, and they've been made available worldwide to everybody who wants one for the same price. We're not limiting this to just children or just the developing world. It's the same price for everyone because that's really helpful to have that whole community around the Raspberry Pi. I'll give some examples. We write free learning resources for makers and educators, and as I say, we have this Pi Academy, our teacher training CPD course, professional development course currently in the UK. We run a few around the UK, and we're taking it to the USA next year, and we'd like to see more things like that around the world. A couple of stories to start about our community and about our origins and how things have developed over the last three years. Ben Crossden is a guy in the UK who brews beer. He wanted to use the Raspberry Pi to control the beer brewing process and monitor it from his phone and have a web app running in that kind of thing. He chose the Raspberry Pi and chose Python to write it in, so he started to develop a platform which allowed him to communicate over the GPIO pins. I'll explain more about those in the next few slides. That project became a general-purpose library for how you talk to the GPIO pins from Python. Another example, Dave Jones, also in the UK. His wife is a paleontologist, and she wanted to use a microscope to do some fossil photography and that kind of thing. The problem was that the university's microscope was a real pullover to use, and it stored it to an external drive somewhere else on the network that you had to then get permission to access, and it was a real pain. He said, just stick a Pi camera on the top, and then you'll get the pictures straight out and be able to use them. He built a little web app that allowed her to monitor and deal with all the pictures that came out of it and archive them. Again, this became the general-purpose Pi camera library, and it's a fantastic resource for people to anyone who wants to use the camera for anything, and he's been working on it ever since. In fact, I told him recently, because I kind of talk about this in a lot of my talks, and I said, oh, by the way, I always use you as an example of when I'm talking about community at the conferences, about how you created the web app for your wife, and he said, oh, did I? Is that why I started? So Raspbian is our Linux distribution that we use. It's a foundation-issued, Debian-based distribution, currently based on Debian Weezy. Jesse is now kind of stable, so we're going to be moving to that shortly. The image that we provide supports Pi 2 and Pi 1, even though they're different architectures on 6 and 7, but we make sure that we still support our old users on the old platform. We pre-install certain software on that image, so you get the Python interpreter, you get idle, unfortunately, and a bunch of other stuff. There's Ruby on there, Sonic Pi, Java, Mathematica, and stuff like that, that we kind of put in the image and create it so that you can use it out of the box. We have other things as well that are kind of community-contributed, so the GPIO library and the Pi Camera Library, for instance, are examples of what's already installed and once we move on to Jesse, it will be a lot easier for us to ship with pip pre-installed. There's alternative distributions available, so Ubuntu, now we're on ARM V7, also works, and there are other ones like Arch Linux, but we support Raspbian ourselves and maintain that ourselves, and all for educational and general-purpose use, we recommend Raspbian. You can get that from raspberrypi.org. The GPIO pins, so this bank along the top there, we refer to as the GPIO bank. Now, strictly speaking, they're not all general-purpose, so they're called GPIO, general-purpose input-output. Strictly speaking, they're not all general-purpose, so you can see this little accessory somebody made. Our community's full of cool stuff like this that people create and put on sale and there's whole businesses around this, but this is a little pin diagram that you just stick over the top of the pins there to tell you which pin is which. So you can see here there's some 3-volt pins and some 5-volt pins, some ground pins, and then these ones are GP and they have numbers. So the GP-19 is general-purpose pin 19, and those ones you can control. You can have inputs or outputs listening for inputs or sending outputs. You can wire things up to those to do physical computing. Analog, so there's no native analog pins on there. They're all digital pins, so ones and zeros, but there are options if you want to use analog inputs with Raspberry Pi, so you can use an ADC to convert analog into digital. There's various Arduino-compatible add-on boards available and there's also PiSiri or the Python module for reading Arduino pins over USB. So let's have a look at the R-Pi GPIO library. So this is included in Raspbian and the implementation is in C. Features are you configure pins, so you give a pin number and you define that pin to be an input or an output, and then you can change them in your script. You can read the inputs, so you can say, is this one high or low? You can just get the value of it, and you can send outputs, say, turn this pin on if it's an output pin. There's also a feature called wait for edge, so an edge is when something changes from high to low or low to high, and you can have a script that pauses and waits for something to change, like wait for the button to be pressed and then continue, and there's event detection with callbacks, so you can run a function on the event of something happening, like a sensor going off or a button being pressed. This is kind of fundamental to everything you might need in such a program. So just a quick example. We've got some stuff on the breadboard here. We have a circuit connecting, putting three volts through an LED and through a resistor to limit the current. Then we have it going back to ground, so that just completes the circuit. There's lots of little bits of basic electronics that kind of help you with these sorts of projects. I don't know an awful lot about this, but just enough to get by. This is just a complete circuit with an LED in it, and putting three volts through there that gets limited through the resistor just means that this is always on. I can't change this in my program. It's just connected to always be on, because it's sending three volts through. If I move that from the 3V3 pin to GPIO2, then I can write a program which turns pin 2 on and turns pin 2 off. This is what the code would look like. We import the GPIO library. We set the mode, because annoyingly there are two numbering systems for the pins, because one isn't enough. We set the mode to BCM, which is the actual numbers that they are according to the chip, so the GP2, GP3, GP4. We set the mode, tell it which mode we're using. I'm using a variable here just to say which pin represents the LED. I set up that pin as an output, and then here's just a little bit that just goes turn it on, sleep, turn it off, sleep, in a loop. So that's just flashing the LED on and off. This is really empowering, especially for young people or for anyone. Instead of just having something saying print hello world or fry in range 10, print I, this is something flashing, something in the real world, something physical. This is another example. A simple circuit where we've got a button going from GPIO 17 through to ground. So just complete a circuit there. We can listen on pin 17 and wait for that button press. So this is what the code would look like. In this case, I'm actually using the pie camera library, so the button is going to trigger the camera to take a picture. So this is just the setup. So we have our set mode, button is pin 17. Setup pin 17 as an input. This is the pull, this is, that's wrong actually, that should be pull up or down. So we set it up, we tell it which pin, what it's going to be, and then here should be GPIO pull up or pull down. This is an electronics, bit of an electronics which determines whether a floating value, like a digital input, is you kind of send it to high or low and then you wait for it to fall. If you've pulled it up, that means it's been pressed. And if you've pulled it down, you wait for it to rise. This is a mistake. So here we, and then the following on, so that's our setup, and following on we have with the camera, so with an instance of a camera, pie camera object, we start the preview of the camera sees in real time. Then we have a loop which just says wait for that button to be pressed, wait for that to fall. So I would have pulled it up on the previous slide. And then it just sits and waits for that button to be pressed on 17, remember this is 17. Wait for that button to be pressed and then continue. So it would go onto this line and capture a frame. Then it is right around incrementing the frame number to this bit here. And then, this is pointless because it's a while tree, but you could have something to catch that to exit like a second button or just a keyboard interrupt. Another example here, we've got this is for a GPIO music box. So instead of wiring up just one button we wire up two. So we have two buttons. We've got one going to GPIO 2, one going to GPIO 3. Then I create an add, use add event detect on that button looking for a falling edge because I've pulled it up. The callback is the function I've defined as play and the bounce time, which means how long it takes before it lets another event come in. A thousand milliseconds, so one second. So I would have a function here called play, which I've defined as my callback. And then all I'm doing here is saying when this is called and it passes in the pin number that actually triggered the event into the function I look up which pin in here and I get this is a pygame sound object and then I can just go sound up play. So I know which pin was pressed, two or three according to which one. So I would do this on both buttons. Then look up which sound to play and play it. This is a really simple straightforward example of using events for multiple button presses and doing different things according to different inputs. There's something great for these types of projects which are really kind of small and simple but really empowering and really can be really interesting and engaging. They're called the Cam Jam Kit. They're just a collection of little bits, really useful bits for lots of these types of projects. These are light and resistors and wires. This is Kit 2 which has a load of sensors. It's got a passive infrared sensor so you can use that as a motion detector. It's got some LEDs, a buzzer and some other bits in the breadboard. These are really cheap. These cost five pounds and this one costs five pounds and this one costs seven pounds. It's a really pocket money electronics. They come with a bunch of things that you can follow along and these are just put together by one of these Raspberry Jam, the community events, in partnership with one of the Raspberry Pi community resellers and accessory sellers. They just got together and made this really cheap and tried to put it out there for more people to get involved in this sort of thing. Once the Raspberry Pi came out there was a lot of add-on boards and accessories and one of the first ones, one of the early ones by a guy called Goertz. He's actually one of the chip architects at the company that made the chip that we use. He's very knowledgeable about Raspberry Pi and here's him teaching me to solder while I'm wearing an elf hat. He made this board called the Goertz board which is, you know, he's an engineer and he thinks this is exactly what people need. This is an amazing board that gives you loads more potential to get out of your Raspberry Pi. It's got all this stuff on it and you know, technically he was right that it's a really cool board and it can potentially do all these things but he didn't provide any software for it and he probably just put, you know, here's a C program which, you know, you can use for this mini project. And another barrier to this was that initially it came unsoldered. So you would buy a kit like that and you'd have to solder up all of that entire board and then there was no software so a lot of people kind of get turned off by that sort of thing because they want to get going. So I'm going to go progressively through kind of good examples. So this one is a young lad actually he was about 17 when he created this called Ryan. He created a little lad on board that just does one thing really well. It's just a little motor controller board. So you can drive motors so you can use it in robotics. He didn't provide any software for this but he, no bespoke software but he shows you how you can use the GPIO library to drive the pins forward. So you can, as long as you know which pin is which, so which pin it's connected to, we'll just say pin 17 is the left motor forward or pin 18 is the right motor back. Then you've got enough to go with and you just write a little bit of code similar to the examples I showed you earlier just turning pins off for a certain amount of time and it will drive forward or spin around or whatever it is that you've asked it to do. So that's kind of cool and a nice nice learning, nice not too steep learning curve. This is another example which is kind of further along the spectrum. It's a little add on board that has three LEDs colored like traffic lights it has a button and a buzzer and a bunch of extra inputs on the front as well. They provide a software library for this. So import Piperella you've got a full abstraction away from which GPIO pins things are connected to you just refer to them by the light and the color. So you just run this function Piperella.light.green.on the green light comes on instead of GPIO output 17 true you have turned the green light on. There's a really nice abstraction especially for young children to get involved even less of a steep learning curve. There's plenty you can do with this as well they've even got event detection so you can create a function that flashes it so turn it on for one second so this is actually all the lights because I didn't specify a color sleep for one second then turn them off and then I can say when the button is pressed run that function so when I press the button flash the lights all the lights on for one second and there's loads of places you can take this this is an add-on board called Energini it's a company that makes remote control switches so you can buy a remote you can turn off the Christmas tree lights without having to get right behind it then they made a Raspberry Pi add-on board so this just sits on top and they provided you a massive file with about 50 lines of Python saying this is how you turn switches on and off we had a young girl with us on work experience she was about 15 we said can you take a look at this code kind of tidy it up work out the logic and then put it into a function that you can turn them on and turn them off because 14 or 15 year old girls are better at programming than the people who make this thing and then I packaged it and took all the credit and put it on on pip so you import Energini switch on and switch off you can pass in the number of if you've got a bank of four one two three four you can turn on the sockets arbitrarily with numbers I also made a little web app to show that you can do this sort of thing this is just a little basic flash app which is on the documentation you just press that on your phone to turn them on or turn them off that was running on a local network configured your router correctly you can do that over the internet and there's plenty of services to help you do that as well so a bit over a year ago we moved from the original Raspberry Pi this one the original Raspberry Pi model B to the B plus so this was still Raspberry Pi 1 but it was a plus version and we extended the pins from a 26 pin to 40 pin so you get a lot more to play with and the hardware would sit on the 26 pin bank and they still work because the first 26 pins are exactly the same but we also defined a specification for add-on boards people don't have to follow this they can still make 26 pin ones they can still make 40 pin ones not following the rules but we call these hats so it's hardware attached on top of the official specification for add-on boards it has features such as you can use ribbon cables like this if you put it out and if you put it in exactly the right dimensions it will fit nicely on top of a B plus or an A plus or a Raspberry Pi 2 and you can use mounting holes because we've used the mounting holes with screws to just hold it in place one of the projects we worked on last year was looking at sous vide cooking for back-impact food such as steak like this and you cook it in water at a very precise temperature so we decided to design some hardware to do this, we did some prototyping first with breadboards and stuff and then we had somebody create an actual hat for this so if it's a hat for cooking it's called the chef hat so it was like this we used the Energenie to remotely control the cooker, it's kind of dumb really we're using a temperature sensor in the water and if it's too high if the temperature is too high we turn it on, too low we turn it on otherwise we turn it off there's a little library that I'm working on it's a work in progress we have another board called these are just some kind of internal projects that we've been working on there's one called the dots board which uses conductive paint and there's a load of little holes on this board that you use with a paintbrush to draw a pattern from to connect the dots we tried this out at a couple of events we went to make a fair and got really young children engaged in doing something more interesting than just typing on screen so they sit there for 5 or 10 minutes just drawing out their plane really intricately they take it over to the Raspberry Pi stick it on top and then they run a Python program that draws a plane in the colours that they chose along the top which is kind of a really novel idea and this is some of the part of the software and all we do here is so we have a pin is active function so we just check given the list of pins we know to be the error plane pins we just count how many of them are active and not so just by putting paint over them connects the outside of the dot to the inside which shorts at the ground which you can detect in software and then we just have how many of them are connected and if enough of them are connected we show the plane it was a little pie game pie game app another one the plant pot greenhouse so this is a beautiful looking board designed by Rachel Reigns from Raspberry Pi Foundation and it's a so this bit you kind of clip all of these bits out so this bit sits on top of the pie that's kind of hat like and then you have a wire running to the sensor board which is this stick here you stick that in soil it's got a soil moisture sensor a light sensor and temperature and humidity and you just use it to monitor the conditions of the plant the you put it inside a little acrylic kind of greenhouse thing so the pie is inside there and then it LEDs on top of the board glow according to the whatever you programmed it to do according to the whether it needs watering or something like that this is one made by an amazing American company called Adafruit the capacitive touch hat so you stick this on top of the pie and you wire up crocodile clips to each of the pins to each of the holes on there and then you can this bit like makey makey where you can build a piano with fruit or something like that you wire up that up to anything and then in Python just read which ones have been pressed and then have different actions according to that there's a bunch of really cool hats made by the community and made by these companies that have accessories Pi Moroni is a brilliant example they were one half of the team that built the Pi Brella that I mentioned earlier this is the unicorn hat so it's a nice 8x8 Neopixel grid that you can program really simply the sky writer which is you can hover your hand over it and it will assign different events to gestures or how close you are and things like that the propeller hat which is a little prototyping board and the explorer hat which has got a lot of capacitive touch things along the side and sub lights here and you can control motors from these extra pins you have here really easily and this sort of thing is really helpful to put out there because it means a teacher can pick that up and really simply put together a simple robot or anything that uses motors or capacitive touch and the great thing about Pi Moroni is that they provide the software libraries in Python and always in Python 3 unfortunately we always nag them about this but it's great that we can have this sort of thing readily available we have something another internal project we've made this weather station so it's a board that sits on the Pi that has some stuff going off to some other sensors we've produced this in-house and having it manufactured and we're sending a thousand of them to schools around the world to collect weather data and feed into a big database that's going to be really cool James Robinson my colleague is going to be giving a talk about that later on today so again this was prototyped on a breadboard just components and looking at different sensors and then some software running that just reads the sensors logs it, uses database that kind of thing we have a, this is kind of our headline project of the year AstroPi if you haven't heard of it is that we're sending two Raspberry Pi's to the International Space Station at the end of this year British astronaut Tim Peake is going to be going up in December and he's taking these two Raspberry Pi's with him he's going to be doing some educational outreach as part of his six months in space so there's some kind of general education stuff they're sending some rocket seeds into space and bringing them back and then distributing them to schools for them to experiment with and growing the seeds to see if to compare seeds that have been in space with regular seeds that haven't been in space to see if there's any difference in their growth and for them to start thinking about space more and another program is this AstroPi competition which is we've built this sensor board which sits a hat that goes on the Pi and there's a competition for kids to write code for this sensor board that they will pick the winners and run that code in space so primary school and secondary school kids in the UK have had a chance this year to have their code run in space the AstroPi board is what we call it the sense hat this is what it looks like so we've got a little 8x8 grid you can that's an RGB LED matrix it's got a bunch of sensors so you can get the temperature humidity pressure gyroscope magnetometer and it also has a mini joystick for input we've been through a lot of testing of getting this hardware suitably acceptable for space for flight in space and it's gone through all sorts of vibration testing and all sorts of things to make sure that it's safe to be in orbit it's going to be mounted on the wall in one of the modules on the ISS and it's going to be there after Tim Peake comes back so we're hoping to do more things with them once they're up there this hardware is going to be really handy for a lot of people as well not just for the competition so this should be going on sale within the next couple of months really handy for a lot of projects so just to finish off we've got this education summit have a look at the rest of the talks on this track for the rest of the day so my colleagues and I and some other people from the community we have a lot of education, Raspberry Pi and all sorts of other things and also at the weekend we have some sprints so if anyone wants to come and hack with us on different educational projects and hopefully we'll have some teachers there and see what they have to say as well so thanks very much and I will close for questions so do we have any questions hi Ben thanks it was a really good talk so I'm quite obsessed with space just as much as I am about programming could you tell us a little bit more about the tests you had to actually put the hats through in order to be able to take it up into orbit yeah so I don't know an awful lot about this because I wasn't part of the testing team but I kind of hear a lot from it we've got a developer called Dave who's been doing all these tests and he's really keen telling us all about it so for the actual launch so for it to the rocket the shuttle to go up they have to, it vibrates a lot so they have to make sure that it doesn't break and break apart during the launch we have to make sure that there's no kind of radioactive materials coming out or anything kind of bad leaking out into the air that could be harmful to the astronauts they have to kind of shatter on with a hammer or something and see kind of what bits come off and what could be harmful and test it again after that and also things like heat that it doesn't gain excessive heat we've actually built a special case for it which is probably the most over engineered case besides the one that we made recently for general use that's ever been made it's a great big giant aluminium case that has the matrix the LED matrix shown a little hole for the camera and it's designed in a very specific way for the heat not to radiate so make sure that it doesn't get hot to the touch even radiate out I like your talk I was just looking at the Raspberry Pi homepage so I have a question are there any bluetooth possibilities with the Raspberry Pi so there's no built in bluetooth on the Raspberry Pi but you can use the USB dongle so if you have some bluetooth device that you can you can do that I think we use the remote the remote for that is bluetooth and I've seen people do projects with that waving the weave around driving a robot forward and that kind of thing it's definitely possible to just need a USB dongle the code that you showed it's quite simple it's meant for kids to be able to use of course and I don't know if the Raspberry Pi has got any visual programming environments like the for instance like the logo on the OLPCL X1 I don't know if you've ever seen that but it's very simple just drag and drop things and then make the turtle do stuff but I was actually thinking that with something like physical confusing it would be even nicer to have a physical block dragging or block aggregation do you know of any projects on that direction so the Raspberry Pi comes bundled with Scratch, so Scratch is a popular visual block based programming language, really good for beginners and really good for young children as their first programming experience not having to think about syntax or even bothering to type anything but just being able to click and drag and drop so that's Scratch is pretty installed and there are possibilities for extending that to be able to use GPIO so you can actually drive robots forward with your drag and drop programming Scratch we tend to in our mind we tend to look at Scratch as the first step the second step is really good move above and beyond Scratch called Sonic Pi which Karyan discussed this morning it's based on Ruby so there's not as much precision required in the syntax not quite as much as Python even though we all like to think Python is great for that but we see tabs and we see spaces and we see colons kids don't really see that stuff so Sonic Pi is a nice step forward before they get to Python they can do more and there's also turtle in Python that's available as well so that's another good one there's no other questions so thank you very much Ben