Help: How do I set the sample frequency for ADXL345

Hello all, I am trying to monitor vibration from the accelerometer(ADXL345) of all 3-axis.

I am using the ADXL345 for vibration trending.Accelerometer ADXL345
I am using the Arduino Uno R3 as a microcontroller. Arduino Uno Board R3
Logging and send data via the wifi and sd storage on the Arduino Wifi Shield.

I have a motor running at 50Hz.. By Nyquist theory i will need at lesat x2 times more. So I want to set it at x5 times, which means i will be logging at the frequency of 250Hz, the time period would then be 0.004 per cycle. Is my understanding correct?

Next, how can I set the number of readings save onto the sd card? The number of readings i get for the code i used is very different for each time.

For x and y axis at
10v i got 655 readings
15v i got 658 readings
20v i got 755 readings
25v i got 692 readings
30v i got 656 readings

For z axis it goes up to 2000++ readings

You are doing quite a lot of activity in regAddress() which is probably slowing down your sample rate.

Start be commenting out the Serial.print & Serial.println statements to see if that makes a difference.

Then check if it is necessary to open/close the SD card on each iteration or can , for example, the open operation be done once in the setup() and the close operation right at the end.

6v6gt:
You are doing quite a lot of activity in regAddress() which is probably slowing down your sample rate.

Start be commenting out the Serial.print & Serial.println statements to see if that makes a difference.

Then check if it is necessary to open/close the SD card on each iteration or can , for example, the open operation be done once in the setup() and the close operation right at the end.

Ok, i have done commenting out some of the Serial.print & Serial.println

I noticed when my iteration(2500) finishes, the sd card is still logging data. Is it because it is too fast, that the SD card cannot keep up ? So if i wait, i will eventually get 2500 readings on the sd card ?

How long did it take to run through 2500 iterations ?
You could find out by doing something like this:

void loop() {
if (runComplete == 0){
  Serial.println( millis() ) ;
  for (i=0; i<2501; i=i+1){
  Serial.print("Number of iteration(seconds) = "); Serial.print(i);
  regAddress();
     delay(4);
   }
  Serial.println( millis() ) ;
  runComplete = 1;
  }
}

You may have to find a method of writing to the SD card which does not involve an open and close operation for every one of the 2500 items of data. May be you should use an array or look here for some tricks: Writting an array to the SD card without looping through it - Storage - Arduino Forum

wow.. it works by commenting out some Serial.print lines.

it takes around 5mins to run 2500 iteration..

If i want to decrease the time, I just have to decrease my delay more? what is the smallest I can go? Right now is 4 ms..

do you know why it take 5mins? I mean, 2500 iteration * 0.004s delay per reading = 10 s ?