Home › Forums › AR Sandbox Forum › USB Button Solution
- This topic has 99 replies, 25 voices, and was last updated 5 days, 21 hours ago by ajy00.
-
AuthorPosts
-
December 12, 2016 at 9:06 pm #102823Oliver KreylosKeymaster
We finally found a good and cheap option to add custom buttons to AR Sandbox installations: Reyann Zero Delay Arcade USB Encoder. It comes as a modular package with a small circuit board, a USB cable, and thirteen button cables compatible with standard 4.8mm terminal microswitches. Assembling it and connecting buttons does not require soldering. Amazon also offers sets of six high-endurance arcade-style buttons in a variety of colors that match this encoder.
Most USB buttons emulate keys, and have a bug in key repeat handling that can cause input buffer overflows and AR Sandbox hangs. This encoder directly advertises up to twelve generic HID buttons, which is more stable and also does not cause interference with desktop applications.
To assemble the encoder, simply plug the provided USB cable into the matching four-prong plug on the circuit board, and your desired number of button cables into the two-prong button plugs along the opposite long edge of the board. Connect the other ends of the button cables firmly to the terminals on your microswitches; polarity does not matter.
Do not use the four two-prong plugs on the short edge; those have special functions and are not sent over the HID protocol. The button plugs along the long row are named “Button0” to “Button11”, in increasing order away from the two power and mode indicator LEDs. You can use any subset of button plugs, they don’t need to be connected consecutively.
After assembling the controller, visually double-checking for short circuits, and plugging the USB cable into your computer, run
lsusb
from a terminal to check that the encoder is detected. It will be listed as:
Bus XXX Device YYY: ID 0079:0006 DragonRise Inc. PC TWIN SHOCK Gamepad
where the bus and device numbers depend on your local setup.Making the encoder usable from the AR Sandbox requires a few simple steps. First, create a device rule to allow non-administrative users to access the button device. From a terminal, run
sudo pluma /etc/udev/rules.d/69-USB-encoder.rules
(pluma is MATE’s text editor; adapt as appropriate). Into the empty file, insert exactly the following line:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0079", ATTRS{idProduct}=="0006", TAG+="uaccess"
then save the file and exit the text editor. Unplug and re-plug the encoder’s USB cable to activate the new rule.Next, create or open the AR Sandbox’s patch configuration file (please see this thread for more information and instructions). Insert the following lines into the “Desktop” section:
section Vrui section Desktop ... inputDeviceAdapterNames += (HIDAdapter) ... section HIDAdapter inputDeviceAdapterType HID inputDeviceNames (USBEncoder) section USBEncoder name USBEncoder deviceVendorProductId 0079:0006 trackingDeviceName Mouse endsection endsection ... endsection endsection
Save the new or edited file, and run the AR Sandbox as usual. If you now press and hold any of the connected buttons, the usual Vrui tool selection menu pops up. Move the mouse to select a tool, and release the pressed button. Then assign additional buttons as usual.
To make the new tool assignments permanent, save the input graph via the main menu’s “Vrui System”->”Devices”->”Save Input Graph” entry, and optionally add the new bindings to the AR Sandbox’s patch configuration file as explained in the forum post linked above. The device name to use for tool bindings is “USBEncoder”, and the button names are “Button0” to “Button11”.
One side effect of using a generic HID button interface is that it is no longer possible to bind desktop shortcuts to the buttons to execute external scripts, such as switching between water and lava rendering modes or changing color maps. To fix this, and to centralize and simplify script management, I added a “Script Executor” tool class to Vrui that can execute scripts from within a Vrui application, bypassing the desktop environment’s mechanism.
The new tool class has not yet landed in Vrui-4.2-006, but can easily be added to an existing installation. Download the tool class’s source code, ScriptExecutorTool.h and ScriptExecutorTool.cpp and save them into the Vrui/Tools subdirectory of the Vrui source code directory. Then run from a terminal:
cd ~/src/Vrui-4.2-006 make sudo make install
to build the tool class and install it.
The new tool class needs to be activated before it can be bound to a button dynamically. Open the AR Sandbox’s patch configuration file again, and insert the following line into the “Tools” section:
section Vrui section Desktop ... section Tools ... toolClassNames += (ScriptExecutorTool) ... endsection endsection endsection
After saving the file and running the AR Sandbox as normal, press some button and select a “Script Executor” tool from the “Utility” submenu of the tool selection menu. A file selection box will pop up where you can select the script you want to execute. It might be easier to bypass this dynamic set-up step and add tool binding sections for script tools directly to the AR Sandbox’s patch configuration file. Use the tool class name “ScriptExecutorTool” and specify the name of the script to be executed by inserting the following tag into the tool binding section:
executablePathName /path/to/and/name/of/your/script
It is also possible to pass command line arguments to scripts, but this can only be done by editing a configuration file or an input graph file. In the appropriate tool binding section, insert a tag
arguments ("argument 1", "argument 2", ..., "argument n")
where each argument is enclosed in double quotes.- This topic was modified 4 years, 7 months ago by Oliver Kreylos. Reason: Added picture of assembled button encoder
March 1, 2017 at 11:06 am #103041LulaNordParticipantHi…i am a new user here. I am having trouble with the USB button. We ordered one of the buttons from the user who posted their Etsy store. We’ve plugged it in and can see it light up, but we can’t seem to get Linux to detect any input from the button. The forum for the button says there should be no drivers needed and when we plug and unplug the button we can see the name of the device appear and disappear when utilizing the “lsusb” command. Any help that can be provided would be much appreciated.
April 7, 2017 at 8:36 pm #103154liudrParticipantSo if a push button press generates “1 is pressed down”, then it would be the same as you pressing and holding “1” on your keyboard, correct? Arduino should be able to do that. The catch is you need to do some programming and soldering. Nice thing about using arduino is, you can, say, program an override switch that disables calibration related buttons. Hide the switch under the sand box and keep it on. Only turn it off when you calibrate so kids won’t mess with these buttons.
June 19, 2017 at 2:11 pm #103487cmeansParticipantCan anybody recommend a remote control that can control the different functions of the sandbox such as lava, water, flood, drought for use in presentations.
June 22, 2017 at 12:42 pm #103504SFultonParticipantI use a GP-Wiz40 from Groovy Game Gear.
June 27, 2017 at 9:22 am #103509tuchwandoParticipantHi All,
I’d like to use the joystick connected to my USB Encoder (the one listed above, Reyann Zero Delay Arcade USB Encoder) to control the local water tool. That is, the user should be able to move a “pointer” around the landscape using the joystick, then press a button to cause rain to fall at the present location.
Is there a simple way to tell Vrui to do this? I tried binding this tool to the USB encoder, but when I move the joystick, Vrui asks to bind it and I’m not sure what the correct choice is. Preferably, I want the binding to be done in the patch config file.
I’m guessing this could be done by adding to the local water tool class, overriding the mouse position typically used in that tool. I could read from the two axes (valuators?) from the joystick, use that to control a new pointer position that I use as the rain position (location where the rain cylinder is rendered). However, I wanted to check if there was a simpler way before jumping in to modifying the code.
Thanks in advance!
July 22, 2017 at 5:24 am #103570ajy00ParticipantFor the RiverWey Trust version of the SARndbox, I’ve now set up three USB buttons – Flood, Drain, and Cycle – where the first is the global water tool, Drain is.. drain, and the third assigns a script (as in Oliver Kreylos’ post above) which cycles round the Water, Lava, Snow options
As a green bash script coder this works but is probably a bit clunky!
# weather.sh #!/bin/bash # pick up current state weather=$( cat /home/sandbox/src/scrip/weather_file.tmp ) echo "Current state is " $weather # use case statement to set the assignment to the next cycle value case $weather in "rain") echo "Changed rain to lava" sh /home/sandbox/src/scrip/switch-to-lava.sh echo "lava" > /home/sandbox/src/scrip/weather_file.tmp ;; "lava") echo "Changed lava to snow" sh /home/sandbox/src/scrip/switch-to-snow.sh echo "snow" > /home/sandbox/src/scrip/weather_file.tmp ;; "snow") echo "Changed snow to rain" sh /home/sandbox/src/scrip/switch-to-water.sh echo "rain" > /home/sandbox/src/scrip/weather_file.tmp ;; esac
The switch scripts are versions of those appearing in the ‘snow shader’ topic in this forum ..
cp ~/src/scrip/SurfaceAddWaterColor-Lava.fs ~/src/SARndbox-2.3/share/SARndbox-2.3/Shaders/SurfaceAddWaterColor.fs
using suitably updated versions of SurfaceAddWaterColor.fs
For the USB buttons, the Reyann branded button options in UK came out at some hugely inflated price on Amazon UK (equivalent $60+)… so xSource (https://www.amazon.co.uk/d/Joysticks/XCSOURCE-Delay-Arcade-Encoder-Joystick-Fighting-AC488/B01LAUYCXE/ref=pd_sim_107_2?_encoding=UTF8&psc=1&refRID=DFKRG5PA12K6NTNXYZK9) at £16.99 ($22) for the same solution is much better … and there is an option for the board without buttons should you wish.
August 15, 2017 at 6:22 pm #103645jKrienertParticipantAugust 15, 2017 at 10:17 pm #103648liudrParticipantI decided to build my own box with buttons and arduino. I’m hiding a button under the box for shutdown. Hopefully there will be enough space in the box to have a cycle button. Great idea! Will post my story once I get mine working.
August 16, 2017 at 11:48 am #103656ajy00Participant@jKrienert … can’t see your last q here, but the first time the script ran the program crashed, but since then it runs with no problems.. you’re script & config looks identical to the one i use as above…
I load the whole config and assignment from a saved input graph. hope you resolve the problem! 😁August 16, 2017 at 5:20 pm #103657jKrienertParticipantWere any major changes necessary to fix the crash issue?
August 17, 2017 at 1:16 am #103658ajy00ParticipantNo changes at all… rerun and fine ever since!
August 31, 2017 at 2:39 pm #103689liudrParticipantHere is my rain and dry button box I built with Arduino:
The buttons are flashing periodically to invite people to press them. These buttons are essentially keys ‘1’ and ‘2’ so I can use them in calibration programs as well. Later I will add two more buttons on the underside to start the program and shut down the machine.
September 20, 2017 at 11:16 pm #103740nathan.countsParticipantWow that’s so cool man. I will definitely try it myself!
January 1, 2018 at 8:08 pm #110853liudrParticipantOK, here is my detailed post regarding the USB button box I constructed. Hope it helps:
-
AuthorPosts
- You must be logged in to reply to this topic.