Hi I'm fairly new to Adafruit and Arduino.
I have connected 3 MMA8451 accelerometers to an Arduino Uno by way of a TCA9548A I2C Multiplexer.
my readings come out as follows:
20:26:07.359 -> Sensor Back Black 7 - X: -0.91 Y: -8.6 Z: 4.85
20:26:07.852 -> Sensor Left Blue 2 - X: -3.71 Y: -5.46 Z: -7.15
20:26:07.852 -> Sensor Right Green 4 - X: 4 Y: -5.95 Z: -6.48
I want to measure quick moments using the Left and Right sensors. I was hoping to remove the unwanted movement readings by deducting the back sensor from the front two. Essentially my project is detecting short movement bursts on the front of a cylinder. This cylinder moves on its own which is why I wanted to have a 3rd sensor to remove this noisy movement.
But the readings of the back sensor and the left and right sensors do not match. So I can’t just subtract the noisy movement.
Is there a way to get all 3 sensors to read at once? They are milliseconds apart but I'm guessing that is part of my issue.
I don’t understand why all 3 are not moving in the same noisy way so I can remove this noise and focus on the short movement bursts.
Would increasing the readings from 9600 to 100000 help? I'm not totally sure what this does but it seems to increase the readings
Or is my approach totally wrong? My accelerometers can detect the short movement bursts but I can’t figure out how to get rid of the noise.
Thank you so much for your help! my code is below which was adapted from someone else using magnetometers so some of the comments are not applicable :
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MMA8451.h>
#define TCAADDR 0x70
/* Assign a unique ID to this sensor at the same time */
Adafruit_MMA8451 mma = Adafruit_MMA8451();
Adafruit_MMA8451 mma1 = Adafruit_MMA8451();
Adafruit_MMA8451 mma2 = Adafruit_MMA8451();
Adafruit_MMA8451 mma3 = Adafruit_MMA8451();
void displaySensorDetails(Adafruit_MMA8451 *mag)
{
sensor_t sensor;
mag->getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" uT");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" uT");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" uT");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Serial.begin(1000000);
Serial.println("MMA8451 Magnetometer Test"); Serial.println("");
/* Initialise the 1st sensor /
Wire.begin();
tcaselect(2);
delay(1000);
if(! mma1.begin())
{
/ There was a problem detecting the HMC5883 ... check your connections */
Serial.println("XXXXXXX no MMA8451 detected ... Check your wiring!");
while(1);
}
/* Initialise the 2nd sensor /
Wire.begin();
tcaselect(2);
if(!mma.begin())
{
/ There was a problem detecting the MMA8451... check your connections */
Serial.println("RRRRRR, no MMA8451 detected ... Check your wiring!");
while(1);
}
/* Initialise the 2nd sensor /
Wire.begin();
tcaselect(4);
if(!mma2.begin())
{
/ There was a problem detecting the MMA8451... check your connections */
Serial.println("RRRRRR, no MMA8451 detected ... Check your wiring!");
while(1);
}
/* Initialise the 2nd sensor /
Wire.begin();
tcaselect(7);
if(!mma3.begin())
{
/ There was a problem detecting the MMA8451... check your connections */
Serial.println("RRRRRR, no MMA8451 detected ... Check your wiring!");
while(1);
}
/* Display some basic information on this sensor */
Serial.println("We got to stage 2");
tcaselect(2);
displaySensorDetails(&mma1);
tcaselect(4);
displaySensorDetails(&mma2);
tcaselect(6);
displaySensorDetails(&mma3);
Serial.println("We got to the end of the setup!");
}
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
tcaselect(2);
mma.getEvent(&event);
Serial.print("Sensor Left Blue 2 - \t");
Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");
tcaselect(4);
mma2.getEvent(&event);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("Sensor Right Green 4 - \t");
Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");
tcaselect(7);
mma3.getEvent(&event);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("Sensor Back Black 7 - \t");
Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");
delay(500);
}