Remote Control Power Sockets: Part 8: Setting Up a BeagleBone Black
In this part we set up the BeagleBone Black as the second target next to the Raspberry Pi from Part 7. Both are small Linux boards, so the steps are very similar: we install a current image, get a compiler and toggle a GPIO pin.
The BeagleBone Black drives the same 433 MHz transmitter as the Raspberry Pi and uses the same GPIO library, libgpiod. At the end of this part we have a first program that controls a pin on the pin header. That is all the transmitter needs to switch a remote control power socket.
Host system (x86_64)
We cross-compile on a Debian 13 (Trixie) host, where Debian installs the ARM packages next to the native ones via multiarch. Alternatively, we build natively on the BeagleBone (see "Building and running" below), which works from any host.
GPIO library (libgpiod)
The Linux kernel exposes every GPIO controller as a character device (/dev/gpiochip0, /dev/gpiochip1, ...). From userspace, a program can open the device and request individual lines with ioctl(). For this the kernel returns a separate file descriptor, through which the program sets and reads the lines. When the program closes the descriptor, explicitly or simply because it exits, the kernel releases the lines again. libgpiod wraps this ioctl interface in a C API and comes with the command line tools gpiodetect, gpioinfo and gpioset. The libgpiod API works the same on every board, so it is the same library we use on the Raspberry Pi in Part 7. The kernel has marked the old sysfs GPIO interface as deprecated, and we do not use it in this series.
The API of libgpiod 2.x is not compatible with version 1.x. Debian 13 (Trixie) ships libgpiod 2.2.1, Debian 12 (Bookworm) still ships 1.6.3. The current BeagleBoard.org image is based on Debian 13, but installs libgpiod from BeagleBoard.org's own package repository, at the time of writing this post in version 2.2.5. The program toggle.c below is written for libgpiod 2.x.
Debian 13: multiarch
Cross toolchain
Cross-compiling means building the program on the fast host instead of on the BeagleBone. Debian ships the compiler as a package. The BeagleBone Black contains an ARM Cortex-A8, which implements the ARMv7 architecture. The armhf compiler gcc-arm-linux-gnueabihf (32-bit ARM with support for the hardware floating-point unit) is therefore the right choice. There is no 64-bit image for this board.
libgpiod for the target
To cross-compile, the libgpiod headers and library for the target architecture must be present on the host. Debian solves this with multiarch, which installs packages of a foreign architecture next to the native ones:
The following command shows which version a host would install:
The candidate version must start with 2, as on Debian 13. A host that only offers 1.x, for example Debian 12, cannot cross-compile toggle.c this way. In that case we build natively on the BeagleBone.
Hello world program
The "hello world" of GPIO programming switches a pin on and off. The program toggle configures pin P9_23 of the BeagleBone Black's pin header as an output and alternately drives it high and low for 1 ms each. On the oscilloscope we expect a square wave with a period of about 2 ms. P9_23 is also the pin that librsswitch uses by default for the transmitter in Part 9. Until then we leave the transmitter disconnected: with toggle running, it would send a meaningless square wave on 433 MHz into the neighbourhood. All signals on the BeagleBone's pin header use 3.3 V logic levels.
toggle is the program from Part 7 with a different chip and a different line. It is written against the libgpiod 2.x API; librsswitch supports libgpiod 1.x and 2.x.
Makefile
The Makefile has one native target and one cross target: make builds directly on the BeagleBone and make clean cross produces a 32-bit ARM binary (arm-linux-gnueabihf-). The clean before the cross target is important, because make does not notice that a leftover toggle belongs to a different architecture. The recipe for toggle comes from make's built-in rule that turns toggle.c into toggle. That is why this Makefile gets by without a single line indented with a tab, and we can copy it from the page unchanged.
# Native build: make # Cross build: make clean cross CROSS_COMPILE ?= CC = $(CROSS_COMPILE)gcc CFLAGS ?= -O2 -Wall -Wextra LDLIBS = -lgpiod # make's built-in rule turns toggle.c into toggle (CC, CFLAGS, LDLIBS) toggle: toggle.c # Target-specific values also apply to the prerequisite toggle cross: CROSS_COMPILE = arm-linux-gnueabihf- cross: toggle clean: ; rm -f toggle .PHONY: cross clean
toggle.c
As soon as we connect the transmitter to this pin in Part 9, the line must not stay high: a 433 MHz transmitter whose data pin stays high permanently sends an unbroken carrier and blocks the band. That is why toggle does not simply "die" on Ctrl-C: SIGINT and SIGTERM only set a flag, the loop ends, the program drives the line low, releases it first and then frees the configuration objects.
#include <errno.h> #include <gpiod.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define CHIP "/dev/gpiochip0" #define LINE 17 /* P9_23 */ static volatile sig_atomic_t stop; static void on_signal(int sig) { (void)sig; stop = 1; } int main(void) { struct gpiod_chip *chip; struct gpiod_line_settings *settings; struct gpiod_line_config *line_cfg; struct gpiod_request_config *req_cfg; struct gpiod_line_request *request = NULL; struct sigaction sa; unsigned int offset = LINE; int ret = EXIT_FAILURE; /* Ctrl-C and kill end the loop instead of killing the program */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = on_signal; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); chip = gpiod_chip_open(CHIP); if (!chip) { fprintf(stderr, "cannot open %s: %s\n", CHIP, strerror(errno)); return EXIT_FAILURE; } settings = gpiod_line_settings_new(); line_cfg = gpiod_line_config_new(); req_cfg = gpiod_request_config_new(); if (!settings || !line_cfg || !req_cfg) { fprintf(stderr, "out of memory\n"); goto out; } /* One output line, low until the loop starts */ if (gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_OUTPUT) || gpiod_line_settings_set_output_value(settings, GPIOD_LINE_VALUE_INACTIVE) || gpiod_line_config_add_line_settings(line_cfg, &offset, 1, settings)) { fprintf(stderr, "cannot configure line %u: %s\n", offset, strerror(errno)); goto out; } gpiod_request_config_set_consumer(req_cfg, "toggle"); request = gpiod_chip_request_lines(chip, req_cfg, line_cfg); if (!request) { fprintf(stderr, "cannot request line %u: %s\n", offset, strerror(errno)); goto out; } while (!stop) { if (gpiod_line_request_set_value(request, offset, GPIOD_LINE_VALUE_ACTIVE)) break; usleep(1000); if (gpiod_line_request_set_value(request, offset, GPIOD_LINE_VALUE_INACTIVE)) break; usleep(1000); } if (stop) ret = EXIT_SUCCESS; else fprintf(stderr, "cannot set line %u: %s\n", offset, strerror(errno)); /* Leave the line low, so a transmitter on it does not stay keyed */ gpiod_line_request_set_value(request, offset, GPIOD_LINE_VALUE_INACTIVE); out: gpiod_line_request_release(request); gpiod_request_config_free(req_cfg); gpiod_line_config_free(line_cfg); gpiod_line_settings_free(settings); gpiod_chip_close(chip); return ret; }
libgpiod addresses a line by chip and line number, and the chip number is the weak spot: on the BeagleBone Black it has changed between kernel versions. On the current image, P9_23 is line 17 of /dev/gpiochip0, and that is what toggle.c uses. We should still not take this number on trust. gpioinfo P9_23 asks the board and prints the chip and line of the named pin. If the pin is on a different chip on our board, we change CHIP. The section "Finding the line" further below shows how.
Both ways, native and make clean cross, need the libgpiod headers and library: on the host from the multiarch package above, on the BeagleBone from libgpiod-dev (see the target system further below). file shows whether the build worked:
The BeagleBone is a 32-bit ARM board, so the output starts with ELF 32-bit LSB and ARM, EABI5, both for the native build and after make clean cross.
Target system (BeagleBoard.org Debian)
Installing the operating system
The BeagleBone Black runs a Debian image from beagleboard.org. We use the current Debian 13 image without a desktop for the BeagleBone Black; at the time of writing this post, that is Debian 13.7 with kernel 6.18. We download the image together with its checksum and verify it:
URL=https://files.beagle.cc/file/beagleboard-public-2021/images IMG=am335x-debian-13.7-base-v6.18-armhf-2026-09-20-4gb.img.xz wget "$URL/$IMG" "$URL/$IMG.sha256sum" sha256sum -c "$IMG.sha256sum"
sha256sum -c must report OK. Otherwise the download is corrupt; in that case we delete the file and download it again. Then we write the image to a microSD card of at least 4 GB. lsblk shows which device the card is. Caution: dd overwrites whatever we name, without asking:
The image has no default password. Before the first boot, we create a user in sysconf.txt on the small FAT partition BOOT of the card (/dev/sdX1); the image reads the file at boot and then removes the password from it. A key for SSH is optional:
user_name=beagle user_password=<your password> user_authorized_key=<content of ~/.ssh/id_ed25519.pub>
We put the microSD card into the BeagleBone, connect it to the Ethernet and power it on. The BeagleBone used here boots from the card on its own. If it boots from the internal eMMC instead, we hold down the boot button S2 (the small push-button next to the microSD slot), apply power and release the button after a few seconds. Then we log in via SSH with the user and host name that the image documents:
As in Part 7, Linux is not a real-time system. The kernel can interrupt the program at any time, and the oscilloscope shows these interruptions as jitter (see below).
Tools and libgpiod
On the BeagleBone we install the compiler, libgpiod including the header files and the libgpiod command line tools, and check which libgpiod version apt installed:
The installed version must start with 2 (2.2.5 on the image from above). If the release still ships libgpiod 1.x, the compiler aborts on toggle.c with implicit declaration of function 'gpiod_line_settings_new'.
Finding the line
The AM335x chip of the BeagleBone has four GPIO banks, and the kernel turns each of them into a GPIO chip. Which gpiochipN number a bank gets depends on the kernel version, so we verify it on our board. gpiodetect lists the chips, and gpioinfo P9_23 searches for the line named after the header pin and prints the chip and line number:
On the image used here, the output looks like this:
$ gpiodetect gpiochip0 [gpio-0-31] (32 lines) gpiochip1 [gpio-32-63] (32 lines) gpiochip2 [gpio-64-95] (32 lines) gpiochip3 [gpio-96-127] (32 lines) $ gpioinfo P9_23 gpiochip0 17 "P9_23" input
The chip labels only give the range of GPIO numbers, so the chip number from gpioinfo is what counts: P9_23 is line 17 of gpiochip0. If gpioinfo reports a different chip on our board, we enter that chip at CHIP in toggle.c.
A pin on the pin header must also be in GPIO mode. On this image, P9_23 is a GPIO right after boot, so we do not have to do anything. The config-pin tool of older images no longer exists; a different pin function would need a device tree overlay, which this series does not use.
Building and running
Natively on the BeagleBone: we copy Makefile and toggle.c from the host to the BeagleBone and build the program there.
ssh beagle@beaglebone.local mkdir -p toggle scp Makefile toggle.c beagle@beaglebone.local:toggle/ ssh beagle@beaglebone.local cd toggle make ./toggle
Cross-compiling on the host: we build with make clean cross, copy the binary to the BeagleBone and run it there.
We stop the program with Ctrl-C. Whether a normal user may open the chip depends on the group that owns the device. ls -l /dev/gpiochip0 shows the group gpio, and groups shows that the user created through sysconf.txt is already a member. For other users, we run sudo usermod -aG gpio $USER and log in again. We could of course also start the program as root, but for security reasons we do not.
Oscilloscope
We shut down the BeagleBone and disconnect it from the power. Then we connect the probe tip to P9_23 and the ground clip to a ground pin of the pin header, for example P9_1. We power the BeagleBone on again, log in and start toggle:

The line toggles between high and low. With 1 ms each for high and low, we expect a period of about 2 ms. Because usleep is not exact and Linux is not a real-time system, the edges wander from period to period: that is the jitter mentioned above. On the BeagleBone Black used here, the oscilloscope measures about 2.70 ms instead of 2 ms: every usleep sleeps a little longer than requested, and the calls into libgpiod and the kernel add to that.
With toggle running, the BeagleBone is ready. In Part 9 we switch the real sockets with librsswitch.
We tested everything with a BeagleBone Black revision A5C and the Debian 13.7 image from above. The revision is in the board's EEPROM; sudo hexdump -C /sys/bus/i2c/devices/0-0050/eeprom | head -1 shows it after A335BNLT.