Writing csv formant to SD card on esp8266

It seems that the lib for SD card for 8266 and 32 are not competable....not even SPI lib...
and 8266 lib can't assign frequency like in esp32...then it could trouble some to get the spi lib to work with other spi device...may not...if we can setup frequency every time before we write. this could be wrong info from google, there is boolean SDClass::begin(uint8_t csPin, uint32_t speed)
with the demo of D1 mini of cd card:
https://github.com/wemos/D1_mini_Examples/blob/master/examples/04.Shields/Micro_SD_Shield/Datalogger/Datalogger.ino and others...
the pin connection is as following:

* The WeMos Micro SD Shield uses:
* D5, D6, D7, D8, 3V3 and G
*
* The shield uses SPI bus pins:
* D5 = CLK
* D6 = MISO
* D7 = MOSI
* D8 = CS
*
* The SD card library uses 8.3 format filenames and is case-insensitive.

I first test with cardinfo, and then read and write to make sure that wiring is correct.

I wish to make few functions in the web server, such as:
1. get file list, kind of dir
2. delete file(serve to delete old file.)
3. create a file name associated with device_ID
4. write in gps info as csv


1. List Dir:

2. remove a file: 
there is a function like this: boolean SDClass::remove(const char *filepath)
I'm about to remove a file, but bot able to list dir again:


Serial.println("initialization done.");
  root = SD.open("/");
  printDirectory(root, 0);
  Serial.println("done!");
  SD.remove("test.txt");
  Serial.println("remove test.txt");
  root = SD.open("/");
 printDirectory(root, 0);


3. the idea is to create a file name for logging data, which has a file name associated to device ID, and with a sequence on the end.
that means you need to know what is the latest file sequence, then you can add one on it. and it should have space to place the sequence. let say 2 digits...
TBD....

4. this is quite easy with the help of String object, I did it like this...kind of stupid...but work fine....

String newline ="";
newline +=device_ID;
newline +=",";
newline +=String(u_Lat.Lat,5);
newline +=",";
newline +=String(u_Lon.Lon,6);
newline +=",";
newline +=String(knot,1);
newline +=",";
newline +=String(bcourse,1);

.
.
return newline
and myFile.println(form_string()); will perform the latest /r/n
and the read write shows correct result....
Need to pay attention that in ESP8266, write() is equal to append() function....

留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

AIS0. understanding AIS NMEA 0183: How it's coded