 I'm going to choose myself on the next slide, but first I want to get the audience participation. Who has never heard of a Raspberry Pi? Everyone in the room, awesome. Who has never heard of Redis? Redis is a database server that is intended for key value storage. So if I've got a long-running query and I want to cache it so I don't have to run the expensive query every time, I can give a key and store the value temporarily. And Redis has all these built-in facilities for automatically expiring values and caching, and it's really quick for key lookups. So it makes it awesome for that. I'm not using it for that. I'm using it for a quick drive. So I post my message to it, and I read messages from a specific channel. Who has never heard of LEDs? They're light bulbs. Who has never heard of Mario? Mario is a fictional character built by a Nintendo, originally created by Shigeru Miyamoto. Okay, let's move on. My name is James Alexander. I am a systems engineer for Leaf Software Solutions, basically program stuff. Leaf Software is a sponsor for in for Pile, Ohio this year. So I wanted to give them a quick plug. We do large-scale electronic records processing. So I've been doing automatic control systems, and recently we're moving into more rapid minimum viable product development. We also do cloud DevOps deployments. So if you've got an internal infrastructure and you want to move to AWS, you want to move to Azure, we've got some guys on staff that can help you do that. Or if you want to move between clouds or away from the cloud or whatever. We also do Microsoft CRM and Dynamics work. So if you want to install those tools or manage them or get support and you live in the in the Atlas area, look us up. I have business cards you can chat with me and I will direct you to someone else. I do not do any of that stuff and then we can get you set up that way. All of the slides and the code is available on my blog here. I blog consistently about once a year and I found the past three years I blogged on the coffee bot. So just pick any of the last three blog posts and you've got some information to look at there. So what are we doing here? I said I was on a multiple year and I got off of a project and so I had some bench time. So I had to decide what to go and do with myself. Like any office we have and we always find that we have the case where there's an empty coffee bot and you have to always make new coffee regardless of if you know it's Brent. First thing in the morning or if it's mid-morning there should always be coffee there, right? Because someone just made it. If you give the job that isn't the case. So we chatted internally and said what if we could measure how much coffee we have in the pod at any given time and we have this habit of kind of scrolling and talking around saying what if we use this, use that and we have this engineering Rube Goldberg machine of how can we solve any problem with the most complicated and so that's what we're going to do next. The critical piece of infrastructure that I needed was the scale that's on the left side here. The scale is a USB postage scale. So what it can do is you as an USB interface you plug it into the back of the Raspberry Pi and it shows up as a human interface device. So the Raspberry Pi is on the upper right and the bottom right here is an LED panel. You can buy these from Adafruit. This is a 16 by 32 which you'll see later on here. What made this whole thing work is when I went to look for scales that were going to work, I found a C file that included a list of different scales that were going to work. This scale that you can get hyper positive right here at the bottom, there's also a company in USB scale that C file that knows how to read data off of each of these scales individually. I was trying to decide which of these scales to buy because I know that these are going to work with Linux because this guy got up to work. I figured that 30 pounds is too much because a full pot of coffee is about 5 pounds so I didn't want to have too much of a scale. At the same time I didn't want to have a 5 pound scale because I didn't want to max out my scale every single time I put coffee on it because people are going to just jam the thing down and I didn't want to damage the scale. So I picked the demo 10 pound scale which is kind of right in the middle. I received an email from some guy on the internet one time saying he tried to do the same thing that I did here where he would connect a scale to a Raspberry Pi and tried to get data off of it. He was running into an issue where the scale would arm like a turn off. There's an auto shut off after 5 minutes. I never ran into this issue I think because I've always got something on the scale. So at the end of the day we leave our coffee pot on it and so it continues to send voltage to the Raspberry Pi and continues to say on. I never heard back whether or not that suggestion helped him but that's a suggestion if you run into the same same problem. So wiring. Here is my messy desk and my my software from my wife. The idea is that we've got some power that goes in the back of the LED panel here and I've got just two tiny two-pond jumper cables that just sit in the back of this wiring here. This is real. If you move it, if you drop it, it's going to come disconnected. Which is one of the problems we're running into now. This sits on top of our fridge so as someone opens and closes the fridge door there's a vibration that runs through the whole fridge and these jumper wires that go into the DPI opens of the Raspberry Pi get shuffled and dozzled and will work themselves loose. So it's time for take a break. Let's move on after that. A better way to wire it is with this little adapter board. The library that I mentioned here is an awesome awesome library. He wrote some C code that would read and will allow you to write images and any thing you want to these writes with the LED panels. He also included wiring diagrams. He also included this image to show how you can use an adapter board and this ribbon cable with an IDC connector to plug directly to the back of the LED panel. Here I'm putting three panels chained together so if you can drive three panels off a single Raspberry Pi you can do it all with this board with three connections. As a hello ward I put it on here so I can show you my wiring using the individual wires. This is supposed to be rotating square. If you kind of squint you can you can see it a little. What it's actually supposed to look like is something more like this. So just to show you that you should keep trying and maybe you wire it the correct way. I was wiring for a Raspberry Pi 1 and I was Raspberry into a Raspberry Pi 3. There are 24 pins in the 1 and there are 36 pins on the 3 so make sure you're looking at the right wiring diagram when you're going to wire this up. Linux is notoriously bad at maintaining Wi-Fi connections. This is true on the Raspberry Pi as well. Even the 3 has a built-in Wi-Fi chip and I didn't personally test it because I just assumed it was going to. We included this Wi-Fi script. All this does is we tie this into Cron so every five minutes this runs it tries to ping our router if it can't it will run if down and then run if up immediately afterwards. This also works great when our local admin will change the Wi-Fi password every six months or so and I don't want to have to take the Pi off the fridge plug it into my laptop change the configuration for it because I forgot to do it so SSHN like the morning before it changes set the new Wi-Fi password and then this will continually try and ping it until the password changes and I get the new password and the new Wi-Fi configuration without having to take the Pi off the fridge. So let's look at the hardware let's look at some software design so the scale at the bottom left here is being read by my coffee underscore scale that py script this is just the infinite loop that will read the data off of the scale once per second. This will publish messages to Redis based on my business of when I want new messages or new things to appear on the LEDs display. The subscriber here on the right called PubSub publish subscribe and we'll listen for those messages and based on whatever it's sent in Redis it will render and start executing a different animations file. The animation scripts are just plain executable Python scripts that will draw the LEDs pixels on the screen based on that library I mentioned earlier the Henners-Zeller library. To read data off of the scale I have to open a file in binary mode and the file is the human interface device that I mentioned before you plug in USB to the back of the Raspberry Pi and it shows up as a device. Here I'm reading four unsigned integers so 16 bytes off of the file and I use just a stranded Python file and I unpack it into what is going to be a tuple. Regardless if you read four characters or one character you're always going to get a tuple back from unpack and so you have to account for account for that fact. Here's the full function that I use so here's the human interface device opening the file for binary read and then in context you can see that the fourth element of the struct is of the tuple is the actual weight in grams. I found this out just by doing print on this it's like oh look at that the weight is always on the fourth tuple. I am having an issue with it recently though the file.read command will hang on me so it doesn't run exception it doesn't stop it just continually sits there and fails to read and it doesn't move on. My assumption is that there's some sort of power fluctuation that the scale doesn't have enough power or I'm not getting 16 bytes fully read out of the thing so it's just kind of hanging there. What I did to solve it which is kind of hack job here I'm using a unix signal and it's a sig alarm so basically I say wait five seconds and if you don't hear from me call this function and this function throws an exception so if I'm sitting here waiting to read and five seconds pass it throws an exception kicks it out of its read and it can continue on with the next iteration of the loop. I'm doing other interesting things here like writing to a dynamo table because iot needs to write to the cloud and specifically dynamo because I have a single scale writing once per second so we need the type of scale that dynamo provides. Here is the actual script that will write a fixed set of text on my led panel I'll show you some screenshots here in a minute but here I'm calling redis so redis.publish and so I specify a named queue which is just a channel string and whatever I want to display on it. My message will either be some text that I'm playing or it'll be a random animation. My business rules are if less than a mug in the coffee pot or the coffee pot has been sitting on the scale longer than two hours don't display how much is in there assume it's bad coffee and display some kind of random animation which is where Mara is going to come in. Yeah this function does the publish so it will publish to a channel and then I've got another side on the you'll see in a minute where I listen to that channel so it's it actually is built into redis I didn't have to write any of this myself this is the redis object so initially all I had was a scale connected to a raspberry pi I didn't have a panel on it at all so in the beginning there was just a csv file of weights and so then they would I would disconnect the raspberry pi put it on my desk and I would graph it like this and I was shocked to learn that the weight changes in the morning there is no activity you see there is no activity in the afternoon I don't know why people drink coffee in the morning maybe thirsty so on the other side here I'm showing how you subscribe so again this is just straight off of a redis object I create a pub sub object and I subscribe to some name channel I'm this is a little bit paraphrased for the sake of getting it all on one slide but I'm using a an environment variable here instead of a fixed string and there's a little bit more going on here so this is my main loop for listening and I have ran into an issue with the redis library so since redis for python is a c extension whenever you hit control c if c is doing something the cco is doing something you don't actually get the signals into python to cancel the process so it sits there and it doesn't respond to your control c also it won't halt my separate process because I'm spawning a separate process for each animation so even if I did get the listening process to close I still have something animating on the led panel that different clever poses so that's why I have a special message that I just call kill that after it that's based on whatever pit that I've saved off it will unsubscribe to my listener and it will move on and we'll kill the process the actual process itself looks like this and again this is made possible by via the henner zealot library that I've mentioned a couple of times now for wiring and everything I just can call python with whatever script that I've derived from his base classes there's a couple of special properties here that I've passed the command line the hardware pulse the GPIO pins share the sound subsystem on the raspberry pi so if you were just sending straight GPIO to this you're going to get a warning from this library saying hey you can't do that you need to turn off this hardware pulse subsystem so that's what this is doing I have a 16 row led panel so that's why I'm just spying 16 here and then in this last parameter is intended to help with ghosting so if there's a single pixel in the middle of the screen right now I've still got ghosting around it picks you can see they're kind of on they're kind of not this parameter is supposed to help you with that it's a pulse based modulation of the signal going to the the led to no matter what value I put in here I still got ghosting and I only notice it when I'm at home alone in my office when it's dark at the office there's plenty of lights and it's not a big of a deal so I just live with it the base class that all of my animations derived from are here there are tons of options that I've omitted for brevity but the library is here we just set up a matrix it's a two-dimensional array of led panels pixels right so you set up your options set up your matrix and then I listen for a sick term event so my listening process is going to try and kill each process if I try to cancel the process or if I want to render something else this is what the fixed text animation looks like I should have mentioned earlier that I wanted to display two lines of text because I've got just enough pixels for two lines horizontal lines on my on my panel and so I send a special message that's got two colons in the front of it so the first line is going to be the top line the second part is the second line and the library gives me draw text and I specify a font and he's got a dozen or so different fonts in there and I believe my next we'll show you if you look at the nine by seven these panels are intended to be chained together so ideally you can have a big wall of these things like a New York Times Square and this would actually you'd see the whole thing but on 16 by 32 you don't see the whole thing six by nine looks a little bit better I'm writing one two three four on two different lines here so I can get most of my message on that first line five by seven is actually what we used in production because when I use four by six the lowercase m looked an awful lot like a capital H so if I were saying four mugs the panel looked like it said four hugs which I don't know if your coffee hugs you in the morning maybe you need a little more coffee the first version of what we had in the break room was this tiny little spark core with a tiny little LED panel we wired this up to a hip chat channel so you could write a hip chat and the message would appear on this on the break room we eventually decided that I want a little bit bigger screen in this tiny thing on a breadboard the thing on the right here is a micro usb cable so that's not much bigger than than that but it was cool right um for the longest time for that once we got the LED panel installed all we could do with it was call the library c code which to display text on it and it would render a marquee and it would just scroll past like this so that's all we could do for about seven months and then something amazing happened we got python library you know with the c binding so I could write python code and render uh to this panel so here is an example of some python code this is my very first uh animation which is kind of garbage um here is my the name of the script it's scanning dash pixel pixel um if you're a fan of pepe and we really all should be you should be cursing my name for using a hyphen and my module name um I apologize I didn't know at the time um I get away with it here because these hyphen script names are all at the very end and none of these were imported by something else so if you try to import these into a different library you're going to get syntax exceptions essentially all this is doing is looping over x y's and setting a bunch of pixels whenever you set pixels though you have to turn them off so the next iteration you have to turn off the pixel you just turned on so this will render kind of a pixel that looks like this you're going to see it just loop row by row one one pixel at a time if you're on the front row and maybe you can still see a little bit of the ghosting but the top and above below and below above that pixel you can still see a little bit of light that's turned on like I said I never could fix them this is my second attempt so not just going down the rows but I have like a car that goes back and forth like I've also seen this referred to as a Cylon which is also is also valid and now I get to my namesake on the the name of the the talk Mario my wife mentioned one time what if you could draw Mario I'm like I bet I could and then I googled 8-bit Mario and this is what I found so all I had to do was render this many pixels and I found that to animate them all I would need to do is have a left foot left hand forward a right hand forward and then a middle so I needed what three different set of pixels to fully render Mario running back and forth so this is what I ended up with I did have to figure out how to swap him so when this loads he'll come in from the left to turn around and then run back the other direction the very first version was just him standing scooting right and then I was like well what if I googled 8-bit jumping Mario and so then I've got a big render jump and forth this I found was a little bit as anyone heard of Conway's game of life John Conway's game of life I'm gonna let this run because this basically a three minute video here but having an arrest almost requires that you're right game of life on it right so this is one of the things that happens if the copy is more than two hours old or there's less than a mug on it this one I like particularly it's called acorn the initial configuration is seven pixels and it will continue on for more than 5,000 generations so anyone not familiar with the rules is any pixel that's on here any live cell with fewer than two lives overpopulation any live so with two or three live on the next generation any live cell with more than three life neighbors dies overpopulation and a dead cell three neighbors because five cell production almost at a time based on the applause in the next room but we actually need to see what it looks like so here you see my disembodied hand on the right side and you'll see if you start there's two mugs in it initially I looked up there's nothing on the scale anymore so I get a game of life animation we spend an endless amount of time pouring I'm not careful with it ideally we should place it back on the scale and it should weigh out to one mug at 1032 so the next things we need to do we need to have more than one 16 by 32 panel we need to implement the hypertext coffee protocol control and we also need to have a rich burn her in an HTTP 418 I am a teapot this is my to-do list thank you very much any questions I think I'm out of time right