Jump start – get your Pi-Car going as quickly as you can with Python

If you have been waiting for your Pi-Car and just want to try and make it do something as quick as possible start here.

This Jump start assumes that you have a Raspberry Pi up and running and you are able to able to access the screen with the big Raspberry Pi showing on it:

Raspberry Pi starting screen

Screenshot of how the Raspberry Pi should look once you have logged in

If you have not yet got this far don’t worry there is loads of help – you can start with our guide to getting up and running by clicking here.

If you do not really understand what a Pi-Car is then click here.

Connect your Pi-Car up


Connect cable to radio controller – make sure that it is pushed in securely.

Connect cable to Raspberry Pi – make sure it is the right way round. On one side of the long black connector is a raised square this should be on the side facing the rest of the Raspberry Pi.

Start your Raspberry Pi and get to the screen with the big raspberry on it (remember at the login prompt that appears when you turn it on type pi and then press enter and type raspberry as the password and press enter. After this type startx) For a full guide click here.

Get something happening

This part does involve writing some lines of Python code – if you don’t fancy this it maybe best to start with the Scratch tutorial.

If you can’t view the video the instructions are below.

Click on the LX terminal and type:

sudo python

This should bring up a prompt that looks like the following

Python terminal

This is how the terminal should appear after typing sudo python

You next need to tell Python that it will be using the GPIO pins so it can get ready to do it. Type and press enter:

import RPi.GPIO as GPIO

Remember capitalisation is important – if it is lower case above type it in as lower case, ditto with upper case.

Next you need to tell python to get the GPIO board ready you do this by typing (and pressing enter after)

GPIO.setmode(GPIO.BOARD)

The final bit of preparation is that you have to tell the GPIO pin that it is an output pin rather than an input one. Type the following in

GPIO.setup(11, GPIO.OUT)

The GPIO pins can be used to output, or send, signals down a cable to something else – like the Pi-Car controller or they can receive a signal from something. Here we are using them as outputs and the line of code above says that.

So we are now ready to actually send something to the Pi-Car. To turn the GPIO pin on and off you set it to 1 to turn it on and 0 to turn it off. Type in the following to turn pin 11 on.

GPIO.output(11, 1)

When you do this your Pi-Car should lurch backwards! To stop it lurching backwards type the following:

GPIO.output(11, 0)

You may have noticed that you can use the up and down arrows in the Python terminal to go to the last entry you typed in and then edit it. You can also always turn your Pi-Car off or disconnect the connector if you get in a muddle!

You can now test the remaining GPIO pins. Remember to set them up first:

GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)

You can then try each one individually by outputting to them as you did earlier:

GPIO.output(12, 1)
  • GPIO pin 11 – backwards
  • GPIO pin 12 – forwards
  • GPIO pin 13 – left
  • GPIO pin 15 – right

When you are finished playing around run the following command to clean up the GPIO pins.

GPIO.cleanup()

This ensures they are left in a good state. If you do get stuck you can always just disconnect your Pi-Car or turn your Raspberry Pi off and on again – call it a ‘Power Cycle’ and you are pretty much a real Engineer already.

Well done if you have got this far. If not don’t panic, check the following things:

  • Is the Pi-Car cable connected securely
  • Can you control the car from the controller – you should be able to even when it is connected to the Raspberry Pi
  • Is the Pi-Car turned on?
  • Did you get any errors when you typed in the Python code

If you are still stuck just leave a comment or email us at info@pi-cars.com.

PDF Version

PDF version of this article – Jump start – get your Pi-Car going as quickly as you can with Python _ Pi-Cars

About Barnaby Kent

http://www.myactionreplay.com
This entry was posted in Blog, Under the bonnet and tagged , , . Bookmark the permalink.

7 Responses to Jump start – get your Pi-Car going as quickly as you can with Python

  1. Andrew says:

    I have just received my pi car and noticed that there were 5 wires not just the 4 that you mention for the input outputs. What is the other wire 4 and where does it connect? Thanks

    • Barnaby Kent says:

      Hi Andrew

      The other wire is for the 0 volts.
      The 0 volts on the pi and 0 V on the controller are now connected through the cable. Pin 6 on the PI GPIO is 0v the other end goes to the Negative terminal on the battery in the controller think the colour of the cable is orange

      gpio pin no cable colour
      6 ——– orange
      11 ——– brown
      12 ——– green
      13 ——– black
      15 ——– yellow

      hope this helps

  2. Pingback: Pi-Cars and Scratch – Driving Lesson #1 | Pi-Cars

  3. Pingback: Jump start – get your Pi-Car going with the Pi Store | Pi-Cars

  4. Pingback: Pi-Cars and Python – Driving Lesson #1 | Pi-Cars

  5. Pingback: Pi-Cars Factory – Beginners Tool Kit | Pi-Cars

  6. Pingback: Introduction to Python, constants and print statements – Driving Lesson #2 | Pi-Cars

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s