Picodev BME280 and Pimoroni badger i2c intermittent

Hi everyone. I am having some trouble getting my Pimoroni Badger to consistently talk to the PiicoDev BME280 sensor board.

I have connected the piicodev BME280 sensor to the Pimoroni Badger via the Qw/ST connector. I am finding that the connection is very intermittent and I often (more often than not) get the following error:

PiicoDev could not communicate with module at address 0x77, check wiring
Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
  File "PiicoDev_BME280.py", line 32, in __init__
  File "PiicoDev_BME280.py", line 29, in __init__
  File "PiicoDev_BME280.py", line 64, in _read16
OSError: [Errno 5] EIO

I am initialising the sensor with the following micropython:

sensor = PiicoDev_BME280(sda=4, scl=5, iir=1)

as per:

I am confident that there is not an obvious issue with the address etc as it does sometimes work and I have tested and can confirm the presence of the sensor at 0x77.

I am fairly new to i2c programming and would appreciate any ideas.

4 Likes

Hi Andrew,

Welcome to the forum :grinning:

Thanks for including the error messages you got and confirming the code you were trying to run.

Can you send us a photo of how the BME280 is connected? Since it is working sometimes and not others it may be something small to do with the wiring and a second set of eyes may be able to spot it.

Otherwise, if we can’t spot anything simple there we may need to look into what the differences are between the Badger and the regular Pi Pico firmware.

2 Likes

Thank you glad to be here and thank you for your quick reply Trent.

I have attached a photo as requested.

If I run the following python:

import machine
sda=machine.Pin(4) 
scl=machine.Pin(5) 
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
 
print('Scan i2c bus...')
devices = i2c.scan()
 
if len(devices) == 0:
  print("No i2c device !")
else:
  print('i2c devices found:',len(devices))
 
  for device in devices:  
    print("Decimal address: ",device," | Hex address: ",hex(device))

I get the output:

Scan i2c bus...
i2c devices found: 1
Decimal address: 119 | Hex address 0x77

Which suggests to me that the wiring is likely ok and that something else is going on. I have also tried a couple of different cables.

Any ideas are gratefully accepted and appreciated.

3 Likes

Hi Andrew,

How awesome is the badger!
I’d give the following a go(one at a time to see if individually any of the changes help):

  • Specify the bus parameter at initialisation, that will change your code to sensor = PiicoDev_BME280(bus=0,sda=Pin(4), scl=Pin(5), iir=1)
  • Try running the scan code a few times, just to check if there is any intermitent faults possibly caused by interference

We dont have a Badger to test with at the moment but as soon as we do we’ll try and set it up here!
Liam.

2 Likes

Thanks Liam,

Yes the badger is fantastic - it’s perfect for my project as it requires a cheap low power display that works in a bright environment. It’s also keeping me busy while I wait for supply chain issues with other boards to work themselves out.

That said, I haven’t seen any difference from adjusting the above settings as you suggested. I will keep looking. Just as way of proof of life I took the following photo as it’s decided to work again - don’t you just love intermittent bugs?!

The scan code works every time and I have included it into my fork of PiicoDev_Unified.py now.

>>> %Run -c $EDITOR_CONTENT
Using supplied freq, sda and scl to create machine I2C
i2c devices found: 1
Decimal address:  119  | Hex address:  0x77

It’s connected via USB to a raspberry pi 4 for power etc.

4 Likes

Hey Andrew,

Re this error:

That can happen if the connector is wobbled. If the device is going to be moved around during use, it might be best to use the solderable breakouts.

Or, wrap the request with Try & Except so that you can catch the intermittent error and then re-initialise the sensor before trying again (to be on the safe side).

4 Likes

Hi Andrew,

A bit of an aside, I’d give my fork a go, it adds a basic scan function for a couple of the PiicoDev sensors -

If you have any feedback lemme know :slight_smile:

To test try the following:

from PiicoDev_Unified import *
i2c = create_unified_i2c()
print(scan_sensors(i2c))
3 Likes

Hi Andrew,

I’ve confirmed the bug and havent got a working solution at the moment, still working through some possible workarounds :smiley:

EDIT: It looks like this one might be a bit deeper Andrew! Redefining the I2C through the Unified library leads to some unexpected results on the RP2040, an issue on GitHub has been raised and we’ll update you when we have a solution!

Liam

3 Likes

Thank you Liam for your help with this. I’m looking forward to seeing how this progresses. I’m glad it wasn’t just down to poor python on my part!

3 Likes