raspberrypi, jetson & ROS - feliyur/exercises GitHub Wiki

Flush and backup raspberry pi:

Flush OS to SD Card:

sudo dd if=<input image>.img of=/dev/<SD card device> bs=1M

Newer raspios images are provided compressed, can extract them on the fly:

xzcat <input image>.img.xz | sudo dd of=/dev/<SD card device> bs=4M status=progress conv=fsync

Backup

ssh pi "sudo dd if=/dev/mmcblk0 bs=1M | gzip -" | dd of=~/Desktop/pibackup.gz

to see progress, use either pv command (might need to install), or dd ... status=progress option. See here. Example:

sudo dd if=/dev/urandom | pv -s 36G | sudo dd of=/dev/null bs=1M

Note that bs (block size) argument can impact copy speed noticeably.

Raspberry pi mouse lag

Add usbhid.mousepoll=0 to /boot/firmware/cmdline.txt

Getting VNC server on Bookworm accessible with Remmina

Server is wayvnc, config file is at /etc/wayvnc/config. Create a backup then modify it, removing the certificate files and disabling pem. Then create a VNC password using

vncpasswd ~/.config/wayvnc/passwd

point the server to it

password = /home/youruser/.config/wayvnc/passwd

and restart the server

sudo service wayvnc restart

Note this disables encryption and should be used very carefully, but it works with Remmina client.

Installing Docker

curl -sSL https://get.docker.com | sh
sudo usermod -aG docker $USER

Reset Raspbian password

Instructions taken from here.

Password is stored in /etc/shadow file. Removing user's pi password then running sudo pi will allow to change it without inputting the old one. Just delete the password, not the entire line! like so:

pi:$wjeg2hgojglaghlkhj0349guoihdajsdgjo39jfjalajgljg:17178:0:99999:7:::

more options here (tl; dr: either raspi-config from command line, or edit password in configuration GUI).

Can remove need for password by editing /etc/passwd file, deleting "x" for authentication: E.g. change pi:x:1000:1000:,,,:/home/pi:/bin/bash into pi::1000:1000:,,,:/home/pi:/bin/bash

If any file got corrupted can fix by re-connecting the SD card to a working linux machine, then mounting it locally and making required fixes to the files.

ROS 1

source /opt/ros/noetic/setup.bash or <workspace_dir>/devel/setup.bash.
catkin build (prefer over catkin make which is the older version).
catkin clean
rostopic list
rostopic echo TOPIC [-b bagfile] [-n num_messages]
rosbag record TOPIC1 [TOPIC2 TOPIC3 ...] -l<NUM> -O <output_name.bag> Record NUM messages on each topic.
rosrun rqt_reconfigure rqt_reconfigure Dynamic configure parameters.
export ROS_MASTER_URI=http://192.168.1.158:11311 Set URI of roscore

Utils

catkin
rostopic
rosmsg
rosbag
rospack
rviz

Installing ROS on Windows

http://wiki.ros.org/Installation/Windows

Using Raspi camera

Enable camera via Preferences ==> Raspberry Pi Configuration ==> Interfaces ==> Camera

Take a single shot:

raspistill -o test.jpg

Stream video

raspivid -o - -t 0 -w 800 -h 600 -fps 12  | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8091/}' :demux=h264

Source: this tutorial.

To reduce disconnects, can try to add --rtsp-timeout 10 --h264-fps=12 arguments to cvlc. Make sure that fps argument to raspivid matches that of cvlc, i.e. number of frames produced matches the number consumed.

Jetson

Boot from SSD

http://www.yahboom.net/study/Jetson-TX2-NX ==> Move the system to SSD

https://www.waveshare.com/wiki/JETSON_NANO_TX2_NX#Set_The_System_To_Boot_From_SSD

Make VNC remotely available

sudo vim /usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml

Add key:

<key name='enabled' type='b'>
    <summary>Enable remote access to the desktop</summary>
    <description>
        If true, allows remote access to the desktop via the RFB protocol. Users on remote machines may then connect to the desktop using a VNC viewer.
    </description>
    <default>true</default>
</key>

Save and re-compile schemas:

sudo glib-compile-schemas /usr/share/glib-2.0/schemas

Now "Desktop Sharing" panel should have stopped. Open the app and tick checkboxes to allow access.

Alternatively (or if the above still doesn't work), using the command line:

export DISPLAY=:0
gsettings set org.gnome.Vino enabled true
gsettings set org.gnome.Vino prompt-enabled false
gsettings set org.gnome.Vino require-encryption false
/usr/lib/vino/vino-server

Should launch and start listening now. Can verify that server is listening using

netstat -tuln    # (within a docker container might need to install `apt install -y net-tools iproute2`).

and look for LISTENING on port 5900 or 5901 which are the default VNC ports.

Can make vino-server start automatically by making it a server. Create a file at /etc/systemd/system/vinoserver.service with the following content:

[Unit]
Description=VinoServer Service
After=network.target

[Service]
Type=simple
User=yuri
ExecStart=/usr/lib/vino/vino-server
Restart=on-failure
RestartSec=5
WorkingDirectory=/home/yuri
Environment="DISPLAY=:0"
LimitNOFILE=1024

[Install]
WantedBy=multi-user.target

Enable the service using systemctl enable vinoserver.service, then run sudo service vinoserver start. Can check status using sudo service vinoserver status.

Backup and restore

https://docs.nvidia.com/jetson/archives/l4t-archived/l4t-3261/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/flashing.html#wwpID0E06P0HA

Configure Jetson as Hotspot

  1. Settings => Network => Wireless => Turn hotspot on
  2. Connections menu at the top of the desktop => Edit connections => Edit Hotspot => Wi-Fi tab => Set Mode to Hotspot (and not ad-hoc).
  3. Connections menu again ==> Connect to hidden wi-fi network ==> connect.

Taken from https://www.youtube.com/watch?v=GAOvGAdwiHk

OctoPrint

Install and run

https://octoprint.org/download/

pip install octoprint
octoprint serve

Set OctoPrint to start at startup

Source: https://community.octoprint.org/t/setting-up-octoprint-on-a-raspberry-pi-running-raspberry-pi-os-debian/2337

Create a file /etc/systemd/system/octoprint.service and put this into it:

[Unit]
Description=The snappy web interface for your 3D printer
After=network-online.target
Wants=network-online.target

[Service]
Environment="LC_ALL=C.UTF-8"
Environment="LANG=C.UTF-8"
Type=exec
User=pi
ExecStart=/home/pi/OctoPrint/venv/bin/octoprint serve

[Install]
WantedBy=multi-user.target

Fix Blinking Display When Connecting Ender printer via USB

It happens because printer starts to draw power via USB, which is bad for the USB port of the connected device. Need to block the 5V pin of the USB plug with e.g. tape, explanation here:

https://community.octoprint.org/t/put-tape-on-the-5v-pin-why-and-how/13574

Potato stuff

Config not opening: raspbian config gui does not work on lepotato, use cli sudo raspi-config instead. link

Disable screen blanking

https://www.radishlogic.com/raspberry-pi/how-to-disable-screen-sleep-in-raspberry-pi/

sudo raspi-config => Display options => Screen Blanking => No => reboot.

Signatures invalid error

https://hub.libre.computer/t/signatures-were-invalid-expkeysig-2e5fb7fc58c58ffb/4166

wget https://deb.libre.computer/repo/pool/main/libr/libretech-keyring/libretech-keyring_2024.05.19_all.deb
sudo dpkg -i libretech-keyring_2024.05.19_all.deb
sudo apt update

Auto-connect hdmi

https://raspberrypi.stackexchange.com/questions/2169/how-do-i-force-the-raspberry-pi-to-turn-on-hdmi

Add to /boot/config.txt and reboot:

hdmi_force_hotplug=1
hdmi_drive=2

Auto-login

sudo raspi-config => System Options => Boot / Auto Login => Desktop Autologin

Tricks

Correctly copy entire tree, e.g. rootfs cp -ax <src> <tgt>

Kill all processes using a given port fuser -kv /dev/ttyUSB9

⚠️ **GitHub.com Fallback** ⚠️