Tuesday, August 31, 2010

Gakken Japanino + LCD Shield



I originally wanted to write about my Japanino/Edo clock project first, but I ended up waiting for the opportunity to make a youtube video for it.
Edit: I added a link to the youtube video. It's pretty shaky and not all that informative, but I think it conveys the application of the dual-axis accelerometer, and some of the graphics that can be generated using it.

Back at the beginning of August, I got some kits and components that I'd asked for my birthday. I wanted to do some experimenting with the Gakken Japanino kit, which is just the Arduino microcontroller with a couple of extra power pins. The presents I received were all from Sparkfun, so this is going to look kind of like an ad for them, but it isn't (not until they start paying me to talk about them here, anyway).

Three of the items are the color LCD Shield, the Proto Shield and the 2-axis accelerometer. I started out trying to get the LCD Shield to work first. It's a 132x132 pixel display from Nokia, that is used in cell phones. There's no code supplied with the kit for making it work, so I had to surf the net to find working examples. Sparkfun does have a link to one site that has example code for drawing lines, dots, raw RGB images and a Mandelbrot. But, the code is designed more for the Arduino Mega, and doesn't fit in the Japanino's limited memory space. So I ripped the Mandelbrot and raw RGB stuff out, plus the code for supporting both the Epson and Philips controller hardware (my board has the Epson hardware so I don't care about Philips support). Then I found the example of an analog/digital clock using the one-wire real-time clock, which gave me functions for drawing circles and writing text. After pulling out the 1-wire code and adding Japanese characters to the font table, I set to work to make a digital version of the Edo clock (pictures of that to come later).

The bottom line regarding using the LCD Shield with the Japanino is that you're limited to small programs - 1K of variables and 14K of code. This means simple block-graphic games, clocks, and line-drawing "screen-savers". On the other hand, it's also good for code debugging, because now you can display text to the screen. However, it can go through batteries fast. I bought a block of 10 AAA batteries for 300 yen ($3.30 USD), and drained 3 of them down to nothing by letting the digital Edo clock program run for 24 hours non-stop.

Additionally, there's no real graphics library for the LCD shield. You need to take what's available, clean it up for your own purposes, and use that. Meaning that you need to know some C++ programming.


(Protoshield with the accelerometer breakout board mounted)

Next, I focused on the 2-axis accelerometer. This is a microelectromechanical system (MEMS) with two small sensors that measure the force applied to them either through movement of the circuit, or the pull of gravity. These things are used in the Wii controller for interfacing to games, and in the Mac laptops to shutdown power if it gets dropped while being carried (they're also good for stabilizer circuits for robots). The 2-axis version can measure motion left and right, back and forth (the 3-axis one adds up and down) as a voltage value between 0.5V and 2.5V. By mounting the breakout board on the Protoshield and then wiring it up to analog pins A0 and A1, I was able to combine it with the Japanino and the LCD shield. Then I just wrote a short sketch to read the two analog pins and display the result on the screen as either a real-time line, or a single dot. This gives me an earthquake sensor. If I wanted to, I could connect the kit to my PC and output serial data to it for real-time data logging. Right now, I'm just drawing pretty pictures with it as I tilt the assembly back and forth.

The LCD shield has 3 push button switches, which I'm reading on pins D3-D5 for toggling text display on and off, and for switching between the line display and the real-time dot.



One more program variant that I'm considering writing is to monitor the accelerometer pins for a big, fast change, then freezing the display, showing the time and amplitude of the change. Again, for earthquake tracking. It'd be a simple routine. The only two drawbacks are that we haven't really had any earthquakes here for a while, and the batteries would probably die out long before the quake hit.

In conclusion, the LCD shield, the proto shield and the 2-axis accelerometer all played together well with the Japanino. They're a fun combination, and it'd be really easy to plug in a speaker to one of the remaining PWM pins to add an audio alarm to the earthquake sensor, or to turn the tilt sensors into a kind of motion-controlled theremin. Good stuff, Maynard.

No comments: