Skip to main content

Accelerometer Testing and Calibration

Dependency Package Installation

Notes
  • If the device is already running the FlyOS-FAST system, the required dependencies are pre-installed, and this step can be skipped.
  • If using a non-FLY host computer, please be sure to complete the following installation steps.
  • It is recommended to connect via SSH tools such as MobaXterm or PuTTY before proceeding.
  • This tutorial is based on the Raspberry Pi; other platforms are for reference only.

Installation Steps

  1. Execute the following commands in sequence to install the dependency packages.
  2. Installation time depends on CPU performance and network conditions, typically taking 10–20 minutes. Please wait patiently until the installation completes.
  3. If the device has insufficient memory (RAM), the installation may fail.

Step 1: Install system dependency packages

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

Step 2: Install Klipper virtual environment dependency packages

~/klippy-env/bin/pip install matplotlib numpy

Accelerometer Testing

Prerequisites

  • The printer has performed the Homing operation.
  • Ensure the accelerometer is correctly enabled in the Klipper configuration file.

Test Command

Enter the following command in the Klipper console:

ACCELEROMETER_QUERY

If multiple accelerometers are connected, you can specify the chip for testing:

ACCELEROMETER_QUERY CHIP=<ADXL chip name>

Replace <ADXL chip name> with the actual accelerometer identifier (e.g., adxl345).

Tip

Some older versions of Klipper require executing ACCELEROMETER_QUERY twice before accelerometer data can be retrieved.

Troubleshooting Common Issues

Power Off Required

Before inspecting, reconnecting, or replacing accelerometer wiring, completely shut down the printer and disconnect the power supply. Do not plug or unplug ADXL/LIS2DW/MPU/ICM modules or touch exposed pins while powered on.

  1. First execution fails: Some Klipper versions may have command recognition delays. If the first execution does not return data, execute the same command once more.
  2. Command not recognized: If repeated attempts still report an unknown command, the Klipper version may be too old. It is recommended to:
    • Update Klipper to the latest version
    • Or reflash the latest system image (e.g., the latest FlyOS-FAST version)
  3. Invalid adxl345 id: If the error Invalid adxl345 id (got xx vs e5) appears, first immediately re-run ACCELEROMETER_QUERY once; if the error persists, prioritize replacing the finished accelerometer cable, adapter board, or sensor module for cross-testing. It is not recommended for users to perform their own soldering or repair solder joints.
  4. Invalid lis2dw / mpu / icm id: If using sensors such as LIS2DW, MPU9250, or ICM20948, confirm that the configuration section name, communication bus, and chip model match the actual hardware.
  5. Unable to obtain response / timeout: This usually indicates a communication issue between the host computer and the accelerometer MCU. Check the USB/CAN connection, [mcu] ID, cs_pin, spi_bus, or i2c_bus.

BatchBulkHelper / spi_transfer_response

Error message: The following appears when executing ACCELEROMETER_QUERY, TEST_RESONANCES, or SHAPER_CALIBRATE:

BatchBulkHelper start callback error
BatchBulkHelper stop callback error
Unable to obtain 'spi_transfer_response' response

Nature of the error: spi_transfer_response indicates that Klipper did not receive a response to the SPI request, but it may not be the root cause. In recent log cases, the MCU first entered shutdown due to Timer too close, and only then did the ADXL bulk collection report the inability to obtain an SPI response. In this case, address the earlier shutdown first rather than directly concluding the accelerometer is faulty.

Troubleshooting steps:

  1. In the full klippy.log, find the first BatchBulkHelper, then search upward for earlier occurrences of Timer too close, Lost communication with MCU, MCU shutdown, or Serial connection closed.
  2. If an earlier shutdown exists, first resolve the root cause according to System and Timeout Errors; the subsequent spi_transfer_response error will typically disappear once the connection is restored.
  3. If there is no earlier shutdown and executing ACCELEROMETER_QUERY immediately reports an error every time, verify the accelerometer's [mcu], cs_pin, spi_bus, and chip type.
Power Off Required

Before reconnecting or replacing the accelerometer wiring, adapter board, or module, completely shut down the printer and disconnect the power supply. Do not plug or unplug SPI/I2C wiring or touch exposed pins while powered on.

  1. After powering off, replace the finished cable, adapter board, or sensor module for cross-testing; do not let regular users perform their own soldering or fly-wiring.
  2. If the error only occurs at the beginning or end of a resonance test, temporarily disable the camera, display, and other high-load services, then retest, and retain the full logs for further analysis.

Result Evaluation

  • Normal output: If a continuous data stream is returned (as shown in the figure below), the accelerometer is working correctly and resonance compensation measurement can proceed.
  • Error output: If a timeout, no data, or communication error is reported, check the following in order:
    1. Power off and confirm the accelerometer wiring is secure
    2. Verify the sensor configuration and SPI settings in the configuration file
    3. Prioritize replacing the finished cable, adapter board, or sensor module to diagnose power/communication issues
Loading...

Common Resonance Test Errors

Error MessageCommon CauseResolution
No data received from accelerometerAccelerometer not connected, SPI/I2C wiring order incorrect, power supply anomalyFirst execute ACCELEROMETER_QUERY to confirm communication is normal, then retest
Insufficient axis data for shaper calibrationMovement range too small, acceleration too low, sensor reading noise too highIncrease the test range or accel_per_hz, check that the accelerometer is firmly mounted
Frequency range too narrowBelt too loose, machine mechanical resonance frequency outside the measurement rangeCheck belt tension and mechanical structure tightness; lower max_freq or increase accel_per_hz if necessary
Resonance graph is all noise with no obvious peaksSensor not firmly mounted, fan vibration interference, wiring harness movementPower off, re-secure the sensor, turn off fans during testing, route signal wires separately from motor wires
SHAPER_CALIBRATE produces no output or exits with an errorMissing Python dependencies (numpy/matplotlib), insufficient memoryInstall dependencies as described at the beginning of this article; large resonance graph calculations may require more memory
Cannot test Z axis together with other axesTEST_RESONANCES specifies the Z axis along with X/Y axesThe Z axis must be tested separately and not mixed with X/Y
Invalid POINT parameterPOINT= coordinate format is incorrect, or missing one of the three x,y,z valuesFill in the format like POINT=100,100,20
Invalid NAME parameterOutput name is empty, contains special characters, or does not match command requirementsUse English letters, numbers, underscores, or hyphens for naming
No accelerometer measurements foundNo valid accelerometer data was collected during the testFirst execute ACCELEROMETER_QUERY, then check sensor mounting and communication
Unsupported outputThe OUTPUT= parameter is set to an unsupported typeFill in a Klipper-supported output type; resonances is commonly used

If ACCELEROMETER_QUERY works normally but the resonance test consistently fails, prioritize troubleshooting in the following order:

  1. Power off and confirm the accelerometer surface is tightly attached to the tested component without loose cushioning material or double-sided tape.
  2. Temporarily turn off the model cooling fan, hotend fan, and chamber fan during testing.
  3. Ensure no wiring is pulling on the sensor or being caught by moving axes during the test.
  4. Increase the test amplitude: in [resonance_tester], gradually raise accel_per_hz from the default 75 to 100–150.
  5. If using an accelerometer on a tool board (USB/CAN), confirm the communication wires are not routed near motor wires or the heated bed wires.

Accelerometer Orientation Configuration

The mounting orientation of the accelerometer affects resonance measurement results. If the axes_map configuration does not match the actual mounting orientation, TEST_RESONANCES or SHAPER_CALIBRATE will produce incorrect frequency responses, rendering Input Shaper compensation ineffective.

What is axes_map

axes_map is used to map the accelerometer's own axes to the printer's X/Y/Z coordinates. Different toolboards, print head housings, or accelerometer modules may have different mounting orientations, so this must be configured according to the actual mounting method.

If axes_map is not filled in, Klipper defaults to x,y,z, meaning the accelerometer's X/Y/Z directly correspond to the printer's X/Y/Z.

[adxl345]
cs_pin: toolboard:PB12
spi_bus: spi1
axes_map: x,y,z # Adjust according to actual mounting orientation

axes_map supports swapping axis order and negation (prefixing the axis with -):

Mounting SituationExample Configuration
Accelerometer X/Y align with the printeraxes_map: x,y,z
Accelerometer rotated 90°, X/Y swappedaxes_map: y,x,z
Accelerometer flipped, Z axis reversedaxes_map: x,y,-z
Accelerometer side-mounted, Y/Z swappedaxes_map: x,z,y
Note

Accelerometer configuration sections such as [adxl345], [lis2dw], [mpu9250], [bmi160], [icm20948], etc., all use the same axes_map rules.

Preliminary Orientation Check via ACCELEROMETER_QUERY

At rest, the accelerometer will detect approximately 1g of gravitational acceleration. By observing which axis shows close to ±1g, you can roughly determine the accelerometer's orientation:

  1. Execute ACCELEROMETER_QUERY and record the readings for each axis.
  2. Tilt the printer (or accelerometer) along the X, Y, and Z directions respectively, and observe which axis shows the greatest reading change.
  3. If the accelerometer's Y axis reading changes the most when tilting the printer along the X direction, the X/Y mapping needs to be swapped.
  4. If the reading on an axis has an inverted sign (e.g., negative reading when tilted in the positive direction), add a - prefix before that axis.

Orientation Verification via Shake&Tune

Prerequisite

The following method requires the Klippain Shake&Tune plugin to be installed. FlyOS-Fast v1.3.5 and above have it pre-installed.

The spectrograms generated by Shake&Tune can visually verify whether axes_map is correct:

  1. Run the resonance tests for the X and Y axes separately:

    TEST_RESONANCES AXIS=X
    TEST_RESONANCES AXIS=Y
  2. Examine the generated spectrograms:

    • Correct orientation: The spectrogram from the X axis test should show a clear resonance peak in the X direction, and the Y axis test should show a clear resonance peak in the Y direction, typically at different frequencies.
    • Incorrect orientation: If the spectrograms from the X and Y axis tests are nearly identical, or the resonance peak positions are unusually close, the axes_map may need adjustment.
  3. After modifying axes_map, execute RESTART, then rerun the tests to compare the results.

Caution

An incorrect axes_map configuration will not cause communication errors, and ACCELEROMETER_QUERY will still return data normally. Only the resonance measurement results will be abnormal, making this issue easy to overlook.

Detailed axes_map troubleshooting: Refer to the axes_map section in the resonance compensation and pressure advance configuration issues

Accelerometer Calibration

Use Shake&Tune for more detailed analysis

If the Klippain Shake&Tune plugin is installed on the system, the TEST_RESONANCES command will automatically generate spectrum charts and belt comparison graphs, providing more intuitive visual analysis than the built-in SHAPER_CALIBRATE. This plugin is pre-installed in FlyOS-Fast v1.3.5 and above.

Calibration Steps

  1. Ensure the printer is homing.

  2. Enter the following command in the console to start automatic calibration of the X and Y axes:

    SHAPER_CALIBRATE
  3. After calibration is complete, save the configuration:

    SAVE_CONFIG

Single-Axis Calibration

If only a single axis needs to be calibrated, use:

SHAPER_CALIBRATE AXIS=X

Or replace X with Y.

Safety Notice

During calibration, the printer may produce intense vibrations. If the vibration is excessive, press the emergency stop button immediately or send the M112 command for an emergency stop.

Adjusting Vibration Intensity

If the vibration is too strong during testing, appropriately reduce the accel_per_hz parameter value (default 75):

[resonance_tester]
accel_per_hz: 50

Configuration and Tuning Issues: For problems such as normal accelerometer hardware but poor results after enabling resonance compensation, improper shaper_freq settings, or conflicts between Pressure Advance and Input Shaper, please refer to Resonance Compensation and Pressure Advance Configuration Issues.

Note: The above steps apply to most resonance compensation configurations for Klipper-based 3D printers. Please adjust according to the actual hardware and system environment.

Loading...