Skip to content

queeek/Adeept_RaspTank

 
 

Repository files navigation

Getting Started with Raspberry Pi Robot and Python

1. Premise

1.1 STEAM and Raspberry Pi

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.

1.2 About the Documentation

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.

mermaid

2. Getting to Use the Raspberry Pi

2.1 Write the Raspberry Pi image to an SD card

2.1.1 Method A: Write 'Raspbian' to the SD card by Raspberry Pi Imager

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

  1. Prepare an SD card (16G or larger) and an SD card reader
  2. Download the Raspberry Pi Imager on the official website Official Raspberry Pi website
  3. Install the Raspberry Pi Imager
  4. 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
  5. 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.

    imagerDownload

  • Insert the SD card into the card reader, connect the card reader and your computer.

  • Run the Raspberry Pi Imager, select CHOOSE 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 the Raspbian 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. The Raspberry Pi Imager needs to download the Raspbian image file during the process. You can download the file following the step in 2.1.2.

    imagerUse

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

2.1.2 Method B: Download the image file Raspbian and write it to the SD card manually

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

  1. Prepare an SD card (16G or larger) and an SD card reader
  2. Download the Raspberry Pi Imager on the official website Official Raspberry Pi website
  3. Install the Raspberry Pi Imager
  4. Download the image file Raspbian
  5. Unzip the file, be noted that the path should be in English for the .img file extracted, no special characters allowed.
  6. Write the image file Raspbian downloaded to the SD card with Raspberry Pi Imager
  7. 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.

    imagerDownload

  • 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; otherwise Raspberry Pi Imager may not open the .img file. It's recommended to save the .img file to the root directory of the C:\ or D:\ disk, but do not save .img on the SD card.

    RPiDownload

  • Insert the SD card into the card reader, connect the card reader and your computer.

  • Run the Raspberry Pi Imager, select CHOOSE OS, and then Use custom to find the .img extracted, click Open.

  • Select CHOOSE SD CARD for the SD card to write the Raspbian, 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.

    imagerUse

  • 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

  1. Prepare an SD card (16G or larger) and an SD card reader
  2. Download the Raspberry Pi Imager from the official website Official Raspberry Pi website
  3. Install the Raspberry Pi Imager
  4. Download the image file Raspbian
  5. Unzip the file, be noted that the path should be in English for the .img file extracted, no special characters allowed.
  6. Write the image file Raspbian downloaded to the SD card with Raspberry Pi Imager
  7. 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.

    imagerDownload

  • 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. otherwise Raspberry Pi Imager may not open the .img file. It's recommended to save the .img file to the root directory of the C:\ or D:\ 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, select CHOOSE OS, and then Use custom to find the .img extracted, click Open.

  • Select CHOOSE SD CARD for the SD card to write the Raspbian, 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.

    imagerUse

  • 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.2 Enable SSH Server of Raspberry Pi

  • 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)

2.2.1 Method A: Enable SSH with peripherals

  • If you've connected a mouse, keyboard, or monitor to the Raspberry Pi, follow these steps to enable SSH.

    1. 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.
    2. Go to Preferences menu, select Raspberry Pi Configuration.
    3. Go to Interfaces option.
    4. Select Enable next to SSH.
    5. Click on OK.

    configSSH

2.2.2 Method A: Enable SSH without peripherals

  • If you haven't connected any monitor to the Raspberry Pi, follow these steps to enable SSH.

    1. Do not remove the SD card after Raspberry Pi Imager writes the image file.

    2. Create a file named ssh under any directory, without any extension name. You may create a ssh.txt and delete the .txt (make sure under Folder Options the box of Hide extensions for known file types is unchecked. Then you have an ssh file without extension name.

    3. Copy the ssh file and paste to the root directory of the SD card. The Raspberry Pi will auto search for the ssh 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.

    4. Do not remove the SD card if you need to configure WiFi.

2.3 Configure WiFi on Raspberry Pi

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.

2.3.1 Method A: WiFi connection with peripherals

  • If you've connected a mouse, keyboard, or monitor to the Raspberry Pi, follow these steps to configure WiFi.

    1. 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.
    2. Select the WiFi icon at the top right corner on the monitor, find the WiFi to connect and select.
    3. Type in the password for the WiFi, connect.
    4. 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.

2.3.2 Method A: WiFi connection without peripherals

  • 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

    1. 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.)

    2. Create a file named wpa_supplicant.conf anywhere in your computer.

    3. 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"
    }
    
    1. TYpe in your own information for Insert country code here, Name of your WiFi, and Password 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"
    }
    
    1. Save and exit. Copy the wpa_supplicant.conf to the root directory of the SD card.

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

    3. For more about the file wpa_supplicant.conf, refer to the official documentation WIRELESS-CLI

3. Software Installation & Operation on Raspberry Pi

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

3.1 Log into Raspberry Pi (Windows 10)

  • 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 named RASPBERRY or Raspberry 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 is raspberry

  • Type in ssh pi@<IP> in the command line, replace the <IP> with the IP address of your Raspberry Pi, as shown below:

    ssh [email protected]

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

winSSH

3.2 Log into Raspberry Pi (Linux or Mac OS)

  • 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 named RASPBERRY or Raspberry 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 is raspberry

  • Type in ssh pi@<IP> in the command line, replace <IP> with the IP address of your Raspberry Pi as shown below:

    ssh [email protected]

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

3.3 Log into Raspberry Pi (Windows)

  • 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 named RASPBERRY or Raspberry 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 for Host 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 password raspberry.
  • You should now have the Raspberry Pi prompt which will be identical to the one found on the Raspberry Pi itself.

putty

3.4 Download Program of the Raspberry Pi Robot

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

3.5 Install Corresponding Dependent Libraries

  • 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 file Raspbian 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.

3.6 Run the Raspberry Pi Robot's Program

  • 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, the webServer.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