kplindegaard / smbus2

A drop-in replacement for smbus-cffi/smbus-python in pure Python
MIT License
238 stars 68 forks source link

Error when running a basic example #40

Open ghost opened 4 years ago

ghost commented 4 years ago

Hey there,

Looking forward to using this library. I ran the pip install and run one the basic examples to read a byte.

I get the following error:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    b = bus.read_byte_data(80,0)
  File "/home/david/.local/lib/python3.7/site-packages/smbus2/smbus2.py", line 412, in read_byte_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 6] No such device or address

which I believe is permission related as i2cdetect -l returns:

sudo i2cdetect -l
i2c-3   smbus           SMBus PIIX4 adapter port 3 at 0b00      SMBus adapter
i2c-10  i2c             NVIDIA i2c adapter 7 at 41:00.0         I2C adapter
i2c-1   smbus           SMBus PIIX4 adapter port 0 at 0b00      SMBus adapter
i2c-8   i2c             NVIDIA i2c adapter 5 at 41:00.0         I2C adapter
i2c-6   i2c             NVIDIA i2c adapter 1 at 41:00.0         I2C adapter
i2c-4   smbus           SMBus PIIX4 adapter port 4 at 0b00      SMBus adapter
i2c-11  i2c             NVIDIA i2c adapter 8 at 41:00.0         I2C adapter
i2c-2   smbus           SMBus PIIX4 adapter port 2 at 0b00      SMBus adapter
i2c-0   i2c             Synopsys DesignWare I2C adapter         I2C adapter
i2c-9   i2c             NVIDIA i2c adapter 6 at 41:00.0         I2C adapter
i2c-7   i2c             NVIDIA i2c adapter 3 at 41:00.0         I2C adapter
i2c-5   smbus           SMBus PIIX4 adapter port 1 at 0b20      SMBus adapter

I took it out of virtualenv but still get an error. Any suggestions?

kplindegaard commented 4 years ago

Could it be that you try to read from address 80 but there is nothing there?

What does i2cdetect -y BUS_NUMBER tell you? (Of course you must replace BUS_NUMBER with actual bus you want to check ;) ).

On my Pi, I have one bus:

$ i2cdetect -l
i2c-1   i2c         bcm2835 I2C adapter                 I2C adapter

And if I want to see what there on that bus:

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

Voila. Two accessible addresses. 0x50 and 0x51, i.e. 80 and 81 in decimal.