locked
Looking for I2C example RRS feed

  • Question

  • I am trying to read data from Sparkfun IMU3000 sensor over I2C using Galileo ver 1. The sensor is attached to Galileo SDA/SCL pins (near the AREF) and works as expected if I run the sample sketch in Arduino IDE provided by Intel. The same code compiles in Visual Studio, but when I start it under Windows 8.1 I get the message "I2C_CONTROLLER IO failed".

    #include <Wire.h>
    #define GYRO 0x68         // gyro I2C address

    void setup()
    {
    Wire.begin();
    ...
    }


    byte buffer[12];   // Array to store ADC values 

    void loop()
    {
    // First set the register start address for X on Gyro  
    Wire.beginTransmission(GYRO);
    Wire.write(REG_GYRO_X); //Register Address GYRO_XOUT_H
    Wire.endTransmission();

    // Now read the 12 data bytes
    Wire.beginTransmission(GYRO);
    Wire.requestFrom(GYRO, 12); // Read 12 bytes
    i = 0;
    while (Wire.available())
    {
    buffer[i] = Wire.read();
    i++;
    }
    Wire.endTransmission();
    ...

    The code seems to fail in the function Wire.requestFrom

    Are there any examples of how to use I2C with Windows on Devices?
    Saturday, August 30, 2014 10:06 AM

Answers

  • Finally I made it working!

    There are two pins labeled SCL and SDA on the Galileo board, but the Wiring library for windows seems to ignore them. You should analog pin instead. A4 - SDA, A5 - SCL, same as on Arduino UNO.

    My second mistake was putting the reading code between Wire.beginTransmission / Wire.endTransmission calls. These functions are necessary only for writing. It seems have no negative effect on classical Arduino, but caused errors under Windows on Devices. 

    Summary:

    A4 pin as SDA, A5 pin as SCL

    Code example:

    #include <Wire.h>
    #define GYRO 0x68         // gyro I2C address
    
    void setup()
    {
       Wire.begin();
    }
    
    byte buffer[12];   // Array to store ADC values 
    void loop()
    {
    // First set the register start address for X on Gyro  
       Wire.beginTransmission(GYRO);
       Wire.write(REG_GYRO_X); //Register Address GYRO_XOUT_H
       Wire.endTransmission();
    
    // Now read the 12 data bytes
       Wire.requestFrom(GYRO, 12); // Read 12 bytes
       i = 0;
       while (Wire.available())
       {
          buffer[i] = Wire.read();
          i++;
       } 
    ...
    }
    

    The resulting performance is about 120 readings per second, 12 bytes each.

    • Marked as answer by VictorMuc Sunday, September 21, 2014 8:45 AM
    Sunday, September 21, 2014 8:43 AM

All replies

  • Lots of examples here:  http://ms-iot.github.io/content/SampleApps.htm

    I believe at least one of them is utilizing I2C


    Ric Lewis

    Tuesday, September 9, 2014 2:55 PM
  • Finally I made it working!

    There are two pins labeled SCL and SDA on the Galileo board, but the Wiring library for windows seems to ignore them. You should analog pin instead. A4 - SDA, A5 - SCL, same as on Arduino UNO.

    My second mistake was putting the reading code between Wire.beginTransmission / Wire.endTransmission calls. These functions are necessary only for writing. It seems have no negative effect on classical Arduino, but caused errors under Windows on Devices. 

    Summary:

    A4 pin as SDA, A5 pin as SCL

    Code example:

    #include <Wire.h>
    #define GYRO 0x68         // gyro I2C address
    
    void setup()
    {
       Wire.begin();
    }
    
    byte buffer[12];   // Array to store ADC values 
    void loop()
    {
    // First set the register start address for X on Gyro  
       Wire.beginTransmission(GYRO);
       Wire.write(REG_GYRO_X); //Register Address GYRO_XOUT_H
       Wire.endTransmission();
    
    // Now read the 12 data bytes
       Wire.requestFrom(GYRO, 12); // Read 12 bytes
       i = 0;
       while (Wire.available())
       {
          buffer[i] = Wire.read();
          i++;
       } 
    ...
    }
    

    The resulting performance is about 120 readings per second, 12 bytes each.

    • Marked as answer by VictorMuc Sunday, September 21, 2014 8:45 AM
    Sunday, September 21, 2014 8:43 AM
  • Victor,

    Thanks - I ran into the same 2 problems with a BMP085 library.  You saved me a lot of time!

    Dan

    Sunday, September 28, 2014 3:19 AM