No announcement yet.

DIY usb based relay/switch reader (based on a gamepad)

  • Filter
  • Time
  • Show
Clear All
new posts

    DIY usb based relay/switch reader (based on a gamepad)

    I had a requirement to read a couple of status lines from my home alarm (relay closures) - instead of close on 50 pounds for 2 powerflashes, I have bought a cheap (7 pounds) usb game pad with 10 switches on it. This afternoon I hacked around a plugin to handle the device so I can detect off/on and on/off on the switches and react accordingly in Homeseer.

    Next part of puzzle is to dismantle and rehouse the controller so I can have a 10 input relay board, usb based for next to nothing.

    Reason for posting is 2 fold:

    1) Have a missed an already existing plugin that does this.
    2) Is anyone else interested - at the moment the working code is less than an hour old - so it is not prime time - but as it is at the moment, I can put some work in to make it more "public" friendly if there is some mileage in it.


    there are indeed several plugins addressing this need already, do a search for "gameport" and you will find some very interesting threads on how to use this interface, and what you can do with it.
    HSPRO 2.4 (ESXi 4.1) | my.Alert NEW | my.Trigger | HSTouch | ACRF2 | UltraM1G | BLWeather | BLLan | Rover
    (aka xplosiv)
    Do You Cocoon? Home Automation News, Tutorials, Reviews, Forums & Chat


      Found one - and I may have missed something, but it did gamePORT based, my one uses the HID / USB interface - that said I am probably reinventing the wheel - but a 10 channel input device for 7 pounds was too good to miss.

      I recheck the groups and see what others have done - if they have something to offer then the learning curve alone was worth it.

      Thanks for the response.


        Nothing wrong with reinventing the wheel, there is always room for some improvement anyways, and as you said, it's a great learning experience. I bought 2 of those 1USB->4gameport adapters, so it is pretty cheap (and easy) to monitor many reed switches and such without having to invest in an expensive I/O board.
        HSPRO 2.4 (ESXi 4.1) | my.Alert NEW | my.Trigger | HSTouch | ACRF2 | UltraM1G | BLWeather | BLLan | Rover
        (aka xplosiv)
        Do You Cocoon? Home Automation News, Tutorials, Reviews, Forums & Chat


          Yours is unique.

          It is hid/usb based so, it can support more than 4 buttons and 3 axis

          And i suppose that yours reacts to events instead of the polling technique in the other joystick plugin.

          Keep working on this. I am excited! With usb hubs you could have hundreds of inputs. ( or thousands!)


            Thanks for the encouragement.

            Yes it is hid based - my current rig uses a 10 button gamepad that cost 7 pounds - 2 inputs currently attached - one for house alarm armed, another for house alarm triggered. I have also tested but not yet implemented reed switches and pressure mats.

            It uses directx to monitor the port status - so it's based on callbacks - so as you say no polling (I haven't looked at the gameport one, but I was concerned about missing a "contact" if it was a quick on/off inside the poll cycle) the call back in mine always fires, so far I haven't been able to trick it.

            I haven't done much with the axis stuff (I haven't needed to use it) and I also haven't scaled it past one device (again laziness - I haven't needed it yet) but both of those are easy to do.

            I'll take some of the less savoury error messages out and tidy up some error checking and post it, if anyone is interested they can play with it then.


              Do you have a URL to the device you purchased ?

              "The universal answer is 42."


                Can't find a url - it was purchased from the local branch of "GAME" - it's their own make, it retailed for 10 pounds but was 6.99 if you bought it along with something else - I bought a mag for a pound.

                I purvchased a general purpose box from Maplin to house it in - took the controller apart and rehoused it in the box - bringing the connections to jack plugs (I happened to have a number of them already).


                  Where is the plugin for the USB Gameport?

                  Hi, I was reading the threads, but for the life of me I can't find the posting of your code, or have ya not done it yet. It sounds exactly what I am needing.



                    Haven't posted yet - have been playing with it a little - I will try to post a stable version this weekend - need to remove some of the "less meaningfull" erro messages.Malarcy


                      Thanks, I found a new device, and it needs just your plugin

                      Hey, I appreciate it, I found a neat USB interface that has alot of inputs. It's meant for a flight simulator cockpit with joysticks and switches, but its just the ticket for input for my home automation. I emailed him, and its about $102 US for the board, expansion, and Shipping to US. It looks neat, take a look at:

                      Here is a snippet.

                      Interface to computer USB 1.1 low speed
                      Number of analogue axes inputs 8
                      Analogue axes inputs resolution 10 bits
                      Number of pushbuttons 64
                      Number of toggle switches 16
                      Toggle switch action Double
                      Number of rotary switches 4
                      Rotary switches type Phase-shifted
                      Rotary switches action Double-speed
                      Number of hat switches 1
                      Hat switch type 8-way
                      Automatic calibration feature Included
                      Centring feature with disabling possibility Included
                      Controls mapping mode selection feature Included
                      Multiple joystick controllers support and ordering feature Included
                      Cockpit wiring complexity reduction using optional Key Matrix board Included

                      Thanks again, and if i can help you test the plugin, just let me know. I'd be happy to help!



                        Holy sh........

                        That's one hell of a device - and more inputs that you can shake a stick at, the plugin as currently exists will only handle the push buttons - who knows how this thing will enumerate.

                        I can add code for the axis - I don't have anything to test with currently - but I am planning to add that support anyway.

                        I will happily share what I have - but I think it will fall short for the "mother" of usb hid devices - hopefully it will get you going.



                          Can't wait, got plenty of ideas!

                          I want to say thanks ahead of time for working on it, I am really looking forward to getting the code, I am currently playing around with VB and a 6 button joystick, but I think you already got most of it figured out.

                          I'm wanting to be able to detect the deadbolts being locked, I can not stand getting into bed, getting comfortable, and hear "did you lock the door?"..arrrrggggg

                          I know several people have spoke of reading deadbold lock/unlock. I've tried several pushbuttons and switches, but none seem to be 100% reliable. I think im gunna epoxy a small piece of neodymium magnet to the end of a of the deadbolt, and put a reed switch in the jam. These are pretty powerful magnets (N48) so it want have to be too close to sense it.

                          I am also about to start tinkering with a way to automatically close and open the french doors to my living room. I got a few 6" throw bi-directional air pistons with end of throw detectors on both ends. I would use the joystick button inputs to detect if it made it all the way open/closed.

                          I was also thinking about using vacuum pressure to open/close the doors. I have a manifold assembly and a nebulizer pump which puts out some good vacuum that should work nicely.

                          Only problem is how to hide the closer mech, waf will dwindle if she sees pneumatic tubing and the pistons on the floor. I gotta find a way to bury them in trim work or something??? The WAF took a big dip this week because I unhooked the CM11a from the computer. So all night, lights were going on and off whenever they wanted..

                          Oh well, im off to tinker some more. (trying to build screeens for mainlobby).

                          Thanks again!




                            Since you have vb I think the easiest way forward is me to send you the source code I have, and then we can drill into the bits to give you what you need - for example in my current config, I only have one HID device connected, so the code for getting the capabilities of the device is lazy - i.e. if a HID device is present it's the one I want, and I know how many buttons it has etc.

                            I haven't currently go the bandwidth to turn this into a general consumption plugin - but since you have compiler access I can help you get started.

                            email address is in my profile - let me know how you want to procede.



                              Malarcy - please do this.

                              Its very hard to find gameport keypads. They are all USB now.

                              I'd be extremely interested in this plug-in for USB devices.

                              Steve C,