 Welcome to the show. It's me, John Park, and it's time for the St. Patrick's Edition 2022 of John Park's Workshop. This is the greenest shirt I had. I apologize. My sneakers are a lot greener. But the shirt, not so much. Welcome. Are you celebrating St. Patrick's Day today? I don't know why I'm making such a big deal out of this. Now it's weird. Let's see. What have we got going on for today? I have, let's say, to start things off, jobs.adafruit.com. You might want to head on over there if you're looking for work or if you're looking to hire someone. This is, in fact, what it looks like when you head there. And there's some projects we've mentioned before here. Nothing new since the last week or so in the help wanted section there. But you can see there's a bunch of projects that are contract positions. There's also some remote work and full-time work, part-time. So head on over there. It's free to use. It's free to set up. All you need is an email address and account with Adafruit. All of the listings are vetted. And so you can trust them. If not, bring it up with PT and LeMore. You can also head over to this available for hire section. I'm not logged in on this browser right now, so I won't see anything. But once you're logged in, you can check out people's resumes and try to find someone and do some work for you. How about that? If you are joining us over on Twitch or one of the other sites where I'm not looking at the chat, I am looking over on YouTube. Hey, Anthony and Jose Maria. Nice to see you all. And this is our Discord here. So if you want to jump into the Discord chat, you can go to Adafruit.it-slash-discord and then head over to the live broadcast chat channel. And that's where the conversation is happening. I am curious actually if anyone in the chat can let me know if Twitch is up. Oh, it looks like, yeah, it looks like it is. Restream wasn't giving me any feedback and I wasn't sure if we were broadcasting there right now, but it looks like we are. Good. Let's see. Next thing, I have to do a little maintenance here. I have a show on Tuesdays. It's called JP's Product Pick of the Week. And I need to add a little update here so we can show the video from this past week. I do a little one minute recap I like to show during this show. The show on Tuesdays is at this time, so four o'clock Eastern time, one o'clock Pacific. It is usually around 15, 20 minutes. I go over a new product pick or a highlight from our archives and we have a big discount, usually 50% discount on the product during the show just during the live stream. So if you can tune in live, you can just log in and grab an item usually at 50% off. There's no coupon code or anything, so just throw it in your cart. You can usually get a limit of 10, so you can't hoard stuff too much, but 10 of something isn't bad. And just give me a second here because I need to load up a piece of media and I wasn't able to grab it before the show. Let's see. Here it is. Here's the one minute recap product pick. It is the OLED featherwing 128 by 64 display. You can use that STEMIQ teaport to add another peripheral. This is Bongo Cat. And if I hold these, these are going to play a little sweep on the original Game Boy audio hardware. The extra bonus here is that you can see I've plugged into the STEMIQ teaport a little accelerometer. And as I tilt that accelerometer, it's a variable that changes the rate of that sweep. It's pretty short sweep. If I'm at one, it gets a little longer and even longer. On the side of the OLED, same pins as my feather, neokey feather there. OLED featherwing, it's 128 by 64, I squared C display with STEMIQ teaport. That was going to try to loop on me, but I caught it, just barely looped. So that was product pick, a cool one, really, really nice one. And that's a big update from the previous one. I think we still sell both versions, but there was a 128 by 32. So half the height that we used to carry OLED featherwing. I'll show you, show the options there. If you check out Adafruit and just go OLED fed in the search, you'll see here's the new one, 128 by 64. And that was the one that was half off yesterday. And then we also have the 128 by 32. If for some reason you need a tinier screen, but they're actually the same price. So that was product pick of the week. Tune in next Tuesday for a new product pick. And I won't give away what it is. I almost said it. Okay, so let's see. Next up, why don't we jump into our Circuit Python Parsec? I'll get all set up for that. Okay, so for this week's Circuit Python Parsec, I wanted to show you a little trick you can do with swapping out colors in an image palette using display IO. So this is part of our continuing series of display IO tips and tricks. This was based on a transparency-based trick that Todd Vaught had put up on his tips and tricks page. And by the way, I'm going to be working on a collaborative guide with Todd where we will put a bunch of his tips and tricks into a learn guide. So it'll include examples and maybe some of these videos as well. So for this one, what I have is an image. This is another one of these really terrific voxel pixel art images. And give me a moment because I want to give credit. I've forgotten the name of the artist on this. And if you want to look it up, it is Meral Ezgi. M-E-R-A-L. Last name, Ezgi-E-Z-G-I. Look those up, Meral Ezgi. A bunch of voxel based art that looks like pixel art. Here we have an 808 drum machine image. It's very cool looking. Right now what I'm doing is I'm just using the Adafruit image load to load this BMP image up on screen. And for now, I'm just leaving it up there. But the trick, the thing I wanted to show you here, I'm going to uncomment my code and resave it to the board. And now what you're going to see is it's going to go through and one by one replace each color in the palette with green. You can pick any color you want. You can do more sophisticated things. In Todd's original example, he was using transparency so he could reveal something behind. But here what you'll see is just every time it loops through, it's going to display the original image for a second. And then it's going to start just making its way through the palette. Every palette in the image and switch the palette value for green. If I change this out, we can do something like let's say red. It's not quite as visible actually because it starts out as an orange image. But you can see there one by one each of those colors changing. And this is a really neat trick. It's something that has its roots in video game art, typically in real time video game art using palettes to swap how things look so that you don't have as many big heavy assets in your scene was a common trick. And so this is a way that you can take the image after loading it. Take a look at the code here. We're doing an image load. We're setting up some display IO stuff. And then this function here image and palette are cast into this Adafruit image load load and then the name of your BMP image sets up the bitmap as a tile grid image using a pixel shader based on the palette. And then in the main loop what I'm doing is grabbing that palette based on whichever image you can have multiple images in here. The pixel shader on the image in this case the 808 BMP. And then one by one I go through however many colors are in the palette. You can have a one color palette. You could have 128 colors 256 however many are in there. And I'm saying take each one starting on the first one and replace it with whatever color I've picked. So if we go in here and change this to blue let's say hit enter. Now whoops did I oh that's good all right. Let me hit save there. So now what you'll see is it just goes through one at a time changes it takes a little a moment there. We can delay how long it sweeps through those otherwise it goes too fast to see. And then it holds that image for a second and repeats it. So that is how you can replace the colors in an image with a specific color using display IOs palette shaders. And that is your circuit Python Parsec. All right so I should I should grab some other art to to show those things with because it's really interesting depending on the style of image. If you have flat artwork if you have some sort of dithered shaded stuff it really can have a cool effect there. Oh and we have a foamy guy in the chat. I saw a foamy guy starting talking our discord. Maybe you have ideas about palette as well. And and let me know if you have some specific tricks you'd like to show. If you want to share some I can do future circuit Python Parsecs on other palette tricks other display tricks or other general circuit Python tricks. Let's see. So I'm checking out over in the YouTube chat Jose Maria Thierina says hello it's first time watching broadcast. Could you give a brief explanation of what you're going to build assemble or show. Well yeah actually that's a that's a really good lead-in to what's happening next. So the main project that I wanted to show that I'm getting started on that I'll be working on a learn guide for so you you can watch this see sort of the beginning steps of how I'm putting this together. And then I'll be writing a learn guide that'll that'll give you the specifics on it. If I jump to my bench cam I have this turn on one light that I forgot to turn on here so you can see a little better. I'm very excited because I just got this new gaming handheld in delivered the other day. This is the wiggle that on and off there. This is the steam deck and I'm going to do is actually I'm going to unplug this stuff here and I'll go and just restart that game there. Let me see if I can jump to that view as well. Okay so let's exit the game confirm. So steam deck here if you're not familiar with it this is a gaming console that is essentially a Linux based machine that can play with a really nice emulation layer all of or many of the games in the steam library the Valve's game service. It runs an emulation layer called Proton I believe or yeah I think that's right. I'll have to look that up and it uses this nice steam UI to make it present more like a game machine so you can go and look in your library of games download games onto the device and then play them. It can work essentially like a gaming PC in that it has a USB-C port that can do everything from mouse keyboard to video over that port so you can use a dock there's a forthcoming dock that'll allow you to use this just as a PC but then grab it on the go if you want. I'm using for the stuff I've just started playing with a pretty typical USB dongle that has a USB-A port for peripherals an HDMI out and a power USB-C that'll keep it charged. In its default sort of intended use you can just grab the the thing and go it's got pretty typical modern gaming controls on it a couple of analog sticks a d-pad button cluster some little track pad kind of guys here and some buttons on the back and what I wanted to do was see how we can make our own controllers for it and so the idea behind this is to use a circuit Python based board in this case the Circuit Playground Express which we can plug in over USB and treat this as a game pad so we're used to taking these kinds of devices and sending keyboard commands to things. Hold on one second I just realized this is another light that's out I think that one's based on a remote. Sorry there was a weird incident earlier today that kept me out of the workshop there was a chemical spill not far away and so we had kind of shut the doors and stayed inside some little delayed. I think everything's gonna be okay though so let me see there we go that's on now much better there we go we have light so you can connect this as a keyboard however there are things in the user interface once you start a game that don't actually work all that well with the keyboard unless you go in and mess with a bunch of settings so for example I don't think there's a keyboard command not one that I found on a typical HID keyboard that will hit start for you so on a game pad typically any button or the A button will start and get you into the game and then you can navigate usually with arrow keys but then something like this to hit start there was no button on the keyboard that would work so rather than use HID keyboard I decided to explore HID game pad and this is sometimes called I think HID joystick but in Circuit Python we have methods of sending game pad HID descriptors and commands and so these are sort of a different flavor than mouse and keyboard based on the same kinds of ideas and this allows you to send these types of commands over USB so typical very dusty haven't used this in a while as a Xbox 360 controller and these will have the button cluster of ABXY they'll have the start and the back button which are some of the ones I needed in this case a home button which on an Xbox is this X on the steam it's this steam which kind of pops you up a layer similar to a Windows button that type of thing they usually have a D pad of some kind a couple of analog joysticks and then sometimes some click extra buttons built into the joysticks shoulder buttons analog in some case shoulder buttons I think these are analog triggers on some of some of the game put pads that I have I can't remember for this on this one and sometimes other other buttons on the back so that's a fairly typical modern game controller but even with the really simple examples of a game controller which would be more like I have one over there but more like a SNES controller let's say D pad four buttons couple shoulder buttons maybe a couple of start and select buttons those are all game pad and so I want to be able to emulate those with my circuit playground express and one of the reasons I want to be able to do that is I would like to be able to control for reasons of it just being fun and funny I want to control this game Cuphead using some cups and straws so using capacitive touch we have seven capacitive touch pads available on the circle playground express that we can use to connect to things that we can then use our own capacitance as a capacitive antenna to determine when we've pressed a button or not so that's the idea let me pop open my discord on my phone here just so I can see if anyone's got thoughts or comments or my audio goes out that's always the big fear but I hope that long answer satisfies your question there who would ask that in in the chat yeah Adam Cadillac says jealous quarter three for mine I don't know how I got so lucky I mean I think a lot of us ordered these on the day that they were released and then somehow mine came pretty quickly so I'm excited about that and I've I've been playing Firewalk on it which I'd never played loving that I'm about to start Elden Ring so that's gonna be my my big hobby is Elden Ring on this this little steam deck okay so looks like we're good looks like audio is working over there so let's give this a go what I'm gonna do is plug in my little dongle there interestingly I found the circuit playground express with a USB C to USB micro B cable works directly plugged in some normal mechanical keyboards that I was plugging in not handmade ones like commercially made ones were only working through this hub for some reason and I'm not quite sure why but interestingly this this circuit playground express worked straight straight into the device the only reason I'm using this hub right now is so that I can keep it charging as well I could also do the HDMI output if there was a reason to so let's see with let's let's reset the circuit playground express some of those things came unplugged but let's see will it I don't know if I have anything hooked up right now that'll tell it to start so let's okay that one is so this I just touched the straw this is essentially acting as my a key so again this was the cool thing about gamepad versus keyboard gamepad a is pretty powerful and the the receiving device is usually set up to know since the game control only has a limited number of buttons that a button is often what people are hitting when they want to just progress and keyboard a wasn't doing that same thing so again you can see here I'm able to touch this metal straw that's connected up to one of the capacitive pads on my circle playground express again start pick a player pick this guy and this is highly incomplete right now so actually I may I think I'll have to use to player to even start because I don't have d-pad stuff working yet just up and down so I'm having my second player use these controls at the moment just for this demo I'll work that out but just to demonstrate it you can see a is jump and that's gonna work just by touching this straw the start button or that's b button actually I think yeah the b button in this control setup is what pops us back out so you can see that player sees and be oh no maybe it is the start whatever button that is we'll look at it in my code in a second and then if I want to shoot I've got I just have this alligator clip right now going to analog for touch input for on the circle playground express now this may require recalibration I'm gonna you can see I've just connected that clip to a metal espresso steaming mug and I'll reset the board and when the circle playground express restarts it should do a calibration it has I believe it has some auto calibration code built in and now it's it doesn't think that that button's being pressed permanently so I can I can shoot just by just by touching it there can jump and shoot and we can go back other controls on here let's see we can okay that's dash and I don't want to dash too much it's gonna dash forward and die if I touch the a6 that's down and a7 that's up versus jump up let's put that back on the shoot there and we should be able to you know point upward and shoot or point downward and shoot it's kind of a crouch okay so that's the basic demo it's gonna be terrible to play the game with this right now and and to be honest it'll always be terrible because real controls are way better than this but I think it's fun and interesting to try it out could be useful for some things for you know one example of course is for assistive technology for people who aren't able to use the default types of controllers you can set up alternate controls even if some are on a controller with one hand and others are on a foot or body part mechanical stuff capacitive touch for people who have limited strength in their fingers for example using touchpad things can be really nice so there are some practical reasons for this but what I thought we'd do now is jump out hit any cup to continue that's right I love that so thanks for me guys a great idea for controllers this I was showing Cuphead on this to the more yesterday and I said I wanted to do something with circuit Python in this and she said how about make a alternate controller where you're touching cups I give credit to the more it's a fun idea so what I'll do is unplug this controller here and let's bring it over to my workstation and we'll take a look at the code that I have running on here now let's get a this will be a good view for this and I'm gonna plug plug this one in in case we want to try changing out excuse me the code on it open up that code on the circuit Python drive now that's not it oh it's this problem again where I have cached I don't think Adam used to do this but it's now started to cash the thing until I close it out so let's actually also open up the supporting files that are necessary so this is all really new to me I had never done the game pad HID stuff before let me show you the guide and example code that Dan Halbert and others have created that make a lot of this possible yeah sorry someone asked over in the YouTube chat the console what's it called it's called the steam deck not to be confused stream deck that's another thing for changing camera buttons and your Google searches will often show you both the let's go over to the learn guides real quick and HID game pad I think okay so I'll bring up in here you can see zoom out this is big this guide called customizing USB devices in circuit Python is really helpful because it has info about setting up your controller type to show up as different USB descriptors to a device I believe what I found with this is that I needed to have it only show up as a game pad otherwise it can confuse the console so typically when we set up USB HID on one of the circuit Python devices they will show up as a series of devices if you look in your in your device manager you'll see things like the USB HID keyboard USB HID mouse USB MIDI device and then also game pad it's also USB storage device and maybe some others so this guide yeah mass storage this guide talks about that and talks about how you can hide devices so I want it to only show up as some things and that's done using this boot.py file also this goes into some of the specifics of your setup for having it show up as different things on boot and how to configure it for the different uses so the one I'm using I think is in here under custom HID devices so game pad is a little out there this it's not as standardized as a keyboard this tends to be it can really vary depending on the type of game pad you want to emulate so you'll have a descriptor that matches something like a PlayStation 4 controller or an Xbox 360 controller or whatever you have so this example that I'm using was based on one that Dan posted that uses this boot.py file and we also use a if you look back at my code here an HID descriptor I think is is the right might be the right term for this is also game no game device game pad device and I'll have to remember now thankfully also a lot of solidify all this always thinking as I work on this and put together a guide on it but there are if we look in the main code here we're setting up a game pad USB HID device and we're importing this HID game pad here so this whole file gets imported to I think to essentially say here's the types of usages the usage page and usage with the words I was looking for as well as the device descriptor and based on that we're sending bytes that are kind of expected by by the device on the other end that fall into button maps analog values for joysticks and other things so what I found just some of these are standardish some of these were just through trial and error I set up this control map here of either button types or joystick types and I'll talk in a second about why I did that but this first group here these are six one two three four five these are five my first five touch pads send a game pad button press of and a release of these values so a one sends a game pad a and let me grab that controller there so you kind of have a physical name so it's pretty typical that there's something called button a and what that does in the game will vary and so I as I was notating this in Cuphead that was jump so I saw jump happen I knew based on button mapping that was a the eight locks the character in place so that they can stand and shoot without running the 12 is the and that's the right right button here so the game pad descriptor I think allows for 16 buttons is kind of the first chunk of options in there so I don't know if you can even go past 16 you probably can with it with your descriptor being customized then let's see the start button here which is used for starting the game from from the beginning is what I'm using to pause the game the shoot is X and the dashes why and those are four and five now there's a way to use what's called D pad or hat and that's your digital pad that's really four buttons under there but that is not in the in the USB descriptor that Dan set up for that example and he and I may work on getting that emulated as well but in actually Dan Halbert's great great idea as well okay the example file does have a provision for the analog joystick actually one or two of them and so that's a set of two potentiometers that send a I'm not sure what they're they might be zero to sixty three thousand ish but what they want to send is a zero in the middle a negative 127 to the left and a positive 127 to the right for X and likewise for up and down and he said well for now what you could do is have some of your touch inputs or physical buttons just send a full 127 or negative 127 or zero and that'll be the same as the D pad which is which is a binary digital thing you could use cap sense maybe to sort of emulate analog stuff but it would be kind of annoying so in my case I this is the kind of game I don't want to have analog I don't want to play it with with the D pad so what I've done is in this little sort of dictionary of setup if the one two three four five six seventh one is is pressed six than seven ones are pressed the first element here is a one and that says okay we're no longer doing just the button press release we're now going to do joystick and we're going to find those as zero on X 127 on Y or negative 127 so that was my down and up or up and down and then this would be for side to side but I don't have enough touch touch pads like I said so I need to reconfigure things and decide how I'm how I'm moving and which which things I need on there in which I don't also have two physical buttons and a slide switch on the circuit playground express so it may be possible to add some stuff that isn't really used during gameplay but just for navigating the menu system this I'm not using right now that was just for as I started working on this you can see here I was originally trying this with the HID key codes but those didn't work out then I'm setting up my touch pins so there's one through six and TX the threshold adjust this is for cap sense and like I said I believe it does calibration on start so I'll dive into that a little more with the different controls that I'm trying to touch as I build this out and then here's the key stuff for game pad in my main loop what I do is I'm only checking those seven touch pads right now so I loop through all of those for I in the range of the length touches touch is the current iterative number so zero through six we do an update we check has that one been touched if it rose that is as if we pressed it just because of the pull-up pull-down so if we've pressed one of those then here's how I'm checking to see is this one of the buttons or is this one of the joysticks I say in this control map sort of dictionary up here is the first element of zero or one if it's a zero it's a button so that's that's this check here if the current element has a zero in that position then we've pressed a button and so I grab whatever that control map is the item one and that item one is going to be whichever button button one button eight button 15 whichever it is when I have a one in that first slot that means we're doing the joystick thing and then I'm sending this command game pad dot move joysticks now this one is expecting both x and y since it's a digital pad and I'm being simplistic about it and not doing diagonals then I'm sending either a zero and a value or a value and a zero but I'm never mixing them and I could probably make the code a little little more forgiving of sort of diagonal moves which you'd want ultimately in the game and then we do the release when we release one of the buttons game pad dot release buttons for whichever one we had touched and for the release of the joystick buttons I'm just sending zero zero which means you're not moving it's always relative and so that's the sort of rough working version of this that I just got working this morning because I really thought it was going to be so much more straightforward by using keyboard but because like I said because of some reasons that didn't work out I got to dive into this and so I'm really excited about because this is a really useful specific type of USB HID which is game pad and so let me know in the comments if people have done any stuff with game pad if you have any suggestions or places to check out more info on that especially if you've done it inside of the inside of circuit Python that would be great to see what you've done with it you can find the USB HID descriptors online if you look look for them for various controllers and that's also a step towards emulating the specific behavior of a particular controller let's see other questions that we have in the chats back out here for a second someone asked is that it is an expensive console it's you know it's it's about $400 US for this entry level one they have a couple of different levels of them that the next level up I think doubles the storage space it has a little solid-state storage in it this one has 64 gigs but it also has a SD card so you can you can play the games effectively off of the SD card people have been reporting good good success from that and then they have a third tier one the most expensive one has double that I think it's 512 gigs and it also has I think a nicer screen I'm not sure if it's just the glass or if it's the OLED itself but yeah you know for for me I don't have a gaming PC and so spending $400 for what can act as a pretty decent gaming machine if you want to plug keyboard mouse and and monitor into it over HDMI it's not bad and then it has the benefit of also being portable the other thing actually that I want to that I want to try is let me see if I can show this on the overhead I'm just gonna adjust some settings here including focus is this is running a Arch Linux desktop on it and so what's loaded here is their steams UI I think it's called steam UI if you hold the power button you can switch to desktop again why won't let me tap it there we go switching to desktop in this mode I was able to plug in my circuit python device and mount it and open up the code dot pi so you can imagine where that's going we should be able to use this to code in circuit python since we don't need an IDE all we need is a notepad it has Vim installed and I imagine you can install other other editors into it it probably has an edit in it is my guess I would need to either use the virtual keyboard which I can't I don't even know how to bring that up in this environment right now like I say I got this like a day ago or plug in a plug in a keyboard and then we can use a hub so that we can plug in a keyboard plug in the circuit python device and then go and code it which would be really cool to code it right on the device and then pop back over to the game and use it you might need to do a reset of the circuit python device so very exciting there's also some you can get Windows drivers and install Windows 10 I think on here I'm not going to do that I think most people who've done that have said this was not worth the effort oh my my it's not connected to my network I'm a little far from from the Wi-Fi for this to work right now so pretty cool and then I think you could switch back to you can you can log out of the Linux desktop and that brings you back I believe over to the the main game UI the steam steam UI and so these you know I'm not I'm not trying to advertise this thing in particular than I'm excited about it and I think there's a pretty decent waiting list but you can buy them you can you can go to steam and and order them and then wait quite a while for them to to get back in stock I don't know what they're what they're supply chain issues if any that they're having are but people are getting them you know they're coming out they've been they've been getting into people's hands for a few weeks so can't wait for Narita boy that I've been playing that on on the Mac but I'd love to play it on here I don't know if it works on here there's stuff that has been certified to work on it and then there's stuff that they say maybe and then the stuff they say no it's definitely not gonna work so that's one I've got to try as well so anyway that's that's enough with that but I'm really excited to dive into game pad so it'll be it'll be fun any other thoughts otherwise we're gonna get out of here and and thank you again for stopping by I think that's it right that's all I got today thanks everyone for jumping in thanks for hopping into the chat nice to see you all and that is gonna do it for this St. Patrick's Day edition 2022 of John Park's workshop stop by tomorrow for a deep dive with foamy guy is that right foamy guy I think you're gonna be there if we head over to the discord you can probably ask foamy guy you can typically do a show times to see what time the shows are foamy guys circuit python stream is at 11 Eastern on Saturdays okay and then deep dive with foamy guy which is taking place of scott's is 5 o'clock on Friday so there's a huge amount of foamy guy you do in both of those that would be awesome you can also check by the way in our live broadcast announce channel and that'll show you when when streams actually go live spider best intentions of keeping that schedule that one is not real-time 2 o'clock Pacific tomorrow deep dive with foamy guy excellent I think that's gonna do it thanks everyone I'm gonna get out of here and go play some Cuphead bye