CAN/IMU/Cameras with Jetson Orin
The Jetson Orin is a development board from Nvidia.
Contents
CAN Bus[edit]
See here for notes on configuring the CAN bus for the Jetson.
Install dependencies:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt upgrade
sudo apt install g++ python3.11-dev
Initialize the CAN bus on startup:
#!/bin/bash
# Set pinmux.
busybox devmem 0x0c303000 32 0x0000C400
busybox devmem 0x0c303008 32 0x0000C458
busybox devmem 0x0c303010 32 0x0000C400
busybox devmem 0x0c303018 32 0x0000C458
# Install modules.
modprobe can
modprobe can_raw
modprobe mttcan
# Turn off CAN.
ip link set down can0
ip link set down can1
# Set parameters.
ip link set can0 type can bitrate 1000000 dbitrate 1000000 berr-reporting on fd on loopback off
ip link set can1 type can bitrate 1000000 dbitrate 1000000 berr-reporting on fd on loopback off
# Turn on CAN.
ip link set up can0
ip link set up can1
You can run this script automatically on startup by writing a service configuration to (for example) /etc/systemd/system/can_setup.service
[Unit]
Description=Initialize CAN Interfaces
After=network.target
[Service]
Type=oneshot
ExecStart=/opt/kscale/enable_can.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
To enable this, run:
sudo systemctl enable can_setup
sudo systemctl start can_setup
Cameras[edit]
Arducam IMX 219[edit]
- Product Page
- Shipping was pretty fast
- Order a couple backup cameras because a couple of the cameras that they shipped came busted
- Quick start guide
Run the installation script:
wget https://github.com/ArduCAM/MIPI_Camera/releases/download/v0.0.3/install_full.sh
chmod u+x install_full.sh
./install_full.sh -m imx219
Supported kernel versions (see releases here):
5.10.104-tegra-35.3.1
5.10.120-tegra-35.4.1
Install an older kernel from here. This required downgrading to Ubuntu 20.04 (only changing /etc/os-version
).
Install dependencies:
sudo apt update
sudo apt install \
gstreamer1.0-tools \
gstreamer1.0-alsa \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav
sudo apt install
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-good1.0-dev \
libgstreamer-plugins-bad1.0-dev
sudo apt install \
v4l-utils \
ffmpeg
Make sure the camera shows up:
v4l2-ctl --list-formats-ext
Capture a frame from the camera:
gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! "video/x-raw(memory:NVMM), width=1280, height=720, framerate=60/1" ! nvvidconv ! jpegenc snapshot=TRUE ! filesink location=test.jpg
Alternatively, use the following Python code:
import cv2
gst_str = (
'nvarguscamerasrc sensor-id=0 ! '
'video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! '
'nvvidconv flip-method=0 ! '
'video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! '
'videoconvert ! '
'video/x-raw, format=(string)BGR ! '
'appsink'
)
cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
while True:
ret, frame = cap.read()
if ret:
print(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
IMU[edit]
We're using the BerryIMU v3. To use it, connect pin 3 on the Jetson to SDA and pin 5 to SCL for I2C bus 7. You can verify the connection is successful if the following command matches:
$ sudo i2cdetect -y -r 7
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- 6a -- -- -- -- --
70: -- -- -- -- -- -- -- 77
The equivalent command on the Raspberry Pi should use bus 1:
sudo i2cdetect -y -r 1
The default addresses are:
0x6A
: Gyroscope and accelerometer0x1C
: Magnetometer0x77
: Barometer