ADXL345 Raspberry pi4 multi SPI

Hi, sorry if I’m not in the right place but I didn’t know where to post.

I have installed on my bed stringer printer, 2 ADXL345.
1 for the X axis and 1 for the Y axis.
I want to connect them permanently by connecting them to a raspberry pi 4b.
So I connected the first one on SPI0 as indicated in the tutorial on resonnance.
I then activated the SPI1 with the command “dtoverlay=spi1-1cs”.
In klipper I modified the firmware to identify the adxl345:

[mcu rpi]
serial: /tmp/klipper_host_mcu

[adxl345 hotend]
cs_pin: rpi:None

[adxl345 bed]
cs_pin: rpi:gpio18
spi_bus: spidev1.0

accel_chip_x: adxl345 hotend
accel_chip_y: adxl345 bed
155,155,20 # an example

I can’t get the SPI1 to work.
Can you tell me what I need to enter in [adxl345 bed]?

Sorry for my english i translate with deepl :slight_smile:

Why 2?

One ADXL345 already does 3 axes:

because I have a tray that moves back and forth and I have a fixed mount, the adxl are screwed on the printer permanently

I see. That makes sense.

I tryed same config on rasp3 (2 differenti adxl345), but seems that only One adxl can work, or both understood few about :sweat_smile:

I was starting to look into doing this until I decided to use a Pi Pico so I could move it from machine to machine (just plugging into the USB of the host Pi).

I could be totally wrong as I haven’t done this yet, but as it was explained to me, Klipper determines which SPI bus to use based on which CS pin is specified. If that’s true, you need to specify the associated CS pin for each of them. If I understand correctly, you don’t want the spi_bus line with that config as it is for software SPI (and I assume you want hardware SPI since you’re not calling out each pin).
Unfortunately, it doesn’t look like GPIO18 is related to SPI0 or SPI1.
I’d recommend using GPIO8/SPI0_CS0 for SPI0 and GPIO16/SPI1_CS0 for SPI1.
Here’s the pinout I’m referencing:

I also saw this chart but I think the site where you found it is not up to date.
On the raspberry 4 the connections are different:

in yellow you find the spi0
in red the spi1

on the site of raspberry you can find the table assigning the gpio :

we can see the spi0 and spi1 assignments :

if I remember well, I tryed to add 2 adxl, with no succes, I retry in this week end…

if I chang from rpi: None to rpi:gpio8 this message appear… so…

Pin ‘GPIO8’ is not a valid pin name on mcu ‘rpi’

Once the underlying issue is corrected, use the “RESTART”
command to reload the config and restart the host software.
Printer is halted

same for:

Pin ‘spio_cs0’ is not a valid pin name on mcu ‘rpi’

Once the underlying issue is corrected, use the “RESTART”
command to reload the config and restart the host software.
Printer is halted

if I return to rpi:None, all works well, with only one adxl345, obviously!

On the rpi machines specifying a cs_pin causes confusion. Use cs_pin: rpi:None, as the Linux kernel spi device driver will automatically drive the CS pin associated with the given SPI device.

Also, I’ve found that if you did use a config that tried to manually alter the GPIO pin, it can put the machine in a confusing state. Remove any references to GPIO18 from the config and then perform a full hardware reboot of the rpi.

Finally, I’ve not tested using SPI1 on the rpi, so I can’t say if it will work or not.


if I understand what you are telling me, I should use only cs_pin: rpi:None.
If I do that, and send the command TEST_RESONANCES AXIS=Y
how would the rpi know if it should use the 1st or the 2nd adxl345?
this does not seem logical to me.
I will test anyway and I will come back to you with the answer.

I finally had some luck getting two ADXL345’s detected at once on a single Raspi. A Raspberry Pi 4B to be specific.

The issues seems to be that SPI0 and SPI1 are “special” and also kind of dumb on the Raspi. SPI 0 & 1 use a separate (legacy I think) controller versus 2-6 which were added to the latter Pi’s. SPI 0 & 1 can be enabled at the same time, but SPI 1 doesn’t support the necessary signaling mode that Klipper needs, so it fails if you try to use it.

SPI 0 works, but enabling it is a trap. If SPI 0 is enabled, SPI’s 2-6 don’t work properly. I’d originally tried combinations of SPI 0 & 1 (fails) as well as 0 & 5 (fails differently). 5 uses the same pins as 1, so that was convenient (no rewiring), but 5 fails if 0 is enabled.

I finally hooked my two ADXL345’s to SPI 5 and 6, and that works! It seems Klipper has a problem finding those though, so I also needed some symlinks to pretend they’re really 0 and 1. So all in, I have:




[mcu rpi]
serial: /tmp/klipper_host_mcu

[adxl345 hotend]
cs_pin: rpi:None
spi_bus: spidev0.0

[adxl345 bed]
cs_pin: rpi:None
spi_bus: spidev1.0

accel_chip_x: adxl345 hotend
accel_chip_y: adxl345 bed

And I had to create symlinks in /dev (re-created each time by klipper’s init script) so I have:

pi@octopi:~$ ls -l /dev/spidev*
lrwxrwxrwx 1 root root     14 Sep 14 06:55 /dev/spidev0.0 -> /dev/spidev5.0
lrwxrwxrwx 1 root root     14 Sep 14 06:55 /dev/spidev1.0 -> /dev/spidev6.0
crw------- 1 root root 153, 0 Jul 20 07:39 /dev/spidev5.0
crw------- 1 root root 153, 1 Jul 20 07:39 /dev/spidev6.0

If I just put 5 & 6 directly in printer.cfg, startup of the raspberry mcu device fails. I’m printing at the moment unfortunately, so I can’t reproduce that error.

With the symlinks, all is happy. I can run resonance tests on either probe without rewiring or changing any configuration.


Thanks. I updated the code to support spidev4.0 through spidev7.0 (commit 8cf1b512).


EDIT: Note that in order to use these new devices from Klipper, it will be necessary to update to the latest code and recompile/flash the linux mcu code.


I tested using 5 & 6 directly without the symlinks today. All good. Thank you!

Hi pendorbound, thanks for sharing! Could you please advice where to connect all the wires for both adxl345 on raspberry 4b? I’ve got a bit confused on where to get the power. Thanks a lot

You can grab power from the 3.3v lines on the Pi’s GPIO header. I had a circuit board made for mine. The exact wiring is going to depend on the ADXL345 boards you use. There are a couple of different ones out there with slightly different pins.

I wired mine to SPI 5 & 6 on the Pi. So that’s pin 39 for ground and 17 for 3.3v, shared to both ADXL boards. (There are two choices for 3.3 and several for ground. Any will work.) Then 8, 10, 32, & 33 for one ADXL and 12, 35, 38, and 40 for the other. Match up the signal names from the Pi header for the SPI & CS lines to the pinout on your ADXL345 boards.

1 Like

thanks, it’s a bit more clear now.
did you activate manually the spi3-6 of the raspberry in the config?

i have modified config.txt and printer.cfg as you marked, but i still get error:
“MCU ‘rpi’ shutdown: Unable to open spi device
Once the underlying issue is corrected, use the
“FIRMWARE_RESTART” command to reset the firmware, reload the
config, and restart the host software.
Printer is shutdown”

from terminal this:

pi@fluiddpi : ~ $ ls -l /dev/spidev*

lrwxrwxrwx 1 root root 14 Nov 7 21:10 /dev/spidev0.0/dev/spidev5.0

lrwxrwxrwx 1 root root 14 Nov 7 21:10 /dev/spidev1.0/dev/spidev6.0

crw-rw---- 1 root spi 153, 0 Nov 7 21:02 /dev/spidev5.0

crw-rw---- 1 root spi 153, 1 Nov 7 21:02 /dev/spidev6.0

any other step missing?