Saturday, December 17, 2011

Wise Clock 4 - Using the RTC 1Hz "Heartbeat"

DS3231 can generate a square wave output signal through pin 3 (aptly named "SQW"). Same pin can be also activated (set low) when one of the two internal alarms is triggered (that's why this pin is also called "INT").

Wise Clock 4 has the INT/SQW pin connected to D2 through a jumper. Therefore, to be able to use this RTC signal, a jumper must connect the 2-header pins, as shown in the picture below (jumper is red, between processor and SD card socket).

Since I don't seem to get things perfect from the first try, I forgot to add the mandatory 10k pull-up resistor (this is fixed in the next iteration of the board, shipping as of mid Dec 2011). Here is how you need to connect the pull-up resistor, as shown in the next photo. Solder one terminal of the resistor in the via (it fits the hole) and the other terminal to the 2-pin header.

Once the hardware is ready, compile and upload this very simple sketch.

#include "WProgram.h"
#include "Wire.h"
#include "DS3231.h"

void rtc_interrupt()

void setup()
  Serial.println("RTC square wave enabled");
  pinMode(2, INPUT);
  attachInterrupt(2, rtc_interrupt, RISING);

void loop()

The sketch (tested with Arduino IDE 22) enables the 1Hz square wave on the RTC and attaches an ISR ("interrupt service routine") that gets executed once every second. (You can see the output of the ISR function in the serial monitor.)

  • The square wave is not enabled by default as DS3231 gets powered. To enable the square wave, bit 2 of the register 0x0E must be set to 0 (it is 1 by default).
  • The square wave frequency can be one of the 4 values: 1Hz, 1024Hz, 4096Hz and 9182Hz. This frequency is selected by setting 2 bits (3 and 4) in control register 0x0E (check page 13 of the datasheet).
  • The file DS3231.h (also required is DS3231.cpp) is the one included in the WiseClock3 library.

I see at least two applications where this square wave/interrupt line can be used:
  • RTC alarm waking up the clock from sleep mode;
  • chronometer.

Friday, December 16, 2011

Data logging with Wise Clock 3/4

If you ever tried to compile the SD library (packaged with Arduino IDE 22 and 23) targeting the Sanguino board (which also covers Wise Clock 3 and Wise Clock 4), you got compilation errors.

For example, compiling Datalogger.pde with the Sanguino file setup detailed here, will give these kinds of errors:

Datalogger:67: error: 'class File' has no member named 'println'
Datalogger:67: error: 'dataString' was not declared in this scope

The main cause for these errors is missing files (e.g. Stream.h, WString.h). Even if you fix these compilation errors, Datalogger.pde sketch will still not work, and this is because SPI pins are incorrectly defined for Sanguino. (Note that the Datalogger sketch compiles and works fine for Arduino.)

I know that Arduino IDE 22 and 23 are no longer supported, but I bet many out there are still using them, as I do. Until I upgrade to Arduino 1.0, I think it is worth fixing the issue in these older IDEs.

So here is the quick recipe for covering the Sanguino board in Arduino 22 and 23 IDEs:

1. add the following section to Arduino-0022/hardware/arduino/boards.txt file:


2. Download file and expand its content into the folder Arduino-0022/hardware/arduino/cores/. This will create the folder "sanguino" under "cores". contains the following files, copied from Arduino-0022/hardware/arduino/cores/arduino/:

Only 2 4 of the original Arduino files have been modified specifically for Sanguino, and they are: pins_arduino.h

Note (March 12/2012): I updated the zip file to include the last two files enumerated above. The original Arduino ones did not handle attachInterrupt() correctly, as the original Sanguino files (released a long time ago for version 18) did. So I just copied over the old files.

By following the 2 steps above, you should be able to compile sketches for the "Sanguino" target (selectable from the menu "Tools/Board" of the IDE). (A few extra steps are required to be able to burn the bootloader, but I will leave this out for now, for the sake of simplicity.)

Now try compiling and uploading Datalogger.pde and see the results for yourself: data is appended to the file datalog.txt on SD card.

Note: The Wise Clock 3/4 software handles reading from SD card just fine even with the old Sanguino files because the SPI pins are defined in the file mmc.cpp, which is part of the Wise Clock 3/4 library. The SD library relies on externally-defined (in file pins_arduino.h) SPI pins.

Guess why am I bringing up data logging on Wise Clock 4? :)

Friday, December 2, 2011

Buy Complete Wise Clock 4 kit - includes display and enclosure

Update May 12, 2018
The complete kit is no longer offered since Sure Electronics discontinued the LED display.
I still sell the kit without the display, for those who can provide their own display, either from old stock or by making it themselves.
I may also have the bigger (5mm LED) display in stock, or may recycle some older ones. Please email me to inquire.

Update July 7, 2015
Before you buy, please read this post on assembling the Wise Clock 4 with the new display.

When you buy the "Complete Wise Clock 4 kit", on top of the Wise Clock 4 kit you get the 3216 bi-color (red/green/orange) LED display from Sure Electronics, plus the enclosure, consisting of two laser-cut transparent acrylic plates and the required hardware (standoffs, screws etc) to assemble it.

The "complete kit" comes with everything you need to build a functional Wise Clock 4. You will need to add your own FAT16/FAT32-formatted SD card (with the necessary files on it), the miniB USB power cable and, eventually, an BTBee module (if you want Wise Clock 4 to display messages sent from your Android device).

The assembly guide, written by StefanK, can be found here.

Thursday, December 1, 2011

Wise Clock 3 - Dec 2011 software release

From the desk of Mr. Ruud, a new software release for Wise Clock 3 is now available.
Below is the long list of impressive features, improvements, changes etc. Ruud, thanks again.

  • Because of the large number (28) of menu entries the menu is now split in 2 loops, one for the Apps and one for the Settings.
  Apps menu loop:

  Settings menu loop:

Selecting the "SETUP" menu entry will take you to the Settings menu loop, selecting the "APPS" menu entry
will take you to the Apps menu loop.
  • Stopwatch: This will show the time passed by in tenths of seconds, pressing the Set key will show the "lap" time.
  • Count Down Timer: This timer allows for setting a time of up to 24 hours and will beep 3 times after counting down to 0 seconds.
  • TIX clock: Showing the time using colored squares (if you do not know what a TIX clock is, Google it!) The PLUS key alows for changing the interval between 1, 4 and 60 seconds.
  • Time Clock: This allows for recording the amount of time spent on a project. You clock "IN" at the start of the project and clock "OUT" when you are finished for the day. The Time clock will show the total amount of hours and minutes spent on that project over several days. It allows for 5 different projects. A project may be cleared by pressing the Plus key when the "IN?" text is displayed, a future version will store all "IN" and "OUT" times together with the project number in  an Excel compatible file on the SD card. This file may then be processed on a PC using Excel.
  • "Word Clock": This will show the time and date using words instead of numbers. All "words" come from a "word" text file on the SD card and can be changed with any editor. At runtime you may choose from 10 different "word" files. Currently there are 5 different "word" files included:
  1. word1.txt The "official" English version showing: "The time is seven minutes past one o'clock in the morning on Monday the fourth of July."
  2. word2.txt The short English version showing: "It's one oh-seven am"
  3. word3.txt The "funny" English version showing: "It's 5 + 2 past six and you are up early"
  4. word4.txt The French texts version showing: "Le temps est sept minutes apres une heure du matin."
  5. word5.txt Example file for advertisement purposes, showing texts like: "We are now closed, opening hours are from 9 - 5" or "10% extra discount from 12 - 1".
  You may create your own versions with whatever texts/language you like, see the word1.txt file for details.

  • New large Font: This new proportional font, selected by "FONT+/FONT-", is 14 dots high and has variable width (letter i = 2 dots wide, letter m = 10 dots wide).
  • The "message.txt" file now contains, 10 different personal messages, the "MESG+" menu entry allows for selecting one of them (M1, M2, M3 etc.).
  • The "Quotes" menu entry now let you choose from up to 10 different "Quotes" files named quot1.txt, quot2.txt etc. several sample files (like: Texts by Shakespeare, fake alarm system, Spanish lesson, the clock's user manual (what you are reading now = "quot0.txt") are included. If you select the 11th file then the "message.txt" file is displayed which shows e.g. all 10 personal messages, reminders, DST etc.You may put your own "quote" file on the SD card, make sure that lines are not longer then 175 characters and end with a Carriage Return and Linefeed character. The file must be bigger then 512 bytes.
  • It is now possible to put characters in the non visible "video" ram and make them visible by overlaying the present display in horizontal or vertical mode. When in Big Mode, press the Set Key to see a demo.
  • The "UTC" mode now allows for changing the number of hours difference (+12 till -12). It allows for showing the time in "Graph" (= analog clock) or "Text" mode. The "Time.txt" file is no longer used and should be removed.
  • The temperature (TEMP+ menu entry) will now also show the highest and lowest temperature for that day.
  • The brightness is now changed with the Plus Key and the scroll speed with the Set key. The Set key is used in some of the new apps, but the brightness can always be changed with the Plus Key. 
  • "STATS" menu: This menu entry will show the highest and lowest temperature for the current year, the last time the power went off and the time when the power came back. It may take up to 24 hours before this info is available.

NOTE: The filemanager for the SD card is limited, so if you want to make any change to the files on the SD card then format the SD card first and copy all files in one go to the SD card. Also there cannot be more then 16 files on the SD Card.