๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Arduino due and NXP 9-DOF
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino due and NXP 9-DOF

by Sombreland on Sat Nov 09, 2019 7:09 am

Hello,

I have buy an Adafruit NXP 9-DOF sensor, when i use it with arduino uno or arduino ADK i have no problem but when i try to use it with an arduino due (on wire1 or wire) it doesn't work.
I have try to scan I2C bus -> i found device on address 0x21 and 0x1F that is ok.
When i try to send a request, wire.availiable() goes to 1 (OK) but wire.read(), read nothing on the I2C com.
Here is the code i used to test the I2C Com.

Can someone have an explanation?

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <limits.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
 Wire.begin();
 Wire.setClock(100000);
 Serial.println("Wire Begin");
}

void loop() {
  // put your main code here, to run repeatedly:
    byte value;
 byte error, address;
  int nDevices;
 
  Serial.print("Scanning");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // La valeur de retour de Wire.endTransmission()
    // est false (0) si le peripherique existe a cette adresse
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    Serial.print(".");
 
    if (error == 0)
    {
      Serial.println("");
      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.println("");
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    } 
    delay(50);
  }
  if (nDevices == 0)
  {
    Serial.println("");
    Serial.println("No I2C devices found\n");
  }
  else
    Serial.println("done\n");
 
  delay(3000);           // on attend 3 secondes et on recommence

  value = trans();
 
  Serial.println(value, HEX);
  Serial.println(Wire.available());

}


uint8_t trans()
{
  uint8_t var = 0;
 
  Wire.beginTransmission((byte)0x21);
  #if ARDUINO >= 100
    Wire.write((uint8_t)0x0C);
  #else
    Wire.send(0x0C);
  #endif
  if (Wire.endTransmission(false) != 0) return 0;
  Wire.requestFrom((byte)0x21, (byte)1);
  Serial.println(Wire.available());
  #if ARDUINO >= 100
    var = Wire.read();
  #else
    var = Wire.receive();
  #endif
 
  return var;
}

Sombreland
 
Posts: 1
Joined: Sat Nov 09, 2019 6:56 am

Please be positive and constructive with your questions and comments.