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 MPU6050 problema direccion I2C (SOLUCIONADO) - Español - Arduino Forum.
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