Show Posts
Pages: 1 [2] 3
16  Forum 2005-2010 (read only) / Interfacing / Re: LM35 thermometer on: October 28, 2008, 06:22:11 pm
Man, that was fast!! smiley

No, I wasn't aware that I needed one... I'm pretty new to all of this electronics stuff! Can you advise me how to work out what type I need?

Cheers!

- EDIT -

OK, so I've solved the fluctuating readings problem - the 5V / 10V power supplies I was using seem to have caused them. As soon as I used the Arduino's 5V supply I got good steady readings.

Now my issue is that the readings seem to be WAY off the mark. Here's the code I'm using (slightly modified from this thread - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203159459):
Code:
/*LM35 Thermometer
 *
 *LM35 simply connected to:           5+
 *                             0V
 *                             Analog Pin 0
 */

int potPin = 0;                             //input read pin for LM35 is Analog Pin 0
float temperature = 0;                      //variable which will be calculated in process

void setup()
{
  Serial.begin(9600);
  Serial.println("LM35 Thermometer    ");       //Print "LM35 Thermometer" once at start
}

void  printTenths( int value){
   // prints a value of  123 as 12.3
      Serial.print(value / 10);
      Serial.print(".");
      Serial.println( value % 10);              
}

void loop ()                              
{
  int span = 20;
  int aRead = 0;
  for (int i = 0; i < span; i++) {        //loop to get average of 20 readings
    aRead = aRead + analogRead(potPin);
}
  aRead = aRead / span;

  temperature = (5.220*aRead*100/1024);           //convert voltage to temperature
  Serial.print ("Analog in reading: ");
  Serial.print (long(aRead));       //print temperature value on serial screen
    Serial.print (" - Calculated Temp: ");
    printTenths(long(temperature));
    
  delay(500);
}


At room temp (around 22 degrees C), I get a fairly steady output of:

Analog in reading: 927 - Calculated Temp: 47.2
Analog in reading: 927 - Calculated Temp: 47.2
Analog in reading: 928 - Calculated Temp: 47.3
Analog in reading: 927 - Calculated Temp: 47.2


Firstly, I thought that there must be a problem in the equation which calculates the temperature, but then I realised that the analog readings were way too high to be correct on this scale in the first place. I'd be expecting readings somewhere around 140 for room temperature..? From the LM35 datasheet, the LM35 should give a temperature range of +2 to +150 deg C in the Basic configuration, so a reading of 927 works out at around 136 degrees!! Can anyone help me get the correct numbers from the analog input?!?

Thanks for reading!
17  Forum 2005-2010 (read only) / Interfacing / Re: LM35 thermometer on: October 28, 2008, 06:17:20 pm
Hi everyone,

I've been trying to implement this type of LM35 temperature sensor into my project but I'm getting some really erratic output. Using either a 5V or 10V input (and adjusting the conversion equation as required) I get output like this:

LM35 Thermometer    
analog value - computed temp
1013 - 49.4
835 - 40.7
312 - 15.2
879 - 42.9
93 - 4.5
842 - 41.1
87 - 4.2
882 - 43.0
87 - 4.2
880 - 42.9
107 - 5.2
918 - 44.8
93 - 4.5
930 - 45.4
50 - 2.4
1020 - 49.8
721 - 35.2
419 - 20.4
905 - 44.1
26 - 1.2
970 - 47.3

And these values are the averages of 10 readings. If I remove the sensor, the readings stabilise, but not in a useful fashion, plus I need the sensor located away from the board. Any ideas as to what may be causing these fluctuating readings?  :-?
18  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 11, 2008, 12:24:36 am
Ha ha - I'm glad you sent this & confirmed that what took me HOURS to work out for myself was correct!! smiley SLIGHTLY frustrating, but I can be philosophical - I'll call it a lesson well learned!! :-[

Cheers,

JB
19  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 10, 2008, 07:56:53 pm
Hi Mickal,

Thanks for the explanation, I think I'm up to speed with what's happening within the function now.

I agree that using a terminator like '.' isn't the most elegant solution, so I'll have a go at forcing the user to enter a two-digit number between 00 and 23.

Quote
(although if you are writing the computer interface as well -- and you probably are -- you could easily rectify this)
I'm afraid you give me WAY too much credit - I'm just planning on using the Arduino serial console for data entry. Although, if you can recommend something pre-existing ...?  :-? In the end, I need this software to be usable by others with VERY minimal computer skills, so I'm trying to do whatever I can to make it easier for them.

I'll let you know how I go with forcing the 2-digit input; would appreciate your thoughts on how I've gone about it when it's done.

Thanks again,

JB
20  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 10, 2008, 06:08:27 pm
@ kg4wsv:

Yeah, I did wonder about that, but I don't have the smarts yet to work out how to recognise that is the source of the problem...

@ mikal:

It's called 'The Noob-iverse'; nice place to visit but you wouldn't want to live there... smiley-wink Hopefully I'm 'just passing through'!!

Forgive my ignorance, but how does the ReadNumber() function return 2-digit numbers if it only calls Serial.read() once? If I call ReadNumber() from the loop and enter a 2 digit number, I get two single digit numbers returned instead of one 2 digit number. Am I calling it wrong or do I need a second Serial.read() within the function to read the second digit? (I will add testing later to make sure the input is between 1 & 24).

Here's what I'm working with:
Code:
#include <Wire.h>

int ReadNumber() {
  int number = 0;
  while (true) {
    while (!Serial.available()) ; // wait for a character
    int c = Serial.read();
    if (c >= '0' && c <= '9') // is it a digit?
        number = 10 * number + c - '0';
    else if (c == '\r') // is it the terminating newline?
      return number;
    else if (c == 'f') // are we all done?
      return -1;
  Serial.print("Number entered = ");
  Serial.println(number);
  number = 0;
  }
  return -1;
}

void setup() {
  Serial.begin(115200);
  Wire.begin();
}

void loop() {

  int PhotoTime = ReadNumber();
      Serial.print("    PhotoTime = ");
      Serial.println(PhotoTime);
}
Also noted that ReadNumber always returns '-1' when I enter 'f' to end the function. How do I pass the number I entered back to the main loop? I can see the 'return number' code, but it doesn't seem to be working as I'd like...

Thanks again folks,

JB
21  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 10, 2008, 12:07:26 am
OK, need more help now...

Can anyone tell me why the following code works fine with the Serial.println("Debug - X"); lines, but then won't accept numbers above 9 without them?!?
Code:
#include <Wire.h>

char incoming;                                      // incoming serial data
int i=0;
int g=0;
int H=0;                                            // variables to calculate photo times in 24-hour format
int HH=0;
int PhotoTime[2] = {0,0};                           // variable for photo times to be written into PhotoTimes[] array.
int PhotoTimes[10] = {0,0,0,0,0,0,0,0,0,0};         // array of times to take photos; default times will be 10am & 3pm.
boolean PhotoTimesEntered = false;

void setup() {

 Serial.begin(115200);
 Wire.begin();
 i=0; // reset the array index
}

void loop() {  // get photo times from the user
Serial.println("Debug 1 - ");  Serial.println("LCRACS initialization - enter hour (in 24-hour format) for first photo, or 'f' to finish, using standard photo times (10am and 3pm): -> ");
Serial.println("Debug 2 - ");  for ( int ecount = 0; ecount <= 9; ecount++ ) {
Serial.println("Debug 4 - ");      while ( Serial.available() < 1 ) {;}
Serial.println("Debug 5 - ");        if ( Serial.available() < 2) {
Serial.println("Debug 6 - ");          incoming = Serial.read();
Serial.println("Debug 7 - ");          if ( '0' <= incoming >= '9' ) {
Serial.println("Debug 8 - ");            Serial.print(" INVALID ENTRY - enter 'F' or 1 - 23 only! -> ");
Serial.println("Debug 9 - ");            break;
Serial.println("Debug 10 - ");          }
Serial.println("Debug 11 - ");          HH = (incoming - 48);    //  minus 48 to convert from ASCII value to decimal value to be stored in PhotoTimes
Serial.println("Debug 12 - ");        }
      else if ( Serial.available() < 3) {
Serial.println("Debug 13 - ");        PhotoTime[0]=Serial.read();
Serial.println("Debug 14 - ");        PhotoTime[1]=Serial.read();
Serial.println("Debug 15 - ");        if ( '0' < PhotoTime[0] > '9') { Serial.print(" Invalid ENTRY - enter 'F' or 1 - 23 only! -> "); break;}      // discard non-numerical input
Serial.println("Debug 16 - ");        if ( '0' < PhotoTime[1] > '9') { Serial.print(" INVALID entry - enter 'F' or 1 - 23 only! -> "); break;}      // discard non-numerical input
Serial.println("Debug 17 - ");        H = ((PhotoTime[0] - 48 )*10);                     // convert 1st digit to 10's or 20's
Serial.println("Debug 18 - ");        HH = ( H + (PhotoTime[1] - 48 ));          // add second digit to get input in 24-hour format
Serial.println("Debug 19 - ");        }
      else { Serial.print(" INVALID ENTRY - enter 'F' or 1 - 23 only! -> ");}
Serial.println("Debug 20 - ");        Serial.print("                  Time entered was: "); Serial.println(HH);
Serial.println("Debug 22 - ");        PhotoTimes[i] = HH;
Serial.println("Debug 23 - ");        Serial.print("             PhotoTimes[");Serial.print(i);Serial.print("] value = "); Serial.println(PhotoTimes[i]);
//          Serial.print("LCRACS initialization - enter hour (in 24-hour format) for first photo, or 'f' to finish, using standard photo times (10am and 3pm): -> ");
//          PhotoTimes[i] = PhotoTime; // copy the photo time to the array
Serial.println("Debug 25 - ");          i++; // increase the array index
Serial.println("Debug 26 - ");          if (i > 9) break;
Serial.println("Debug 27 - ");   }
Serial.println("Debug 28 - ");   PhotoTimesEntered = true;
Serial.println("Debug 29 - ");   Serial.println("Photo Times: ");
   for (int count=0; count<=9; count++){
     Serial.print("PhotoTime[");Serial.print(count);Serial.print("] - ");Serial.print(PhotoTimes[count]); Serial.println(":00, ");
   }  Serial.println("");
Serial.println("Debug 33 - ");  delay(50);
}

What this section of code (it will be inserted into the larger program as a function) is supposed to do is accept times from the user from 1 to 24 representing the hour of the day, then put that number, in order, into the array PhotoTimes[10].

This is REALLY annoying me - I thought I'd fixed my problem when everything worked fine with the debug lines in, but as soon as I take them out it stops working properly!?!  >smiley-sad

As always, I'm completely open to (a) having my code picked to pieces, and/or (b) suggestions of better ways to accomplish my goals!

Thanks

JB
22  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 08, 2008, 10:10:15 pm
Thanks j, that's what I figured so I've created a DataDump() function.

There's something about tinkering, isn't there... you can always think of something else to add!

I'm now trying to add a 'setup menu', where the user can enter the hour(s) of the day to take a photo (not worried about mins/secs), rather than having to edit, re-compile & upload the sketch whenever a change is required. I've got the following code which is a bit of a mash-up of other bits I've found on the forums & my own ideas (which are probably what's causing the issues!):
Code:
void EnterPhotoTimes() {  // get photo times from the user

  Serial.println("LCRACS initialization - enter hour (in 24-hour format) for first photo, or 'f'");
  Serial.print("     to finish, using standard photo times (10am and 3pm): -> ");
  i=0; // reset the array index

  while (Serial.available()) {
    incoming = Serial.read();
    while (incoming != 'f') {
    Serial.print(incoming);
      for (int g=0; g <= 9; g++){
        tPhoto[g] = incoming;
        if (tPhoto[g] == 'f') break; // escape character is f
          if ((tPhoto[g] < '0') or (tPhoto[g] > '9')) break; // discard non-numerics
          outbound[i]=incoming; //copy the serial byte to the array
          i++; // increase the array index
          }

      if (i != 0) {      // if the array is not zero, there is data
        outbound[i] = 0; // terminating character <- add this line
        Serial.print(outbound);
        Serial.println("");
        }
 delay(50);
  PhotoTimesEntered == true;
    }
  }
}
What I'm hoping to do is have the user enter the times that they would like the photos taken, with the values entered stored in a 10-byte array (shouldn't need to be taking more than 10 photos a day). I can then compare the array values to the real-time clock & take a photo if the time is right. I imagine that I could possibly work my way through the code above if someone could just let me know how to have the program stay in this 'input' state until the user enters 'f' (or 10 values). At the moment the "LCRACS initialization etc" message displays, then the program merrily goes about it's normal business, not waiting for any input from me.

Thanks again,

JB

- EDIT - Never mind (for now) - I've put in a do...while 'loop' which has gotten me going again. Now just mucking around with recording the input correctly, but I think I should be able to work my way around that on my own... Will call if I need more help! smiley
23  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 08, 2008, 05:46:24 pm
Once again, saved by the forum! void data_dump() procedure which is called from the loop, or is what I've done OK? I'm thinking that it's probably better to have procedure calls in the loop rather than lots of code... any opinions would be greatly appreciated!

Thanks j & Mikal,

JB
24  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 08, 2008, 06:30:25 am
... The section after "MinTemp = 40" below seems to be causing the problems. If I comment this lot out down to the delay my program behaves just fine.

// if (second == 30){
// if (hour == 12) { if (minute == 00) { if (second == 00) {}}
 if (minute == 30){ if (second == 0){
    EEPROM.write(WriteAddress,MinTemp);
    ++WriteAddress;
    Serial.println("                              MinTemp recorded");
    MinTemp = 40;
    }
  }
  // DATA-DUMP: check for any incoming serial input, then proceed only if 'd' is pressed
      if (Serial.available() > 0) {
      incomingByte = Serial.read();      
          if (incomingByte == 100) {
          Serial.println("          Data dump initiated:");
            Serial.print("\t");
            Serial.print("   Date");
            Serial.print("\t");
            Serial.print("MaxTemp");
            Serial.print("\t");
            Serial.println("MinTemp");

            value = EEPROM.read(ReadAddress);
            while (ReadAddress < 511) {
//              Serial.print(ReadAddress);
//              Serial.print("\t");
              Serial.print(value, DEC);
              ReadAddress = ReadAddress + 1;
              value = EEPROM.read(ReadAddress);
              Serial.print("/"); Serial.print(value, DEC);
              ReadAddress = ReadAddress + 1;
              value = EEPROM.read(ReadAddress);
              if(value < 10) {
                Serial.print("/200");}
                else {Serial.print("/20");}
              Serial.print(value, DEC);
              ReadAddress = ReadAddress + 1;
              value = EEPROM.read(ReadAddress);
              Serial.print("\t"); Serial.print("   "); Serial.print(value, DEC);
              ReadAddress = ReadAddress + 1;
              value = EEPROM.read(ReadAddress);
              Serial.print("\t"); Serial.print("   "); Serial.print(value, DEC);
              ReadAddress = ReadAddress + 1;
              Serial.println();
              }
          ReadAddress = 0;
      }
      }
 delay(1000);
}


Just for a quick run-down, the program is designed to take a photo at the pre-programmed times each day. The camera system will be remotely deployed & run off a solar panel & 12V battery. The program monitors temperatures & will switch on fans to cool down the box if the temp goes over 35 degrees Celcius. We're recording the temperatures to see what extremes the camera is being exposed to, as it's just a consumer-grade Canon PowerShot A720IS.

As I mentioned, the program WITHOUT the data dump feature works fine so there's no problems there. Just not sure why the data dump section is corrupting the clock's data!! smiley-sad

Sorry for the lengthy posts and thanks for any ideas!!

JB

PS - by the way, thanks to those of you who recognise the bits of code above that they've contributed to this project!  ;D
25  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 08, 2008, 06:14:58 am
Hi Mikal,

The min temp is actually OK - the grabs I've shown are when the program is displaying output every second, and the Min Temp is calculated over the past 60 seconds.

Well, in the hope that it helps, here's the code...

#include <EEPROM.h>
#include <Wire.h>
#include <math.h>
#include <DateTime.h>

int potPin = 0;                                 // input read pin for LM35 is Analog Pin 0
float temperature = 0;                             // variable which will be calculated in process
long val=0;                                 // variable to store the value coming from the sensor
#define TRIGGER_INACTIVE 0xffffffff              // a special value that indicates that no trigger is active.
unsigned long  endTrigger = TRIGGER_INACTIVE;
#define ThermistorPIN 0                          // Analog Pin 0
double temp;

int MinTemp = 40;       // setting a high initial value makes for easy comparison in the loop,
int MaxTemp = 0;        // and vice versa for a low initial MaxTemp.
int WriteAddress = 0;   // initial address for EEPROM writes.
int ReadAddress = 0;
byte value;             // will be used
int incomingByte = 0;      // for incoming serial data

int hour;
int minute;
int second;
int month;
int day_of_week;
int day;
int year;

char* dow[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

double Thermistor(int RawADC) {
 //    Inputs ADC Value from Thermistor and outputs Temperature in Celsius
 //    requires: include <math.h>
 //    Utilizes the Steinhart-Hart Thermistor Equation:
 //    Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3}
 //    where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08
 long Resistance;  double Temp;  // Dual-Purpose variable to save space.
 Resistance=((10240000/RawADC) - 10000);  // Assuming a 10k Thermistor.  Calculation is actually: Resistance = (1024/ADC)
 Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later. // "Temp" means "Temporary" on this line.
 Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));   // Now it means both "Temporary" and "Temperature"
 Temp = Temp - 273.15;  // Convert Kelvin to Celsius                                         // Now it only means "Temperature"
 return Temp;  // Return the Temperature
}

void printDouble(double val, byte precision) {
  // prints val with number of decimal places determine by precision
  // precision is a number from 0 to 6 indicating the desired decimal places
  // example: printDouble(3.1415, 2); // prints 3.14 (two decimal places)
  Serial.print (int(val));  //prints the int part
  if( precision > 0) {
    Serial.print("."); // print the decimal point
    unsigned long frac, mult = 1;
    byte padding = precision -1;
    while(precision--) mult *=10;
    if(val >= 0) frac = (val - int(val)) * mult; else frac = (int(val) - val) * mult;
    unsigned long frac1 = frac;
    while(frac1 /= 10) padding--;
    while(padding--) Serial.print("0");
    Serial.print(frac,DEC) ;
  }
}

void TakePhoto() {
  int FanStatus = digitalRead(3);
  digitalWrite(3,LOW); // first, switch off the fans
  Serial.print(" Fans switched off - status stored as ");
  if (FanStatus == 0) Serial.println("OFF");
  else Serial.println("ON");
  digitalWrite(9,HIGH); // then send power to the camera
  Serial.println("  Power to Camera");
//  delay(500); // time for current to get to camera - not sure if this is needed...
  digitalWrite(6,HIGH); // trigger the solenoid for 100 msec
  Serial.println("   Solenoid triggered");
  delay(100);
  digitalWrite(6,LOW);
  delay(15000); // wait 15 seconds for the camera to take a photo then shutdown
  digitalWrite(9,LOW);
  Serial.println("    Camera power switched off");
  digitalWrite(3,FanStatus); // return fans to initial status
  Serial.print(" Fans returned to ");
  if (FanStatus == 0) Serial.print("OFF");
  else Serial.print("ON");
  Serial.println(" status");
}

void setup()
{
 pinMode(3,OUTPUT); // FANS control - YELLOW
 digitalWrite(3,LOW);
 pinMode(6,OUTPUT); // SOLENOID power control - WHITE
 digitalWrite(6,LOW);
 pinMode(9,OUTPUT); // CAMERA control - BLUE
 digitalWrite(9,HIGH);
 pinMode(13,OUTPUT);
 Serial.begin(115200);
 Wire.begin();
}

void loop() {

 // Below required to reset the register address to 0.
 Wire.beginTransmission(104); // transmit to device #104, the ds 1307
 Wire.send(0x00);
 Wire.endTransmission();    // stop transmitting

 Wire.requestFrom(104, 7);    // request 7 bytes from slave ds1307, we'll assume it'll send them all even though it doesn't have to
 second = Wire.receive();
 minute = Wire.receive();
 hour = Wire.receive();
 day_of_week=Wire.receive();
 day = Wire.receive();
 month = Wire.receive();
 year = Wire.receive();

 // Convert all the BCD values that might have "tens" to decimal.
 hour=hour/16 * 10 + hour % 16;
 minute=minute/16 * 10 + minute % 16;
 second=second/16 * 10 + second % 16;
 day=day/16 * 10 + day % 16;
 month=month/16 * 10 + month % 16;
 
 year=2000 + year/16 * 10 + year % 16;
 
// Change times below to desired photo times. Copy & paste to add more photos per day.
// NOTE: for some reason, 8's & 9's cause an error, so don't use them on their own below;
// 18 & 19 work fine, but 08 & 09 do not.
 if (hour == 9) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 10) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 11) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 12) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 13) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 14) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 15) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 16) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 17) { if (minute == 00) { if (second == 00) { TakePhoto();}}}
 if (hour == 18) { if (minute == 00) { if (second == 00) { TakePhoto();}}}

 Serial.print(hour);
 Serial.print(":");
 if (minute < 10) { Serial.print("0"); }
 Serial.print(minute);
 Serial.print(":");
 if (second < 10) { Serial.print("0"); }
 Serial.print(second);
 Serial.print(" on ");
 Serial.print(dow[day_of_week]);
 Serial.print(", ");
 Serial.print(day);
 Serial.print("/");
 Serial.print(month);
 Serial.print("/");
 Serial.print(year);

  int span = 20;  int aRead = 0;
  for (int i = 0; i < span; i++) {        //loop to get average of 20 readings
    aRead = aRead + analogRead(ThermistorPIN);
}
  aRead = aRead / span;
  temperature = Thermistor(aRead);
 Serial.print(" - Current temperature is: "); printDouble(temperature,1);     // display Celsius

 Serial.print("; Max - "); printDouble(MaxTemp,1);     // display current MaxTemp
 Serial.print(", Min - "); printDouble(MinTemp,1);     // display current MinTemp
 Serial.println("");

  if( temperature > 35 ){  // is the Temp above 35 degrees Celcius?
      if( endTrigger == TRIGGER_INACTIVE){  // only proceed if no trigger is active.  
        // trigger the fans and store the time to turn off the LED
         digitalWrite(3, HIGH);
    Serial.println("              Threshold Temperature EXCEEDED, switching fans on.");
         endTrigger = DateTime.now() + (1 * 60); // set trigger for 1 minute(s) from now
              // note that DateTime.now() returns seconds since Arduino started
    }
  }
    if( DateTime.now() >= endTrigger ){ // only process this if endTrigger has been set
      if( temperature > 33 ){  // if temp has dropped below 33 degrees Celcius, turn fans off
        Serial.println("   Temperature still above threshold, fans remaining on.");
      endTrigger = DateTime.now() + (1 * 60);
      }      // or, if temp is still above threshold, leave fans on for another minute
      else if( temperature <= 33 ) {Serial.println("   Temperature has dropped below threshold, fans switched OFF.");
      digitalWrite(3,LOW);
      endTrigger = TRIGGER_INACTIVE;
      }
    }

// Now need a loop to read the temperature in the box, work out a daily MinTemp & MaxTemp, and record to EEPROM memory.
// This needs to repeat every day.

  if( temperature > MaxTemp) {MaxTemp = temperature;}
  if( temperature < MinTemp) {MinTemp = temperature;}

// if (second == 0){
// if (hour == 23) { if (minute == 59) { if (second == 50) {}} // just before midnight to avoid possible date confusion
 if (minute == 0){ if (second == 0){

    EEPROM.write(WriteAddress,(day));
    ++WriteAddress;
    EEPROM.write(WriteAddress,month);
    ++WriteAddress;
    EEPROM.write(WriteAddress,(year-2000));
    ++WriteAddress;    
    EEPROM.write(WriteAddress,MaxTemp);
    ++WriteAddress;
    Serial.println("                              MaxTemp recorded");
    MaxTemp = 0;
  }
}


... code continued next post ...
26  Forum 2005-2010 (read only) / Interfacing / Re: real time clock ds 1307 on: December 07, 2008, 11:51:50 pm
Apologies for reviving an old thread, but it's the closest topic I could find to my problem, and I'm using essentially the code above to talk to my DS1307 mini board.

I have a sketch which (among other things) monitors & calculates the maximum & minimum daily temperatures, then writes the date (dd/mm/yy), MaxTemp & MinTemp to the Arduino's onboard EEPROM memory. This is working fine, but I thought I'd try to add the ability to display the recordings when I connect the USB cable and press 'd' (for 'dump data').

Currently I have to upload a small sketch to display the data, then re-load the original sketch. For simplicity I'd much rather just press 'd' & cut and paste the resulting data, without having to 'stop' the original program. Unfortunately, it seems that trying to monitor the serial port via Serial.read() somehow messes with the SDA/SCL lines. The standard output from my sketch looks like this:
Code:
15:05:37 on Monday, 8/12/2008 - Current temperature is: 24.7; Max - 23.0, Min - 22.0
15:05:38 on Monday, 8/12/2008 - Current temperature is: 25.7; Max - 24.0, Min - 22.0
15:05:39 on Monday, 8/12/2008 - Current temperature is: 26.4; Max - 25.0, Min - 22.0
15:05:40 on Monday, 8/12/2008 - Current temperature is: 26.9; Max - 26.0, Min - 22.0
15:05:41 on Monday, 8/12/2008 - Current temperature is: 26.8; Max - 26.0, Min - 22.0
15:05:42 on Monday, 8/12/2008 - Current temperature is: 26.6; Max - 26.0, Min - 22.0
When I add in the code to monitor for serial input, the clock output becomes something nonsensical, like this:
Code:
8:00:00 on I, 8/3/2000 - Current temperature is: 23.5; Max - 0.0, Min - 22.0
8:00:00 on I, 8/3/2000 - Current temperature is: 24.6; Max - 0.0, Min - 22.0
8:00:00 on I, 8/3/2000 - Current temperature is: 25.3; Max - 0.0, Min - 22.0
8:00:00 on I, 8/3/2000 - Current temperature is: 25.9; Max - 0.0, Min - 22.0
8:00:00 on I, 8/3/2000 - Current temperature is: 26.4; Max - 0.0, Min - 22.0
8:00:00 on I, 8/3/2000 - Current temperature is: 26.8; Max - 0.0, Min - 22.0
The data dump does work when I press 'd', but obviously it's pretty much useless if it messes with the clock. As a newbie I'm chuffed to have achieved this functionality, and won't be too fussed if there's no way around this, but you guys seem to be able to solve just about everything else that comes up!! smiley

Thanks for reading!

JB

PS - I haven't posted the code because it's pretty long, so let me know if you need it...
27  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 16, 2009, 02:15:38 am
Hooray - I've been able to give something BACK to the forums instead of just using everyone else's knowledge!!

Glad it's working for you!!

JB
28  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 15, 2009, 04:46:44 pm
I had to 'fill up' my data.csv file with junk data so that it was bigger than 512 bytes before it would write anything. One of the sketches which was presented in this post recommended at least 15kb file size; having a data.txt file of 0 bytes would lead to sectorsavailable() returning 0 & there being not enough space in the file to write any data. As I understand it, you will only be able to write data to the file up until the original file size; more data will NOT increase the file size as required, it will just fail to write to the file.  (I think - sirmorris will correct me if this is wrong! smiley)

Try making your file larger... fill it with anything you like as it will be overwritten anyway. You could even take any other old .txt file & rename it if you wanted, saves the hassle of making stuff up!

Hope this helps,

JB.
29  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 13, 2009, 05:46:15 pm
Just for the record - everything is working fine with 0012. Will upgrade to 0013 soon to keep up with the community!
30  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 12, 2009, 07:32:44 pm
Hi again everyone!

After numerous emails, pulling of hair & re-writes, sirmorris has helped to get my SD card logging dreams up & running. You can get the 'final' sketch here: http://docs.google.com/Doc?id=dqhc6fg_0gmk96kdd. It's certainly not the prettiest sketch, and I can't claim much of it at all as my own work, but it does what I hoped it would (although real-world testing hasn't happened yet).

Here's a photo of my current test setup...

Needs a LOT of work before it's ready for final implementation!!  ;D

Please feel free to suggest code improvements/rip my sketch to shreds - I'm no programmer, I've got thick skin, and any help is greatly appreciated!!

One last thanks to sirmorris & bobemoe for their work here - it's amazing how generous you've been with your help & knowledge.

I'll pop a note in here when I get something up in the exhibition area.

JB.

Pages: 1 [2] 3