### Install Java and Maven, Setup GraalVM Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Install OpenJDK 17, Maven, download and extract GraalVM CE, and install the native-image component. ```bash sudo apt -y install openjdk-17-jdk-headless maven wget -O - https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.2.0/graalvm-ce-java17-linux-aarch64-22.2.0.tar.gz | tar zxf - ./graalvm-ce-java17-22.2.0/bin/gu install native-image ``` -------------------------------- ### Install Debian using QEMU (Initial Boot) Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Start the QEMU AARCH64 system to begin the Debian installation using the downloaded installer files. ```bash qemu-system-aarch64 -smp 2 -M virt -cpu cortex-a57 -m 1G \ -initrd installer-initrd.gz -kernel installer-linux \ -append "root=/dev/ram" \ -device virtio-scsi-device \ -blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \ -device scsi-hd,drive=hd0 \ -netdev user,id=unet -device virtio-net-device,netdev=unet \ -nographic -no-reboot ``` -------------------------------- ### Install Debian using QEMU Source: https://www.diozero.com/boards/qemuaarch64.html Launch QEMU to install Debian Buster using the downloaded installer files and the created disk image. This command configures the system with 2 SMP cores, Cortex-A57 CPU, 1GB RAM, and basic network setup. ```bash qemu-system-aarch64 -smp 2 -M virt -cpu cortex-a57 -m 1G \ -initrd initrd.gz -kernel linux \ -append "root=/dev/ram console=ttyAMA0" \ -device virtio-scsi-device \ -blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \ -device scsi-hd,drive=hd0 \ -netdev user,id=unet -device virtio-net-device,netdev=unet \ -nographic ``` -------------------------------- ### SSH Login and Sudo Setup Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Log in to the QEMU guest via SSH and install sudo for the user. ```bash ssh -p 5555 matt@localhost su - -c "apt -y install sudo" su - -c "usermod -aG sudo matt" exit ``` -------------------------------- ### Launch Installed Debian System Source: https://www.diozero.com/boards/qemuaarch64.html Boot the installed Debian system in QEMU using the extracted kernel and initrd files. Configured with 2 SMP cores, Cortex-A57 CPU, 1GB RAM, and standard device setup. ```bash qemu-system-aarch64 -smp 2 -M virt -cpu cortex-a57 -m 1G \ -initrd initrd.img-4.19.0-16-arm64 \ -kernel vmlinuz-4.19.0-16-arm64 \ -append "root=/dev/sda2 console=ttyAMA0" \ -device virtio-scsi-device \ -blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \ -device scsi-hd,drive=hd0 \ -netdev user,id=unet -device virtio-net-device,netdev=unet \ -nographic ``` -------------------------------- ### Setup NBD and Mount Disk Image Source: https://www.diozero.com/boards/qemuaarch64.html Install necessary tools and use Network Block Device (NBD) to connect and mount the qcow2 disk image. This allows extraction of kernel files. ```bash sudo apt install nbd-client qemu qemu-utils sudo modprobe nbd max_part=8 sudo qemu-nbd --connect=/dev/nbd0 disk.qcow2 sudo mount /dev/nbd0p1 /media/qcow ``` -------------------------------- ### Install NBD Client and Connect to Disk Image Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Install necessary tools and connect the disk image to the NBD device for accessing its contents. ```bash sudo apt install nbd-client qemu qemu-utils sudo modprobe nbd max_part=8 sudo qemu-nbd --connect=/dev/nbd0 disk.qcow2 ``` -------------------------------- ### Install Utilities and Disable Graphical Desktop Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Install essential utilities and set the system to boot into multi-user target (text mode). ```bash sudo apt -y install curl gcc make unzip zip vim git build-essential libz-dev zlib1g-dev sudo systemctl set-default multi-user.target ``` -------------------------------- ### Install and Configure Network Manager Source: https://www.diozero.com/boards/bbbsetup.html Commands to install, enable, and start Network Manager for managing network connections via CLI. Use this as an alternative to connman. ```bash sudo apt -y install network-manager sudo systemctl enable network-manager sudo systemctl start network-manager ``` -------------------------------- ### Setup Debian User Account Source: https://www.diozero.com/boards/bbbsetup.html Commands to set up the 'debian' user account, including installing SSH keys, changing the password, granting sudo privileges without a password, adding the user to the gpio group, and enabling a color prompt. ```bash ssh-copy-id debian@ ``` ```bash passwd debian ``` ```bash %admin ALL=(ALL:ALL) NOPASSWD: ALL ``` ```bash sudo usermod -a -G gpio debian ``` ```bash force_color_prompt=yes ``` -------------------------------- ### Install Java Development Kit (JDK) Source: https://www.diozero.com/boards/commonsetup.html Installs the OpenJDK 17 headless version, suitable for server environments or applications that do not require a GUI. ```bash sudo apt -y install openjdk-17-jdk-headless ``` -------------------------------- ### Install ZSH and Oh My Zsh Source: https://www.diozero.com/boards/commonsetup.html Installs the Zsh shell, changes the default shell to Zsh, and installs the Oh My Zsh framework for enhanced shell customization. ```bash sudo apt -y install zsh chsh -s /usr/bin/zsh sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ``` -------------------------------- ### Install Development Libraries and Tools Source: https://www.diozero.com/boards/commonsetup.html Installs essential development tools and libraries required for hardware interaction, including avahi-daemon, build tools, and specific I2C/GPIO libraries. ```bash sudo apt -y install avahi-daemon gcc make unzip zip vim git sudo apt -y install i2c-tools libi2c-dev gpiod libgpiod2 libgpiod-dev libpigpiod-if-dev libpigpiod-if2-1 ``` -------------------------------- ### Install and Enable NTP Source: https://www.diozero.com/boards/bbbsetup.html Installs and enables the Network Time Protocol (NTP) service to synchronize the system clock with network time servers. ```bash sudo apt update && sudo apt install ntp ntpdate sudo systemctl enable ntp ``` -------------------------------- ### Launch Debian with Increased Resources Source: https://www.diozero.com/boards/qemuaarch64.html Boot the installed Debian system in QEMU with increased resources, allocating 8 cores and 4GB of RAM. This is useful for more demanding workloads. ```bash qemu-system-aarch64 -smp 8 -M virt -cpu cortex-a57 -m 4G \ -initrd initrd.img-4.19.0-16-arm64 \ -kernel vmlinuz-4.19.0-16-arm64 \ -append "root=/dev/sda2 console=ttyAMA0" \ -device virtio-scsi-device \ -blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \ -device scsi-hd,drive=hd0 \ -netdev user,id=unet -device virtio-net-device,netdev=unet \ -nographic ``` -------------------------------- ### Install Build Dependencies Source: https://www.diozero.com/performance/graalvm.html Install essential build tools and libraries required for compiling native images. This includes build-essential, libz-dev, zlib1g-dev, and zlibc. ```bash sudo apt -y install build-essential libz-dev zlib1g-dev zlibc ``` -------------------------------- ### Download Debian Buster Installer Files Source: https://www.diozero.com/boards/qemuaarch64.html Download the network installer initrd.gz and kernel linux files for Debian Buster ARM64. ```bash wget http://ftp.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/initrd.gz wget http://ftp.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/linux ``` -------------------------------- ### Install Sudo and Add User to Sudo Group Source: https://www.diozero.com/boards/qemuaarch64.html Log in as root and install the sudo package, then add the 'matt' user to the sudo group to grant administrative privileges. ```bash su - -c "apt -y install sudo" su - -c "usermod -aG sudo matt" exit ``` -------------------------------- ### Download Debian Bullseye Installer Files Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Download the Debian Bullseye network installer initrd and linux files for AARCH64. ```bash wget -O installer-initrd.gz http://ftp.debian.org/debian/dists/bullseye/main/installer-arm64/current/images/netboot/debian-installer/arm64/initrd.gz wget -O installer-linux http://ftp.debian.org/debian/dists/bullseye/main/installer-arm64/current/images/netboot/debian-installer/arm64/linux ``` -------------------------------- ### Install Utilities and Set Default Target Source: https://www.diozero.com/boards/qemuaarch64.html Install essential utilities like curl, gcc, make, and development libraries. It also sets the system to boot into the multi-user target, disabling the graphical desktop. ```bash sudo apt -y install curl gcc make unzip zip vim git build-essential libz-dev zlib1g-dev sudo systemctl set-default multi-user.target ``` -------------------------------- ### Install pigpio C library Source: https://www.diozero.com/concepts/providers.html Command to install the pigpio C library on a Raspberry Pi. This is a prerequisite for using the pigpio provider in diozero. ```bash sudo apt update && sudo apt -y install pigpio ``` -------------------------------- ### Run LEDTest with Firmata via Serial Port Source: https://www.diozero.com/concepts/remotecontrol.html Example command line to run the LEDTest application using the Firmata provider over a serial port. Ensure the necessary JARs are on the classpath. ```bash java -cp diozero-sampleapps-1.4.2.jar:diozero-provider-firmata-1.4.2.jar com.diozero.sampleapps.LEDTest -Ddiozero.firmata.serialPort=COM5 12 ``` -------------------------------- ### Install Essential Development Tools Source: https://www.diozero.com/boards/bbbsetup.html Installs essential development tools and libraries for BeagleBone, including git, build tools, i2c utilities, and gpiod libraries. ```bash sudo apt update && sudo apt -y install git gcc make build-essential i2c-tools libi2c-dev unzip zip vim gpiod libgpiod-dev libgpiod2 ``` -------------------------------- ### Create a QCOW2 Disk Image Source: https://www.diozero.com/boards/qemuaarch64.html Create a 20GB qcow2 disk image file for the Debian installation. ```bash qemu-img create -f qcow2 disk.qcow2 20G ``` -------------------------------- ### Button Listener Example Source: https://www.diozero.com/devices/inputdevices.html Demonstrates how to create a Button instance and attach a listener to detect changes in its state. The listener logs the event details. Requires a Button and SleepUtil. ```java try (Button button = new Button(inputPin, GpioPullUpDown.PULL_UP)) { button.addListener(event -> Logger.debug("valueChanged({})", event)); Logger.debug("Waiting for 10s - *** Press the button connected to input pin " + inputPin + " ***"); SleepUtil.sleepSeconds(10); } ``` -------------------------------- ### Install gpiod Tools on Debian Source: https://www.diozero.com/internals/gpio.html Install the gpiod command line tools on Debian-based systems for troubleshooting GPIO interactions. These tools include gpiodetect, gpioinfo, gpioget, gpioset, and gpiomon. ```bash sudo apt install gpiod ``` -------------------------------- ### Configure QEMU with Increased Resources and Port Forwarding Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Start the QEMU AARCH64 system with 8 cores, 4GB RAM, and forward host port 5555 to guest port 22 for SSH access. ```bash qemu-system-aarch64 -smp 8 -M virt -cpu cortex-a57 -m 4G \ -initrd initrd.img-5.10.0-17-arm64 -kernel vmlinuz-5.10.0-17-arm64 \ -append "root=/dev/sda2" \ -device virtio-scsi-device \ -device scsi-hd,drive=hd0 \ -blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \ -netdev user,id=net0,hostfwd=tcp::5555-:22 -device virtio-net-device,netdev=net0 \ -nographic ``` -------------------------------- ### Install pigpio-tools Source: https://www.diozero.com/boards/rpinotes.html Installs the pigpio-tools package, which provides utilities for interacting with the Raspberry Pi's GPIO pins. This is often a prerequisite for hardware-specific libraries. ```bash sudo apt -y install pigpio-tools ``` -------------------------------- ### Button Controlled LED Example Source: https://www.diozero.com/devices/inputdevices.html Shows how to control an LED using a Button. The LED turns on when the button is pressed and off when released. Requires Button and LED classes. ```java try (Button button = new Button(buttonPin, GpioPullUpDown.PULL_UP); LED led = new LED(ledPin)) { button.whenPressed(nanoTime -> led.on()); button.whenReleased(nanoTime -> led.off()); Logger.info("Waiting for 10s - *** Press the button connected to pin {} ***", Integer.valueOf(buttonPin)); SleepUtil.sleepSeconds(10); } ``` -------------------------------- ### Install OpenJDK 8 on BeagleBone Black Source: https://www.diozero.com/boards/bbbsetup.html Installs OpenJDK 8 using the AdoptOpenJDK repository, which is necessary due to compatibility issues with OpenJDK 11 on the BeagleBone Black. ```bash sudo apt -y install software-properties-common wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add - sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ sudo apt update && sudo apt -y install adoptopenjdk-8-hotspot sudo update-java-alternatives -s adoptopenjdk-8-hotspot-armhf ``` -------------------------------- ### Enable pigpiod Service Source: https://www.diozero.com/concepts/remotecontrol.html Enables the pigpiod daemon to start on system boot. This is a prerequisite for remote pigpio access. ```bash sudo systemctl enable pigpiod.service ``` -------------------------------- ### Setup Radxa ROCK 4C+ for Bullseye Stable Source: https://www.diozero.com/docs/8_boards/7_RadxaRock4.html This command sets the distribution environment variable and imports the public key for the Radxa repository, necessary for setup on the Radxa ROCK 4C+. ```bash export DISTRO=bullseye-stable curl http://apt.radxa.com/$DISTRO/public.key | sudo apt-key add - ``` -------------------------------- ### Run Application with Exported JAR and Classpath Source: https://www.diozero.com/application.html Example command to run an application packaged as a JAR, including runtime dependencies via the classpath. This method does not generate a runnable JAR. ```bash java -cp tinylog-api-2.5.0.jar:tinylog-impl-2.5.0.jar:diozero-core-1.4.2.jar:yourapp.jar <> ``` -------------------------------- ### Install GraalVM Native Image Builder Source: https://www.diozero.com/performance/graalvm.html Install the native-image tool using the gu (GraalVM Updater) utility. This command is essential for creating standalone native executables. ```bash gu install native-image ``` -------------------------------- ### Configure Static IP for Ethernet Source: https://www.diozero.com/boards/bbbsetup.html Example configuration for setting a static IP address, subnet mask, gateway, and DNS servers for an Ethernet connection using connmanctl. ```bash connmanctl config ethernet_a0f6fd4c0e73_cable --ipv4 manual 192.168.1.16 255.255.255.0 192.168.1.254 --nameservers 192.168.1.254 ``` -------------------------------- ### Enable Hardware PWM Channel 0 Source: https://www.diozero.com/boards/rpinotes.html Configures a single hardware PWM channel by adding a device tree overlay to `/boot/config.txt`. This example enables PWM channel 0 on GPIO 12 with function 4. ```bash dtoverlay=pwm,pin=12,func=4 ``` -------------------------------- ### Control a PWM LED Source: https://www.diozero.com/devices/outputdevices.html Shows how to control a PWM LED, including setting its brightness, blinking, and pulsing. This example uses a try-with-resources statement for proper resource management. ```java float delay = 0.5f; try (PwmLed led = new PwmLed(pin)) { led.on(); SleepUtil.sleepSeconds(delay); led.off(); SleepUtil.sleepSeconds(delay); led.toggle(); SleepUtil.sleepSeconds(delay); led.toggle(); SleepUtil.sleepSeconds(delay); led.setValue(.25f); SleepUtil.sleepSeconds(delay); led.toggle(); SleepUtil.sleepSeconds(delay); led.setValue(.5f); SleepUtil.sleepSeconds(delay); led.blink(0.5f, 0.5f, 5, false); led.pulse(1, 50, 5, false); } catch (RuntimeIOException e) { Logger.error(e, "Error: {}", e); } ``` -------------------------------- ### Install Azul OpenJDK 11 for ARMv6 Source: https://www.diozero.com/boards/rpinotes.html Downloads and installs Azul OpenJDK 11 for ARMv6/7 architecture on Raspberry Pi. This involves downloading the tarball, extracting it, creating a symbolic link, and configuring system alternatives for `java` and `javac`. ```bash JAVA_VERSION=11.0.18 ZULU_JDK_VERSION=11.62.17-ca cd wget https://cdn.azul.com/zulu-embedded/bin/zulu${ZULU_JDK_VERSION}-jdk${JAVA_VERSION}-linux_aarch32hf.tar.gz cd /usr/lib/jvm sudo tar xf ~/zulu${ZULU_JDK_VERSION}-jdk${JAVA_VERSION}-linux_aarch32hf.tar.gz sudo ln -s zulu${ZULU_JDK_VERSION}-jdk${JAVA_VERSION}-linux_aarch32hf java-11-zulu-armhf sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-11-zulu-armhf/bin/java 1 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-11-zulu-armhf/bin/javac 1 sudo update-alternatives --config java sudo update-alternatives --config javac ``` -------------------------------- ### Button-controlled LED with diozero Source: https://www.diozero.com/ This example shows how to connect a button to control an LED. When the button is pressed, the LED turns on; when released, it turns off. The application will sleep for 20 seconds to allow interaction. ```java try (Button button = new Button(12); LED led = new LED(18)) { button.whenPressed(nanoTime -> led.on(); button.whenReleased(nanoTime -> led.off()); SleepUtil.sleepSeconds(20); } ``` -------------------------------- ### Copy Kernel Files Source: https://www.diozero.com/boards/qemuaarch64.html Copy the extracted initrd.img and vmlinuz files from the mounted disk image to the parent directory for use in launching the installed system. ```bash sudo cp initrd.img-4.19.0-16-arm64 vmlinuz-4.19.0-16-arm64 ../qemu/. sync ``` -------------------------------- ### Configure System Locale and Timezone Source: https://www.diozero.com/boards/commonsetup.html Installs locales, sets the system locale to en_GB.UTF-8, and configures the timezone to Europe/London. Requires reconfiguring locales and tzdata. ```bash sudo apt install locales sudo localectl set-locale en_GB.UTF-8 sudo timedatectl set-timezone Europe/London ``` -------------------------------- ### Connman CLI Commands Source: https://www.diozero.com/boards/bbbsetup.html Example commands to interact with connman for WiFi network management. This is a workaround when connman fails to detect networks. ```bash connmanctl> tether wifi off Error disabling wifi tethering: Already disabled connmanctl> enable wifi Error wifi: Already enabled connmanctl> agent on Agent registered connmanctl> scan wifi Scan completed for wifi connmanctl> services *AO Wired ethernet_a0f6fd4c0e73_cable connmanctl> exit ``` -------------------------------- ### Enable Two Hardware PWM Channels Source: https://www.diozero.com/boards/rpinotes.html Configures two hardware PWM channels using a device tree overlay. This example enables PWM channel 0 on GPIO 18 and channel 1 on GPIO 19, both with function 2. ```bash dtoverlay=pwm-2chan,pin=18,func=2,pin2=19,func2=2 ``` -------------------------------- ### Provisioning Analog Input Device with MCP3008 Source: https://www.diozero.com/concepts/providers.html Example of using an AnalogInputDeviceFactory (McpAdc) to provision an AnalogInputDevice (LDR). This is useful when the host board lacks analog input capabilities. ```java try (AnalogInputDeviceFactoryInterface ain_df = new McpAdc(McpAdc.Type.MCP3008, chipSelect); LDR ldr = new LDR(ain_df, pin, r1)) { System.out.println(ldr.getUnscaledValue()); } ``` -------------------------------- ### Control LED with MCP23017 GPIO Expander Source: https://www.diozero.com/devices/expansionboards.html Example of controlling an LED and responding to a button press using an MCP23017 chip. Requires initialization of the MCP23017, a Button, and an LED object. ```Java try (MCP23017 mcp23017 = new MCP23017(intAPin, intBPin); Button button = new Button(mcp23017, inputPin, GpioPullUpDown.PULL_UP); LED led = new LED(mcp23017, outputPin)) { led.on(); SleepUtil.sleepSeconds(1); led.off(); SleepUtil.sleepSeconds(1); led.blink(0.5f, 0.5f, 10, false); button.whenPressed(nanoTime -> led.on()); button.whenReleased(nanoTime -> led.off()); Logger.debug("Waiting for 10s - *** Press the button connected to MCP23017 pin {} ***", Integer.valueOf(inputPin)); SleepUtil.sleepSeconds(10); button.whenPressed(null); button.whenReleased(null); } ``` -------------------------------- ### Boot Debian with Copied Kernel Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Boot the QEMU AARCH64 system using the copied initrd and vmlinuz files. ```bash qemu-system-aarch64 -smp 2 -M virt -cpu cortex-a57 -m 1G \ -initrd initrd.img-5.10.0-17-arm64 \ -kernel vmlinuz-5.10.0-17-arm64 \ -append "root=/dev/sda2 console=ttyAMA0" \ -device virtio-scsi-device \ -blockdev qcow2,node-name=hd0,file.driver=file,file.filename=disk.qcow2 \ -device scsi-hd,drive=hd0 \ -netdev user,id=unet -device virtio-net-device,netdev=unet \ -nographic ``` -------------------------------- ### Install dhcpcd5 Source: https://www.diozero.com/boards/bbbsetup.html Command to install the dhcpcd5 package, which is used for managing network interfaces on some Debian-based systems. ```bash sudo apt install dhcpcd5 ``` -------------------------------- ### Run LEDTest Sample Application with Pigpio Provider Source: https://www.diozero.com/concepts/gettingstarted.html This command compiles and runs the LEDTest sample application using the pigpio provider. Ensure all specified JAR files are in your classpath. ```bash sudo java -cp tinylog-api-2.5.0.jar:tinylog-impl-2.5.0.jar:diozero-core-1.4.2.jar:diozero-sampleapps-1.4.2.jar:diozero-provider-pigpio-1.4.2.jar:pigpioj-java-2.6.1.jar com.diozero.sampleapps.LEDTest 12 ``` -------------------------------- ### Install GraalVM CE Source: https://www.diozero.com/performance/graalvm.html Download and extract GraalVM Community Edition for Linux AArch64. This command sequence installs the necessary components into the system's JVM directory. ```bash wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.0.0.2/graalvm-ce-java11-linux-aarch64-21.0.0.2.tar.gz tar zxf graalvm-ce-java11-linux-aarch64-21.0.0.2.tar.gz sudo mv graalvm-ce-java11-21.0.0.2 /usr/lib/jvm/. ``` -------------------------------- ### Display System Information Source: https://www.diozero.com/boards/tbsetup.html Run this command to display detailed system information, including diozero version, OS details, CPU temperature, and board information. ```bash sudo java -cp diozero-sampleapps-1.4.2.jar com.diozero.sampleapps.SystemInformation ``` -------------------------------- ### Install OpenJDK 8 via Debian Stretch Security Updates Source: https://www.diozero.com/boards/bbbsetup.html Installs OpenJDK 8 by adding the Debian Stretch security updates channel, providing an alternative method if the AdoptOpenJDK repository is not preferred. ```bash sudo apt -y install software-properties-common sudo apt-add-repository 'deb http://security.debian.org/debian-security stretch/updates main' sudo apt update && sudo apt -y install openjdk-8-jdk ``` -------------------------------- ### Mount and Copy Kernel Files Source: https://www.diozero.com/boards/qemuaarch64_bullseye.html Mount the first partition of the NBD device and copy the initrd and vmlinuz files to the host system. ```bash sudo mount /dev/nbd0p1 /media/qcow sudo cp initrd.img-5.10.0-17-arm64 vmlinuz-5.10.0-17-arm64 ../qemu/. sync sudo umount /dev/nbd0p1 sudo nbd-client -d /dev/nbd0 ``` -------------------------------- ### Disable Graphical Desktop Source: https://www.diozero.com/boards/bbbsetup.html Commands to disable the graphical desktop environment and set the system to boot into multi-user mode. This is useful for headless setups. ```bash sudo systemctl disable graphical.target sudo systemctl set-default multi-user.target ``` -------------------------------- ### Get PinInfo by Physical Pin Source: https://www.diozero.com/api/utilityclasses.html Retrieve PinInfo using the physical pin number on a specific header. This is useful for board-specific pin identification. ```java // GPIO 18 on the Raspberry Pi String header = "J8"; int physical_pin = 12; PinInfo pin_info = DeviceFactoryHelper.getNativeDeviceFactory().getBoardPinInfo() .getByPhyscialPinOrThrow(header, physical_pin); try (LED led = new LED(pin_info, true, false)) { led.on(); SleepUtil.sleepSeconds(1); led.off() } ``` -------------------------------- ### Control an LED with diozero Source: https://www.diozero.com/ This snippet demonstrates basic LED control using the diozero library. It turns an LED on, waits, turns it off, waits, and then toggles its state. Ensure the LED is connected to the specified GPIO pin. ```java try (LED led = new LED(18)) { led.on(); SleepUtil.sleepSeconds(1); led.off(); SleepUtil.sleepSeconds(1); led.toggle(); } ``` -------------------------------- ### Close LED with Try-with-Resources Source: https://www.diozero.com/concepts.html Demonstrates automatic closing of an LED resource using Java's try-with-resources statement. ```java try (LED led = new LED(18)) { led.toggle(); SleepUtil.sleepSeconds(.5); led.toggle(); SleepUtil.sleepSeconds(.5); } ``` -------------------------------- ### Get PinInfo by Chip and Line Offset Source: https://www.diozero.com/api/utilityclasses.html Retrieve PinInfo using the GPIO character device chip and line offset. This is useful for direct GPIO register interaction. ```java // GPIO 18 on the Raspberry Pi int chip = 0; int line_offset = 18; PinInfo pin_info = DeviceFactoryHelper.getNativeDeviceFactory().getBoardPinInfo() .getByChipAndLineOffsetOrThrow(chip, line_offset); try (LED led = new LED(pin_info, true, false)) { led.on(); SleepUtil.sleepSeconds(1); led.off() } ``` -------------------------------- ### GPIO Performance Test (Default JVM) Source: https://www.diozero.com/performance/graalvm.html Runs the GPIO performance test with a large number of iterations using the default JVM. This establishes a baseline performance metric. ```bash > java -cp diozero-sampleapps-1.4.2.jar com.diozero.sampleapps.perf.GpioPerfTest 21 50000000 19:59:21.284 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.main - Starting GPIO performance test using GPIO 21 with 50000000 iterations 19:59:23.387 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 50,000,000 iterations: 1.847 s, frequency: 27,070,926 Hz 19:59:25.224 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 50,000,000 iterations: 1.828 s, frequency: 27,352,298 Hz 19:59:27.024 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 50,000,000 iterations: 1.799 s, frequency: 27,793,218 Hz 19:59:28.823 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 50,000,000 iterations: 1.797 s, frequency: 27,824,151 Hz 19:59:30.623 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 50,000,000 iterations: 1.798 s, frequency: 27,808,676 Hz ``` -------------------------------- ### Read Temperature using MCP3008 and TMP36 Source: https://www.diozero.com/api/gpio.html Example of reading temperature from a TMP36 sensor connected via an MCP3008 analog-to-digital converter. Requires setting up the ADC voltage range. ```java try (McpAdc adc = new McpAdc(McpAdc.Type.MCP3008, chipSelect); TMP36 tmp36 = new TMP36(adc, pin, vRef, tempOffset)) { for (int i=0; i /etc/sudoers.d/01_sudo-nopassword ``` -------------------------------- ### Groovy LED Controlled Button Example Source: https://www.diozero.com/concepts/gettingstarted.html A Groovy script that controls an LED based on button presses. It requires the diozero core, sampleapps, and pigpio provider libraries to be in the classpath. ```groovy import com.diozero.devices.Button import com.diozero.devices.LED import com.diozero.util.SleepUtil led = new LED(12) button = new Button(25) button.whenPressed({ led.on() }) button.whenReleased({ led.off() }) println("Waiting for button presses. Press CTRL-C to quit.") SleepUtil.sleepSeconds(5) ``` -------------------------------- ### Generate Native Application with GraalVM Source: https://www.diozero.com/performance/graalvm.html Build a native executable for the GpioPerfTest application using the extracted configuration files. This command utilizes the native-image tool with specific configuration file arguments. ```bash native-image -H:JNIConfigurationFiles=./config/jni-config.json \ -H:ReflectionConfigurationFiles=./config/reflect-config.json \ -H:ResourceConfigurationFiles=./config/resource-config.json \ -H:+TraceServiceLoaderFeature -H:+ReportExceptionStackTraces \ --allow-incomplete-classpath --no-fallback \ -cp diozero-sampleapps-1.4.2.jar:diozero-core-1.4.2.jar:tinylog-api-2.2.1.jar:tinylog-impl-2.2.1.jar \ com.diozero.sampleapps.perf.GpioPerfTest ``` -------------------------------- ### GPIO Performance Test (Default JVM, Fewer Iterations) Source: https://www.diozero.com/performance/graalvm.html Runs the GPIO performance test with a smaller number of iterations using the default JVM. This demonstrates the impact of the JVM's JIT compiler on early results. ```bash > java -cp diozero-sampleapps-1.4.2.jar com.diozero.sampleapps.perf.GpioPerfTest 21 500000 19:50:27.109 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.main - Starting GPIO performance test using GPIO 21 with 500000 iterations 19:50:27.417 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 500,000 iterations: 0.053 s, frequency: 9,433,962 Hz 19:50:27.468 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 500,000 iterations: 0.043 s, frequency: 11,627,907 Hz 19:50:27.491 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 500,000 iterations: 0.020 s, frequency: 25,000,000 Hz 19:50:27.510 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 500,000 iterations: 0.018 s, frequency: 27,777,778 Hz 19:50:27.530 [main] INFO com.diozero.sampleapps.perf.GpioPerfTest.test - Duration for 500,000 iterations: 0.018 s, frequency: 27,777,778 Hz ``` -------------------------------- ### Customize Oh My Zsh Theme Source: https://www.diozero.com/boards/commonsetup.html Copies the default robbyrussell theme and prepares it for customization to include the hostname in the prompt. ```bash cd ~/.oh-my-zsh/themes cp robbyrussell.zsh-theme robbyrussell_tweak.zsh-theme ```