 Hello everybody. Thank you for coming. We have now a presentation about Python and Raspberry Pi. Please to do a big, huge thing for the new speaker, Ben Nuttva. Hi everyone, thanks for coming to the talk. I'm Ben Nuttva, I'm Raspberry Pi's community manager based in Cambridge in the UK. I'm the creator of one of the libraries I'm going to be talking about today. I'm a columnist on opensource.com. I recommend you take a look at their website. We've got some great open source materials. There's me on GitHub and Twitter on my email if you want to reach me. I'm from the Raspberry Pi Foundation. We've sold over 11 million Raspberry Pi's now in the last almost five years, which is really cool. A lot of people know us as the hardware company but we're fundamentally an educational charity. I work for the charity side. We own a subsidiary which is called Raspberry Pi Trading Limited. They do all the engineering, make all the hardware and the license fee for each Raspberry Pi sold goes to fund our educational programs. That's how we're set up. Our mission is putting the power of digital making into the hands of people all over the world. We do this by providing low cost, high performance computers, doing outreach and education programs and putting out free resources and teacher training. We do a lot of work like that in the foundation. This is what the current state of the Raspberry Pi hardware looks like. Raspberry Pi 3 is our premium main model at the moment. It's a 64-bit quad-core ARM V8 that runs at 1.2 GHz. It's got a gig of RAM and costs $35. We've always had the $35 price point for our main Raspberry Pi model. A year or so ago we actually launched a new model called Raspberry Pi Zero based on the original Raspberry Pi 1 chip in a smaller form factor that costs just $5. It runs at 1 GHz. It's a single-core ARM V6 with half a gig of RAM but still really popular, really cool, really good for embedding and things. The Raspberry Pi runs a full Linux operating system. We've created a distro based on Debian called Raspbian based on Debian Jesse. We've done a lot of work very recently on the skin and the look and feel, the user experience of the desktop. It now looks really nice, looks like this. We even released an X86 image fairly recently. You can install this on a PC, on a laptop, on a Mac. You can use a LiveDisk or a USB drive and boot into that, which is a new development, a way of us to getting out the programming tools and educational content that comes with the Raspberry Pi operating system image that you could just run on a PC. One of the great things about the Raspberry Pi that's the main thing we're going to be talking about is the big differentiator between a Raspberry Pi and a conventional PC. There's GPIO pins, general-purpose input-output pins. There's a set of 40 pins along the Pi that you can connect to physical devices. So you can do lights, motors, robotics, photo and video, attach all sorts of sensors and do lots of sort of IoT type of hacking. You can do some really cool stuff that you can't generally do on normal PCs. Take a look at the GPIO header. There's a set of 40 pins and they're each designated different purposes. So you have some pins that are 3V3, which is a constant supply of 3.3 volts. Some pins are 5 volts, a constant supply of 5 volts. You've got GPIO pins which are variable 3V3, so you can turn them on and off and they'll ultimately give out 3.3 volts, which is how you control your components and things. And then there's other interfaces, so there's SPI, I2C and UART, so different sort of communication protocols that you can use, high-speed data transfer used over those pins, just over the GPIO pins. If you have a look at the website pinout.xyz, there's a full comprehensive sort of set of information and documentation about what the pins are used for on different boards and things. So two main ways of sort of accessing the things on the pins. One is sort of wiring things up to the pins or using a breadboard and connecting the components directly that way. Or you can design PCBs, which are meant to sit on top of the whole pin set and give you all the bits sort of on the board itself. So a lot of people in the ecosystem are building boards, add-ons and accessories, and we've even got a standard call hat, which stands for hardware attached on top, which is for 40-pin headers that slot on top of the Pi and give you something specific or a more general purpose add-on board. The way you program the pins in Python, so there's a low-level library that's been around for about four years or so, called RPI GPIO. Very low-level, but looks very similar if you've used something like Arduino before. It's all about setting up pins as outputs or inputs, setting output pins high or output pins low and reading the value of input pins. Very low-level and my library that I sort of been working on with the last year or so, it's called GPIO zero. The zero are not being Pi zero related, but zero boilerplate. So the idea of this is you have component classes and you create instances of something like an LED or a button and just give it the pin number in the construction and you can use the DSL methods there on. So you get things like rather than turning pins high and low to flash an LED, you tell the LED to come on and tell it to go off or use the blink method, which gives you the threading stuff for free, so it lets you hack away at things much quicker. We've got a sort of multi-paradigm approach to this as well, so here I have an LED and a button. I've created instances of those on particular pins. And one way of doing this, if I want the LED to come on when the button is pressed, I can just use a wire loop, check the state of the button and optionally turn the LED on or off, which works fine. That's what I would generally start with with kids. Another sort of paradigm is event-driven approach. So again, you have your LED and your button, but you attach events to the action of the button being pressed and being released, so running those methods as callbacks. And the third approach is really clever, which is sort of the implementation of this would make for a really good talk of itself, but a sort of more declarative style, which is where you connect these two devices up so the button is constantly sending its current value into the LED. And you can do a lot of really powerful stuff with that, especially with more complex devices. The G-Power Zera library supports a range of everything from very simple devices to sort of more complex things. So you've got LED, button, buzzer, motion sensor, distance sensor, a few little add-on boards, which compose of different devices, things like light sensors. You can wire up potentiometers to an analog digital converter and read the values of those very easily. There's an Energenie there, which is a remote control socket, which I'm going to be talking about later. Line sensors, sets of traffic lights, robotic add-on boards, motors, servos, and all sorts of things like that. There's a great device hierarchy on our Read the Docs page you can take a look at. There's some really interesting stuff in there. It just saves you having to work out exactly how the implementation of these devices work. You can just use the methods and stuff that the abstraction gives you. GPIO Zero supports multiple backends. It was originally just an abstraction layer on top of the library I mentioned earlier, RPI GPIO. And then we managed to bring in sort of swappable backends so you can bring in a different PINs library and use that but get the advantage of the abstraction of GPIO Zero for free. So we support RPI GPIO, another library called RPIO. There's a great one that I'm going to cover in the next slide called PIGPIO, which has some really nice features. If you don't have it, it sort of goes through looking at what you've got installed and if you haven't got one of these installed, it sort of falls back to a pure Python implementation of basic PINs, which is a little experimental but kind of cool to be there. And we've also provided mock PIN classes, PIN classes, so we have a test suite that runs this through the logic of the API using mock, which is really cool. So back to PIGPIO. One of the things you can do in PIGPIO is run GPIO Zero code on your PC, on your laptop, or even on another Pi and remotely control the GPIO pins of that Pi over the network. So you can do something like this. There's one way of doing it where you, rather than creating an instance of an LED on a particular, just an integer passing into the PIN number in the constructor, you can pass in a PIN object and do it this way. So you can have sort of several different ones you could use. Or you can set an IP address as an environment variable and just run the script as you would on the Pi itself. Also, there's the Raspberry Pi camera module. So this is an official add-on accessory that the foundation puts out. V2 is an 8 megapixel camera. The previous one was a 5 megapixel. There's visible light and infrared versions available. So the green one is the regular visible light camera. The black one is called PINUR. It's got the infrared filter removed. You can do 1080p video at 40 frames per second, 720p at 60 frames per second, and VGA resolution at 90 frames per second with this camera. There's a basic sort of command line options available for capturing and doing all sorts of stuff with the camera on the command line. But there's also a Python implementation, which I'm going to show you. So the Pi camera library, this is an example of just taking a picture. So you create an instance of the connection to the camera, start the preview, sleep for a few seconds, so you actually see what's coming in real time on the screen, and then capture and stop the preview. It's as simple as that. If you want to record video, just swap that out for start recording and stop recording. It's very easy to drop in GPO0 and use a push button before you capture. So rather than just an arbitrary sleep, you can wait until the button's being pressed, then capture. And there's lots of really cool stuff that the GPU does all the hard work for you that you can supply different image effects and all sorts of different things that the library gives you and the firmware gives you. So this, for instance, you can render all these different image effects, and they actually come through on real time as they're processed through the GPU. One of the examples in the pie camera documentation is web streaming. So it's really simple, just a block of code that you can run and run a web server that constantly streams the video. This is actually my house. I bought a tortoise recently, and I dropped in a camera module and been monitoring it. So that's really cool. And so one thing I mentioned earlier, energy, so this is a really safe way of controlling real live electronics that have connected to the wall socket. So real powerful, normal power socket things. So you can actually send remote commands from the pie to turn on and off a device plugged in at the wall using this energy module. You can use relays and things like that. Anybody who's done bits of electronics might have used relays before, but getting up to that sort of voltage, you really need to know what you're doing. So energy gives you a simple way of doing that. And so this is one actually set up for the tortoises as well. So energy needs built into GPIO zero, and we also have some internal classes, internal devices, which sort of act like the GPIO devices and sort of connect with them really well. So we create an internal device called time of day, which is a bit like a, in the same way a button is active when it's pressed, the time of day is active between the times that you created. So you sort of create a time there between 8am and 8pm, and all I'm doing is saying the lamp should be on during that time of day. So those two, there's just two scripts running, one that I got from the documentation, one that you can see on the screen, and that had my whole sort of little hobby project set up quite easily. Another official add-on product is the sense hat. So we actually made this for a specific purpose, and then we decided that it would be good if we were able to put it on sale, because a lot of people would be able to make use of it. We made it for one of our educational programs called AstroPie. The British astronaut Tim Peake went to the space station for six months last year, and as part of his mission, we ran competitions for kids to write code that would be run on the space station. So they were running on this sensor board. So it's a board as a hat that goes on top of the pie. It gives you an 8x8 RGB matrix, LED matrix, so you can display messages on there or change the colors and things, and it's got a bunch of sensors and a little joystick. So it just drops onto the pie straight like that, so you can buy these as well. So a simple way of using it like that, just read the sensors with properties there, and you can use methods to write stuff to the screen. Just a simple example there is reading the humidity value, getting that as a percentage, and I've missed something there, times it by 255, and then displaying the intensity of the red according to the humidity. So just a simple example showing how it is to get something from the sensors showing on the screen. So AstroPie is a competition. Tim Peaks is now back on Earth, but the French astronaut Tamar Pascay is now on the space station, and we've got a whole European-wide competition running for kids. So if you know any teachers or anyone in education, be worth pointing them in the direction of the AstroPie website. There's plenty of resources and stuff to get started, and you can even apply for a free kit to get started with this. One of the other things we did to make it more accessible to people to get involved in that competition is to create an emulator. So you can code the sensor in a web browser using Trinket, and it's exactly the same Python code that you write on there and you get a visualization of it on the screen. You also get a bunch of sliders for the sensors that you can change. So it's good either if you haven't got a Raspberry Pi or a Sense Hat, or if you just want to test your code without needing real sensor data, you can test it in this emulator. As well as the one in the web browser, we've got a Python version that you can download and just run natively just on your machine. That's really cool as well. So the documentation for the projects I've been talking about, so there's gpl0.readthedocs.io, pycamry.readthedocs.io, and pythonhosted.org slash Sense Hat. So I just want to finish with pointing people in a few different directions of how they can get involved in the Raspberry Pi and the community. So one thing you could do is contribute to some of these Python libraries or help create more Python libraries for things that you can use with Raspberry Pi. There's some really interesting projects you can do at home and it'd be great to see some contributions. And if there's any libraries you see around still using Python 2, of course a lot of teachers have problems where they hit a brick wall when they've been trying to use Python 3 and they have to switch back to Python 2 for some particular library. So if you could help with that, that would be great. We have a magazine called the MagPi which you can buy in shops and you can get subscriptions for it. You actually get a free Pi Zero if you subscribe to the magazine. It was originally a community magazine that they just put out free PDFs every month, just a few members of the community. They came and asked us to help them keep it going once they sort of reached that point in an open source style project where they had a bit of fatigue and we helped them out. We've actually managed to get it into the shops so we have this monthly magazine and you can buy subscriptions, but we still provide that as a free PDF, so do check that out. There's plenty of projects, news and articles and resources and things in there. We actually gave away the first batch of Pi Zeros with the magazine as well. The team that produces the MagPi also make books, like make games with Python, experiment with the Sense app and things like that. We put those together as well and you can buy the books or download them for free from the MagPi website. Raspberry Jam, these are community events mixed between tech user groups and family friendly tech events. They happen all over the world really, a lot of them in the UK and the US and a few around Europe. Have a look on the Raspberry Pi website whether there's a map and a calendar of all the upcoming events and if you want to get something started in your area, if you're a member of a hack space or a tech user group or something, really good place to start and welcome more people into coding on Raspberry Pi. Another program that we're involved with is the Raspberry Pi Foundation's project called Code Club, which is not a Raspberry Pi specific project, it's just introducing kids to coding in schools. So it's free volunteer-led afterschool coding clubs for children. We've got a big project in the UK, but there are sort of franchises of this around the world and in different countries. We provide projects in scratch, HTML and Python and provide training for volunteers. So we need help translating more materials and things, but if you want to take a look and see if you can volunteer, then take a look at coclubworld.org. That's all, I'll stop for questions. Thank you.