PiicoDev Motion Sensor MPU-6050 | Raspberry Pi Pico Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's measure how our raspberry pi pico moves using a picodev motion sensor the motion sensor is a six axis inertial measurement unit which means that it can measure linear acceleration and angular velocity in three axes each we'll wire these two together and get some example code working to see what this thing can do let's get started [Music] to follow along you'll of course need a raspberry pi pico this one with pins soldered facing down a picodev motion sensor and expansion board for raspberry pi pico and a picodev cable to connect your sensor start by plugging your raspberry pi pico into the expansion board making sure that the usb connector is on the same side as the 2 pin battery connector you can double check that pin number 0 on the expansion board is to the left of the usb connector find the pico dev socket on the bottom edge and connect your cable and then connect the other end to your motion sensor i'm going to use a picodev platform to keep everything nice and secure and connect to your computer with a usb lead in the article for this tutorial find the download section and download the three files that you'll need for this example right click each link and select save link as save these somewhere that makes sense i'm saving mine to a pico dev folder in my documents open up thony and use the file pane to navigate to where you saved your files we have a getting started guide if you need help with funny select all three files with a shift click and upload to the files are uploaded to the raspberry pi pico we're ready to run the example just go into the shell and press ctrl d to reboot and we can see immediately there is some acceleration data streaming up the shell it's a little bit tricky to read but the x and y values are very close to 0 and the z value is about 9.8 meters per second squared a little bit easier to see that in the plot so we have blue is x orange is y and z is red and we can see z is floating up there at about 10 meters per second squared let's check that makes sense on the silk screen label on the motion sensor we can see the x y and z axis labels and positive zed is pointing straight up this little dot is the head of an arrow that's pointing straight up but that would mean that the device is accelerating upwards at 10 meters per second squared now i know that that's about gravity but why is it in the positive z direction well this is an inertial measurement unit if we were in a rocket ship in space that was accelerating straight up at one g that would feel to us exactly the same as standing on earth's surface under the effect of gravity and that's why the z acceleration is currently positive 9.8 meters per second squared if i roll the sensor onto the side i can make z fall off to zero and now x is at positive 10 meters per second squared and if we return to that label that makes sense the x arrow for positive acceleration is pointing this way so if i point that arrow straight up we get a positive x acceleration now if i give the sensor a shove to the left in the positive x we can see a positive spike and then a negative spike and if i shove it to the left we get a negative spike followed by a positive splat in that x-axis if you think about it that makes sense this is an accelerometer that we're using so to shove it to the left i have to first accelerate it in the positive x direction which gives the positive spike and then to come to a stop i have to decelerate it which means accelerating it in the negative x direction to bring it to a stop so i get a positive spike followed by a negative spike and if i move it forward that's positive y so i can do the same thing with the y axis and of course up and down is the z direction let's take a look at this example script we'll work with the script that's saved to the raspberry pi pico so stop the script with ctrl c to halt execution and open up main.py on the pico here's what's going on we first import the pikadev motion sensor package and also import the sleep function so we can create a delay we create a variable called motion and assign that we create an instance of the motion sensor and call it motion then in an infinite loop we read the acceleration data with motion dot read excel data that reads our three axes of the accelerometer and that returns a dictionary so to make the next line a little bit easier to read we read the x value from that dictionary and assign it to a variable and we repeat that with y and z then the next line just prints all that data we print x colon and then we print the data for acceleration in the x direction and because that's a number we convert it to a string and concatenate it in and then we just repeat that with y and the string of that data and z and the string of that data and if we come down past all this commented out code at the bottom we have a sleep for 0.1 seconds or 100 milliseconds there's a little bit more going on in this script though i'm going to first comment out using alt 3 comment out that print statement to keep our shell a bit cleaner and uncomment this whole block using alt 4. before we were reading from the accelerometer now we'll read some gyroscope data save the script and restart with ctrl d now we have angular velocity coming through in the shell and the plot for that is much more interesting just as before we can look at the axes and read off which is the positive direction for each axis we have the x the positive x direction arrow pointing this way and using the right hand rule that means positive x rotation is rolling this way so if i tip the whole platform towards me i should see a positive spike in the x-axis and that is the blue axis i'll try to be as steady as i can and then do a roll towards me and there it is and you can see that that peaked out at about 250 degrees per second which means that if i flick back to flat that should be a negative roll and that was at 250 degrees per second reading the z-axis positive z in the acceleration is this way and positive z in the rotation is this way you can see that arrow curling anti-clockwise so that means an anti-clockwise rotation is positive z and let's give that a test there it is there's that positive z-hump just like acceleration we get a positive impulse and then it falls to zero as i slow to a stop this time though because it's not acceleration it's angular velocity the velocity is remaining positive it's just that the rate then falls to zero as i come to a stop all right last example we'll comment out the gyroscope print and we'll skip temperature that's not as interesting i think we'll jump straight to g-force so i'll uncomment this block with alt4 save the script run with ctrl d and now we are just measuring the absolute g force experienced by the sensor so we're very very close to one g and that makes sense we're experiencing one of earth's gravity interestingly if i very slowly roll the sensor and just rest it on the desk in any orientation that value always settles out to about one so this is like the absolute g force if i accelerate the sensor side to side i can create higher g forces but what i think is more interesting is what happens if the sensor experiences freefall if i carefully drop the whole platform without breaking anything we can see that the acceleration or the g-force gets very close to zero there we go that was a good one if the sensor experiences free fall the the g-force gets very close to zero free-fall is zero g so we can detect free-fall by looking for samples that are very near or at zero g-force now the unit that's being plotted is gs but that's because we have this argument that we're passing into the function which is g equals true if we stop the script ctrl c and either replace that with a false or if we just remove that we can just leave it as no argument and re-run the script then now the g-force is being plotted in mid absolute meters per second squared so you can choose to either have gs or meters per second squared so there you have it a bit of instant gratification reading motion data using the pico dev motion sensor if you make anything cool from this little starter project we'd love for you to share it in the core electronics forums that's also the best place to ask technical questions until next time catch you later
Info
Channel: Core Electronics
Views: 15,375
Rating: undefined out of 5
Keywords: How To Use MPU-6050 Motion Sensor With Raspberry Pi Pico, How To Program MPU-6050 Motion Sensor With Raspberry Pi Pico, How To Program A Motion Sensor With Raspberry Pi Pico, How To Measure Motion With Raspberry Pi Pico, How To Measure G-Force With Raspberry Pi Pico, How To Measure Acceleration With Raspberry Pi Pico, Raspberry Pi Pico Motion Sensor Measure, Raspberry Pi Pico, MPU-6050, Motion Sensor, How To, Guide, PiicoDev, Accelerometer, Gyroscope, Angular Velocity, Linear Velocity
Id: rcaA81l-spw
Channel Id: undefined
Length: 9min 18sec (558 seconds)
Published: Tue Jul 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.