BME280 all-values.py

Just trying to get this breakout working and it has an error on the final line print statement.
IndentationError: unexpected indent
The final round bracket is being arrow’d
Why is this and how can I correct it?
Thanks

I don’t know the why but I do know the how.
Compare your file to this

#!/usr/bin/env python



import time

try:

    from smbus2 import SMBus

except ImportError:

    from smbus import SMBus

from bme280 import BME280



print("""all-values.py - Read temperature, pressure, and humidity



Press Ctrl+C to exit!



""")



# Initialise the BME280

bus = SMBus(1)

bme280 = BME280(i2c_dev=bus)



while True:

    temperature = bme280.get_temperature()

    pressure = bme280.get_pressure()

    humidity = bme280.get_humidity()

    print('{:05.2f}*C {:05.2f}hPa {:05.2f}%'.format(temperature, pressure, humidity))

    time.sleep(1)

If its the same and hasn’t been accidentally altered change that print line by removing the indent ahead of it.
Change

      print('{:05.2f}*C {:05.2f}hPa {:05.2f}%'.format(temperature, pressure, humidity))

to

print('{:05.2f}*C {:05.2f}hPa {:05.2f}%'.format(temperature, pressure, humidity))

and see if that fixes it.

Thanks for the reply. That line and the time.sleep line below were indented, don’t know why/how!
Corrected it and then it error’d with unable to find bme280 errors.
I have re-seated in another ‘garden’ connector and rebooted.

pi@weatherpi:~/bme280-python/examples $ python3 all-values.py
all-values.py - Read temperature, pressure, and humidity

Press Ctrl+C to exit!

Traceback (most recent call last):
File “all-values.py”, line 21, in
temperature = bme280.get_temperature()
File “/usr/local/lib/python3.7/dist-packages/pimoroni_bme280-0.0.2-py3.7.egg/b me280/init.py”, line 258, in get_temperature
self.update_sensor()
File “/usr/local/lib/python3.7/dist-packages/pimoroni_bme280-0.0.2-py3.7.egg/b me280/init.py”, line 244, in update_sensor
self.setup()
File “/usr/local/lib/python3.7/dist-packages/pimoroni_bme280-0.0.2-py3.7.egg/b me280/init.py”, line 222, in setup
raise RuntimeError(“Unable to find bme280 on 0x{:02x}, CHIP_ID returned {:02 x}”.format(self._i2c_addr, chip.id))

That may be a python3 / python 2 thing?
Run this from a terminal window and try again
sudo pip3 install pimoroni-bme280
And also make sure i2c is enabled in Raspberry Pi Configuration, under Interfaces.

Thanks again.
The pip3 command came back with ‘already satisfied lines’ Checked Ic2 is enabled.
Ran python3 all-values.py again and it came back with the same errors as above.

Ok, make sure you have plugged in the correct way around. Plugging it in backwards won’t hurt it, it just won’t work, and would be easy to do.
If you run it from python 2 “python” instead of python 3 “python3” does it work?
Does it show up if you run sudo i2cdetect -y 1

I believe they are correct, I match the ‘pin’ markings on the board to the breakout.
i2cdetect comes back with 23 and 76. 23 Is the ltr559 which is also plugged in. See below
Python2 also errors, similar lines, but less, as above. Lines 258, 224, 222 and ‘Unable to find bme280 on 0x76’. See below

Blockquotepi@weatherpi:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – 23 – – – – – – – – – – – –
30: – – – – – – – – – – – – – – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – – – – – – – – –
70: – – – – – – 76 –

pi@weatherpi:~/bme280-python/examples $ python2 all-values.py
all-values.py - Read temperature, pressure, and humidity

Press Ctrl+C to exit!

Traceback (most recent call last):
File “all-values.py”, line 21, in
temperature = bme280.get_temperature()
File “build/bdist.linux-armv6l/egg/bme280/init.py”, line 258, in get_temperature
File “build/bdist.linux-armv6l/egg/bme280/init.py”, line 244, in update_sensor
File “build/bdist.linux-armv6l/egg/bme280/init.py”, line 222, in setup
RuntimeError: Unable to find bme280 on 0x76, CHIP_ID returned 58

I think I have some corrupted files so I am deleting them and starting again.
I will post again when running again.
Thanks for your help.

This time around you could try the following instead of pip install.

git clone https://github.com/pimoroni/bme280-python
cd bme280-python
sudo ./install.sh

Deleted all files and directories and git cloned a new copy, worked immediately!
Now just need logging/visualising code to really make use of it.
Thanks for your support

I like using the git clone option, it pretty well gets you everything on that respective git hub page, including the examples folder. I think it also installs any dependencies etc as well
Good to hear you got it working.