Go Down

Topic: RTC, logging shield (Read 461 times) previous topic - next topic

jogeir1959

Good Morning, evening, what ever :-)

Refering to this (nice and easy one):
https://www.instructables.com/id/Arduino-Easy-Weather-Station-With-BME280-Sensor/

qouting
I did post the following question:
Nice and easy project, thank you.
What I like to do, but do not have the knowledge to do, is to stack another shield,
"XD-204 Data Logger Shield | RTC | Data Logger for Arduino UNO" from ebay.
I did try to write my code myself, but ........
Anyone outthere can help out with that, will be most appreciated :-)
end qouting

The instructables is quite old, so I did not get any answer, I am sure this is an easy one
for most of you out there, so I hope some kind soule can help me out :-)

Thank You.

jogeir1959

Here is a sketch I have so far, an Arduino UNO, RTC logging shield and a key pad LCD shield stacked.
And a BMP180 sensor.
This one works, but suggestions to add logging to this.
I did try meny things but non of them works, so a clue how to do it would be nice.

Thank You.

jogeir1959

#include <SFE_BMP180.h>
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Keypad Shield
SFE_BMP180 pressure;
RTC_DS1307 RTC;
#define BMP (0x77));
#define DS3231_I2C_ADDRESS 0x68
// Altitude of home.
#define ALTITUDE 60.0
char daysOfTheWeek[7][12] = {"Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
void setup()
{
 Serial.begin(9600);
 lcd.begin(16, 2);
 Wire.begin();
 RTC.begin();

 lcd.clear();
 lcd.setCursor(15, 1);
 lcd.print("C");
 lcd.setCursor(7, 1);
 lcd.print("mb");
 {
   // sets time and date data to DS3231
   Wire.beginTransmission(DS3231_I2C_ADDRESS);
   Wire.write(0); // set next input to start at the seconds register

   Wire.endTransmission();
 }

 Serial.println(); // New line
 Serial.print("Provided Altitude:\n");
 Serial.print(ALTITUDE, 0);
 Serial.print(" meters, ");
 Serial.print(ALTITUDE * 3.28084, 0);
 Serial.println(" feet\n");
 Serial.print("Read BMP180 Pressure Sensor:\n");

 if (pressure.begin())
   Serial.println("BMP180 init success");
 else
 {
   Serial.println("BMP180 init fail\n\n");
   while (1); // Pause forever.
 }
}

void loop()
{

 char status;
 double T, P, p0, a;
 Serial.println(); // New line

 status = pressure.startTemperature();
 if (status != 0)
 {

   DateTime now = RTC.now();
   char dateBuffer[12];

   sprintf(dateBuffer, "%02u-%02u-%04u ", now.day(), now.month(), now.year());
   Serial.print(dateBuffer);

   lcd.setCursor(0, 0);
   sprintf(dateBuffer, "%02u-%02u ", now.day(), now.month());
   lcd.print(dateBuffer);

   sprintf(dateBuffer, "%02u:%02u:%02u ", now.hour(), now.minute(), now.second());
   Serial.print(dateBuffer);

   lcd.setCursor(6, 0);
   sprintf(dateBuffer, "%02u:%02u ", now.hour(), now.minute());
   lcd.print(dateBuffer);

   lcd.setCursor(12, 0);
   // lcd.print(now.dayOfTheWeek());
   lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
   Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
   
   //  Serial.println();
   delay(1000);

   // Wait for the measurement to complete:
   delay(status);

   //  Serial.print("Read BMP180 Temperature Sensor:\n");
   status = pressure.getTemperature(T);
   if (status != 0)
   {
     Serial.print(" ");
     Serial.print(T, 2);

     lcd.setCursor(10, 1);
     lcd.print(T, 2);

     Serial.print(" deg C, ");
     Serial.print((9.0 / 5.0)*T + 32.0, 2);
     Serial.print(" deg F  ");

     status = pressure.startPressure(3);
     if (status != 0)
     {
       // Wait for the measurement to complete:
       delay(status);


       status = pressure.getPressure(P, T);
       if (status != 0)
       {
         // Print out the measurement:
         // Serial.print("Absolute Pressure: ");
         Serial.print(P, 2);
         lcd.setCursor(0, 1);
         lcd.print(P, 2);
         Serial.print(" mb, ");
         Serial.print(P * 0.0295333727, 2);
         Serial.print(" inHg");
       }
       else Serial.println("error retrieving pressure measurement\n");
     }
     else Serial.println("error starting pressure measurement\n");
   }
   else Serial.println("error retrieving temperature measurement\n");
 }
 else Serial.println("error starting temperature measurement\n");

 delay(5000);  // Pause for 5 seconds.
}

Delta_G

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up