KlipperLab
Isometric 3D printer with a blue ADXL345 accelerometer on the toolhead, cabled to a small controller board, with vibration arcs near the nozzle.
tuning

Klipper Input Shaper Setup: Wiring and Tuning an ADXL345

Wire and configure an ADXL345 for Klipper input shaping, run resonance calibration, and troubleshoot sensor or host MCU connection errors.

By KlipperLab Editorial · ·Updated · 8 min read

To set up Klipper input shaping with an ADXL345 connected directly to a Raspberry Pi, wire the sensor over SPI, configure Klipper, verify the sensor, then run and save a resonance calibration. Follow these steps from Klipper’s Measuring Resonances and Raspberry Pi as a Secondary MCU guides.

  1. Install the host packages, then install NumPy in Klipper’s Python environment at ~/klippy-env.
  2. Wire the ADXL345 to the Raspberry Pi’s SPI pins and enable SPI plus the host MCU.
  3. Add the [mcu rpi], [adxl345] and [resonance_tester] blocks to printer.cfg.
  4. Check the sensor with ACCELEROMETER_QUERY and MEASURE_AXES_NOISE.
  5. Run SHAPER_CALIBRATE if your setup can measure both axes in one run. On a bed slinger with one sensor, follow the separate X and Y runs under Measure and Calibrate, moving the sensor from the toolhead to the bed between runs. Review the recommendations after each run and use SAVE_CONFIG if you want to keep the settings. Set max_accel separately.

The steps were checked against Klipper’s online documentation and the master branch of klippy/configfile.py. The steps were not run for this article.

Before You Wire Anything

Klipper’s Resonance Compensation guide says ringing “usually has mechanical origins” and that those causes “should be checked and fixed first, if possible.” Loose belts, a binding or bumpy axis, running toolhead fans and a nonrigid accelerometer mount can all make resonance measurements unreliable. Measuring Resonances

If you use pressure advance, the Resonance Compensation guide says it “may need to be re-tuned” after input shaping is set. See the pressure advance calibration guide.

For the host’s role in motion planning and configuration, see how Klipper works. If you have not chosen an accelerometer or a place to plug it in yet, Klipper hardware requirements covers the options.

Host Prerequisites

Start with the system packages in the software installation section. Measuring Resonances

sudo apt update
sudo apt install python3-numpy python3-matplotlib libatlas-base-dev libopenblas-dev

Then install NumPy in Klipper’s own Python environment, ~/klippy-env, and check that it imports:

~/klippy-env/bin/pip install -v "numpy<1.26"
~/klippy-env/bin/python -c 'import numpy;'

Depending on CPU performance, the NumPy install can take up to 10–20 minutes. On some boards with too little RAM, installation may fail and require swap. A successful import check returns to the shell without an error.

Wiring

Use SPI for the ADXL345. The chip’s I2C connection is too slow for Klipper’s resonance measurements. The pin assignments below follow Measuring Resonances.

ADXL345 pinRPi pinRPi pin name
3V3 (or VCC)013.3V DC power
GND06Ground
CS24GPIO08 (SPI0_CE0_N)
SDO21GPIO09 (SPI0_MISO)
SDA19GPIO10 (SPI0_MOSI)
SCL23GPIO11 (SPI0_SCLK)

Voltage. Use the Pi’s 3.3 V supply for the ADXL345 and double-check the wiring before powering up. For a 5 V printer MCU, use an ADXL345 breakout with a voltage regulator and level shifters.

Mounting. Attach the sensor rigidly to the moving part being measured. Electrically isolate the accelerometer and its mounting screws from the printer’s metal parts. On a bed slinger, prepare a toolhead mount for X and a bed mount for Y.

Raspberry Pi Pico over USB

The Pico can connect over USB to the Raspberry Pi running Klipper. Wire the ADXL345’s 3V3 to pin 36, GND to pin 38, CS to pin 2 (GP1), SDO to pin 1 (GP0), SDA to pin 5 (GP3) and SCL to pin 4 (GP2).

Set the Pico firmware options in make menuconfig as shown under Flash the Pico Firmware. Hold BOOTSEL while connecting the Pico over USB, flash with make flash FLASH_DEVICE=first, then find its serial path with ls /dev/serial/by-id/*. Use the guide’s Pico configuration, which sets [mcu adxl], cs_pin: adxl:gpio1 and spi_bus: spi0a. Measuring Resonances

Enable SPI and the Host MCU

A sensor on the Pi’s own pins needs the Pi to run as a second Klipper microcontroller. The Raspberry Pi as a Secondary MCU guide gives these steps.

Enable SPI with sudo raspi-config, under the “Interfacing options” menu. Then install the host MCU service:

cd ~/klipper/
sudo cp ./scripts/klipper-mcu.service /etc/systemd/system/
sudo systemctl enable klipper-mcu.service

Configure the host MCU code first.

cd ~/klipper/
make menuconfig

Set “Microcontroller Architecture” to “Linux process”, then save and exit. Build and install the host MCU code before starting Klipper again.

sudo service klipper stop
make flash
sudo service klipper start

If klippy.log reports a “Permission denied” error on /tmp/klipper_host_mcu, the guide’s fix is to add the user to the tty group. Its command for the pi user is shown below.

sudo usermod -a -G tty pi

Configuration

With the sensor on the host’s SPI bus, the Measuring Resonances guide gives this printer.cfg block:

[mcu rpi]
serial: /tmp/klipper_host_mcu

[adxl345]
cs_pin: rpi:None

[resonance_tester]
accel_chip: adxl345
probe_points:
    100, 100, 20  # an example

Start with one probe point slightly above the middle of your own print bed.

The Configuration Reference lists the defaults you can leave alone. For [adxl345], rate defaults to 3200 and spi_speed to 5000000. For [resonance_tester], min_freq defaults to 5 Hz and max_freq to 135 Hz.

Bed slinger setup

With one ADXL345, measure X with the sensor on the toolhead and move it to the bed to measure Y. With two ADXL345s, use separate SPI interfaces or separate boards. The Measuring Resonances example puts the toolhead sensor on the Pi and the bed sensor on the printer board.

For two sensors, replace the [adxl345] and [resonance_tester] sections above with the sections below. Fill in the printer board’s chip-select pin and your probe point.

[adxl345 hotend] # Assuming `hotend` chip is connected to an RPi
cs_pin: rpi:None

[adxl345 bed] # Assuming `bed` chip is connected to a printer MCU board
cs_pin: ...  # Printer board SPI chip select (CS) pin

[resonance_tester] # Assuming the typical setup of the bed slinger printer
accel_chip_x: adxl345 hotend
accel_chip_y: adxl345 bed
probe_points: ...

After saving the configuration, run RESTART in the Klipper console.

Verify the Sensor Answers

Run these two commands in order in the OctoPrint terminal.

ACCELEROMETER_QUERY
MEASURE_AXES_NOISE

The query should return axis readings that include gravity. If you installed two sensors with the configuration above, replace the first command with ACCELEROMETER_QUERY CHIP=hotend and ACCELEROMETER_QUERY CHIP=bed. G-Codes

MEASURE_AXES_NOISE reports noise on every axis. The Measuring Resonances guide gives roughly 1–100 as a typical range. High readings, such as 1000 or more, can point to a sensor problem, a power problem or a noisy imbalanced fan.

Measure and Calibrate

Use G28 to move the printer to its origin. Watch the first run closely and use M112 for an emergency stop. If the vibration is too strong, try reducing accel_per_hz in [resonance_tester] before retrying. G-Codes · Measuring Resonances

For manual measurement, run the X test first.

TEST_RESONANCES AXIS=X

If X completes safely, continue to Y. If your bed slinger uses one sensor, move it from the toolhead to the bed before running Y.

TEST_RESONANCES AXIS=Y

The tests write /tmp/resonances_x_*.csv and /tmp/resonances_y_*.csv. To plot a single run, use one CSV file per axis. The script averages multiple matching files. Plot both axes with these commands.

~/klipper/scripts/calibrate_shaper.py /tmp/resonances_x_*.csv -o /tmp/shaper_calibrate_x.png
~/klipper/scripts/calibrate_shaper.py /tmp/resonances_y_*.csv -o /tmp/shaper_calibrate_y.png

The script prints a fitted frequency, estimated vibration and smoothing, and a suggested max_accel for each shaper. In the guide’s example, the recommended shaper is MZV at 34.6 Hz, with a suggested acceleration limit of 3500 mm/s².

For automatic calibration on a fixed-bed printer or a bed slinger with two configured sensors, run the following command to measure both axes.

SHAPER_CALIBRATE

Review the recommended shaper type and frequency for each axis, then save the settings if you agree with them.

SAVE_CONFIG

According to the Measuring Resonances guide, SHAPER_CALIBRATE writes its data to /tmp/calibration_data_*.csv by default.

With one sensor on a bed slinger, run SHAPER_CALIBRATE AXIS=X with the sensor on the toolhead. To keep the suggested settings, use SAVE_CONFIG to save and restart. Move the sensor to the bed and repeat the procedure with SHAPER_CALIBRATE AXIS=Y.

Limit smoothing

If the recommended shaper smooths too much, the guide shows --max_smoothing=0.2 added to the script command:

~/klipper/scripts/calibrate_shaper.py /tmp/resonances_x_*.csv -o /tmp/shaper_calibrate_x.png --max_smoothing=0.2

Smaller scores indicate less projected smoothing. SHAPER_CALIBRATE uses the max_smoothing: limit in [resonance_tester] when MAX_SMOOTHING is omitted. Pass MAX_SMOOTHING=<max_smoothing> to override the configured limit for that run. G-Codes

How SAVE_CONFIG stores the result

The G-Codes reference says SAVE_CONFIG “will overwrite the main printer config file and restart the host software.” The values go in an autosave block at the end of printer.cfg.

Klipper’s configfile.py comments out autosave duplicates of settings in the regular config at load time, so the regular config wins. If an included file already defines the same section and option that SAVE_CONFIG is saving, the command stops and reports the conflict.

Read the Shaper Result

For manual configuration, copy the recommended type and frequency for each axis into [input_shaper]. The example from Measuring Resonances shows a Y result and leaves X for your own measurement.

[input_shaper]
shaper_freq_x: ...
shaper_type_x: ...
shaper_freq_y: 34.6
shaper_type_y: mzv

Shapers trade vibration suppression against smoothing. The Resonance Compensation guide gives these approximate frequency-error ranges for default shaper parameters and damping ratios around Klipper’s default.

ShaperTolerated frequency error (at the 20x vibration reduction level)
MZV±4% of shaper_freq
EI±20% of shaper_freq
2HUMP_EI−40% to +45% of shaper_freq

The same guide warns that “At very low ringing frequencies (~25 Hz and below) even MZV shaper may create too much smoothing.” At very low resonance frequencies, smoothing can limit acceleration and print speed.

Set max_accel

SAVE_CONFIG saves the shaper settings. Set max_accel manually in [printer], at or below the lower of the X and Y estimates. Measuring Resonances

Consider leaving a safety margin below the script’s theoretical acceleration limits. The script assumes a square_corner_velocity of 5.0 by default. If yours differs, pass --square_corner_velocity=... to the script. To see how shaper choice and measured frequency affect acceleration, use the input shaper and acceleration sizer.

The guide also notes that smoothing scores only compare configurations, so print test parts to see real smoothing.

Troubleshooting

SymptomLikely causeWhat to do
Invalid adxl345 id (got xx vs e5) on ACCELEROMETER_QUERYSPI initialization issue. A persistent error can indicate a connection problem or faulty sensor.Retry immediately. If the error persists, check power, wiring and soldering (per Measuring Resonances)
“Permission denied” on /tmp/klipper_host_mcu in klippy.logThe account running Klipper lacks tty group membershipAdd that account to the tty group. If Klipper runs as pi, use sudo usermod -a -G tty pi (per RPi_microcontroller)
High noise in MEASURE_AXES_NOISE, for example 1000 or morePossible sensor issues, power problems or noisy imbalanced fans (per Measuring Resonances)Turn fans off for resonance testing
Unreliable resonance measurementsNonrigid mount, loose belts, a binding or bumpy axis, or running toolhead fans (per Measuring Resonances)Mount the sensor rigidly on the moving part, disable fans during testing and inspect the moving axis for faults
An autosaved setting has no effectThe same section and option is already defined in the regular configuration (per configfile.py)Check the active [input_shaper] settings in printer.cfg and its included files
SAVE_CONFIG reports a conflict with an included valueAn included file already defines the same section and option that SAVE_CONFIG tries to store (per configfile.py)The error names the section and option to look for in your included files

When to Measure Again

The Measuring Resonances guide suggests repeating SHAPER_CALIBRATE after changes that can affect the printer’s motion. Avoid daily calibration or running it before every print. Frequent calibration can increase wear and the risk of loose parts. Check that everything is secured after each calibration.

If you are still weighing whether this workflow justifies running Klipper at all, see Klipper vs Marlin.

Sources

  1. Klipper: Measuring Resonances
  2. Klipper: Resonance Compensation
  3. Klipper: Raspberry Pi as a Secondary MCU
  4. Klipper: G-Codes
  5. Klipper: Configuration Reference
  6. Klipper source: klippy/configfile.py

Related