Hello everyone,
This is my first post here so hopefully I've followed all the rules. I'm building an ROV for fun and am trying to send serial data from a MPU6050 and a 30 Bar pressure sensor from Blue Robotics from my Uno to Processing IDE. I'm also still relatively new to all of this so if I'm all screwed up here, take it easy on me.
To the issue: I've written sketches for both of these sensors including the multiplexer that work nicely, all of the values I want are being generated and I've confirmed I can get the data in Processing just fine. The problem is when I have to sensors connected to the multiplexer, only the second one generates reliable data. Whatever sensor is connected to the first port of the multiplexer either creates wild values (e.g. pitch or roll of 100000 degrees), or doesn't respond at all to the sketch. I've tried switching the two sensors to different pairs of SDA or SCL on the multiplexer and every time its the second sensor I get good data from.
I've done a lot of trouble shooting on this and I'm very sure its multiplexer, how can I get data from both sensors at the same time? My Arduino sketch is below, thanks for the help!
#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(57600);
Wire.begin();
PCA9548A(1);
ms5837.init();
delay(5000);
ms5837.setModel(MS5837::MS5837_30BA);
ms5837.setFluidDensity(1029); // kg/m^3 (997 is freshwater, 1029 for seawater)
PCA9548A(2);
byte status = mpu.begin();
// mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
mpu.calcOffsets();
}
void loop() {
ms5837.read();
int humidity = dht11.readHumidity();
mpu.update();
if((millis()-timer)>1000){ // print data every 10ms
Serial.print(mpu.getAngleX());
Serial.print("\t");
Serial.print(mpu.getAngleY());
Serial.print("\t");
Serial.print(mpu.getAngleZ());
Serial.print("\t");
Serial.print(humidity);
Serial.print("\t");
Serial.print(ms5837.depth());
Serial.print("\t");
Serial.print(ms5837.pressure());
Serial.print("\t");
Serial.print(ms5837.temperature());
Serial.print("\t");
Serial.println(ms5837.altitude());
timer = millis();
delay(1000);
}
}