2 Replies Latest reply on Nov 13, 2015 11:31 AM by dethSwatch

    Ubilinux + libmraa i2c with AM2315 (Remote I/0 Error on write)

    BenjiWeb

      I'm trying to read from the AM2315 temperature humidity sensor using libmraa. I'm using the intel edison breakout board, and I have followed example 4 from emutex multiplexing guide to configure IO18 + IO19 for i2c: EmutexLabs. Im getting the remote i/0 error errno when calling mraa_i2c_write.  Any help resolving this issue would be appreciated.

       

      I have connected 4.7K resistors between the SDA/SCL lines of the AM2315 sensor to 5V, and am using the I2C address 0x5C (note: the datasheet for the sensor uses 0xb8, but this appears to be a mistake as I've found several posts indicating that 5C is the correct address).

       

      I've initialized an i2c context on i2c-6 and have tried connecting the SCL/SDA pins of the sensor to A5/A4 as well as the SCL/SDA pins on the breakout board, but still get the remote i/0 error.

       

      Below is my main program which shows how Im initializing i2c-6. I'm using usleep to implement delay as this particular sensor has some wait times needed for temperature conversion and recovering from hibernation.

       

      int main(int argc, char** argv)

      {

              mraa_init();

              mraa_i2c_context i2c;

              uint8_t addr = 0x5c; //Address of AM2315

              i2c = mraa_i2c_init(6);

              if (i2c == NULL) {

                      fprintf(stdout,"I2C failed init");

                      return 1;

              }

       

              mraa_i2c_frequency(i2c,MRAA_I2C_STD);


               // askr stores the command

              // needed to ask for TEMP + Humidity

       

              uint8_t  askr[3];

              askr[0]=0x03;

              askr[1]=0x00;

              askr[2]=0x04;


              //Empty array to store result

              uint8_t  readr[8];

       

              bzero(readr,8);


       

              //AM2315 hibernates to avoid

               // getting too hot.

              // Send it its address to wake it up

              mraa_i2c_address(i2c,addr);

              usleep(2000);

             

              //Ask for temp + humidity

              mraa_i2c_address(i2c,addr);

              mraa_i2c_write(i2c,askr,3);

              printf("ERRNO  %s\n", strerror(errno));

              usleep(10000); //sleep 10ms

       

              //READ TEMP + HUMIDITY

              mraa_i2c_read(i2c,readr,8);

       

       

              //PRINT RESULT

              int i;

              for(i=0;i<8;i++){

                      fprintf(stdout,"R[%d]:%x\n",i,readr[i]);

              }

              mraa_i2c_stop(i2c);

              return 0;

      }


      Here is the output of i2c-detect on i2c-6

       

      i2cdetect -F 6 

      Functionalities implemented by /dev/i2c-6:

      I2C                              yes

      SMBus Quick Command              no

      SMBus Send Byte                  yes

      SMBus Receive Byte               yes

      SMBus Write Byte                 yes

      SMBus Read Byte                  yes

      SMBus Write Word                 yes

      SMBus Read Word                  yes

      SMBus Process Call               no

      SMBus Block Write                no

      SMBus Block Read                 no

      SMBus Block Process Call         no

      SMBus PEC                        no

      I2C Block Write                  yes

      I2C Block Read                   yes