Welcome to Our Community

Some features disabled for guests. Register Today.

Raspberry Pi, Xbox Controller, bCNC and You!

Using a Xbox controller with bCNC.

  1. Hisha
    This post is going to cover connecting and getting to work a Xbox controller with a Raspberry Pi and bCNC. This will probably work also with any Linux machine that has a USB port and bCNC running on it, and honestly if whatever controller software you are using allows for keyboard movements and shortcuts it should work for them also. I am going to make the assumtion that you have your Linux machine up and running and configured with a working copy of bCNC. Basically what is happening here is that we are taking in the buttons from the Xbox controller and converting them into simulated keyboard keystrokes.

    So here we go!

    XPAD Section:

    First we need to blacklist Xpad, you might not even have it installed but this is a good practice so that it will not interfere with Xboxdrv down the road, so from a terminal window type "sudo echo "blacklist xpad" >> /etc/modprobe.d/blacklist.conf". What this command does it makes or updates a file blacklist.conf in the etc/modprobe.d folder with blacklist xpad. This will stop any update or manual request to install Xpad. We will follow this up with the command "sudo rmmod xpad", this will unload Xpad if it was already installed.

    XBOXDRV Section:

    The next thing thing to do is install "Xboxdrv", you can do this from source, but I'm a bit lazy so I use the command "sudo apt-get install xboxdrv" from a terminal window. Once this is done we can do a quick test to make sure everything going forward will work correctly. Plug your Xbox controller into a USB port and from the terminal type "sudo xboxdrv --silent". The "--silent" flag blocks a lot of spam you would normally receive, what you should see is an output listing your controller and the device location(s) inside of Linux. To stop Xboxdrv for the time being press "CTRL+C".

    Now that we have Xboxdrv installed we need to make it start at boot so everytime we boot it will be running already for us. From a terminal window type "sudo nano /etc/init/xboxdrv.conf", this command will create a new file in the etc/init folder called xboxdrv.conf and open that file in nano, which is a command line text editor. Enter the following in that file:

    start on filesystem
    exec xboxdrv -D
    expect fork

    Then you press "CTRL+X" followed by typing "Y" and then pressing "ENTER". "CTRL+X" tells nano that you want to exit, because you edited the file with those three lines it will ask if you want to save what you entered which we do so that's why you tpye "Y". Then finally it will ask what you want to name the file which we already supplied so we just press "ENTER".

    QJOYPAD Section:

    At this point we are done messing with Xboxdrv, but now we need to get QJoyPad working. So from a terminal window use the command "sudo apt-get install qjoypad". This will install QJoyPad and if you give it a few seconds should add it to your menu system. Under games you should now see QJoyPad, if you click it you will notice a new system tray icon that looks like a game controller. If that doesn't work open a terminal window and type "qjoypad --notray". Once the icon is there left clicking it should open a layout editor. First thing to do is click "Add" and name it if you want to. You can mess with the individual buttons if you want, but I just clicked on "Quick Set". This will open a new dialog box wanting you to press your desired controller button, once you press the controller button it will then ask you for the keyboard key you want to associate with that button to be pressed. The following is a copy of the keyboard keys that are preset by bCNC:

    bCNC Jogging Keyboard keys:

    <Right> pan +X
    <Left> pan -X
    <Up> pan +Y
    <Down> pan -Y
    <PgUp> pan +Z
    <PgDn> pan -Z
    <+> or <=> Increase step by one unit (=current decade)
    <-> or <_> Decrease step by one unit (=current decade)
    <1> Set as step the step1 (default 0.1) value from the configuration
    <2> Set as step the step2 (default 1) value from the configuration
    <3> Set as step the step3 (default 10) value from the configuration
    <*> Multiply step by x10
    </> Divide step by /10

    So how I configured my controller was as follows

    Controller Keyboard
    ________________________________________________
    DPad Left Left Arrow
    DPad Right Right Arrow
    DPad UP Up Arrow
    DPad Down Down Arrow
    Left Bumper PgDn Button
    Right Bumper PgUp Button
    Y Button "=" Button
    B Button "-" Button
    X Button "*" Button
    A Button "/" Button
    Guide Button(Big X in center) "F12" Button(See bCNC Shortcuts section)

    You can add as many keybinds as you have buttons, but that is up to you. Once you are done click "Done" and then from there click "Save". You now have a configured layout so you can click "Quit"

    The only thing left to do for QJoyPad is to have it start automatically when you log into the system. We will do this by adding "@qjoypad --force-tray" to "~/.config/lxsession/LXDE-pi/autostart". To do this, from a terminal window type "sudo nano ~/.config/lxsession/LXDE-pi/autostart", this will again open nano to edit the autostart file in your user's home folder( that's what the "~" denotes btw). After the current last line in that file type ""@qjoypad --force-tray", then you press "CTRL+X" followed by typing "Y" and then pressing "ENTER".

    At this point you can reboot the computer to get everything started and working. I am going to also lightly touch on shortcuts in bCNC which can be done before or after rebooting and will not hurt anything either way.

    bCNC Shortcut Section:

    In bCNC under the Tools tab is an option for Shortcuts, once you click that you will see the listing of the current shortcuts that are avaliable to assign. Just click on the right hand column inline with the key you want to assign something to and enter in the command. For example in my controller setup I have the "F12" key assigned "home" which will cause bCNC to run a homing cycle. You can see on the commandline link that you can even send G commands. The only little quirk I found is that you need to restart bCNC for bCNC to know about the new keybind.

    Hopefully this helps someone out, I hope to add screenshots later for some of the areas of this tutorial. If someone wants to make a how to video that would really be awesome. If there is any questions I can help as much as possible.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice