2015年07月 文档列表

鸡腿遥控器

这里说的鸡腿,是指Wii经典的游戏手柄nunchuck。
Wii Nunchuck鸡腿遥控器

Wii Nunchuck鸡腿遥控器

这个单词到底是什么意思其实我也不知道,也不知道该怎么发音。不过大家一般都亲切的把它称为“小鸡腿”,看上去还真有点儿神似。
毕竟是大公司的经典工业设计产品,手感非常好!

Step 1: 功能区设计

鸡腿用于遥控电滑板

鸡腿用于遥控电滑板

原来的遥控器,只有一个JoySticker摇杆,自带一个按键。

而这个鸡腿有一个摇杆和两个按键,实际上它里面还有一个陀螺仪,不过我暂时没有想好用陀螺仪来做什么。

Step 2: 各种组装

剪掉壳里的支撑片

各种飞线和裸奔的模块

各种飞线和裸奔的模块

由于鸡腿里面的空间比较小,所以原来的洞洞板或者PCB板全都放不进去,只能裸奔着用飞线连接,然后一大坨塞进去。

另外,鸡腿里面的隔板还得剪掉,好在这个鸡腿不承力,强度还是够用的。

Step 3: 充电口和开关

一股脑塞进鸡腿

一股脑塞进鸡腿

开关和充电口

开关和充电口

原来的鸡腿是带线的,做遥控器当然要把线剪掉。

尾巴那里正好就可以用来安装充电口和开关。电路图你们就别找我要啦,这么简单个操作,跟连个灯泡是一样的 :)

Step 4: 蓝牙指示灯

连接指示灯

连接指示灯

把电路塞进鸡腿之后,有个比较大的麻烦就是指示灯。原来可以通过指示灯的闪烁,来判断蓝牙是否连接成功,现在全塞在里面了。

为了解决这个问题,我用小电钻在鸡腿上打了个小孔,然后在里面嵌了一个LED灯。
实践证明,虽然蓝色灯看上去比较漂亮,但是白天几乎看不清,还是用红色灯比较醒目。
鸡腿里面的空间太小,这个灯装的非常牵强,几乎是硬卡在那里的。有兴趣的同学以后可以改用贴片的那种小LED。

Step 5: nunchuck使用的Arduino库

在网上能找到很多针对numchuck的Arduino代码库,但是因为Arduino版本升级的原因,大部分都已经不能用了,编译错误。

我做了一些修改,目前Arduino的版本1.6.5已经可以顺利跑通。代码如下:
static uint8_t nunchuck_buf[6]; // array to store nunchuck data,

// Uses port C (analog in) pins as power & ground for Nunchuck
static void nunchuck_setpowerpins()
{
#define pwrpin PC3
#define gndpin PC2
DDRC |= _BV(pwrpin) | _BV(gndpin);
PORTC &=~ _BV(gndpin);
PORTC |= _BV(pwrpin);
delay(100); // wait for things to stabilize
}

// initialize the I2C system, join the I2C bus,
// and tell the nunchuck we're talking to it
void nunchuck_init()
{
Wire.begin();	// join i2c bus as master
Wire.beginTransmission(0x52);	// transmit to device 0x52
Wire.write(0x40);	// sends memory address
Wire.write(0x00);	// sends sent a zero.
Wire.endTransmission();	// stop transmitting
}

// Send a request for data to the nunchuck
// was "send_zero()"
void nunchuck_send_request()
{
Wire.beginTransmission(0x52);	// transmit to device 0x52
Wire.write(0x00);	// sends one byte
Wire.endTransmission();	// stop transmitting
}

// Receive data back from the nunchuck,
// returns 1 on successful read. returns 0 on failure
int nunchuck_get_data()
{
int cnt=0;
Wire.requestFrom (0x52, 6);	// request data from nunchuck
while (Wire.available ()) {
// receive byte as an integer
nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.read());
cnt++;
}
nunchuck_send_request(); // send request for next data payload
// If we recieved the 6 bytes, then go print them
if (cnt >= 5) {
return 1; // success
}
return 0; //failure
}

// Print the input data we have recieved
// accel data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits. That is why I
// multiply them by 2 * 2
void nunchuck_print_data()
{
static int i=0;
int joy_x_axis = nunchuck_buf[0];
int joy_y_axis = nunchuck_buf[1];
int accel_x_axis = nunchuck_buf[2]; // * 2 * 2;
int accel_y_axis = nunchuck_buf[3]; // * 2 * 2;
int accel_z_axis = nunchuck_buf[4]; // * 2 * 2;

int z_button = 0;
int c_button = 0;

// byte nunchuck_buf[5] contains bits for z and c buttons
// it also contains the least significant bits for the accelerometer data
// so we have to check each bit of byte outbuf[5]
if ((nunchuck_buf[5] >> 0) & 1)
z_button = 1;
if ((nunchuck_buf[5] >> 1) & 1)
c_button = 1;

if ((nunchuck_buf[5] >> 2) & 1)
accel_x_axis += 2;
if ((nunchuck_buf[5] >> 3) & 1)
accel_x_axis += 1;

if ((nunchuck_buf[5] >> 4) & 1)
accel_y_axis += 2;
if ((nunchuck_buf[5] >> 5) & 1)
accel_y_axis += 1;

if ((nunchuck_buf[5] >> 6) & 1)
accel_z_axis += 2;
if ((nunchuck_buf[5] >> 7) & 1)
accel_z_axis += 1;

Serial.print(i,DEC);
Serial.print("\t");

Serial.print("joy:");
Serial.print(joy_x_axis,DEC);
Serial.print(",");
Serial.print(joy_y_axis, DEC);
Serial.print(" \t");

Serial.print("acc:");
Serial.print(accel_x_axis, DEC);
Serial.print(",");
Serial.print(accel_y_axis, DEC);
Serial.print(",");
Serial.print(accel_z_axis, DEC);
Serial.print("\t");

Serial.print("but:");
Serial.print(z_button, DEC);
Serial.print(",");
Serial.print(c_button, DEC);

Serial.print("\r\n"); // newline
i++;
}

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char nunchuk_decode_byte (char x)
{
x = (x ^ 0x17) + 0x17;
return x;
}

// returns zbutton state: 1=pressed, 0=notpressed
int nunchuck_zbutton()
{
return ((nunchuck_buf[5] >> 0) & 1) ? 0 : 1; // voodoo
}

// returns zbutton state: 1=pressed, 0=notpressed
int nunchuck_cbutton()
{
return ((nunchuck_buf[5] >> 1) & 1) ? 0 : 1; // voodoo
}

// returns value of x-axis joystick
int nunchuck_joyx()
{
return nunchuck_buf[0];
}

// returns value of y-axis joystick
int nunchuck_joyy()
{
return nunchuck_buf[1];
}

// returns value of x-axis accelerometer
int nunchuck_accelx()
{
return nunchuck_buf[2]; // FIXME: this leaves out 2-bits of the data
}

// returns value of y-axis accelerometer
int nunchuck_accely()
{
return nunchuck_buf[3]; // FIXME: this leaves out 2-bits of the data
}

// returns value of z-axis accelerometer
int nunchuck_accelz()
{
return nunchuck_buf[4]; // FIXME: this leaves out 2-bits of the data
}