Index>Robot Kit>Mars Rover PiCar-B Smart Robot Car Kit for RPi>Lesson 3 Installing and Configuring Raspberry Pi System

Lesson 3 Installing and Configuring Raspberry Pi System

2105

Lesson 3 Installing and Configuring 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.

3.1 Preparation

 

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.

You need to insert the SD card into the card reader first, and then connect the card reader to the computer.

 

3.2 Downloading the Raspberry Pi system Raspbian

 

Raspbian is the official operating system of the Raspberry Pi Foundation. It is customized based on Debian GNU/Linux and can run on all versions of the Raspberry Pi motherboard. According to the experience, Raspbian combines Raspberry Pi the best. It is stable, powerful, and easy to use. It can basically meet the needs of various applications. This course uses Raspbian as the preferred operating system for the Raspberry Pi. Next, we will teach you how to download the Raspberry Pi system Raspbian. Now there are two ways to download Raspbian for Raspberry Pi system (we recommend method one first).

Method one :

1. visit the official website of the Raspberry Pi through a browser to download Raspbian:

https://www.raspberrypi.org/downloads/

After logging in to the official website, click on the location shown below:

image.png 

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.

image.png 

3. Choose to download the ".ZIP" file and wait for the download to complete:

image.png 

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

image.png 

Method two:

Manually downloading the image file we provide and write it to the SD card (not recommended).

The image downloaded according to the method one is the latest official version of Raspbian and comes with some pre-installed software. At the same time, the normal operation of the robot product requires many other dependent libraries, although we provide a script to install these simple methods of relying on libraries (will be introduced in detail later), occasionally encountering dependent library updates may cause the installation of dependent libraries to fail, so we provide a Raspbian mirror file pre-installed with dependent libraries. The disadvantage of this method is that the mirror files and related dependent libraries we provide cannot be kept updated at any time. Only when you encounter a very difficult problem, you can try this method to solve it.Download the Raspbian image file address we provide:https://www.adeept.com/learn/detail-33.html

After the download is complete, decompress it. The path of the decompressed” .img” file must be all English letters and no special characters.

 

3.3 Burning the downloaded Raspberry Pi system to the SD card

 

We recommend using the Raspberry Pi Imager tool officially provided by the Raspberry Pi. Raspberry Pi Imager is a new image burning tool launched by the Raspberry Pi Foundation. Users can download and run this tool on Windows, macOS and Ubuntu to burn the system image for the Raspberry Pi. Its usage is similar to Etcher and win32diskimager.

3.3.1 Downloading Raspberry Pi Imager

1. Visit the official website of Raspberry Pi to download through a browser:  https://www.raspberrypi.org/downloads/

For Windows system, click "Raspberry Pi Imager for Windows" to download.

For Mac OS, click "Raspberry Pi Imager for macOS" to download.

For Linux system, Click "Raspberry Pi Imager for Ubuntu" to download.

After the download is complete, install the software and burn the Raspberry Pi system.

Now take Windows as an example.

image.png 

 

2. Open the downloaded file "imager.exe" and click "Install".

image.png 

3. Then click "Finish".

image.png 

4. The software interface after opening is as shown below:

image.png 

 

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

.image.png

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.

image.png 

3. Find the ".img" file of the Raspberry Pi system that we downloaded and decompressed before. Click "Open".

image.png 

4. Select the ".img" file and click "Open".

image.png 

5. Then on the interface of Raspberry Pi Imager, the ".img" file of our selected Raspberry Pi system will appear.

image.png 

6. Click "CHOOSE SD".

image.png 

7. Then select the SD card we need to burn.

image.png 

8. Click "WRITE" to write it to the SD card. Wait for the burn to complete.

image.png 

9. After the burning is completed, the following message will be prompted,indicating that the burning is finished, click "CONTINUE".

image.png 

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

 

 

 

 

3.4 Starting the Raspberry Pi SSH service

 

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:

image.png 

2. Right-click on the blank space of the D drive, select "New", and select "Text Document".

image.png 

3. Name the file "ssh", as shown below:

image.pngimage.png 

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:

image.png 

 

3.5 Setting up Raspberry Pi WIFI wireless connection

 

Next, we also need to set up a WIFI wireless connection for the Raspberry Pi.

1. Create a new file named wpa_supplicant.conf in the root directory of the D driver of the computer.

image.png 

2. Click to select the wpa_supplicant.conf file, right-click the mouse, and select "Open Mode (H)".

image.png 

3. Select "Notepad" to open it.

image.png 

 

 

 

 

4. Write the following contents:

country=US

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

network={

ssid="WIFI"

psk="PASSWORD"

key_mgmt=WPA-PSK

priority=1

}

image.png 

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

image.png 

5. Save the set wpa_supplicant.conf file, and then copy it to the root directory of the SD card of the Raspberry Pi system. As shown below:

image.png 

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.

image.png 

 

3.6 Remotely logging in to the Raspberry Pi system

 

Before using SSH to connect to Raspberry Pi, you need to know the IP address of the Raspberry Pi and the software that supports SSH.

The remote login to the Raspberry Pi is achieved through the SSH protocol, and the Raspberry Pi can be remotely logged in through the software with the SSH protocol. For example: Putty, MobaXterm, etc. It is recommended that MAC users install Putty windows and install MobaXterm.

Linux or Mac OS comes with SSH function, and you can also log in to the Raspberry Pi remotely through the terminal.

3.6.1 Obtaining the IP address of the Raspberry Pi

Method One:

Obtaining an IP address with an external display

We provide a simple and fast way to get the Raspberry Pi IP address. You need to prepare the following components:

One Type-C data cable: used to supply power to the Raspberry Pi.

One HDMI cable: used to connect the monitor.

One mouse: used to operate.

One monitor

One Raspberry Pi

image.png 

1. Connect the HDMI cable to the HDMI port of the monitor:

image.png 

2. 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 " image.png" 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.

image.png 

3. You can also check the following IP address by opening the command window of the Raspberry Pi and entering the following command, you need to write it down:

hostname  -I

image.png 

Method Two:

Obtaining an IP address with a mobile phone

1. You need to download an APP called "Fing" on your phone, as shown below:

image.png 

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

image.png 

3. Click“CONTINUE WITHOUT PERMISSION

image.png 

 

4. Click “OK

image.png 

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

image.png 

 

3.6.2 Remotely logging in to the Raspberry Pi system

This course recommends two kinds of software for SSH login to Raspberry Pi. In actual use, you only need to download one. LInux or Mac OS comes with SSH function, you can log in to the Raspberry Pi remotely with the terminal without downloading software.

Putty

You need to download and install PuTTY corresponding to your computer system version, and use it to log in to the Raspberry Pi. PuTTY download address: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

1. Run PuTTY, enter the IP address of the Raspberry Pi into the Host Name, and click “Open.

For example: 192.168.3.179

image.png 

2. If it prompts Network error: Connection timed out, it means you probably entered the wrong IP address.

3. When the connection is normal, you will see a security warning. You can safely ignore it and click the "Yes" button. You will see this warning when PuTTY connects to a Raspberry Pi that has not been connected before.

4. You will now see the usual login prompt. Log in with the same username and password as the Pi itself. The default login name of Raspbian is pi and the password is raspberry. When entering the password, the screen will not display the entered password. After entering raspberry, press Enter to confirm.

image.png 

5. You should now have the Raspberry Pi prompt, which will be the same as the prompt on the Raspberry Pi itself.

image.png 

 
MobaXterm

MobaXterm is a terminal tool software that can be used to remotely control the Raspberry Pi.

1. Log in to the official website with a browser to download:   https://mobaxterm.mobatek.net/download.html

Choose the Free version to download.

image.png 

2. Download the Portable edition of MobaXterm Home Edition (current version):

image.png 

3. Find the downloaded file MobaXterm_Portable_v20.2.zip, double-click to open it, unzip it to get a new file.

image.png 

image.png 

 

4. Open the unzipped folder, there is a file MobaXterm_Personal_20.2.exe inside.

   image.png

5. Double-click to open MobaXterm_Personal_20.2.exe, and then directly open the MobaXterm software. The interface is as follows:

image.png 

6. Click "Session" in the upper left corner.

image.png 

7. Click "SSH".

image.png 

8. Enter the your IP address of the Raspberry Pi queried before, E.g:192.168.3.157, and click "OK" to confirm.

image.png 

9. Enter the Raspberry Pi default account: pi, then press the Enter key, and then enter the Raspberry Pi default password: raspberry. Press Enter to log in to the Raspberry Pi system.

image.png 

10. After successfully logging in to the Raspberry Pi system, the following interface will appear:

image.png 

11. The red box in the figure below is the command window, where you can control the Raspberry Pi by entering commands.

image.png 

12. When we close the MobaXterm software and open MobaXterm again to connect to the Raspberry Pi, we can double-click the IP address under "User sessions" on the left: 192.168.3.157, enter the account name: pi, and you can directly connect to the Raspberry Sent.

image.png 

 

Windows10, LInux and Mac OS comes with SSH function

Steps to connect to Raspberry Pi via SSH:

1. Open a console terminal window.

2. The initial user name of the Raspberry Pi is “pi” and the initial password is “raspberry”.

3. Enter ssh pi@<IP> in the command line and replace <IP> with your Raspberry Pi IP address, as shown in the following example:

ssh pi@192.168.3.157

4. Press Enter, and the prompt Are you sure you want to continue connecting (yes/no)?

5. Enter yes, press Enter, “pi@192.168.3.157's password: appears, fill in the initial password “raspberry of the Raspberry Pi, pay attention to the case, there will be no changes on the screen during the password input, but it does not Indicates that the input was not successful, press enter after the input is complete.

6. Now you have logged in to the Raspberry Pi.

 

3.7 Downloading the code program to control the robot

 

For the power supply of Raspberry Pi, please refer to this official document:

https://www.raspberrypi.org/documentation/hardware/raspberrypi/power/README.md

Our Raspberry Pi robot driver board Robot HAT can directly supply power to the Raspberry Pi through the GPIO pins. However, because the software installation time in the Raspberry Pi is relatively long, it is not recommended to use battery power when installing the Raspberry Pi. The Raspberry Pi robot driver board Robot HAT or camera need not be installed when installing the software in the Raspberry Pi. This does not affect the software installation, but when you run the installed program, you must connect the driver board and the Raspberry Pi camera, otherwise Will cause the program to report an error.

If you manually download the image file provided by us, you only need to load the SD card into the Raspberry Pi to boot, and the program of the robot product will run automatically. You can skip this section.

All the code of our product has been open sourced on GitHub, you need to download it to the Raspberry Pi and install the relevant dependencies before it can run normally. github address: https://github.com/adeept/adeept_picar-b

1. After the operations in the previous section, we have logged in to the Raspberry Pi, and enter the following commands in the console:

sudo git clone https://github.com/adeept/adeept_picar-b.git

2. After the input is complete, press enter to start downloading the robot program from GitHub. This process will continue for a period of time. Wait patiently for the download to complete.

Take MobaXterm as an example:

image.png 

4. After the download is complete, a new folder adeept_picar-bwill appear, in which the product code is stored. Check through the Linux command "ls".

ls

image.png 

 

3.8 Installing the dependency library of program

 

If you use "Manually download the image file we provide" to write the image file to the SD card, the dependency library of the robot product has been installed, you can directly boot the Raspberry Pi to start using the robot.

If you used "Download the official Raspbian image file" to write the image file to the SD card, you can refer to this section to install the dependent libraries.

When installing dependent libraries, the installation of some dependent libraries may fail due to network problems or dependent library version issues. For dependent libraries that fail to install, the program will automatically install multiple times.

After the installation is complete, the Raspberry Pi will automatically restart. At this time, the remote login program of the Raspberry Pi via SSH will be terminated. Please log in again.

When installing dependent libraries, the installation may fail due to network or regional reasons. If you encounter any problems, please contact us: support@adeept.com

We have prepared a script to install all the dependent libraries that need to be used and set up operations such as turning on the camera and automatically running on startup.

Steps:

1. Enter the following code in the console and run the script setup.py to install the required dependent libraries:

sudo python3 adeept_picar-b/setup.py

image.png 

2. Press Enter to confirm. The following operations are automatically completed by the script program. Depending on the network environment, this process may last for tens of minutes or several hours, just wait patiently.

3. After the installation is complete, the console will show text:

image.png 

After the installation is complete, the Raspberry Pi will automatically disconnect the SSH connection and restart. At this time, if you are using a Raspberry Pi connected by software such as Putty, there will be an error message such as Network error: Software caused connection abort, which is normal, just close the window.

 

3.9 Whether the dependent library is installed successfully

 

When no error message appears when the webServer.py program is running, the dependent library is installed successfully.

Only by successfully running the webServer.py program on the Raspberry Pi, can the Raspberry Pi be accessed with the IP on the browser.(After installing the dependent libraries, the Raspberry Pi will automatically run webServer.py).

Prepare the components required for installation, and turn off the power of the Raspberry Pi during installation.

image.png 

1. Install the camera cable, contact the metal surface of the cable with the metal surface of the Raspberry Pi (the same applies to installing the camera).

image.png 

2. Install Robot HAT and camera, and connect the Raspberry Pi power supply.

image.png 

After the Raspberry Pi is turned on (about 30-50s), you can access the Raspberry Pi with a browser.   

If the program is not run when the robot is booted, try to connect Raspberry Pi via SSH, manually run `webServer.py` with code and check the errors. Refer to the Q&A below or email us for help: support@adeept.com

before manually running `webServer.py`, you need to end the program possibly auto run in the back end to release resources.

sudo killall python3

image.png 

Use the following command to run webServer.py. If there are errors, please see the F&A in this tutorial.

sudo python3 adeept_picar-b/server/webServer.py

image.png 

Open the web control interface.

1. Make sure your device is in the same local area network as the Raspberry Pi.

2. Obtain the IP address of the Raspberry Pi (refer to the software installation section).

3. Open the browser on the device (chrome browser is recommended to avoid possible browser compatibility issues), enter the IP address of your Raspberry Pi in the address bar, and visit port 5000, for example: 192.168.3.44:5000

image.png 

3. The web controller will then be loaded into the browser.

image.png 

Depending on the product, the modules on the web controller are also different.

 

3.10 Creating a WiFi Hotspot on Raspberry Pi

 

The dependent library is successfully installed, and after "webServer.py" runs automatically, our product will automatically turn on the hotspot when the wifi is not connected.

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_Robot. The default password is 12345678. 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 on the console to turn on the WIFI:

sudo create_ap wlan0 eth0 Adeept_Robot 12345678

Adeept_Robot is the name of the WIFI hotspot, 12345678 is the password of the WIFI hotspot.

 

 

Q&A

 

Errors occur with `permission denied` prompt when I manually run `server.py` or `webServer.py`.

The Raspberry Pi needs the root permission to run the dependent libraries for WS2812 LED lights control.

You need to add `sudo` to the beginning of `server.py` or `webServer.py` to run the program. [PATH] is the product folder path. E.g: sudo python3 adeept_picar-b/server/webserver.py

sudo python3 [PATH]/server.py

sudo python3 [PATH]/webServer.py

 

Raspberry Pi can't boot.

Remove all parts on the driver board. Only connect the board to Raspberry Pi and power supply, reboot.

Observe if the green light of the Raspberry Pi is blinking.

    If the indicator does not flash or the indicator flashes at the same interval, it means that the image file has not been burned successfully, please re-burn the system.

 

"Remote side unexpectedly closed network connection" shows on a popup window.

There can be error prompts during installation because the Raspberry Pi will auto reboot after the installation, which will disconnect the board.

 

Raspberry Pi failed to connect a WiFi.

Please connect to the Raspberry Pi through the mouse, keyboard, monitor, and then click the wifi icon in the upper right corner of the Raspberry Pi interface to enter the wifi information.

 

I can not connect to the Raspberry Pi terminal via SSH

Please connect to the Raspberry Pi through the mouse, keyboard, monitor, and then click on the main menu in the upper left corner of the Raspberry Pi interface, select "preferences", select "Raspberry Pi Configuration", select "Interfaces", set the SSH bar to "Enabled", then Click "OK"

 

SSH can't connect, error: WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

Enter the following in the command line and press Enter

ssh-keygen -R <the Raspberry Pi's IP address>

For example:

ssh-keygen -R 192.168.3.157

Then you can SSH to the Raspberry Pi again

 

Can I supply the Robot HAT and Raspberry Pi via USB?

A 2A output is required for a Raspberry Pi 3B, when at least 3A is needed for a Raspberry Pi 4. You can use the USB power for software installation and testing, but it's not suitable for high power module like servo or motor adjustment as it may result in low voltage. It's recommended to use battery for power here.

 

no cv2 error occurs when I manually run `server.py` or `webServer.py`.

OpenCV is not installed correctly. Type in the command sudo pip3 install opencv-contrib-python in the Raspberry Pi to manually install OpenCV.

 

When using a computer to copy ssh and wpa_supplicant.conf to the SD card, it prompts that there is no SD card

If this happens, unplug the card reader and connect it to the computer.

 

 

Run "webServer.py" error: Could not start camera.

Check whether the camera is installed correctly:

The metal surface of the camera cable is in contact with the metal surface of the camera,The metal surface of the camera cable is in contact with the metal surface of the camera interface of the Raspberry Pi

How to judge whether the camera is connected correctly

Please run the command in the terminal: "raspistill -t 1000 -o image.jpg",

If the camera is installed correctly, the program will not go wrong, and after running the command "ls", an image file of image.jpg will appear

If an error occurs, it means that the camera is not installed correctly or the camera is malfunctioning