Arduino Nano and two acceleration sensors

Hi, I have two acceleration sensors (ADXL345) connected to Arduino UNO and everything works fine. I am thinking about of buying Arduino Nano so that I could send the acceleration data wirelessly to my laptop (either using wifi or bluetooth, which one should I use?). So I am asking if it is possible to connect these two acceleration sensors to Arduino Nano? Here is my wiring diagram used on Arduino UNO and the code to read the data. It has been few years since I played with these things so any help is appreciated!

code to read acceleration data:

#include<Wire.h>// Wire.h library is used for the I2C communication.

// set I2C addresses for ADXL345 sensors 
#define accel_module (0x1d)         // SDO-> Vcc
#define accel_module2 (0x53)       // SDO-> GND

int output[3];
int output2[3];
byte values[6];
int grange;
int samplingRate;

void setSampligRate(int accelSensor, int samplingRate)
{ 
  Wire.beginTransmission(accelSensor); // Start communicating with the device
  Wire.write(0x2C); // Access to Register 0x2C—BW_RATE (Read/Write)
  Wire.write(10);  
  Wire.endTransmission();
  switch(samplingRate){
    case(1600): // 1600hz setting  0000 1110
      Wire.beginTransmission(accelSensor); // Start communicating with the device
      Wire.write(0x2C); // Access to Register 0x2C—BW_RATE (Read/Write)
      Wire.write(14); //(14dec = 1110 binary)
      Wire.endTransmission();
      break;
    case(800): 
      Wire.beginTransmission(accelSensor); 
      Wire.write(0x2C); 
      Wire.write(13); 
      Wire.endTransmission();
      //Serial.println("set sr 800hz");
      break;
    case(400): // 400hz setting  0000 1100
      Wire.beginTransmission(accelSensor); 
      Wire.write(0x2C); 
      Wire.write(12); 
      Wire.endTransmission();
      break;
    case(200): // 400hz setting  0000 1011
      Wire.beginTransmission(accelSensor); 
      Wire.write(0x2C); 
      Wire.write(11);
      Wire.endTransmission();
      break;
  }

}
void setRange(int accelSensor, int grange)
{ 
  Wire.beginTransmission(accelSensor); // Start communicating with the device
  Wire.write(0x31); // Access to DATA_FORMAT register - 0x31
  Wire.write(0); //reset register
  Wire.endTransmission();
  switch(grange){
    case(2): 
      // when both D1 and D2 are zeros we have 2g setting 
      // 0000 0000
      break;
    case(4):
      //4g setting 0000 0001
      Wire.beginTransmission(accelSensor); // Start communicating with the device
      Wire.write(0x31); // Access to DATA_FORMAT register - 0x31
      Wire.write(1); //set D0 to 1:  (2dec -> 0000 0001 binary) 
      Wire.endTransmission();
      break;
    case(8):
      ////8g setting 0000 0010
      Wire.beginTransmission(accelSensor);
      Wire.write(0x31); 
      Wire.write(2);
      Wire.endTransmission();
      break;
    case(16):
      ////16g setting 0000 0011
      Wire.beginTransmission(accelSensor);
      Wire.write(0x31); 
      Wire.write(3); 
      Wire.endTransmission();
      break;
  }

}

void getAccelration(int accelSensor, int out[])
{
  int xyzregister = 0x32;//specify the first data register. This address is given in the datasheet.
  
// === Read acceleromter data === //
  Wire.beginTransmission(accelSensor);
  Wire.write(xyzregister);// Start with register 0x32 
  Wire.endTransmission();

  Wire.beginTransmission(accelSensor);
  Wire.requestFrom(accelSensor, 6);//Read 6 registers total, each axis value is stored in 2 registers
  int i = 0;
  while(Wire.available())
  {
    values[i] = Wire.read();//store data from the register
    i++;
    }
  Wire.endTransmission();
  out[0] = (((int)values[1]) << 8) | values[0];
  out[1] = (((int)values[3])<< 8) | values[2];
  out[2] = (((int)values[5]) << 8) | values[4];
}

void turnOnAccelSensor(int accelSensor)
{ Wire.beginTransmission( accelSensor); // Start communicating with the device
  Wire.write(0x2D); // Access to power control register - 0x2D
  Wire.write(0); //clear register
  Wire.endTransmission();
  
  Wire.beginTransmission( accelSensor);
  Wire.write(0x2D);
  Wire.write(8); //  Enable measurement mode by setting Bit D3 High (8dec -> 0000 1000 binary) 
  Wire.endTransmission();
}


char data [23];//acceleration data is transmitted as a string
void loop()
{   
    // // read acceleration data
    getAccelration(accel_module, output); // ********accel 0x1D*********//
    getAccelration(accel_module2, output2); // ********accel 0x1D*********//
    sprintf(data,"%d %d %d %d %d %d %d",output[0], output[1], output[2], output2[0], output2[1], output2[2]);
    Serial.println(data);
}

Which model? There are so many Arduino boards called Nano these days, it makes your head spin. Some do not have WiFi or BT. The ones that do are 3.3V devices, so you would no longer need your level converter.

I don't see why any Nano would not work with 2x sensors in the same way that Uno does.

Hi, thanks for the response. I do not have specific Nano model in mind. Which one would you recommend? I am trying to read the data in real time so maybe model with Wifi if better for that?

What do you plan to do with the data when it is received by your laptop?

How fast will the data arrive? How many samples power second?

Actually, I dont have to read the data in real time. I am recording the acceleration data at 400hz and the recording duration is around 5min, so maybe I can store the data on the Arduino nano and then after the recording is done, sent it to the laptop?

Ok, let's do some maths.

400Hz x 5 mins = 120K samples

If each sample is 6 values, 4 bytes per value, that's ~3MB

If it can be squeezed down to 2 bytes per value, it's still around 1.5MB.

I don't think any Nano model has enough RAM memory to hold that. So it will need to be stored, ready to be transmitted.

If you use the Flash memory of an Arduino, remember that Flash memory can only be re-written maybe 10,000 times before it fails.

I see. I did not know that Flash memory will fail that quickly. The data needs to be sampled at least 200hz. So maybe I can read this to RAM and concurrently send the data to laptop? I guess, I need a model which has the largest RAM to act as a buffer. Furthermore is it possible to power the Arduino nano via rechargeable battery ?

There you go again taking like there is only one type of Arduino Nano!

Some Nano can be powered by a li-po battery or li-ion cell, yes. Those batteries/cells are available in a wide range of sizes and capacities. However, even though some Nano models are 3.3V, they need a 5V supply, so avoid those.

With so much data to be captured, maybe something with lots of RAM would be best, like a Raspberry Pi of some kind.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.