Skip to content

Error when running basic examples #37

Description

@andrewcdowning

When running any examples I get the following error

(pimoroni) pi@weather:~/Pimoroni/weatherhat/examples $ python basic.py 
Traceback (most recent call last):
  File "/home/pi/Pimoroni/weatherhat/examples/basic.py", line 5, in <module>
    sensor = weatherhat.WeatherHAT()
  File "/home/pi/.virtualenvs/pimoroni/lib/python3.9/site-packages/weatherhat/__init__.py", line 62, in __init__
    self._int = self._chip.request_lines(
  File "/home/pi/.virtualenvs/pimoroni/lib/python3.9/site-packages/gpiod/chip.py", line 331, in request_lines
    req_internal = cast(_ext.Chip, self._chip).request_lines(
OSError: [Errno 16] Device or resource busy
Exception ignored in: <function WeatherHAT.__del__ at 0xf737f2b0>
Traceback (most recent call last):
  File "/home/pi/.virtualenvs/pimoroni/lib/python3.9/site-packages/weatherhat/__init__.py", line 121, in __del__
    self._poll_thread.join()
AttributeError: 'WeatherHAT' object has no attribute '_poll_thread'
(pimoroni) pi@weather:~/Pimoroni/weatherhat/examples $ 

I can reproduce in console by trying

>>> import weatherhat
>>> 
>>> sensor = weatherhat.WeatherHAT()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.virtualenvs/pimoroni/lib/python3.9/site-packages/weatherhat/__init__.py", line 62, in __init__
    self._int = self._chip.request_lines(
  File "/home/pi/.virtualenvs/pimoroni/lib/python3.9/site-packages/gpiod/chip.py", line 331, in request_lines
    req_internal = cast(_ext.Chip, self._chip).request_lines(
OSError: [Errno 16] Device or resource busy

When I write code to access the BME280 Sensor directly I can access and get readings directly

>>> import bme280
>>> from smbus2 import SMBus
>>> import time
>>> from bme280 import BME280
>>> bus = SMBus(1)
>>> bme280 = BME280(i2c_dev=bus)
>>> 
>>> while True:
...     temperature = bme280.get_temperature()
...     pressure = bme280.get_pressure()
...     humidity = bme280.get_humidity()
...     print(f"{temperature:05.2f}°C {pressure:05.2f}hPa {humidity:05.2f}%")
...     time.sleep(1)
... 
24.55°C 819.55hPa 21.61%
24.55°C 819.55hPa 21.61%
24.56°C 819.56hPa 21.61%
24.56°C 819.56hPa 21.59%
24.56°C 819.56hPa 21.57%
...

I currently have wind and rain sensors plugged in but it is the same result when they are unplugged.

I am getting addresses with i2c detect command.

(pimoroni) pi@weather:~/Pimoroni/weatherhat/examples $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- 12 -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- 23 -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 --   

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions