Partage
  • Partager sur Facebook
  • Partager sur Twitter

ecriture lecture eeprom arduino

30 décembre 2020 à 19:01:02

Bonsoir,

J'essaie d'ecrire une variable qui peut changer en eeprom, et la restituer en cas de reboot, et voilà la variable est initialisée en float bidon_ph =10.00 (ligne33) au premier boot puis ensuite je l'efface à la main et refait un téléchargement.

ensuite je passe par les lignes 99 à 105 puis j'appelle la fonction relais_ph ligne 105 et vais à la ligne 323 ou je met à jour bidon_ph

voici le code

/*
  Web Server
*/
#include <EEPROM.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 6
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
#include <SPI.h>
#include <Ethernet.h>
#include <ds3231.h>
#include <Wire.h>
#include <avr/wdt.h>
#include <config.h>
char concadate;//*********************************************
int flag_ph=0;
int flag_chl=0;
float val_ph;
int val_chl;
int temp_pisc;
int temp_ext;
int heure_departpompe=13;//parametrable
int tempspompe;
int heurefin;
int finpompe;
 int compteur_ph=0;
 int compteur_chl=0;
 int debut_ph=10;//*************************************relevé PH à chaque heure parametrable*****************************
 int debut_chl=15;//************************************relevé CHL à chaque heure parametrable******************************
 int tempo_ph;
 int tempo_chl=1;
float bidon_ph;//parametrable
float bidon_chl;//parametrable
float ph_moins;
struct ts t;
// On définit le OneWire
OneWire oneWire(ONE_WIRE_BUS);
// Et on le passe en réfence de la librairie Dallas temperature
DallasTemperature sensors(&oneWire);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 50);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  pinMode (2,OUTPUT);//relais pompe
  pinMode (9,OUTPUT);//relais chlore
  pinMode (5,OUTPUT);//relaisPH
  //heureph=(t.hour);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
   Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
   Serial.println("Ethernet cable is not connected.");
  }

  // start the server
  server.begin();
  //Serial.print("Adresse IP :  ");
  Serial.println(Ethernet.localIP());
  wdt_enable(WDTO_8S);
  Serial.begin(9600);
 //*******************************************On demande la température pscine************************
  sensors.begin();
 
  Wire.begin();
  //*******************************************init RTC************************************************
  DS3231_init(DS3231_INTCN);
  //********************************************init LCD*********************************************
  lcd.init();
  lcd.backlight();
 //********************************************relais  au repos**********************************
digitalWrite(2, LOW);//relais au repos
digitalWrite(5, HIGH);//relais au repos
digitalWrite(9, HIGH);//relais au repos

//*********************************************calcul temps par defaut marche pompe*******************************
temp_pisc=(sensors.getTempCByIndex(0));
delay(1);
//********************************************* "tempspompe" au demarrage******************************
sensors.requestTemperatures();
  delay(1);
  temp_pisc=(sensors.getTempCByIndex(0));
  delay(1);
tempspompe=(temp_pisc/2);
delay(5);
//*********************************************sauvegarde des bidons ph...*********************************************
if (bidon_ph<10.00){
  EEPROM.get(0,bidon_ph_lu);
  bidon_ph=bidon_ph_lu;
  Serial.println (bidon_ph);}
    else if (bidon_ph==10.00){
     EEPROM.put(0,bidon_ph);
    Serial.println ("nok");}
lcd.clear();
Serial.println (bidon_ph);
}

//**********************************************LOOP  ***********************************************************************************************
void loop() {

 //*************************************On demande la température de la piscine et extérieur*********************
  sensors.requestTemperatures();
  delay(1);
  temp_pisc=(sensors.getTempCByIndex(0));
  delay(1);
  temp_ext=(sensors.getTempCByIndex(1));
  delay(1);
 
  //******************calcul du temps de marche pompe avec mesure à 14h(soleil au zenit) et mise en EEPROM*******************************
  if ((t.hour)==14 && (t.min)==00 && (t.sec)<5) { 
  tempspompe=(temp_pisc/2);
  delay(1);
  }
 //****************************mise en forme DHM pour affichage web********************************
  DS3231_get(&t);
  String   stringOne = "Nous sommes le:  "+String(t.mday)+ "/" + String(t.mon)+" il est "+String(t.hour) + ":" + String(t.min)+"     ";
  //Serial.println (stringOne);
   //Serial.println (t.hour);
//*************************************************calcul du PH*******************************************
           int (analogChannel)=0;               
           int sensorReading; 
           val_ph = ((1023 - analogRead(analogChannel)) / 73.071);               
            (analogChannel)=1;               
            int sensorReading1 = analogRead(analogChannel);
            val_chl=sensorReading1;
   
   //***************************************affichage DHM sur LCD************************************
    
    lcd.setCursor(0,0); // positionne le curseur à la premiere colonne de la premiere ligne

    if (t.mday < 10) lcd.print("0");
    lcd.print(t.mday); lcd.print("/");
    if (t.mon < 10) lcd.print("0");
    lcd.print(t.mon); lcd.print(" ");
    if (t.hour < 10) lcd.print(" ");
    lcd.print(t.hour); lcd.print(":");
    if (t.min < 10) lcd.print("0");
    lcd.print(t.min); lcd.print(" ");
    if (t.sec < 10) lcd.print("0");
    lcd.print(t.sec);
//   ***********************************affichage température sur LCD*******************************
  lcd.setCursor(0,1);
  lcd.print("PISC:");
  lcd.print(sensors.getTempCByIndex(0),0);// temperature piscine*****************************
  delay(1);
//   Symbole degré
  lcd.write(223);
  lcd.print("C");
  lcd.setCursor(11,1);
  lcd.print("EXT:");
  lcd.print(sensors.getTempCByIndex(1),0);// temperature exterieure*****************************
  //Serial.print(sensors.getTempCByIndex(1),0);
  delay(1);
 // Symbole degré
  lcd.write(223);
  lcd.print("C");


 
  //affichage ph et chlore sur LCD
      lcd.setCursor(0,2);
      lcd.print("PH: ");
      lcd.print(val_ph,1);
      lcd.setCursor(10,2);
      lcd.print("CHL: ");
      lcd.print(val_chl);

      lcd.setCursor(0,3);
      lcd.print("POMPE D:");
      lcd.setCursor(8,3);
      lcd.print(heure_departpompe);
      lcd.setCursor(10,3);
      lcd.print("H  F:");
      heurefin=heure_departpompe+tempspompe;
      lcd.print(heurefin);
      lcd.print("H");
      
   if ((t.hour)>=heure_departpompe){
   relaispompe();//**************************************************************/***vers fonction relais pompe***************************************
   relaisPH();//*********************************************************************vers fonction relais PH******************************************  
   relaischlore();}//********************************************************************vers fonction relais chlore**************************************
     

 
  wdt_reset(); 
  //delay(10);  
  // listen for incoming clients
  EthernetClient 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: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<body style=background-color:#33a6ff;font-size:300%>");
          //*******************************************************Sortie sur internet de la DHM
                  
          client.print (stringOne);
          client.print("<br><br><br><br>");
//****************************************************valeurs sur sorties analogique 0 et 1 du PH et du chlore                              
            client.print("Valeur PH : ");
            client.print(val_ph);
            client.print("<br />");
            client.print("Nb injection PH ; ");
            client.print(compteur_ph);
            client.print("<br />");
            client.print ("niveau bidon PH : ");
            client.print(bidon_ph);
            client.print (" L ");
            client.print("<br><br>");  
            client.print("Valeur Chlore : ");
            client.print(val_chl);
            client.print("<br />");
            client.print("Nb injection CHL : ");
            client.print(compteur_chl);
            client.print("<br />");
            client.print ("niveau bidon CHL : ");
            client.print(bidon_chl/100);
            client.print (" L ");
            client.print("<br><br>");
            
    //**********************************************************Sortie sur internet de la temperature
    client.print ("Temperature de l'eau : "); 
    client.print (temp_pisc); 
    client.print (char(186));
    client.print ("C");  
    client.println("</html>");
    client.print("<br />");
    client.print ("Temperature de l'air ext : ");//******************temperature exterieure*******************
    client.print (temp_ext);
    client.print (char(186));
    client.print ("C");  
    client.println("</html>");
    client.print("<br />");
    client.print ("la pompe fonctionne de ");
    client.print (heure_departpompe);
    client.print ("h à");
    client.print (heurefin);
    client.print ("h");     
          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 disconnected");
  }
}
    
void relaispompe(){//******************************************************************** fonction relais pompe******************
// tempspompe = EEPROM.read(1);
  delay(5);
  heurefin=heure_departpompe+tempspompe;
 //Serial.println(heurefin);
 
  if ((t.hour)<heurefin){
   Serial.println(heurefin); 
  digitalWrite(2, HIGH); //relais pompe en 4 de H6 pompe en marche
  Serial.println ("pompe en marche"); 
  }
   if ((t.hour)==heurefin){
   digitalWrite(2, LOW); //relais pompe en 4 de H6 arret pompe 
   Serial.println ("arret pompe");
   compteur_chl=0;
   compteur_ph=0;}
}
void relaischlore(){  //******************************************************************* fonction relais chlore******************
 if ((t.hour)<(heurefin) and (t.min) == debut_chl ){ //and val_chl<=600
 Serial.print ("debut  ");
  Serial.print (t.hour);
 Serial.println (t.min);
 digitalWrite(9, LOW); //relais chlore en marche
 flag_chl=1;  
 }
  if ((t.min)==debut_chl+tempo_chl and flag_chl==1){
   digitalWrite(9, HIGH); //relais chl: arret pompechl
  Serial.print ("fin  ");
  Serial.print (t.hour);
  Serial.println (t.min);
 compteur_chl=compteur_chl+1;
 flag_chl=0;
  Serial.println ("arret chl");}
  Serial.println (compteur_chl);
   }
void relaisPH(){ //******************************************************************** fonction relais PH**********************
 if ((t.hour)<(heurefin) and (t.min) == debut_ph and val_ph>=3.2){ 
 Serial.print ("debut  ");
  Serial.print (t.hour);
 Serial.println (t.min);
 digitalWrite(5, LOW); //relais ph en marche
 flag_ph=1;  
 }
  if (val_ph>=6){
    tempo_ph=1;
    ph_moins=0.3;
   }
   /* else if( val_ph<8 and val_ph>=7.5){
      tempo_ph=2;
      ph_moins=0.2;
      }
      else if (val_ph<7.5 and val_ph>6) {
        tempo_ph=1;
        ph_moins=0.1;
              }*/
      
   if ((t.min)==debut_ph+tempo_ph and flag_ph==1){
   Serial.print (tempo_ph);
   digitalWrite(5, HIGH); //relais ph: arret pompeph 
  Serial.print ("fin  ");
  Serial.print (t.hour);
  Serial.println (t.min);
  
  bidon_ph = bidon_ph - ph_moins;//(tempo_ph);// 0.1;
  Serial.print (tempo_ph);
  Serial.print ("/");
  Serial.println (bidon_ph);//************************ valeur ok
  compteur_ph=compteur_ph+1;
  flag_ph=0;
  EEPROM.put(0,bidon_ph);
  Serial.print ("bidon_ph: ");
  Serial.println (bidon_ph);//*********************** valeur nok
  Serial.println ("arret ph");}
  Serial.println (compteur_ph);
  }

Bonne fete à tous

j'ai oublié de vous dire que ca ne marche pas ligne 354 c'est la bonne valeur mais après écriture c'est pas bon...

merci de votre aide

-
Edité par Claudio91 30 décembre 2020 à 19:07:11

  • Partager sur Facebook
  • Partager sur Twitter
3 janvier 2021 à 18:36:38

Re

Bon bah 'ai trouvé, tout fonctionne, pour le moment...

  • Partager sur Facebook
  • Partager sur Twitter