Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 8 months ago.
Error: Object of abstract class type "SDFileSystem" is not allowed in "main.cpp"
- include "mbed.h"
- include "SDFileSystem.h"
SDFileSystem sd(D11, D12, D13, PB_6, "sd"); MOSI, MISO, SCLK, SSEL
int main() { FILE *fp = fopen("/sd/mbed.txt", "w"); fprintf(fp, "Hello World!\n"); fclose(fp); }
Question relating to:
1 Answer
8 years, 8 months ago.
Re-import SDFileSystem, do not enable the 'update all sub libraries to latest version'. Then it shoudl work (or at least that fixed it in the past).
Yes,it's working. Now I'm looking to store the 3-axis sensor values with time stamp. 100 samples per second. But now it is not working.
- include "ADXL345_I2C.h"
- include "mbed.h"
- include "SDFileSystem.h"
ADXL345_I2C accelerometer(D14,D15); SDFileSystem sd(D11,D12,D13,PB_6, "sd"); MOSI, MISO, SCLK, SSEL DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
int main() { pc.baud(115200); printf("RTC example\n"); set_time(1387188323); Set RTC time to 16 December 2013 10:05:23 UTC printf("Date and time are set.\n"); int readings[3] = {0, 0, 0};
pc.printf("Starting ADXL345 test...\n"); wait(.001); pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); wait(.001);
These are here to test whether any of the initialization fails. It will print the failure if (accelerometer.setPowerControl(0x00)){ pc.printf("didn't intitialize power control\n"); return 0; } Full resolution, +/-16g, 4mg/LSB. wait(.001);
if(accelerometer.setDataFormatControl(0x0B)){ pc.printf("didn't set data format\n"); return 0; } wait(.001);
3.2kHz data rate. if(accelerometer.setDataRate(ADXL345_3200HZ)){ pc.printf("didn't set data rate\n"); return 0; } wait(.001);
Measurement mode.
if(accelerometer.setPowerControl(MeasurementMode)) { pc.printf("didn't set the power control to measurement\n"); return 0; }
while (1) {
accelerometer.getOutput(readings); time_t seconds = time(NULL);
printf("/r/n/nTime as seconds since January 1, 1970 = %d", seconds);
printf("/r/nTime as a basic string = %s", ctime(&seconds));
char buffer[32]; strftime(buffer, 32, "%I:%M:%S %p", localtime(&seconds)); printf(" Time = %s", buffer);
myled = !myled; pc.printf("\r\n%i, %i, %i", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
FILE *fp = fopen("/sd/PCE datalog.txt", "a");
fprintf(fp,"\r\n Accelerometer: X: %ig, Y: %ig, Z: %ig", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); fprintf(fp," Time = %s", buffer);
fclose(fp); wait(1);
wait(0.001); }
}
Can you find the mistake. thank you.
posted by 18 Aug 2015A seperate forum topic/question would be handier. Then also use <<code>> and <</code>>
around your code to make it readable. Finally give as much information as possible. Does it work if you just print to terminal? Does your SD card work if you just store a fixed string on it and nothing else?
I could print sensor values to SD card. I could see sensor values with time stamp on serial terminal ( tera term). But i could not print sensor values with time stamp on SD card
#include "ADXL345_I2C.h" #include "mbed.h" #include "SDFileSystem.h" ADXL345_I2C accelerometer(D14,D15); SDFileSystem sd(D11,D12,D13,PB_6, "sd"); // MOSI, MISO, SCLK, SSEL DigitalOut myled(LED1); Serial pc(USBTX, USBRX); int main() { pc.baud(115200); printf("RTC example\n"); set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC printf("Date and time are set.\n"); int readings[3] = {0, 0, 0}; pc.printf("Starting ADXL345 test...\n"); wait(.001); pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); wait(.001); // These are here to test whether any of the initialization fails. It will print the failure if (accelerometer.setPowerControl(0x00)){ pc.printf("didn't intitialize power control\n"); return 0; } //Full resolution, +/-16g, 4mg/LSB. wait(.001); if(accelerometer.setDataFormatControl(0x0B)){ pc.printf("didn't set data format\n"); return 0; } wait(.001); //3.2kHz data rate. if(accelerometer.setDataRate(ADXL345_3200HZ)){ pc.printf("didn't set data rate\n"); return 0; } wait(.001); //Measurement mode. if(accelerometer.setPowerControl(MeasurementMode)) { pc.printf("didn't set the power control to measurement\n"); return 0; } while (1) { accelerometer.getOutput(readings); time_t seconds = time(NULL); //printf("/r/n/nTime as seconds since January 1, 1970 = %d", seconds); // printf("/r/nTime as a basic string = %s", ctime(&seconds)); char buffer[32]; strftime(buffer, 32, "%I:%M:%S %p", localtime(&seconds)); printf(" Time = %s", buffer); myled = !myled; pc.printf("\r\n%i, %i, %i", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); FILE *fp = fopen("/sd/PCE datalog.txt", "a"); fprintf(fp,"\r\n Accelerometer: X: %ig, Y: %ig, Z: %ig", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); fprintf(fp," Time = %s", buffer); fclose(fp); //wait(1); wait(0.001); } }