Koepel:
I see. The code is in a zip file. Others publish their code on Github, then I could make an issue. Even when the code is on Github, some people don't like me for telling that the Wire library is used in the wrong way and keep on doing it wrongI don't know if Sparkfun supplies a Wire library with the board. They use their own bootloader, but I don't see a specific Wire library: GitHub - sparkfun/SAMD21_Dev_Breakout: An Arduino shield-compatible breakout board for the ATSAMD21G18. Battery-power enabled, with an onboard LiPo charger..
If the bootloader is compatible with the bootloader of the Arduino M0 or Arduino Zero, then you could select one of the official Arduino boards.
If the internal pullup resistors are enabled, they are weaker than with an Arduino Pro Mini.
Does the MPU-6050 module have pullup resistors on the module ?
Without pullup resistors I would expect other problems then a second byte being 255.Can you try that short example ? You only have to change the Serial to SerialUSB.
You have to do a few tests to get closer to the problem. It is a weird problem and at the moment there are too many things that might be the cause.
Thanks for the follow up!
I tried adding external Pullups at 4.7K. No improvement.
I created a shorter script as you suggested, but really got no improvement in the results.
I tried this new script on both the SAMD21 and also on a Teensy 3.2. Again, no good results.
I created it so it would be simple to change the I2C clock setting regardless of which board I used. And, as you said, it is a simple matter to change the "Serial..." to SerialUSB..." also making it easy to test on a variety of boards. I'm starting to believe it may have more to do with my script than the board it's self. I loaded this script onto a Pro Micro and got the same MSB of 255. If I loaded the test script that came with the YABR robot, the same one I listed previously, it works great on the Pro Micro. So, I'm kinda confused now.
Honestly, I would not be surprised if the Wire library I am using is jacked up. I do know one is provided when you install the SF boards, but that doesn't mean it is right.
So, any suggestions on what I should use?
At this point I am ready to just move forward with the Pro Micro and scrap the idea of using the SAMD21.
Here is the shorter script.
#include <Wire.h>
int address;
void setup() {
Wire.begin();
TWBR = 12;
//Wire.setClock(400000);
//sercom3.disableWIRE(); // Disable the I2C bus
//SERCOM3->I2CM.BAUD.bit.BAUD = SystemCoreClock / ( 2 * 470000) - 1 ; // Set the I2C SCL frequency to 400kHz
//sercom3.enableWIRE(); // Restart the I2C bus
Serial.begin(115200);
Serial.println("Starting Gyro....");
set_gyro_registers();
delay(50);
}
void loop() {
Serial.print("Balance value: ");
Wire.beginTransmission(0x68);
Wire.write(0x3F);
Wire.endTransmission();
Wire.requestFrom(0x68,2);
Serial.println((Wire.read()<<8|Wire.read())*-1);
delay(20);
Serial.println("Printing raw gyro values");
Wire.beginTransmission(0x68);
Wire.write(0x43);
Wire.endTransmission();
Wire.requestFrom(0x68,6);
while(Wire.available() < 6);
Serial.print("Gyro X MSB = ");
Serial.print(Wire.read());//<<8|Wire.read());
Serial.print(" Gyro X LSB = ");
Serial.println(Wire.read());
Serial.print("Gyro Y MSB = ");
Serial.print(Wire.read());//<<8|Wire.read());
Serial.print(" Gyro Y LSB = ");
Serial.println(Wire.read());
Serial.print("Gyro Z MSB = ");
Serial.print(Wire.read());//<<8|Wire.read());
Serial.print(" Gyro Z LSB = ");
Serial.println(Wire.read());
delay(1500); // Add to ing evry 1.5 sec.
}
void set_gyro_registers(){
//Setup the MPU-6050
Wire.beginTransmission(0x68); //Start communication with the address found during search.
Wire.write(0x6B); //We want to write to the PWR_MGMT_1 register (6B hex)
Wire.write(0x00); //Set the register bits as 00000000 to activate the gyro
Wire.endTransmission(); //End the transmission with the gyro.
Wire.beginTransmission(0x68); //Start communication with the address found during search.
Wire.write(0x1B); //We want to write to the GYRO_CONFIG register (1B hex)
Wire.write(0x00); //Set the register bits as 00000000 (250dps full scale)
Wire.endTransmission(); //End the transmission with the gyro
Wire.beginTransmission(0x68); //Start communication with the address found during search.
Wire.write(0x1C); //We want to write to the ACCEL_CONFIG register (1A hex)
Wire.write(0x08); //Set the register bits as 00001000 (+/- 4g full scale range)
Wire.endTransmission(); //End the transmission with the gyro
Wire.beginTransmission(0x68); //Start communication with the address found during search
Wire.write(0x1A); //We want to write to the CONFIG register (1A hex)
Wire.write(0x03); //Set the register bits as 00000011 (Set Digital Low Pass Filter to ~43Hz)
Wire.endTransmission(); //End the transmission with the gyro
}