First of all, let me introduce :
I’m quite new on Pimoroni forums, currently ending my IT studies and use Python for my graduation work with several sensors on a Raspberry Pi 4 2GB which will send everything in JSON format to a server which will store and create graphs from it.
For my graduation work, I wanted to use the BME680 from Pimoroni along with other sensors.
No problem with the others but with the BME680, I’m actually facing a little problem.
Whenever I launch my code, it states for an attribute error (module ‘bme680’ has no attribute ‘BME680’) even though it’s the exact same part of code from the given example code.
I really don’t understand why the example code works fine but mine is stuck at:
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
I also tried by not stating the address like the “Getting Started with BME680 Breakout” indicates but like I was thinking about the problem, it doesn’t change anything.
Really strange, you’re calling the sensor like I did and it doesn’t work in my code :/
EDIT : Here’s part of my code :
import time, datetime
import bme680
''' Calibration and initial reading '''
try:
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
except IOError:
sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY)
# These calibration data can safely be commented out, if desired.
print('Calibration data:')
for name in dir(sensor.calibration_data):
if not name.startswith('_'):
value = getattr(sensor.calibration_data, name)
if isinstance(value, int):
print('{}: {}'.format(name, value))
# These oversampling settings can be tweaked to
# change the balance between accuracy and noise in
# the data.
sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
sensor.select_gas_heater_profile(0)
If you only have the one BME680, and haven’t changed its i2c address via the jumper, as far as I know you don’t need all that I2C_ADDR_PRIMARY I2C_ADDR_SECONDARY stuff. Try remarking it out.
I don’t know if its an issue, but its what I would do. I don’t use it in my code with my one stock BME680.
Something else to keep in mind, no two i2c devices can have the same i2c address. If they do they won’t work. This crops up from time to time when somebody tests multiple sensors one at a time and they work, but fail when they wire them all up at once.
I think maybe you are using an old version of the bme680 library. I know the ltr559 library went through a transition from a module of functions to a class with constructor. Perhaps the bme680 library has done the same.
With sensor = bme680;, I have an other AttributeError.
It states :
module ‘bme680’ has no attribute ‘calibration_data’
You can check on my older reply here with part of my code that I use it to calibrate data.
If I set this part in comment, it states that there is no attribute ‘set_humidity_oversample’.
Just to confirm, the Pimoroni example files run fine?
And its a BME680 not a BMP680?
And lastly, you installed the software via curl https://get.pimoroni.com/bme680 | bash
Yes, the Pimoroni example file run fine.
The sensor is the officiel Pimoroni BME680 (I ordered it on the shop part of Pimoroni website).
Yes. I retried and it states that all requirements are present, all dependencies are up-to-date.
Just to let you know I’ve found the problem: I simply had to rename the python file from bme680.py to bme680sensor.py
The problem was that the old name was makeing troubles with the calling of the Pimoroni module. I now understand why Adafruit are naming their modules as “adafruit-circuitpython-xxx” :P
Dear Melvinmajor: can you elaborate what you mean by python file from bme680.py to bme680sensor.py
I am not able to understand that which why I still stuck with this problem. I get exactly the same error as you did. Your help will be appreciated
Simply rename your file in order to not have the same name as the library.
Python will then understand that import bme680 is the actual module from Pimoroni and not your code.
Hey Thank you for the quick response. Did that before but I didnt realize that there as another file with the same name that was causing the error. Thanks a lot!