Beaglebone Black + SPI + GY-291 ADXL345

Basic Information:

Printer Model: Rostock custom Delta
MCU / Printerboard: Beaglebone Black + CRAMPS
Host / SBC: Beaglebone black

BeagleBone Black is a very capable hardware system which contains:
1x 1Ghz Cortex-A8 CPU
512 MB DDR3 memory
2x additional 32Bit/200Mhz hardware cores for true Realtime processing
2x 1Mbit Can buses (2 accessible)
6x UART/Serial (up to 3.6Mbit) (4x accessible)
4x SPI 48Mhz (2 accessible)
3x I2C 400kBit (2 accessible)
7x ANALOG (6 accessible)
and much more of other goodies.

With that specification this board is excellent candidate to drive Klipper + Moonraker + Fluid configuration.
Additionally exist expansion board for it which is called CRAMPS- it was designed for 3D Printers, if you add it to BeagleBone - you will have fully functional 3D printing solution.

BeagleBone is designed for 3.3V hardware, but 5v power is also available on board, so in some cases you will need level shifters to be able to work with 5v or 12v systems, if you use CRAMPS extension board - it already contain required level shifters.

Accelerometer Module
In this setup I did use GY-291 ADXL345 chines accelerometer module, It’s Documentation state following:

  • Operating Voltage: 4V to 6V
  • I/O Voltage Range: 1.7V to 3.6V
  • Communication: SPI and I2C

Additionally ADXL345 chip datasheet state that to get 800Hz resolution - you need to use fast speed 400Kbit I2C interface, to get greater resolutions up to 3200Hz you must use only SPI >=2MHz

So BeagleBone Black and GY-291 ADXL345 are compatible on voltages and speeds, so we can use this combination for resonance measurement and input shaping.

Only few roadblocks need to be resolved:
Issue #1: Current BeagleBone Klipper images and documentation is outdated, issue is solved in this topic

Issue #2: BeagleBone is very flexible in terms of pin configuration and by default SPI pins can be configured for other tasks, to solve this issue we will target SPI1 interface, to enable it you need to disable HDMI Audio and enable SPI1.
To do that edit file /boot/uEnv.txt with elevated permissions

sudo editor /boot/uEnv.txt

uncomment variable

disable_uboot_overlay_audio=1

next uncomment variable and define it this way

uboot_overlay_addr4=/lib/firmware/BB-SPIDEV1-00A0.dtbo

Save changes and reboot the board.
Now you have SPI1 Enabled, to verify it’s presence execute command
ls /dev/spidev1.0

Issue #3: You don’t use Real-time (PRU) cores and using BegleBone just as a Host system or you want to use PRU Cores because you are driving steppers with it.

Unfortunately SPI access thru Real-Time (PRU) cores is not implemented in klipper firmware, but you can use SPI thru Linux MCU, by default SPI support is enabled in Linux MCU, it will be creating huge load on main CPU during communication with accelerometer but it will work.

Issue #4: Wiring. Use same wiring approach as in main klipper documentation. To directly connect GY-291 ADXL345 to BeagleBone black use this pins:
P9_07 or P9_08 - +5V(SYS) (VCC)
P9_01 or P9_02 - GND
P9_28 - CS
P9_29 - MISO(SDO)
P9_30 - MOSI(SDA)
P9_31 - SCK(SCL)

To connect GY-291 ADXL345 with CRAMPS extension board use this pins:
P503.2 - MISO(SDO)
P503.4 - SCK(SCL)
P503.6 - MOSI(SDA)
P503.8 - CS
any even pin from P502 - Negative Endstops rail - GND
any of P501 - Positive Endstops rail - +5V (VCC)

Issue #5: Configuration

[adxl345]
#cs_pin: host:gpiochip3/gpio17
cs_pin: host:None
rate: 1600
spi_speed: 15000000
spi_bus: spidev1.0

[resonance_tester]
accel_chip: adxl345
accel_per_hz: 75
probe_points: 0, 0, 100

In configuration i have disabled cs_pin - why ?
Because this config use Linux MCU and it will try to drive that pin by software on very high speed - creating additional load on system, so it’s disabled, but still we need to supply “host:None” for proper selection of responsible MCU for SPI.

In config I decreased rate to 1600 - why?
I use Delta style printer and during resonance tests it must drive all 3 axis at once, together with SPI load from Linux MCU it was too much and I was getting ‘Timer too close’ errors because high load was slowing down communication with PRU cores. By reducing rate twice - we get twice less data to process, and 1600 is enough for resonance testing.

In config I increased spi_speed to 15Mhz - why ?
By default it’s value equals to 2Mhz, Linux max limit defined as 16Mhz, main reason of increasing speed is to unblock CPU from spending time on waiting, it’s counter-intuitive but higher freq make CPU wait shorter period for answer, with less speed CPU need to wait longer for answer. I was trying to define 16Mhz - but GY-291 was giving wrong replies, reduction to 15Mhz did helped.

I’m sharing this data as is - they works perfectly fine for me, but for your setup - please re-check everything Twice!, Be careful, especially if you are using some other hardware than described here.

Good luck.

1 Like