I've trying to get data from a MPU 6050, using the I2C protocol, but for some reason i get nothing in the serial monitor.
I'm using the pins :
PA22-SDA
PA23-SCL
So i tested the same code with an Arduino UNO and it worked perfectly.
I'm using 4k7 pull-up resistors in the SCL and SCA lines.
There you have my code:
// Codigo adaptado de: Usuário do Arduino JohnChi
#include<Wire.h>//Biblioteca para comunicação I2C
const int MPU_addr=0x68; //Endereço do sensor
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; //Variaveis para pegar os valores medidos
void setup(){
Wire.begin(); //Inicia a comunicação I2C
Wire.beginTransmission(MPU_addr); //Começa a transmissao de dados para o sensor
Wire.write(0x6B); // registrador PWR_MGMT_1
Wire.write(0); // Manda 0 e "acorda" o MPU 6050
Wire.endTransmission(true);
Serial.begin(9600); //Inicia a comunicaçao serial (para exibir os valores lidos)
}
void loop(){
Wire.beginTransmission(MPU_addr); //Começa a transmissao de dados para o sensor
Wire.write(0x3B); // registrador dos dados medidos (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true); // faz um "pedido" para ler 14 registradores, que serão os registrados com os dados medidos
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
//Agora escreve os valores no monitor serial
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //Equação da temperatura em Cº de acordo com o datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
}
I hope someone can help figure out the problem with my SAMD21 board.
As i said it shows all the addresses from 1 to 118. Then, when i run the MPU 6050 code acceleration in the axis get stucked in -1, as well as the temperature.
The SAMD21 board is set to be a MKR Fox 1200, just like @horace. I initially set it as a Arduino Zero board using the native port, but my serial monitor was freezed in that setup. When I changed to a MKR Fox I started to see life in the serial.Eventhough it's not useable data .