Show Posts
|
|
Pages: [1]
|
|
2
|
International / Français / Re: Integrer Horloge DS1307 à mon sketch
|
on: January 29, 2013, 02:02:04 pm
|
|
En fait le probleme est que les secondes se rafraichissent toutes les 4 secondes alors que j'avais indiqué delay(1000)
Et le second probleme c'est pour les nombres inférieurs à 10. Serial.print("0") ne vas pas juste afficher le nombre 0 dans le mode moniteur serie? Je sais pas comment placer if (...)
|
|
|
|
|
3
|
International / Français / Re: Integrer Horloge DS1307 à mon sketch
|
on: January 29, 2013, 12:45:06 pm
|
Salut, oui je sais, le code correspondant à l'horloge n'est pas dans le code que j'ai inscrit, c' est pour ca. Voila mon code actuel : #define DHTPIN 3 // sonde dht (t/rh) #define DHTTYPE DHT22 //#define DHTTYPE DHT11 (capteur DHT11) #include <OneWire.h> //capteur t #include <LiquidCrystal.h> //lcd #include <DHT.h> //capteur dht #include "RTClib.h" #include <Wire.h> DHT dht(DHTPIN, DHTTYPE); RTC_DS1307 RTC; float h = 0; float t = 0;
OneWire ds(4); //capteur t LiquidCrystal lcd(5, 6, 7, 8, 9, 10, 11); int backLight = 12; // pin 13 will control the backlight
void setup(void) { Serial.begin(9600); //capteur t dht.begin(); //capteur dht pinMode(backLight, OUTPUT); digitalWrite(backLight, HIGH); // turn backlight on. lcd.begin(20,4); Wire.begin(); RTC.begin(); 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(__DATE__, __TIME__));
} } void loop(void) { DateTime now = RTC.now(); byte i; byte present = 0; byte type_s; byte data[12]; byte addr[8]; float celsius, fahrenheit; if ( !ds.search(addr)) { Serial.println("No more addresses."); Serial.println(); ds.reset_search(); delay(250); return; } Serial.print("ROM ="); for( i = 0; i < 8; i++) { Serial.write(' '); Serial.print(addr[i], HEX); }
if (OneWire::crc8(addr, 7) != addr[7]) { Serial.println("CRC is not valid!"); return; } Serial.println(); // the first ROM byte indicates which chip switch (addr[0]) { case 0x10: Serial.println(" Chip = DS18S20"); // or old DS1820 type_s = 1; break; case 0x28: Serial.println(" Chip = DS18B20"); type_s = 0; break; case 0x22: Serial.println(" Chip = DS1822"); type_s = 0; break; default: Serial.println("Device is not a DS18x20 family device."); return; } {Serial.print(now.day(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.year(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); }
ds.reset(); ds.select(addr); ds.write(0x44,1); // start conversion, with parasite power on at the end delay(1000); // maybe 750ms is enough, maybe not // we might do a ds.depower() here, but the reset will take care of it. present = ds.reset(); ds.select(addr); ds.write(0xBE); // Read Scratchpad
Serial.print(" Data = "); Serial.print(present,HEX); Serial.print(" "); for ( i = 0; i < 9; i++) { // we need 9 bytes data[i] = ds.read(); Serial.print(data[i], HEX); Serial.print(" "); } Serial.print(" CRC="); Serial.print(OneWire::crc8(data, 8), HEX); Serial.println();
// convert the data to actual temperature
unsigned int raw = (data[1] << 8) | data[0]; if (type_s) { raw = raw << 3; // 9 bit resolution default if (data[7] == 0x10) { // count remain gives full 12 bit resolution raw = (raw & 0xFFF0) + 12 - data[6]; } } else { byte cfg = (data[4] & 0x60); if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms // default is 12 bit resolution, 750 ms conversion time } celsius = (float)raw / 16.0; fahrenheit = celsius * 1.8 + 32.0; Serial.print(" Temperature = "); Serial.print(celsius); Serial.print(" Celsius, "); Serial.print(fahrenheit); Serial.println(" Fahrenheit"); lcd.begin(20,4); // columns, rows. use 16,2 for a 16x2 LCD, etc. lcd.clear(); // start with a blank screen lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row) lcd.print(now.day(), DEC); lcd.print('/'); lcd.print(now.month(), DEC); lcd.print('/'); lcd.print(now.year(), DEC); lcd.print(' '); lcd.print(now.hour(), DEC); lcd.print(':'); lcd.print(now.minute(), DEC); lcd.print(':'); lcd.print(now.second(), DEC); lcd.setCursor(0,1); // set cursor to column 0, row 1 lcd.print(t = dht.readTemperature()); lcd.setCursor(6,1); // set cursor to column 0, row 3 lcd.print("*C"); lcd.setCursor(0,2); // set cursor to column 0, row 2 lcd.print(h = dht.readHumidity()); lcd.setCursor(6,2); // set cursor to column 0, row 3 lcd.print("%RH"); lcd.setCursor(0,3); // set cursor to column 0, row 3 lcd.print(celsius = (float)raw / 16.0); lcd.setCursor(6,3); // set cursor to column 0, row 3 lcd.print("*C"); lcd.setCursor(12,3); // set cursor to column 0, row 3 lcd.print("temp ext"); h = dht.readHumidity(); t = dht.readTemperature(); if (isnan(t) || isnan(h)){ Serial.println( "Lecture impossible !"); }else{ Serial.print("Humidite :"); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature :"); Serial.print(t); Serial.println(" *C"); } delay(1000); } Pour l'instant je n'arrive pas à comprendre pourquoi les secondes se rafraichissent toutes les 4 secondes. Et comment passer au niveaux des chiffres de 1 à 01 par exemple 01/01/2013 et pas 1/1/2013
|
|
|
|
|
4
|
International / Français / Integrer Horloge DS1307 à mon sketch
|
on: January 29, 2013, 11:44:46 am
|
Salut à tous Voila je viens de recevoir mon tiny RTC, j'utilise pour le moment un arduino nano avec divers capteurs, j'ai pu faire fonctionner l'horloge mais IMPOSSIBLE d' avoir l'heure ET la date... Voici mon sketch, si quelqu'un peut m'aider à integrer l'heure et date sur mon LCD c'est pas de refus. J'ai fouillé partout sur le net et à chaque fois il y a un truc qui va pas (comme la mise en memoire de la date en cas de coupure d'alim) #define DHTPIN 3 // sonde dht (t/rh) #define DHTTYPE DHT22 //#define DHTTYPE DHT11 (capteur DHT11) #include <OneWire.h> //capteur t #include <LiquidCrystal.h> //lcd #include <DHT.h> //capteur dht DHT dht(DHTPIN, DHTTYPE); float h = 0; float t = 0;
OneWire ds(4); //capteur t LiquidCrystal lcd(5, 6, 7, 8, 9, 10, 11); int backLight = 12; // pin 13 will control the backlight
void setup(void) { Serial.begin(9600); //capteur t dht.begin(); //capteur dht pinMode(backLight, OUTPUT); digitalWrite(backLight, HIGH); // turn backlight on. lcd.begin(20,4); // columns, rows.
}
void loop(void) { byte i; byte present = 0; byte type_s; byte data[12]; byte addr[8]; float celsius, fahrenheit; if ( !ds.search(addr)) { Serial.println("No more addresses."); Serial.println(); ds.reset_search(); delay(250); return; } Serial.print("ROM ="); for( i = 0; i < 8; i++) { Serial.write(' '); Serial.print(addr[i], HEX); }
if (OneWire::crc8(addr, 7) != addr[7]) { Serial.println("CRC is not valid!"); return; } Serial.println(); // the first ROM byte indicates which chip switch (addr[0]) { case 0x10: Serial.println(" Chip = DS18S20"); // or old DS1820 type_s = 1; break; case 0x28: Serial.println(" Chip = DS18B20"); type_s = 0; break; case 0x22: Serial.println(" Chip = DS1822"); type_s = 0; break; default: Serial.println("Device is not a DS18x20 family device."); return; }
ds.reset(); ds.select(addr); ds.write(0x44,1); // start conversion, with parasite power on at the end delay(1000); // maybe 750ms is enough, maybe not // we might do a ds.depower() here, but the reset will take care of it. present = ds.reset(); ds.select(addr); ds.write(0xBE); // Read Scratchpad
Serial.print(" Data = "); Serial.print(present,HEX); Serial.print(" "); for ( i = 0; i < 9; i++) { // we need 9 bytes data[i] = ds.read(); Serial.print(data[i], HEX); Serial.print(" "); } Serial.print(" CRC="); Serial.print(OneWire::crc8(data, 8), HEX); Serial.println();
// convert the data to actual temperature
unsigned int raw = (data[1] << 8) | data[0]; if (type_s) { raw = raw << 3; // 9 bit resolution default if (data[7] == 0x10) { // count remain gives full 12 bit resolution raw = (raw & 0xFFF0) + 12 - data[6]; } } else { byte cfg = (data[4] & 0x60); if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms // default is 12 bit resolution, 750 ms conversion time } celsius = (float)raw / 16.0; fahrenheit = celsius * 1.8 + 32.0; Serial.print(" Temperature = "); Serial.print(celsius); Serial.print(" Celsius, "); Serial.print(fahrenheit); Serial.println(" Fahrenheit"); lcd.begin(20,4); // columns, rows. use 16,2 for a 16x2 LCD, etc. lcd.clear(); // start with a blank screen lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row) lcd.print("Heure Date"); // change this text to whatever you like. keep it clean. lcd.setCursor(0,1); // set cursor to column 0, row 1 lcd.print(t = dht.readTemperature()); lcd.setCursor(6,1); // set cursor to column 0, row 3 lcd.print("*C"); lcd.setCursor(0,2); // set cursor to column 0, row 2 lcd.print(h = dht.readHumidity()); lcd.setCursor(6,2); // set cursor to column 0, row 3 lcd.print("%RH"); lcd.setCursor(0,3); // set cursor to column 0, row 3 lcd.print(celsius = (float)raw / 16.0); lcd.setCursor(6,3); // set cursor to column 0, row 3 lcd.print("*C"); lcd.setCursor(12,3); // set cursor to column 0, row 3 lcd.print("temp ext"); h = dht.readHumidity(); t = dht.readTemperature(); if (isnan(t) || isnan(h)){ Serial.println( "Lecture impossible !"); }else{ Serial.print("Humidite :"); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature :"); Serial.print(t); Serial.println(" *C"); } delay(5000); } Merci d'avance
|
|
|
|
|