JavaScript Electronics on the Pi Zero

async_july.jpg

In this talk, Seb Lee-Delisle (@seb\_ly) shows us how to get started with connecting electronic components on the Raspberry Pi. Additionally, Seb shows us how to work with super bright LEDs, buttons, displays, sensors and motors entirely in JavaScript. This talk was filmed at Async in Brighton (July event). \[00:00:03\] Stuff That Talks to The \[…\]

Introduction

In this talk, Seb Lee-Delisle (@seb_ly) shows us how to get started with connecting electronic components on the Raspberry Pi. Additionally, Seb shows us how to work with super bright LEDs, buttons, displays, sensors and motors entirely in JavaScript.

This talk was filmed at Async in Brighton (July event).

[00:00:03] Stuff That Talks to The Interwebs is my workshop series about IOT and originally it was with an Arduino and Wi-Fi shield, but now I do it with Raspberry Pis and Wi-Fi. Obviously, a little Raspberry Pi is a great prototyping platform for internet things. Things that I call it “Stuff That Talks to The Interwebs”. This is where I talk about my work, fireworks. I’m still talking about fireworks. Pixelpyros is the biggest project I’ve ever done – it’s massive. Huge screen. How wide is it? It’s like 20 meters wide. It’s like crazy wide. I project computer generated fireworks onto this screen and each one is triggered by humans. You can see there, they’re touching these orbs of light and when you wave your hand in front of it, it makes fireworks. You’ve seen it, it was in Brighton a couple of times. Yes, half of you have seen it. Brilliant. I do it with lasers now. Lasers are a recurring theme in my work, just lasers all the time. Pixelpyros is primarily a software project. There’s a bit of hardware. You can see these infrared lights behind the screen, they’re completely invisible to your eyes. My infrared cameras can see it. Hopefully I’ve got some footage here, which is pretty cool. This is what my infrared cameras see and that’s how the motion detection works. Apart from that, there isn’t really much hardware.

[00:01:25] A couple of years ago I made a project called, “Laser Light Synths” and it was the opening to Brighton Digital Festival and this was probably the most sophisticated electronics project I’ve done. Essentially, in the last few years, I’ve just been doing less software and more hardware. I suppose even when you’re doing stuff with electronics, it’s still very much like programming as well. It’s always a very closely knit programming side to all of these electronic things. I don’t know why we haven’t got sound, but that’s not important. Lunar Trails is another really heavy electronics project – I could talk about this for ages. In fact, I might just get my phone out so I can keep an eye on the time because I have literally no idea how long I’m going to talk today. If you want to just shout out questions or whatever, please do because it’s totally loose. This talk is completely loose. I should have said that at the beginning, but that’s fine. You’ll figure it out yourself before too long. This project is based around my obsession with the 1979 arcade game “Lunar Lander”. This is actually my own Lunar Lander cabinet. I bought it on eBay. It’s in LA, I can’t get it. Here it is. It’s just sat in my friend’s office. It’s in his canteen. Always staff play it but apparently they still enjoy it so that’s fine. I’m never going to get it, that’s fine. This is what it looks like. It’s a beautiful vector rendered display. I made a perfect recreation of that in JavaScript and you can play it yourself at Moonlander.seb.ly, no I’m talking now. We’ll do it later; we’ll do it in the break. Then we can have a look.

[00:03:08] You can play this game and try and land the ship and I thought, “Wouldn’t it be good to spy on everyone playing the game and leave little trails when they’re moving around” and it made art. I accidentally did “an art” and then I thought, “Wouldn’t it be even better to make a big physical version of this.” I bought an arcade cabinet, a flat-pack, just like Ikea and put – this was the first time I’d really done much of this sort of building stuff. I was so excited. I did metal work, there was sparks and everything. I learned about servo motors because not only did I have to build the arcade machine, I also wanted to build this massive drawing machine. With the help of an engineer friend, I built this hanging plotter all based on – now the sound comes. Okay good. Out of my little, crappy speakers. You can see the hanging plotter here has got two motors at the top two corners and it winds in and out wires and it moves the hanging pen holder to draw any shape that you want, really. It’s quite a sophisticated system. As you play the game, the arcade game, the drawing machine actually plots your path that you take in the game, in real life. You can see it running there. I haven’t got time to dwell on this. I’ve got to move on to Laser Arcade.

[00:04:34] I told you that I liked lasers. This was right after I’d just learned how to do lasers with Pixelpyros and I thought, “Everything has to have lasers”. I recreated an old, classic shooting gallery but with laser projected targets and nerf gun darks. You actually would fire real nerf gun bullets at laser projected targets. This was a crazy project because it used microphones to pick up the sound of where the bullet hit the wall. There were six microphones and it measured the tiny differences in the amount of time it took to reach each one. You can see there, the gap there between it and some really complex maths which I could talk about for ages but I won’t. I’ve got no time at all. I’ve got so much to get through. I’m doing a new version of Laser Arcade. I’m going to be doing it in the digital festival. Definitely bring your own beamer, the projection events at the coin exchange. I might also be doing the opening event at the Digital Festival. I’m not sure yet. Instead of using nerf gun darks because, frankly, I’m sick of picking up nerf gun dark bullets. I’ve got myself a couple of these Nintendo zappers from the NES. Does anyone play duck hunt? Yes, you know it? Really cool. I could talk about these for ages but I won’t. All you need to know is that I ripped the insides out of one of them and made my own custom circuit board. You can see it there. That’s the design and then it’s all milled out on a CNC machine. I’m redesigning that at the moment. Essentially, I want it to be a real laser gun, with real lasers in it but the thing with lasers is you can’t really see the laser beam unless there’s loads of smoke. I could just fill the room with smoke but I thought that’s a bit boring. Instead, well, first of all, I covered in neo pixels and you can see the laser beam coming out there. You wouldn’t be able to see that laser beam at all unless there was a bit of smoke in the room.

[00:06:38] I just happened to make some smoke in the room. I thought, “Wouldn’t it be better if the smoke is coming out of the gun?” I basically spent altogether too much time trying to figure out how to fit an e-cigarette inside the gun. Obviously, blowing out nicotine free vaping fluid. Obviously, you don’t want to be giving everyone a little nicotine buzz while they’re doing it, but it’s not enough to have an e-cigarette in there because if you just power up an e-cigarette, the vape smoke doesn’t come out. You have to physically push it out with an air pump. I managed to find not only a really tiny e-cigarette but also a tiny air pump as well, that’s blowing through the e-cigarette. That’s not enough to really drive out the smoke. It just blows it out of the e-cigarette and it just lingers there. I also had to find a tiny, tiny, little fan and then I had to fit it all inside this gun, which his quite small anyway. Anyway, this is a work in progress. This was this morning and that’s kind of where I’m at. You can see with the smoke, the laser looks really cool, doesn’t it? I’m finally thinking because up to this point I’ve been, “This is never going to work, I’ve bought so many e-cigarettes and fans and pumps and it’s never going to work. I’m just wasting all my time and money.” Then, this morning I was like, “Yes, that could work.” That defines my process.

[00:08:10] Anyway, I can relax now because we’re back to the subject of my talk. I just get so paranoid everyone’s like, “Stop talking about your projects, just get to the Raspberry Pi stuff.” Okay. Raspberry Pi. Yes, we’ve talked a little bit about it. It’s such a wonderful project and it’s nice that there’s a product that’s a massive success. What, they sold like, I think, it’s eight million now. They’ve sold eight million Raspberry Pis. That’s the best-selling British computer ever, which is fantastic. Most brilliantly, the thing that I really love is it’s not some corporation making tons of money out of it. It’s a charitable foundation. They exist solely to get more computers into the hands of kids to learn to code. That is great. Almost accidentally, they’ve started this other community, it’s multiple communities: artists, engineers, installation people like museum people or whatever, hobbyists, makers. All of these different people have started to use Raspberry Pis, musicians. There’s any number of things that you can do with it. Although, I’ve been working with them for quite a while, I’ve pretty much only been doing electronics but you can do loads of other things with them. Obviously, I’ve covered them a little bit. I love Raspberry Pi. I always, up until recently, preferred Arduino for small electronics projects. I guess Arduino’s – they’re quite expensive – actually, the parts are very cheap and you can get clones as well. You can get Arduino clones very cheaply and, actually, because it’s all open source hardware, you can build your own Arduino even cheaper. If you’re designing a product for market, you can basically recreate Arduino and make your own custom version of it with all your connectors and your components that you need for your products. That’s great. With Raspberry Pi, you do get a full Linux computer. There’s certain amount of overhead with that; whereas, you wouldn’t necessarily want a smart light to have to boot up before it works.

[00:10:27] Arduino is really good for those sort of things. Arduino isn’t necessarily very good at internet, right? It’s okay at it but it’s not very good at passing text. You need extra hardware if you want to use secure connections and stuff like that. It’s getting better all the time but, obviously, if you work with Raspberry Pi it’s just glossed over all of those problems brilliantly. Obviously, at the cost of having a Linux operating system but that’s fine because you get so many other benefits. Plus, of course, you can also program it in JavaScript, which if you know it already, is cool. Yes, the Pie Zero, this is where things got really real. The Raspberry Pi is 20 quid or something like this. This is like three pounds fifty. It’s so ridiculous. Even once you’ve bought the SD card and the power supply and the cable, the Wi-Fi dongle, it’s still probably cheaper than an Arduino, right, without any Wi-Fi. This is really revolutionary. Of course, you can’t get one for love nor money. No, stock is getting a bit easier now. Yes, unbelievable. You think, “How on earth have they made a whole computer that cheap and still make a profit?” Well, the answer is I don’t think they are making a profit. They’ve done it literally at cost. Again, just to get more computers in kid’s hands. They’ve brought out the Raspberry Pi Three now. I’ve got one over there. It’s the same sort of form factor as this but it’s also got Wi-Fi and Bluetooth built in and they’re like 25/28 quid, something like that. They’re making loads of money on Raspberry Pis Twos and Threes and so they don’t necessarily have to worry so much about making money on these.

[00:12:21] Again, isn’t it wonderful that it’s a charitable foundation and it has totally different motivations than a corporation. I find that really refreshing. Yes, what have we got here? All the usual computer stuff, right? It’s got this port there is to plug the power supply in. Here’s a USB port. Obviously, it’s tiny, right? If you want to plug in an actual USB stuff you need an adapter. It’s got a mini HDMI, so if you want to plug it into a monitor you can either get a mini HDMI cable or you can get an adapter. They’ve obviously made compromises to make it so small. SD card slot there. The new ones, this is an old one, but the new one, I don’t know if you can see along the top, there’s a little white connector at the top. That’s for a camera. The Raspberry Pi has a Pie Camera with it and all the other Raspberry Pis have those Pie Camera slots there. This is a slightly smaller one but you can get a different cable and plug a camera into this. Brilliant. The new model Zero. I don’t really care about any of that stuff. I don’t really need the USB particularly or the HDMI. I’m not plugging in a keyboard; I’m not plugging in a mouse. All I care about is this, the GPIO header and it’s two rows of pins – I think there are 40 of them – and these are GPIO pins. That just stands for General Purpose Input Output. It sounds complicated but all it is, is something that you can connect bits of electronics to. I don’t know about you but I can’t remember the last time a computer had something like this. Since maybe the BBC Micro. At school you could plug in robots and motors and electronics into the BBC Micro. Since then, it hasn’t been that easy to do that, right? I think it’s great.

[00:14:21] I don’t even think it’s that important to Raspberry Pi. I think they wanted to do it because they wanted to be like the BBC Micro but I think most of the education or resources aren’t necessarily around the electronics but, of course, it’s a wonderful thing to be able to program something and have something physical happen. I think that’s a huge part of the appeal of the Raspberry Pi. You can see the GPIOs there. You don’t have to worry too much about them. I guess I could just give you a very quick lesson in electronics. In fact, I’m going to have to do that. Before I do that, most of these pins, some of them have got special functions, but most of them can either be set to an input or an output. Who has ever done any Arduino before? A couple of you, half of your, I guess. Those of you that have done Arduino, you know you can set a pin as an input or an output. If it’s an output, you can attach an LED or a motor or something to it and you can either put electricity into that thing or not put electricity through it. You can do that with code. You can also have it as an input. You could have either electricity going into it or not electricity going into it and you can read that, the state of that pin in code. That way you can have switches and buttons and stuff like that. You’ve got inputs and outputs. Do I have time to explain electronics? Yes, why not? You’d have the battery at the bottom. Which way around is it? I don’t even know. It doesn’t matter. That’s a battery symbol. I could never colour that in. In my day – my God, I’m old – you would have actual filament bulbs, right. You’ve got plus and minus. I think that’s the right label.

[00:16:23] This isn’t really what happens. It’s crazy what actually happens with electronics and electricity. We all believe this lie which serves our purposes and is a perfectly adequate model for 99.9% of all the electronics you want to do and that model is that electricity comes out of the plus side, goes around the circuit, through this, whatever it is, makes it light up and then goes into the minus side. You can think of it as a plumbing system, you can think of it as water taps, right. This could be your mains and what would that be? A mill or something that the water is pumping around. This is a crap analogy. It goes out into the drain. That’s a basic circuit but what’s that got to do with Arduino? Hang on, what am I teaching? Raspberry Pi. Same stuff. It’s all GPIOs. All of these input and output pins, they either put out or can read in up to 3.3 volts. If you put five volts into it, you’ll damage your Raspberry Pi, potentially, which is really dangerous because you see there are two five-volt power pins up there. If you just plug one of those into any one of the other pins, you’ve broken your Raspberry Pi. In that way, Raspberry Pis are a little bit Fragile. Arduinos generally just run on five volts throughout, so it’s much safer. I just thought I’d probably better give you that warning.

[00:18:02] How do you use GPIO pins? Well, what you can do is on this side, instead of plus, you can actually plug in a wire into a pin. I’m just going to call it “P”, any one of those pins. Take a wire out of that, put it into a LED, which is a light emitting diode. Does everyone know about those? Some of you probably don’t but that’s okay. Then that goes to ground. What I’ve got is a Raspberry Pi pin going out there into an LED and to ground. Now, with code, I can set this pin to be an output and also with code, I can either set this to put out 3.3 volts or I can set it to put out nothing. Obviously, if it puts out 3.3 volts, then the LED lights up. If I turn it off, then the LED turns off. I can do that entirely with code. In this case, I can do it with JavaScript. What else do I have to say about that? What you’re actually doing with the pin, rather than turning it on and off, you’re actually saying you’re putting either voltage in there or you’re putting it to ground. Turning it off is the same as putting it to ground. It means that it’s ground on both sides and there’s no electricity going anywhere, there’s nothing happening. That’s sometimes known as on or off, but often it’s referred to as high and low. If it’s high then you’ve got voltage coming out of it, if it’s low then it’s gone to ground.

[00:19:41] I designed these baseboards with my logon on it. Very cool. I wonder if there’s a picture there. You can kind of see it there. The Raspberry Pi sits on one side and these little spaces have also got a little key, a little label for all the pins. On the right hand side, we’ve got a thing called a breadboard? Who’s ever used a breadboard before? Yes, for those of you who don’t know, it’s a way to make circuits without having to do any soldering. These holes are connected in a certain way. If you plug one wire into one end of that row and another wire into the other end of the row, then those two things are connected. There’s a very easy way to set up prototypes, electronic circuits. With the kit, they give you a ton of LEDs. Those are the LEDs there. Loads of other components, resistors and stuff. There’s a button. Yes, that’s basically how we build these prototypes circuits. In this case, with code, I’m turning those LEDs on and off when I’m reading the signal that’s coming from that button into another pin. I’ve got one pin for the button that’s either going high or low when it’s pressed and each one of those LEDs are connected to another pin. With code, I’m turning them to switch on or off. You’ll notice that they’re fading up and down, that’s a whole other level of conversation. Those kind of inputs and outputs from a single pin are probably the simplest form of electronics. You can do some pretty cool stuff with that. There is wonderful array of other types of components which you can also interface with. You can see here – this is all part of the kit as well; I don’t mean to sound like an advert for my workshop but I can’t help it. I’m sorry. It’s how I am. Most of the stuff I do doesn’t really earn any money. The workshops are the one thing that subsidises all my laser fun. You can see here there are a few different components. There’s an eight by eight LED matrix and I’ll fire one of those up later and a seven segment display. You can see there are eight characters. Each character is seven segments.

[00:22:04] Both of those things are controlled by the same chip. There’s actually a chip on that circuit board underneath the display, so rather than interfacing with all of those 64 pixels directly from my Raspberry Pi. I’ve got to stop calling it an Arduino, that’s just embarrassing. I haven’t even been using – I suppose I have been using an Arduino this week. That’s my excuse. There’s a chip on that board, on that module, on that LED module. Rather than controlling every single LED individually, I can just interface with that chip with a couple of wires, three wires in this case, and I can send data down those wires to tell the chip that’s managing that display what to do. Rather than using up all your pins on all of those LEDs, there are ways to interface with multiple LEDs with just using a few connections. There are a few different data protocols that you’ll start to become familiar with too. This one here is an OLED display. Again, you can use as a simple data protocol to send data back and forth. They’re beautiful those OLEDs. Again, I’ve got one here that you can have a look at later. 128×64 pixels, I think. They’re less than an inch wide, so they’re really high resolution and really fun. Yes, that’s probably all about that. Then we come to neo pixels, which are my favourite thing ever. Do you remember the Laser Light Synths from 20 minutes ago? The laser light synths are completely made out of neo pixels. I think there are about 800 in a single laser light synth but this is a neo pixel ring. You can buy those in quarters from any of the UK suppliers. They’re really cool.

[00:23:52] These are massively bright LEDs. Again, they’re just really clever. If you have a look at one of these little LEDs, see that little black dot in there? That is a chip. There’s not only a chip in there but there’s also three LEDs; there’s red, green and blue. Each one of these LEDs can be any colour that you want, which is cool. Not only that, they are strung together. They are daisy chained together. There’s one line of data that goes into the first pixel and it goes out of the first pixel and into the second pixel. Just one line of data and resending pulses of data through the first one and onto the second one. You can control maybe 100 neo pixels just from one wire. Right, that’s kind of insane.

Do they have a state in them, so if you’re sending the same data they can say, “Okay, I’m responding to data X” and it’s listening for X?

Kind of. You’ve got to decide how many neo pixels you’ve got first. Neo pixel isn’t their real name by the way. That is what Ada Fruit decided to call them and everyone else has picked up on it. Thank goodness for that. I was going to swear there. I’ve got to watch my language today. Sorry, Jay. Thank fun for that because their real name is WS2812B. Well, that’s the name of the driver chip anyway. Anyway, what was I saying? Yes, I’m going to have to really get into this now. You send a bunch of data down the data line. One block of data for every pixel that you’ve got. The first pixel gets the first chunk of that data and it sets itself to that colour. Then when it sends the data to the next pixel, it just takes that bit away. The next pixel is missing the first bit but it gets the second onwards and then it deals with that bit of data and then it takes that one away and sends it along. That’s how it works. They’re really clever. Obviously, that’s not great, they’re a little bit fragile. That data line is a little bit fragile. You have to be a bit careful. Also, they draw tons of current. They draw 60 milliamps each, which isn’t very much really. Except when you’ve got 800 of them, that’s like 40 amps. 40 amps, when you’re using 40 amps, you need a wired that’s maybe 5mm in diameter. It’s very difficult to power them. Anyway, sorry, I could talk about neo pixels all – I’ve got some here. You can have a look at them later. They’re not on at the moment. Save that for later. I wouldn’t want to ruin anything.

You can have 800 of them in a single one?

[00:26:45] I don’t believe that there’s any limit, but obviously the longer your strip is, the longer it takes to send all the data down, so your framerate will go down significantly. Plus, also, the data does deteriorate as it goes through the strip as well as the resistance increases through the stip. Really, I probably wouldn’t put – what am I doing? Actually, I’m just thinking, you know Rebo? The company Rebo? I’m doing a hack day with them and they want to put neo pixels all around their windows and I think we’re talking about… what is it? It’s like 6 meters of 74 per meter, so that’s about 600. We’re going to try putting 600 on a single line and see how that works. In theory, it’s possible. You might just get a few issues with data and it might slow your framerate down. With laser light synths, I split it up into five tracks. There are actually nine rows of pixels, so there’s four sets of two and one set of one. I think there’s never more than – I’m just trying to think – there’s probably about 100 per line or something like that. 80/100 per line, so no more than maybe 160, I think, in that project. Yes, it’s really good. Some things are better at controlling neo pixels than other things, but because it’s using DMA it doesn’t block the code, right? Obviously, if I was doing this with a Raspberry Pi, especially in JavaScript, it can get very slow because it’s all blocking code. Although, we’ll come to this later but usually the libraries you use in node.js for controlling the electronics, they are actually wrapped C code, which has its own special set of problems. At least it’s optimised.

[00:28:47] Anyway, I’m going to come back to core components later. First of all, I have to talk a bit about some of the challenges. I don’t know if it’s changing, some of the challenges with setting up a Raspberry Pi, not only with node.js but specifically with node.js for doing hardware stuff because you can see I’m running these computers headless. In other words, I haven’t got any monitors, there are no keyboards, no mouse, it’s a headless Linus computer. Your first challenge is how do you do anything with it you get an SD card and you can write the Linux disk image to it. Raspberry Pi maintain a Linux distribution and you can just literally download a disk image, write it onto the SD card, stick it in your Raspberry Pi and it will boot up. How do you then connect to that if you’ve got no keyboard? Well, with one of the older Raspberry Pis, it was relatively easy because they all have Ethernet on, so you could just plug in an Ethernet cable and then you’ll see it on your network. Then you can connect to it through SSH. If any of you are new to Linux or a server admin, this is a way, basically, to over the network access your computer or Raspberry Pi through a command line interface. It’s as though you’re typing in terminal on your computer but it’s going over the network to another computer. As long as you can see that Raspberry Pi on the network, then you can SSH into it because it’s turned on by default on the disk image. That’s cool. If you haven’t got Ethernet, which we don’t on a Raspberry Pi Zero, then it’s a bit more challenging. Well, there are so many options. You can get a micro USB to Ethernet adapter, that’s one easy way of doing it. You can also get a serial interface. I’ve got one here.

[00:30:52] A serial interface and plug it into some of the pins, some of the pins on there and then you can access it through USB, so you can connect over USB and through serial port to the Raspberry Pi. Again, you can access a command line on the Raspberry Pi over the serial port. Or, someone’s figured out a clever way of just plugging in a USB cable between this and your computer and connecting to it through serial that way. Once you’ve connected to your Raspberry Pi once, then you can set up the Wi-Fi on the Raspberry Pi and so then you just plug in a Wi-Fi dongle. You can see I’ve got some here, some pretty small ones. As you can see, I’ve got a little adapted there to make it go from normal to micro USB. Once it’s on the Wi-Fi, then you never have to worry about it every again. You can just SSH over the Wi-Fi. Any questions? Once you’re in, you’re in. You can command line, you can do the updates and everything. Obviously, if you’re new to Linux that’s pretty scary but I tell you what, I’ve got this really cool resource on the internet which is teaching you command line and Linux in an interactive webpage. It’s really fun. If you’re new to Linux, I should probably get some links together but if I forget, hit me on Twitter and I’ll send you a link. I’ve been doing Linux on and off for a long time, I’ve never really learnt. Just a few years ago I started doing server admin for my web server and I was terrible at it for years and years and I’m still quite terrible at it. I guess just doing it more and more you start to become a bit familiar around it. I’m still a little bit lost in the dark. I suppose any of you doing node.js without too much admin experience knows what I’m saying. It does get a bit easier with time and I think that tutorial I mentioned does really help.

[00:32:56] Okay, node.js on a Raspberry Pi, how do you install it? Well, there’s a package manager for Linux, the default one which is at Git, so you can install node.js just the Linux way, but don’t do that because the node.js – well, you can do that but it’s like 10.29 or something. It’s not a particularly new version of node. Who’s done node.js before? Most of you. Not all of you. There are a lot of libraries on the internet for working with electronics on the Raspberry Pi on node.js, but they tend to be someone who’s just got a bit of hardware working well enough for them and published it and not really thought too much about it from then on. I’ve dug around a bit and found some that are good, some that are terrible, but some of them, if not most of them, don’t work on all version of node.js because they often wrap C libraries or C++ libraries or C++ code. Every time a new version of node came out, there was a new way to wrap C libraries, a new way to write those C code to make it work with your new version of node. Now, at some point, someone decided this was a problem, so they invented a new way to wrap C libraries with this system called, “NAN” N-A-N. What does it stand for? I’ve forgotten. I always forget. NAN is like the worst name ever for anything because it’s not a number or anything. No, it’s NAN, native abstraction something, I think. If you write a C library using this magic system, then it works on all versions of node. Of course, most of the libraries haven’t done that. It’s frustrating but I find if I’m working with 0.12. something usually works or the common ones’ work. I think a lot of people working on Raspberry Pi hasn’t updated node for a while. That’s one of the real frustrating things and I’ve slowly been figuring out how to update C libraries to work with NAN.

[00:35:10] I’m reasonably experienced and comfortable with C++ but it’s still a massive pain. Anyway, enough talking, we’ve gone on quite a bit, haven’t we? Do you want a quick demo or a quick break and more demos? What do you want? Okay, right, so let’s just increase the size of this. You can see on there, on my terminal and I’m currently SSHed into this Raspberry Pi, yes? You can see I can do all of the usual things. Have a look at the file system. This is all the pre-set examples from my workshop. I’m just going to bring that up a bit. Is that helpful? Let’s, first of all, just make a… what have I got? Let’s just blink an LED. Anyone working with electronics will know that blinking an LED is the “hello world” of electronics. Here we are, in this case, I’m using a node module called, “On/off” and that gives you input and output access to the pins. I’m setting one of these GPIO pins, number 21 to be an output. Then I’m just doing this old fashioned set interval, which you shouldn’t really do. This example is specifically to show you how you do Arduino style coding which always has an update, which isn’t necessarily the right way but it’s fine. Then what I’m doing is writing to that LED 1- whatever the current value is. That’s basically going from zero to one. That’s really all the code there is, except some nice clean up stuff. Then I can just run that by typing node and hopefully – I don’t know if the pins are set up right on that – we should have a blinking light, right? Yes, go on. There is a button on that.

[00:37:16] This is really technical and you don’t necessarily need to know this right away but on/off accesses the Linux drivers for the GPIO, which obviously everything in Linux is a file system. That’s just doing file access but this GPIO is doing it in hardware and because of that it can do fading. You can see that fading up and down. Let’s just get to the good one, come on.

At the back can you see the fading okay?

Yes. Right. Now, I’ve basically got fading on multiple LEDs in a chaser, yes. That’s the sort of thing you can do and we can take a closer look at some of that code. Seven segment display has a chip on it, running it, driving it. That’s the wrong way. It’s too bright. I actually converted the Arduino library into node.js for running this chip. Now, you can do fun stuff like put in a counter. Of course, the wonderful thing about JavaScript is that things like passing strings find data for all the letters in the alphabet, which is actually impossible with seven segments, but you can see there. I’ve done a reasonable job. You can still read it, which is quite amusing. Of course, we are connected to the internet so you can do stuff like read APIs. In this example, I haven’t tried it for a while, but in theory this should find out where we are through a GOIP server and then it should go to another server that tells us when the next pass of the ISS is going to go over. You can see that counting down. It’s going to happen in 53 minutes. Well, that’s good, isn’t it? It’s never been dark when I’ve run this. I’ve run this software and it’s never actually been dark. You can see we’ve getting some really fun stuff with the internet.

[00:39:28] The thing about node that’s really special and makes it a lot easier in some ways than Arduino and C++ is that there’s a ton of web server libraries. It’s really easy to make a web server. What I can do is actually run – do I need studio? I’m not sure, let’s just do it anyway, why not? If in doubt, give it permissions. In this case, I’ve actually set up a web server and if you’re on my network, my network is just called Sebs by the way. If you want to go to my network, the Wi-Fi is called Sebs. The password is “Internet” with a capital “I” and if you manage to get on that, then you should be able to access the web server on my Raspberry Pi. What’s it called? Rpie-leds.local. Okay, so this one actually connects to a different web socket server somewhere else. In this case, I go to my server. I don’t know which one, let’s try that. Okay. I don’t know if the client is connected to it or not but can you just push the button on that? There you go. Did you see what happened? Right, so actually when I pushed this button, stop for a moment, when I push that then that light should go on too.

Which light?

Yes? This is connecting to my web socket server that’s hosted somewhere else and I can have a direct connection then between the Raspberry Pi and any browser, which is pretty much and vice versa. Okay. This is quite a fun one. This isn’t really part of the workshop but it’s something that I’ve been working on, which is remote lights. At home I’ve got a bank of neo pixels that I use for lighting when I do videos and stuff. I can adjust the white balance. I hope this works. I think this is on this one here.

Do you want me to hold it up?

Let’s just see if it works. Have we got anything? It’s broken, isn’t it? It’s gone down. Maybe I have to run it, actually. That could be it. This one runs by itself when it starts up. I think it’s that one.

It looks like it runs really quite rapidly.

[00:42:05] Here we have an interface. This is just something that I mocked up quickly. I have to finish it off properly. Imagine this is like the lights – did someone else turn that one? I was like, “Why is that turned on?” Imagine that’s like a bank of lights and I use it for my videography. I can actually adjust the brightness. You can see it gets really bright and also I can adjust the white balance too. If I have it at full saturation, I haven’t got the full range of hues here but I can go from green to orange. If you’ve got that on your phone, you should see it updating as well. That’s the power of web sockets. There you go, someone else is doing it now.

Multiple people can adjust the controls at the same time?

Yes, and it all goes crazy in a really fun way.

Do you know how much this strip costs?

Okay, so that’s not a neo pixels strip, that is something called, “Dot Star” which is slightly different from neo pixels but basically the same. I don’t know how much it is. If you buy strips from normal suppliers it can be quite expensive but you can if you’re patient get them on eBay or from China. I think I’d pay maybe 15 dollars a meter. If you bought it in England, it would probably be 30 pounds a meter. It’s quite different.

Still, for what’s essentially a smart light, that’s pretty good.

Yes. I’ve got this other setup there. I wonder if I can connect to that one. Right, maybe that one will work. I’ve got another Raspberry Pi set up here. This one has just got a little strip of neo pixels. There are ten on that, so that should be enough to power from an ordinary Raspberry Pi. People are just messing with that now. An ordinary Raspberry Pi and that little strip comes with my workshop. It’s quite fun. If you want, we can do some hacking on that in a moment but let’s just run some of the tests. What were some of the other neo pixel ones? 4.0 neo pixel iterate. Right, it’s just actually rebooting that computer. Right, so we’ll leave that one for a moment. It’s a good opportunity for me to talk about this. With Raspberry Pis, you get things called “hats”. Have you heard of hats? Essentially, they’re another littler circuit board that just gets pushed on top of the Raspberry Pi and the pins line up. You can see this one is called “a unicorn hat”, it’s made by a wonderful Raspberry Pi supplier and designer of hardware in Sheffield called Pie Morony and they’re brilliant, they make cool cases. I love their website. If you want to shop for Raspberry Pi stuff I would highly recommend them. They have a lot of Ada Fruit stuff too.

[00:45:22] They’ve got this; it’s called a unicorn hat. It’s and 8×8 matrix of neo pixels, which is pretty fun. Yes, so we could try running that if you want. If that one booted up yet, maybe?

It’s booting up. We’ve got one light a different colour now.

What’s that? Yes, so when they just boot up, when neo pixels start they’re usually blue but if there’s a bit of noise on the line of something, then one of them might just change a random colour. That’s quite fun. Let’s try that one too. The Wi-Fi is really… it’s my Wi-Fi. There’s just something about this space that’s pretty toxic. There are a lot of radio waves. What is it? It was 4.0. I can put in the number of pixels, hopefully something might happen. Is it cool?

Yes.

Okay. You can see how bright they are. That’s one pixel. Let’s run the other one, which is a rainbow. That’s not even full brightness. I could try putting it to full brightness and I say try because it will draw loads of current and it might cause the Pie to…

To what?

To explode. HSL. I think I can go to 50. Yes. Let’s just try it. Okay. I need to see this. Right, so that’s pretty cool. If you can imagine, this is what I – you can’t even look at it, can you? That’s how cool it is. You see a bit of retinal burn, that was me for three months doing laser light synths. I also have another fun little device. Where is it? It’s this one. You can put those down now. I really love these little – Jesus, that is bright – these little 8×8 LED modules. They’re actually my favourite. They’re so old school and a bit rubbish but I really love them. They’re so beautiful. It’s the same chip as the seven segment display, so you can just replace the wiring. In fact, you can run the seven segment display examples on that but it’s just random pixels light up.

[00:48:20] I’ve got too many computers. Help! What was that one? That was the LED one, wasn’t it? It’s gone. SSH. It was that one, I think. I don’t know, something like that. It sounds plausible. Just do it, man. That’s going to be amazing. 3.3, so this little – just to make sure it’s working. These are really cool. I actually really love this one. We can have it play pong by itself, I think. That’s pretty cool. Cool. That’s a massive whistle stop tour of all these components. They’re obviously lots of sensors as well. You can get light sensors and temperature sensors and distance sensors. I didn’t bring any of those today; I was concentrating mostly on outputs. That’s fine. Obviously, we can connect any of those things with a Raspberry Pi to the internet. It’s obviously been a really short summary and gloss over. There is a full two days of workshop of this stuff and that’s still not the full amount. Obviously, node.js and Raspberry Pi, obviously, you wouldn’t have that problem with Python either. It’s just so easy to set up a web socket server in node.js. It’s ridiculously easy. If you look at some of those code example, it’s just a few lines of code. Obviously, it gets more complicated when you have more architecture and rooms and user accounts and stuff like that. Just to set up a simple connection is really super easy. This, hackathon classics is a new show that I’m putting together for the digital festival. It’s essentially like this but more fun. I’m looking at retro hardware light the Nintendo light guns, like the Casio VL tone keyboard. Some other stuff too. I’m hacking it and also doing cool modern things with computers and lasers. There’s going to be loads of audience interactions, motion detection, applause triggered games and stuff like that. It’s going to be a really fun show. That’s on the 28th of September, at the Old Market. I don’t know how to find out about that, really. It’s part of the digital festival. It might, I don’t know this for sure, but it might actually be the official closing event for the digital festival. Wait and see about that. Yes, it should be a lot of fun. I’m going to bring a big laser to that. That’s some pretty serious stuff. I think that’s probably it but there’s all my contacts. Twitter is probably the best way to get hold of me. Yes, I think that’s cool, right? Excellent. Thanks very much.