UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

KXTJ3 Class

Module: common

Methods

KXTJ3

(
  • bus
  • addr
)
Number

If no errors occur, the device is initialized with default values and set to active state

Parameters:

  • bus Number

    I2C bus

  • addr Number

    I2C address of the sensor

Returns:

Number:

SensorInit

(
  • odr
  • resolution
  • g_range
)

Sensor is set to standby mode during the initialization and back to active after initialization.

Parameters:

  • odr KXTJ3_ODR_T

    One of the KXTJ3_ODR_T values

  • resolution KXTJ3_RESOLUTION_T

    One of the KXTJ3_RESOLUTION_T values

  • g_range KXTJ3_G_RANGE_T

    One of the KXTJ3_G_RANGE_T values

GetWhoAmI

() Number

Returns:

Number:

Who am I value of the sensor

SensorActive

()

SensorStandby

()

SetGRange

(
  • g_range
)

Sensor needs to be in standby mode when setting the acceleration range value
Be cautious not to set g_range to 14-bits modes with the resolution being on LOW_RES

Parameters:

  • g_range KXTJ3_G_RANGE_T

    One of the KXTJ3_G_RANGE_T values

SetResolution

(
  • resolution
)

LOW_RES valid only for ODR <= 200 Hz
Be cautious not to set resolution to LOW_RES with the G_RANG being on 14-bits modes
Sensor needs to be in standby mode when setting the sensor resolution

Parameters:

  • resolution KXTJ3_RESOLUTION_T

    One of the KXTJ3_RESOLUTION_T values

SetOdr

(
  • odr
)

Sensor needs to be in standby mode when setting the ODR

Parameters:

  • odr KXTJ3_ODR_T

    One of the KXTJ3_ODR_T values

SetOdrForWakeup

(
  • odr
)

Sensor needs to be in standby mode when setting the ODR

Parameters:

  • odr KXTJ3_ODR_WAKEUP_T

    One of the KXTJ3_ODR_WAKEUP_T values

SelfTestDigitalCommunication

()

This method is called by SensorSelfTest also
Sensor must be in standby mode before performing this action

SensorSelfTest

()

The method prints out the values before and during test and the average difference for each axis
See the datasheet for more information

SensorSoftwareReset

()

You should call kxtj3_sensor_init() after the software reset
See the datasheet for more details

GetAccelerationRawVector

() Std::vector float

Gets raw acceleration data from the sensor.

Returns:

Std::vector float :

Acceleration vector [x, y, z]

GetAccelerationVector

() Std::vector float

Gets acceleration data in (m/s^2) from the sensor.

Returns:

Std::vector float :

Acceleration vector [x, y, z]

GetAccelerationSamplePeriod

() Number

Returns:

Number:

Floating point value of the sampling period

GetWakeUpSamplePeriod

() Number

Returns:

Number:

Floating point value of the sampling period

EnableDataReadyInterrupt

()

Sensor must be in standby mode before performing this action

DisableDataReadyInterrupt

()

Sensor must be in standby mode before performing this action

EnableWakeUpInterrupt

()

Sensor must be in standby mode before performing this action

DisableWakeUpInterrupt

()

Sensor must be in standby mode before performing this action

EnableInterruptPin

(
  • polarity
  • response_type
)

For Wakeup function, the response type is always latched unless set wakeup latch off Sensor needs to be in standby mode when enabling the interrupt
See datasheet for more details

Parameters:

  • polarity KXTJ3_INTERRUPT_POLARITY_T

    Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.

  • response_type KXTJ3_INTERRUPT_RESPONSE_T

    Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values.

DisableInterruptPin

()

Sensor needs to be in standby mode when disabling the interrupt pin

SetInterruptPolarity

(
  • polarity
)

Polarity ACTIVE_HIGH or ACTIVE_LOW
Sensor must be in standby mode before performing this action

Parameters:

  • polarity KXTJ3_INTERRUPT_POLARITY_T

    Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.

SetInerruptResponse

(
  • response_type
)

Response either latch until cleared by reading INT_REL register, or transmit one pulse Pulse width of 0.03-0.05ms
For Wakeup function, the response type is always latched unless set wakeup latch off
Sensor must be in standby mode before performing this action
See datasheet for more details

Parameters:

  • response_type KXTJ3_INTERRUPT_RESPONSE_T

    Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values

GetInterruptStatus

() Boolean

See datasheet for more details

Returns:

Boolean:

Return true if an interrupt event has occurred (DRDY or WUFS is 1), returns false if no interrupts have occurred

ReadInterruptSource1

() Number

See datasheet for more details

Returns:

Number:

Value of the interrupt source register

GetInterruptSource

() KXTJ3_INTERRUPT_SOURCE_T

See datasheet for more details

Returns:

KXTJ3_INTERRUPT_SOURCE_T:

One of the KXTJ3_INTERRUPT_SOURCE_T values/types

InstallIsr

(
  • edge
  • pin
  • isr
  • isr_args
)

Parameters:

  • edge Mraa_gpio_edge_t

    One of the mraa_gpio_edge_t values. Interrupt trigger edge.

  • pin Number

    The GPIO pin to use as the interrupt pin

  • isr Function

    Pointer to the method to be called, when the interrupt occurs

  • isr_args Void *

    The arguments to be passed to the method

UninstallIsr

()

ClearInterrupt

()

See datasheet for more details

EnableWakeUpSingleAxisDirection

(
  • axis
)

Sensor must be in standby mode before performing this action

Parameters:

  • axis KXTJ3_WAKEUP_SOURCE_T

    The axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value

DisableWakeUpSingleAxisDirection

(
  • axis
)

Sensor must be in standby mode before performing this action

Parameters:

  • axis KXTJ3_WAKEUP_SOURCE_T

    The axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value

GetWakeUpAxisDirection

() Kxtj3_wakeup_axes

See datasheet for more details

Returns:

Kxtj3_wakeup_axes:

A kxtj3_wakeup_axes struct with values of true/false for a wakeup for each axis and its direction

EnableWakeUpLatch

()

When this bit is set, the wakeup interrupt has to be cleared manually (cannot use interrupt response with pulse)
Sensor must be in standby mode before performing this action

DisableWakeUpLatch

()

The wakeup threshold is advised to not be very low to avoid interrupt being triggered in an almost continuous manner
Sensor must be in standby mode before performing this action
When this bit is cleared, and the interrupt response type is set to Pulse, then upon a wakeup event the wakeup interrupt signal will pulse and return low, but only once. Then, the interrupt output will not reset until data is read or interrupt cleared.

SetWakeUpMotionCounter

(
  • count
)

The count is limited to values from 1 to 255
Every count is calculated as (1 / Wakeup_ODR_FREQUENCY) where Wakeup_ODR_FREQUENCY is the current odr_in_Hz value from odr_map_in_Hz_wakeup value
Sensor must be in standby mode before performing this action
See datasheet for more details

Parameters:

  • count Number

    The timer count from 1 to 255

SetWakeUpMotionTime

(
  • desired_time
)

the desired time should be such that (0 < desired_time * wakeup_odr_frequency <= 255)
Sensor must be in standby mode before performing this action
See datasheet for more details

Parameters:

  • desired_time Number

    The desired time in seconds

GetWakeUpMotionTime

() Number

Returns:

Number:

Time value in seconds

SetWakeUpNonActivityCounter

(
  • count
)

The count is limited to values from 1 to 255
Every count is calculated as (1 / Wakeup_ODR_FREQUENCY) where Wakeup_ODR_FREQUENCY is the current odr_in_Hz value from odr_map_in_Hz_wakeup value
Sensor must be in standby mode before performing this action
See datasheet for more details

Parameters:

  • count Number

    The timer count from 1 to 255

SetWakeUpNonActivityTime

(
  • desired_time
)

the desired time should be such that (0 < desired_time * wakeup_odr_frequency <= 255)
Sensor must be in standby mode before performing this action
See datasheet for more details

Parameters:

  • desired_time Number

    The desired time in seconds

GetWakeUpNonActivityTime

() Number

Returns:

Number:

Time value in seconds

SetWakeUpThresholdCounter

(
  • count
)

The count is limited to values from 1 to 4096, that it is 16g threshold with (3.9mg/count) It is advised to not set the threshold to a very low value which may cause bad behaviour in the wakeup interrupt
Sensor must be in standby mode before performing this action
See datasheet for more details

Parameters:

  • count Number

    The timer count from 1 to 4096, that it is 16g threshold with (3.9mg/count)

SetWakeUpThresholdGRange

(
  • g_threshold
)

The count is limited to values up to 16g, with steps of 3.9mg. It is advised to not set the threshold to a very low value which may cause bad behaviour in the wakeup interrupt
Sensor must be in standby mode before performing this action
See datasheet for more details

Parameters:

  • g_threshold Number

    The acceleration threshold (in g) in g, from 3.9mg to 16g, steps of 3.9mg/count.

GetWakeUpThresholdGRange

() Number

Returns:

Number:

Threshold value in g