WWT Tutorial
WWT Tutorial
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:
[email protected]
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:
http://www.freenove.com
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
📧 [email protected]
Contents
Welcome ............................................................................................................................................................................................... 1
Contents ................................................................................................................................................................................................ 1
List ........................................................................................................................................................................................................... 1
Spider Shield for Raspberry Pi .............................................................................................................................................. 1
Machinery Parts ......................................................................................................................................................................... 2
Transmission Parts .................................................................................................................................................................... 3
Acrylic Parts ................................................................................................................................................................................. 3
Electronic Parts........................................................................................................................................................................... 4
Tools .............................................................................................................................................................................................. 5
Calibration Graph ...................................................................................................................................................................... 6
Required but NOT Contained Parts .................................................................................................................................... 7
Preface ................................................................................................................................................................................................... 8
Raspberry Pi ................................................................................................................................................................................ 9
Chapter 0 Raspberry Pi Preparation .......................................................................................................................................... 19
Install a System ........................................................................................................................................................................ 19
Remote desktop & VNC ....................................................................................................................................................... 28
Spider Shield for Raspberry Pi ............................................................................................................................................ 36
Chapter 1 Installation of Python Libraries(Important) ......................................................................................................... 38
Step 1 Obtain the Code ........................................................................................................................................................ 38
Step 2 Configuration .............................................................................................................................................................. 41
Step 3 Execute the Installed Program .............................................................................................................................. 43
Chapter 2 Assembly of the Robot (Important) ....................................................................................................................... 44
Step 1 Installing Servo Base................................................................................................................................................. 44
Step 2 Installing Servos ......................................................................................................................................................... 46
Step 3 Assembling the center of the body..................................................................................................................... 49
Step 4 Installing Battery Holder ......................................................................................................................................... 54
Step 5 Assembling Legs and Head to the Body ........................................................................................................... 56
Step 6 Installing Base and Cover Plates........................................................................................................................... 66
Chapter 3 Module Test (necessary)............................................................................................................................................ 67
Chapter 4 Hexapod Robot ............................................................................................................................................................ 81
Server .......................................................................................................................................................................................... 82
Client ........................................................................................................................................................................................... 92
Free your innovation ............................................................................................................................................................116
Android and iOS app ...........................................................................................................................................................121
What's Next? ....................................................................................................................................................................................122
█ www.freenove.com List 1
List
Top
Bottom
📧 [email protected]
2 List www.freenove.com █
Machinery Parts
📧 [email protected]
█ www.freenove.com List 3
Transmission Parts
Acrylic Parts
📧 [email protected]
4 List www.freenove.com █
Electronic Parts
Battery holder x2
📧 [email protected]
█ www.freenove.com List 5
Tools
📧 [email protected]
6 List www.freenove.com █
Calibration Graph
📧 [email protected]
█ www.freenove.com List 7
Four 18650 lithium batteries without protection board. Discharge current is greater than 15A
📧 [email protected]
8 Preface www.freenove.com █
Preface
Welcome to use this robot. Following this tutorial, you can make a very cool robot 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.
The contents in this book can help enthusiasts with little technical knowledge to make a robot. If you are
very interested in Raspberry Pi, and want to learn how to program and build the circuit, please visit our
website www.freenove.com or contact us to buy the kits designed for beginners:
Freenove Basic\LCD1602\Super\Ultrasonic\RFID\Ultimate Starter Kit for Raspberry Pi
📧 [email protected]
█ www.freenove.com Preface 9
Raspberry Pi
So far, at this writing, Raspberry Pi has advanced to its fourth 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 4 Model B CAD image of Raspberry Pi 4 Model B
📧 [email protected]
10 Preface www.freenove.com █
📧 [email protected]
█ www.freenove.com Preface 11
Actual image of Raspberry Pi 1 Model B+: CAD image of Raspberry Pi 1 Model B+:
📧 [email protected]
12 Preface www.freenove.com █
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+:
📧 [email protected]
█ www.freenove.com Preface 13
📧 [email protected]
14 Preface www.freenove.com █
GPIO
Connector Ethernet
Connector
Display
Connector
USB
Power Connector x4
Connector
GPIO
Connector
USB
Connector
Display
Connector
Ethernet
Power Connector
Connector
📧 [email protected]
█ www.freenove.com Preface 15
GPIO
Connector
USB
Display Connector
Connector
Power
Connector
GPIO
Connector
Camera
Connector
📧 [email protected]
16 Preface www.freenove.com █
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.
For more details about pin definition of GPIO, please refer to http://pinout.xyz/
📧 [email protected]
█ www.freenove.com Preface 17
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:
📧 [email protected]
18 Preface www.freenove.com █
You can also use the following command to view their correspondence.
gpio readall
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 19
Install a System
Component List
Required Components
Raspberry Pi 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
https://www.amazon.com/dp/B076Q595HJ/
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
📧 [email protected]
20 Chapter 0 Raspberry Pi Preparation www.freenove.com █
In addition, RPi also needs an Ethernet network cable used to connect it to a WAN (Wide Area Network).
All these components are necessary for any of your projects to work. Among them, the power supply of at
least 5V/2.5A, because a lack of a sufficient power supply may lead to many functional issues and even
damage your RPi, we STRONGLY RECOMMEND a 5V/2.5A power supply. We also recommend using a SD
Micro Card with a capacity 16GB or more (which, functions as the RPI’s “hard drive”) and is used to store the
operating system and necessary operational files.
In future projects, the components list with a RPi will contain these required components, using only RPi as a
representative rather than presenting details.
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 21
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 computer monitor “sharing” the PC monitor with your RPi.
Required Accessories for Monitor
If you want to use an independent monitor, mouse and keyboard, you also need the following accessories.
1. A Display with HDMI interface
2. A Mouse and a Keyboard with an USB interface
For different Raspberry Pi, the optional items are slightly different. But they all aim to convert the interfaces
to Raspberry Pi standards.
Item Pi Zero Pi Zero W Pi A+ Pi 3A+ Pi B+/2B Pi 3B/3B+/4B
Monitor Yes Yes Yes Yes Yes Yes
Mouse Yes Yes Yes Yes Yes Yes
Keyboard Yes Yes Yes Yes Yes Yes
Micro-HDMI to
Yes Yes No No No No
HDMI cable
Micro-USB to USB-A
Yes Yes No No No No
OTG cable
USB HUB Yes Yes Yes Yes No No
USB transferring to select optional Internal
optional select
Ethernet interface one from Integration
one from
USB Wi-Fi receiver two or Internal Internal
two or
select Internal Integration Integration
select two optional
two from Integration
from two
two
📧 [email protected]
22 Chapter 0 Raspberry Pi Preparation www.freenove.com █
Raspberry Pi OS
Download OS file
Visit following website to download the OS file.
https://www.raspberrypi.com/software/operating-systems/
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 23
📧 [email protected]
24 Chapter 0 Raspberry Pi Preparation www.freenove.com █
Image option.
Enable SSH.
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 25
Configure WiFi and location. Here we set username as pi, password as raspberry
Finally WRITE.
📧 [email protected]
26 Chapter 0 Raspberry Pi Preparation www.freenove.com █
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 27
Start Raspberry Pi
If you don’t have a spare monitor, please skip to next section.
If you have a spare monitor, please follow the steps in this section.
After the system is written successfully, put SD card into the SD card slot of RPi. Then connect your RPi to
monitor through HDMI cable, attach your mouse and keyboard through the USB ports,
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.
You can connect WiFi on the right corner if WiFi is connected successfully.
Now you can skip to VNC Viewer.
📧 [email protected]
28 Chapter 0 Raspberry Pi Preparation www.freenove.com █
After you log in Raspberry Pi, please use VNC Viewer to connect Raspberry Pi for this robot. Other
remote ways may not support GUI. If you have logged in Raspberry Pi please skip to VNC Viewer.
If you don't have a spare monitor, 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.
Open the terminal and type following command. If this command doesn’t work, please move to next page.
ssh [email protected]
The password is raspberry by default, case sensitive.
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 29
📧 [email protected]
30 Chapter 0 Raspberry Pi Preparation www.freenove.com █
If you are using win10, you can use follow way to login Raspberry Pi without desktop.
Press Win+R. Enter cmd. Then use this command to check IP:
ping -4 raspberrypi.local
Or enter router client to inquiry IP address named “raspberrypi”. For example, I have inquired to my RPi
IP address, and it is “192.168.1.147".
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 31
Type the following command. And select Interfacing Options VNC YesOKFinish. Here Raspberry Pi
may need to be restarted, and choose ok. Then open VNC interface.
sudo raspi-config
📧 [email protected]
32 Chapter 0 Raspberry Pi Preparation www.freenove.com █
Then download and install VNC Viewer according to your computer system by clicking following link:
https://www.realvnc.com/en/connect/download/viewer/
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.
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 33
If the resolution ratio is not great or there is just a little window, you can set a proper resolution ratio via
steps below.
sudo raspi-config
Select Display OptionsVNV ResolutionProper resolution ratio (set by yourself)OKFinishYes.
And then reboot Raspberry Pi.
📧 [email protected]
34 Chapter 0 Raspberry Pi Preparation www.freenove.com █
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.
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 35
Here, you have logged in to Raspberry Pi successfully by using VNC Viewer and operated proper setting.
Raspberry Pi 4B/3B+/3B integrates a Wi-Fi adaptor. If you did not connect Pi to WiFi. You can connect it to
wirelessly control the robot.
📧 [email protected]
36 Chapter 0 Raspberry Pi Preparation www.freenove.com █
The control board is mainly connected the Raspberry Pi through the “PI-GPIO” port and the positioning
holes on the board are suitable for the Raspberry Pi. The features and functions of the control panel are as
follows.
D2 Indicator D1 Indicator
S1(CTRL)Switch
S2(LOAD)Switch
IO Port
MPU6050 Port
LED Port
DC Jack
Ultrasonic Port
Servo Port
Buzzer
📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 37
Spider Shield board: powered by two sets of batteries without protection plates, with each set containing
two 18650 batteries and voltage ranging from 7V-8.4V.
DC socket: Two DC sockets available, each connecting to one set of batteries, each containing two 18650
batteries.
S1(CTRL) Switch: It mainly controls chips like PCA9685 and ADS7830 and the power supply of the
Raspberry Pi. When it is pressed, D1 indicator will turn ON.
S2(LOAD) Switch: It mainly controls the power supply of servos. When it is pressed, D2 indicator will turn
ON.
LED port: Used to connect the LED Module, controlled directly by RPi.
MPU6050 Module port: Used to connect MPU6050, controlled directly by RPi.
PI-GPIO port: Used to connect control board with RPi, facilitating RPi to control the robot
I2CExtension Board: Used for the extension of other I2C devices.
Servo port: 32 servo ports available.
Sonic module port: The interface of HC-SR04 Ultrasonic Module is provided.
Buzzer: Turning ON when it is at high level and OFF at low level, directly controlled by RPi
📧 [email protected]
38 Chapter 1 Installation of Python Libraries(Important) www.freenove.com █
Caution: Do NOT install it without referring to the tutorial. Otherwise, it may cause installation errors and
damage the components.
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.
You can watch this video while reading this chapter: https://youtu.be/_w_dp9LDZyc
Start the Raspberry Pi and open the terminal. You can open the terminal as follows or press “CTRL+ALT+T”
on the desktop.
Terminal Terminal
📧 [email protected]
█ www.freenove.com Chapter 1 Installation of Python Libraries(Important) 39
Enter the following commands in the terminal to obtain the robot’s code and save it to the user’s directory”
Pi”. (Note that here are two commands, please enter them one by one in order.)
cd ~
First, execute python to check default python on your raspberry Pi. Press Ctrl-Z to exit.
📧 [email protected]
40 Chapter 1 Installation of Python Libraries(Important) www.freenove.com █
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 “↑” will bring back the previous command, and pressing “↓” will
bring back the latter command.
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 letter, pressing Tab key once won’t have any result.
And pressing Tab key again will list all the eligible options. This command/path will be directly completed
when there is only one eligible option.
As shown below, under the ‘~’directory, enter the Documents directory with the “cd” command. After typing
“cd D”, press Tab key, then there is no response. Press Tab key again, then 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 completed
automatically.
📧 [email protected]
█ www.freenove.com Chapter 1 Installation of Python Libraries(Important) 41
Step 2 Configuration
Configure i2c
Click
Select
📧 [email protected]
42 Chapter 1 Installation of Python Libraries(Important) www.freenove.com █
Additional supplement
Raspbery Pi, other than 4B and 400, nees to disable the audio module, othewise the LED will not work
properly.
1. Create a new snd-blacklist.conf and open it for editing
sudo nano /etc/modprobe.d/snd-blacklist.conf
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.
📧 [email protected]
█ www.freenove.com Chapter 1 Installation of Python Libraries(Important) 43
1. Execute the following command to enter the directory where robot code “setup.py” locates.
cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code
2. Run setup.py
sudo python setup.py
The installation program will automatically install pca9685 library, rpi_ws281x library and PyQt5 library, etc.
When the installation is successful, please restart Raspberry Pi.
Our solution is: Re-execute setup.py. After installing successfully, restart Raspberry Pi. Most installation failures
are caused by a poor network.
sudo python setup.py
📧 [email protected]
44 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
You can watche this video while reading this chapter: https://youtu.be/l4R5f8EvvPo
We will help you with any concerns via [email protected]
Take out the disc servo arms from the servo package.
M1.8x8
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 45
After all disc servo arms are installed successfully, it should look as follows:
📧 [email protected]
46 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
Servo
M4 Anti-Slip Nut
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 47
M4x14
M4 Anti-Slip Nut
M4x14
M4 Anti-Slip Nut
Assembly
M3x12
M3 Nut
📧 [email protected]
48 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
Assembly
M3x12
M3 Nut
Servos at left and right hip joints (Note: the direction of servos on each side is different.)
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 49
Head
M2.5x8
M2.5x8
📧 [email protected]
50 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
M3x12
LED Module
M3 Nut
Wiring
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 51
Note: There are two rows of female header, please plug the module into the right.
MPU6050 Module
Female Header on
the right
Installing Raspberry Pi
M2.5x8
Raspberry Pi
📧 [email protected]
52 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
Installing Connector
M3x12
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 53
📧 [email protected]
54 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
M3x14
Countersunk screw
M3 Nut
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 55
M3x12
M3x12
📧 [email protected]
56 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
Before installing, fix the servos at the specified angle. At this point you need to run the servo program.
Plug batteries into the battery holder. And then plug the battery holder to control board.
Plug into
S2 S1
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 57
Open Raspberry Pi. (All contents in Chapter 1 should be executed correctly first. If not, please return Chapter
1 to finish it first.)
Enter the following command to enter the directory where the servo program locates.
cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
b. Execute the following command to run “Servo.py”.
sudo python Servo.py
Next, fix each servo to the corresponding disc servo arm. Do NOT pull the servo wires during the installation
process.
📧 [email protected]
58 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
Bottom
Top
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 59
📧 [email protected]
60 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 61
Asseble 6 standoff
M3x12
M3x55
📧 [email protected]
62 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 63
Installing head
Servo1
M2 Nut
M2 Nut
M2x16
M2x16
Ultrasonic Module
M2 Nut
Camera
Servo0
M2x16
M1.4x5
M2x16
📧 [email protected]
64 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
Screws in servo
package
📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 65
📧 [email protected]
66 Chapter 2 Assembly of the Robot (Important) www.freenove.com █
M3x12
📧 [email protected]
█ www.freenove.com Chapter 3 Module Test (necessary) 67
Servo
Run program
Enter following commands in the terminal to test servos.
If the terminal displays the directory as below (where test.py is located). You can directly execute the test.py
command.
📧 [email protected]
68 Chapter 3 Module Test (necessary) www.freenove.com █
Result:
In the previous chapter, we have assembled the robot and executed the servo installation program, which
makes the six legs of the robot straight.
After running the servo test program, the robot slowly rotates its six legs clockwise from the original straight
state, and then lifts the legs up, and finally stands with the lower leg extended back. If the sequence of the
movement of your robot is different, please check whether the wiring is correct.
📧 [email protected]
█ www.freenove.com Chapter 3 Module Test (necessary) 69
Reference
setServoAngle(channel, angle)
There are two parameters in this function to rotate the servo of specified channel to a specified angle.
The first parameter indicates the servo channel
The second parameter indicates the rotation angle
For example:
setServoAngle(0,60) Rotate servo of channel 0 to 60 degrees
setServoAngle(15,160) Rotate servo of channel 15 to 160 degrees
📧 [email protected]
70 Chapter 3 Module Test (necessary) www.freenove.com █
ADC Module
Run program
Enter following commands to test ADC module.
If the terminal displays the directory as below (where test.py is located). You can directly execute the test.py
command.
Result:
Print out the voltage value of two sets of batteries every one second,You can press "Ctrl + C" to end program.
📧 [email protected]
█ www.freenove.com Chapter 3 Module Test (necessary) 71
Reference
batteryPower()
Return the voltage value of the battery, retaining two decimal places.
📧 [email protected]
72 Chapter 3 Module Test (necessary) www.freenove.com █
Ultrasonic module
Run program
Enter the following command in the terminal to test the ultrasonic module:
If the terminal displays the directory as below (where test.py is located). You can directly execute the test.py
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=ultrasonic.getDistance() #Get the value
7 print ("Obstacle distance is "+str(data)+"CM")
8 time.sleep(1)
9 except KeyboardInterrupt:
10 print ("\nEnd of program")
Reference
getDistance()
This function is used to obtain the distance of ultrasonic module and front obstacle, with unit CM.
📧 [email protected]
█ www.freenove.com Chapter 3 Module Test (necessary) 73
Led
Run program
Enter the following commands to test LED.
If the terminal displays the directory as below (where test.py is located). You can directly execute the test.py
command.
Result:
The LED lights up with the color of red, green, blue and white in turn and then it turns OFF. You can end the
program ahead of time by pressing "ctrl+c".
If the LED color display order is not correct, open the "Led.py" file in the current directory and modify the
value of the "self.ORDER" variable on line 16.
📧 [email protected]
74 Chapter 3 Module Test (necessary) www.freenove.com █
Reference
colorWipe(strip, color, wait_ms)
This function erases the color of one pixel at a time, has three input parameters, strip represents the
Neopixel object, color represents the color to be erased, and wait_ms represents the erasure interval. The
default is 50ms. For example, colorWipe(strip, Color(255,0,0),20) means that the LED0 color is red first, wait
for 20ms, and then the LED1 color is also red, so that all eight LEDs are lit and red.
📧 [email protected]
█ www.freenove.com Chapter 3 Module Test (necessary) 75
Buzzer
Result:
The buzzer will be turn on lasting for 3s. Then the program will automatically end or you can press "Ctrl + C"
to end the program.
📧 [email protected]
76 Chapter 3 Module Test (necessary) www.freenove.com █
Reference
buzzer.run(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.
📧 [email protected]
█ www.freenove.com Chapter 3 Module Test (necessary) 77
Camera
To use the camera, you need to disable legacy camera, which is disabled by default on the latest Raspberry
Pi OS. If it is not disabled, please do it as below.
Enter the following command. Choose Interface Options Legacy Camera NoOKFinish,and then
restart the Raspberry Pi.
sudo raspi-config
📧 [email protected]
78 Chapter 3 Module Test (necessary) www.freenove.com █
libcamera-apps does not work properly on Pi 0 to 3 devices when running the latest Bullseye images.
A workaround is to open a terminal, run "sudo raspi-config", navigate to "Advanced Options" and enable
"Glamor" graphic acceleration. Then reboot your Pi.
sudo raspi-config
📧 [email protected]
█ www.freenove.com Chapter 3 Module Test (necessary) 79
📧 [email protected]
80 Chapter 3 Module Test (necessary) www.freenove.com █
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 81
The robot features with live video, ultrasonic ranging and other functions. Based on Python3 and PyQt5, it has
also been built with server and client, which communicate with each other through TCP/IP protocol and can
be controlled remotely with the same LAN.
📧 [email protected]
82 Chapter 4 Hexapod Robot www.freenove.com █
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
Run on RPi, the server can send image data obtained by camera and ultrasonic data to client as well as receive
commands from client.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 83
4 0x8915,
5 struct.pack('256s',b'wlan0'[:15])
6 )[20:24])
7 def turn_on_server(self):
8 #ip address
9 HOST=self.get_interface_ip()
10 #Port 8002 for video transmission
11 self.server_socket = socket.socket()
12 self.server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1)
13 self.server_socket.bind((HOST, 8002))
14 self.server_socket.listen(1)
15 #Port 5002 is used for instruction sending and receiving
16 self.server_socket1 = socket.socket()
17 self.server_socket1.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1)
18 self.server_socket1.bind((HOST, 5002))
19 self.server_socket1.listen(1)
20 print('Server address: '+HOST)
21 def turn_off_server(self):
22 try:
23 self.connection.close()
24 self.connection1.close()
25 except :
26 print ('\n'+"No client connection")
27 def reset_server(self):
28 self.turn_off_server()
29 self.turn_on_server()
30 self.video=threading.Thread(target=self.transmission_video)
31 self.instruction=threading.Thread(target=self.receive_instruction)
32 self.video.start()
33 self.instruction.start()
Reference
For more code, please check “Server.py” in the Server directory.
get_interface_ip()
To obtain the IP address of RPi’s WLAN0
turn_on_server()
To turn ON TCP to wait for the connection of Client
turn_off_server()
To turn OFF TCP
send_data()
📧 [email protected]
84 Chapter 4 Hexapod Robot www.freenove.com █
reset_server ()
To restart TCP
transmission_video()
To send video data to client
receive_instruction()
To receive commands from client
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 85
Open Server
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.
📧 [email protected]
86 Chapter 4 Hexapod Robot www.freenove.com █
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.
sudo raspi-config
Select 7 Advanced OptionsA5 Resolutionproper resolution ratio (set by yourself)OKFinish. And then
reboot Raspberry Pi.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 87
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.
📧 [email protected]
88 Chapter 4 Hexapod Robot www.freenove.com █
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 89
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 main.py is located:
cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
2. Run main.py:
sudo python main.py -t -n
or Run main,py with following command:
sudo python main.py -tn
“-t” means open TCP communication. “-n“ means don’t show interface.
📧 [email protected]
90 Chapter 4 Hexapod Robot www.freenove.com █
4 Modify permissions.
sudo chmod 777 start.sh
5 Enter the following command to create a directory.
mkdir ~/.config/autostart/
6 create and open “start.desktop” file
sudo nano .config/autostart/start.desktop
7 Add the following content to “start.desktop” file.
[Desktop Entry]
Type=Application
Name=start
NoDisplay=true
Exec=/home/pi/start.sh
Press Ctrl + O and then press Enter to save it. Press Ctrl+X to exit.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 91
8 Modify permissions.
sudo chmod +x .config/autostart/start.desktop
Note: To cancel auto start, please delete the files “start.sh” and “start.desktop” created above.
📧 [email protected]
92 Chapter 4 Hexapod Robot www.freenove.com █
Client
Client can receive video data and commands from the server as well as send commands to server. It can also
be run in different systems including Windows and macOS as long as you install the related software and
libraries.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 93
37 try:
38 self.client_socket1.send(data.encode('utf-8'))
39 except Exception as e:
40 print(e)
41 def receive_data(self):
42 data=""
43 data=self.client_socket1.recv(1024).decode('utf-8')
44 return data
Reference
For more code, please check “Client.py” in the Client director.
turn_on_client ()
To connect to the server
turn_off_client ()
To disconnect server。
receiving_video()
To receive video data from server
is_valid_image_4_bytes ()
To check the integrity of each frame of video data
send_data ()
To send commands to server
receive_data ()
To receive commands from server
📧 [email protected]
94 Chapter 4 Hexapod Robot www.freenove.com █
When the Client is opened successfully, you need to turn on Raspberry Pi and open the server. Enter Raspberry
Pi’s IP address in the white IP editor and click “Connect” to connect the robot with RPi. After connecting
successfully, you need to calibrate the robot's six legs before control it to move.
Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 95
2.Install python3 and some related python libraries and execute the program through python3 editor.
This section will be completed in your computer with windows system, not Raspberry Pi.
Running client on Windows system requires the installation of some software and libraries, which take some
time. At this point, it does not require to run server and use the Raspberry Pi, so you can turn OFF RPi
temporarily. After installing successfully, turn ON the RPi and run the Server.
Install python3
Download the installation file via below:
https://www.python.org/downloads/windows/
Select “Windows x86 executable installer”. Execute the installer when completes downloading.。
📧 [email protected]
96 Chapter 4 Hexapod Robot www.freenove.com █
Check “Add Python 3.8 to PATH” and install according to your needs.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 97
My installation path here is Disk D (You can choose whichever you prefer). Click Install.
📧 [email protected]
98 Chapter 4 Hexapod Robot www.freenove.com █
Installation finishes.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 99
Install libraries including PyQt5 library, opencv library, numpy library, etc.
If have not download the zip file, download it via below:
https://github.com/Freenove/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/archive/master.zip
Then unzip it and delete “-master” to rename it to “Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi”.
Then put it into D disk for example.
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.
1.Enter D disk. If you put it into E, it should be E:
D:
2.Enter directory where setup_windows.py is located:
cd D:\Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi\Code
3.Run: setup_windows.py
Python setup_windows.py
The installation takes some time, please wait with patience. When all the libraries are installed successfully,
you can see the prompt “All libraries installed successfully” on the screen.
📧 [email protected]
100 Chapter 4 Hexapod Robot www.freenove.com █
If there is any library fails to install, it will print “Some libraries have not been installed yet. Please run 'python
setup_windows.py' again” on the screen, then you need to execute the command python setup_windows.py
again. Most installation fails because of poor network, so you can check your network before installing the
libraries.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 101
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 Main.py is located:
cd D:\Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi\Code\Client
3.Run Main.py:
Python Main.py
Note: If the default python of your Windows system is not Python3 but python2, change the command
Main.py as follows:
Python3 Main.py
📧 [email protected]
102 Chapter 4 Hexapod Robot www.freenove.com █
When the Client is opened successfully, you need to turn on Raspberry Pi and open the server. Enter Raspberry
Pi’s IP address in the white IP editor and click “Connect” to connect the robot with RPi. After connecting
successfully, you need to calibrate the robot's six legs before control it to move.
Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time.
Running client on macOS system requires the installation of some software and libraries, which take some
time. At this point, it does not require to run server and use the Raspberry Pi, so you can turn OFF RPi
temporarily. After installing successfully, turn ON the RPi and run the Server. The system comes with python2
instead of python3, so you need to install python3 first, as all the program of this robot are run with python3.
Install python3
Download the installation package via: https://www.python.org/downloads/
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 103
If your macOS is NOT 11, like 10.15, please install python 3.8. If you have
📧 [email protected]
104 Chapter 4 Hexapod Robot www.freenove.com █
Slide to the bottom of the page and click macOS 64-bit installer.
Click Continue
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 105
Click Continue
Click Agree
📧 [email protected]
106 Chapter 4 Hexapod Robot www.freenove.com █
Click “Install”, enter the computer password and click “Install Software”.
Install successfully
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 107
Open “Terminal”
📧 [email protected]
108 Chapter 4 Hexapod Robot www.freenove.com █
When all the libraries are installed successfully, you can see the prompt “All libraries installed successfully” on
the screen. If there is any library fails to install, it will print “Some libraries have not been installed yet. Please
run ' python3 setup_macos.py' again” on the screen, then you need to execute the command python3
setup_macos.py again.
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
Most installation fails because of poor network, so you can check your network before installing the libraries.
Open client
Installing successfully, now you are in the directory where setup_macos.py locates.
1. Enter the following command to enter the client program folder:
cd Client/
2. Enter the following command to run the program
python3 Main.py
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 109
When the Client is opened successfully, you need to turn on Raspberry Pi and open the server. Enter Raspberry
Pi’s IP address in the white IP editor and click “Connect” to connect the robot with RPi. After connecting
successfully, you need to calibrate the robot's six legs before control it to move.
Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time.
📧 [email protected]
110 Chapter 4 Hexapod Robot www.freenove.com █
Open client
Enter the following commands at the terminal.
1. Use the cd command to go to the directory where Main.py is located.
cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Client
2. Run Main.py:
sudo python Main.py
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 111
When the Client is opened successfully, you need to turn on Raspberry Pi and open the server. Enter Raspberry
Pi’s IP address in the white IP editor and click “Connect” to connect the robot with RPi. After connecting
successfully, you need to calibrate the robot's six legs before control it to move.
Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time.
📧 [email protected]
112 Chapter 4 Hexapod Robot www.freenove.com █
Calibration
3. Connect client with server successfully, click the "Calibration" button on the client, then a calibration
window pops up.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 113
4. Calibrate the six legs to make the six foot points fall to the corresponding positions. (Due to the error of
the installation and error of the servos themselves, the six foot points may fail to fall to the specified
position perfectly, which is reasonable but we should try to make them as accurate as possible.)
5. When all the six foot points fall to the specified positions, click “Save” and you can control the robot to
move.
Note: Poor calibration will affect the robot’s movement. You can recalibrate it when needed.
📧 [email protected]
114 Chapter 4 Hexapod Robot www.freenove.com █
Control
Battery Power
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 115
📧 [email protected]
116 Chapter 4 Hexapod Robot www.freenove.com █
If you have any concerns, please feel free to contact us via [email protected]
If you want to write your own program to control the robot dog, you can follow this chapter.
The robot 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:
https://python.swaroopch.com/basics.html
Program
First, open Thonny Python IDE which is easy to use for beginners.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 117
Name it myCode and save it in Server folder of robot code folder that you have downloaded.
📧 [email protected]
118 Chapter 4 Hexapod Robot www.freenove.com █
Open the Server folder of the robot code and you can see the file you created.
Write the code in myCode.py and click save after finishing, as shown below.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 119
Type the following command to enter the directory where myCode.py is located.
cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
Run myCode.py
sudo python myCode.py
Result:
The robot moves straight forward first and then walks to the right (Gait Mode1 and Action Mode1), and then
it moves back and turn right.( Gait Mode2 and Action Mode2)
Related py Files
Some important functions included in the py files are listed below. For more detailed code, please refer to the
corresponding py file.
ADS7830.py
Function Description
voltage(channel) Returns the voltage value of corresponding channel
batteryPower() Returns the voltage value of the two sets of batteries
Buzzer.py
Function Description
run(command) Enter 0, the buzzer will not sound; Enter 1, the buzzer sounds.
Contorl.py
Function Description
coordinateToAngle(x,y,z) Enter the foot coordinate and it returns the rotation angle of servos
on each joint.
angleToCoordinate(a,b,c) Enter the joint angles and it returns the foot coordinate.
Condition() Process the action command
coordinateTransformation() Transformation of coordinate system
map() Mapping a value from one range to another
Position(x,y,z) Control the in-situ movement of the body in x,y,z directions
postureBalance(r,p,y) Control in-situ twist of the body(deflection angle, roll Angle and
course angle)
run() Control the movement of the robot with two gait modes and two
📧 [email protected]
120 Chapter 4 Hexapod Robot www.freenove.com █
action modes.
IMU.py
Function Description
imuUpdate() Update the current deflection angle, roll angle and course angle of
the robot
Led.py
Function Description
ledIndex( Index, R, G, B) Turn ON a single LED and set its color
wheel(pos) Generate RGB value of different colors
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 7
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
Servo.py
Function Description
setServoAngle(channel, angle) Rotate the servo of specified channel to a specified angle
Ultrasonic.py
Function Description
getDistance() Obtain the distance between the ultrasonic module and the barrier in
front of it.
📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 121
You can download and install the Freenove Android app from below:
On Google play:
https://play.google.com/store/apps/details?id=com.freenove.suhayl.Freenovez
On GitHub:
https://github.com/Freenove/Freenove_App_for_Android
In this github repository, you can find the App instruction (Tutorial.pdf).
You can download and install the Freenove iPhone ios app by searching freenove in app store.
Gait Mode/
Action Mode LED
Power of servo
Balance
Height Mode
Operator
The servos and the Raspberry Pi are powered by two separate, independent power supplies. When the
servos are powered OFF, the power supply of RPi remains its original state.
📧 [email protected]
122 What's Next? www.freenove.com █
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:
[email protected]
We will make every effort to make changes and correct errors as soon as feasibly possible and publish a
revised version.
After completing the contents in this book, you can try to reform this robot by 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 (https://github.com/freenove).
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.
http://www.freenove.com/