I guess we probably need to click go live When live you're live Okay. Yeah hit go live at the top. All right. I think we're almost there. You might even be there already See if I can double-check Back to this page. Yeah. Yeah, this is running now. Okay, so I'll paste this in the chat although I know a couple of you are here already This is Link YouTube Well, I think I just put it twice also because I pasted it again. That's all right okay Okay, so now I know now I know schedule create the scheduled event and then That's that's really the key that I needed create the scheduled event and then everything on the restream side hooks into it Okay, so I'll remember that and we should go smoother next week Okay, so I know there's a couple folks here already. Let's do a quick introduction. Let me just real fast also shuffle my Windows around a little bit so that I can actually see all of the chats here Okay, the one other thing actually is we're gonna pop this out and then I need to try to find this Window name here Can we make okay? Yeah, this thing. I remember this from the other day when I tried to do I Make this go away. Will it scroll off or okay? Yeah, it looks like it'll scroll off after we get a little bit more Okay, which is less delayed Because YouTube does captions that makes sense they have to do processing and everything Okay, so let me do a quick introduction and then I'll I'll do some hello's to everybody that we've seen so Hello to everyone. My name is Tim. I go buy from a guy on github and discord This will be the deep dive stream as I'm sure most of you are aware Scott is taking some time off And I am filling in to do the deep dives and this is the first one as you can probably tell We had a little trouble getting set up, but we're ready to go now If you are watching this live, you can go to the discord which is linked down this way On the screen ADA FRU IT slash discord That is where the chat that is on the screen is coming from along with also the youtube chat is right below me as well So head there and you can ask questions or chat with all the folks that are watching along There is also chat on twitch. I will say right now. I don't have the twitch window up So I can pull that up maybe here in a few minutes and try to keep an eye on it as well But I would encourage folks the best place to go if you want to chat in my opinion is the discord That's the place that I have kind of the closest eye On and that's the place where you can ping me if you wanted to get my attention So I would say head to the discord first Hey stop fighting Excellent, yeah, I got a cat showdown Haven't set up the cat cameras yet, but right now they would be like a cat showdown camera. Hopefully they'll chill out If you're watching this in the future and you don't know what we're talking about in this stream We're gonna be dealing with circuit python stuff. So this is a good place to start if you want to learn more about this Circuit python.org. This is basically an implementation of Python that runs on tiny computers Much like this one right here, which is a pi portal device on the back of here There is a chip which is basically a tiny Computer for all intents and purposes and we can write Python code save it on to this device Just as a thumb drive. So this is connected to my computer as One of these circuit pi drives right here And we can just save an update to the code.py file in there and it will run the new version on our device So the main There's all different shapes and sizes of these different microcontrollers a little bit farther on circuit python.org here There's a bunch of them in the background This one is a pi portal It's you know sort of claim the fame if you will the nice thing about this one is that it has a nice big screen on it It also has a touch overlay So today I'm gonna do some stuff with display IO and graphical inputs So I figured this would be a good one to use but there are many many different shapes and sizes Ranging from you know ones with screens ones with lots and lots of IO pins ones made for alligator clips ones with You know rubbery little buttons with LEDs inside of them All kinds of different form factors of these devices, so we're gonna be using the pi portal today But there are different ones that can be used for all sorts of different kinds of projects If you're interested in circuit python and you want to get involved in the project There's a contributing link right here. This is a good place to go for folks that want to get involved There's a list of pull requests and open issues Which are kind of the the most basic things that we usually point for folks Ports if they want to start getting involved And the other thing I'll mention circuit python is an open source product project rather But it is primarily funded by this company adafruit. This is their website adafruit.com So they are paying the folks who are working on the team Full-time the development team like scott who's in the chat there They're paying some folks to work on the project part-time such as myself Both like working on mondays and nights and weekends and doing this stream now So they are the folks Currently who are paying the majority of the people who are working on circuit python as a job So if you want to help support the project, but you don't necessarily want to get involved in development One way you can do it is by purchasing hardware from adafruit So they sell the microcontrollers The things that you can plug in and do with the microcontrollers all sorts of doodads and fun little gadgets So head there if you would and you want to help support the project Um, so let me catch up on the chat and then We'll actually kind of get going here. So I'm going to scroll this up a bit Uh, hello to patrick. Yep. Can't stay long. No worries, but thank you for the well wishes Uh, let's see. I got a little ways to go. Uh, so hello to everyone that's here so far. We got bruce uh, two two three one puppy Uh, tammy, uh How's it going tammy? Thanks for joining in uh and congratulations as well on a couple of your streams I've been uh, been checking those out. So um, keep up the the good work there I'm super excited to see more and more folks, uh, starting to stream circuit python content So for folks that don't know tammy makes things in the chat, uh, is over on twitch as well Streaming similar types of content. So head over there. If you're interested in more folks streaming this sort of stuff Uh, michael purples bruce Let's see scott's here. Thank you to scott. Um, leon leon url, uh, l art, uh, yt Or alive, but unfortunately have to go to sleep. No worries. Uh, yep very late in france You can catch the video after the fact. Uh, and also that's a good point that's got pointed out is um, I do stream earlier in the day on saturdays So I will be back tomorrow morning, uh, and you can catch me there Possibly at a better time for you. I actually did a back when I chose the time saturday mornings That was one of the things I took into account was I knew that we had some folks in the community that were over in europe And that it's very late for them to watch the deep dive So that was actually one of the inspirations for me choosing the uh, the saturday morning slot that I have been streaming on um, let's see Standard next week Yep Um, yeah, yeah daylight Daylight savings time is uh, is this weekend Which is a good note. So next week will be An hour different slightly but the clock will say the same thing. It's a whole weird Thing, but we are at um two p.m. Pacific time, which is generally how this You know this stream has been referred to since scott does it and he's in the pacific time Is four p.m. Central time, which it's very likely that I'll end up saying that more frequently Um, but those are the same time and we do have daylight savings time come up So we will be a little bit different uh next week. Um, so just be sure to Either adjust your clock or check if you're not in a place that does daylight savings time Then you can adjust the time of day. It'll be an hour different Zarnalyn. Yep. Just in time. Thanks for tuning in Ham's labs looking forward to see what direction. Thank you. Um Tammy makes things. Yep, there's the link. Thank you to Tammy Drop in that link. Uh, got some follows Video mask circle looks great. Thank you Uh, and I think we're caught up there on The discord Let me make a quick scroll through the youtube chat here and have as much devodessa. We do need a catcam Uh, I have plans, but I don't have it set up yet. Uh, and then protokit first time catching the stream. Uh, that's awesome Thanks for tuning in and I would encourage you to watch the the back history of this If this kind of content is interesting to you scott's been doing it for I think a little over a year now Um, and so there's lots and lots of good Previously run Episodes of the stream so check those out Um, and now that I have made it through all of that I do remember I don't have this showing. Oh, okay interest and hello. Somebody did fill in the uh times for me. I appreciate that Uh So jumping in a little bit. What are we working on today? I thought it would be fun to um Do kind of my first episode of deep dive working with some of the stuff that I am working on most frequently on My own streams, which is display IO related stuff and specifically I wanted to kind of pick up where I left off actually last week so um For folks that don't know I stream on saturday mornings at 10 a.m. Central time And what I worked on last week was this example right here Which is for the async IO library and it was writing uh, kind of like a basic example of uh, using async IO with display IO Controls particularly touch screen controls. We were touching buttons and having it affect other stuff that was going on inside of a separate task Um, so I want to work on another example of this async IO with display IO concept But this week I'm going to go a little bit more complex And we're going to pull in a sensor data as well And we're going to also do some different types of manipulations and use some different widgets that we didn't touch last week Um, Paul ask hi phone guy and everyone present question. How can I write something in twitch? Um, so Uh, if you are on the twitch page, there should be a chat on the right hand side I believe it is by default. Um, I think you'll have to make an account I'm not I don't have a too much experience with twitch like beyond like without being logged in So I've had a twitch account for a while now and it just stays logged in I don't know the exact way it works So if you don't have an account this may be different You might need to create an account and log in not a hundred percent sure um, but There is a chat usually on the right hand side on twitch and you can um Put messages in there just by typing and then hitting the send or enter or something like that, which reminds me Let me go ahead and actually I'll try to pull up the twitch chat as well and Try to keep an eye on it. I will say I generally am pretty good about keeping an eye on one Chat, I'm going to try my best to Uh, keep up with all of them But you know work with me a little bit like if I don't respond to you real quick in one place Um, you know, you could try to ping me if it's if it's something you really want answered or Um, you could try hitting the discord again is probably the place where I'm most likely to see it Um, but I will pull this up. Let me pop it out here and then I'd chat pop out chat. There we go I don't know. Does it want to be It's definitely muted. I don't know if it will show me the chat if it's paused. So I'll let it play here And One more second of me staring over here while I shuffle a couple more of these Cuts around. Okay Um, it sounds like a good show. Thank you. Uh, and how's it going to dexter as well?  I appreciate that scott. Um, still can't say how much I love Uh, cannot say how much I love a I think I oh now that I've used it. Yeah, I've I found it really cool This was the first a real example where I dove into it But I found it to be a neat a neat way to structure programs I think uh, especially um interactive programs with the touchscreen. I think can benefit from structuring the code this way To make the code more clear and easier to maintain Um, so I like it as well. I don't have too much experience yet, but I was definitely happy with the experience I had so far Um, oh, yeah, that's rough. Arizona. Yeah, there's a couple of places. I think where they don't like Like uh, Tammy is saying like half the state does it and half of the state doesn't it depends what city you're in And there are some places in the world where they have just like decided not to do it Like a couple of weeks before it was supposed to take effect. Um It it causes all kinds of weird weird stuff. Um daylight savings time this is Basically a two hour change if you're in another Yeah, so I have I'm Gonna work on maybe a different type of a setup or something But I have the chats over here. So if you see me looking off this way That's wise because I'm actually looking at the uh the chat windows over here um So the example I want to this is the one we did last week And I'll run this real quick. We can see what it does and then I'll talk about what I'm gonna do this week Which will be different. So let's run this one Um, I'll have two circuit python devices because I have the macro pad running And let's see did we keep this what's in here right now. This is basically simple test for this Uh This sensor which is plugged into my device Uh, which I'm gonna actually keep because I'm gonna use this sensor here in a minute Well in a little while once we get to that part of our new example This is the code from last week And there's an open pr. So if folks are interested in using this code Or reviewing the pr or playing around with this to see how I did it You can find that over on github if anybody is interested in that I can drop the Drop the link, but this is the code for it here. Also, I'd encourage you if this Particular code here is interesting to you. Um, check out the vod of this of my stream On on my channel separate from eta fruit. You can find that vod on youtube or twitch Where I built this so you can see the history that that went into this particular Example, um, but here's what it does. We have a couple of different buttons We have this blinking circle up in the top left which kind of represents like an led essentially the The existing async io examples were made with leds couple of them So I kind of took the the idea of an led and put it into Onto the display just by drawing a circle and having it turn on and off by blinking This is the one we made last week. Uh, the things that we can do are Press the invert button right here invert color and as long as we have this button down Then the color of the blinking circle will change it will go to the invert of what it was So if I release the button, it's blue if I press the button It's like a beige color because it happens to be the invert of the blue that we're using And then we also have these two buttons down here faster and slower And we can press those and they will increase and decrease the rate that the circle is blinking So I press faster a couple of times It's now blinking much faster than it was before And we can slow it down by pressing slower a couple of times And take it down to a much slower interval. So this one is meant purely as an example It's not necessarily, you know, a really practical project that does something But it's mostly just an example for how you can use async i o with You know two things display i o Graphics like the circle here as well as a gooey like touch input buttons like this So that's really what this was meant to do is just illustrate how to do these things The thing I'm working on today is a little bit more practical But still kind of in the same vein of it's mostly meant for An example not necessarily a finished project And so the one I want to do today is going to be We're going to read data from the sensor and I just chose a random this happens to be a magnetometer It doesn't really matter what the sensor is. We're just reading live data from the sensor We're going to output the data onto the screen And then we're going to provide Three switches that can be turned on or off one Representing each of the three colors red green and blue And then our label that is showing our data that's coming from the sensor is going to be turned a certain color Based on those switches being turned on on or off So if we turn just the red switch on our label will be red if we turn red and blue then our label will be purple You know if we turn like red and green then it will be yellow So like those three colors will be able to turn on and off and change the color of the label And again, you know, that is a little more practical than this because we're at least like outputting real data from a real sensor But I do grant like, you know, it doesn't matter too much what the color is This is still mostly meant as an example of how to set the stuff up Thank you scott for linking the other youtube there in the chat. Yep. That is my um, that is my Other youtube account. So that's where you can find me saturday mornings as well as you can see the previous Um videos of my streams including the one where I created this, uh, code that is on the pipe portal right now Let me catch up a little bit here on the chat We are not going to work on a daytime library today See, where's the last one? I think this probably scrolls it on the screen, doesn't it too? So While I scroll this up, you'll uh We'll see it on the chat. So yeah, this is where I was. Um Yep Not a big fan of daylight savings losing and gaining. Yeah Totally agree. I think it's it's just such a shock to just randomly change the each calendar, but Canada Saskatchewan, they don't do it. Interesting 13 hour day clocks in their own cities Yeah, zarno and there's some cities. Yeah, where it's uh, that's kind of like what Tammy was talking about with Arizona earlier About farm country. Yeah, that's that's kind of a thing. I've heard as well as like farmers want it so they can Kind of get up earlier and get to work. I don't know I think that some farmers have come out and say that it doesn't doesn't really help them too much though Blocking is awful at some point. We need to see an rtos with circuit python And all things that block can be handled nicely. I'd love to see a c-level r-toss that integrates with asyncio and python cannot be possible Yeah Metronome a funny story about metronomes metronomes. I cannot listen to metronomes anymore. Metronomes Literally drive me insane at this point I can I can stand like 10 or 15 seconds of a metronome and then I like have to Turn it off or leave the area or something I was in marching band in high school and one of the things that we did during practice was They would set up a metronome and put it right in front of a like a bullhorn basically and it made the most like Brain piercing sound that went through it. I can't even describe it.  And so anytime I hear a metronome It kind of takes me back to that sort of brain drilling Thing so Um, luckily I don't do a whole lot with music stuff anymore. So I don't run into metronomes too much RTC DST detector. Oh interesting cedar Do you have a daylight? daylight savings Time utility for circuit python this one in circuit python Or this is a pdf that shows the conversions I see okay Um, all right, so let's jump in I think I'll start with um, let's get the controls I want to use so Uh, I think has this been moved over to here now So for folks that don't know the circuit python org on github, this is called an organization Anything that's like github.com slash and then the name here Sometimes this is a user an individual user, but it can also be an organization So the circuit python one is an organization and this is where we have been putting some of our newer Uh, display out widgets and I think the one I want is in here flip input. I think is Oh, no, no, no, I get this wrong actually. It's not flip input. It is uh, it is switch round Round is what we want That's right. I think there's pictures of it in the docs Maybe not let's see Okay, I think this is it though So this is one of the display out widgets. Uh, I think I want to say kmatch created this Not a hundred percent positive. So I could be be wrong, but let's Grab the simple test for this And then it'll make it real clear like what it is And I will overwrite the code from last week say sink. I oh And then show the camera So this is the switch input So it has a couple of different things which we can control. I'm pretty sure we can control the colors When the user touches it it flips, you know back or forth based on whether it's on or off There's a little icon in the center that turns into a circle or a line And I think we can also do the The colors so I think what we'll do is like Um, we'll make one that's red one that's blue one that's green and then when it's on it will be that color And when it's off, it'll be Kind of blank like this one is Um, so let's start by just making the three of those and then you know We're just gonna add add and add and add until we get to what what we're aiming for which is what I described before so first Let's look at how this is set up. So we will still initialize the touchscreen Uh 2030 I'm guessing this is probably yeah x y Let's see Yeah And so there's lots more stuff we can specify Let's start by One of the docks I think And we want to look for things like the colors fill color off I think we'll keep default fill color on though. I think we'll do um We'll do the different colors for each one. So we have our green one. Although I think I should make the first one red So let's go set fill color on This Fill color on Probably take some Hex or tuples Okay, so that made the inside of the circle red I'm guessing we have maybe outline color or background color Background color on and off. So let's set that so maybe we should do a little bit darker red for Yeah, darker red I think for the background and brighter red for the foreground and I will mention the colors come through a little bit weird Um on the camera. Let's see somewhere. I have camera controls I could do this which will make the colors a little bit better. Maybe although Hopefully I didn't get that much better in this case. We're already fairly bright. Yeah, that doesn't really change it So I won't mess with it. That's the flash on the camera But it looks a little orangish yellow here to the naked eye though It does look red on my end. So That's what we'll go with and then background color on this one. I'll just do a little bit darker. So maybe like C's See how that looks Okay, I think we want it still a little bit darker. That's not that much different. So let's go maybe Nines That's getting closer, but I still think we could go a little bit darker uh, and also I My camera controls over the chats. Let me There we go. Okay, uh, and then it looks like we also have the outline color Around the circle.  Yeah, unexpected maker. It looks red Or looks yellow. That's true on the camera. It definitely does to the eye though. It does look red Going to check out bluetooth midi soon. Oh, that should be fun I actually just learned um a little bit about midi this week. I had never really played with midi before um, but the other day I took it out and played with it on the macro pad a little bit. There's a really really nice guide I think liz made it. Um That talks about all the details of midi and gives lots of really good examples. So check that out if you haven't already uh, ham slab As you're coding describe your workflow in the process environment. I can do that. Um So, uh Environment, I will say it's pie charm As far as the process what I will do is uh link to This I think, uh There's a page that that I actually wrote that explains everything I did inside my pie charm to get set up So that's the best place instead of me. I'm trying to remember it all and relay it See Maybe is it essentials? Oh exactly which Guide it's in And yeah, feel free to ask Questions and such folks. I'm happy to answer questions. I'm happy to go Down rabbit holes and off and look into different things as you can probably already tell same kind of energy that deep dive had This page right here. This shows the full setup everything that I did inside my pie charm probably the most important things are disabling the autosave and Uh installing the circuit python stubs those were the two thing. Oh, and I would say also making a local Project, there's like a local project folder on my pc and then I added a like linked folder that goes to the Uh folders inside the media directory that way they get pulled in and treated as part of the project But they're actually stored in a separate place This makes it so that When I open this project inside pie charm, even if I don't have a circuit pie device connected I'm still able to open it and nothing breaks if you try to create a project directly on the circuit pie drive It will work and it will work while it's plugged in But if you ever launch your pie charm and open that project when your circuit pie drive is gone It freaks out because the You know, it's expecting to find stuff there and it doesn't find it. So those are the main things I did To set it up. Uh, and I really like it. Uh, I came into this I used pie charm before I ever got to circuit python So I was already familiar with it. I will say it's a little bit overwhelming. There's lots and lots of different things that pie charm can do Um, and there's lots of all these little windows all around that will open if you You know click on stuff around the edges and there's a ton of different ones that I'll do You know different weird things. I will say like you don't need most of those things You can kind of hide it down to pretty much just the file list And the code that is what I use the majority of time and then I'll say the one other thing that I use a whole lot Um, which I don't we can't actually do it in this repo But I'll do it in this one is the get stuff.   You can kind of uncheck them in this box here. So Git I would say is the other like huge Really good feature and at least in terms of my workflow that pycharm adds is a nice visual overlay On top of git that makes it super easy to do all kinds of stuff. So Um, let's see if we can do that outline color. I think that was um Probably just okay outline color on and off So let's go back to here outline color on let's go. I think we'll just do the same red As the background. Yeah, that looks pretty good similar to vcs workspace idea Just found an esp 32 board that has audio line in and out interesting I was wondering if there was any devices with audio line in the other day made by expressive All right, uh, how's it going paul? Uh, let's see shulinik. I may have butchered the name. I apologize if so. Thanks for tuning in there on youtube Um, so let's make a blue and a green one of these And let's rename this this is something else about pycharm that I really like is this refactor Rename stuff. So like if I want to rename a variable, I can highlight it And like you can do find replace right which works pretty well, but this is actually a little bit smarter. You can highlight it It's shift f6 happens to be the hot key for it. I'm sure there's other ways you can access it This is the one I use But we can rename this to whatever we want. So let's say we want red switch Hit refactor and then this will actually look through Not only this code file But all the rest of the code files in the project in this case Like we don't have any other usages because this is the circuit pie drive But you could imagine if you're in like a library repo or something This is really handy to be able to change a variable once and have it Go and search through the rest of the code and find all the usages of it Like this one right here changed even though I didn't Specifically do anything else and these ones down here as well. So That's another thing that I do Really like about pycharm is the ability to edit the code And have it go find all the rest of the instances of use of that variable So let's do A green switch as well And a blue switch 66 And we'll change these around a little bit. I think let's move it closer to the corner right now It's at 20 30. Let's go like 10 10 See how that looks and then 10 x on all of these and Each one will get lower So I don't know the exact height. Let's just take a guess maybe and say 40 and then like 70 and let's see what that looks like No, okay, so we created our switches, but we did not add them to the group yet. So we need to go Basically this There we go. Okay, not far enough. We need more than 30 pixels We could change the size too, but I do like them being nice and big because it makes them easier to hit So let's go um, maybe 60 and then 50 more than that. So 110. Whoops when 110 Visual studio code has the same Concept of multiple project trees. I got you. Yeah, I know there's lots of folks that like visual studio We get a fair amount of questions coming to ask about visual studio um Oh, okay. So the other thing is uh, we don't have the touch listener stuff, right? Those ones aren't hooked up yet. So we do need to go in our main loop and here we need to go like uh, lf Green switch contains P Then we go green switch that selected Uh, it's interesting selected P. We just call it with the um The touch point Blue switch that contains P Selected it will pass that Now these should have let these should let me Yeah Perfect. All right, so we got red green and blue switches. Uh, the red switch does look a little more orangeish, but IRL it's looking pretty red The green and the blue come through pretty well So now we want to make another label and this label Will then kind of dynamically set the color of it based on these other three switches So let's do that. Um, we need to import label stuff Let's go from Adafruit display text, uh bitmap label import label Output label equals New label Dot contains is a really nice attribute. Yeah, we try to I think dot contains is part of um Oh, I it's called widget. I think it's the name of the classes No, no, no control control We have a class called control Which has the properties that are used for like touch inputs most commonly and contains is one of them um I like your nice little micro controller pillow. Thank you. Uh, my wife made me this beanbag I actually have a couple of these beanbags around my Um around my table here I put my wrist on one to use the mouse and I found it's also really nice for putting devices under to keep them propped up a little bit and Stuff like that. So yeah, thank you I will pass the message as long as well And so it was a gift that was made for me Um This one we need to give it a font. So we're gonna go terminal i o dot font, which we need to import Um Another nice thing about pie charm like control. No, what was that alt enter? Maybe I do that just out of habit now I don't even know the right combination. I think it's alt enter Uh, it will let you um It'll fix the imports for you. So you don't have to actually go all the way back to the top and do it and then come back Um text, let's just go. Hello world for now. Eventually. We'll fill this in from the Coming with data coming from our sensor. Um, this one. I'm gonna place by anchor point anchor point 00 I like to use on labels and then anchor position We want to put it to the right of all of our switches Um and towards the top it doesn't really matter too much beyond that. So let's just say maybe um Maybe like a hundred x and then 20 y And then let's add that to our group My group got a pinned Output label. I'm gonna rename my group to main group Just because it's kind of like The name I typically use main group Save that Okay, um, let's go a little bit bigger and a little bit farther over to the right 160 And let's also go scale maybe like It's three too big. Let's see if three is too big Yeah, well, maybe if we don't scoot it so far Pretty close Eventually we may adjust this anyway, uh, because we'll be showing some different data But this is good enough for testing. So right now the color of it is white Which would correspond to all three switches being on So all three switches being off, I guess would go to black I don't know that we want to default to black Maybe we'll default to a dark gray and maybe we can still get a little bit of contrast from the screen Uh control dot contains. Yep. Perfect. Thank you for linking that over uh dexter That is the contains, um method that the switches are using here that i'm using because they extend Uh control it should so This is the code through control click. That's the other thing I just did Um, you can in in pie charm You can control click on things and it will take you inside of them to their declaration wherever it may be This one happens to be in a library I have installed since outside packages But it would also take you to other files If they were part of your project So yeah switch around extends control, which is how we get that contains method. So if you want to make your own Uh interactable widget with display i o that's one way you can do it You can extend control and then that will give you all the logic that this contains thing Um does so you then then you basically just get your touch event from the touch screen library And then check it against contains and you don't have to worry about the um The actual details beyond that so it's pretty nice Um, so let's default this I think to Color I think we want something sort of grayish, but not too dark. So See what that does are we able to still see it? Yeah, okay And then we'll set the colors based on Which switches are on so what i'm going to do is make a variable for Um Text color it's gonna actually start as this I'm gonna fill it in here, but of course it won't change yet And then what we're gonna do is when we So how do we want to do this here? I think Let's see. I think what we want is a Def update color Function and this function will check Let's see. So I think we'll have one this will basically check the switches. So if Uh not red switch That's selected Interesting that we don't have a touch point though. I guess, um, I guess we could always pass it here So if red is not so basically I'm going to try to make if all of them are not selected This will get us back to gray and then we'll have different logic if one or more of them are selected. So Um And not Green selected touch Oops and not blue Selected touch Control alt l that's another nifty thing inside a pie charm that will format all the code although in this case the format Wasn't really what I wanted. So I did some extras That does look a little weird though. I guess it's just supposed to be like that So if all of these are Not selected we want to go back to gray Output label. This is how we change the color super easy color property equals new color Text color. Oh, this is where the logic gets different. So I think See here. Oh, this is Probably connected to the wrong device. Yeah, this is the macropad Which I totally just stopped the thing from running. Um So this is now connected to my pie portal I need to see if Some of these operators work how I think so If I do this one Bitwise Yeah, that's what I want Perfect so Now basically we're gonna go Else that means at least one Switch is on so we're gonna go So Text color, I'm gonna start it on black and then If red switch is selected Then we're gonna go text color. Can you do like bitwise equal? Bitwise equal red, so we'll do This And so then it will start at zero zero if this is selected Then essentially it will become ff. It'll become red And then for each one of these will bitwise again, and it will add those two digits of hex Let's do them in Order rgb at least it doesn't really matter the order, but that's the way I think about it. So let's do them in that order I'm gonna use the Faust For audio it directly supports usb 32 and the sport. It's going to be super cool I'll put the project on hackaday. Nice Yes underscores leading underscores Sometimes I'm good about it. Sometimes I'm bad about it. Sometimes I put it on there and then later decide it probably should be more public This one I think though makes sense Because we're not it's not meant to be user-settable the program itself is going to change it The user could change maybe the default the gray, but For each one of those if it's selected it's going to add those two digits If all of them are selected we'll get white because we'll be all fs If like red and green are selected we'll get yellow because we'll have four fs Red and blue will give us pink I think that should do what we Think what we want. So label then we're just going to set the color To the new color and now here we can go We just call update color in here And this is all going to end up getting refactored when we bring the tasks the asyncio stuff into it, but For now, I'm going to write the code essentially just synchronous without any of the tasks P we got to pass at the touch point. I think is that all we need? Maybe all we need Oh, we're in ripple. Okay. I think maybe I used selected rung inside of here. Maybe this Maybe we can't do this. Maybe we need a different property. That seemed like it changed them, which I don't want to do Value value property. Yeah. Oh, hey, why are these like this? That's interesting It's like the dock string might be Somehow different than what sphinx or read the docks is expecting. Usually this would be one One full column So I think we actually just want value and we don't pass touch point value Nope, we still switched all of those Uh, because I did this here as well actually So calling selected like this is causing it to actually move the switch Makes sense because that's what we did inside the contains. Yeah, there we go Now Yeah Okay We basically have three color control rgb Over our text now we turn them all on we get white Red and blue gives us pink red by itself gives us red red and green gives us yellow Green and blue gives us teal Green by itself blue by itself All off gives us back to gray So Now We will put instead of hello world. We'll just put the data that's coming from our sensor And then after we have that part in that's when I'm going to refactor this to use async.io So this is where we will come back to this code that I kept earlier And a couple of things out of it to set up our sensor Doesn't matter too much where I do this Sensor, let's print dur sensor. Let's see is magnetic the only thing we can access here Dur sensor magnetic data rate Operation mode performance mode That looks like the only one that's actual data Some of these like data rate performance mode operation mode these exist, but these are properties. I assume for setting the way it behaves Magnetic though is the actual data. Oh range. What is range? So this one I don't have the stubs for so this one. I cannot, uh, write like a control click into What I will do though is go to github And then the docs And let's look at what range is Oh, oops API references is what I want range test measurement range I don't know what that means beat I think that's not data though print sensor dot range It's actually print Uh, I think you want, uh, yes. Yep dexter button value. You were right It's half assembling my latest project Just realized I forgot a power switch Dur. Yes, totally dur is like One of the things I use most frequently. Um, I got zero. I think that it's not I think that it's not data. So let's stick to magnetic. So let's go Here we'll do it pretty similar to this but I'll um I'll use new lines a little bit more So let's make a def update sensor data And really we can go output label dot text equals this And then what I want though is not commas. I actually want to do three lines So we'll put new lines between these and then In the main loop, let's say update Sensor data Mag X is not defined Ah, yes, we need to do, um Mag XYZ Z equals Sensor magnetic. Whoops There we go. And I want less space. There's so much space there. Um, I don't know where it's getting the space I'm not, I don't actually, um, I've never learned the way that this syntax works Let's move it over Yeah, this is probably also cutting off some digits or something So we're getting less precise data, but that's okay. That looks good I'm going to scoot it just a tad bit more back Towards the left I'm gonna start using I have this uh stylist right here, which makes it a lot easier Can also keep my hand out of the way a little bit better All right We have our sensor data. We have our colors. All of that's working So now let's start refactoring this Uh to use async.io. Uh, Dave Odessa gotta go. No worries. Thanks for the stream. Uh, yep. Thank you for watching um, so let's Go, I think let's look back at this example And I will kind of model my new one off of this Yeah dirt really really is Sometimes I forget about it and I'm quick to like go open a browser and pull up the like read the docs or disc Get hub and look in the actual code But you can really go a lot faster sometimes with just dirt and find out what you need using only the rebel. It's super nice So let's see we made Okay, right. So we basically we want to make a Co routine is what these are called for each of the things we want to do So I think one co routine will be Fetching the current data from the sensor and updating the screen Which we currently have a regular function for but it's going to become a co routine our other co routine will be reading the touch input And then checking on all the switches Setting the color according to whatever is in them And then do we need any others? I think those are the only Two that I can think of at least off the top of my head and then we'll need State objects to be able to share. Whoops. I need this anymore We'll need state objects to be able to share the state between those different co routines because the one that is touching the data Do we Do we don't well we need to share the label at the very least Because we need to be able to set the text and we need to be able to change the color Right. Well, we need it. Yeah We'll need to share the label back and forth because one co routine the one that's reading the sensor and changing the text That one needs access to the text But the other co routine that's reading the touch screen and checking the switches It also needs access to the label because it needs to change the color So I think our state object will have The label on it Which in this one we created button state and it held Uh just a true false in this case and then an integer in this case And so ours I think will hold the Label I'm gonna call it application state. I don't know. There's maybe a better name for it Okay, we'll see if we need to share anything Else, I don't know. Maybe we would need the sensor. I'm not sure Uh, thanks sas patrick check. Um, yeah. Thank you for tuning in. See you later How do I explain co routine? That is a good question This guide does a better job than I could probably the way that I think about it though is like A function that is meant to be run in an async way. So really I think about it a lot like the same way I think about a function Um cooperative multitasking. This is the guide That will do a much better job explaining it than I could most likely Uh, which actually I think this is where I even learned Last week that these are called coroutines The task is a kind of coroutine the coroutine it can stop in the middle So it's it's almost like a function that can be paused and resumed basically It's a function that can do some stuff and then pause itself And then later on the system can come back and like check in and let it resume itself and do some more things again um So it's almost like a repetitive thing more than it is a function, but I think it has a loop inside of it. So um I don't know. It's kind of an interesting way to write the code though because you end up with a loop inside the coroutine function Was that dict do I don't know That dict on the um Dict on the on which object So I think what I want async def We did before we had Had blink which blinked the dots We're able to make one of those for each dot and then we had handle buttons, which is what did Oh, and we need a main as well actually Oh, we had monitor buttons. Okay I think I want to aim a little bit more generally. We're not using buttons exactly this time we have switches And I don't think I necessarily want to call it monitor switches I think what I'll do is let's go a little more generic and say Handle touch inputs handle touch inputs I'm also kind of trying to think of like Good general names to use for this to be an example that folks could copy and then cut some parts out of paste new stuff into um So I'm trying to aim a little bit more generic than what I'm actually writing specifically so that it'll be Hopefully easy for folks to reuse and still lead to having good code that makes sense Um, so this is gonna definitely take the application state Uh, does it need anything else? this one It took the two buttons. Okay, so it will need the switches. Yeah, it will need the switches. So red switch green switch blue switch One switch to switch Whoa Underdict I'm probably doing it wrong, but 90 90 of the async functions. I've created have a while true loop. No, I think that's right Linux 203. I think that's correct That's very very often is the case and in fact in this one that I did last week We have the while true inside of here and it makes sense at least in my mind. It makes sense because our coroutine Uh is going to keep running over time, right? We don't want our coroutine to stop unless we have some way to exit it or something but generally we want it to run And keep doing its thing over and over again whatever its thing is we want to keep doing it Um, so I do think that does make sense Yeah, Dexter posted a good example too of an async which has the bubbles Bubbles example, which is like moving some circles around on the screen Dr. Seuss does circle python. Yes, it would be amazing Yeah So basically here this is where we're going to do the stuff that's currently Inside of update color And so do we pass? Let's see. How did I do? Okay, we just did we get the touch point inside of here. Okay while true p equals actually Yes No, no and now I think update color since we already have this function Although this one doesn't take the switches I think it should Or do we just move all of this logic? Maybe we just move all this logic inside the coroutine Actually, I think I like that better Do I I don't know update color is nice because it says more Specifically what we're doing. Um, I think I like this breakdown. Actually. Yeah, the coroutine Gets the input from the touchscreen, but then calls a function in order to do The actual logic that way the logic can happen inside of a function with a different name And this coroutine would be reusable even if you weren't using switches And you're using buttons or something else you could reuse this part of it and just change out the function that you're calling Your own which sounds at least in the moment to me like a pretty good way to structure the code So let's do keep this But let's add these I think we would need these because I think inside of This coroutine and then ultimately inside of here. We wouldn't be able to access Switches unless we pass them in I think but I'm not a hundred percent sure Hope is another one. Yeah, that one's similar to dur I don't know the exact differences, but that one does list out a bunch of neat stuff as well Expected two blank lines I don't know why it thinks touch point. Oh, I guess because we're not actually using touch point anymore Are we we passed in touch point because I was doing that selected thing before but it turned out that that was actually wrong Okay, okay, so we actually we need to read the switches first right here. We're updating the color based on The current value of the switches, but we actually need to do this stuff We need to check the touchscreen Figure out which thing was actually touched or not I'll go ahead and cut this. We already got this running. I could probably get back to it if we need to Sometimes I'm hesitant when I'm refactoring to like cut stuff and delete stuff instead of just copying But then I end up with extra ones and comments them out. So I'll just feel the band-aid now. We'll cut it move it So this is actually gonna Set all the switches based on the touch input then update the color based on all the switches We no longer actually need this One more thing though. I think we will need to pass in the label App state label And then we do end up shadows text color from the outer scope It's probably okay. In fact, we probably don't really need it in the outer scope. Honestly, we probably only need it inside of here because we're Creating it setting it to the color we want and then putting it into the label You'd always access it back out of there if we needed to get it again Yeah, honestly, I think we probably don't need this And instead maybe here we could just go back to doing it this way But then it will get updated from here When adding the Adafruit packages in PyCharm will it hurt to add all of them to the project? I'm not sure what you mean add it to the project But usually what I do is well, I will install with pip any of the ones that I want to use um, so like display text for instance, I have installed with it like um I don't know the exact command, but I would have done something like pip install Adafruit circuit python. I guess maybe this is this is the exact command possibly Um, I would have done this in this case. I already have it installed So it's not actually going to do anything new But I would have installed that and I would do that type of thing for all of the libraries I'm using although you can see here. I haven't done it for this driver From the mag not magnetometer Um, but that's usually what I would do and I don't Installing them with pip. There is no real downside That I'm aware of like those are getting loaded on your pc. They're not taking up space on the drive or anything Is there a number of function parameters Beyond which it's better to pass the dict or quarks function oops Instead of individuals or is it just a stylic? Is that just a stylic stick question or is there a performance benefit? So I don't know performance wise. I could not answer that part at all Um, it does seem like a style thing to me I know pilot eventually will complain if you have too many arguments and so you could theoretically change One or more of your arguments into being a dictionary or if you wanted to be even more Um, you know proper I guess you could change it into a class With you know particular fields and stuff instead of a dictionary where it's all generic and they can just be any key in any value You could create an actual class and you could pass that in um To me, I think the line is like I don't know somewhere around five or six it starts getting unwieldy but also Not to the point of like I don't know it feels unwieldy a little bit more than like five or six But also I'll say it also feels unwieldy to like turn it into a dictionary or turn it into an object And then pass the object in Uh, also feels unwieldy to me. So it's not something that I typically do When I'm just kind of left to my own devices and writing code Um, but I do grant it does when you have more and more and more it does start to make your initializers Um big behemoths and it's not the best looking As far as I know I swap from lots of parameters as a function Input to a class or addict as a function input when it becomes hard for me to keep track and read lots of inputs I don't do it for performance Uh, but for Keith the programmer who's trying to read the code. Yeah But maybe there's performance benefit to one or the other. Yeah, it I'm sure there is some difference I don't actually know under the hood what it does. But yeah, I would kind of echo that sentiment that Keith says Um, when I would make that switch it would definitely be for code readability more than anything else That would be my primary goal of making that switch Um Okay, so I think this works as our handle touch inputs. Let's make async def um Let's say read sensor Read sensor Yeah, this one I guess This is gonna get passed into here Or maybe I think actually app state should have That's sensor Almost feels like maybe did these be as part of the app state. I'm not sure I Will say also fair warning like this is all cutting-edge stuff async IO has not been in circuit python that long And thus far the only example that i'm aware of of circuit python async IO with display stuff is this one that I wrote last week Um, and I don't claim to be an expert on any of these things. So it's very possible There are better ways to do what I'm doing. We are very much like learning along together right here So it ends up being that the way, you know, certain ways I'm doing this are not the most clear or don't end up being the most efficient That's totally possible Um, ultimately, I'm hoping we get an example that is clear good code that's reusable And is relatively efficient Um, that's where I'd like to end up but fair warning if you're trying to copy the code live or anything Like we might not be there yet Um Yeah stuff may still change App state we've passed in whoa Got the cats throwing down again Function parameters rather than a dictionary is somewhat easier for beginner programmers to understand Yeah, I would agree with that see grover regular function parameters Don't require knowing as much stuff You have to know a little bit more to change it to an object or a dictionary Function has 47 parameters. Maybe it's time to think about it. Yeah That's a good question. I don't know the answer if it matters into python itself. That would that would be a good thing to find out though I do think it's a good question I know like I said, I know pylon does can Complain eventually if you have too many, I have no idea what the cutoff by default for pylon is and it may be configurable Also, I don't know that either but Um, so, you know, at least that tool does think there is some benefit to keeping it lower rather than higher But whether that's efficiency or code readability I'm not entirely sure Yeah cat cam will need to be an action cam. Yeah, I think what I'm going to do is set a couple of them up around a few of the spots where they hang out Mike, there's two cats here One of them tends to stay up in my wife's office a lot more often than not The other one tends to run around and act all crazy Um, not neither of them really just Hang out and chill right near my desk kind of like uh scott's cats do so There are a couple places where the stripey cat That's the boy who runs around more crazily usually there are a couple places where he hangs out So we might be able if we put a couple cameras Um, I can probably pull it up on my computer and we might be able to see him some of the time But I don't have just an easy place where I can set it right by me He doesn't really hang out In one spot right by me very long Um, one thing we're missing. I know I'm like halfway in between writing the second one right now But I just happened to notice this one thing we're missing though is the uh, the sleep thing. Yeah, we need this When the buttons one though, this is closer to buttons Import that And I'll go ahead and put it here as well Before I forget this will be where we read the data And update the labels so sensor label Update sensor data app state sensor app state label This one's gonna loop over and over read the state from the sensor Set it into the label this one's gonna loop over and over Get the touch event check each of the switches Set them true or false According to whether they were touched Then update the color based on which ones are true and which ones are false That sounds right to me one thing we'll do is we added this so let's change that to label Um This sort of makes the code a little bit more reusable as well if you're using a magnetometer you could switch in your own Code like if you had one that's not specifically the lis 3 mdl you could initialize yours here with this name And then uh if it Is a magnetometer then it will have this magnetic Property and so you could actually reuse this code just by changing the sensor You could also switch to a totally different kind of sensor and then you would just be putting different stuff into the label I think what we need next is our main I'm gonna steal the main I think from here We now have an application state Which is gonna get our sensor and our Output label in that order You know other order wrong way Sensor yeah Should be better. Okay. Uh, let's not call it this though I hesitate to call it that because that's the name I used in the functions It's maybe not the end of the world, but it's probably best if we don't shadow it let's see Moving parameters to a class is not holy grail as a newbie And only things are dictionaries under the hood in python anyway Oh, that does make sense. I guess yeah that code and um shared bindings Is very dictionary like so even if you have different parameters under the hood You're ending up with a dictionary anyway Property of multitasking means you don't have to limit the screen updates To one thread Um, yeah, I think that's true Extra, I don't know if that's a question or a statement. I think that's true though I think we'll be able to update the screen from Different co-routines in this case We're not really changing the screen at all. We're not updating the screen from This touch inputs we're reading the touch event and we're looking at stuff on the screen to determine if the touch event's in it But we're not actually changing. Oh, no. No, we are we are changing the color inside of here Yeah, so we are updating I would say maybe there's a case to be made where it might be better. It might make more sense to only update the Screen from one co-routine that could be possible and that's a lot more how like android is structured and android Only the main thread quote unquote main thread is the only one that's allowed to change the screen Um I haven't sort of planned this whole thing out But it could end up being the case where that might make more sense from a code organization perspective and from a like Not updating the screen as much unnecessarily. I don't actually know for sure but All right, so we made a state. We need to create the tasks. So we will have a touch input input task equals async I No, no async Create task and then this takes a function takes Calling a function calling a function. So this is a handle three switches red green blue and an app state what we gave I think you want to be careful about not updating the same screen object from more than one co-routine It could be possible. I do think one of the things that it does explain in this guide though Is that while it feels like things are running at the same time? They aren't actually They are actually still sequential. So I don't believe that there is actually Risk of two things trying to update the screen at the exact same time Um, I think where did it say? I know that it talked about that in here Back in overview, maybe Ah, here we go race conditions. Yeah I'll drop this link here as well This one explains though that they are technically still sequential and that you shouldn't have a problem with Race conditions if I understood it correctly, which is possible. I didn't but that was my understanding based on that little section there Um, so we got our touch input task. We need a let's go with what did we call the other ones like, um Sensor data. Oh, let's call this one just sensor task. I think sensor task You think I'll create task this one will be What did we call that read sensor? Yeah Read sensor and this one just takes the application state. So we give it that And then we do what collect. I think it is or something. Um Oh boy Create all our tasks gather not collect. It's gather. Is this inside of main still? Yeah, and of course our tasks are differently named. So we'll do those. Let's say touch input and sensor Oops task Coroutines switch only when you await So they don't it will never actually run both at once A nice demo with switches. Hey, how's it going k-match got a lot to learn about async. Yeah, me as well That's part of my motivation for playing with it during the streams is to get more familiar with it myself. So Definitely part of that same club Imagine that you could get weirdly hard to debug behavior depending on the sequencing between coroutines possible Could be true, but I don't totally understand async yet either. Yeah, I'm uh, I'm I'm with you I do not know yet either But I'll keep I'll keep a lookout for it and that's another part of my motivation For writing this code out today is to try to discover stuff like that if it turns out that we do run into trouble I'll keep a lookout for it and then we'll figure out how to structure it better Hopefully avoid it. You were mentioning earlier where to look for the widget docs for anyone interested in making new widgets Yeah, yeah, thank you for linking that by the way If folks are if you want to make your own widget kind of like this touch Um the switch that we're using here This is a custom widget and this link that k-match just dropped in the chat is the sort of page that Walks you through the process of creating your own one of those. Um Custom widgets, so it's a really good resource. Thank you to k-match both for linking that and actually I think authoring the majority of it Originally as well. I believe Um, so we gather those do we need anything else after gather? Nope doesn't look like it not in main. So The other stuff that we'll do is show our group And then basically start our main coroutine So we're not gonna have A while true We will start main and I'll go ahead and move down this Just so the code is structured the same as the other one. It doesn't really matter. This could be up there It wouldn't make a difference. I don't think All right, so let's see If this works, I'm sure I have done something wrong I'm sure it will very likely not work the first time Okay, so we have no touch That's better than I thought though honestly this we got farther than I thought I figured we would get a crash To be honest. So the fact that we made it to Running and just have a logic error. It's not doing what I expected. It's actually pretty good Why is it not doing what we expect? So let's check the basic stuff inside of main We gathered part of gather we passed in touch input task This is handle touch events Which wants an extra line These are mad because they shadow the outer name I don't think that should cause it to break So if we print inside Handle touch is this actually happening? Yes. Oh, but it only wants And then this fails We are We are crashing we are crashing But we're not crashing so bad that it can't continue We're crashing only bad enough. So that's actually one thing that you will have to be careful with When it comes to cooperative multitasking It looks like if one of your tasks crashes It does not necessarily crash your whole program. Other stuff could continue working So in our case our handle touch inputs has crashed But our Update sensor data has not so it's continuing to run just fine That is interesting. I did not realize that was the way that worked. So that's good to know Yeah bonus I found with async.io I know what I'm about to give up control with a weight That's a good point as well. Yep, you get to control when those other things are going to step on your toes Basically, you could say, okay, I'm ready for you to step on my toes now rather than just it doing it whenever it feels like it Linux 2.0.3 posted an example of a ackyl example Of a ackyl example Thank you for sharing nice Oh, I like the way you did tasks.append and made a list And then use the star I kind of like that instead of having one big giant gather call happened to me just today crash one co-routine. Yeah I don't know about cpython. I haven't actually played with ackyl in cpython Um A tiny bit but not very much So why don't we crash in here? Let's see Thanks. 113 is that okay, but that's just our gather Line 54 handle touch inputs Hmm. Okay None type isn't subscriptable If p we need if p Because p would be none if nothing was being touched Yeah Yeah, there we go And it is actually working now So we were really close actually I'm actually surprised how close we were I'll take this back out. We don't need to spam this anymore Do we want to Only update colors if there was a p That will save us a little bit of resetting back to the same color I want to say Yeah, but we still do change colors whenever we need to So it doesn't matter too much But this does save us from all the iterations where we didn't touch anything We were previously calling update color We don't actually need to Yeah, so this is back to working. I'm actually Pretty stoked Surprised we got it as easily as we did Feel like this means I'm starting to learn the ways of the the asyncio um Let's uh, let's add in something else Let's um, there is This is analog devices 80 t7 for something temperature sensor. So there's a temperature sensor built on To the pi portal Let's grab data from it as well Just bring more stuff into the mix again I'm kind of just trying to add more stuff and build up good examples. So Um, I don't have a specific need for the temperature But if I can add another sensor into the mix and figure out How to do it and what problems it comes with then It might as well So really what I'm looking for is the name of the library, which I guess will be the same as the sensor probably This is what I'm looking for really Surcup for anybody who doesn't know. Surcup is a super easy Touch, uh, not touch command line about as far away as you can get from touch But command line interface for installing things On your circuit python device, um, you do have to run surcup install If you want to install though, so this is kind of like pip but for your circuit python device Um, this is kind of the way that I install everything nowadays So we have that let's also grab the simple test for that And then we can gank a little bit of code out of it To be able to switch it to asyncio sleep, uh instead of the zeros you mean so we have asyncio sleep zero Like these ones Let me also catch up looks like I'm behind the chat I was hitting array index out of bounds condition in one task. So neopixels did an update after a while Asyncio dot gather awaitables return exceptions false Ooh, I don't know return exceptions. That's a good thing to check into though If that Is in our asyncio as well, then maybe you could pass that and have it change the behavior Or when one task, uh, crashes interesting I wonder if the switch has time dot sleep in it for the animation um It does I want to say either time dot sleep or Um using like time dot monotonic, maybe It does have some way to Wait though. I'm pretty sure It does it seems like it's working smoothly though actually Or is it Maybe it's not No, it is. Yeah, I definitely saw it there Uh, there's uh, there's a couple of parameters you can do also to Change the animation. I think So I guess this would be inside selected probably Yeah, which calls animate switch. So let's look inside of animate switch Okay, so when you highlight a thing and then control f it pre-fills. That's nice So not time dot sleep, but yes, uh, recording a time and then checking monotonic To see if it's time to change again yet Well, maybe Reposition easing There's a couple of different ones of these functions as well. So this is like This is like, um What's controlling the the in-between? Animation like it speeds up at the beginning and then slows down at the end I think there's an overshoot one as well There's a couple others of these where you can swap them out and get slightly different animation effects Um, which is really nice. This is all stuff that k-match made as well. I believe so folks are interested in this I think k-match popped up in the chat a little while ago Um, this is a widget that he created Fantastic how quick we got to add it in that's an ifty library. Yeah, fully agree The mag updates pause briefly when the animation is active. Ah, I see Yeah They do That's true. Okay So while we are animating that's actually stopping our co-routines from running, but the thing that could happen is The switch widget could be rewritten To make use of a sync IO, I don't know if there's an easy way where it could be either or So maybe it would be like creating a new widget that's like switch round a sync IO version. Um Or maybe there's some way it could be either or gonna have both logics in here But if that were done, then we would be able to still Be running the other co-routine in this case the one reading the sensor While the animation is running That's kind of like the next layer. I think of This a sync IO stuff is right now all of our widgets were created Without this a sync IO model in mind, but we could actually start making them With the a sync IO model it could be using the co-routines itself internally I assume those can be functions on a class Um add a light level sensor to control the screen brightness Um, I could probably do that next time. I think I don't think I have a light sensor Pulled out and ready to go and I don't want to go digging through my boxes to find it right now Circle up install requirements works too. That's a good tip. Actually, I didn't I don't think I realized that That you could do the requirements file. That's pretty nifty Yeah, there's some really really cool stuff that happens in the animation of this what scott's talking about up there where it adapts to the frame rate Trying to set up for homey guy slash a sync IO Installed circle, but when I issue So for for one thing I'll say if you're trying to install This is to paul in the chapter paul sk if you're trying to Install specifically my fork the foamy guy fork of a sync IO I don't think you can use circup to do it. Um, I don't know for sure, but circup. I think is pulling out of Well by default circup is definitely pulling out of the published eta fruit library bundle Which will have the eta fruit fork of that repo not the foamy guy one I don't know if there's a way you can pass it a flag or something to tell it to use a different repo If that's possible, maybe you could install mine Um, so yeah, just keep that in mind if you're trying to install specifically mine You I think we'll just have to manually like go to github You could either download it with the green button or you could clone my fork And then copy the code out of there. I don't I'm not sure if you can do it with circup. There may be a way but you would definitely need some kind of flag um, yeah async IO sleep it could do inside of the widget Could not find a connected device. I will say though that error that issue that I was talking about is not Should not be related to what you're doing You at worst I would think this would install the eta fruit async IO Instead of the foamy guy one and that's what I would expect to happen But what you're seeing is it actually says it can't find a device And you have an unexpected maker pro s3 See it as tty usb zero I'm not sure how circup finds the device Maybe make sure that the device the drive name is circ circuit pie. Oh, there's a light sensor built in Oh, is that what the hole is for? Yeah, okay. There's a hole on there. We can maybe we can maybe add that part in Um, yep, take it easy mark. Uh, thanks for stopping by Just did a pip three install on circup and it went okay. All right. Nice See I have a Thing but this was in this room. I think here. Yeah Uh, let's see. Where are we at here? So I was gonna get 80 Something is it still copied? Maybe from my here. I'm here already. Okay examples All right, so we already have i2c. We will need to import it. Let's do let's do that This is the initialization We should probably call these different things though sensors should be mag sensor Here's a list of all the things that found that it wants to change It's good to double check and make sure it's not going to change stuff in other files that we don't want it to Um, probably we should call it mag sensor here And then temp sensor um, I will Let me write this I will mention we're getting close to 7 p.m. My time central time and I know deep dive generally went about two hours Um, I sometimes go a little longer than two hours. So I'm gonna keep going for now But I probably will be stopping within about the next Uh, probably less than another full hour I may go 20 or 30 minutes or something to just depend on where we get with this Mostly what I want to do is get the second sensor put in and then I'll probably stop After I do that. Um, so if folks are like interested in the the two hour window specifically We're coming up on that and if you're heading out, that's cool. Thank you for watching I appreciate all of you that that watched and stuck with us, especially through the rocky beginning there But I will I am also going to keep going for a little bit longer at least I don't typically go over three hours On saturdays, which is when I normally stream I usually go between two and three And I may end up going on the shorter side now that I'm doing an extra day a week, but Just kind of play it by How I'm feeling in the moment and right now I'm feeling like trying to get the other sensor setup. So I'm going to do that Um mag sensor temp sensor But let's call this temp sensor I could have done refactor, but we only have it in two spots. So I'll just copy paste the second one there Um And I think for now, I'll just handle it inside of the same read sensor. This one's nice and generic read sensor I guess we could call it read sensors Yes, we're going to be doing two now, but beyond that, I think it's okay to keep pretty much there And maybe what we'll do is split these off. So we'll have update mag Will we no Yeah, I think we'll keep I think we'll keep them in one function for now actually because I don't want to make a second label I actually just want to reuse the same label Um, and I don't want to reset the text over it after I already set it this iteration The easiest way for me to achieve all of that is just do it inside of here as well All right, again, though, like it's possible that there's a better way To do this and given more time to sit down and refactor it and plane it out I might end up landing on a different solution. But for now I think I want to do this one So we set all of the mag sensor in it and then now let's get the temperature also AdT dot temperature nice and easy Um, so I'm going to go string equals Uh Variable a new line another variable So itself the first one is itself Whoops The next one is the new value which is going to be Actually going to have two sensors Mag sensor temp sensor sensor Then after we've done that we put the entire string onto the label Put our temp sensor onto the application state That means it gets passed into here but It also means it gets passed to Read sensors this one application state Where it then gets passed to update sensor data And then actually read This is still mad because I've shadowed the names. I don't know is that I guess probably It must be Celsius You know, which thing is the actual sensor this thing? Yeah I can get it to go down because my skin temperature happens to be a little cold right now my fingers a little cold And so we got down from like 30 down to 26 there and if I let go then it'll slowly go back up to room temp Um See here, let me catch up on the chat Make sure you regularly update circa Yep That's a good point as well I think there's also a message now if you have a relatively recent circuit It has a check when you run it that will check and see if there's a newer version and it'll print out a message for you Um, the old if you're if your one is too old though Then it doesn't have that yet because it wasn't put in until more recently The perfect will to be nice to separate the sensors into their own co-routines. Uh, I agree see grubber. I think ultimately Given more time. I probably would try to separate this To where each sensor got its own Co-routine I think and or or if not each sensor getting its own co-routine at a bare minimum. I probably would do At least like different function here for each one So like update mag sensor data and then update temp sensor data. Maybe these could be functions and the co-routine calls it Um, but yeah, I would probably I would probably split it out more I just don't want to change too much of the code And I do want to use one label and I don't want to reset the text in the label multiple times in the same iteration Um, which are all kind of constraints. I just added on myself We totally could and I believe it would work, but Um, those are some things I want to try to do and therefore I am gonna stick with it All in one for right now Yeah, I do like this sort of example though that you should Or you've got the separate separated ones there Tip install upgrade circuit Yeah, that will yeah, yeah, that will update your circuit grade flag on pip should um We're pretty good already and we can change the colors. I think this will probably just be working already So that is working. I guess we'll throw a c on there for Celsius that We could turn off some of this this I notice is printing every time I don't really need that part anymore It used to be pretty good. What does Somebody was at cgrover. Maybe your dexter one of the two. I'm not sure which one for sure. Sorry, but somebody mentioned using this Using the light sensor to affect the brightness Um, it's like brightness is a float 1.0 is must be all the way brightness That get darker that one definitely got darker Let's throw that one in as well. Again. I'm gonna I think just tack on more stuff into the Overteens I have now But I do grant it probably ultimately would be good to separate them out control Anybody know by chance offhand the way to use the light sensor Or even what the light sensor is Maybe is it just analog? It's a plain analog in pin We pin out speed So name be a light sensor. Yep board dot light Can read it as an analog value Okay, so that's pretty easy we can go Put a python essentials There's an analog page in here You can basically just do the same stuff Let's go light sensor Uh, no, I don't necessarily need the temperature accurate to four decimal places. We could totally chop that down I just threw the straight value. I got off the sensor in there. Let's create an analog in Get voltage So let's just I think let's just print it to start with And we could do that inside of I think read sensors Actually, we're not really updating to the screen. I mean we're gonna change the brightness of the screen I think it makes a little bit more sense actually to do it outside here, though The coroutine directly and it doesn't really matter if we do it before after we do the other ones I'm gonna add one more These to my state Which should be designed like this to keep the animation looking live. You may miss some of the animation Feel if you're doing other computing at least At least the animations will compute with a known time. Yeah Light sensor. Thank you. Carter. This is the part of the schematic Which has our light sensor So we gave it to state Inside of our coroutine. We're reading it off a state Printing it so we should start seeing those show up in the ripple and if I I don't know if it will work how I was thinking Because honestly, we're not I know you don't have the camera anymore We're not getting They're a little bit different when it's covered. It looks like I'm getting We know for ish But occasional one spiking up into the point o fives And occasional one spiking lower into the point o threes I didn't saw a point o six there as well And with no finger covering it. We're in the fives point o fives point o sixes there's Relatively little difference though, honestly Biggest thing is these seem to get down into the 40s, but some of them are still poking back up into the 50s I'm thinking Yeah We're on like the very very low End of The capability here. There's really really minor difference between Covered up entirely with my finger Versus not covered up at all and just absorbing the light ambient in this room If I shine a light on it, which is what I just just did here We can get much higher numbers and if I really get the light right up in it We can get even up above one or two But the ambient light we're really splitting hairs down at the bottom end of the range here We could still probably map it and Give it a range of brightness Since there's somewhat directional Need to turn the output to a scale of 1 to 255 The hard part about turning it to 1 to 255 though is we don't like technically our range is Zero to I guess probably 3.3 or whatever the voltage after the regulator is But we're not really using that full range the actual range of like what we legitimately get with Without shining extra light on it Is very very small like maybe 0.04 on the low side and like 0.05 8 Ish on the high side We could map just that range But then if we dip below it or if we actually have more light like what i'm afraid is if I put that code in To map it to 0 to 255 today right now It's about 6 15 p.m. My time here. The sun is like on the way down But not all the way set yet if I put that code in right now It will work for this range And we could set it up to where brightness like full brightness, you know 0.58 ish goes to full and then 0.04 whatever goes to You know 10 brightness or something we could set that range up What i'm afraid of though is like i'm going to turn this thing on tomorrow morning when the sun is actually out And my range might be a little bit higher right then tomorrow morning when the sun's out we might be getting like 0.5 on the low side and 0.8 on the high side or something and that's going to change The math in the in the range Which is not to say that I can't do it We definitely could and we could make it a way to adjust it But I think I want to probably hold off. I think I want to come up with I think I want to come up with something different for the brightness because I think I want I want to If we're gonna hook it up based on the brightness in the room. I want to be able to use like More of the range we're so close together on the low side and the high side that we would have to clamp it Super duper far and just look at one little sliver of what's available Which means that if the conditions in the room change just a little bit Then like we're always going to be all the way on because if we wake up tomorrow and turn this on and with the sun out and shining The low end we're getting maybe is 0.55 or whatever, which is kind of the high end we're getting tonight Then we basically be full brightness Maybe add an awaitable selected method. Ah, okay. So yeah, um, that's back to the idea of implementing Async.io inside of the widget One way that we could have it support both maybe is have a different method for selected that's meant to be awaited Which I do I do like that idea if it works if it works that way. That's a good idea Dexter. Thank you Uh from a guy created a project folder in windows 11 ran vs code start a terminal ran pip 3 install circuit this one successful And then also install async.io Which does also look uh successful to me at least as far as I can tell I can't blow it up super big But it looks like it worked to me. So nice Map range. Yeah map range. The function to do it is right there. Thank you linux 203. That's definitely the function we could use Uh in zarnolin as well. I think talking about the same concept. We definitely can use the map range I think the problem though that I'm that I'm seeing is that Because we're not using the full range of the sensor and in fact because we're using such a Very very very very small section of the full range of the sensor If we choose values to map it to Tonight, I think they're not going to apply tomorrow, honestly Or I think they're not going to apply in different lighting conditions is is the root of it Um, this is such a miniscule portion of the range Like we I think we would end up having to come back whenever we ran this in the future and adjust the values That we're mapping the range to Maybe we could make some scheme where it's like there's a configuration mode and you like cover it all the way up And then you uncover it and it records the the minimum and the maximum and then it could base it off that so it could be dynamic Um, but that is a little more in depth than I do want to get into for right now Each remember. Yeah, it's the voltage Being read from the pin. That's true dx dt to the rescue Might not be a linear scale Isn't brightness hard to make feel linear because the eyes are non-linear. You could do simply a mapping of highlight adjust The light adjust Yeah, I think that's true. I think that's what I'm kind of describing but I I want to I don't know call it stubbornness or something. I would I want to try to Come up with a way where there's not these values that I would need to change based on the ambient environment, um It would make a good example But the problem with I think sharing it as an example is then somebody else would set it up And it would not it would appear to not work They would run the code not necessarily understand it and say hey The light sensor is not working because my brightness is not changing When in reality like maybe they just need slightly different values for these Uh Things that go into the mapping which we could try to add comments and instructions and tell them to do it And that's totally cool as well but It's I want to think of something different. Basically. I want to try to I want the example to Hopefully work the same for everyone Without having to adjust any values if possible So if there's a way we could do that like dynamically like I was talking about maybe they do a setup where we're like, okay You know, uh, one two three ready set go put your finger over the sensor For you know four seconds or whatever and then they put it over And it takes readings and it stores them and then it's like, okay ready set go one two three Take your take your finger off and it records more readings and it saves them and then it uses those dynamic values Something like that maybe could work and then you wouldn't have to adjust them But that's also a little bit more than I want to do right now So I don't think we're gonna do it It's too slow to type the examples. Yeah No worries. Um, yeah, I think I think what I'll do actually is let's back out of the light sensor for now Let's go back to no light sensor and I'll come up with another way You know, what would be nice to though is like I maybe we could have some other control on the screen um You know what would be really cool is if we had a slider bar If we could have a slider bar on the screen and you could scroll it like all the way to the right for max brightness All the way to the left for men brightness Then it just works the same for everybody and it gives us another Interactive bit to write some code around Yeah, I think that actually slider bar that might be what we ultimately do But I don't think there is Oh, uh, who did I see made a slider bar? Um I have seen a slider bar somewhere. It was um Somebody else did a stream Somebody else in the community did a stream Only like one or two Um Gosh, okay, they made a whole framework. They did this is Slowly coming back to me. Who was that? it's um Kind of blank somebody made a whole like application framework. I think they made it for a watch they were working on And as a demo of their framework, they did a stream one day And they showed a slider bar Oh, it's killing me that I cannot come up with the name right now I wonder if we just I think we'll get mega lucky on google circuit python Display framework Joey castillo, this is not who I was thinking of but this is also a person who made a watch And it looks like some kind of gooey Um display framework. I've not it looked into this one This is actually a very similar concept to what I'm thinking of right now though That the other person made so we did actually get pretty close with google But that's not the one I don't Go I was thinking of Anyway, I won't um I won't sit here and search through it All right now. I'll try to come up with that though and If I can figure out who that was I'll share the link next time and maybe we can go find their uh Their slider bar. Maybe okay one more try. Let's see if we're gonna spin the google wheel one more time What if we go circuit python Slider Slider widget sunrise camera Let me slider widget. Oh, hey, here's one on pi pi. Yeah, passata. Okay. This was Jose Okay I didn't know as I made this I don't think I've seen this one before this looks like what we need though So I'm glad I gave the google Sheen one more spin actually because we could use that one maybe Tech, uh, it's tg techie. I think it's tg techie GitHub tg I think is tg techie's name. Yeah. Yeah. Yeah, this is it um tg gooey This is the framework they did a stream one day They showed an overview of this framework and how to write code for it And during the stream they showed um The widget which was a slider widget so we made it there. I don't know if it's tg slider or something Or if it's it maybe is it part of gooey? Do the widgets live inside of here? I'm not sure how the project works Oh qt. It looks like maybe you could write code that would also run on uh d python Those have widget styled widget Payout stack prelude Would prelude be I'm not sure what that is. Anyway tg techie. This is who that was. I have no idea if that video is still out there It was a fascinating look though at this framework that um Jonah has created And i'm pretty sure That there was a slider in it, but actually now that I found this one that jose did looks like about a year ago Maybe we'll try this one out and then get it Uh up to if there's anything we need to update for new circuit python or stuff like that We'll get it all updated and then maybe we could pull this into um circuit python ord as well Jose has been a little bit less active lately But did do a bunch of work on the widgets and stuff with me a little while back and is one of the members of the circuit python org Um, yeah, joy castillo zarnalyn joy castillo is the one that did the castillo watch. Uh, how's it going? Um Johnny yep looks like I didn't check the chat for a little while but scott was right tg techie Is who did that gooey framework? Maybe just display the light sensor value and don't use it to change anything. We could do that Definitely could do that Joey Castillo is who's working on the watch stuff the casio watch stuff tg techie was also working on a watch um But not I don't think it was like the casio clone watch it was Uh more like a smart watch honestly, I think it had a little lcd screen there's Watch software watch 2.0 pcb You watch looks like this one is the one most recently updated See a photo or anything though I think this watch though that jono was working on is why he created the Framework and then ultimately did that stream and showed the um Slider so that was down down a bit of a rabbit hole But I encourage folks if you're interested in display i o And widgets and frameworks and things and ways to write display i o code I encourage you to take a look at tg gooey. It turns out was the name of it Um because this is also kind of an interesting Framework to build applications with um Yeah, that's one thing we could do the progress bar to output it although the progress bar then we do still have a similar Issue of like because we're using smut such a small range of the actual sensor value Um, we have a similar problem with the progress bar. We have to decide What number maps to the full progress bar and what number maps to the empty progress bar? and If we choose the if we choose the full range Then because our actual sensor is using such a small portion of it Our progress bar will be mostly empty the whole time If we use a much smaller range then our progress bar could look full sometimes we run into that same problem I was describing earlier where if the ambient light changes Those values that we map to the full and the empty Would need to change as well. So those would have to be variables to get updated or something like that Um, I do like though printing it on the screen. I think we'll maybe add it Into the label uh and change the scale. We probably need to go a little bit smaller We'll add the light sensor there and then I would like to maybe make a slider Uh control on the screen Which you can slide back and forth and then it does the brightness But I think I'm going to hold that stuff for tomorrow. So we're at about two and a half hours now I got the second sensor put in we started looking at the light sensor But I think I decided that this is how I want to do it Show it on the screen on the label And then add a slider that will control the brightness. So light sensor and brightness will be decoupled They won't actually be together But it will be a third sensor that we're reading and showing the value of and then we'll also have a fourth input Being that touch slider which will then affect the brightness And I think I'll do that stuff tomorrow though I don't know I'm ready to hop off for now and get some food and do some other stuff. So Um, I super appreciate everybody who is watching. Thank you all uh for tuning in and hanging out in the chat talking back and forth Yes, tg paul sk. That is the um, I realized I pointed over there. Maybe I should point outwards at the camera But yes, that is the watch I believe that's the watch. Oh, that looks like somebody found the stream. Thank you cgrover Thank you to scott For doing all the deep dives before this being one of the major inspirations for me streaming at all And then also of course for giving me the opportunity to continue the deep dives Thank you to everybody else if you want to see the conclusion of this Exciting example code experiment Check out uh tomorrow. I'll be on it 10 a.m. Central time, which is about what is it? it is uh So five and a half hours would get us to midnight my time and then it's 10 hours after that so 15 and a half hours from now Whatever time zone you're in In 15 and a half hours. I will be back streaming But I will not be on the ate a fruit account. I'll be on my own So foamy guy underscore twitch is where you can find it And if you come to the discord the live broadcast chat discord, which we have on the stream here I always put links in when I start so I'll link the youtube and the twitch In that chat when I get going and I think I will pick up this Project and work some more on it tomorrow morning. So thanks again everybody and I


Alright, let's see. So I'll do this Andrew question, but really this is the last question. Just came for vacation in DR. DR is Dominican Republic and was wondering what you thought of economics in the Caribbean overall in terms of poverty rights, individual rights, investing, etc. was thinking about retiring there someday. I mean if you're an American Andrew, then the place to retire is Puerto Rico because in Puerto Rico you have property rights and individual rights to the extent that the federal government enforces them and you don't pay federal taxes. And if you structure your retirement right, you don't pay many taxes at all. So there are massive advantages to Puerto Rico over, if you're an American citizen, over place like the Dominican Republic. I think the problem with the Dominican Republic and the problem with the rest of the Caribbean, well with some exceptions like the Cayman Islands maybe and maybe the British Virgin Islands, is that there is no respect for poverty rights and individual rights and you could have a flip in the regime or something would happen and they decide to rob you of everything that you have and there's no protection against that. That's why I like being in Puerto Rico where I'm still protected somewhat by the rule of law, the American rule of law. I don't think you get that. Now Cayman Islands, the islands that have a more British tradition have more of a rule of law tradition and therefore I would feel more comfortable in if you don't want to come to Puerto Rico. Poverty is bad in all the Caribbean. Again, Cayman Islands might be an exception and poverty is a problem in Puerto Rico and it's one of the main issues here.