Sunday, March 21, 2010

Wiseduino with DS1337

DS1337 is another real time clock (RTC) from Maxim, closely resembling DS1307 that comes with the Wiseduino kit.

The main difference between these two chips is the ability of DS1337 to handle (set, trigger) an alarm. Otherwise, both have similar pin configurations, both "talk" I2C, and both use a 3V coin battery (DS1307 only as backup, DS1337 as the only power source).

Many others have included DS1337 on their boards and wrote libraries for this chip. I thought I should give it a try myself, especially because of the alarm capability. The easiest way was to modify an Wiseduino board, by cutting 3 traces and adding 2 wires, as shown in this image:



The cuts are shown with yellow lines, the wires are light blue. The rightmost cut is on the back of the board.

Updated Apr 17/2010
After I started the actual work, I realized that, since DS1337 is powered by the 3V coin battery, voltage level adapters (on SCL and SDA lines) need to be used between the clock and a 5V-powered Wiseduino. So I decided to power Wiseduino with 3V as well (2xAA batteries). This means the frequency cannot be 16MHz (according to ATmega168/328 datasheet); so I installed an 8MHz resonator instead. So far so good. I am able to upload the DS1337 sketch and read back the time. Current consumption is a under 5mA.

Here are a few other things I did to make this work:
  • on Wiseduino, I am using an ATmega168 with the bootloader, instead of the 328;
  • I changed boards.txt to accommodate the 8MHz working frequency:
diecimila.upload.speed=9600
#diecimila.upload.speed=19200
...
diecimila.build.f_cpu=8000000L
#diecimila.build.f_cpu=16000000L
  • tried unsuccessfully JLuciani's DS1337 library; it seems to require/use a different set of "wire" files than those coming with Arduino IDE 18; confusion ensues; files and functions need to be renamed etc etc; I just gave up;
  • tried, with limited success, xSmurf's DS1337 library; there seem to be multiple versions of the DS1337 class (and header), no sample sketch that uses the class; I had to eliminate some alarm-related stuff, define some macros etc. In the end, I have a simplified version working;
  • to upload the sketch to the board, I used the 3V3 version of the FTDI breakout from sparkfun (the 5V has the signal voltages too high).
Next steps:
  • put the microcontroller to sleep when time is not read (this will reduce the consumption to micro amps, hopefully);
  • implement the alarm functionality, with interrupts.

Conclusion DS1307 vs DS1337:
  • DS1337 should be used in a 3V3 environment; it is not meant to be mixed with 5V signals;
  • DS1337 libraries I looked at so far are pretty finicky compared to DS1307 libraries;
  • an equivalent of (that is, as easy to use as) DS1307 for 3V3 is DS1340 (used by JeeLabs in their JeeNode boards).

Sunday, March 14, 2010

Scrolling text on the Dual RG matrix shield

As one may recall, the "Dual RG matrix shield" was introduced as the display for IllyClock. In that case, it showed the time (hour and minutes) statically.

Earlier, I wrote a sketch for this shield that displays moving (scrolling) text. Somebody may find it useful, and that is why I thought of sharing it.

The demo sketch, tested with Arduino IDE 18, can be downloaded here.
This is how it looks in action.


Saturday, March 13, 2010

BookClock - new member of the Wise Clock family



Don't throw away that carboard box your Monochron was packaged in. You can use it as enclosure for the cheapest (yet) member of the Wise Clock family, currently named "BookClock" (for the reason that it can be placed on a book shelf, among books).

Note: The featured cardboard box is sold by ULine. It has the code ULine S-974 and can be found here.

The BookClock contains only two elements: Wiseduino, of course, and the 8x32 LED display from Sure Electronics. One nifty addition is a tilt sensor that changes what is displayed depending on the clock orientation (standing on the smallest side as a book, or laying flat on the largest side).



To build it, let's start with the enclosure, the cardboard box. With an xacto knife, cut an opening for the display.


The opening, waiting for the display, should look like this:


Stick some scotch tape along the cut lines to strengthen (and also smooth) them.
After inserting the display, attach it to the box with some sticky tape (I used electrical tape).
This is how it looks when standing, as a book on the shelf.


The "guts" of the BookClock is a "hacked" Wiseduino board, which looks like this:


This board does not have the extension (female) headers, since there will be no shield mounted anyway. So I soldered (the required wires of) the 16-wire ribbon cable directly where the headers would have been.

Wires number 15 and 16 of the ribbon are GND and Vcc (5V) respectively. For mechanical reasons I soldered them into D0 and D1, whose lines were previously cut. (I then re-connected D0 and D1 to Vcc and GND respectively, see the red and blue wires.)

The board also has a tilt sensor soldered between analog 0 (A0) and ground. A 10K resistor pulls A0 up (connects it to Vcc).

This is how it looks on the inside (not yet connected to power).