09-01-2017, 07:23 PM
Has anybody used this library for I2C?
I got my first I2C device recently, this temp/pressure sensor. I tried reading it from an ESP8266 and an arduino first and didn't have any luck, so I decided to give it a try on the pine64. It shows up on i2cdetect, and if I run "sudo i2cdump twi1 0x76" it dumps a bunch of data, so I'm guessing it's wired up right.
I saw in the notes in github that this library has I2C "borrowed from pyA20", so a little googling found me some documentation here (you have to scroll a bit to get to the I2C info).
From that info, I put together this python script:
Now when I run this (as root) using python3, I get this error:
I tried changing the first line to use python2 instead of python3, and then I get this error instead:
Any idea what I'm doing wrong?
I got my first I2C device recently, this temp/pressure sensor. I tried reading it from an ESP8266 and an arduino first and didn't have any luck, so I decided to give it a try on the pine64. It shows up on i2cdetect, and if I run "sudo i2cdump twi1 0x76" it dumps a bunch of data, so I'm guessing it's wired up right.
I saw in the notes in github that this library has I2C "borrowed from pyA20", so a little googling found me some documentation here (you have to scroll a bit to get to the I2C info).
From that info, I put together this python script:
Code:
#!/usr/bin/env python3
from RPi import I2C
I2C.init("/dev/twi1")
I2C.open(0x76)
# set power mode to forced
I2C.write([0xF4,0x01])
sleep(1)
# dump data
I2C.write([0xF7])
value = I2C.read(1)
print(value)
I2C.close()
quit()
Now when I run this (as root) using python3, I get this error:
Code:
Traceback (most recent call last):
File "./bmp280_readonce.py", line 2, in <module>
from RPi import I2C
File "/usr/lib64/python3.4/site-packages/RPi/I2C/__init__.py", line 4, in <module>
from RPi._I2C import *
ImportError: dynamic module does not define init function (PyInit__I2C)
I tried changing the first line to use python2 instead of python3, and then I get this error instead:
Code:
Traceback (most recent call last):
File "./bmp280_readonce.py", line 5, in <module>
I2C.open(0x76)
IOError: [Errno 2] No such file or directory
Any idea what I'm doing wrong?