The Raspberry Pi (RPi) Pico offers a convenient and cost efficient way to create a portable resonance measurement device that can be used across different Klipper printers.
ADXL345/343 boards
There are different ADXL345 boards on the market and also the ADXL343 board is a valid alternative.
Depending on the board layout and used components a few things should be considered when connecting the board.
General
The boards can be mainly distinguished by potentially having a Voltage Regulator or a Level Shifter.
Voltage Regulator
- The Voltage Regulator allows the board to be connected to either 3.3V or to 5V
- The ADXL chip itself requires 3.3V. The voltage regulator ensures that only 3.3V actually reach the chip
- In the following images, a Voltage Regulator is marked with a green rectangle
WARNING: Boards without such a Voltage Regulator must not be connected to 5V or the board will be destroyed
Level Shifter
- Digital electronics, like MCUs (aka printer boards) or RPis require a certain voltage on their pins
- Typical voltages in 3D printing are either 3.3V (most common) or 5V
- A Level Shifter allows to translate between 3.3V and 5V or vice versa
- The ADXL family is in the 3.3V domain by default. This means that it outputs only 3.3V even when connected to 5V (see voltage regulator).
- A Level Shifter changes this: When the ADXL is connected to 5V (see Voltage Regulator) it will also output 5V on the board’s connecting pins
- In the following images, a Level Shifter is marked with a yellow rectangle
WARNING: RPIs and many MCU boards are designed for 3.3V only. A board with Level Shifter must not be connected to 5V and to a partner tolerant only to 3.3V. This will destroy the partner.
I2C Boards
- Most boards use the SPI as communication bus. SPI is fast enough to deliver up to 3200 samples/s, as it is needed for resonance measurement
- Some boards seem to be forced into I2C mode (another bus type) with a pull-down resistor
- Such boards do not work for resonance measurement but can potentially be reworked by removing the pull-down resistor
- Refer to ADXL345 Invalid ID · Issue #3637 · Klipper3d/klipper · GitHub with special thanks to @JanKolibri
WARNING: Avoid such boards, if you do not feel comfortable with soldering on such a board.
ADXL345 with Voltage Regulator and Level Shifter
ADXL345 with Voltage Regulator
ADXL345 without Voltage Regulator
ADXL343 with Voltage Regulator and Level Shifter
ADXL345 with Voltage Regulator and forced to I2C
Wiring
ADXL345 pin | RPi Pico pin | RPi Pico pin name |
---|---|---|
VIN (or VCC) | 36 | 3V3 Out |
GND | 38 | GND |
CS | 2 | SPI0 CSn (GP 1) |
SDO | 1 | SPI0 RX (GP 0) |
SDA | 5 | SPI0 TX (GP 3) |
SCL | 4 | SPI0 SCK (GP 2) |
Compiling & flashing the firmware for the Pico
Compile the firmware
cd ~/klipper/
make menuconfig
make
Flash the firmware
- Conncect the Pico to the regular Klipper Raspberry Pi (or other SBC) USB port, while holding down the
BOOTSEL
button - Given no other mass storage devices are existing, the Pico should register as block device
/dev/sda
- Mount the block device and copy the Klipper firmware file to it
sudo mount /dev/sda1 /mnt
sudo cp out/klipper.uf2 /mnt
sudo umount /mnt
- After un-mounting, the Pico should automatically reboot with the new firmware
Configuring Klipper
- Get the correct
serial
path withls /dev/serial/by-id/*
- Add the following to the
printer.cfg
file:
[mcu pico]
serial: /dev/serial/by-id/usb-Klipper_rp2040_mySerial
[adxl345]
spi_bus: spi0a
cs_pin: pico:gpio1
[resonance_tester]
accel_chip: adxl345
probe_points:
100,100,20 # an example
- Restart Klipper with the
RESTART
command.
Important: The first measurement, after freshly connecting the RPi Pico or restarting Klipper, will fail. This is due to some issues with the SPI initialization. Subsequent measurements will work.
Available SPI buses on the RPi Pico
It is possible to connect multiple ADXL boards to one RPi Pico:
ADXL345 pin | RPi Pico pin name | spi0a | spi0b | spi0c | spi1a | spi1b |
---|---|---|---|---|---|---|
VIN (or VCC) | 3V3 Out | 36 | 36 | 36 | 36 | 36 |
GND | GND | 38 | 38 | 38 | 38 | 38 |
CS | CSn | 2 (GP1) | 7 (GP5) | 22 (GP17) | 12 (GP9) | 17 (GP13) |
SDO | SPI RX | 1 (GP0) | 6 (GP4) | 21 (GP16) | 11 (GP8) | 16 (GP12) |
SDA | SPI TX | 5 (GP3) | 10 (GP7) | 25 (GP19) | 15 (GP11) | 20 (GP15) |
SCL | SPI SCK | 4 (GP2) | 9 (GP6) | 24 (GP18) | 14 (GP10) | 19 (GP14) |
Notes:
- Header is the name of the bus, values given as
pin-number (GPIO number)
- Pin definition is based on klipper/spi.c at 02d5f9754fc7f9e493c8bc5a6418e2a9ea9d7ae1 · Klipper3d/klipper · GitHub
- I left out the buses
spi0d
andspi1c
as I could not match them to the Pico Pin-Out diagram. So theoretically, there may be even 2 more buses - Untested. Any feedback is appreciated