Saturday, May 23, 2015

Chapter 2 Glove Implementation 60 MPU-6050

Now it’s time for the code, firstly don’t forget to import MPU-6050
library we can import all of I2Cdev libraries from this page
github.com/jrowberg/i2cdevlib and put it in the right place on the PC which is C:\Users\”username”\Documents\Arduino\libraries
So to read row values of the accelerometer we will use this code, this code is modified version of the original version exist in MPU-6050 example in the I2Cdev libraries




#include "I2Cdev.h"
#include "MPU6050.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
MPU6050 accelgyro;
int16_t ax, ay, az;
void setup() {
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
Serial.begin(9600);
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
void loop() {
accelgyro.getAcceleration(&ax, &ay, &az);
#ifdef OUTPUT_READABLE_ACCELGYRO
Serial.print("a/g:\t");
Serial.print(ax); Serial.print("\t"); Serial.print(ay); Serial.print("\t"); Serial.println(az);
#endif }

No comments:

Post a Comment