Hi,
I'm currently working on a project where I should use multiple ADXL335 sensors (8 total), since the arduino mega 2560 only have 16 analog pins which allow me to add 5 sensors, I brought an extra board so I can add twice the amount of sensors.
I'm not aware how I can get the two boards to communicate, so the sensors (accelerometers) record at the same time with the same sample frequency.
I have uploaded the code for 4 sensors working on one arduino board, pls help with the connection.
#include <math.h>
const int x_out = A0; /* connect x_out of module to A1 */
const int y_out = A1; /* connect y_out of module to A2 */
const int z_out = A2; /* connect z_out of module to A3 */
// Calibration variables
const double x_offset = 0.8790; /* Fill in the x-axis offset value */
const double y_offset = 0.8642; /* Fill in the y-axis offset value */
const double z_offset = 0.2975; /* Fill in the z-axis offset value */
// Take multiple samples to reduce noise
const int sampleSize = 10;
void setup() {
Serial.begin(115200);
}
void loop() {
int x_raw, y_raw, z_raw;
double x_accel, y_accel, z_accel;
x_raw = analogRead(x_out); /* Digital value of voltage on x_out pin */
y_raw = analogRead(y_out); /* Digital value of voltage on y_out pin */
z_raw = analogRead(z_out); /* Digital value of voltage on z_out pin */
x_accel = ((((double)(x_raw * 5) / 1024) - 1.08) / 0.660) - x_offset ; /* Acceleration in x-direction in m/s^2 */
y_accel = ((((double)(y_raw * 5) / 1024) - 1.08) / 0.660) - y_offset ; /* Acceleration in y-direction in m/s^2 */
z_accel = ((((double)(z_raw * 5) / 1024) - 1.83) / 0.660) - z_offset ; /* Acceleration in z-direction in m/s^2 */
Serial.print("x = ");
Serial.print(x_accel, 4); /* Display with 4 decimal places */
Serial.print("G");
Serial.print(", y = ");
Serial.print(y_accel, 4); /* Display with 4 decimal places */
Serial.print("G");
Serial.print(", z = ");
Serial.print(z_accel, 4); /* Display with 4 decimal places */
Serial.print("G");
Serial.println();
delay(100);
}
// Take samples and return the average
int ReadAxis(int axisPin)
{
long reading = 0;
analogRead(axisPin);
delay(1);
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(axisPin);
}
return reading/sampleSize;
}

