Excellent. Thank you for the video, well explained. Question? If I was storing a large amount of data, say a data logger (Date\Time and Sample). EG 2023-10-28T23:00:00 100.1 And this was 1000s of sample values. How can I loop each line fast and read that line based on a index or line number on the file. That is not read the whole file and then loop, but somehow read a line directed on the SD card and return only that line. This way I don't have to store something that could be 4GB in size. EG - read line 10,009 and get what this line is?
I guess there are a couple of routes. I have seen some SD card libraries that seem to allow random access to files. Have a look at mySD - github.com/nhatuan84/esp32-micro-sdcard/tree/master The other option is to break the data stream up into manageable chunks e.g. 100 samples per file and then save these with numeric file names, e.g. 1.txt, 2.txt. You'll then be able to pick out a block of 100 samples by filename. You might have to be careful about the number of files allowed in any folder, especially when you get to many thousands. You'd then need to use folders. e.g. folder 0000 contains data files 0-999, folder 0001 files 1000-1999, etc. You can then have 1000 folders of 1000 files. Hope this helps.
@@BytesNBits Thank you for this. Will look into the mySD option. But a good idea to do lots of files, seen this before and explains why people have done things this way.
Here's the code from the tutorial. It might be that your compiler is complaining about there being an empty function in the loop function. Try adding something in there. #include "SPI.h" #include "SD.h" #define SD_CLK 13 #define SD_MISO 12 #define SD_MOSI 11 #define SD_CS 6 void setup() { Serial.begin(115200); // avoid chip select contention pinMode(SD_CS, OUTPUT); digitalWrite(SD_CS, HIGH); if (!SD.begin(SD_CS)) { Serial.println("SD Card initialization failed!"); while(true){ ; } } else { Serial.println("SD Card OK!"); } // check if directory / folder exists and create if (!SD.exists("/data")){ SD.mkdir("/data"); } // create folder for next data run int folderCounter = 1; String baseFolder = "/data/run"; while(SD.exists(baseFolder + folderCounter)){ folderCounter ++; } String runFolder = baseFolder + folderCounter; Serial.println("Folder for this run = " + runFolder); SD.mkdir(runFolder); runFolder = runFolder + "/"; // check if file exists and delete if (SD.exists(runFolder + "my_file.txt")){ SD.remove(runFolder + "my_file.txt"); } // create new file File myFile = SD.open(runFolder + "my_file.txt", FILE_WRITE); Serial.println("Created new file"); // put some text in the file myFile.print("This was created on run "); myFile.println(folderCounter); Serial.print("First line of text added to file on run"); Serial.println(folderCounter); // close file myFile.close(); // open file for reading myFile = SD.open(runFolder + "my_file.txt", FILE_READ); // output file contents to serial monitor char nextChar; byte nextByte; while(myFile.available()){ nextChar = myFile.read(); Serial.write(nextChar); } // close file myFile.close(); } void loop() { }
Hi. With an arduino you're not going to be able. It hasn't the processing power or memory to do it. Most microcontrollers (Pi Pico, ESP32, etc) would really struggle with this task and give only a couple of frames per second (if that!).
Hello, thank you for the tutorial. I have the following questions: is there a limit on the capacity of the SD card? I'm asking because I'm having trouble using a 16 Gb SD card. Can't find anywhere the specs of the SD part of this hardware. Thank you.
FAT32 should be fine up to 32GB but as you mention the board itself might be limiting you. Individual files should be less than 4GB if you're hitting issues with large files.
Hi. You need to isolate the output pins from each Arduino when it's not driving the SPI bus. Have a look at tri state buffers which will let you disconnect from the sd card, or have a play with setting the Arduino pins to their weak pull up state when not in use - not sure how this will affect the spi library code.
Hello how are you , I am trying to make a project with arduino Leonardo and 3.5 TFT LCD the project i want make it as timer controller of cocking food can you help me please
The Leonardo should work very much the same as the Uno in the video. You just need to make sure you connect to the right pins and adjust the software setup accordingly.
How to use SD card if ESP32 is used? I able to draw graphic and touch function but I can't get SD card to work. I found this tutorial ->th-cam.com/video/ZmMTr8LEa1A/w-d-xo.html Is this only way to fix the problem? I'm not good with soldering. I don't want to fry my ESP32 and TFT.
I copied that code on video and I got some erros: C:\Users\pc\AppData\Local\Temp\cc6WS8wb.ltrans0.ltrans.o: In function `main': C:\Users\pc\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:46: undefined reference to `loop' collect2.exe: error: ld returned 1 exit status Se encontraron varias bibliotecas para "SD.h" Usado: C:\Users\pc\Documents\Arduino\libraries\SD No utilizado: C:\Users\pc\AppData\Local\Arduino15\libraries\SD exit status 1 Compilation error: exit status 1
Awesome video, it's great how you explain each line of the code. thanks for taking the time to make it for us.
No problem. Glad you found it useful.
Thanks for video!! Order couple SD modules and try experimenting soon. Cheers ...
Have fun!
Excellent. Thank you for the video, well explained.
Question? If I was storing a large amount of data, say a data logger (Date\Time and Sample).
EG
2023-10-28T23:00:00 100.1
And this was 1000s of sample values. How can I loop each line fast and read that line based on a index or line number on the file. That is not read the whole file and then loop, but somehow read a line directed on the SD card and return only that line. This way I don't have to store something that could be 4GB in size. EG - read line 10,009 and get what this line is?
I guess there are a couple of routes. I have seen some SD card libraries that seem to allow random access to files. Have a look at mySD - github.com/nhatuan84/esp32-micro-sdcard/tree/master
The other option is to break the data stream up into manageable chunks e.g. 100 samples per file and then save these with numeric file names, e.g. 1.txt, 2.txt.
You'll then be able to pick out a block of 100 samples by filename.
You might have to be careful about the number of files allowed in any folder, especially when you get to many thousands. You'd then need to use folders. e.g. folder 0000 contains data files 0-999, folder 0001 files 1000-1999, etc. You can then have 1000 folders of 1000 files.
Hope this helps.
@@BytesNBits Thank you for this. Will look into the mySD option. But a good idea to do lots of files, seen this before and explains why people have done things this way.
@@waynehawkins654 No problem. Hope you get it working 😃
Darn. Should have watched this video before I ordered my level shifters 🤣 this works how I expected mine to work.
These ones are really good and very easy to get working in both directions.
do you have the code for this example? thanks...
Here's the code from the tutorial. It might be that your compiler is complaining about there being an empty function in the loop function. Try adding something in there.
#include "SPI.h"
#include "SD.h"
#define SD_CLK 13
#define SD_MISO 12
#define SD_MOSI 11
#define SD_CS 6
void setup() {
Serial.begin(115200);
// avoid chip select contention
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
if (!SD.begin(SD_CS)) {
Serial.println("SD Card initialization failed!");
while(true){
;
}
}
else {
Serial.println("SD Card OK!");
}
// check if directory / folder exists and create
if (!SD.exists("/data")){
SD.mkdir("/data");
}
// create folder for next data run
int folderCounter = 1;
String baseFolder = "/data/run";
while(SD.exists(baseFolder + folderCounter)){
folderCounter ++;
}
String runFolder = baseFolder + folderCounter;
Serial.println("Folder for this run = " + runFolder);
SD.mkdir(runFolder);
runFolder = runFolder + "/";
// check if file exists and delete
if (SD.exists(runFolder + "my_file.txt")){
SD.remove(runFolder + "my_file.txt");
}
// create new file
File myFile = SD.open(runFolder + "my_file.txt", FILE_WRITE);
Serial.println("Created new file");
// put some text in the file
myFile.print("This was created on run ");
myFile.println(folderCounter);
Serial.print("First line of text added to file on run");
Serial.println(folderCounter);
// close file
myFile.close();
// open file for reading
myFile = SD.open(runFolder + "my_file.txt", FILE_READ);
// output file contents to serial monitor
char nextChar;
byte nextByte;
while(myFile.available()){
nextChar = myFile.read();
Serial.write(nextChar);
}
// close file
myFile.close();
}
void loop() {
}
hi sir,
how can i display movie using tft 2.8
Hi. With an arduino you're not going to be able. It hasn't the processing power or memory to do it. Most microcontrollers (Pi Pico, ESP32, etc) would really struggle with this task and give only a couple of frames per second (if that!).
Hello, thank you for the tutorial. I have the following questions: is there a limit on the capacity of the SD card? I'm asking because I'm having trouble using a 16 Gb SD card. Can't find anywhere the specs of the SD part of this hardware. Thank you.
FAT32 should be fine up to 32GB but as you mention the board itself might be limiting you. Individual files should be less than 4GB if you're hitting issues with large files.
Thank you! 👍
Nice video!
Thanks!
hi, do you know how can i connect two arduinos to the same sd card without having problems with the MOSI pin?
Hi. You need to isolate the output pins from each Arduino when it's not driving the SPI bus. Have a look at tri state buffers which will let you disconnect from the sd card, or have a play with setting the Arduino pins to their weak pull up state when not in use - not sure how this will affect the spi library code.
Hello how are you , I am trying to make a project with arduino Leonardo and 3.5 TFT LCD the project i want make it as timer controller of cocking food can you help me please
The Leonardo should work very much the same as the Uno in the video. You just need to make sure you connect to the right pins and adjust the software setup accordingly.
How to use SD card if ESP32 is used? I able to draw graphic and touch function but I can't get SD card to work.
I found this tutorial ->th-cam.com/video/ZmMTr8LEa1A/w-d-xo.html
Is this only way to fix the problem? I'm not good with soldering. I don't want to fry my ESP32 and TFT.
You can buy ESP32 models with the SD card slot built in. Otherwise you'll need to write a card adapter in to your circuit.
I copied that code on video and I got some erros:
C:\Users\pc\AppData\Local\Temp\cc6WS8wb.ltrans0.ltrans.o: In function `main':
C:\Users\pc\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:46: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
Se encontraron varias bibliotecas para "SD.h"
Usado: C:\Users\pc\Documents\Arduino\libraries\SD
No utilizado: C:\Users\pc\AppData\Local\Arduino15\libraries\SD
exit status 1
Compilation error: exit status 1
I always have similar problem. It is because of unmatched "{ " or "}"
probably your loop is inside setup().