Bonjour,
Problème avec RTC 1307 : Le programme 'essai' (ci-joint) fonctionne parfaitement.
Lorsque je greffe ce programme au programme 'essai_sauv' que je veux utiliser pour mon bateau (affichage de l'heure, pression, température air et eau), il y a un 'bug'. L'afficheur se met à l'heure, le ":" clignote une fois, puis plus rien (l'affichage des températures et pression sur LCD 16x2 fonctionne correctement).Code:#include <Wire.h> #include "RTClib.h" #include "TM1637.h" #define ON 1 #define OFF 0 int8_t TimeDisp[] = {0x00,0x00,0x00,0x00}; unsigned char ClockPoint = 1; #define CLK 2//pins definitions for TM1637 #define DIO 3 TM1637 tm1637(CLK,DIO); #if defined(ARDUINO_ARCH_SAMD) // for Zero, output on USB Serial console, remove line below if using programming port to program the Zero! #define Serial SerialUSB #endif RTC_DS1307 rtc; //char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; void setup () { tm1637.set(); tm1637.init(); #ifndef ESP8266 while (!Serial); // for Leonardo/Micro/Zero #endif Serial.begin(9600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); } // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); } void loop () { DateTime now = rtc.now(); //Serial.print(now.year(), DEC); //Serial.print('/'); //Serial.print(now.month(), DEC); //Serial.print('/'); //Serial.print(now.day(), DEC); //Serial.print(" ("); //Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); //Serial.print(") "); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); //Serial.print(':'); //Serial.print(now.second(), DEC); Serial.println(); // Serial.print(" since midnight 1/1/1970 = "); // Serial.print(now.unixtime()); // Serial.print("s = "); // Serial.print(now.unixtime() / 86400L); // Serial.println("d"); // Serial.println(); // delay(5000); tm1637.point(POINT_ON); TimeDisp[0] = now.hour() / 10; TimeDisp[1] = now.hour() % 10; TimeDisp[2] = now.minute() / 10; TimeDisp[3] = now.minute() % 10; tm1637.display(TimeDisp); delay(500); tm1637.point(POINT_OFF); tm1637.display(TimeDisp); delay(500); }
Nouveau en programmation Arduino, je soupçonne un problème de bus I2C, mais c'est juste une idée.Code:#include <Wire.h> #include "RTClib.h" #define DS1307_I2C_ADDRESS 0x68 // essai avec et sans cette instruction // initialisation de l'afficheur #include "TM1637.h" #define ON 1 #define OFF 0 int8_t TimeDisp[] = {0x00,0x00,0x00,0x00}; unsigned char ClockPoint = 1; #define CLK 2//pins definitions for TM1637 #define DIO 3 TM1637 tm1637(CLK,DIO); #if defined(ARDUINO_ARCH_SAMD) // for Zero, output on USB Serial console, remove line below if using programming port to program the Zero! #define Serial SerialUSB #endif RTC_DS1307 rtc; // initialisation du RTC // initialisation LCD #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); uint8_t hausse[8] = {0x7, 0x3, 0x5, 0x8, 0x10, 0x0, 0x0}; // création caractères spéciaux uint8_t baisse[8] = {0x0, 0x0, 0x10, 0x8, 0x5, 0x3, 0x7}; #include <Adafruit_BMP085.h> // Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!) // Connect GND to Ground // Connect SCL to Analog 5 // Connect SDA to Analog 4 Adafruit_BMP085 bmp; //thermometre etanche // which analog pin to connect #define THERMISTORPIN A0 // resistance at 25 degrees C #define THERMISTORNOMINAL 10000 // temp. for nominal resistance (almost always 25 C) #define TEMPERATURENOMINAL 25 // how many samples to take and average, more takes longer // but is more 'smooth' #define NUMSAMPLES 5 // The beta coefficient of the thermistor (usually 3000-4000) #define BCOEFFICIENT 3950 // the value of the 'other' resistor #define SERIESRESISTOR 10000 int samples[NUMSAMPLES]; int T = 0; int P = 0; int TE = 0; int avant = 0; // ces quatre instructions sont utilisées pour une extension du programme unsigned long N; unsigned long t; boolean alarme = false; void setup () { lcd.begin(); // initialize the lcd lcd.backlight(); lcd.createChar(0, hausse); lcd.createChar(1, baisse); lcd.home (); analogReference(EXTERNAL);// précision du thermomètre étanche Serial.begin(9600); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } tm1637.set(); tm1637.init(); #ifndef ESP8266 while (!Serial); // for Leonardo/Micro/Zero #endif Serial.begin(9600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); } rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); } void loop () { DateTime now = rtc.now(); // pour le bmp 180 T = Arrondi(bmp.readTemperature()); Serial.println(T); P = Arrondi(bmp.readPressure()/100); // pour le thermometre étanche uint8_t i; float average; int j = 0; // take N samples in a row, with a slight delay for (i=0; i< NUMSAMPLES; i++) { samples[i] = analogRead(THERMISTORPIN); delay(500); } // average all the samples out average = 0; for (i=0; i< NUMSAMPLES; i++) { average += samples[i]; } average /= NUMSAMPLES; // convert the value to resistance average = 1023 / average - 1; average = SERIESRESISTOR / average; float steinhart; steinhart = average / THERMISTORNOMINAL; // (R/Ro) steinhart = log(steinhart); // ln(R/Ro) steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro) steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; TE = Arrondi(steinhart); // fin des calculs du thermomètre étanche // affichage des résultats lcd.setCursor(0,0); lcd.print("Air "); lcd.setCursor(4,0); lcd.print(T); lcd.setCursor(6,0); lcd.write(0xDF); // utilise l'adresse hexa du caractère à afficher (prg customchar de la librairie) lcd.setCursor(9,0); lcd.print("Eau "); lcd.setCursor(13,0); lcd.print(TE); lcd.setCursor(15,0); lcd.write(0xDF); lcd.setCursor(4,1); lcd.print(P); lcd.print(" hPa"); // récupération de l'heure et affichage DateTime now = rtc.now(); Serial.print(now.hour()); Serial.print(":"); Serial.print(now.minute()); Serial.print(":"); Serial.print(now.second()); Serial.println(); tm1637.point(POINT_ON); TimeDisp[0] = now.hour() / 10; TimeDisp[1] = now.hour() % 10; TimeDisp[2] = now.minute() / 10; TimeDisp[3] = now.minute() % 10; tm1637.display(TimeDisp); delay(500); tm1637.point(POINT_OFF); tm1637.display(TimeDisp); delay(500); } // Sous programme arrondi int Arrondi(float nombre_float) { float nombre; nombre = nombre_float - int(nombre_float); if (nombre >= 0.5) { nombre = int(nombre_float) + 1; } else { nombre = int(nombre_float); } return nombre; }
Appel à l'aide !
Et merci d'avance !
-----