Alarm library and RTC in logging shield

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

It is the capital M.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Alarm library and RTC in logging shield

Post by adafruit_support_rick »

Oops - it's supposed to be "minute()" - no caps.

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

Going back to the stop switch, earlier in this thread: I have arranged that an "X" changes to "Y" on the LCD every 10 seconds so that I can see that the readings have not frozen; this is done with an Alarm.timerRepeat. When I use the stop switch after the program has been running for days and remove the SD card, the LCD screen goes blank after some seconds. On replacing the SD card and releasing the stop switch, the screen remains blank - program seems to have crashed. If I remove and replace the supply, with the stop switch set, the screen shows the readings but updates every 10 seconds. So it seams that having the stop sequence at the start of the loop is ineffective because the two Alarm.timerRepeat sequences operate outside of loop control?
I am ging to try including the "Stop" sequence at the start of the Repeat functions too.

Code: Select all

while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
        stopped = true; 
      }
      stopped = false;  //stop switch is turned off

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

Tried that - LCD goes blank after about 10 seconds. But reads again as soon as the stop switch is released - maybe that is OK then, except that I don't know WHY it goes blank. I don't actually need the display while stopped.

Code: Select all

void Repeat2(){
   while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
        stopped = true; 
      }
      stopped = false;  //stop switch is turned off
    
  Run ++ ;
  if (Run > 1) {
    lcd.setCursor(15, 0);
    lcd.print("X");
    Run=0 ;
  }
  else {
    lcd.setCursor(15, 0);
    lcd.print("Y");
  }
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Alarm library and RTC in logging shield

Post by adafruit_support_rick »

I have no idea why the lcd would go blank. If you post your entire sketch, I'll take a look

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

Thank you Rick.
I would like to know how the LCD retains its display. Is it being refreshed the whole time a program is running? But it does keep displaying when the STOP is operational. (And I think, in the past, it has been longer than 10 seconds.)
The reason that I ask is that I would like to make the LCD display show maximum and minimum values interposed with the current readings, which are polled at 30 minute intervals. I wonder if I can write some code to effect this without disturbing the half-hourly capture. It would be nice if the display could show 10 seconds of the last half-hourly readings followed by 10 seconds of the newly calculated max and Min.
Here is the code.

Code: Select all

#include <avr/wdt.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <RTClib.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <Adafruit_RGBLCDShield.h>
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
#define PIN 3  // the pin for button/ rain gauge
#define STOP_SWITCH 2
 bool stopped = false;
RTC_DS1307 RTC;
time_t syncProvider()     //this does the same thing as RTC_DS1307::get()
{
  return RTC.now().unixtime();
}
uint32_t syncTime = 0; // time of last sync()

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging files
File logfile;
File rainfile;
void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  while(1);
}

 long mon=0;
 int dy=0;
 int hr=0;
 int mn=0;
 int sec=0;
volatile int flag=0;
int nflag;
int Run = 0;
int test = 1;
int nutim = 0;
int oldtim = 0;
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

#define BMP085_ADDRESS 0x77  // I2C address of BMP085
const unsigned char OSS = 1;  // Oversampling Setting
// 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;
byte fetch_humidity_temperature(unsigned int *p_Humidity, unsigned int *p_Temperature);

void setup()
{
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
  RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  setSyncProvider(syncProvider);     //reference our syncProvider function instead of RTC_DS1307::get()

  //configure pin2 as an input and enable the internal pull-up resistor
      pinMode(STOP_SWITCH, INPUT_PULLUP);
      
  // initialize the SD card
  Serial.print("InitSD");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) 
  {
    error("Cd fail");
  }
  Serial.println("cdinit.");
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) 
  {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!    
    }
  }

  if (! logfile) {
    error("No lgfile");
  }

  Serial.print("Log to ");
  Serial.println(filename);
  Serial.println();

  // create a new file
  char filename2[] = "RAINEY00.CSV";
  for (uint8_t i = 0; i < 100; i++) 
  {
    filename2[6] = i/10 + '0';
    filename2[7] = i%10 + '0';
    if (! SD.exists(filename2)) {
      // only open a new file if it doesn't exist
      rainfile = SD.open(filename2, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
//This should work but does not - why?
 /*  if (! rainfile) {
   error("couldnt create rnfile");
   }
  */ 
  Serial.print("Log to ");
  Serial.println(filename2);
  Serial.println();

  bmp085Calibration();

  pinMode(PIN, INPUT);     //set the pin to input
  digitalWrite(PIN, LOW); //use the internal pullup resistor
  PCintPort::attachInterrupt(PIN, burpcount,RISING); // attach a PinChange Interrupt to our pin on the rising edge
  // (RISING, FALLING and CHANGE all work with this library)
  // and execute the function burpcount when that pin changes 

  DateTime now;
 Serial.println(minute());
  while (minute() != 0) //Prog holds here until the hour.
  {
    delay(1000);
  }
  Alarm.timerRepeat(1800, Repeats);
  Alarm.timerRepeat(10, Repeat2);
  Repeats();// Adafruit Rick says this will call the function immediately, thus giving readings at startup.
  wdt_enable(WDTO_8S);
}

void loop(){
   if (LOW == digitalRead(STOP_SWITCH)){
         logfile.flush(); 
         rainfile.flush();
         Serial.println("flush");
   }
   
  while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
        stopped = true; 
      }
      stopped = false;  //stop switch is turned off
    
  Alarm.delay(0); // wait 0 seconds - something needed here or
 
  if (flag != nflag){    

  DateTime now = RTC.now();
  mon=now.month();
  dy=now.day();
  hr=now.hour();
  mn=now.minute();
  sec=now.second();
  nutim = mn;
if((nutim - oldtim) >= 2){
  test = 1;}
  oldtim = mn;
      Serial.print(flag);
      Serial.print(",");    
      Serial.print(mon);
      Serial.print('/');
      Serial.print(dy);
      Serial.print(' ');
      Serial.print(hr);
      Serial.print(':');
      Serial.print(mn);
      Serial.print(':');
      Serial.print(sec);
      Serial.println();
      lcd.setCursor(8, 0);
      lcd.print(" Rn");
      lcd.print(flag);

     
      rainfile.print(flag);
      rainfile.print(",");
      rainfile.print(mon);
      rainfile.print('/');
      rainfile.print(dy);
      rainfile.print(' ');
      rainfile.print(hr);
      rainfile.print(':');
      rainfile.print(mn);
      rainfile.print(':');
      rainfile.print(sec);
      rainfile.println();
       
    if (test == 1){
    rainfile.flush(); 
    Serial.println("flushed");
    }
    test = 0;
  }  
   nflag = flag;
   wdt_reset();
}

void Repeats(){
   while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
        stopped = true; 
      }
      stopped = false;  //stop switch is turned off
    
  Serial.println("30 minute timer"); 
  byte _status;
  unsigned int H_dat, T_dat;
  float RH, T_C;
  _status = fetch_humidity_temperature(&H_dat, &T_dat);
  RH = (float) H_dat * 6.10e-3;
  T_C = (float) T_dat * 1.007e-2 - 40.0;
  // fetch the time
  //now = RTC.now(); 
  logfile.print(day(), DEC);
  logfile.print("/");
  logfile.print(month(), DEC);
  logfile.print("/");  
  logfile.print(year(), DEC);
  logfile.print(" ");
  logfile.print(hour(), DEC);
  logfile.print(":");
  logfile.print(minute(), DEC);
  logfile.print(":");
  logfile.print(second(), DEC);
  logfile.print(",");

 temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());

  Serial.print(hour(), DEC);
  Serial.print(":");
  Serial.print(minute(), DEC);
  Serial.print(":");
  Serial.println(second(), DEC);


  logfile.print(T_C, 2);
  logfile.print(",");    
  logfile.print(RH, 1);
  logfile.print(",");
  logfile.print(pressure, DEC); 
  logfile.print(RH, 1);
  logfile.println();
  logfile.flush();  
  
 
  Serial.print("Pres ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");

  lcd.setCursor(0, 0);
  lcd.print("P ");
  lcd.print(pressure, DEC);
  lcd.setCursor(0, 1);
  lcd.print("RH ");
  lcd.print(RH, 1);
  lcd.print(" ");
  lcd.print("T ");
  lcd.print(T_C, 2);

  Serial.print("RH ");
  Serial.print(RH, 1);
  Serial.print("  T ");
  Serial.println(T_C, 2);
  Serial.println();
}

void Repeat2(){
   while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
        stopped = true; 
      }
      stopped = false;  //stop switch is turned off
    
  Run ++ ;
  if (Run > 1) {
    lcd.setCursor(15, 0);
    lcd.print("X");
    Run=0 ;
  }
  else {
    lcd.setCursor(15, 0);
    lcd.print("Y");
  }
}

void burpcount()
{
  flag++; 
} 
// 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;

  b6 = b5 - 4000;
  // Calculate B3
  x1 = (b2 * (b6 * b6)>>12)>>11;
  x2 = (ac2 * b6)>>11;
  x3 = x1 + x2;
  b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;

  // Calculate B4
  x1 = (ac3 * b6)>>13;
  x2 = (b1 * ((b6 * b6)>>12))>>16;
  x3 = ((x1 + x2) + 2)>>2;
  b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;

  b7 = ((unsigned long)(up - b3) * (50000>>OSS));
  if (b7 < 0x80000000)
    p = (b7<<1)/b4;
  else
    p = (b7/b4)<<1;

  x1 = (p>>8) * (p>>8);
  x1 = (x1 * 3038)>>16;
  x2 = (-7357 * p)>>16;
  p += (x1 + x2 + 3791)>>4;

  return p;  
}
// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
  unsigned char data;
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission(); 
  Wire.requestFrom(BMP085_ADDRESS, 1);
  while(!Wire.available());
  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;

  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
  Wire.requestFrom(BMP085_ADDRESS, 2);
  while(Wire.available()<2)
    ;
  msb = Wire.read();
  lsb = Wire.read();
  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));
  // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF6);
  Wire.endTransmission();
  Wire.requestFrom(BMP085_ADDRESS, 3);
  // Wait for data to become available
  while(Wire.available() < 3)
    ;
  msb = Wire.read();
  lsb = Wire.read();
  xlsb = Wire.read();  
  up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long)
    xlsb) >> (8-OSS);
  return up;
}

byte fetch_humidity_temperature(unsigned int *p_H_dat, unsigned int *p_T_dat)
{
  byte address, Hum_H, Hum_L, Temp_H, Temp_L, _status;
  unsigned int H_dat, T_dat;
  address = 0x27;
  ;
  Wire.beginTransmission(address); 
  Wire.endTransmission();
  delay(100);

  Wire.requestFrom((int)address, (int) 4);
  Hum_H = Wire.read();
  Hum_L = Wire.read();
  Temp_H = Wire.read();
  Temp_L = Wire.read();
  Wire.endTransmission();

  //_status = (Hum_H >> 6) & 0x03;
  Hum_H = Hum_H & 0x3f;
  H_dat = (((unsigned int)Hum_H) << 8) | Hum_L;
  T_dat = (((unsigned int)Temp_H) << 8) | Temp_L;
  T_dat = T_dat / 4;
  *p_H_dat = H_dat;
  *p_T_dat = T_dat;
  return(_status);
}







User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Alarm library and RTC in logging shield

Post by adafruit_support_rick »

I'm not 100% sure of the logic of this, but I think your problems may coming from your switch bouncing (i.e., making and breaking contact extremely rapidly as you are moving it to the closed position). This is a very common problem with mechanical switches, and the solution is referred to as 'de-bouncing'.

Before I get to that, let me back up a bit and address your "while (LOW == digitalRead(STOP_SWITCH))" logic. First of all, you don't need that in Repeats and Repeat2, because those functions are indirectly called from loop through Alarm.delay(). If loop() is stopped, then the repeat functions will not be called.

Second, you have a hole in your logic here, known as a 'race condition'.

Code: Select all

void loop(){
   if (LOW == digitalRead(STOP_SWITCH)){
         logfile.flush(); 
         rainfile.flush();
         Serial.println("flush");
   }
   
  while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
        stopped = true; 
      }
      stopped = false;  //stop switch is turned off
It is possible to flip your stop switch in-between the "if" and the "while". If that happens, then your sketch will stop without flushing your files, and you will be none the wiser until you discover that some of your data is missing. Here's a safer way to do it:

Code: Select all

void loop(){
  if (LOW == digitalRead(STOP_SWITCH)){
    logfile.flush(); 
    rainfile.flush();
    Serial.println("flush");

    while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
      stopped = true; 
    }
  }
  stopped = false;  //stop switch is turned off
Now, we can address the switch bounce. The fix involves nothing more than waiting a few milliseconds for the switch to stop bouncing:

Code: Select all

void loop(){
  if (LOW == digitalRead(STOP_SWITCH)){
    logfile.flush(); 
    rainfile.flush();
    Serial.println("flush");

    delay(10);  //switch de-bounce interval
    
    while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
      stopped = true; 
    }

    delay(10);  //switch de-bounce interval
  }
  stopped = false;  //stop switch is turned off
So, substitute that code block, and remove the STOP_SWITcH tests from Repeats and Repeat2, and see if that helps with the LCD problem.
Spiney wrote:I would like to know how the LCD retains its display. Is it being refreshed the whole time a program is running? But it does keep displaying when the STOP is operational. (And I think, in the past, it has been longer than 10 seconds.)
The display is maintained by the driver chip attached to the display. There's no way that it's going to "time out" and go blank. I think that was some kind of artifact of your bouncy switch and STOP_SWITCH logic.
Spiney wrote:I wonder if I can write some code to effect this without disturbing the half-hourly capture. It would be nice if the display could show 10 seconds of the last half-hourly readings followed by 10 seconds of the newly calculated max and Min.
I think you can just do that in the Repeat2 function.

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

Doh! Could it be that

Code: Select all

wdt_enable(WDTO_8S);
negates the stop switch? I measured 9 seconds from setting the switch to the display going blank.
When the stop switch is released Setup runs and opens new SD files.

This fixed the problem.

Code: Select all

while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
        stopped = true; 
        wdt_disable();
      }
But I trust that wdt is re-enabled outside of the While loop? How can I check that?

Thank you, I have included the de-bounce anyway - good practice no doubt.
I have found Rob Tillaart's Statistics library - that might do the Max and Min for me.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Alarm library and RTC in logging shield

Post by adafruit_support_rick »

Ohhhhhh! You got the watchdog enabled! I forgot about that. Yes - that would certainly explain the display reset.

Actually, you don't want wdt_disable() in the loop, you want wdt_reset(). That way, the watchdog is never disabled.

Code: Select all

while (LOW == digitalRead(STOP_SWITCH)) {  //stick here until stop switch is turned off.
        stopped = true; 
        wdt_reset();
      }
Do you want daily Max and Min? As in, they reset at midnight? Or do you want Max and Min for the preceding 24 hours?

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

Thank you.
I have changed to reset. Does that mean that the watchdog is reset at the repetition rate of the loop for the whole time that the stop switch is active?

I thought that I might try for both Yesterday's max and min and also Today's current updating max and min if I can manage the code and if I don't run out of program space and SRAM.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Alarm library and RTC in logging shield

Post by adafruit_support_rick »

Yes, you're resetting the watchdog at that rate. Which is perfectly OK. The whole idea with the watchdog is to keep resetting it so it doesn't time out.

You can keep track of the min and max in Repeats() like this:

Code: Select all

temperature = bmp085GetTemperature(bmp085ReadUT());
maxTemperature = max(temerature, maxTemperature);
minTemperature = min(temperature, minTemperature);
Copy to yesterday's max & min at midnight, and reset.

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

Great! Thank you.
Work done - almost.

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

I tried your max and min suggestion and I get a strange answer. Here is the code followed by the monitor result.
Is that a binary temperature?

Code: Select all

void Repeats(){
    
  byte _status;
  unsigned int H_dat, T_dat;
  float RH, T_C;
  _status = fetch_humidity_temperature(&H_dat, &T_dat);
  RH = (float) H_dat * 6.10e-3;
  T_C = (float) T_dat * 1.007e-2 - 40.0;
  // fetch the time
  //now = RTC.now(); 
  logfile.print(day(), DEC);
  logfile.print("/");
  logfile.print(month(), DEC);
  logfile.print("/");  
  logfile.print(year(), DEC);
  logfile.print(" ");
  logfile.print(hour(), DEC);
  logfile.print(":");
  logfile.print(minute(), DEC);
  logfile.print(":");
  logfile.print(second(), DEC);
  logfile.print(",");

 temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  
 maxTemperature = max(temperature, maxTemperature);
    minTemperature = min(temperature, minTemperature);
    
  Serial.print(hour(), DEC);
  Serial.print(":");
  Serial.print(minute(), DEC);
  Serial.print(":");
  Serial.println(second(), DEC);


  logfile.print(T_C, 2);
  logfile.print(",");    
  logfile.print(RH, 1);
  logfile.print(",");
  logfile.print(pressure, DEC); 
  logfile.print(RH, 1);
  logfile.println();
  logfile.flush();  
  
 
  Serial.print("Pres ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");

  lcd.setCursor(0, 0);
  lcd.print("P ");
  lcd.print(pressure, DEC);
  lcd.setCursor(0, 1);
  lcd.print("RH ");
  lcd.print(RH, 1);
  lcd.print(" ");
  lcd.print("T ");
  lcd.print(T_C, 2);

  Serial.print("RH ");
  Serial.print(RH, 1);
  Serial.print("  T ");
  Serial.println(T_C, 2);
  Serial.println();
  Serial.print("Max" );
  Serial.print(maxTemperature, 2); 
  Serial.println();
  Serial.print("Min" );
  Serial.print(minTemperature, 2);
}

Code: Select all

InitSDcdinit.
Log to LOGGER56.CSV

Log to RAINEY55.CSV

58
16:0:28
Pres 100824 Pa
RH 54.2  T 19.76

Max11000111
Min0InitSDcdinit.
Log to LOGGER57.CSV

Log to RAINEY56.CSV

2
16:4:38
Pres 100824 Pa
RH 54.7  T 19.83

Max11001000
Min016:6:38
Pres 100821 Pa
RH 55.1  T 19.90

Max11001000
Min0

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Alarm library and RTC in logging shield

Post by adafruit_support_rick »

You must have maxTemperature and minTemperature declared as integer instead of float

When the first argument to print() is an integer, the second argument is interpreted as the number base to use. So '2' gives you a binary number.

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: Alarm library and RTC in logging shield

Post by spiney »

Thank you.
Evidently I need to do some homework on declarations. But I don't understand why the T_C and RH lines work to give me 2 and 1 decimal places.

Where does the max and min function come from?

Having inserted the max and min lines, I am finding that the setup runs sometimes, so probably the program sometimes hangs and is then watchdogged back. I shall check again for SRAM usage.

Code: Select all

 byte _status;
  unsigned int H_dat, T_dat;
  float RH, T_C;
  _status = fetch_humidity_temperature(&H_dat, &T_dat);
  RH = (float) H_dat * 6.10e-3;
  T_C = (float) T_dat * 1.007e-2 - 40.0;



 Serial.print("RH ");
  Serial.print(RH, 1);
  Serial.print("  T ");
  Serial.println(T_C, 2);

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”