Yeah, you are right! But my Wemos arduino board, point the PA22 and PA23 as the I2C pins. I just selected MKR Fox Board in order to find a solution to the non displaying serial monitor. For sure it would optimal if I get data with the zero board selected.
My MCU is a Arduino Zero Clone board called Weemos SAMD21.
There you have my code :
#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(){
digitalWrite(SDA, 1);
digitalWrite(SCL, 1);
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);
}
As you can see I'm using internal pull-ups, in the I2C line, but i've tried to add 4k7 resistors in order to see different results.
With new I2C modules, it is best to test your connection with the I2C Address Scanner, and make sure it recognizes a device with the correct I2C address, before moving on.
Have you done that in this case?
This should not be necessary. The Wire library turns on the internal pullups.
digitalWrite(SDA, 1);
digitalWrite(SCL, 1);
When posting output or error messages, please copy and paste into your post (with code tags), rather than posting an illegible screen shot.
Your two topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you wonāt have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Some of the SAMD21 boards have "Serial" as the first hardware serial port, rather than the virtual USB Serial port. if you want to be sure to send debugging info on the USB port, Use SERIAL_PORT_USBVIRTUAL.println() and etc.
(I think "Arduino Zero" is one of them. I can't tell, from a quick glance, whether that switches when you use the "native usb port" instead of the debug port.)
I also used @horace and @westfw for SerialUSB as you guys can se in my code:
#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);
SerialUSB.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
SerialUSB.print("AcX = "); SerialUSB.print(AcX);
SerialUSB.print(" | AcY = "); SerialUSB.print(AcY);
SerialUSB.print(" | AcZ = "); SerialUSB.print(AcZ);
SerialUSB.print(" | Tmp = "); SerialUSB.print(Tmp/340.00+36.53); //Equação da temperatura em Cº de acordo com o datasheet
SerialUSB.print(" | GyX = "); SerialUSB.print(GyX);
SerialUSB.print(" | GyY = "); SerialUSB.print(GyY);
SerialUSB.print(" | GyZ = "); SerialUSB.println(GyZ);
delay(333);
}