6 Replies Latest reply on Sep 24, 2015 3:21 AM by turtle-syp

    how to enable the ms5611 on Edison Arduino kit?

    freshbird

      unlucky,i want to use the ms5611 sensor on Edison by i2c procotol, but i find it can't work well.

      i can see the SCL and SDA signal on oscilloscope. and i connected the PS pin to High(3.3V) and CSB to GND.

       

      1.jpg

      and below is the result,can't read any data from ms5611.

      PROM COEFFICIENTS ivan
      Error reading PROM 1
      0
      Error reading PROM 1
      0
      Error reading PROM 1
      0
      Error reading PROM 1
      0
      Error reading PROM 1
      0
      Error reading PROM 1
      0
      
      
           Actual TEMP= 20.00      Actual PRESSURE= 0.00
      
      
           Actual ALTITUDE= infm
      
      
       RAW Temp D2=  4294967295 RAW Pressure D1=  4294967295
      
      
      
      
       C1 = 0
       C2 = 0
       C3 = 0
       C4 = 0
       C5 = 0
       C6 = 0
      

       

       

      below is my code:

      #include <Wire.h>
      #define ADDRESS 0x77 //0x76   IIC Address
      
      uint32_t D1 = 0;
      uint32_t D2 = 0;
      int64_t dT = 0;
      int32_t TEMP = 0;
      int64_t OFF = 0; 
      int64_t SENS = 0; 
      int32_t P = 0;
      uint16_t C[7];
      
      float Temperature;
      float Pressure;
      const float sea_press = 1013.25;
      
      void setup() {
        Wire.begin();
        Serial.begin(9600); //9600 changed 'cos of timing?
        delay(1000);
        initial(ADDRESS);
      }
      
      void loop()
      {
        D1 = getVal(ADDRESS, 0x48); // Pressure raw
        D2 = getVal(ADDRESS, 0x58);// Temperature raw
      
        dT   = D2 - ((uint32_t)C[5] << 8);
        OFF  = ((int64_t)C[2] << 16) + ((dT * C[4]) >> 7);
        SENS = ((int32_t)C[1] << 15) + ((dT * C[3]) >> 8);
      
        TEMP = (int64_t)dT * (int64_t)C[6] / 8388608 + 2000;
      
        if(TEMP < 2000) // if temperature lower than 20 Celsius 
        {
          int32_t T1    = 0;
          int64_t OFF1  = 0;
          int64_t SENS1 = 0;
      
          T1    = pow(dT, 2) / 2147483648;
          OFF1  = 5 * pow((TEMP - 2000), 2) / 2;
          SENS1 = 5 * pow((TEMP - 2000), 2) / 4;
      
          if(TEMP < -1500) // if temperature lower than -15 Celsius 
          {
            OFF1  = OFF1 + 7 * pow((TEMP + 1500), 2); 
            SENS1 = SENS1 + 11 * pow((TEMP + 1500), 2) / 2;
          }
      
          TEMP -= T1;
          OFF -= OFF1; 
          SENS -= SENS1;
        }
      
      
        Temperature = (float)TEMP / 100; 
      
        P  = ((int64_t)D1 * SENS / 2097152 - OFF) / 32768;
      
        Pressure = (float)P / 100;
      
        Serial.print("     Actual TEMP= ");
        Serial.print(Temperature);
        Serial.print("      Actual PRESSURE= ");
        Serial.print(Pressure);
        Serial.println();
        Serial.println();
      
        Serial.print("     Actual ALTITUDE= ");
        Serial.print(getAltitude(Pressure, Temperature));
        Serial.println("m");
        Serial.println();  
        Serial.print(" RAW Temp D2=  ");
        Serial.print(D2);
        Serial.print(" RAW Pressure D1=  ");
        Serial.println(D1);
        Serial.println();
      
      //  Serial.print(" dT=  ");
      //  Serial.println(dT); can't print int64_t size values
        Serial.println();
        Serial.print(" C1 = ");
        Serial.println(C[1]);
        Serial.print(" C2 = ");
        Serial.println(C[2]); 
        Serial.print(" C3 = ");
        Serial.println(C[3]); 
        Serial.print(" C4 = ");
        Serial.println(C[4]); 
        Serial.print(" C5 = ");
        Serial.println(C[5]); 
        Serial.print(" C6 = ");
        Serial.println(C[6]); 
      //  Serial.print(" C7 = ");
      //  Serial.println(C[7]);
        Serial.println();
      
        delay(1000);
      }
      float getAltitude(float Pressure, float Temperature) {
        return ((pow((sea_press / Pressure), 1/5.257) - 1.0) * (Temperature + 273.15)) / 0.0065;
      }
      long getVal(int address, byte code)
      {
        unsigned long ret = 0;
        Wire.beginTransmission(address);
        Wire.write(code);
        Wire.endTransmission();
        delay(10);
        // start read sequence
        Wire.beginTransmission(address);
        Wire.write((byte) 0x00);
        Wire.endTransmission();
        Wire.beginTransmission(address);
        Wire.requestFrom(address, (int)3);
        if (Wire.available() >= 3)
        {
          ret = Wire.read() * (unsigned long)65536 + Wire.read() * (unsigned long)256 + Wire.read();
        }
        else {
          ret = -1;
        }
        Wire.endTransmission();
        return ret;
      }
      
      void initial(uint8_t address)
      {
      
        Serial.println();
        Serial.println("PROM COEFFICIENTS ivan");
      
        Wire.beginTransmission(address);
        Wire.write(0x1E); // reset
        Wire.endTransmission();
        delay(10);
      
      
        for (int i=0; i<6  ; i++) {
      
          Wire.beginTransmission(address);
          Wire.write(0xA2 + (i * 2));
          Wire.endTransmission();
      
          Wire.beginTransmission(address);
          Wire.requestFrom(address, (uint8_t) 6);
          delay(1);
          if(Wire.available())
          {
             C[i+1] = Wire.read() << 8 | Wire.read();
          }
          else {
            Serial.println("Error reading PROM 1"); // error reading the PROM or communicating with the device
          }
          Serial.println(C[i+1]);
        }
        Serial.println();
      }
      
        • 1. Re: how to enable the ms5611 on Edison Arduino kit?
          freshbird

          i test it in Arduino UNO

          and i find it can run well with Arduino UNO, the output is below:

          temp: 25.57 degC pres: 1019.23 mbar

          temp: 25.62 degC pres: 1019.26 mbar

          temp: 25.67 degC pres: 1019.25 mbar

          temp: 25.71 degC pres: 1019.27 mbar

          temp: 25.75 degC pres: 1019.29 mbar

          temp: 25.78 degC pres: 1019.28 mbar

          temp: 25.81 degC pres: 1019.33 mbar

          temp: 25.83 degC pres: 1019.30 mbar

          temp: 25.85 degC pres: 1019.31 mbar

          temp: 25.88 degC pres: 1019.33 mbar

          temp: 25.89 degC pres: 1019.31 mbar

          temp: 25.91 degC pres: 1019.33 mbar

          temp: 25.93 degC pres: 1019.32 mbar

          temp: 25.94 degC pres: 1019.35 mbar

          temp: 25.95 degC pres: 1019.34 mbar

          temp: 25.96 degC pres: 1019.33 mbar

          temp: 25.97 degC pres: 1019.36 mbar

          temp: 25.98 degC pres: 1019.33 mbar

          temp: 25.99 degC pres: 1019.35 mbar

          temp: 26.00 degC pres: 1019.36 mbar

          temp: 26.01 degC pres: 1019.35 mbar

          temp: 26.01 degC pres: 1019.38 mbar

          temp: 26.02 degC pres: 1019.36 mbar


          the test code(Arduino IDE) is in here:http://pan.baidu.com/s/1i3rIpY9

          example/MS561101BA_simple
          • 2. Re: how to enable the ms5611 on Edison Arduino kit?
            DiegoV_Intel

            Hi freshbird,

             

            I don't have that sensor to test it but I have tested some other I2C devices and sometimes I'm not able to communicate the Edison with them. In those cases I test the device with a simple sketch (I2C Scanner) to know if I'm able to detect the device. The sketch is attached to this post. You could run it to know if you can detect your sensor.

             

            Additionally, I will give you some alternative suggestions that you could try. I checked the datasheet of the sensor you are using (http://www.daedalus.ei.tum.de/attachments/article/61/MS5611-01BA01.pdf) and I noticed that it has an SPI interface too. I would test it using the SPI interface to know if I can get better results than using I2C communication.

             

            A test report for different shields can be found here: Intel® Download Center. There are some I2C devices that have been tested with Edison. There are some notes about how the shields were tested; you might take advantage of them for your project.

             

            For the rest, I would suggest to double check your I2C configuration. You could test the sensor using Python or directly through the Linux shell to know if you can get a better response from the device.

             

            Regards,

            Diego.

            • 3. Re: how to enable the ms5611 on Edison Arduino kit?
              freshbird

              Hi,DiegoV

                   First,Thanks for your attention.

                   and i test the sketch which is attached in your post,and unluckly,it told me that

              Scanning...

              No I2C devices found

               

              and i had test the i2cdetect -y -r 6 before,it's also no device founded.

              and you suggested me that drive the MS5611 via SPI,and i will test it by myself.and i will also wait your result of test.

               

              best regards.

               

              freshbird.

              • 4. Re: how to enable the ms5611 on Edison Arduino kit?
                DiegoV_Intel

                Hi freshbird,

                 

                Unfortunately I don't have the sensor you are using so I can't test it. Please test the SPI interface, you might get better results.

                 

                An additional suggestion would be to make sure you are using the correct voltage level. If the sensor is 3.3V compatible you should set the proper jumper on the board to make the IO pins 3.3V compatible, but if the sensor is 5V compatible the board should be configure to be 5V compatible as well. Please check this document for further details about the IOREF jumper: Intel® Edison Products — Jumper Headers

                 

                Regards,

                Diego.

                • 5. Re: how to enable the ms5611 on Edison Arduino kit?
                  freshbird

                  Hi,DiegoV

                        Oh.It's a good new.

                        Thanks for your suggestions.I can get the desired result by SPI mode.

                   

                  best regards,

                   

                  FreshBird.

                  • 6. Re: how to enable the ms5611 on Edison Arduino kit?
                    turtle-syp

                    You can connect 5611 module with Edison through I2C now. I fully test this question on my 2 Edisons with Arduino Extension and Breakout Extension.

                    There are 2 steps to solve it:

                    1. remove the pullup resistors of SDA and SCL on your GY86 module or 5611 stand alone module. Since Edison has internal pullup resistors, and the ones on GY86 or 5611 are only 2~10K, which are too strong and may damage the SCL pulse of Edison.

                    2. execute the flowing command:

                        $echo high > /sys/devices/pci0000:00/0000:00:09.1/i2c_dw_sysnode/mode

                        $echo on > /sys/devices/pci0000:00/0000:00:09.1/power/control

                        The first line will change the comm frequency to high speed mode instead of the default fast mode.

                        Second line turn off the power management of the I2C interface. This will eliminate the latency between the data transmitting and clock ticking.

                    Then, just run your 5611 module testing code based on Arduino IDE or mraa, or even Linux I2CDev-6 interface, are all OK to you.

                    I have fully test these steps and they do work on Edison with the latest WW25 release image.

                    Good luck.