Badger2040W and BME680 crashes

Hi,
I use an off-shelf BME680 via I2C. The driver seems to crash though and I don’t know why.

import badger2040
badger = badger2040.Badger2040()
import time
import machine
import breakout_bme68x
import pimoroni_i2c

PINS_I2C = {"sda": 4, "scl": 5} 
i2c = pimoroni_i2c.PimoroniI2C(**PINS_I2C)
#98 (0x62), not 118 (0x76) like breakout_bme68x.I2C_ADDRESS_DEFAULT or 119 (0x77) from breakout_bme68x.I2C_ADDRESS_ALT
#print(i2c.scan())
bme = breakout_bme68x.BreakoutBME68X(i2c, address=0x62)
print(bme.read())

this crashes the board, but the chip is recognised.
print(i2c.scan())

returns
[81, 98] so there is the eInk display at 0x51 (81) and the BME680 at 0x62 (98).

what’s to do?

oh and I even tried to catch the exception:

import errno
import badger2040
badger = badger2040.Badger2040()
import time
import machine
import breakout_bme68x
import pimoroni_i2c

try:
    PINS_I2C = {"sda": 4, "scl": 5}
    i2c = pimoroni_i2c.PimoroniI2C(**PINS_I2C)
    #print(i2c.scan())
    bme = breakout_bme68x.BreakoutBME68X(i2c, address=0x62)
    print(bme.read())
except OSError as err:
    print(err.value)
    print(err.errno)
    time.sleep(1)

but still nothing happens

Try to catch and print every exception (not only OSError). And then sleep for a very long time… Maybe this gives us some hints.

thank you for your suggestion. I do now

except Exception as err:
    print(err.value)
    print(err.errno)
    time.sleep(100)

but what I see in the terminal is:

>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
[

after a while, the connections gets lost.
it seems to die instantly after the BreakoutBME68X object is created. Only if I insert a time.sleep(1)after print(i2c.scan()) I even get any results printed out.

now I tried with threading:

##testing pimorinis breakout driver
import errno
import badger2040
badger = badger2040.Badger2040()
import time
import _thread
import machine
import breakout_bme68x
import pimoroni_i2c

def threadtesting():
    try:
        #98 (0x62), not 118 (0x76) like breakout_bme68x.I2C_ADDRESS_DEFAULT or 119 (0x77) from breakout_bme68x.I2C_ADDRESS_ALT
        bme = breakout_bme68x.BreakoutBME68X(i2c, address=0x62)
        time.sleep(100)
        print(bme.read())
        
    except:
        print("exception occured")
        time.sleep(1000)


PINS_I2C = {"sda": 4, "scl": 5} ##PINS_PICO_EXPLORER 
i2c = pimoroni_i2c.PimoroniI2C(**PINS_I2C)

print(i2c.scan())
time.sleep(5)
print("now running threadtesting()")
_thread.start_new_thread(threadtesting, ())
a_lock = _thread.allocate_lock()

with a_lock:
    print("a_lock is locked while this executes")
    print ("locked=", a_lock.locked())
    
c = 0 
while(True): #loop to keep alive
    print ("...", c, "locked =", a_lock.locked())
    c=c+1
    time.sleep (1)

but the lock is released immediately

>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
[81, 98, 119]
now running threadtesting()
a_lock is locked while this executes
locked= True
... 0 locked = False
... 1 locked = False
... 2 locked = False

so I guess I do something wrong here, too.

One question regarding your “off-shelf bme680”: is this a Pimoroni or Adafruit product or something else? From your I2C-addresses, this does not look like a BME680, which technically only supports 0x76/0x77.

The 0x51 you see is from the PCF85063A-RTC of the badger-w (the e-ink is attached via SPI). The only sensors I know that use the 0x62 are the SCD40/SCD41, but I cannot believe somebody is selling these expensive sensors as a BME680.

Maybe you can post an image of the sensor?

it’s a cheap china breakout board. just like this I will make a photo later today

Did you connect CS to VCC? This will select the I2C interface. Don’t let it float.

no I did not connect css but will try that, thank you.

it helped. I soldered vcc (3.3) to cs and now it works well. Next time, I will not save a few bucks and go for adafruit or pimoroni breakouts first. At least they are documented well.

1 Like

Please don’t take this the wrong way. I post on several Pi / Pico related forums, and going cheap, usually results in many, many questions for help getting said device to work.
Me personally, I’m to old for that ****. =)

1 Like

Well, the document from Bosch is fine and very detailed. But Adafruit and Pimoroni decide for you and thus you don’t have a choice between SPI and I2C.

These Chinese builds just put the bare minimum of components on the breakout giving you all degrees of freedom. But also a higher chance to fail.

Disclosure: I had the same problem with a Chinese BME280 and it took me also some time to figure it out. So no worries, that is why we have forums.

1 Like

@alphanomeric @bablokb thank you again. You’ve been very kind