I am new to Arduino, but I wanted to know if it would be possible to connect an MPU6050, MSA301 accelerometer, and OLED to one Arduino. I originally wanted to connect two MSA301 sensors and one OLED screen to one Arduino, but that didn't work because they had the same fixed I2C address. Is it possible to use an MPU6050 sensor instead and display just the acceleration reading on the OLED screen under the acceleration reading for the MSA301? The code below is what I have so far (I have not yet gotten the MPU6050). I'm asking this because the two sensors have different resolutions (14 bit and 16 bit ADC), and I'm not sure if they can be used together.
// 2 accelerometers on one OLED display
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_MSA301.h>
#include <Adafruit_Sensor.h>
Adafruit_MSA301 msa;
Adafruit_MPU6050 mpu;
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
void setup(void) {
Serial.begin(115200);
Serial.println("Adafruit MSA301 demo");
// Try to initialize!
if (! msa.begin()) {
Serial.println("Failed to find first accelerometer ");
while (1) { delay(10); }
}
Serial.println("MSA301 Found!");
Serial.begin(115200);
Serial.println("MPU6050 OLED demo");
if (!mpu.begin()) {
Serial.println("Failed to find second accelerometer");
while (1)
yield();
}
Serial.println("Found a MPU-6050 sensor");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(500); // Pause for 2 seconds
display.setTextSize(1);
display.setTextColor(WHITE);
display.setRotation(0);
}
void loop() {
sensors_event_t event;
msa.getEvent(&event);
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
display.clearDisplay();
display.setTextSize(1);
/* Display the results (acceleration is measured in m/s^2) */
Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
Serial.print(" \tY: "); Serial.print(event.acceleration.y);
Serial.print(" \tZ: "); Serial.print(event.acceleration.z);
Serial.println(" m/s^2 ");
display.setCursor(0,0);
display.print("("); display.print(event.acceleration.x*.10197); display.print(", ");
display.print(event.acceleration.y*.10197); display.print(", ");
display.print(event.acceleration.z*.10197); display.print(")");
Serial.print("Accelerometer ");
Serial.print("X: ");
Serial.print(a.acceleration.x, 1);
Serial.print(" m/s^2, ");
Serial.print("Y: ");
Serial.print(a.acceleration.y, 1);
Serial.print(" m/s^2, ");
Serial.print("Z: ");
Serial.print(a.acceleration.z, 1);
Serial.println(" m/s^2");
display.setCursor(0,8);
display.print("("); display.print(a.acceleration.x*.10197);
display.print(", ");
display.print(a.acceleration.y*.10197);
display.print(", ");
display.print(a.acceleration.z*.10197);
display.print(")");
display.display();
delay(100);
}
I also want the reading to be displayed in g, so that's why I converted it.