So I have two pressure sensors that I need for my projects to work together, the HK1100C is submerged in a tank to get the pressure of the water and the BMP 180 is for the atmospheric pressure, but when I try and use the serial monitor to check if they are reading correctly together, the serial monitor freezes with no display.
The code works for each sensor individually, but I can't get my Arduino to read both at the same time. I am using a Mega if it helps, and the HK1100C is reading off pin A4 and the BMP is using the SDA and SCL pins just like in the example that Sparkfun provides.
Any ideas on how to fix this?
// Your sketch must #include this library, and the Wire library.
// (Wire is a standard library included with Arduino.):
#include <SFE_BMP180.h>
#include <Wire.h>
// You will need to create an SFE_BMP180 object, here called "pressure":
SFE_BMP180 pressure;
void setup()
{
Serial.begin(9600);
if (pressure.begin())
Serial.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.
Serial.println("BMP180 init fail\n\n");
while (1); // Pause forever.
}
}
void loop()
{
char status;
double T, P, p0, a;
status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure.getTemperature(T);
if (status != 0)
{
// Print out the measurement:
Serial.print("temperature: ");
Serial.print(T, 2);
Serial.println(" deg C, ");
status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure.getPressure(P, T);
if (status != 0)
{
// Print out the measurement:
Serial.print("absolute pressure: ");
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
P = P / 10;
Serial.print(P);
Serial.println(" kPa");
Serial.print("gauge pressure: ");
int sensorValue = analogRead(A4);
Serial.print(sensorValue);
Serial.println(" units");
delay(1000); // Pause for 5 seconds.
}