Pages

Saturday, August 29, 2015

Physics 295 Project / Connecting MPU-6050/GY-521 to Arduino UNO

It was a while since I wrote the last post. I have some of them almost ready to publish, but they still need some polishing. Recently, I've enrolled in the course called Physics 295; it's an independent research in physics. Check out the video below:



The video shows Far Horizons Project at the Alder Planetarium in Chicago. The project uses a weather balloon to perform experiments at high altitudes. It flies over 100,000 feet into the stratosphere, as it goes up, the air is so thin the balloon expands until it ruptures. Here is the view:


As you can see, the camera moves in every direction, but our project is to make it rotate into one, set direction without all of that swiveling. My role in the project is to program the Arduino with all of it's component to fulfill that goal. I'll post the pictures of the construction next week, so you'll have a better idea of what it looks like.

Today, I would like to show you how I connected the MPU-6050/GY-521 Accelerometer with Gyroscope. The MPU-6050 sensor contains a MEMS accelerometer and a MEMS gyroscope in a single chip. More on it, here. 


MPU-6050/GY-521

Connecting MPU_6050/GY-521 to Arduino UNO

Step 1: Arduino connections



Here are schematics and graphics, please notice that you have to connect the power to 3.3V.




MPU-6050/GY-521
Arduino UNO
VCC
3.3V
GND
GND
SCL
A5
SDA
A4
INT
2


Step 2: Upload the code and test



Download the Arduino Library for MPU-6050/GY-521, extract the library. Copy/Cut the folder ‘MPU6050’ and paste it in C:\Users\UserName\Documents\Arduino\libraries (Windows OS), or in the Arduino’s library folder (for other OS).

You should see the library’s examples added to your menu.




The other way to do this after you download the zip file, without extracting it, go to Sketch > Import Library... > Add Library... > Select the location of MPU6050.zip file.

Add I2Cdev library following the same instructions.


Before we start, let’s calibrate MPU6050. Open AccelGyro_calibration file and upload it to Arduino.




Next, open up a Serial Monitor and set the baud rate to 115200. Make sure, the sensor is placed on levered surface in horizontal position, with package letters facing up, and don’t touch it until you see a finish message.






Make sure you note the offsets and close the sketch.

Open the example program from File > Examples > MPU6050 > Examples > MPU6050_DMP6.


Inside the code, supply your own offsets from the calibration, make sure you type them in the right fields.



After all is set, run Serial Monitor (115200 baud). At this point you should see the values coming in from MPU-6050/GY-52.



Step 3: Model values from MPU-6050 using processing.


Download processing IDE. Open up MPU6050_DMP6 from examples library. Comment #define OUTPUT_READABLE_YAWPITCHROLL  by  //#define OUTPUT_READABLE_YAWPITCHROLL.

Uncomment: //#define OUTPUT_TEAPOT  by  #define OUTPUT_TEAPOT.




Upload the sketch to Arduino. Then open processing example for the MPU-6050. File > Open > navigate the folder where your MPU6050 library for the Arduino (Windows: C:\Users\User_Name\Documents\Arduino\libraries\MPU6050\Examples\MPU6050_DMP6\Processing\MPUTeapot).

Inside the code, change the values (notice, you’re not in Arduino software now, you’re in Processing):

Comment - String portName = “/dev/ttyUSB1″  by  //String portName = “/dev/ttyUSB1″;

And uncomment - //String portName = “COM4″;  by  String portName = “COM4

Replace COM4 with COM port on which your Arduino is connected (Tools > Serial Port).



Download toxiclibs-complete-0020 folder and copy it to Processing libraries folder (Windows: C:\Users\UserName\Documents\Processing\libraries).

You are ready to run processing code by clicking play symbol. Wait for about 10 seconds for the sensor to get stabilized, after that you can see 3D model of your MPU-6050/GY521.

Quick demo:





I got two more sensors to connect to Arduino, it's a Magnetometer HMC5883L and a Pressure Sensor BMP180 which I'll write a tutorial next time. The sensors will talk to Arduino and the board will adjust the motor to rotate accordingly. More pictures coming!

1 comment: