Thursday, September 23, 2010
Gakken's Edo-era Clock, redux
I've kind of been busy with work, the Garo magazine write-ups, and so on, so I haven't spent all that much time on working with Gakken's Edo-era clock (kit #28). However, there's also been another complication that delayed me - the color LCD shield from Sparkfun.
I got this shield for my birthday, and it arrived without documentation. Although the Sparkfun site had some example code for running it, that code was written for the Arduino Mega, which has a lot more memory than the Japanino does. So, I had to rip out the Mandlebrot and raw RGB display routines, and slowly piece together what I needed and what I didn't. Another complication is that there are two driver sets for the Nokia LCD panel - Epson and Phillips - and I had to figure out which driver I needed (Epson). Additionally, when I posted a request for help on both the Sparkfun and Arduino forums I got ignored, initially. Fortunately, I decided to check out the Analog Clock demo on the Fun with Microcontrollers (FwM) site and the sketch I found there gave me code for drawing lines, rectangles and text on the LCD shield. Naturally, the Analog clock circuit included a 1-wire real time clock, which I don't have, so I had to pull that code out also.
Anyway, I got the barebones code to work for drawing the Edo analog clock on the LCD Shield, which I think looks pretty cool. This also gave me the code for writing debug text to the shield, which made life a lot easier from that point on, too. The next step was figuring out which pins were still available for connecting to the real Edo clock (I decided to double up on pins 3 and 5, which are assigned to 2 of the 3 pushbuttons on the LCD shield) and to find out just how bouncy the Edo clock leaf switch is. Actually, it's really badly bouncy. It takes about 8 minutes for the connection to become steady. Meaning that I had to throw in some debounce delays in the Japanino sketch. Fortunately, the final code is just about 12K, and the Japanino has 14K of code space, which is fine for my needs.
Link to the video.
Gakken suggested mounting a bell on top of the Edo clock, and then using the Japanino to drive a servo with a brass bar tied to it to ring the bell when the leaf switch closes. I decided to be a little more silly. A year ago I got a birthday card with a built-in sound chip and speaker - the kind where when you open the card it plays "Tequila". Turns out that you can run the sound chip off one of the Japanino output pins. Just pull the button batteries out of the card, and connect the card's power pads to the Japanino output pin and ground. Write a "HIGH" to the appropriate pin and the card plays just fine. That meant that all I had to do was add a small delay to the sketch to have it write a "LOW" to the pin when I wanted the music to stop. Alternatively, if you don't want to drive yourself insane listening to Tequila all the time, you can replace the sound chip with an LED.
A visitor to the blog asked about reading the time on the Edo clock. I couldn't answer this, so I started surfing the net. I learned that in Japan, long ago, when the Portuguese traders had arrived, they brought with them the technology for western-style clocks. However, the Japanese time-keeping system in the 1600's was divided into 12 periods - 6 during the daylight and 6 at night. So, clocks were developed using 2 pendulums, which were adjusted every 2 weeks to account for seasonal shifts in the number of hours of daylight and darkness.
This explains the use of the cam system for engaging and disengaging the two rotating pendulum arms. Now, in my original post I'd stated that the cams didn't seem to be rotating for me. Turns out that when I took the faceplate off the clock in order to install the leaf switch, the cam spring fell out and disappeared. After I discovered where the problem was, I replaced the lost spring with 1/2 of a spring from a ballpoint pen. Works fine. I'd also compared the 8-hour runtime of the hanging weight approach for the Slow Clock to the unknown max time for the Edo clock's windup spring. I haven't let the Edo clock run nonstop yet (too noisy at night) but the windup spring seems to be good for at least 2 days, if not 5.
There's no particular reason to use the leaf switch supplied by Gakken. It's really nothing more than 2 pieces of bent metal screwed down to a separator block. If you plan on connecting the Edo clock to an alarm circuit, you're better off using a commercial roller-type microswitch and hot gluing it in place in the clock. That way you'll avoid the problem of having to debounce the switch.
Since the Edo clock doesn't have a fixed rate for sweeping out 1 "hour" of time, it's not that important that the kit doesn't have a minute hand. You're looking at rough approximates for the current time of the day no matter what you do. Still, it's a fun look at Japanese technology history.