Skip to content

Add ADXL355 accelerometer support over SPI#7215

Open
entemomoh2 wants to merge 8 commits intoKlipper3d:masterfrom
entemomoh2:feature/adxl355-upstream
Open

Add ADXL355 accelerometer support over SPI#7215
entemomoh2 wants to merge 8 commits intoKlipper3d:masterfrom
entemomoh2:feature/adxl355-upstream

Conversation

@entemomoh2
Copy link

Summary

This PR adds ADXL355 accelerometer support over SPI for Klipper resonance measurement and input shaper workflows.

It includes:

  • MCU-side ADXL355 bulk sampling support
  • Host-side [adxl355] module with standard ACCELEROMETER_* commands
  • Documentation updates for config, G-codes, API endpoint, and resonance guide
  • A compatibility fix for boards where POWER_CTL.STANDBY reads back as 0

What’s Included

  1. MCU support
    Added src/sensor_adxl355.c
    Added MCU commands:
    config_adxl355
    query_adxl355
    query_adxl355_status
    Wired build/config:
    src/Makefile: CONFIG_WANT_ADXL355
    src/Kconfig: new WANT_ADXL355 option and NEED_SENSOR_BULK dependency update
  2. Host module
    Added klippy/extras/adxl355.py
    Uses bulk_sensor.FixedFreqReader + BatchBulkHelper pattern
    Supports:
    ACCELEROMETER_QUERY
    ACCELEROMETER_MEASURE
    ACCELEROMETER_DEBUG_READ
    ACCELEROMETER_DEBUG_WRITE
    Supports axes_map and ADXL355 ODR rate values
    Validates device IDs (DEVID_AD, DEVID_MST, PARTID)
  3. Robustness fix
    Handles ADXL355 variants that always read POWER_CTL.STANDBY back as 0
    Keeps strict register write verification for all other cases
  4. Documentation
    Updated:
  • docs/Config_Reference.md
  • docs/G-Codes.md
  • docs/API_Server.md
  • docs/Measuring_Resonances.md
    Validation

Test environment:

OctoPi / Raspberry Pi host MCU ([mcu rpi])
ADXL355 connected via SPI (spidev0.0)

Build/runtime checks performed:

make -j4 successful (including sensor_adxl355.c)
Host module import/compile sanity check successful
RPi host MCU updated and restarted with ADXL355 commands present
Command checks:
ACCELEROMETER_DEBUG_READ CHIP=adxl355 REG=0x00 -> 0xad
ACCELEROMETER_DEBUG_READ CHIP=adxl355 REG=0x01 -> 0x1d
ACCELEROMETER_DEBUG_READ CHIP=adxl355 REG=0x02 -> 0xed
ACCELEROMETER_QUERY CHIP=adxl355 returns live XYZ values
ACCELEROMETER_MEASURE start/stop generates CSV data (/tmp/adxl355-smoketest.csv)

Notes

This series follows existing accelerometer bulk-sensor architecture and command conventions.
The standby readback quirk handling is intentionally narrow (only REG_POWER_CTL, only standby-bit mismatch) to avoid weakening register verification behavior.

Please let me know if there are any issues/bugs right away. This is my first PR but I hope it's useful and done right :)
Heads-up: I created the initial driver as a derivative of adxl345 because I only had a 355 on hand and finished proper integration using AI. I tested the features on my Ender 2 Pro and validated everything there.

@entemomoh2
Copy link
Author

Added follow-up fixes:

  • f0324e2: wrap ADXL355 lines to satisfy whitespace check
  • 0b77e4f: disable ADXL355 in stm32f042 size-limited test config to avoid ROM overflow

@KevinOConnor
Copy link
Collaborator

Thanks. In general it seems useful. I have some questions/comments:

  • The copyrights in the Python and C code need to contain a full real name and email address. Please see the format of the existing files. It is not necessary to include my copyright on these new files.
  • Please don't change various locations in the documentation that say "adxl345" to say something like "adxl345 or adxl355". This would be the sixth accelerometer supported, and as you can imagine the documentation will just get unwieldy if every sentence tries to list every permutation. If you wish, feel free to submit a separate PR (or separate commit in this PR) that changes various references from "adxl345" to "accelerometer" (or something similarly generic).
  • Please clearly identify in your comments here if this code was written by AI.
  • It looks like you've used the sensor_adxl345.c method of querying for each measurement. That mechanism isn't a great template as it is heavily dependent on quirks of the adxl345. I think you want to look at sensor_lis2dw.c (or sensor_mpu9250.c) as alternatives. Basically you want to read the fifo_samples register and when you have enough data to completely fill a bulk_status message (ie, 45 bytes / 15 fifo entries / 5 full samples) you want to do a single read of all that data from the fifo register.
  • It would be nice to add the new accelerometer to scripts/motan/data_logger.py.

@dmbutyugin - fyi.

Cheers,
-Kevin

@entemomoh2
Copy link
Author

entemomoh2 commented Mar 5, 2026

Hi @KevinOConnor, thanks for reviewing!

I changed the documentation to reduce redundancies while keeping examples where I deemed necessary and changed the copyright statements. If you want me to, I can condense it even more.
Regarding AI, I wrote the original 355 python file while I used Codex 5.3 to generate the c file and update the documentation.
furthermore, I added the adxl355 to data_logger and adjusted the c file and succesfully tested data acquisition on my Ender2Pro :)

Best regards
Sven

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants