RaspArmS Tutorial
RaspArmS Tutorial
1
complicated part of the structure. We use a linkage mechanism to increase the
strength of the chuck.
There are drawings of the robotic arm in our document, including dimensions
and assembly hole specifications, which is convenient for users to use the robotic arm
in more occasions.The robotic arm itself is also a modular design, so users can
flexibly assemble it into the form they need.
RaspArm-S is equipped with an OLED screen to display key information. When
you are debugging or running the robotic arm on the desktop, you can use the micro
USB interface on the driver board to power the RaspArm-S. No extra battery is
required. This avoids the trouble of charging the product during the development
process. The advantages of permanent power and simple structure enable you to focus
on product development without any worries and realize your creative ideas more
efficiently.
2
Raspberry Pi
1. Introduction to Raspberry Pi
(1) Raspberry Pi
In our lessons, we will use the Raspberry Pi 4 motherboard. Let's take a look at
the structure of the Raspberry Pi 4 motherboard. As shown in the following figure:
3
The following contents will briefly explain the main structure ports of the
Raspberry Pi 4 motherboard:
(1) GPIO 40-PIN pin:
The General Purpose Input Output (GPIO) is designed as a slot with two rows of
pins on the Raspberry Pi motherboard. GPIO can be used to connect various
peripheral electronic devices and sensors to control or monitor these devices through
input/output level signals. For example, you can use GPIO to control the speed of a
DC motor, or read the measured distance of an ultrasonic sensor. These functional
characteristics of GPIO make the Raspberry Pi different from ordinary computer
motherboards because it gives developers the freedom to operate manually. We will
further introduce GPIO in the subsequent chapters and use them extensively.
(2) Gigabit Ethernet port:
The Ethernet interface allows the Raspberry Pi to connect to the computer
network in a wired manner, which allows us to easily access the Internet or log in to
the Raspberry Pi remotely. The Raspberry Pi's Ethernet interface is implemented
using a USB bus, and data is transferred through the USB bus. Most models of
Raspberry Pi provide an Ethernet interface
(3) Micro HDMI port:
4
High-definition multimedia interface (High Definition Multimedia Interface,
HDMI) is a fully digital video and sound transmission interface, used to transmit
uncompressed audio and video signals. By connecting it to a display (or TV) equipped
with an HDMI interface, the content of the Raspberry Pi can be displayed. The HDMI
interface can transmit video and audio signals at the same time, so when we use it, we
don't need to connect speakers to the audio interface of the Raspberry Pi. If we really
need to play sound through the audio interface, we need to modify the operating
system configuration accordingly.
(4) USB2.0/3.0 port:
The Universal Serial Bus (USB) interface is the most common interface on a
computer. You can use it to connect devices such as keyboards, mice, USB flash
drives, and wireless network cards. When the number of USB ports is not enough, we
can also increase the number of USB ports through a USB hub.
(5) Audio port:
Audio interface (3.5mm headphone jack) When HDMI connection is not used,
you can use the standard 3.5mm headphone jack speakers or headphones to play audio.
At the same time, the interface also integrates a composite video interface with a
composite audio and video output function, which is generally used to connect to old
models of TVs, and is currently rarely used.
(6) MIPI CSI camera port:
The CSI interface can be used to connect the CSI camera to the Raspberry Pi via
a ribbon cable for easy video recording and image capture. Compared with the USB
camera, this camera module has better performance.
(7) USB-C 5V/3A power supply port:
The Micro USB power supply interface is one of the main power supply methods
of the Raspberry Pi. The rated voltage is 5V. The standard current requirements of
different versions of the Raspberry Pi are slightly different. For example: the 1B type
only needs 700mA, and the 3B+ type requires 2.5A. The chargers of many Android
mobile phones can provide the necessary voltage and current for the Raspberry Pi.
5
The current demand of the Raspberry Pi is also related to the connected external
device. It is recommended that it should be calculated in advance when using it.
Choose a suitable current (power) power supply for the Raspberry Pi. When the
external device has a large power, an independent power supply should be used Power
supply for external devices.
(8) Micro SD card slot:
The SD card slot is located on the back of the Raspberry Pi motherboard. The
SD/MicroSD card is an essential storage part of the Raspberry Pi. It is used to install
the operating system and store data. The capacity of the SD card should be above
2GB. In order to have a better experience, it is recommended to equip your Raspberry
Pi with a large-capacity (above 16G) high-speed (Class10 or above) SD card.
(9) Bluetooth port:
The Bluetooth function allows the Raspberry Pi to connect with
Bluetooth-enabled devices (such as a mouse, keyboard, and handle).
(10) PoE HAT port:
Active Ethernet (Power Over Ethernet, PoE) refers to a technology that uses
Ethernet for power transmission. On the basis of the original Micro USB and GPIO
power supply, the Raspberry Pi 3B+ type adds a new power supply method over
Ethernet. Users can use the network cable to supply power to the Raspberry Pi
without the need to configure an additional power supply, which is convenient for
certain application scenarios.
(11) MIPI DSI display port:
You can connect the LCD display to the Raspberry Pi, which is generally used
for embedded product development. Under normal circumstances, the HDMI
interface can already meet the demand.
(3)Operating system
(4)Programming language
For the Raspberry Pi, there are many programming languages available. In fact,
any language that can be compiled for the ARM architecture (such as the C language)
can be used for the Raspberry Pi. The most popular language should be Python. In
7
fact, the Pi in the name of the Raspberry Pi was inspired by the word Python. Python
is an interpretive, object-oriented, and dynamic data type high-level programming
language with powerful functions, good compatibility, and high reliability. Python
programs are easy to write and read. At present, there are two major versions of
Python: Python 2 and Python 3. Both versions have been updated and maintained, but
people still have disputes about which version to use. You can visit Python's official
website (www.python.org) to understand more related content, in the future we will
mainly use Python 3 for development introduction. In addition, because the
compatibility of the Raspberry Pi is splendid, the program we wrote on the 3B+
model can be run on the Zero W model with little modification.
2. Introduction to GPIO
8
Any of the GPIO pins can be designated (in software) as an input or output pin
and used for a wide range of purposes.
Note: the numbering of the GPIO pins is not in numerical order; GPIO pins 0 and
1 are present on the board (physical pins 27 and 28) but are reserved for advanced use
(see below).
Voltages
Two 5V pins and two 3V3 pins are present on the board, as well as a number of
ground pins (0V), which are unconfigurable. The remaining pins are all general
purpose 3V3 pins, meaning outputs are set to 3V3 and inputs are 3V3-tolerant.
Outputs
A GPIO pin designated as an output pin can be set to high (3V3) or low (0V).
Inputs
A GPIO pin designated as an input pin can be read as high (3V3) or low (0V).
This is made easier with the use of internal pull-up or pull-down resistors. Pins
GPIO2 and GPIO3 have fixed pull-up resistors, but for other pins this can be
configured in software.
More
As well as simple input and output devices, the GPIO pins can be used with a
variety of alternative functions, some are available on all pins, others on specific pins.
-PWM (pulse-width modulation)
-Software PWM available on all pins
-Hardware PWM available on GPIO12, GPIO13, GPIO18, GPIO19
9
-SPI
-SPI0: MOSI (GPIO10); MISO (GPIO9); SCLK (GPIO11); CE0 (GPIO8),
CE1 (GPIO7)
-SPI1: MOSI (GPIO20); MISO (GPIO19); SCLK (GPIO21); CE0 (GPIO18);
CE1 (GPIO17); CE2 (GPIO16)
-I2C
-Data: (GPIO2); Clock (GPIO3)
-EEPROM Data: (GPIO0); EEPROM Clock (GPIO1)
-Serial
-TX (GPIO14); RX (GPIO15)
GPIO pinout
It's important to be aware of which pin is which. Some people use pin labels (like
the RasPiO Portsplus PCB, or the printable Raspberry Leaf).
10
For more details on the advanced capabilities of the GPIO pins see gadgetoid's
interactive pinout diagram.
11
【Form description】:
(1) Three naming (coding) methods for Raspberry Pi pins
Three ways to name the Raspberry Pi pins:
The WiringPi number is the pin number of the functional wiring (such as TXD,
PWM0, etc.); the BCM number is the Broadcom pin number, also known as GPIO;
the physical number is the number corresponding to the physical location of the pin
on the Raspberry Pi motherboard (1 ~40).
(2) 3.3V/5V pin and GND pin
3.3V/5V pin and GND pin are commonly known as power and ground pins. The
power and ground pins allow your Raspberry Pi to power some external components,
such as LED lights. It should be noted that before using these pins to power any
external modules or components, care should be taken. Excessive operating current or
12
peak voltage may damage the Raspberry Pi. Do not use voltages greater than 5V!
(3) SDA and SCL pins
The SDA and SCL pins constitute the I2C interface. I2C is a simple, bidirectional
two-wire synchronous serial bus developed by Philips. It only requires two wires to
transfer information between devices connected to the bus. The Raspberry Pi can
control multiple sensors and components through the I2C interface. Their
communication is done through SDA (data pin) and SCL (clock speed pin). Each
slave device has a unique address, allowing rapid communication with many devices.
The ID_EEPROM pin is also an I2C protocol, which is used to communicate with
HATs.
(4) SCLK, MOSI and MISO pins
SCLK, MOSI and MISO pins form the SPI interface. SPI is a serial peripheral
interface, used to control components with a master-slave relationship, and works in a
slave-in, master-out and master-in-slave manner. The SPI on the Raspberry Pi consists
of SCLK, MOSI, and MISO interfaces, and SCLK is used for controlling data speed,
MOSI sends data from the Raspberry Pi to the connected device, while MISO does
the opposite.
(5) TXD and RXD pins
TXD and RXD form a UART interface. TXD is a pin to send data, and RXD is a
pin to receive data. A friend who uses Arduino must have heard of UART or Serial.
The Universal Asynchronous Receiver/Transmitter interface is used to connect the
Arduino to the computer for which it is programmed. It is also used for
communication between other devices and the RX and TX pins. If the Raspberry Pi
has a serial terminal enabled in raspi-config, you can use these pins to control the
Raspberry Pi through a computer or directly to control the Arduino.
13
Introduction of Robot HAT Driver Board
When you get the RaspArmS product, you will see a board with its name printed
on it called: Adeept Robot HAT, which is an important part of RaspArmS. There are
many interfaces on the Robot HAT driver board. By these interfaces, you can connect
some sensors and electronic hardware modules, so that you can achieve many
extended functions. Our RaspArmS products need to be used in conjunction with the
Raspberry Pi. Let's first get to know the Robot HAT driver board.
14
on.
【Tracking】 is the pin interface of Tracking Module.
【WS2812】 is the pin interface of WS2812 Module.
【3.3V-GND】 3.3V power supply interface.
【Uart】 Uart interface.
【GPIO 40-PIN】 General Purpose Input Output (GPIO) is designed as a slot with
two rows of pins on the Robot HAT driver board. GPIO can be used to connect
various peripheral electronic devices and sensors and control or monitor these devices
with input/output level signals. In Alter products, this GPIO interface is connected to
the GPIO pins on the Raspberry Pi driver board.
【5V-GND】 5V power supply interface.
【IIC】IIC interface. It is also the interface of the OLED screen module.
【MPU6050】The interface of MPU6050 sensor.
【Port】is divided into Port1, Port2, and Port3 interfaces, which are commonly used
to connect Small LED light.
【Servo port】Servo interface.
【motor】 is divided into motor1, motor2 interfaces.
【Ultrasonic】Ultrasonic interface.
16
Lesson 1 Installing and Logging in to the
Raspberry Pi System
In this lesson, we will learn how to install and remotely log in to the Raspberry Pi
system under Windows. And we will download the code program to control the robot.
1.1 Preparation
(1) When studying this lesson, you need to prepare the following components
first:
One SD card that has been formatted (we recommend using an SD card with
memory above 16G), 1 card reader, Raspberry Pi development board.
(2) You need to insert the SD card into the card reader first, and then connect the
card reader to the computer.
17
(2) We need to find out the Raspberry Pi OS (32-bit) with desktop and
recommended software. It contains a complete desktop system and recommended
software packages.
18
(3) Choose to download the ".ZIP" file and wait for the download to complete:
(4) Find the ".ZIP" file you just downloaded, double-click to open it, and extract
it. The uncompressed file format of the file is ".img". Pay attention, you must name
the path of the uncompressed .img file all English letters without special
19
characters.
20
(2) Open the downloaded file "imager.exe" and click "Install".
21
1.3.2 Burning Raspberry Pi system to SD card with Raspberry
Pi Imager
(1) Click "CHOOSE OS" on the opened Raspberry Pi Imager software
interface.
22
(2) Click "Use custom" and select a custom ".img" file from your computer,
which is the ".img" file of the Raspberry Pi system that we downloaded and
decompressed before.
(3) Find the ".img" file of the Raspberry Pi system that we downloaded and
decompressed before. Click "Open".
23
(4) Select the ".img" file and click "Open".
(5) Then on the interface of Raspberry Pi Imager, the ".img" file of our selected
Raspberry Pi system will appear.
24
(7) Then select the SD card we need to burn.
(8) Click "WRITE" to write it to the SD card. Wait for the burn to complete.
25
(9) After the burning is completed, the following message will be
prompted,indicating that the burning is finished, click "CONTINUE".
【Pay Attention】
Don't remove the SD card after burning! After the Raspberry Pi Imager is burned,
the memory card will be ejected in the program. This will cause the subsequent copy
26
operation to prompt that the SD card has not been found. You can unplug the card
reader from the computer and then plug it into the computer again.It is necessary to
configure SSH and WIFI connection later. At this time, once the SD card is put into
the Raspberry Pi to boot, it may cause subsequent headless WIFI configuration
failure.
SSH is a protocol designed to provide security for remote login sessions and other
network services. Through the SSH service, you can remotely use the command line
of the Raspberry Pi on another machine. In the subsequent operations and the process
of using the Raspberry Pi, you can control the Raspberry Pi through another machine
in the same local area network without connecting the mouse, keyboard and monitor
to the Raspberry Pi. After 2016, Raspbian distributions disable the SSH service by
default, so we need to manually enable it.
(1) We first enter the driver D of the computer, click "View" in the upper left
corner, and select "File Extension", as shown below:
(2) Right-click on the blank space of the D drive, select "New", and select "Text
Document".
27
(3) Name the file "ssh", as shown below:
(4) Then delete the suffix ".txt". We will get an ssh file without any extension. As
shown below:
(5) Copy this ssh file to the root directory of the SD card of the Raspberry Pi
system. When the Raspberry Pi starts, it will automatically find this ssh file. If it is
found, it will start SSH. This method only needs to be used once. After that, every
time you start the Raspberry Pi, it will automatically start SSH without repeating the
above operations. Copy the ssh file to the Raspberry Pi as shown below:
(2) Click to select the wpa_supplicant.conf file, right-click the mouse, and select
"Open Mode (H)".
29
update_config=1
network={
ssid="WIFI"
psk="PASSWORD"
key_mgmt=WPA-PSK
priority=1
}
"Country" is your country code, do not modify it, the default is US; "ssid" needs
to be changed to the name of the WIFI you want to connect; "psk" needs to be
changed to the password of the WIFI you want to connect; other parts do not need to
do any modifications.
For example, our company's WIFI name is Adeept, WIFI password is 123456, and
the modified wpa_supplicant.conf file is as shown below:
(5) Save the set wpa_supplicant.conf file, and then copy it to the root directory of
30
the SD card of the Raspberry Pi system. As shown below:
(6) Now we can take out the SD card and put it into the "MICRO SD CARD"
card slot on the Raspberry Pi development board, and use the Type-C data cable to
supply power to the Raspberry Pi. And then the Raspberry Pi will start up and
run.
31
MobaXterm is a terminal tool software that can be used to remotely control the
Raspberry Pi.
(1)Log in to the official website through a browser to download:
https://mobaxterm.mobatek.net/download.html.
Select Free version to download.
32
(4) Open the unzipped folder, there is a file MobaXterm_Personal_20.2.exe.
33
(5) One Raspberry Pi
34
Turn on the monitor switch, and connect the mouse to the USB port of the
Raspberry Pi, supply power to the Raspberry Pi with the Type-C data cable, then the
Raspberry Pi starts. After entering the system interface, we move the mouse cursor to
the " " in the upper right corner, then it will display the
IP address of the Raspberry Pi: 192.168.3.157 (the IP address of each Raspberry Pi is
different). It is necessary for you to record this IP address for it is needed to log in to
the Raspberry Pi system later.
35
2. You can also open the command window of the Raspberry Pi and enter the
following command to view the following IP address, you need to write it down:
hostname -I
2. After the download is complete, your phone and Raspberry Pi need to be in the
same local area network, that is, your phone and Raspberry Pi are connected to the
same WIFI, then open "Fing" and click "Scan for devices":
36
Click“CONTINUE WITHOUT PERMISSION”:
Click OK:
37
3. Wait for the scan to complete. In the list, you find a device named "Raspberry
Pi". In the lower left corner, you will see the IP address of the Raspberry Pi:
192.168.3.157. You need to write down this IP address.
38
(2) Click "Session" in the upper left corner.
39
(4) Enter the IP address of the Raspberry Pi previously queried: 192.168.3.157,
and confirm with "OK".
(5) Enter the default account of Raspberry Pi: pi, then press Enter, and then enter
the default password of Raspberry Pi: raspberry. Press Enter to log in to the Raspberry
Pi system.
40
(6) After successfully logging into the Raspberry Pi system, the following
interface will appear as shown below:
(7) The red box in the figure below is the command window, where you can
control the Raspberry Pi by entering commands.
41
(8) When we close the MobaXterm software and then open it to connect to the
Raspberry Pi, we can double-click the IP address under the "User sessions" on the left:
192.168.3.157, enter the account name: pi. Then the Raspberry Pi will be directly
connected.
42
Lesson 2 Downloading and Installing the Relevant
All the code programs of our robot products have been open sourced on GitHub.
You need to download them to the Raspberry Pi and install the relevant dependencies
before they can run normally.
After successfully logging in to the Raspberry Pi, we need to download the code
program to control the robot, and enter the following command in the console:
sudo git clone https://github.com/adeept/adeept_rasparms.git
After successfully downloading, you will see a new folder adeept_rasparms in the
file resource list on the left. This folder stores some very important program codes.
We will teach you how to use it in detail in the following courses.
43
2.2 Installing the relevant dependency libraries of the
robot
Press the "Enter" button and wait for the download and installation to complete.
2. After the download is complete, the following prompt will appear:
44
prompt.
Raspberry Pi will automatically run the program of the robot product every time
it restarts. Specifically, every time it restarts, it will run
[RobotName]/server/webServer.py. Replace [RobotName] with the name of your
robot product program folder, but if without connecting the Raspberry Pi camera and
the driver board RobotHAT, webServer.py will not run successfully. This is a normal
phenomenon, because the program of the robot product needs to use the camera and
the PCA9685 chip. Our RobotHAT uses PCA9685 to control the servo.Raspberry Pi
communicates with PCA9685 with I2C. If RobotHAT is not installed on Raspberry Pi,
communication failure will occur when instantiating PCA9685's dependent library,
which will cause program error.
We can turn off the Raspberry Pi, install the camera module and RobotHAT, and
turn it on again, so that webServer.py can run successfully.
Under normal circumstances, there is no need for people to manually run
webServer.py, because every time the Raspberry Pi is turned on, webServer.py will be
run automatically.
You can open Google Chrome, enter the IP address of the Raspberry Pi and add:
5000 after it, press enter to jump to the Raspberry Pi web page, an example is shown
below:
http://192.168.3.157:5000
If the page fails to open, you can log in to the Raspberry Pi by using SSH, and
use the following command to end the robot program that automatically runs on
startup to release resources. Otherwise, problems such as camera initialization failure
or port occupation will occur. Enter the following command in the command window:
sudo killall python3
Use the following command to manually run webServer.py:
sudo python3 adeept_rasparms/server/webServer.py
45
2.4 Editing the code program in Raspberry Pi
To view and edit the code program in the Raspberry Pi on the MobaXterm
terminal software, we provide two methods for reference.
The first is to use Linux commands. For example, if you need to view the code
program LED.py in this section of the course, then you can enter the following
commands in the console of the MobaXterm terminal:
sudo nano LED.py
1. In this way, you can view our code program. You can modify and edit the
code with the direction keys on the keyboard to realize the control function you want.
But you need to learn and search about the command operation method of Linux nano.
Here we provide several common operation commands about nano:
1. To save the modified program, you need to press the shortcut key Ctrl+O on the
keyboard
2. To exit the code editing interface, you need to press the shortcut key Ctrl+X on
the keyboard
3. To cut a line of code, you can use Ctrl+K
4. Paste the code, you can use Ctrl+U
46
The second method is to use a third-party IDE tool to view and edit the code
program of this lesson. You can find the file you want to edit in the file resource
management system on the left side of MobaXterm, right-click the file, and click
Open with , Choose your IDE, we recommend you to use Sublime Text IDE, you need
to download it to edit files in the Raspberry Pi After editing:
http://www.sublimetext.com/3. In this way, you can use your favorite IDE to edit the
files in the Raspberry Pi. After editing, CTRL+S can save the files.
47
When you need to save the modified file, you can press the shortcut key CTRL+S,
and then select Yes or Yes to all.
48
49
Lesson 3 Creating a WiFi Hotspot on Raspberry Pi
The method of turning on the WIFI hotspot in our robot product uses a project
from GitHub create_ap. Our installation script will automatically install this program
and related dependent libraries. If you have not run our installation script, you can use
the following command to install create_ap:
sudo git clone https://github.com/oblique/create_ap.git
cd create_ap
sudo make install
1.Install related dependent libraries:
sudo apt-get install -y util-linux procps hostapd iproute2 iw haveged dnsmasq
2.Before turning on the hotspot, your Raspberry Pi cannot be connected to WIFI,
and the WIFI module cannot be turned off, so when you test the hotspot function, you
need to connect the necessary peripherals for the Raspberry Pi.
3.Under normal circumstances, if the robot program is not connected to the WIFI
when it is turned on, it will automatically turn on the hotspot. You can use your phone
or computer to search for the WIF named Adeept. The default password is 1234. Once
the connection is successful, you can log in to 192.168 .12.1: 5000 using a browser to
open the WEB application to control the robot.
4.If your Raspberry Pi is connected to peripherals, and you want to test the
Raspberry Pi ’s ability to turn on hotspots, you can click the WIFI icon in the upper
right corner of the Raspberry Pi ’s desktop, click the name of the connected WIFI,
click forget, and never turn Off WIFI, if it is already in the off state, you need to turn
it on.
5.When the WIFI module of the Raspberry Pi is turned on and is not connected to
any known network, you can enter the following command:
sudo create_ap wlan0 eth0 Adeept 1234
Adeept is the name of the WIFI hotspot, 1234 is the password of the WIFI
hotspot.
50
Lesson 4 Downloading and Installing Python
The course sample code programs of the RaspArm-S robot are all based on
Python. Some courses need to use the Python development environment, so you need
to download Python before learning the course. Below is a tutorial for downloading
and installing Python on Windows 10.
(2) Click the "Download Python 3.8.3" button to download and wait for the download
to complete:
(6) Wait for the Python installation to complete and click "Close" to close.
52
(7) Check whether Python is installed successfully. Press the shortcut key Win+R,
then enter cmd in the run bar, click OK to open the command window:
(8) In the command line window, enter python, then press Enter, the version number
checked is consistent with the version number downloaded and installed.
53
(9) Enter 1+1 to see if it can run to calculate the correct result.
54
Lesson 5 Displaying Text on the OLED Screen
In this lesson, we will learn how to display text on the OLED screen.
Raspberry Pi 1
Robot HAT 1
4 pin wire 1
OLED screen 1
55
interface to connect the OLED screen to the IIC interface on the Robot HAT.
If you do not use Robot HAT driver board to connect with Raspberry Pi driver
board, then you need to connect Vin of OLED screen to 5V or 3.3V of Raspberry Pi,
and connect GND of OLED screen to GND of Raspberry Pi. Connect SCL of Robot
HAT to SCL of OLED, and SCA of Robot HAT to SCA of Raspberry Pi. Please refer
to the pin definition diagram of Raspberry Pi for specific pins.
If you want to use the OLED Screen module, you need to connect the IIC
interface on the Robot HAT driver board, as shown in the figure below:
56
5.4 How to display text on the OLED screen
57
3. The relevant code programs of the RaspArm-S robot are stored in the
adeept_rasparms folder, which has been explained in "2.1 Downloading the code
program for controlling the robot" in Lesson 2. First, you need to enter a command
with the command window of the Raspberry Pi to enter the folder where the course
code is stored: CourseCode, this folder stores the sample code program for each
course, enter the following command:
cd adeept_rasparms/CourseCode
5. The 01OLEDtext folder contains the sample code of this lesson. Enter the
command to enter this folder:
cd 01OLEDtext
58
7. OLEDtext.py is a python program. When using the OLED Screen module, we
need to install the Python dependent library needed to control the OLED screen,
called luma.oled library, and enter the following commands in the console of the
command window:
sudo pip3 install luma.oled
If a download timeout warning appears, you can download the luma.oled library
by adding a image source, and enter the following command:
sudo pip3 install luma.oled -i https://pypi.tuna.tsinghua.edu.cn/simple/
9. After successfully running the program, you will observe that "ROBOT" will
be displayed on the OLED screen.
10. If you want to terminate the running program, you can press the shortcut key
Ctrl+C on the keyboard.
59
After the above hands-on practice, you already know how to use and run our
course sample code program. You must be curious about how our code program is
programmed to display text on OLED screen on the Raspberry Pi. Let’s get to know
the main code program.Here we use Subline IDE to view and edit the code program
of this lesson. For the specific method, please see the content of Lesson 2: "2.4
Editing the code program in Raspberry Pi". In the file manager of the MobaXterm
terminal, find adeept_rasparms/CourseCode /01OLEDtext, open the code of this
lesson: OLEDtext.py.
1. First import the library used to control the OLED screen.
4. Display the text "ROBOT" at the position (0, 20) on the OLED screen.
60
Lesson 6 Playing Animation on the OLED Screen
In this lesson, we will learn how to play animation on the OLED screen..
Raspberry Pi 1
Robot HAT 1
OLED screen 1
4 pin wire 1
61
interface to connect the OLED screen to the IIC interface on the Robot HAT.
If you do not use Robot HAT driver board to connect with Raspberry Pi driver
board, then you need to connect Vin of OLED screen to 5V or 3.3V of Raspberry Pi,
and connect GND of OLED screen to GND of Raspberry Pi. Connect SCL of Robot
HAT to SCL of OLED, and SCA of Robot HAT to SCA of Raspberry Pi. Please refer
to the pin definition diagram of Raspberry Pi for specific pins.
1. The OLED screen can display images, and the image format needs to be PPM
format.
62
2. The principle of animation is to play multiple images per second.
3. First, draw a few pictures in jpg format (the ones you want to display) in the
PC and put them in the same folder (jpg). Note that these pictures need a pure black
background.
4. Then create a new folder named ppm.
5. Finally, create a new ppmGenout.py outside the folder, this program is
responsible for generating PPM sequence strings.
6. It is also necessary to create another oledPlay.py, which is responsible for
playing the PPM sequence string that has been generated.
7. This program can be executed on Raspberry Pi or other computers, and
Python3 and pillow library need to be installed.
When the OLED Screen module is in use, it needs to be connected to the IIC
interface on the Robot HAT driver board, as shown below:
63
2. Log in to your Raspberry Pi (the way to log in to Raspberry Pi has been
introduced in Lesson 1):
3. The relevant code programs of the RaspArm-S robot are stored in the
adeept_rasparms folder, which has been explained in "2.1 Downloading the code
program for controlling the robot" in Lesson 2. First, you need to enter a command
with the command window of the Raspberry Pi to enter the folder where the course
code is stored: CourseCode, this folder stores the sample code program for each
course, enter the following command:
cd adeept_rasparms/CourseCode
64
5. The 02OLED_Cartoon folder contains the sample code of this lesson. Enter the
command to enter this folder:
cd 02OLED_Cartoon
7. It can be found that there are four files.These are the reference cases we
provide.If you want to realize your own creativity, you can also imitate this method.
The "jpg" folder is to store pictures in jpg format that have been drawn (if you want to
play other pictures, then you can put the pictures in this folder). Note that these
pictures need a pure black background; "ppm" is a folder that needs to be established,
named ppm, and the inside is empty; "ppmGenout.py" is a python program that
generates PPM sequence strings from pictures in jpg format. After running it, a
sequence string in ppm format will be generated in the "ppm" folder. "OledPlay.py" is
a code program for playing PPM sequence strings.
2. First, you need to run ppmGenout.py to generate the PPM sequence string.
Enter the following command to run the ppmGenout.py program on the Raspberry Pi:
sudo python3 ppmGenout.py
3. Then in the file explorer on the left side of MobaXterm, open the folder "ppm"
65
of this lesson in the adeept_rasparms/CourseCode/02OLED_Cartoon directory. This
folder was empty before. After you successfully run the ppmGenout.py program After
that, many ppm sequence strings will be generated inside, as shown below:
2. Then continue to download the driver library of the OLED Screen module:
Adafruit_SSD1306, enter the following command:
66
sudo pip3 install Adafruit_SSD1306
3. After successfully generating the PPM sequence string, you need to run the
oledPlay.py program again, so that the animation will be displayed on the OLED
screen:
sudo python3 oledPlay.py
4. After running the program successfully, you will observe that an animation will
be played on the OLED screen.
5. When you want to terminate the running program, you can press the shortcut
key Ctrl+C on the keyboard.
After the above hands-on practice, you already know how to use and run our
course sample code program. You must be curious about how our code program is
programmed to play animation on OLED screen on the Raspberry Pi. Let’s get to
know the main code program.We use Sublime IDE to view and edit the code program
of this lesson. For details, please refer to the content of Lesson 2: "2.4 Editing the
Code Program in Raspberry Pi". In the file manager of the MobaXterm terminal, find
adeept_rasparms/CourseCode/02OLED_Cartoon, and open the code of this lesson:
ppmGenout.py and oledPlay
67
Get the file names of all jpg images in the jpg folder.
Convert the pictures in the "jpg" folder one by one. First open a jpg image.
Delete the suffix .jpg from the original name, and re-modify it to the suffix .ppm,
so that it becomes a file of ppm sequence.
oledPlay.py
Import OLED screen related libraries.
68
Set the playback frame rate.
Calculate the delay time per frame according to the playback frame rate.
Import these frames, then open the file in PPM format and binarize it with
convert('1'); store the converted image into LaughImage.
69
Lesson 7 How to Control 180° Servo
Raspberry Pi 1
Robot HAT 1
180°Servo 1
What is a servo?
The servo is a position (angle) servo driver, which is suitable for those control
systems that require constant angle changes and can be maintained. It has been widely
used in high-end remote control toys, such as airplanes, submarine models, and
remote control robots.
We use a 180° servo in this lesson, which can move between 0° and 180°. It is
used in the RaspArm-S robot products. Since the 180° servo can use the PWM signal
to control the rotation angle of a certain mechanism, it is a more commonly used
module in robot products. The walking robot, robotic arm and pan/tilt are all driven
by it.
On the Raspberry Pi driver board Robot HAT, there is a PCA9685 chip specially
used to control the servo. The Raspberry Pi uses I2C to communicate with the
PCA9685. It controls the servo by sending pulse signals from the microcontroller.
These pulses tell the servo mechanism of the servo where to move. The picture of the
70
180° servo is as follows:
71
7.4.1 Run the program of this course
3. The relevant code programs of the RaspArm-S robot are stored in the
adeept_rasparms folder, which has been explained in "2.1 Downloading the code
program for controlling the robot" in Lesson 2. First, you need to enter a command
with the command window of the Raspberry Pi to enter the folder where the course
code is stored: CourseCode, this folder stores the sample code program for each
course, enter the following command:
cd adeept_rasparms/CourseCode
72
4. Enter the command to display the contents of the current directory:
ls
5.The 03Servo180 folder stores the sample code of this course. Enter the
command to enter this folder:
cd 03Servo180
9. After successfully running the program, you will observe that the servo will
rotate regularly.
10. If you want to terminate the running program, you can press the shortcut key
Ctrl+C on the keyboard.
The code in the figure above is for the program 180Servo_01.py.In the above
code, set_pwm_freq(50) is used to set the frequency of PWM to 50Hz. This setting
depends on the model of the servo. The servo used by our robot products needs to be
controlled by a 50Hz PWM signal. If you use other servos, we need to refer to the
specific servo documentation to set this value.
pwm.set_pwm(3, 0, 300) is used to control the rotation of a servo to a certain
position. 3 is the port number of the servo, which corresponds to the number marked
on the RobotHAT drive board.Pay attention to the occasion that do not insert the
ground wire, VCC and signal wire in the reverse direction when connecting the servo
with the driver board. Brown to black, red to red, and yellow to yellow; 0 is the
deviation value for controlling the rotation of the servo, but our program does not use
this function to correct the deviation (the reason for the error of the servo can be
referred to 4.2 precautions for structural assembly); 300 is the PWM duty cycle value
to be set. Depending on the servo, the servo angle represented by this value is also
74
different. The PWM duty cycle range of the servo we use is about 100 to 560, which
corresponds to a rotation range of about 0° to 180°.
The above code cannot control the rotation speed of the servo. If we want a servo
to slowly reciprocate between two positions, we need to use the method of increasing
or decreasing the variable to control it.
Using the above code can make the servo rotate slowly back and forth between
300 and 400, but this method of controlling the servo also has great drawbacks. When
the program is executed to the slow motion part of the servo, it will be blocked, which
will seriously affect the program. Therefore, a multi-threaded solution is provided in
our robot product program to solve this problem.
75
Lesson 8 Simple TCP Communication
76
8.3 How to remotely control Servo
77
3. The relevant code programs of the RaspArm-S robot are stored in the
adeept_rasparms folder, which has been explained in "2.1 Downloading the code
program for controlling the robot" in Lesson 2. First, you need to enter a command
with the command window of the Raspberry Pi to enter the folder where the course
code is stored: CourseCode, this folder stores the sample code program for each
course, enter the following command:
cd adeept_rasparms/CourseCode
5. The 04TCP_servo folder contains the sample code of this lesson. Enter the
command to enter this folder:
cd 04TCP_servo
78
7. tcpPC.py needs to be run on the PC, you need to modify the IP
8. Then run the tcpPI.py program on the Raspberry Pi, and directly enter the
following commands to run this program on the Raspberry Pi:
sudo python3 tcpPI.py
9. After successfully running the program, you also need to run the tcpPC.py
program on the PC. You need to change the IP inside to the IP of your Raspberry Pi,
so that the connection can be established.
1. In the directory:
adeept_asparms/CourseCode/04TCP_servo
Download the file tcpPC.py to the PC and remember the path of this file.
79
2. Use MobaXterm or other IDE to open the tcpPC.py file on your computer. You
need to modify the IP address in the SERVER_IP line of code and change it to the IP
of your Raspberry Pi (please check the IP address of the Raspberry Pi in lesson one),
so that the PC can establish a connection with the Raspberry Pi.
3. After the modification is completed, you can directly double-click to open the
tcpPC.py file. After opening, as shown below, there are two buttons "ON" and "OFF".
When you click the "ON" button, the servo will rotate; when you click the "OFF"
button, the servo will stop rotating.
Define a flag fun_flag to control the servo; then use multi-thread to control the
servo.
Start monitoring the client connection, and start receiving the information sent
from the client after the client connection is successful.
Receive the information from the client, if the information content is on, the servo
rotates, if the information content is off, the servo stops rotating.
81
Finally, print out the received data, and continue to monitor the next message sent
by the client.
Python uses Tkinter to quickly create GUI applications and instantiate them while
importing them.
Call this method to send the command'on' to control the rotation of the servo.
Enter the IP address of the Raspberry Pi here (you need to change it to your
Raspberry Pi IP address when you use it).
82
defined by the server in the Raspberry Pi.
Use Tkinter's Button method to define a button, the button is on the root window,
the name on the button is 'ON', the text color of the button is #E1F5FE, and the
background color of the button is #0277BD. When the button is pressed, it will call
lights_on( )function.
Define another button in the same way. The difference is that the text on the
button is changed to'OFF'. When the button is pressed, the lights_off() function is
called.
83
Lesson 9 Multithreading OLED Screen Control
In this lesson, we will use multithreading to display text and other information on
the OLED screen.
84
If you do not use Robot HAT driver board to connect with Raspberry Pi driver
board, then you need to connect Vin of OLED screen to 5V or 3.3V of Raspberry Pi,
and connect GND of OLED screen to GND of Raspberry Pi. Connect SCL of Robot
HAT to SCL of OLED, and SCA of Robot HAT to SCA of Raspberry Pi. Please refer
to the pin definition diagram of Raspberry Pi for specific pins.
9.2 Preparation
You need to prepare a robot in the RaspArm-S that has been assembled, and make
sure that the robot has been connected to the OLED Screen module.
85
9.3 Using multithreading to display text on OLED
Screen
Set to True.
Resume the thread from the suspended state, if it has been suspended.
Set to False.
Call this function to control the OLED screen. Position is the number of the line
where you want to change the content, can be 1-6, text is the content.
87
Set the content of the first line to 12345678.
Since the above operation will not block the thread, we need to loop here to avoid
the program exit after the execution is complete.
88
3. The relevant code programs of the RaspArm-S robot are stored in the
adeept_rasparms folder, which has been explained in "2.1 Downloading the code
program for controlling the robot" in Lesson 2. First, you need to enter a command
with the command window of the Raspberry Pi to enter the folder where the course
code is stored: CourseCode, this folder stores the sample code program for each
course, enter the following command:
cd adeept_rasparms/CourseCode
89
7. When using the OLED Screen module, we need to install the Python dependent
library needed to control the OLED screen, called luma.oled library, and enter the
following commands in the console of the command window:
sudo pip3 install luma.oled
8. OLED.py is the sample code for this lesson, enter the command to run this
program:
sudo python3 OLED.py
9. After running the program successfully, you will see some text messages on
the OLED screen of the robot.
90
Lesson 10 RaspArm-S Assembly Tutorial
In this lesson, we will learn how to assemble the RaspArm-S robotic arm. It has
two forms of structure. The first form is a robotic arm that can grip objects. For the
assembly tutorial, please refer to "10.2 RaspArm-S Robotic Arm Assembly Tutorial"
in this lesson. "; The second form is a robotic arm that can be transformed into a
"writing pen". For the assembly tutorial, please refer to "10.3 RaspArm-S Writing Pen
Robotic Arm Assembly Tutorial" in this section of the course.
Before assembling, you need to prepare the parts used for assembling the
RaspArm-S robot arm according to "10.1 Parts List".
Electrical parts
Name Quantity
91
AD002 servo 4
Copper pillar
Name Quantity
M2.5x10+6 12
M3x18 8
M4x22 4
M2.5x14 4
Screw
Name Quantity
M4x6 4
M2.5x8 11
M2.5x10 1
M2x8 20
M3x10 24
Nut
Name Quantity
M2 20
M3 10
Wire
92
Name Quantity
4pin wire 1
Mechanical Parts
Name Quantity
Sucker 4
Tool
Name Quantity
Winding Pip 1
Own parts
Name Quantity
18650 battery 2
Raspberry Pi 3B/Raspberry Pi 4 1
93
In order to make the structural assembly process more intuitive, we dye the
screws used in the product. During the assembly process, you can refer to the color of
the fastener in the tutorial to determine which type of screw and nut to use.
The actual color of the product is subject to the product, and the actual screws
are not colored.
Acrylic part name (the number in the figure is for the convenience
94
of explaining the assembly and marking)
(1) Use 4 M4x6 Screws and 2 M3 Nuts to install on the acrylic part A01 as shown
in the figure below.
(2) Use 2 M3x8 Countersunk head screws to install the 18650 battery holder on
95
the acrylic part A01.
(3) Install 4 M4x22 Copper standoffs under the acrylic part A01.
Then install 4 sucker on the M4x22 Copper standoff.
96
Then install 4 M2.5x10+6 Copper standoffs on the M2.5x8 Screw.
97
(6) Install the RobotHAT driver board on the Raspberry Pi, and pay attention to
the alignment of the GPIO pin ports.
98
Then use 4 M2.5x10+6 Copper standoffs to connect and fix.
(8) First use 4 M2x8 Screws and 4 M2 nuts to fix the 0.96 OLED screen on the
acrylic part A02. Note the orientation of the 0.96 OLED screen.
99
(9) Place the aluminum alloy part L04 on the acrylic part A02, the holes need to
be aligned, and then use 4 M3x10 Screws and 4 M3 Nuts to fix L04.
Wiring method
When assembling to this step, you need to consider how to wire in advance.
First, you need to connect the external power cord to the Vin interface of the
RobotHAT driver board;
Use the 5pin wire to connect the rotary encoder switch to the Track interface of
the RobotHAT drive board;
Use a 4pin wire to connect the 0.96 OLED screen to the IIC interface of the
RobotHAT driver board;
Connect the AD002 servo to the Servo interface. In our course example, the 4
servos are divided into A, B, C, D from bottom to top, and the 4 servos A, B, C, D are
connected to Servo respectively on pins 12, 13, 14, and 15 of the interface, pay
attention to the color alignment when wiring, otherwise the wiring will be reversed.
100
The figure below is the structure diagram of the servo of the robotic arm.
(10) Use 4 M2.5x8 Screws to install the assembled acrylic part A02 above the
RobotHAT drive board.
101
(11) Install the aluminum alloy part L03 on the aluminum alloy part L04, and fix
it with 1 M3x10 Screws and 1 M3 Lock.
(12) Install AD002 servo on L03. The servo needs to be equipped with its own
rocker arm. Use 2 M2x8 Screws and 2 M2 Nuts to fix the servo. The servo number of
this part is A.
102
(13) Rotate L03 to the position as shown in the figure below, and use 1 M2.5x8
Screw and 1 M1.4x6 self-tapping screw that comes with the servo to fix L03.
(14) Install the aluminum alloy part L02 on the L03, and use 1 M3x10 Screw and
1 M3 Lock Nut to fix L02.
103
(15) Install AD002 stervo on L03 as shown in the figure below, and fix AD002
servo with 2 M2x8 Screws and 2 M2 Nuts. The servo number for this part is B.
Then install the rocker arm that comes with the servo to the servo.
104
(16) Install another L02 on the position of the servo as shown in the figure below,
and use 1 M2.5x8 Screw and 1 M1.4x6 self-tapping screw that comes with the servo
to fix L02.
(17) Install another aluminum alloy part L04 on L02 as shown below, and fix L04
with 1 M3x10 Screw and 1 M3 Lock Nut.
105
(18) Install the acrylic part A03 on L04 as shown in the figure below, and use 4
M3x10 Screws and 4 M3 Nuts to fix A03.
(19) Install AD002 servo on L04 as shown in the figure below, and install the
servo rocker arm. The number of this part of the servo in the course is D3, which
106
means the third servo of the robot arm from bottom to top. The servo number for this
part is C.
107
(20) Use 1 M2.5x8 Screw and 1 M1.4x6 self-tapping screw that comes with the
servo to fix L02 on the servo.
(21) Install AD002 servo on A03 as shown in the figure below, pay attention to
the direction of the servo. You need to find 2 M2 Nuts to fix the servos. The servo
number of this part is D.
108
Use 2 M2x8 Screws to fix the servo, and then install the rocker arm that comes
with the servo.
(22) Install the acrylic part A04_a on the rocker arm of the servo and fix it with a
M1.4x6 self-tapping screw that comes with the servo.
109
(23) Use 1 M3x10 Screw to pierce another acrylic part A04_b, and place this
A04_b and the A04_a connected to the servo on the same horizontal line; find 2
M3x10 Screws, 3 M3x18 Copper standoffs, and 1 Acrylic part A05. Place them as
shown in the figure below. When assembling, first install and fix 3 M3x18 Copper
standoffs on the 3 holes on the A03 of the servo, and use 3 M3x10 Screws to fix the
M3x18 Copper standoff. Then install the A05 below on the M3x18 Copper standoff
and fix it with 3 M3x10 Screws. Finally, put two M3x10 Screws into the
corresponding holes, and then install A04_b on the same horizontal line as A04_a.
110
(24) Below A05, you need to use 1 M2.5x10 Screw to insert the hole connected
with the servo, this screw needs to go through A04_a.
111
The two M3 Lock Nuts used to fix A06 should not be installed too tightly,
loosen them slightly. If they are too tight, the robot arm will not be able to grip things.
(26) Install two A07s on A06 and fix them with four M3x10 Screws and four M3
Lock Nuts.
112
10.3 RaspArm-S writing pen robot arm assembly
tutorial
If the shape and structure of the RaspArm-S robotic arm cannot satisfy your more
creativity and ideas, then you can follow the assembly tutorial below to transform it
into a "writing pen" shape robotic arm.
The RaspArm-S writing pen shape manipulator is modified from the shape and
structure of the RaspArm-S manipulator arm, and its chuck is replaced with a
structure that can be equipped with writing pens.
If you did not perform the "10.2" steps to complete the robotic arm assembly,
then you are assembling this robotic arm for the first time. For the first part of the
assembly tutorial, please refer to (1)—(21) Steps in this lesson "10.2 RaspArm-S
Robotic Arm Assembly Tutorial". At step (20), the robotic arm is assembled into the
following form:
113
(22) You need to disassemble the A03 parts marked in the picture, as shown
below:
(22) Then use 2 M3x10 Screws and 2 M3 Nuts to install the disassembled A03
(including the servo) to the side of L04, as shown below:
114
(23) Install the aluminum alloy part L01 on the D servo, and use 1 M2.5x8 Screw
and 1 M1.4x6 self-tapping screw that comes with the servo to fix L01.
(24) Install 2 acrylic parts A08 on L01, pay attention to their placement direction,
and fix them with 4 M2x8 Screws and 4 M2 nuts.
115
(25) After the final assembly is completed, you can use a rubber ring or rope to
fix the pen. Then operate the writing pen robotic arm according to the following
lesson case.
10.3.2 Basing on the robot arm to refit into a writing pen robot
arm
116
If you have installed the robotic arm according to the steps in "10.2" of this
lesson, how do you convert it into a pen robotic arm? Let's modify it together.
(1) First, the chuck part of the robotic arm needs to be disassembled, as the part in
the red circle in the picture below, when disassembling, you need to keep the A03 part
(do not disassemble the servo).
The structure part of A03 that has been disassembled is retained as shown below:
(2) Then use 2 M3x10 Screws and 2 M3 Nuts to install the disassembled A03 part
(including the servo) to the side of L04, as shown in the following figure:
117
(3) Install the aluminum alloy part L01 on the D servo, and use 1 M2.5x8 Screw
and 1 M1.4x6 self-tapping screw that comes with the servo to fix L01.
(4) Install the 2 acrylic parts A08 on L01, pay attention to their placement
direction, and fix them with 4 M2x8 Screws and 4 M2 nuts.
118
(5) After the final assembly is completed, you can use a rubber ring or rope to fix
the pen. Then operate the writing pen robotic arm according to the following lesson
case.
(6) For the use case of the morphological structure of the robotic arm writing pen,
please refer to the content of lesson 14 below.
119
Lesson 11 Remotely Control of Robotic Arm with
GUI
In this lesson, we will learn how to remotely control the robotic arm with the
GUI.
3. The relevant code programs of the RaspArm-S robot are stored in the folder of
120
adeept_rasparms, which has been explained in "2.1 Downloading the Code Program
for Controlling the Robot" in Lesson 2, you need to download the GUI folder to your
computer under the directory of adeept_rasparms, click the GUI with the mouse, and
then click the button to download the code program to the PC, and save it in the path
of English letters, as shown in the figure below:
4. Then double-click on the PC to open the Python program GUI for Remote.py,
you must make sure that the python environment has been installed on your PC. The
GUI interface after opening is as follows:
121
【Pay attention】
If you cannot connect, I suggest you turn off the Raspberry Pi again, and then
turn on the Raspberry Pi again.
When studying this section, you only need to read and understand, you don’t
need to do any click operations. We will provide an operation case in section 11.3.
(1) :
After opening the GUI control interface, you need to enter the IP address of the
Raspberry Pi in the IP Address input field. Then click the Connect button to connect
to the Raspberry Pi, after successful connection, as shown below:
122
(2) :
1. :
Click the button , and the robot arm will record the coordinate position of
the X, Y, Z, G axis of the current end point of the robot arm.
2. :
Click the button and the end point of the robotic arm will repeatedly
move between the positions of the different coordinate points recorded in the last
save.
When the end point of the robotic arm is at different coordinate points (more than
123
2 coordinate points), click the button , and the robotic arm will record the
position information of the different coordinate points in the form of an array [X, Y, Z,
G]. If you click the button , the end point of the robotic arm will repeatedly
move between the recorded positions of different coordinate points.
3. :
When you click the button , the previously saved coordinate point
position information will be deleted, and you will enter the setting mode of
re-recording the position of the end point of the robotic arm. You only need to click
once. At this time, you can slide the X, Y, Z, and G sliders. To adjust the position of
the end point of the robotic arm, each adjustment, combined with the button
can save the coordinates of the end point of the robotic arm.
4. :
Click the button , the system will record the coordinate point position
information of the end point of the robotic arm in the form of an array [X, Y, Z, G],
and save it as a ".json" file, which will be saved in the course routine as a "plan.json"
file.
5. :
Click the button and the robot arm will stop moving.
(3)
1. [X+ and X-]: Controlling the end point of the robotic arm to move left and
right
(1) X+:
If the x value becomes larger, the end point of the robotic arm will shift to the right. It
124
can be adjusted by the slider on the right.
(2) X-:
If the x value becomes smaller, the end point of the robotic arm is shifted to the left.
2. [Y+ and Y-]: Controlling the end point of the robotic arm to move back and
forth
(1) Y+:
If the Y value becomes larger, the end point of the robotic arm moves forward. It can
be adjusted by the slider on the right.
(2) Y-:
If the Y value becomes smaller, the end point of the robotic arm moves backward.
The area about the end point of the robotic arm is as follows:
3. [Z+ and Z-]: controlling the end point of the robotic arm to move up and down
(1) Z+:
If the Z value becomes larger, the end point of the robotic arm moves upward. It can
be adjusted by the slider on the right.
(2) Z-:
If the Z value becomes smaller, the end point of the robotic arm moves downward.
4. [G+ and G-]: controlling the opening and closing of the mechanical arm clip
(1) G+:
If the G value becomes larger, the mechanical arm clamp is closed. It can be adjusted
125
by the slider on the right.
(2) G-:
If the G value becomes smaller, the mechanical arm clip opens.
When you open the GUI control application for the first time, click the
button , and the robot arm will repeat the movement between the last
recorded and saved position points (must be 2 different positions), then how to change
the end point of the robotic arm to move at different points? Let's learn together.
First click the button to stop the moving robot arm, and then click the
button to start recording a new position point. At this time, you need to
combine the X, Y, Z, and G sliding buttons in the figure below to locate the end point
of the robot arm to make adjustments, such as sliding the X slide bar to the far right,
and turning the end point of the robotic arm to the right. At this time, we need to save
the position of this coordinate point. By clicking the button , we can save
the current position; then we also need to record the new position again, continue to
slide the X slide bar to the middle position, click the button at this time to
save the current position; continue to slide the X slide bar to the leftmost position,
click the button at this time, save the current position; now we have
recorded three different position points, now click the button , the end point
of the robotic arm will repeat the movement between the three different position
points just recorded. If you want to continue running the location you just recorded
126
and saved when you turn on the Raspberry Pi next time, then you can record the
127
Lesson 12 Controlling the Robotic Arm with
Raspberry Pi Peripherals
In this lesson, we will learn how to control the movement of the robotic arm with
the GUI when the Raspberry Pi is connected to an external monitor.
128
2. Connect the HDMI cable connected to the Raspberry Pi to the HDMI port of
the display:
129
3. Turn on the display switch and supply power to the Raspberry Pi. You will see
the startup interface of the Raspberry Pi, and wait for the Raspberry Pi to start
successfully. Then click OK.
130
Click the X button in the upper right corner.
132
Lesson 13 Controlling the Robotic Arm with a Web
Application
We have developed a WEB application to control the robotic arm to lower the
barriers to use of the robotic arm. The WEB application is convenient to use. You can
remotely control the robotic arm on a device with a browser (Google browser is
recommended).
133
3. The relevant code programs of the RaspArm-S robot are stored in the folder of
adeept_rasparms, which have been explained in "2.1 Downloading the code program
to control the robot" in Lesson 2. First, you need to enter the server directory with the
command window of the Raspberry Pi and enter the following command:
cd adeept_rasparms/server
134
At this point, you need to open the Google browser (on your phone or computer)
and enter the URL in the following format in the address bar: Raspberry Pi IP: 5000
For example, the IP address of my Raspberry Pi is 192.168.3.187, then the URL
format in the address bar of the browser is: 192.168.3.187:5000
The interface after logging in to the web application is shown below:
135
13.2 Introduction to Web Application Functions
136
When learning the content of section 13.2, you only need to read and
understand, without any click operations. We will provide an operation case in
section 13.3.
The following is an introduction to the functions of each button.
13.2.1 [X+ and X-]: Controlling the end point of the robotic arm
(1) X+:
If you click the X+ button, the x value becomes larger, and the end point of the
137
robotic arm shifts to the right.
(2) X-:
If you click the X- button, the x value becomes smaller and the end point of the
robotic arm is shifted to the left.
13.2.2 [Y+ and Y-]: Controlling the end point of the robotic arm
(1) Y+:
If you click the Y+ button, the Y value becomes larger and the end point of the robotic
arm moves forward.
(2) Y-:
If you click the Y-button, the Y value becomes smaller and the end point of the robotic
arm moves backward.
13.2.3 [Z+ and Z-]: Controlling the end point of the robotic arm
(1) Z+:
If you click the Z+ button, the Z value becomes larger, and the end point of the
138
robotic arm moves upward.
(2) Z-:
If you click the Z- button, the Z value becomes smaller and the end point of the
robotic arm moves downward.
13.2.4 [G+ and G-]: Controlling the opening and closing of the
(1) G+:
If you click the G+ button, the G value becomes larger and the mechanical arm clip
opens.
(2) G-:
If you click the G- button, the G value becomes smaller, and the mechanical arm
clamp closes.
13.2.5
Click the button , and the robot arm will record the coordinate position of
13.2.6
Click the button , the end point of the robotic arm will repeatedly move
Click the button directly, and the robotic arm will move back and forth
repeatedly between the positions where the coordinate points are saved in the
"plan.json" file by default.
When the end points of the robotic arm are at different coordinate points (more
than 2 coordinate points), click the button , and the robotic arm will record the
position information of the different coordinate points in the form of an array [X, Y, Z,
G]. If you click the button , the end point of the robotic arm will repeatedly
139
move between the recorded positions of different coordinate points.
13.2.7
When you click the button , the previously saved coordinate point
position information will be deleted. At this time, you can combine the button
13.2.8
When you click the button , the previously saved coordinate point
position information will be deleted, and you will enter the setting mode of
re-recording the position of the end point of the robotic arm. You only need to click it
once. At this time, you can click the X, Y, Z, and G buttons. Adjust the position of the
end point of the robotic arm. Each time you adjust, combine the button to
save the coordinates of the end point of the robotic arm.
13.2.9
Click the button and the robot arm will stop moving.
When you open the web control application for the first time, click the
button , and the robot arm will repeat the movement between the last
recorded and saved position points (must be 2 different positions), then how to change
the end point of the robotic arm to move at different points? Let's learn together.
140
First click the button to stop the moving robot arm, and then click the
button to start recording a new position point. At this time, you need to
combine the X, Y, Z, and G buttons to adjust the position of the end point of the robot
arm, such as by clicking the button , the end point of the robotic arm rotates to
the right to a position to stop. At this point, we need to save the position of this
coordinate point. By clicking the button , we can save the current position;
then we need to record the new position again, continue to slide the X slider to the
middle position, and click the button to save the current position to record;
now we have recorded 2 different position points, now click the button , the
end point of the robotic arm will repeat movement between the 2 different positions
just recorded. If you want to continue running the location you just recorded and
saved when you turn on the Raspberry Pi next time, you can record the location
141
Lesson 14 Replacing the Arm Clip with a Writing Pen
In this lesson, we will learn another form of the RaspArm-S robotic arm, which is
to replace the clip of the robotic arm with a writing pen. With this new structure, you
can use it for some creations, such as drawing. The specific assembly steps are in
"10.3 RaspArm-S Writing Pen Robotic Arm Assembly Tutorial" in Lesson 10.
The assembled structure of RaspArm-S in writing pen form is as follows:
You need to modify the raspArmS.py program when using the pen shape
structure.
1. Open the terminal software MobaXterm:
142
2. Log in to your Raspberry Pi (the way to log in to the Raspberry Pi has been
introduced in Lesson 1), in the file explorer on the left, go to the directory of
adeept_rasparms/server:
3. Select the program raspArmS.py, right-click the mouse, and use the third-party
tool Subline IDE to view and edit the code program. For the specific method, please
see the content of Lesson 2: "2.4 Editing the code program in the Raspberry Pi".
4. Find line 257, modify gripper to pen, and save the modified file. This
143
completes the setting.
144
Lesson 15 API Instructions
Import raspArms,the object that instantiates and controls the robotic arm is ras,
call the start() function in raspArmS.py with ras, you don't need to input any
parameters, call the start() function to control the motion of the robotic arm.
【effect】:
xyzInput([x, y, z]) can control the end point of the robotic arm to move to a
certain point (the end point of the robotic arm is roughly the point where the chuck
clamp is located).
【Call example】:
145
【Parameter Description】:
1. [x, y, z] is the coordinate point of the Cartesian coordinate system where the
end point is located.
2. When the x value is 0, the end point of the robotic arm is the point directly in
front of it, and the x value becomes larger, and the end point shifts to the right; the x
value becomes smaller, the end point shifts to the left.
3. The y value is the position of the end point relative to the front and back of the
robot arm: if the y value becomes larger, the end point position will shift forward; if
the y value becomes smaller, the end point position will shift backward
4. The z value is the position of the end point relative to the upper and lower
positions of the robotic arm: if the z value becomes larger, the end point position will
shift upward; if the z value becomes smaller, the end point position will shift
downward.
15.3 servoAngInput(angleInput)
【effect】:
Controlling each servo of the robotic arm to rotate a certain angle.
【Call example】:
【Parameter Description】:
The angleInput parameter is an array of four servo angles.
For example, when the parameter angleInput is [10, 20, 30, 40]:
It means to control A servo to rotate 10°, B servo to rotate 20°, C servo to rotate
30°, and D servo to rotate 40° (all the above degrees are relative to the initial position
of the servo).
【pay attention】
If the parameter angleInput is [0, 0, 0, 0], it means to control all the servos to
146
rotate to the initial position.
15.4 servoInitSet()
【effect】:
Setting the neutral position of the servo.
【Call example】:
【Parameter Description】:
There is no need to write parameters when calling servoInitSet(), but you need to
enter commands in the console to adjust the position of the servo. Refer to the table
below:
【effect】:
Changing the working mode.
【Call example】:
147
【Parameter Description】:
Special note: The working mode selection needs to cooperate with the
corresponding mechanical structure assembly form to operate normally. There are two
structural forms of the robotic arm, one is a "mechanical arm" that can grip objects,
and the other is a "writing pen robotic arm" that can write and draw. For details,
please refer to "Lesson 10 RaspArm-S Assembly Tutorial".
1. In the writing pen mode, Rudder D will try its best to automatically maintain
the aluminum alloy parts that connects to it and maintain an angle with the ground.
2. In the chuck mode, D servo is used to control the opening and closing of the
chuck.
15.6 changeSpeed(speedInput)
【effect】:
Changing the speed of the servo.
【Call example】:
【Parameter Description】:
1. The range of the parameter speedInput: 0 <speedInput <= 100.
2. The default value is 100.
3. This setting affects the running speed of the moveXYZ (newPos) function of
15.7
15.7 moveXYZ(newPos)
148
【effect】:
Controlling the robotic arm to slowly move to a new position.
【Call example】:
【Parameter Description】:
1. The parameter newPos is an array of new positions, such as [0, 0, 0, 0].
2. This function will cause the program to block, and it will jump out when
ras.globalCommand =='stop'.
15.8 gripper(command)
【effect】:
Controlling the chuck of the robotic arm.
【Call example】:
【Parameter Description】:
1. When the parameter command is "catch", the mechanical arm chuck is
clamped.
2. When the parameter command is "loose", the mechanical arm chuck is
released.
3. When the parameter command value is between 0-90, the chuck of the
mechanical arm forms a certain angle, 90 is clamping, and 0 is loosening.
15.9 planGoes(planList)
【effect】:
The robotic arm automatically repeats the scheduled task.
149
【Call example】:
【Parameter Description】:
1. The parameter planList is an array composed of each target point position, for
example: [[90, 140, 0, 90], [-90, 140, 0, 0], [0, 140, 90, 0]]
2. This function will cause the program to block, and it will jump out when
ras.globalCommand =='stop'.
【Effect】:
Controlling the simple movement of the robotic arm. (If the robotic arm is
converted into a PTZ, you can use this function to control the movement of the PTZ
in real time)
【Call example】:
【Parameter Description】:
1. The parameter axis is used to select the desired motion axis, which can be: ‘X’,
‘Y’, and ‘Z’.
2. The parameter direction is used to select the control direction, which can be: ‘+’
or ‘-’.
3. This function will not block the program, and the robot arm will start to move
after the call is completed.
【Pay attention】:
1. The parameter axis is used to select the motion axis that you want to stop. It
150
can be: ‘X’, ‘Y’, and ‘Z’.
2. After an axis starts moving, this function needs to be called to stop the axis.
151
Lesson 16 Mounting the RaspArm-S Robotic Arm to
Other Robots
You can use the RaspArm-S manipulator as an extension module of other robots
and install it on the robot. For example, you can install it on the Alter Dog product
developed and designed by us:
We open sourced the key assembly dimension parameters of this robotic arm, as
shown in "Dimensional Drawing.pdf".
This assembly size is also a commonly used size for the steering wheel of a
digital servo. You can expand it appropriately according to your needs.
152
The robot arm can be fixed directly with M3x10 screws and M3 nuts, or it can be
fixed with copper pillars.
After the robotic arm is installed, please refer to the content of lesson 15 for the
related API call method of controlling the robotic arm. If you change the servo
connection port, you need to modify the course sample code config.json provided by
us. The method of modifying the code program in the Raspberry Pi is as follows:to
view and edit our code program on the MobaXterm terminal software, we provide two
methods for reference.
(1) The first is to use Linux commands. For example, if you need to view and
modify the code program config.json of this lesson, then you can log in to the
Raspberry Pi with the MobaXterm terminal and enter the following command in the
command window (Raspberry Pi console) :
sudo nano adeept_rasparms/server/config.json
After opening the code file, you need to find this line of code:
Among them, 12, 13, 14, and 15 are the default servo interface numbers of our
course examples. You need to modify them according to your actual situation. The
153
structure diagram of the servo of the robotic arm from bottom to top is as follows:
In this way, you can view and modify our code program. You can modify and edit
the code with the direction keys on the keyboard to realize the control function you
want. But you need to learn and search about the command operation method of
Linux nano.
[Nano commonly used operation commands]:
1. To save the modified program, you need to press the shortcut key Ctrl+O on
the keyboard
2. To exit the program code interface, you need to press the shortcut key Ctrl+X
on the keyboard
3. To cut a line of code, you can use Ctrl+K
4.To paste the code, you can use Ctrl+U
154
(2) The second method is to use a third-party IDE tool to view and edit the code
program of this lesson. You can find the file you want to edit in the file resource
management system on the left of MobaXterm, and click the right mouse button on
this file. Click Open with, select your IDE, we recommend you to use Sublime Text
IDE, you need to download it before you can use: http://www.sublimetext.com/3, so
that you can use your favorite IDE to edit the files in the Raspberry Pi. After editing,
CTRL+S can save the file.
155
When you need to save the modified file, you can press the shortcut key CTRL+S,
and then select Yes or Yes to all.
156
Lesson 17 Using Multithreading to Control the Servo
of RaspArm-S
This lesson introduces the use of multi-threading to realize the control of 180°
servo. Multi-threading is a very common operation that we use in robot projects,
because robots have high requirements for real-time response. When performing a
certain task, it is necessary to try not to block the main thread communication.
Multithreading is similar to executing multiple different programs or tasks at the
same time. Multithreading has the following advantages:
1. Using threads to put time-consuming tasks in the background for processing.
2. Improving the operating efficiency of the program.
3. The encapsulated multi-threaded task is more convenient to call, similar to the
non-blocking control method, that is, the control method of the servo is encapsulated
by multi-threading
We use Python's threading library to implement multi-threaded control of the
robot. The thread is the smallest unit of work in the application. The current Python
version does not yet provide multi-thread priority, thread group, thread can not be
stopped, suspended, resumed, and interrupted.
17.2 Preparation
You need to prepare the assembled RaspArm-S robotic arm. Make sure that the
robotic arm has been connected to the circuit according to the assembled circuit
diagram. Refer to "10.2 Robotic Arm Assembly Tutorial" for details.
157
17.3 Controlling the servo with multiple threads
We use the following code to implement multi-threaded control of the servo. Here,
we use Subline IDE to view and edit the code program of this lesson. Please see
section 2.4 in Lesson 2 for specific methods. The specific code and comments are as
follows:
In the file manager of the MobaXterm terminal, find the adeept_rasparms/server
directory and open the code of this lesson: mutiTest.py.
Import the library socket for TCP communication, import the library threading for
enabling multi-threading and the library raspArms for controlling the servo.
158
Instantiate the servo control object and start the thread that controls the servo.
This method is used to receive information from the TCP client and perform
corresponding actions.
This method is used to establish a TCP server. After the server is established, it
starts to monitor the client connection. After the connection is successful, runTcp() is
called to receive instructions from the client.
Define the information related to TCP communication, the port number needs to
be consistent with the client.
159
Start receiving instructions from the client.
Start the thread guard so that when the main thread ends, this thread will also end.
160
3. Enter the Course Code folder, this folder stores the sample code program to
control the robot, enter the following command:
cd adeept_rasparms/server
5. When using the Servo module, we need to install the Python dependency
library to control Servo: Adafruit_PCA9685, enter the following command in the
console of the command window:
sudo pip3 install adafruit-pca9685
6. mutiTest.py is the sample code for this lesson, enter the command to run this
program:
161
sudo python3 mutiTest.py
After successful operation, you will see the following interface, prompting you to
establish a connection with the Raspberry Pi. We follow the next 7th step to open the
GUI application control program on the PC.
7. Open the GUI application on your computer: GUI for Remote.py (there are
related operation methods in Lesson 11, find GUI in the directory of adeept_rasparms,
click the button to download the GUI folder to the PC), in the PC
double-click to open the GUI for Remote.py in the GUI folder (you must have Python
installed on your computer), and the opened interface is as follows:
162
8. You need to enter your Raspberry Pi IP address in , and then
click the Connect button. After the connection is successful, the button
on the right will turn green: with the GUI control interface,
you can operate the robotic arm.
163
17.4 Controlling the end point of the robotic arm to
move between the new position points
When you open the GUI control application for the first time, click the
button , and the robot arm will repeat the movement between the last
recorded and saved position points (must be 2 different positions), then how to change
the end point of the robotic arm to move at different points? Let's learn together.
First click the button to stop the moving robot arm, and then click the
button to start recording a new position point. At this time, you need to
164
combine the X, Y, Z, and G sliding buttons in the figure below to locate the end point
of the robot arm to make adjustments, such as sliding the X slide bar to the far right,
and turning the end point of the robotic arm to the right. At this time, we need to save
the position of this coordinate point. By clicking the button , we can save
the current position; then we also need to record the new position again, continue to
slide the X slide bar to the middle position, click the button at this time to
save the current position; continue to slide the X slide bar to the leftmost position,
click the button at this time, Save the current position; now we have
recorded three different position points, now click the button , the end point
of the robotic arm will repeat the movement between the three different position
points just recorded. If you want to continue running the location you just recorded
and saved when you turn on the Raspberry Pi next time, then you can record the
When you click the X, Y, Z, G buttons to adjust, the coordinate position of the
end point of the robotic arm will be printed in the command window of the Raspberry
Pi.
165
Lesson 18 Introduction to the Soft Motion Method of
the Servo
In this lesson, we will learn the soft motion method of the servo.
Here we use Subline IDE to view and edit the code program of this course. For
the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in
Lesson 2. The specific code and comments are as follows:
In the file manager of the MobaXterm terminal, find
adeept_rasparms/CourseCode/06Smooth, and open the code of this lesson: smooth.py.
Import the library that is used to control the servo.
Define three positions and let the servo move slowly to these positions in
sequence.
This is the initial position and the variable which is used to store the end point of
the last movement of the servo.
166
Enter a new position in the parameter of this function, the rudder will move
smoothly from lastPos to newPosInput.
Main function, which is used to control the servo to move slowly to the three
points in posList.
167
3. The relevant code programs of the RaspArm-S robot are stored in the folder of
adeept_rasparms, which has been explained in "2.1 Downloading the Code Program
for Controlling the Robot" in Lesson 2. First, you need to enter a command with the
command window of the Raspberry Pi to enter the folder where the course code is
stored: CourseCode, this folder stores the sample code program for each course, enter
the following command:
cd adeept_rasparms/CourseCode
5. The 06Smooth folder stores the sample code of this lesson. Enter the
command to enter this folder:
cd 06Smooth
168
7.smooth.py is the sample code for this lesson, enter the command to run this
program:
sudo python3 smooth.py
8. After running the program successfully, you will observe that the robotic arm
will move between the three positions set in the program.
169
Lesson 19 Inverse Solution Function of Plane Link
In this lesson, we will learn the inverse solution function of the plane link.
170
19.2 Learning the code program of the inverse
function of the plane Link
Here we use Subline IDE to view and edit the code program of this course. For
the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in
Lesson 2.
In the file manager of the MobaXterm terminal, find
adeept_rasparms/CourseCode, download the folder 07linkageRT to your PC, select
this folder, click the button to download the file to the PC, save it in the path
of English letters, and use Subline IDE to open the linkageRT.py in the 07linkageRT
folder. The main code and comments are as follows:
Import the mathematical function library numpy.
Set the length of AB to 70, the length of BC to 150.0, and the length of CD to 10.
171
servoNumCtrl = [0,1] is the number of the AB servos; servoDirection = [1,-1]
corresponds to the movement direction of the AB servos, set by 1 and -1.
The array linkageLenCtrl which is composed of the lengths of links AB and BC.
The function planeLinkageReverse() is used to input the length of the link and the
error parameters, the end position of the link and the number of the servos, and the
rotation angle of the AB servos of this connecting rod mechanism can be obtained.
Used to calculate the angle error between the end point of the link and the
rotation axis of the servo.
The input links AB, BC, and CD are abstracted into AB and BD to facilitate
subsequent calculations.
172
19.3 Running linkageRT.py on the PC
Find the folder 07linkageRT that you downloaded in step 19.2 on your PC,
double-click to open the linkageRT.py program inside, you must make sure you have
downloaded and installed Python according to "Lesson 4".
After double-clicking to open, as shown in the figure below, in the running
command window, the printed data are the rotation angle of servo A; the rotation
angle of servo B; the length of AD; the length of AD; the angle of AD.
173
Lesson 20 Drawing Lines with Matplotlib
In this lesson, we will learn how to use matplotlib to draw simple lines.
Matplotlib is a plotting library for the Python programming language and its
numerical mathematics extension NumPy. It provides an object-oriented API for
embedding plots into applications using general-purpose GUI toolkits like Tkinter,
wxPython, Qt, or GTK+. There is also a procedural "pylab" interface based on a state
machine (like OpenGL), designed to closely resemble that of MATLAB, though its
use is discouraged.[3] SciPy makes use of Matplotlib.
Matplotlib was originally written by John D. Hunter, since then it has an active
development community,[4] and is distributed under a BSD-style license. Michael
Droettboom was nominated as matplotlib's lead developer shortly before John
Hunter's death in August 2012,[5] and further joined by Thomas Caswell.
Here we use Subline IDE to view and edit the code program of this course. For
the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in
Lesson 2.
In the file manager of the MobaXterm terminal, find
adeept_rasparms/CourseCode, download the 08linkageM folder to your PC, select
this folder, click the button to download the file to the PC, save it in the path
of English letters, and use Subline IDE opens linkageM.py in the 08linkageM folder.
The main code and comments are as follows:
Import numpy.
174
Import matplotlib.
The function drawLine() is used to input the coordinates pos1 of the initial point
of the line segment and the coordinates pos2 of the end point.
Call the drawLine() function to draw a line segment starting at (0,0) and ending at
(2,2).
Find the folder 08linkageM you downloaded in step 20.2 on your PC, copy the
linkageM.py program inside to the C drive directory, and double-click to open the
linkageM.py program inside. Make sure you have followed Lesson 4 to download and
install Python.
1. First open the cmd command window on the PC:
175
2. In the opened command window, enter the command to install matplotlib:
pip install matplotlib
3. After the installation is complete, you can use the mouse to double-click to
open the linkageM.py, and then you will see the following picture, the middle is the
line segment drawn by the program.
176
177
Lesson 21 Simulating a Plane Link with Matplotlib
In this lesson, we will learn how to use matplotlib to simulate a plane link.
Matplotlib is a plotting library for the Python programming language and its
numerical mathematics extension NumPy. It provides an object-oriented API for
embedding plots into applications using general-purpose GUI toolkits like Tkinter,
wxPython, Qt, or GTK+. There is also a procedural "pylab" interface based on a state
machine (like OpenGL), designed to closely resemble that of MATLAB, though its
use is discouraged. SciPy makes use of Matplotlib.
Matplotlib was originally written by John D. Hunter, since then it has an active
development community, and is distributed under a BSD-style license. Michael
Droettboom was nominated as matplotlib's lead developer shortly before John
Hunter's death in August 2012, and further joined by Thomas Caswell.
Here we use Subline IDE to view and edit the code program of this course. For
the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in
Lesson 2.
In the file manager of the MobaXterm terminal, find the
adeept_rasparms/CourseCode, download the folder 09linkageR to your PC, select this
folder, click the button to download the file to the PC, save it in the path of
English letters, and use The Subline IDE opens the linkageR.py in the 09linkageR
folder. The main code and comments are as follows:
Import numpy.
178
Import matplotlib.
Set the length of AB to 70, the length of BC to 150.0, and the length of CD to 10.
Used to calculate the angle error between the end point of the link and the
179
rotation axis of the servo B.
The input links AB, BC, and CD are abstracted into AB and BD to facilitate
subsequent calculations.
The animateLine() function is used to draw a line segment. The input parameters
are the initial coordinate point X and Y values of the line segment, the length of the
line segment, the angle of the line segment, and the angle deviation.
180
make animations, which will be explained later.
Note here that there must be a',' after the last return value, do not delete.
181
21.3 Running the linkageR.py program on the PC
On your PC, find the folder 09linkageR that you downloaded in step 21.2, copy
the linkageR.py program inside to the C drive directory, and double-click to open the
linkageR.py program inside. Make sure you have downloaded in accordance with
“Lesson 4 Downloading and Installing Python".
1. First open the cmd command window on the PC:
182
3. After the installation is complete, you can use the mouse to double-click to run
linkageR.py, and then you will see the following figure, which is the plane link
simulation of matplotlib.
183
Lesson 22 Matplotlib Dual-view Linkage Simulation
In this lesson, we will learn how to use matplotlib for dual-view linkage
simulation.
Matplotlib is a plotting library for the Python programming language and its
numerical mathematics extension NumPy. It provides an object-oriented API for
embedding plots into applications using general-purpose GUI toolkits like Tkinter,
wxPython, Qt, or GTK+. There is also a procedural "pylab" interface based on a state
machine (like OpenGL), designed to closely resemble that of MATLAB, though its
use is discouraged. SciPy makes use of Matplotlib.
Matplotlib was originally written by John D. Hunter, since then it has an active
development community and is distributed under a BSD-style license. Michael
Droettboom was nominated as matplotlib's lead developer shortly before John
Hunter's death in August 2012, and further joined by Thomas Caswell.
Here we use Subline IDE to view and edit the code program of this course. For
the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in
Lesson 2.
In the file manager of the MobaXterm terminal, find the
adeept_rasparms/CourseCode, download the folder 10linkage to your PC, select this
folder, click the button to download the file to the PC, save it in the path of
English letters, and use The Subline IDE opens the linkage.py in the 10linkage folder.
The main code and comments are as follows:
Import numpy.
184
Import matplotlib.
Here defines the distance between the A-axis of the servo and the servo axis
responsible for the left and right swings. This distance is determined by the structure
and cannot be changed.
Define the position of the oscillating servo here to correct the initial position error,
generally 0 is enough.
This function is used to input the three-dimensional coordinates of the end point
of the link, and return the rotation angle of the left and right swing servo and the
length of the yellow line segment.
[Important Reminder]: The length of the yellow line segment is the X value of
the link inverse solution function of the previous course, and the Z value here is the Y
value of the link inverse solution function of the previous course.
185
The function used to draw the line segment is the same as in the previous lesson.
The Animate() function is responsible for generating animation, the i value inside
the function is the input variable.
Return the rotation angle of the left and right servo and the length of the yellow
line segment.
Note here that there must be a',' after the last return value, do not delete.
186
22.3 Running the linkage.py program on the PC
On your PC, find the folder 10linkage that you downloaded in step 22.2, copy the
linkage.py program inside to the C drive directory, and double-click to open the
linkage.py program inside. Make sure you have downloaded in accordance with
“Lesson 4 Downloading and Installing Python".
1. First open the cmd command window on the PC:
187
3. After the installation is complete, you can use the mouse to double-click to run
linkage.py, and then you will see the following figure, which is the matplotlib's
dual-view linkage simulation.
188
Lesson 23 Reading and Saving json Files
In this lesson, we will learn how to read and save json files.
Here we use Subline IDE to view and edit the code program of this course. For
the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in
Lesson 2.
In the file manager of the MobaXterm terminal, find adeept_rasparms/server, and
open the code of this lesson: rwJson.py. The specific code and comments are as
follows:
Import related dependent libraries.
Open plan.json.
2. Log in to your Raspberry Pi (the way to log in to the Raspberry Pi has been
introduced in Lesson 1):
190
3. The relevant code programs of the RaspArm-S robot are stored in the folder of
adeept_rasparms, which have been explained in "2.1 Downloading the code program
to control the robot" in Lesson 2.First, you need to enter the server directory with the
command window of the Raspberry Pi and enter the following command:
cd adeept_rasparms/server
191
Lesson 24 Using json Data to Record and Repeat
Actions
In this lesson, we will learn how to use json data to record and repeat actions.
2. Log in to your Raspberry Pi (the way to log in to the Raspberry Pi has been
introduced in Lesson 1), in the file manager of the MobaXterm terminal, find the
adeept_rasparms/server directory, right-click the file plan.json, open the plan.json file
by selecting the third-party tool Sublime Text by "Open with" in the options:
192
【Note】
If you don't have the third-party tool Sublime Text, you can use the nano
command of Linux to operate, and the specific method can be viewed in 2.4.
3. After opening, as shown below, the data of these two-dimensional arrays is to
save and record the coordinate data of the robot arm at a certain position. Each
element in the array represents the coordinate information of a position, such as
[90,140,0,90] ,it means the coordinate information of a position point. The first data is
the X-axis coordinate position, the second data is the Y-axis coordinate position, the
third data is the Z-axis coordinate position, and the fourth data is the rotation of the
chuck. angle.
The three elements in the array are three different locations:[[90, 140, 0, 90],[-90,
140, 0, 0],[0, 140, 90, 0]], which are connected when the robot arm enters the
automatic operation mode (in GUI or Web application interface, click the
button , the robot arm enters the automatic motion mode), the path of its
motion is saved in the plan.json file location point. If you want to run the new path
automatically, you can manually modify the data at the corresponding location in the
plan.json file and save it.
193
【Note】
194
Lesson 25 json Data Communication
In this lesson, we will learn json communication. In the example of this lesson,
two sample programs are provided: server.py and client.py, which are on different
devices in the same LAN. It can also be run on the same device. Run server.py first
and then client.py. Server.py can send two arrays to client.py in a loop, and client.py
can be used like a normal array. It is possible to send the dictionary without sending
the array, and the method is the same.
Here we use Subline IDE to view and edit the code program of this course. For
the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in
Lesson 2.
In the file manager of the MobaXterm terminal, find
adeept_rasparms/CourseCode/11Json, and open the code of this lesson: server.py. The
specific code and comments are as follows:
Import libraries related to TCP communication.
195
Define two arrays.
Here we use Subline IDE to view and edit the code program of this course. For
the specific method, please see "2.4 Editing the Code Program in Raspberry Pi" in
Lesson 2.
In the file manager of the MobaXterm terminal, find
adeept_rasparms/CourseCode/11Json, and open the code of this lesson: client.py. The
specific code and comments are as follows:
The IP address here needs to be changed to the IP address of the server, which is
the IP address of the device where you run the client.py program. For example, if you
run client.py on your computer, then you need to modify SERVER_IP to your
computer's IP.
The IP address here needs to be changed to the IP address of the server.
this folder, click the button to download the file to the PC, and save it in
English letters Under the path.
2. In the MobaXterm terminal, log in to your Raspberry Pi and use the command
to enter under the adeept_rasparms/CourseCode/11Json:
cd adeept_rasparms/CourseCode/11Json
5.Open the client.py program you downloaded in step 1 on the PC, and then the
following data will appear.
197
198
Lesson 26 Using a Rotary Encoder to Control a
Robotic Arm
In this lesson, we will introduce how to use a rotary encoder to control a robotic
arm.
Rotary encoder is a device used to measure the speed and cooperate with PWM
technology to achieve rapid speed adjustment. By photoelectric conversion, the
photoelectric rotary encoder can convert the angular displacement and angular
velocity of the output shaft into corresponding electrical pulses for digital output
(REP). In this lesson, the rotary encoder we use mainly acts as a switch button. With
this feature of the rotary encoder, you can use it to control the robotic arm.
1. First, you need to supply power to the robotic arm, and the OLED screen is lit
(if the screen is not lit, then you need to ensure that you have successfully installed
the dependent libraries according to the content of 2.2), you will see the first level
199
directory:
2. In the first-level directory, you will see three options. When you want to enter
the first option, you can rotate it by operating the rotary encoder.
3. How to enter "XYZ CTRL", when "<<<" is marked in the first option, you can
press the rotary encoder to enter the first option, as shown below:
When "<<<" is marked in the first item: X-ALLXS, press the rotary encoder at
this time to turn on the mode of controlling the end point of the robotic arm to move
in the X-axis direction. Then you can control the robotic arm by the rotary encoder.
200
4. How to return to the previous or first level main catalog, you can return to the
previous or first main catalog by long pressing the rotary encoder.
5. After returning to the main menu, you can use the rotary encoder. When "<<<"
is marked in the second option, you can press the rotary encoder to enter the second
option: SERVO CTRL, this mode controls the A, B, C, D servos on the robotic arm
structure respectively. You can select A-SERVO by pressing, and the rotary encoder
controls the movement of the A servo, as shown in the following figure:
201