 Hello and welcome to the show. It's me, John Park, and we are here for John Park's workshop. That's what's going on right here. Thanks everyone for stopping by. And when I say everyone, I'm talking about the people over in our YouTube and in our Discord. Of course, we're thankful if you're watching somewhere else and hope you're enjoying it. But if you're wondering where the discussion is going on, that's a good place to check out. You can go to Adafruit.it slash Discord and you'll get an immediate instant invite in to our server. And then you can head over to the live broadcast chat channel. That's where the discussions are going on. And hello over there in YouTube chat land as well. I can't check the other ones. So if you're on Twitch or something, I'm wondering where are people? Over here on Discord. So let's see what else have we got going on. We have a job board I should mention and that is over at Jobs.Adafruit.com. You can check that out if you're looking for work or if you're looking to post your resume. If you're looking to hire someone, there are a bunch of interesting positions available here. Some of them full time, some of them part time, some of them remote, some of them onsite, a whole array of things. Lead hacker, firmware engineer, director of the Schup family idea lab, Arduino code composite, manufacturing assistant, lots and lots of good stuff there. Over on Jobs.Adafruit.com and all of it is vetted by PT and LeMore so probably no scams in there, at least we hope. So go check that out. Over on Jobs.Adafruit.com. Other things that are happening in the world of making stuff. The Tuesday show I do is JP's product pick of the week and that's a great show to check out if you want to see some demos of a new product pick and get a discount on it when it's available and I'm again gonna apologize. This one sold out super quickly so I know not too many people got them but we know that you understand with all these global supply parts, shortages and things it's not always possible to have as many of them as we would like. This week it was this one the MCP 2317 or 23017 I should say which is a 16 port IO expander and the show is usually in 15 minutes long but I like to make a little excerpt that's just a minute so you can see what was going on and check out the demo and here it is. There it is my very own MCP 23017 breakout board. This is a 16 IO expander so you can do inputs and outputs. You can add up to 16 switches or buttons to your project. You can add up to 16 outputs such as LEDs, has the stem of QT port. Simply plug that in and all of a sudden this little board that doesn't have that much IO built onto it grabs an extra 16 ports. You can see it underneath this board here there's the MCP 23017 with eight wires running to LEDs and resistors on the top row there and eight wires running to these switches here. It's the MCP 23017 16 IO expander. Yes it is and let's see what else is going on. There's a little section here I like to do called the circuit python parsec and you know what that's coming right up so let's get ready for it. Okay well I gotta pause the little video feedback on the side there because that's distracting. It's a five second later echo of me going on over there. Okay this looks like it's ready to go yeah I think it is. Okay for the circuit python parsec today I want to show some more display IO stuff. This time it's going to be positioning so when you create shapes inside of display IO a lot of their settings are fixed at creation time but one thing that you can definitely do is change the position of an object so here you can see I've got this little pill shape this is actually a round rectangle and I've set it up on this OLED feather wing so that I can use the A and C buttons to slide this left and right move that around kind of like a little paddle in arcanoid or breakout and I can also hit the B button to reset it and that just kind of centers it back back there on the screen. This is actually pretty smooth in person I know in video it's got a little bit of a lag but what I want to do is show you how you can do this in code so first of all we're going to import some libraries including the display IO library and in this case the display shapes round rectangle as well as the driver for this display then I set up the display and I create this object right here the round rect is a round rect and I position it at zero and a particular height as well as a width and height of the object I'm using some I'm driving those from the display itself so this is somewhat portable code and then I'm setting this to have a radius of eight around those corners I fill it black and put a little white outline on it with a stroke of one then as I in the main loop of the program adjust buttons we're simply changing the position so I have a variable called x pause and I'm either subtracting from it or adding to it and then I'm updating the object with this line right here round rect dot x equals x pause so as that x position changes so does the position of the round rectangle the middle button here sets this to be one particular position which is sort of the center of the screen and then the button on the right adds to it and so that's a really simple way to use the x positioning on an object inside of display IO to move things around and that is your circuit python parsec and thank you I was just checking in the chat and people said it was looking pretty smooth on video one thing I noticed actually is my broadcast software when it doesn't have focus but I still am seeing it as I'm over there in atom changing stuff it starts to glitch a little bit but it's uh I'm glad to hear it's it's smoothly smoothly streaming so that's nice um the other question was about positioning and yeah the uh the convention here with display IO is the top left corner is position zero zero bring this back up here uh so this upper left corner would be zero zero and in fact let's let's take a look at adjusting some of this code a little bit because that's that's kind of a nice thing to see uh so right now in the creation of initially I have it at zero on x and then the height is uh sort of halfway down if I set that height to zero as well and update that you'll see now it's appearing in the upper left corner sorry about the glare there uh if I get rid of the radius on this I don't know if I can do radius of zero I should be able to uh it'll be a little more obvious that that corner upper left corner of the shape is in the upper left corner of the display there um and then yeah everything else is is derived from that so the uh width of this one is a zero to 127 we can actually go off the edges of the screen it doesn't constrain you you could you could write code that does that but now I'm I'm still traveling I'm over here by my by my other monitor by this point and I go hey there we are we're back and keep sliding back over left and uh as you can imagine you could do multiple buttons this is probably not fast enough to play a super fast video game but uh who knows if actually a foamy guy is watching uh he's he's a master of display i o so if you've got thoughts or tips and tricks oh he is here in fact I see him typing look this is fun we've got a tim sighting um and let's see paul cutler says yeah perfect timing for positioning I need to learn this for a project well good there are a bunch of great resources um in learn system if I pop over here you will see this is a guide called ui quick start by carter and this has a page uh or rather the guide is circuit python display support using display i o this page is the ui quick start is a good place to to go and get some information as well as look into some of the helper libraries and this this talks about some of those positioning things um uh foamy guy noted is worth worth noting that the circle is uh anchor at its center point but I think most of or if not all the other shapes are are at their sort of upper left corner I don't know about triangle I don't know where triangle is is found maybe it's the the center of the object who knows um so yeah so that's some some cool display i o stuff I might keep doing this let me know if you have any requests in this I'd like to sort of do a little series here doing display i o and this OLED is is kind of a nice thing to do it with because you can just plonk that right on top of a feather or use the little feather doublers and you have a nice display there's a lot of other great things like the clue or the pie portals or the pie gamer pie badge so a lot of uh a lot of products that have some i o built into them some buttons and things like that as well as a screen which is really fun for getting started with your graphic programming uh and let's see I think that covers it for that that circuit python parsec extended edition uh oh and c grover mentions vector i o is a bit faster for solid shapes there's no outline yet uh good no yes uh c grover's another one who's done some really great stuff with ui work uh and display i o work so thank you all right uh so let's get to a couple i've got kind of a couple things going on with this week's project so first of all uh if you recall the last couple weeks i've been working on my telephone project and one of the cool things about that project playing back sound files was using the audio mixer inside of circuit python to be able to adjust levels and uh one of the nice things about that is not only adjusting levels to sort of fade things in and out or balance things but almost using it as a mute switch so that you can play a whole bunch of things and then just mute or unmute them as you need them one of the reasons this is really cool is it's actually a bit difficult to precisely sync up multiple samples or multiple wave files unless you start them all playing at the same time and then they're always in sync and then we can use muting and unmuting or the levels functions to bring those in and out and so that's uh one half of sort of one half of the things i'm going to be doing today this is all based on some excellent stuff that todd bought todd curt has been posting on his social media as well as his tips and tips tips and tricks page on github and i'll point you there later over on uh on discord i'll call it up on here so you can see it all right and so there was one project that todd was working on that was calling up samples and some of those samples were looping using some break beats particularly the amen break and so uh lemore asked me hey why don't you do something with that why don't you do a project with that so i'm going to start off at least my prototypes i found really easy to do using the neo trellis m4 and that's for a couple of reasons one we've got buttons two we've got leds under those buttons and three we have audio output built right into it so there's uh and it's a m4 chip so this actually a couple of analog outs i'm using just the analog zero out i think this is mono that i'm doing and uh this has the circuitry on it to do a little bit of noise filtering so it's an easy one to just plug into what i may do did i bring those in here no i didn't what i may do is actually also develop this on the macro pad or even do a sort of custom project using some of our little snap apart uh key switch pcb's and lighted pc uh lighted key switches and and uh and glow through keycaps so there's some places to go with this but i think this is a really good platform for developing this and one thing i want to start off with is just a little bit of an explanation of what's what's going on with break beats uh if you've heard that term or if you haven't uh there were drum breaks in some funk songs in particular in the 60s this one was by the band called the winstons called amen brother and there was this break uh that was just a really cool little drum fill uh sort of sort of not even a solo really it's it's more of a a fill or a bridge with the drums and uh that's been sampled sort of tens of thousands of times at this point inside of music of all kinds and it's a really familiar one i don't think i can play it on here on its own without risking copy strikes but you'll at least hear my sampled versions of it playing on here but i'm not going to just call up youtube for that um Gregory Coleman by the way is the is the drummer who created this this fill or this break and one thing that people like to do is take that that sample and cut it up into little pieces and either rearrange them or mute and unmute them and fill other things in so uh both of the kind of prototypes that i've got going here make use of that and some other sort of synced 160 bpm loops that'll that'll work alongside of it so i think the second one i'll show will be running for loops that all are in sync together on four sort of tracks and then using these buttons to change the levels to mute and unmute just some sections of that so that'll be one the other one i'll do actually i'll start with this one i gotta change the code on the board here to do this is a just a sample player uh because i think this is a simpler starting point but with a couple little fancy tricks on it so first thing i'm gonna do is fire this up and let me uh switch to an overhead camera oops not that one not that one that one all right and let me pull out here a little bit and we'll take a look at code in a minute but let me just start off with uh getting this going for for a bit of a example so i'm gonna actually i'll go to this view why not i'm gonna pull up different set of code on here this will be the that one yeah that one looks good okay so let me save this to the board as code dot pi what i'm doing here by the way um you can't see my finder window coming up but i'm since i'm working with two related pieces of code here i have them same saved both to this circuit pi drive and uh with unique names and then i'll open one and resave it as code dot pi to to show that or to work on that and and then kind of store them here i'm also storing it on a different disc since it's good to have some backups uh but i'm saving the code i just opened as code dot pi replacing the existing code dot pi so you'll see this is going to change here and and this one i'm using in kind of a vertical orientation and let's zoom out just a little bit there focus and let me plug an audio cable into there okay so i'm going to turn up uh okay so you should be able to hear that let me know uh i'll keep an eye on the chat let me know if any of those levels need to change if you can't hear me or if you can't hear the the drums and things so what you'll see i've got here in this sort of prototype this one is um um essentially just a one-shot player so i've got some of these 909 samples we can play multiple notes at the same time and these are just playing these are uh i'm not doing any of the level stuff so in this this example here i'm just playing or not playing and i start them from scratch and that's all the ones i have in here so i've got a couple empty slots uh the second column here is the break beats so this first one is going to be the amen break and you can hear it loops uh and now i've got variations on it now these ones unlike these one shots these are actually all playing all the time and my button presses are just simply changing their level so it's muting or unmuting them and the reason that's cool is that all of them are in sync all the time so if i hold one of these down and then bring up another one or switch between them it should sound like we're we're not creating a sort of train wreck of of mismatched rhythms so those are all in sync because they are exactly the same length they're beat matched to begin with and then they're just always running uh these one shots can be added to that but that's that's on you right that's that's on you to actually hit them at the right time it requires rhythm so that's the the use of these two uh let me turn that volume down for a second that's the use of these two different types so kind of a one shot versus a loop and using the play function in audio mixer or the uh the muting so let's let's take a look at how that works inside a code here you can see on this one i'm bringing in uh some sort of typical expected stuff time uh i don't think i'm using the random function that's just left over from the code i started from trellis m4 which gives us a bunch of convenience stuff for the buttons and the leds uh it's similar in a lot of ways to keypad which is why you can transfer this code fairly easily to something like the macro pad or anything that can use the keypad as a as a way of reading a large group of buttons uh some lighting stuff neopixel supervisor for some timing stuff and then the key here i'm importing audio core audio i o which is going to allow me to go audio out uh on the on the DAC pin and audio mixer i'm setting up some key maps here of each of these coordinate positions and that allows me to correlate a series of wave files uh with which buttons being pressed as well as doing some lighting stuff uh then we do a little light show at the beginning when it starts up uh some timing stuff and then here's the wave file so you can see right now this is set up as these four columns of eight samples each so there's that i can turn this back up the kick clap snare symbol closed hat open hat and then these two blank spaces are none and none and then what you'll see after them here is a uh a second uh piece of information which is are we gonna loop that or are we not gonna loop that so these ones are one shots they're gonna play when you press them and that's it they don't try to loop which is probably good because they're not particularly beat matched to loop inside of this 160 bpm that i'm using with all those other loop samples you could do that but in this case it's not really necessary these are just gonna play when you hit them and and that's it uh if we did do that let's let's take one that'll that'll loop probably pretty well let's take the snare and i'm gonna set that to true hit save so that's the third uh sample so it's gonna be the third button down so you can hear it's looping but there's also a little bit of a empty tail a little blank space at the end there so it's there's probably zero chance that's matched to this you can hear just kind of all over the place falling out of sync with that so that's how these are being designated as one shots versus this second column here as well as the first button on the third column those are playing wave files just the same except these are set to loop true which means once they're once they hit play they just play forever and then i have a bunch of empty spaces that could be filled in with other samples here then i'm doing a little bit of a color fill setting up the audio mixer and this is set to have the number of voices because the audio mixer you can just think of it as like a big mixing console it has however many voices in it as you designate i don't know what the upper limits are this is going to be a memory constraint at some point but right now we have you know almost 16 voices going on in here because of the the number of samples that are that are in here i'm presuming we could go all the way to 64 on this which is which is our number of buttons right is that right or is that 32 32 so then once the mixer object is started it's playing and it's ready to play any of those that have a wave start and have their sample volume level go up and then there are these two functions here that are used for handling the different types of samples that we can play so for the one shots i have this function handle sample and then which sample number and if it's been pressed then the voice is whichever voice number correlates to that so we set that that we tell the audio mixer that we're using that voice let's say voice three right now to play this if it's pressed the wave file is opened and then it loops if it's set to loop if not it it is going to stop when you release so that's the one shots and by the way some of this i said this is prototype code stuff i'm working on this morning and chatting with taut about and sort of wrestling his code into into slightly esoteric uses he didn't intend initially so there's some stuff in here that's not necessary since these these ones actually right now i'm setting to use the handle sample only on ones that don't loop all right then what i'm doing is opening and playing all of the ones that do loop so these are eight through seventeen these buttons here those i just open them all up and i set them playing and i set their level to zero if we set this to one to begin with uh we should hear a lot of noise when this starts up let's see so they're all playing right now we can stop them in this case by by hitting all the buttons but we don't want that we want that to start at zero and then here's how i am unmuting them so that's with this handle mixer and i have the number of whichever voice if it's pressed the level goes to one if it's released the level goes to zero it's very simple again there's some leftover stuff i don't need to arguments going into this function here that's just leftover cruft uh then there's some timing stuff set up with millies and the supervisor ticks in milliseconds the scaling of the volume allows us to work in integers so that we don't give it uh sort of decimal float numbers uh we fill the pixels up with this blue color once it's sort of ready to ready to go and then we hit the main loop of the program here we watch for pressed keys so this is a trellis function similar to event get event inside of keypad and this creates a set kind of a list of which keys are pressed so it so it knows all the pressed ones and it can do things with those again that's kind of a convenience function of how the trellis works trellis library works for those that are pressed we're going to set the color i'm not doing anything fancy i'm just picking a this sort of magenta color here uh then when they when they are pressed we take the pressed keys and check which um sample number they are so we know which which um which one to pull up as well as which key to light up uh if the sample number is less than eight we use this handle sample so that's all these one shots here if it's greater than eight that's the rest of these and we use the handle mixer which brings the volume back up uh and then when it's released we kind of do the opposite we change the color back and we mute the the sample or stop playing the the one shot again that's only necessary if they're looping which they're not right now so that was the the kind of first version of it and then uh let me see if there's any questions in here uh no we're good okay cool so let's now um let's jump over actually to to the bench over here i gotta set up a little audio thing but i want to show um on a pretty advanced piece of gear what this sort of sample chopping can do and then we'll do our uh sort of simplified version of that on our trellis with the other code that i've got let me switch this camera here that's the one i meant okay so i need to grab a powered speaker for this let's try this little red radio see if this one will work this one has kind of a noisy audio connection but we'll see if i can get that working that there and before i forget let me um bring up my discord on the phone so i can see if anyone's telling me i've done something weird so here we are and there's the library all right uh so we'll keep an eye on that okay let's grab an audio cable wow i don't have many audio cables over here are you one nope that's a funny one let's uh steal one from over here all right let's see how that does okay so you should be able to hear that uh so this is the uh you've seen me bring this out before i love this gizmo this is sort of a desktop sampling workstation it's called the black box from 1010 music and it is uh among other things really good at dealing with sample slicing so if we take a look um let's use well let's use the the amon break here for uh to sort of keep apples to apples so if we look at a cell here on this i can load a sample so this is pretty similar to how the trial this works we're loading up a wave file uh so i will go into my big folder of break beats and see the winstons amen brother load that okay so there's the file actually here hopefully we get away with playing this this is uh leading up into and out of the break so you can hear what it started life as nope we can't why is that not playing did this lose power i think this battery died there we go okay all right stop that there uh so now if you look at uh this as a series of slices we can go in and let's say remember how to slice it on a grid or scan it let's scan it this won't be perfect but what this is going to do is it's going to try to find the sort of transience where it gets loud and quiet and and slice those into little individual sections if i so this is just one little slice of that okay so you get the idea uh and on here we can even take that set of slices and play them individually um okay and so what that allows you to do is either rearrange those to place different sounds in the original spaces um or do this sort of muting and and playing thing that uh that we're going to look at if if you look at one other example on here just because i already made something with one of these uh there's a there's a james brown so that's uh in a funky now but i'm really messing around with with the timing of things uh so so what we'll do with the trellis is somewhat similar to this and this was uh another excellent todd curt idea uh which is to take these samples have them all playing and then be able to mute them and unmute them so what i'll do is open up this other bit of code here uh which is the beat slicer and i'm going to resave that to the trellis as code dot pi replace yes uh this one is horizontally oriented here so we'll flip our cables around c grover for the sharp eye you may notice a little white dot on that cable so what's happening now on this one is we've got four samples that i've loaded in they're all playing and then they're actually 16 steps long so this is kind of a loop but we can use eight buttons wide just because the how the hardware is laid out we use eight buttons to decide if step uh the first step or the first step of the the second section are going to be muted or unmuted so let's start with that amen break so you can hear now it's just skipping every other because it's muting it out now let's see what we have on another track this is like a drum and bass loop okay very different feel but beat matched and so now what you can do is start to mix and match and then i also took uh sometimes it's fun to add a vocal into there that doesn't necessarily have to uh fit rhythmically or musically you can kind of ride along in a different tempo so here i've got a vocal you'll recognize if you watched the live stream last night ask an engineer uh let's let's bring in some uh rhythm to accompany it first all right so this is a little clip of uh the retro tech section from the show last night with phil and amore got a cool uh cool sounding sample from from them uh so let's take a look at this one how this is working we've got uh you can see the code here uh we're bringing in simple stuff time board audio core audio mixer audio aio to send out over pin a zero there and then the trellis m4 do a little bit sleep at the beginning to let us be settled down especially when you're doing audio stuff sometimes it can it can make noise at you so uh it's good to put a little sleep at the beginning there when it starts up then i'm picking my uh wave files that i'm using and i also actually had a different one in here um if i resave this you'll hear here's a kind of a cool it'd be nice if i had a special uh vulcan grip like all four corners to mute them all uh so that's the list there loop files is the list of wave files that are just sitting on the disk and they're pretty small they're they're 22k 16 bit uh mono files and you could probably make them even smaller if you needed to uh then we have the number of loops that there are which is the length of that loop files there so it's four and then the number of slices is how many of these mute slices that we have going horizontally with the buttons beats per minute here is 160 and that's derived from the samples so we're really starting from some samples you can use audio uh processing software to adjust that to get it to where you want but then we're not stretching that stuff in real time we're just reading it off the disk really fast which is which is what makes this all possible and so we want our little mute steps to go along in time with that uh then we set up the trellis and i'm setting brightness pretty low just so you can see it on the on the screen here the audio i o is set to go out on pin a zero mixer is set up again with uh in this case four voices so voice counts equal to the number of loops audio mixer uh is attached to audio playback the drum loops all start essentially at the same exact time here so for i in range number of loops we open each wave we set it to its respective voice and then we set it's it's uh level at zero so they're playing but volume is down um do some uh stuff with millies uh so that we can clock our little mute steps there and and run that little light across there and then the main loop here we're again checking for uh this creating this set of keys that are pressed so it keeps in mind which ones are pressed uh when i press one i am checking the x y coordinate so this in this case with this orientation this is button zero zero zero one no zero zero is it x y i think it is one zero two zero three zero four zero and so on uh row one row two row three so zero one two and three uh of rows and seven zero three seven for columns uh so with those in uh in mind we know exactly which uh sample we're dealing with which voice because it's the uh second number there the y and which mute segment we're on because it's the x we check if something is playing there then for each of those beats we uh move along and set the volume to either be fully up or have it to point eight or fully down depending on if one of those buttons are pressed so so we can run through and check each of those x buttons as we as we move along in time um let's see what else i was just distracted Todd said by the way all of these samples except for amen break are from freesound.org yeah and i don't know if anyone's getting in trouble at this point for using amen break it's a complicated uh it's a complicated situation as far as uh the Winston's never getting royalties for the tens of thousands of times it's been used but sorry guys uh then let's see for each of those uh we go through and set the lit color or the pressed color or the unlit color rather uh and then the beat marker sets it to this so if we want to change colors here actually i did this on one one version of mine um we can do let's say a blue color and this way you have it's kind of nice so you know when it starts up that it's uh that it's actually started up oh now i've done it sometimes this will this will need a reset i was pushing it i should have just let it play so oh now i've yeah i've i've angered it again let me hit reset on here i broke the reset button on this one so it's it's just the little copper nub now so i don't like to press that one too much there we go um that's kind of a whiplash to go to that little slower sample there or that mellower sample um and so let's see yeah that about covers uh these two sort of prototypes let me know what you think in the comments uh or over on the discord chat i am gonna refine these a bit and then think about either uh let me know what you think about hardware if you if you'd like to just see this on this it's it's kind of perfect this there's nothing to build it's a software uh pretty much a software only project which i like and we have these we have these in stock you can get the kit um in fact let's let's jump over to that i'll show you what what i'm running here if you're not familiar with it this was uh in an adabox a couple years ago now so i know a lot of people got them uh let's go to fruit and this one is called the neo trellis m4 uh there's a bare one or the kit which you probably want uh which includes the uh elastomer buttons and the acrylic case and the screws you need um i left some laser cut paper brown paper on there so it doesn't usually look like that usually see the black through um so these yeah it's uh we have some of these in stock and they're 60 bucks there's a lot of projects for these in our in our learn system but i thought this would be a cool one to do because it's um beyond just a sound board which is very cool this one is more of a um sort of sequencer sample sample playback thing and it uses audio mixer which is very cool how well that that works for us uh yeah let me know what you think otherwise options are kind of any of our keyboard types of things macro pad our standalone uh what are they called the let's let's go to keyboards we have a category now if you go into oh no that's under raspberry let's go to macro pad i think that's in that category mechanical keyboards so if you head here um i think under development boards we'll probably see this one here this five by six snap apart so you can kind of rearrange that into anything this one might be a cool one to to rearrange into some 16 beat wide things uh but you know that's a whole whole different level of of uh fabricating your project and and it's kind of nice uh on this one but this would definitely work on macro pad as well uh and the main thing to add there is just a audio uh out via the stem of qt because the the macro pad kind of the only only output on the macro pad is that stem of qt cable on the side of it right there so you can take that over and instead of sending i squared c stuff over the sca or the serial data you could scl or serial data you could send uh pwm audio i think but this one works well so maybe we'll we'll keep this uh keep this as an m4 um yet todd mentions trellis m4 is also really good as a macro pad it is for sure um all right well i think that's going to do it thank you uh everyone for stopping by for this hope you enjoyed it hope you enjoyed getting your uh your fill of some break beats for the day and i will be uh hanging around in the discord for a little bit as i finish up documenting and writing the phone uh the the dial a song guide i've got a bunch of photos to to process and put into the guide there and uh so i'll be around so hit me up if you have any questions otherwise that's going to do it for another episode of jp's product pick of the week and uh i'll leave you with this bye