GPioneer - A side project compatible with PiPlay
  • GPioneer - A Python Based GPIO Controller

    I'm releasing a side project that is compatible with PiPlay called GPioneer. A Python based GPIO controller. For anyone that is familiar with Adafruit's RetroGame Utility, this is very similar. The main difference being that this is much more user friendly.
    • It has a configuration tool to auto map keystrokes to buttons
    • it has a web-front end to modify settings/will auto integrate with piplay's web frontend
    • supports button combinations for alternate keystrokes
    • It supports system commands! (you can map volume/shutdown/etc to buttons)

    How to install

    in terminal type:
    cd ~
    git clone https://github.com/mholgatem/gpioneer.git
    bash gpioneer/install.sh

    That's it! The installer is still very much in the beta stage, so let me know if you have problems. But I have tested it on several clean raspbian/piplay images with no problem.

    How to use

    After the installer runs, you will be prompted to run the configuration tool. You will be prompted to press each direction twice to register the correct gpio pins (note: after registering 'up', you can skip any configuration by pressing up twice).
    After running the configuration, GPioneer will automatically run in the background. You can customize any buttons or add your own custom combos by going to the web interface on a local computer (Pi's ip address/if you have piplay installed, go to the 'database admin->GPioneer' section)

    I'll be editing the 'readme' section of the git repository soon to add some extra info
  • Well done @mholgatem great idea. No one knows better than you the problems encountered when trying to get the GPIO based joysticks/buttons working (I alone have been harassing you with no end of questions and troubleshooting advice!). Now that I've got my controller working pretty darn well though I'm reluctant to switch, though probably will at some point. Would be interested to hear how people go and what they think.

    Keep up the good work mate.

    tSm
  • Thanks. I've just been enjoying the fact that I can now control volume and I have about 5 games that I can auto launch with the press of a button.
  • Oooooow, control volume. I'd like that. Would it be hard to move from one to the other (and back if something breaks)?

    The flexibility of it sounds great in lieu of all the basic functions on mine working but anything secondary doesnt.

    Might even be a workaround to that tab problem I'm having on the keyboard.
  • Yeah, it's really easy to switch around because it doesn't really install anything that piplay doesn't already install. Are you running Adafruit's Retrogame utility currently?
  • ok, I just updated the installer. It will now automatically comment out retrogame from your /etc/rc.local and/or /home/pi/.profile files so that retrogame won't activate on startup, but the files will still be there. If you decide that you want to switch back, just type:
    sudo nano /etc/rc.local

    and remove the : # from in front of the retrogame command, and put # in front of the gpioneer command.

    easy peasy


    ignore that. I added a removal script to the repo. Just run bash remove.sh to uninstall gpioneer and re-enable retrogame (if it was disabled by gpioneer)
  • Excellent, will give it a go when i get a chance and see how it goes. Thanks very much.
  • Okay so fired this up. Installed and ran the config tool which all seemed to go well. I set the select button to to button 1 but that doesnt seem to work in the Pi Play menu or within Advance Mame (when i navigate there with the keyboard). Left, right, up and down work fine in the Pi Play menu i should probably add. Have I forgotten something, or do i now need to go and adjust the advmame.rc? Thanks
  • Would also be interested to see how to go about creating a volume up and down control using the held down 1P coin button (pin 33) + up on joystick (pin 3) and 1P coin button (pin 33) + down on joystick (pin 5).

    Also is there a list of all keyboard functions on piplay/advmame? I do recall seeing one a while back but a search hasnt turned up anything.

    Thanks for all the help. :)
  • oh, sorry. I should have mentioned. At the beginning, when you are configuring, it will go up/down/left/right/exit/start... then it will have you configure 'select', which is like the select button on a regular nes controller, not like 'select this option'. When you configure player1 -> generic button 1, it will automatically be assigned as the 'Enter' key, which should allow you to make selections in piplay (as for advmame, you may need to run the controller config to get it all set up correctly)

    You can also change any of the key's/ add commands by going to the web front-end:
    Pi's IP address -> Database Admin -> GPioneer

    You should see a list of already configured keys:
    • Name: can be anything, it's just for the user to know what they are for
    • command: use 'KEY_' to send keystrokes, anything else will be sent as a system command. Multiple keys/commands can be assigned by separating them with a pipe '|'
    • pins: these are the pin(s) that when pushed (together), will send the keystroke or command. You can separate these with a comma to require that multiple pins be active in order to send a command.


    So, in order to configure volume up and volume down like you want, you would create a new entry:
    Name: Volume up (or whatever you want)
    command: /usr/bin/amixer -q -c 0 sset PCM 3dB+ unmute nocap
    pins: 3, 33

    Now create another entry:
    Name: Volume down
    command: /usr/bin/amixer -q -c 0 sset PCM 3dB- unmute nocap
    pins: 5, 33
  • Yeah cool worked that bit out and when navigating to the Pi's IP address -> Database Admin -> GPioneer it looked like it had assigned the "enter" key to player 1 button 1 like i wanted, but still didnt work. Will have another look tonight. On that note it would likely be a good option for me to reconfigure again. Is there a command for me to do that? I assume there is an easier option than unistalling GPioneer then reinstalling and running through the config again?

    Thanks for the Volume commands, I'd never have worked that out. :) Think I'll have to hit you up for a 3 button combo script to shut down the Pi in the future as working that out will be beyond me.

    Thanks again.
  • Did you at some point alter your /home/pi/pimame/pimame-menu/controller.yaml file? maybe 'enter' isn't the key that you need for that anymore.

    You can rerun the configuration by running:
    sudo python ~/gpioneer/GPioneer.py -c

    a 3 button combo for for shutdown or reboot will be pretty easy
    Name: shutdown
    command: sudo poweroff or sudo reboot
    pins: 33,35,37 (will be different based on what buttons you want)
  • Perfect, thanks man. Gives me plenty to work on! Will let you know how I get on. Cheers.
  • Yes, you can. It will register each as a separate device. The only thing that it doesn't play well with is other programs that use the gpio (retrogame) because it cant see what pins that they are trying to control
  • piplay controls audio via 2 methods. The in-menu music (only some themes have music) is controlled using pygame's built-in volume control, which does not directly affect anything outside of the piplay music. The volume adjust is controlling audio via Alsa command lines. I'm not familiar with adafruits usb audio, but knowing them, I wouldn't be surprised if there was a command line to adjust the audio. GPioneer supports nearly any type of command line command (including running an external script).
  • That's what I'm here for!
  • I tried out GPioneer but I am having trouble with it. The configuration is easy but something is causing my Pi to freeze. I am running 0.8 beta 9. It seems to be very repeatable on my setup. I had ESC mapped as a combo of my coin button and button 1(KP1 and ENTER). Whenever I use that combo to exit from an emulator menu(back to the main screen) my pi freezes.

    I just wanted to let you know. If you have any ideas I will set it up again and try it out.
  • hmm. Two things, if you wouldn't mind checking...
    first, check to make sure that retrogame is not getting enabled:
    nano ~/.profile
    sudo nano /etc/rc.local


    second,
    what happens if you assign ESC to just a single button? does it still freeze?
  • one last thing, can you tell me which pins are being activated with the combo? (You can check the GPioneer table in the web-frontend if you don't know off-hand)
  • It was on a fresh install before I put retrogame on there. The pins are 11 and 12. I will install it again later today and try to assign it to a single key and I will let you know. It will probably be in another 5 or 6 hours.
  • I got a chance to try switching ESC to a single button and I couldn't get it to freeze. I also set some other buttons up as combos(tab and p) and it caused the same problem.

    If there is anything else you want me to try let me know.
  • I am trying to add a capacitive touch sensor (based on AT42QT1010 - from sparkfun.com) to the GPIO to make a keyboard input, and am having no luck getting it right for retrogame to interface. Would it be possible with GPioneer? thanks for any input!
  • From what I see from your touch sensor, it puts the output line high when touched, which means that you need to set the gpio pin internal resistor to pulldown. In Retrogame, You can edit line 330ish to change to a pulldown gpio[GPPUD] = 2; I'm not 100% certain but I think that you need to set it to =1;

    Gpioneer has a flag that you can use to set the pins to pull down. After installation edit /etc/rc.local and change "python ../../Gpioneer.py &" to include "python ../../Gpioneer.py --pulldown &"

    In either case, you will want to make sure that you avoid pins 3 & 5. They have a physical pullup resistor that can't be pulled down.
  • That is exactly what the sensor does, which, of course is opposite from all other inputs. Would that flag set all pins to pulldown? I have one other GPIO wired button (simple open/closed) that retrogame ties to ESC. I just cant get retrogame to play with the active high sensor properly. Or, could I use the flag and put the ESC switch on pin 3 or 5 since the pullup is needed there?
  • technically, yes. You could use the gpioneer flag and then connect your standard button between one of the i2c pins (3 or 5) and a ground pin, just be careful not to mix them with the normal pins as you can cause a short. An alternative as well would be to wire your standard momentary button as follows 3.3v pin->10kohm resistor ->button->gpio pin.

    As mentioned above, you can also achieve the same results with retrogame by editing line 330ish. That is part of a loop that will set all of the pins to either high or low, you could also copy that chunk of code and paste it outside of the loop and then specify a specific pin to be either high or low.
  • I have tried editing retrogame. I put this code just in front of the munmap() call:

    bitmask = (1 << 13);<br /> gpio[GPPUD] = 1; // Enable pulldown
    for(shortWait=150;--shortWait;); // Min 150 cycle wait
    gpio[GPPUDCLK0] = bitmask; // Set pulldown mask
    for(shortWait=150;--shortWait;); // Wait again
    gpio[GPPUD] = 0; // Reset pulldown registers
    gpio[GPPUDCLK0] = 0;

    and,.................nothing. (I used GPIO 13 for the input).

    should the //enable pulldown value be "2"?

    Apologize for the bother. I thank you again for your comments and insight.
  • as far as I can tell, that should work, but it has been some time since I messed around with retrogame. As you stated, you are using GPIO 13, maybe just double check that you are indeed connected to pin 33?
  • YOU ARE MY HERO! I wired the other button through 3.3v with the resistor as you suggested, and used the pulldown flag. After using the slick web interface and a reboot, both buttons work perfectly, and no interference with RetroPie that I can tell.

    My tribe will sing your praises over the campfire for eternity, sir! Thanks again!
  • Cool. Glad you got it working man!
  • A couple of general questions. First, I have discovered that the keystroke mapping for one of the pins is a "P" . Turns out that the P key initiates a pause in games. Further, pause does not seem to be a 'mappable' action in MAME4ALL input configuration (neither general nor game specific). I can go into the GPioneer DB and change it to a different character. Are there any issues with doing that? Any other considerations? Similarly, I had wired up a couple of extra pins for future use. Of course, I could not configure them during the initial GPioneer setup. If/when I hook something up to these wires, I would prefer to add rows to the DB, as opposed to running through the entire configuration again. Can I map the pins to any unused character or are there specific ones (like "P"), I should avoid?
    Thanks
    • yeah, that's exactly what the db is for; so that you can remap keys that don't work for you. You should be able to remap to just about any other key. I haven't tested things like the 'F#' keys.

    • Those extra pins can be set up through the database later if you want. Just remember that they are based on the board pin numbers, not the bcm numbering. so 1,3,5,7,9... are on one side, 2,4,6,8,10 are on the other side.

    • You should be able to use pretty much any keys that you want. to avoid duplicate keys, I had to map certain ones in the configurator, but you by no means have to use those
  • Thanks. One day you'll have to explain the pattern/logic behind the bcm numbering.
  • it's just the number portion of the pins labeled gpio#. I guess that it's based on the Broadcom Soc Channels, but that's about the extent on my knowledge about that. :D
  • Great work with a good idea.You discussed the main problems encountered while interfacing the GPIO based controls.The flexibility of it sounds great in lieu of all the basic functions on others work.

    http://www.7pcb.com
  • @JohnDumais, Thanks! I've been casually using it for a while now and haven't really had any problems, so I hope that it's the same for everyone else!
  • hmm. I'm not sure. I've never needed to do something like that, but I imagine that there is something out there like that.
  • post edited out because I am stupid.
  • lol. Yes I am, and I'm trying to make amends for my stupidity (on that thread as well)

    For those interested:
    I have now used Adafruit's Retrogame, MK_arcade_joystick, and GPioneer.
    GPioneer is by far the best option, for many reasons.
  • hmm. that's weird. I just installed it on an unrelated raspberry pi no problem. Now, does it say: no module named evade? or no module named evdev?

    in any case, try this out:
    sudo apt-get remove python-six
    sudo pip uninstall six
    sudo pip install six


    if gpioneer still doesn't work, then type this:
    python -c 'import six; print(six); print(six.__version__); print(six.PY2)'

    and post what it outputs. also, post any other errors that you get.
  • ah, that's why. The installer should have installed pip for you, but something must have gone wrong.

    try manually installing

    sudo apt-get update
    sudo apt-get -y install python python-dev python-requests python-pip
    sudo apt-get -y install supervisor gunicorn sqlite3
    sudo pip install flask pyyaml flask-sqlalchemy flask-admin evdev

    if that all runs fine, then run the gpioneer installer.
    bash gpioneer/install.sh
  • Hello!
    I just Wanted to say THANK YOU !!
    Great work so easy to get my arcade controls working 100% .
    I used Emulatorstation with retropie before and used a guide but 2 ways on 1 controller stick didnt work :(.
    And must say i think piplay looked better with theme.
  • should just be:
    sudo apt-get install python-dev python-requests python-pip
    sudo pip install evdev
  • what version of raspbian are you running? It seems that you have an x86 version of gcc installed.

    you can try
    sudo apt-get --purge remove gcc
    sudo apt-get install gcc
  • oh nice! I'm glad you got that working.

    yeah, that warning will always come up. It's a warning from the Rpi.GPIO module, it doesn't affect the running of it. You can use pins 3 and 5 though (I do), just make sure that the i2c interface is turned off in raspi-config->8. advanced->A7. I2C

    if restarting doesn't get the web interface running again, try typing:
    sudo supervisorctl
    (press ctrl+D to exit)
    it should list all of it's running processes
  • ok, first run
    sudo pip install flask pyyaml flask-sqlalchemy flask-admin

    then try restarting. If it still exits after a few seconds, try running the web frontend directly:
    sudo python /home/pi/gpioneer/web-frontend/app.py &

    you can also look at the error and output logs here:
    stderr_logfile=/var/log/long.err.log
    stdout_logfile=/var/log/long.out.log
  • YAY! I'm glad that you got it working! Thanks for the heads up on the problems that you ran into. It will definitely make it easier to troubleshoot in the future.
  • hmm... I really have no idea why that would happen. I did notice that evdev (the core library that gpioneer uses) just recently got an update, I wonder if that has anything to do with it. I'll try to test it out when I get a chance, but I'm in the middle of a really big backyard project right now, so I'm not sure when that will be.
  • well, it uses supervisord to handle the web app. you can stop it with the command sudo supervisorctl stop all

    I was just checking out the documentation for supervisord, it looks like the config file could use an extra line.

    The config file is located at /etc/supervisor/conf.d/gpioneer-web.conf

    [program:gpioneer-web]
    directory=/home/pi/gpioneer/web-frontend/
    command=sudo python app.py
    autostart=true
    exitcodes=0,2
    autorestart=unexpected
    stderr_logfile=/var/log/long.err.log
    stdout_logfile=/var/log/long.out.log

    (the exitcodes line is missing) If that doesn't work, you can also set autostart=false in order to keep it from starting on startup.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!