Mémorisation SD
Répondre à la discussion
Affichage des résultats 1 à 7 sur 7

Mémorisation SD



  1. #1
    Szigetzy

    Mémorisation SD


    ------

    Bonjour,
    Je dois réaliser un projet visant un stocker des trames DMX dans une carte SD, pour cela je dois créer un programme qui permet de Stocker les trames DMX qui sont envoyés au microcontrôleur et traiter par celui-ci puis je dois les stocker dans la carte SD.
    N'étant pas très calé en programmation j'aurais besoin de quelques conseils sur la démarche à suivre.
    J'ai trouvé quelques librairies mais je ne comprends pas tous et ci celle-ci correspond avec le travail qui mets demandé.

    1er Programme trouvé :
    Code:
    /*
      SD card basic file example
     
     This example shows how to create and destroy an SD card file 	
     The circuit:
     * SD card attached to SPI bus as follows:
     ** MOSI - pin 11
     ** MISO - pin 12
     ** CLK - pin 13
     ** CS - pin 4
     
     created   Nov 2010
     by David A. Mellis
     updated 2 Dec 2010
     by Tom Igoe
     
     This example code is in the public domain.
     	 
     */
    #include <SD.h>
    
    File myFile;
    
    void setup()
    {
      Serial.begin(9600);
      Serial.print("Initializing 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. 
      pinMode(10, OUTPUT);
    
      if (!SD.begin(4)) {
        Serial.println("initialization failed!");
        return;
      }
      Serial.println("initialization done.");
    
      if (SD.exists("example.txt")) {
        Serial.println("example.txt exists.");
      }
      else {
        Serial.println("example.txt doesn't exist.");
      }
    
      // open a new file and immediately close it:
      Serial.println("Creating example.txt...");
      myFile = SD.open("example.txt", FILE_WRITE);
      myFile.close();
    
      // Check to see if the file exists: 
      if (SD.exists("example.txt")) {
        Serial.println("example.txt exists.");
      }
      else {
        Serial.println("example.txt doesn't exist.");  
      }
    
      // delete the file:
      Serial.println("Removing example.txt...");
      SD.remove("example.txt");
    
      if (SD.exists("example.txt")){ 
        Serial.println("example.txt exists.");
      }
      else {
        Serial.println("example.txt doesn't exist.");  
      }
    }
    
    void loop()
    {
      // nothing happens after setup finishes.
    }
    
    
    2ème programme trouvé :
    
    
    /*
      SD card read/write
     
     This example shows how to read and write data to and from an SD card file 	
     The circuit:
     * SD card attached to SPI bus as follows:
     ** MOSI - pin 11
     ** MISO - pin 12
     ** CLK - pin 13
     ** CS - pin 4
     
     created   Nov 2010
     by David A. Mellis
     updated 2 Dec 2010
     by Tom Igoe
     
     This example code is in the public domain.
     	 
     */
     
    #include <SD.h>
    
    File myFile;
    
    void setup()
    {
      Serial.begin(9600);
      Serial.print("Initializing 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. 
       pinMode(10, OUTPUT);
       
      if (!SD.begin(4)) {
        Serial.println("initialization failed!");
        return;
      }
      Serial.println("initialization done.");
      
      // open the file. note that only one file can be open at a time,
      // so you have to close this one before opening another.
      myFile = SD.open("test.txt", FILE_WRITE);
      
      // if the file opened okay, write to it:
      if (myFile) {
        Serial.print("Writing to test.txt...");
        myFile.println("testing 1, 2, 3.");
    	// close the file:
        myFile.close();
        Serial.println("done.");
      } else {
        // if the file didn't open, print an error:
        Serial.println("error opening test.txt");
      }
      
      // re-open the file for reading:
      myFile = SD.open("test.txt");
      if (myFile) {
        Serial.println("test.txt:");
        
        // read from the file until there's nothing else in it:
        while (myFile.available()) {
        	Serial.write(myFile.read());
        }
        // close the file:
        myFile.close();
      } else {
      	// if the file didn't open, print an error:
        Serial.println("error opening test.txt");
      }
    }
    
    void loop()
    {
    	// nothing happens after setup
    }
    Merci pour votre aide, Bonne Journée

    -----
    Dernière modification par gienas ; 21/03/2014 à 09h20. Motif: Ajouté les balises code obligatoires pour les programmes

  2. #2
    Szigetzy

    Re : Mémorisation SD

    J'ai trouvé une 3ème programme qui permet d'enregistrer les données visiblement, peut-ont me confirmer et me l'expliquer si s'est ce qu'il faut.

    3ème programme :

    Code:
    /*
      SD card datalogger
     
     This example shows how to log data from three analog sensors 
     to an SD card using the SD library.
     	
     The circuit:
     * analog sensors on analog ins 0, 1, and 2
     * SD card attached to SPI bus as follows:
     ** MOSI - pin 11
     ** MISO - pin 12
     ** CLK - pin 13
     ** CS - pin 4
     
     created  24 Nov 2010
     updated 2 Dec 2010
     by Tom Igoe
     
     This example code is in the public domain.
     	 
     */
    
    #include <SD.h>
    
    // On the Ethernet Shield, CS is pin 4. Note that even if it's not
    // used as the CS pin, the hardware CS pin (10 on most Arduino boards,
    // 53 on the Mega) must be left as an output or the SD library
    // functions will not work.
    const int chipSelect = 4;
    
    void setup()
    {
      Serial.begin(9600);
      Serial.print("Initializing SD card...");
      // make sure that the default chip select pin is set to
      // output, even if you don't use it:
      pinMode(10, OUTPUT);
      
      // see if the card is present and can be initialized:
      if (!SD.begin(chipSelect)) {
        Serial.println("Card failed, or not present");
        // don't do anything more:
        return;
      }
      Serial.println("card initialized.");
    }
    
    void loop()
    {
      // make a string for assembling the data to log:
      String dataString = "";
    
      // read three sensors and append to the string:
      for (int analogPin = 0; analogPin < 3; analogPin++) {
        int sensor = analogRead(analogPin);
        dataString += String(sensor);
        if (analogPin < 2) {
          dataString += ","; 
        }
      }
    
      // open the file. note that only one file can be open at a time,
      // so you have to close this one before opening another.
      File dataFile = SD.open("datalog.txt", FILE_WRITE);
    
      // if the file is available, write to it:
      if (dataFile) {
        dataFile.println(dataString);
        dataFile.close();
        // print to the serial port too:
        Serial.println(dataString);
      }  
      // if the file isn't open, pop up an error:
      else {
        Serial.println("error opening datalog.txt");
      } 
    }
    Dernière modification par gienas ; 21/03/2014 à 09h23. Motif: Balises code

  3. #3
    Yoruk

    Re : Mémorisation SD

    Certes... Maintenant intéresse toi au DMX ! Tes programmes d'écriture sont une bonne base.
    La robotique, c'est fantastique !

  4. #4
    RISC

    Re : Mémorisation SD

    Salut,

    Quel microcontroleur utilises-tu ?

    a+

  5. A voir en vidéo sur Futura
  6. #5
    Yoruk

    Re : Mémorisation SD

    ça sent la arduino vu les exemples, je les reconnais.
    La robotique, c'est fantastique !

  7. #6
    Szigetzy

    Re : Mémorisation SD

    Je m'occupe seulement de la partis programmation pour stocker sur Micro SD. Les trames DMX sont envoyés sur le microcontrôleur, elles sont lus et je dois ensuite les stocker.
    Je travail sur un microcontrôleur PIC32MX320F de ChipKit et je programme sur Mpide ça ressemble à arduino mais en PIC du coup.

  8. #7
    Yoruk

    Re : Mémorisation SD

    Citation Envoyé par Szigetzy Voir le message
    Les trames DMX sont envoyés sur le microcontrôleur, elles sont lues et je dois ensuite les stocker.
    Sans le code qui correspond à cela, tu auras du mal à avancer...
    La robotique, c'est fantastique !

Discussions similaires

  1. Fonction memorisation
    Par ghirlandaio dans le forum Électronique
    Réponses: 1
    Dernier message: 16/12/2012, 19h48
  2. Memorisation son
    Par nini631 dans le forum Électronique
    Réponses: 3
    Dernier message: 25/01/2010, 08h53
  3. memorisation
    Par invited9ab8c2f dans le forum Psychologies (archives)
    Réponses: 2
    Dernier message: 17/09/2007, 22h46
  4. mémorisation d'une impulsion !!!!!!!!
    Par omar.STE dans le forum Électronique
    Réponses: 57
    Dernier message: 07/09/2007, 16h05
  5. mémorisation
    Par invite08afaa93 dans le forum Psychologies (archives)
    Réponses: 6
    Dernier message: 18/12/2006, 17h47
Découvrez nos comparatifs produits sur l'informatique et les technologies.