Show Posts
Pages: 1 ... 76 77 [78] 79 80 ... 100
1156  Using Arduino / Storage / Re: EEPROM overwite previous data? on: August 13, 2011, 12:01:24 am
That looks great, don't now how you are going to get time for fencing now your a moderator !

I will try that sketch out when I have had my morning coffee.

The extra byte I need to save is historically the best number of days between events, which could have been 5 events ago, but its simply compared to the latest one at an event time, and the largest is then stored as the best.
1157  Using Arduino / Storage / Re: EEPROM overwite previous data? on: August 12, 2011, 06:28:10 pm
BTW Rob,  The Bobuino with bells, whistles, inter-cooler and turbo looks really cool !

I don't like to just cut'n'paste without trying to understand the code, I have put some comments on your code to see if I understand it :-
Code:

// Reset the register pointer                          //  because the DS1307 sequences through all the addresses ?
    Wire.beginTransmission(RTC_address);         // this would be 0x68 , the address for all DS1307s ?
    Wire.send(0x00);                                        // starts the sequence back at 00 ( seconds and CH ) ?
    Wire.endTransmission();

// Now read the current time registers
    Wire.requestFrom(RTC_address,8 );    //  imports current time and control in bcd format, sequencing through as above ?
    seconds = Wire.receive();                 //  extract 1 byte from above, 1 nibble tens seconds, one units seconds  ?
    minutes = Wire.receive();                 // and so on
    hours = Wire.receive(); 
    day_week = Wire.receive(); 
    date_month = Wire.receive(); 
    month = Wire.receive(); 
    year = Wire.receive(); 
    sqwe = Wire.receive();

// Reset the register pointer                   
    Wire.beginTransmission(RTC_address); 
    Wire.send(0x08);  // RAM 0x08-0x3F      // advance the pointer to the start of the eeprom or battery ram ?
    Wire.endTransmission();

// Write it to RAM 
    Wire.beginTransmission(RTC_address,8);  //   I dont need time,  but need to save previous best ( 0-99 )
    Wire.send(seconds); 
    Wire.send(minutes);   
    Wire.send(hours);   
    Wire.send(day_week);   
    Wire.send(date_month);   
    Wire.send(month);   
    Wire.send(year);   
    Wire.send(sqwe);
    Wire.endTransmission();
1158  Using Arduino / Storage / Re: EEPROM overwite previous data? on: August 12, 2011, 05:44:32 pm
Thanks Rob

What must I change ( apart from the Serial ) to get the main part working with the normal usb?

Just remove the HEX from all the Serialprints ?

I get      ÿ?ñn¢³30 ¿<ðn¢³30 ¿>ðo£322¡ÿ>ñn£°23aß?ño£°23áÿ?ñ  at the moment on the monitor
1159  Using Arduino / Storage / Re: EEPROM overwite previous data? on: August 12, 2011, 01:48:53 pm
Thanks Rob

I will have a look at that now
1160  Using Arduino / Storage / Re: EEPROM overwite previous data? on: August 12, 2011, 11:03:04 am
Thanks Rob,  I wondered about that, is that the RC register they talk about in the datasheet?

I can store the previous best number ( 0-99) preferably in 2 bytes ( so I can just use each one - tens and units - easily for the display.)  Although I still have to compare it to  the current elapsed days to see which is the "best"

The date can be yyyy mm dd  or seconds since 1970 .  so I don't know the best way to try to store it.

If I store it in seconds since 1/1/1970 I can easily divide down the difference between latest and stored seconds to get elapsed days, but I still will need to display the previous date after a power down.....?
1161  Using Arduino / Storage / Re: EEPROM overwite previous data? STUCK on: August 12, 2011, 10:38:32 am
I can usually McGuiver a way to make a sketch work , but this seemingly simple project has me going round in circles ( I am obviously in new ground with the  RTC and eeprom - and cannot understand some of the dozens of examples I have looked at )

As I see it, if I could simply store the current time "now() " in eeprom whenever there is an event, if the power goes off for a few days , at setup I can read the old current time from eeprom, to calculate the previous date, and the days since event.

( I would also need to store the previous best, but that is just a byte ( 0-99 days ) and I can do that I think ! )

I have tried dividing the seconds into days and masking off the higher and lower bytes to store in this form, but I loose the hours and could end up with the wrong day count

Might I be better off storing the date of the previous event as separate bytes for YY MM DD, and use a look up table for the months to calculate the days since last event ?

I have spent 43 of the last 48 hours trying to get this right and it is driving me nuts!  I stupidly made a promise I could get it done by the weekend -  it looked so easy :-)

Has anyone seen a working sketch that they can point me to?  or give some advice..
1162  Using Arduino / Storage / Re: EEPROM overwite previous data? on: August 11, 2011, 09:37:22 am
Thanks Paul
So I could perhaps save the current time and current date as two bytes in eeprom, after any event,  and reconstitute it back into the same format as prevEventTime in setup ?
Can I read eeprom in setup?

OR  perhaps save the now() whenever an event occurs. ( in seconds since Jan1 1970 ) , but divided by 60*60*24 when an event occurs which will give me the number of complete days in one byte, and save that to eeprom as dayselapsed

Then when booting up after a power interruption , I could just work in days ??  but now I am moving away from a sketch that is actually working......
1163  Using Arduino / Storage / EEPROM overwite previous data? on: August 11, 2011, 08:50:10 am
I have at last got my RTC board running using the Time.h and DS1307RTC.h  libraries.

The TimeRTCLogger example appears to be almost right for the project I am playing with , which is a sign showing the days since the last event, date of previous event, and previous longest days between events.

I know the DS1307 will keep the time for years,  but I have a couple of questions

Firstly, I can only see the Syncing the time from the RTC during Set up ?
is it keeping time with its now() call ?

Secondly ,
 if this project is unplugged at some time, presumably the prevEventTime will be lost when the micro boots up again.
Could I store    prevEventTime  as  eeprom_write_byte  and eeprom_read_byte ?

If so would it be in the same address -  ie overwrite the previous one?

I only expect an event every few weeks, so the 10,000 write cycles will be fine  -   ( I am 63 years old  )
BTW  The events are nothing to do with romance !

the code follows :-
Code:
/*
 * TimeRTCLogger.pde
 * example code illustrating adding and subtracting Time.
 *
 * this sketch logs pin state change events
 * the time of the event and time since the previous event is calculated and sent to the serial port.
 */

#include <Time.h> 
#include <Wire.h> 
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

const int nbrInputPins  = 6;             // monitor 6 digital pins
const int inputPins[nbrInputPins] = {2,3,4,5,6,7};  // pins to monitor
boolean state[nbrInputPins] ;            // the state of the monitored pins
time_t  prevEventTime[nbrInputPins] ;    // the time of the previous event

void setup()  {
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to sync the time from the RTC 
  for(int i=0; i < nbrInputPins; i++){
     pinMode( inputPins[i], INPUT);
    digitalWrite( inputPins[i], HIGH);  // uncomment these lines if
     state[i] = HIGH;                    // pull-up resistors are wanted
  }
}

void loop()
{
   for(int i=0; i < nbrInputPins; i++)
   {
     boolean val = digitalRead(inputPins[i]);
     if(val != state[i])
     {
        time_t duration = 0; // the time since the previous event
        state[i] = val;
        time_t timeNow = now();
        if(prevEventTime[i] > 0) 
           // if this was not the first state change, calculate the time from the previous change
           duration = duration = timeNow - prevEventTime[i];         
        logEvent(inputPins[i], val, timeNow, duration );  // log the event
        prevEventTime[i] = timeNow;                       // store the time for this event 
     }
   }
}

void logEvent( int pin, boolean state, time_t timeNow, time_t duration)
{
   Serial.print("Pin ");
   Serial.print(pin);
   if( state == HIGH)
      Serial.print(" went High at ");
   else   
     Serial.print(" went  Low at ");
   showTime(timeNow);
   if(duration > 0){
     // only display duration if greater than 0 
     Serial.print(", Duration was ");
     showDuration(duration);
   }
   Serial.println();
}


void showTime(time_t t){
  // display the given time
  Serial.print(hour(t));
  printDigits(minute(t));
  printDigits(second(t));
  Serial.print(" ");
  Serial.print(day(t));
  Serial.print(" ");
  Serial.print(month(t));
  Serial.print(" ");
  Serial.print(year(t));
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void showDuration(time_t duration){
// prints the duration in days, hours, minutes and seconds
  if(duration >= SECS_PER_DAY){
     Serial.print(duration / SECS_PER_DAY);
     Serial.print(" day(s) ");
     duration = duration % SECS_PER_DAY;     
  }
  if(duration >= SECS_PER_HOUR){
     Serial.print(duration / SECS_PER_HOUR);
     Serial.print(" hour(s) ");
     duration = duration % SECS_PER_HOUR;     
  }
  if(duration >= SECS_PER_MIN){
     Serial.print(duration / SECS_PER_MIN);
     Serial.print(" minute(s) ");
     duration = duration % SECS_PER_MIN;     
  }
  Serial.print(duration);
  Serial.print(" second(s) ");   
}








1164  Using Arduino / Networking, Protocols, and Devices / Re: DS1307 won't work... Everything is hooked up properly on: August 11, 2011, 07:39:43 am
OK everything works with the DS1307RTC library !
1165  Using Arduino / Networking, Protocols, and Devices / Re: DS1307 won't work... Everything is hooked up properly on: August 11, 2011, 06:25:38 am
I too am completely lost now with this dang RTC,  I have done some searches, and there seems to be so many different ideas of how to try and use the DS1307 with Arduino !
There are more posts on this than on Blinking LEDs!!!  :-)

I have a small board with the DS1307, 3.2v battery,  Xtal  right on the pins, decoupling on the 5v, 10k pull ups on the  SCL and ADA pins.

I have tried several sketches just to set the time and read it, I have removed the settings in setup and uploaded again, but each time I get random results, sometimes just everything switching from 00-000-00 00;00;00  to the correct time for a few seconds.

And Crossroads, your "simple" sketch is way over my "Global Newbie"  head I am afraid :-)

This was the result from the latest attempt using the DS1307 library example from Álvaro Justen aka Turicas;
Code:
Please enter date and time in the format "YYYY-MM-DD HH:MM:SS D",
Where D is the number of the day of week (0 = Sunday, 6 = Saturday).
Example: 2011-04-23 02:25:27 6
Date and time set!
Reading data from RTC...
20165-08-11 12:58:00 - day of week: Friday
2000-00-00 00:00:00 - day of week: Sunday
2000-00-00 00:00:00 - day of week: Sunday
2011-08-11 12:58:03 - day of week: Friday
2011-08-11 12:58:04 - day of week: Friday
20165-165-165 12:58:05 - day of week: Friday
2000-00-00 00:00:00 - day of week: Sunday
2011-08-11 12:58:07 - day of week: Friday
2011-08-11 12:58:08 - day of week: Friday
2011-08-11 12:58:09 - day of week: Friday
2000-00-00 00:00:00 - day of week: Sunday
2000-00-00 00:00:00 - day of week: Sunday
2011-08-11 12:58:12 - day of week: Friday

anybody have a failsafe equivalent to Blink without delay for DS1307 chips !

the code for above is :
Code:
/*
This example firstly waits for Serial input and then sets date and time on DS1307
Real-Time Clock based on what user sent.
Secondly it reads the date and time from DS1307 Real-Time Clock
and send this information to your PC using USB/Serial (like the ReadDate example).
Make the connections below, upload the code and open Serial Monitor.

Made by Álvaro Justen aka Turicas

Pin connections on DS1307 module:

[DS1307] <--> [Arduino]
5V       <--> 5V
GND      <--> GND
SQW      <--> (not connected)
SCL      <--> Analog Input 5
SDA      <--> Analog Input 4

This software is free software.
*/

#include <Wire.h>
#include <DS1307.h>

char dateTime[22];
int RTCValues[7], i = 0, year, month, dayOfMonth, dayOfWeek, hour, minute,
    second;

void setup() {
    Serial.begin(9600);
    Serial.println("Please enter date and time in the format \"YYYY-MM-DD HH:MM:SS D\",");
    Serial.println("Where D is the number of the day of week (0 = Sunday, 6 = Saturday).");
    Serial.println("Example: 2011-04-23 02:25:27 6");
    DS1307.begin();

    while (i < 21) {
        if (Serial.available()) {
            char c = Serial.read();
            dateTime[i] = c;
            i++;
        }
    }
    dateTime[i] = '\0';

    year = 10 * (dateTime[2] - 48) + (dateTime[3] - 48);
    month = 10 * (dateTime[5] - 48) + (dateTime[6] - 48);
    dayOfMonth = 10 * (dateTime[8] - 48) + (dateTime[9] - 48);
    dayOfWeek = (dateTime[20] - 48);
    hour = 10 * (dateTime[11] - 48) + (dateTime[12] - 48);
    minute = 10 * (dateTime[14] - 48) + (dateTime[15] - 48);
    second = 10 * (dateTime[17] - 48) + (dateTime[18] - 48);

    DS1307.setDate(year, month, dayOfMonth, dayOfWeek, hour, minute, second);
    Serial.println("Date and time set!");
    Serial.println("Reading data from RTC...");
}

void loop() {
    DS1307.getDate(RTCValues);
    sprintf(dateTime, "20%02d-%02d-%02d %02d:%02d:%02d", RTCValues[0],
            RTCValues[1], RTCValues[2], RTCValues[4], RTCValues[5],
            RTCValues[6]);
    Serial.print(dateTime);
    Serial.print(" - day of week: ");
    Serial.println(fromNumberToWeekDay(RTCValues[3]));

    delay(1000);
}
1166  Using Arduino / Storage / Re: SD card error - SOLVED on: August 09, 2011, 10:12:14 pm
You might be right there Rob,
If you have got the microSD in the adaptor working reliably, you are miles ahead.

I will try a separate 3.3v supply when I have one hooked up on the bench again ( and scope the supply as it is first )
1167  Using Arduino / Storage / Re: SdFat and big SD cards on: August 09, 2011, 08:52:54 am
FWIW     I have been able to pick up 256Mb cards cheap from camera repair shops, they always seem to have some in the drawer.
They are the only things that work in my message anouncer.
1168  Using Arduino / Storage / Re: SD card error - SOLVED on: August 09, 2011, 08:47:05 am
Hi Rob,

Did you come right with your SD cards?  I have had problems using any card other than the old  256 Mb ones, but all the latest ones like the 2 Gb and micro SD with adaptor fail after a while. ( weeks or a month )

I changed the 125 chip and it made no difference.

I have resorted to buying old smaller cards from camera repair shops !
1169  Using Arduino / Installation & Troubleshooting / Re: saving to new file each time ? on: July 13, 2011, 04:19:36 am
Thanks,  thats what I will set up then.

It is about time I had a tidy up, every time theres a new Arduino version, I just copy all the libraries and examples into it and work from there.

1170  Using Arduino / Installation & Troubleshooting / saving to new file each time ? on: July 11, 2011, 09:38:42 pm
I have done a search and cant find a reason why, when I want to save a file that I am working on, it says some files are read-only, save to a new file.

Its not always, sometimes it saves as normal windows .

I have put up with it til now, but sometimes you might make just one small change, and have to save it to  a new name each time.... ?
Pages: 1 ... 76 77 [78] 79 80 ... 100