Wiimote as bluetooth transciever for an Arduino
After some trying, I have been able to use a wiimote for two-way communication for an Arduino. So far I just have a proof of concept. The code is very rough. For the set up and wiring, first look at my earlier entry on using the wiimote for one way communication.
Data is sent to/received from the Nunchuk by writing to/reading from address space 0x04A400xx. Data written to that location, then gets transmitted through expansion port using TWI. The arduino then reads it in.
My test code runs on linux and requires libcwiimote. You need to have version .3 of libcwiimote installed. Download my sample code at: test1.c. Just copy it over test1.c that comes with libcwiimote and run make again.
The test code will send the numbers 1 to 15 to the wiimote/arduino. The data will be transmitted to the wiimote and written to registers 0x04a40001 to 0x04a4000F where it will be sent to the arduino.
The sample code for the arduino is wiimotetest.pde. It will listen for input from the wiimote and write that input to a buffer. Once 50 bytes have been written to the buffer, the arduino prints the buffer out over its serial connection (just to prove that the data made it to the arduino. I used minicom to read the data). The arduino will transmit 6 bytes of data to the wiimote. This data will be transmitted back to the PC over bluetooth.
A sample of the input the arduino reads from the wiimote is:
Start Data Dump :0,:0,:0,:1,1,:0,:2,2,:0,:3,3,:0,:0,:4,4,:0,:5,5,:0,:6,6,:0,:7,7,:0,:8,8,:0,:0,:9,9,:0,:10,10,:0,:11,11,:0,:12,12 End Data DumpEach set of input is separated by ":". As you can see the wiimote seems to be constantly sending "0" to the expansion port. This is probably some type of handshaking used by the nunchuck. The numbers 1 to 15 you see where sent by the test1.c program. When test1.c sends a byte, the arduino reads two bytes. The first byte is the address and the second byte is the number. So for "2,2", I sent the number 2 to address 0x04a40002, for "3,3" I sent the number 3 to address 0x04a40003 and so on. That seems to be the pattern at least. At the same time, I had the arduino transmit back 6 bytes. Test1.c also show those bytes. The arduino can't read in TWI transmissions at the same time it sends serial data, so sometimes the data was a little weird. With a little work, I think a library could be written to adequately use the wiimote as a low cost bluetooth transceiver.