Please do not post a support request without first reading and following the advice in

Setting ServoStik using python and GPIO pins

  • The details:
    Raspberry Pi 3B+
    RetroPie 4.5.1
    Ultimarc ServoStik

    I was following a tutorial from this page:

    I was trying to do the same thing where I would control a ServoStik from a python script using the hook.

    I had to change the script a little bit, but I'm confident that the code is at least running the functions.

    I've tried running my python script with "sudo", and my print statements tell me it should be setting the pins properly, but it still doesn't control my Servostik.

    I've tested my cable by splicing the cut end of the USB cable back together and using the Windows utility. That would rule out the motor, control board and cable.

    I tried hooking the positive and negative power to the 5v and ground GPIO pins. I've also tried connecting the positive and negative power to the cut end of the USB cable and plugging it into a USB port.

    I'm at a loss for what I can try next.

    Here is the python code:

    #!/usr/bin/env python3
    A script for setting the ServoStik to 4-way mode or 8-way mode.
    usage = """
    Usage: set-joystick [4|8|0]
    Takes a single argument which should be either "4" (four-way), "8" (eight-way),
    or "0" (which means "I have no clue what to do and am willing to leave it up to
    this script to decide.")
    import sys
    #from RPi import GPIO
    import RPi.GPIO as GPIO
    MODE_8 = 6  # white 
    MODE_4 = 5  # green 
    GPIO.setup(MODE_4, GPIO.OUT)
    GPIO.setup(MODE_8, GPIO.OUT)
    def set_joystick_mode(mode):
      target_pin = MODE_8
      other_pin = MODE_4
      if mode == 4:
        target_pin = MODE_4
        other_pin = MODE_8
      print("set high",target_pin)
      GPIO.output(other_pin, GPIO.LOW)
      GPIO.output(target_pin, GPIO.HIGH)
    mode = sys.argv[1]
    if mode not in ("0", "4", "8", ""):
      print("Invalid argument!", file=sys.stderr)
    if mode == "0" or mode == "":
      #Zero equals a shrug. Put the joystick in 8-way mode.
    elif mode == "4":
    elif mode == "8":

    (Looking at the preview, I'm not sure if the spaces in the python code are going to come through properly)

  • Global Moderator

    Use code blocks (```) to surround your code, so it's properly indendet and highlighted. I've edited the post and added them.

  • Global Moderator

    According to the RPI GPIO board numbering, Pins 5 and 6 do not correspond to what's in the diagram referenced in the article (which shows pins 8 and 10 connected). Pin 6 is ground, so I don't think it needs to be pulled high/low.

    How did you wire the Servo to the GPIO pins ?

  • I did notice that too. Using the card that came with my raspberry pi, I connected the white and green wires to the GPIO pins 6 and 5, which are pin numbers 31 and 29, respectively.

    I sent an email to Ultimarc and they said that the ServoStik could not be controlled through GPIO pins, but only through control transfers via a USB protocol. This sounds a lot more complex. I'm really hoping that there is another solution.

  • Global Moderator

    @corminos said in Setting ServoStik using python and GPIO pins:

    I'm really hoping that there is another solution.

    What's the difference between GPIO and and USB connection ? It seems easier to me to conenct via USB. If this is the supported method, why aren't you using it ?

  • I see my problem now. When I first read the instructions on the link, I did not understand what he meant by "switching to hardware mode". At the time I did not have the joysticks and did not understand what that meant. Now I do.

    I'm going to do some more reading and then give it a try. Just a little nervous because this is a one-way ticket and I really don't feel like shelling out more for another control board if I screw it up.

    Thanks to those who read and responded. I love how active this forum is.

Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.