記事一覧

WiiのヌンチャクをArduinoで使って見る(その1)

I connected Wii Nunchaku to Arduino (No.1)

RoboTakaoです。ようこそ「極力ローコスト ロボット製作 ブログ」にお越しくださいました。
Hello everyone! I’m RoboTakao. Welcome to my robot blog.

先日Book OffでWiiのヌンチャクを180円で買った話を書きましたが、今回はこのヌンチャクをArduinoに接続してみたいと思います。

I posted the article that I bought used Wii Nunchaku at BookOff (used book store).

nunchaku01.jpg

ネットで見ると結構前から先人がテストしていてドキュメントも色々ありました。今回はお試しということで下記のブログのヘッダファイルとArduinoのスケッチをほぼそのまま使わせていただきました。

There are many documents of using Wii Nunchaku on Arduino on many web sites.

http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/

結線 Connections
WiiのヌンチャクをはI2C接続なのでとても簡単です。
Wii Nunchaku use I2C. It’s very easy.

nunchaku03.png

nunchaku02.jpg

結果 Results
特にトラブルもなく普通にXYZ軸の加速度とジョイスティックのXY軸そして2つのボタンの状態をシリアルモニタで表示できました。
ただし加速度は換算しないといけません。次回計算したいと思います。
I can print X,Y,Z axis accelerations and X,Y axis data of joystic and 2 buttons.



Arduinoのスケッチ
オリジナルのものに対して、すべてのデータを表示させるように微修正しました。

#include
#include "nunchuck_funcs.h"

int loop_cnt=0;

byte accx,accy,accz,joyx,joyy,zbut,cbut;
int ledPin = 13;


void setup()
{
Serial.begin(19200);
nunchuck_setpowerpins();
nunchuck_init(); // send the initilization handshake

Serial.print("WiiChuckDemo ready\n");
}

void loop()
{
if( loop_cnt > 100 ) { // every 100 msecs get new data
loop_cnt = 0;

nunchuck_get_data();

accx = nunchuck_accelx();
accy = nunchuck_accely();
accz = nunchuck_accelz();
joyx = nunchuck_joyx();
joyy = nunchuck_joyy();
zbut = nunchuck_zbutton();
cbut = nunchuck_cbutton();

Serial.print("accx: "); Serial.print((byte)accx,DEC);
Serial.print(" accy: "); Serial.print((byte)accy,DEC);
Serial.print(" accz: "); Serial.print((byte)accz,DEC);
Serial.print(" joyx: "); Serial.print((byte)joyx,DEC);
Serial.print(" joyy: "); Serial.print((byte)joyy,DEC);
Serial.print(" taccy: "); Serial.print((byte)accy,DEC);
Serial.print(" tzbut: "); Serial.print((byte)zbut,DEC);
Serial.print(" tcbut: "); Serial.println((byte)cbut,DEC);
}
loop_cnt++;
delay(1);
}


それでは今回はこの辺で失礼します!ありがとうございます。

スポンサードリンク

コメント

コメントの投稿

非公開コメント

プロフィール

RoboTakao

Author:RoboTakao
みなさんご訪問ありがとうございます。ロボット作りたいけどお小遣いそんなにないし、簡単でローコストでロボットを作るための私のプロジェクトを紹介します。

ウェブサイトもありますのでそちらもよろしくお願いします。
http://robotakao.jp/

スポンサーリンク