2 Replies Latest reply on Mar 1, 2016 12:22 AM by GerardVidal

    Impossible to plug more than one sensor on I2c Arduino breakout

    GerardVidal

      Hi,

       

      I hope this is not due to bad wiring or understanding of I2c, I have read many posts and as far as I can understand it I have followed the best practices. Here is my problem I would like to plug on the same bus :

      Pressure sensor  fromhttp://www.mikroe.com/click/altitude/ mpl3115a2http://cache.nxp.com/files/sensors/doc/data_sheet/MPL3115A2.pdf?pspll=1
      Temp/humidityhttps://www.adafruit.com/products/1899htu21d

      https://www.adafruit.com/datasheets/1899_HTU21D.pdf

      My config is :

      >>> mraa.getVersion()
      'v0.9.4-4-g8e8ed7d'
      >>> mraa.getPlatformName ()
      'Intel Edison'
      >>> mraa.getPlatformVersion ()
      'arduino'
      >>> 
      

      For each sensor individually things work perfectly here is the output of python commands using upm :

      >>> import mraa
      >>> import pyupm_htu21d
      >>> bus = 6
      >>> tempAddress = 0x40
      >>> temp = pyupm_htu21d.HTU21D(bus, tempAddress)
      >>> temp.resetSensor ()
      >>> temp.sampleData()
      0
      >>> RH = temp.getCompRH()
      >>> temperature = temp.getTemperature()
      >>> hygro = temp.getHumidity ()
      !>>> print '\t%.3f\t\t'%temperature + '%.3f\t\t'%hygro + '%.3f'%RH
      
          21.790        36.968        37.449
      

      and

      >>> import pyupm_mpl3115a2
      >>> bus = 6
      >>> pressAdress = 0x60
      >>> press = pyupm_mpl3115a2.MPL3115A2(bus, pressAdress)
      >>> press.sampleData()
      0
      >>> temperatureP = press.getTemperature()
      >>> pressure = press.getPressure()
      >>> pressea = press.getSealevelPressure()
      >>> alt = press.getAltitude()
      >>> print '\t%.3f\t\t'%temperatureP + '%.3f\t\t'%pressure + '%.3f\t\t'%pressea + '%.3f'%alt
          22.062        98498.500        98498.500        238.029
      

       

      My true altitude is 184 m  and preasure read at the nearest weather station (few hundred meters) is 1005.7 HPa which seems to correspond properly with my readings.

       

      Then I ty to wire both sensors on the same bus, as recommended on most (all) posts I add pullup resistors on both SCL and SDA.

      i2c-1sensors.jpg

      I have checked with 3.3v and 5v power suply and even without pullup resistors th result is exactly the same : I get weird results like this :

      >>> temp.resetSensor ()
      >>> temp.sampleData()
      0
      >>> RH = temp.getCompRH()
      >>> temperature = temp.getTemperature()
      >>> hygro = temp.getHumidity ()
      >>> print '\t%.3f\t\t'%temperature + '%.3f\t\t'%hygro + '%.3f'%RH
          -46.850        -6.000        4.777
      >>> press.sampleData()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib/python2.7/site-packages/pyupm_mpl3115a2.py", line 223, in sampleData
          return _pyupm_mpl3115a2.MPL3115A2_sampleData(self)
      RuntimeError: UPM Runtime Error: i2cWriteReg:mraa_i2c_write() failed
      >>> temperatureP = press.getTemperature()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib/python2.7/site-packages/pyupm_mpl3115a2.py", line 277, in getTemperature
          return _pyupm_mpl3115a2.MPL3115A2_getTemperature(self, bSampleData)
      RuntimeError: UPM Runtime Error: i2cWriteReg:mraa_i2c_write() failed
      >>> pressure = press.getPressure()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib/python2.7/site-packages/pyupm_mpl3115a2.py", line 261, in getPressure
          return _pyupm_mpl3115a2.MPL3115A2_getPressure(self, bSampleData)
      RuntimeError: UPM Runtime Error: i2cWriteReg:mraa_i2c_write() failed
      >>> pressea = press.getSealevelPressure()
      >>> alt = press.getAltitude()
      >>> print '\t%.3f\t\t'%temperatureP + '%.3f\t\t'%pressure + '%.3f\t\t'%pressea + '%.3f'%alt
          22.062        98498.500        98498.500        238.029
      

      Last values look good but they are not, they correspond to the previous readings.

       

      I may do something wrong but I really need  to have more than one casensor on my bus..... Any help would be highly appreciated.

       

      Tanks.