After getting the Arduino LCD shield code running again, I wanted to come up with some kind of a mod to the Gakken Flip Clock. Most of the obvious ones have already been done – drawing animations on the clock number sheets (you can buy blank punch out sheets without the numbers from Gakken for about $5 per set), robotizing the clock, putting it into a new case, or connecting it to some kind of smartphone app. But, something that I’ve been noticing with the last couple Gakken kits is that they haven’t been doing as much for connecting up the Japanino.
Since I just bought my replacement Japanino and I had the LCD shield code working, the idea for drawing the flip animation on the LCD and then controlling that with the clock was an easy leap. I just had to find some time to sit down with a soldering iron, and to figure out how to encode the graphics.
For the graphics, the limitations are that the Japanino only has 1K of variable space and 16K of program memory. Couple this with the fact that the LCD shield is 128 pixels by 128 pixels and doesn’t have buffer memory, you see the image updating as it’s being drawn. I decided to keep the drawings small – 64 x 64 pixels, to keep the visible updating to a minimum, and to use 8-color run length encoding (RLE) to keep the code simple. I took the existing Sparkfun library and converted the setChar() method to draw my picture instead of text fonts. I used GIMP to make each animation frame (2 frames per cycle), saved them as .bmps, and wrote a short perl script to convert the .bmp binary to ASCII text. Because I know VBscript better than perl, I wrote a .vbs file to convert the ASCII .bmp into a C++ char array to be copy-pasted into the .h file for the modified setChar() header. I didn’t bother trying to make pretty pictures – that can come later. Right now, I’m just trying to prove the concept. But with SLEEPING, DRIVING, EATING, WORKING, TOILET and PUZZLED, I have six 2-frame cycles and the program size is about 10K. That gives me room to either make more detailed pictures, add more colors, add more frames, or add more activities.
On the hardware side, I soldered in 2 wires to the motors (to the black and blue contacts), and spliced in a ground wire running from the battery holders. Earlier, I put in an on/off switch to the red wire from the battery pack and hand-drilled a mounting hole for the switch at the back of the case. I just ran the three new wires out the hole used for the minutes leaf switch and routed them to the back of the housing. I then soldered the two motor wires to an Arduino through-header, and connected a straight pin to the ground wire. Minutes goes to A0, Hours to A1, and black to one of the GND pins. analogRead() returns near-zero when the motor is off, and between 500 and 750 when it’s pulsed (it’s a dirty pulse, probably because the battery is being pulled down when both motors are running.) So, I just do an inline-if to get a “0” value if the analogRead() is below 300, and a “1” if it’s above.
To advance the minutes and hours numbers, the motors are pulsed once per increment, and the pulse cycles are about 100 ms long. When the batteries are fully charged, the clock will automatically reset to “00:00” on power-on. I have a short delay timer that suppresses the motor pulse counter until after the reset is done. However, if the batteries are getting weak, there’s no reset and the clock time will be wrong, so my reset delay timer gets overridden if there’s no reset in the first minute. After the reset delay, any motor pulses will increment my minutes and hours variables. Finally, I flip through the animation cycles 2 frames per second, and the actions portrayed in the animations are determined by an if-statement with time = minutesCnt + hoursLookUp[hoursCnt] * 60.
Lastly, a comment about hoursLookUp. In order to keep the number of holes the same in the minutes and hours drums, the hours numbers are duplicated, and the clock controller sends multiple pulses depending on the time. There are 2 flip cards for 00 to 12 hours (1 pulse every 30 minutes), and 3 flip cards for 13 to 23 (1 pulse every 20 minutes). To simplify things, I just put the hours values in a 60-element array, and get the actual hour based on the number of motor pulses detected. I could speed the code up a little more by doing the “* 60” part within the array elements as a static constant. (I’ll do that when I have time.)
But, the idea works, and I can use the same approach to turn the LCD shield into a simple photo frame. I may even add .gif support to the library. Some day.
(Sidenote: There’s been no real news from Gakken lately, beyond a couple announcements of the Open Reel Ensemble’s concert and subsequent DVD going on sale back in May. Amazon.jp currently has a July 25th release date for the next Gakken kit, the updated pinhole planetarium.
Last week, the subject for the famous people series magazine was Tolstoy; the character design looked like a Kewpie doll with white cotton glued on for a beard. This week is Glen Miller, and I don’t know what that design is supposed to look like. Next week is Kenyan activist Wangari Maathai, who I’m not really interested in. I’m waiting for Howard Carter, the week after.)