- Getting Started with Raspberry Pi Robot and Python
- 1. Premise
- 2. Getting to Use the Raspberry Pi
- 3. Software Installation & Operation on Raspberry Pi
- 4. Precautions for Structure Assembly * 4.1 Documentation for structure assembly * 4.2 Precautions for Structure Assembly
- 5. Controlling Robot via WEB App
- 6. Q&A
STEAM stands for Science, Technology, Engineering, Arts and Mathematics. It's a type of transdisciplinary education idea focused on practice. As a board designed for computer programming education, Raspberry Pi has lots of advantages over other robot development boards. Therefore, Raspberry Pi is used for function control of the robot.
This documentation is for software installation and operation guide for the Python robot product. It describes every detail of the whole process of fulfilling the robot project by Python and Raspberry Pi from scratch as well as some precautions. Hope you can get started with the Raspberry Pi robot on Python and make more creations with this documentation.
Raspberry Pi Imager
is an image writing tool to SD card developed by the Raspberry Pi Organization. It comes with many versions working on different systems and it's quite easy to use; all you need is choose the operating system and SD card, Raspberry Pi Imager will download the corresponding image file for the system and install it to the SD card.
Step-by-Step Overview
- Prepare an SD card (16G or larger) and an SD card reader
- Download the
Raspberry Pi Imager
on the official website Official Raspberry Pi website- [Raspberry Pi Imager for Windows](https://downloads.raspberrypi.org/imager/imager.exe "Click here to download Raspberry Pi Imager for Windows)
- Raspberry Pi Imager for macOS
- Raspberry Pi Imager for Ubuntu
- Install the
Raspberry Pi Imager
- Write the operating system for Raspberry Pi to the SD card with
Raspberry Pi Imager
Raspbian Full - A port of Debian with desktop and recommended application
- Leave the SD card connected after writing is completed, we'll use for configuring SSH and WiFi connection later.
Detailed Steps:
-
Open a web browser on your computer, go to the Raspberry Pi website Official Raspberry Pi website, find and download the
Raspberry Pi Imager
for your computer OS, or click on the links above for the corresponding system to directly download and install. -
Insert the SD card into the card reader, connect the card reader and your computer.
-
Run the
Raspberry Pi Imager
, selectCHOOSE OS
->Raspbian(other)
->Raspbian Full - A port of Debian with desktop and recommended applications
. -
Click on
CHOOSE SD CARD
for the SD card to write theRaspbian Full
, please be noted that the image writing will automatically delete all files on the SD card if any. -
Click on
WRITE
, wait for the writing. TheRaspberry Pi Imager
needs to download theRaspbian
image file during the process. You can download the file following the step in 2.1.2. -
Do not remove the SD card connected when writing is completed, we'll use for configuring SSH and WiFi connection later. Otherwise, if you remove the card, insert it into the Raspberry Pi and boot, WiFi configuration without any peripherals may fail in the following process.
Since the image file is downloaded with the Raspberry Pi Imager
in 2.1.1, it can take a long time due to a slow network in some places. You may then manually download the image file Raspbian
and write it to the SD card with th Raspberry Pi Imager
.
Step-by-Step Overview
- Prepare an SD card (16G or larger) and an SD card reader
- Download the
Raspberry Pi Imager
on the official website Official Raspberry Pi website- [Raspberry Pi Imager for Windows](https://downloads.raspberrypi.org/imager/imager.exe "Click here to download Raspberry Pi Imager for Windows)
- Raspberry Pi Imager for macOS
- Raspberry Pi Imager for Ubuntu
- Install the
Raspberry Pi Imager
- Download the image file
Raspbian
- Unzip the file, be noted that the path should be in English for the
.img
file extracted, no special characters allowed. - Write the image file
Raspbian
downloaded to the SD card withRaspberry Pi Imager
- Leave the SD card connected after writing is completed, we'll use for configuring SSH and WiFi connection later.
Detailed Steps:
-
Open a web browser on your computer, go to the Raspberry Pi websiteOfficial Raspberry Pi website, find and download the
Raspberry Pi Imager
for your computer OS, or click on the links above for the corresponding system to directly download and install. -
On the Raspberry Pi website Official Raspberry Pi website, select through
Downloads
->Raspbian
->Raspbian Buster with desktop and recommended software
, and click on the torrent or zip file to download. Unzip the file after download, be noted that the path should be in English for the.img
file extracted, no special characters allowed; otherwiseRaspberry Pi Imager
may not open the.img
file. It's recommended to save the.img
file to the root directory of theC:\
orD:\
disk, but do not save.img
on the SD card. -
Insert the SD card into the card reader, connect the card reader and your computer.
-
Run the
Raspberry Pi Imager
, selectCHOOSE OS
, and thenUse custom
to find the.img
extracted, clickOpen
. -
Select
CHOOSE SD CARD
for the SD card to write theRaspbian
, please be noted that the image writing will automatically delete all files on the SD card if any. -
Click on
WRITE
, wait for the writing. -
Do not remove the SD card connected when writing is completed, we'll use for configuring SSH and WiFi connection later. Otherwise, if you remove the card, insert it into the Raspberry Pi and boot it up, WiFi configuration without any peripherals may fail in the following process.
2.1.3 Method C: Manually download the image file provided by us and write it to the SD card (not recommended)
The Raspbian image file downloaded in 2.1.1 and 2.1.2 is the official source with some preinstalled software. To operate the robot, you may need many dependent libraries. Though we provide the simple script to install them (see details later), failure can happen during installation if the library is not the latest version. Therefore, despite we provide the downloading of the Raspbian image file, it may happen that our image file and the dependent libraries are not most updated versions. Please only use when you encounter the most troublesome situation.
Step-by-Step Overview
- Prepare an SD card (16G or larger) and an SD card reader
- Download the
Raspberry Pi Imager
from the official website Official Raspberry Pi website - Install the
Raspberry Pi Imager
- Download the image file
Raspbian
- Unzip the file, be noted that the path should be in English for the
.img
file extracted, no special characters allowed. - Write the image file
Raspbian
downloaded to the SD card withRaspberry Pi Imager
- Leave the SD card connected after writing is completed, we'll use for configuring SSH and WiFi connection later.
Detailed Steps:
-
Open a web browser on your computer, go to the Raspberry Pi website Official Raspberry Pi website, find and download the
Raspberry Pi Imager
for your computer OS, or click on the links above for the corresponding system to directly download and install. -
Go to our official website, find and download the image file - Image file for the Raspberry Pi Robot. Unzip the file, be noted that the path should be in English for the
.img
file extracted, no special characters allowed. otherwiseRaspberry Pi Imager
may not open the.img
file. It's recommended to save the.img
file to the root directory of theC:\
orD:\
disk, but do not save.img
on the SD card. -
Insert the SD card into the card reader, connect the card reader and your computer.
-
Run the
Raspberry Pi Imager
, selectCHOOSE OS
, and thenUse custom
to find the.img
extracted, clickOpen
. -
Select
CHOOSE SD CARD
for the SD card to write theRaspbian
, please be noted that the image writing will automatically delete all files on the SD card if any. -
Click on
WRITE
, wait for the writing. -
Do not remove the SD card connected when writing is completed, we'll use for configuring SSH and WiFi connection later. Otherwise, if you remove the card, insert it into the Raspberry Pi and boot it up, WiFi configuration without any peripherals may fail in the following process.
- By SSH (Secure Shell) server, you can use the command line of Raspberry Pi remotely on another device. In the subsequent operation and when using the Raspberry Pi, you don't have to connect a mouse, keyboard, or monitor to it, but simply control it on a computer in the same LAN.
- As of the November 2016 release, Raspbian has the SSH server disabled by default. You will have to enable it manually.
- The method to enable the SSH in this documentation can be referred to the Raspberry Pi official website SSH(Secure Shell)
-
If you've connected a mouse, keyboard, or monitor to the Raspberry Pi, follow these steps to enable SSH.
- Remove the SD card from the computer, insert it to the Raspberry Pi, connect a mouse, keyboard, and monitor to the Raspberry Pi, boot it up.
- Go to
Preferences
menu, selectRaspberry Pi Configuration
. - Go to
Interfaces
option. - Select
Enable
next toSSH
. - Click on
OK
.
-
If you haven't connected any monitor to the Raspberry Pi, follow these steps to enable SSH.
-
Do not remove the SD card after
Raspberry Pi Imager
writes the image file. -
Create a file named
ssh
under any directory, without any extension name. You may create assh.txt
and delete the.txt
(make sure under Folder Options the box of Hide extensions for known file types is unchecked. Then you have anssh
file without extension name. -
Copy the
ssh
file and paste to the root directory of the SD card. The Raspberry Pi will auto search for thessh
file when booting, and enable SSH if the file is found. You only need to copy for one time because the Raspberry Pi then will automatically enable SSH at every boot. -
Do not remove the SD card if you need to configure WiFi.
-
There are many ways to connect WiFi for Raspberry Pi. Two methods are provided in this documentation; you may visit the official Raspberry Pi website for more: Wireless connectivity.
-
If you've connected a mouse, keyboard, or monitor to the Raspberry Pi, follow these steps to configure WiFi.
- Remove the SD card from the computer, insert it to the Raspberry Pi, connect a mouse, keyboard, and monitor to the Raspberry Pi, boot it up.
- Select the WiFi icon at the top right corner on the monitor, find the WiFi to connect and select.
- Type in the password for the WiFi, connect.
- After it's connected successfully, the WiFi will be saved and the Raspberry Pi will auto connect for next boot, so you don't need to connect peripherals every time.
-
If you haven't connected any monitor to the Raspberry Pi, follow these steps to configure WiFi.
-
This method is based on the official documentation
-
Do not remove the SD card after
Raspberry Pi Imager
has written the image file. (This method works for the situation that the Raspbian image file has just been written to the SD card; if you've already plugged the SD card into the Raspberry Pi and got it rebooted after the image file being written, the configuration may fail.) -
Create a file named
wpa_supplicant.conf
anywhere in your computer. -
Open the file
wpa_supplicant.conf
created with Textbook, enter the following code:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=Insert country code here network={ ssid="Name of your WiFi" psk="Password for your WiFi" }
- TYpe in your own information for
Insert country code here
,Name of your WiFi
, andPassword for your WiFi
. Pay attention to the capitalization. Refer to the example below:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=US network={ ssid="MyName" psk="12345678" }
-
Save and exit. Copy the
wpa_supplicant.conf
to the root directory of the SD card. -
If you've alreay copied the file
ssh
to the SD card as instructed in 2.2, then both the WiFi and SSH settings without peripherals are done. You may remove the SD card, insert it into the Raspberry Pi, and boot it up. -
For more about the file
wpa_supplicant.conf
, refer to the official documentation WIRELESS-CLI
-
-
If you followed the steps in 2.2.1 and 2.3.1 for SSH and WiFi configuration, you may remove the peripherals now and use SSH to remotely control the Raspberry Pi later on.
-
If you followed the steps in 2.2.2 and 2.3.2, you may now insert the SD card into the Raspberry Pi and boot it up. The Raspberry Pi will auto boot and connect WiFi when powered on, with no need of peripherals.
-
Some steps mentioned below are based on the official Raspberry Pi documentation SSH.
-
For power supply of the Raspberry Pi, refer to the official documentationPower supply.
-
The Robot HAT board of the Adeept Raspberry Pi Robot can supply power for the Raspberry Pi via GPIO port. However, since it may take a long time to install software on the Raspberry Pi, it's not recommended to supply with the batteries during this process. You may skip the installation of the Robot HAT board or camera during software installation; though you need to make sure the driver board and camera for the Raspberry Pi when it's ready yto run the software installed, or a program error will occur.
-
For Windows 10, SSH is built in the versions after October 2018, so you don't need any third-party software.
-
For lower versions of Windows OS, SSH is not built in, and you may log into the Raspberry Pi by referring to the official documentation SSH using Windows.
-
Before connecting the Raspberry Pi via SSH, you need to know the IP address of the Raspberry Pi. Check the Management interface for your router, or download the app
Network Scanner
-> search for a device namedRASPBERRY
orRaspberry Pi Foundation
to get the IP address. -
For other methods of obtaining the IP address of Raspberry Pi, refer to the official documentation IP Address
-
Press the keys win+R, type in
cmd
, and press enter. -
The default user is
pi
, and the password israspberry
. -
Type in
ssh pi@<IP>
in the command line, replace the<IP>
with the IP address of your Raspberry Pi, as shown below: -
Press Enter key and a prompt will appear:
Are you sure you want to continue connecting (yes/no)?
-
Type in
yes
, press Enter and it'll show[email protected]'s password:
, type in the initial password of the Raspberry Pi,raspberry
(pay attention to capitalization). There's no change on the screen when you're typing in, but it doesn't mean you're not entering the information. Press enter after you finish typing in. -
So now you've logged into the Raspberry Pi.
-
Before connecting the Raspberry Pi via SSH, you need to know the IP address of the Raspberry Pi. Check the Management interface for your router, or download the app
Network Scanner
-> search for a device namedRASPBERRY
orRaspberry Pi Foundation
to get the IP address. -
For other methods of obtaining the IP address of Raspberry Pi, refer to the official documentation IP Address
-
Open the terminal window (or command line)
-
The default user is
pi
, and the password israspberry
. -
Type in
ssh pi@<IP>
in the command line, replace<IP>
with the IP address of your Raspberry Pi as shown below: -
Press Enter key and a prompt will appear:
Are you sure you want to continue connecting (yes/no)?
-
Type in
yes
, press Enter and it'll show[email protected]'s password:
, type in the initial password of the Raspberry Pi,raspberry
(pay attention to capitalization). There's no change on the screen when you're typing in, but it doesn't mean you're not entering the information. Press enter after you finish typing in. -
So now you've logged into the Raspberry Pi.
- For lower versions of Windows OS, SSH is not built in, and you may log into the Raspberry Pi by referring to the official documentation Raspberry PiSSH using Windows.
- Before connecting the Raspberry Pi via SSH, you need to know the IP address of the Raspberry Pi. Check the Management interface for your router, or download the app
Network Scanner
-> search for a device namedRASPBERRY
orRaspberry Pi Foundation
to get the IP address. - For other methods of obtaining the IP address of Raspberry Pi, refer to the official documentation IP Address
- You may need to download the
PuTTY
version for your OS and log into Raspberry Pi with the tool. Click here to download PuTTY - Run
PuTTY
, type in the IP address of Raspberry Pi forHost Name
, and click Open. - If a prompt of
Network error: Connection timed out
appears, possibly you've entered an incorrect IP address. - When the connection works you will see the security warning shown below. You can safely ignore it, and click the 'Yes' button. You will only see this warning the first time PuTTY connects to a Raspberry Pi that it has not seen before.
- You will now see the usual login prompt. Log in with the same username and password you would use on the Pi itself. The default login for Raspbian is
pi
with the passwordraspberry
. - You should now have the Raspberry Pi prompt which will be identical to the one found on the Raspberry Pi itself.
-
The code for the robot product has been uploaded to GitHub, you may need to download to your Raspberry Pi and install the corresponding dependent libraries to run the program.
-
In the previous section you've logged into the Raspberry Pi, and here type in the follow command in the terminal window:
sudo git clone https://github.com/adeept/adeept_rasptank.git
-
Press enter to start downloading the program of the robot from GitHub. It may take some time, please wait until it's done.
-
Follow the steps below to install the libraries if you wrote the image file to the SD card based on 2.1.1 Write 'Raspbian' to the SD card by
Raspberry Pi Imager
and 2.1.2 Download the image fileRaspbian
and write it to the SD card manually. -
But you should skip this section if you wrote the image file to the SD card based on 2.1.3 Manually download the image file provided by us and write it to the SD card; refer to 2.4.5 for configuration of auto start program.
-
Here a script is provided for installing all dependent libraries needed and configuration of starting the camera and other auto start programs.
-
Type in the code below in the terminal window to run the dependent libraries for the script
setup.py
:sudo python3 adeept_rasptank/setup.py
-
Press enter and the script will auto run. This may take minutes or hours, depending on the network status. Please wait until it's done.
-
After installation is completed, the following prompts will appear:
The program in Raspberry Pi has been installed, disconnected and restarted.
You can now power off the Raspberry Pi to install the camera and driver board (Robot HAT). After turning on again, the Raspberry Pi will automatically run the program to set the servos port signal to turn the servos to the middle position, which is convenient for mechanical assembly. -
When installation is completed, the Raspberry Pi will automatically disconnect SSH and reboot. If you used puTTy to connect the Raspberry Pi, there can be an error prompt like
Network error:Software caused connection abort
. You can just ignore and close it.
-
Raspberry Pi auto runs the program for the robot when rebooting every time, which is the part
[RobotName]/server/webServer.py
(replace[RobotName]
for the name of the folder for your robot product's program). However, if the Raspberry Pi camera or RobotHAT is not connected, thewebServer.py
can't run well. It makes sense because the robot's program needs the camera and the chipset PCA9685. RobotHAT controls servo with PCA9685; the Raspberry Pi communicates with PCA9685 via I2C; so if Robot HAT is not connected to Raspberry Pi, a program error will occur when instantiating dependent libraries for PCA9685 due to communication failure. -
Power off the Raspberry Pi, connect camera module and RobotHAT, reboot it up and now
webServer.py
can run. -
Generally you don't need to manually run
webServ