Étape 3: Configuration d’EEPROM
Configuration de l’EEPROM pour la première fois est facilement réalisable en utilisant le croquis suivant, que j’ai appelé EEPROM_config. Cette esquisse (avec SGDL lui-même) nécessite une bibliothèque supplémentaire, appelée EEPROMAnything, qui doit être ajouté au dossier de bibliothèques de l’Arduino, partout où son dossier de carnet de croquis est. Pendant que vous y êtes, vous devez également ajouter la bibliothèque dont nous avons besoin pour la SGDL.
/* ************************************************************************ * *** Super Graphing Data Logger - EEPROM config *** * ************************************************************************ * Everett Robinson, December 2012. * * The following extra non standard libraries were used, and will need to be * added to the libraries folder: * - EEPROMAnything: http://playground.arduino.cc/Code/EEPROMWriteAnyt... * * This sketch helps you set the values in EEPROM which are necessary for * Super Graphing Data Logger. It should only need the be run once before * the first time you set up SGDL, or in the unlikely event that the EEPROM * becomes corrupted. * * Please ensure that the values in configuration config are appropriate for * your project before uncommenting the EEPROM_writeAnything(0, config); line. * */ #include <EEPROM.h>#include <EEPROMAnything.h> typedef struct{ unsigned long newFileTime; char workingFilename[19]; } configuration; //This is a one off thing, so everything is in setup void setup(){ Serial.begin(9600); //Create the config struct to write to EEPROM, change values as appropriate //Make sure your filename is not too long for the workingFilename char array configuration config = {1356912000L,"/data/25-12-12.csv"}; //Write the values to the EEPROM //EEPROM_writeAnything(0, config); //Uncomment when you're sure everything is correct configuration config2; //Create a second config struct for verification EEPROM_readAnything(0,config2); Serial.print("The value read from EEPROM for newFileTime is: "); Serial.println(config2.newFileTime); Serial.print("The value read from EEPROM for workingFilename is: "); Serial.println(config2.workingFilename); Serial.println("If those values are correct then everything went as planned. Otherwise,"); Serial.println("please double check that the values declared for the struct config are"); Serial.println("correct and that that EEPROM_writeAnything line is uncommented."); } void loop(){ }
Volontairement, j’ai commenté la ligne d’écriture afin que personne n’écrit indésirable dans l’EEPROM par accident. Alors que l’EEPROM a une vie de ~ 100 000 cycles d’écriture, j’ai plutôt pas gaspillerait un quelconque d'entre eux. Veuillez lire attentivement l’esquisse et s’assurer que vous avez ajusté en conséquence avant Uploader sur l’Arduino. La chose la plus importante est de faire en sorte que votre newFileTime est quelque chose de sensé (dans un proche avenir surtout).