ListFiles() shows the list of files in Serial Monitor but not in a browser

Good afternoon.

I started working with an Arduino Mega1280 in order to make a datalogger system. I use Arduino IDE 1.0.1 and, thanks to this forum and the open-source examples, I managed to make it work. So, a number of sensors measure some parameters, the information is stored in .csv files and the list of files is presented both in the serial monitor and a browser. :slight_smile:

After everything worked as I wanted, I constructed my own Arduino, as I needed specific pins and my own reset circuit for remote management. It was based on Atmega1280 schematic, but, instead, I put an Atmega2560 microcontroller for more memory. I also use the Ethernet-to-Serial module WIZ812MJ and the USB-to-Serial UM232R.

When the contruction completed and the bootloader for Atmega2560 was loaded, I managed to upload sketches and everything worked OK. Finally, I tried to load my code that I had alreday written on the Arduino Mega 1280.

The problem is here… On Arduino Mega 1280, the list of files is presented on the Serial monitor and the browser as well (the ListFiles() function worked fine). On my own board, the list of files is presented on the Serial monitor only and not on the browser. :~

Any idea why this is happening?
Thank you in advance.

On my own board, the list of files is presented on the Serial monitor only and not on the browser.

Strange.

Any idea why this is happening?

I'd venture to guess that there is something wrong with your code.

Thank you PaulS for your quick response.

I’d venture to guess that there is something wrong with your code.

If there was something wrong with my code, wouldn’t I have the same problem when I run the sketch on the Arduino Mega 1280? Is there any possibility that the difference in memory between Atmega1280 and Atmega2560 microcontrollers causes this problem?

The function I use in order to see the files listed on a browser is the following:

void ListFiles(Client client, uint8_t flags) {
  // This code is just copied from SdFile.cpp in the SDFat library
  // and tweaked to print to the client output in html!
  dir_t p;
 
  root.rewind();
  while (root.readDir(p) > 0) {
    // 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 file name with possible blank fill
    //root.printDirName(*p, flags & (LS_DATE | LS_SIZE) ? 14 : 0);
 
 
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
    if (DIR_IS_SUBDIR(&p)) {
      client.print('/');
    }
 
    // print modify date/time if requested
    if (flags & LS_DATE) {
       root.printFatDate(p.lastWriteDate);
       client.print(' ');
       root.printFatTime(p.lastWriteTime);
    }
    // print size if requested
    if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
      client.print(' ');
      client.print(p.fileSize);
    }
    client.println("
");
  }
}

I tried to debug entering Serial.print() messages and I realized that in while loop

while (root.readDir(p) > 0) { ..... }

the code does nothing. Really strange… :~

AS you have got your own flavoured Arduino there may have been most probably a problem in circuit , as always double check your connections most probably this is happening due to floating connections or connections gone wrong or perhaps connections not at all done.

void ListFiles(Client client, uint8_t flags) {
  // This code is just copied from SdFile.cpp in the SDFat library
  // and tweaked to print to the client output in html!
  dir_t p;

  root.rewind();
  while (root.readDir(p) > 0) {
    // done if past last used entry
    if (p.name[0] == DIR_NAME_FREE) break;

What is p.name[0]?

NI$HANT: AS you have got your own flavoured Arduino there may have been most probably a problem in circuit , as always double check your connections most probably this is happening due to floating connections or connections gone wrong or perhaps connections not at all done.

I checked the connections and everything looks fine. I am using the WIZ812MJ for ethernet to serial conversion and a microSD. I made the same connections as the connections on Arduino Ethernet Shield.

GoForSmoke: ``` void ListFiles(Client client, uint8_t flags) {   // This code is just copied from SdFile.cpp in the SDFat library   // and tweaked to print to the client output in html!   dir_t p;

  root.rewind();   while (root.readDir(p) > 0) {     // done if past last used entry     if (p.name[0] == DIR_NAME_FREE) break;




What is p.name[0]?

p.name[0] indicates the first character of the file name

On the part of function ListFiles()

....
  root.rewind();
  while (root.readDir(&p) > 0) {
    .....

I put a message Serial.println() to see the returning value of root.readDir. It returns negative. After searching, I found that possible errors include readDir() called before a directory has been opened, this is not a directory file or an I/O error occured.

Could the SPI cause this problem? (both Ethernet module WIZ812MJ and microSD use SPI) Any help would be appreciated. :)