Home Code KX134 Triple Axis Accelerometer and Arduino example

KX134 Triple Axis Accelerometer and Arduino example

by shedboy71

In this article we look at another Triple-axis Magnetometer, the KX134 Triple Axis Accelerometer, and connect it to an Arduino Uno

This is very similar to the KX132 we wrote about previously

Sensor Information

This KX134 is a digital accelerometer from Kionix. We will use the KX134 breakout from Sparkfun

The KX134 is a low-power, 16-bit resolution three-axis accelerometer capable of measuring ±8g/16g/32g/64g (user-selectable) and has up to a 10kHz output data rate making it ideal for high-g measurements as well as high-speed applications such as vibration sensing

The KX134 includes a host of features including Freefall detection, Directional Tap™ and Double-Tap™ detection, tilt orientation detection and more. The Qwiic KX134 can interface with controllers using both I2C and SPI at high speeds so you can use it in an existing Qwiic chain or on an SPI bus.

This is what the breakout looks like

Features

  • Measurement Range: ±8g, ±16g, ±32g, ±64g (User Selectable)
  • High Resolution (8 or 16-bit)
  • User-Configurable Output Data Rate (ODR) up to 25600Hz
  • User-Configurable 3-stage Advanced Data Path featuring low-pass filter, low-pass/high-pass filter and RMS calculation engine
  • Wide range of built-in sensing functions
    • Free Fall
    • Directional-Tap / Double-Tap
    • Device Orientation & Activity Algorithms
  • Low Noise: 130µg/√Hz (varies based on ODR, power mode & other settings)
  • High-Resolution Wake-Up & Back-to-Sleep Detection with a configurable threshold as low as 3.9mg
  • 512-byte FIFO buffer that continues recording data while being read
  • Selectable Low-Power or High-Performance operating modes
  • Low Power with Integrated Voltage Regulator
    • High-Performance Operating Current Consumption (400Hz ODR + Wake-Up Detection): 148µA
    • Low Power Operating Current Consumption (0.781Hz ODR + Wake-Up Detection): 0.53µA
    • Standby Current Consumption: 0.5µA
  • Self-Test Functionality
  • Digital I2C up to 3.4MHz and Digital SPI up to 10MHz
  • 2x Qwiic Connectors
  • SPI available on PTH Header Pins
  • I2C Address: 0x1E (0x1F can be used as an alternate but requires soldering abridge across 2 pads on the underside of the board)

Parts Required

You can connect to the sensor using DuPont style jumper wire.

Name Link
Arduino Uno UNO R3 CH340G with usb cable
KX134 Aliexpress link
Connecting cables Male to Male + Male to Female and Female to Female Jumper Wire Dupont Cable

 

Schematic/Connection

I used 3.3v from the Arduino Uno

I also used a Qwiic cable, but if you do not have one, there is an unpopulated set of pins you can solder a header to. This is how you would wire this up

 

Code Example

I installed the Sparkfun library using the Arduino ide

Click the Manage Libraries … menu item, search for KX134, and select the Sparkfun KX13x library like this

This is one of the examples that gets installed with the library, with a  few comments and unused lines removed.

#include <Wire.h>
#include <SparkFun_KX13X.h>

SparkFun_KX134 kxAccel;

outputData myData; // Struct for the accelerometer's data

void setup()
{

  Wire.begin();
  Serial.begin(115200);

  // Wait for the Serial monitor to be opened.
  while (!Serial)
    delay(50);

  if (!kxAccel.begin())
  {
    Serial.println("Could not communicate with the the KX13X");
    while (1)
      ;
  }
  Serial.println("Ready.");

  if (kxAccel.softwareReset())
    Serial.println("Reset.");

  // Give some time for the accelerometer to reset.
  // It needs two, but give it five for good measure.
  delay(5);

  // Many settings for KX13X can only be
  // applied when the accelerometer is powered down.
  // However there are many that can be changed "on-the-fly"
  // check datasheet for more info, or the comments in the
  // "...regs.h" file which specify which can be changed when.
  kxAccel.enableAccel(false);

  kxAccel.setRange(SFE_KX134_RANGE16G);         // 16g for the KX134

  kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
  // kxAccel.setOutputDataRate(); // Default is 50Hz
  kxAccel.enableAccel();
}

void loop()
{
  // Check if data is ready.
  if (kxAccel.dataReady())
  {
    kxAccel.getAccelData(&myData);
    Serial.print("X: ");
    Serial.print(myData.xData, 4);
    Serial.print(" Y: ");
    Serial.print(myData.yData, 4);
    Serial.print(" Z: ");
    Serial.print(myData.zData, 4);
    Serial.println();
  }
  delay(500); // Delay should be 1/ODR (Output Data Rate), default is 1/50ODR
}

 

Output

When run and the sensor was moved around

Ready.
Reset.
X: 0.3035 Y: -0.0088 Z: -0.9189
X: -0.0044 Y: 0.6022 Z: -1.2317
X: -1.3576 Y: -0.2172 Z: -0.2381
X: -0.0693 Y: -0.0176 Z: 0.6759
X: -0.4948 Y: 0.0517 Z: -0.7491
X: -0.6334 Y: -0.6637 Z: 0.9052
X: -0.4304 Y: -0.7862 Z: 0.0810
X: -0.8867 Y: -0.5251 Z: -0.1635

Links

https://kionixfs.azureedge.net/en/datasheet/kx134-1211-e.pdf

Share

You may also like

Leave a Comment