 Oh, if you're just starting to watch the stream, make sure and check, well, if you're not watching the live stream, check the comments for time codes. We tend to go about two hours, so it's great to look at time codes and skip around. We're going to take a little bit of time to get going here. I just need to adjust my camera. I shifted everything on my desk a little bit, so I'm going to have to figure that out a little. I'll say hi to folks in just a second. Hello folks. Oh yeah, I was just moving, moving them or I don't even remember trying to keep this room a little cleaner. Vin was actually in there earlier. All right, so Spook's like, oh, it's time for the stream. Maybe you'll see him just a second here. Hi David, hi River, hey Mark, hi Johnny, hey Bruce, hi Piata, hi Randall, hey Dean, hey Bradley, hi Hamslab, Bruce again. Yeah, I think I have that cat thing turned off in Dino. Hey Gary, hey Alvaro, hey Doctor, I know you're missing it anyway, hey David, thanks to David for taking time codes, I assume, since he's here. He's doing that. Oh, let me pause these playback streams and we'll get going. Everything seems to be working, well the overhead's not working, but it's not critical for what we're doing today, I don't think. So what I did is I got these C clamps, so I'm actually, you may notice that the view is a little different, it's because I am sitting further back from my desk because my keyboard's now on like camera mounts and so I've got to adjust them, haven't found like the perfect setup yet, but hopefully the hope is that I can like sit here and have my kind of keyboard where it's most comfortable for me to sit. Oh and did Spook, oh yeah he's in the cat cam, he's doing his part, oh and Mark says yeah you made a soldering desk behind me, I did, yeah so I used to have all the stuff in the laundry room which is the next room over and we decided that I would consolidate everything into here so that we would have more room outside this room. So that's, it's a huge mess still. This is like, there's a big pile right to my right that's all Goodwill stuff, so yeah it's a work in progress. Work in progress. Okay let's get started. Hello everyone my name is Scott and I work for Adafruit on CircuitPython. Adafruit is an open source hardware and software company based out of New York City. I work in Seattle so I'm remote for them and I work on CircuitPython which is a version of Python designed for inexpensive computers called microcontrollers. I'll show an example here, here's what's called a Clue. It's in a microbit form factor, it's got a screen instead of LEDs and then on the back under this metal thing the microcontrollers under there so they're really small. This runs I don't know $20 or $30 tops so it's like very inexpensive, easy to get into. So that's me, if you want to support me if you like this stream go to Adafruit.com and buy something. We had a really great crew, last week we sold a lot of macro pads which are microcontrollers are really common in other things so here's the macro pad that we made last week that I still haven't set any software up on but there's a microcontroller in here that acts like a keyboard so you can program the keyboard to act however you like. So yeah we did that Adafruit.com, if you want to hang out with me and others in the Discord chat which is this way here you can go to the URL adafru.it-discord so check that out we're there all week so it's a great way to hang out with us and keep tabs of what's what all is going on. So this is a deep dive that happened regularly on Fridays at 2pm Pacific which so this is a normal time stream occasionally if we're taking just a long weekend then we'll be on Thursday at 2pm or I might cancel all together but yeah this is a deep dive and it's about two to two hours or so long so if you have questions about anything related to electronics I'll do my best there's also like folks that are in the chat that are really knowledgeable as well. So yeah I think next week I forgot to check next week I think is fine if you want to get notified if we have any time shifts there is a Discord role called Deep Divers that I'm happy to add you to and let me know in the comments or in the chats if you'd like me to actually like ping Deep at Divers when we start streaming I could do that as well. So the last piece of housekeeping is the kitty Spook who's there in the window if I got a cat cam he loves to lay in the sun that that is Spook he is epileptic so occasionally he has seizures he's been doing really good so I doubt it'll happen but if you if I'm on stream but not talking I'm watching like somewhere else it's just me making sure that he's okay but he's been doing really good so I don't think that will happen. Okay Deep Divers joining yeah Yanni you're in there already Paul Darkin weirdos watching my email for macropad to come back in stock or the product focus from that camera yeah so what I wanted to show off today is as you know I've been working a lot on and I'll say how to Justin to I didn't say how to Justin so the main thing that I've been working on is I've been working on being able to transfer files over Bluetooth so Bluetooth is a wireless protocol that's commonly used for headphones like largely headphones but oh and there are eight of boxes available to people want to get an eight of box it's a great way to keep up with our latest products so Bluetooth is a protocol for doing low kind of bit count transfers over Wi-Fi or not Wi-Fi wirelessly not Wi-Fi though Wi-Fi is a separate protocol so what I've been working on is the file transfer stuff and then what I was working on kind of in the last week or two was connecting the REPL over the serial link so that was just merged in I did both of those PRs and Dan was like they look fine I don't know how to test them and so that comes to the the real question of the problem with Bluetooth is there's no standard file transfer format there is a standard UART service which we could actually test here so the way that I think I can test these things is in Chrome and go to the desktop and if folks have questions feel free to ask them I'm just like my brain's kind of in this stuff right now DCD says are you going to refer the reverse engineer the Bluetooth clock no I'm not I'm not planning on doing that if somebody knows how to get it to be 12 hour and 20 instead of 24 hour that would be great but I can do the math if need be it's just been really nice especially like in the last week we've had a lot of heat so it's been good to good to see how hot it is in here like on Monday it got into 90 and got to 95 in here whereas it's only 81 now so it's a lot more comfortable okay so web Billy is a spec for talking to oh I'm spoiling it it's a it's a spec for talking from a web page to a Bluetooth the energy device and what I've been doing is so this is totally spoilers but so on my desk I have an Android phone here and so I think what I can do is I can mirror what I'm seeing on the screen there it's not connected up so one thing that I should note while I'm here to in order to this work there is this experimental API there is it you so you need to go into Chrome slash flags and enable experimental web platform features and use the new permission back end what this does is allows the web page to say like hey what devices have you previously allowed me to connect to so there's this microdive web Bluetooth maker diary maker diary maker diary serial there's a maker diary serial console that they have where is it sorry I did not have quite as much time as I usually do what to get set up let's see what this does this is Python Bluetooth Bluetooth Bluetooth oh maybe I have it on here I already went to my CLI that's what I ah okay so let me I think if I do Chrome devices Chrome inspect there we go pixel 3a ah so here we go so this is a mirror of what I'm seeing on the Android here so if I say I'm printing stuff out and it's not showing so you're not going to be able to see everything on my screen but what I've got here is I do have a a feather and zero express plugged in and it's blinking and it's running something close to what is something close to what is checked in if we hit connect you can't see it but I got a list of devices and I can click the surpy one and now it's connected so I am now connected to let me make it bigger if I can so from my Android phone which is plugged into USB I'm getting the repel so if I tap here and I say print hopefully this works still so the the space below you can't see is the there's a keyboard on the screen so all you're seeing is like the web page you're not seeing any of the like Android stuff around it but if I hit print hello it sends over Bluetooth via serial to the device and it did the repel now unfortunately there's no way in this repel to hit control D although maybe we support was it quit is that doing anything no I don't know what it's doing is there a way to get out of the repel but I don't know quit quit quit is not I haven't actually played around with it so this this is showing that the repels working name quit is not defined exit okay I remember somebody enabling it no that doesn't work either I think there is a sys exit what if we do import well so this shows that the serial over Bluetooth it's working which is good I don't know I'm hitting enter and getting sys is back which is not correct but if I delete everything I don't know whether the issue here is circuit Python hard reset yeah I could do that this isn't the really fun stuff though like it's not sending returns if I hit enter not at the end of the line oh I hit a space let's try to import so this is just using a terminal edit there we go if I add an extra space space enter sys exit doesn't work either so I can't do alt f4 because I'm on like I'm on an android supervisor.reload we could try that import super there's no tab either is there it's really interesting to see space enter does that work from repel no it doesn't either term you later yeah Christian Patrick's is exit as well well sorry I don't know why it's not working there might be third-party can keyboards that have a control button on it if you're interested in installing something else for it no I'm not really this is this is using a terminal called hterm and I do want to use it but generally this is just a web page that we don't control so what I've been working on is let's go to this I've been working on let's go straight to the punchline so code dot circuit by done org is looks really really terrible but this has just been my like test page microcontroller dot reset I mean I have physical access I could hit the reset button which I certainly will probably will have to do but what I can do is I've already paired with it so actually maybe the first time I think it might be running oh no GDP crashed oh I could get out of it using USB as well see that the cat was circling me so what I'm what I can do is and I should show this so this will probably crash but it's white now because we're in the repel so I'm what I what you have to do if if your board has USB as well you have to prompt it to start advertising it won't won't advertise and unless you explicitly wanted to so you hit once and then it goes yellow and then it goes fast blue and when it's fast blue you hit it again and then when it starts up the second time it should be like solid blue so now it should be it should be broadcasting publicly which means that I should be able to well on my Android I think I've got to forget it but we can try so I'm going to hit request Bluetooth device and unfortunately you can't see this because it's like part of Chrome not the web page but it's showing I guess I could pull it up so it's saying do you want a pair and then it's called sir pie because I don't have the numbers working so I'm gonna click that and hit pair and now you should be able to see what happened so the two buttons great out here and then I can hit bond and it's prompting me now that I want to pair and connect so all oh I missed it oh no let me hit bond again let's see bond no I lost it let me reload request device after it's paired you can click this connect to Bluetooth devices so that's what I just did and so it's now now connected now I'm gonna hit bond again and it prompted me so I'm gonna hit pair and connect and then pair and now you can see that it's going so what's happening here so the read what I have is that I'm using the Chrome dev tools I was like I've been doing a lot of debugging in the console output of the JavaScript page and so that's what's happening on the right hand side and it turns out this is the way that you do it for debugging Android so I have too many cables on my desk sorry I tried to get the overhead working but it wasn't cooperating so that's why I'm holding stuff up okay so all of this on the right hand side is all my debugging output me making sure everything works and stuff so what on what is on the left here is actually it's a mirror of the page as rendered by my Android that's connected over USB for debugging and let's see the other thing I want to show is here so here is this and so let me just change let me scroll up or click up so now that it's like only the top half that's because the keyboard is showing in the bottom half so if I delete this smiley here and I pick another smiley like this one now it's saying it's not defined so what happened is all I'm doing is I'm editing the code in the web page and there's a delay timer that's preventing it from sending out a bunch but yeah so let me fix this so that was the wrong place to do so I'll do that this is the first time I've used emoji as variable names which I think is actually quite wild so it just updated and it got this little so it's a bunch of prints and it just printed out the person with the party hat and playing that so what I can also do is if you want to see something more dramatic let's say I want to delete like I was like doing it like a pro last time so I'm not just gonna delete all of these and we'll see that it transmitted and now they're not printing out so this is very very cool I don't know if you can appreciate this but it is editing code from a mobile Android phone straight to an nrf device and it's also showing like all the smiley face stuff is fun because it's showing that so now we have 10 of those yeah so this is all using a browser so I was actually I started developing this on my Mac from Chrome I don't I haven't been able to get it working on Linux Linux I don't think has the persistent stuff but yeah so this is editing code from your phone like if I change let's change to a different emoji hundred percent so we got ten hundreds now so one thing I want to do on this page as well it's it's gonna be made a lot nicer but this is just the proof of concept and then I also want to do a serial terminal on this page as well so you'd be able to see all of the output what would the difference be with Linux it the thing is that it's it's Chrome's implementation yet to whatever like the OS provides for Bluetooth so they have to have different backends for the same API for all the different OSes so one thing I found was I was doing it on Mac first and then when I got to Android I couldn't write more than like 500 bytes at a time I actually have to write in 20-byte chunks which is unfortunate it means it's slower but it still works then awesome so yeah so if anybody wants to try this it's live could something like this be replicated using BLE CLI tools in Linux 100% yeah yeah so if you wanted to get it working in Linux the way that we were thinking is there's already a circuit Python library for it that's like the thing I did before everything else so give BLE file transfers the repo so this is the protocol definition in it and you can see like all the different like pack packets and stuff that are being sent back and forth what you could do is you can use Blinka BLE IO ideally with this library and that would give you in here there's like this in 80 fruit file transfer there is a the service but then also the file transfer client so the client just says you can you can say like read a path starting at an offset write a path starting at an offset that sort of thing so if you wanted to make a CLI tool you could definitely do that and and we will the thing that the unfortunate thing about all of this is like it's checked in but there's just like every system needs its own implementation of the same thing so if you want to see the code for the web editor it's in this circuit Python web editor repo that I have just been pushing directly to you and they go to it goes straight to code.circuitPython.org it's very pretty simple but I already did make a package an NPM package for doing the for doing the file transfer so now there's this Adafruit BLE file transfer thing that's too big oh that's really big so in here you can see that there's this Adafruit BLE file transfer stuff and there's a file transfer client for JS as well unfortunately well I've only implemented a read file and write file I haven't done like delete or list or make directory but those are these are the toughest ones so right now code.circuitPython.org is just hard-coded to do code.py I'm pretty sure that if it works in Chrome then it should work in Deno as that's v8 under the hood and they're making the JavaScript isomorphic yeah I don't know what Deno is that sounds cool though anyway I think this BLE stuff is really cool and I'd love to hear if it works for you I haven't haven't tried it on Windows yet but the the writing 20 bytes of file should be pretty universal there is a safe mode crash from allocating outside the VM that I've been hitting off and on that I don't know exactly what it is so that's that's in the code still though too but yeah this is a coding with emojis over a BLE you can see the output it's a lots of 100s it's a hundred hundreds and then if I just bleed it it sends it over and then I get 10 so one thing I was thinking about is that in circuitpython normally you have to hit save but because like we could add a save button to this page but also like I this timer is kind of okay to me it was I had to do a lot to make it a bit more resilient but so far it's I or I've gotten it to a reasonable spot now so let's see oops one thing it would be nice as if so the editor that I'm using is called code mirror and code mirror oh sorry they code mirror does structural parsing it doesn't just tokenize it actually has like a tree structure from parsing so it would be nice if it would be able to tell me like syntactically whether it was okay or not oh interesting oh dino is like no switched up nice now we have a 10 by 10 monaco editor which is used in vs code one thing that I liked about code mirror is that I'm using code mirror six and it's like pretty new but one thing they say is that it's better for mobile so if we pull up code mirror six like code mirror itself is actually used in a lot of places but it has like touchscreen support and it's accessible as well so like it's better designed to be better for screen readers to so yeah that's why I went with code mirror yeah so one thing I was thinking we could do on the stream today is I could either try to get the serial terminal working on this page or I'm not like a great HTML wizard does code mirror handle Python stuff and circuit Python stubs not natively but it has a plug in architecture and River who is kind of some of the inspiration for this along with just the fact that like we needed something to test Bluetooth against River was looking at doing that earlier today so yeah we could definitely expand to this editor to be better for circuit Python but I'm not I'm not a great JS HTML person so if folks in the chat are better at it than me let me know I'll bug the learned people too it's just it's a holiday weekend this weekend too so let's just because it's exciting where's to da I love the to dole and of course I don't have a pulled up so yeah that's give it a shot all you need is the absolute latest version of circuit Python that you can get from Amazon as three via circuit Python org slash downloads and then also you can you need an nrf board nrf 52 840 board to load that on but then you it should be enabled you shouldn't have to rebuild it or anything ah Aaron says Monaco is great for mobile to and also has syntax highlighting for many languages built in yeah I haven't looked at it I just I would I would be happy I would be happy to I would be happy to have somebody switch it it's I haven't spent a lot of time this has just gotten me really far although one thing I wanted to look into was ideally we would do we would be able to do type inference so we'd be able to autocomplete kind of more intelligently and code mirror has the ability to do like better structured parsing rather than just tokenization so I'm not sure how Monaco handles that but yeah I'm open to it like clearly you all know more than I do about it so one thing I could do is the serial stuff yeah stubs are live currently on pi PI yep thanks to phone the guy for that but naredoc says now to test it on the micro bit v2 so that was the other thing I was thinking I could do on the stream today is actually get it going with the micro bit which I think I will do because I don't know a lot of don't know a lot of JS stuff but yeah I'll keep working on the the library like a lot of what I do is I lay the foundation I don't I don't leave a pretty I just get proof of concepts going so folks want to help make this code dot circuit by fun or not terrible then please let me know I was more looking to figure out whether it could be done at all and it looks like a can so one one thing that I was worried about is if you look in here when it writes the device actually disconnects so here's a right finishing here and then it disconnects and then the sync starting says like so what we're doing is we're sending we're sending starting from the edit to the end of the file every time we edit so it'll be slower to edit the start of the file than the end of the file but that's kind of what the protocol allows right now but I was worried about all of this reconnect stuff and it's actually working pretty good Tony B says there is some code out there to use antler with Monaco since antler can generate parsers in many languages including JS and java script and type script yeah I mean this there's already a parser for Python for this for code mirror so we are getting syntax highlighting we're just not getting like type specific information but yeah I'm trying to build all of the libraries so that whatever in whatever language you want you can do file transfers over over Billy okay so let's do this micro bit because this will be the first board that's Billy only and this is one of the reasons I'm doing it so here's a micro bit it's version 2 not version 1 that's the back there's the front version 1 doesn't have enough RAM really to run circuit Python Mark says this will work in 6 3 or 7 alpha 3 no you need like absolute newest you alpha 3 is too old as well you can use says I love Billy be Bluetooth classic used to make me want to rip my hair out but Billy was really simple awesome yeah and it's I was just thinking about this today too like there's a there's a spec for file transfers that they had that the Bluetooth organizations kind of floated but it looks but it uses the lower level thing called the link it's thinking of the link there but it's there's a L2 cap like there's a protocol under Billy under Billy gap that that uses I use explicitly chose not to do that and as a result like web Bluetooth can work for this which is awesome that's how you know we're in a deep dive of alpha 3 is too old Dan was talking about doing an alpha 4 like today or tomorrow and it did get merged in so basically like both the file transfer stuff and the serial stuff is merged in I'm sure there are bugs still but River says what I did is to modify the Python mode JS file for code mirror to have circuit by done highlighting I don't think in my client I have any changes let me look I was just doing some stuff to debug here kid status like I just have this one thing changed let's add micro bit V2 oh we got a new stage module micro bit V2 good you can see me I was just thinking did I switch my screen over yeah so for all you JS folks please help me make this site not terrible what River showed River did a separate editor that was on the forums I definitely credit River for it first like kicking me over the line oh I haven't done forums today I should do that I do know I know it's on here zero setup one stop yeah so this is this is partly my inspiration here oh and that looks nice nicer than before but this is all designed to use the file system API and the web serial API so this is for if you're plugged into USB so I want to like merge the two as well which would be really cool so you can just go to code dot circuit by that Oregon it could say like are you doing Billy or USB and it would be the same experience for both of them can you tell what I got up really this morning so I'll keep working on this and get the other stuff if you know something oh here's here's a question for the JavaScript people do you know a good library I could use for showing a file higher hierarchy because I'm I'm gonna do list directory make directory and delete directory or the other three commands I think it's all need to test those as well but let's do micro bit V2 that's what we're doing so we only have this one file change and we'll just include that that's okay and then let's pull it are here so yeah if folks get this work and let me know make sure you do do the the two chrome flags as well okay so in circuit Python we're going to copy I want to cop I want to start with so the the chip that's on the micro bit is a NRF 50 to 833 which is like the 840 except it has flash half the flash and half the ram so what we're gonna do is there's two in here I think that we build already there's the PCA 10 100 and there's the simil as well so I'm just gonna duplicate this and it's gonna be the micro bit P2 no that's P2 the awkward moment when I don't remember to get the RP 2040 connect back into bootloader mode so that won't work with this if you're trying to do this demo the the connect the RP 2040 connect uses an external Bluetooth device which is not the same as having a native nrf so this demo I showed will not work with the external at ESP 32 although one of the things we will we do want to do once this infrastructure for for the workflow stuff is out is we we probably want to do ESP 32 support so all your old ESP 32 boards will become Billy only circuit bytes on boards okay so let's do this and yeah web docs file system is experimental but support on Chrome and Firefox etc yeah so web Bluetooth is Chrome only it's not even on Firefox reduce the nrf soft radio memory usage I was one thing I was thinking about is whether we would actually be central at all but I know one thing one thing we can do is we can turn USB off we do need to do the internal file system which is unfortunate but the micro bit the chip supports the chip supports USB but the micro bit doesn't have it connected which is really unfortunate creator so this is for discovery over Bluetooth and micro pie Harbor LED status LED TX RX let's find a schematic for the micro bit meet the new micro bit what do we sell them for to the bundle is 20 oh they're $18 a piece it's a lot the original was like seven I think yeah UPS attempting to misdeliver a parcel here is that what the sound was there a UPS person did goodbye or is that just coincidence hmm apparently they're $18 oh nice let's see is it the tech website schematic schematic hi Randy no worries it's blank there's nothing on there right now I'm trying to connect to the Bluetooth clock temp humidity display oh I ended up installing the media temp app for it a circuit playground blue fruit should work here we go interface LEDs LED USB LED power is that it there's no status LED what are they connected to I guess there's an LED matrix I got I got it target MCU is it just the LED matrix that it work and I find documentation on Adafruit PIO ASM the language or the library like isn't it just yeah if you go to the repo and then if you hit docs passing it will take you to the thing and it has an example use if I wanted to make sure that I always have the hardware on hand for what you're working on during deep dives is there a way to do that Twitter you're you're not giving I don't I don't really prep for this but if you wanted you could just bug me about it on discord ping me ping me on discord and ask what what I'm thinking so the language here is this this bit for the PIO ASM is exactly it's exactly the language that is documented from Raspberry Pi so it's the same it's the same language that you would use with their like PIO ASM stuff it's no different than the the one that you would like use to generate C code or whatever so you would want to look in the like Raspberry are the RP 2040 docs for that it's no different it's it's not gonna support everything but it's what it does support it's gonna be the same button you art so we don't really have a status oh so there's both rows and columns oh they use it for light sensing too that's clever well this is unfortunate I don't think that there is a great status LED besides the matrix so we might need something a bit more custom to get a status LED so the LED power is out of the interface and LED USB so we would have to we would really want to do like something custom like I think that's what they usually do is they actually use the grid to display status information so let's just ignore that for now it won't be obvious but so let's see let's do pinout while we're here so what do they call the pins on the micro bit here we go so there is P1 P0 1 2 no oh there is a 3 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 just done a neat keypad on a one pin of a micro using an ABC and a resistor ladder nice yeah near doc says like scroll Bluetooth on the LEDs maybe we scroll maybe what we do is we scroll like the last line of the repel or something right Rackford says you could draw scrolling text on the LED matrix for the most complicated Python prompt yeah we could just do like the last line of text that's been output that's an option that's a lot more code than I care to do today but I'm mainly just wanting to get the so through 16 right and then what's the multi select it's like this no I forget what am I trying to solve what what I'm doing right now as I'm trying to learn how the micro bit references the pins and then mapping those pins to their internal names and then I think what we should do is for button like we just model so our policy for how we name things and this is what ends up in the board module in circuit Python and the policy is to match kind of how it's documented by the board creator it would be easier if I was using my full screen but I'm not oh you know it looks like no caller so it is connected oh it's up through it's 16 and then 1920 which are also SCL and SDA we definitely want to define those because those are those are the names that like we'll use for I squared C so rings are let's look at see they don't call it by their peas here there's got to be a edge connector that's a beautiful diagram without labels test point map nice oh look it we can make a thing that touches the USB lines I'm surprised that where's their zero one two they really don't have like a anything thank you edge connector pins ah this is what I'm thinking thank you Nerdok you read my mind this is who boy do they have a v2 created by those pimeroni folks okay so we have that this gives us all our names and I squared C let's just start figuring out the pinouts here so 20 is SDA sorry my keyboard's in a new spot which is slowing me down so if we look here motion sensor back that says this might have been asked before I joined but if the micro bit v2 doesn't expose usb how does one install circuit python onto it does it have a bluetooth enabled bootloader so it does have it has a separate chip that manages the main chip and that the usb is connected to the management chip so you can load circuit python onto it over usb but that usb is not to the chip that would be running to circuit python would be running circuit python so you would get no circuit py drive I don't know if the bootloader is bluetooth enabled it would be nice if it was but I haven't looked but yeah it's kind of this weird case of like you can load circuit python over usb but you can't use circuit python over usb and hopefully I'll show that so what which ones are these SCL is 026 and 010 0 is SDA 26 is what I said that's right I don't actually have to get this all right I could keep going this is actually just most of the work it's getting this right yeah 26 is right all right let's it would be way quicker if I was not having to flip back and forth here let's just assume that's correct for now drop a note saying like to do update this the usb chip is connected to serial making it suitable for repel access in micro python now oh do I have a baby this is my knee I don't sit at my chair like I should that's just my knee sometimes I have a cat on my lap though playing around with the moment we allowed repel access over that though the moment we would like people would want to transfer files over it I'm telling you bluetooth it's the future so they could have integrated a usb hub to connect both chips like maker diaries nrf 5840 and decay has yes they could have yeah but they didn't okay and then the main question is like how will we actually know it's working but let's just give it a shot make no debug a bit also sitting with bad posture yeah okay so we got some errors so I tried to fix these creation ones so the creation IDs are IDs that are broadcast over BLE to recognize to ignite to state what board it is and they're meant to be a super set of usb so if the board does usb as well it will reuse that circuit by console BLE I thought I got rid of that I thought I called it serial supervisor serial do I not am I not based on the latest thing now this was merged today and there's my ad serial over BLE which should have deleted it so why is that wrong I'm gonna see if it's oh no no it's insured yeah see circuit by serial BLE what is this oh this is in oh this is you aren't this is an artifact of it not knowing yeah we're gonna delete this delete this is the first time I've done this is the first time I've done a non USB BLE only build Greg says we could reprogram the KL 27 to provide file access to a sure it wouldn't be pretty I don't really want to reprogram that coprocessor because then it would make switching to micro proper micro bit and back like way more difficult I don't know what is our people not excited about having file access over BLE like you should be all the toolings really young but a year from now it's gonna be like why do I have to use a wire okay so I think the problem is it's supervisor we say oh USB supervisor shared Bluetooth serial if circuit pie USB is zero well I deleted the file and that made it make sense wagon load says I've been trying to figure out how to send data over laser is PWM the way to go I imagine imagine you want to do like just you could do just you art because it encodes like as long as you decide the speed the ship who says there's IRDA but I would probably try to do you art right where you have a photo and my brain went to MIDI MIDI is like it's over a wire but there's a isolator so you end up with a light like there's a photo well opto coupler and in MIDI and so you could think of the laser is like that opto coupler in MIDI I mean MIDI is not very fast so that's another problem but okay so here's this if storage enabled in supervisor shared Bluetooth transfer supervisor shared Bluetooth file transfer if circuit pie USB MSC didn't account for USB completely being completely off yeah the ship who says you are it should be more straightforward undefined reference well you're getting a deep dive so nrf supervisor port alright I'm moving this off-screen so I could look at it task event ready 392 if look up FSO free space optical immunization communication not immunization I thought you were like immunizing the optical data from the air or something undefined reference to USB HADs GC collect this is good this is the birth of USB less circuit Python which is exciting huh I think what we should do is in pie USB it's essentially what SpaceX is doing with and I think what I'll do is I'll factor these out for consistency this if hasn't highlighted am I doing it wrong I think it has to be like if equals or something a lot of questions today and I'm not talking very much it's kind of hot in here you know the windows are open okay oh building again oh you know what we need these as well but you know what I don't even think I need I'll take any of that I think I just need to change the ones to depending on actually no that's not true because I that should be fine thinking about like like should a board be able to rep override like no that's just a misconfiguration so we just default these to circuit pi USB like if you explicitly turn on any of these and you have to also explicitly turn on USB make it's been enhanced since I was fluent with it must read about it it's just the way the way that micro Python is using it this doesn't surprise me we have to run this stuff down but USB HAD GC collect is what we were looking at earlier but I thought it was that it was gated correctly 862 I switched it yeah see maybe in our board death we're accidentally turning it on we just need to clean and rebuild if you're ever developing circuit Python and the build doesn't work it's always a good idea to do a clean and then try it oh that's a lot less undefined reference to storage enable USB drive it's in shared bindings I think here's a question do if you call USB enabled disable what do we do if USB is not on in the build do we raise an exception or do we silently maybe we'll raise this cannot change USB devices now let's do exactly the same pattern that we did before except this time we'll default default so if circuit pi USB msc okay is equal to that why are we doing this here I feel like we shouldn't be doing this here we should always have those let's say oh it's in that function undefined reference shared modules storage if circuit pi msc here we go let's say else and then it's if we return false it will say okay so we just return false in here I think in general it's better to raise an exception then silently assume that we did the right thing close getting close the only thing we don't have now is serial write substring why is that that should be from supervisor shared serial supervisor right right substring it's right there but maybe we're not doing this shared version like our make like maybe we're in here if there's no supervisor serial then we use the stub otherwise we don't why is that we don't want to use the stub if not circuit pi USB otherwise you can't raise an exception from boot up high you can it'll I it should output to boot out dot txt and in fact micro python just if you raise an if you get an exception in boot up higher in micro python now it won't run anything else which I think we should do is to we should do too where do we pull in oh here we do shared serial here's what I think let's delete this stub serial and if yeah we'll use supervisor serial if it's provided so we're gonna get rid of stub serial let's just say that's right David were you asking me about NM I'm not sure why you're asking that I clean again these are all the places that USB stuff leaked into things these are all in live tiny USB and we overflowed in function serial connected in shared serial should be oh maybe we don't we don't successfully guard it that doesn't make much sense does it can you do something like a trace route to find where USB is called I mean I I think that's essentially what the linker is doing like the linker is telling us like the file that's calling something that's not available the linker error message might have pointed to where the error undefined write substring was it it didn't tell you where it expected to get it from though so I think the subtlety here is like USB CDC is not controlling whether we do CDC at all oh AG yeah okay I think that's right I'll get us closer should I go into more detail about so the the compilation process is it compiles it takes every individual file and it produces machine code for each individual function and then the second step is what's called the linker and the linker saying like this code here said there's a function called that and I'm looking through all these other files and I don't think I think that end if should have been an LF here it'll be fine it's okay and we're overflowing well last but one one you can do my review and tell me supervisor workflow reset this is a chance for me to use old IBM's actually had this syntax check compilation and linking as two separate steps supervisor shared workflow oh maybe I'm here we must not have anybody that's doing their own serial handling but I thought that they um this presence did so this is the escape hatch if you don't want to use tiny USB for your serial you can't provide your own serial instead well bummer it's too big it's too big even though turn some stuff off so let's take a look at the map file and see or you know the other the other trick I like to do is the first step my mouse is too far away from me so just saved it so that a file has been updated and then I do v equals 2 and it prints out the full command which will let me look through all of the things that we are we have enabled so we're doing how big is too big we're like 1800 bytes over 818 80 which is why I was thinking about making it peripheral only so Billy can has these two roles central is the thing that scans and initiates connections and then the peripheral is the thing that advertises and can be connected to so like your headphones are only ever peripherals but your phone can be a peripheral or a central and circuit Python devices right now can be both as well but one thing I have in the back of my mind is that we for the ones that we need a lot of need that room the we could turn it off so that they can only be peripherals and we could even be we could more specifically be we could even make it so that like only circuit Python itself can use Billy so like Billy IO would be gone completely for example if we if we wanted to do that we could that's an option so we don't have alarm which I actually imagine we would want alarm we don't have MP3 we don't have been ASCII so what I'm doing is I'm going through these so we do have Billy H Billy IO and we have Billy file service using NM we have board we don't have bus device we do have pow three yeah what is pow three I don't even know bus IO no camera no can digital IO go to save space no frame buffer no vector IO no MPY native yes air no no JSON no keypad no math no memory monitor we have microcontroller no pixel buff no ps2 IO do have pulse IO in PWM IO and random no RE we do have rotary IO we do have RTC serial Billy storage struct supervisor synth IO terminal IO touch we do want touch no USB I'm surprised USB didn't save more space like I think that's the first thing we should check let's just make sure oh look at this here it says circuit pi USB HID is equal to circuit pi USB so it's possible possible but well no it's probably okay that's certainly not right we should fix that but sounds of sea planes landing on like union yeah probably they do like to fly over us it's three argument math up how yeah let's turn that off let's turn that off first this is the make it fit game we could also make it slower and then I'll fit dollars your kid Python USB you're right let's do a voice device would be nice to have open still I think it doesn't need prints do I think it does I'm gonna do a clean I was hoping the USB stuff would help it's your USB slash Bluetooth a subset of something else so you can access it through another doorway not sure what you mean lag loads some of those subset of something else I can run make clean all then I delete everything well we got like 500 bytes back that was probably the POW though but now we can do the same thing and save a file and make it again the v2 I'm actually quite surprised that it's not a subset of port I still don't know what you mean oh they clean and then all which is the same as make I see let's see did we fix circuit pie yeah the USB CDC thing we fixed there's no file system which is part of the problem I kind of want to just do is there some flash size configuration I don't well it it's per it's for the specific device so I think it's right like this is not the first board with an nrf 52 833 I kind of do think some of these things we're gonna want to well I have a couple tricks up my sleeve here one is that we can take a look at what the symbol does the symbols on the same board and they do these three optimizations as well so we can do those for sure and that should free up enough for us to build no I don't think it's unstable I think it'll work something he's using a lot of overhead so if you can access it going through a different path that doesn't use the overhead I mean the overhead the thing that uses a lot of overhead is like all of the circuit pipe on mechanics and that 833 I think is 256k flash is that right or is it 512 it's probably 512 52 833 it might actually not be okay so it's 512 flash 8182 kb ram and how much of that flash is used by different things so this built and see it with dash s now we have 21k but here we can see that the flash firmware has 237 so 232k which is not a lot that's significantly less let's find our linker file our linker file is going to see on nrf 5840 the first 64k rams 8 blocks so can you link your script for the 840 with 6.0 soft device how does this get built make file and Dan did this flash with debugger flash with dfu really common dot template that LD is usually like a LD defines here we go fake source to capture values circuit pi firmware start address so what we should be able to find in here is a in our build micro bit be to there's a common LD so entire flash is not right 512 times 1024 yeah that is right 512 k I wonder if that works flash nbr flash firmware look at all that math Billy config nvm so you get our Python out the Billy stack is huge yeah that would be my expectation what is that magic optimization and why would it not always be enabled so what I changed was the compilation settings so there is kind of four tiers of compilation optimization so there's oh zero which doesn't do any optimization there's oh one and oh two and oh three and like as you go up in numbers the more aggressive the compiler is and those that usually that gradation usually optimizes for execution speed it doesn't execute for code size so there's also dash OS which optimizes for code size so the problem with that is is that it may not be the fastest thing to execute but it will it it it instead is a bunch of settings that are geared towards being smaller so the bootloader itself is 40k we have 60k for fat of s and we have 12k for a Billy config and then this big long math thing for how big the firmware is which should be the 262 or 232 32 2 32 wagons is what about doing something type of memory allocation like what is done in JSON buffer size I'm not sure what you mean by that soft device is this much which is how much 150k 152 so we're taking 500 we have 512 and we have 232 minus 152 we use 128 so that's soft device and that but then the file system the circuit pi file system is 60 the bootloader is 40 and the bootloader settings is another four which leaves us with 24 which this the ISR is 4 and then NBR is oh there's also Billy config Billy config is 12 what is soft device so soft device is it's a binary blob that Nordic gives you that does all of the Billy stuff so it's not not something really that we can I think this is 8k it's it's not something we have a lot of control over it's 4k so we're missing 4k shrink memory allocation for something you're not using so you can add it to what you need needs more buffer size yeah definitely that's that's kind of what we're doing is we're looking at all the different things that we're using and figuring out which of those we we can squeeze Anthony says thanks for showing me this on your stream I don't think people and even me realize how much hard work goes into making circuit pi fun you're welcome Anthony that's what deep dyes are all about deep dyes are all about the weeds all the details so if you have questions feel free to ask them so this is for we accounted for this oh the ISR is the last four I can't remember anyway we're pretty close let's take a look at let's do some googling here it works for RAM but not for flash memory think of it like a disc yeah so we have 512 total we could also look at optimizing circuit Python itself which we can do but I want to just see so if you look down there's the SDK so here's the soft devices it's a memory optimized so here are our options that we can use so what we're currently using is this s140 which is a feature rich central and peripheral stack for the 811 the 820 the 833 and 840 and it's got all this stuff in it 122 is a central only be a Lee protocol stack for the 820 the 833 and 811 so this wouldn't work on the 840s and then the s113 is a peripheral only which is what we were talking about it works in the 805 the 810 the 811 820 832 oh which is interesting the nrf 3528 32 is an older chip 833 and 840 so that that's something that we can use kind of across the board so what I'm curious about is what the size of this 113 is I don't remember where they tell you soft device sizes oh this is interesting let's look at this 805 is 192k flash the 810 192 192 832 is 512 depending on which version you have and the 840 has a whole one megabyte which is great and most of our 840 boards also have external flash so that 60k we're using for the internal drive now we wouldn't need either so I think generally it's okay for us to be if we were peripheral only yeah for almost all of our cases you wouldn't be able to have it be no you would be able to have it be yeah peripheral only would be fine I was thinking like the case where you want it to be like a USB or like a keyboard or a mouse like you could still do that okay so let's see what this 113 size is is it in specification yeah see it's a pre-compiled and linked binary image implementing 5.1 multi-protocol support supports the use of a bootloader I'm not sure where I found it here before product overview so the soft device will tell you like what layout it expects all images already on your file system yes and maybe it's memory usage it's either that or it's this probably the bootloader memory map here we go there's a map of what we're talking about nbr vector table nbr soft device that could be so it does change a little bit from with how you configure the soft device that's true as well I'm remembering that now the amount that you need to give it there's a process for like when you initialize it you tell it how much it has I think and it can tell you how much it uses oh here memory resource requirements soft device ran consumption oh maybe that's with RAM 1536 but it doesn't show I think I'm I'm misremembering I'm thinking of the RAM how to decide the RAM size let's just Google it soft device sizes Nordic Q&A of what soft device consumers in terms of flash or RAM more specifically in their release notes 33 2 is 168 ah it's provided by Dynastream they must be the reason is closed source let's see if we can find the release notes was it 1 to 113 I think is what we were looking at right 113 7 oh specification is the release notes not in here revision history no or we get it from Dynastream plus oh these are all the other ones oh you know it might be on let's just look at the 140 documentation downloads so we're actually on like 6 1 change log release notes can you see that they're kept brief ah so here you can see it's 152k so that's 6 1 1 I'm curious about the later versions so like what if we went all the way up to like 7 2 if we download 7 2 what do we get I don't know why it's like double zipped release notes oh it's like a history so 7 2 is also 156 discovered more efficiently 156 that's the number to remember for 7 40 now if we go to products oh dear maybe if we bump jump to the device 113 what this is yeah 113 downloads 7 I bet they're all the same it's like doubles it so s113 is 112 112 so it would save 156 44 kilobytes we're over time and surprise y'all are with me still we actually have a binary so let's let's end by seeing what we could do so it does that as a you have to but we don't have a you have to bootloader on this so if I unplug my feather sorry you won't be able to see this but if I plug in the micro bit it makes noise it's got the default code on it but it also shows up here is micro bit so what I'm gonna do is I'm gonna go into circuit python ports nrf build micro bit v2 and we actually do have a hex here as well so I'm gonna drag the hex over and copy it there and see what that does I'm not sure how it manages soft device and things so it I could brick it can you imagine a classroom of kids making that sound I know right well so I'm not sure if it did anything this circuit pi drive here is is a different device see what detail says like it's using this like daplink firmware does web USB it's not making noise let me see if it's advertising with my phone great doing great so my my iPhone's not seeing any advertisements so what I probably need to do is the next step is figure out how to connect a debugger see if it's like crashing or something is there anything like Billy buffer size 1024 there's a lot of options it's not just one unfortunately ship ship ship shoo great stream really enjoying seeing under the hood thank you you're welcome thanks for hopping in the discord sorry it looks like this micro bits not gonna cooperate it's gonna take some more focus than what I have right now let me just see my Android doesn't see it either so one thing to think about that I don't know is like they might they might not allow you to program the flat is the soft device or something so like if we're expecting a different soft device than what they like force you to use then that could be a problem so I'm gonna have to take a look into like what the binary format expectation is for that Garrett says great progress off topic has anyone used co-pilot the AI programming assistant thingy big get up I have not I'm I'm all about things that make it easier to program though so I think that's cool and Fetty to let me know how the beauty editing stuff goes for you I think you're gonna do it on Linux so make some tools for that would be awesome so my group it's gonna take some more work to figure out exactly what is going on so sorry but check out code that sacrifice on org if you have Chrome on Android Apple windows or Linux might work I don't think so but you might be able to get that a try and then you want an nrf 52 840 board to go with it Minnesota metastas thanks again Scott always enjoy have a great weekend yeah you too I'm out Monday Tuesday but I should be back Friday so let me wrap up thank you everyone this has been an awesome couple hours with you we've been working on the bealy workflow for circuit Python still very early days but making lots of really really good progress as always I'm sponsored by Adafruit to do the streams and do the work on circuit Python so if you want to support me support them by Adafruit by going to Adafruit comm and purchasing some hardware that was a great time to pick up a nrf 52 840 board if you haven't already able to test all this new stuff that we're doing ESPs will come later when we get all of this stuff earned out but for now nrf 52 840s are the place to be if you want to chat with me and a lot of others you can join the discord by going to the URL adafru.it slash discord love to have you there again this is a deep dive that happened normally at 2 p.m. Pacific I'm at Seattle that's why and they go for two hours so thank you all I will pet spook on the way out like I normally do and talk with you next week after I ban this person silly I was so close so close to finishing the stream all right time for some kitty pets you're hiding where they can't see you all stretched out all right folks have a great weekend see you next week and on the discords you're welcome for banning wagon loads that's that's what we do we moderate our communities bye