JETSON-NANO-DEV-KIT-MANUAL

From Waveshare Wiki
Jump to: navigation, search
Servo Driver HAT
JETSON-NANO-DEV-KIT-MANUAL.jpg
Servo Driver HAT (B)
JETSON-NANO-DEV-KIT-MANUAL2.jpg

128- Core NVIDIA Maxwell™
64-bit Quad-core ARM A57 (1.43GHz)
4GB 64-bit LPDDR4 25.6GB/s
{{{name3}}}

{{{name4}}}

{{{name5}}}

Overview

Note

If you purchased the Nano kit with the module provided by Waveshare, we have programmed the JetPack4.6 image on the emmc before leaving the factory, and have set the SD card recognition. If you need to modify the SD card startup, please refer to the manual to modify the startup path.
If you have special requirements for the factory image version, please contact the customer service of the Waveshare shop to communicate and confirm.

Introduction

Based on AI computers Jetson Nano and Jetson Xavier NX, providing almost the same peripheral interfaces, size and thickness as the Jetson Nano Developer Kit (B01), more convenient for upgrading the core module. By utilizing the power of core module, it is qualified for fields like image classification, object detection, segmentation, speech processing etc. and can be used in sorts of AI projects.

  • The header switch of the DC power supply has been canceled, which means that we can directly insert the DC power supply to the circular interface and do not need to use a jumper cap to short the J48 interface first.
  • Waceshare JETSON-NANO-DEV-KIT not only supports U-disk booting but also supports TF card booting as it has integrated a TF card slot on the expansion board. The reading and writing are stable, and it is almost the same as the B01 official core board with a TF card slot.

System Installation

System Environment Construction

  • The programming system needs to use the Ubuntu 18.04 host or virtual machine, and use the SDK Manager tool to program.
  • The system environment in this manual uses VMware 16 virtual machine to install Ubuntu 18.04 system, only for learning.
  1. Download SDK Manager: open the browser and enter the URL, click to download SDK Manager.
https://developer.nvidia.com/zh-cn/embedded/jetpack

JETSON-NANO-DEV-KIT-MANUAL01.png
You need to register an account. After logging in, we can download it successfully. If you don't know how to register, you can refer to NVIDIA-acess
2. After the download is complete, we enter the download path Downloads to install, and input the following content in the terminal:

sudo dpkg -i sdkmanager_1.6.1-8175_amd64.deb (enter according to your own version).

JETSON-NANO-DEV-KIT-MANUAL02.png
3. After the installation is complete, the system may report an error that the dependency files cannot be found. Enter the following command to solve this problem.

sudo apt --fix-broken install

4. Open the Ubuntu computer terminal and run the SDK Manager to open the software.
5. Click LOGIN, log in to the NVIDIA account, and a link will pop up in the browser, enter the previous registered email and password to log in.
JETSON-NANO-DEV-KIT-MANUAL03.png
6. At this point we have successfully logged in to the SDK Manager.
JETSON-NANO-DEV-KIT-MANUAL04.png

Install image on EMMC

Equipment Preparation

  1. Jetson Nano board
  2. 5V/4A power adapter
  3. Jumper caps (or Dupont wire)
  4. USB data cable (Micro USB interface, can transfer data)

Hardware configuration (enter recovery mode)

  1. Use jumper caps or Dupont wires to short-circuit the FC REC and GND pins, as shown in the figure below, at the bottom of the core board.
  2. Connect the DC power supply to the circular power port and wait a moment.
  3. Connect the Micro USB port of the Jetson Nano to the Ubuntu host with a USB cable (note that it is a data cable).

JETSON-NANO-DEV-KIT-MANUAL07.png

System Programming

  1. Open the Ubuntu computer terminal and run the SDK Manager to open the software.
  2. Using a virtual machine requires setting up the device to connect to the virtual machine.

JETSON-NANO-DEV-KIT-MANUAL08.png
3. Log in to your account, if the Jetson Nano is recognized normally, SDK Manager will detect and prompt options.
JETSON-NANO-DEV-KIT-MANUAL09.png
4. In the JetPack option, take the JetPack4.6 system as an example, uncheck Host Machine and click CONTINUE.
JETSON-NANO-DEV-KIT-MANUAL10.png
5. Select Jetson OS, and remove the option of Jetson SDK Components. Check the protocol and click CONTINUE.
JETSON-NANO-DEV-KIT-MANUAL11.png
6. The path saved by HW Imager is good by default. Select Create and the path will be created automatically.
JETSON-NANO-DEV-KIT-MANUAL12.png
7. Enter the virtual machine password, wait for the download, and the programming is complete.
JETSON-NANO-DEV-KIT-MANUAL13.png

    • Starting from JetPack 4.6.1, the preconfig window will pop up when using SDK Manager to program the system.
    • Here, the development board type is selected by default. Be careful not to make a mistake when selecting the type of development board earlier.
    • Here, we select Manual Setup-Jetson Nano.

8. After the programming is completed, remove the jumper cap of the baseboard, connect to the monitor, power on again, and follow the prompts to configure the boot (if it is pre-config set, it will directly enter the system after power on).

U disk and TF card booting principle

  • U disk or TF card startup is to start the system on the EMMC in the core board first, and then the system of the core board is guided to the U disk to start or the TF card to start.
  • The system in the core board can use the SDK Manager in the virtual machine to program the system; the TF card system can use Win32DiskImager to program the system; the system in the U disk uses the virtual machine to program the system.
  • When preparing for U disk startup or TF card startup, first ensure that the EMMC system is successfully programmed.

Install image in the U disk

Preparation

  1. Jetson Nano board
  2. Ubuntu18.04 virtual machine (or computer host)
  3. U disk or mobile hard disk with USB interface (USB3.0 is recommended)
  4. One USB cable (Micro USB interface, which can transmit data)
  5. 5V/4A power adapter

System Installation

  • To avoid errors in the process of programming the image, you need to use the Panasonic_SDFormatter-SD card formatting software to format the U disk before programming the image.
  • Pay special attention when formatting, if your computer has another removable hard disk inserted, do not format the wrong drive.

1. Connect the U disk to the Jetson Nano, check the device number of the U disk, such as sda, open the Jetson Nano terminal, and enter.

ls /dev/sd*

2. Connect the U disk to the computer and choose to connect to the virtual machine.
JETSON-NANO-DEV-KIT-MANUAL08.png
3. View the device number of the U disk on the computer, such as sdb.

sudo lsblk -p -d | grep sd
    • At this point, we get two device numbers: the U disk is connected to the Jetson nano device number sda, and the U disk is connected to the virtual machine device number sdb.

4. Use a virtual machine to install the system on the U disk, first format the U disk to ext4 format.

sudo mkfs.ext4 /dev/sdb

Note: Please refer to your actual situation for the specific device number. Some devices may be sda or others.
5. Mount the U disk.

sudo mount /dev/sdb /mnt

6. Enter the HW Imager address and copy the rootfs root file system (the HW Imager address is the path automatically generated when EMMC flashes the system).

cd <path>/Linux_for_Tegra/rootfs/

7. Note: Please refer to your actual address. For example, and my path command is:

cd /home/jetson/nvidia/nvidia_sdk/JetPack_4.6_Linux_JETSON_NANO_TARGETS/Linux_for_Tegra/rootfs

8. After the copy is complete, unmount the U disk (don't plug it out):

sudo umount /mnt

9. Set the nano to recovery mode (refer to the flashing tutorial), then connect to the virtual machine and program the bootloader from the U disk.

cd ../
sudo ./flash.sh jetson-nano-emmc sda

Note: The sda here should be filled in as the actual device number of the U disk identified in the Jetson Nano in the first step.
After flashing is complete. Disconnect the Jetson Nano and the USB flash drive, connect the USB flash drive to the Jetson Nano, power on it, and follow the prompts to complete the configuration process.

Install Image on TF Card

Preparation

  1. Jetson Nano board
  2. Ubuntu18.04 virtual machine (or computer host)
  3. 64G TF card and TF card reader
  4. One USB cable (Micro USB interface, which can transmit data)
  5. 5V/4A power adapter

System Installation

  1. To avoid errors in the process of programming the image, you need to use the Panasonic_SDFormatter-SD card formatting software to format the TF card before programming the image.
  2. Pay special attention when formatting, if your computer has another removable hard disk inserted, do not format the wrong drive.
  3. First download the TF card image, the image must be initialized, otherwise it will fail to boot, you can download the image provided by Waveshare.
  4. Open Win32DiskImager image software, insert the TF card into the card reader and insert the card reader into the computer.
  5. Select the downloaded image file, click "Write" and wait for the writing to complete.

Program Boot Loader

1. Install dtc software in the virtual machine.

sudo apt-get install device-tree-compiler

2. Enter the HW Imager kernel path, decompile the dts source file (for different jetpacks, modify the corresponding path).

cd ~/nvidia/nvidia_sdk/JetPack_4.6_Linux_JETSON_NANO_TARGETS/Linux_for_Tegra/kernel/dtb
dtc -I dtb -O dts -o tegra210-p3448-0002-p3449-0000-b00.dts tegra210-p3448-0002-p3449-0000-b00.dtb

3. Modify the device tree

sudo vim tegra210-p3448-0002-p3449-0000-b00.dts

4. Find the following part, change status = "disable" to okay, and add TF information below:

cd-gpios = <0x5b 0xc2 0x0>;
sd-uhs-sdr104;
sd-uhs-sdr50;
sd-uhs-sdr25;
sd-uhs-sdr12;
         
no-mmc;
uhs-mask = <0xc>;

JETSON-NANO-DEV-KIT012.png
5. Compile dtb file.

dtc -I dts -O dtb -o tegra210-p3448-0002-p3449-0000-b00.dtb tegra210-p3448-0002-p3449-0000-b00.dts

6. To program the system, the Jetson Nano needs to enter the recovery mode and connect to the Ubuntu computer.

cd ~/nvidia/nvidia_sdk/JetPack_4.6_Linux_JETSON_NANO_TARGETS/Linux_for_Tegra
sudo ./flash.sh jetson-nano-emmc mmcblk1p1

How to Expand U disk or TF card system

  • GParted is a very powerful partitioning tool under Linux. GParted can easily create and delete partitions, as well as resize and move partitions.

1. When we use a U disk or TF card larger than the image memory to program the image, there will be a part of the free memory that cannot be used.

df -h

2. Download GParted Disk Partitioning Tool.

sudo apt-get update
sudo apt-get install gparted -y

3. Click "Open" in the search bar or enter the following command in the terminal to open.

gparted

JETSON-NANO-DEV-KIT-MANUAL012.png
After opening, you will be prompted to enter the login password.
JETSON-NANO-DEV-KIT-MANUAL013.png
4. First look at the upper right corner, click and two partitions will appear:"mmcblk0" and "mmcblk1".
Among them, mmcblk0 is the EMMC storage device that comes with Jetson Nano, and mmcblk1 is the TF card storage device.
If you are using a U disk, the sda partition is usually displayed.
JETSON-NANO-DEV-KIT-MANUAL0013.png
5. We select mmcblk1 (if it is a U disk boot, select sda) and find that 14.4g is not allocated.
Click on the allocated part, and the yellow arrow above changes from gray to yellow.
JETSON-NANO-DEV-KIT-MANUAL014.png
JETSON-NANO-DEV-KIT-MANUAL015.png
6. Drag the arrow directly to expand the partition to the maximum.
Click "Resize", and the "Apply".
After waiting, we click the green arrow to successfully assign the partition.
JETSON-NANO-DEV-KIT-MANUAL016.png
JETSON-NANO-DEV-KIT-MANUAL017.png
JETSON-NANO-DEV-KIT-MANUAL018.png
7. At this point, the viewing space in the terminal matches the TF card space.

df -h

Login

Offline Login

  • Use the image provided by Waveshare, the user name and user password are as follows:
Username: waveshare
User password: waveshare

Remote Login

Preparation

  • Please connect Jetson Nano by a network cable, and then connect the LAN port of the router with the other end of the cable.
  • Please make sure Jetson Nano and your computer are under the same router or the network segment.

Get Jetson Nano IP

  • Method 1: Log in to the router to find the IP of Jetson Nano.
  • Method 2: You can use some LAN IP scanning tools, here is an example of Advanced IP Scanner.
  1. Run Advanced IP Scanner.
  2. Click the "Scan" button to scan the IP in the current LAN.
  3. Find "all" IP with the word "NVIDIA" in Manufacture and then record.

JETSON-NANO-DEV-KIT IP01.png

4. Power on the device and connect to the network.
5. Please click the "Scan" button again to scan the IP in the current LAN.
6. Exclude all the IP addresses with the word "NVIDIA" in the previously recorded Manufacturer, and the rest is your NVIDIA IP address.

Log in with MobaXterm

Terminal Window

  1. Download MobaXterm and unzip it to use.
  2. Open XobaXterm, click Session and choose "ssh".
  3. Enter the IP address 192.168.15.102 we queried earlier in the Remote host (fill in according to your actual IP), after filling in, click ok.

JETSON-NANO-DEV-KIT terminal.png

4. Click "Accept". Waveshare provides the image login name: waveshare, enter the login password: waveshare (when entering the password, the screen does not change is a normal phenomenon, click Enter to confirm.)

JETSON-NANO-DEV-KIT terminal2.png

Nomachine Login

  • Compared with SSH and VNC, you may not know much about Nomachine. Nomachine is free remote desktop software.
  • NoMachine basically covers all major operating systems, including Windows, Mac, Linux, iOS, Android and Raspberry, etc.

Install on Jetson Nano

  1. Download and unzip NoMachine
  2. After unzipping, please use U disk or file transmission to copy ".deb" file to Jetson Nano.
  3. Install it with the following commands:
sudo dpkg -i nomachine_7.10.1_1_arm64.deb

Install on Windows PC

  • Download NoMachine and then install. After clicking "Finish", you have to reboot your computer.

Nomachine.gif

Connect to Jetson Nano

1. Open NoMachine and then enter the IP of Jetson Nano in the "Search" bar. For example, "192.168.15.100".
Jetson Nano Dev Kit No.png
2. Click "Connect to new hos 192.168.15.100", and then enter the username and password of Jetson Nano. Click "login".
Jetson Nano Dev Kit No02.png
3. After loading, there is an interface for software introduction, and we just need to click "OK".
Jetson Nano Dev Kit No03.png
4. By now, we can log in to Jetson Nano successfully.
Jetson Nano Dev Kit No04.png

VMC Login

  • In the absence of a display screen, if you want to enter the desktop of the Jetson Nano, you need to use the remote desktop to log in. (It is recommended to use the display screen, VNC has a certain delay).

Configure the VNC Server

  • Jetson Nano uses vino as the default VNC server, but the default settings need some modifications.

1. Configure VNC Server:

gsettings set org.gnome.Vino require-encryption false
gsettings set org.gnome.Vino prompt-enabled false
gsettings set org.gnome.Vino authentication-methods "['vnc']"
gsettings set org.gnome.Vino lock-screen-on-disconnect false
gsettings set org.gnome.Vino vnc-password $(echo -n "mypassword"|base64)
  • It should be noted that do not use sudo to run the above command, mypassword is the password to connect to VNC.

2. Set the desktop to start automatically at boot, and create a new self-starting file in the .config path.

 mkdir -p .config/autostart
sudo vim ~/.config/autostart/vino-server.desktop

Add the following content:

[Desktop Entry]
Type=Application
Name=Vino VNC server
Exec=/usr/lib/vino/vino-server
NoDisplay=true

3. Check what manager you are currently using:

cat /etc/X11/default-display-manager

4. Edit the file:

sudo vim /etc/gdm3/custom.conf

5. Remove the comments on the following three lines, and modify the AutomaticLogin line to your own username.

WaylandEnable=false
AutomaticLoginEnable = true
AutomaticLogin = waveshare

6. Reboot Jetson Nano:

sudo reboot

Download and Install VNC Viewer

Remotely connect to Jetson Nano using VNC Viewer

1. Open VNC Viewer, enter the IP address of Jetson Nano and press Enter to confirm. For example:

192.168.15.102

2. Enter the VNC login password set earlier and click "Ok":
3. At this point, you have successfully logged in to Jetson Nano.
500px

Linux Basic Operation

Common Command Introduction

File System

sudo

  • The sudo command executes commands as a system administrator.
  • To use the root user, log in as the waveshare user and execute the following command:
sudo su #Switch to super user
su waveshare #Switch common users

ls

  • The ls command is used to display the contents of the specified working directory (list the files and subdirectories contained in the current working directory).
  • Commonly used commands:
ls
ls -a #Show all files and directories (hidden files starting with . are also listed)
ls -l #In addition to the file name, it also lists the file type, permissions, owner, file size and other information in detail
ls -lh #file sizes are listed in an easy-to-understand format, e.g. 4K
  • To learn about more parameters of the command, we can use the "help" command to view:
ls --help

chmod

  • The chmod command is for users to control permissions on files.
  • The file calling permissions of Linux/Unix is divided into three levels: file owner (Owner), user group (Group), and other users (Other Users).
  • In the figure below, the detailed file information under the Linux root directory is displayed. Among these file information, the most important is the first column, which describes in detail the permissions of files and directories, while the third and fourth columns show which user or group the file and directory belong to.

Chmod02.png

  • There are three file attributes in Linux: read-only (r), write (w), and executable (x). However, the above file attributes are divided into 10 small cells, because in addition to the first cell displaying the directory, the other three groups of three cells respectively represent the file owner permissions, permissions within the same group, and other user permissions.
    • If d is displayed in the first column, it means that this is a directory; if it is a link file, l is displayed here; if it is a device file, c is displayed.
    • The first rwx field: -rwx------ indicates the permissions of the file owner.
    • The second rwx field: ---rwx--- indicates user rights within the same workgroup.
    • The third rwx field: ------rwx indicates other user rights.
    • E.g:
    • -rwx rwx rwx means that no matter which user can read, write and execute this file.
    • -rw- --- --- Indicates that only the file owner has read and write permissions, but no execute permissions.
    • -rw -rw -rw means that all users have read and write rights.
  • Symbolic mode
    • who (user type)
who User Type Description
u user file owner
g group The file owner's group
o others All other users
a all User used, equivalent to ugo
    • operator (symbol pattern table)
Operator Description
+ Increase permissions for the specified user type
- Remove the permission of the specified user type
= Set the settings of the specified user permissions, that is to reset all permissions of the user type
    • permission (symbol pattern table)
Mode Name Description
r read set to read permission
w write set to writable permission
x Execute permission Set as executable permission
X Special execution permission Set the file permission to be executable only when the file is a directory file, or other types of users have executable permission
s setuid/gid When the file is executed, set the file's setuid or setgid permissions according to the user type specified by the who parameter
t paste bit set the paste bit, only superuser can set this bit, only file owner u can use this bit
    • Symbolic Pattern Examples
1. Add read permissions to all users of the file:
chmod a+r file
2. Remove execute permission for all users of the file:
chmod a-x file
3. Add read and write permissions to all users of the file:
chmod a+rw file
4. Add read, write and execute permissions to all users of the file:
chmod +rwx file 
5. Set read and write permissions to the owner of the file, clear all permissions of the user group and other users to the file (space means no permission):
chmod u=rw,go= file
6. Add read permission to the user for all files in the directory waveshare and its subdirectory hierarchy, and remove read permission for the user group and other users:
chmod -R u+r,go-r waveshare
  • Octal literals
    • The chmod command can use octal numbers to specify permissions. The permission bits of a file or directory is controlled by 9 permission bits, each of which is a group of three, which are read, write, and execute for the file owner (User), read, write, and execute for the user group (Group). Other users (Other) read, write, and execute.
# Permissions rwx Binary
7 Read + Write + Execute rwx 111
6 Read + Write rw- 110
5 read + execute rwx 101
4 Read only r-- 100
3 Write + Execute -wx 011
2 Write only -w- 010
1 Only execute --x 001
0 None --- 000
  • For example, 765 is interpreted as follows:
    • The owner's permission is expressed in numbers: the sum of the numbers of the owner's three permission bits. For example, rwx, which is 4+2+1, should be 7.
    • The permissions of a user group are expressed in numbers: the sum of the numbers of the permission bits that belong to the group. For example, rw-, which is 4+2+0, should be 6.
    • The permission of other users expressed in numbers: the sum of the numbers of other users' permission bits. For example, r-x, which is 4+0+1, should be 5.
  • Commonly used digital permission:
    • 400 -r------- The owner can read, no one else can operate;
    • 644 -rw-r–r-- all owners can read, but only the owner can edit;
    • 660 -rw-rw---- Both owner and group users can read and write, others cannot operate;
    • 664 -rw-rw-r-- readable by everyone, but editable only by owner and group users;
    • 700 -rwx------ The owner can read, write and execute, other users cannot do anything;
    • 744 -rwxr–r-- everyone can read, but only the owner can edit and execute;
    • 755 -rwxr-xr-x everyone can read and execute, but only the owner can edit;
    • 777 -rwxrwxrwx Everyone can read, write and execute (this setting is not recommended).
  • For example:
    • Add read permissions to all users of the file, and the owner and group users can edit:
      sudo chmod 664 file

touch

  • The touch command is used to modify the time attributes of a file or directory, including access time and change time. If the file does not exist, the system will create a new file.
  • For example, in the current directory, use this command to create a blank file "file.txt" and enter the following command:
touch file.txt

mkdir

  • The "mkdir" command is used to create directories.
  • In the working directory, create a subdirectory named waveshare:
sudo mkdir waveshare
  • Create a directory named waveshare/test in the working directory.
sudo mkdir -p waveshare/test
  • If the waveshare directory does not already exist, create one. (Note: If the -p parameter is not added in this example, and the original waveshare directory does not exist, an error will occur.)

cd

  • Change the current working directory:
cd .. #Return to the previous directory
cd /home/waveshare #Enter /home/waveshare directory
cd #return to user directory

cp

  • The cp command is mainly used to copy files or directories.
  • parameter:
    • -a: This option is usually used when copying directories, it preserves links, file attributes, and copies everything under the directory. Its effect is equal to the combination of dpR parameters.
    • -d: keep links when copying. The links mentioned here are equivalent to shortcuts in Windows systems.
    • -f: Overwrite existing object files without prompting.
    • -i: Contrary to the -f option, give a prompt before overwriting the target file, asking the user to confirm whether to overwrite and answer "y" the target file will be overwritten.
    • -p: In addition to copying the contents of the file, also copy the modification time and access rights to the new file.
    • -r: If the given source file is a directory file, all subdirectories and files in the directory will be copied.
    • -l: Do not copy files, just generate link files.
  • Use the command cp to copy all the files in the current directory test/ to the new directory "newtest", and enter the following command:
sudo cp –r test/ newtest

mv

  • The mv command is used to rename a file or directory or move a file or directory to another location.
  • parameter:
    • -b: When the target file or directory exists, create a backup of it before performing the overwrite.
    • -i: If the specified moving source directory or the file has the same name as the target directory or file, it will first ask whether to overwrite the old file. Enter "y" to directly overwrite, and "n" to cancel the operation.
    • -f: If the source directory or file specified to be moved has the same name as the target directory or file, it will not be asked, and the old file will be overwritten directly.
    • -n: Do not overwrite any existing files or directories.
    • -u: The move operation is performed only when the source file is newer than the target file or the target file does not exist.
  • Use the command mv to copy the file1 file in the current directory test/ to the new directory /home/waveshare, and enter the following command:
sudo mv file1 /home/waveshare

rm

  • The rm command is used to delete a file or directory.
  • parameter:
    • -i: ask for confirmation one by one before deleting.
    • -f: even if the original file attribute is set to read-only, it will be deleted directly without confirming one by one.
    • -r: delete the files in the directory and below one by one.
    • To delete a file, you can use the "rm" command directly. If you delete a directory, you must use the option "-r", for example:
      sudo rm  test.txt
    • rm: delete the general file "test.txt"? y
      sudo rm  homework
    • rm: cannot delete directory "homework": is a directory.
      sudo rm -r homework
    • rm: delete the directory "homework"? y

reboot

  • The reboot command is used to restart the computer. Changing the configuration of Tinker Board 2 often requires restarting.
  • parameter:
    • -n: do not write the memory data back to the hard disk before rebooting.
    • -w: don't actually reboot, just write the log to the /var/log/wtmp file.
    • -d: do not write logs to the /var/log/wtmp file (-d is included with the -n parameter).
    • -f: force reboot, do not call shutdown command.
    • -i: stop all network related devices before rebooting.
  • reboot
sudo reboot

shutdown

  • When the Jetson Nano is turned off, you cannot directly unplug the power cord, because the Tinker Board 2 will use the memory as a temporary storage area. If you directly unplug the power cord, some data in the memory will not have time to be written to the SD card, resulting in data loss. The data on the SD card is lost or damaged, causing the system to fail to boot.
  • Parameter:
    • -t seconds: set the shutdown procedure after a few seconds.
    • -k: don't actually shut down, just send a warning message to all users.
    • -r: reboot after shutdown.
    • -h: shutdown after shutdown.
    • -n: do not use the normal program to shut down, use the forced method to kill all the programs in execution and then shut down by itself.
    • -c: cancel the shutdown action that is currently in progress.
    • -f: do not do fsck when shutting down (check Linux file system).
    • -F: force fsck action on shutdown.
    • time: Set the shutdown time.
    • message: The warning message is sent to all users.
  • Example:
    • Shut down now.
      sudo shutdown -h now
    • Shutdown after specified 10 minutes.
      sudo shutdown -h 10
    • restart the computer.
      sudo shutdown -r now
  • No matter which command is used to shut down the system, root user authority is required. If the user uses a common user such as linaro, the sudo command can be used to temporarily obtain root authority.

pwd

  • The pwd command displays the name of the current working directory: on Jetson nano, typing "pwd" will output something like "/home/waveshare".

head

  • The "head" command displays the beginning of the file, which can be used with "-n" to specify the number of lines to display (default is 10), or with "-c" to specify the number of bytes.
head test.py -n 5

tail

  • The tail shows the end of the file. -c bytes or -n lines specify the starting point in the file.

df

  • Displays available and used disk space on mounted filesystems. Use df -h to see the output in a readable format, use M for MB instead of bytes.
df -h

tar

  • The "tar" command is a tool program used to create and restore backup files. It can add and unpack files in backup files.
  • Compressed file:
tar -cvzf waveshare.tar.gz *
  • unzip files:
tar -xvzf waveshare.tar.gz

apt

  • "apt" (Advanced Packaging Tool) is a shell front-end package manager in Debian and Ubuntu.
  • The "apt" command provides commands for finding, installing, upgrading, and removing a package, a group of packages, or even all packages, and the commands are concise and easy to remember.
  • "apt" command execution requires super administrator privileges (root).
  • "apt" common commands:
    • List all updatable software inventory commands: sudo apt update.
    • Upgrade packages: sudo apt upgrade.
    • List updatable packages and version information: apt list --upgradeable.
    • Upgrade packages, delete the packages that need to be updated before upgrading: sudo apt full-upgrade.
    • Install the specified software command: sudo apt install <package_name>.
    • Install multiple packages: sudo apt install <package_1> <package_2> <package_3>.
    • Update the specified software command: sudo apt update <package_name>.
    • Display package specific information, such as version number, installation size, dependencies, etc.: sudo apt show <package_name>.
    • Remove package command: sudo apt remove <package_name>.
    • Clean up unused dependencies and libraries: sudo apt autoremove.
    • Remove packages and configuration files: sudo apt purge <package_name>.
    • Find packages command: sudo apt search <keyword>.
    • List all installed packages: apt list --installed.
    • List version information of all installed packages: apt list --all-versions.
  • For example, we install nano editor.
sudo apt install nano

Network

ifconfig

  • Used to display the network configuration details of an interface on the current system when run with no arguments (ie) ifconfig.
  • When connecting with SSH, you can find the IP address through ifconfig, and enter the terminal:
ifconfig
  • Check the IP address of the wired network, input the terminal:
ifconfig eth0
  • Check the IP address of the wireless network and enter the terminal:
ifconfig wlan0

hostname

  • The hostname command displays the current hostname of the system. When we use Jetson Nano, we often need to use remote tools, and the default network configuration IP address adopts dynamic allocation, which will cause the problem of IP address uncertainty.
  • When the IP address of our Jetson Nano changes, it is possible to log in using the hostname.

1. Log in to Jetson Nano, and modify the host file, the command is as follows:

sudo vim /etc/hosts
  • Replace jp46 with the name to be modified, such as Waveshare, press the keyboard ZZ to save and exit:

Jetson nano hostname.png
2. Modify the hostname file, and replace the jp46 here with the name to be modified, such as waveshare, and press the keyboard ZZ:

sudo vim /etc/hostname

Jetson nano hostname2.png
3. After the modification is completed, restart the Jetson Nano:

sudo reboot

4. We can also check the IP address with the following command:

hostname -I

Vim Editor User Guide

  • The Vim editor is a standard editor under all Unix and Linux systems. Its power is not inferior to any of the latest text editors. Here is just a brief introduction to its usage and common commands.
  • Basically vim is divided into three modes, namely command mode (Command mode), input mode (Insert mode), and **bottom line command mode (Last line mode).
    • Command mode: control the movement of the screen cursor, delete characters, words or lines, move and copy a section.
    • Input Mode: Input characters and edit files in this mode.
    • Bottom line mode: save the file or exit vim, you can also set the editing environment, such as finding strings, **listing line numbers, etc.
    • We can think of these three modes as the icons at the bottom:

Jetson nano vim01.png
1. First remove the default Vi editor:

sudo apt-get remove vim-common

2. Then reinstall Vim:

sudo apt-get install vim

3. For convenience, you have to add the following three sentences after the /etc/vim/vimrc file:

set nu #display line number
syntax on # syntax highlighting
set tabstop=4 #tab back four spaces

Common Command

  • Open file, save, close file (use in vi command mode):
vim filename //Open the filename file
        :w // save the file
        :q //Quit the editor, if the file has been modified please use the following command
        :q! //Quit the editor without saving
        :wq //Exit the editor and save the file
        :wq! //Force quit the editor and save the file
        ZZ //Exit the editor and save the file
        ZQ //Exit the editor without saving
  • Insert text or line (used in vi command mode, after executing the following command, it will enter insert mode, press ESC key to exit insert mode:
a //Add text to the right of the current cursor position
i //Add text to the left of the current cursor position
A //Add text at the end of the current line
I //Add text at the beginning of the current line (the beginning of the line with a non-empty character)
O //Create a new line above the current line
o //Create a new line below the current line
R //Replace (overwrite) the current cursor position and some text behind it
J //Merge the line where the cursor is located and the next line (still in command mode)
  • Delete and restore characters or lines (used in vi command mode):
x // delete the current character
nx // delete n characters from the cursor
dd // delete the current line
ndd //Delete n lines including the current line down
u //Undo the previous operation
U //Undo all operations on the current row
  • Copy and paste (used in vi command mode):
yy //Copy the current line to the buffer
nyy //Copy the current line down n lines to the buffer
yw //Copy the characters from the cursor to the end of the word
nyw //Copy n words starting from the cursor
y^ //Copy the content from the cursor to the beginning of the line
y$ //Copy from cursor to end of line
p //Paste the contents of the clipboard after the cursor
P //Paste the contents of the clipboard before the cursor

Configuration

File transmission

This tutorial takes a Windows system to remotely connect to a Linux server as an example. There are multiple ways to upload local files to the server.

MobaXterm File Transmission

  • Transferring files with MobaXterm tool is very simple and convenient.
    • To transfer files from Windows to Raspberry Pi simply drag the files to the left directory of MobaXterm.
    • Similarly, to transfer Raspberry Pi files to Windows, just drag the files in the left directory of MobaXterm to Windows.

Jetson nano vim010.gif

NoMachine File Transmission

  • When the NoMachine remote connection is successful, the NoMachine icon will appear in the upper right corner of the Jetson Nano desktop. We click the icon and select Transfer a file.
    • Upload file from the client is to transfer files from a Windows computer to the Jetson Nano.
    • Download file from the server is to transfer files from Jetson Nano to Windows computer.

Jetson nano vim011.png

SCP File Transmission

  • The SCP command can be used to securely copy or encrypt transfer files and directories across Linux systems.
  • Format:
scp +parameter +username/login name+@+hostname/IP address+ : + target file path+local storage path
  • First enter the directory where you want to store the file, hold down the keyboard Shift and right-click the blank space to open Windows PowerShell.
  • Copy the file from the Jetson Nano to the local Windows and enter it in the terminal:
scp [email protected]:file .

Where "." represents the current path.

  • Copy the file from the local Windows to the Jetson Nano and enter it in the terminal:
scp file [email protected]:
  • Copy the file folder from the Jetson Nano to the local Windows. Since the file is a directory, you need to add the parameter r and enter it in the terminal.
scp -r [email protected]:/home/pi/file .
  • Copy the file folder from the local Windows to the Jetson Nano and type in the terminal:
 scp -r file [email protected]:

Note: The above waveshare needs to be changed to the username of your system, and the IP address to the actual IP address of Jetson Nano.

File sharing (Samba)

File sharing is possible using the Samba service. The Jetson Nano file system can be accessed in the Windows Network Neighborhood, which is very convenient.
1. First install Samba, enter into the terminal:

sudo apt-get update
sudo apt-get install samba -y

2. Create a shared folder sambashare in the /home/waveshare directory.

mkdir sambashare

3. After the installation is complete, modify the configuration file /etc/samba/smb.conf:

sudo nano /etc/samba/smb.conf

Pull to the end of the file and add the following statement to the end of the file.

[sambashare]
    comment = Samba on JetsonNano
    path = /home/waveshare/sambashare
    read only = no
    browsable = yes

Note: waveshare here needs to be changed to your system username. In other words, path is the shared folder path you want to set.
4.Restart the Samba service.

sudo service smbd restart

5. Set shared folder password:

sudo smbpasswd -a waveshare

Note: The username here needs to be changed to the username of your system. If it is not the username, it will fail.
You will be asked to set a Samba password here. It is recommended to use your system password directly, which is more convenient to remember.
6. After the setup is complete, on your computer, open the file manager.

\\192.168.15.100\sambashare

7. Enter the login name and password set in step 5 earlier.
Jetson nano vim012.png
8. Let's verify, create a new test folder in windows, and you can see the test folder in the Jetson Nano sambashare directory.
Jetson nano vim013.png

System Backup

  1. Create a new blank file with the .img suffix on the Windows computer desktop. Insert the SD card with the system image and select the drive letter of the corresponding SD card.
  2. Open Win32DiskImager, click "Read", and then convert Jetson Nano's SD card file to an image.

Camera

View the first connected camera screen:

nvgstcapture-1.0

View the picture of the second camera connected:

nvgstcapture-1.0 --sensor-id=1

The default camera model is IMX219. If you need to change the camera of other models, execute

sudo /opt/nvidia/jetson-io/jetson-io.py

Select Configure Jetson Nano CSI Connector -->> Configure for compatible hardware.
Select the corresponding camera model:

| Camera IMX219 Dual |

| Je Camera IMX477 Dual or: |

| Camera IMX477-A and IMX219-B |

|ConfigurCamera IMX219 Dualardware |

After selecting Save pin changes -->> Save and reboot to reconfigure pins.
Just wait for restart.

FAN

Fan speed adjustment, note that 4 wires are required to debug the fan.

sudo sh -c 'echo 255 > /sys/devices/pwm-fan/target_pwm'
#Where 255 is the maximum speed, 0 is stop, modify the value to modify the speed
cat /sys/class/thermal/thermal_zone0/temp
#Get the CPU temperature, you can intelligently control the fan through the program
#The system comes with a temperature control system, and manual control is not required in unnecessary situations

Wi-Fi connection without display (applicable to packages with wireless network card)

  • After the first successful login, we want to connect to WiFi later.

1. Scan WIFI.

sudo nmcli dev wifi

2. Connect to the WIFI network ("wifi_name" and "wifi_password" need to be replaced with the SSID and password of your actual WiFi.)

sudo nmcli dev wifi connect "wifi_name" password "wifi_password"

3. If "successfully" is displayed, the wireless network is successfully connected, and the motherboard will automatically connect to the WiFi you specified next time it is powered on.
Jetson nano vim016.png

Getting Started with AI

  • This tutorial is based on the JetPack4.6 system image, the Python version is Python3.6, the TensorFlow version is 2.5.0, and the Pytorch version is 1.9.0 as an example.
  • Note: The TensorFlow version and the Pytorch version must correspond to the JetPack version.

PIP Installation

1. Python3.6 version is installed by default in Jetson Nano, directly install PIP.

sudo apt update
sudo apt-get install python3-pip python3-dev

2. After the installation is complete, we check the PIP version.

pip3 -V

Jetson Nano AI01.png
3. The default installed PIP is version 9.01, you need to upgrade it to the latest version.

python3 -m pip install --upgrade pip

Jetson Nano AI02.png
4. After the upgrade is successful, check the pip version information and find some problems.

pip3 -V

Jetson Nano AI03.png
5. We use the command to solve it as follows:

python3 -m pip install --upgrade --force-reinstall pip
sudo reboot

Jetson Nano AI04.png
6. Install important installation packages in the field of machine learning.

Install important packages in the field of machine learning
sudo apt-get install python3-numpy
sudo apt-get install python3-scipy
sudo apt-get install python3-pandas
sudo apt-get install python3-matplotlib
sudo apt-get install python3-sklearn

Set up the CUDA environment

1. Check the CUDA version, if there appears "command not found", you need to configure the environment.

nvcc -V
cat /usr/local/cuda/version.txt

Jetson Nano AI015.png
Note: If you use the "cat" command, you can not check the version here. Please enter the "/usr/local/" directory to see if there is a CUDA directory.
If you do not install CUDA by referring to the Uninstalled CUDA section below, configure the environment after the installation is complete.

2. Set environment variables:

sudo vim .bashrc
Add at the end of the file:
export PATH=/usr/local/cuda-10.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-10.2

Jetson Nano AI016.png
3. Update environment variables.

source .bashrc

4. Check the CUDA version again.

nvcc -V

Jetson Nano AI017.png

CUDA is not installed on Jetson Nano

  • Under normal circumstances, Jetson Nano will install CUDA by default, but I have also encountered a situation where CUDA is not installed by default. The solution is as follows:

1. Open the SDK Manager on the Ubuntu 18.04 computer, skip to step 2, and download CUDA; after the download is complete, find the CUDA installation package.

cd /Downloads/nvidia/sdkm_downloads

Jetson Nano AI018.jpg

Jetson Nano AI019.jpg

  • Transfer the installation package to Jetson Nano and add the downloaded key to the local trusted database:
sudo apt-key add /var/cuda-repo-10-2-local/7fa2af80.pub
  • Install CUDA Toolkit and CUDA:
sudo apt update
sudo apt install cuda-toolkit-10-2
sudo dpkg -i cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb

Tensorflow GPU Environment Construction

1. Install the needed package:

sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
sudo pip3 install -U pip testresources setuptools==49.6.0

2. Install python independencies:

sudo pip3 install -U --no-deps numpy==1.19.4 future==0.18.2 mock==3.0.5 keras_preprocessing==1.1.2 keras_applications==1.0.8 gast==0.4.0 protobuf pybind11 cython pkgconfig packaging
sudo env H5PY_SETUP_REQUIRES=0 pip3 install -U h5py==3.1.0

3. Install Tensorflow (online installation often fails, you can refer to step 4 for offline installation).

sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v46 tensorflow

4. Finally, it is recommended to install offline, first log in to NVIDIA's official website to download the TensorFlow installation package (take "jetpack4.6 TensorFlow2.5.0 nv21.08" as an example, it is recommended to use Firefox browser to download).
Jetson Nano AI020.png
5. After the installation is complete, check whether the installation is successful, enter into the terminal:

python3
import tensorflow as tf

6. View the version information:

tf.__version__

Jetson Nano AI021.png

Pytorch Environment Setting

Pytorch Installation

1. Login and download Pytorch. Here, we take Pytorch v1.9.0 as an example:
Jetson Nano AI022.png
2. Download the independencies libraries.

sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev libopenblas-base libopenmpi-dev

3. Install Pytorch

sudo pip3 install torch-1.9.0-cp36-cp36m-linux_aarch64.whl 

4. Verify whether Pytorch has been installed successfully.

python3
import torch
x = torch.rand(5, 3)
print(x)

Jetson Nano AI023.png
5. View the version information:

import torch
print(torch.__version__)

Jetson Nano AI024.png

Torchvision Installation

1. The Torchvision version should match the Pytorch version. The Pytorch version we installed earlier is 1.9.0, and Torchvision installs the v0.10.0 version.
Jetson Nano AI030.png
2. Download and install torchvision:

git clone --branch v0.10.0 https://github.com/pytorch/vision torchvision
cd torchvision
export BUILD_VERSION=0.10.0
sudo python3 setup.py install

3. Verify whether Torchvision is installed successfully.

python3
import torchvision

Jetson Nano AI031.png
4.The error may be that the Pillow version is too high, uninstall and reinstall.

sudo pip3 uninstall pillow
sudo pip3 install pillow

Jetson Nano AI032.png
5. View the version information.

import torchvision
print(torchvision.__version__)

Jetson Nano AI033.png

Yolo V4 Environment Construction

1. First download darknet on github:

git clone https://github.com/AlexeyAB/darknet.git

2. After downloading, you need to modify Makefile:

cd darknet
sudo vim Makefile

Change the first four lines of 0 to 1.

GPU=1
CUDNN=1
CUDNN_HALF=1
OPENCV=1

3. The cuda version and path should also be changed to our actual version and path, otherwise the compilation will fail:

Change NVCC=nvcc to
NVCC=/usr/local/cuda-10.2/bin/nvcc

4. After the modification is completed, compile and enter into the terminal:

sudo make

Inference with YOLOv4

  • There are three basic reasoning methods: picture, video, camera (live image).
  • Choose Yolo v4 and Yolo v4-tiny (more lightweight models, suitable to run on Jetson Nano) for testing. First, you need to download the trained model weight file.

Image Test

1. Test

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights data/dog.jpg

Jetson Nano AI30.png
2. If you want to open the picture, you need to use the test mode, it will ask you to enter the location of the picture after execution:

./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights

Video Test

1. Yolov4-tiny video detection (there is no video file in the data downloaded from github, and the user needs to upload the video file to be detected to the data folder).

./darknet detector demo cfg/coco.data cfg/yolov4-tiny.cfg yolov4-tiny.weights data/xxx.mp4

Jetson Nano AI31.png
The frames is about 14 fps.

Live image test

1. Check the device number of the USB camera:

ls /dev/video*
./darknet detector demo cfg/coco.data  cfg/yolov4-tiny.cfg  yolov4-tiny.weights /dev/video0
./darknet detector demo cfg/coco.data  cfg/yolov4.cfg  yolov4.weights /dev/video0

Hello AI World

  • For the excellent YOLOv4 algorithm, running on Jetson Nano, and the FPS is low.
  • The Hello AI World project integrates the powerful TensroRT acceleration engine in NVIDIA, which improves performance by several times.

Environment Construction

1. Install cmake.

sudo apt-get update
sudo apt-get install git cmake libpython3-dev python3-numpy

2. Get the jetson-inference open source project.

git clone https://github.com/dusty-nv/jetson-inference
cd jetson-inference
git submodule update --init

3. Create a new folder, compile:

sudo mkdir build
cd build
sudo cmake ../

When the download model and Pytorch interface appear, we choose to skip (Quit and skip).
Jetson Nano AI33.png
Jetson Nano AI34.png
4. Download the model, then place it in the "jetson-inference/data/networks" directory, and unzip it.
5. Copy files to Jetson Nano with U disk or file transmission.

cd jetson-inference/build
sudo make
sudo make install

6. Install v4l camera driver, input the following command in the terminal:

sudo apt-get install v4l-utils
v4l2-ctl --list-formats-ext

DetectNet Runs Real-time Camera Detection

  • Use the camera to recognize objects in the environment.
cd ~/jetson-inference/build/aarch64/bin/
./detectnet-camera

Jetson Nano AI detect01.png
Use TensorRT to accelerate the frame rate to 24 fps.

  • The content below is a list of pre-trained object detection networks available for download, along with the "--network" parameter for loading the pre-trained model:
./detectnet-camera --network=facenet # Run the face recognition network 
./detectnet-camera --network=multiped # run multi-level pedestrian/baggage detector
./detectnet-camera --network=pednet # Run the original single-stage pedestrian detector
./detectnet-camera --network=coco-bottle # Detect bottles/soda cans under camera
./detectnet-camera --network=coco-dog # detect dog under camera
  • Let's use the "detectnet" program to locate objects in a static image. In addition to input/output paths, there are some additional command line options:
  • Change the optional "--network" flag for the detection model in use (the default is SSD-Mobilenet-v2).
  • "--overlay" flag can be comma-separated boxes, lines, labels, conf, or none.
    • Default "--overlay=box",labels,conf show boxes, labels and confidence coefficient.
    • The box option draws filled bounding boxes, while lines only draw unfilled outlines.
  • "--alpha" value, sets the alpha mixed value used during overlay (the default is 120).
  • "--threshold" sets an optional value for the minimum threshold for detection (thedefault 0.5).
  • "--camera" flag sets the camera device to use. (The default is to use MIPI CSI sensor 0 (--camera=0).)
  • "--width" and "--height" flags set camera resolution (the default is 1280 x 720).
  • The resolution should be set to a format supported by the camera, queried with "v4l2-ctl --list-formats-ext".
./detectnet-camera --network=facenet # Use FaceNet, default MIPI CSI camera (1280 × 720)
./detectnet-camera --camera=/dev/video1 --network=facenet # Use PedNet, V4L2 camera /dev/video1 (1280 x 720)
./detectnet-camera --width=640 --height=480 --network=facenet # Use PedNet, default MIPI CSI camera (640 x 480)

Hardware Control

The Jetson TX1, TX2, AGX Xavier, and Nano development boards include a 40-pin GPIO header, which is similar to the 40-pin header in the Raspberry Pi.

GPIO

  • The digital inputs and outputs of these GPIOs can be controlled using the Python library provided in the Jetson GPIO library package.
  • The Jetson GPIO library provides all the public APIs provided by the RPi.GPIO library. The use of each API is discussed below.

1. To import the Jetson.GPIO module, please use:

import Jetson.GPIO as GPIO

2. Pin number:

  • The Jetson GPIO library provides four methods for numbering I/O pins.
  • The first two correspond to the modes provided by the RPi.GPIO library, namely BOARD and BCM, which refer to the pin number of the 40-pin GPIO header and the Broadcom SoC GPIO number respectively.
  • The remaining two modes, CVM and TEGRA_SOC use strings instead of numbers, corresponding to the CVM/CVB connector and signal names on the Tegra SoC respectively.
  • To specify the mode you use (mandatory), use the following function to call:
GPIO.setmode(GPIO.BOARD)
GPIO.setmode(GPIO.BCM)
GPIO.setmode(GPIO.CVM)
GPIO.setmode(GPIO.TEGRA_SOC)
  • To check which mode has been set, you can call:
mode = GPIO.getmode()

The model must be GPIO. BOARD, GPIO. BCM, GPIO. CVM, GPIO. TEGRA_SOC or None. 3. If GRIO detects that a pin has been set to a non-default value, you will see a warning message.

  • You can disable warnings with the following code:
GPIO.setwarnings(False)

4. Set the channel:

  • The GPIO channel must be set before it can be used as an input or output. To configure a channel as an input, please call:
# (where channel is based on the pin numbering mode discussed above)
GPIO.setup(channel, GPIO.IN)
  • To set the channel as output, please call:
GPIO.setup(channel, GPIO.OUT)
  • You can also specify an initial value for the output channel:
GPIO.setup(channel, GPIO. OUT, initial=GPIO. HIGH)
  • When you set a channel to an output, you can also set multiple channels at the same time:
 
# add as many as channels as needed. You can also use tuples: (18,12,13)
channels = [18, 12, 13]
GPIO.setup(channels, GPIO.OUT)

5. input

  • To read the value of a channel, please use:
GPIO.input(channel)
This will return the GPIO. LOW or GPIO. HIGH.

6. output: To set the value of a pin configured as an output, please use:

GPIO.output(channel, state)
where state can be GPIO.LOW or GPIO.HIGH.
  • You can also output to a list of channels or tuple:
channels = [18, 12, 13] # or use tuples
GPIO.output(channels, GPIO.HIGH) # or GPIO.LOW
# set first channel to LOW and rest to HIGH
GPIO.output(channel, (GPIO.LOW, GPIO.HIGH, GPIO.HIGH))

7. clean up
At the end of the program, it's a good idea to clean up the channel so that all pins are set to their default state. To clean up all used channels, please call:

GPIO.cleanup()
  • If you don't want to clean up all channels, you can also clean up a single channel or a list of channels or tuple:
GPIO.cleanup(chan1) # cleanup only chan1
GPIO.cleanup([chan1, chan2]) # cleanup only chan1 and chan2
GPIO.cleanup((chan1, chan2)) # does the same operation as previous statement

8. Jetson Board Information and Library Versions:

  • To get information about Jetson modules use/read:
GPIO.JETSON_INFO

This provides a Python dictionary with the following keys: P1_REVISION, RAM, REVISION, TYPE, MANUFACTURER, and PROCESSOR. All values in the dictionary are strings, but P1_REVISION is an integer.

  • To get information about library versions use/read:
GPIO.VERSION

This provides a string with the XYZ version format.
9. Interrupt
In addition to polling, the library provides three additional methods to monitor input events:

  • wait_for_edge() function
  • This function blocks the calling thread until the provided edge is detected. The function can be called as follows:
GPIO.wait_for_edge(channel, GPIO.RISING)
  • The second parameter specifies the edge to detect, which can be GPIO.RISING, GPIO.FALLING, or GPIO.BOTH. If you just want to limit the wait to a specified time, you can optionally set a timeout:
# timeout is in milliseconds
GPIO.wait_for_edge(channel, GPIO.RISING, timeout=500)

The function returns the channel on which the edge was detected, or None if a timeout occurred.

  • event_detected() function
  • This function can be used to periodically check if an event has occurred since the last call. The function can be set and called as follows:
# set rising edge detection on the channel
GPIO.add_event_detect(channel, GPIO.RISING)
run_other_code()
if GPIO.event_detected(channel):
    do_something()

As before, you can detect events for GPIO.RISING, GPIO.FALLING or GPIO.BOTH.

  • Callback function to run when an edge is detected.
  • This function can be used to run a second thread for the callback function. Therefore, the callback function can run concurrently with your main program in response to the edge. This feature can be used as follows:
# define callback function
def callback_fn(channel):
    print("Callback called from channel %s" % channel)

# add rising edge detection
GPIO.add_event_detect(channel, GPIO.RISING, callback=callback_fn)
  • Multiple callbacks can also be added if desired, like this:
def callback_one(channel):
    print("First Callback")

def callback_two(channel):
    print("Second Callback")

GPIO.add_event_detect(channel, GPIO.RISING)
GPIO.add_event_callback(channel, callback_one)
GPIO.add_event_callback(channel, callback_two)

In this case, the two callbacks run sequentially, not simultaneously, because only the thread runs all the callback functions.

  • To prevent multiple invocations of the callback function by merging multiple events into one, optionally set a debounce time:
# bouncetime set in milliseconds
GPIO.add_event_detect(channel, GPIO.RISING, callback=callback_fn,
bouncetime=200)

If edge detection is no longer needed, it can be removed as follows:

GPIO.remove_event_detect(channel)

10. Check GPIO channel functionality
This function allows you to check the functionality of the provided GPIO channels:

GPIO.gpio_function(channel)
The function returns GPIO.IN or GPIO.OUT.

Turn on LED

  • Sample demo:
import Jetson.GPIO as GPIO
import time as time

LED_Pin = 11

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED_Pin, GPIO.OUT)

while (True):
   GPIO.output(LED_Pin, GPIO.HIGH)
   time.sleep(0.5)
   GPIO.output(LED_Pin, GPIO.LOW)
   time.sleep(0.5)

Demo Use

  • For the jetson.gpio library, the official also provides some simple demos.
  • First download jetson-gpio:
git clone https://github.com/NVIDIA/jetson-gpio
  • Move the downloaded file to /opt/nvidia:
sudo mv ~/jetson-gpio
  • Go to the jetson-gpio library folder and install the library:
cd /opt/nvidia/jetson-gpio
sudo python3 setup.py install
  • Before using it, you also need to create a gpio group, add your current account to this group, and give it permission to use.
sudo groupadd -f -r gpio
sudo usermod -a -G gpio user_name

Note: user_name is the username you use, say waveshare.

  • Copy the 99-gpio.rules file to the rules.d directory
sudo cp /opt/nvidia/jetson-gpio/lib/python/Jetson/GPIO/99-gpio.rules /etc/udev/rules.d/
  • In order for the new rules to take effect, you need to reboot or reload the udev rules by running:
sudo udevadm control --reload-rules && sudo udevadm trigger
  • After the configuration is complete, we can use the demo inside, such as "simple_input.py" can read the status of the pins.
cd /opt/nvidia/jetson-gpio/samples/
sudo python3 simple_input.py

Jetson nano hardware01.png

IIC

1. Install I2Ctool first and input in the terminal:

sudo apt-get update
sudo apt-get install -y i2c-tools
sudo apt-get install -y python3-smbus

2. Check the installation and input in the terminal:

apt-cache policy i2c-tools

If the output is as follows, the installation is successful:

i2c-tools:
Installed: 4.0-2
Candidate: 4.0-2
Version list:
***4.0-2500
500 http://ports.ubuntu.com/ubuntu-ports bionic/universe arm64 Packages
100 /var/lib/dpkg/status

i2cdetect

  • Query i2c devices:
 sudo i2cdetect -y -r -a 0

Jetson nano hardware2.png

  • Parameter: -y is to execute directly regardless of interaction problems, -r is the SMBus read byte command, -a is all addresses, and 0 refers to SMBus 0.
  • Scan the register data:
sudo i2cdump -y 0 0x68
  • Write in the register data:
sudo i2cset -y 0 0x68 0x90 0x55
  • Parameter:
parameters meaning
0 represents the I2C device number
0x68 represents the address of the I2C device
0x90 represents the register address
0x55 represents the data written to the register
  • Register data read:
    sudo i2cget -y 0 0x68 0x90
  • parameter:
parameters meaning
0 represents the I2C device number
0x68 represents the address of the I2C device
0x90 represents the register address

Resource

Software