How Tiltie feels an item landing on the tray, talks back with light, and hands everything to the rest of the system.

In the previous update I split Tiltie into three parts: a mechanical controller, a main system and a classification service. This post is about the mechanical controller, the Raspberry Pi Pico that spins the tray, tilts it and finds its home with a CandemBoss microswitch. This week it learned three new tricks:
- It can feel. An ADXL372 accelerometer turns the moment an item lands on the tray into a vibration footprint.
- It can talk back with light. A small LED panel with six CandemBoss LEDs, driven through a ULN2003AN, shows which container was chosen and what Tiltie is up to.
- It speaks a documented wire protocol. A Raspberry Pi CM4 over UART or a PC over USB drive the Pico with exactly the same code, and fetch the footprints that feed the classification API.
Along the way I also rebuilt the Pico firmware as four small Arduino libraries, because the sketch had grown to well over a thousand lines and I was starting to lose arguments with it.
The Pico at a glance
|
Part |
Pico pins |
Notes |
|---|---|---|
|
Stepper 28BYJ-48 (yaw) |
GP2–GP5 |
runs alone on core 1 |
|
Servo (tilt) |
GP6 |
|
|
Limit switches |
GP7 (home), GP8 (90°) |
normally closed |
|
LED panel (6 LEDs) |
GP9–GP14 |
through a ULN2003AN |
|
ADXL372 |
GP16 MISO, GP17 CS, GP18 SCLK, GP19 MOSI, GP20 INT1 |
SPI0 |
|
Host link |
USB, and UART0 on GP0 (TX) / GP1 (RX) |
921600 baud, 8N1 |
Core 1 only moves the stepper and watches the switches. Core 0 does everything else: servo, LEDs, the accelerometer and the serial protocol.
Limit switch:

Candemboss LEDs:


Stepper motor:

Why a vibration footprint?
The camera tells Tiltie what an item looks like. The tray can tell it how the item lands. A paper wad goes “thud”, a metal screw goes “tink”, a plastic lid bounces and rattles. In the last update I mentioned the crumpled wrapper that looks like paper but may not be paper, and that is exactly the kind of case where a second witness helps.
I don’t expect the accelerometer to classify anything on its own. It is one more voice in the conversation, and the classification service decides how much to trust it.
Meet the ADXL372
The ADXL372 is an Analog Devices MEMS accelerometer built for impacts: ±200 g, 12-bit output, SPI, and an output data rate up to 6400 Hz with a 4-pole anti-aliasing filter. I’m using the EVAL-ADXL372Z breakout, a 20 mm × 20 mm board with four mounting holes (15 mm × 15 mm apart), two 5-pin header footprints and the bypass capacitors already fitted.

|
What matters for Tiltie |
Value (datasheet Rev. C) |
|---|---|
|
Range |
±200 g |
|
Resolution |
12 bits, 100 mg per LSB (10 LSB per g) |
|
Noise |
3.5 LSB rms in normal mode (about 0.35 g), 3 LSB in low-noise mode |
|
Output data rate |
400 to 6400 Hz |
|
Anti-aliasing filter |
4-pole, 200 to 3200 Hz, must stay at or below ODR/2 |
|
Interface |
SPI up to 10 MHz (limited I²C also available) |
|
Supply |
1.6 to 3.5 V |
|
Current |
22 µA at 3200 Hz ODR and 2.5 V |
Two warnings from the user guide are worth repeating: the breakout has no reverse-polarity protection, and dropping it on a hard surface can generate thousands of g. I would rather not find out.
Wiring is short: 3V3 to VS and VIO, GND to GND, and SCLK, MOSI, MISO, CS and INT1 to the Pico pins in the table above. INT1 is configured as DATA_RDY, so the Pico knows exactly when a new sample is ready.

Decisions I made (and why)
- Stay in measurement mode. The ADXL372 has an ultra-low-power instant on mode (1.4 µA) and a wake-up mode. They are great for battery nodes, but Tiltie has motors, so power is not the problem. Instant on triggers at 10 g ± 5 g by default, far above a paper wad, and wake-up mode has no FIFO, no interrupts and sleeps at least 52 ms between looks, so it could miss the landing. I want continuous data.
- Fastest rate, generous bandwidth. 6400 Hz output data rate with a 1600 Hz filter, which leaves the 4-pole filter room to work instead of sitting right at Nyquist. Low-noise mode is on: it costs a few extra µA I don’t care about.
- All the digital filters off. The built-in high-pass filter would remove the static offset, but the sensor sits on a fixed chassis, so gravity is constant and I can subtract a baseline in software. The activity low-pass filter averages at around 10 Hz, which would erase exactly the transient I am after.
- No FIFO. The chip has a 512-sample FIFO, but the silicon has a known erratum (er002) where axes can come out rotated (y, z, x instead of x, y, z). Instead I read X, Y and Z in one 6-byte burst every time INT1 says a sample is ready, and keep my own circular buffer. As a bonus, I get a pre-trigger window for free.
- Mount it on the chassis, not on the tray. The board lives on the chassis that holds the stepper. The orientation never changes, the wires never move, and the mounting is repeatable. The price is that an impact reaches the sensor through the tray, servo, beam, yoke and bearings, so it arrives smaller and filtered. The datasheet suggests mounting near a rigid point anyway. And since the footprint is really the response of the structure, being repeatable matters more than being loud.
- Live with the errata. Erratum er003 puts a small spurious tone at 1/5 of the output data rate (1280 Hz at 6400 Hz) in every capture. It is constant, so it is tolerable as long as training and inference use the same rate.
How the sensor gets armed
I wrote a small state machine, the ImpactRecorder, that runs from the main loop without blocking.

- Settling. After ARM, it waits 500 ms. Any motor motion restarts this wait, so the tray has stopped ringing before I measure anything.
- Baseline. It averages 512 samples (about 80 ms) to learn the resting vector: gravity plus offsets.
- Armed. It keeps a circular buffer with the last 64 samples (10 ms) and watches the deviation from the baseline. The baseline slowly follows drift, so a warm sensor doesn’t cause false triggers.
- Trigger. When the deviation magnitude stays above the threshold (1.5 g by default) for two consecutive samples, it fires. Requiring two samples avoids single-sample glitches.
- Capture. It stores 2000 more samples (about 312 ms). With the pre-trigger samples that makes 2064 samples per axis, 322.5 ms.
- Hold. The capture and its features stay in memory until the next ARM, so the client can fetch them, retry, or dump them whenever it wants.
How do I choose the threshold? There is a NOISE command that measures one second of rest noise and suggests three times the rms. I only run it with the motors stopped, and it is worth running again with the servo attached and detached, because a holding servo can add vibration of its own.
What is in a footprint
The raw capture is 2064 × 3 signed 12-bit samples. On top of that the Pico computes a few quick features, mostly for gating and debugging:
|
Feature |
Meaning |
|---|---|
|
peak |
highest 3D deviation from the baseline (g) |
|
tpk |
trigger to peak (ms) |
|
decay |
peak to the last sample above 20 % of the peak (ms) |
|
energy |
sum of squared deviation divided by the sample rate (g²·s) |
|
axis |
dominant axis, X, Y or Z |
|
fzc |
rough dominant frequency from zero crossings (Hz) |
|
miss |
samples lost because the loop was too slow |
|
dist |
a motor moved during the capture |
|
trunc |
the decay did not finish inside the window |
The real analysis (MFCCs and so on) happens in the classification service, from the raw samples. If miss is not zero or dist is set, the client simply leaves the vibration out and classifies from the photo alone.
Reading some real footprints
These are captures from the bench, loaded into the classification workbench. Each panel shows the trace (6400 Hz, 2064 samples, 323 ms), the MFCC mean ± std for C0 to C12, the 20-band mel profile, and a few numbers. One note: the workbench label says “1D Accelerometer / Piezo Impulse” because it also accepts piezo input. Our trace is 1D because the API takes a single channel, so the client sends the dominant axis, baseline-subtracted, in g.
|
Trace |
Peak |
Decay (−20 dB) |
Centroid |
Shape |
|---|---|---|---|---|
|
Ball pen |
17.1 g |
70.0 ms |
2035 Hz |
a tall burst, then a second isolated kick about a quarter of the way in |
|
metal screws |
8.5 g |
67.5 ms |
2040 Hz |
several comparable peaks that ring down |
|
Plastic Lid |
12.2 g |
17.5 ms |
1946 Hz |
one sharp spike and then almost silence |
|
Used Paper Tissue |
1.5 g |
312.5 ms |
2411 Hz |
no impact at all, just a sustained oscillation across the whole window |
Images and captions:
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
A few things stand out:
- Amplitude and decay vary a lot. From 1.5 g to 17 g, and from 17 ms to 70 ms. These are the strongest differences between the traces.
- The spectra look alike. The three real impacts have centroids around 1.95 to 2.04 kHz and the same pattern in the MFCCs, with C0 and C1 dominating. With so few samples I can’t say the MFCCs help yet. For now, amplitude and decay look like the more useful features. I need many more drops.
- Used Paper Tissue trace is what a non-event looks like. Its peak is right around the default 1.5 g trigger, and it is a regular oscillation rather than a decaying impact. A soft item such as a tissue barely excites a ±200 g sensor with 0.1 g resolution, so what is left is mostly the structure ringing. That is the sensitivity limit I was worried about, and now I have a picture of it.
The tissue case is also a good example of sensors disagreeing. When I classified the tissue, vision said “used paper tissue” with 92 % confidence, but the reasoning line on the LCD readout says “Vibration suggests stiff object.” That doesn’t sound right for a tissue. My suspicion is that the model was reading a footprint made of ringing rather than a landing. It is a reminder that fusion should weigh the vibration by how convincing the impact is.
What the service did with them
All six drops below went through the same /api/v1/classify call, image plus vibration MFCC features, using gemini-3.1-flash-lite:
|
Item |
Outcome |
Confidence |
Latency |
|---|---|---|---|
|
plastic cap |
Packaging (C02) |
95 % |
4637 ms |
|
metal screws |
Unsupported Waste, remove item |
95 % |
3332 ms |
|
ballpoint pen |
General Waste (C04) |
98 % |
1930 ms |
|
used paper tissue |
General Waste (C04) |
92 % |
1053 ms |
|
used tissue on plate |
General Waste (C04) |
85 % |
3744 ms |
|
E-waste mechanism |
Unsupported Waste |
98 % |
2795 ms |




The 4 × 20 character LCD readout is a nice touch of the API: row 1 is the status (C02:Packaging 95%, REMOVE:Unsup 95%) and the other three rows are the reasoning, truncated to 20 characters, which is why the screws message ends with “remove for”. The Pico has no LCD; it is meant for the client side, the Raspberry Pi CM4.
Also worth noting: classification took between about 1 and 4.6 seconds. That is the budget the tray has to wait before the LEDs and the mechanics can react.
The LED panel
Tiltie needs to say things without a screen: which container it chose, that it is thinking, that something needs attention. I’m building a panel with six LEDs in two vertical columns of three (red, amber, green from top to bottom).
The LED panel uses two CandemBoss Pluggable Terminal Blocks.

Together they form a square outline with the top-middle and bottom-middle LEDs missing, which gives four natural corners, one per container.

Driving it with a ULN2003AN
The ULN2003AN is an array of seven Darlington transistors with open collectors, and I use six of its channels. Each GPIO drives one input, and when it goes HIGH the channel sinks current to ground and the LED lights. That keeps the LED current out of the Pico pins, and lets the LEDs run from a supply higher than 3.3 V. It matters, because the ULN2003 drops a fraction of a volt to about a volt across the channel, which would leave very little headroom for a red or green LED on 3.3 V.

I used a 5 V supply with 390 Ohms resistors to limit current.

The animations
Animations run from the main loop with no delay(): the panel checks the clock, and only writes to the pins when the pattern changes.
|
Command |
What you see |
Use |
|---|---|---|
|
ANIM CW / ANIM CCW |
a bright LED with a tail runs around the outline |
turning right or left |
|
ANIM C1 to ANIM C4 |
one corner stays lit |
the chosen container |
|
ANIM RED / AMBER / GREEN |
the two LEDs of that colour |
traffic light |
|
ANIM FLASH |
all six blink |
alert, for example remove an item |
|
ANIM PLAY |
random sparkle |
attract attention |
|
ANIM STOP |
everything off |
Every animation accepts a duration in milliseconds, and with no duration it runs until ANIM STOP. When a timed animation ends, the Pico sends ! ANIM_DONE. The corners match the compartments in the workbench: C1 Paper (top-left), C2 Packaging (top-right), C3 Organic Waste (bottom-right), C4 General Waste (bottom-left).
< OK
< ! ANIM_DONE (3 seconds later)
> ANIM C2 (container 2 stays lit)
< OK
> ANIM STOP
< OK
The client turns an API answer into light like this: ACTUATE_COMPARTMENT lights the container corner, REMOVE_ITEM flashes, and MANUAL_CLASSIFICATION_REQUIRED goes amber. One thing I want to measure: switching LEDs adds current steps to the supply, and the accelerometer is on the same board. The steady animations (corner, traffic light) don’t switch while they run, so they are the safe choice while the sensor is armed.
The wire protocol
The CM4 will be the brain in the final bin, but while developing I want to use the same Pico from my PC. So the Pico serves the same protocol on two links at the same time:
|
Link |
Pico side |
Client side |
|---|---|---|
|
USB (PC) |
USB CDC |
COMx or /dev/ttyACM0, baud rate ignored |
|
UART (CM4) |
UART0, GP0 = TX, GP1 = RX |
crossed RX/TX, common GND, 921600 baud, 8N1, 3.3 V |
On the CM4, use a PL011 UART (/dev/ttyAMA*). The mini-UART, which /dev/serial1 may point to, is not reliable at 921600. Replies always go to the port that asked, and events go to every port that has talked to the Pico, so a PC and a CM4 can even listen at once. ( recommended one master at a time.) The firmware also doesn’t wait for a USB host at boot, which matters when only the CM4 is plugged in.
Three kinds of lines
Everything is plain ASCII text, one line per message, up to 63 characters per command:
|
Prefix |
Meaning |
|---|---|
|
OK ... |
success reply to the last command |
|
ERR <CODE> |
failure, for example BUSY, BAD_ARG, NOT_HOMED, NO_DATA |
|
! <NAME> ... |
an event, which can arrive at any moment between replies |
A multi-line reply has lines=N in its OK header, then exactly N lines, then END. Nothing else is sent in between.

The commands
|
Command |
What it does |
|---|---|
|
PING, VERSION, STATUS, HELP |
liveness, capabilities, state, command list |
|
HOME, YAW 0|90, TILT -45..45, STOP |
the mechanics; completion arrives as ! HOMED / ! DONE |
|
ANIM <name> [ms], LED n 0|1 |
the LED panel |
|
ARM, DISARM, THR [g], NOISE |
the accelerometer |
|
TRACE [id] |
fetch the vibration footprint |
|
DUMP |
the same footprint as CSV, for debugging |
The events you will see most are ! ARMED, ! IMPACT, ! DONE, ! HOMED, ! ANIM_DONE and ! BOOT. A complete session looks like this (the numbers are illustrative):
< OK
< ! ARMED
< ! IMPACT id=7 peak=4.2 tpk=-0.2 decay=40.0 energy=0.011 axis=Z fzc=900 miss=0 dist=0 trunc=0
> TRACE 7
< OK trace id=7 n=2064 ch=XYZ fmt=i16le odr=6400 scale_g=0.1 trig=63 base=1.00,-2.00,10.00 axis=Z miss=0 dist=0 bytes=12384 crc32=1DA313A6 lines=129
< D 0 <128 base64 characters>
< ...
< D 128 <128 base64 characters>
< END
How the footprint travels
The payload is the raw capture as interleaved little-endian int16 (X0 Y0 Z0 X1 Y1 Z1 ..., 6 bytes per sample), which is 12,384 bytes. It is split into 129 lines of 96 bytes, each encoded as base64, so it stays text and survives any terminal. The header carries what the client needs to rebuild the signal: the sample rate (odr), the scale (scale_g), the index of the trigger (trig), the baseline of each axis (base), the dominant axis, the quality flags and a CRC32 of the whole payload. If the CRC doesn’t match, the client just asks again, because the capture stays in memory until the next ARM.
On the wire that is about 17.6 KB: roughly 0.19 s at 921600 baud, 1.5 s at 115200, and immediate over USB.
To get from there to the API, the client converts each sample to g and keeps one axis:
a_g[i] = (raw[i] - base) * scale_g
Then it builds the request. The vibration part is just a sample rate and an array:
"vibration_trace": { "sample_rate_hz": 6400, "samples": [0.002, 0.014, -0.095, ...] }
If there is no usable trace it leaves the field out, because the API rejects an empty array. I also wrote a small reference client in Python, so the whole cycle looks like this:
link = PicoLink.open("/dev/ttyAMA0", 921600) # or "COM9" on a PC
link.command("ARM")
event = link.wait_event("IMPACT")
trace = link.get_trace(int(event.fields["id"])) # CRC checked, retried if needed
body = make_classify_request(jpeg, trace if trace.clean else None)
result = classify(body)
show_result(link, result) # ANIM C1..C4 / FLASH / AMBER
For bring-up there are two handy flags: --no-api --save-trace trace.json just captures an impact and saves the API-ready trace, and --extract-mfcc sends it to the service’s feature extraction endpoint without calling the classifier, which is a cheap way to check units and shape.
Four small libraries
The Pico sketch had outgrown itself, so I split it into four reusable Arduino libraries with a thin sketch that wires them together:
|
Library |
What it does |
|---|---|
|
TiltieCommand |
the command processor: reads USB and UART, calls the handlers you register, sends replies and events |
|
TiltieLeds |
the LED animations |
|
TiltieServo |
the tilt servo, with a callback when it has settled instead of a delay() |
|
TiltieAccel |
the ADXL372 driver, the impact recorder and the trace encoder |
The libraries never print anything. They call callbacks (onImpact, onSettled, setFinishedCallback), and the sketch turns those into events. Adding a command to the protocol takes a handler plus a single cmd.on("NAME", handler) line. Each library has its own README and examples, and the code is in the repository
https://github.com/javagoza/smart-tilting-bin/tree/main/rpipico/tiltie_bin_firmware
Because debugging a 6400 Hz sampling loop with printf is not fun, I also wrote tests that run on a PC against small stubs of the Arduino API. They cover command parsing, LED sequences, servo timing, the ADXL372 register writes, impact detection and the trace encoding.
Two compile errors worth a smile
- I named an array PIN_LED, and the RP2040 core already defines PIN_LED as a macro for the on-board LED. The compiler error was very confusing.
- A private method called bit() met the Arduino macro bit(b). Same kind of mess. Now my test stubs define the core’s macros too, so my PC build catches these before the IDE does.
What I learned
- Design the whole loop around the sampling. At 6400 Hz a sample arrives every 156 µs, so nothing in loop() may block while the sensor is armed. Everything is polled, nothing waits.
- Don’t trust the FIFO blindly. Reading the errata sheet before writing code saved me a nasty misalignment bug.
- The footprint is the response of the structure. Where the sensor sits matters as much as the sensor.
- Light items are close to the noise floor. The honest answer today is “not enough data yet”.
What’s next
- Collect many more drops per item (20 to 30 each) and check which features separate the classes.
- Try the sensor closer to the drop point, for example on the tray or beam, and compare with the chassis.
- Measure the noise with the servo attached and detached, and with the LEDs running.
- Connect the Pico to the CM4 software stack and run the full cycle: drop, footprint, photo, classify, light, move.
- Use the manual labels in the workbench to build the training dataset, and see whether the vibration really improves the classification.
Want to Follow the Complete Journey?
This is the sixth article in the Tiltie series. You can find all previous and future project updates in the Tiltie tag page:
See you in the next update!







