Pages: [1]   Go Down
Author Topic: mpu6050  (Read 1603 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have the due board and am trying to get raw data from the mpu-6050 accelerometer. i have tried  the i2cdevlib, freeimulib, and the sample sketch on the playground page.  The  ic2devlib and freeimulib both have issues with mpu6050.h or mpu6050 = gyro statement.  The sample sketch on the playground page uploads but gives errors in serial window. I have also tried the i2c_scanner which does not find any devices.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26525
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but gives errors in serial window
But you're not going to tell us what they are?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

invernsense MPU-6050
june 2012
who am i : 0, error =1
pwr_mgmt_2 : 0, error =1

mpu-6050
read accel, temp and gyro, error =1
accel x,y,z: 6680, 64, -21224
temperature: 42.529 degrees celsius
gryro x,y,z: 256, 0, 2048

her is one from sketch from  playground
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i2c_scanner output :


I2C scanner
scanning .......
no i2c device found
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

from mpu6050_raw  from i2cdevlib

MPU6050_raw.ino:37: fatal error:
MPU6050.h: no such file directory compilation terminated
Logged

White River Junction, Vermont USA
Offline Offline
Full Member
***
Karma: 5
Posts: 106
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Sean,

Wire.endTransmission() doesn't work on the DUE.  Neither does I2Cscanner.  If your program uses either one of these functions, then it will break. (unless it's been updated recently)

The Wire library for the DUE is broken.  You'll need to write your own code.  Do some searching on the forum for I2C problems.

Good luck,

Chris
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you very much  smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have exactly the same problem when using Due with i2cdevlib,
Sean can you pleasse shrae your f inding and if you sahre some snipets of code I woul be very appreciated ! Tank you.
I can collaborate to help us run it on Due.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi sean and ectar.
I used mpu6050 with Arduino Due.
And I used Library from there:
https://docs.google.com/file/d/0B2_rhDNAxM4sbkk0Y0htaXo1bVE/edit
This is my program, where I used mpu5060:
Code:
//exohod.ino

#include <Servo.h>

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

unsigned int uiPtr = 0;
int iFiltrAX = 0;
int iFiltrAY = 0;
int iFiltrAZ = 0;
int iFiltrGX = 0;
int iFiltrGY = 0;
int iFiltrGZ = 0;
int iAbsFiltrGZ;

const int ciIR_pin = A5;

Servo myservo;       // create servo object to control a servo
                     // a maximum of eight servo objects can be created
 
const int ciSRVIR = 11;///3   // (pwm) pin 11 connected to servo of Sharp IR sensor
const int ciINTpin = 2;///2
///const int ciDRDYpin = 3;
 
const int ciAIA = 9;  // (pwm) pin 9 connected to pin A-IA
const int ciAIB = 5;  // (pwm) pin 5 connected to pin A-IB
const int ciBIA = 10; // (pwm) pin 10 connected to pin B-IA
const int ciBIB = 6;  // (pwm) pin 6 connected to pin B-IB
 
byte bHighSpeed = 255;    // change this (0-255) to control the speed of the motors
byte bLeftSpeed;
byte bRightSpeed;
int iDecCnt = 0;
int iF = 0;
 
void setup() {
/// debug:
///  Serial.begin(9600);
///  Serial.begin(115200);
///
  // join I2C bus (I2Cdev library doesn't do this automatically)
  Wire.begin();
  // initialize device
  accelgyro.initialize();
  // verify connection
///    Serial.println("\nTesting device connections...");
///    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  accelgyro.setInterruptLatch(false);
  accelgyro.setIntDataReadyEnabled(true);
  accelgyro.setDLPFMode(5);///10Hz

  pinMode(ciINTpin, INPUT);
///  pinMode(ciDRDYpin, INPUT);
  attachInterrupt(ciINTpin, IRQ1func, RISING);

  myservo.attach(ciSRVIR);   // attaches the servo on pin 11
  myservo.writeMicroseconds(1450);  // middle position (450uS...2450uS)

  pinMode(ciAIA, OUTPUT); // set pins to output
  pinMode(ciAIB, OUTPUT);
  pinMode(ciBIA, OUTPUT);
  pinMode(ciBIB, OUTPUT);
  bLeftSpeed = bHighSpeed;
  bRightSpeed = bHighSpeed;
  delay(2000);                      //
  forward();
}
 
void loop() {
  if(iF)
  {
    iF = 0;
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
///    accelgyro.getAcceleration(&ax, &ay, &az);
///    accelgyro.getRotation(&gx, &gy, &gz);
///Filter:
    iFiltrGZ += gz;
    uiPtr++;
    if(uiPtr > 9)
    {
      uiPtr = 0;
      iFiltrGZ += 2200;
      iFiltrGZ >>= 9;///9
      if(iFiltrGZ < 0) iAbsFiltrGZ = iFiltrGZ * -1;
      else iAbsFiltrGZ = iFiltrGZ;
      if(iAbsFiltrGZ > 255) iAbsFiltrGZ = 255;
      if(iFiltrGZ < 0)
      {
        bLeftSpeed = bHighSpeed - (byte)iAbsFiltrGZ;
        bRightSpeed = bHighSpeed;
      }
      else
      {
        bLeftSpeed = bHighSpeed;
        bRightSpeed = bHighSpeed - (byte)iAbsFiltrGZ;
      }
/// debug:
///    Serial.print(bLeftSpeed); Serial.print("\t");
///    Serial.print(bRightSpeed); Serial.print("\t");
///    Serial.print(iFiltrGZ); Serial.print("\t");
///    Serial.println(iAbsFiltrGZ);
///    Serial.println(iDecCnt);
///
      iFiltrGZ = 0;
      forward();
    }
  }

  int iDistance = GetDist();
/// debug:
///Serial.print((byte)(iDistance>>8),HEX);
///Serial.println((byte)iDistance,HEX);
///
  if(iDistance > 0x240)///10cm
  {
    pause();
    delay(100);
    myservo.writeMicroseconds(950);  // Left 45degrees position
    delay(200);
    int iDistLeft = GetDist();
    myservo.writeMicroseconds(1950); // Right 45degrees position
    delay(400);
    int iDistRight = GetDist();
    myservo.writeMicroseconds(1450); // middle position
    delay(300);
    if(iDistRight > iDistLeft) right();
    else left();
    delay(350);
    pause();
    delay(200);
    forward();
  }
}

void IRQ1func()
{
  iDecCnt++;
  if(iDecCnt > 8)
  {
    iF = 1;
    iDecCnt = 0;
  }
}
 
int GetDist()
{
  int iD = 0;
  for(int iA = 0; iA < 8; iA++)
  {
    iD += analogRead(ciIR_pin);
  }
  iD >>= 3;
  return iD;
}

void backward()
{
  analogWrite(ciAIA, LOW);
  analogWrite(ciAIB, bRightSpeed);
  analogWrite(ciBIA, LOW);
  analogWrite(ciBIB, bLeftSpeed);
}
 
void forward()
{
  analogWrite(ciAIA, bRightSpeed);
  analogWrite(ciAIB, LOW);
  analogWrite(ciBIA, bLeftSpeed);
  analogWrite(ciBIB, LOW);
}
 
void left()
{
  analogWrite(ciAIA, bHighSpeed);
  analogWrite(ciAIB, LOW);
  analogWrite(ciBIA, LOW);
  analogWrite(ciBIB, bHighSpeed);
}
 
void right()
{
  analogWrite(ciAIA, LOW);
  analogWrite(ciAIB, bHighSpeed);
  analogWrite(ciBIA, bHighSpeed);
  analogWrite(ciBIB, LOW);
}

void pause()
{
  analogWrite(ciAIA, LOW);
  analogWrite(ciAIB, LOW);
  analogWrite(ciBIA, LOW);
  analogWrite(ciBIB, LOW);
}
Maybe this helps you.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

i read the MPU6050 without the MPU6050-lib (based on the lib):

Initialisation:

Code:
void initMPU6050() {
  Serial.print("Init MPU6050 ");             // MPU6050 initialisieren
  SetConfiguration(0x6B, 0x80) ;             // Powermanagement aufrufen Sensor schlafen und Reset, Clock wird zunächst von Gyro-Achse Z verwendet
  delay(500);
  SetConfiguration(0x6B, 0x03);              // Powermanagement aufrufen Sleep beenden und Clock von Gyroskopeachse X verwenden
  delay(500);
  SetConfiguration(0x1A, 0x00);              // Konfigruation  aufrufen: Default => Acc=260Hz, Delay=0ms, Gyro=256Hz, Delay=0.98ms, Fs=8kHz
  Serial.println(".. ready!");
}

void SetConfiguration(byte reg, byte setting) {
  Wire.beginTransmission(IIC_ADRESS_ACCELGYRO); // Aufruf des MPU6050 Sensor
  Wire.write(reg);                              // Register Aufruf
  Wire.write(setting);                          // Einstellungsbyte für das Register senden
  Wire.endTransmission();
}

Read the sensor:

Code:
void readMPU6050(byte accelgyroCalibrated) {
  byte i;
  int accelGyroUFilt[6];
  byte result[14];
 
  Wire.beginTransmission(IIC_ADRESS_ACCELGYRO);       // Aufruf des MPU6050 Sensor
  Wire.write(0x3B);                                   // Anfangsadresse von Beschleunigungssensorachse X
  Wire.endTransmission();
  Wire.requestFrom(IIC_ADRESS_ACCELGYRO, 14);         // 14 Bytes kommen als Antwort
  for(i=0;i<14;i++) {result[i] = Wire.read();}        // Bytes im Array ablegen

  accelGyroUFilt[0] = ((result[0]<<8) | result[1]);   // ax
  accelGyroUFilt[1] = ((result[2]<<8) | result[3]);   // ay
  accelGyroUFilt[2] = ((result[4]<<8) | result[5]);   // az
  accelGyroUFilt[3] = ((result[8]<<8) | result[9]);   // gx
  accelGyroUFilt[4] = ((result[10]<<8) | result[11]); // gy
  accelGyroUFilt[5] = ((result[12]<<8) | result[13]); // gz
}

This works quite fine ... And you don't have to include any libs beyond Wire.h

Philipp
« Last Edit: November 17, 2013, 05:32:35 am by PhilippN » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi boys, can you explain me how to connected and used this sensor on arduino due? I have connected Vcc  to 5V, GND to GND, SDA to pin 20 and SCL to pin 21. I have used i2cScanner but it not recognize my sensor. I have a GY-521 sensor.
Logged

Pages: [1]   Go Up
Jump to: