Sts pi robot built but cannot make it work

Hello, my son has built the robot, loaded code for the explorer hat, as well as the code that Sandy Macdonald posted on GitHub (he has flash). Neither of us has any idea what to do next - how to go from having the code there to instructing the robot to move. Are there any online instructions that would help a complete novice (me) and a child to get the thing going. We are about to buy a wifi dongle and a battery pack but we could make it move initially while it’s wired up to the monitor and power supply I think. None of the online resources I’ve found actually tell us what to do next. Please, please help.

I feel your pain! this site gives great start to finish instructions ,I have used it myself so I cant offer anything expect the link ,good luck [Sts pi robot ,

You have to build your code based on what you want it to do. And what you want to use to control it.
I built a couple of rovers based on the Explorer phat. I used a USB wireless keyboard for control. This is the code I used.

#!/usr/bin/env python
import os
import usb.core
import usb.util
import explorerhat
import time
import RPi.GPIO as GPIO

GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

x=(2) #shutdown variable
S=(100) #speed default value.
M=(0) # 0 = Not moving, 1 = Moving Forward, 2 = Moving Backward,

USB_VENDOR  = 0x1997 # Rii
USB_PRODUCT = 0x2433 # Mini Wireless Keyboard

USB_IF      = 0 # Interface
USB_TIMEOUT = 5 # Timeout in MS

BTN_LEFT  = 80 # <
BTN_RIGHT = 79 # >
BTN_DOWN  = 81 # V
BTN_UP    = 82 # ^
BTN_STOP  = 44 # Space
BTN_EXIT  = 41 # ESC
BTN_OK    = 40 # OK
BTN_ONE   = 30 # 1
BTN_TWO   = 31 # 2
BTN_THREE = 32 # 3
BTN_FOUR  = 33 # 4
BTN_FIVE  = 34 # 5
BTN_SIX   = 35 # 6
BTN_SEVEN = 36 # 7
BTN_EIGHT = 37 # 8
BTN_NINE  = 38 # 9
BTN_ZERO  = 39 # 0

dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
endpoint = dev[0][(0,0)][0]

if dev.is_kernel_driver_active(USB_IF) is True:

usb.util.claim_interface(dev, USB_IF)

def Shutdown(channel):  
    global x
    x = (0)

GPIO.add_event_detect(5, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)

while True:
    control = None
        control =, endpoint.wMaxPacketSize, USB_TIMEOUT)

    if control != None:
        if BTN_ONE in control:
          S = (10)

        if BTN_TWO in control:
          S = (20)

        if BTN_THREE in control:
          S = (30)

        if BTN_FOUR in control:
          S = (40)

        if BTN_FIVE in control:
          S = (50)
        if BTN_SIX in control:
          S = (60)

        if BTN_SEVEN in control:
          S = (70)

        if BTN_EIGHT in control:
          S = (10)

        if BTN_NINE in control:
          S = (90) 

        if BTN_ZERO in control:
          S = (100)

        if BTN_DOWN in control and M != 1: # Go into reverse if not moving forward, and stop turning if turning.
          M = 2
        if BTN_UP in control and M != 2: # Go into forward if not moving in reverse, and stop turning if turning.
          M = 1
        if BTN_LEFT in control and M == 0: # Turn left while stoped

        if BTN_RIGHT in control and M == 0: # Turn right while stoped

        if BTN_LEFT in control and M == 1: # Turn left while moving forwards

        if BTN_RIGHT in control and M == 1: # Turn right while moving forwards

        if BTN_LEFT in control and M == 2: # Turn left while moving backwards

        if BTN_RIGHT in control and M == 2: # Turn right while moving backwards

        if BTN_OK in control: # Stop moving and stop turning 
          M = 0
        if BTN_EXIT in control:          
          raise SystemExit

        if BTN_STOP in control:
          os.system("sudo shutdown now -P")


    if x == 0:
        os.system("sudo shutdown now -P")
    elif x == 1:
        raise SystemExit

To get keyboard software I used

sudo apt-get install libusb-dev
git clone
cd pyusb
sudo python3 install

To have it run automatically on boot I did the following.

run crontab -e
@reboot sudo python3 /home/pi/ &

Thank you so much! Taking a look now

Thank you. That’s really helpful

Hi there. I created a basic guide for a school challenge project. Not sure if it is what you are looking for but hope it helps.

Thank you - this is hugely helpful!

It may be a bit of work, and some trial and error with the code. Very rewarding when you get it working though.