 and welcome to the show. It's me, JP, and it's time for another John Park's Workshop. Thanks for coming by, everyone. I am excited about the show today. I have some cool stuff to show, some fun things to play with, talk about. If you're joining us to chat, then please head on over to Discord. Adafruit's got a Discord. There's lots of people on it. Chatting all the time. You'll want to go to the live broadcast channel inside of the Adafruit Discord, which you can get to by going to adafruit.it You'll get an instant invite. And off you go. In fact, let's bring up the Discord right now. Look, that's what it looks like right there. Throw on these glasses. Hello. Good, we've got the YouTube up and running. And so nice to see you all. Hi, BlitzCity. Hey, Mr. Certainly, Cgrover, Fede2. Welcome, everyone. And let's see. Before I get caught up in things and forget, let's do a little bit of housekeeping. So first of all, I will mention, if you are interested in getting the next Adabox, we may still have some subscriptions available. I'm not sure what the status is on that. I know Phil was talking about that a bit yesterday. You can head to the adabox.com website. In fact, let's go there right now. I'm gonna bring up a little browser window there. And adabox.com will show you that we've got an Adabox getting ready to ship. It's gonna be in July. I know we had some questions about that yesterday. So yes, we will be doing a July Adabox. Should be a great one. We strive for them all to be great. So you can go there and subscribe, or you can also subscribe someone else. You can get it for someone as a gift, which makes a very lovely gift, I'd say. Let's see. I'm gonna check in also over on the YouTube chat. It looks like we're up and running. My window has gone funny on me. Let's see, can I see the chat? Maybe, maybe not. I will stop poking there or I might break something. And now I'm seeing the echo version of myself. I'll pause that or I'll get very distracted. Let's see. So what else is going on? You may know that I've got a show that I do on Tuesdays. That's it right there. It's called JP's Product Pick of the Week. It looks something like that. And this show is one of the only shows we know of that broadcasts from inside the product page. And during the broadcast, you can get a substantial discount on the product of the week. So I usually go for about 15, 20 minutes, do some demos, talk about the thing. And then I make a little recap video, which I'm gonna show you right now. It is the Slider Trinky. It can act as a MIDI device, a USB, HID keyboard, mouse. This is a little laptop of mine. And I have some DJ software running on here. This software I'm using is able to be configured to look at a MIDI input for moving that crossfader around. And what I can do is use the slider here to crossfade between, it is the Slider Trinky. It is a fader on a USB stick. And it has a couple of underlit NeoPixels as well as a capacitive touch button on it. And it runs circuit Python and Arduino on the Cortex M0 that is built right on there. Oh, hey, whoa. That's just gonna start all over again, wasn't it? The other thing I wanted to point out is not only do we have a discount during the livestream, but I believe we also, in the case of some products that have restrictions on how many you can buy, sometimes we lift those during the, or increase those, I should say, during the livestream. So I know that that Slider Trinky was in limited supply and I believe there was just a one item per customer in effect until the livestream. And then during that, we boosted that up to 10. So you could buy a bunch of them in case you had some big plans for using those. And let's see what else. I didn't mention our jobs board. If you are looking for work or you're looking to hire someone, you could find worse places to go to than this right here. This is the jobs site at jobs.aderfruit.com. And you'll see there's a bunch of posts here for people looking for someone to hire. Here's one at Headspin Incorporated in Toronto, Canada, looking to hire a full-time hardware engineer. If you click on that link, you can find out a whole bunch more about it. They're looking for someone to join a cross-functional hardware team focused on innovative electronics design and manufacturing in the mobile testing space. What more do you need to know? So if you're looking for work or you're looking to hire someone, head to jobs.aderfruit.com. It's entirely free to post your positions, to post your resume, to connect with people, to get work, to give out work, to receive money, to give money, all those things. That's what jobs.aderfruit.com is all about. Whew, I'm gonna get a drink of water. It's getting hot again. So let's see, what have we got next? I'm gonna just get us ready for our next segment, which is a favorite of mine. It's our new, I think this is the ninth edition of the Circuit Python Parsec. All right, so for the Circuit Python Parsec today, let me get this set up. I'm gonna hide one layer for now and shoot that over there, that worked. I just checked that monitor over there. So let's see if I can get this all set up. Yeah, that'll do it. Ooh, that's doing something funny, but we'll live with it. There we go. For the Circuit Python Parsec today, what I wanted to do was talk about the map range command inside of the simple math library. Sometimes you will receive an input or have numbers coming at you from somewhere that are in a certain range, let's say zero to 65,520, which is what an analog input will usually read using something like a potentiometer in this case. If I want to use those numbers in a different range, you can use this simple math library called map range, which allows you to take an input minimum and maximum and then set an output minimum and maximum and it does all the rest for you. So in this case, you can see down at the bottom, I have this potentiometer I'm turning and it goes from about zero to 65,520 and you can see on the right side there, I am remapping that to a range of zero to 127, which happens to be the range of a lot of your MIDI CC commands, but this could be for anything else. You could go from zero to 100, you could go from 0.0 to 1.0. This library will take care of it for you and you can see if you check out how I'm doing this in the code, the key thing is that I'm importing this simple math import map range and then I'm setting up an analog input. So on this Pico microcontroller, I'm reading an analog in here and then I am using this variable called remap value followed by, I want an integer, so I set int and then this is the map range here. Map range and then I'm reading a sensor and then I'm taking its minimum of zero, maximum of 65,520 and then I'm setting it to a new minimum and a new maximum. If we look at these variables here, those start out at zero and 127. Let's say I don't want to go all the way to zero. I want to just have a minimum of 32. If I hit save on that, you'll now see down at the bottom as I, let me try saving that again. Hold on, see if I'm really saving it where I think I'm saving it. Who knows where I saved that? Oh, I know where I saved that. I just screwed up a camera controller possibly. So now you can see after changing the new minimum to 32 when I turn this knob, it'll go down to 32 and still up to 127 and we can set those to anything we want. If you take a look at this image here, you can see my software there has a filter value in the middle that's now going from instead of zero, it's going from 32. If you see that little bump moving along there for this filter frequency notch, it goes not all the way to the bottom which you usually stop hearing things when the cutoff value goes down to zero. So if I don't want to be able to cut this off accidentally all the way, then I will use something like this. And let's see, I might be asking for trouble if I try to listen to that, let's see if it works. Hopefully that worked and didn't blow out your ear drums or echo too badly. And so that is a really useful technique inside of Circuit Python. And so that is how you can take a range of values and map them to a different range of values, all using the map range inside of simple math. And that is your Circuit Python Parsec. All right, well, thanks for that. That was a whole bunch of moving parts there. I wasn't quite so sure if it was gonna work. I had some audio software giving me problems this morning. So we'll see, I have some other stuff we're gonna use later or we'll fall back on this one. This one, by the way, I'll jump back to, how about this view here. This is some open source and free or you can pay money to contribute. Of course, software called Helm, H-E-L-M. You can go and look that up and it's available on a bunch of different platforms. I think you can get it on iOS now as well as Mac, Windows, Linux. Pretty sure it's available on all of those. So that's a nice one because it has a lot of the fundamentals of sort of a subtractive synthesis right inside of there as well as arpeggiators, sequencer, modulations that are semi automated very cool. Let's see, yeah, over in the chat, we have a couple of people giving the thumbs up to map range. It's really helpful. Liz, map range is the best. See Grover says map range is great for reversing the output range too. Oh yeah, that's a really good point. You can set your minimum let's say to 127 and your maximum to zero and now it'll flip it or you could do an exact flip of whatever those incoming values were. So definitely worth checking that out. And also I think it's worth mentioning that this is now the simple math library is really small and it just contains like three functions related to this sort of range mapping and constraining. Dan Halbert pulled it out of the library it was previously residing in, which I can't remember now which one it was in because that was a pretty big library. And sometimes you'd be on something small like a little cutie pie M zero and you just wouldn't have a lot of flash space to store libraries. So Dan gave us the gift of the simple math library which is nice and small. So you can get that in the library bundle. All right, so let's see. Next up, what I wanted to talk about is the project for the week this week. So let me jump back over to this browser. So for the project this week what I'm doing is actually looking back again at this Pico keyboard I built but you could do what I'm gonna show you on pretty much any keyboard that you can turn into a USB MIDI out. So macro pads, little two button controllers like this one that I just built the other day. If you're wondering, yeah, what can I do? I know Lady Eight is excited about these macro pads and you've got sometimes nine or 12 keys on them. You could build calculators with them. You can have them fire off macros for you like the name implies if you wanna have a button for copy a button for paste something that launches a browser and goes to a certain page. You can do all that using USB HID but something you can also do is use these as MIDI keyboards. And so this design that I created somewhat coincidentally has three rows of seven keys on it and that works really well for creating a keyboard, a musical keyboard for using with MIDI that gives us let's say three different octaves of a mode. So if you look at something like the Mixolydian mode it is sort of a scale, it's a subset of a scale that typically has seven keys in it. So if you look at why I'm interested in this well, I'm not a keyboard player. And so the potential to hit bad notes play a traditional keyboard is very high unless you play say just the white keys or just the black keys you can run into trouble. And so constraining your keyboard kind of like our map range thing constraining your keyboard to only play good notes playing within a mode is a really nice way to have some input without being a talented keyboard player or putting in the practice in the hours. And so that's what I've done. So let's first of all just a refresher on this particular keyboard. This is based on a Pico. You could use pretty much any circuit Python device you want for this. One of the nice things about the Pico is that it has a lot of IO. I was able to do 21 individual key switches on this without needing to use a diode matrix or any other type of scanning. So these are just individual buttons wired to the Pico's inputs. And if you take a look at, and so for this one I built a custom PCB for it but you can also do this sort of thing with a breadboard, maybe some of our little breakouts for keys. 21 keys is a lot for that but you could do it. So here's a fritzing diagram of, you can see, I've got this large web of connections. They're all sharing ground and then they each have a wire going to one of the digital inputs on the Pico. And then I had a couple of versions of this using either a 3D printed case or a combination of laser cut and 3D printed. And the Pico gets soldered down in sort of SMD mode with those cast-related pads. This is a soldered PCB. So I soldered these key switches on here. I did not use the little kale sockets but that would be really cool to do because then you could change these out for different keys if you want. I also don't have any LEDs. There's no neopixels under these. This one is simpler than that. So there you can see what goes into building this and that's the final result using some pretty stylish keycaps I have to say but you can design this to work with any keypads you want. And notice this is also in an ortho-linear format. So your typical, do I have a real keyboard around here worth showing? Just this flat little, not so fun to type on thing. But this is a typical layout here. Boy, this thing's dirty. That's staggered for typing and for standard spacing but ortho-linear gives you a nice tight grid which is a little more natural for this use for using it as a musical input. So if you take a look now at my, let's go to the overhead. And I think that my update that I did to this laptop over here means that the software I was gonna show you is not gonna work. So I was gonna show you VCV Rack which is a modular synthesizer and use the keyboard as a MIDI input but that seems to be in a very weird, everything has disappeared except for a few things mode. I'm not sure why. So I'm gonna head over there and we're gonna pick some different software to use instead of that one. And we'll take a look at using this as a MIDI keyboard in Mixolydian mode and then I'll show you the code for doing that. So let me head over here. Also, sorry, due to my software issues that I was having, I don't have a fancy setup for audio. So the audio is gonna be just what we can hear over the microphone that I have my little Avalier microphone here. So yeah, I'm gonna quit rack. It's just not gonna be happy. I don't think unless, let me just see if there was a theme kind of setting but I don't think this has that. Let's see. Nah, nah, I think we'll give up on rack today. I'll save that for a different day. But I do have Helm as my backup here. It's a very nice one, a good backup. So if you look, I'm gonna scoot this. Oh, it's not that. We'll scoot that a little bit. I may not be able to show, this has some problems resizing I think. Oh, no, there it'll let me, okay. So if you look down at the bottom here, there is a little crank the volume on this. So there's a little keyboard down there that you can click by pressing around with your mouse or your track pad. What I'm gonna do is actually, let's switch to a different synth sound. So we'll grab a pad, which will have kind of a rich, warm, sci-fi, organ-like sound to it. Test that. Actually, you know what, let me go back. Let's go back to a real simple sound so you can hear the pitches first. That'll be helpful. Let's go to a lead. How about hard lead? Oh, that's terrible, sorry. Do you have anything in the normal category? Maybe a bass, all right. Or keys, let's go to keys. There we go. There we go. Okay, you'll hear that. It's kind of like a little bit of a plucked string. So now rather than using that little virtual keyboard there, I will use my little macro pad here. And what I have are three octaves. I think they're, I think I might swap these. These may be going low to high. And I kind of want this one to be the lowest octave, middle and highest. But what you'll hear is this is gonna be one octave of the A mixolydian scale. The next octave, the next octave. Okay, so it's not too far off from what you might consider parts of the major scale there, but it is no sour notes, right? It's nothing that turns this into a mess. Okay, now what I'll do, by the way, this is polyphonic so we can play. Okay, so nothing makes things sound better than having lots of reverb and soft sort of pads on it when you're not a keyboard player. So I'm gonna swap over to a pad, which is usually a kind of lush type of preset, synth preset. Let's see, what's this one, epic? Yeah, it's a nice one actually. It has a fairly quick attack. Sometimes they have a really slow attack so it takes a while to hear stuff. So if you now start to do either just held notes or build up chords, and I even got it to sort of resolve. And hopefully you can hear that. I never checked in on the chat because I'm never quite sure what the lavalier mic is gonna pick up. It's really best for picking up voice. So I'm gonna bop over into the chat here for a second. And let's jump to that view there so we can talk about it. And let me grab my Discord. One thing, by the way, oh good, Mr. Certainly said it sounded excellent, I'm glad. Thank you. So one thing you'll notice there too, by the way, using external keyboard, I don't have to leave the presets window like you do using just the mouse. So that's a big help if you're actually just trying to find a preset there. Dexter Starboard said hard lead, oof. Yeah, that was almost rough. Let's see, Fedes says I've been playing music on and off for 25 years and I can't get scales in my head. This might be a nice way of learning them. Yeah, that's a really good point. This sort of thing can be a helpful learning aid. And so something that I was looking at doing, let's take a look at the code here now. How about that one and that one there will work. And I may need to plug that in and open the code. I don't think I saved it elsewhere, which is dangerous, but I'm gonna grab this keyboard, my little, that keyboard there. And one, a couple of things I was gonna say about before we look at the code is that you can, unlike a commercially purchased MIDI keyboard, you can extend something like this to your heart's content. So if you wanted to, let's say add a little OLED display that plays the names of the notes or highlights notes that are gonna sound good together. If you wanted to add a, let's say, keyboard combo on boot up that switches the scales or add a rotary encoder or some other piece of input to this if you have space. I think I have one digital pin left that I can use, so it might need to be a button to click through. Totally possible, so you can, in this case, I've just kind of hard coded the one key, but what you'll find, and I know Liz has done a bunch of this, BlitzCityDIY in our chat has done a bunch of work creating interfaces to MIDI-based circuit Python devices and Arduino devices that allow you to choose between different keys and different modes, as well as note ranges that are useful for drums in general MIDI and things like that. So let me jump over to my code and let me open up, close that for now. I don't think that's it, nope. And I think I renamed this drive, this is not on a circuit Pi drive, for clarity this is called PicoKeeb, there we go. So here what you'll see is how simple the sort of thing is. Other than the fact that it has a lot of inputs, this is not much different than doing a one button MIDI keyboard out of a mechanical keyswitch like I've done a couple times in the last few weeks. By the way, I put a little link up here to remind myself of a nice website with info about modes, so maybe we'll take a look at that in a minute. But here's what's going on in the code, I'm importing time so that I can do pausing if I need to. I actually didn't use the debouncer on this one, I probably would switch to it now, but I was using some small bit of time sleep to prevent multiple bouncing on press. I think I also have some state stuff, so I'm kind of mimicking what the debouncer does for you. Import board, so I get the pin definitions of this board. Digital IO, and that's what I'm using to read each of those clicks of those little mechanical keyswitches there. And then I'm importing USB MIDI, Adafruit MIDI, the MIDI note on and the MIDI note off. And the way those work is they typically take three arguments, they take the argument of what note are you trying to play, what velocity are you playing it at, and I think is there one more or am I, no, that's it, they take the two. Yeah, so just the note and what velocity. Now what you'll find is sometimes this type of keyboard, this is the key bed I took out of an old broken MIDI controller. Sometimes these will offer velocity sensitivity, so there's a few ways they do that, some of them use two contacts and they just, I think, check the speed with which you press it and they equate that to velocity. Some of them may use more sophisticated sensors than that. And that means that the velocity is usually translated to a amplitude, so are you pressing the note quietly or are you pressing it hard? So zero to 127 is the range for that, like a lot of these MIDI things. And I'm sending it a 120, so it's almost the top all the time so that I have to pick one. And you can do things to accent notes if you want, you could add a button you hold when you want to add an accent if you don't have velocity sensitivity, but for me and for this type of stuff it's not that important. So then we set up MIDI on the USB port. You could use this with a, if you use a serial output, I don't have a jack on this that I'm using for that sort of thing, but you can add a serial output so that you can go over a, essentially a 3.5 millimeter headphone cable, stereo TRS cable. You can go to a classic MIDI synthesizer as well. It doesn't have to be over USB, but in this case it is. Then I'm just turning on the LED on the board there. I just like to see some sign of life, so there's a little green LED that you can see on the Pico there that I turn on so that I know that it's on. The next thing I do, I think I blink that. I think I'm not even using that anymore. I think I was blinking that on startup or some other condition, I forget now. This, by the way, was the code I used for my macro pad, sending HID keyboard commands, and I've just modified a few sections of it to do MIDI instead. So here you can see this is my GPIO pins that I'm using as the digital input on the board. And then I'm giving them nice easy names to use, which is zero through 21, and I think, do I skip one of them there? Why do I have, I think I only need 20 of those. I think I only need zero through 20. I don't think I ever get to the 21st, do I? I don't think so. I think that needs to come out. And then I set up all of those pins, so this is the setup with digital IO. We could use debouncer here instead, or in addition, if we wanted to. That's where you'd add that. I'm setting up something called switch state, which I'm using to keep track of if something's pressed or not. Again, something you could do without if you use the debouncer or fall and rise. And then here's my little collection of MIDI notes. So these are the MIDI note equivalents to A, A the next octave up, A the next octave up, and so forth through the Mixolydian scale. Each semitone is one number. So 57, if you were going from A to A sharp or B flat, you would go 57 to 58, but in this scale, we are skipping that half step, so we go straight to 59. So that's, you can see there, if it's whole or half steps, just based on the numbers in the MIDI there. And something I'd love to do, I've done this a couple of times. I've never had like, oh, this is it. I've found the ultimate way I wanna do this, but create some code that does a nice MIDI translation for me. I think actually the Winter Bloom Soul by Thea Flowers is a, the code for that is in Circuit Python, and I think she has some nice helper libraries for MIDI stuff. And then you could add things like pick a mode or a scale just by a name and have all of the proper intervals there for you. But this is just a kind of brute force. I've picked these 21 notes to go along with these 21 keys. And this is the main loop of the program then. So what happens is we scan through every button. So this is for button in range, and that goes from zero to 20. It'll look through all of those. If the switch state is zero, then if the button value is off, it's gone from high to low. And we will press a MIDI note. Now normally you could just use this. You wouldn't need this try accept, but we can reach the six key limit on the USB transport and cause an error. So we're gracefully passing when that sixth key gets pressed. The topic of end key rollover always confuses me and I can't remember if we're able to do it or not now with some of the more advanced USB descriptor stuff, but for now six at a time is all we're gonna get. So this deals with that seventh key getting pressed. Let's see, and then on press, what we're doing is MIDI send note. And we're picking from that MIDI notes array right there or list whichever key is pressed. So if we press the first key on here, key zero, then it's gonna grab the zero index and note number 57 is gonna get played. I think if I show the serial output here, is this the right one? Hey, I still have a synth hooked up. Okay, it's the other one, hold on. Oops, now I've done it. I was not, my mouse wasn't where I thought it was. Okay, screen, screen, screen, seven. Okay, so you can see there, I just have a little bit of a print statement helping me out. I'm gonna turn the volume down a bit. That just prints out the note or rather the key name. If we wanted to, we could also print out the note and this will just be the MIDI number, but you could of course use a different list to give you the note name. So we just say A2, A3, A4 and so on. To do that, if you look here in this print statement, I have, I'm doing this print the name of this key. You know what, I'll just, let me add a second one and I'll print MIDI note and that'll be MIDI notes button. Let's see if that works. Okay, so there you go. MIDI note 57, 961 and so on. You also have the release, I'm not gonna add that statement in here now, but you also, when the key goes from low back to high, we send the MIDI note off command. This by the way is being really proper about it. One thing a lot of people do is they just send the MIDI note on with a velocity of zero. That's a really common thing. I'm sure it's, I mean, that's not the specification, but it works just the same. Sending the note on with a zero turns the note off. So just to be sort of correct correct about it, I'll use this note off. But if you ever wonder why, if you're looking at some MIDI code inside of Arduino, inside of circuit Python, you'll find a lot of times people will not even bother importing MIDI note off. If anyone knows of a reason, please let me know in the chat if you've ever run into a reason why something works better using MIDI note off. And that is it. That's all there is to it. It loops through all the buttons. So like I said, we can, oh, this is a mono synth. I don't think that one's gonna play it. Let's go back to a, oh, this'll be a weird one. Let me go back to a down camera here so you can actually see what I'm doing there. But again, like I said, the nice thing is, I don't know what I'm doing on a real keyboard. I'll play bad things if I try to get it off of the white keys. I'm the center of it somehow again. So that is about it for this. It's fairly straightforward, but I really was excited to put this cool little keyboard to a different use. And when I realized, hey, seven, three rows of seven, that's actually pretty useful for music stuff. And you can code that to do whatever you want. You can get much more sophisticated with it. You could create our peggiators and things like that. But just as a neat little keyboard, it's nice and small, it's reprogrammable. I'm actually gonna be traveling next week. So I'll mention now there will not be a JP's product pick of the week or a John Park's workshop next Tuesday and Thursday. I'll be back the following week. One of the reasons, other reasons I bring it up is, I'll probably bring this with me on the plane so I can goof around just with a software synth on a laptop and have a nice little input that isn't the keyboard. So that way you can still type and still adjust code, but I'll have this little fun thing to play the music with and maybe to code it itself. So, you know, you could do other stuff like latching. You could require a second button press to unlatch a note so you could create holds with things and then go and switch around. That would be really nice on an underlit keyboard, so I may save that for one of our macro pads that'll have the NeoPixels underneath it. So just like this one, just like that little one I built last week with the little underlit NeoPixels on it, that'll allow you to do some cool stuff like it goes red when it's latched and held and playing and then bring it back back off. So, yeah, let me pop back into the chat and see if there's any other thoughts and questions. Thank you Dexter Starboard says, hope you have a nice break. I appreciate it. And what city DIY says it can definitely turn into a rabbit hole, hoping to do some stuff with Thea's libraries, that is awesome. I would look forward to that. Sometimes not sending note off can have undesirable effects, especially with more robotic applications. Yeah, so if you're using MIDI to do things other than music, probably stick with note off. It's definitely worth having a definitive note off. Something else that I've been meaning to do, oh, Todd Bout asked if I'm gonna stream live from the plane. I guess I could, right? That would be really annoying to the poor rest of the plane. I won't do it. Gosh, I wonder if I could port Wirecast to broadcast over my cell phone as a modem, maybe. I won't do that. Let's see, there was one other thought I had and it's just left my head entirely. Well, thank you all so much again for stopping by and hanging out. And I, yeah, I'm looking forward to having some time off, getting into a plane for the first time now that I'm fully vaccinated and hopefully everyone else is too. And that's gonna do it. So thanks everyone for stopping by and I will see you in two weeks. That's gonna do it for John Park's workshop. Bye-bye.