Nvidia Jetson Guide - dlx-designlab/Attune GitHub Wiki
Setup:
Requirements:
- Nvidia Jetson Dev Kit Board (Nano or Xavier NX)
- SD Card (min 32gb)
- Power Supply (5V 2 Amps Min for the Nano, 12V or above fro the Xavier)
- Good quality USB cable
- Genie Tech G-Scope
- For the full assembly instructions and BOM see Scan-Stations Page
Using a preconfigured SD card Image:
- Download the latest Zip from here and Extract the IMG file inside
- Write The IMG file to an SD card (32GB or bigger)
- Insert the card into the Jetson
- Upon 1st boot make sure to expand the file-system. The Jetson should do it automatically
- Check the file-system was expanded to accommodate all the space available on the SD card:
df -h
(if not try this) - Update the WiFi-AP SSID to correspond with Attached the GScope number (see section 22 below)
- Reboot the Jetson
- Check everything works as expected:
- The scope_control_app starts upon boot - GScope Light goes on and the screen says "Capillary"
- WiFi-AP "scoPi_##" is Available
- Connection to http://192.168.4.1:8000 works from another device (phone or laptop)
Fresh Install Step by Step:
Please note: this might take several hours as multiple libraries need to be downloaded/compiled:
-
Follow this tutorial to set-up the Jetson (Nano/Xavier) Dev Kit.
-
During / After setup:
- IMPORTANT: Set Username to "attune", Password to "attune2020", Computer Name to "attune-jetson"
- After the install check filesystem was properly expanded and is matching the SD card size:
df -h
(if not try this)
-
If using a Jetson Nano - Attach and setup a Wifi dongle + internet connection
-
Adjust OS Sleep and Power settings:
- Settings > Power: Don't Suspend
- Settings > Brightness & Lock: Never Turn the Screen Off, Lock Off, Don't require a password when waking from suspend
- Set Jetson Power Mode (Xavier NX only):
Status Bar > Power Mode 15W 6CORE. Alternatively, run the following commands:sudo nvpmodel -m 2 sudo jetson_clocks
-
Update OS package manager index:
sudo apt-get update && sudo apt update
-
Install dependencies required for YOLOv4 - as described in the 1st step here
-
Install v4l2 (a tool to control USB video devices):
sudo adduser $USER dialout sudo apt-get install v4l-utils
-
Reboot the Jetson, Connect the G-Scope and check it's being recognized:
v4l2-ctl --list-devices --list-formats
-
Install pyUVC (a python library to control USB video devices):
- Install libusb 1.0-0-dev:
sudo apt-get install libusb-1.0-0-dev
- Change to your Downloads directory:
cd ~/Downloads
- Install G-Scope Adapted version of libuvc:
git clone https://github.com/yurikleb/libuvc cd libuvc/ mkdir build cd build cmake .. make && sudo make install sudo ldconfig
- Go back to your Downloads Folder:
cd ~/Downloads
- Install libjpeg-turbo:
wget -O libjpeg-turbo.tar.gz https://sourceforge.net/projects/libjpeg-turbo/files/1.5.1/libjpeg-turbo-1.5.1.tar.gz/download tar xvzf libjpeg-turbo.tar.gz cd libjpeg-turbo-1.5.1/ ./configure --with-pic --prefix=/usr/local sudo make install sudo ldconfig
- Set UDEV rules:
echo 'SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GROUP="plugdev", MODE="0664"' | sudo tee /etc/udev/rules.d/10-libuvc.rules > /dev/null sudo udevadm trigger
- Go back to your Downloads Folder:
cd ~/Downloads
- Install pyUVC:
git clone https://github.com/pupil-labs/pyuvc.git cd pyuvc/ sudo python3 setup.py install
- Attach the G-Scope and run the example file to confirm pyuvc was installed and works:
sudo python3 example.py
- Install libusb 1.0-0-dev:
-
Download and test our custom YOLOv4 model with the G-Scope - see step 3-4 here
Optional: you can skip most of this step and only run theinstall_pycuda.sh
script -
Download and install VS-Code (.deb ARM64 version)
-
Install a few more required dependencies:
- Flask web application framework:
sudo pip3 install flask
- File management libraries:
sudo pip3 install psutil pyfolder pyzip
- I2C libraries for communication with the TMP and TOF sensors:
sudo pip3 install adafruit-circuitpython-vl6180x adafruit-circuitpython-mlx90614
- Python Image Processing library (might take a while):
sudo pip3 install scikit-image
The above command might work but still produce errors when importing to python, in such case try building and installing locally:cd ~/Downloads git clone https://github.com/scikit-image/scikit-image.git sudo pip3 install -e scikit-image/
- Flask web application framework:
-
Install pyexiv2 (a python library to manage image metadata)
Try:sudo pip3 install py3exiv2
orcd ~/Downloads git clone https://github.com/mcmclx/py3exiv2.git sudo apt-get install -y python-all-dev sudo apt-get install -y libexiv2-dev sudo apt-get install -y libboost-python-dev sudo apt-get install -y g++ cd py3exiv2 python3 configure.py ./build.sh sudo ./build.sh -i
-
Install Nona for panorama stitching:
sudo apt-get install hugin-tools
-
IMPORTANT: Before running the scope-control-app:
- make sure to configure GRBL and check motors move and behave as expected
- Check the i2c sensors (IR temp, TOF Range) are detected:
On a Jetson Nanosudo i2cdetect -y -r 1
On a Jetson Xaviersudo i2cdetect -y -r 8
-
Clone the "scope_pi_app" branch of this repo:
cd ~/Projects/
git clone --single-branch --branch scope_pi_app https://github.com/dlx-designlab/Attune.git
-
Check and update the settings in
~/Projects/Attune/scope_control_app/scope_settings.json
, such as the Apex Detection Model file name to match the device you are using (the model files are located in~/Projects/Attune/scope_control_app/yolo/
) -
Try running the scope control app:
cd ~/Projects/Attune/scope_control_app
sudo python3 app.py
-
Open a browser and navigate to: http://localhost:8000/
If everything was installed correctly you should see the video feed from the scope (G-Scope light should turn on) and be able to adjust the scope controls. -
Configure USB drives auto-mounting settings, to allow the scope-control-app backup user data to USB Drives:
sudo nano /etc/fstab
add the following line at the bottom of the file:
/dev/sda1 /media/usb/ vfat rw,suid,dev,nouser,nofail,uid=1000,umask=000 0 2
IMPORTANT: for best performance and compatibility the USB drive file-system should be FAT32 -
Setup a server and make the "scope_control_app" run Automatically when the Jetson boots up:
sudo apt-get install supervisor
pip3 install gunicorn
create a new config file for the "scope_control_app":
sudo nano /etc/supervisor/conf.d/scope_app.conf
Input the following settings and save the file:
[program:scope_app] command=/home/attune/.local/bin/gunicorn -b 0.0.0.0:8000 --workers=1 --threads=4 app:APP directory=/home/attune/Projects/Attune/scope_control_app user=attune autostart=true autorestart=true stopasgroup=true killasgroup=true
-
Configure the Jetson as a hotspot:
- Open system settings > Network and click "Use as Hotpot..."
- In the status bar, click: Wifi > Network Connections (or run
sudo nm-connection-editor
) - Select "Hotspot" > Connection Settings Button
- Update the settings to:
General: Automatically Connect to this network when it is available + All users can connect to this network SSID: jetscope_## (change ## to the device number) Mode: Hotspot Band: 2.4 GHz Wi-Fi Security: None IPv4: Address: 192.168.4.1 Netmask: 24
- Disable "Auto Connect" for all other WiFi networks
- You can also toggle between hot-spot mode and regular WiFi connection by listing all the networks:
nmcli con show
And setting the default network via:
nmcli con mod <connection-name> connection.autoconnect yes
-
Make the Jetson boot into CLI:
sudo systemctl set-default multi-user.target
-
Shutdown the Jetson:
sudo shutdown now
IMPORTANT: It's best to shut down and unplug the Jetson from power for a few seconds to ensure full system reset, as we experienced cases in which the G-Scope connection would not reset after a "soft reboot", blocking a new instance of the "scope_control_app" from auto-launch.
Upon reboot the "scope_control_app" should be launched, the GScope Light should turn on and the GScope screen should read "Capillary".
Connect to the WiFi Access Point "jetscope_##" from any device, open google chrome and navigate to http://192.168.4.1:8000
On a Mobile phone, you can select to Add to Home Screen so it works like any other App on your device. -
Save your current setup in an IMG file: Follow This Guide
Maintenance
Useful Commands
- Disable boot to GUI:
sudo systemctl set-default multi-user.target
- Enable boot to GUI:
sudo systemctl set-default graphical.target
- Launch GUI:
sudo systemctl start gdm3.service
- Start/Stop "scope-control-app" via supervisorcontrol:
sudo supervisorctl start/stop scope_app
Access the Jetson via SSH
- From your laptop, connect to the Jetson WiFi Hotspot (ssid: jetscope_##)
- Open a terminal and type in:
ssh [email protected]
orssh [email protected]
- U: attune
P: attune2020
Please note: If you are trying to connect to several different jetscope stations from the same computer you might get an SSH Key Warning or Error!
In such case remove the cached keys for the address you are trying to connect to:
ssh-keygen -R 192.168.4.1
or ssh-keygen -R attune-jetson.local
Downloading Captured Image files from the Jetson
- Connect to the Pi WiFi Hotspot (default ssid: jetscope_##)
- Open a terminal window and CD to the directory you want to download the files to (for example
cd ~/Downloads
) - To download all the captured images stored on the Pi, Type in:
scp -r [email protected]:~/Projects/Attune/scope_control_app/static/captured_pics local-copy-of-folder-name
- If you want to download the images of a specific user add his UUID to the Path:
scp -r [email protected]:~/Projects/Attune/scope_control_app/static/captured_pics/ABCD1234 local-copy-of-folder-name
Update Default Scope Settings
- Connect to the Pi via SSH
- The default capture settings are saved inside the "scope_settings.json" file:
sudo nano ~/Projects/Attune/scope_control_app/scope_settings.json
- Update the settings and save the file
- Reboot the Pi
↓↓↓ OLD Instructions ↓↓↓
-
Follow this tutorial to assemble the Pi + CNC Shield and setup the lastest Raspbian-OS with GRBL Support
-
Attach a Motor Driver + Stepper Motor and test GRBL motor control Works as expected using one of the g-code tools on the pi desktop.
-
Install CMake, and pyuvc following those instructions
IMPORTANT: when installinglibuvc
use the modified version compatible with the G-Scope:
git clone https://github.com/yurikleb/libuvc
-
Install OpenCV 4: Try Method 1 (pip install) from this tutorial.
Basically you only need the dependencies from step #2 and then install openCV via this command:
pip3 install opencv-contrib-python==4.1.0.25
-
Check SPI and I2C are enabled
IMPORTANT: Protoneer CNC Shield - the SDA and SCL pins of the I2C/GROVE connector are flipped. Make sure to cross solder the cables connected to those pins. more info here and here. -
Attach a G-Scope to the Pi
-
In Pi Preferences > Raspberry Pi Configuration:
- Change Pi boot settings to "Boot to CLI"
-
Configure the Pi as an Access Point (skip the "Enable routing and IP masquerading" step)
When configuring the "hostapd.conf" file use the settings below.
IMPORTANT: UpdatescoPi_YourGScope##
with the real number of the G-Scope attached to the Pi. e.g.ssid=scoPi_04
and check thecountry_code
is correct:country_code=JP interface=wlan0 driver=nl80211 ssid=scoPi_YourGscope## hw_mode=g channel=7 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0
Updating
In order to update the Scope-Control app to the latest version you will need to:
- Disable the "scoPi_##" hotspot
- Connect the Pi to your home/work wifi network which has access to the internet
- Download the update from this Github repo
- Re-enable the #scoPi_##" hotspot
Please follow the instructions below:
-
Turn on the scope and connect to the "scoPi_##" hotspot
-
Connect to the Pi via SSH:
- On MacOS/Linux open terminal and type:
ssh [email protected]
- On Windows use PuTTY and open a new SSH connection to: "raspberrypi.local"
You might need to install Bonjour to be able to connect to "hostname.local" address instead of an IP address
If it's the 1st time you are connecting to this Pi, type in: 'yes'
Input username (Windows only): pi
Input password: attune2020
If successful, your command line should say:pi@raspberrypi:~ $
- On MacOS/Linux open terminal and type:
-
Turn off the scope-control app:
sudo supervisorctl stop scope_app
-
Configure your WiFi settings (skip this step if you configured this before):
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Go to the bottom of the file and add the following:
network={ ssid="testing" psk="testingPassword" }
Update the
ssid
and thepsk
values to match your WiFi network Name and Password
Press CTL + X to save and close the file
Press 'Y' to confirm saving changes -
Disable the "scopi_##" Network:
sudo nano /etc/dhcpcd.conf
Go to the bottom of the file and comment the last 3 lines (add '#' before each line) so it looks like this:
#interface wlan0 # static ip_address=192.168.4.1/24 # nohook wpa_supplicant
Press CTL + X to save and close the file
Press 'Y' to confirm saving changes -
Reboot the pi (the SSH connection to the pi will close):
sudo reboot now
-
The Pi Should reboot and connect to your local WiFi network configured in step 4
-
Connect your computer to the same local WiFi network and SSH into the Pi gain (as described in step 2)
-
Turn off the scope-control app:
sudo supervisorctl stop scope_app
-
Goto the App Directory:
cd Projects/Attune/
-
Get the latest version of the app from Github:
git pull
Input your Github username and password.
If successful, you should see the list of the updated files (something similar to this):
-
Activate the "scopi_##" Network:
sudo nano /etc/dhcpcd.conf
Go to the bottom of the file and un-comment the last 3 lines, (remove '#' before each line) so it looks like this:interface wlan0 static ip_address=192.168.4.1/24 nohook wpa_supplicant
Press CTL + X to save and close the file
Press 'Y' to confirm saving changes -
Reboot the pi (the SSH connection to the pi will close):
sudo reboot now
-
Wait for the Pi to reboot.
Connect to the "scopi_##" network from your laptop or phone.
Check the app works and the new features are available!