I'm trying to start an I2c communication with my Raspberry Pi using the pigpio library. It works fine for me with SPI, but I really do struggle with I2C.

When I use

if (gpioInitialize() < 0) printf("Coudn't initialize gpio");
i2c_handle = i2cOpen(0, 0b1100000, 0);

I always get back -74 as handle, which stands for PI_BAD_I2C_BUS.

Can somebody explain that to me? The bus number I give to the function is 0, that should be totaly valid. But I also tried some different numbers and I always get this same error...

  • What model Pi are you using? What happens if you try this i2c_handle = i2cOpen(1, 0b1100000, 0); Commented Aug 1, 2017 at 10:45
  • I use a Raspberry Pi 3. No matter what bus number I use, there is always the same return.
    – jusaca
    Commented Aug 1, 2017 at 10:49
  • did you enable i2c in raspi-config?
    – crasic
    Commented Aug 1, 2017 at 23:14
  • Ok, that actually was the problem. Embarrassing. But I don't understand, I didn't enable SPI either, and that worked just fine from the beginning. Can I somehow mark your comment as solution, despite it's not an answer?
    – jusaca
    Commented Aug 2, 2017 at 8:46
  • @crasic, hi, I would like to invite you to post that solution as an answer. Thanks.
    – Ghanima
    Commented Oct 16, 2018 at 19:30

1 Answer 1


I was getting the same error:

raspberrypi $ python
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pigpio
>>> mypi = pigpio.pi()
>>> myi2c = mypi.i2c_open(1, 0x1E)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pigpio.py", line 2644, in i2c_open
    self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents))
  File "/usr/lib/python3/dist-packages/pigpio.py", line 979, in _u2i
    raise error(error_text(v))
pigpio.error: 'bad I2C bus'

And I eventually figured out that you need to enable I2C on the raspberry pi:

sudo raspi-config

And select 5 Interfacing Options -> P5 - I2C -> Yes to enable I2C

You can then check if I2C is enabled by looking in /dev/

raspberrypi $ ls -l /dev/i2c*
crw-rw---- 1 root i2c 89, 1 Apr 14 19:13 /dev/i2c-1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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