Hi everyone,
I recently purchased a 30Bar pressure sensor and am trying to get it to work in combination with a DHT11 sensor and an MPU6050 on an Arduino Uno. I’m using an I2C multiplexer, specifically a PCA9548A for serial communication. The SDA and SCL for both the 30Bar pressure sensor and the MPU6050 are connected to the multiplexer which is connected to A4 and A5 on my arduino.
I want to run these three sensors at once and send the data to processing IDE. I wrote an arduino sketch for each to collect basic data. All the sensors work fine independently, I tried merging them and my 30Bar is reading really crazy values. After some trial and error I think it has something to do with the MPU6050. If I run a sketch for the MPU6050 alone through the multiplexer it works fine, same with the 30Bar, when connecting through the multiplexer alone it works fine.
If I merge the DHT11 sketch with the 30Bar sketch, both work fine, when I add the MPU6050 sketch to that I get crazy numbers, just for the pressure sensor. I made sure to set the model as a MS5837_30BA, I don’t get any errors when I run the sketch, which is below btw. Thanks!
#include <Wire.h>
#include <MS5837.h>
#include <MPU6050_light.h>
#include <DHT11.h>
MPU6050 mpu(Wire);
MS5837 ms5837;
unsigned long timer = 0;
DHT11 dht11(3);
void PCA9548A(uint8_t bus) {
Wire.beginTransmission(0x70);
Wire.write(1<<bus);
Wire.endTransmission();
Serial.print(bus);
}
void setup() {
Serial.begin(9600);
Serial.println("Starting");
Wire.begin();
ms5837.setModel(MS5837::MS5837_30BA);
ms5837.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
PCA9548A(2);
while (!ms5837.init()) {
Serial.println("Init failed!");
Serial.println("Are SDA/SCL connected correctly?");
Serial.println("Blue Robotics Bar30: White=SDA, Green=SCL");
Serial.println("\n\n\n");
delay(5000);
}
PCA9548A(3);
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ }
Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(1000);
// mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
mpu.calcOffsets();
Serial.println("Done!\n");
}
void loop() {
ms5837.read();
Serial.print("Pressure: ");
Serial.print(ms5837.pressure());
Serial.println(" mbar");
Serial.print("Temperature: ");
Serial.print(ms5837.temperature());
Serial.println(" deg C");
Serial.print("Depth: ");
Serial.print(ms5837.depth());
Serial.println(" m");
Serial.print("Altitude: ");
Serial.print(ms5837.altitude());
Serial.println(" m above mean sea level");
delay(1000);
mpu.update();
if((millis()-timer)>10){ // print data every 10ms
Serial.print("X : ");
Serial.print(mpu.getAngleX());
Serial.print("\tY : ");
Serial.print(mpu.getAngleY());
Serial.print("\tZ : ");
Serial.println(mpu.getAngleZ());
timer = millis();
}
int humidity = dht11.readHumidity();
if (humidity != DHT11::ERROR_CHECKSUM && humidity != DHT11::ERROR_TIMEOUT) {
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
}