The Factory | Huge MicroPython Speed-Up With WS2812 LEDs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to the factory we have been doing some production this week first up we've gone through some new glow bit led modules we're finally getting into it we're manufacturing the new globet modules this time with the black ws2812 leds just to remove that visual impact of the white leds [Music] a little bit of construction work happening next door but we're just gonna have to deal with it so bear with me just so you can see now an in the flesh comparison between those leds and i think that for our new line of glowbit hardware this is going to be a really nice touch so we've got the 4x4 matrix which tiles in one direction very easily we've got the glow bits stick which ties in one direction very easily as well that has eight that has 16 leds looking nice we're testing them right now we're bagging them and we should be releasing them pretty soon stay tuned we actually made the call with the 4x4 to remove all the front-facing artwork because you know all the pin labels are on the back so we'll just keep that face nice and blank nice and clean for everyone that wants a very clean display and i can tell you that using the new production line equipment is an absolute dream the really really big changes were the oven which now has the rails so we can go straight from the pick and place machine into the oven with no human interaction and really importantly the oven now feeds into the pcb loader so once that pcb comes out of the oven it just gets automatically loaded into a cassette which for panels like these that only take a few minutes that's a really big deal before we'd have to be getting up every couple of minutes just to catch the panel as it comes out of the oven but now it just gets automatically pushed into a pcb cassette and you'll see that that cassette just indexes down to the next row and that gives us the capacity for a hundred panels theoretically a hundred panels without any human interaction which is oh this is going to be good there's been a little while since we've released a pkdf module we just released the picodev three channel capacitive touch sensor earlier this week and we're hoping to get at the rgb module very soon as well as the light sensor so we'll be doing more productions in the near future now here's the thing putting leds on a pcb and soldering them is really the easy part there's actually a whole that's that's probably only a quarter of the effort that goes into making a product like this really what's going on behind the scenes with these glow bit modules is all the work that brenton's putting into them to get them really beautiful and easy to use in micro python things like turning the led index into an xy coordinate so you can just treat the thing like a screen with xy pixels getting really pleasing demos together so that your first experience is like really gratifying straight away you you can be inspired with what you can do with these modules and so in his journey in creating these drivers and these examples brenton's actually made what i think is a really non-trivial contribution to micropython and that is he's sped up the ws2812 led driver a lot it's actually kind of bonkers we started off with the example that was in the data sheet for the raspberry pi pico and we've made it at least a couple of times faster so i'll hand i'll hand things over to brenton so he can walk you through his changes so over the last week i have been hard at work trying to make glowbit.py the glowbit micropython driver to allow you to get started with our globet products as fast as possible on something like the raspberry pi pico now one of the beautiful things about micropython is it is really really easy to develop on compared to other programming methods like c or arduino but it comes at the cost as mostly being a little bit a little bit slower or significantly slower depending on what you're doing so one of the things i've been trying to work out is how to make micropython code run as fast as possible the feature we'll be talking about today is the micropython viper decorator effectively the micropython viper decorator will compile a small snippet of micropython code basically just a function that you've written and it will compile it to the native machine code of the device you're running on so for the raspberry pi picker we've got here it will try to compile it to the machine code for the cortex the arm cortex m0 plus which is an um thumb assembly device so let's look at the code we'll be demonstrating today it's currently running the demonstration on your right there we've started with the code that's on the core electronics website um just in the guide for getting started on the raspberry pi pico with the ws2812 or you know the device that the globets are made from um and at the bottom of this code i've got some code here that runs the runs the demonstration in the background i don't want to talk too much about how this is working at the moment the code's a bit rushed and ugly a more polished version of this is going to be included in the glowbit library i do however want to talk about two particular functions one of them is this draw drop function here which is as you can see an unrolled loop which draws several pixels to the screen at different x y coordinates and the other function here panel transform which takes an xy coordinate on our 3x3 tiled matrix here and turns it into the address for that individual pixel you'll see at the top of these functions i've got a commented outline that says at micropython.viper this is what's called a micropython decorator effectively what's happening here is the microphyton interpreter is calling a function called viper and then that function in turn is running the code inside the function that we've written this is all built into the micropython interpreter and effectively what this viper function does is it takes your micropython code and compiles it to machine code it's basically a very basic assembly compiler you know python to assembly compiler um and down the bottom here i've got a frames per second counter at the moment we're sitting around 10 frames per second which is going to be fine for a lot of animations but let's see how fast we can get this to go before we actually run it at full speed we need to talk about a little bit of extra syntax that's been thrown in here you'll see in the arguments list for this function we've got this syntax here which just tells the viper compiler or tells python that x is going to be an integer likewise our y coordinate is also going to be an integer and this little bit of syntax on the right here says that the return value will be an integer this is one of the compromises you need to expect if you want to try to write micropython viper code you have to specify what the argument data type is effectively it needs to know what the data type of every single variable is or it doesn't know what to do with it if we scroll down to our draw drop function it's got exactly the same thing it's got a self argument because this is actually inside a class i don't really want to talk about that right now it's beyond the scope of the video but the x and y coordinates that are being passed to it again they are specified as integers so let's just quickly run this without um this commented out we'll bring in the micropython.viper on that function and we'll bring in the micropython viper there and hit control r to run this and you'll see straight away we've jumped from 10 to about 20 to 23 frames per second this varies it varies with the number of raindrops that are being drawn on the screen but we've got almost a doubling in speed improvement just by using micropython viper decorators on two of our crucial functions there's a few things you should probably be aware of before you start jumping in using micropython.viper everywhere one is that you can't have default values on your arguments so if i say that x is by default zero here and try to run that we're going to get an invalid syntax here we get a syntax error if you're specifying the data type for a viper function you can't specify a default value another limit is that the return value can just be basically it has to be an integer there's a few other return values that are supports but you're basically limited to just having a single value being returned you can't return lists of python objects or something like that you can only return single values and lastly this is perhaps a huge one for some people but you can't do what's called emulated floating point operations if we go say down here and say instead of instead of 8 that that's an 8.0 that's going to start doing what's called floating point calculations okay the so floating point calculations is when a large um you know decimal fraction library is brought in because the cpu we're using can't do floating point calculations natively if we try to run that we're going to get another error and it says yeah we can't do an operation between an integer which is what this variable mc here is and object in this case it's trying to turn 8.0 into a floating point object micropython.viper won't let you do that and lastly this does break portability with c python so if you're writing python code that's going to run on a raspberry pi and on a raspberry pi pico micropython.viper will cause errors when you try to run this on your raspberry pi we are developing a workaround for that for the glow bit library so that's that's going to be okay you'll be able to see that when that library is released but for now just be aware that you're probably going to break portability maybe this will work fine on a pico and it won't work fine on say an esp32 based dev board there's going to be a little a few gotchas there micropython.viper is very much an experimental feature if it works great if it doesn't work you sort of just have to live without it if you would like to know more about how to use the micropython.viperdecorator or as the documentation calls it the code emitter we'll leave a link to the documentation in the description below we've also been assembling our picodev oled module and this is probably the most challenging module to date it actually requires a hand assembly step the final step in the process after we pick and place the boards we run them through the oven we clean them we dry them there's still one more process to do before testing which is to solder on the oled module and then tape it down in place and then test and so this is a manual operation for now there are machines that will do this but man it's it's such a at the moment it's such a niche application soldering this 30 pin flat flex cable but for now we're doing it by hand with like this t-bar soldering tip so we solder that in place in a jig that we made just out of some fr4 and then we take the oled module down and test it in our jig and that's just a test pattern where we illuminate every pixel and then just like remove or print in black pico dev just so we know that the data that's coming through is sensible it's not just blanking white for some other reason so we're working through all our productions on picodev globit makeverse and that means that you ought to see a bunch of juicy new hardware hitting the website very soon stay tuned so there you have it a bunch of new hardware goodies and some major major improvements to the micropython ws2812 drivers if you have any questions or if you just want to have a chat open a thread in the core electronics forums and until next time thanks for watching [Music]
Info
Channel: Core Electronics
Views: 2,177
Rating: undefined out of 5
Keywords: Viper Code Emitter, Viper Code Decorator, Viper Decorator, How To Speed Up MicroPython Code With A Viper Code Emitter, How To Speed Up MicroPython Code With A Viper Code Decorator, Maximising MicroPython Speed, Viper For Micropython, LED Matrices, GlowBit, NeoPixel, WS2812, WS2812b, Pick and Place Production, Pick and Place Machine, PCB Assembly, Reflow Oven, How To Design A WS2812 LED Matrix
Id: zC-vDwFpGXU
Channel Id: undefined
Length: 10min 57sec (657 seconds)
Published: Thu Oct 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.