USB Button Solution

Home Forums AR Sandbox Forum USB Button Solution

Viewing 15 posts - 1 through 15 (of 100 total)
  • Author
    Posts
  • #102823
    Oliver Kreylos
    Keymaster

    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.

    Picture of USB button encoder with six arcade-style buttons and one naked microswitch.

    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
    #103041
    LulaNord
    Participant

    Hi…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.

    #103154
    liudr
    Participant

    So 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.

    #103487
    cmeans
    Participant

    Can anybody recommend a remote control that can control the different functions of the sandbox such as lava, water, flood, drought for use in presentations.

    #103504
    SFulton
    Participant

    I use a GP-Wiz40 from Groovy Game Gear.

    #103509
    tuchwando
    Participant

    Hi 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!

    #103570
    ajy00
    Participant

    For 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
    three buttons on the box

    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.

    #103645
    jKrienert
    Participant

    @ ajy00
    Your solution to cycle through fluid options with a single button is a great hardware solution!
    Thanks for sharing this.

    • This reply was modified 3 years, 11 months ago by jKrienert.
    • This reply was modified 3 years, 11 months ago by jKrienert.
    #103648
    liudr
    Participant

    I 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.

    #103656
    ajy00
    Participant

    @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! 😁

    #103657
    jKrienert
    Participant

    Were any major changes necessary to fix the crash issue?

    #103658
    ajy00
    Participant

    No changes at all… rerun and fine ever since!

    #103689
    liudr
    Participant

    Here is my rain and dry button box I built with Arduino:

    https://youtu.be/dn63OG_Z_Fs

    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.

    • This reply was modified 3 years, 10 months ago by liudr.
    • This reply was modified 3 years, 10 months ago by liudr.
    #103740
    nathan.counts
    Participant

    Wow that’s so cool man. I will definitely try it myself!

    #110853
    liudr
    Participant

    OK, here is my detailed post regarding the USB button box I constructed. Hope it helps:

    My blog post

Viewing 15 posts - 1 through 15 (of 100 total)
  • You must be logged in to reply to this topic.

Comments are closed.