Accelerometer Testing and Calibration
Dependency Package Installation
- 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
- Execute the following commands in sequence to install the dependency packages.
- Installation time depends on CPU performance and network conditions, typically taking 10–20 minutes. Please wait patiently until the installation completes.
- 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).
Some older versions of Klipper require executing ACCELEROMETER_QUERY twice before accelerometer data can be retrieved.
Troubleshooting Common Issues
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.
- 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.
- 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)
- Invalid adxl345 id: If the error
Invalid adxl345 id (got xx vs e5)appears, first immediately re-runACCELEROMETER_QUERYonce; 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. - 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.
- 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, ori2c_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:
- In the full
klippy.log, find the firstBatchBulkHelper, then search upward for earlier occurrences ofTimer too close,Lost communication with MCU,MCU shutdown, orSerial connection closed. - If an earlier shutdown exists, first resolve the root cause according to System and Timeout Errors; the subsequent
spi_transfer_responseerror will typically disappear once the connection is restored. - If there is no earlier shutdown and executing
ACCELEROMETER_QUERYimmediately reports an error every time, verify the accelerometer's[mcu],cs_pin,spi_bus, and chip type.
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.
- 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.
- 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:
- Power off and confirm the accelerometer wiring is secure
- Verify the sensor configuration and SPI settings in the configuration file
- Prioritize replacing the finished cable, adapter board, or sensor module to diagnose power/communication issues
Common Resonance Test Errors
| Error Message | Common Cause | Resolution |
|---|---|---|
No data received from accelerometer | Accelerometer not connected, SPI/I2C wiring order incorrect, power supply anomaly | First execute ACCELEROMETER_QUERY to confirm communication is normal, then retest |
Insufficient axis data for shaper calibration | Movement range too small, acceleration too low, sensor reading noise too high | Increase the test range or accel_per_hz, check that the accelerometer is firmly mounted |
Frequency range too narrow | Belt too loose, machine mechanical resonance frequency outside the measurement range | Check belt tension and mechanical structure tightness; lower max_freq or increase accel_per_hz if necessary |
| Resonance graph is all noise with no obvious peaks | Sensor not firmly mounted, fan vibration interference, wiring harness movement | Power 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 error | Missing Python dependencies (numpy/matplotlib), insufficient memory | Install dependencies as described at the beginning of this article; large resonance graph calculations may require more memory |
Cannot test Z axis together with other axes | TEST_RESONANCES specifies the Z axis along with X/Y axes | The Z axis must be tested separately and not mixed with X/Y |
Invalid POINT parameter | POINT= coordinate format is incorrect, or missing one of the three x,y,z values | Fill in the format like POINT=100,100,20 |
Invalid NAME parameter | Output name is empty, contains special characters, or does not match command requirements | Use English letters, numbers, underscores, or hyphens for naming |
No accelerometer measurements found | No valid accelerometer data was collected during the test | First execute ACCELEROMETER_QUERY, then check sensor mounting and communication |
Unsupported output | The OUTPUT= parameter is set to an unsupported type | Fill 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:
- Power off and confirm the accelerometer surface is tightly attached to the tested component without loose cushioning material or double-sided tape.
- Temporarily turn off the model cooling fan, hotend fan, and chamber fan during testing.
- Ensure no wiring is pulling on the sensor or being caught by moving axes during the test.
- Increase the test amplitude: in
[resonance_tester], gradually raiseaccel_per_hzfrom the default75to100–150. - 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 Situation | Example Configuration |
|---|---|
| Accelerometer X/Y align with the printer | axes_map: x,y,z |
| Accelerometer rotated 90°, X/Y swapped | axes_map: y,x,z |
| Accelerometer flipped, Z axis reversed | axes_map: x,y,-z |
| Accelerometer side-mounted, Y/Z swapped | axes_map: x,z,y |
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:
- Execute
ACCELEROMETER_QUERYand record the readings for each axis. - Tilt the printer (or accelerometer) along the X, Y, and Z directions respectively, and observe which axis shows the greatest reading change.
- 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.
- 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
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:
-
Run the resonance tests for the X and Y axes separately:
TEST_RESONANCES AXIS=XTEST_RESONANCES AXIS=Y -
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_mapmay need adjustment.
-
After modifying
axes_map, executeRESTART, then rerun the tests to compare the results.
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
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
-
Ensure the printer is homing.
-
Enter the following command in the console to start automatic calibration of the X and Y axes:
SHAPER_CALIBRATE -
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.
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_freqsettings, 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.