Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 03/09/2015, à 18:24

Luc2511

ecriture sur SD de caracteres non reconnus

Bonjour,
Je patauge depuis une semaine sur un problème qui me dépasse.

J'ai un montage avec un module GY-GPS6MV2 et une carte SD sur laquelle je veux entegistrer les donnees GPS.

#include <Wire.h>
#include <SD.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>
//........................... SD .............................. 

// ** MOSI - pin 11
// ** MISO - pin 12
// ** CLK - pin 13
// ** CS - pin 4
Sd2Card card;
File myFile;
const int chipSelect = 4; 

//------------------------- gps --------------------------------

SoftwareSerial GPS(2,3); //Tx=2, Rx=3

TinyGPS shield;    // Create an instance of the TinyGPS object
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long fix_age=0;
float latitude, longitude;


//========================= SETUP ============================== 
void setup()
{
  Serial.begin(9600); 
  //------------------------- gps --------------------------------
  GPS.begin(9600); 
  
  
  //............................... SD .............................
  Serial.print("Initializing SD card...");  
  pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialisation SD ratee!");
    //alarme();
  } else {
  Serial.println("initialsation SD reussie.");
  }
  
  myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile) {
    Serial.print("ecriture de  test.txt...");
    myFile.println("testing 1, 2, 3.");
    myFile.close();
    Serial.println("ecriture test.txt reussie.");
  } else {
    Serial.println("error opening test.txt");
    //alarme();
    myFile.close();
  }

  
}

//========================= VOID ===============================
void getgps(TinyGPS &gps)  // The getgps function will interpret data from GPS and display on serial monitor
{
  shield.f_get_position(&latitude, &longitude);    // Then call this function
  Serial.println("--------------------------------------------------------------");
  Serial.print("Lat: "); 
  Serial.print(latitude,5); 
  Serial.print(" Long: "); 
  Serial.print(longitude,5);
 

  shield.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths,&fix_age);
 
  // Print data and time
  Serial.print("   GMT - ");
  Serial.print(hour, DEC);
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
    Serial.print(minute, DEC);
  } 
  else if (minute>=10) 
  {
    Serial.print(minute, DEC);
  }
  Serial.print(":");
  if (second<10) 
  {
    Serial.print("0");
    Serial.print(second, DEC);
  } 
  else if (second>=10)
  {
    Serial.print(second, DEC);
  }
  Serial.print(" ");
  Serial.print(day, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.println(year, DEC);
  

}



//============================= LOOP ===========================
void loop()
{
  byte a;
  if ( GPS.available() > 0 ) // if there is data coming from the GPS shield
  {
    a = GPS.read(); // get the byte of data
    if(shield.encode(a)) // if there is valid GPS data...
    {
      getgps(shield); // then grab the data and display it on the LCD
      ecritureSD();
    }
  }
}


//................................. ecritureSD ....................
void ecritureSD()
{

    myFile = SD.open("geoloc.csv", FILE_WRITE);
    if (myFile)
    {
      Serial.print("j'ecris...");
      myFile.print("Lat: ");                               //ecriture sur carte
      myFile.print(',');    
      myFile.print(latitude,5);
      myFile.print(',');
      myFile.print(" Long: ");
      myFile.print(',');
      myFile.print(longitude,5);
      myFile.print(',');
      myFile.print(hour, DEC);
      myFile.print(',');
      myFile.print(minute, DEC);
      myFile.print(',');  
      myFile.print(second, DEC); 
      myFile.print(',');  
      myFile.print(day, DEC); 
      myFile.print(','); 
      myFile.print(month, DEC); 
      myFile.print(',');  
      myFile.println(day, DEC); 
   
 
      myFile.close();
      Serial.println("donnees enregistrees sur SD");
    } else 
    {
      Serial.println("ecriture geolocal.csv impossible");
      //alarme();
    }

}

Tout fonctionne correctement à l'écran. J'obtiens sans problème les coordonnées gps et l'heure.
Mais quand je démarre le code, la première fois fonctionne normalement. Ensuite, je retire la carte pour vérifier que mes données sont bien enregistrées. Et là, je trouve en première ligne un fichier vide dont le nom est formé de caractères ascii de dessin...
Je remets la carte, et le code ne peut pas l'initialiser. Je remets la carte dans l'ordi et message suivant: "ECHEC AU MONTAGE  Not authorized to perform operation."
J'ouvre gparted qui me dit:

"(gpartedbin:19681); glibmm-CRITICAL **)
unhandled exception (type Glib::Error) in signal handler:
domain: g_convert_errot
code : 1
what : Séquence d'octets incorrecte en entrée du convertisseur

J'ai cherché sur internet et j'ai trouvé la bibliothèque SdFat. J'ai telechargé le code pour reformater une carte SD et voilà le résultat:

This program can erase and/or format SD/SDHC cards.

Erase uses the card's fast flash erase command.
Flash erase sets all data to 0X00 for most cards
and 0XFF for a few vendor's cards.

Cards larger than 2 GB will be formatted FAT32 and
smaller cards will be formatted FAT16.

Warning, all data on the card will be erased.
Enter 'Y' to continue: Y

Options are:
E - erase the card and skip formatting.
F - erase and then format the card. (recommended)
Q - quick format the card without erase.

Enter option: F

SD initialization failure!
Is the SD card inserted correctly?
Is chip select correct at the top of this program?
error: card.begin failed
SD error: 1,ff

Alors, deux questions en premier:
1) comment reformater mes cartes SD (j'en ai flingué 4 et ça commence à faire beaucoup!).
2) Qu'y-a-t-il dans mon code qui crée ce pb?   (ce code n'est pas de moi!)

et aussi: faut-il changer de bivliothèque SD? 

merci à vous

Dernière modification par Luc2511 (Le 03/09/2015, à 18:25)

Hors ligne