kbrownlees / bme280

Python Driver for the BME280 Temperature/Pressure/Humidity Sensor from Bosch
Other
39 stars 15 forks source link

Attribute Error #4

Open H60gh opened 6 years ago

H60gh commented 6 years ago

Hi I use bme280 0.3 package. As "i2cdetect -y 1" command returns, my BME280 has address 0x77 and "read_bme280 -- help" command works well. But when I test "read_bme280 --i2c-address 0x77" command, following error appears: Traceback (most recent call last): File "/usr/local/bin/read_bme280", line 9, in load_entry_point('bme280==0.3', 'console_scripts', 'read_bme280')() File "/usr/local/lib/python3.4/dist-package/bme280/bme280.py", line 210, in main bme280_i2c.set_default_bus(int(args.i2c_bus)) File "/usr/local/lib/python3.4/dist-package/bme280/bme280.py", line 22, in set_default_bus default_bus = smbus.SMBus(bus_number) AttributeError: 'NoneType' object has no attribute 'SMBus'

Can anybody help me?

kbrownlees commented 6 years ago

There should of been a warning like

smbus is not available, you will not be able to use i2c

If so you need to follow the instructions in the README, mainly:

For I2C access you must have the 'smbus' package available - for debian based systems install python-smbus. If you wish to compile it, the package required is smbus-cffi (https://pypi.python.org/pypi/smbus-cffi/)

H60gh commented 6 years ago

Thank you kbrownlees I am using Raspberry pi 3 board with Rasbian and I have smbus 1.1 running on it and as I checked, I have the newest i2c library versions on it too. But still having the problems. My python version is 3.4.2 and I have bme280 version 0.3 installed library too.

Also, when I run "pip install smbus-cffi", I recerive an error which it says " ... No distribution at all found for smbus-cffi ... "

Should I make more changes in Raspberry pi configuration?

Exscotticus commented 6 years ago

I have two smbus-like libs installed, so not sure which one was needed...

pi@raspberrypi:~ $ pip3 search smbus
Adafruit-PureIO (0.2.1)  - Pure python (i.e. no native extensions) access to Linux
                           IO including I2C and SPI.  Drop in replacement for smbus
                           and spidev modules.
smbus-cffi (0.5.1)       - This Python module allows SMBus access through the I2C
                           /dev interface on Linux hosts. The host kernel must have
                           I2C support, I2C device interface support, and a bus
                           adapter driver.
  INSTALLED: 0.5.1 (latest)
pyblinkm (0.1.0)         - Drive a BlinkM with Python via I2C using python-smbus on
                           Raspberry Pi.
pysmbus (0.1)            - Pure Python implementation of the I2C SMBus protocol.
smbus2 (0.2.0)           - smbus2 is a drop-in replacement for smbus-cffi/smbus-
                           python in pure Python
  INSTALLED: 0.2.0 (latest)

And this seems to be the minimum Python needed to get a result...

pi@raspberrypi:~/$ python3
Python 3.5.3
Type "help", "copyright", "credits" or "license" for more information.
>>> from bme280 import bme280
>>> bme280.bme280_i2c.set_default_i2c_address(0x76)
>>> bme280.bme280_i2c.set_default_bus(1)
>>> bme280.setup()
>>> bme280.read_all()
Data(humidity=55.73471521799349, pressure=948.001722783354, temperature=11.319838337250985)

Hope this helps.