Showing posts with label controller. Show all posts
Showing posts with label controller. Show all posts

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
  A 
C   D
  B


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
  C
B   A
  D

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


Summary

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


















Friday, October 9, 2015

9th Egham Jam – Show and Tell Competition – Prizes donated by 4tronixs


I think we might be coming to the end of the Prize announcements.
So, last but not least are the Prizes donated by 4tronixs.

Robot lovers Prizes from 4tronixs

These prizes are especially situated to the robots lovers.

Each Prize includes:

The PlayHat includes a 3x3 full colour neopixel LED matrix, 4 big buttons and a buzzer.
Great for programming with the Raspberry Pi. This is just begging out for a game of Simon to be created.

PiRoCon and iBoost64 This board is great. Te PiRoCon  plugs right on top of the Raspberry P and gives you all the additional electronics needs to drive motors.
Motors are fun things. When they start they draw a lot of  power (think of train pulling out of the station. It needs far more power to get going then it does to keep itself moving.  Same thing for motors).  This mean if you want to drive motors you need extra circuitry to do it safely without damaging your Raspberry Pi.  The PiRoCon is one of the best solutions for this for the Raspberry Pi.

In addition to motors drawing a lot of power when they start and stop they can also affect the voltage and current of electronics drawing from the same power supply.  This can cause difficulties in getting good readings or accurate control.  This is where the iBoost64 comes in.  It cleans up the signals and makes them good without affecting the rest of the circuit.  Ideal for robots where there can be a lot of stopping and starting of motors as well as reading of external sensors for line following or object avoidance.

With the combination of the PiRoCon and iBoost64 you have the electronics to get that robot built.
If working in Scratch the current ScratchGPIO library from Simon Walters supports the PiRoCon.

If you have robots you will need power.  The final 2 boards are a 1 way and 4 way charger board for Li-Po batteries.  These are great batteries for robotic as they store lots of energy and give out a consistent voltage.  Cheap batteries have a power curve that means they very quickly drop from the maximum voltage which can cause lots of problems with motors.  Li-Po batteries are the ones used in high quality remote control cars.
Unfortunately you can't just plug a Li-Po battery into your normal battery charger due to the way they work so custom chargers are usually provided or need to be purchased with the battery.  These great little boards mean you can use a standard 5V microUSB power supply to charge the batteries.  This is the same type of power supply used for the Raspberry Pi, meaning if you are building a Raspberry Pi based robot you will already have the correct power supply.
There are 2 different boards included.  A 1 way, so it can charge 1 battery and a 4 way which can change 4 batteries at the same time.  Giving you more than enough power for your laser guided, GPS tracking, missile shooting, web cam streaming, grabber, digger, flame thrower robot. Or maybe just a line following robot.

From the picture you can see they also provided some pens.

Thank you 4tronixs for the prizes.