Raspberry Pi – First ‘driven’ program

Making IT Fun!

1. Installing Sphero software + setting it up

  • Within Raspbian (Raspberry Pi), open the terminal and type the following command
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
  • Next, we’ll download the files we need by typing in the following
    git clone https://github.com/sphero-inc/sphero-sdk-raspberrypi-python.git
  • After the download is complete type the following
    mv sphero-sdk-raspberrypi-python sphero
  • Next, we are going to run the first time setup, so finish with typing the following one line at a time
    cd sphero
    ./first-time-setup.sh
  • Restart and reopen the terminal window, and enter the follow one line at a time
    cd sphero
    pipenv shell
    exit
    pipenv --rm
    pipenv --python /usr/bin/python3.7
    pipenv install --skip-lock

The first line is because Linux will default to an old version of Python, this will make it so it’s using the latest version of python for everything; and our software will crash with the old version of Python.

The second line of code is reaching out into the internet to what is called a ‘git repository,’ basically it’s just saying to clone the files from that area of the internet onto your Raspberry Pi

The third line of code is using the mv (move) command, we’re renaming the sphero-sdk-raspberrypi-python folder to simply be called sphero just for the sake of not having to type that long folder name all the time.

The fourth sets of code is just running the configuration file. The ./ command is how we run a program in the terminal, and the program itself is just unpacking and configuring things for the raspberry pi to be able to execute our files correctly that we’ll write and use in the future.

The fifth and final is installing what we call dependencies and getting them situated properly. Dependencies are pieces of software that our code is going to be dependent on in order to run. An example of this would be the wheels of a car are dependencies of the rest of the car to function; it’ll get pretty hard to try and drive a car with no wheels, it’ll get pretty hard to run your program without these dependencies.

2. Getting ready to rumble

We’re ready to drive the RVR with the Pi. First thing to do it to make sure you have a charged battery in the RVR, and PROP IT UP SO THE WHEELS AREN’T TOUCHING ANYTHING, WIRES INCLUDED! Do this how you can, I used a whiteboard eraser in the picture here, but just as long as the RVR is stable and the wheels aren’t touching anything, because this thing can get a little wild.

Ctrl – c

Before we go any further, let’s talk about how we STOP a running program

Ctrl – c

You may notice that keyboard shortcuts to copy/paste do not work in the terminal; this is because they are used to terminate running programs! If you need to stop the RVR, hold the Ctrl key and press C in the terminal that is running the program.

3. We rumble!

Power up the RVR, if it’s been on then cycle the power (It cannot receive commands when it’s in sleep mode). Within the ~/sphero folder in your terminal, type the following code one line at a time:
pipenv shell
cd projects/keyboard_control/
python drive_with_wasd_keys.py

Now while you’re in the terminal, you should have got the message above and at that point, you are in control of the RVR remotely and you can move it with the wasd keys. Notice it is DIFFICULT to get the wheels to stop spinning, this is a very crude program and the reason why we have the RVR propped up so nothing is touching the wheels, it’s very hard to control with this program!

Hold Ctrl and press c afterwards press any key on the keyboard and the Pi will terminate the running program, making the RVR stop in its tracks.

4. We’re done here! Head to the FAQ with any issues, or return back to the main menu.

YouTube Walk-through: https://youtu.be/Hd-TlzoGGTY

Next Section: Raspberry Pi – FAQ
Return to main: Raspberry Pi – Introduction and how to’s