The MCP79410 breakout board gives easy access to this cute little timekeeper.
//clock.setDateTime(__DATE__,__TIME__);However, you should then comment this line out and upload the program to the Arduino again, otherwise every time you power up the Arduino the time on the MCP79410 chip would be reset. There is a way to query the MCP79410 to find out if the time has been set already but this little hack has worked for us. If you get the is running query working let us know in the comments! The full code is below.
/* LucidTronix Real time clock MCP79410 library * Serial output example. See tutorial at: * http://lucidtronix.com/tutorials/59 */#include#include String stime = "";unsigned int last_update = 0;MCP79410 clock = MCP79410();void setup(){ Wire.begin(); Serial.begin(9600); // Uncomment this line to set the time // Upload code a second with it commented out // so time doesn't always reset at startup //clock.setDateTime(__DATE__,__TIME__);} void loop(){ if (millis() - last_update > 1000){ // update every second stime = " "; byte a_hour = clock.hour24(); String a_hour_s = String(a_hour,HEX); int hour_int = a_hour_s.toInt(); String ampm = "am "; if (hour_int >= 12){ ampm = "pm "; if (hour_int > 12) hour_int -= 12; a_hour_s = String(hour_int); } if (a_hour == 0 || a_hour == 12 ) stime += String(12); else stime += a_hour_s; stime += ":"; byte a_min = clock.minute(); if (a_min < 10 ) stime += String(0); stime += String(a_min,HEX); stime += ":"; byte a_sec = clock.second(); if (a_sec < 10 ) stime += String(0); stime += String(a_sec,HEX); Serial.println(stime + ampm); last_update = millis(); }}
| Title | Description | # | Cost | Link | Picture |
| PCB DS1307 Breakout Board | Breakout board for the DS1307 Real time clock chip. Uses I2C protocol. | 1 | $4.5 | Link |
|
| Clock MCP79410 Real-Time Clock Chip | I²C, 2-Wire Serial 1.8 V ~ 5.5 V Alarm, Leap Year, Square Wave Output, SRAM, Unique IDValue: I²C | 1 | $1.08 | Link |
|
| Crystal 32.768KHZ 12.5PF SMD | 32.768KHz crystal oscillator for use with DS1307 RTC chip.Value:32.768kHz | 1 | $0.94 | Link |
|
| Battery Lithium Coin Cell 3V 12.5MM | Batteries Non-Rechargeable (Primary) Lithium Coin, 12.5mm 3V 36mAhValue:3V | 1 | $0.71 | Link |
|
| HOLDER COIN CELL 12MM SMD | Coin Cell, Retainer PCB, Surface Mount SMD (SMT) TabValue: Coin, 12.0mm | 1 | $0.49 | Link |
|
| LED SMD | LED 3X1.5MM 568NM Green Clear SMDValue:2.2V Green | 1 | $0.18 | Link |
|
| Resistor SMD 2.2K 0805 | Surface Mount resistor 2.2k ohm, 0805 package.Value:2.2k | 2 | $0.1 | Link |
|
| Resistors | RES 300 OHM 1/8W 5% 0805 SMDValue:300 | 1 | $0.1 | Link |
|
Comments: