You can easily wire this breakout to any microcontroller, we'll be using an Arduino Uno/328P compatible. For another kind of microcontroller, as long as you have 4 available pins it is possible to 'bit-bang SPI' or you can use two I2C pins, but usually those pins are fixed in hardware. Just check out the library, then port the code.
- Connect Vin to the power supply, 3-5V is fine. (Red wire on STEMMA QT version.) Use the same voltage that the microcontroller logic is based off of. For most older Arduinos, that is 5V.
- Connect GND to common power/data ground. (Black wire on STEMMA QT version.)
- Connect the SCK/SCL pin to the I2C clock SCL pin on your Arduino. (Yellow wire on STEMMA QT version.) On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3.
- Connect the SDI/SDA pin to the I2C data SDA pin on your Arduino. (Blue wire on STEMMA QT version.) On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2.
SPI Wiring
Since this is a SPI-capable sensor, we can use hardware or 'software' SPI. To make wiring identical on all Arduinos, we'll begin with 'software' SPI. The following pins should be used:
- Connect Vin to the power supply, 3V or 5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V.
- Connect GND to common power/data ground.
- Connect the SCK/SCL pin to Digital #13 but any pin can be used later.
- Connect the SDO pin to Digital #12 but any pin can be used later.
- Connect the SDI/SDA pin to Digital #11 but any pin can be used later.
- Connect the CS pin Digital #10 but any pin can be used later.
Later on, once we get it working, we can adjust the library to use hardware SPI if you desire, or change the pins assignments.
Download Adafruit_BMP3XX library
To begin reading sensor data, you will need to install the Adafruit_BMP3XX library (code on our github repository). It is available from the Arduino library manager so we recommend using that.
From the IDE open up the library manager...
And type in adafruit bmp3xx to locate the library. Click Install
You'll also need to install the Adafruit Unified Sensor library
We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
Load Demo
Open up File -> Examples -> Adafruit_BMP3XX -> bmp3xx_simpletest and upload to your Arduino wired up to the sensor.
Depending on whether you are using I2C or SPI, change the pin names and comment or uncomment the following lines.
#define BMP_SCK 13 #define BMP_MISO 12 #define BMP_MOSI 11 #define BMP_CS 10 #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); // Software SPI
Once uploaded to your Arduino, open up the serial console at 115200 baud to see data being printed out:
Temperature is calculated in degrees C, you can convert this to F by using the classic F = C * 9/5 + 32 equation.
Pressure is returned in the SI units of Pascals. 100 Pascals = 1 hPa = 1 millibar. Often times barometric pressure is reported in millibar or inches-mercury (Hg). For future reference 1 pascal =0.000295333727 inches of mercury, or 1 inch Hg = 3386.39 Pascal. So if you take the Pascal value of say 100734 and divide by 3389.39 you'll get 29.72 inches-Hg.
You can also calculate Altitude. However, you can only really do a good accurate job of calculating altitude if you know the hPa pressure at sea level for your location and day! The sensor is quite precise but if you do not have the data updated for the current day, then it can be difficult to get more accurate than 10 meters.
Pass in the current sea level pressure in hPa - so the value will be somewhere around ~1000. You can also test with the generic 1013.25 value.
Example Code
The following example code is part of the standard library. It illustrates how you can retrieve sensor data from the BMP388 for the temperature, pressure and approximate altitude:
/*************************************************************************** This is a library for the BMP3XX temperature & pressure sensor Designed specifically to work with the Adafruit BMP388 Breakout ----> http://www.adafruit.com/products/3966 These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried & Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution ***************************************************************************/ #include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include "Adafruit_BMP3XX.h" #define BMP_SCK 13 #define BMP_MISO 12 #define BMP_MOSI 11 #define BMP_CS 10 #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BMP3XX bmp; void setup() { Serial.begin(115200); while (!Serial); Serial.println("Adafruit BMP388 / BMP390 test"); if (!bmp.begin_I2C()) { // hardware I2C mode, can pass in address & alt Wire //if (! bmp.begin_SPI(BMP_CS)) { // hardware SPI mode //if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) { // software SPI mode 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 :("); 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); }
Page last edited January 22, 2025
Text editor powered by tinymce.