SunFounder PiCar-S Manual
Hide thumbs Also See for PiCar-S:

Advertisement

Quick Links

About SunFounder
SunFounder is a technology company focused on Raspberry Pi and Arduino open
source community development. Committed to the promotion of open source culture,
we strive to bring the fun of electronics making to people all around the world and
enable everyone to be a maker. Our products include learning kits, development
boards, robots, sensor modules and development tools. In addition to high quality
products, SunFounder also offers video tutorials to help your own project. If you have
interest in open source or making something cool, welcome to join us! Visit
www.sunfounder.com for more!
About the PiCar-S
PiCar-S
The
is a cool smart car that can work with Raspberry Pi 3 model B, 3 model B+,
and 4 model B. Equipped with three sensor modules including ultrasonic obstacle
avoidance, light follower, and line follower, you can better learn the programming on
how to control the car.
In this manual, we will show you how to build the PiCar-S via description, illustrations
of physical components, in both hardware and software respects. You will enjoy
learning how all this work. You may visit our website
download the related code and view the user manual on
watch related videos under VIDEO, or clone the code on our page of github.com at
https://github.com/sunfounder/SunFounder_PiCar-S
You are welcome to pull requests and issue posts on our page on Github.
Free Support
If you have any TECHNICAL questions, add a topic under
website and we'll reply as soon as possible.
For NON-TECH questions like order and shipment issues, please
to
service@sunfounder.com. You're also welcomed to share your projects on
FORUM.
Preface
www.sunfounder.com
LEARN -> Get Tutorials
FORUM
section on our
send an email
to
and

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the PiCar-S and is the answer not in the manual?

Questions and answers

Summary of Contents for SunFounder PiCar-S

  • Page 1 In this manual, we will show you how to build the PiCar-S via description, illustrations of physical components, in both hardware and software respects. You will enjoy learning how all this work.
  • Page 2: Table Of Contents

    Contents Components List .......................... 1 Structure Plates ........................1 SunFounder SF006C Servo x 1 .................... 2 Mechanical Fasteners ......................3 Wires ............................4 PCB .............................. 4 Other Components ......................... 5 Tools ............................6 Introduction ........................... 7 Building the Car ..........................8 Front Half Chassis ........................
  • Page 3 Connect the Motor ....................... 20 Get Started with Raspberry Pi ....................22 If You Have A Screen ......................23 - Required Components ....................23 - Procedures ........................23 If You Have No Screen ......................30 - Burn System ......................... 30 -...
  • Page 4 Robot HATS ..........................71 PCA9865 ..........................72 Motor Driver Module ......................73 Line Follower Module ......................74 Light Follower Module ......................75 Ultrasonic Obstacle Avoidance Module ................. 76 SunFounder SF006C Servo ....................77 DC Gear Motor ........................78 Copyright Notice ........................78...
  • Page 5: Components List

    Components List Structure Plates 1. Upper Plate x 1 2. Front Half Chassis x 1 3. Hex Front Wheel Fixing Plate x 6 4. Ultrasonic Support x 1 5. Bearing Shield x 6 6. Steering Linkage x 1 7. Steering Connector x 2 8.
  • Page 6: Sunfounder Sf006C Servo X 1

    SunFounder SF006C Servo x 1 1. Servo x 1 2. 1-arm Rocker Arm x 1 3. arm Rocker Arm x 1 4. 4-arm Rocker Arm x 1 5. Rocker Arm Fixing Screw x 1 6. Rocker Arm Screw...
  • Page 7: Mechanical Fasteners

    Mechanical Fasteners Name Component Qty. M2x8 Screw M2.5x6 Screw M2.5x12 Screw M3x8 Screw M3x8 Countersunk Screw M3x10 Screw M3x25 Screw M4x25 Screw M2 Nut M2.5 Nut M3 Nut M4 Self-locking Nut M2.5x8 Copper Standoff M3x25 Copper Standoff 4x11x4 F694ZZ Flange Bearing...
  • Page 8: Wires

    Wires 100mm 5-Pin Jumper Wire 50mm 4-Pin Jumper Wire 50mm 2-Pin Jumper Wire 100mm 2-Pin Jumper Wire 200mm 5-Pin Jumper Wire 200mm 4-Pin Jumper Wire 200mm 3-Pin Jumper Wire Robot HATS...
  • Page 9: Other Components

    PCA9685 PWM Driver Motor Driver Module 5-CH Line Follower Module Ultrasonic Obstacle Avoidance Module Light Follower Module Other Components 2x18650 Battery Holder...
  • Page 10: Tools

    DC Gear Motor Rear Wheel Front Wheel Ribbon (30cm) Tools Cross Screwdriver Cross Socket Wrench M2.5/M4 Small Wrench M2/M3 Small Wrench...
  • Page 11: Introduction

    Introduction SMART SENSOR is a car robot based on Raspberry Pi, which comes with three sensor modules, including the light follower, line follower and ultrasonic obstacle avoidance. With these modules, this smart car is capable of some simple automatic actions. Thus, you can learn some basics of programming in Python to control the car with these sensors.
  • Page 12: Building The Car

    Building the Car Extremely excited when opening the box and checking so many components? Keep your patience and take it easy. Please note that some details in the following steps CAREFUL need observation. You should double-check your work based on the figures in the manual after finishing each step.
  • Page 13 You can use the Cross Socket Wrench to secure the M4 Self-locking Nut, then use the screwdriver to tighten the M4x25 screw. Note: The Self-locking Nut should be screwed tight enough. It would be better to tighten the screw until the wheel and Steering Connector cannot move first, then loosen the screw a little, so that the Steering Plate can just move.
  • Page 14: Steering Part

    Steering Part Connect the Steering Linkage and the rocker arm with the Rocker Arm Screw (a longer one in the servo package). Note: Insert it into the first hole of the arm (as indicated by the arrow below) which is the farthest from the gears.
  • Page 15: Upper Plate

    Upper Plate Mount the M2.5x8 copper standoffs and M2.5 nuts into the upper plate first. Pay attention that the side the protruding prop should face up.
  • Page 16: Battery Holder

    Battery Holder Turn the Upper Plate upside down. Cut the ribbon into two halves. Thread them through the holes on the plate. Pay attention to the direction and leave one end longer out of the plate for each to remove the battery easily later. Fasten the battery holder with two M3x8 countersunk screws and two M3 nuts: pay attention to the direction of battery holder’s wire.
  • Page 17: Rear Wheels (Screws)

    Rear Wheels (Screws) Insert four M3x8 screws with four M3x25 copper standoffs:...
  • Page 18: Pcb Assembly

    PCB Assembly 1) Assemble the Raspberry Pi (TF Card inserted) with eight M2.5x8 copper standoffs, then plug the Robot HATS onto it. 2) Fix the Robot HATS with four M2.5x6 screws. 3) Fix The PCA9685 PWM Driver, the Motor Driver with eight M2.5x12 screws and M2.5 nuts into the down plate.
  • Page 19: Rear Wheels (Driving)

    Rear Wheels (Driving) Assemble the two motors to the Back Half Chassis with four M3x25 screws and M3 nuts. Pay attention to place the motors with wires inward, providing convenience for connecting the circuit. Place wires inwards Assemble the rear wheels with 4 M3 nuts.
  • Page 20 Align the rear wheels with the motor shaft, and rotate to insert them gently.
  • Page 21: Circuits Building

    Circuits Building Connect the Power...
  • Page 22: Connect The Modules

    Connect the Modules...
  • Page 23: Connect The Servo

    Connect the Servo...
  • Page 24: Connect The Motor

    Connect the Motor...
  • Page 25 The complete connection is shown as follows. So now the circuit boards are all installed onto the car and the wiring is done. But still you're not ready to adjust the servo yet. First you need to complete some software installation.
  • Page 26: Get Started With Raspberry Pi

    Get Started with Raspberry Pi So the back part of the car is completed. Next we'll move on to the front part. But before assembly, since servos are used in this part, they need some configuration for protection. We need to make the servo keep in 90 degrees when it's mounted. In this chapter, we firstly learn to start up Raspberry Pi.
  • Page 27: If You Have A Screen

    Without a screen, you can refer to Page 31 to configure Wi-Fi and start SSH after flashing. If You Have A Screen If you have a screen, you can use the NOOBS (New Out Of Box System) to install the Raspbian system.
  • Page 28 NOOBS LITE can only be operated online. Here, you are suggested to use the former. Here is the download address of NOOBS: https://www.raspberrypi.org/downloads/noobs/ Step 2 Plug in the Micro SD reader and format the Micro SD card with the SD Formatter (https://www.sdcard.org/downloads/formatter/index.html).
  • Page 29 Step 5 Insert the Micro SD card into the Raspberry Pi. In addition, connect the screen, keyboard and mouse to it. Finally you are also recommended to use the power adapter of Raspberry Pi to power your car for that the first test will take a long time. Step 6 It will go to the NOOBS interface after starting up.
  • Page 30 Step 8 If you run Raspberry Pi for the first time, the application of “Welcome to Raspberry Pi” pops up and guides you to perform the initial setup. Step 9 Set country/region, language and time zone, and then click “next” again.
  • Page 31 Step 10 Input the new password of Raspberry Pi and click “Next”. Step 11 Connect the Raspberry Pi to WIFI and click "Next".
  • Page 32 Step 12 Retrieve update. Step 13 Click "Done" to complete the Settings. Now we can run the Raspberry Pi. Step 14 Click the Terminal icon on the top left corner.
  • Page 33 Terminal Step 15 Then you can input the commands on the Terminal. Note: You can check the complete tutorial of NOOBS on the official website of the Raspberry Pi: https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up...
  • Page 34: If You Have No Screen

    If You Have No Screen If we don't have a screen, we can directly write the Raspbian system to the Micro SD card and we can control the Raspberry Pi on PC remotely by directly modifying the configuration file of the network settings in the Micro SD card. -...
  • Page 35: Connect The Raspberry Pi To The Internet

    You need to replace “WiFi-A” with your custom name of WiFi and “Sunfounder” with your password. By doing these, the Raspbian system will move this file to the target directory automatically to overwrite the original WIFI configuration file when it runs keep the USB card reader plug in next time.
  • Page 36: Start Ssh

    - Start SSH To use the function of remote control of the Raspberry Pi, you need to start SSH firstly that is a more reliable protocol providing security for remote login sessions and other network services. Generally, SSH of Raspberry Pi is in a disabled state. Additionally, if you want to run it, you need to create a file named SSH under directory /boot/.
  • Page 37: Use The Ssh Remote Control

    - Use the SSH Remote Control We can open the Bash Shell of Raspberry Pi by applying SSH. Bash is the standard default shell of Linux. The Shell itself is a program written in C that is the bridge linking the customers and Unix/Linux.
  • Page 38 Step 4 Input the passcode and the default password is raspberry. Step 5 We now get the Raspberry Pi connected and are ready to go to the next step. Note: When you input the password, the characters do not display on window accordingly, which is normal.
  • Page 39  For Windows Users If you're a Windows user, you can use SSH with the application of some software. Here, we recommend PuTTY(You can download from Google). Step 1 Download PuTTY. Open PuTTY and click Session on the left tree-alike structure. Enter the IP address of the RPi in the text box under Host Name (or IP address) and 22 under Port (by default it is 22).
  • Page 40 Step 3 When the PuTTY window prompts “login as:”, type in “pi”(the user name of the RPi), and password: “raspberry” (the default one, if you haven't changed it). Note: When you input the password, the characters do not display on window accordingly, which is normal.
  • Page 41: Servo Configuration

    You can find the source code in our Github repositories. Download the source code by git clone clone --recursive https://github.com/sunfounder/SunFounder_PiCar-S.git Note: Please pay attention to your typing – if you get the prompt of entering your user name and password, you may have typed wrong. If unluckily you did so, press Ctrl + C to exit and try again.
  • Page 42: Install The Environment Via Script

    Install the Environment via Script You can get all the required software and configuration done with the installation script. If you want to do step by step instead, refer to the operations in Appendix 1: Installing Manually. sudo ./install_dependencies Notes: 1.
  • Page 43 3) Rotate slowly but continuously. find conditions above, please send e-mail service@sunfounder.com . We will change a new one to you. If it is broken in the process of using assembling, should official website www.sunfounder.com...
  • Page 44: Build The Rest Of The Car

    Build the Rest of the Car Please keep the command servo-install running in the whole process of assembly. Mount the steering servo to the Upper Plate with two M2x8 Screws and two M2 nuts (pay attention to the direction of the servo wires): Connect the Steering Linkage and the Rocker Arm with Rocker Arm Fixing Screw...
  • Page 45 Mount the wheels onto the Upper Plate carefully. Then put the assembled Front Half Chassis onto the Upper Plate with standoffs aligned with the holes.
  • Page 46 Hold them carefully, turn upside down, and fasten the standoffs and the Upper Plate with four M3x8 screws: So now, the whole assembly is DONE! Congratulations!
  • Page 47: Calibration

    Calibration Calibrate the Servo Remember the commands to adjust the servo to 90 degrees previously? Now, let’s talk about the other two commands. The second command front-wheel-test is used to test whether the front wheels can turn flexibly after assembly. When you run this command, it will drive them to turn left and right.
  • Page 48: Calibrate The Motors

    number). DO NOT over-configure the wheels (recommended a value between -30 and 30), or the servo may be stuck and broken. After changing the value of turning_offset, press Ctrl + O to save the changes, and press Ctrl + X to exit. Run the command picar servo-install to check the front wheel’...
  • Page 49 Press Ctrl + O to save the changes, and press Ctrl + X to exit. picar rear-wheel-test Run the command again to check whether the rear wheels are rotating in accordance with the command. picar rear-wheel-test config example PiCar-S Copy to the directory under config ~/SunFounder_PiCar-S/example...
  • Page 50: Arming The Car

    Now let’s turn the into the PiCar-S. What exactly is the PiCar-S? ------- We arm the PiCar with some sensors, which endow the car with the ability to collect and process the data. The sensor modules...
  • Page 51: Obstacle Avoidance

    Raspberry Pi that can calculate the distance from the obstacle. The Pi will send a command to adjust the front wheels and rear wheels direction and rotation to control the PiCar-S walk away from the obstacle if there is one. - Procedures...
  • Page 52 Step 3 Test First, test the ultrasonic obstacle avoidance module before applying. ~/SunFounder_PiCar-S/example/ python3 test_ultrasonic_module.py You may find that the distance measurement may be not that accurate. It doesn ’ t matter. This 25kHz ultrasonic module is not a commonly used one, but one has a horizontal detecting range of about 30~40 degrees.
  • Page 53: Code Explanation For Ultra_Sonic_Avoid.py

    The PiCar-S starts running now. Just place the car on the ground. It will follow the program to turn when it detects an obstacle; if the obstacle is too close, it will move backwards, and turn left/right. You can also modify the threshold of obstacle detecting range and that of moving backwards in the code.
  • Page 54 The ultrasonic module returns a digital value, i.e., High or Low level, and the interval time between two levels returned can be converted to the distance to the obstacle. Thus, we call the time module in Python for timing here. The formula to calculate the distance is written in the ultrasonic module’s driver.
  • Page 55 Functions Explanation ua = Ultra_Sonic.UltraSonic_Avoidance(17) UltraSonic_Avoidance Create an object ua of a class in the Ultra_Sonic module. The number in the round bracket is the initial parameter, which represents the pin number the SIG of the module is connected to. Since the BCM naming method is applied, the corresponding pin on the Raspberry Pi is #17.
  • Page 56: Light Following

    Light Following - How It Works The light follower module detects light sources in the surroundings, and transfers the data to the processor. The processor analyzes the data and finds the direction of the light resource, so it will send a command to control the movement of the front and rear wheels to approach the resource.
  • Page 57 Note: You may wonder why we connect 5V to 3.3. Well, since the working voltage of DO NOT the STM8 chip on the light follower is 2.7-5.5V, we can connect it to 3.3V here. connect 5V to 5V! All the analog ports on the Robot HATS are led from the PCA8591, which is powerd by 3.3V.
  • Page 58 Expose the phototransistors to the light spot of the flashlight. When you increase the light intensity, more LEDs light up, and the output values decrease. Here we can rotate the blue adjustable resistor to change the values under the same light luminance.
  • Page 59: Code Explanation For Light_Follower.py

    Small turning Straight forward Large turning [1,1,0] [0,0,1] [0,1,0] - Code Explanation for light_follower.py Whole Work Flow 1. Light-sensitive sensors need to be calibrated before actual use because of complex light conditions in the environment. It gathers the information of the ambient light luminance.
  • Page 60 Subflow of Light Follower Calibration Function We need to configure three light-sensitive components separately, so we set three lists to store the values in A0, A1, and A2 collected for multiple times. Then pick out the minimum values, which are the output analog values in the brightest conditions. Since the light source we use is much brighter than the ambient light, we should take the output values in the brightest conditions as reference.
  • Page 61 and 0, for none. For example, [1,0,0] shows that light is detected only by the left probe, meaning th light source is at the left of the car, thus setting the car’s response action as turning left; [1,1,0] means that light is detected on the left and central probes, thus its response action should be set turning left too;...
  • Page 62 lf = Light_Follower.Light_Follower() Then we can call the function by a class object. A0 = lf.read_analog()[0] This function read_analog() will return a list with three elements, which stores the detected analog values of three probes. Here we use A0 = lf.read_analog()[0], A1 = lf.read_analog()[1], and...
  • Page 63: Line Following

    Line Following - How it works The line follower detects lines in the surrounding environment, and transfers the data to the processor. The processor analyzes the data, and sends a command to control the movement of front wheels and rear wheels. -...
  • Page 64 Step 3 Test Get into the directory example: ~/SunFounder_PiCar-S/example Check whether any i2c device is recognized or not via i2c-tools sudo i2cdetect -y 1 We can see 11 is the line follower’s i2c address. If it is not shown, it proves your wiring is not correct and the i2c communication with Raspberry Pi fails too.
  • Page 65 When the module calibration is all completed, we can run the car then. Place the PiCar-S with probes above the black line on the white board, and then it will go forward following the line itself. How to make a track for line following...
  • Page 66 right 45 degrees, the semidiameter of the path by which the car turns is equal to the wheelbase (the distance between the center of the front wheels and rear wheels). The car won't be able to turn and pass the curve smoothly if the semidiameter of the curve is too small.
  • Page 67: Code Explanation Of Line_Follower.py

    - Code Explanation of line_follower.py Whole Work Flow Considering the interference of negative environment factors, we need to calibrate the line follower sensor before actual use. Start Calibrate the Run line follower calibration function line follower Run line following Follow line function Keyboard interrupt...
  • Page 68 Line follower calibration function Prompt user to Prompt user to calibrate for calibrate for white color black color Delay for user to Delay for user to place the sensor place the sensor above white surface above black line Take the average value for each sensor Sensor reads the...
  • Page 69 Subflow of Line Following Function...
  • Page 70 In the line following function, we set the turning angle of the servo in different levels according to the detection results of the probes. If the line in front of the car is detected as a small curve, then the car will turn a small angle; if it is a big one, the car will turn a large angle.
  • Page 71 line (2). If there is no response program in such case, the car will be unable to follow the line again. Thus we set the response program to let the car move backwards in the opposite direction (3), and then turn back to the original direction until a black line is detected again and move forward (4).
  • Page 72: Combination

    Combination So, this smart car now is smart in three separate features. But, you think only one sensor module is not enough? Try to combine those sensor modules in one! Here we can show you an experiment - light following with obstacle avoidance for reference. When the car runs with the light follower, sometimes it may crash into obstacles when following the light, and it’s not quite convenient to let the car move back (though we've set the car to move backward if the array is [1,0,1], it’...
  • Page 73 In the function state_light(), the return value is light_flag. If the light spot is in front of the car, it will return light_flag = if the spot is at the right side, it will return light_flag = if the spot is at the left side, it will return light_flag = if the spot is at the back, it will return light_flag =...
  • Page 74: Appendix 1: Installing Manually

    2. Install python-smbus. sudo apt-get install python-smbus -y 3. Install the PiCar module. clone --recursive https://github.com/sunfounder/SunFounder_PiCar.git SunFounder_PiCar python3 setup.py install 4. Enable I2C. Edit the file /boot/config.txt sudo nano /boot/config.txt The "#" in front of each line is to comment the following contents which does not take effect in a sketch.
  • Page 75: Appendix 2: Modules

    Appendix 2: Modules Robot HATS Robot HATS is a specially-designed HAT for a 40-pin Raspberry Pi and can work with Raspberry Pi 3 model B, 3 model B +, and 4 model B. It supplies power to the Raspberry Pi from the GPIO ports. Thanks to the design of the ideal diode based on the rules of HATS, it can supply the Raspberry Pi via both the USB cable and the DC port thus protecting it from damaging the TF card caused by batteries running out of power.
  • Page 76: Pca9865

    5V power output: 5V power output to PWM driver. UART port: 4-wire UART port, 5V VCC, perfectly working with SunFounder FTDI Serial to USB. Motor control ports: 5V for motors, direction control of motors MA and MB and a floating pin NC; working with motor driver module.
  • Page 77: Motor Driver Module

    PWM output ports: 3-color ports, independent power PWM output port, connect to the servo directly. 2 & 3. port: 4-wire I2C port, can be used in parallel. Compatible with 3.3V/5.5V PWM power input: 12V max. 5. LED: power indicator for the chip and for the PWM power input. Motor Driver Module The Motor Driver module is a low heat generation one and small packaged motor drive.
  • Page 78: Line Follower Module

    Line Follower Module The TCRT5000 infrared photoelectric switch adopts a high transmit power infrared photodiode and a highly sensitive phototransistor. It works by applying the principle of objects' reflecting IR light – the light is emitted, then reflected, and sensed by the synchronous circuit.
  • Page 79: Light Follower Module

    Light Follower Module Phototransistor, also known as photodiode, is a device that converts light to current. Currents are generated when photons are absorbed in the P-N junction. When a reverse voltage is applied, the reverse current in the device will change with the light luminance.
  • Page 80: Ultrasonic Obstacle Avoidance Module

    Ultrasonic Obstacle Avoidance Module This module contains an ultrasonic sensor to detect the distance to an obstacle in front. It is usually used on robots to avoid obstacles. With the two holes, it can be assembled easily on the robot. There is power indicator light added onside to indicate power on/off.
  • Page 81: Sunfounder Sf006C Servo

    We suggest to use over 60ms measurement cycle, so as to prevent trigger signal to the echo. SunFounder SF006C Servo The SunFounder SF0180 Servo is a 180-degree three-wire digital servo. It utilizes PWM signal of 60Hz and has no physical limit – only control by internal software to 180 degrees at most.
  • Page 82: Dc Gear Motor

    Copyright Notice All contents including but not limited to texts, images, and code in this manual are owned by the SunFounder Company. You should only use it for personal study, investigation, enjoyment, or other non-commercial or nonprofit purposes, under the related regulations and copyrights laws, without infringing the legal rights of the author and relevant right holders.

Table of Contents