Deep Dive w/Scott: RP2040 DMA and Audio #raspberrypipico #rp2040 #adafruit @tannewt

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
oh if you're watching this video not during the live stream check the description below after a few hours uh it will have time codes to skip around in it so it's going to be about two hours we're gonna take about 10 minutes or so five minutes or so to to get started so uh if you don't want to just sit around and hear me talk i mean what that's what this video will be anyway but uh yeah uh check the check the notes below for like a kind of table of contents of what we're what we're talking about today all right hello everyone good morning internet says unexpected maker hello hugo hello alvaro oh let me turn off my my streams here looks like everything's going everything's looking good hi anecdata hi paul hi bad devil hi gordy hi john hi norm hi pover86 i almost missed you very good morning from india hi ken thank you jose for helping me a bit really hi simon hi james hi bruce hi quirky hi randy waiting on my pico yeah hopefully it's on its way i'll tell you i'm waiting for my uh new processor i got the motherboard and i'm getting the ram hopefully today or tomorrow gonna upgrade this computer and i'm super excited about it gonna have all the cores hi jim good afternoon seattle looks pretty good i haven't actually been outside very much but the sun was out during lunch um but yeah i would i would say it's a bit chilly the object object is deep in the bells of discord's stream kit dug into it for a while on wednesday and thursday and it comes from the server like that oh no i did try it on chrome and it had the same problem thank you for looking into it hugo i was also wondering if there's an issue we should find hi tg techie hi bad abby um yeah that that makes sense um it's interesting that the hugo came through okay if you put object object in it maybe it works hi from cornwall hi andrew hi john john says i'm really curious about the pio for driving hub 75 led arrays i know that there's an example and that phil b has started looking at it for the protomatter stuff tim says i got three picos from canikit that came last night the adafruit order comes monday steve says it's in the teens there that's too cool so it's a it's not me objectifying everyone it's discord um no it doesn't work good try tg techie hi emmett how's everyone doing i was not as productive as i was hoping this week but i'm i'm kind of hoping to do audio all in one fell swoop hi mike what's the weather like in st louis hi simon oh that's nice i have 32 gigs of ram coming as well and randy says i'm going to use a pi 4 to develop with pico yeah that's the only way i did i have a pi 4 on my desk that i should probably turn off that i was using when i needed swd it hugo says that's what someone mentioned on reddit hi griffin do we have anybody watching on non-youtube hi from thailand that sounds warm hi martin ooh emmett was very productive but burned my finger with a one amp lipo poverty 6 got my first pico day before yesterday i played with it for 24 hours but it just died last night oh no that sounds surprising to me i had that's the first time i've heard somebody of it uh of it dying on them hi matthew hi johnny yeah gordy says uh program to do quadrature encoder without interrupts yeah i that we're gonna have to look at that mike says not too bad here sunny couple inches of snow on the grass 40. i think we're in the 40s here as well but we don't have any snow hi grow guard hi keith e 26 c-ish it'll warm up when the sun rises yeah that sounds that's warm anyway hi david thank you for testing twitch for me christian says guess what i say i'll say hi to hello looking forward to playing with pio soon where are the kitties in the kitty cam we have one kitty on the kitty cam uh vin's not in here she was all fussy but spooks in his bed surround your name with brackets does work really that's hilarious something's wrong on their end all right it's two o'clock thank you all for saying hi spooks down to sleep in the sun ah johnny got a pico with the hackspace magazine today dominick says i i'd actually like to start playing with the pico but it won't be her until the 12th of march ah who did you order it from hi mark i almost missed you doesn't look like the bracket trick works for everyone though didn't work for bruce some people are just special i guess maybe it's like different versions of a server a generation generation i think i said hi to everyone if i miss you i'm sorry uh steve says uh pemeroni has uh picos in stock still awesome all right hi folknology uh let's get the show on the road shall we um let's do start with housekeeping here i think i have the timestamps going oh let me switch to hello everyone my name is scott and i work for adafruit on circuit python if you don't know what those are adafruit is an awesome open source hardware and software company based out of new york i work remotely for them so i'm in seattle which is on the other side of the usa it's just after 2 pm in the afternoon here this is the normal time that i stream um on the adafruit channels uh we do deep dives and the questions are welcome they typically go about two hours so about four o'clock is when we'll end up uh finishing up um like i said questions are are helpful um and i'll i'll take those as they come in uh it's we like to wander we like to talk about whatever it is uh and dive deep into the topics that we cover um yeah so friday's 2 p.m pacific uh i'm in seattle that's why it's pacific uh next week is on friday as well um occasionally i'll shift it to like uh thursdays if that doesn't work out um but yeah i so adafruit open source hardware open source software if you want to support me support them by going to adafruit.com and purchasing some hardware there um they pay me to work on uh circuit python full time so uh if you like that support then please uh if you want to chat with me and a lot of others get some help with your picos or whatever boards you're working on arduino circuit python raspberry pi there's folks in this in the adafruit discord server which you can join by going to the url adafru.its discord hop in there chat with us you'll see there's a number of help help with channels there that's where if you're just getting started uh you can get some help and then there's also a circuit python channel and that's where we do all of our discussion for all our discussion for circuit python development circuit python is an open source version of python based on micropython that's designed to make it really easy to program uh small computers called microcontrollers uh to do basically one thing or a few things um it's not going to be your broad like run a whole web server and all this stuff with python it's it's much simpler designed to be more embeddable in different things that you're working on um last piece of housekeeping uh the cat in the picture uh this is a cat cam that's spook he is epileptic he does have seizures from time to time he's been doing really well on his new bed so i don't expect it to happen but early on when i was streaming it did happen so i just like to say heads up if i'm like on the stream but not paying attention that's what's going on i'm just making sure he's okay um and he'll be okay he's actually looks like he's dreaming his paws are going like this um sleeping in the sun okay um so that is it a couple more hellos i think um oh john says i had a kitty that had seizures sometimes too ah yeah it's weird especially when you go to the vet and they're like oh this is usually just dogs hi tabletronics thanks for hopping in um hi mark sorry i missed you if you said something earlier um on the website dominic said oh it's a german spot yeah sorry um [Music] first question of the day i see here is from david who said uh why did you mention shenzhen i o in your last stream uh and i think that's because he got fully addicted to the game um we were talking about the like low level assembly nature of uh low level assembly nature of uh pios and shenzhen i o if folks haven't seen it is very much like it as well um switch to the desktop so it's a zactronix game who's like a game maker known for doing puzzle stuff um but you can do like a little very simple like state machine sort of assembly stuff which is totally like pio so uh if you if you're if you get sucked into video games and you don't want to don't look it up otherwise uh it's it's pretty neat um although i've seen people doing uh doing pios real pio stuff as well um moto teemo says any plans for and maybe i should take a if i'm gonna answer some questions here let me take some time codes um oh yeah and we have one from dcd as well so any plans for esp32 wired ethernet featherwing not that i know of i mean we already have a wiznet featherwing so i would i would assume that that's enough um and foamy guy warns against looking at factorio as well yeah john says i'm glad you found meds at work well yeah it's been five years since we really have um yeah so it's uh it's been really good these last meds that he's been on otherwise he was having them every two weeks or so so but it's been a few months at least now so it's good um flavio says hi scott i'm flavio f you helped me with an mqtt issue the other day just decided to drop by welcome um and paul says i have a dog that has seizures too meds help once you get them right 100. um hi matt thanks for helping in i know it's saturday morning in australia sorry about that um do you have any questions before you get going um johnny asks does the wiznet library support tls and the answer is i don't know um david says i i bought three pico three rp2040s and gave two of them away zero from twitter is asking which os are you using um i'm using uh arch linux with um kde and then um it's set up with a weird uh skin as well moto timo says no tls along with anecdata says no tls so yeah no no tls on there ralph says can pico run circuit python yes definitely um if you want to run circuit python on your pico you go to circuitpython.org downloads and then you can search pico and you can find the raspberry pi pico here and since i have it pulled up i'll put it in the chat too matt says i'm curious about how the peak report is going but no no burning questions so um yep arch linux uh we can talk a bit about that i can i can talk about where we're at um state of circuit python [Music] 2040. um so i would say were a lot of the way through we have kind of what i would consider the core of circuit python so all the usb stuff works they they use tiny usb in the pico sdk so like that kind of just works which is great so that means we have mass storage cdc hid midi um and then uh that works um we have bus io but bus io we we only have i scored c and spy implemented i haven't done uart yet a couple people have uh done that um david says maybe you should discuss the disc partition of the rp2040 yeah we could talk about that a little bit and also the gpio15 um so we have that we have pwmio which gives pwm out um yeah twitter account adafruit or my personal one is at 10 newt um uh let's see api wise um i was gonna do your and i so we have we have rp to pio for the pio what's missing there is we only have write implemented right now we can't read from it uh and the reason that is is because i was focused on supporting neopixels so we have neopixel it works with pio under the hood so you don't have to like instantiate the um you don't have to instantiate the pio yourself if you want neopixels it just it works like any other neopixel um yeah so there's work to do on pio to get um reading from it and then there's a big question mark also about um there's also some uh thoughts about like how to do async like buffers to and from a pio that i've been thinking a lot about uh but my current focus is actually on all the audio stuff so um i wanna do audio pwm so uh playback audio to uh the pwm on the rp2040 i wanna do i2s out as well which will give you better quality um and then lastly i i just looked at it and pdm pdm in which is the microphone that we have on the circuit playground um looks very easy to do with a pio so i think i'm actually just gonna try to knock out all those three and i i was originally just gonna do audio pwm but i kind of like grew what i wanted to do because a lot of the code is shared and i wanted to like i wanted to unify that there um i wanted like centralize it from the get-go okay let me read back i know i i said a lot um david we'll get to you that um get to you in just a bit that that doesn't remind me i think matt asks mention this so i watched matt runs the my melbourne micropython meetup and they've been streaming their um their meeting so if you want to see uh like straight from the horse's mouth straight from damian's mouth about where micropython is i recommend doing that they do it once a month it's late at night for me um but you know everyone's in different time zones um and matt did ask whether we'd be able to do irq support from the pios um i think there's you know one thing we could do in circuit python is we can simply have you be able to read the state of the irq um there is some trickiness about like allocating irqs between different programs on the pio because there are only four and they can address any of the four so there's got to be some way to like allocate them um which is a little weird um so yeah there's definitely work there to do but um a lot of what we do when we design apis is like start from the very minimum with know what we know we need which is what i did for pio for neopixel and then we'll like add stuff to it as we find that we need it uh for example like for pdm in i'd love to be able to test it with the rp2 pio interface and therefore i would be able to need to read some bits um and so like i'll probably just add that um so yeah that's that's kind of like the pio stuff uh hi mbek [Music] okay we've got questions and if anybody else has a question and they can't stay the whole time just let me know and i'll i'll try to prioritize it um hugo asks how do you come to choose arch uh i really like um rolling release distributions uh meaning that there's no like here's the release every two years or every six months there's this just like we update things as updates come um i was on gen 2 for a long time uh but compiling everything gets old and also the gentoo community for a while like kind of i think from what i could tell lost its way and like the wiki wasn't as up-to-date as it was and i think arch in a lot of ways like kind of supplanted gentoo in that like we don't need to recompile everything but we have a really good wiki on how to set everything up um and i like the rolling release stuff i like to i like to know what the latest and greatest is um yes so okay let me yeah and matt's going to post the recordings of the older micropython meetups if you missed it let me just address this question here from gareth who said uh how to smooth library porting to and from micropython um i think so we do have adafruit blinka which was originally actually designed to put the circuit python apis on top of a micropython so if you really do want to do that i recommend it but honestly i think you should just use circuit python there's not a whole lot that i know of that you that you can do in micro python that you can't do in circuit python people will say circuit python doesn't have interrupts but all the things i i haven't found somebody who can't do something they need to do with interrupts using the tools that we've given them in circuit python which has kind of been our model um so i would say like i obviously i'm biased right like i work on circuit python but circuit python has very strong baseline apis to build on top of and so i would recommend starting there poverty 6 says where did my notes go sorry i'm getting backlogged but we'll go through them unable to create some images oh cause i have the i don't need the emoji in there thank you very much uh how feasible is it to replace and upgrade the flash chip on the pico um i think it'd be pretty hard because the chip is really small um like it's it's it's very tiny it's not like the flash chip is this chip here and it's not a large one you're gonna definitely need a hot air gun um and if you have a hot air gun you could probably do it but um software wise you'll need to you'll need to change the size that everything is um but yeah one reason i'd like interrupts can't stop an ongoing network fetch free of button presses that this is what i say about networking networking is the reason that we really have to deal with that it's pain um flavio asks and let me i'll just i'll just roll through these lots of good questions um let's see floyd says have you ever talked about ota on the circuit by them based deployment um so we talked about it briefly in the hack chat on wednesday basically for esp32 s2 we we set aside space for a second copy of circuit python that you can use to switch between the two um and there is an api for writing to it and switching to it that microdev added so try it but again it's open source software and it comes with no warranty um so if you are expecting to deploy it in a lot of places you are responsible for making sure it does what you need um yeah at the end of the day it's on you okay so ralph says um what makes the pico better than other boards and here's where i'll say i don't think the pico is a very good dev board the reason that it's very popular right now is that it's the first and only way right now to get an rp2040 the rb2040 is really really interesting um but the pico as a dev board i think um is not great and i'll tell you why i shouldn't just criticize it without backing it up um so let me let me switch here so i don't have the overhead set up today so here's the dev board one criticism i have is that there is no pin labels on the top so the top doesn't tell you what pin is what and if you put it on a breadboard that's going to be a huge pain now some people are like oh well i just put this side up but the problem is that there's a button here and that button is the boot select button so if you solder it down this way you can't get access to the button secondly if you want to restart the board you have to unplug it and plug it back in because there's no reset button so i also think that's that's a fail so honestly i don't think this is a great dev board um but the chip is really really cool um and one thing to say about this dev board is that it is very inexpensive so it's very cool that it's four dollars a pop um and the cancellations are cool too so i think um i think there's room for improvement um but i'm like i have a i'm one of the few people that has like a prototype rp 2040 feather um which is this one so like here here's something that that adafruit has designed but we just simply don't have the chips yet it's got a usb type-c it's got a battery charger like all the other feathers there are labels of all the pins on there um yeah so i think i'm biased but i i think the rp-2040 chip is really cool and it's worth getting a pico to play with it early but once the chips become available i think you're gonna find better dev boards um than the pico itself okay so ryan asked um will pwm capture be supported yes eventually so that's the pulse i o module um that is something i want to add but it's not super high on my list um so if you'd like to take a stab at it that would be awesome uh but i'm trying to do audio and then i'm gonna i need to do uart um before i get to pulse io um ah corky says after the gentoo wiki loss it hasn't recovered very well so they actually lost the data that's unfortunate um i really like arch on raspberry pi's yeah i just run raspbian on there generation generation says pen two versus arch for your opinion which one is more secured um i don't know i'm i'm not a great security person there's there's better folks to ask that of um in fact i i realize because i do open source work at home like i don't even have a like my my screen doesn't lock like i don't need to type my password in uh there's there's very little very little reason to worry about that um randy asked um is circa python going to support the dual cores of the pico um i think we should uh i think i talked about this last week so if you haven't watched last week uh at least look in the time codes for there but the gist is that um i'm really thinking about treating the second core as a um run something bare metal assembly or short compiled c code on it instead of just running more python um so yeah matt says interrupts and solid async io so mbx says we have async io turned on but it's based on the older version we do want to update to micropython that's one of the reasons um but concurrency is really hard i'd love to know what you use interrupts for because you may not need them in circuit python um let's see oh yeah so it yeah power on led that's a good point too um folk knowledge you pointed out on discord for pico you can always run micro python on core one and circuit python on core two i'd love to see somebody do that micropython assumes they can use the second core though and you have to worry about like where you place it in flash as well um and beck asks will there be a start with circuit python on the picobook so let me let you in on a little secret here um if you go to learn uh we have a guide if you do i don't think it's on new guides for some reason but we have this get started raspberry pi pico um and here's a little secret we actually have uh in the works uh circuit python examples of the stuff that's in the micropython uh picobook so uh that will that will get you going it's just uh not quite finished with review so keep an eye on this guide um next week hopefully it'll go out but these are the examples that are from that book and we have the python version of them uh so it's coming i don't think we'll like we'll never print it out as a book but uh at least we'll have the like the comparison of how that how the two work um yeah kristin points out the rp2040 could dedicate a whole court of networking thanks matt you may be gone by the time i read that tablatronic says the pico is like a breakout board yep [Music] right christian says it's a little surprising they could fit a buck boost converter into the budget with but not an extra button yeah it's priorities like clearly they want it to be embedded in other stuff too so um you know who knows what their design constraints were oh no feel better mark and get some sleep i know it's late for you um daniel says uh could you tell us let me i'll take a time go hold on we can talk about this briefly too it is something i've covered before but we'll it's it doesn't hurt to say again uh we'll see how long i can ramble uh daniel says could you tell us something about circuit python versus micropython um yeah so uh [Music] circuit python is based on micropython i was hired in 2016 to start working on micropython for adafruit um but as i started to look at it one thing i noticed was there was no consistent hardware api across all of the ports uh as i said i was like adding a new port i was adding for this amd and it wasn't clear there was no one central place documented of what the standard api was and that was really really important to me because i knew adafruit was going to do the same play or model that they had for arduino which is like now we're gonna make drivers and sample code for all of the products that we sell on this foundation and i knew that because of that we needed to have a solid hardware api at the bottom of it um so that was like the one of the main reasons that we kind of like moved away from circuit python um so generally what you'll find is that um circuit python is more consistent and consistent across ports a lot of our work does focus on the like how do you get going really quickly stuff so we don't have as advanced apis as micropython does that doesn't mean that we can't add them if people want them it just means that like folks paid by adafruit to work on circuit python will only do reviews like i'll review that stuff but i won't work on it myself um so yeah i recommend circuit python the one of the selling points i i i say about circuit python for um the pico in particular is that the micro python version doesn't do mass storage so you have to use it um you have to use it with um thawney which uh i think some people like like it but um i i i like the philosophy of like you can use whatever editor you want and some editors are more hand-holdy than others um and so the way the circuit python does is you you drag and drop it on your pico just like micropython but then it shows up as a circuit pi drive with your code on it which makes it much easier to get started much quicker as well so if you you could try both and that's what i recommend um but yeah as patrick says maybe we can record this answer micropython versus circuit python plays it as an outro bravo delto says i firmly believe circuit python wouldn't be as great as it is without me thank you i'm glad you think it's good i've definitely put a lot of uh my time into it and and and my software background as well um psy says at my previous job the head of it used to open a random web browser tab that is offensive to warn people to lock their laptops when leaving it unattended yeah luckily the cats haven't figured that out yet um hi hi nicholas greetings from chile um hi chris okay i see this question in a couple spots so let me answer it and uh dcd does i have a question i should answer too here so what is your guess how far the pios can be pushed quadrature and coder wise for circuit python um you know i i haven't looked at it um the tricky thing is um the tricky thing with quadrature and quotas is like the the pios don't do any sort of state machine um so besides reading the values on the quadrature coder and i'm not sure i haven't i don't think i've seen an example to do it yet um so i'm not actually sure whether the pio is the right way to go about it or not um in circuit python for for ports without pio we'll just do interrupts we do interrupts on pin change of the two pins and maybe we can use the pio to do that as well and it says github changed my picture that's unfortunate uh tim moved away from micropython target paul says so lesson number one for the night don't try to make tea load a dishwasher and watch a d dive at the same time just dropped a sharp knife on my finger is blunt side luckily oh that very lucky size says bonnie is a bit weird to use it it has some good things like it it makes sure it saves your files i think to the pc as well um pikachu 922 says arduino on the pico when that's a question for arduino um i have no inside knowledge and i would say really you should try circuit python it's easier uh it's easier and it's faster to iterate too um let's see did i miss anything yeah and paul is suggesting suspecting that arduino will launch software support when they launch their board um and beck asks do you see the rp2040 pico and circuit by then overtaking arduino due to python being so much easier to code for beginners and otherwise uh i mean that's a bit of a loaded question um certainly like we are trying to make something that's easier than arduino um but arduino has its place like there there's definitely things that you can do with having a compiler that you simply can't do in circuit python um so i think it's more about like pushing arduino to improve stuff and micropython as well right like we see what each other is doing and we see the innovations that are happening and push that um so i i want people to try circuit python i do think it's a better experience than arduino um but that doesn't mean that like arduino is not going to exist hi blitz city thanks for helping in um toddbot says i'm having a hard time installing linux on my pico even arch yeah um you're not gonna be able to do that and i i feel bad for raspberry pi having such a strong brand associated with linux that i'm sure they're getting lots of questions like that um gareth says arduino was a game changer a decade ago when getting your tool chain running took a week now it's getting a bit old um yeah i think i think the fact that micropython and circuit python have um microprocessor and circuit python have uh tool chains built in that you don't have to install is a huge deal and quite surprising why the pico micropython doesn't allow you to just do edit file on the drive sorts of stuff it requires the thoni install or or r shell which is weird to me um not even alpine yeah well so though like pico doesn't have a memory map unit so i don't know if there's linux without that my understanding is that you need it for linux so that you can like page in memory oh that's the wrong spot oh and i'm uh let's see what embec is asking here i often get old print statements from infinite loops still printing in the mu serial output after saving and my code restarting is that due to a big buffer somewhere still pushing out text that sounds like a bug to me um if you see it restart i would expect it to be different um sometimes what can happen is you can have like partial updates of the code.pie depending on how your host os writes stuff out which could also cause the problem um yeah kristen says probably not linux but there will be a lot of c64 clones and the like i bet i want to make circuit python a c64 clone we talked about this before but i think it would be really cool to use circuit python like a c64 where you're like just in one screen and you're editing on it and stuff i actually had the basic python if you saw it last last week or the week before um i did this like super quick demo of editing python like it was basic if you can see the animation here but it does the prompt and then um so yeah it's like 30 lines of python but you're editing python code like like it's basic which is a bit weird but i think kind of cool let's see hugo says micropython versus circuit python try it yourself and take the pepsi python challenge um oh yeah somebody asked about q spy so the love factory someone is going to get doom running on the pico um where did this go here um is the circuit is circuit python doing quad spy or q uh to flash or is it just spy i think right now it's just spy and that thank you for reminding me that's actually something i need to need to work on sooner rather than later um circuit python pico right or rp2040 right now is just assuming that the flash works in the way that it's set up um but in that's not actually going to be true we actually need to be able to like configure how to talk to the flash um and so that's something i have to do so right now i think it is just spy but i'd like to move it to cue spy but in order to do that we need to be able to like configure which flash chip you're talking to um yeah the pio asm stuff is definitely not for beginners i agree with that but it's important to note that we are we are using pio to do the things that you want to do without you needing to know its pio as well um topbot says arduino is great because it doesn't create a floor for efficiency you can drop down to bare cd sdks or even assembly that is not possible in circuit by then until maybe we get the ability to load binary modules so micro python does have a way to like inject assembly into it um we don't currently have it and we might have it enabled i'm not sure um but i would argue that you're arguing there's a there's no floor because you're already in the basement um there it is possible to drop down in the sea um but uh it's more work to go down down a floor for sure um kristen says oh that's awesome yeah i really want to get circuit python running bare metal on the raspberry pi um i want to get it running bare metal on the raspberry pi so that you can do um uh [Music] like this circuit this c64 style circuit python on a raspberry pi 400 specifically um keep trying to move forward to circuit by them and fall back in the arduino ide when i want to use some other chip i have a tiny pico and a feather s2 project underway and i will soon use python let me just say that the fact that circuit python works the same across boards is actually really really powerful like i've had to point people like we don't need a pico book because all of these things besides pio are the same and i don't people fully don't think fully people fully appreciate that yet um okay we got a question from jack with says did you implement peak in c64 no i didn't um we've thought some about how we would have memory io like memory io allowing you to like peak and poke registers of a certain range um but the the example i'm doing is actually just running into python um davey asks um can certain python take advantage of sparkfun's proposed larger flash part um not in its current form um but my plan my hope is to get all the flash stuff refactored so that by the time the boards are actually available we can um and the way that it will do that is we've allocated a megabyte at the start of flash for circuit python and then the remaining megabytes however many they are will just show up in your circuit pi drive um and in fact i think we're planning on putting a four megabyte one on the feather um although no promises until it's actually released um ryan asks will framata work on this board um i think fermata is based on arduino so once there's arduino support it will um but i would say if you like my understanding is that for for mata gives you python on your host to talk to the board i would encourage you to look at micropython or circuit python as a way to actually do it better because it runs independently um garrett says actually now you've wrapped it up it might be a perfect educational vehicle for assembly 100 that's why i'm thinking like pio assembly to start and then cortex m0 assembly after that hi paul let me answer lots of good questions um so let me flavio says just to follow up on the ota question what i meant was the support for changing files like code.pi on the mass storage and not circuit python itself would that still be considered ota i think so um there's a current pr that allows you to switch the next file that circuit python runs and i think that's what you need um because that pr also allows you to say like run this file on success do this but if it fails like if it throws an exception run this other file or do something else which i think is like the primitive that you need to like do ota of python um ax patrick w says the ability to use circuit python libraries across boards is huge in micropython many libraries are port specific yeah moto timo says circuit python is common with the exception of the esp32 spy ethernet sport there are other things that only work on esp32 wi-fi right now not wiznet 5k yeah that's because the first round of our our socket networking stuff was not very socket compatible um so the goal is like as we get through it like we'll um we'll be able to like have real sockets and then like it'll work then the libraries that build on sockets will work in c python and esp32 s2 wi-fi and then hopefully wiznet and esp32 spy at some point as well um david says how would you control a low power state entry without wait for event or wait for uh interrupt so circuit python has higher level primitives for low power states we've just added all these apis for the esp32 s2 and the way that it works is that circuit python will basically do wait for interrupt automatically when it's asleep so you'll just get that for free um we don't do any cross-course stuff yet so we won't do wait for event um but basically the the philosophies will do it for you um so that like timed out sleep is a light sleep we also now have um i'm already forgetting the name of it so on read the docs you can see all of the apis and we have the ability to light sleep until an event occurs which we call alarms so alarms and sleep is where you want to look and we have the ability to persist memory we have oh look we have light sleep until alarms so you give it any number of alarms and then when it wakes up it gives you the alarm back that woke you up um and then if you want to do deep sleep we have this exit and deep sleep until alarms and the way that works is you give it a list of alarms as well but it actually never returns it shuts everything off it validates that you can wake up from deep sleep from those alarms but then it will restart your code and set the the alarm that woke you up as alarm.wake alarm so you don't need the assembly versions we've got an api for doing uh sleep state stuff and under the hood we try to get the sleep state as low as we can based on what you want to do christian says there was a guy who made lisp repo and bare metal raspberry pi might be a good starting point yeah there are some good docs it's really a matter of um really a matter of when i can actually get to it oh boy i'm a little bit behind not too far circuit assembler well we have we have an assembler now oh no paul's order is delayed awesome okay let's get to um let's get to this other question we have okay so um david said earlier uh or asked me in the chat um time code uh given earlier interest in fpgas and compared to the focused power of the rp2040s have you followed the glasgow interface explorer is it the next step has anyone backed it yet just four days left on crowd supply so let's pull that up so i think if you're interested you should support them um if i remember right it's an ecp five and they're well above their goal which is awesome almost a thousand percent that's amazing um i think it's primarily done by um forgetting their name yeah but it's the person who does and me jen uh white quark white quark is doing this i think and um white quark is amazing um so yeah eston is doing it too with white quark but i think white cork is doing a lot of the engineering um so if that sounds cool to you i highly recommend it um i think for me at this point i feel like i have too many things um generally i have um generally i have too many dev boards um and me jen's really cool i would love to get back to it but the reality is that there's just like a lot i still want to do to make it kind of what i think is coolest i have these like fantasies of being able to like write a class that represents a peripheral on an fpga that you can also use as the driver to talk to it um so yeah it's certainly something to watch um i know that they've done a lot of work on it i have not backed it but yeah it's great to see that they're it's great to see that they're uh going that far i still think if we if we want to go into fpgas i still think the way to go is like having an i squared c device that's an fpga um and in fact that's what i think i have it on my desk still yeah so this is kind of what i was thinking and it's my terrible soldering with let's change deep dive with scott to scott's fantasies yeah the first hour tends to be like this um this is i think where i would go with where i would start i would should say with fpgas um it's like designed to be a stemma fpga so it's a mock xo2 and it's basically like create your own i squared z device uh rather than your whole system on a chip um the goal would be to be like low cost and easy to load um and to some degree you could think about like how we'd load software on like a pio would be something something similar as well uh but yeah please if it if this interface explorer is interesting to you i can certainly vouch that um one bit squared is a good company to get it from and white cork does has done amazing work with nmegen um which is like using python to define like logic structure which is i think very very cool um dave says it's gonna complain about posting pasting another emoji in all right we got to that question that's good uh maybe at the hour mark we'll switch over here so um davey asks does circuit python have the ability to toy with clock to get lower to get current lower on the new speed um no uh i've been trying to be good about like not assuming the clock speed and reading it from somewhere else um but especially for the rp2040 there's not a lot of clock isolation um so no i like we we we we've tried to like what what happens when you try to design apis at work across boards is you really have to do simplify them so like with our with our sleep state stuff it's basically like you're on your running your idle or if you're in light sleep like you try to turn off as much as you can and then if you're in deep sleep you turn everything off including like your ram and stuff so no um you know like another way to think about the comparison between micropython and circuit python is like to some degree micropython's designed if you've read the datasheet and circuit python is designed so you don't have to read the datasheet the consequence of that is that though the weird parts of the data sheet you may not be able to do through circuit python where you could potentially do them through micropython um how is current compared to portenta i haven't looked at the portenta i have one around here somewhere because i did want to bring circuit python to it but it's just never been a priority um and i've certainly not put it on a power thing um so yeah i can't tell you i can't tell you that um yeah gareth says if you could provide an i squared c stack that would be super useful device so i actually have code i already wrote the code to load um load bitstreams into the mock x02 over i squared c i have that the the challenge is like how do you create those bit streams um i can't remember the name of the repo but you can bug me on discord and i can find it later [Music] this is a good question um so mark asked um any part of the rp2040 port that would be useful for me to poke at working on that still needs to be done now that i have a couple picos finally um so what's on my radar is i wanted to redo the flash stuff which is probably better that i do uh uart is a bit tricky because it has like a circular buffer under the hood but that would be nice um and then i'm working on the audio stuff which is also pretty tricky one thing you can actually do though mark that might be a good one for you is um parallel bus so display io dot parallel bus would actually be probably pretty easy um and it would be really it you would have to you would use the pio um but that could be something really cool to do that i think is pretty pretty easy to do as well so if you wanted to take a look at that that obviously was not like a top of my list but um there's a lot of these other things that that would be really nice like microdev just knocked off um the watchdog stuff too so the watchdog stuff works which is cool too yeah the rtc stuff is not perfect either keith ee says i i backed the glasgow and a couple years ago i backed the icebreaker fpga for me it'll be a digital digital logic analyzer at the very least so it's a worthwhile tool yeah totally johnny was joking that mark should add arduino support for the rp2040 uh ask patrick wanted me to point out that um brent has been working on bringing the date time module from python to circuit python so you can go to github.com adafruit adafruit underscore circuit python underscore datetime now and install that library for datetime on circuitpython um foamy guy points out kmatch did the parallel port work in s2 yeah that would be cool all right any other questions before we stop stop with the scots fantasies portion of today and we dive a little bit deeper i thought it would be really interesting to talk dma um as i'm doing all this audio stuff i'm realizing the real the real beef of the real uh the real works in dma it's not actually in the audio stuff [Music] um ntp dear mash is working on the watch dog for this amd yeah i linked you to the pr from microdev adding it to the rp2040 love the factory says uh time code timecode timecode um will uart work over old school pins instead of in addition to through the usb yes um in fact it doesn't the the the serial connection that you're getting over um the serial connection that you're getting over usb has nothing to do with uart um like it doesn't use the europe peripheral at all it's like the usb version of that protocol um it's unlike something like an esp32 or an esp8266 where it's like literally a uart out to another chip that's converting from uart to like um usb's version of of it um so yeah it'll work on old school pins i i saw one one person uh get to the point where uh they were trying to do midi uh with circuit python [Music] like actual midi um and they needed uart to do that so we haven't implemented it yet it's on my list um but i asked the more what was her priority and she set audio and i think audio is going to be really cool for people so i'm hoping i can wrap up audio next week and i'm being ambitious so what does audio mean in terms of rp 2040 and we have chance for dma in the chat as well um audio what does audio mean and and i guess this can be a setup for let's let's let's dig into this so i've got a lot of tabs open here um circuit python has an audio system uh randy says where is the parallel pio bus documented so what i'm talking about for that is this um display io parallel bus i don't think i opened an issue for it but it's one of the ways that you can talk to a display is what i was referring to um bruce accidentally rebooted their computer um okay so let's talk audio and then we'll get into why dma is like the real thing that you have to worry about um okay so if we're looking at the docs and maybe i should make it a little bit bigger let me close this tab that'll make it bigger um so i'm on the docs and these are all the modules we have an audio bus io if i click in there it has i2s out and it has pdm in so those are two digital sound formats i2s out is a structure actually i have the wikipedia open it you it requires a separate dac chip which does the digital analog conversion um but the advantages is that that can those are tend to be really pretty high quality sound outputs uh because what you can do is you transmit um you alternate samples between left channel and right channel and i2s you can actually vary the number of bits so like the dac here uh i have it open so this is the this is the data sheet for the i2s dock that we have in the store for adafruit and uh it's a 24-bit deck but the way that it works is you transmit from the most significant bit down so if you only transmit like eight bits it just the top eight bits are that and then the rest are zero um so it's super flexible and like how much resolution you on the digital side you give it um so that's really nice and that's kind of like how you can get high quality audio out of a microcontroller is through i2s so we have i2s support the other thing in audiobus io is an input which is called pdm in so pdm is pulse density modulation which means that um it's a digital signal in that it's either high or low but the amount of time that it takes high or low is indicative of kind of like where it is in between um so what what you do there is you can like sample it at a particular rate and then like the number of ones versus the number number of zeros can like give you uh like a perspective on like how uh like what the actual signal value is um which makes me think maybe i should take one step back and talk about the way that you represent um audio um electromaker points out it's stacks are way less hassle to use than i expected to be honest yeah uh 100 so let me actually let i installed audacity audacity is slow to start up but it's actually a really good uh kind of way to understand the way digital audio works so i think i have yeah this is just an mp3 i downloaded um it's just like a chunk of an adafruit song so it's totally okay to play although i don't think the playback works yeah i know audacity's not working that well for me um yeah pdm says mems microphones i think they're they're typically that so how do i zoom in so if we zoom zoom zoom zoom zoom um this is so time is left to right right and then um the value above or below the line is like i think of it as like the position of the speaker cone which i think is actually i think that is true um so the way that that you produce audio is basically you send a stream of values that vary like this over time um and i think if we zoom far enough in so here's the project rate so it's 44.1 kilohertz um which means that there's forty four thousand one hundred samples per second uh which actually is quite slow um oh yeah there's a better view so look there you can see like the individual samples um davey asks can circuit by then support different ethernet chips or just wiznet i think we just have a library for wiznit uh but it's done purely in the library so if you had another one you could theoretically write another library but that that's the only one i know of um so this is this is the challenge with audio the the challenge with audio is that you're basically producing you're moving like we talked a little bit about this last week right like computers are number machines and so the goal of um electromaker says i feel like a struck stuck record whenever i say this but the folks at bella have an incredible from scratch audio dsp and c plus course on their youtube channel hop on our discord and send me a link because i'd love to see that um discord is a d a f r u dot i t slash discord um i'm not a good dsp person so i would love to to learn more about it um thank you um yeah this this will show you my understanding of audio so the challenge with audio is that you have to continually vary value i and it's relatively slow rate right like um 44.1 kilohertz uh this is where i break out my my calculator also known as python this is what i like the rebel for by the way this is what i use the ripple for so um it's all about about how much time you have some to do something so the pico runs at 125 megahertz so that's six zeros and then we want to change the value in a register at 44.1 kilohertz which is 44 100 which means that we have just under 3 000 cycles of the cpu the system clock to move one value to another place um which should be plenty but potentially like i've seen like 320 kilohertz samples and stuff like that too so um generally what what cpus have our problem being consistent right this is why the p pio is so interesting is that it's something separate it's not getting interrupted it's just running at a fixed frequency so like if this was our pio which we can also run at 125 megahertz like we have 2800 or so um things that we can do um so there's multiple different apis in circuit python um and if we're just talking about uh like our outputs we have i2s out which i've there's an example for i2s in pio so that means that we need to deliver [Music] we need to deliver one sample at 44.1 kilohertz which is kind of the standard because that's what cds are um and what you can do is you can actually like cue up stuff so like the pio has a for entry buffer but if you're only doing one direction you can make it you can use the other one to make eight so that gives you some flexibility there um and then let's let's keep looking through the library so that's audiobus we have audio core which gives us raw sample and wav file that's that's how you know like what your your sound source is so um raw samples are the easiest they're just like i'm gonna like when i actually get to testing this i'll just take this example and try it right like that's the benefit of circuit python is like this is an example i worked on three years ago when i when i implemented this um and i should be able to just use it so i'll start with that raw samples they're just in memory and they're a sequence of values that produce a tone or you know you can loop it or whatever so audio i o is uh the audio out object which is if you're actually if you have a digital to analog converter on the microcontroller itself um sandy 21 samd51 have this um the pico does not um one thing that's also pretty common with a dac and also adcs is that they have a particular bit resolution so um wav files tend to be either 8-bit or 16-bit sound samples i think the highest quality i've seen is like 24 bit but we don't really deal with 24 bit at this point um but the challenge with audio out is that you get like fraction you get not fractional bits but you get like a 10 bit or a 12-bit resolution so there's some work that has to be done to convert those 16-bit samples down to like a 12-bit sample um and you don't like one of the challenges is that like a wav file could be really big and we don't want to load that all into ram all at once so there's there's a system in circuit python that basically says like the thing that's outputting says hey give me another chunk of samples and then it kind of like back propagates and figures out like okay like let me get some more samples through this pipeline um so that's audio out audio mixer is one of those things that could be in the middle of like a raw sample and the output um this allows you to actually like have both a raw sample and another like wave file and mix them together and then output them so that's what audio mixer does and the mixer voice is like rep mixer voice represents like the the like each side of that mixer i guess um a lot of this is inspired by the teensy stuff that paul did um although we don't have like a an editor things there a question from davey says should guitar pickups be i2s for a local multi-musician jam session that is synced i'm not sure um [Music] yeah i mean i2s is generally pretty high quality but i'm really not a great person to ask you about the the finer details of audio stuff um audio mp3 so not only can we do raw samples and and wave files but we can actually do mp3 decoding and i want to try to turn this on i i suspect that the pico will actually just work with us but it might vary with uh quality so generally that's what can happen with audio is that like you just have to downgrade the quality of your sound samples to the point where like everything can keep up um gareth says you need a microcontroller next to the i2s microphones so maybe midi is better um so audio pwm i o so this is a way to output that the audio signals using a pwm signal so what you can do is you can you have a fixed like frequency of the pwm and then you adjust like how how high it is for how long um to basically produce the waveform still um this is already used on the nrf52840 because it also doesn't have a digital analog converter just like the rp2040 so this is something that we want to do for the rp2040 and i think that's all of the related things so to summarize um i'm trying to do audio pwmil i'm trying to do i2s out and i i thought i'd throw in pwm and or pdm in as well um fucknology says can you take advantage of the parallel read slash right across memory banks to improve throughput on the pico um i don't think we need to worry about it because simply like audio is not that fast um right like we did the math versus the system clock and it's like 2 800 cycles so like i'm not worried about the speed on i don't i don't think that's our limiting factor um what you do want to be able to do is you want to be able to like not worry about it every time right like you don't want to have to be interrupted every 2800 instructions just write another value and that's where dma comes in so dma is really cool i think i mentioned it dm dma is short for direct memory access maybe um but the general idea is that instead of having a cpu have to keep track of like i'm copying from here to here dma you can say like hey copy this much stuff from here to here and let me know when you're done um it's something that uh like we get some grief in circuit python for not being able to do things concurrently um but dma is something that we take advantage of when we can and we can do things concurrently as a result so so yeah dma is really handy um there are some challenges might do that for multi-channel audio yeah it depends on how many channels you you want to be able to do so maybe i'll just pull up my working code and by working code i mean code i'm working on not that it works um so one of the challenges is for pwm i o this is the this is the place i started and i was kind of working my way back so my plan on pwm i o is the pwm i was looking at the nrf 52 implementation and because pwm has a frequency of its own you want to make sure that the pwm frequency is far higher than what humans can hear otherwise you may actually be able to hear it as part of what you're listening to so um there's some complicated math in the nrf52 side that tries to figure out like the optimal version of that um but it has the challenges that the pwm on the nr52 is running a lot slower than the one is on um the rp2040 so uh kind of where i've settled is that um i can just pick like how fast the pwm is going to be running um so the the pwm will always run at the same frequency and then what we'll do is we'll have um let me pull up the data sheet as well so here's the problem here's my math so 125 divided by 44.1 kilohertz is great until what you do is you divide it by the number of bits of resolution you want per sample um because like even here like 177. so that's still okay this math is complicated let's see if we do two to the ten oh 2 times 10. that'll do it yeah i think this is this is the inverse of the math i was doing so um what you need to be able to do is the way that pwm works right is that like it's going to count um so you have megahertz coming in but then you need n bits of resolution um davie says can circuit python stream to or from multi-channel i2s microphones or dac chips at decent audio speeds for music or just voice quality um we haven't really focused on quality i think you'll find that just because this chip is pretty powerful we'll be able to do more higher quality stuff than than some of our other boards but it's really just a matter of like um how much cpu time we have and stuff uh we can only do i2s out right now we can we cannot do itus in yet um so yeah the challenge with pwm out is that you lose resolution to how uh long your like what your top value is of the pwm which is how many bits of resolution you get in the in the value um so one i think this is going to be the major limiting factor to audio pwm i o but um it's nice that uh the i2s doesn't have this problem because it's just sending a digital value out so it costs two cycles per bit of resolution so um does it have any dsp that will allow to modify the audio oh no i would love to do a synthio but we never did that i'd love to be able to like generate samples uh on the fly but i haven't done that yet so if you're a sound person there's room to play there um yeah so one one challenge of the pdm is io is that uh you can lose resolution so i think what i'm going to do is i'm going to say oh it's just always going to be 10 bits resolution and there's 2.76 cycles per uh 44.1 kilohertz sample so you'll actually output it more than once um david says chiptune co-processor on the second core um yeah yeah so the m0s don't have any sort of floating point math hardware um what they did with the rp 2040 is that they included some really good floating point software routines in the in the rom which means you're like you can rely on those to be fast access whereas like code might actually be fetched from flash which would make it slower okay so that's a challenge here so the way that i'm going to have audio pwmio working is that um the pwm will just be clocked at a fixed frequency with a fixed top value so it won't divide down the 125 at all what it will do is it'll just divide it by like whatever the top value is and then what i'm going to do is i'm going to copy in at the sample frequency i'm going to copy in the value that i want the pwm to be outputting and there's this really cool feature of the dma and it's kind of almost a footnote oop wrong window it's almost a footnote in the in the data sheet here i think but the dma on the rp2040 actually has what they call pacing timers and these are timers that are exclusive to the to the dma um that can just like output at a given frequency and trigger dma to copy a value um yeah like look at this pacing timers it's like three two sentences three sentences uh these allow transfer data roughly once every n clock cycles instead of using an external peripheral d d rec is a data request to trigger the transfer so usually what happens with dma or the the simpler way is like you have the thing at the edge like the i2s or whatever and p that pio can do this as well like you have it running and then whenever it has a buffer of one or more and anytime that there's space in that buffer output say like it will raise a data request line and then you can hook up a dma channel to pay attention to that and that's really handy but i don't think i'm going to do that with pwm out all the pwm will do its thing and then i'll have a pacing timer that's running at the sample frequency um that's basically like copying over at a partic particular uh rate um and phonology says does that use up a state machine no i none of this has is pio stuff um at least for pwm thank you bar doctors for the link to the bella stuff i've heard of bella before but i haven't seen their um real-time uh like programming stuff i should watch that i'm always looking for good apis um uh let me copy that over i'll post it here too copy link and i'll put it in the notes too somebody didn't grab it already oh yes people wanted the gpio15 story too um we can talk about that yeah i mean not only is it what i know but it's also what folks who watch know which is awesome so that's my plan for pwm and there's i know of at least three different ways to do clock division in the rp2040 um so the the pacing timers um yeah i figured uh the pacing timers have a fractional divider uh that generates a maximum of one request per system clock system so pacing timers can run up to 125 megahertz um the fractional divider is x over y and so one thing i did this week that is in my code that is a work in progress is computing okay if i want if i'm taking 125 megahertz and i want 44.1 or however close i can get like how could i like what is the ratio the x and y that i want to use for that so i actually what i did is i prototyped a do i have it oh i can close this no i don't need to say that um in my circuit python ports raspberry pi um i did this divisor finder code and basically what i decided is i could just brute force it uh to figure out the x the the x and y of the divisor so they're each 16 bit values so i do okay i want to do a system clock i want the sample clock i keep track of what the best one is and then i just do a for loop until i find something that's i exact or i complete davey says what tool chain choices are there for ingesting apis to build libraries for circuit python typically all every everything but extensa um everything but extensive builds off the arm gcc uh the make files are kind of like a circuit python conglomeration of stuff [Music] which is not spectacular and i want to replace it and i've talked about that before [Music] and then [Music] we don't have the c plus stuff set up so um yeah we should set it up so c plus plus can be brought in too but we just haven't gotten around to it and i i i've not done embedded sequels plus so i didn't really know um yeah so here's the trick so i prototyped this math on here and i'll just i'll show you so this is me trying to wrap my head around clock rates and then if i just do python 3 i call it divisor finder you'll see that oh here the numerator is 15 the divisor is 42 55 17 which ends up being a 44.100.007 clock rate um this 300 is the the remainder the modulo of something um so this is like and this is the opposite of that um yeah tim says uh thumbs up while you're here uh i've been happy to see that we're getting lots of thumbs up which is good um yeah so best error best remainder um and then if we look in my code and we could like you can see i have prints i was like debugging it so i first did it the very naive way of like using floating point and all that stuff that python has but i actually customized this code after i kind of figured it out to do fixed integer math because i wanted to do that instead and then let me show you i haven't tested this yet so it's all all subject to change but if we go to my my branch rp 2040. yeah this can get us into audio pwmo and don't let me forget about the gpe 15 stuff [Music] this is gonna be bad i think i'm gonna get a unicorn if i compare because my my fork is set to compare against micropython by default oh it worked only uh five thousand plus commits different um i think i could do it is fruit circuit python hi mister certainly all right this is better four commits and let me reset the zoom haha christian says nice solution oh here's the story about the pacing timer i almost forgot um uh i was looking in the docks i think it's still in there um but this says there are four timers available on the rp2040 but i looked in the sdk and it only had two so i filed an issue on picofeedback and i said hey like you need to change this four to a two because i looked at the sdk and it only has two and they got back to me with the response that said oh no the sdk is wrong we have four i was like perfect like i'd much rather find the errors in the documentation and the silicon has more than i thought um so yeah i i was pretty excited about that so we're gonna have to i'm gonna have to add a system for like sharing pacing timers if like anything else besides audio pwm io uses them uh because they're a resource uh but yeah gareth asks how close do you actually need to be to nominal 44.1 kilohertz is a few hertz off okay or do heirs accrue um the audio people could probably answer this but i think like the way that i see it is that it doesn't really matter like um if if it's a frequency that we can't do exactly like the closest we get is the closest we get um and what you'll find is that uh like if you're playing a an mp3 that's three minutes 30 seconds long and like you're if we are clocking it like slightly faster you'll just find that it like takes a little bit less time and the pitch will be just a little bit off [Music] and yeah clocking is really fascinating i was doing audio work i did a lot of this audio work i think for the circuit playground express and um it had an issue the sandy 21 christian says if you're close but not exact it will desync over time but sound okay in this case the more important thing will be the jitter and when the samples get pushed out um yeah and david says maybe not a problem if you don't do video and expect it to stay in sync um yeah if you want it to be exact like you could do i think the like the eight kilohertz like 48 48 kilohertz divides exactly um i think so like you could pick a rate that would actually be exact now um cedar grove says sample frequency may be an issue of moving the samples into a digital workstation agree that jitter is the primary concern yeah so i think this so this is the approach that i'm taking for pwm i o or for pwm audio um but we don't need to do that for ios uh maybe that's not entirely true so i2s you'll have my plan with i2s is that the pio will clock uh the data out so there's a divisor there that you can do and that divisor is different that's a visor i think like i said i think there's three different types of divisors like there's this xy one there's one that's like eight bits and four bits and then which i forget what it's for maybe pwm and then there's also one for pa pio which is different as well um so yeah it depends on the divisor how accurate you can get and then the things that you can get accurate depending on what your source clock is and then of course your source clock may not be right either so um when i was doing the circuit playground express stuff what i found is that um the way that the sandy 21 works is that it can operate without an external crystal but the problem is is that the internal crystal is really not that great and in fact the way that the way that it it works well enough to work on usb is that the internal crystal runs and then you plug it in the usb and it actually synchronizes the internal clock to the usb clock to make it accurate enough for usb and what i found actually was that um on the circuit playground express originally what would happen is you could play a tone on the cpx and then plug it in and play that same tone again but it would be a different tone like it was different enough that i could hear it that it wasn't uh the same tone even though the sample it was playing was the same um so yeah i don't think i don't think um i don't think this is gonna have that problem like the the rp2040 requires you to have an external crystal um and so we should be more reliable from like our source crystal out but i thought that was a really weird thing with the same d21 and the way that i fixed it actually is i think this code's still in here um on the cpx i think this i think we only do it for the cpx but what happens is that if we detect you're on usb we actually save the calibration registers of the internal oscillator and then if we have those we use them again later um to make it so that it doesn't change between off usb and on usb um yeah which is interesting so like it's one of those things where you have to realize that you're never going to be exact um it's all a matter it's it's all a game of like how exact do you need to be um yeah very interesting um okay so that's my plan for pwm my plan for i2s is that there's an example that's very straightforward let me just find it saving the crystal registration register yeah okay we talked about this let me close it uh we talked about sleep but that's the yeah the philosophy of circuit python is we'll do it for you we'll have apis for the things you want to do um we talked about basic python talked about blinka pico downloads handy to just have open i don't have it open um what was i gonna i just lost my trade of thought said says some high performance dsp systems use multiple clocks and even jitter reclockers to deal with the jitter problem in i2s clock streams yeah i'm not there's there are many levels deeper than i am able to go here um paul says much deeper and you're shaving quartz with a laser plan for i2s yes oh i was gonna bring up the example thank you uh raspberry pi pico so there's two examples uh directories of for pico there's pico examples and there's pico extras um oh and i have it open it's just not in this one so here's the pio for i2s so it says here transmit a mono or stereo i2s audio stream as stereo 16 bits for a sample you can alter that with the set parameters or you can program it by using set x with the move x and putting it in the y register which i this is what i plan on doing is is using the y register for that um auto pull must be enabled and you do two samples at once um data is output at one bit per clock use a clock divider to adjust frequency so again we're going to be at the mercy of the of the pio divider to to tell us how closely we can get to this sample rate but we don't actually divide down to the sample rate we divide down to the one bit per clock which i think is actually two i think it's actually two clocks per bit um so let's take a look at this pil you have to compensate for temperature and gravity for the quartz as well um okay so this pio and this is the same syntax that we would use for the circuit python assembler which is why i'm glad we did that the other reason i'm glad we did it i was watching the micropython meetup and the micropython syntax for pio does a really bad job at distinguishing instructions from non-instructions um which is uh which is bad instructions versus non-instruction uh because with pio it's important to be able to count exactly how many instructions you're doing and in the micropython format it's all function calls and all the functions look like functions you don't you can't tell the difference in the form via a label um or an instruction so i'm glad we went this way um gara says so this is pio pulling from so yeah so what the the shared bit that we're gonna have to have is we're gonna have a ping pong buffer ping pong dma so um and that's the that's the reason i think i can do ios and pwm at the same time as we need this same thing so um what a ping pong thing is is that you have two dmas and they are uh what you're doing is you're like you're taking that sample stream and you're splitting it into like odd and even or every other buffer so what you basically do is you fill up one buffer and you say okay okay start with that and then while that buffer is going you fill in the other one and then while this one's going you fill that one in again um and that what that means is that you like ping-pong between the two um and so like it gives you if you find something that like it doesn't play well what you do is you make those buffer buffers larger so that you have more time to fill in the other one while you're at it um so yeah so that's so what will happen for the pio or the pacing timer is that it will tell the dma hey i need a new sample the pio has its own buffer of four or eight samples so we'll have some [Music] timing slop there as well um whether we want four or eight is actually up to us um but uh yeah that's like the ping pong buffers themselves is not that hard but the problem is that we have this system where we're like getting the sample buffer from something else like the mixer and potentially what we have to do is we have to convert that format of the mixer into the format that we're going to actually produce or that we actually need to copy things over which i think is pretty straightforward for the i2s case but it's going to be more difficult for the pwm because we're going to do like 10 bit so we actually need to be able to like do some math as we fill in those buffers and that should be shared [Music] so that's the tricky bit the tricky bit is the dma and the keeping the buffers full um with the format that they need to output to whatever they're outputting to um so let's just go over this um functology says can we use the sio in the stream the sio is just like writing directly writing directly to the i o i don't think we need to um you don't wanna set says have you got a dma buffer size limit essentially no um you know a lot of this system was designed for like a cmd21 where we only have 300 or 32k of ram so like the buffers are allocated on the circuit python heap so that that depends on like that will influence it and the the rp2040 has more ram so like you're just gonna be able to make those buffers bigger um which would be really helpful um the dma on the rp2040 has the ability to do ring as well um which basically means that like it can automatically start again at the start of a buffer um but it's very limited in that the ring where do they talk about this i've spent a lot of this week reading this chapter on dma um it's based on it's it you have to have if you do a ring it has to be a power of two and it has to be aligned with the power of two because basically what it does is it just masks like the lower however many bits you have um and i don't think it necessarily like tells you when it's complete either it's something i was thinking about using for uart as well um but i'm not planning on doing that what you can do instead for the ping pong stuff is that you can chain you can yeah so you can chain from one channel to another um yay mark mark built circuit python for the rp2040 yeah it should be really easy it's not like the idf it's simpler than that um so i think the way that the chain two stuff works and i haven't actually gotten this testing but basically what you can say is like you can set up one transaction per channel so you can tell if we just look at like what do you need to know for a dma transfer let's talk about that first so um it's a little small but i think the quality should be good enough if you make your screen big you should see it um so there's there's basically like the read address so this is where you're copying from the right address which is where you're copying to and the transaction count so that's how many times you're going to do those copies it's not in terms of bytes because there's also this fourth register this control register that has a lot of knobs that you can do and maybe but we're diving deep let's talk about all this um so uh yay lucas got their pico that's super exciting um so there's lots of things there but the list of registers is actually kind of handy too so let's just look at that um there is the read address the right address and the transaction count that's not the number of bytes because you can change the data size so if we look at this control register we can see there's three bits for error status um mike got theirs too awesome um the picos are really cool like the rp2040s are really cool um so busy flag this tells you whether like it started and it's in the process like it's counting down transactions um sniffer enable this is something that some dmas have dmas actually have the ability to do um like a crc computation on the data it's copying and that's really useful if you're worried about data being corrupted um is that you can use gma say like hey figure out a crc for this data and you could actually like you could probably copy to the same place and see or see it which would be cool um so you can do like dma can copy from memory to memory memory to peripheral or from a peripheral to memory uh so that's pretty neat um you can swap bytes you can change the way that the interrupts work so t-rex select transfer request select and this is either the data requests that we talked about which are from peripherals or you can see the four timers are here as well and then 3f is a permanent request it just does it as fast as it can so chain two chain two is the thing that allows you to automatically switch from one buffer to another um there's yeah there's that way to do it and then there's other ways to do it um the way that i'm thinking i'm gonna use chain two is that i will i have to allocate two channels so there's 12 total dma channels um so that will be a limiting factor and then um the number of pacing timers if we're doing pwm audio will be a limiting factor as well because there's four um uh so we'll have to have two dma channels one for like buffer a and one for buffer b and then this chain two you chain this gma's channel to the other one uh so that when you finish this transaction it automatically keeps going and that's the moment that you have something that's like oh i gotta fill this one up now before it gets to the end of this buffer and returns back um so that's what chain that's one thing chain can chain two can do the other thing that chain two can do which i don't need i don't think i need it here but what you could actually do is you can actually have chain two like as a meta almost a meta dma so instead of dma memory to peripheral what you could do is you could actually do memory so you finish your buffer you trigger another dma and that dma is actually writing to the dma peripheral to change the buffer that start that that that first channel dmas to like changes the settings of that first thing um so if you wanted to chain like five buffers together that were all like separate pieces of memory um you would actually be able you would have like this meta dma that's like updating the configuration of the first one when the first one finishes which is kind of just like mind blowing and the reason i didn't want to do that is i only needed the two so i can just have the two chaining to each other but if you wanted more than two then you could do this meta sort of thing instead it will be a little little slower to react because you may depending on how many registers you have to overwrite in that first dmas config but yeah it's pretty wild so here's the ring stuff whether you want to treat it as a ring or not [Music] one thing that's very handy and a lot of dmas have is increment write and increment read um this is really handy if you're writing or reading to the same register over and over again so this is really common if you're going to or from a peripheral right like there's one register for adding to the fifo for the pio so like you if you're writing to that you're always going to write to the same address you don't need to increment uh for every transaction um data size so you have the option of like transferring a byte two bytes or four bytes um and it will change if you are incrementing either the right or the read addresses like it will increment them based on that uh that number uh and then high priority and then enable and i'm actually putting on so another wrinkle that i had to think about for the audio stuff is that we our apis allow you to pause and resume and if you pause audio you basically want to keep the same value that you were using if you don't keep the same value you're going to inadvertently cause like sound so that's another wrinkle in the whole thing is figuring out how to pause and resume i think for the pwm side it's very easy because like we have pwm running pretty independent to a pacing timer so if we just um disable dma the pwm is just going to stay the same good night randy thanks for for hanging out with us see you next week hopefully um yeah so that's pretty wild uh so dma is super duper powerful it's a way to do lots of data stuff without the cpu's involvement um tim says yeah inadvertently causing sound is unpopular with your users yeah if you've ever had like your headphones headphones go like or something like it's tricky um gareth says i2s not so easy to pause yeah totally um i was looking at um i was looking at the way that jeff did it for the i2s on the nrf and basically i think what you have to do is you have to dma what you can do is you you figure out what value you're on you stop the dma and then you just like set up a new dma that's like copying that value over and over and over again um until you resume and then you have to figure out how to get back to where you were so um yeah it's gonna be tricky we'll see how well we can do um but yeah it's it's not as easy as the pda pwm side [Music] um yeah tim says we're wired to notice sound glitches even faster than visual glitches hi paul thanks for dropping in you have inspired like a lot of the way that i did this audio work although i'm sure you would have done it better than i would have uh aspiring to to match the teensy audio stuff set says typically wouldn't you just pump out zeros and smoothly mute in and out what's coming from the mixer we don't always have a mixer but yeah we could that's the other thing zero is not always zero because in i2s land it's signed but for pwm and um dax typically it's unsigned so there's like sign conversion that you have to worry about as well um kara says how to choose when you have three ways to implement it good question uh sometimes the first way you do it's the best that doesn't work then you change it later paul says from experience that won't give you the pause behavior you want if you want to go from sound to silence you need to make a gradual transition over several milliseconds 100 eric says fade to zero works too just let the dma buffer run on all data yeah but you have to fade it first yeah maybe maybe the buffer filler just fades it um we're not spectacular about it if if you're an audio person and you care about this stuff and you want to work in c code like we have places you could help us for sure like there's a to do in the nrf that says like when you start up ramp to the like we allow you to specify like a quiescent value which is like the value that you kind of want us to like start and stop at but there's a to-do in there that says like ramp to this value we don't right now so yeah if you're really into audio stuff paul's tnt library is is really good i did actually look at at potentially bringing the teensy audio library into circuit python um but there was a lot of stuff that was statically allocated at compile time um and like arduino has the benefit that it the compiler can do a lot of optimization whereas circuit python can't do that okay i think that's a that's the brain dump of all this audio work um it's not a trivial amount of work so i'm hoping to finish it tomorrow where's that where's paul's library tnc audio i think that's what you're talking about alvaro points out there's an old entry in jobs.adafruit.com for adafruit asking for people who know about filters can't remember if it was audio was the context i think it was i like so pdm microphones are are one bit samples and you have to filter them to get higher bit resolutions and like i just my brain doesn't work well for it um yeah so that was part of the reason is like audio's really tough i i think this is the right link for the tt audio stuff yeah let's do some questions um let's let's do some questions and then we'll call it a day um i'll get back to this audio stuff next week but uh it's friday afternoon slash evening uh if you wanna i i showed the i showed my branch if you do want to take a look at it and no i didn't talk about gpa 15 so let's let's talk about that um but let's handle any questions that have come up here um okay we did that um let's let me do questions first because they're scrolled off i have gpio15 in my list already um johnny says nah it's way after midnight um okay completely unrelated question is there a way to use the usb connection as a usb cdc serial device with micropython i would assume since the replies over the usb this wouldn't work so um in circuit python and micropython the the cdc connection is used kind of for the core um and there is ways that you can get data to and from but the problem is that the core does look for certain values like control c and like immediately follows them um so uh there's no good way dan is about to start working on uh in circuit python having a second cdc connection that is like dedicated to the user uh which won't have that problem um so the way that you the way that you can do it now is what you can do is you can use print to have out over a serial and you can do input in python to read from serial but yeah it's not not spectacular because there is some stuff that um that you can't do okay [Music] paul says the thing about audio is that for every successful feature you implement you get requests and learn about two more to do 100 um i see all the gp 15 stuff thank you for reminding me um let me answer this other question that's not copied in yet i will get to it everybody wants to know what the the deal is um but bader says what are the downsides of the rp 2040 compared to sandy 51 um oh and let me snag this one too from phonology um so one thing that the rp2040 that doesn't do that the sandy 51 does is the sandy 51 is a cortex m04 with floating point so if you're doing a lot of floating point math the cortex m0 or the cortex m4 and the sandy 51 is going to be better um if you're i mean usb is better you have comparable ram like the top parts of the sandy 51 have 256k ram as well um it has built-in flash so with rp2040 you have to have external flash which is not has benefits it has benefits in that like you can have a lot the downside is is that if you have to go there it's slow um so if your code doesn't fit within like a 16 kilobyte cache which is what they have on the rp2040 you're gonna be a lot slower than you you think you are um the s they both have dma they both have a lot of peripherals the sandy 51 does have a digital analog converter so if you want to go to like analog values that's better um but the pios are really cool so if you're doing any sort of digital interfacing the paos are going to be really neat the sandy 51 has this thing called the ccl which is like eight lookup tables full of logic so if you do need to do like very basic like take this pin and end it with another pin you can do that uh but it's like leagues dumber than the pios are um samd51 has more pins if you need a lot of pins the same d51 has more like the rp2040 only has 30 gpio um yeah i think i think that's kind of what i can think of um i think the rp 2040 is going to be cheaper if that matters to you um but yeah it's all trade-offs i think the rp2040 is very clearly designed to be a complement to what you get from a like a raspberry pi meaning that it's like very good at being real very real-time and the same day 51 like i've i i said this in the hack chat it's like i've tried to be very real time with it by talking to a game boy and i i just didn't feel like i could do it that well um yeah paul says m4 is so much faster per clock cycle yeah m4s are just like they're they're significantly faster than m0s but of course you have two m0s on the rp-2040 we don't use that in circuit python but you could do it um badar says oh yeah i heard lamore say about the lack of analog input so both have analog inputs the rp-2040 only has four of them but the arp but the cmd51 has more and then the same d51 has digital analog outputs but the the um the rp2040 does not the evp 2040 does not also have a touch peripheral which the cmd51 and 21 does as well um so yeah it's it's pretty it's interesting right it all depends on what you're doing and what what you need to to be able to do um relatedly mike says do you think the raspberry pi 5 will have the rp2040 is a co-processor i fully expect that um i have no insight into whatever raspberry pi 5 will be but that makes total sense to me right like if you talk about the things that the raspberry pi does not do well like having the rp2040 is a co-processor solves some of those problems like analog input like it makes total sense like i would be very surprised if they did not um davey sorry i'm going a little out of order davey baker says can you be a web server in circuit python yes um it's a very very new code and it is changing still uh but we just added to uh lucian just added the bind except and there's three socket apis you need to be able to be a web server and he added them so on the esp32 s2 you can accept tcp connections uh which is what you need to do that so barely it's not gonna perform anywhere near what uh like raspberry pi would um let's see it's not done but it does i think some people have worked it's being redone a little bit um there's a pr out to re-organize some stuff um but it is in there it's in beta one i think um knowledge you said could you inject ramp pio instructions for the transition i suppose you could i don't know how many instructions it would take but you could certainly like like it does allow you to do like very basic like increment decrement stuff uh listen thank you anecdata um okay let's talk gp 15. and if there's more questions we'll talk we're we're out of time but i don't have to immediately go um okay so gp15 um this is something that we ran into where um gp15 is this pin that is broken out on the pico and in fact is used in a lot of examples in the micropython book but only a week or two before the launch i got i heard this thing from uh more that said we can't use gp15 like there's a silicon bug in the usb that uses gp15 so like it's just a no-go like you can't use it blah blah blah and i was like all right well i like removed gp15 even from the like internal like micro microcontroller.pin and then i was like uh you know i should probably have it in there but i won't put it in board because we can't use it and then launch happens and uh we discover like the day before catney's doing this guide to like go along with the book it's like oh all of their examples use gp 15 even though like our understanding is that you shouldn't um and so you're like all right well like we'll we'll take it uh like we'll add it back and we we did more some investigation and like i asked them i asked the raspberry pi people it was like so what's the deal should we use this or should we not use it um and if you look in the data sheet you can actually see the errata are at the bottom um so if you just go to the bottom i think it's e5 so like the usb device fails to exit reset state on the busy usb bus and then the work around is like there's some debug logic for the usb that's connected to gpio15 um and basically for like just under a millisecond like it takes it over and pretends to the internal circuitry to reset um but the problem is that like if you're using gp15 like it just overrode whatever you're doing with it uh not forever but whenever you need to do a reset then it then is required um so i'm a little bit like i don't like to make it i don't like to take things fast and loose so like i was hoping not to like expose it at all but like it was just found too late in the process and so we've added it back and you can use it and there's this chance that like if you need to reset your usb bus um like it will take over the pin and like not quite like put it back to its own state circuit by then is probably not a big deal because circuit python when you connect to usb will likely rerun your code and when it reruns your code it will reset the state of that pin and then it'll work again so it's not like super fatal [Music] but yeah it's kind of a pain um and so it's enabled i assume they'll fix it whenever they do a rev of the silicon i don't know when that's gonna be uh but for now i guess we're just all playing it a little fast and loose um and you can choose to like not have it there or not uh on on or not i like the fix for it um but i think the case is like your usb never comes up if your usb bus next to it is really busy because the like peripheral expected to see a long delay but like if the bus is busy it's actually seeing a lot of traffic um so yeah that's i think that's the story for gp15 that that answer i don't know who originally asked about it but we should have it now um um [Music] okay i think we got one more question which i think was answered in the chat already which is oh that's not where my notes are what is the best target for circuit python to do ethernet um i've as far as i know ethernet is only done through um the wiznet right now we did previously have like native wiznet stuff um but that uh is being deprecated because i don't want to do it that way i want all our networking stuff to live in the vm because we have so many co-processors that do networking um so yeah that's later said yeah we have to call it too it's been a while um but yeah i know of the wiznet uh if folks want to do the other stuff then that would be awesome um yeah thanks electromaker care all right let's wrap up um one final time code uh thank you all so much for hanging out with me i know that these streams are long um but we spent the first hour answering a bunch of questions um let's see oh yeah this timer is ahead of even my time here um as always this is deep dive it it's this deep this long every week fridays at 2 p.m pacific uh here on the adafruit uh streams uh if you want to hang out with me and others and have questions in the interim you can go to the adafruit discord server people will love to help you out there you can go to the url adafru.it discord to check that out and get some help we do circuit python development there we answer questions there i recommend it we have discord for the chat here as well next week will be on friday again if you want to support me support adafruit by going to adafruit.com purchased some hardware there i know we've i think we sold a lot of picos which is great really helpful and we'll have some board designs of our own once we have the chips in hand and [Music] i don't know i don't have a housekeeping list at the end but yeah in a couple hours i'll have all the notes and the time codes in the description as well uh but for now thank you all we'll see you next week and see on the discord in the meantime if you if you have a pico and haven't tried circuit python please please do i think you'll be very pleasantly surprised uh and if you know people who haven't tried it also ask them as well you can go to circlepython.org download search for pico and you'll see it there in the list works for 100 and some odd boards as well let's see what is our account 173 boards so we'll probably bake 200 when the rb2040 chips are available um anyway thank you all and i'll talk to you next week cat cam thank you all right good everyone
Info
Channel: Adafruit Industries
Views: 6,171
Rating: undefined out of 5
Keywords: adafruit, electronics, diy, arduino, hardware, opensource, projects, raspberry, pi, computer, raspberrypi, microcontrollers, limor, limorfried, ladyada, STEAM, STEM, python, microbit, circuitpython, neopixel, neopixels, raspberry pi, circuitplaygound, nyc, make, makers, micro:bit, adafrit, adafruit promo code, ada fruit, adafruit coupons, raspberry pi zero, micropython, machine learning, ai, tensorflow
Id: WS64J3BTBj0
Channel Id: undefined
Length: 137min 54sec (8274 seconds)
Published: Fri Jan 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.