I have the Sparkfun pressure sensor BMP384 and I’ve connected it to my arduino uno. I’m using the “Example1_BasicReadingsI2C” example file with some edits and it’s giving me the error -1. What does that error mean, and how can I fix it? Here’s the code I’m using:
#include <Wire.h>
#include "SparkFunBMP384.h"
// Create a new sensor object
BMP384 pressureSensor;
// I2C address selection
uint8_t i2cAddress = BMP384_I2C_ADDRESS_DEFAULT; // 0x77
// uint8_t i2cAddress = BMP384_I2C_ADDRESS_SECONDARY; // 0x76
void setup()
{
// Start serial
Serial.begin(9600);
Serial.println("BMP384 Example1 begin!");
// Initialize the I2C library
Wire.begin();
// Check if sensor is connected and initialize
// Address is optional (defaults to 0x77)
// while(pressureSensor.beginI2C(i2cAddress) != BMP3_OK)
// {
// // Not connected, inform user
// Serial.println("Error: BMP384 not connected, check wiring and I2C address!");
//
// // Wait a bit to see if connection is established
// delay(1000);
// }
Serial.println("BMP384 connected!");
}
void loop()
{
// Get measurements from the sensor
bmp3_data data;
int8_t err = pressureSensor.getSensorData(&data);
// Check whether data was acquired successfully
if(err == BMP3_OK)
// while()
{
// Acquisistion succeeded, print temperature and pressure
Serial.print("Temperature (C): ");
Serial.print(data.temperature);
Serial.print("\t\t");
Serial.print("Pressure (Pa): ");
Serial.println(data.pressure);
}
else
{
// Acquisition failed, most likely a communication error (code -2)
Serial.print("Error getting data from sensor! Error code: ");
Serial.println(err);
}
// Only print every second
delay(1000);
}