Use case: CLI with an AI agent
Goal
Add an ADXL345 accelerometer to a Raspberry Pi 4 by asking an AI agent in a
terminal: Claude Code, with the analog-attach-linux skill, runs the
analog-attach commands, and you answer its questions and approve the
deploy. At the end the overlay is on the board and the acceleration reads back
over the network.
What you need
Item |
Details |
||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Board / carrier |
Raspberry Pi 4 Model B, running ADI Kuiper |
||||||||||||
Evaluation board / part |
MikroElektronika Accel Click (ADXL345), set for I2C at address
|
||||||||||||
Wiring |
Five jumper wires from the Click to the Pi’s 40-pin header:
|
||||||||||||
Cables and power |
The Pi’s USB-C power supply; an Ethernet cable from the Pi to the host.
Here the host shares its connection over that cable, and the Pi gets
|
||||||||||||
Host |
Linux machine with Analog Attach installed (see Installation),
Claude Code, |
||||||||||||
Software versions |
Analog Attach 0.2.0; the ADI Linux tree ( |
Steps
Step 1: Wire the Click
With the Pi off, connect the Click as in the table above.
Step 2: Install the skill
analog-attach skill install analog-attach-linux
This copies the skill to ~/.claude/skills/analog-attach-linux/, where
Claude Code finds it. See Working with AI Agents.
Step 3: Start the agent in the project folder
mkdir -p ~/work/rpi4-adxl345 && cd ~/work/rpi4-adxl345
claude
The project can be new: the agent sets it up. It asks for the kernel tree and
the board rather than guessing them. Answer ~/linux and
bcm2711-rpi-4-b.dts, or set the project up first (see
Configuration).
Step 4: Ask for the device
Type, for example:
Add an ADXL345 accelerometer on the Raspberry Pi’s I2C bus at 0x1d, interrupt on GPIO 27 rising edge, then validate and build.
The agent runs analog-attach commands with --json and reads their
answers. Claude Code shows each command and asks before it runs one you
haven’t allowed. The commands differ from run to run; a run goes like this:
Command |
What it is for |
|---|---|
|
What the project has set. For a new project, |
|
The compatible: |
|
Whether the kernel tree has an overlay to start from
( |
|
The buses. You named the I2C bus, so it takes |
|
The node, at |
|
The interrupt controllers: |
|
The GPIO controller as the interrupt parent. |
|
GPIO 27, rising edge, as you said. |
|
A warning: the bus is disabled, Linux won’t probe the device. |
|
Turns the bus on in the overlay. |
|
No errors. |
|
|
When it is done, the agent says what it wrote, and offers to deploy.
Step 5: Deploy
Deploy copies the overlay to the Pi and reboots it, so the agent asks first. Tell it the Pi’s address and password, for example deploy it to 10.42.0.196, user analog. It then runs:
analog-attach --json config var BOARD_IP 10.42.0.196
BOARD_PASSWORD=… analog-attach --json deploy
The password goes in the environment of deploy only, never in a file.
Approve the command when Claude Code asks. To keep the password out of the
conversation, run the deploy yourself instead: analog-attach deploy asks
for it, hidden.
Result
When the Pi is back, the ADXL345 is an IIO device:
iio_info -u ip:10.42.0.196 | grep -A3 adxl345
lists adxl345 with its channels accel_x, accel_y and accel_z.
Read the raw values on the Pi:
$ ssh analog@10.42.0.196
$ cd /sys/bus/iio/devices/iio:device0 # the device whose name is adxl345
$ cat name in_accel_x_raw in_accel_y_raw in_accel_z_raw
adxl345
2
1
253
With the board lying flat, X and Y are close to 0 and Z reads about 253: 1 g.
You can also ask the agent to explain the workfile, or to change it: each
change is another update, and the agent validates again.
The workfile, as in Use case: Configure a device with the CLI only (the node’s name and label are the agent’s choice and may differ):
/dts-v1/;
/plugin/;
/ {
fragment@0 {
target = <&i2c_arm>;
__overlay__ {
status = "okay";
adxl345: adxl345@1d {
compatible = "adi,adxl345";
reg = <0x1d>;
interrupt-parent = <&gpio>;
interrupts = <27 1>;
};
};
};
};
Troubleshooting
The agent doesn’t use analog-attach. Check that the skill is installed (
analog-attach skill installlists it asinstalled), and startclaudeagain after installing it.The agent guesses the wiring. Say the bus, address and interrupt in the prompt, as above, and check what it set before you deploy:
analog-attach read adxl345.No adxl345 in iio_info. See the troubleshooting of Use case: Configure a device with the CLI only.
Next steps
Use case: GUI with an AI agent: an agent in the GUI, as its Assistant.
Working with AI Agents: the skill, and what the agent does on its own.