3 Replies Latest reply on Apr 23, 2015 10:15 AM by Intel_Peter

    I2C problem with sensor (SRM08)

    ruben_vleuten

      Hi,

       

      At the moment I'm trying to connect a SRM08 (SRF08 Ultra sonic range finderultrasound distance sensor to an Edison with an Arduino board. The problem is that it's not working.

       

      I used the Arduino library that is recommended here: Arduino Playground - SonarSrf08. And got the code running on a normal Arduino UNO without a problem. But when I try to connect the sensor to the Edison, it's not working.

       

      I have the feeling it has to do with the I2c. It seems that it's not working properly on the Edison. I connected the SDA and SCL to A4 and A5 (the same as with arduino), but for one reason or the other it's not reading properly, or reading at all. (i've also tested with another I2c device and had the same problems, it was working on the UNO but not on the Edison). Is there something i'm doing wrong. Do I have to rearrange jumpers, or change the code?

       

      The code I'm using at the moment is:

       

      #include <Wire.h>

      #include <SonarSRF08.h>

       

       

      #define MAIN_08_ADDRESS (0xE0) >> 1)

      SonarSRF08 MainSonar;

       

       

      // Setup Analogue Gain

      #define GAIN_REGISTER 0x09

      // Setup Range Location

      #define LOCATION_REGISTER 0x8C

       

       

      char unit = 'c'; // 'i' for inches, 'c' for centimeters, 'm' for micro-seconds

       

       

      void setup() {

          Serial.begin(9600);

       

       

          MainSonar.connect(MAIN_08_ADDRESS, GAIN_REGISTER, LOCATION_REGISTER);

          isConnected("SRF08", MainSonar.getSoft());

      }

       

       

      void loop() {

          float sensorReading = 0;

          sensorReading = MainSonar.getRange(unit);

          distance("sensor", sensorReading);

      }

       

       

      // Print out distance

      void distance(String reference, int sensorReading) {

          Serial.print("Distance from " + reference + ": ");

          Serial.print(sensorReading);

          Serial.println(unit);

      }

       

       

      // Print out distance

      void isConnected(String reference, int sensorSoft) {

          if (sensorSoft >= 0)

          {

              Serial.print("Sensor " + reference + " connected (");

              Serial.print(sensorSoft);

              Serial.println(")");

          }

          else

          {

              Serial.println("Sensor " + reference + " not detected");

          }

      }


      Thanks


      R.