Tutorial
Tutorial
com List 1
Welcome
Thank you for choosing Freenove products!
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
Contents
Welcome....................................................................................................................................................................................... 1
List .................................................................................................................................................................................................. 2
Robot Shield for Raspberry Pi ........................................................................................................................................ 2
Machinery Parts ................................................................................................................................................................. 3
Transmission Parts............................................................................................................................................................. 4
Acrylic Parts......................................................................................................................................................................... 4
Electronic Parts and Tools ............................................................................................................................................... 5
Required but NOT Contained Parts .............................................................................................................................. 7
Preface .......................................................................................................................................................................................... 8
Raspberry Pi Introduction ................................................................................................................................................ 9
Chapter 0 Raspberry Pi Preparation ................................................................................................................................... 19
Install a System................................................................................................................................................................ 19
Getting Started with Raspberry Pi .............................................................................................................................. 29
Robot Shield for Raspberry Pi ..................................................................................................................................... 39
Chapter 1 Install Python Libraries (Required) ................................................................................................................... 41
Step 1 Obtain the Code and Set python3 as default ............................................................................................ 41
Step 2 Configuration ..................................................................................................................................................... 44
Step 3 Run the Installation Program .......................................................................................................................... 47
Chapter 2 Assemble Robot ................................................................................................................................................... 48
Step 1 Install Disk Servo Arms ..................................................................................................................................... 48
Step 2 Install Body Bracket ........................................................................................................................................... 51
Step 3 Install Shield ........................................................................................................................................................ 52
Step 4 Install MPU6050 ................................................................................................................................................. 53
Step 5 Install LED module ............................................................................................................................................ 53
Step 6 Install Raspberry Pi ............................................................................................................................................ 55
Step 7 Install Connector................................................................................................................................................ 56
Step 8 Install Servo to Acrylic Board .......................................................................................................................... 58
Step 9 Run Servo Program (Necessary) .................................................................................................................... 61
Step 10 Assemble Legs to Body ................................................................................................................................. 64
Step 11 Assemble Head................................................................................................................................................ 68
Step 12 Assemble Head to Body ................................................................................................................................ 69
Step 13 Wiring................................................................................................................................................................. 70
Step 14 Install Calibration Support ............................................................................................................................ 74
Step 15 Verify Assembly ............................................................................................................................................... 75
Chapter 3 Module test (Required) ...................................................................................................................................... 76
Chapter 4 Robot Dog ............................................................................................................................................................. 88
Server................................................................................................................................................................................. 89
Client.................................................................................................................................................................................. 96
Free your innovation.................................................................................................................................................... 120
Android and iOS app................................................................................................................................................... 126
What's Next?........................................................................................................................................................................... 128
List
If you have any concerns, please feel free to contact us at support@[Link]
Top
Bottom
Machinery Parts
Note: You may receive M1.4*4 or M1.4*5. Both are suitable. If a package of M1.2*7 self-tapping
screws cannot be found, it may be packed in the servo package.
Transmission Parts
Acrylic Parts
Please note: There are two models of connection boards, remember their version numbers.
LED module Camera HC-SR04 ultrasonic module
Connection board (PCB_V1.0) Connection board (PCB_V2.0) Not yet available for
sale
Note:
The PCB Version 2 is not on sale yet. They are current at our warehouse. The only distinction between
Version 1 and Version 2 of the adapter board lies in the modification of the LED control pin.
Version 1 employs GPIO18, whereas Version 2 has switched to GPIO10.
Due to significant changes in the Raspberry Pi 5, the library rpi-ws281x-python is unable to function
properly. This library was designed to work with GPIO18, and the lack of detailed documentation on the
RP1 chip from the Raspberry Pi authorities has hindered the resolution of this issue.
Consequently, we have introduced an alternative approach, utilizing the SPI MOSI pin for communication
with the LED lights. Although this restored the functionality of the LEDs, it also meant that SPI-related
pins (SCK, MISO) could not be used for other purposes. This serves as an interim measure, and once the
rpi-ws281x-python library resumes normal functionality on pi 5, Version 2 is expected to be phased out.
If you want to achieve the function of V2, you can connect GPIO10 to GPIO18 with a jumper wire, as
shown below.
Please note that this cable only come with the purchase of the Raspberry Pi 5 version.
Cross screwdriver (3mm) x1 Cable tidy x80cm Red ball
Cross screwdriver (2mm) x1
Preface
Welcome to use Freenove Robot Dog Kit for Raspberry Pi. Following this tutorial, you can make a very cool
robot dog 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. This kit contains all electronic components, modules,
and mechanical components required for making the robot dog. And all of them are packaged individually.
There are detailed instructions for assembly and configuration in this book.
If you encounter any problems, please feel free to contact us for quick and free technical support.
support@[Link]
This book can help enthusiasts with little technical knowledge to make a robot dog. 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, the text 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.
Actual image of Raspberry Pi 3 Model B+: CAD image of Raspberry Pi 3 Model B+:
Actual image of Raspberry Pi 1 Model B+: CAD image of Raspberry Pi 1 Model B+:
Actual image of Raspberry Pi 3 Model A+: CAD image of Raspberry Pi 3 Model A+:
Actual 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 how you can utilize them in all sorts of ways in your projects. Most RPi Module pins can be used as either
an input or output, depending on your program and its functions. When programming the GPIO pins, there
are 3 different ways to reference them: GPIO numbering, physical numbering, WiringPi GPIO Numbering.
For more details about pin definition of GPIO, please refer to [Link]
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:
Different from the previous two types of GPIO serial numbers, RPi GPIO serial number of the WiringPi are
numbered according to the BCM chip use in RPi.
You can also use the following command to view their correlation.
gpio readall
Install a System
Component List
Required Components
Raspberry Pi 5 / 4B / 3B+ (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 a stand-alone monitor. 2)
Using a remote desktop or laptop computer monitor “sharing” the PC monitor with your RPi.
Required Accessories for Monitor
If you choose to use an independent monitor, mouse and keyboard, you also need the following accessories:
1. A display with a HDMI interface
2. A Mouse and a Keyboard with an USB interface
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
Without Screen - Use Raspberry Pi - under Windows PC: [Link]
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]
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
Set Resolution
You can also set other resolutions.
If you don't know what resolution to set properly, you can try 1920x1080.
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 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.
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,
Shield Introduction
The shield is connected to the Raspberry Pi through the IO Port on the board. The positioning holes on the
board are suitable for the Raspberry Pi. The features and functions are as follows.
S1(LOAD)
D2 indicator
D1 indicator
LED port
IO port
MPU6050 port
Buzzer
Sonar port
Servo port
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
Type following command to get robot dog code and place it in user directory "Pi".
Please execute commands below one by one in turn.
cd ~
git clone --depth 1
[Link]
If you want to set python2 as default python in other projects, just repeat the commands above and change
python3 to python2.
Shortcut Key
Now, we will introduce several shortcuts that are very useful and commonly used in terminal.
1. up and down arrow keys. History commands can be quickly brought back by using up and down arrow
keys, which are very useful when you need to reuse certain commands.
When you need to type command, pressing “↑” (the Up key) will go backwards through the command
history and pressing “↓” (the Down Key) will go forwards through the command history.
2. Tab key. The Tab key can automatically complete the command/path you want to type. When there are
multiple commands/paths conforming to the already typed letters, pressing Tab key once won’t have any
result. And pressing Tab key again will list all the eligible options. However, when there is only one eligible
option, the command/path will be completely typed as soon as you press the Tab key..
As shown below, under the ‘~’directory, enter the Documents directory with the “cd” command. After typing
“cd D”, press Tab key, there is no response. Press Tab key again, all the files/folders that begin with “D” is
listed. Continue to type the character "oc", then press the Tab key, and then “Documents” is typed
automatically.
Step 2 Configuration
Click
Click
Note that if your connector version is V2.0, remember to turn on the SPI feature. If your connector version is
V1.0, turn off the SPI feature.
Press "CTRL"+"O" and then "Enter" to save the modified content. Then press "CTRL"+"X" to exit editing.
After the modification is completed, reboot Raspberry Pi to make the change work. You can also reboot the
Raspberry Pi after completing the step 3 below.
Type a command to check whether the I2C module is enabled:
lsmod | grep i2c
If I2C module has been enabled, the following content will show up (the numbers showing in your device may
be different):
Install I2C-Tools
Type the command to install I2C-Tools.
sudo apt-get install i2c-tools
Install python-smbus
Python-smbus is a module of the program Python, which contains some classes and methods to operate I2C.
Type the following command to install python-smbus:
sudo apt-get install python3-smbus
Additional supplement
Raspbery Pi, other than 5, 4B and 400, needs to disable the audio module, othewise the LED will not work
properly.
1. Create a new [Link] and open it for editing
sudo nano /etc/modprobe.d/[Link]
Add following content: After adding the contents, you need to press Ctrl+O, Enter, Ctrl+Z.
blacklist snd_bcm2835
It will take effect after restarting, and you can restart after executing the next section.
If you want to restart the audio module, just restore the content modified in the above two steps.
This program will automatically install the pca9685, rpi_ws281x, PyQt5 library, etc. Please reboot the Raspberry
Pi after the installation is completed, as shown below.
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]
It is recommended to assemble and use the robot dog according to the tutorial. Otherwise, there may be
installation errors, device damage, etc.
M1.2*7screws
Disk servo arm
There are 4 pairs of opposite holes on the disk servo arm, and the distance between each pair is different.
Need support? support@[Link]
█ [Link] Chapter 2 Assemble Robot 49
M1.2x7
M1.2*7 screws are contained in following plastic bag. If a package of M1.2*7 self-tapping screws cannot
be found, it may be packed in the servo package.
This side is
Longer distance attached to
acrylic board.
M1.2x7
M1.2x7
Rectangular hole
Head mark
M3 Nut
M3x12
Brass standoffs
M2.5x14+6
M2.5x8
Shield
Brass standoffs
M2.5x14
Note: There are two rows of headers. Plug the MPU6050 into the outer Row.
MPU6050
M3x12
LED module
M3 Nut
Head
Rear
Use tapes
to cover
the hole
Use tapes
to cover
the hole
Attach the Raspberry PI to the robot dog with four M2.5x8 screws.
M2.5x8
Raspberry Pi
Connector
We have two types of connection boards, but they are installed in the same way.
See here for more information.
Connection board (PCB_V1.0) Connection board (PCB_V2.0)
Not yet available for sale
Press connector to
reach its end.
√ ×
If you have any concerns, please feel free to contact us via support@[Link]
We will offer you satisfying solution.
Now we have assembled the main body part. We will assemble leg parts later.
M2 Nut
Black servo
M2 Nut
M2x14
M2 Nut
M3x12
M3 Nut
Assemble another two parts. Note: they are different from parts above.
Assemble another two parts. Note: they are different from parts above.
Asseble them.
M3x12
M3 Nut
Now you will get four parts as below. Note, they are different.
Connect All 12 black servos and 1 blue servo to servo port Randomly. And install batteries. Push batteries
to “+” ends.
Install batteries
3.7v 18650
High drain
12 black servos
1 blue servo wiring
You can still use cable to power Raspberry Pi with switches ON. If you disconnect cable, the batteries will
power Raspberry Pi. Press S1 and S2 and there will be two indicators ON.
S2
S1
Turn on the Raspberry Pi. Make sure all three steps in Chapter 1 have been performed correctly. If you
haven’t done that, please perform the steps in Chapter 1 first.
a. Type the following command to enter servo code folder “Server”.
cd ~/Freenove_Robot_Dog_Kit_for_Raspberry_Pi/Code/Server
b. Run [Link]
sudo python [Link]
After running the program, all servos will keep at 90°.
Next we will connect the servos to disk arm.
Keep the power on and all servos connected during the assembly. Don’t disconnect servos.
[Link]
When running the code, if it reports “Remote I/O error”, please check the following three aspects:
1. Whether the connector is connected well
Connector
S2
S1
3. Whether the batteries are contacted well with the battery holder
Keep the power ON and all servos connected to shield. Do NOT disconnect wiring. We need to keep the
servo at 90° when connected to them to servo arms. (servo wires are not shown in the following content.)
Try to install them close to 90°. The angles are acceptable within 65~115.
Assemble legs of one side. Try to install them at 90°. The angles are acceptable within 65~115.
Small screw in
servo package
Close to 90°
Keep the power ON and all servos connected to shield. Do NOT disconnect wiring.
Select two legs of different sides as rear legs. And install them as below. Then install the servo screws.
Servo screw
In this step, if you did not cover tape to the holes before, you can turn off Load S1 to install the screw. After
the screw is installed, turn on the Load S1.
M3x12
Bracket
M3 Nut
Keep the power ON and all servos connected to shield. Do NOT disconnect wiring.
Assemble front legs and install the servo screw.
Servo screw
Assemble them.
In this step, if you did not cover tape to the holes before, you can turn off Load S1 to install the screw. After
the screw is installed, turn on the Load S1.
M3 Nut
M3x12
M3 Nut
M3x12
M1.4x4
Ultrasonic module
Camera
The servo arm and screws are included in the blue servo package.
Servo arm
M2x14
M2 Nut
M2x14
M2 Nut
Keep the power ON and servos connected when installing arm to servo.
Small screw in
servo package
We will complete wiring in next section. Shut down the Raspberry Pi first. Do NOT turn on Raspberry Pi
until chapter 3.
Step 13 Wiring
Connect servos according to the numbers. Note servo ports 0, 1, 14 are not connected to servo. They
are spare.
Wiring of Ultrasonic module (Note: Do NOT connect wrongly. If you connect 5V to GND, it may
damage the ultrasonic module)
√ ×
√ ×
Camera for Pi5
Please note that this cable is only available with the purchase of the Raspberry PI 5 version.
Connect one end of cable to Raspberry Pi. Please note the front and back of the cable.
√ ×
Connect another end of cable to Raspberry Pi. Please note the front and back of the cable.
√ ×
M3x12
M3x12
M3 Nut
Support
Servo screw
If it does not look like this, you need to disassemble servo screws of incorrect servos. Then reassemble
the incorrect servo to make the robot look like posture above.
The robot dog has been assembled in the previous chapter. This chapter will test each module of the robot
dog. It is a necessary check for later control.
Before starting, please install the battery for the robot dog and turn on the S1 and S2 switches. Place the
robot dog with the calibration supports on a horizontal table to ensure that the wiring of each servo is correct.
Please use VNC Viewer to build this robot when you use remote mode to login RPi, or there will be
errors. Because other desktop remote doesn’t support GUI.
Servo
Execute following command to check i2c address.
i2cdetect -y 1
As shown in the figure below, the addresses 0x40, 0X48, and 0X68 corresponds to the PCA9685 chip, ADS7830
chip, and MPU6050 module, respectively.
Run program
Enter 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.
Result:
After assembly in the previous chapter, the robot should look as shown in picture A.
After servo test program is executed, the robot’s posture will change to A, B, C, D gradually, which indicates
the servo channel works normally.
If the situation is not correct, check the servo wiring.
(A) (B)
(C) (D)
Reference
setServoAngle(channel, angle)
This function has two parameters to control the Servo of the corresponding channel to the corresponding
angle.
The first parameter indicates the servo channel
The second parameter is the rotation angle
Example:
setServoAngle (0,60) The Servo of channel 0 is turned to 60 degrees
setServoAngle (15,160) The Servo of channel 15 is turned to 160 degrees
ADC Module
Run program
Enter following commands to test ADC module.
If the terminal displays the directory as below (where [Link] is located). You can directly execute the second
command [Link].
Result:
Print voltage value of batteries per second. You can press "Ctrl + C" to end the program.
Reference
readAdc (channel)
This function has one parameter for reading the ADC value of the corresponding channel.
For example:
readAdc (0)
Read the ADC value of the batteries voltage. The returned number ranges between 0-255. Divide the
obtained value by 255.0 and then multiply by the reference voltage of 5.0V, and then triple the value to
get the batteries voltage.
Ultrasonic module
Run program
If the terminal displays the directory as below (where [Link] is located). You can directly execute the [Link]
command.
Result:
Every 1s, the distance between the obstacle and the ultrasonic module will be printed in, and you can press
"Ctrl + C" to end the program.
The code is as below:
1 from Ultrasonic import *
2 ultrasonic=Ultrasonic()
3 def test_Ultrasonic():
4 try:
5 while True:
6 data=[Link]() #Get the value
7 print ("Obstacle distance is "+str(data)+"CM")
8 [Link](1)
9 except KeyboardInterrupt:
10 print ("\nEnd of program")
Reference
getDistance()
This function is used to obtain the distance between ultrasonic module and the obstacle in front of it in
centimeters.
LED
There is an RGB LED module on the robot as below:
Run program
Enter the following commands to test LED.
If the terminal displays the directory as below (where [Link] is located). You can directly execute the [Link]
command.
If your connection board version is V2.0 and you do not have the SPI feature turned on, the LedPixel will not
show the color. Refer here to turn on the SPI.
Result:
The LED module will show red, green, blue and white in turn. Then all LED are turned OFF.
You can end the program ahead of time by pressing "ctrl+c".
The code of [Link] is as below:
1 from Led import *
2 led=Led()
3 def test_Led():
4 try:
5 #Red wipe
6 [Link]([255, 0, 0])
7 [Link](1)
8 print ("\nRed wipe")
9
10 #Green wipe
11 [Link]([0, 255, 0])
12 [Link](1)
13 print ("\nGreen wipe")
14
15 #Blue wipe
16 [Link]([0, 0, 255])
17 [Link](1)
18 print ("\nBlue wipe")
19
20 #White wipe
21 [Link]([255, 255, 255])
22 [Link](1)
23 print ("\nWhite wipe")
24
25 [Link]([0, 0, 0]) #turn off the light
26 print ("\nEnd of program")
27 except KeyboardInterrupt:
Buzzer
Run the program
Result:
The buzzer will be turned ON lasting for 3s. Then the program will automatically end or you can press "Ctrl +
C" to end the program.
Reference
[Link](cmd)
This function has one input parameter. If the input is ’1’, the buzzer will be turned on. If the input is ‘0’, the
buzzer will be turned off.
Camera
There are two ways to drive the camera.
First method, use the system's default camera detection function.
1. Open the [Link] file.
sudo nano /boot/firmware/[Link]
2. Enable the automatic camera detection function.
camera_auto_detect=1
Second method, manually configure the camera.
1. Disable the automatic camera detection function.
camera_auto_detect=0
2. Add the following instruction at the very bottom.
If you are a Raspberry PI 5, add the following command.
dtoverlay = ov5647,cam0
If you are not a Raspberry PI 5, add the following command.
dtoverlay = ov5647
3. Save the file and exit, then restart the Raspberry PI.
Run program
1. execute the cd command:
cd ~/Freenove_Robot_Dog_Kit_for_Raspberry_Pi/Code/Server
2. Execute command below:
python [Link]
Then please open and check the generated [Link] under
/Freenove_Robot_Dog_Kit_for_Raspberry_Pi/Code/Server.
This robot has rich functions, such as real-time video, LED, ultrasonic ranging. The server and client are
established, based on Python3 and PyQt5. They communicate via TCP/IP protocol. The robot can be
controlled remotely within a local area network (LAN).
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
The server runs on the Raspberry Pi. It sends the camera data and ultrasonic module data to the client, and
receive commands from client.
The code in the Server folder is used as an example.
Part of server code is as below:
1 def get_interface_ip(self):
2 s = [Link](socket.AF_INET, socket.SOCK_DGRAM)
3 return socket.inet_ntoa([Link]([Link](),
4 0x8915,
5 [Link]('256s',b'wlan0'[:15])
6 )[20:24])
7 def turn_on_server(self):
8 #ip adress
9 HOST=self.get_interface_ip()
10 #Port 8000 for video transmission
11 self.server_socket = [Link]()
12 self.server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1)
13 self.server_socket.bind((HOST, 8000))
14 self.server_socket.listen(1)
15
16 #Port 5000 is used for instruction sending and receiving
17 self.server_socket1 = [Link]()
18 self.server_socket1.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1)
19 self.server_socket1.bind((HOST, 5000))
20 self.server_socket1.listen(1)
21
22 print('Server address: '+HOST)
23
24 def turn_off_server(self):
25 try:
26 [Link]()
27 [Link]()
28 except :
29 print ('\n'+"No client connection")
Reference
For more code details, please open “[Link]” in Server folder to check.
get_interface_ip()
This function can get the IP address of WLAN0 of the Raspberry Pi.
turn_on_server()
This function is used to open TCP and wait for a client connection. The channel of port 5000 is mainly used
to send and receive commands between the client and server. The channel of port 8000 is used to send
video data to the client.
turn_off_server()
This function is used to close TCP.
send_data()
This function is used to send commands to the client.
reset_serve()
This function is used to close TCP and restart.
transmission_video()
This function is used to transmit video data to the client.
receive_instruction()
This function is used to receive commands from the client
Open Server
Step 1 Login Raspberry Pi via VNC viewer
Because server and client use GUI. You need use VNC viewer as remote desktop way.
Download and install VNC Viewer according to your computer system by clicking 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. And click OK.
Then on the VNC Viewer panel, double-click new connection you just created, and the following dialog box
pops up. Enter username: pi and Password: raspberry. And click OK.
WiFi
If the resolution ratio is not great or there is just a little window, you can set a proper resolution ratio via
steps below.
Select Screen Configuration. Select the appropriate resolution in the new window. Click Apply.
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.
Need support? support@[Link]
█ [Link] Chapter 4 Robot Dog 93
You will see your server address (Raspberry Pi IP), Which is the LAN IP address of your Raspberry Pi. In the
next chapter, you will need to enter this IP address to connect the Raspberry Pi client with the server.
The robot will start from this posture. We define it as Relax mode. It will also be referenced later.
If you don’t like the interface, you can also enter the commands to open the server. It is more convenient.
1. Use cd command to enter directory where [Link] is located:
cd ~/Freenove_Robot_Dog_Kit_for_Raspberry_Pi/Code/Server
2. Run [Link]:
sudo python [Link] -t -n
or Run main,py with following command:
sudo python [Link] -tn
“-t” means open TCP communication. “-n“ means don’t show interface.
Press Ctrl + O and then press Enter to save it. Press Ctrl+X to exit.
4 Modify permissions.
sudo chmod 777 [Link]
8 Modify permissions.
sudo chmod +x .config/autostart/[Link]
Note: To cancel auto start, please delete the files “[Link]” and “[Link]” created above.
Client
The client can receive video data and commands from the server, and can send commands to the server. And
it can run on different systems, such as windows, macOS and so on. However, you need to install related
software and libraries when running it.
Reference
For more code details, please open “[Link]” in Client folder to check.
turn_on_client ()
This function is used to connect client to the server.
turn_off_client ()
This function is used to disconnect from the server.
receiving_video()
This function is used to receive video data sent from the server.
is_valid_image_4_bytes ()
This function is used to check whether each frame of video data is complete.
Looking_for_the_ball ()
This function is used to find the small ball in the video image.
send_data ()
This function is used to send commands to the server.
receive_data ()
This function is used to receive commands from the server.
Option 2 Install python3 and some related python libraries to run client
If you want to modify the client, you can follow this section.
This section will be completed in your computer with windows system, not Raspberry Pi.
To run the client on a Windows system, you need to install some software and libraries, which takes some
time. During this process, it does not need to run a server and a Raspberry Pi. You can turn off the Raspberry
Pi first. After the installation is completed, turn on the Raspberry Pi and the server.
Install python3
Download the installation file via the below link:
[Link]
Here python is installed into D disk as an example (You can choose your own installation path). Click Install.
Installation is successful.
You can also place it into other disks (like E), but the path in following command should be modified
accordingly (replace D: by E:).
Press “win + R” and enter cmd, and click ok. Then enter following commands.
[Link] D disk. If you put it into E, it should be E:
D:
[Link] directory where setup_windows.py is located:
cd D:\Freenove_Robot_Dog_Kit_for_Raspberry_Pi\Code
[Link]: setup_windows.py
Python setup_windows.py
Note: If the default python in your windows system is not python3 but python2, then change all "python" in
"setup_windows.py" to "python3" and run the command "setup_windows.py" as shown below.
Python3 setup_windows.py
Installation takes some time, please be patient. If all installations are successful, it will prompt “Press any key
to continue…” and "All libraries installed successfully".
If some libraries are not installed successfully, it will prompt "Some libraries have not been installed yet. Please
run 'python setup_windows.py' again". Then you need to execute the python3 setup_windows.py command
again. Most installation failures are caused by a poor network. You can check the network before installing.
Open client
Press “win + R” and enter cmd, and click ok. Then enter following commands.
[Link] D disk. If you put it into E, it should be E:
D:
[Link] directory where [Link] is located:
cd D:\Freenove_Robot_Dog_Kit_for_Raspberry_Pi\Code\Client
[Link] [Link]:
Python [Link]
Note: If the default python in your windows system is not python3, then change the command to run
[Link] as shown below.
Python3 [Link]
After the connection is successful, you need to calibrate the robot in Calibration section. After the calibration
is completed, the robot dog can be controlled to move.
Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time.
If your macOS is NOT 11, like 10.15, please install python 3.8. If you have
On the bottom of the page, click macOS 64-bit installer to download installer.
Click Continue.
Click Continue.
Click Agree.
Click Install. If your computer has a password, enter the password and click Install Software.
Open “Terminal”.
If some libraries are not installed successfully, 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 installation failures are caused by a poor network. You can check the 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
After installation is completed in previous step, now it is in the directory that setup_macos.py is located.
Calibration
You can refer to this video: [Link]
Calibrate the robot.
1. Lay the calibration paper on a horizontal hard table.
2. Install the calibration supports on the robot dog and place it on the corresponding position on the
calibration paper.
3. Connect client with server successfully, click the "Calibration" button on the client, then a calibration
window pops up. And the robot’s legs will automatically put to the following position.
4. Calibrate the four legs to make 4 foot points fall to the corresponding positions. Feel the contact force
between the robot dog and the ground during calibration. Future control depends on this step.
5. After all the 4 points have reached the designated position, click "Save" to save. Now calibration is
completed.
NOTE:
1. It is best to have the robot dog walk on a flat hard floor. The robot dog may not walk well on other
grounds.
2. There is an offset when controlling the robot dog to walk straightly, which is normal. It is caused by
the installation error and the error of the servo itself. As a result, the left and right legs cannot be
completely symmetrical, and may differ by 1mm or 2mm. As the walking distance accumulates, this error
is constantly superimposed. Then there will be a large offset from the original position.
3. If the calibration is not good enough, it will affect walking. You can recalibrate the robot with same steps.
Control
After calibrating successfully, you can control the robot dog to move.
Relax mode.
a) When the robot dog moves for 3 minutes at a time, it will feel tired (the servo will get hot). In order to
protect the servo, the robot will get into relax mode for 1 minute. During this time, it won’t respond
to any motion command. You can still use the functions of LED, buzzer, real-time video and so on.
b) When the robot dog moves for less than3 minutes and rests for 1 minute. The timer will start from 0.
Then the robot can move for 3 minutes again.
c) If the robot isn’t tired and is standing, when the robot does not receive motion command for 10s, it will
get into relax mode. In this situation, it will respond to all commands.
You can click and drag the cross cursor in the coordinate system to adjust the yaw and pitch angle of body.
Note: Do NOT use different names when re-entering images of the same person to avoid client working
abnormally.
Note:
If the robot work abnormally, please check following contents.
1. Check the battery level. Low battery level will make the server shut down.
2. Check if the wireless connection is disconnected.
3. Check if the Raspberry Pi is stuck.
4. If all three points above work well, please restart server and client. If there still is any abnormality, please
contact us by email (support@[Link]). We will help you.
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 robot dog, you can follow this chapter.
The robot dog program is based on python3. If your python is python2 by default, please change to python3.
If you have never learned python before, you can learn some basics through the following links:
[Link]
Program
First, open Thonny Python IDE which is easy to use for beginners.
Name it with myCode as an example and save it in Server folder of robot code folder.
Open the Server folder of the robot dog code and you can see the file you created.
Write the code in [Link] as below and click save after finished, as shown below.
Type the following command to enter the directory where [Link] is located.
cd ~/Freenove_Robot_Dog_Kit_for_Raspberry_Pi/Code/Server
Run [Link]
sudo python [Link]
You can see that your robot dog moves forward for 5 steps, then twists its body at 10 degrees to the right,
then 20 degrees to the left, then returns to the original attitude and move forward 5 steps and then stops.
Related py files
Some important functions included in the py files are listed below. If you want to see more detailed code
content, please open the corresponding py file to check directly.
[Link]
Function Description
power(channel) Enter 0 to return the battery voltage value.
[Link]
Function Description
run(command) Enter 0, then the buzzer will not sound. Enter 1, the buzzer will sound.
[Link]
Function Description
coordinateToAngle(x,y,z) Enter the foot coordinate then return servo angle of each joint in one
leg.
angleToCoordinate(a,b,c) Enter the leg joint angle then return the foot coordinate.
Condition() Execute corresponding action commands
map() Mapping a value from one range to another
backWard () Move backward one step
forward() Move forward one step
turnLeft() Turn left one step
turnRight() Turn right one step
stop() Stop.
setpLeft() Move to left one step
setpRight() Move to right one step
upAndDown() Adjust height of body
beforeAndAfter() Make body move forward or backward
attitude(r,p,y) Set roll, pitch, and yaw angle of the robot.
[Link]
Function Description
imuUpdate() Update the current roll, pitch, and yaw angle of the robot.
[Link]
Function Description
ledIndex( Index, R, G, B) Turn on one LED and set color.
wheel(pos) Create different RGB values.
LED_TYPR(order,R_G_B) Change the order in which the LED color data is transmitted. When
the value of the order parameter is
"RGB", the order of data transmission should be: R-G-B; when the
value of the order parameter is "GBR",
and the order of data transmission should be: G-B-R
theaterChaseRainbow(strip, The function is used to make 7 LEDs show one color at the same time,
wait_ms) and change various colors to blink.
The blinking interval is wait_ms, and the default value is 50ms
rainbow(strip, wait_ms) This function achieves the effect of rainbow breathing. It makes 8
LEDs display same color at the same
time, and then change all various colors like breathing. The interval is
wait_ms. The default value is 20ms.
rainbowCycle(strip, wait_ms) This function also achieves the effect of rainbow breathing. but unlike
rainbow(), it makes eight LEDs to display different colors at the same
time, and then change various color separately. The interval is
wait_ms.
The default value is 20ms
[Link]
Function Description
setServoAngle(channel, angle) Turn the servo of the specified channel to specified angle.
[Link]
Function Description
getDistance() Obtain the distance between the obstacle in front and the ultrasound.
Custom Action
We have also customized some specific actions, such as push-up, greeting, etc. You can run "[Link]" to
play.
You can download and install the Freenove Android app from below links:
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 iOS app by searching freenove in app store.
Relax mode.
a) When the robot dog moves for 3 minutes in total, it will feel tired (the servo will get hot). In order to
protect the servo, the robot will get into relax mode for 1 minute. During this time, it won’t respond
to motion command. You can still use the functions of LED, buzzer, real-time video and so on.
b) When the robot dog moves for <3 minutes and then the robot rest for 1 minute. The timer will start
from 0. Then the robot can move for 3 minutes again.
c) If the robot isn’t tired and is standing, when the robot does not receive motion command for 10s, it will
get into relax mode. In this situation, it will responds to any commands.
On the top of the interface, there is a timer slider to indicate the time for moving or resting.
Raspberry Pi wlan0 IP Time slider Balance Take picture RGB Led Buzze
r
Attitude control
Connec
t
Set speed
Angle of head
Relax
Height
Control motion
Frame rate
Gravity mode
Control body
position
Need support? support@[Link]
128 What's Next? [Link] █
What's Next?
THANK YOU for participating in this learning experience!
We have reached the end of this Tutorial. If you find errors, omissions or you have suggestions and/or
questions about the Tutorial or component contents of this Kit, please feel free to contact us:
support@[Link]
We will make every effort to make changes and correct errors as soon as feasibly possible and publish a
revised version.
If you want to learn more about Arduino, Raspberry Pi, Smart Cars, Robotics and other interesting products
in science and technology, please continue to visit our website. We will continue to launch fun, cost-effective,
innovative and exciting products.
[Link]