0% found this document useful (0 votes)
5 views

WWT Tutorial

廢水廠處理

Uploaded by

u950358
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

WWT Tutorial

廢水廠處理

Uploaded by

u950358
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 126

Welcome

Thank you for choosing Freenove products!

About Battery

First, read the document About_Battery.pdf in the unzipped folder.


If you did not download the zip file, please download it and unzip it via link below.
https://github.com/Freenove/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/archive/master.zip

Get Support and Offer Input

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 provides open source electronic products and services worldwide.

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

Free your innovation

Raspberry Pi® is a trademark of Raspberry Pi Foundation (https://www.raspberrypi.org/).

📧 [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

We will help you with any concerns via [email protected]

Spider Shield for Raspberry Pi

Top

Bottom

📧 [email protected]
2 List www.freenove.com █

Machinery Parts

📧 [email protected]
█ www.freenove.com List 3

Transmission Parts

Servo package 1 x18 Servo package 2 x2

Acrylic Parts

📧 [email protected]
4 List www.freenove.com █

Electronic Parts

LED module x1 Camera x1 HC-SR04 Ultrasonic Connection board x1


Module x1

Jumper Wire F/F(4) x1

1.25mm 3Pin LED cable (same direction) x1

FPC 25cm 15Pin camera cable (reversed direction) x1

Battery holder x2

📧 [email protected]
█ www.freenove.com List 5

Tools

Cross screwdriver (2mm) x1 Cross screwdriver (4.5mm) x1

Cable Tidy x150cm Multifunctional Spanner x1

📧 [email protected]
6 List www.freenove.com █

Calibration Graph

📧 [email protected]
█ www.freenove.com List 7

Required but NOT Contained Parts

Four 18650 lithium batteries without protection board. Discharge current is greater than 15A

Raspberry Pi (Recommended model: Raspberry 4B / 3B+ / 3B) x1

📧 [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.

[email protected]

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 █

Actual image of Raspberry Pi 3 Model B+ CAD image of Raspberry Pi 3 Model B+

Actual image of Raspberry Pi 3 Model B: CAD image of Raspberry Pi 3 Model B:

📧 [email protected]
█ www.freenove.com Preface 11

Actual image of Raspberry Pi 2 Model B: CAD image of Raspberry Pi 2 Model B:

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

Actual image of Raspberry Pi Zero W: CAD image of Raspberry Pi Zero W:

Actual image of Raspberry Pi Zero: CAD image of Raspberry Pi Zero:

📧 [email protected]
14 Preface www.freenove.com █

Hardware interface diagram of RPi 4B:

GPIO
Connector Ethernet
Connector

Display
Connector

USB
Power Connector x4
Connector

Micro HDMI Camera Audio


Connector x2 Connector Connector

Hardware interface diagram of RPi 3B+/3B/2B/1B+:

GPIO
Connector
USB
Connector
Display
Connector

Ethernet
Power Connector
Connector

HDMI Camera Audio


Connector Connector Connector

Hardware interface diagram of RPi 3A+/A+:

📧 [email protected]
█ www.freenove.com Preface 15

GPIO
Connector

USB
Display Connector
Connector

Power
Connector

HDMI Camera Audio


Connector Connector Connector

Hardware interface diagram of RPi Zero/Zero W:

GPIO
Connector

Camera
Connector

HDMI USB Power


Connector Connector 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.

BCM GPIO Numbering


Raspberry Pi CPU use BCM2835/BCM2836/BCM2837of Broadcom. GPIO pin number is set by chip
manufacturer. These are the GPIO pins as that computer recognizes. The numbers are unordered and don't
make any sense to humans. You will need a printed reference or a reference board that fits over the pins.
Each pin is defined as below:

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:

WiringPi GPIO Numbering


Different from the previous mentioned two kinds of GPIO serial numbers, RPi GPIO serial number of the
WiringPi was renumbered. Here we have three kinds of GPIO number mode: based on the number of BCM
chip, based on the physical sequence number and based on wiringPi. The correspondence between these
three GPIO numbers is shown below:

(For more details, please refer to https://projects.drogon.net/raspberry-pi/wiringpi/pins/ )

📧 [email protected]
18 Preface www.freenove.com █

You can also use the following command to view their correspondence.
gpio readall

For more details about wiringPi, please refer to http://wiringpi.com/ .

📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 19

Chapter 0 Raspberry Pi Preparation

We will help you with any concerns via [email protected]

Install a System

Firstly, install a system for your RPi.

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 █

Raspberry Pi 1 Model A+ wireless network adapter


Power requirements of various versions of Raspberry Pi are shown in following table:
Product Recommended Maximum total USB Typical bare-board
PSU current peripheral current draw active current
capacity consumption
Raspberry Pi Model A 700mA 500mA 200mA
Raspberry Pi Model B 1.2A 500mA 500mA
Raspberry Pi Model A+ 700mA 500mA 180mA
Raspberry Pi Model B+ 1.8A 600mA/1.2A (switchable) 330mA
Raspberry Pi 2 Model B 1.8A 600mA/1.2A (switchable) 350mA
Raspberry Pi 3 Model B 2.5A 1.2A 400mA
Raspberry Pi 3 Model A+ 2.5A Limited by PSU, board, and 350mA
connector ratings only.
Raspberry Pi 3 Model B+ 2.5A 1.2A 500mA
Raspberry Pi 4 Model B 3.0A 1.2A 600mA
Raspberry Pi Zero W 1.2A Limited by PSU, board, and 150mA
connector ratings only.
Raspberry Pi Zero 1.2A Limited by PSU, board, and 100mA
connector ratings only
For more details, please refer to https://www.raspberrypi.org/help/faqs/#powerReqs

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

As to Pi Zero and Pi Zero W, you also need the following accessories:


1. A Micro-HDMI to HDMI Adapter and Cable.
2. A Micro-USB to USB-A Adapter and Cable (Micro USB OTG Cable).
3. A USB HUB.
4. USB to Ethernet Interface or USB Wi-Fi receiver.

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

Required Accessories for Remote Desktop


If you do not have an independent monitor, or if you want to use a remote desktop, first you need to login
to Raspberry Pi through SSH, then open the VNC or RDP service. This requires the following accessories.
Item Pi Zero Pi Zero W Pi A+ Pi 3A+ Pi B+/2B Pi 3B/3B+/4B
Micro-USB to USB-A Yes Yes No
OTG cable
USB transferring to Yes Yes Yes
Ethernet interface NO

📧 [email protected]
22 Chapter 0 Raspberry Pi Preparation www.freenove.com █

Raspberry Pi OS

Install imager tool


Visit this website to install imager tool.
https://www.raspberrypi.com/software/

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

Write System to Micro SD Card


First, insert your Micro SD card into card reader and connect it to USB port of PC. Then open imager tool.
Choose system that you just downloaded in Use custom.

Choose the SD card.

📧 [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 █

Remote desktop & VNC

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.

MAC 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.

You may need to type yes during the process.

📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 29

You can also use the IP address to log in Pi.


Enter router client to inquiry IP address named “raspberry pi”. For example, I have inquired to my RPi IP
address, and it is “192.168.1.131".

Open the terminal and type following command.


ssh [email protected]
When you see pi@raspberrypi:~ $, you have logged in Pi successfully. Then you can skip to next section.

Then you can skip to VNC Viewer.

📧 [email protected]
30 Chapter 0 Raspberry Pi Preparation www.freenove.com █

Windows OS Remote Desktop

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

Then 192.168.1.147 is my Raspberry Pi IP.

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".

ssh [email protected]

📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 31

VNC Viewer & VNC

Type the following command. And select Interfacing Options VNC YesOKFinish. 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.

Enter username: pi and Password: raspberry. And click OK.

📧 [email protected]
█ www.freenove.com Chapter 0 Raspberry Pi Preparation 33

Here, you have logged in to Raspberry Pi successfully by using VNC Viewer

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 OptionsVNV ResolutionProper resolution ratio (set by yourself)OKFinishYes.
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 █

Spider Shield for Raspberry Pi

Description of Robot Control Board

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

I2C Expansion 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 █

Chapter 1 Installation of Python Libraries(Important)


In this chapter, we will do some necessary foundational preparation work: Start your Raspberry Pi and install
some necessary libraries. And we will assemble the robot in the next chapter.

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

We will help you with any concerns via [email protected]

Step 1 Obtain the Code

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

The terminal is shown below:

📧 [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 ~

git clone https://github.com/Freenove/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi.git


Downloading need much time. Please wait with patience.
You can also find and download the code by visiting our official website (http://www.freenove.com) or our
GitHub repository (https://github.com/freenove).
Note: all codes of the robot are written with Python3. If run with Python2, it may cause errors.

Set Python3 as default python

First, execute python to check default python on your raspberry Pi. Press Ctrl-Z to exit.

If it is python3, you can skip this section.


If it is python2, you need execute following commands to set default python to python3.

1. Enter directory /usr/bin


cd /usr/bin
2. Delete the old python link.
sudo rm python
3. Create new python links to python.
sudo ln -s python3 python
4. Check python. Press Ctrl-Z to exit.
python

If you want to set python2 as default python in other projects.


Just repeat command above and change python3 to python2.

📧 [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

2. We also need to edit config file.


sudo nano /boot/config.txt
Find the contents of the following two lines (with Ctrl + W you can search):
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
Add # to comment out the second line. Press Ctrl+O, Enter, Ctrl+Z.
# Enable audio (loads snd_bcm2835)
# dtparam=audio=on

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

Step 3 Execute the Installed Program

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.

If the installation fails as shown below

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 █

Chapter 2 Assembly of the Robot (Important)

You can watche this video while reading this chapter: https://youtu.be/l4R5f8EvvPo
We will help you with any concerns via [email protected]

Step 1 Installing Servo Base

Take out the disc servo arms from the servo package.

Use the middle hole of each


group of holes

Fix each disc servo arm to the joints.

disc servo arm


M1.8x8

M1.8x8

disc servo arm

📧 [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 █

Step 2 Installing Servos

Installing Servos on the Legs

Install servos on the lower legs

lower legs M4x14

Servo

M4 Anti-Slip Nut

The other 5 leg parts are installed in the same way.


Note: The robot has six legs and its left lower legs and right lower legs are in different directions.

📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 47

Installation of servos on the hip joints of the three left legs.

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 █

Installation of servos on the hip joints of the three right legs.

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

Step 3 Assembling the center of the body

Installing Control Board

Installing control board


Brass standoff
M2.5x8

Head

M2.5x8

M2.5x8

📧 [email protected]
50 Chapter 2 Assembly of the Robot (Important) www.freenove.com █

Installing LED Module

M3x12

LED Module

M3 Nut

Wiring

Connected to Control Board

📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 51

Installing MPU6050 Module

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

Install the comection board


Press it until you can see the pins

Installing Brass Standoff

M3x30 Brass Standoff

M3x12

📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 53

Installing Servo Arms

Servo arms in servo package Self-tapping screw in servo package

📧 [email protected]
54 Chapter 2 Assembly of the Robot (Important) www.freenove.com █

Step 4 Installing Battery Holder

M3x14
Countersunk screw

M3 Nut

📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 55

M3x20 Brass Standoff

M3x12

M3x12

📧 [email protected]
56 Chapter 2 Assembly of the Robot (Important) www.freenove.com █

Step 5 Assembling Legs and Head to the Body

Run the servo installation program

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

Press S1 and S2.

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 █

Installing Hip Joint

Connect the servo wires to corresponding servo port.

Bottom

Top

📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 59

Black screws in the servo package

📧 [email protected]
60 Chapter 2 Assembly of the Robot (Important) www.freenove.com █

Installing Lower Leg and the Head

Connect the servo wires to corresponding servo port.

📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 61

Black screws in the servo package

Asseble 6 standoff

M3x12

M3x55

📧 [email protected]
62 Chapter 2 Assembly of the Robot (Important) www.freenove.com █

Connect a 4P cable which will be used later.

📧 [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

Servo arm in the servo package


Acrylic
M2 Nut

M2x16

Screws in servo package

📧 [email protected]
64 Chapter 2 Assembly of the Robot (Important) www.freenove.com █

Screws in servo package

Screws in servo
package

Connecting Wires of Camera and Ultrasonic Module

Connect camera wire

You need power off Raspberry Pi when wire camera.


After connected, it should be as follows

📧 [email protected]
█ www.freenove.com Chapter 2 Assembly of the Robot (Important) 65

Connecting Ultrasonic Module


Note: VCC, Echo, Trig, GND are connected to VCC, Echo, Trig and GND on the connection board
respectively. Do NOT connect them wrongly. Otherwise, it may burn out the Ultrasonic module.

📧 [email protected]
66 Chapter 2 Assembly of the Robot (Important) www.freenove.com █

Step 6 Installing Base and Cover Plates

M3x12

Congratulations! You have finished the assembly of the robot.

📧 [email protected]
█ www.freenove.com Chapter 3 Module Test (necessary) 67

Chapter 3 Module Test (necessary)


In the previous chapter, we have assembled the robot. In this chapter, we will test all modules of the robot to
see whether they work.
Before starting, please plug in the batteries, and switch ON S1 and S2. Place the assembled robot on a
horizontal table and make sure that the wiring of each servo is correct.
If you have never learned python before, you can learn some basic knowledge via the link below:
https://python.swaroopch.com/basics.html

You can watch this video while reading this chapter:https://youtu.be/D00LdVqXC5E

We will help you with any concerns via [email protected]

Servo

Enter the following command to check I2C.


i2cdetect -y 1
As shown in the following illustration, the address of two PCA9685 chips are 0x40 and 0x41 respectively, the
address of ADS7830 chip is 0x48 and the address of MPU6050 module is 0x68。

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.

1. If not, execute the cd command:


cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
2. Execute test.py command:
sudo python test.py Servo

📧 [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

The code is as below:


1 from Servo import *
2 servo=Servo()
3 def test_Servo():
4 try:
5 for i in range(50):
6 servo.setServoAngle(15,90+i)
7 servo.setServoAngle(12,90+i)
8 servo.setServoAngle(9,90+i)
9 servo.setServoAngle(16,90+i)
10 servo.setServoAngle(19,90+i)
11 servo.setServoAngle(22,90+i)
12 time.sleep(0.05)
13 for i in range(60):
14 servo.setServoAngle(14,90+i)
15 servo.setServoAngle(11,90+i)
16 servo.setServoAngle(8,90+i)
17 servo.setServoAngle(17,90-i)
18 servo.setServoAngle(20,90-i)
19 servo.setServoAngle(23,90-i)
20 time.sleep(0.05)
21 for i in range(150):
22 servo.setServoAngle(13,i)
23 servo.setServoAngle(10,i)
24 servo.setServoAngle(31,i)
25 servo.setServoAngle(18,180-i)
26 servo.setServoAngle(21,180-i)
27 servo.setServoAngle(27,180-i)
28 time.sleep(0.05)
29 print ("\nEnd of program")
30 except KeyboardInterrupt:
31 print ("\nEnd of program")

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.

1.If not, execute the cd command:


cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
2.Execute test.py command:
sudo python test.py ADC

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

The code is as below:


1 from ADS7830 import *
2 adc=ADS7830()
3 def test_Adc():
4 try:
5 while True:
6 Power=adc.batteryPower()
7 print ("The battery voltage is "+str(Power)+'\n')
8 time.sleep(1)
9 except KeyboardInterrupt:
10 print ("\nEnd of program")

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.

1. If not, execute the cd command:


cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
2. Execute test.py command:
sudo python test.py Ultrasonic

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

There is an LED module on the robot, as shown below:

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.

1.If not, execute the cd command:


cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
2.Execute test.py command:
sudo python test.py Led

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 █

The code of test.py is as below:


1 from Led import *
2 led=Led()
3 def test_Led():
4 try:
5 #Red wipe
6 print ("\nRed wipe")
7 led.colorWipe(led.strip, Color(255, 0, 0))
8 time.sleep(1)
9
10
11 #Green wipe
12 print ("\nGreen wipe")
13 led.colorWipe(led.strip, Color(0, 255, 0))
14 time.sleep(1)
15
16
17 #Blue wipe
18 print ("\nBlue wipe")
19 led.colorWipe(led.strip, Color(0, 0, 255))
20 time.sleep(1)
21
22
23 #White wipe
24 print ("\nWhite wipe")
25 led.colorWipe(led.strip, Color(255, 255, 255))
26 time.sleep(1)
27
28 led.colorWipe(led.strip, Color(0, 0, 0)) #turn off the light
29 print ("\nEnd of program")
30 except KeyboardInterrupt:
31 led.colorWipe(led.strip, Color(0, 0, 0)) #turn off the light
32 print ("\nEnd of program")

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

Run the program


Enter following command in the terminal to test buzzer.
If the terminal displays the directory as below (where test.py is located). You can directly execute the test.py
command.

1.If not, execute the cd command:


cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
2.Execute test.py command:
sudo python test.py 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 █

The code is as below:


1 from Buzzer import *
2 buzzer=Buzzer()
3 def test_Buzzer():
4 try:
5 buzzer.run('1')
6 time.sleep(1)
7 print ("1S")
8 time.sleep(1)
9 print ("2S")
10 time.sleep(1)
11 print ("3S")
12 buzzer.run('0')
13 print ("\nEnd of program")
14 except KeyboardInterrupt:
15 buzzer.run('0')
16 print ("\nEnd of program")

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 NoOKFinish,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 █

Then reboot your Pi.


If you do not get the result above, please check whether the camera wire is connected correctly.
(Note: When plugging in or pulling out camera wire, please make sure Raspberry Pi is turned OFF. Otherwise,
it may burn out the camera.)
Run program
1. execute the cd command:
cd ~/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server
2. Execute test.py command:
python camera.py
Result:
After executing the commands, you can see image.jpg in the corresponding directory.

📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 81

Chapter 4 Hexapod Robot


You can refer to these videos to open client and calibrate the robot:
Client control: https://youtu.be/KlxxgnW6uyo
Calibration: https://youtu.be/NdXG3wmdufI

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.

We will help you with any concerns via [email protected]

📧 [email protected]
82 Chapter 4 Hexapod Robot www.freenove.com █

Start Start

Open server Open client

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.

Part of the server code is as follows:


1 def get_interface_ip(self):
2 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
3 return socket.inet_ntoa(fcntl.ioctl(s.fileno(),

📧 [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 █

To send commands to client

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

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:
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. 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 OptionsA5 Resolutionproper resolution ratio (set by yourself)OKFinish. 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.

Step 2 Run commands


Enter following command in the terminal.
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

The interface is as below:

📧 [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.

Sever Auto Start


1 Open the terminal and execute the following two commands respectively to create a “start.sh” file.
cd ~
sudo touch start.sh
2 Open “start.sh”.
sudo nano start.sh
3 Add the following contents to “start.sh” file.
#!/bin/sh
cd "/home/pi/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/Server"
pwd
sleep 10
sudo cp point.txt /home/pi
sudo python main.py
Press Ctrl + O and then press Enter to save it. Press Ctrl+X to exit.

📧 [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

9 Finally enter the following content to reboot Raspberry Pi.


sudo reboot

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.

Part of the client code is as follows:


1 def turn_on_client(self,ip):
2 self.client_socket1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
3 self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4 print (ip)
5 def turn_off_client(self):
6 try:
7 self.client_socket.shutdown(2)
8 self.client_socket1.shutdown(2)
9 self.client_socket.close()
10 self.client_socket1.close()
11 except Exception as e:
12 print(e)
13 def receiving_video(self,ip):
14 try:
15 self.client_socket.connect((ip, 8002))
16 self.connection = self.client_socket.makefile('rb')
17 except:
18 #print ("command port connect failed")
19 pass
20 while True:
21 try:
22 stream_bytes= self.connection.read(4)
23 leng=struct.unpack('<L', stream_bytes[:4])
24 jpg=self.connection.read(leng[0])
25 if self.is_valid_image_4_bytes(jpg):
26 if self.video_flag:
27 self.image = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8),
28 cv2.IMREAD_COLOR)
29 if self.fece_id == False and self.fece_recognition_flag:
30 self.face.face_detect(self.image)
31 self.video_flag=False
32 except BaseException as e:
33 print (e)
34 break
35 def send_data(self,data):
36 if self.tcp_flag:

📧 [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 █

Run Client on Windows system

There are two ways to run Client on Windows.


1. Running executable file directly
Find the “Client.exe” file in the specified directory, double click it and the Client is opened.

The client interface is shown as below:

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/

Click Latest Python Release - Python 3.8.1

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.

Check all the options and click “Next”.

📧 [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.

Wait for the installation,

📧 [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

Or you can enter “Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi\Code\” directory and double click


“setup_windows.py” to execute the installer.

Or open “setup_windows.py” with python3 and execute it.


Caution: If the default python of your Windows system is not python3 but python2, change the command
"setup_windows.py" as follows and replace all “python” in setup_windows.py to “python3”.
Python3 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

Or you can enter “Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi\Code\Client” directory and double-


click “Main.py”.
Or use python3 to open and execute “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

The client interface is shown as below:

📧 [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.

Run Client on macOS system

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/

If your macOS is 11. Like 11.0, please install python 3.9.

📧 [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

installed python 3.9. You need uninstall it first.

📧 [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

You can find it in your Applications.

Install PyQt5 library, opencv library, numpy library, etc.


If you have not yet downloaded the robot code, you can download it through the following link:
https://github.com/Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/archive/master.zip
After downloading, you can find it in “Downloads”.

Open “Terminal”

Enter the following commands in “Terminal”


1.Enter “Downloads” (where you save the robot code. If your path is different, please change it.)
cd Downloads
2.Enter directory where setup_macos.py is located:
cd Freenove_Big_Hexapod_Robot_Kit_for_Raspberry_Pi/Code/
3.Run setup_macos.py:
python3 setup_macos.py

📧 [email protected]
108 Chapter 4 Hexapod Robot www.freenove.com █

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. 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 █

Run client on Raspberry Pi(Linux) system

Install opencv library


Enter the following three commands one by one
sudo apt-get install -y libopencv-dev python3-opencv

sudo pip3 install opencv-contrib-python

sudo apt-get install -y libatlas-base-dev libjasper-dev

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

The interface is shown below:

📧 [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

Calibrate the robot’s six legs


1. Lay the calibration paper on a horizontal table.
2. Place the robot to the corresponding position on the calibration paper as shown below:

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

Control the body to twist

Control the body to move horizontally

Options of Gait mode Operation Board

Options of Action mode

Battery Power

📧 [email protected]
█ www.freenove.com Chapter 4 Hexapod Robot 115

The following is the corresponding operation of the buttons and keyboards.


Button on Client Key Action
ForWard W Move
BackWard S Back off
Turn Left A Turn left
Turn Right D Turn right
Connect/ Disconnect C Connection ON/OFF
Open Video/ Close Video V Video ON/OFF
Relax R Relax/Activated
LED L Open LED control interface
Balance B balance mode ON/OFF
Face Recog F face recognition ON/OFF
Sonic U Ultrasonic ranging ON/OFF
Calibration T Open calibration interface
Face ID I Open the face reading interface
Buzzer/Noise Y Buzzer ON/OFF

The function of SliderBar is below:


SliderBar Function
Head Rotate the robot’s head
Speed Control the robot’s speed

📧 [email protected]
116 Chapter 4 Hexapod Robot www.freenove.com █

Free your innovation

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

Create a new file.

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

Android and iOS app

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.

The interface of the APP is shown below:

Distance from Voltage of two Take


IP address of RPi Connect/ Disconnect Buzzer
the obstacle sets of batteries photo
s

Gait Mode/
Action Mode LED

Power of servo

Balance
Height Mode

Operator

Switching operator Camera Movement

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/

Thank you again for choosing Freenove products.

📧 [email protected]

You might also like