MPU6050 with Raspberry Pi using python in easiest way | Accelerometer | Gyroscope | Temperature

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we won me a legit with a new video and in this video I will show you how you can use one of these in pew 650 senses which has very PI to get accelerometer data gyroscope data and temperature data using Python so let's get started [Music] now at first we have to connect this MPU 6050 with Raspberry Pi now as you can see there are total eight pins but we need to connect only four pins the VCC ground is da NaCl now let me first connect this with that as very pi so as you can see here I have connected the VCC pin of the IMP you 6050 with the VCC or + V PI I mean the five old pin up Raspberry Pi and then we have to connect the ground pin of the module with the ground any of the ground pins in today's berry pie and SDAP number module with the SDAP number - berry pie and finally the SCL pin of the module 2 de sel pin of the Raspberry Pi and that's all about the connection so once again I am showing you the connections so as you can see the pieces you will be going to any of the 5 volt pins in there as verify so you can connect this with this pin or discipline so this these two pins are 5 volt pins and ground will be go to any of the ground pins in raspberry pi and the SD will be go to go to base da pin and IC l will go to the SCL pin and this is all about connections now after two connections are done we need to get into the PI and code it now as we know that amp you 6050 has 3-axis gyroscope and three axis accelerometer and also a temperature sensor so we are going to write a code to get those data from the sensor and we'll plane those data in the terminal ok so now let's get into the PI so here I'm using puddi to get into the PI - SSH now here you can see I am inside the pie and now at first what we need to do is we need to enable the serial communication out I to see communication for that you need to go to sudo s 5 config and here you can go to the interfacing options and there you will get this I to see you click on this and if it is asking that if you are one to like enable or not so you click yes and then you just finish it and that's it okay so like this you need to enable i2c and then you need to check that if you have connected this like this sensor properly or not or your if your as bleep I have detected distance R or not to check this you need to simply write I to see detect why and here you might get one and you just click enter and as you can see here is showing 68 so if you also can see this 68 here that means that it has your as berry pie has detected the sensor properly so this is the address of the sensor ok now we need to install few libraries ok so to install this you can simply go to my github people study and there you will get this commands and you can just simply copy them so we need to install Python 3 smbus so you first install that in my case it has already installed ok and you also need to install a Python library which is imp you see CPP raspberry pi so so we also can write a code from scratch but this will make it more easier and if we can write the code in four to five lines eventually ok so after this we need to write the code so just write and I know let's say mu 60 50.5 60 50 dot pi and now we need to write a code so for the code you can go to my depository and here you will get the code also you can just clone the depository that will be also k so it is very small could actually because we are using that library like I said so let me explain you the code first so so if you see here so at first we are importing that m2 6050 library ok access you are importing the 6ut library and I'm also importing time just because I just want to use a slip and then here we are initializing the object used as MP u now as you can see here I am writing 68 and this is because last time I have shown you that the address of this sensor is 68 and 0 X is just because it is a hexadecimal value so by mentioning this address I am initializing this object in pew and after that I am just using an infinite loop because I want to print all those extra meter gyroscope and temperature values continuously okay so here to get those values is quite easy you just need to write impute or get them to get a temperature okay so impute get m2 is going to give you maybe absolute value I think and then I'm just converting this into our string and then just printing with temp okay and here i'm using print to just make a gap okay and the same way I am here getting the extra meter values Excel data and here we are just writing impure dot gate Excel data okay so instead of gate M we are just using gate accelerator and and then I am just so it will going to return me our dictionary and in this dictionary I can simply use XYZ as keys and then it will give me the axilla acceleration in x axis acceleration in y axis and acceleration in z axis and I'm going to print all those values and then I am just getting that gyroscope data using the gate gyro data function and then I mean printing that using though that dictionary using XYZ Aki okay and that's all about the whole code and then I'm just giving a sleep time once again okay so like this using this function calls you can get those data and you in your court okay in my case I am only painting it nothing else so let me just run this code and see what happens so you can Superior write it like this and save it and then if we just run it with might on three Python 3 and Q 6 Q P dot pi so if which is clicker as you can see it's printing the data properly okay so as you can see the temperature is not changing that much okay and this valve is also constant now if I just move this sense a little bit so you will see this value is going to change okay Dory's our temperature will not change that much but this values this extra acceleration and gyroscope values are going to change okay so like this you can use this okay so that's all about okay thank you for watching this video and I hope you liked it so please subscribe to my channel for more this kind of videos thank you
Info
Channel: SPARKLERS : We Are The Makers
Views: 43,138
Rating: undefined out of 5
Keywords: mpu6050, raspberry pi, temperature, accelerometer, gyroscope, python
Id: JTFa5l7zAA4
Channel Id: undefined
Length: 7min 41sec (461 seconds)
Published: Fri Feb 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.