Linux

How to install MinIO commander (mc) globally on Linux

sudo bash -c 'curl https://dl.min.io/client/mc/release/linux-amd64/mc > /usr/local/bin/mc'
sudo chmod a+x /usr/local/bin/mc

 

Posted by Uli Köhler in Linux, S3

How to connect to Tekceleo WLG-75-R on Linux using picocom

Use the following command to connect to the Tekceleo WLG-75-R piezo motor eval kit using the picocom terminal program:

picocom -b 9600 /dev/ttyACM0 --imap lfcrlf --echo

 

Posted by Uli Köhler in Linux

How to query USB device information using udev

You can use udevadm to query information such as the USB device path for a given USB device such as /dev/usbtmc0:

udevadm info -q all /dev/usbtmc0

Example output:

P: /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.3/1-1.3:1.0/usbmisc/usbtmc0
N: usbtmc0
L: 0
E: DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.3/1-1.3:1.0/usbmisc/usbtmc0
E: DEVNAME=/dev/usbtmc0
E: MAJOR=180
E: MINOR=176
E: SUBSYSTEM=usbmisc

 

Posted by Uli Köhler in Linux

Thorlabs PM100(D) USB-TMC udev rules

SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="1313", ATTRS{idProduct}=="8078", GROUP="dialout", MODE="0666"

How to install:

sudo cp 99-thorlabs-pm100.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && sudo udevadm trigger

 

Posted by Uli Köhler in Linux

How to set Linux hardware clock to a specific date

hwclock --set --date '2021-01-04 13:04:00'

 

Posted by Uli Köhler in Linux

Systemd service to use a DS3231 RTC on the Raspberry Pi

The following systemd service will automatically. See this guide for more information on the setup and ensure sudo i2cdetect -y 1 detects the RTC with address 0x68.

This is an automatic service installation & enable script based on A simple systemd service autoinstall script . This script will automatically enable the service on boot:

#!/bin/bash
# This script installs and enables/starts a systemd service
# It also installs the service file
export NAME=ConfigureRTC

cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}

[Service]
ExecStart=/bin/bash -c 'echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device && hwclock -s'
Restart=always

[Install]
WantedBy=multi-user.target
EOF

# Enable and start service
systemctl enable --now ${NAME}.service

This is just the systemd service:

[Unit]
Description=ConfigureRTC

[Service]
ExecStart=/bin/bash -c 'echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device && hwclock -s'
Restart=always

[Install]
WantedBy=multi-user.target

 

Posted by Uli Köhler in Linux, Raspberry Pi

How to enable or disable NTP time synchronization on the Raspberry Pi

Disable NTP:

sudo systemctl disable --now systemd-timesyncd

Enable NTP:

sudo systemctl enable --now systemd-timesyncd

Verifying if NTP is active

You can verify if NTP is active or not by running

timedatectl

Then look for these lines:

System clock synchronized: yes
NTP service: active

System clock synchronized will tell you if the NTP service has successfully synchronized the system time to a NTP time server: yes if synchronized, no if not synchronized.

NTP service will tell you if the NTP service is running, i.e. if it is trying to synchronize the system time to a NTP time server: active if running, inactive when not running

Output with NTP active:

               Local time: Tue 2023-03-14 16:49:28 CET
           Universal time: Tue 2023-03-14 15:49:28 UTC
                 RTC time: Tue 2023-03-14 15:49:28
                Time zone: Europe/Berlin (CET, +0100)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Output with NTP inactive:

               Local time: Tue 2023-03-14 16:48:01 CET
           Universal time: Tue 2023-03-14 15:48:01 UTC
                 RTC time: Tue 2023-03-14 15:48:01
                Time zone: Europe/Berlin (CET, +0100)
System clock synchronized: no
              NTP service: inactive
          RTC in local TZ: no

 

Posted by Uli Köhler in Linux, Raspberry Pi

How to automatically add module to /etc/modules if it doesn’t exist

#!/bin/bash
check_module() {
  local module="$1"
  if grep -Fxq "$module" /etc/modules
  then
    echo "$module already exists in /etc/modules"
  else
    echo "$module not found in /etc/modules. Adding it now..."
    echo "$module" | sudo tee -a /etc/modules
  fi
}

check_module "i2c-dev"

This script will at the module if it doesn’t exist in /etc/modules yet.

Note that it will only detect if exactly the same line as the argument to check_module is already present in /etc/modules. For example if i2c-dev option1=value1 is in /etc/modules, the script will only detect this line correctly if you call it like

check_module "i2c-dev option1=value1"

but not if you call it like

check_module "i2c-dev"

 

 

 

Posted by Uli Köhler in Linux

How to fix Raspberry Pi i2cdetect: command not found

Problem:

When trying to detect I2C devices on the Raspberry Pi (Raspbian) using i2cdetect, you see the following error:

$ i2cdetect
bash: i2cdetect: command not found

Solution:

Install i2c-tools using

sudo apt -y install i2c-tools

After installing i2c-tools , you can use i2cdetect and other related tools such as i2cget.

Posted by Uli Köhler in Embedded, Linux, Raspberry Pi

How to list all V4L cameras using v4l2-ctl

You can list all connected cameras using

v4l2-ctl --list-devices

Example output:

bcm2835-codec-decode (platform:bcm2835-codec):
        /dev/video10
        /dev/video11
        /dev/video12
        /dev/video18
        /dev/video31
        /dev/media0

bcm2835-isp (platform:bcm2835-isp):
        /dev/video13
        /dev/video14
        /dev/video15
        /dev/video16
        /dev/video20
        /dev/video21
        /dev/video22
        /dev/video23
        /dev/media2
        /dev/media3

rpivid (platform:rpivid):
        /dev/video19
        /dev/media1

HD USB Camera: HD USB Camera (usb-0000:01:00.0-1.2):
        /dev/video0
        /dev/video1
        /dev/media4

 

Posted by Uli Köhler in Audio/Video, Linux

How to fix VirtualHere USB client ./vhuit64 ERROR: could not insert ‘vhci_hcd’: Operation not permitted

Problem:

When trying to run the VirtualHere USB client on Linux, you see the following error message:

$ ./vhuit64 
Please run with sudo
modprobe: ERROR: could not insert 'vhci_hcd': Operation not permitted

Solution:

Simply run vhuit64 using sudo:

sudo ./vhuit64

 

Posted by Uli Köhler in Linux

How to install fpm package builder on Ubuntu/Debian

Problem:

You want to build a package using the fpm command, but you see the following error message:

fpm: command not found

Solution:

First, install rubygems:

sudo apt -y install rubygems

and now install fpm using rubygems:

sudo gem install fpm

 

Posted by Uli Köhler in Linux

How to fix Linux error: Package ‘libjpeg8-dev’ has no installation candidate

Problem:

While trying to install libjpeg8-dev using apt or similar tools, you see the following error message:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package libjpeg8-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  libjpeg62-turbo-dev:armhf libjpeg62-turbo-dev

E: Package 'libjpeg8-dev' has no installation candidate

Solution:

As you can see in the error message, the correct package name to install is now libjpeg62-turbo-dev. Therefore, install it using

sudo apt -y install libjpeg62-turbo-dev

 

Posted by Uli Köhler in Linux

OctoPrint systemd service file for autostarting OctoPrint

After you have installed OctoPrint using

sudo pip3 install OctoPrint

you can create /etc/systemd/system/octoprint.service with the following content (depending on your setup, you might need to replace the user & group pi by the name of the user that should run OctoPrint):

[Unit]
Description=octoprint

[Service]
ExecStart=/usr/local/bin/octoprint serve
WorkingDirectory=/data
Restart=always
User=pi
Group=pi

[Install]
WantedBy=multi-user.target

After creating the file, enable autostart & start the service using

sudo systemctl enable --now octoprint

 

Posted by Uli Köhler in 3D printing, systemd

How I fixed SSH X11 forwarding sudo: Unable to init server: Could not connect: Connection refused

Problem:

While I was trying to run sudo gparted, the following error occured:

X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused

(gpartedbin:29293): Gtk-WARNING **: 01:55:02.070: cannot open display: localhost:10.0

Solution:

For me, the solution was to copy the .Xauthority file from the user uli I logged in as to root:

sudo cp ~$USER/.Xauthority /root

as this was required for the X11 program running as root to properly login to my local X11 server.

Posted by Uli Köhler in Linux

How to install entr on Ubuntu

entr is a utility to automatically restart a script if one or more files change.

Installing it on Ubuntu as is as easy as

sudo apt -y install entr

 

Posted by Uli Köhler in Linux

How to install .NET Core SDK on Ubuntu 22.04

wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0

Source for these commands: Microsoft documentation

Posted by Uli Köhler in C#, Linux

LumenPnP: Always assign the same serial port number on Linux

It is certainly a hassle when you always have to re-configure OpenPnP to open the correct serial device for LumenPnP.

In order to fix, this, we’ll create an alias /dev/lumenpnp that points to /dev/ttyACM0 or /dev/ttyACM1 or any other port that gets assigned to LumenPnP. Create /etc/udev/rules.d/99-lumenpnp.rules:

ACTION=="add", ENV{ID_VENDOR_ID}=="0483", ENV{ID_MODEL_ID}=="5740", SYMLINK+="lumenpnp"

Now, reload udev to activate the rule:

sudo udevadm control --reload-rules && sudo udevadm trigger

Now, open ~/.openpnp2/machine.xml, find this line:

<serial line-ending-type="LF" port-name="ttyACM0" baud="115200" ...

and set port-name to lumenpnp:

<serial line-ending-type="LF" port-name="lumenpnp" baud="115200" ...

After this, you need to restart OpenPnP. Typically, it works without reconnecting the device (due to udevadm trigger). If it doesn’t work, unplug and re-plug the mainboard USB connector.

Posted by Uli Köhler in Linux, LumenPnP

How to add route to local network in Linux even if VPN is active

If you route all your traffic via a VPN on Linux, you will typically not be able to access local networks except for the network which you are directly connected to via L2.

In order to fix this, you can simply add a route, which typically takes precedence over the VPN route even with additional options.

The following example will add a route to 10.1.2.0/24 (local network) via the gateway=local router we’re connected via L2 to (192.168.1.1)

sudo ip route add 10.1.2.0/24 via 192.168.1.1

 

Posted by Uli Köhler in Linux, Networking