Thursday, November 9, 2017

White Wii Nunchuck shaped Bluetooth Joystick - £1.85/£1.99 on eBay

When I attended PiWars (a great event for people who like to build robots using the Raspberry Pi) earlier this year I saw a whole range of controllers being used for controlling Raspberry Pi based robots. With many using USB dongle ones and others using Bluetooth or even apps on phones.  Expecting to see some BlueDot next year a great Android App for controlling things over Bluetooth.

Since my phone is iPhone (too long to explain) BlueDot isn't an option for me and with my continuing goal of finding cheap solutions to a problem I found a £1.85 Bluetooth controller from eBay - 3D Bluetooth Virtual Reality Glasses VR BOX Game Remote Control Gamepad Handles

What I liked about it is that it uses AAA batteries so if at an event the batteries died I could swap them out. No need to wait for recharging.

It's billed as being for mobile gaming and virtual reality and no mention of working with a regular computer or even Raspberry Pi, so I took a punt for £1.85, well actually £3.70, as I bought two. (walking on the wild side). 

eBay order confirmation

NOTE: The listing I bought from has ended but the same seller has a new listing at £1.99

I've seen some similar listing with switches on the side.  This is not the model I have bought. Mine has no switch.

What it looks like on eBay listing

They arrived and actually look good.  Plastic is definitely cheap, but they don't feel flimsy.
Below are a couple of pictures of the real thing.  A little different to the render but I'm happy..

Top. Joystick, power button, mode change button and 4 facing buttons.

Front has 2 additional buttons for when held straight rather than sideways
Time to start testing.

Setting up a new Raspbian image and using Raspberry Pi ZeroW I added the two AAA batteries and it came on. Blue light flashes to say ready to pair.

Using the Bluetooth Add Device in Raspbian the device VR BOX was found and paired successfully.  The unusal name actuallymakes sense as the listing on eBay is for "3D Bluetooth Virtual Reality Glasses VR BOX Game Remote Control Gamepad Handles"

Bluetooth on Raspbian paired with VR BOX

From the eBay listing and the single sheet of instructions the Gamepad/Nunchuck has 4 modes that you select with a combination of the @ and the relevant button.

A : Function Select (Music Video Mode.)
B : Function Select (game mode)
C : Function Selection (VR video self-timer mode.)
D : Function Select (mouse self-timer mode.)

It starts up in Music mode, so to use as a gamepad you have to change this after it pairs.

As I wanted to test in game mode I did [@]+[B]

I previously created a small python/pygame program to help with the testing.  It's available on GitHub.

I downloaded it to the PiZeroW (one of these days I'll do the proper git clone thing) and ran the program.
I run from the command line as the terminal window prints the details in text while the pygame window gives a graphic representation of the gamepad so I can see if multiple button presses are possible and which button numbers are pressed.  The code includes an analogue joystick so it will show the full range of movement for the gamepad joystick.

python2/pygame gamepad tester

Pressing the buttons the appropriate red square appeared and the terminal window stated which button was pressed or released.  Success! It's being detected as a gamepad and the buttons are working.

I then used the joystick which looks like an analogue stick you see on many projects. Only it's not. The joystick is digital.  Up, Down,Left,Right.  No range in values.  Except for a strange thing.
The positive values are 0.999969482422 and the negative values are -1, so you can't test for 1 for down and right when in gamepad (sideways) mode as 0.999969482422 is not 1. A little gotcha for coding.

The different modes

As listed above there are 4 different modes for the controller.

[@]+[A] for music
Nothing happened on the Pi. I haven't figured out what Bluetooth Music Mode is yet.
I tried this mode with my phone and it does provide volume up/down, mute an play so does what is expected with the target device.

[@]+[B] game mode
This is gamepad in horizontal mode, like a traditional controller with the joystick on the left and the buttons on the right.
For example, if you push up the Up joystick is detected

[@]+[C] VR video self-timer mode
This is a gamepad in Nunchuck mode. So vertical.
For example, if you have the controller held vertically and press up then Up Joystick is detected.

All the buttons are the same as for game mode.

[@]+[D] mouse self-timer mode
Guess what the joystick operates like a mouse held like a Nunchuch (vertical) with the lower front button (trigger) being left click and the higher front button (trigger) being right click.
In mouse mode buttons A and B still get recognised as gamepad buttons so that could be useful.Not sure how or when but extra buttons are always useful. 

Button combinations

In game mode some of the buttons could be pressed at the same time while others could not.

@ and Power are reserved so have no button function.

Bottom trigger and top trigger could not be pressed at the same time. Lower trigger always took priority even if upper was pressed first.

Bottom trigger could be pressed with any of the face bottoms (A,B,C,D). Same for Top Trigger.

A could be pressed with C, but not B or D. A stays active and the others do not show.
If you press B or D first and then press A, A will be activated and the other will be released.

B and C can be pressed at the same time

D is over ridden by all face buttons, so if you have D pressed and then press any of the other their function is activated and D is released.

Also, either trigger and two button face combinations that were noted to work above will also work.
So, if you need 2 buttons at the same time and one is the master and the second one needs to be one of 4 I'd recommend using a trigger as the master and the face buttons as the secondary as this works for all face buttons.
If you need 3 buttons then there are a small number of combinations that will work.
Top button, A and C worked for me.

Future Note: I have a feeling this section may need a chart of some nature. Need to figure out how to represent it.

For Python/Pygame and I expect other system the buttons are numbered:

Gamepad Mode

Face button arrangement
C   D

Top Trigger: button 7
Bottom Trigger: button 6
A: button 4
B: button 0
C: button 3
D: button 1

VR mode (Nunchuck)

Face button arrangement
B   A

Top Trigger: button 7
Bottom Trigger: button 6
A: button 1
B: button 3
C: button 0
D: button 4

When I saw it changed I thought the button values would have turned clockwise 90 degrees so the buttons were in the same position (top, left, right, bottom) would have the same values but they don't. Top and bottom shift correctly, but left and right are mirrored.

Where did 2 and 5 go.  I wonder if they're on the board and not broken out. Might be a tear down thing


For £1.85, or £1.99, last time I checked if your need is digital controls then I think this is a hit.  It paired easily. The instructions though really sparse are enough to change modes.
With a phone it does the media things promised from mode A and on the Raspberry Pi and expect and device that supports a Bluetooth Gamepad and Mouse it does exactly what it says on the tin.

For controlling robots it's ideal (except for no analog).
Joystick for direction control and then buttons for other functions. Maybe take a picture, fire a missile, change mode from piloted to auto mode for different challenges at an event like PiWars.
With the advantage of using regular AAA batteries there is no fear that at an even the controller will run out of power and need to be charged.

A little but extra

As each controller having a unique Bluetooth Device ID it's possible to set up a cronjob on Linux to  pair with a specific gamepad when the Raspberry Pi (ZeroW) is booted/rebooted so  at events if you had 5 robots, 5 controllers each controller would be set up to work with a specific controller
It's not too complicated to do.

Get the device ID for the VR Box using the command bluetoothctl
Mine was FF:FF:70:00:76:8B

Run crontab -e
Select your editor if running for the first time. I use Nano

Go to the end and add the line
@reboot echo "connect FF:FF:70:00:76:8B" | bluetoothctl

If using Nano do a [ctrl]-[x] to exist and 'y' to save.
Reboot an you're done.

This will try to auto pair when the Pi boots.

You can also do a cronjob to continuously try to reconnect and not just at boot.
This is useful if the Pi has completed booting before the gampad has been turned on or if the controller hasn't been used for 10 minutes or in pairing mode fails to pair after 3 minutes and so needs to repair when the controller is turned back on