Offline
Newbie
Karma: 0
Posts: 22
|
 |
« on: June 02, 2012, 11:39:25 pm » |
Hello!
I am having a bit of trouble lately logging accelerometer data on a microSD (2GB, FAT16). The reason is, to capture vibrations/impacts/movements, the accelerometer has to run at least at 50Hz in order to obtain a nice resolution. However, data is being logged at approximately 5-10Hz. I would appreciate any help or ideas on how to log data at higher rates.
Thank you.
|
|
|
|
|
Logged
|
|
|
|
|
SE USA
Offline
Faraday Member
Karma: 33
Posts: 3625
@ssh0le
|
 |
« Reply #1 on: June 02, 2012, 11:43:17 pm » |
code? Libraries used?
the SDFAT lib can get in the clock speed area of around 8Mhz, getting data logged at 5-10 Hz sounds like something else is up
|
|
|
|
|
Logged
|
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
|
 |
« Reply #2 on: June 02, 2012, 11:47:33 pm » |
the SDFAT lib can get in the clock speed area of around 8Mhz, getting data logged at 5-10 Hz sounds like something else is up
I'm using SD library, maybe there is something in the code... #include <SD.h> #include <Wire.h> #include <ADXL345.h>
const int chipSelect = 8; ADXL345 accel;
void setup() { Serial.begin(9600); Wire.begin(); accel = ADXL345(); pinMode(10, OUTPUT);
// Set the range of the accelerometer. accel.SetRange(16, true); accel.EnableMeasurements(); if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); return; } Serial.println("Card initialized."); //Write Log File Header File logFile = SD.open("ADXL345.txt", FILE_WRITE); if (logFile) { String header = "ADXL345 Initialized"; logFile.println(header); logFile.close(); Serial.println(header); } else { Serial.println("Couldn't open log file"); } }
void loop() { if(accel.IsConnected) // If we are connected to the accelerometer. { // AccelerometerRaw raw = accel.ReadRawAxis(); AccelerometerScaled scaled = accel.ReadScaledAxis();
File dataFile = SD.open("ADXL345.txt", FILE_WRITE);
// if the file is available, write to it: if (dataFile) { dataFile.print(scaled.XAxis); dataFile.print(","); dataFile.print(scaled.YAxis); dataFile.print(","); dataFile.println(scaled.ZAxis);
dataFile.close(); // print to the serial port too: Serial.print(scaled.XAxis); Serial.print(","); Serial.print(scaled.YAxis); Serial.print(","); Serial.println(scaled.ZAxis); } // if the file isn't open, pop up an error: else { Serial.println("Error opening file"); } } delay(10); }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #3 on: June 03, 2012, 12:36:36 am » |
Serial.begin(9600); ... // print to the serial port too: Serial.print(scaled.XAxis); Serial.print(","); Serial.print(scaled.YAxis); Serial.print(","); Serial.println(scaled.ZAxis); Say you are printing 10 characters, eg. 12,34,56\r\n At 9600 baud that will take 0.0104 seconds so you can only do 96 a second. Comment out the serial prints, or bump up your baud rate to 115200.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
|
 |
« Reply #4 on: June 03, 2012, 12:55:13 am » |
Serial.begin(9600); ... // print to the serial port too: Serial.print(scaled.XAxis); Serial.print(","); Serial.print(scaled.YAxis); Serial.print(","); Serial.println(scaled.ZAxis); Say you are printing 10 characters, eg. 12,34,56\r\n At 9600 baud that will take 0.0104 seconds so you can only do 96 a second. Comment out the serial prints, or bump up your baud rate to 115200. I tried doing that but it didn't work. Actually just a few moments ago I realized that it works better if I send a single string; therefore I have to send the data using a buffer. I also just tested this method and it gave much much better results (almost 100Hz). The only downside is that my raw accelerometer data is setup as floating point numbers, which cannot be send as strings (being read as "?"). I am trying to convert float to char at the moment, and hopefully that should solve the problem. Thanks for your tip!
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #5 on: June 03, 2012, 12:58:05 am » |
it gave much much better results (almost 100Hz)
96 Hz? Do what you did, and get rid of the serial prints.
|
|
|
|
|
Logged
|
|
|
|
|
Dubai, UAE
Offline
Edison Member
Karma: 20
Posts: 1627
|
 |
« Reply #6 on: June 03, 2012, 03:03:29 am » |
Hi, Its a while since I used the SD Library, but do you need to open the file everytime, can't you open it in setup and then just use it in loop ? i.e move this to setup - File dataFile = SD.open("ADXL345.txt", FILE_WRITE); Duane B rcarduino.blogspot.com
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #7 on: June 03, 2012, 03:19:15 am » |
How would you close the file before stopping/resetting the Arduino.
Brown out feature maybe ...
-Enjoy fh : )_~
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 28
Posts: 1079
Arduino rocks
|
 |
« Reply #8 on: June 03, 2012, 07:54:31 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
|
 |
« Reply #9 on: June 03, 2012, 06:42:11 pm » |
I solved the problem today, here are some factors which helped in speeding up the data logging process:
1. Wrote a single string at a time to SD card (most important) 2. Removed all "Serial.print" which were used for debugging 3. Removed any unnecessary variables and code (lowered sketch size)
Now I am logging data on the SD card at about ~10ms (~100Hz) which provides really nice resolution.
I also tried moving the file open command in the setup(), but that does not help as the file is being appended and has to be opened and closed within the loop.
Thank you everyone for your suggestions!
|
|
|
|
|
Logged
|
|
|
|
|
|