go-api-bindings: github.com/Tinkerforge/go-api-bindings/accelerometer_v2_bricklet Index | Files

package accelerometer_v2_bricklet

import "github.com/Tinkerforge/go-api-bindings/accelerometer_v2_bricklet"

Measures acceleration in three axis.

See also the documentation here: https://www.tinkerforge.com/en/doc/Software/Bricklets/AccelerometerV2_Bricklet_Go.html.

Index

Package Files

accelerometer_v2_bricklet.go

Constants

const DeviceDisplayName = "Accelerometer Bricklet 2.0"
const DeviceIdentifier = 2130

type AccelerometerV2Bricklet Uses

type AccelerometerV2Bricklet struct {
    // contains filtered or unexported fields
}

func New Uses

func New(uid string, ipcon *ipconnection.IPConnection) (AccelerometerV2Bricklet, error)

Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ipcon` is connected.

func (*AccelerometerV2Bricklet) DeregisterAccelerationCallback Uses

func (device *AccelerometerV2Bricklet) DeregisterAccelerationCallback(registrationId uint64)

Remove a registered Acceleration callback.

func (*AccelerometerV2Bricklet) DeregisterContinuousAcceleration16BitCallback Uses

func (device *AccelerometerV2Bricklet) DeregisterContinuousAcceleration16BitCallback(registrationId uint64)

Remove a registered Continuous Acceleration 16 Bit callback.

func (*AccelerometerV2Bricklet) DeregisterContinuousAcceleration8BitCallback Uses

func (device *AccelerometerV2Bricklet) DeregisterContinuousAcceleration8BitCallback(registrationId uint64)

Remove a registered Continuous Acceleration 8 Bit callback.

func (*AccelerometerV2Bricklet) GetAPIVersion Uses

func (device *AccelerometerV2Bricklet) GetAPIVersion() [3]uint8

Returns the version of the API definition (major, minor, revision) implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.

func (*AccelerometerV2Bricklet) GetAcceleration Uses

func (device *AccelerometerV2Bricklet) GetAcceleration() (x int32, y int32, z int32, err error)

Returns the acceleration in x, y and z direction. The values are given in gₙ/10000 (1gₙ = 9.80665m/s²).

If you want to get the acceleration periodically, it is recommended to use the RegisterAccelerationCallback callback and set the period with SetAccelerationCallbackConfiguration.

func (*AccelerometerV2Bricklet) GetAccelerationCallbackConfiguration Uses

func (device *AccelerometerV2Bricklet) GetAccelerationCallbackConfiguration() (period uint32, valueHasToChange bool, err error)

Returns the callback configuration as set by SetAccelerationCallbackConfiguration.

func (*AccelerometerV2Bricklet) GetBootloaderMode Uses

func (device *AccelerometerV2Bricklet) GetBootloaderMode() (mode BootloaderMode, err error)

Returns the current bootloader mode, see SetBootloaderMode.

Associated constants:

* BootloaderModeBootloader
* BootloaderModeFirmware
* BootloaderModeBootloaderWaitForReboot
* BootloaderModeFirmwareWaitForReboot
* BootloaderModeFirmwareWaitForEraseAndReboot

func (*AccelerometerV2Bricklet) GetChipTemperature Uses

func (device *AccelerometerV2Bricklet) GetChipTemperature() (temperature int16, err error)

Returns the temperature in °C as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.

func (*AccelerometerV2Bricklet) GetConfiguration Uses

func (device *AccelerometerV2Bricklet) GetConfiguration() (dataRate DataRate, fullScale FullScale, err error)

Returns the configuration as set by SetConfiguration.

Associated constants:

* DataRate0781Hz
* DataRate1563Hz
* DataRate3125Hz
* DataRate62512Hz
* DataRate125Hz
* DataRate25Hz
* DataRate50Hz
* DataRate100Hz
* DataRate200Hz
* DataRate400Hz
* DataRate800Hz
* DataRate1600Hz
* DataRate3200Hz
* DataRate6400Hz
* DataRate12800Hz
* DataRate25600Hz
* FullScale2g
* FullScale4g
* FullScale8g

func (*AccelerometerV2Bricklet) GetContinuousAccelerationConfiguration Uses

func (device *AccelerometerV2Bricklet) GetContinuousAccelerationConfiguration() (enableX bool, enableY bool, enableZ bool, resolution Resolution, err error)

Returns the continuous acceleration configuration as set by SetContinuousAccelerationConfiguration.

Associated constants:

* Resolution8bit
* Resolution16bit

func (*AccelerometerV2Bricklet) GetFilterConfiguration Uses

func (device *AccelerometerV2Bricklet) GetFilterConfiguration() (iirBypass IIRBypass, lowPassFilter LowPassFilter, err error)

Returns the configuration as set by SetFilterConfiguration.

.. versionadded:: 2.0.2$nbsp;(Plugin)

Associated constants:

* IIRBypassApplied
* IIRBypassBypassed
* LowPassFilterNinth
* LowPassFilterHalf

func (*AccelerometerV2Bricklet) GetIdentity Uses

func (device *AccelerometerV2Bricklet) GetIdentity() (uid string, connectedUid string, position rune, hardwareVersion [3]uint8, firmwareVersion [3]uint8, deviceIdentifier uint16, err error)

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c' or 'd'.

The device identifier numbers can be found `here <device_identifier>`. |device_identifier_constant|

func (*AccelerometerV2Bricklet) GetInfoLEDConfig Uses

func (device *AccelerometerV2Bricklet) GetInfoLEDConfig() (config InfoLEDConfig, err error)

Returns the LED configuration as set by SetInfoLEDConfig

Associated constants:

* InfoLEDConfigOff
* InfoLEDConfigOn
* InfoLEDConfigShowHeartbeat

func (*AccelerometerV2Bricklet) GetResponseExpected Uses

func (device *AccelerometerV2Bricklet) GetResponseExpected(functionID Function) (bool, error)

Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.

For getter functions this is enabled by default and cannot be disabled, because those functions will always send a response. For callback configuration functions it is enabled by default too, but can be disabled by SetResponseExpected. For setter functions it is disabled by default and can be enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is send and errors are silently ignored, because they cannot be detected.

See SetResponseExpected for the list of function ID constants available for this function.

func (*AccelerometerV2Bricklet) GetSPITFPErrorCount Uses

func (device *AccelerometerV2Bricklet) GetSPITFPErrorCount() (errorCountAckChecksum uint32, errorCountMessageChecksum uint32, errorCountFrame uint32, errorCountOverflow uint32, err error)

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

* ACK checksum errors, * message checksum errors, * framing errors and * overflow errors.

The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

func (*AccelerometerV2Bricklet) GetStatusLEDConfig Uses

func (device *AccelerometerV2Bricklet) GetStatusLEDConfig() (config StatusLEDConfig, err error)

Returns the configuration as set by SetStatusLEDConfig

Associated constants:

* StatusLEDConfigOff
* StatusLEDConfigOn
* StatusLEDConfigShowHeartbeat
* StatusLEDConfigShowStatus

func (*AccelerometerV2Bricklet) ReadUID Uses

func (device *AccelerometerV2Bricklet) ReadUID() (uid uint32, err error)

Returns the current UID as an integer. Encode as Base58 to get the usual string version.

func (*AccelerometerV2Bricklet) RegisterAccelerationCallback Uses

func (device *AccelerometerV2Bricklet) RegisterAccelerationCallback(fn func(int32, int32, int32)) uint64

This callback is triggered periodically according to the configuration set by SetAccelerationCallbackConfiguration.

The parameters are the same as GetAcceleration.

func (*AccelerometerV2Bricklet) RegisterContinuousAcceleration16BitCallback Uses

func (device *AccelerometerV2Bricklet) RegisterContinuousAcceleration16BitCallback(fn func([30]int16)) uint64

Returns 30 acceleration values with 16 bit resolution. The data rate can be configured with SetConfiguration and this callback can be enabled with SetContinuousAccelerationConfiguration.

The returned values are raw ADC data. If you want to put this data into a FFT to determine the occurrences of specific frequencies we recommend that you use the data as is. It has all of the ADC noise in it. This noise looks like pure noise at first glance, but it might still have some frequnecy information in it that can be utilized by the FFT.

Otherwise you have to use the following formulas that depend on the full scale range (see SetConfiguration) to calculate the data in g/10000 (same unit that is returned by GetAcceleration):

* Full scale 2g: acceleration = value*625/1024 * Full scale 4g: acceleration = value*1250/1024 * Full scale 8g: acceleration = value*2500/1024

The data is formated in the sequence x, y, z, x, y, z, ... depending on the enabled axis. Examples:

* x, y, z enabled: x, y, z, ... 10x ..., x, y, z * x, z enabled: x, z, ... 15x ..., x, z * y enabled: y, ... 30x ..., y

func (*AccelerometerV2Bricklet) RegisterContinuousAcceleration8BitCallback Uses

func (device *AccelerometerV2Bricklet) RegisterContinuousAcceleration8BitCallback(fn func([60]int8)) uint64

Returns 60 acceleration values with 8 bit resolution. The data rate can be configured with SetConfiguration and this callback can be enabled with SetContinuousAccelerationConfiguration.

The returned values are raw ADC data. If you want to put this data into a FFT to determine the occurrences of specific frequencies we recommend that you use the data as is. It has all of the ADC noise in it. This noise looks like pure noise at first glance, but it might still have some frequnecy information in it that can be utilized by the FFT.

Otherwise you have to use the following formulas that depend on the full scale range (see SetConfiguration) to calculate the data in g/10000 (same unit that is returned by GetAcceleration):

* Full scale 2g: acceleration = value*256*625/1024 * Full scale 4g: acceleration = value*256*1250/1024 * Full scale 8g: acceleration = value*256*2500/1024

The data is formated in the sequence x, y, z, x, y, z, ... depending on the enabled axis. Examples:

* x, y, z enabled: x, y, z, ... 20x ..., x, y, z * x, z enabled: x, z, ... 30x ..., x, z * y enabled: y, ... 60x ..., y

func (*AccelerometerV2Bricklet) Reset Uses

func (device *AccelerometerV2Bricklet) Reset() (err error)

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

func (*AccelerometerV2Bricklet) SetAccelerationCallbackConfiguration Uses

func (device *AccelerometerV2Bricklet) SetAccelerationCallbackConfiguration(period uint32, valueHasToChange bool) (err error)

The period is the period with which the RegisterAccelerationCallback callback is triggered periodically. A value of 0 turns the callback off.

If the `value has to change`-parameter is set to true, the callback is only triggered after the value has changed. If the value didn't change within the period, the callback is triggered immediately on change.

If it is set to false, the callback is continuously triggered with the period, independent of the value.

If this callback is enabled, the RegisterContinuousAcceleration16BitCallback callback and RegisterContinuousAcceleration8BitCallback callback will automatically be disabled.

func (*AccelerometerV2Bricklet) SetBootloaderMode Uses

func (device *AccelerometerV2Bricklet) SetBootloaderMode(mode BootloaderMode) (status BootloaderStatus, err error)

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Associated constants:

* BootloaderModeBootloader
* BootloaderModeFirmware
* BootloaderModeBootloaderWaitForReboot
* BootloaderModeFirmwareWaitForReboot
* BootloaderModeFirmwareWaitForEraseAndReboot
* BootloaderStatusOK
* BootloaderStatusInvalidMode
* BootloaderStatusNoChange
* BootloaderStatusEntryFunctionNotPresent
* BootloaderStatusDeviceIdentifierIncorrect
* BootloaderStatusCRCMismatch

func (*AccelerometerV2Bricklet) SetConfiguration Uses

func (device *AccelerometerV2Bricklet) SetConfiguration(dataRate DataRate, fullScale FullScale) (err error)

Configures the data rate and full scale range. Possible values are:

* Data rate of 0.781Hz to 25600Hz. * Full scale range of ±2g up to ±8g.

Decreasing data rate or full scale range will also decrease the noise on the data.

Associated constants:

* DataRate0781Hz
* DataRate1563Hz
* DataRate3125Hz
* DataRate62512Hz
* DataRate125Hz
* DataRate25Hz
* DataRate50Hz
* DataRate100Hz
* DataRate200Hz
* DataRate400Hz
* DataRate800Hz
* DataRate1600Hz
* DataRate3200Hz
* DataRate6400Hz
* DataRate12800Hz
* DataRate25600Hz
* FullScale2g
* FullScale4g
* FullScale8g

func (*AccelerometerV2Bricklet) SetContinuousAccelerationConfiguration Uses

func (device *AccelerometerV2Bricklet) SetContinuousAccelerationConfiguration(enableX bool, enableY bool, enableZ bool, resolution Resolution) (err error)

For high throughput of acceleration data (> 1000Hz) you have to use the RegisterContinuousAcceleration16BitCallback or RegisterContinuousAcceleration8BitCallback callbacks.

You can enable the callback for each axis (x, y, z) individually and choose a resolution of 8 bit or 16 bit.

If at least one of the axis is enabled and the resolution is set to 8 bit, the RegisterContinuousAcceleration8BitCallback callback is activated. If at least one of the axis is enabled and the resolution is set to 16 bit, the RegisterContinuousAcceleration16BitCallback callback is activated.

The returned values are raw ADC data. If you want to put this data into a FFT to determine the occurrences of specific frequencies we recommend that you use the data as is. It has all of the ADC noise in it. This noise looks like pure noise at first glance, but it might still have some frequnecy information in it that can be utilized by the FFT.

Otherwise you have to use the following formulas that depend on the configured resolution (8/16 bit) and the full scale range (see SetConfiguration) to calculate the data in g/10000 (same unit that is returned by GetAcceleration):

* 16 bit, full scale 2g: acceleration = value*625/1024 * 16 bit, full scale 4g: acceleration = value*1250/1024 * 16 bit, full scale 8g: acceleration = value*2500/1024

If a resolution of 8 bit is used, only the 8 most significant bits will be transferred, so you can use the following formulas:

* 8 bit, full scale 2g: acceleration = value*256*625/1024 * 8 bit, full scale 4g: acceleration = value*256*1250/1024 * 8 bit, full scale 8g: acceleration = value*256*2500/1024

If no axis is enabled, both callbacks are disabled. If one of the continuous callbacks is enabled, the RegisterAccelerationCallback callback is disabled.

The maximum throughput depends on the exact configuration:

Number of axis enabled| Throughput 8 bit| Throughout 16 bit
--- | --- | ---
1| 25600Hz| 25600Hz
2| 25600Hz| 15000Hz
3| 20000Hz| 10000Hz

Associated constants:

* Resolution8bit
* Resolution16bit

func (*AccelerometerV2Bricklet) SetFilterConfiguration Uses

func (device *AccelerometerV2Bricklet) SetFilterConfiguration(iirBypass IIRBypass, lowPassFilter LowPassFilter) (err error)

Configures IIR Bypass filter mode and low pass filter roll off corner frequency.

The filter can be applied or bypassed and the corner frequency can be half or a ninth of the output data rate.

.. image:: /Images/Bricklets/bricklet_accelerometer_v2_filter.png

:scale: 100 %
:alt: Accelerometer filter
:align: center
:target: ../../_images/Bricklets/bricklet_accelerometer_v2_filter.png

.. versionadded:: 2.0.2$nbsp;(Plugin)

Associated constants:

* IIRBypassApplied
* IIRBypassBypassed
* LowPassFilterNinth
* LowPassFilterHalf

func (*AccelerometerV2Bricklet) SetInfoLEDConfig Uses

func (device *AccelerometerV2Bricklet) SetInfoLEDConfig(config InfoLEDConfig) (err error)

Configures the info LED (marked as Force on the Bricklet) to be either turned off, turned on, or blink in heartbeat mode.

Associated constants:

* InfoLEDConfigOff
* InfoLEDConfigOn
* InfoLEDConfigShowHeartbeat

func (*AccelerometerV2Bricklet) SetResponseExpected Uses

func (device *AccelerometerV2Bricklet) SetResponseExpected(functionID Function, responseExpected bool) error

Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is send and errors are silently ignored, because they cannot be detected.

func (*AccelerometerV2Bricklet) SetResponseExpectedAll Uses

func (device *AccelerometerV2Bricklet) SetResponseExpectedAll(responseExpected bool)

Changes the response expected flag for all setter and callback configuration functions of this device at once.

func (*AccelerometerV2Bricklet) SetStatusLEDConfig Uses

func (device *AccelerometerV2Bricklet) SetStatusLEDConfig(config StatusLEDConfig) (err error)

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

Associated constants:

* StatusLEDConfigOff
* StatusLEDConfigOn
* StatusLEDConfigShowHeartbeat
* StatusLEDConfigShowStatus

func (*AccelerometerV2Bricklet) SetWriteFirmwarePointer Uses

func (device *AccelerometerV2Bricklet) SetWriteFirmwarePointer(pointer uint32) (err error)

Sets the firmware pointer for WriteFirmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

func (*AccelerometerV2Bricklet) WriteFirmware Uses

func (device *AccelerometerV2Bricklet) WriteFirmware(data [64]uint8) (status uint8, err error)

Writes 64 Bytes of firmware at the position as written by SetWriteFirmwarePointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

func (*AccelerometerV2Bricklet) WriteUID Uses

func (device *AccelerometerV2Bricklet) WriteUID(uid uint32) (err error)

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

type BootloaderMode Uses

type BootloaderMode = uint8
const (
    BootloaderModeBootloader                    BootloaderMode = 0
    BootloaderModeFirmware                      BootloaderMode = 1
    BootloaderModeBootloaderWaitForReboot       BootloaderMode = 2
    BootloaderModeFirmwareWaitForReboot         BootloaderMode = 3
    BootloaderModeFirmwareWaitForEraseAndReboot BootloaderMode = 4
)

type BootloaderStatus Uses

type BootloaderStatus = uint8
const (
    BootloaderStatusOK                        BootloaderStatus = 0
    BootloaderStatusInvalidMode               BootloaderStatus = 1
    BootloaderStatusNoChange                  BootloaderStatus = 2
    BootloaderStatusEntryFunctionNotPresent   BootloaderStatus = 3
    BootloaderStatusDeviceIdentifierIncorrect BootloaderStatus = 4
    BootloaderStatusCRCMismatch               BootloaderStatus = 5
)

type DataRate Uses

type DataRate = uint8
const (
    //Deprecated: Use 0_781Hz instead.
    DataRate0781Hz  DataRate = 0
    DataRate0_781Hz DataRate = 0
    //Deprecated: Use 1_563Hz instead.
    DataRate1563Hz  DataRate = 1
    DataRate1_563Hz DataRate = 1
    //Deprecated: Use 3_125Hz instead.
    DataRate3125Hz  DataRate = 2
    DataRate3_125Hz DataRate = 2
    //Deprecated: Use 6_2512Hz instead.
    DataRate62512Hz  DataRate = 3
    DataRate6_2512Hz DataRate = 3
    //Deprecated: Use 12_5Hz instead.
    DataRate125Hz   DataRate = 4
    DataRate12_5Hz  DataRate = 4
    DataRate25Hz    DataRate = 5
    DataRate50Hz    DataRate = 6
    DataRate100Hz   DataRate = 7
    DataRate200Hz   DataRate = 8
    DataRate400Hz   DataRate = 9
    DataRate800Hz   DataRate = 10
    DataRate1600Hz  DataRate = 11
    DataRate3200Hz  DataRate = 12
    DataRate6400Hz  DataRate = 13
    DataRate12800Hz DataRate = 14
    DataRate25600Hz DataRate = 15
)

type FullScale Uses

type FullScale = uint8
const (
    FullScale2g FullScale = 0
    FullScale4g FullScale = 1
    FullScale8g FullScale = 2
)

type Function Uses

type Function = uint8
const (
    FunctionGetAcceleration                        Function = 1
    FunctionSetConfiguration                       Function = 2
    FunctionGetConfiguration                       Function = 3
    FunctionSetAccelerationCallbackConfiguration   Function = 4
    FunctionGetAccelerationCallbackConfiguration   Function = 5
    FunctionSetInfoLEDConfig                       Function = 6
    FunctionGetInfoLEDConfig                       Function = 7
    FunctionSetContinuousAccelerationConfiguration Function = 9
    FunctionGetContinuousAccelerationConfiguration Function = 10
    FunctionSetFilterConfiguration                 Function = 13
    FunctionGetFilterConfiguration                 Function = 14
    FunctionGetSPITFPErrorCount                    Function = 234
    FunctionSetBootloaderMode                      Function = 235
    FunctionGetBootloaderMode                      Function = 236
    FunctionSetWriteFirmwarePointer                Function = 237
    FunctionWriteFirmware                          Function = 238
    FunctionSetStatusLEDConfig                     Function = 239
    FunctionGetStatusLEDConfig                     Function = 240
    FunctionGetChipTemperature                     Function = 242
    FunctionReset                                  Function = 243
    FunctionWriteUID                               Function = 248
    FunctionReadUID                                Function = 249
    FunctionGetIdentity                            Function = 255
    FunctionCallbackAcceleration                   Function = 8
    FunctionCallbackContinuousAcceleration16Bit    Function = 11
    FunctionCallbackContinuousAcceleration8Bit     Function = 12
)

type IIRBypass Uses

type IIRBypass = uint8
const (
    IIRBypassApplied  IIRBypass = 0
    IIRBypassBypassed IIRBypass = 1
)

type InfoLEDConfig Uses

type InfoLEDConfig = uint8
const (
    InfoLEDConfigOff           InfoLEDConfig = 0
    InfoLEDConfigOn            InfoLEDConfig = 1
    InfoLEDConfigShowHeartbeat InfoLEDConfig = 2
)

type LowPassFilter Uses

type LowPassFilter = uint8
const (
    LowPassFilterNinth LowPassFilter = 0
    LowPassFilterHalf  LowPassFilter = 1
)

type Resolution Uses

type Resolution = uint8
const (
    Resolution8bit  Resolution = 0
    Resolution16bit Resolution = 1
)

type StatusLEDConfig Uses

type StatusLEDConfig = uint8
const (
    StatusLEDConfigOff           StatusLEDConfig = 0
    StatusLEDConfigOn            StatusLEDConfig = 1
    StatusLEDConfigShowHeartbeat StatusLEDConfig = 2
    StatusLEDConfigShowStatus    StatusLEDConfig = 3
)

Package accelerometer_v2_bricklet imports 4 packages (graph). Updated 2019-12-09. Refresh now. Tools for package owners.