Freenove Tank Robot Kit Guide
Freenove Tank Robot Kit Guide
About Battery
Freenove provides free and responsive product and technical support, including but not limited to:
⚫ Product quality issues
⚫ Product use and build issues
⚫ Questions regarding the technology employed in our products for learning and education
⚫ Your input and opinions are always welcome
⚫ We also encourage your ideas and suggestions for new products and product improvements
For any of the above, you may send us an email to:
support@[Link]
Safety and Precautions
Please follow the following safety precautions when using or storing this product:
⚫ Keep this product out of the reach of children under 6 years old.
⚫ This product should be used only when there is adult supervision present as young children lack necessary
judgment regarding safety and the consequences of product misuse.
⚫ This product contains small parts and parts, which are sharp. This product contains electrically conductive
parts. Use caution with electrically conductive parts near or around power supplies, batteries and
powered (live) circuits.
⚫ When the product is turned ON, activated or tested, some parts will move or rotate. To avoid injuries to
hands and fingers, keep them away from any moving parts!
⚫ It is possible that an improperly connected or shorted circuit may cause overheating. Should this happen,
immediately disconnect the power supply or remove the batteries and do not touch anything until it
cools down! When everything is safe and cool, review the product tutorial to identify the cause.
⚫ Only operate the product in accordance with the instructions and guidelines of this tutorial, otherwise
parts may be damaged or you could be injured.
⚫ Store the product in a cool dry place and avoid exposing the product to direct sunlight.
⚫ After use, always turn the power OFF and remove or unplug the batteries before storing.
About Freenove
Freenove is committed to assist customers in their education of robotics, programming and electronic circuits
so that they may transform their creative ideas into prototypes and new and innovative products. To this end,
our services include but are not limited to:
⚫ Educational and Entertaining Project Kits for Robots, Smart Cars and Drones
⚫ Educational Kits to Learn Robotic Software Systems for Arduino, Raspberry Pi and micro: bit
⚫ Electronic Component Assortments, Electronic Modules and Specialized Tools
⚫ Product Development and Customization Services
You can find more about Freenove and get our latest news and updates through our website:
[Link]
Copyright
All the files, materials and instructional guides provided are released under Creative Commons Attribution-
NonCommercial-ShareAlike 3.0 Unported License. A copy of this license can be found in the folder containing
the Tutorial and software files associated with this product.
This means you can use these resource in your own derived works, in part or completely, but NOT for the
intent or purpose of commercial use.
Freenove brand and logo are copyright of Freenove Creative Technology Co., Ltd. and cannot be used without
written permission.
○
R
Welcome....................................................................................................................................................................................... 1
Contents ....................................................................................................................................................................................... 1
List .................................................................................................................................................................................................. 1
Machinery Parts ................................................................................................................................................................. 1
Transmission Parts............................................................................................................................................................. 2
Acrylic Parts......................................................................................................................................................................... 3
Electronic Parts ................................................................................................................................................................... 3
Tools ..................................................................................................................................................................................... 4
Self-prepared Parts ........................................................................................................................................................... 5
Tank Smart Car Board for Raspberry Pi ....................................................................................................................... 6
Preface .......................................................................................................................................................................................... 6
Raspberry Pi Introduction ................................................................................................................................................ 7
Chapter 0 Raspberry Pi Preparation ................................................................................................................................... 16
Install a System................................................................................................................................................................ 16
Getting Started with Raspberry Pi .............................................................................................................................. 26
Chapter 1 Software installation and Test (necessary)..................................................................................................... 37
Step 1 Obtain the Code ................................................................................................................................................ 37
Step2 Install the Needed Libraries ............................................................................................................................. 38
Chapter 2 Assemble Smart Car ............................................................................................................................................ 41
Chapter 3 Module test (necessary) ..................................................................................................................................... 65
Chapter 4 Ultrasonic Obstacle Avoidance Car ................................................................................................................. 80
Description ....................................................................................................................................................................... 80
Chapter 5 Infrared tracking automatic wrecker ............................................................................................................... 82
Description ....................................................................................................................................................................... 82
Chapter 6 Smart video car .................................................................................................................................................... 85
Server................................................................................................................................................................................. 86
Client.................................................................................................................................................................................. 88
Android and iOS app................................................................................................................................................... 108
Free innovation ............................................................................................................................................................. 110
What's next? ........................................................................................................................................................................... 117
█ [Link] List 1
List
If you have any concerns, please feel free to contact us via support@[Link]
Machinery Parts
Transmission Parts
Acrylic Parts
Electronic Parts
Or
XH-2.54-5Pin cable x1
FPC cable x1
Tools
Cross screwdriver (3mm) Black tape x1 Cable Tidy x20cm Red ball x1
x1
Self-prepared Parts
2X 3.7V 18650 lithium rechargeable batteries with continuous discharge current >3A.
It is easier to find proper battery on eBay than Amazon. Search “18650 high drain” on eBay.
Note: The images of the car board may look different from the one you receive (V1.0 or V2.0). By the way,
the interface design of the two version is the same, so the operation on them are the same. You can just
follow this book to use it.
Tank Smart Car Board V1.0 Tank Smart Car Board V2.0
Preface
Welcome to use Freenove Tank Kit for Raspberry Pi. Following this tutorial, you can make a very cool smart
car with many functions.
This kit is based on Raspberry Pi, a popular control panel, so you can share and exchange your experience
and design ideas with many enthusiasts all over the world. The parts in this kit include all electronic
components, modules, and mechanical components required for making the smart car. And all of them are
packaged individually. There are detailed assembly and commissioning instructions in this book.
And if you encounter any problems, please feel free to contact us for fast and free technical support.
support@[Link]
The contents in this book can help enthusiasts with little technical knowledge to make a smart car. If you are
very interested in Raspberry Pi, and want to learn how to program and build the circuit, please visit our
website [Link] or contact us to buy the kits designed for beginners:
Freenove Basic\LCD1602\Super\Ultrasonic\RFID\Ultimate Starter Kit for Raspberry Pi
Raspberry Pi Introduction
Raspberry Pi (called RPi, RPI, RasPi, these words will be used alternately later), a micro-computer with size of
a card, quickly swept the world since its debut. It is widely used in desktop workstation, media center, smart
home, robots, and even the servers, etc. It can do almost anything, which continues to attract fans to explore
it. Raspberry Pi used to be running with Linux system and along with the release of windows 10 IoT. We can
also run it with Windows. Raspberry Pi (with interfaces USB, network, HDMI, camera, audio, display and GPIO),
as a microcomputer, can be running in command line mode and desktop system mode. Additionally, it is easy
to operate just like Arduino, and you can even directly operate the GPIO of CPU.
So far, at this writing, Raspberry Pi has advanced to its fifth generation product offering. Version changes are
accompanied by increases in upgrades in hardware and capabilities.
The A type and B type versions of the first generation products have been discontinued due to various reasons.
What is most important is that other popular and currently available versions are consistent in the order and
number of pins and their assigned designation of function, making compatibility of peripheral devices greatly
enhanced between versions.
Below are the raspberry pi pictures and model pictures supported by this product. They have 40 pins.
Physical image of Raspberry Pi 3 Model B+: CAD image of Raspberry Pi 3 Model B+:
Physical image of Raspberry Pi 1 Model B+: CAD image of Raspberry Pi 1 Model B+:
Physical image of Raspberry Pi 3 Model A+: CAD image of Raspberry Pi 3 Model A+:
Physical image of Raspberry Pi 1 Model A+: CAD image of Raspberry Pi 1 Model A+:
Below are the raspberry pi pictures and model pictures supported by this product. They have 40 pins.
Hardware interface diagram of RPi 5 is shown below:
GPIO
Connector
USB
PCl Express Connector x4
interfance
On/Off button
Ethernet
Power Connector
Connector
GPIO
Connector Ethernet
Connector
Display
Connector
USB
Power Connector x4
Connector
GPIO
Connector
USB
Connector
Display
Connector
Ethernet
Power Connector
Connector
GPIO
Connector
USB
Display Connector
Connector
Power
Connector
GPIO
Connector
Camera
Connector
GPIO
GPIO: General purpose input/output. We will introduce the specific feature of the pins on the Raspberry Pi
and what you can do with them. You can use them for all sorts of purposes. Most of them can be used as
either inputs or outputs, depending on your program.
When programming the GPIO pins there are 3 different ways to refer to them: GPIO numbering, physical
numbering, WiringPi GPIO Numbering.
PHYSICAL Numbering
Another way to refer to the pins is by simply counting across and down from pin 1 at the top left (nearest to
the SD card). This is 'physical numbering', as shown below:
For more details about pin definition of GPIO, please refer to [Link]
Install a System
Component List
Required Components
Raspberry Pi 5 / 4B / 3B+/ 3B /3A+ (Recommended) 5V/3A Power Adapter. Different versions of
Raspberry Pi have different power requirements.
Micro USB Cable x1 Micro SD Card (TF Card) x1, Card Reader x1
This robot also supports the following versions of the Raspberry Pi, but additional accessories need to be
prepared by yourself.
Raspberry Additional accessories
Raspberry Pi Zero W Camera cable(>25cm) for zero w, 15 Pin 1.0mm Pitch to 22 Pin 0.5mm
[Link]
Raspberry Pi Zero 1.3 wireless network adapter,
Camera cable(>25cm) for zero w, 15 Pin 1.0mm Pitch to 22 Pin 0.5mm,
OTG cable (USB Type micro B to USB Type A)
Raspberry Pi 2 Model B wireless network adapter
Raspberry Pi 1 Model A+ wireless network adapter
Raspberry Pi 1 Model B+ wireless network adapter
In addition, RPi also needs an Ethernet network cable used to connect it to a WAN (Wide Area Network).
The Raspberry Pi 5 provides 1.6A of power to downstream USB peripherals when connected to a power supply
capable of 5A at +5V (25W). When connected to any other compatible power supply, the Raspberry Pi 5
restricts downstream USB devices to 600mA of power.
Optional Components
Under normal circumstances, there are two ways to login to Raspberry Pi:
1) Using independent monitor, or remote desktop to share a monitor with your PC.
2) Using a remote desktop or laptop computer monitor “sharing” the PC monitor with your RPi.
For different Raspberry Pi Modules, the optional items may vary slightly but they all aim to convert the
interfaces to Raspberry Pi standards.
Pi Zero Pi
Pi Zero Pi A+ Pi 3A+ Pi B+/2B Pi 4B Pi 5
W 3B/3B+
Monitor Yes (All)
Mouse Yes (All)
Keyboard Yes (All)
Micro-HDMI to
HDMI Adapter & Yes No Yes No No No No No
Cable
Micro-HDMI to
HDMI Adapter & No Yes
Cable
Micro-USB to
USB-A Adapter &
Yes No Yes No
Cable (Micro USB
OTG Cable)
USB HUB Yes Yes Yes Yes No No No No
USB to Ethernet Internal
select one from optional
Interface Integration
two or select Internal Integration
USB Wi-Fi Receiver Internal
two from two optional
Integration
Raspberry Pi OS
Automatically Method
You can follow the official method to install the system for raspberry pi via visiting link below:
[Link]
In this way, the system will be downloaded automatically via the application.
Manually Method
After installing the Imager Tool in the link above. You can also download the system manually first.
Visit [Link]
You can download the latest system image. The following is just for your reference.
Select a Raspberry PI Device based on your Raspberry PI version. It will help us filter out the right version of
the system for the Raspberry PI.
Click Save, in the new screen, click Yes, wait for SD to brush into the Raspberry system.
Insert SD card
Then remove SD card from card reader and insert it into Raspberry Pi.
Connect to the power supply and wait for the Raspberry PI to turn on.
Monitor desktop
If you do not have a spare monitor, please skip to next section Remote desktop & VNC. If you have a spare
monitor, please follow the steps in this section.
After the system is written successfully, take out Micro SD Card and put it into the SD card slot of RPi. Then
connect your RPi to the monitor through the HDMI port, attach your mouse and keyboard through the USB
ports, attach a network cable to the network port and finally, connect your power supply (making sure that it
meets the specifications required by your RPi Module Version. Your RPi should start (power up). Later, after
setup, you will need to enter your user name and password to login. The default user name: pi; password:
raspberry. After login, you should see the following screen.
Congratulations! You have successfully installed the RASPBERRY PI OS operating system on your RPi.
Raspberry Pi 5, 4B, 3B+/3B integrates a Wi-Fi adaptor. You can use it to connect to your Wi-Fi. Then you can
use the wireless remote desktop to control your RPi. This will be helpful for the following work. Raspberry Pi
of other models can use wireless remote desktop through accessing an external USB wireless card.
Connect WiFi
In addition, your VNC Viewer window may zoom your Raspberry Pi desktop. You can change it. On your
VNC View control panel, click right key. And select Properties->Options label->Scaling. Then set proper
scaling.
Here, you have logged in to Raspberry Pi successfully by using VNC Viewer and operated proper setting.
Raspberry Pi 5/4B/3B+/3B integrates a Wi-Fi [Link] you did not connect Pi to WiFi. You can connect it to
wirelessly control the robot.
If you have logged in Raspberry Pi via display, you can skip to VNC Viewer.
If you don't have a spare display, mouse and keyboard for your RPi, you can use a remote desktop to share
a display, keyboard, and mouse with your PC. Below is how to use:
MAC OS remote desktop and Windows OS remote desktop.
MAC OS Remote Desktop
Open the terminal and type following command. If this command doesn’t work, please move to next page.
ssh pi@[Link]
The password is raspberry by default, case sensitive. You may need to type yes during the process.
“pi@raspberrypi:~ $” indicates that you have successfully connected to Rpi, as shown below.
Please note that the typing is invisible when you enter the password. Make sure you type it correctly.
Then download and install VNC Viewer according to your computer system by click following link:
[Link]
After installation is completed, open VNC Viewer. And click File → New Connection. Then the interface is
shown below.
Enter ip address of your Raspberry Pi and fill in a name. Then click OK.
.
Then on the VNC Viewer panel, double-click new connection you just created,
In this chapter, we will make some necessary preparation: start your Pi Raspberry and install some necessary
libraries. Then test some parts. Batteries are needed when driving peripherals such as motors, servos, LEDs,
etc.
Note:
1, Please use Raspberry Pi OS with Desktop
2, The installation of libraries takes much time. You can power Raspberry Pi with a power supply Cable.
3, If you are using remote desktop to login Raspberry Pi, you need to use VNC viewer.
Vedio: [Link]
To download the code, you can power Raspberry Pi with a power supply cable or switch on S1 (Power Switch).
Then open the Raspberry Pi and the terminal. You can open the terminal by clicking as shown below, or you
can press “CTRL + ALT + T” on the desktop.
Terminal
Open the terminal and type the following commands to obtain the car code. And the code will be placed in
the directory "Pi". (Note: Here are two commands. Please execute them in order.)
cd ~
git clone --depth 1 [Link]
We have wrriten a Python script for you to install all dependency libraries automatically.
1. Change the root.
sudo chmod 755 -R ~/Freenove_Tank_Robot_Kit_for_Raspberry_Pi
2. Execute following commands to enter directory of “[Link]”.
cd ~/Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code
3. Run [Link]
sudo python [Link]
If it is your first time to run the script, it will ask you to input the camera type. At this point, input the content
according to the camera you have. (The one included in this kit is of the type ov5647).
OV5670 Imx219
If your Rpi is a Pi 5, it will ask you which camera interface to use. You can type in cam0 or cam1 based on the
interface you want to use.
Note: Make sure you connect the camera cable to the corresponding interface.
If it is not Raspberry Pi, this setting is not needed, as there is only camera interface available.
Cam1 Cam0
The reboot of the pi takes some time, please wait with patience.
If the installation fails, please rerun [Link]. After the installation is completed, restart the Raspberry Pi. Most
installation failures are caused by network reasons.
sudo python [Link]
Vedio: [Link]
If you have any concerns, please feel free to contact us via support@[Link]
Step 1 Install line tracking sensor.
Secure the line tracking sensor to the acrylic using two M3X12 screws and two M3 nuts.
M3X12 screw
M3 nut
Step 2
Attach four acrylic support frames to the acrylic using four M3X12 screws and four M3 nuts. Note the
position of the round holes in the acrylic support frame.
M3 nut
round holes
M3X12 screw
Step 3
Using a Half Tooth Screw M4*50 and an M4 nut, assemble the drive wheel as shown below.
M4 nut
M4 nut M4 nut
Step 5
There is a special fixed bracket to fix motor, which contains an aluminum bracket, two M3*30 screws, two
M3*8 screws, and two M3 nuts, as shown below:
Use 2 M3x30 screws and 2 M3 nuts.
Do NOT remove the cable tie on the motor!
Coupling with
bore 6mm
M3*8
Step 7
Attach the track driver to the motor using an M3x8 screw. (Use the screw in the M3x8 screw bag.))
M3*8
Step 8
Put the track on as shown in the picture below.
Use two M3x8 screws from the motor bracket bag at the bottom to hold the motor in place.
M3*8 in
motor bracket
bag
Step 9 With the same steps, install the motor and track on the other side.
Step 10
Attach the camera and ultrasound to the acrylic using eight M1.4x5 screws.
M1.4*5
M1.4*5
If they cannot be installed, please flip the acrylic board. The hole sizes are different on two sides.
Step 11
Mount the camera and ultrasound onto the acrylic using one M3x12 screw and one M3 nut.
M3*12
Step 12
Use four M3x8 screws to fix four M3x24 standoff onto the acrylic.
Standoff M3*24
M3*8
Step 13
Use 4 M3x10 screws and 4 M3 nuts to secure the battery case to another piece of acrylic.
M3*10
M3 Nut
Step 14
Attach 4 M2.5x6+6 screws to the other side of the acrylic using 4 M2.5x7 screws.
M2.5*6+6
M2.5*7
Step 15
Using 2 M3x12 screws and 2 M3 nuts, secure the two acrylic connectors to the acrylic sheet. Please note
that the shape of the acrylic is not the same, and their position is fixed.
M3*12
M3*12
Step 16
Attach an M4x10 Rivet to the acrylic as shown in the image below.
Rivet
M4*10
Step 17
Using 2 M2x20 screws and 2 M2 nuts, attach the Opaque Black Servo and 2 acrylics to the bottom acrylic.
Servo shaft is below.
M2*20
Step 18
Install Raspberry PI.
Step 19
Install 4 M2.5x11 standoff onto the Raspberry PI.
Standoff
M2.5*11
√ ×
√ ×
Attention for Pi 5 users: As we have set the camera interface when installing the libraries in the
previous chapter, please connect the camera to the corresponding interface.
Cam1 Cam0
If you want to change the interface, please repeat the library installation steps to set another interface.
Pay attention to the Blue bar of cable.
Step 21 Install the upper and lower acrylic sheets together using four M3x8 screws.
Note: The images of the car board may look different from the one you receive (V1.0 or V2.0). By the way,
the interface design of the two version is the same, so the operation on them are the same. You can just
follow this book to use it.
Tank Smart Car Board V1.0 Tank Smart Car Board V2.0
Tank Smart Car Board V1.0 Tank Smart Car Board V2.0
Servo 1
Port 8
Servo 0
Port 7
Servo 1
Port 13
Servo 0
Port 12
assembling the servos, please perform the following steps to adjust the servos to appropriate angles;
otherwise it will affect the final effect.
1. Run the following command to enter the directory
Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Server
cd ~/Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Server/
Result:
The two servos will spin to the designated angles. If the servos are already at that position, nothing will be
observed upon running the code.
Keep the program running during the servo assembly process to avoid assembly offset.
Step 26
Install using the screws in the Servo package as shown below.
Screw in servo
package
Rivet
M4*10
Rivet
M4*10
Step 28
Using 2 M3x12 screws and 2 M3 nuts, install the acrylic as shown below.
M3 Nut
M3*12
M3 Nut
M3*12
M4*10
Rivet
Step 30 Install the structure of the previous step on the trolley. Note the direction of the structure.
Step 31
Install the clear black steering gear to the trolley using 2 M2x20 screws and 2 M2 nuts.
Notice that the Servo axis of rotation is on the left.
Step 32 Using 2 M2x20 screws and 2 M2 nuts, secure the three acrylics together. At the same time, install
using the steering wheel and screws in the Servo package as shown below.
Screw in servo
package M2*20
M2 Nut
Step 33
Install using the screws in the Servo package as shown below.
You can press “Ctrl+C” to end the [Link] program after finishing servo assembly.
Step 34 Use two M3x8 screws to fix two M3x10 standoff into the acrylic.
M3*8 M3*8
Standoff Standoff
M3*10 M3*10
Step 35 Using 2 M2x20 screws and 2 M2 nuts, secure the three acrylics together.
M2*20
M2*20
M2 Nut M2 Nut
Rivet
M4*10
Step 37
Use one M3x8 screw to install the structure of the previous step to the trolley, as shown below.
M3*8
S2:
S1:
Motor and servo
Main power switch
power switch
During the test, the motor will work. So you can disconnect the wheels or put it on the ground to avoid that
it falls down and is damaged. Next, test RGB LED, motor, ultrasonic module, servo, etc.
Button S1 is the Raspberry PI power supply switch. When you only press S1, you can perform other tests
except motor and servo.
Button S2 is the motor and servo power switch. When you press S1 and S2, you can test the motor and servo.
You can still power Raspberry Pi with a power supply Cable when switches are pressed.
If you have never learned python before, you can learn some basic knowledge via the link below:
[Link]
Motor
Run program
Before running the program, please make sure all needed libraries are installed; otherwise, the program will
fail to run.
Open the terminal of Raspberry Pi. Enter the following commands to test the motor.
1. Use the cd command to enter the directory where [Link] is located.
cd ~/Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Server
2. Execute [Link] command:
sudo python [Link] Motor
Result:
The car moves forward for 1 seconds, then moves back for 1 seconds, then turns left for 1 seconds, turns right
for 1 seconds, then stops. You can press "Ctrl + C" to end the program ahead of time. If the car doesn’t
work normally, please check if both switches are pressed.
If the direction is reversed, it moves back then move forward, please exchange wiring of the two motors.
Reference
setMotorModel(data1,data2)
This function has two input parameters, which control the left motor and the right motor respectively. When
the input parameter is in the range of 0~4095, the motor rotates forward. In the range of -4095~0, the
motor rotates in reverse. The larger the absolute value, the faster the motor. When the input is 0, the motor
will stop. If the function input is as follows: setMotorModel(2000,2000), the two motors will rotate forward
and the car will move forward.
Run program
Enter the following command in the terminal to test line tracking module.
If the terminal displays the directory as below (where [Link] is located), you can directly execute the [Link]
command.
Result:
When the black tape is at the left of the sensor, it will print “Left” on the terminal; when it is at the middle,
print “Middle”; and at the right, print “Right”. You can press “CTRL+C” to end the program.
LED
There are 4 RGB LEDs on the smart car board, as shownbelow. You can control them separately.
LED1 LED0
LED2 LED3
Run program
Enter the following commands to test LEDs.
If the terminal displays the directory as below (where [Link] is located), you can directly execute the [Link]
command.
Note: On the board V1.0, the WS821x LEDs are connected to GPIO 18, which can be used on Raspberry Pi
series 1-4, but not on Rpi 5.
On version 2.0, we connect them to GPIO10, which applies SPI interface, so it is compatible with Raspberry Pi
series 1-5.
Tank Smart Car Board V1.0 Tank Smart Car Board V2.0
At the first time you run the code, the system will check your hardware version. Please enter the version
according to the board you receive. You can refer to the images above to check the version.
After you input the version (here we take verion 2 as an example), the LED test program will be run. If the
LEDs do not respond, please check whether you type in a wrong version.
Result:
When the program is running, the LEDs will blink with different modes and colors. The order of the modes
is: ledIndex->colorWipe->theaterChaseRainbow->rainbow->rainbowCycle
You can press CTRL+C to end the program.
Note, the PCB version must be correctly input, which depends whether the code can run successfully. If you
input a correct version, please follow the steps below to configure it again.
1. Enter the directory /Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Server/, and run the
[Link] under Server folder.
cd ~/Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Server/
sudo python [Link]
2. Input the number according to the board version.
Servo
Run program
Enter the following commands in the terminal to test servos.
If the terminal displays the directory as below (where [Link] is located), you can directly execute the [Link]
command.
If your Raspberry pie is not Pi5 and your PCB version is V1.0, run the following command before running the
[Link].
sudo pigpiod
If you want to end the pigpio process, run the following command.
sudo killall pigpiod
The servo will repeat the following: servo 0 is closed gradually, servo 1 from top to bottom, and then from
bottom to top, servo 0 is opened gradually. You can press Ctrl + C to end the program.
When testing servo steering gear, you need to observe whether servo 0 is closed to the minimum, whether
servo 1 hits the ground during the descent,
When servo 0 is just closed to the minimum and servo 1 drops close to the ground without touching the
ground, it means that your servo 0 and servo 1 are properly installed.
When other conditions occur, please check that the installation steps of the relevant servo are correct.
For details, see Step 24 in Chapter 2.
Reference
setServoAngle(Servo,angle)
There are 2 parameters.
The first one is related to servo index.
The second one is related to the angle of servos.
For example,
setServoAngle (‘0’,90) makes servo0 rotate to 90°.
setServoAngle (‘1’,90) makes servo1 rotate to 90°.
Ultrasonic module
Next, use jumper wires F/F to connect ultrasonic module with pins on smart car board.
When connecting the ultrasonic module, you should keep the silk screen of the ultrasonic module and the
smart car board consistent. Vcc should be connected to 5V, Trig to TRIG, Echo to ECHO, and Gnd to GND.
If the connection is wrong, for example, if Vcc is connected to GND, and Gnd is connected to 5V, it will
cause the damage to ultrasonic module. After the wiring is completed, you can start testing.
Run program
Enter following command in the terminal:
If the terminal displays the directory as below (where [Link] is located). You can directly execute the [Link]
command.
Result:
Every 0.3s, the distance between the obstacle and the ultrasonic module will be printed out, and you can press
"Ctrl + C" to end the program.
Reference
get_distance()
This function is used to obtain the distance between ultrasonic module and obstacles in front of it, with unit
CM.
Camera
Run Program
If the terminal displays the directory as below, you can directly run the [Link].
Results:
Five seconds after the program runs, it will take a picture in jpg format and save it to the current directory.
You can run the ls command to see if it is there.
Description
The obstacle avoidance function of the vehicle mainly uses HC-SR04 ultrasonic module. The ultrasonic module
will detect the distance between obstacles and the robot in real time, and then control the tank robot to move
according to different distances.
Run program
If the terminal displays the directory as below, you can directly run the [Link].
16 [Link](1500, 1500)
17 # Sleep for a short duration
18 [Link](0.2)
Result analysis
When the tank robot detects that the distance between the obstacle and the car is less than 45cm, it will
successively retreat for a period of time and then turn left for a period of time. When the robot detects that
the distance between the obstacle and the robot is greater than or equal to 45cm, it will move forward.
Description
The circuit tracking function of the tank robot mainly uses infrared module. When the sensor detects a black
line, the corresponding LED lights up to control the tank robot's movement according to the values of the
three sensors. The tank robot detects whether there are obstacles on the road through the ultrasonic sensor
while finding the line. When there are obstacles, the tank robot starts the obstacle clearing function. After the
obstacle is cleared, the tank robot continues to find the line.
Run program
If the terminal displays the directory as below, you can directly run the program.
If your Raspberry pie is not Pi5 and your PCB version is V1.0, run the following command before running the
code.
sudo pigpiod
If you want to end the pigpio process, run the following command.
sudo killall pigpiod
5 infrared_value = [Link].read_all_infrared()
6 # print("distance:", distance, "infrared:", infrared_value)
7
8 # Control motor based on infrared sensor values
9 if infrared_value == 2:
10 [Link](1200, 1200) # Move forward
11 elif infrared_value == 4:
12 [Link](-1500, 2500) # Turn left
13 elif infrared_value == 6:
14 [Link](-2000, 4000) # Turn left more sharply
15 elif infrared_value == 1:
16 [Link](2500, -1500) # Turn right
17 elif infrared_value == 3:
18 [Link](4000, -2000) # Turn right more sharply
19 elif infrared_value == 7:
20 [Link](0, 0) # Stop
21
22 # If distance is between 5.0 and 12.0 cm, perform clamp operations
23 if distance > 5.0 and distance <= 12.0:
24 [Link](0, 0) # Stop motor
25 self.set_mode_clamp(1) # Set clamp mode to 1 (up)
26 while self.get_mode_clamp() == 1 and self.infrared_run_stop == False:
27 self.mode_clamp() # Perform clamp up operation
28 if self.infrared_run_stop == True:
29 [Link](0, 0) # Stop motor if infrared run stop is True
30 return
31 [Link](-1500, 1500) # Turn left
32 [Link](1.5)
33 [Link](0, 0) # Stop motor
34 self.set_mode_clamp(2) # Set clamp mode to 2 (down)
35 while self.get_mode_clamp() == 2 and self.infrared_run_stop == False:
36 self.mode_clamp() # Perform clamp down operation
37 if self.infrared_run_stop == True:
38 [Link](0, 0) # Stop motor if infrared run stop is True
39 return
40 [Link](1500, -1500) # Turn right
41 [Link](1.4)
Result analysis
The car has the functions of line inspection and automatic obstacle clearance. The specific realization of the
car's line inspection function is as follows:
There are three sensors on the left, center and right. When the black line is detected by the sensor, it will
display a high level, or it is low. When the sensor left: high, middle: low, right: low, the car gently turns left.
When the sensor is left: high, middle: high, right: low, the car turns left. When the sensor left: low, medium:
high, right: low, the car goes straight. When the sensor left: low, medium: low, right: high, the car gently turns
right. When the sensor is left: low, middle: high, right: high, the car turns right.
The car's automatic obstacle clearance function is as follows: under the condition of line inspection, the car
detects whether there are obstacles in front of the car in real time through the ultrasonic module. When the
car detects obstacles in front of the car, the car stops and removes the obstacles through the steering gear.
After clearing, the car continues to perform the function of line inspection.
The smart video car integrates the previous functions of obstacle avoidance, line tracking and obstacle clearing,
video transmission, ball tracking, LED and so on. It consists of a server and a client, so it can be controlled
remotely.
Start Start
Wait Connect
connection server
No
No
If success
If success
Yes
Yes
Wait
Send
command
command
No Yes
If get
command If success
Done No
Yes success
keep
Execute
sending
Command
End End
Server
Open Server
If your Raspberry pie is not Pi5 and your PCB version is V1.0, run the following command before running the
code.
sudo pigpiod
If you want to end the pigpio process, run the following command.
sudo killall pigpiod
The interface is as below:
The Server is ON when the code is run. To turn it off, you can click the “Off” button.
To exit the server, you can close the server interface or run CTRL+C on the Terminal.
If you are very interested in the implementation of the code, you can view the code:
Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Server
1 Open the terminal and execute the following two commands respectively to create a “[Link]” file.
cd ~
sudo touch [Link]
2 Open “[Link]”.
sudo nano [Link]
3 Add the following contents to “[Link]” file.
#!/bin/sh
cd "/home/pi/Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Server"
pwd
sleep 10
sudo python [Link]
Press Ctrl + O and then press Enter to save it. Press Ctrl+X to exit.
4 Modify permissions.
sudo chmod 777 [Link]
5 Enter the following command to create a directory.
mkdir ~/.config/autostart/
6 create and open “[Link]” file
sudo nano .config/autostart/[Link]
7 Add the following content to “[Link]” file.
[Desktop Entry]
Type=Application
Name=start
NoDisplay=true
Exec=/home/pi/[Link]
Press Ctrl + O and then press Enter to save it. Press Ctrl+X to exit.
8 Modify permissions.
sudo chmod +x .config/autostart/[Link]
9 Finally enter the following content to reboot Raspberry Pi.
sudo reboot
Note: To cancel auto start, please delete the files “[Link]” and “[Link]” created above.
Client
The client connects to the server through TCP, which receives the video stream and other commands from
the server. And it also sends commands to the server to control the car.
Clients can run on different systems such as windows, macOS, and Linux. You need to install related software
and libraries.
After the client opens successfully, you need open the Raspberry Pi and open server first, then enter the IP
address of the Raspberry Pi in the white IP edit box, and then click “Connect” to connect smart car to Raspberry
Pi. After the connection is successful, you can click on the controls on the interface to operate the car.
Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time.
If pressing forward but the car moves backward, please refer to page 66 to modify the code.
Choose the color of the ball in your hand, take the Red ball as an example, when you click the button "red",
into the tank robot tracking red ball control program, when your environment is poor recognition of red,
you can click "Custom", by adjusting the HSV parameters to adjust the accuracy of recognition,
This recognition program is for color recognition, can track red objects not limited to red ball.
When the car motion control is abnormal, you can click the color button again to make the car stop moving.
After the color threshold is displayed, the recognition effect can be observed and the appropriate data can
be selected according to the following HSV color range table to improve the recognition accuracy.
The HSV color range is listed below:
black gray white red orange yellow green cyan blue purple
H- 0 0 0 0 156 11 26 35 78 100 125
H+ 180 180 180 10 180 25 34 77 99 124 155
S- 0 0 0 43 43 43 43 43 43 43
S+ 255 43 30 255 255 255 255 255 255 255
V- 0 46 221 46 46 46 46 46 46 46
V+ 46 220 255 255 255 255 255 255 255 255
Option 2 Install python3 and some related python libraries to run the client
Install python3
Download the installation file:
[Link]
Choose and download Windows x86 executable installer. After downloading successfully, install it.
Select “Add Python 3.8 to PATH”. You can choose other installation features.
Here, my install location is D. You can also choose other location. Then click “Install”.
Wait installing.
You can also place it into other disks (like E), but the path in the following command should be modified
accordingly (replace D: by E:).
Press “win + R” and enter cmd, and click ok. Then enter following commands.
1. Enter D disk. (If you put it into E, it should be E:)
D:
2. Enter directory where setup_windows.py is located: (If you put it into E, it should be E:)
cd D:\Freenove_Tank_Robot_Kit_for_Raspberry_Pi\Code
3. Run setup_windows.py:
python3 setup_windows.py
If not all installations are successful, it will prompt "Some libraries have not been installed yet. Please run '
Python3 setup_windows.py ' again", then you need to execute the Python3 setup_windows.py command again.
Most of the installation failures are caused by poor networks. You can check your network before installing.
Open client
Press “win + R” and enter cmd, and click ok. Then enter following commands.
1. Enter D disk. If you put it into E, it should be E:
D:
2. Enter directory where [Link] is located:
cd D:\Freenove_Tank_Robot_Kit_for_Raspberry_Pi\Code\Client
3. Run [Link]:
python [Link]
After the client opens successfully, you need open the Raspberry Pi and open server first, then enter the IP
address of the Raspberry Pi in the white IP edit box, and then click “Connect” to connect smart car to Raspberry
Pi. After the connection is successful, you can click on the controls on the interface to operate the car.
Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time.
If pressing forward but the car moves backward, please refer to page 63 to modify the code.
Control
And you can also control the car with following blue keys.
When you enter the IP address for the first time, the program saves the IP address. When you close the
program and open the program again, the program automatically fills in the last IP address. The IP address
is saved in the “[Link]” file.
When you run the program for the first time, the contents of the "[Link]" file are: "IP address", then the program
page is opened as follows:
After you enter the address, for example, [Link], close the program and open the program page
again as follows:
Here take MacOS 10.13 as an example. To run the client on MacOS, you need to install some software and
libraries. At this time, it does not need to run the server or use the Raspberry Pi. So you can turn off the
Raspberry Pi first. After the installation is complete, turn on the Raspberry Pi and run the server. MacOS 10.13
comes with python2, but no python3. However, the programs in this project need run under python3, so you
need to install it first.
Install python3
Download installation package, link: [Link]
If your macOS is NOT 11, like 10.15, please install python 3.8. If you have
At bottom of the page, click macOS 64-bit installer and download installation package.
Click Continue.
Click Continue
Click Agree.
Click Install. If your computer has a password, enter the password and Install Software.
Installation will take some time. Just wait patiently. For successful installation, it will prompt "All libraries
installed successfully":
If not all installations are successful, it will prompt "Some libraries have not been installed yet. Please run
'python3 setup_macos.py' again", then you need to execute the python3 setup_macos.py command again.
Most of the installation failures are caused by poor networks. You can check your network before installing.
If you are using macOS under 11.0, like 10.15. Just skip to “Open client”.
If you are using macOS 11.0 or later version. Please run commands below:
pip3 uninstall PyQt5
pip3 install PyQt5
Open client
Following the previous step, after the installation is completed, you are now in the directory where
setup_macos.py is located.
The control way of Raspberry Pi macOS System client is same with Windows (Control).
Run client
Enter the following commands at the terminal.
1. Use the cd command to go to the directory where [Link] is located.
cd ~/Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Client
2. Run [Link]:
sudo python [Link]
Trouble shooting
If the car works abnormally, it may be caused by following reasons: raspberry pi system is stuck or
batteries have no power.
You need check batteries power indicator or recharge batteries.
If the batteries are OK, raspberry pi system is stuck. You need wait some time to check if the client works. Or
reopen the server and client.
The latest Raspberry Pi official system is not stable. It occasionally is stuck. The old version is more stable.
If the raspberry pi system is stuck for a long time, you need reboot raspberry pi.
If you have any concerns, please feel free to contact us with pictures:
support@[Link]
You can download and install the Freenove Android app from below:
On Google play:
[Link]
On GitHub:
[Link]
In this github repository, you can find the App instruction ([Link]).
You can download and install the Freenove iPhone ios app by searching freenove in app store.
Open the server in Raspberry Pi car first. And enter your Pi IP.
Set
Pinch object
Free innovation
If you have any concerns, please feel free to contact us via support@[Link]
If you want to write your own program to control the car, just follow this section. We will teach you how to
program this car.
If you have never learned python before, you can learn some basic knowledge via the link below:
[Link]
First, turned on S1 and S2. Then open Raspberry Pi, right click and create a new folder on the desktop: Test
Click Save and save it into the Test folder, with name: test_Code.
Note: the code and library are written by Python 3. You need execute the code with python 3.
Open the terminal and use the following command to enter the directory where test_Code.py is located:
cd ~/Desktop/Test
Run test_Code.py:
sudo python test_Code.py
Code example
Following are code example for the parts. For more detail, please refer to Module test section.
For more details, please refer to Motor.
1 from Motor import * #import Motor
2 PWM=Motor() #create an object
3 [Link](2000,2000) #Forward
4 print(”The car is moving forward”)
5 [Link](3) #waiting 3 second
[Link](0,0) #Stop
These codes can be integrated into one code to achieve your requirement.
What's next?
Thanks for your reading.
This book is all over here. If you find any mistakes, missions or you have other ideas and questions about
contents of this book or the kit and ect., please feel free to contact us, and we will check and correct it as soon
as possible.
After completing the contents in this book, you can try to reform this smart car, such as purchasing and
installing other Freenove electronic modules, or improving the code to achieve different functions. We will
also try our best to add more new functions and update the code on our github ([Link]
If you want to learn more about Arduino, Raspberry Pi, smart cars, robots and orther interesting products in
science and technology, please continue to focus on our website. We will continue to launch cost-effective,
innovative and exciting products.
[Link]