MPU6050 problema

Hola a todos.

Os pido ayuda para conectar MPU6050 a mi Arduino UNO, tras hacer muchas pruebas y buscar por el foro e Internet,
mi problema es parecido al que tenía Alfon en http://forum.arduino.cc/index.php?topic=97226.0.

Mi primer problema es el mismo

Initializing I2C devices...
Testing device connections...
MPU6050 connection failed
a/g:	0	0	0	0	0	0
a/g:	0	0	0	0	0	0

Y tras intentar a hacer un escan de la direcciones, con el mismo ejemplo que usa el

/**
 * I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr, 
                void(*callback)(byte address, byte result) ) 
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,DEC);
  Serial.print(",");
  Serial.print(addr, HEX);
  Serial.print(",");
  Serial.print(addr, BIN);
  Serial.print(",");
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}

byte start_address = 1;
byte end_address = 120;

// standard Arduino setup()
void setup()
{
    Wire.begin();

    Serial.begin(19200);
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,DEC);
    Serial.print(" to ");
    Serial.print(end_address,DEC);
    Serial.println("...");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");
}

// standard Arduino loop()
void loop() 
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}

me da error en compilación en la linea:

rc = twi_writeTo(addr, &data, 0, 1);

C:\Program Files (x86)\Arduino\libraries\Wire/utility/twi.h: In function ‘void scanI2CBus(byte, byte, void ()(byte, byte))’:
C:\Program Files (x86)\Arduino\libraries\Wire/utility/twi.h:44: error: too few arguments to function 'uint8_t twi_writeTo(uint8_t, uint8_t
, uint8_t, uint8_t, uint8_t)’
sketch_oct26a:24: error: at this point in file.

tambien e probado

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

pero me responde:

I2C Scanner
Scanning…
No I2C devices found

Scanning…
No I2C devices found

Alguien me puede decir que estoy haciendo mal o algo tengo roto.

Gracias

Hola Bellot, En tu primer ejemplo, la funcion twi_writeTo requiere de 5 parametros y solo veo cuatro. Debes agregar un cero al final como se muestra a continuacion.

rc = twi_writeTo(addr, &data, 0, 1, 0);

No dispongo de un MPU6050 pero con dicho cambio el sketch corre bien.

Para el segundo ejemplo, si bien compilar bien, pudiera tratarse de un problema en el cableado, por lo que te recomiendo que lo verifiques de nuevo:

MPU6050 Arduino VCC ----------- 3V3 CS ------------ 3V3 GND ----------- GND SDA ----------- Analog 4 SCL ----------- Analog 5

Tampoco se la marca de tu acelerometro. Algunos fabricantes no colocan los pull-up resistors en los pines SCL/SDA lo que genera problemas de comunicacion.

Saludos cordiales y suerte.

Primero de todo gracias por la pronta respuesta.

YA CONSEGUI QUE FUNCIONASE :D

SOLUCION. Hoy, quito el cableado y el MPU6050, lo pincho todo en otra parte del protoboard, añado el 0 como 5 parametro de la funcion (ayer tabien hice pruebas añadiendo el 5 parametro, pero creo que probe solo con el 1 no con el 0 como indicas, ya no estoy seguro, despues de tantas pruebas) y me funciona a la primera. :astonished:

I2CScanner ready! starting scanning of I2C bus from 1 to 120... addr: 1,1,1, addr: 2,2,10, addr: 3,3,11, addr: 4,4,100, addr: 5,5,101, addr: 6,6,110, addr: 7,7,111, addr: 8,8,1000, addr: 9,9,1001, addr: 10,A,1010, addr: 11,B,1011, addr: 12,C,1100, addr: 13,D,1101, addr: 14,E,1110, addr: 15,F,1111, addr: 16,10,10000, addr: 17,11,10001, addr: 18,12,10010, addr: 19,13,10011, addr: 20,14,10100, addr: 21,15,10101, addr: 22,16,10110, addr: 23,17,10111, addr: 24,18,11000, addr: 25,19,11001, addr: 26,1A,11010, addr: 27,1B,11011, addr: 28,1C,11100, addr: 29,1D,11101, addr: 30,1E,11110, addr: 31,1F,11111, addr: 32,20,100000, addr: 33,21,100001, addr: 34,22,100010, addr: 35,23,100011, addr: 36,24,100100, addr: 37,25,100101, addr: 38,26,100110, addr: 39,27,100111, addr: 40,28,101000, addr: 41,29,101001, addr: 42,2A,101010, addr: 43,2B,101011, addr: 44,2C,101100, addr: 45,2D,101101, addr: 46,2E,101110, addr: 47,2F,101111, addr: 48,30,110000, addr: 49,31,110001, addr: 50,32,110010, addr: 51,33,110011, addr: 52,34,110100, addr: 53,35,110101, addr: 54,36,110110, addr: 55,37,110111, addr: 56,38,111000, addr: 57,39,111001, addr: 58,3A,111010, addr: 59,3B,111011, addr: 60,3C,111100, addr: 61,3D,111101, addr: 62,3E,111110, addr: 63,3F,111111, addr: 64,40,1000000, addr: 65,41,1000001, addr: 66,42,1000010, addr: 67,43,1000011, addr: 68,44,1000100, addr: 69,45,1000101, addr: 70,46,1000110, addr: 71,47,1000111, addr: 72,48,1001000, addr: 73,49,1001001, addr: 74,4A,1001010, addr: 75,4B,1001011, addr: 76,4C,1001100, addr: 77,4D,1001101, addr: 78,4E,1001110, addr: 79,4F,1001111, addr: 80,50,1010000, addr: 81,51,1010001, addr: 82,52,1010010, addr: 83,53,1010011, addr: 84,54,1010100, addr: 85,55,1010101, addr: 86,56,1010110, addr: 87,57,1010111, addr: 88,58,1011000, addr: 89,59,1011001, addr: 90,5A,1011010, addr: 91,5B,1011011, addr: 92,5C,1011100, addr: 93,5D,1011101, addr: 94,5E,1011110, addr: 95,5F,1011111, addr: 96,60,1100000, addr: 97,61,1100001, addr: 98,62,1100010, addr: 99,63,1100011, addr: 100,64,1100100, addr: 101,65,1100101, addr: 102,66,1100110, addr: 103,67,1100111, addr: 104,68,1101000, found! addr: 105,69,1101001, addr: 106,6A,1101010, addr: 107,6B,1101011, addr: 108,6C,1101100, addr: 109,6D,1101101, addr: 110,6E,1101110, addr: 111,6F,1101111, addr: 112,70,1110000, addr: 113,71,1110001, addr: 114,72,1110010, addr: 115,73,1110011, addr: 116,74,1110100, addr: 117,75,1110101, addr: 118,76,1110110, addr: 119,77,1110111, addr: 120,78,1111000,

done

Prueba el segundo ejemplo que puse ayer y tambien me funciona a la primera :astonished:

I2C Scanner Scanning... I2C device found at address 0x68 ! done

Scanning... I2C device found at address 0x68 ! done

La conexion que uso es: 3.3v --> VCC GND --> GND A4 --> SDA A5 --> SCL

no tengo CS

Me temo que algun sector de mi protoboard esta dañado, ya que hoy he usado el mismo cableado de ayer, pero en otro sitio. :0