Configure an ADXL345 Accelerometer (viam-micro-server)

The accel-adxl345 movement sensor model supports the Analog Devices ADXL345 digital accelerometer. This three axis accelerometer supplies linear acceleration data, supporting the LinearAcceleration method.

If you are using a Viam Rover, this is the accelerometer on it.

Physically connect your movement sensor to your microcontroller and power both on. Then, configure the movement sensor:

Navigate to the CONFIGURE tab of your machine’s page in the Viam app. Click the + icon next to your machine part in the left-hand menu and select Component. Select the movement-sensor type, then select the accel-adxl345 model. Enter a name or use the suggested name for your movement sensor and click Create.

Creation of an `accel-adxl345` movement sensor in the Viam app config builder.

Copy and paste the following attribute template into your movement sensor’s attributes field. Then remove and fill in the attributes as applicable to your movement sensor, according to the table below.

{
  "board": "<your-board-name>",
  "i2c_bus": "<your-i2c-bus-name-on-board>",
  "use_alt_i2c_address": <boolean>,
}
{
  "board": "local",
  "i2c_bus": "default_i2c_bus"
}
{
  "components": [
    {
      "name": "<your-sensor-name>",
      "model": "accel-adxl345",
      "type": "movement_sensor",
      "namespace": "rdk",
      "attributes": {
        "board": "<your-board-name>",
        "i2c_bus": "<your-i2c-bus-name-on-board>",
        "use_alt_i2c_address": <boolean>
      }
    }
  ]
}
{
  "components": [
    {
      "name": "local",
      "model": "esp32",
      "type": "board",
      "namespace": "rdk",
      "attributes": {
        "pins": [15, 21, 22],
        "i2cs": [
          {
            "name": "default_i2c_bus",
            "bus": "i2c0",
            "data_pin": 21,
            "clock_pin": 22
          }
        ]
      }
    },
    {
      "name": "my-adxl",
      "model": "accel-adxl345",
      "type": "movement_sensor",
      "namespace": "rdk",
      "attributes": {
        "board": "local",
        "i2c_bus": "default_i2c_bus",
        "use_alt_i2c_address": false
      }
    }
  ]
}

Attributes

NameTypeRequired?Description
boardstringRequiredThe name of the board to which the device is wired.
i2c_busstringRequiredThe name of the I2C bus on the board wired to this device.
use_alt_i2c_addressboolOptionalDepends on whether you wire SDO low (leaving the default address of 0x53) or high (making the address 0x1D). If high, set true. If low, set false or omit the attribute.
Default: false

Test the movement sensor

After you configure your movement sensor, navigate to the Control tab and select the dedicated movement sensor dropdown panel. This panel presents the data collected by the movement sensor.

The movement sensor component in the control tab

Troubleshooting

If your movement sensor is not working as expected, follow these steps:

  1. Check your machine logs on the LOGS tab to check for errors.
  2. Review this movement sensor model’s documentation to ensure you have configured all required attributes.
  3. Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the movement sensor there.

If none of these steps work, reach out to us on the Community Discord and we will be happy to help.

Next steps

For more configuration and usage info, see:

Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.