astro-pi / python-sense-hat

Source code for Sense HAT Python library
https://sense-hat.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
505 stars 253 forks source link

python 3.8 cannot use sensors: OSError #101

Open jwhendy opened 3 years ago

jwhendy commented 3 years ago

Trying to do something like this:

$ cat acc-example.py 

from sense_hat import SenseHat

sense = SenseHat()

while True:
    acceleration = sense.get_accelerometer_raw()
    x = acceleration['x']
    y = acceleration['y']
    z = acceleration['z']

    x=round(x, 0)
    y=round(y, 0)
    z=round(z, 0)

    print("x={0}, y={1}, z={2}".format(x, y, z))

Results in:

$ python acc-example.py 
Traceback (most recent call last):
  File "acc-example.py", line 6, in <module>
    acceleration = sense.get_accelerometer_raw()
  File "/home/jwhendy/.local/lib/python3.8/site-packages/sense_hat/sense_hat.py", line 844, in get_accelerometer_raw
    raw = self._get_raw_data('accelValid', 'accel')
  File "/home/jwhendy/.local/lib/python3.8/site-packages/sense_hat/sense_hat.py", line 703, in _get_raw_data
    if self._read_imu():
  File "/home/jwhendy/.local/lib/python3.8/site-packages/sense_hat/sense_hat.py", line 684, in _read_imu
    self._init_imu()  # Ensure imu is initialised
  File "/home/jwhendy/.local/lib/python3.8/site-packages/sense_hat/sense_hat.py", line 648, in _init_imu
    raise OSError('IMU Init Failed')
OSError: IMU Init Failed

Info

$ python --version
Python 3.8.2

$ pip freeze
sense-hat==2.2.0
RTIMULib==7.2.1

From looking at the code, seems like this is not playing nice with RTIMUlib. I installed/built it from source as described here.

Thanks.

jwhendy commented 3 years ago

Just posted at RTIMULib2 as I think that's causing the issue here and in #79 .