0
\$\begingroup\$

I am working on a project that involves logging the altitude from the BMP280 breakout board from Adafruit on an SD card using an Arduino Uno and SPI. initially I got the whole thing working right and the data was being logged as expected but after a while it stopped working consistently. right now it only works sometimes when I turn it on.

It seems that when I turn it on either the bmp.begin() or the SD.begin(SDCS) function won't work (usually the SD card is the culprit but sometimes it's the BMP). I've tried many things but I can't seem to get it too work. Full list of things I've tried:

  • rewiring (many, many times)
  • checking the voltage (each are getting a good 5 V when checked with a multimeter)
  • switching out the sensor (I've tried two BMP280's and two different SD card readers and many SD cards)
  • switching from a breadboard to directly adding jumper wires and now a PCB
  • checking the memory usage of the Arduino (usually fine)

Additionally the SD card is formatted properly as FAT16 with SD Card formatter and is 32 GB SDHC.

I am very confused at this point as I don't understand why it can work one time I turn it on and then stop for the next few hours. I'm not really sure what I should try next.

Below are the exact sensors:

BMP

SD Card Reader

I'm starting it the same way Adafruit recommends on their examples:

BMP Code:

Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
if (!bmp.begin()) {  
  Serial.println("Could not find a valid BMP280 sensor, check wiring!");
  while (1);   
}

SD Code:

bool success = SD.begin(SDCS);

if (success)
  datafile = SD.open(FILENAME, FILE_WRITE);

Both SDCS and BMPCS are defined constants to their respective CS pins.

Below is the part of the schematic that is of interest:

Schematic

Note: The SD card and BMP280 are hooked up to terminal blocks in the schematic which is why the pinout doesn't match perfectly.

I'm completely out of ideas for troubleshooting and would appreciate any help I could get to solve this.

\$\endgroup\$
  • \$\begingroup\$ Have you tried each of them on their own? (i.e. only have one SPI slave device connected). Can you ensure CS is high on other devices when they are not being used? Try taking an oscilloscope reading of MISO/MOSI/SCK and CS of device when in use? \$\endgroup\$ – pm101 Apr 24 '19 at 13:12
  • \$\begingroup\$ I tried using then individually and it doesn't really work much better. I haven't tried using an oscilloscope on it yet so I'll see what that looks like. Thanks \$\endgroup\$ – sam h Apr 24 '19 at 13:19
  • \$\begingroup\$ I'd get an oscilloscope reading from the BMP if that isn't working as its probably a much simpler protocol than the SD card \$\endgroup\$ – pm101 Apr 24 '19 at 13:28
  • \$\begingroup\$ It's not a scope you need, rather add debug output to both libraries so you can see where things depart from plan. \$\endgroup\$ – Chris Stratton Apr 24 '19 at 13:30
  • \$\begingroup\$ I tried putting some debug output in the BMP280 library and it seems to be failing right after the SPI.begin() call when it tries to read the chip id. \$\endgroup\$ – sam h Apr 24 '19 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.