preface

Last time we have the hardware ready, this article we will build the raspberry PI system, and install some necessary tools software.

Raspberry PI mirror burning

Raspberry PI on the operating system to choose a lot, here we take the main computer for Win10 system, the official latest version of 2020.8.20 as an example.

Download the software Raspberry Pi Imager from the official website, then download the system image file and the recommended software.

https://www.raspberrypi.org/downloads/
Copy the code

In the Operating System –> Use Custom select the image file that you downloaded, and then select the SD CARD that you want to Use. Finally, click WRITE to burn.

Enable SSH and configure Wifi

If the keyboard and screen are not configured, you need to create two new files to configure the wifi connection and enable SSH before starting the OS for the first time.

1. Open the SSH

In the boot partition root directory of MircoSD, create a blank file and rename it SSH, all lowercase and no extension.

2. The configuration of Wifi

Also in the root directory, create a new wpa_supplicant.conf file with the following content:

country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
 
network={
ssid="SSID"
psk="PASSWORD"
key_mgmt=WPA-PSK
priority=1
}
Copy the code

Among them,

Ssid is the SSID of Wifi network.

PSK is the connection password;

Key_mgmt indicates the encryption mode:

Wpa-psk = WPA pre-shared key (this requires the 'PSK' field) WPA-EAP = WPA uses EAP authentication EEE8021X =IEEE 802.1x uses EAP authentication and dynamically generates keys NONE = WPA is not used; You can use plain key or static WEP WPA-PSK-SHA256 = similar to WPA-PSK but using enhanced SHA256-based encryption algorithm WPA-EAP-SHA256 = similar to WPA-EAP If the enhanced SHA256-based encryption algorithm is not set, the mode is set to WPA-psK WPA-EAPCopy the code

Priority indicates the priority. A larger number indicates a higher priority.

Modify the ssiD, PSK, and KEY_mgmt values based on the route configuration.

The wpa_supplicant. Conf file is automatically transferred to /etc/wpa_supplicant. The SSH file is converted to the command to enable the SSH service and is deleted. So if you want to change the configuration, add the file again next time.

Configure the raspberry PI

Now you can unplug the MircoSD card, insert the raspberry PI, and power on as normal.

Tip:

Note the two indicators on the raspberry PI. Red indicates power and green generally indicates SD read/write. In normal cases, if the red indicator is steady on and the green indicator blinks every few seconds, the network connection is successful. The green light flashes regularly, indicating that the SD card is not properly inserted or invalid.

1. Query the IP address of raspberry PI

If you have a monitor, you can directly use ifconfig to get the IP address;

If you do not have a monitor, you can use the Advanced IP Scanner to obtain the corresponding information:

2. SSH to log in

With the IP address, you can use SSH to log in. Type the command

SSH [email protected]Copy the code

Enter the default password, raspberry, and you’ll be able to log in.

3. Configure the raspberry PI

On the logged in SSH connection, enter the command

sudo raspi-config
Copy the code

Select 1 Change User Password to Change the Password of the current User.

Select 5 Interfacing Options –> P1 Camera to enable the Camera.

Choose 5 Interfacing Options –> P2 SSH Enable SSH (enabled).

5 Interfacing Options –> P3 VNC Enable VNC.

Select 7 Advanced Option –> A1 Expand Filesystem to Expand the available space.

Select 7 Advanced Option –> A5 Resolution to change the screen Resolution.

Remote connection to raspberry Pie

1. Use the VNC remote desktop

Install VNC-viewer 6.20.113-Windows, create a new connection, enter the IP address of raspberry PI, enter the user name PI, password raspberry to log in.

Tip:

If “Cannot currently show the desktop” is displayed after VNC connection, you can reset the screen resolution again.

2. Change the IP address of raspberry PI to a fixed one

Every time the raspberry PI is powered on, the IP address assigned by the ROUTER’S DHCP sometimes changes. Here, we set a fixed address to facilitate the next connection.

To see the Raspberry PI desktop, right-click on the Wifi icon in the upper right corner of the screen and select Wireless & Wired Network Settings.

Configure select SSID, bind only the specified Wifi connection, and fill in the corresponding network segment:

IPv4 address: 192.168.1.101

The Router: 192.168.1.1

DNS Servers: 192.168.1.1

3. Use PuTTY to access the raspberry PI

After changing the IP address of raspberry PI, restart raspberry PI and use PuTTY to connect to 192.168.1.101.

PuTTY not only has SSH, but also comes with PSCP and PSFTP for transferring files between the main computer and raspberry PI.

4. Use PSCP to transfer files

  • Upload files/folders from Windows to raspberry PI
#Copy the entire directoryPSCP - r d: \ raspi [email protected]: / home/PI#Copying a single filePSCP d: \ raspi \ test. TXT [email protected]: / home/PICopy the code
  • Download files/folders from raspberry PI to Windows
#Copy the entire directoryPSCP - r [email protected]: / home/PI d: \ raspi#Copying a single filePSCP [email protected]: / home/PI/test. TXT d: \ raspiCopy the code

Detailed parameters:

Usage: PSCP [option] [username @] Host: source Destination PSCP [option] Source [Other source...] [username @] Host: target PSCP [options] -ls [username @] Host: specify file options: -v Displays the version information and exits. - PGPFP displays the PGP key fingerprint and exits. -p Retains file properties. -r Recursively copy directory -v Display details -load Session name Load saved session information -p Port Connection to a specified port -L User name Use the specified user name to connect to a pw password Use the specified password to log in to a PW - 1-2 Forcibly use the SSH version -4 -agent Disable Pageant authentication agent. - Agent Enable Pageant authentication agent. - Hostkey AA :bb:cc:... Manually specify the host key (which may be repeated) - Batch Disable all interactive prompts -proxycmd Command Use "command" as the local proxy. - Unsafe allows wildcards on the server. - SFTP Forcibly uses SFTP -sshlog file -sshrawlog File Records detailed protocol logs to the specified fileCopy the code

5. Use PSFTP to transfer files

PSFTP is similar to PSCP in that it is faster, but there is no progress bar.

PSFTP 192.168.1.101#Enter PI and raspberry
#Upload a file
put d:\raspi\test.txt 
#The download file
get /home/pi/test.txt
Copy the code

Common command: CD Switch directory. Ls Displays directory files. Get [fileName] Downloads the file to the current local directory. Get -r [dir] Recursively downloads all files in a remote directory to the current local directory, that is, the download folder. Put [fileName] Sends a long file to the current remote directory. Put -r [dir] recursively uploads all files in a local folder to a remote destination directory, that is, the upload folder. Delete [fileName/dir] Deletes a file or folderCopy the code

6. Use WinSCP to transfer files

You can also install WinSCP. After a connection is set up, you can use a file manager to transfer files more easily.

Update the raspberry PI system

1. Change the mirror source

Due to well-known reasons, the domestic raspberry PI update server cannot be accessed, so the domestic mirror site can be used as the update point.

sudo nano /etc/apt/sources.list
Copy the code

Note the first line, and then add tsinghua source, the file content is as follows:

#deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
Copy the code

Press CTRL + O to write and CTRL + X to exit.

2. Replace the PIP source

Also replace ali source and douban source to PIP.

sudo mkdir ~/.pip
ls .pip
sudo nano pip.conf
Copy the code

Write the following to the configuration file:

[global] timeout = 10 index-url = http://mirrors.aliyun.com/pypi/simple/ extra-index-url= http://pypi.douban.com/simple/  [install] trusted-host= mirrors.aliyun.com pypi.douban.comCopy the code

3. Use THE VPN to connect to the official source

Domestic images are updated asynchronously. Sometimes some third-party libraries are not accessible, especially raw resources on Github, which are more convenient to use VPN. Here’s the example I used for expressVPN. Other VPNS are similar.

  • Use WinSCP to upload the installation package to the Raspberry PI Download directory.

  • Go to the directory and install the VPN client.

    CD Downloads/ sudo DPKG -i expressVpn_xv_2.6.3.3-1_armhf.debCopy the code
  • Activate the software

    expressvpn activate
    Copy the code
  • Connect the VPN

    Expressvpn Connect # Connect to the VPN expressVPN List # Check the list of available servers ExpressVPN Status # Check the connection status ExpressVPN disconnect # Disconnect the connectionCopy the code

4. Update your system

Once the connection problem is resolved, the system update is ready.

sudo apt-get update
sudo apt-get upgrade
pip3 install -U pip
Copy the code

5. Install the Chinese character bank and Chinese input method

#Install the Chinese character library
sudo apt-get install fonts-wqy-zenhei
#Install Chinese input fCITx and Google Pinyin input
sudo apt-get install fcitx fcitx-googlepinyin fcitx-module-cloudpinyin fcitx-sunpinyin
Copy the code

Tool software

1. Linux_Reader

On Windows, you can read files directly from raspberry PI MircoSD.

2. Teamviewer

VNC needs to be on the same LAN to be remotely connected, and installing Teamviewer allows you to visit raspberry PI from anywhere over the Internet. Especially in AIoT applications, devices are accessed over 4G networks.

  • Install teamViewer_setup. exe client on Windows.

  • On raspberry PI, upload the teamViewer – Host_15.9.4_armhf. Deb to the Downloads directory.

CD Downloads/ sudo DPKG -i teamviewer-host_15.9.4_armhf. DebCopy the code

There is an error missing teamViewer -host dependency, fix that

sudo apt-get -f install
sudo apt-get install gdebi
sudo gdebi teamviewer-host_armhf.deb
Copy the code

Accept the agreement and you will see the TeamViewer icon in the top right corner of your desktop. Click Easy Access, then log in to your account, and you’ll be able to connect remotely.

3. Win32DiskImager

In addition to the raspberry PI official website burning tools, you can also use Win32DiskImager to write images, small and convenient green, no need to install.

The software can not only write, but also image export, which makes it easy to save multiple development environments, especially after configuring OpenCV and PyTorch is cumbersome, so you don’t have to redo the system and configuration every time.

System backup

The size of the Win32DiskImager backup file depends on the size of MircoSD. Therefore, you are advised to run the dd command to back up the Win32DiskImager and then compress the image in Linux.

1. View the device name

Run LSBLK to view the drive letter of MircoSD, which is usually SDB.

lsblk
Copy the code

2. Run the dd command to back up the SD card

Run the dd command to copy the SD card data and save it as an IMG image file.

sudo dd if=/dev/sdb of=./rpi_backup.img bs=8M
Copy the code

3. Compress the backup image

Use PiShrink to reduce the image size

git clone https://github.com/Drewsif/PiShrink.git
cd PiShrink
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin
sudo pishrink.sh -s rpi_backup.img new_rpi_backup.img
Copy the code

More parameters are as follows:

Usage: $0 [-adhrspvzZ] imagefile.img [newimagefile.img]
  -s         Don't expand filesystem when image is booted the first time
  -v         Be verbose
  -r         Use advanced filesystem repair option if the normal one fails
  -z         Compress image after shrinking with gzip
  -Z         Compress image after shrinking with xz
  -a         Compress image in parallel using multiple cores
  -p         Remove logs, apt archives, dhcp leases and ssh hostkeys
  -d         Write debug messages in a debug log file
Copy the code

Tip:

Pishrink. Sh: ERROR occured in line 275: resize2fs failed mount: / TMP/tmp.sj9z4exLzv: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error. mv: Unable to get ‘/ TMP/TMP. Sj9Z4EXlzV/etc/rc. Local. Bak’ file status (stat) : no file or directory umount: / TMP/TMP. Sj9Z4EXlzV: not mount. Losetup: /dev/loop0: Failed to disconnect: there is no device or address

Set var LANG=en_US. utF-8 could fix it.

4. Clone and back up the SD card

Use Win32DiskImager (backup file large speed fast), or dd command after compression (long file small), there is another way is directly in the Raspberry PI SD card clone. Remember to buy a few MircoSD cards in the hardware section, here it is useful.

# Check the disk space and SD card mounting information df -hCopy the code

Insert the blank Card into the raspberry PI in USB reader mode, then go to the main menu –> Accessories –> SD Card Copier, select /dev/mmcblk0 as the source disk, select /dev/sda as the target disk, and click Start to Start copying.

Insert another raspberry PI directly available, inserted 2 USB card readers can restore the image of each other.

Software download

The software mentioned above has been uploaded to the Baidu web disk, the public account “Deep Awakening”, the background reply: “RPI02”, you can get the download link.


Next preview

We will start compiling OpenCV, PyTorch installation Tensorflow and other development environment, stay tuned…