-
Preface 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 you make your own project.
-
Contents Components List ..................................................................................................................................................... 1 Constructure Plates ........................................................................................................................................ 1 Servo Accessories ...........................................................................................................................................
-
Code Explanation ........................................................................................................................................ 54 Server Code ........................................................................................................................................... 55 Client Code ............................................................................................................................................ 57 1. Designing the Interface .................
-
Components List Constructure Plates 1. Upper Plate x 1 2. Front Half Chassis x 1 3. Back Half Chassis x 1 4. Servo-Camera Base x 1 5. Servo Mount x 1 6. Camera Mount x 1 7. Steering Connector x 2 8. Bearing Shield x 6 9. Steering Linkage x 1 10.
-
1. 1-arm Rocker Arm 2. 2-arm Rocker Arm 3. 4-arm Rocker Arm 4. Rocker Arm Screw 5. Rocker Arm Fixing Screw × 2 Mechanical Fasteners Name Component Qty. M1.6x4 Cross Selftapping Screw 8 M2x8 Cross Screw 6 M2.5x6 Cross Screw 4 M2.
-
M3x8 Cross Screw 8 M3x8 Countersunk Cross Screw 2 M3x10 Cross Screw 7 M3x25 Cross Screw 4 M4x25 Cross Screw 2 M2 Nut 6 M2.
-
M4 Self-locking Nut 2 M2.5x8 Copper Standoff 8 M3x25 Copper Standoff 8 4x11x4 F694ZZ Flange Bearing 2 Wires 100mm HX2.54 5-Pin Jumper Wire 1 50mm HX-2.54 4-Pin Jumper Wire 1 50mm HX-2.
-
100mm HX-2.
-
TB6612 Motor Driver 1 Other Components 2x18650 Battery Holder 1 DC Gear Motor 2 6
-
SunFounder SF006C Servo 3 120°Wide-angle USB Camera 1 Rear Wheel 2 7
-
Front Wheel 2 USB Wi-Fi Adapter 1 Ribbon (30cm) 1 Tools Cross Screwdriver 1 8
-
Cross Socket Wrench 1 M2.
-
Introduction The is developed based on the previous Smart Video Car Kit. It’s equipped with the new PCA9685 PWM driver, smaller and better-performing DC motor driver TB6612, a Robot Hat with power and interface integrated, a wider-angle camera with clearer vision, some better wheels and tires, and so on. Later we'll check more details. The basic functions of this new version still stay the same, including controlling the PiCar-V remotely and streaming the video data it captures back.
-
Visual Programming with Dragit Instead of coding the Sensor Kit directly in Python, you can also do it in a graphical/visual programming software - Dragit, developed based on Snap! (check http://snap.berkeley.edu/ for more). What's good about Dragit is that, the programming process is visible with graphics. So you can just drag and drop the blocks (unit in the software) to make the code in each lesson, no need of the knowledge of any programming languages or syntaxes.
-
Building the Car Are you excited when you open the box and see so many components? Keep your patience and take it easy. Please note that some details in the following steps need careful observation. You should double-check your work based on the figures in the manual after finishing each step. Don’t worry! Kindly reminders will be given in some particular steps. Just follow the tutorials step by step. Okay, guys, let’s start! Fixing Rear Wheels Assemble the two motors with four M3x25 screws and M3 nuts.
-
Upper Plate Mount the M2.5x8 copper standoffs and M2.5 nuts into the upper plate first. Four copper standoffs are needed. So here 4 holes should be used, marked with cross as shown below: Assemble the M2.5x8 copper standoffs and M2.5 nuts as shown below. Pay attention that the side the protruding prop should face up.
-
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 M3 nuts: pay attention to the direction of battery holder’s wire.
-
Rear Wheels (Screws) Insert four M3x8 screws with four M3x25 copper standoffs: 15
-
PCB Assembly Assemble the Raspberry Pi (TF Card inserted) with eight M2.5x8 copper standoffs, then plug the Robot HATS onto it, and fix the Robot HATS with four M2.5x6 screws. Fix The PCA9685 PWM Driver, the TB6612 Motor Driver with eight M2.5x12 screws and M2.
-
Rear Wheels (Driving) Assemble the rear wheels 17
-
Align the rear wheels with the motor shaft, and rotate to insert them gently.
-
Connect the PWM CONTROL of the Robot HATS with the PCA9685 PWM Driver, and the TB6612 CONTROL with the TB6612 Motor Driver. Then the Left Motor and the Right Motor of the TB6612 to two motors, and the Motor PWM with the No. 4 and 5 PWM channel of the PCA9685. Connect the PWM Power of the PCA9685 with the Robot HATS, and its channel 0, 1, and 2 of with the Turning Servo, the Pan Servo and the Tilt Servo respectively.
-
Servo Configuration 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 rotate to the 90 degrees when it's mounted, so the rotating range can match with the application in the car. Otherwise, damages may be caused to servos.
-
suffix in the file name. 7) Create a WiFi configuration file wpa_supplicant.conf under /boot and add the following to the file: ssid= "(name of the Wi-Fi)" psk= "(your Wi-Fi password)" B. Car Power Supply Now you can unplug the TF card from the PC and insert it into the Raspberry Pi. For power supply of the smart car, please note: 1) Supply the Raspberry Pi independently with a 5V/2A power – the software installation and calibration needs a long time and the battery won't be able to support.
-
IP Address There are many network scanners available, and here we recommend the Advanced IP scanner. This software will detect the network segment of the computer and decide the scan range automatically. For example, when the IP is 192.168.1.101 of the computer, its scan range is 192.168.1.* Click Start to start the scanning and you will see a computer list within the same network segment. One advantage of this software is that it can find out the manufacturer of the network devices.
-
Type in ssh pi@ip_address – ssh is the tool for remote login, pi, the user name, and ip_address, as the name suggests, your Pi's IP address. For example: ssh pi@192.168.0.101 Press Enter to confirm. If you get a prompt that no ssh is found, you need to install an ssh tool like Ubuntu and Debian by yourself: sudo apt-get install ssh For other Linux platforms, please contact your supplier. For Windows Users If your computer runs on Windows, you need to pen the Bash shell with the help of some software.
-
1. Download PuTTY. 2. Open PuTTY and click Session on the left tree-alike structure (generally it's collapsed upon PuTTY startup).Enter the IP address of the RPi you just got in the textbox under Host Name (or IP address) and 22 under Port (by default it is 22). 6. Click Open. Note that when you first log in to the Raspberry Pi with the IP address, you'll be prompted with a security reminder. Just click Yes.
-
D. Get Source Code You can find the source code in our Github repositories. Download the source code by git clone: cd ~/ git clone https://github.com/sunfounder/SunFounder_PiCar-V.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.
-
Notes: 1. The installation script will install the required components and configure for the running environment. Make sure your Raspberry is connected to the Internet during the installation, or it would fail. 2. The Raspberry Pi will prompt you to reboot after the installation. You're recommended to type in yes to reboot. G.
-
Continue to Assemble Note: Please keep servo-install running in the whole process of assembly. Note: Please pay attention to the direction of Steering Connector before assembling.
-
Steering Part Take out the 1-arm Rocker Arm and the Rocker Arm Screw (a longer one in the servo pack): Connect the Steering Linkage and the rocker arm with the screw. Note: Insert it into the FIRST hole of the arm (as indicated by the arrow below) which is the farthest from the gears. Since the screw is larger than the hole, you should try to screw it hardly so as tight to the arm. Don't worry of the arm which is soft.
-
Mount the servo that connects to PWM Channel 0, the steering servo, to the Upper Plate with two M2x8 Screws and M2 nuts (pay attention to the direction of the servo wires): Connect the Steering Linkage and the rocker arm. Make sure the rocker arm is in an angle as shown below. Try to spin the arm on the shaft, NOT on the linkage). If it's unmovable, it means the servo is adjusted to 90 degrees.
-
Front Half Chassis Assemble the Front Half Chassis with four M3x25 copper standoffs and M3 nuts as shown below: Take out the assembled front wheels and the Upper Plate, and mount the wheels onto the Upper Plate carefully: insert one bulge of the Steering Connector at one wheel into the hole on the Steering Linkage plate at the corresponding end, and the other bulge into the Upper Plate (pay attention to the height level of two bulges), and similar with the other wheel.
-
Then put the assembled Front Half Chassis onto the Upper Plate with standoffs aligned with the holes.
-
Hold them carefully, turn upside down, and fasten the standoffs and Upper Plate with four M3x8 screws: Pan-and-Tilt Take out the Cross rocker arm and mount it onto the Pan-and-tilt Base with four M1.6x4 screws (into the hole like this). Pay attention to the holes on the round rocker arm to be fastened; though the pointed end of the screwdriver is a little bigger than the screws, you can still tighten them – just insert them and screw slowly: Do the same operation to the Tilt Arm.
-
Assemble the two servos connected to PWM Channel i.e.
-
Make sure the servo shaft has spun to 90 degrees. Then assemble the Tilt Arm and The Gasket with the Rocker Arm Fixing Screw in a fixed angle as shown below: Note: Do not rotate the servo by hands in case of breaking the servo down. Similarly check that the servo shaft has spun to 90 degrees.
-
Other Components Take out the camera and nip it to the Camera Mount. Connect its USB cable to the USB port on the Raspberry Pi.
-
Installing the Client (Operation on the PC) Since you've finished the car building, now it's time to configure the environment for the client. Or you may skip this part and go to the subsequent Web Client for controlling on the webpage. Environment Configuration The client is written by Python 3 + PyQt5, so it’s necessary to install the two in your PC. Python 3 website: https://www.python.org/downloads/ Select the proper version of Python 3 for your PC, and follow the instructions to install.
-
Code Package Download Open a web browser and go to the Github page of the PiCar-V: https://github.com/sunfounder/SunFounder_PiCar-V Click Clone or download on the page, and click Download ZIP as shown below. After download, unzip the file. Or in Linux, you can download the code package by git clone (recommended): Install git with software manager: Ubuntu/Debian: sudo apt-get install git Fedora/Red Hat: sudo yum install git Then clone the code: git clone https://github.com/sunfounder/SunFounder_PiCar-V.
-
Getting on the Road! Make sure all the procedures have been finished, and check there is no problem about the mechanical assembly and software installation. Then you can start the car now. Install two batteries, and turn on the power switch. Tips: If you keep the Raspberry Pi power on from the beginning, now you do not need to turn it off. DO NOT unplug the Micro USB cable until you've installed the batteries and switched it on. So you do not need to turn it on or off again.
-
DEBUG "camera.py": Set pan servo and tilt servo debug off DEBUG "Servo.py": Set debug off DEBUG "Servo.py": Set debug off None System check identified no issues (0 silenced). November 09, 2016 - 06:28:41 Django version 1.10.2, using settings 'remote_control.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C. If you get the result similar as shown above, the server is ready. Now move on to start the client. 2.
-
Run the client and you will see: This is the login interface of the client. Enter your Raspberry Pi’s IP address and the port, 8000 by default, and then click Log in to connect to the Raspberry Pi. It may take a while to establish connection, sometimes may not respond at all, so just wait several seconds. If it’s successful, you'll be on the operation interface. If not, double check your Raspberry Pi's IP address and make sure the server script is run without error prompts.
-
The interface will show the view captured by the camera in a real-time manner. There are some number buttons at the bottom to adjust the car’s speed, ascending from level 1 to 5. You can also press the key 1-5 on the keyboard. The rest control movements of the car are implemented by keyboard.
-
Click the setting button at the bottom right or press Alt + S, and you will see the Calibration page as below (click the three larger icons for the corresponding calibration): Camera – to calibrate the camera movement. Short cut: Alt + C. Front Wheels – to calibrate the front wheels. Short cut: Alt + F. Rear Wheels – to calibrate the rear wheels. Short cut: Alt + R. Click the arrow return button or Alt + ← and you will go back to the operation interface.
-
Calibration: Camera When completed, the camera should look like the figure above. The camera should be in the center line of the car and face exactly front. You can use the keyboard to adjust, by the arrow keys ↑, ←, ↓, and →, or W, A, S, and D. The servo turning angle is very small, so it's quite suitable for fine tuning; press and hold it to coarsely adjust quickly. Click OK or press Alt + O to save the calibration result; click Cancel or press Alt + C to cancel the calibration and exit.
-
Calibration: Front Wheels Adjust the front wheels to the appropriate position according to the above figure. You can use the keyboard to adjust, that is, ←, →, A, and D. Click OK or press Alt + O to save the calibration result; click Cancel or press Alt + C to cancel the calibration and exit. If the servo gets stuck, remove the rocker arm and readjust again (refer to the Servo Configuration).
-
Calibration: Rear Wheels Adjust the rotating direction of the rear wheels, to make the car go forward. Adjust the wheels by the keys ← and → or A and D. The left and right is to control the left and right wheels respectively and each clicking will reverse the rotation of the wheel. After all the calibration is done, you can return to the operation interface. Make sure both LED indicators on the Robot HATS board light up. Now you can unplug the Micro USB cable and put the car on the ground.
-
- Method B Visit the server of the car at http://:8000/. You will see a welcome page: Click LET'S ROCK to go to the operation interface: On this page, you can press the keys W, A, S, and D on the keyboard to control the car to move forward, backward, turn left, and turn right, press the arrow keys to control the camera’s movement, and number 1~5 to change the speed level.
-
Also for mobile phones, tap the FULLSCREEN button to have a better view and performance. Then, tap the buttons of 5 speed levels on the page to control the speed, and the arrow buttons to control the direction of the car and the pan-and-tilt. But you can only tab one touchpoint at one time. Click FULLSCREEN again to bring back the title bar.
-
Though the appearance may not be as good as on the PC. Later updates may be released irregularly on Github. You are welcome to fork our repository and submit a Pull request with your changes. If there is no problem after testing, we are more than pleased to merge your request.
-
Components Robot HATS Robot HATS is a specially-designed HAT for a 40-pin Raspberry Pi and can work with Raspberry Pi model B+, 2 model B, and 3 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.
-
2. Analog ports: 3-wire 4-channel 8-bit ADC sensor port, reference voltage: 3.3V, VCC voltage: 3.3V. 3. I2C ports: 3.3V I2C bus ports 4. 5V power output: 5V power output to PWM driver. 5. UART port: 4-wire UART port, 5V VCC, perfectly working with SunFounder FTDI Serial to USB. 6. TB6612 motor control ports: includes 3.3V for the TB6612 chip, 5V for motors, and direction control of motors MA and MB; working with SunFounder TB6612 Motor driver. 7. Switch: power switch 8.
-
1. PWM output ports: 3-color ports, independent power PWM output port, connect to the servo directly. 2 & 3. I2C port: 4-wire I2C port, can be used in parallel. Compatible with 3.3V/5.5V 4. PWM power input: 12V max. 5. LED: power indicator for the chip and for the PWM power input. TB6612 The TB6612 Motor Driver module is a low heat generation one and small packaged motor drive. 1.
-
2. PWM input for the motors: PWM signal input for adjusting the speed of the two motors 3. Motor output port: output port for two motors USB Webcam This camera supports a wide angle of 120°, which provides a wide and clear vision, thus giving better experience when you're using it on the PiCar-V. SunFounder SF006C Servo Clutch gear digital servo with a DC core motor inside, After a certain load, the steering gear reducer will automatically clutch and protect the product from damage and normal load.
-
WiFi Adapter The Ralink RT5370 Wireless Adapter is used in the car. Below are the features: USB: XC1291 Network Connectivity: Wireless-Wi-Fi 802.11b, Wireless-Wi-Fi 802.11g, Wireless-Wi-Fi 802.11n Applicable Network Type: Ethernet Transmission Rate: 150Mbps DC Gear Motor It's a DC motor with a speed reducing gear train. See the parameters below: Motor Gear Reducer Model F130SA-11200-38V Rated Voltage 4.
-
Code Explanation There are two folders under /home/pi: SunFounder_PiCar for controlling motors and steering and SunFounder_PiCar-V for pan/tilt and wireless control. Here look into the code of PiCar-V. Since too many contents and instructions are involved in the code, we will not cover every detail. For more knowledge about Python 2, Python 3, PyQt, Django, HTML, and CSS in the programs, you can visit related websites or buy books to learn by yourself.
-
Server Code The server code is based on Django 1.10 (adapt to the latest release if needed). If you are interested in this, you can visit the Django website https://www.djangoproject.com/, or read The Django Book to learn more at http://gsl.mit.edu/media/programs/south-africa-summer2015/materials/djangobook.pdf. Here we will just learn how the web server works. Note: The code may be updated irregularly on Github to fix bugs and release some functions update. So the code here is the initial version.
-
templates is a Django app for storing the webs in the html format. urls.py is generated automatically to configure the URL to associate with the code. views.py is the code for page control which is associated by the URL. It calls the templates to show the page and the driver to control the car. wsgi.py is generated automatically and does not need changes. For more, please visit the official website of Django. So here is how the code works: Run the main program manage.
-
There are three HTML files that also consist of layers. The low level base.html stores contents contained on each page such as the
of HTML, the overall layout, and contents of the home page by default. The surface layer: cali.html for calibration and run.html to control the car. So that's the code of the server. Next we will come to the code of the client written by PyQt. Client Code In Windows, you can check the contents of client directory by grouping files by file type: client.
-
The interfaces go one by one like this: 1. The login page: enter the Raspberry Pi’s IP address and click Log in go to the operation interface. 2. The operation interface will show the view captured by the camera. You can control the movement of the car on this page. You can click the return button, to go back to login, and the settings button to go to calibration interface. 3. The calibration interface: you can control and adjust the car by keyboard.
-
Design the first interface (login), with the GUI design tool. In the left column is the Widget Box section. You can just drag the components available here to the edit window in the center to see the effect directly. In the right column, on top is Object Inspector, where you can check the association and category of the added objects. Under this section, the property of the object is shown. You can set the attributes in this part, to differentiate all the widget objects.
-
The setting of other components such as button, line edit and on, is just similar, though the properties are different. The name of the objects whose property has been changed will be marked bold automatically for convenience in next check. You can open those .ui files to see the property details that can be changed, or the widget type by objects in Object Inspector. After editing, you can select Window -> Preview in the Qt Designer to see the effect, or by the shortcut Ctrl + R.
-
2. Programing the Functions Now the interface design is finished. However, the interface files are just some static images and cannot be put into use. So the next step, write the client.py to implement all the interfaces with the corresponding functions as well as redirections. The PyQt is like this: In Line 5, enter the name of the ui file you designed in the quotation marks. In Lin 7e, "uic" is the contents in the previously imported PyQt; the built-in function loads the ui files.
-
So that's all for the code. Here we've only looked at the entry-level usage. For more detailed code explanation, go to the client.py file. There you can see very detailed comments. Advanced Now the car is running! You may try control it or view the image captured in Windows, Linux, or Mac OS X. So what to do next? Yes, sensors! There are 8 digital and 4 analog channels on the Robot HATS, as well as two I2C ports.
-
PiCar-V: https://github.com/sunfounder/SunFouner_PiCar-V PiCar driver: https://github.com/sunfounder/SunFounder_PiCar And of course, if you have any questions or ideas, please feel free to email us at service@sunfounder.com. Appendix: Function of the Server Installation Scripts You may have a question: What do the installation scripts do when we install the server on the Raspberry Pi by them? So here let's check the detailed steps. 1. Install pip apt-get install python-pip 2.