Bill Greiman
Well-known member
I just posted a new version of SdFat on GitHub https://github.com/greiman/SdFat/.
This version has a Teensy 3 SPI fix that Paul sent. It also has many other changes and several new examples.
I have only tested a few examples on Teensy 3. Various versions of the Teensy software fail in different ways with my use of USB Serial input. I don't have the patience to fight this problem.
Teensy 1.20RC2 seems to work somewhat.
Try the LowLatencyLogger example, it uses one of the new features. It is easily modifiable and does not use an RTOS or tricky ISR. I was able to log four analog pins on a Teensy 3.0 at 2500 Hz. I used a low cost class 4 SanDisk card.
Here is a bit of the output with floating pins. The first column is the time in microseconds.
Here are the functions you need to modify for you needs.
This version has a Teensy 3 SPI fix that Paul sent. It also has many other changes and several new examples.
I have only tested a few examples on Teensy 3. Various versions of the Teensy software fail in different ways with my use of USB Serial input. I don't have the patience to fight this problem.
Teensy 1.20RC2 seems to work somewhat.
Try the LowLatencyLogger example, it uses one of the new features. It is easily modifiable and does not use an RTOS or tricky ISR. I was able to log four analog pins on a Teensy 3.0 at 2500 Hz. I used a low cost class 4 SanDisk card.
type:
c - convert file to CSV
d - dump data to Serial
e - overrun error details
r - record data
Creating new file
Erasing all data
Logging - type any character to stop
Truncating file
File renamed: DATA08.BIN
Max block write usec: 203
Record time sec: 166.286
Sample count: 415716
Samples/sec: 2500.01
Overruns: 0
Here is a bit of the output with floating pins. The first column is the time in microseconds.
time,adc0,adc1,adc2,adc3
6714002,247,180,139,78
6714401,125,109,89,68
6714802,147,140,180,110
6715201,109,219,46,74
6715602,154,78,11,130
6716002,50,96,128,154
6716401,245,224,116,119
6716801,171,166,116,100
6717201,145,120,116,106
6717601,253,136,124,87
Here are the functions you need to modify for you needs.
Code:
const uint8_t ADC_DIM = 4;
struct data_t {
unsigned long time;
unsigned short adc[ADC_DIM];
};
// Acquire a data record.
void acquireData(data_t* data) {
data->time = micros();
for (int i = 0; i < ADC_DIM; i++) {
data->adc[i] = analogRead(i);
}
}
// Print a data record.
void printData(Print* pr, data_t* data) {
pr->print(data->time);
for (int i = 0; i < ADC_DIM; i++) {
pr->write(',');
pr->print(data->adc[i]);
}
pr->println();
}
// Print data header.
void printHeader(Print* pr) {
pr->print(F("time"));
for (int i = 0; i < ADC_DIM; i++) {
pr->print(F(",adc"));
pr->print(i);
}
pr->println();
}