Go Down

Topic: MKRZero I2c Issues (Read 348 times) previous topic - next topic

OranDeutsch

Hi

I have the sparkfun BNO080 library example working with an Arduino uno with no issues. However, when I use my MKRZero (pins 12 and 11 for SCL and SDA respectively) the code just hangs.

Ive played around with the I2C on my zero since then and have noticed it does not work with a majority of my I2C devices. The only exception being the Adafruit drv2605l  haptic motor driver I have lying around.

From googleing the issue it seems many have been having issues with the SAMD arduino boards with I2C but I have not seen anything resolved.

Has this issue been thrown under the rug or is there a simple solution I am not aware off.

While I doubt it is the issue, here is the code I am trying to use:

Code: [Select]




#include <Wire.h>

#include "SparkFun_BNO080_Arduino_Library.h"
#include "Adafruit_DRV2605.h"


struct IMUData {
  float quatI;
  float quatJ;
  float quatK;
  float quatReal;
  float quatRadianAccuracy;
  float heading;
  float bank;
  float attitude;
};

IMUData data[2];
BNO080 myIMU[2];
Adafruit_DRV2605 drv;
int threshhold;


 void get_euler(IMUData &tempData) {
    double sqw = tempData.quatReal*tempData.quatReal;
    double sqx = tempData.quatI*tempData.quatI;
    double sqy = tempData.quatJ*tempData.quatJ;
    double sqz = tempData.quatK*tempData.quatK;
   
    tempData.heading = atan2(2.0 * (tempData.quatI*tempData.quatJ + tempData.quatK*tempData.quatReal),(tempData.quatI - tempData.quatK - sqz + sqw));
    tempData.bank = atan2(2.0 * (tempData.quatJ*tempData.quatK + tempData.quatI*tempData.quatReal),(-sqx - sqy + sqz + sqw));
    tempData.attitude = asin(-2.0 * (tempData.quatI*tempData.quatK - tempData.quatJ*tempData.quatReal));
}

void setup()
{
  Serial.begin(9600);
  Serial.println();
  while(!Serial);
  Serial.println("BNO080 Read Example");

  threshhold = -15;

  Wire.begin();
  Wire.setClock(400000); //Increase I2C data rate to 400kHz

  myIMU[0].begin(0x4B,Wire);
  delay(50);
  myIMU[1].begin(0x4A,Wire);

    drv.begin();
 
  drv.selectLibrary(1);
 
  // I2C trigger by sending 'go' command
  // default, internal trigger when sending GO command
  drv.setMode(DRV2605_MODE_INTTRIG);

 

  myIMU[0].enableRotationVector(10); //Send data update every 50ms
  delay(50);
  myIMU[1].enableRotationVector(10); //Send data update every 50ms

  Serial.println(F("Rotation vector enabled"));
  Serial.println(F("Output in form i, j, k, real, accuracy"));
}

void loop()
{
  //Look for reports from the IMU
  for (int i = 0; i < 2; i++)
  {
    //Serial.println(i);
    if (myIMU[i].dataAvailable() == true)
      {
        data[i].quatI = myIMU[i].getQuatI();
        data[i].quatJ = myIMU[i].getQuatJ();
        data[i].quatK = myIMU[i].getQuatK();
        data[i].quatReal = myIMU[i].getQuatReal();
        data[i].quatRadianAccuracy = myIMU[i].getQuatRadianAccuracy();

        get_euler(data[i]);

       

    }

    Serial.print((data[1].attitude - data[0].attitude) * 57);
    Serial.print(",");
    Serial.print(threshhold);
    Serial.print(",");
    //Serial.print(data[1].attitude);
    //Serial.print(",");
    //Serial.print(data[0].attitude);
    //Serial.print(",");
    Serial.println();

    if (((data[1].attitude - data[0].attitude) * 57) < threshhold)
    {
         drv.setWaveform(0, 15);  // play effect
         drv.setWaveform(1, 0);       // end waveform

  // play the effect!

    }else{
     
        drv.setWaveform(0, 0);  // play effect
        drv.setWaveform(1, 0);       // end waveform
     
    }
      drv.go();

    delay(10);
   
  }
}



Again, works fine on an Arduino Uno and Due but not my MKRZero which is a real shame.

Go Up