RepRapFirmware 3.3 includes support for connecting accelerometers. The primary purpose is to identify the ringing frequencies of the mechanics so that DAA and in future other forms of input shaping can be used to reducing ringing.
- In RRF 3.3, data collection from accelerometers is currently only available when running the Duet in standalone mode. In RRF 3.4beta, data can be collected when running in SBC mode too.
- Use of an accelerometer as a Z probe is not currently supported.
The only type of accelerometer supported in RRF 3.3 and 3.4beta1 is the LIS3DH. We have chosen this chip because of its low cost and because it provides a mechanism to read all the data stored in its FIFO in a single block command.
RRF 3.4beta2 and later support the LIS3DSH too. Connection via SPI and configuration are exactly the same as for the LIS3DH.
Revision 1.1 of the Duet 3 Tool Board has a LIS3DH accelerometer built in.
For machines not using the Tool Board, breakout boards using the LIS3DH are readily available, for example SparkFun SEN-13963 https://www.sparkfun.com/products/13963 and Adafruit 2809 https://www.adafruit.com/product/2809. UK resellers of these boards include https://thepihut.com/products/adafruit-l..., https://www.hobbytronics.co.uk/lis3dh-ac... and https://shop.pimoroni.com/products/adafr.... The Adafruit and SparkFun boards are also available from Digikey. There are two different versions of the Adafruit board; either can be used.
Accelerometer boards using the LIS3DSH are readily available via eBay and Amazon. Compared to the LIS3DH, the LIS3DSH has higher resolution and more convenient sampling rates.
Two types of accelerometer connection are supported: direct SPI connection to a Duet main board, and I2C connection to a SAMMYC21 board that is connected to a Duet 3 over CAN bus.
Direct SPI connection to a Duet main board
To use a direct connection, connect the accelerometer MOSI (also called SDI), MISO (also called SDO), SCLK and GND pins to the corresponding pins on the SPI daughter board connector. You can also pick up +3.3V on the daughter board connector to feed to the Vcc pin of the accelerometer.
Two further signals must be connected on the accelerometer breakout board: SPI CS, and INT1. The INT1 pin must be connected to a Duet pin with interrupt capability. The CS pin should be separated from other signal wires if possible because it is sensitive to interference, especially when using a Duet 3 Mini or Duet 3 MB6HC (see note below).
This is what we suggest:
- On the Duet 3 Mini only the IOn.IN pins have interrupt capability, so we suggest you choose one of the IO_n ports with both input and output connections, for example IO_3. Connect the accelerometer CS pin to IO_3.OUT and the accelerometer INT1 pin to IO_3.IN. Then use this command to tell RRF about it:
M955 P0 C"io3.out+io3.in"
- On Duet WiFi and Duet Ethernet all the SPI CS pins have interrupt capability, so you can use any two spare CS pins on the daughter board connector. For example, on a Duet WiFi or Duet Ethernet you could connect the accelerometer CS pin to SPI.CS4, and the INT1 pin to SPI.CS3. [Note: if you already have one daughter board plugged into the main board and you wish to connect to SPI.CS4 and SPI.CS3 on the top of that daughter board, the daughter board passes SPI.CS4 and SPI.CS3 to the pin positions directly above the SPI.CS2 and SPI.CS1 pins on the main board. This is so that a second daughter board stacked on top automatically uses SPI.CS4 and SPI.CS3 instead of SPI.CS2 and SPI.CS1.] Use this command to tell RRF about the accelerometer:
M955 P0 C"spi.cs4+spi.cs3"
- On the Duet 2 Maestro use the same connections as for Duet 2 WiFi/Ethernet except that pins spi.cs4 and spi.cs3 on the daughter board connector are replaced by twd0 and twck0. So use this configuration command:
M955 P0 C"twd0+twcl0"
- On Duet 3 MB6HC you can use either of these wiring schemes.
The first photo on the right shows a sample cable that connects the Adafruit LIS3DH board to a Duet 2 WiFi, Ethernet, Maestro or Duet 3 MB6HC if no temperature daughter boards are in use. The second cable on the right shows a sample cable that connects a LIS3DH or LIS3DSH board to a Duet 3 Mini. Both cables are wired as follows. This wiring scheme has been designed to keep the wire carrying CS away from the other signal wires.
|Wire#||Accelerometer signal||Duet signal|
|1||not connected||not connected|
|3||not connected||not connected|
|7||INT1||IO2.IN (Duet 3 Mini) or TWCK0 (Maestro) or SPI.CS3|
|8||3V3 or VCC||+3V3|
|9||CS||IO2.OUT (Duet 3 Mini) or TWD0 (Maestro) or SPI.CS4|
|10||not connected||not connected|
You can add parameter I (uppercase 'i') to the M955 command if you need to change the default orientation, and you can add R and S parameters if you want to change the resolution or sample rate.
Note: some users have found it difficult to get SPI-connected accelerometers to work with the Duet 3 Mini. We have found that one reason for this is that transitions on SDO are capacitively coupled into CS in the cable, especially if these signals use adjacent conductors. This causes a glitch on CS of a few nanoseconds, which is sufficient to cause the accelerometer to stop transmitting. This is why we recommend that you keep th CS signal away from other signal wires. Where this has not been done and the CS wire runs next to the SDO wire, a resistor with value between 100 ohms and 1K in series with SDO at the accelerometer end of the cable has solved the problem for some users.
Connection via SAMMYC21 and CAN bus
Version 3.3beta3 of the sample SAMMYC21 firmware is configured to support a LIS3DH connected via I2C at address 0x18. You need to supply 3.3V power and ground to the LIS3DH, which you can obtain from the SAMMYC21 if you have not converted it to 5V operation. The SDA and SCL pins of the accelerometer must be connected to pins PA22 and PA23 of the SAMMYC21 respectively. The INT1 accelerometer pin must be connected to PA13.
The accelerometer must be configured at address 0x18. The Adafruit breakout board defaults to this address. The Sparkfun board can be configured at this address by bridging two pads on the underside.
You do not need to tell RRF about the accelerometer, however you can use M955 if necessary to set the orientation, sample rate and resolution, for example:
M955 P124.0 I10 ; specify orientation of accelerometer on SAMMYC21 with CAN address 124
The I (orientation) parameter tells the firmware which of the 24 possible orientations the accelerometer chip is in relative to the printer axes. It is expressed as a 2-digit number. The first digit specifies which machine direction the Z axis of the accelerometer chip (usually the top face of the chip) faces, as follows: 0 = +X, 1 = +Y, 2 = +Z, 4 = -X, 5 = -Y, 6 = -Z. The second digit expresses which direction the X axis of the accelerometer chip faces, using the same code. If the accelerometer chip axes line up with the machine axis, the orientation is 20. This is the default orientation if no orientation has been specified.
Forum user "Nuramori" has produced a graphical guide to help illustrate the orientation options with a Duet 3 Tool Board 1LC rev 1.1 (with onboard accelerometer):
Use command M955 as described above to create an accelerometer (not necessary if using the built-in accelerometer on the Tool Board version 1.1, or if the accelerometer is connected via a SAMMYC21) and/or to configure its orientation, resolution, or sample rate. For most purposes the defaults (10 bit resolution, 1344Hz sampling rate) should suffice.
Prior to making measurements with the accelerometer, disable any input shaping (including DAA if you are using it), unless of course you are trying to establish the effect of using input shaping.
Use command M956 to collect accelerometer data. RRF 3.3 only supports capture mode 0 (immediate capture). Here is a typical command to capture data for a travel move in the X direction:
G1 X-50 G4 S2 M956 P124.0 S1000 A0 G4 P10 G1 X50 F20000
This commands the X axis to position -50 (G1 X-50) and then waits for two seconds to let any ringing subside (G4 S2). Then it requests the accelerometer on board 124 to collect 1000 samples, followed by a pause of 10ms to let the accelerometer start and provide a baseline. It then commands a travel move to X=+50 at 20000 mm/min.
Acceleration measurements captured during movement typically show higher frequency components caused by the motors and belts. For this reason, you may get results that are easier to interpret if you collect data immediately after a sharp stop, using a command such as this:
G1 X-50 G4 S2 G1 X50 F20000 M400 M956 P124.0 S1000 A0
RRF 3.4beta1 and later allow you to name the file that data is written to using an additional F parameter. The name should end in .csv so that the Accelerometer plugin for Duret Web Control recognises it.
Retrieving the data
A successful M956 command causes a new file to be created in /sys/accelerometers. The filename includes the CAN address of the board to which the accelerometer is connected, and the date and time that the data was captured. It is in comma-separated-variable format so it can be imported into a spreadsheet. When browsing these files in DWC you may need to click the Refresh button to make DWC aware of newly-created files.
The last line of the file will report the average data rate and the number of overflows recorded. If the number of overflows is nonzero then data samples have been lost and the file should be discarded. Overflows are rare when using CAN-connected sensors, but more common with direct-connect sensors because a single task is used both to collect the data and to write it to file. If you find that you get overflows every time you collect data, try the following:
- Do not use an external SD card while collecting data
- Try a new SD card
- Try a faster SD card
- Reduce the number of samples requested, or the number of axes sampled
- Use a lower sampling rate
Analysing the data
Duet Web Control 3.3 includes an Accelerometer plugin that can be used to display the accelerometer data and its Fourier transform. To enable it, first go to Settings/General/Built-in Plugins and start it. Then go to Settings/Machine Specific/Accelerometer.