Pages: [1]   Go Down
Author Topic: sdfat + due error  (Read 2276 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got my Due

but whe trying to upload the tutorial I found

i got this error-->

error: call to 'SdBaseFile::readDir' declared with attribute error: use readDir(&dir)

Can you tell me how can I work it out?

Thanks,
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the tutorial is this

http://www.ladyada.net/learn/arduino/ethfiles.html
Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1604
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From the changes.txt file:
Quote
The default for ALLOW_DEPRECATED_FUNCTIONS has been changed to
false.  If you get compile errors for these functions, either
change to the prefered replacement function indicated in the
error message or set ALLOW_DEPRECATED_FUNCTIONS nonzero.

from readme.txt
Quote
A number of configuration options can be set by editing SdFatConfig.h
#define macros.  Options include:

ALLOW_DEPRECATED_FUNCTIONS - enable or disable deprecated functions.

Several SdFat functions had two definitions, one with call by reference and another with call by pointer.  Two years ago I declared the call by reference versions to be deprecated.

If you have this:
Code:
root.readDir(p)
Change it to this
Code:
root.readDir(&p)

Call by reference is considered bad practice when the argument is not const.  Having two definitions of a function is even worse so I have now set ALLOW_DEPRECATED_FUNCTIONS to zero in this beta.
« Last Edit: December 04, 2012, 07:32:24 pm by fat16lib » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks, I overcome that issue

I got this new error:

In file included from SDWebBrowse.ino:30:
/home/admin-aite/sketchbook/libraries/SPI/SPI.h:16: fatal error: avr/pgmspace.h: No such file or directory
compilation terminated.
Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1604
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are getting an old version of the AVR SPI library from your sketchbook/libraries folder.  You must remove this SPI library so the correct library gets used for Due.

The standard place for the SPI library is in the IDE folder so you shouldn't need to install it in your sketchbook/libraries folder for Due or Uno Arduinos.

The Due SPI library is located in arduino-1.5.1r2/hardware/arduino/sam/libraries/SPI and is selected automatically by the IDE.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much, you have been really helpful.

one more question, How can I use the softwareserial library in the Due.

My code used it but now I have 4 Serial Ports I just want to know smiley

Again, thanks.

W
Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1604
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The SoftwareSerial library is highly ATmega dependent so it is not likely to be ported to the Due's SAM3X processor.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I finally had some time to test the sketch, in hardware.

it compiles perfect, but on the due it does not seem to work. I enter the IP. but it does not work.

I tested using the Ethernet library examples like the Web Server, it worked.

I wonder if the issue has to do with the SS pin and the SPI library - - SPI.begin()

Thanks,

w

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>
#include <SPI.h>

/************ ETHERNET STUFF ************/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 3 };
EthernetServer server(80);

/************ SDCARD STUFF ************/
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))

void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

void setup() {
  Serial.begin(9600);
  SPI.begin();
  PgmPrint("Free RAM: ");
  Serial.println(FreeRam()); 
 
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  pinMode(53, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(53, HIGH);                    // but turn off the W5100 chip!

  if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");
 
  // initialize a FAT volume
  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();
 
  if (!root.openRoot(&volume)) error("openRoot failed");

  // list file in root with date and size
  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();
 
  // Recursive list of all directories
  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);
 
  Serial.println();
  PgmPrintln("Done");
 
  // Debugging complete, we start the server!
  Ethernet.begin(mac, ip);
  server.begin();
  delay(1000);
}

void ListFiles(EthernetClient 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();
  client.println("<ul>");
  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 any indent spaces
    client.print("<li><a href=\"");
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name == ' ') continue;
      if (i == smiley-cool {
        client.print('.');
      }
      client.print((char)p.name);
    }
    client.print("\">");
   
    // print file name with possible blank fill
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name == ' ') continue;
      if (i == smiley-cool {
        client.print('.');
      }
      client.print((char)p.name);
    }
   
    client.print("</a>");
   
    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("</li>");
  }
  client.println("</ul>");
}

// How big our line buffer should be. 100 is plenty!
#define BUFSIZ 100

void loop()
{
  char clientline[BUFSIZ];
  int index = 0;
 
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
   
    // reset the input buffer
    index = 0;
   
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
       
        // If it isn't a new line, add the character to the buffer
        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          // are we too big for the buffer? start tossing out data
          if (index >= BUFSIZ)
            index = BUFSIZ -1;
         
          // continue to read more data!
          continue;
        }
       
        // got a \n or \r new line, which means the string is done
        clientline[index] = 0;
       
        // Print it out for debugging
        Serial.println(clientline);
       
        // Look for substring such as a request to get the root file
        if (strstr(clientline, "GET / ") != 0) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
         
          // print all the files, use a helper to keep it clean
          client.println("<h2>Files:</h2>");
          ListFiles(client, LS_SIZE);
        } else if (strstr(clientline, "GET /") != 0) {
          // this time no space after the /, so a sub-file!
          char *filename;
         
          filename = clientline + 5; // look after the "GET /" (5 chars)
          // a little trick, look for the " HTTP/1.1" string and
          // turn the first character of the substring into a 0 to clear it out.
          (strstr(clientline, " HTTP"))[0] = 0;
         
          // print the file we want
          Serial.println(filename);

          if (! file.open(&root, filename, O_READ)) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>File Not Found!</h2>");
            break;
          }
         
          Serial.println("Opened!");
                   
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/plain");
          client.println();
         
          int16_t c;
          while ((c = file.read()) > 0) {
              // uncomment the serial to debug (slow!)
              //Serial.print((char)c);
              client.print((char)c);
          }
          file.close();
        } else {
          // everything else is a 404
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>File Not Found!</h2>");
        }
        break;
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}
Logged

Pages: [1]   Go Up
Jump to: