Sunfounder Pi Car-S

Overview

For Fullscreen: https://www.youtube.com/watch?v=fClKay0WES8

We wanted to show the versatility of the Quantum system by showing that it is capable of replacing the raspberry pi in their own projects and is much simpler to program and wirelessly control. The Sunfounder Pi Car-S is a smart sensor car kit created for Raspberry Pi. This project will use the Quantum platform to replace the Raspberry Pi and allow you to wirelessly control the car with a joystick controller.

Intermediate

1-2 Hours

2 Clients


Hardware Components

Picture

Name

Quantity

Link

Picture

Name

Quantity

Link

 

Sunfounder Pi Car-S

1

Can be purchased here

Quantum Joystick DIY Kit

 

1

Can be purchased here

Joystick

(OPTIONAL if you don’t want to use the DIY Kit)

1

Included in the Component Kit

Or, they can be purchased here

MM Jumper Wires

2

Included in the Component Kit

Or, they can be purchased here

MF Jumper Wires

8

Included in the Component Kit

Or, they can be purchased here

Solderable bread board

1

Can be purchased here

Male pin headers

8 pins

Can be purchased here

Q-Client Builder Base

2

Q-Client

Tools Used

Picture

Name

Quantity

Link

Picture

Name

Quantity

Link

 

Small slotted-head screwdriver

1

Included in the Component Kit

or you can pick from one on our Recommended Tools List


Assemble the Circuit

Start by following the instructions included with the Pi Car-S up until you need to start adding the wires, but DO NOT include the Raspberry Pi Board.

*If you do not have a manual, don’t worry. You can find a pdf copy of the manual in the resources section of this documentation below.

For the circuit building, you will want to use the diagrams in the included instruction manual (pages 24 & 25 of the PDF attached below). We will be partially following these instructions.

Use the supplied cables to do the following.

  • Connect the left motor to J2 on the TB6612 motor driver

  • Connect the right motor to J3 on the TB6612 motor driver

  • Connect the Motor Driver board (J4) to the PWM ports 4 & 5 on the PCA9685 Driver board.

    • The black wire connects to pin 4

    • The red wire connects to pin 5

    • Please note that the PWM ports are the yellow pins, not the red and black ones.

  • Connect J18 on the PCA9685 to J10 on the Robot HATS board

  • Connect the servo to PWN 0 on the PCA9685

    • Make sure the darker wire on the servo is connected to the black pin on PWM 0 and the lighter pin is connected to the yellow pin on PWM 0. Don’t reverse these.

Now this is where we stray from their instructions. You will need to create terminal blocks to connect all the PWR and GND connections so we can attach them to the Quantum Builder Base later on. There are many ways to do this, but for simplicity and cleanliness we just cut part of a solderable bread board and soldered pin headers to create a GND and PWR rail that will make easy connections with the jumper wires. We then attached that to a piece of acrylic where we also mounted the Builder Base. See how we did it in the photo below.

Now connect a 5 wire connector to J1 on the Motor Driver board and attach male-female jumper wires to the following:

  • Connect a wire from the black wire on the connector to the GND terminal block you just created

  • Connect a wire from the red wire on the connector to the PWR terminal block you just created

  • SKIP the red wire in the middle

  • Connect a wire from the yellow wire on the connector to PWM pin 7 on the PCA 9685

    • Remember, this is the yellow pin on the PCA board

  • Connect a wire from the white wire on the connector to PWM pin 6 on the PCA 9685

Next, connect a 4 wire connector to J16 on the PCA9685 PWM board and do the following:

  • Connect the white wire on the connector to the SCL port on the Quantum Builder Base

  • Connect the yellow wire on the connector to the SDA part on the Builder Base

  • Connect the red wire on the connector to the PWR terminal block you made

  • Connect the black wire on the connector to the GND terminal block you made

Now plug a 5 wire connector to J11 on the Robot HATS board and do the following:

  • Connect the black wire on the connector to the GND terminal block that you made

  • Connect the red wire next to it on the connector to the PWR terminal block that you made

Lastly, connect the terminal blocks to their respective ports on the Builder Base:

  • GND to any GND port on the Builder Base

  • PWR to the 5v port on the Builder Base

Now let's turn it on to make sure we did everything correctly.

Flip the switch on the Robot HATS board and you should see the following lights turn on:

  • You should see both green LEDs turn on right behind the switch on the Robot HATS

  • You should see the status LED on the Builder Base turn on

  • You should see both green LEDs on the PCA9685 PWM driver board turn on

If you don’t see all the light, check your connections. Sometimes jumper wires can’t be connected properly.

If you see all 5 lights turn on, your circuit is now complete!

*PLEASE NOTE: we will be controlling this car with the joystick so make sure you have connected a joystick and uploaded the firmware to a Builder Base. Linked are the documentation on how to set up the Joystick DIY Kit or a simple joystick.


Pair the Builder Base

Now that your circuit is complete, it’s time to pair your Joystick and Pi Car Builder Bases to your Q-Server. If you’ve already done that you can skip this step.

First, make sure your Builder Bases are powered on and log into your Q-Server.

Navigate to the Clients tab and select the “unpaired” tab. You will find a list of numbered devices.

Click the 3 dots next to each device and select the “pair” option.

Once you have pair both of the clients needed for this project you can go back to the “paired” tab.

Pick a device, click the 3 dots next to it and then select “Identify”. You will see the status LED on the Builder Base start flashing red and green. This is to help you identify the builder base.

Depending on which device blinked, click the 3 dots next to it again and select “edit”. Now you can give it a name and location.

For this project we named our Builder Bases “Joystick” and “Pi Car”.

Now that your Builder Bases are set up and paired, let’s create the firmware.


Build the Firmware

In this section we will build the firmware used in this project.

This project uses I2C devices so before we start building the actual firmware file we will need to know the I2C address of the PiCar’s Builder Base.

To find the I2C address, stay on the “Clients” page and click the actions button next to the PiCar Builder Base you just paired.

Select the “Debug” option.

Now click the “Scan” button next to where it says “I2C Scan”.

Once you click the “Scan” button, a banner will appear with the I2C address for that Builder base.

Now that you have the I2C address, navigate to the Firmware tab on the tool bar and select “+ Create New”.

You will now be prompted to name your firmware file, we named ours “PiCar”.

Now, select the “+ Add Hardware” button and add the motor hardware to the firmware file.

 

We will name this hardware “Right Wheel” and then click “Add Hardware”.

Next, click “+ Add Hardware” again and add another motor. We will call this one “Left Wheel”.

Next, click “+ Add Hardware” and add a Servo hardware to you client. We will call this one “Steering” and then click “Add Hardware”.

Now that you have added all the devices that are connect to the Pi Car Builder Base, we will configure each one.

First, we will configure the Servo hardware we named “Steering” as follows:

  • For the driver, select “PCA9685”

  • For the I2C address, input the address you scanned for previously. (For us it’s 40)

  • For channel, input “0”

Next, we will do the “Right Wheel” motor as follows:

  • For the driver, select “PCA9685 Speed Dir”

  • For the I2C address insert the same one you used for the Servo

  • For the Speed Channel, input “4”

  • For the Direction Channel, input “6”

Lastly, we will configure the “Left Wheel” as follows:

  • For the driver, select PCA9685 Speed Dir

  • For the I2C address, input the I2C address you scanned for

  • For the Speed Channel, input “5”

  • For the Direction Channel, input “7”

Once that’s done, click the “Save” button and then your PiCar firmware file is complete!

Now we will upload it to the Builder Base on the PiCar.

To do this, select the 3 dots next to the PiCar firmware and click “Upload”.

And then select the PiCar Builder Base and click “Upload”.

Now that both the PiCar and Joystick have their firmware files, let’s build the app.


Build the App

Navigate from the Firmware Builder to the App Builder via the toolbar on the left side of the screen.

Once there, click “+ Create New”.

Name your app and hit create. We named ours “PiCar”.

You will be redirected to the canvas where you will build your App.

The first object will be bring out is the Joystick Hardware Object, which you can search for or find it under the hardware drop down.

Notice how the top of the joystick object says “untitled”. We will now want to give that object a name so our mapping process is way easier later on.

We will just name it “Joystick” and then click “Save Properties”.

Next, drag out a Servo hardware object and name it “Servo”.

Now drag out two Motor hardware objects. Name one “Right Motor” and the other “Left Motor”.

Now that we have our hardware objects on the canvas we will have to do some configurations.

Joysticks give out values of 0 to 4095 for each axis, but the problem is that Servos only go from 0 to 180 degrees and for the PiCar we don’t want 180 degree range of steering otherwise it’ll break something. We will want the Servo to range from 60 to 120 degrees. This is where the Manual ranging code object comes in handy. We will use this object to turn the joystick values and range it within the 60 to 120 degree spectrum of the Servo.

So now, drag out a Manual Ranging code object. You’ll notice that it will be a pinkish color.

Now we will have to configure specific ports on the Manual Ranging Object. All you need to do is click the box next to each text on the object to configure its specific properties.

First, click on the “In Max” port on the Manual Ranging Object and you will see on the right side of the canvas a place to insert the “Default Value”.

Type in “4095” for this value and then click “Save Properties”.

Next click the “Out Min” port and insert “60” as the value and click “Save Properties”.

Lastly, click the “Out Max” port and insert “120” as the value and click “Save Properties”.

Once, that’s configured we can connect all the objects together.

Start by connecting the “X-axis” port from the Joystick object to the “Value” port on the Manual Ranging Object like so.

Next, connect the “Value” out port on the Manual Ranging Object to the “Degrees” port on the Servo object.

Now we will connect the “Y-axis” port on the Joystick object to the “Joystick Axle” objects on both motors.

*OPTION: If you are using the DIY controller and want to use both joysticks you can just add a second Joystick object and one object will have it’s x-axis link to the Servo and the other one will have it’s y-axis link to the two motors. Just make sure to label them correctly for the mapping process.

Thats it!

Your App is now complete. You can save it by clicking the “Save App” button in the upper right hand corner of the screen.

 

After saving, click “Return To My Apps”.


Map the Hardware

You should now be back on the Apps page.

Find your “PiCar” app and hit the play button.

A list containing all of the devices in your application will expand.

Now we will have to map the Hardware objects to the correct Builder Base with the correct firmware file uploaded to it.

We will start with the Left Motor and select the option that says “PiCar - Left Wheel”. You will see a green check mark once that is mapped.

Next we’ll do click the Joystick and select the “Joystick - Right”. This is how we named our joystick client and firmware file, but yours might be different.

Next, click the Right Motor and select “PiCar - Right Wheel”.

Lastly, click the Servo and select “PiCar - Steering”.

Once you see all the hardware have green check marks next to them your application is mapped!


Run the App!

Congrats on building this project! Now it’s time to use it!

Hit “Save + Run” and enjoy driving your PiCar using the Quantum System!


 Resources

Application

 

Firmware

 

Schematic

Diagram

Sunfounder Pi Car-S Instruction Manual