Hi guys, thanks for all your great inputs.
@ groundFungus : You are right, it's better for everyone. I also simplify the codes so that only the data logging part are shown, everything else doesn't matter for now.
@ hzrnbgy : I didn't took that into account while buying the FRAM module, should have taken the SPI one.
@ david_2018: 33'000 addresses....yeah should have known better. Why should I use unsigned long instead of int ? I estimate that it should take less than 32'767 milliseconds that's why I chose int. Is it false to int it that example?
I did the test again, using the codes below, and still found a large difference. I'm saving 20Bytes in each test.
Code used with the SD card, arduino pro mini. I'm using struct because it's the fastest way I've found to save different types of data. For this example, I'm only saving int, but I might have to save floats or longs.
#include <SPI.h>
#include "SdFat.h"
SdFat SD;
const int chipSelect = 8;
File dataFile;
struct datastore {
int variable1;
int variable2;
int variable3;
int variable4;
int variable5;
int variable6;
int variable7;
int variable8;
int variable9;
int variable10;
}; // 10*2bytes = 20bytes
unsigned long millis_at_Start;
unsigned long total_Time;
void setup() {
Serial.begin(9600);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
dataFile = SD.open("log.txt", FILE_WRITE);
// Start timer;
millis_at_Start = millis();
// Save 20Bytes as fast as possible, 20bytes * 1000 = 20Kbytes
for (int counter = 0; counter < 1000; counter++) {
struct datastore myData;
myData.variable1 = myData.variable2 = myData.variable3 = myData.variable4 = myData.variable5 = myData.variable6 = myData.variable7 = myData.variable8 = myData.variable9 = myData.variable10 = 42;
dataFile.write((const uint8_t *)&myData, sizeof(myData));
}
// Print time is took to save 20Kbytes
dataFile.close();
total_Time = millis() - millis_at_Start;
Serial.print("Total time to save 20Bytes : ");
Serial.print(total_Time);
Serial.print(" ms");
}
void loop() {
}
Code used with the FRAM module, arduino pro mini.
#include <Wire.h>
#include "Adafruit_FRAM_I2C.h"
Adafruit_FRAM_I2C fram = Adafruit_FRAM_I2C();
uint16_t framAddr = 0;
int long x = 0;
uint16_t address;
unsigned long millis_at_Start;
unsigned long total_Time;
void setup(void) {
Serial.begin(9600);
Serial.println("");
Wire.begin();
Wire.setClock(400000);
fram.begin(0x50);
// Start timer
millis_at_Start = millis();
// Save 20Kbytes as fast as possible
for (address = 0; address < 20000; address++) { //write a number into the fram
fram.write8(address, 42);
}
// Print time is took to save 20Kytes
total_Time = millis() - millis_at_Start;
Serial.print("Total time to save 20Bytes : ");
Serial.print(total_Time);
Serial.print(" ms");
}
void loop() {
}
There is still a massive difference between the two tests, I'm get 149ms for the SD card test and 8481ms for the FRAM.
- Considering that I2C is 400Khz, why does it takes so long ? I'm saving 20Kbytes at max 400Kbytes, so quick math (there are certainly a lot of things I still do not understand) would give about 50ms to store 20Kbytes. Why does it takes over 150 times longer ?
- Is there a faster library ? Or a faster way to store data on a fram ?
- I have not seen a difference, in using wire.setClock(400000) or not ,which might indicate that the FRAM module itself is the limiting part regading data logging speed, am I right ?
Thanks again for your help.