The Wowwee Alive! controller
Having decided not to interfere with Wowwee's internals, hacking the remote seemed like a good idea. The controls are pretty straightforward - buttons and microswitches in a 4-way joystick configuration. Typically, the buttons are for vocalisations, the switches for actions. If I'd been more patient, I would probably have taken out all the connections from the controller PCB. As it was, I went for 3 buttons, a couple of switches, V+ and Gnd.
The Chimp Interface box
Like most engineers, I previously bought a microcontroller development kit, wrote a program to flash the LED, then, disgusted at having to use a parallel port, stuck it in a cupboard. As it turned out my Atmel MR-8 CPU Board from Active Robots was just the ticket for the chimperface, with a hardware UART and 20 I/O lines. I stuck the MR-8 in an old breadboard, added a MAX232-based level shifter, an LM7805 regulator to drop the 9v controller supply to 5v and wired up the MR8 PORTC bits to the custom remote connector.
The custom remote connector
With a bit of sawing and drilling (and biting), I managed to stuff the whole thing into an old iPod nano case.
ChimpOS
I needed a simple protocol for communicating with the chimp. It goes like this: issue a command "a" to "h". In response, the microcontroller pulls the appropriate PORTC pin high for 100ms and responds with "OO!". If there's an error, it returns "AA!". The whole thing looks like this:
program monkeyio
dim key as byte
dim crlf as string[3]
dim msg as string[20]
sub procedure pulse(dim portId as byte)
PORTC.portId = 1
Delay_ms(100)
PORTC.portId = 0
end sub
main:
crlf[0] = chr(13)
crlf[1] = chr(10)
crlf[2] = 0
USart1_Init(9600)
Delay_ms(10)
DDRC = $FF
PORTC = $00
msg = "Monkey API 1.0"
strcat(msg, crlf)
Usart1_Write_Text(msg)
while true
while USart1_Data_Ready=0
wend
key = USart1_Read
select case ( key )
case "a","b","c","d","e","f","g","h"
pulse(key - "a")
USart1_Write_Text("OO!")
case "*"
USart1_Write_Text("OO!")
case else
USart1_Write_Text("AA!")
end select
wend
end.
I used the demo version of the excellent BASCOM-AVR. Yes it's BASIC. So what? Server-side software Back in the comfortable world of Java, only the dirty details of connecting to the chimperface's serial port remained. I was somewhat pissed to discover that javax.comm only supports Unix boxes these days. Luckily, the fine folks at rxtx stepped in to plug the gap.
Code
The chimperface unit tests look like this:
package com.volutio.ma.chimp.io.test;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.volutio.ma.chimp.Chimp;
import com.volutio.ma.chimp.ChimpException;
public class ChimpTest {
private static Chimp s_chimp = null;
@BeforeClass
public static void setup() throws ChimpException {
s_chimp = Chimp.discoverChimp();
Assert.assertNotNull(s_chimp);
}
@Test
public void goNuts() throws ChimpException {
s_chimp.rollEyes();
s_chimp.makeBirdSong();
s_chimp.actFurious();
s_chimp.actRandy();
s_chimp.actTerrified();
}
}
Production code looks more like this:
public ChimpConsole() throws ChimpException {
// Create chimp
_chimp = Chimp.discoverChimp();
if (_chimp == null) {
throw new ChimpException("No chimp available");
}
// Add sniffers
_sniffers.add(new NewUserActivatedChimpSniffer().register(this).startSniffing());
}
Conclusion
That's it! For the future, I'll do a proper wiring job on the controller for greater monkey expressiveness. If there's even the slightest interest (you never know), I'll provide schematics so you can pimp your own chimp in safety.
No comments:
Post a Comment