Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C works, but SPI fails due to wrong chip id #43

Closed
iyanmv opened this issue Aug 1, 2024 · 2 comments · Fixed by #44
Closed

I2C works, but SPI fails due to wrong chip id #43

iyanmv opened this issue Aug 1, 2024 · 2 comments · Fixed by #44

Comments

@iyanmv
Copy link

iyanmv commented Aug 1, 2024

Hello,

I just received a Adafruit BMP280 and I can't make the SPI example work. This is the error I get:

Traceback (most recent call last):
  File "/home/iyan/bmp280/example.py", line 13, in <module>
    bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/iyan/bmp280/.venv/lib/python3.11/site-packages/adafruit_bmp280.py", line 531, in __init__
    super().__init__()
  File "/home/iyan/bmp280/.venv/lib/python3.11/site-packages/adafruit_bmp280.py", line 143, in __init__
    raise RuntimeError("Failed to find BMP280! Chip ID 0x%x" % chip_id)
RuntimeError: Failed to find BMP280! Chip ID 0xff

I2C works just as described in the example and in the tutorial.

I was first using a Raspberry Pi 5, but because I read other people having issues with the latest RPi, I also tried on a RPi 3B with the same outcome. I was also using a GPIO Extension Board, but just in case I also tried connecting the cables directly, but it doesn't make a difference.

This is the exact example I'm trying to run:

import time
import board
import digitalio
import adafruit_bmp280

spi = board.SPI()
bmp_cs = digitalio.DigitalInOut(board.D10)
bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)

bmp280.sea_level_pressure = 1013.25

while True:
    print("\nTemperature: %0.1f C" % bmp280.temperature)
    print("Pressure: %0.1f hPa" % bmp280.pressure)
    print("Altitude = %0.2f meters" % bmp280.altitude)
    time.sleep(2)

And here is a photo of the setup:

image

Probably related to this I found this closed issue (#27) and this closed thread in the forum.

Any ideas what might I be doing wrong? Or how to debug further? I have no prior experience with SPI.

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Nov 7, 2024

@iyanmv I believe the forum post is essentially saying to try something like this:

spi = board.SPI()
spi.configure(polarity=1, phase=1)
# ... rest of the code same

Or maybe try different permutations of 1 and 0 for the values of those, the default values are both 0, so try the other 3 permutations and see if any of them work for you.

@FoamyGuy
Copy link
Contributor

I tested the BMP280 sensor over SPI on a Raspberry Pi 4 with current versions of Blinka and the BMP280 driver and found it was successfully initializing and taking readings.

I did not need ot use the polarity or phase arguments, I used a mostly stock simpletest script from this repo with the only changes being to uncomment the SPI sections of code and to change the CS pin to D5 instead of D10.

@iyanmv Upon taking a closer look at your image, I think that latter change of the pin from D5 to D10 might be the crux of your issue.

In the code you posted it's using D10 for the CS pin: bmp_cs = digitalio.DigitalInOut(board.D10)

But in the photo it appears that your CS pin is connected to pin D5 on the Raspberry pi (https://www.raspberrypi.com/documentation/computers/images/GPIO-Pinout-Diagram-2.png?hash=df7d7847c57a1ca6d5b2617695de6d46) D5 is the 3rd pin away from the SCK pin.

Were you following along with this learn guide page? https://learn.adafruit.com/adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout/circuitpython-test#python-computer-wiring-2997144

I did notice that the wiring diagram on that page shows the connection to D5 which looks to match your wiring. And some of the code sections on that page do refer to pin D5. But the final code section which shows the complete example is using pin D10 which would require different wiring from what is shown above. I will open a PR to change the pin in the example code to D5 so it matches the image and the other code snippets in the guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants