bmp280 library not working?

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

bmp280 library not working?

Post by cbrucewarren »

I installed and ran the test program shown here https://circuitpython.readthedocs.io/pr ... en/latest/ .
I was running successfully for weeks.
Now, when I run the program, i get a number of errors all seeming related to the bmp library?
I did update of Pi and re-installed library.
Suggestions??

[quote]Python 3.7.3 (/usr/bin/python3)
>>> %cd /home/pi/MyPython/MyScripts
>>> %Run bmp280_test_plot.py
Traceback (most recent call last):
File "/home/pi/MyPython/MyScripts/bmp280_test_plot.py", line 38, in <module>
print("\nTemperature: %0.1f C" % bmp280.temperature)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_bmp280.py", line 319, in temperature
self._read_temperature()
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_bmp280.py", line 151, in _read_temperature
while self._get_status() & 0x08:
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_bmp280.py", line 184, in _get_status
return self._read_byte(_REGISTER_STATUS)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_bmp280.py", line 380, in _read_byte
return self._read_register(register, 1)[0]
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_bmp280.py", line 412, in _read_register
i2c.write(bytes([register & 0xFF]))
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_bus_device/i2c_device.py", line 102, in write
self.i2c.writeto(self.device_address, buf, start=start, end=end)
File "/home/pi/.local/lib/python3.7/site-packages/busio.py", line 115, in writeto
return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 49, in writeto
self._i2c_bus.write_bytes(address, buffer[start:end])
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 308, in write_bytes
self._device.write(buf)
OSError: [Errno 121] Remote I/O error

User avatar
dastels
 
Posts: 15665
Joined: Tue Oct 20, 2015 3:22 pm

Re: bmp280 library not working?

Post by dastels »

It sounds more like a hardware problem. It's having trouble talking to the sensor. My first step would be to check the wiring.

Dave

User avatar
cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: bmp280 library not working?

Post by cbrucewarren »

when I run "i2cdetect -y -1" it shows the device, also a test probe of the device in python [ detect it, not read it] without using the adafruit library works....

User avatar
dastels
 
Posts: 15665
Joined: Tue Oct 20, 2015 3:22 pm

Re: bmp280 library not working?

Post by dastels »

OK, That's odd.

User avatar
cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: bmp280 library not working?

Post by cbrucewarren »

yes, very odd; especially since it had been working and I hadn't updated/upgraded or changed any of the code and then this happened. However, as I type this I recall that I had tried to implement a Dallas 1-wire connection in python so now i'm wondering if any of that has messed with the library?

User avatar
dastels
 
Posts: 15665
Joined: Tue Oct 20, 2015 3:22 pm

Re: bmp280 library not working?

Post by dastels »

Messing with a libary seems odd, unless it or parts of it were replaced during the other work.

Dave

User avatar
cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: bmp280 library not working?

Post by cbrucewarren »

status:
1) have -wire code working
2) i2cdetect finds BMP280 address
3) this code runs OK:

Code: Select all

"""CircuitPython Essentials I2C Scan example"""
# If you run this and it seems to hang, try manually unlocking
# your I2C bus from the REPL with
#  >>> import board
#  >>> board.I2C().unlock()

import time
import board

i2c = board.I2C()

while not i2c.try_lock():
    pass

try:
    while True:
        print("I2C addresses found:", [hex(device_address)
              for device_address in i2c.scan()])
        time.sleep(2)

finally:  # unlock the i2c bus when ctrl-c'ing out of the loop
    i2c.unlock()
4) runniing this code give error that I2C not found:

Code: Select all

import time
import board
# import digitalio # For use with SPI
import busio
import adafruit_bmp280
# import time
import psutil
import matplotlib.pyplot as plt
#%matplotlib notebook
#plt.rcParams['animation.html'] = 'jshtml'
fig = plt.figure()
fig1 = plt.figure()
ax = fig.add_subplot(111)
bx = fig1.add_subplot(111)

fig.show()
 
fig1.show()

i=0
x,y = [],[]
x1,y1 = [],[]
#Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)

# OR create library object using our Bus SPI port
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# bmp_cs = digitalio.DigitalInOut(board.D10)
# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)

# change this to match the location's pressure (hPa) at sea level
# bmp280.sea_level_pressure = 1013.25

while True:
    
    #time.sleep(20)
    print("\nTemperature: %0.1f C" % bmp280.temperature)
    print("Pressure: %0.1f hPa" % bmp280.pressure)
    print(" Cycle no: %0.1f" % i)
    print("Minutes from Start: %0.1f" % (i*5))
    print("Hours from Start: %0.1f" % (i/12))
#    print("Altitude = %0.2f meters" % bmp280.altitude)
   #------ setup pressure plot -----------
    x.append(i)
    
    y.append(bmp280.pressure)
    ax.set_title("Barometric Pressure")
    ax.plot(x,y,color ='b')
    fig.canvas.draw()
    ax.set_xlim(left=max(0,i-200),right = i+200)
    ax.set_ylim(870,900)
    
    
    #--- set up temperature graph?
    x1.append(i)
  
    y1.append(bmp280.temperature)
    bx.set_title("Room Temp")
    bx.plot(x1,y1,color ='b')
    fig1.canvas.draw()
    bx.set_xlim(left=max(0,i-200),right = i+200)
    bx.set_ylim(8,25)
    i+=1
    time.sleep(300)
5: code in (4) ran continously for a week or so

User avatar
cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: bmp280 library not working?

Post by cbrucewarren »

In terminal mode:
1) "i2cdetect -y 1 " finds the BMP280 address
2) "i2get 1 0x77 " results in "Error: read failed"

It is not the module; i swapped it with another module running on an Arduino set up.

I'm baffled as to what to try next -- thoughts??

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”