Собственно имеем модуль ds1307 как вывести время в формате 00:00:00 на lcd дисплей например 16, 2 ? Переписав код из примера в библиотеке DS1307 вот этот
#include <Wire.h> #include <DS1307.h> // written by mattt on the Arduino forum and modified by D. Sjunnesson
void setup() { Serial.begin(9600);
//RTC.stop(); //RTC.set(DS1307_SEC,1); //set the seconds //RTC.set(DS1307_MIN,36); //set the minutes //RTC.set(DS1307_HR,15); //set the hours //RTC.set(DS1307_DOW,6); //set the day of the week //RTC.set(DS1307_DATE,12); //set the date //RTC.set(DS1307_MTH,10); //set the month //RTC.set(DS1307_YR,14); //set the year //RTC.start();
}
void loop() {
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true Serial.print(":"); Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false) Serial.print(":"); Serial.print(RTC.get(DS1307_SEC,false));//read seconds Serial.print(" "); // some space for a more happy life Serial.print(RTC.get(DS1307_DATE,false));//read date Serial.print("/"); Serial.print(RTC.get(DS1307_MTH,false));//read month Serial.print("/"); Serial.print(RTC.get(DS1307_YR,false)); //read year Serial.println();
delay(1000);
}
к такому виду
#include <Wire.h> #include <DS1307.h> // written by mattt on the Arduino forum and modified by D. Sjunnesson #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,20,4);
void setup() { lcd.init(); lcd.backlight(); //RTC.stop(); //RTC.set(DS1307_SEC,1); //set the seconds //RTC.set(DS1307_MIN,36); //set the minutes //RTC.set(DS1307_HR,15); //set the hours //RTC.set(DS1307_DOW,6); //set the day of the week //RTC.set(DS1307_DATE,12); //set the date //RTC.set(DS1307_MTH,10); //set the month //RTC.set(DS1307_YR,14); //set the year //RTC.start();
}
void loop() { lcd.setCursor(0, 0); lcd.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true lcd.setCursor(2, 0); lcd.print(":"); lcd.setCursor(3, 0); lcd.print(RTC.get(DS1307_MIN,false));//read minutes without update (false) lcd.setCursor(5, 0); lcd.print(":"); lcd.setCursor(6, 0); lcd.print(RTC.get(DS1307_SEC,false));//read seconds //Serial.print(" "); // some space for a more happy life //Serial.print(RTC.get(DS1307_DATE,false));//read date //Serial.print("/"); //Serial.print(RTC.get(DS1307_MTH,false));//read month //Serial.print("/"); //Serial.print(RTC.get(DS1307_YR,false)); //read year //Serial.println();
}
получаю вот такое. рою поиск но что то не могу понять как сделать, вывод времени вида 00:00:00 . Попой чую что через if {} функцию с перемещением курсора и рисованием ноля, но как?
Упд так сказать. Проблема с нолем в часах так же как и в дате решилась очень просто. Записью значений в переменную с последующим выводом на дисплей через управляющие операторы "if else" Собственно запись в переменную int hour = (RTC.get(DS1307_HR,true)); И вывод на дисплей соответственно с решением проблемы ноля. Если значение часов меньше десяти выводим ноль выводим время. Иначе просто выводим время
Ладно с часами разобрались возникла другая проблема. А проблема эта с датчиком давления bmp085. Суть через несколько часов работы значения высоты уплывают на 30-40 метров вниз.
Код и настройка взяты из примера библиотеки
void setup()
dps.init(MODE_STANDARD, 17810, true); // настройка датчика по высоте
{ dps.getPressure(&dav); // считываем значение давления dps.getAltitude(&alt); // считываем значение высоты dps.getTemperature(&temp); // считываем значение темературы
дальше вывод значений на дисплей
высота вот в таком виде
lcd.print(alt/100);
Сообщение отредактировал konstantin - Среда, 22.10.2014, 20:47
Попробуйте мой скетч. А высота она имхо не нужна... ---------------------------------------------
Код
#include <Wire.h> //#include <dht11.h> #include <LiquidCrystal.h> LiquidCrystal lcd(7, 6, 5, 4, 3, 2); #define BMP085_ADDRESS 0x77 // I2C address of BMP085 #define DS1307_ADDRESS 0x68 const unsigned char OSS = 0; // Oversampling Setting int led = 13; // Calibration values int ac1; int ac2; int ac3; unsigned int ac4; unsigned int ac5; unsigned int ac6; int b1; int b2; int mb; int mc; int md; // b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...) // so ...Temperature(...) must be called before ...Pressure(...). long b5; short temperature; long pressure; void setup() { lcd.begin(16, 2); Wire.begin(); bmp085Calibration(); pinMode(led, OUTPUT); } void loop() { // lcd.clear(); //bmp085 temperature = bmp085GetTemperature(bmp085ReadUT()); pressure = bmp085GetPressure(bmp085ReadUP()); // lcd.setCursor(0, 0); // lcd.print("P="); // int press=pressure/133.3; // lcd.print(press); // lcd.print("mm"); // lcd.setCursor(8, 0); // lcd.print("Tp="); // lcd.print(temperature/10); // lcd.print("oC"); // delay(3000); //отсюда работа с часиками printDate(); // delay(40); } byte bcdToDec(byte val) { // Convert binary coded decimal to normal decimal numbers return ( (val/16*10) + (val%16) ); } void printDate(){ lcd.clear(); digitalWrite(led, HIGH); //цикл под "живые" часики for (int i=0; i<=600; i++){ // Reset the register pointer if (i>=300){digitalWrite(led, LOW);} Wire.beginTransmission(DS1307_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS, 7); int second = bcdToDec(Wire.read()); int minute = bcdToDec(Wire.read()); int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time int weekDay = bcdToDec(Wire.read()); //1-7 -> Sunday - Saturday int monthDay = bcdToDec(Wire.read()); int month = bcdToDec(Wire.read()); int year = bcdToDec(Wire.read()); //Рисуем дату и время на lcd: День/Месяц/Год День недели lcd.setCursor(0, 0); if (monthDay<10) {lcd.print(0);lcd.print(monthDay);} else {lcd.print(monthDay);} lcd.print("/"); if (month==1){lcd.print ("Jan");} if (month==2){lcd.print ("Feb");} if (month==3){lcd.print ("Mar");} if (month==4){lcd.print ("Apr");} if (month==5){lcd.print ("May");} if (month==6){lcd.print ("Jun");} if (month==7){lcd.print ("Jul");} if (month==8){lcd.print ("Aug");} if (month==9){lcd.print ("Sep");} if (month==10){lcd.print ("Oct");} if (month==11){lcd.print ("Nov");} if (month==12){lcd.print ("Dec");} lcd.print("/"); lcd.print(year+2000); if (weekDay==1){lcd.print (" Sun.");} if (weekDay==2){lcd.print (" Mon.");} if (weekDay==3){lcd.print (" Tue.");} if (weekDay==4){lcd.print (" Wed.");} if (weekDay==5){lcd.print (" Thu.");} if (weekDay==6){lcd.print (" Fri.");} if (weekDay==7){lcd.print (" Sat.");} lcd.setCursor(0, 1); if (hour<10) {lcd.print(0);lcd.print(hour);} else {lcd.print(hour);} lcd.print(":"); if (minute<10) {lcd.print(0);lcd.print(minute);} else {lcd.print(minute);} lcd.print(":"); if (second<10) {lcd.print(0);lcd.print(second);} else {lcd.print(second);} lcd.setCursor(9, 1); lcd.print("P="); int press=pressure/133.3; lcd.print(press); lcd.print("mm"); } } // Stores all of the bmp085's calibration values into global variables // Calibration values are required to calculate temp and pressure // This function should be called at the beginning of the program void bmp085Calibration() { ac1 = bmp085ReadInt(0xAA); ac2 = bmp085ReadInt(0xAC); ac3 = bmp085ReadInt(0xAE); ac4 = bmp085ReadInt(0xB0); ac5 = bmp085ReadInt(0xB2); ac6 = bmp085ReadInt(0xB4); b1 = bmp085ReadInt(0xB6); b2 = bmp085ReadInt(0xB8); mb = bmp085ReadInt(0xBA); mc = bmp085ReadInt(0xBC); md = bmp085ReadInt(0xBE); } // Calculate temperature given ut. // Value returned will be in units of 0.1 deg C short bmp085GetTemperature(unsigned int ut) { long x1, x2;
x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15; x2 = ((long)mc << 11)/(x1 + md); b5 = x1 + x2; return ((b5 + 8)>>4); } // Calculate pressure given up // calibration values must be known // b5 is also required so bmp085GetTemperature(...) must be called first. // Value returned will be pressure in units of Pa. long bmp085GetPressure(unsigned long up) { long x1, x2, x3, b3, b6, p; unsigned long b4, b7;
return Wire.read(); } // Read 2 bytes from the BMP085 // First byte will be from 'address' // Second byte will be from 'address'+1 int bmp085ReadInt(unsigned char address) { unsigned char msb, lsb;
return (int) msb<<8 | lsb; } // Read the uncompensated temperature value unsigned int bmp085ReadUT() { unsigned int ut;
// Write 0x2E into Register 0xF4 // This requests a temperature reading Wire.beginTransmission(BMP085_ADDRESS); Wire.write(0xF4); Wire.write(0x2E); Wire.endTransmission();
// Wait at least 4.5ms delay(5);
// Read two bytes from registers 0xF6 and 0xF7 ut = bmp085ReadInt(0xF6); return ut; } // Read the uncompensated pressure value unsigned long bmp085ReadUP() { unsigned char msb, lsb, xlsb; unsigned long up = 0;
// Write 0x34+(OSS<<6) into register 0xF4 // Request a pressure reading w/ oversampling setting Wire.beginTransmission(BMP085_ADDRESS); Wire.write(0xF4); Wire.write(0x34 + (OSS<<6)); Wire.endTransmission();
// Wait for conversion, delay time dependent on OSS delay(2 + (3<<OSS));