0

I have a Raspberry Pi 3 Model B+. My I2C device which is this (exact breakout board) isn't getting detected through PIGPIO Library. The sensor works very well with the example codes which uses SMBUS library. Upon doing a i2cdetect -y 1, my device is beint detected and I receive the following :

    pi@raspberrypi:~/Desktop $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- 0c -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Initially, as I converted the SMBUS code to PIPGIO, I just got the i2c write failed errors and such and was very confused as no such errors were addressed anywhere on the net. Now, I found this code by the library's creator to check if the device is detected through the PIGPIO Library. This is the code :

#!/usr/bin/env python

# 2015-06-30
# i2c_detect.py
# Public Domain

import pigpio

pi = pigpio.pi() # connect to local Pi

for device in range(128):

      h = pi.i2c_open(1, device)
      try:
         pi.i2c_read_byte(h)
         print(hex(device))
      except: # exception if i2c_read_byte fails
         pass
      pi.i2c_close(h)

pi.stop # disconnect from Pi

I used this and it just passes. To confirm my suspicion, I added a "print("Failed")" before the pass which returned this.

pi@raspberrypi:~/Desktop $ python i2chml.py
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
Failed
pi@raspberrypi:~/Desktop $

So that's the problem. I know my wiring and everything else is okay because I'm getting the intended output from the example code which uses SMBUS in the "Sparfun Hookup Guide" which I've thoroughly followed to set this up as well.

Over to you guys, I guess.

1

The most likely solution is that the I2C device does not support the SMBus read byte command.

i2cdetect uses a variety of probing methods and chooses the one most likely according to the device's address. The pigpio example script is much simpler.

See man i2cdetect

As there is no standard I2C detection command, i2cdetect uses arbitrary SMBus commands (namely SMBus quick write and SMBus receive byte) to probe for devices. By default, the command used is the one believed to be the safest for each address. See options -q and -r to change this behavior.

  • Thanks! That could be it. I've decided again to go with SMBus for other reasons and I gotta say you're doing god's work! Thanks for the beautiful library, man! – BLOODHOUND Sep 4 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.