Attempting to implement fast SD card reading methods... but failing

Hey y'all,

I have an Arduino Ethernet board (not the shield, but the discontinued board with Ethernet built-in). I wrote a simple HTML file and saved it to an SD card. Now I'm trying to read that file and serve it to network clients. But it is slow.

I've read a couple different threads on here that this is due to the SD card being read a byte at a time (using read() - a lot of overhead per byte). I also read about creating an array to use as a buffer and then filling it using read(buffer,size).

Those threads are here:
https://forum.arduino.cc/index.php?topic=319097.msg2208278#msg2208278
https://forum.arduino.cc/index.php?topic=205442.msg1513005#msg1513005

Ok, understood. So here's my code (BTW, "client.write..." is writing to the Ethernet port; confirmed working):

  uint8_t buf[100];  
  File dataFile = SD.open("header.htm");
  if (dataFile) {
    while (dataFile.available()) {
      dataFile.read(buf, sizeof(buf));
      client.write(buf);
    }
    dataFile.close();
  } else {
    Serial.println("error opening header.htm");
  }

But here are the problems...

  • As written, I get a compile warning ("warning: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]") and error (error: no matching function for call to 'write(uint8_t [100])' client.write(buf);).
  • If I change uint8_t to char, it compiles but I get "error opening header.htm" on the console when I hit the board with a browser.
  • If I revert to not using a buffer and instead use "client.write(dataFile.read());", it works... but is horribly slow because of the byte-by-byte read it is doing from the SD card.
    Any idea what's going on here? It's got to be simple.

I found something very interesting going on here. This could be a compound problem.

If global variables uses >= 1380 bytes, I get the "error opening header.htm" message on the console. This happens even if I use the (previously working) "client.write(dataFile.read());" method.