網頁

2020年5月27日 星期三

Connect Raspberry PI and Wii

以下以適用 Jetson Nano

搖桿, Gamepad, Joysticks
參考 Wiimote Controller Configuration for Raspberry Pi 2/3
參考 How to Connect Wiimotes to the Raspberry Pi
參考 wminput.list
參考 action_enum.txt
參考 pd-l2ork cwiid

$ cat mywminput
# Classic-Controller
#Classic.Dpad.X = ABS_X
#Classic.Dpad.Y = ABS_Y
#Classic.LStick.X = ABS_HAT0X
#Classic.LStick.Y = ABS_HAT0Y
#Classic.RStick.X = ABS_HAT1X
#Classic.RStick.Y = ABS_HAT1Y
Classic.A = BTN_A
Classic.B = BTN_B
Classic.X = BTN_X
Classic.Y = BTN_Y
Classic.Minus = BTN_SELECT
Classic.Plus  = BTN_START
Classic.Home  = BTN_MODE
Classic.L  = BTN_TL
Classic.R  = BTN_TR
Classic.ZL = BTN_TL2
Classic.ZR = BTN_TR2

# WiiMote
Wiimote.A = BTN_A
Wiimote.B  = BTN_B
Wiimote.Dpad.X = ABS_HAT0X
Wiimote.Dpad.Y = -ABS_HAT0Y
Wiimote.Minus = BTN_SELECT
Wiimote.Plus = BTN_START
Wiimote.Home = BTN_MODE
Wiimote.1 = BTN_X
Wiimote.2 = BTN_Y

# Nunchuk
Nunchuk.C = BTN_C
Nunchuk.Z = BTN_Z
Nunchuk.Stick.X = ABS_RX
Nunchuk.Stick.Y = -ABS_RY

Plugin.led.Led1 = 1
#Plugin.led.Led2 = 1
#Plugin.led.Led3 = 1
#Plugin.led.Led4 = 1

Plugin.ir_ptr.X = ABS_HAT1X
Plugin.ir_ptr.Y = ABS_HAT1Y

Plugin.acc.X = ABS_X
Plugin.acc.Y = ABS_Y
#Plugin.acc.Z = ABS_Z


$ cat connectwii.sh

#!/bin/bash
sleep 1 # Wait until Bluetooth services are fully initialized
hcitool dev | grep hci >/dev/null
if test $? -eq 0 ; then
    wminput -d -c  /home/pi/mywminput 00:1A:E9:EB:07:2A &
else
    echo "Blue-tooth adapter not present!"
    exit 1
fi

同時按下1,2 並放開
$ sudo ./connectwiimote.sh
$ sudo apt-get install jstest-gtk
$ jstest-gtk
$ ps -efa | grep wminput
$ sudo kill -9 pid


使用 python 控制
參考 Raspberry Pi 4 bluetooth scale
參考 wiiweigh
參考 xwiimote

export PYTHONPATH=/usr/lib/python2.7/site-packages
sudo visudo
Defaults env_keep += "PYTHONPATH"
加入上一行

同時按下1,2 並放開
$ bluetoothctl
[bluetooth]# connect 00:1A:E9:EB:07:2A
[bluetooth]# exit
$ xwiishow list
Listing connected Wii Remote devices:
  Found device #1: /sys/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:12/0005:057E:0306.0004
End of device list
$ xwiishow 1
$ bluetoothctl
[bluetooth]# disconnect 00:1A:E9:EB:07:2A
[bluetooth]# exit
$ cd src/xwiimote-bindings/examples/python
$ sudo python xwiimote_test.py

可以加入下列程式
        elif evt.type == xwiimote.EVENT_NUNCHUK_KEY:
            code, state = evt.get_key()
            print "Nunchuk Key:", code, ", State:", state
        elif evt.type == xwiimote.EVENT_NUNCHUK_MOVE:
            x, y, z = evt.get_abs(0)
            #print "Nunchuk controller move 1:", x, y
        elif evt.type == xwiimote.EVENT_ACCEL:
            x, y, z = evt.get_abs(0)
            #print "Accelerometer move 1:", x, y, z


Wii Balance Board
參考 chaosbiber / wiiweigh
參考 Raspberry Pi Smart Scale
參考 Disassembling Wii Balance Board
參考 Wii Balance Board Smart Scale ( w/ ESP32 )

HX711接腳
青-E+
綠-E-
紅-A-
白-A+

雙黑 開關
LED 白P 青N

沒有留言:

張貼留言