Teensy 2.0 logger with external flash W25Q64FV and "SerialFlash" library

Status
Not open for further replies.

moris

New member
Hi
I am working on a simple data loggers project and considering to use Teensy 2.0 (32u4 uP) with external flash W25Q64FV and using the "SerialFlash" library in Arduino IDE.
I am familiar with the limitation. Looking at the examples i can see file transfers but i do not see a Read/Write of single value. Will this library work to log single discrete values to the flash.
For example if i would like to transfer floating point 2.15 to a file "Data.bin" i would first open with "file = SerialFlash.open("Data.bin");" and then place the value in a single point array "buffer" and use "file.write(buffer, 256);".
Is this correct?
Is there an example code with "write" command for single floating or integer number for Arduino IDE ?
Thanks
 
write() just expects an address and number of bytes, a snippet to write floats might look like
Code:
...
  // check if this file is already on the Flash chip
  if (SerialFlash.exists(filename)) {
    Serial.println("-already exists on the Flash chip");
    Serial.println("-delete file from Flash chip");
    SerialFlash.remove(filename);
  }

  // create the file on the Flash chip and copy data
  if (SerialFlash.create(filename, 128)) {
    delay(2);
    SerialFlashFile ff = SerialFlash.open(filename);
    if (ff) {
      float x=3.7, y=-1.455;
      ff.write(&x,sizeof(x));
      ff.write(&y,sizeof(y));
      ff.close();
    } else {
      Serial.println("  error opening freshly created file!");
    }
  } else {
    Serial.println("  unable to create file");
  }
...

Careful, W25Q64FV is 3.3v device and Teensy 2 is 5v (unless you have modified it to run at 3v3). You'll need level shifters and 3v3 power source. Or better, use a Teensy 3* or LC
 
Last edited:
Thanks a lot for the prompt reply and easy to understand and use example.
As per your advice i would be using TXB0108PWR for level translating.
If i would like to extract and display all the floating point data from the file with the "Serial.print" and SerialFlash read command "file.read(buffer, 256);".: Will the numbers be displayed in hex/binary or human readable ASCII characters ?
If hex/binary can you point to an example of a converter?

Moris
 
If i would like to extract and display all the floating point data from the file with the "Serial.print" and SerialFlash read command "file.read(buffer, 256);"

That depends on the definition of "buffer". But usually buffer would be an array of byte, char or uint8_t.


Will the numbers be displayed in hex/binary or human readable ASCII characters ?

Again, that depends on what you do with "buffer". If it's of type "byte" and you use Serial.print() for each item, you'll end up with numbers from 0 to 255 printed for each individual byte.


If hex/binary can you point to an example of a converter?

How exactly you would convert the data also depends on how it was converted to bytes to be stored into the memory.

Can you see a "it depends" theme here? When questions are generic and lacking details, answers can only be fairly generic. Or we can make blind guesses about the data and try to help based on assumptions, but instead I'm going to suggest you provide more info. Or maybe show the Data.bin file (put it in a ZIP file to share here - use "Go Advanced" for the editor that lets you attach a file to your message).
 
Thanks Paul.
I was looking for a generic answer and the reply helps me a lot. I am still in evaluation phase of the project and comparing the different external SPI flash libraries and found "SerialFlash" because of it small footprint combined with file alike interface is best choice for uP with small flash space as Teensy 2.0.
There will be a set of 5 data-loggers based on Teensy 2.0 that will record 1 time per hour data coming from a single sensor. The data will be coming through Rx/Tx (Serial1) as a floating point in ASCII and i would like to keep it this way if possible. There is a lot more memory space that i will need so no need to use binary. There will be 1 file only per flash and my intention is to make this file as big as the flash size.
I would like to record the data with a "write" command" and 1.5 years later to connect with a PC to the datalogger using Arduino Serial Monitor (or putty) and use SerialFlash read file command to extract the data and save to the PC.
From your answer i assume if i declare the buffer as "char" type for both writ and read then the data will saved and extracted as ASCII.
Is this correct?

Moris
 
Status
Not open for further replies.
Back
Top