惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
月光博客
月光博客
博客园 - Franky
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
有赞技术团队
有赞技术团队
V
V2EX
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
腾讯CDC
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
Martin Fowler
Martin Fowler
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
C
Check Point Blog
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog

Linux.org

Arduino Uno Q - LED Matrix - Rain Python Series Part 25: Canvas Widget - Part 2 Proxmox VE Series Part 5: Windows Virtual Machine PocketBeagle 2: Setup, Imaging, and Internet Access Orange Pi 6 Plus and Pimox 8.4.10 IRC is back on linux.org Arduino UNO Q: A Debian Linux Board for Headless Projects R36Pro Handheld with Linux ArkOS The Linux.org Story Python Series Part 25: Canvas Widget - Part 1: The Canvas and Its Drawable Objects Proxmox 04 - Linux Virtual Machine Banana Pi R4 (BPI-R4) - DHCP for Multiple Subnets Run Windows Apps on Linux with WinBoat Getting Started with the Radxa X5 SBC on Linux Python Series Part 23: Text Widget - Part 1 Proxmox VE Series Part 3: Basic Configuration Banana Pi R4 (BPI-R4) Python Series Part 23: Text Widget - Part 1 Proxmox VE Series Part 2: Installing Proxmox
PocketBeagle 2 TechLab - Part 1
invalid@example.com (Jarret B) · 2026-09-12 · via Linux.org

The TechLab is a Cape used to help learn to program for the PocketBeagle 1 and 2. There are quite a few components built-in to the TechLab, so this is an inexpensive way to learn some programming.

The images you can download for the PocketBeagle 2 include one that is listed as 'Workshop'. You need the image when hooking up to the TechLab since it has the drivers in the kernel for the TechLab Cape.

Specs on the PocketBeagle TechLab

The TechLab is a CAPE that attaches to a PocketBeagle and adds sensors and output mechanisms to enhance the PocketBeagle. Mainly, the TechLab is for educational purposes for teaching someone about programming and using the TechLab to enhance the PocketBeagle's abilities.

The sensors and output mechanisms include:

  • User Inputs:
    • 2 push buttons (L and R)
    • 1 light sensor via ADC (Analog-to-Digital Converter)
  • User Outputs:
    • 1 tri-color RGB LED via PWM (Pulse Width Modulation)
    • 2-digit, 7-segment display via SPI
    • 1 buzzer via a PRU (Programmable Real-Time Unit)
  • Sensors:
    • 1 accelerometer
  • Expansion:
    • 1 mikroBus header for connecting compatible add-on boards
  • Memory:
    • 1 I²C EEPROM (write-protected) for board identification and additional data storage

To make this work, you need the 'Workshop' version of the Linux Debian image, which has all the drivers as well as the necessary scripts to interact with the TechLab.

Figure 1 shows the TechLab.

Figure 1.gif

FIGURE 1

When connecting the PocketBeagle 2 to the TechLab, you need to have the USB-C connector on the PocketBeagle 2 on the same side of the diagram as the 'USB Reference' label, which is near the USB-A connector. The SD card is not on the opposite side as labeled on the PocketBeagle 2. The SD card is now on the same side as the USB-C connector.

After you push the PocketBeagle 2 onto the pins and power on the PocketBeagle 2, lights should come on just as before, but on the TechLab, there should be lights on the TechLab as well. After the initial boot, if no lights on the TechLab light up on the PocketBeagle 2, then you need to remove the power and verify the PocketBeagle 2 connection to the TechLab board is proper and on all pins.

NOTE: The PocketBeagle 2 does not push flush and cover the pins completely on the TechLab.

HAT vs CAPE

You may have heard of add-on devices being called a HAT. This is a name used for Raspberry Pi devices. For Beagle Board devices, these are called CAPEs.

HAT (Hardware Attached on Top)
CAPE (Capulets Attached on Peripheral Expansion)

There are other types of add-on boards:

  • pHATs (Partial Hardware Attached on Top) for Raspberry Pi
  • Capes (for BeagleBone) which can include display capes
  • DIPs (for C.H.I.P.)
  • Mezzanine (for 96boards)
  • Shields (for Arduino)
  • Daughterboards or expansion boards are general electronics terms for these items.

Example Code

After you have the TechLab operational, you need to make sure there is a connection to the internet, as detailed in the article 'PocketBeagle 2'.

Make sure you perform a repository update and then an upgrade:

Code:

sudo apt update
sudo apt upgrade -y

After you complete this, you need to download the workshop sample code. Use the following command to do this; just remember that file downloads go to the Present Working Directory (pwd).

Code:

git clone https://openbeagle.org/beagleboard/vsx-examples.git

After the download, there should be a folder with the name 'vsx-examples'. Once you go into this folder, there are four folders:

  1. docs
  2. BeagleBone
  3. Libraries
  4. PocketBeagle-2

For our device, we need the folder named 'PocketBeagle-2'. So, under this folder, there are eight folders of importance. Each folder contains example code for the specific sensor or output device. These eight items are:

  1. accelerometer
  2. button
  3. led lights
  4. seven_segment
  5. rgb_led
  6. light-sensor
  7. tonal_buzzer
  8. eeprom

We will get into Python examples soon. The languages used in the download are Python and Rust, but we will look at Python since I have written articles to cover Python programming.

For each sensor and output device, we will go over the downloaded examples. You can see the sensors and output mechanisms in Figure 2.

Figure 2.jpg

FIGURE 2

Accelerometer

The Accelerometer is an 'MMA-8453' chip, which is a 3-axis digital accelerometer.

In the code, we specify the chip model, which is 'mma8453' and then find the device and assign its location to a variable. We can then access the information in the chip’s registers to determine a value in the change for the X, Y and Z axes.

You can find the code in the folder ‘/vsx-examples/PocketBeagle-2/accelerometer' then under 'Python' in 'main.py'.

Looking at Figure 1, the X-axis is to the left and right. If the board is flat and level, the X value will be ‘0’. If the right side is higher than the left side, the X value will be positive. But if the right side is lower than the left, the value is negative.

For the Y-axis, the value is ‘0’ if it is level. The value will be positive if the top is higher than the bottom, yet negative if the bottom is higher than the top.

The Z-axis goes through the board up and down if the board is level.

There are three files that contain the value of the specific axis:

  • /sys/bus/iio/devices/iio\:device1/in_accel_x_raw
  • /sys/bus/iio/devices/iio\:device1/in_accel_y_raw
  • /sys/bus/iio/devices/iio\:device1/in_accel_z_raw

The value inside each file is a basic value for the accelerometer in each axes, but to get the value in meters per second per second (m/s²), you need to take the value for the axis and then multiply it by the sensitivity, or scale, found in ‘/sys/bus/iio/devices/iio\:device1/in_accel_scale’. When I use ‘cat’ to see the contents, my scale is ‘0.038307’. Keep in mind that the device sitting still will give a value for the Z axis of 9.8 m/s², which is the pull of gravity. The values change for all axes if you move the board, and it becomes greater when moving faster.

The code given with the ‘vsx-examples’ for the accelerometer is:

Code:

from time import sleep
from sysfs import Device

DEV_NAME = "mma8453"
accel = Device(name=DEV_NAME)
scale = accel.sysfs("in_accel_scale").read_float()
x_raw = accel.sysfs("in_accel_x_raw")
y_raw = accel.sysfs("in_accel_y_raw")
z_raw = accel.sysfs("in_accel_z_raw")

while True:
    x_scaled = x_raw.read_float() * scale
    y_scaled = y_raw.read_float() * scale
    z_scaled = z_raw.read_float() * scale
    print(
        f"Acceleration along X = {x_scaled:.2f} ms^2, Y = {y_scaled:.2f} ms^2, Z = {z_scaled:.2f} ms^2"
    )
    sleep(1)

The ‘sysfs’ file imported at the beginning is used to allow an interface with the kernel for the hardware.

The script then places the device name into a variable ‘DEV_NAME = "mma8453”’ and on the next line, we place the location of the device into the variable ‘accel’. We then map the variables ‘scale’, ‘x_raw’, ‘y_raw’ and ‘z_raw’ to the specific locations of the files containing the values for the specific axes. We can then read the values every second and calculate the acceleration for all three axes.

If we wanted, we could test the X-value and tell whether it is moving left or right. We can test the Y-value to see if the board is moving forward or backward. Testing the Z-value will let us see if the board is right-side up or upside down.

Button

On the TechLab board are two buttons, a left and right button that are labeled as ‘L’ and ‘R’. You can see them marked in Figure 2 in the lower-left corner.

We can use Python to create code to catch when a person presses or releases a button. Before we do this, we need to understand what is happening and how it is determined about a button press or release.

The buttons transmit data over the General-Purpose Input/Output (GPIO) pins. The input of these is in

/dev/char/’. It sends the codes on the drive 13 (GPIO) at the pin number 64, so the file in the folder is ‘13:64’. The contents of the file are in binary and we must convert them through the imported file ‘chardev.py’ from ‘main.py’. The sample code is in ‘vsx-example/PocketBeagle-2/button/python/’. If you load the ‘main.py’ and get access to the variable ‘evt’, the output is like:

Code:

InputKey(timeval=Timeval(tv_sec=8.72694379e-315, tv_usec=5.19105e-319), inp_type=1, code=105, value=0)

Each item in the list is broken down by the ‘evt’ variable, such as ‘code’ is referenced as ‘evt.code’ or ‘evt.value’. The Event Code (evt.code) represents the code for the buttons. The left button is ‘105’ and the right is ‘106’.

The ‘evt.value’ determines if someone presses the button (0) or releases (1) it.

For the way the initial sample code is written, it only tests for the right button and if the button is released. We can change the ‘main.py’ file to include the left button and test for a button press:

Code:

from chardev import CharDev
BUTTONS_NAME = "buttons"
LEFT_CODE = 105
RIGHT_CODE = 106
btn = CharDev.input_device_by_name(BUTTONS_NAME)
print("Waiting for Input")
while True:
    evt = btn.read_evt()
    if evt.code == RIGHT_CODE and evt.value == 1:
        print("Right button released")
    if evt.code == LEFT_CODE and evt.value == 1:
        print ("Left button released")
    if evt.code == RIGHT_CODE and evt.value == 0:
        print("Right button pressed")
    if evt.code == LEFT_CODE and evt.value == 0:
        print ("Left button pressed")

In the code, we first import ‘chardev.py’. We specify the ‘BUTTONS_NAME’ variable to be ‘buttons’. Then we set the values for the left and right buttons in their own variables. We then specify that the variable ‘btn’ should contain the input of the buttons from the ‘chardev’ imported file. Then, it prints ‘Waiting for Input’. The last step in the code is to run a loop. Within the loop, we get the event (evt) from the folder we discussed. The code then checks the ‘evt’ items to determine which event has occurred and prints the output to tell which button is being pressed or released. You can hold a button down to see the individual output before you release the button for the final output of ‘released’.

Conclusion

I do not want to make the article too long to cover all the sensors and output mechanisms, so we will cover more in the next article.

I must say that the TechLab board is a very fun device to add-on to the PocketBeagle 2. Both boards are fun to use and extremely cool for their size.

Check out www.BeagleBoard.com and order them soon.