BMP388 to Arduino Micro failing to interface

Heya,

So I've been trying to get my Adafruit BMP388 to output pressure / altittude readings for weeks but to no avail. The datasheet only provides an example for the Arduino Uno and I'm using a Micro so have edited the example code from here: Arduino | Adafruit BMP388 and BMP390 - Precision Barometric Pressure and Altimeter | Adafruit Learning System
to the code below.

It's connecting, but only outputting 0C and 0HPA, (and then calculating an altitude of 43km presumably from the 0 air pressure) or it displays "Failed to perform reading :frowning: ".

I've wired the VIN to the 5V on the arduino, SCK to SCK, SDI to MI, and SDO to MOSI, and CS to SS. I've tried swapping the MOSI and MISO around (I'm new to arduino so not sure which way round they should be); checked the wiring tried using the digital pins, and I've tried using the I2C and SPI part of the code but don't understand the difference in the wiring; I'm just out of ideas.

Can anyone work out what I'm doing wrong?

***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP3XX.h>
/*#define BMP_SCK = 13;M
#define BMP_SDO = 12;
#define BMP_SDI = 11;
#define BMP_SS = 10;*/
int BMP_SCK = SCK;
int BMP_MISO = MOSI; //also called the SDO
int  BMP_MOSI = MISO; //SDI
int BMP_CS = SS;
#define SEALEVELPRESSURE_HPA (1013.25)
// Adafruit_BMP3XX bmp; // I2C
Adafruit_BMP3XX bmp(BMP_CS); // hardware SPI
// Adafruit_BMP3XX bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); +
void setup() {
Serial.begin(9600);
/*while (!Serial);
Serial.println("BMP388 test"); 
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP3 sensor, check wiring!");
while (1);
}*/

// Set up oversampling and filter initialization
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
//bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}
void loop() {
if (! bmp.performReading()) {
Serial.println("Failed to perform reading :(");
delay(10000);
return;
}
Serial.print("Temperature = ");
Serial.print(bmp.temperature);
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bmp.pressure / 100.0);
Serial.println(" hPa");
Serial.print ("Approx. Altitude = ");
Serial.print (bmp.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
/*Serial.println();*/
delay(2000);
}

I've wired the VIN to the 5V on the arduino

In this case you fried the BMP388 as it's a 3.3V device, connecting it to 5V may destroy it.

The same applies to all SPI signals.

If you didn't connect the chip but some breakout board you failed to tell us that important detail and you failed to provide a link to the board's schematics.

Hi Padders,

I've tried swapping the MOSI and MISO around...

Adafruit's BMP388 breakout board uses +5V to +3.3V level-shifters on the SCK and MOSI/SDI pins, but unfortunately not on MISO/SDO. Therefore care must be taken ensure that MOSI and MISO connections are correct before powering up, otherwise the Arduino Micro will drive its +5V MOSI signal into the BMP388's +3.3V SDO output with the potential for damaging the barometer device.

The correct connections should be:

MOSI --> SDI
MISO --> SDO

I've written a BMP388 library called BMP388_DEV (https://github.com/MartinL1/BMP388_DEV) that's availaible from the Arduino IDE library manager, (Sketch->Include Library->Manage Libraries...). To check that your barometer's working OK simply install the library and upload the sketch below on to your Arduino Micro:

///////////////////////////////////////////////////////////////////////////////
// BMP388_DEV - SPI Communications, Default Configuration, Normal Conversion
///////////////////////////////////////////////////////////////////////////////

#include <BMP388_DEV.h>                             // Include the BMP388_DEV.h library

float temperature, pressure, altitude;              // Create the temperature, pressure and altitude variables
BMP388_DEV bmp388(10);                              // Instantiate (create) a BMP388_DEV object and set-up for SPI operation on digital pin D10

void setup() 
{
  Serial.begin(115200);                             // Initialise the serial port
  bmp388.begin();                                   // Default initialisation, place the BMP388 into SLEEP_MODE 
  bmp388.setTimeStandby(TIME_STANDBY_1280MS);       // Set the standby time to 1.3 seconds
  bmp388.startNormalConversion();                   // Start BMP388 continuous conversion in NORMAL_MODE 
}

void loop() 
{
  if (bmp388.getMeasurements(temperature, pressure, altitude))    // Check if the measurement is complete
  {
    Serial.print(temperature);                      // Display the results    
    Serial.print(F("*C   "));
    Serial.print(pressure);    
    Serial.print(F("hPa   "));
    Serial.print(altitude);
    Serial.println(F("m"));  
  }
}

I've tested it with my Arduino Micro and Adafruit BMP388 breakout board and can comfirm that it works:

20.99*C   1000.51hPa   108.90m
21.00*C   1000.47hPa   109.24m
21.01*C   1000.49hPa   109.06m
21.02*C   1000.47hPa   109.25m
21.02*C   1000.47hPa   109.23m
21.03*C   1000.48hPa   109.11m
21.04*C   1000.47hPa   109.22m
21.05*C   1000.46hPa   109.34m

The BMP388_DEV library will also handle the BMP388 interrupts (INT pin) and store up to 72 temperature and pressure measurements using the barometer's on-chip 512 byte FIFO buffer.