Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Discussions


Index du Forum » Discussions » Problemes Arduino
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Problemes Arduino

Posté le 13/03/2014 22:26

Bon voila j'ai un soucis avec ma Arduino pour la lecture de carte SD via un shield Ethernet pour une mise en réseau des données
J'ai suivis le topic de ladyada mais il ou elle avait du le faire avant la mise a jour de la librairie ... Donc avant de prendre l'ancienne version de la librairie, quelqu’un saurais t'il resoudre l'erreur de compilation dans la fonction ListFiles

Le code
Cliquer pour enrouler
#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, 177 };
EthernetServer server(80);

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

// 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);

  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(10, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(10, 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();
}

void loop()
{
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
          // 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
          //ListFiles(client, 0);
          client.println("<h2>Files:</h2>");
          //ListFiles(client, 0);

          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}

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();
  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("<br>");
  }
}


Le retour du compilateur
Cliquer pour enrouler
no matching function for call to 'SdFile::readDir(dir_t&)'

sketch_mar13a.ino: In function 'void ListFiles(EthernetClient, uint8_t)':
sketch_mar13a:116: error: no matching function for call to 'SdFile::readDir(dir_t&)'
C:\Documents and Settings\User\Bureau\User\Arduino\libraries\SdFat/SdBaseFile.h:325: note: candidates are: int8_t SdBaseFile::readDir(dir_t*)



1, 2 Suivante
Lephenixnoir En ligne Administrateur Points: 24145 Défis: 170 Message

Citer : Posté le 13/03/2014 22:36 | #


Quelle erreur as-tu à la compilation ?
Mon graphe (24 Mars): (gint#27 ; (Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; ...) || (shoutbox v5 ; v5)
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 11:02 | #


Je t'ai modifier le topic
Alphacreator Hors ligne Membre Points: 1464 Défis: 43 Message

Citer : Posté le 14/03/2014 11:30 | # | Fichier joint


code
Cliquer pour enrouler
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;

void setup()
{
// Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();
  
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
  
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
  
}

En fichier joint la lib
Après tu peux modifier ce que tu veux, je te conseille de regarder les exemples contenus dans le .rar
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 12:13 | #


Oui la lib est inclue par défaut je crois (en tout cas je l'avais)
Merci je vais regarder si je peux l'adapter au shield pour le HTML
Alphacreator Hors ligne Membre Points: 1464 Défis: 43 Message

Citer : Posté le 14/03/2014 12:16 | #


Je pense que ça devrait être faisable, à toi de voir. Bonne chance (si je trouve un truc je te le dis, là je suis plutôt en train de m'occuper de mon écran tactile et après je vais faire de la com sans fil mais j'utiliser cette lib pour mon écran)
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 12:19 | #


va a la balise 1.13
Je pense que tu connais mais on sais jamais
Alphacreator Hors ligne Membre Points: 1464 Défis: 43 Message

Citer : Posté le 14/03/2014 12:23 | #


T'inquète, je sais utiliser mon écran, je l'ai depuis Septembre, et j'ai déjà une lib pour ça. Je disais que j'avais des projets dessus (un éditeur de fichiers de la carte SD avec pas mal d'options: créer/renommer un fichier/un dossier... Mais il faut que je fasse le design: )
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 13:30 | #


Ca avance dur mais je me demande si c'est normal que le micro-contrôleur du shield chauffe autant (je suis limite en train de me bruler quand je pose le doigt dessus après 10 minutes d'utilisation) ?
Alphacreator Hors ligne Membre Points: 1464 Défis: 43 Message

Citer : Posté le 14/03/2014 13:33 | #


Ça fait pareil avec le mien, c'est pas trop grave si tu fais attention à ne pas t'en servir trop longtemps et qu'il n'y ai pas de risques.
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 17:21 | #


Bon zlors la je comprends pas trop...
Aucune erreur, j'arrive bien a me connecter au serveur mais je comprends pas pourquoi il ne m'affiche pas les fichier contenus dans les dossiers ...
Autre problème, comment faire pour inclure le "client.println("<meta charset="utf-8" />");" ?

Le code
Cliquer pour enrouler
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;

EthernetServer server(80);
EthernetClient client;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  
  Serial.println("\nEn attente...");
  while(Serial.read()<=0);
  
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("Server is at ");
  Serial.println(Ethernet.localIP());
  
  Serial.println("\nEn attente...");
  while(Serial.read()<=0);
}

void loop()
{
  client = server.available();
  
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
      client.println("Refresh: 120");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<head>");
          // client.println("<meta charset="utf-8" />");
          client.println("<title>Arduino SD</title>");
          client.println("</head>");
          client.println("<body>");
          client.println("<p><strong>Starting...</strong></p>");
          
          if (!SD.begin(4)) {
            Serial.println("initialization failed!");
            client.println("<p><strong><em> ! FAIL ! </em></strong></p>");
            return;
          }
          Serial.println("initialization done.");
          client.println("<p><strong><em>initialization done.</em></strong></p>");
          
          // Affichage des fichiers
          client.println("<h2>SD Files:</h2>");
          
          File root = SD.open("/");
          
          printDirectory(root, 0);
          
          client.println("</body>");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
  
}

void printDirectory(File dir, int numTabs) {
   while(true) {
    
     client.print("<p>");
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print("\t");
       client.print("\t");
     }
     Serial.print(entry.name());
     client.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       client.print("/");
       client.println("</p>");
       printDirectory(entry, numTabs+1);
     } else {
        files have sizes, directories do not
       Serial.print("\t\t");
       client.print("\t\t");
       Serial.println(entry.size(), DEC);
       client.print(entry.size(), DEC);
       client.println("</p>");
     }
    
     entry.close();
   }
}

Alphacreator Hors ligne Membre Points: 1464 Défis: 43 Message

Citer : Posté le 14/03/2014 17:22 | #


Pour la balise meta, tu as des "" en trop, essaye d'utiliser ' à la place, en HTML, ça devrait passer. Par contre je ne suis pas sûr que le /t marche en HTML, vérifie car je dis peut être des bétises, utilise la propriété text-indent sinon
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 17:31 | #


Le code en HTML de la page ... Il y a plusieurs balise <p> qui bugs a cause de la recurence ...
Le Code
Cliquer pour enrouler
<html>
<head>
<title>Arduino SD</title>
</head>
<body>
<p><strong>Starting...</strong></p>
<p><strong><em>initialization done.</em></strong></p>
<h2>SD Files:</h2>
<p>LOST.DIR/</p>
<p><p>DCIM/</p>
<p><p>VIDEOS~1/</p>
<p><p>MUSIC~1/</p>
<p><p>SOUNDS~1/</p>
<p><p>ANDROID/</p>
<p><p>@BGSR/</p>
<p><p>SDCARD/</p>
<p><p>NOTIFI~1/</p>
<p><p>T_L_CH~1/</p>
<p><p>SOUNDH~1/</p>
<p><p>ANDROI~1/</p>
<p><p>STHUMBDB.TDB        2885184</p>
<p>PLAYLI~3/</p>
<p><p>OPENFE~1/</p>
<p><p>BEINTO~1/</p>
<p><p>BURSTL~1/</p>
<p><p>RINGTO~1/</p>
<p><p>RINGTO~2/</p>
<p><p>SPI0N/</p>
<p><p>OTHERF~1/</p>
<p><p>SOCIAL~1/</p>
<p><p>SHOWME~1/</p>
<p><p>DEEZER/</p>
<p><p>MEDIA/</p>
<p><p>PPY_CR~1/</p>
<p><p>ADC~1/</p>
<p><p>DOWNLOAD/</p>
<p><p>YUME_A~1/</p>
<p><p>MMSYSC~1/</p>
<p><p>BEEZIK/</p>
<p><p>SCOREL~1/</p>
<p><p>CUTTHE~1/</p>
<p><p>VUNGLE~1/</p>
<p><p>MINICL~1.TXT        24</p>
<p>DATA/</p>
<p><p>MONSTE~1.DB        1032192</p>
<p>CATSTU~1/</p>
<p><p>BULLDO~1        63</p>
<p>CLIPBO~1/</p>
<p><p>POLARI~1/</p>
<p><p>SMS_BA~1/</p>
<p><p>ESTRON~1/</p>
<p><p>PHOTOS/</p>
<p><p>IMAGES/</p>
<p><p></body>
</html>

Alphacreator Hors ligne Membre Points: 1464 Défis: 43 Message

Citer : Posté le 14/03/2014 17:33 | #


Bizarre... Il faut que j'essaye avec le mien (je sais d'où vient ta carte SD moi j'en ai 2 exprès pour l'arduino et une pour mon portable)
Par contre il vaut mieux que je change d'IP si on bosse avec la même en même temps
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 17:34 | #


Oui je sais elle est un peut nfectée par des tas de fichiers android ça donne une belle arborescence en tout cas
Alphacreator Hors ligne Membre Points: 1464 Défis: 43 Message

Citer : Posté le 14/03/2014 17:49 | #


Il te mets quoi dans la fenêtre serial? Il me met 2 caractères bizarres... comme ™þ parfois faudrait que j'essaye avec une autre adresse MAC et une autre IP mais même quand le shield n'est pas connecté ça me fait ça, bizarre.
J'espère juste que ce n'est pas mon shield qui fait n'importe quoi parce que sinon je suis mal... En tout cas c'est pas mes cartes car c'est pareil pour toutes
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 17:52 | #


C'est que je suis en 115200 baud
Sinon j'ai un En attente puis toutes les infos client
Lephenixnoir En ligne Administrateur Points: 24145 Défis: 170 Message

Citer : Posté le 14/03/2014 17:55 | #


Le caractère bizarre, c'est juste un octet dont la valeur dépasse 128 ; il te sort un caractère étendu.
Mon graphe (24 Mars): (gint#27 ; (Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; ...) || (shoutbox v5 ; v5)
Alphacreator Hors ligne Membre Points: 1464 Défis: 43 Message

Citer : Posté le 14/03/2014 18:06 | #


Exact, je me suis mis en 9600, je te dis si ça marche chez moi

Ajouté le 14/03/2014 à 18:13 :
Non, chez moi ça marche bien, par contre j'ai une balise <p> avant le </body> il suffit de mettre client.print("<p>"); après avoir regardé s'il n'y avait plus de fichiers
Theprog Hors ligne Membre Points: 1447 Défis: 20 Message

Citer : Posté le 14/03/2014 18:40 | #


ca t'affiche tous les fichiers même ceux contenus dans les dossiers ?
Lephenixnoir En ligne Administrateur Points: 24145 Défis: 170 Message

Citer : Posté le 14/03/2014 18:46 | #


Ça dépend de la plateforme, mais si c'est une carte SD, il est probable que tu n'obtiennes qu'une liste des fichiers et dossiers du répertoire actuel, sans information quant au contenu des sous-dossiers.
Mon graphe (24 Mars): (gint#27 ; (Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; ...) || (shoutbox v5 ; v5)
1, 2 Suivante

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2024 | Il y a 115 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd