Show Posts
Pages: 1 ... 76 77 [78] 79 80 ... 100
1156  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......
1157  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 :-
 * 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()  {
  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 ");
   if( state == HIGH)
      Serial.print(" went High at ");
     Serial.print(" went  Low at ");
   if(duration > 0){
     // only display duration if greater than 0 
     Serial.print(", Duration was ");

void showTime(time_t t){
  // display the given time
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(" ");

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  if(digits < 10)

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(" second(s) ");   

1158  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 !
1159  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;
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 :
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,

void setup() {
    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");

    while (i < 21) {
        if (Serial.available()) {
            char c =;
            dateTime[i] = c;
    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() {
    sprintf(dateTime, "20%02d-%02d-%02d %02d:%02d:%02d", RTCValues[0],
            RTCValues[1], RTCValues[2], RTCValues[4], RTCValues[5],
    Serial.print(" - day of week: ");

1160  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 )
1161  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.
1162  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 !
1163  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.

1164  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.... ?
1165  Using Arduino / Storage / Re: New version of the SdFat SD card library on: July 07, 2011, 10:38:35 am

I only see the problem when I plug the chip into the project, so I have no serialPrint info.

The cards are running at   BitRate   =  352 Kbs
                                     A sample =  16 bit
                                     Chan =        1 mono
                                     samp rate = 22 KHz
                                     audio       =  PCM

I am OK with using 125 Mb older cards, but some might like to store larger/more audio files ?

The micro cards in the adapter look very cute , I wonder if they behave differently in a socket designed for them ?
1166  Using Arduino / Storage / Re: New version of the SdFat SD card library on: July 07, 2011, 07:10:28 am
I am still having fun and games with the SD cards using the waveHC library, that you suggested was best for audio files.

I am using the card to store 9 prerecorded messages of about 4 seconds each ( about 100k file size )

I have just looked at another couple of prototypes that I made that have failed, and it turns out that on the one card, it would only read tracks 1 to 9 , and cut off on track6,       and on the other it only reads tracks 6 to 8 !
Both of these cards ( Kingston and Patriot ) are micro SD cards in a SD adaptor.  I found another similar one and that only plays tracks 7 8 and 9.

I have tried them at 8 MHz and 4 MHz with the same result.  The Vcc line is decoupled right at the pins of the reader.

A normal SD type ( which our local computer shop no longer stocks ) seems OK.

I scratched  round the family for any old 128  Mb  cards they might have laying around, and they all work OK ....

Should I update anything in the libraries while I am at it ?
1167  Using Arduino / LEDs and Multiplexing / dead key on keypad library ? on: June 30, 2011, 02:45:18 pm

I started posting about a problem I had with KeyPad, where one key was not working, but just typing it up gave me the clue, so I will just mention it in case others have the same problem.

The unit is a remote control, using VirtualWire driving the transmitter.  I reallocated the default transmit pins ( data and PTT ) to 15 and 13 to suit my layout.

Being only a transmitter I completely forgot that VirtualWire also allocates pin 11 as the default vw_set_rx_pin, which I had as set as one of the columns in KeyPad.

Reallocating the vw_set_rx_pin to a spare pin cured it of course.
1168  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: June 29, 2011, 02:49:41 am

Good tips, I will try them
1169  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: June 29, 2011, 12:43:39 am
Right, but actually, would it not be possible for the compiler to spot that particular error quite easily?  and say " that ain't gonna get to 3 to start counting"

Or if you have the perennial   if ( a=0 )  instead of a==0  ,    it could nudged you and say "are you sure you want to make a be zero right now?"

Or perhaps us old farts should pay more attention to what we are typing, but I get carried away when I can see the code in my head, and just want to test it.
1170  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library sorted ! on: June 28, 2011, 03:57:13 pm

Its working now,  some idiot typed   for ( int n =0; n>=3; n++ )   instead of  for ( int n =0; n<=3; n++ )   smiley-eek-blue

Pages: 1 ... 76 77 [78] 79 80 ... 100