Hi, I'm trying to print out the content of sd card to I2C display. I figured out the best way would be editing function in SD library and adding print function from I2C library, but don't know know how to do it cause I'm begginer in C/C++. I added all .h files it needed into the folder but still it gives me some compilation error. Maybe there's better solution to this, I don't know but I'm still curious how to combine libraries.
you wouldn't combine the libraries, you'd include both of the libraries, store what you read from the sd card into a variable, then tell the display to show that variable.
the program would layout like this
include Sd library
include lcd library
declare and initialize variables
run setup function
start loop
run function to read from SDcard
run function to display information read from sd card
end loop.
do you have any working code that does partially what you want? what libraries? ect.
I'd start with trying to get the lcd to display "hello world"
I'm using the LiquidCrystal_V1.2.1 library which can work with I2C lcd displays and trying to edit function in SD library, particularly SdFile::ls so that it won't print to serial but straight to lcd. The problem with your solution is that this function has void return type. And yes, I already played with LCD, made a function which reads string from serial and then it formats it and prints to display.
and trying to edit function in SD library, particularly SdFile::ls so that it won't print to serial but straight to lcd.
What have you added to the SdFile::ls() method? What happened?
The ls() method is meant to demonstrate that the card and hardware are working. Look at what it does. It makes NO use of private data, so everything that it does could be done from your code. Do it from your code, and you can put the file name anywhere you want - to the serial port, to the LCD, to the moon, Alice.
The ls() method is meant to demonstrate that the card and hardware are working.
I mean this method - void SdFile::ls(uint8_t flags, uint8_t indent). I found there is printDirName() function so in that method in for cycle I added simple LCD lcd; and lcd.print(dir.name[j]). But as I said I'm just begginer in c/c++ so it gave me compilation error.
I added simple LCD lcd; and lcd.print(dir.name[j]). But as I said I'm just begginer in c/c++ so it gave me compilation error.
Someone with a 3 hour old Arduino and programming career IS able to post code and error messages. That you haven't tells me that you are not serious about solving the problem.
Ok, here you go.
Here is the ls() method:
void SdFile::ls(uint8_t flags, uint8_t indent) {
dir_t* p;
rewind();
while ((p = readDirCache())) {
// done if past last used entry
if (p->name[0] == DIR_NAME_FREE) break;
// skip deleted entry and entries for . and ..
if (p->name[0] == DIR_NAME_DELETED || p->name[0] == '.') continue;
// only list subdirectories and files
if (!DIR_IS_FILE_OR_SUBDIR(p)) continue;
// print any indent spaces
for (int8_t i = 0; i < indent; i++) Serial.print(' ');
// print file name with possible blank fill
printDirName(*p, flags & (LS_DATE | LS_SIZE) ? 14 : 0);
// print modify date/time if requested
if (flags & LS_DATE) {
printFatDate(p->lastWriteDate);
Serial.print(' ');
printFatTime(p->lastWriteTime);
}
// print size if requested
if (!DIR_IS_SUBDIR(p) && (flags & LS_SIZE)) {
Serial.print(' ');
Serial.print(p->fileSize);
}
Serial.println();
// list subdirectory content if requested
if ((flags & LS_R) && DIR_IS_SUBDIR(p)) {
uint16_t index = curPosition()/32 - 1;
SdFile s;
if (s.open(this, index, O_READ)) s.ls(flags, indent + 2);
seekSet(32 * (index + 1));
}
}
}
And here is the printDirName() method I tried to edit.
void SdFile::printDirName(const dir_t& dir, uint8_t width) {
LCD lcd;
uint8_t w = 0;
for (uint8_t i = 0; i < 11; i++) {
if (dir.name[i] == ' ')continue;
if (i == 8) {
Serial.print('.');
w++;
}
Serial.write(dir.name[i]);
lcd.print(dir.name[i]);
w++;
}
if (DIR_IS_SUBDIR(&dir)) {
Serial.print('/');
w++;
}
while (w < width) {
Serial.print(' ');
w++;
}
}
Compilation error:
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp: In static member function 'static void SdFile::printDirName(const dir_t&, uint8_t)':
C:\Program Files (x86)\Arduino\libraries\SD\src\utility\SdFile.cpp:605:5: error: 'lcd' was not declared in this scope
lcd.print(dir.name*);*
- ^*
Error compiling.
LCD lcd;
What class is lcd supposed to be an instance of? Does the LCD class really have a no-argument constructor?