..
 #############################################################
 # This file was automatically generated on 2015-05-08.      #
 #                                                           #
 # If you have a bugfix for this file and want to commit it, #
 # please fix the bug in the generator. You can find a link  #
 # to the generators git repository on tinkerforge.com       #
 #############################################################

:orphan:
:breadcrumbs: <a href="../../index.html">Home</a> / <a href="../../index.html#software-modbus">Software</a> / Modbus - Load Cell Bricklet

.. |device_identifier_constant| unicode:: 0xA0
   :trim:

.. _load_cell_bricklet_modbus:

Modbus - Load Cell Bricklet
===========================

.. note::
 This Bricklet is currently in the prototype stage and the software/hardware
 as well as the documentation is in an incomplete state.


This is the description of the :ref:`Modbus protocol <llproto_modbus>` for the :ref:`Load Cell Bricklet <load_cell_bricklet>`. General information and technical
specifications for the Load Cell Bricklet are summarized in its :ref:`hardware description
<load_cell_bricklet_description>`.

.. _load_cell_bricklet_modbus_api:

API
---

A general description of the Modbus protocol structure can be found
:ref:`here <llproto_modbus>`.




Basic Functions
^^^^^^^^^^^^^^^



.. modbus:function:: BrickletLoadCell.get_weight

 :functionid: 1
 :emptyrequest: empty payload

 :response weight: int32

 Returns the currently measured weight in grams.
 
 If you want to get the weight periodically, it is recommended 
 to use the callback :modbus:func:`CALLBACK_WEIGHT <BrickletLoadCell.CALLBACK_WEIGHT>` and set the period with 
 :modbus:func:`set_weight_callback_period <BrickletLoadCell.set_weight_callback_period>`.
 
.. modbus:function:: BrickletLoadCell.led_on

 :functionid: 10
 :emptyrequest: empty payload

 :noresponse: no response

 Turns the LED on.
 
.. modbus:function:: BrickletLoadCell.led_off

 :functionid: 11
 :emptyrequest: empty payload

 :noresponse: no response

 Turns the LED off.
 
.. modbus:function:: BrickletLoadCell.is_led_on

 :functionid: 12
 :emptyrequest: empty payload

 :response value: uint8

 Returns *true* if the led is on, *false* otherwise.
 
.. modbus:function:: BrickletLoadCell.tare

 :functionid: 14
 :emptyrequest: empty payload

 :noresponse: no response

 Sets the currently measured weight as tare weight.
 


Advanced Functions
^^^^^^^^^^^^^^^^^^

.. modbus:function:: BrickletLoadCell.set_moving_average

 :functionid: 8
 :request average: uint8

 :noresponse: no response

 Sets the length of a `moving averaging <http://en.wikipedia.org/wiki/Moving_average>`__ 
 for the weight value.
 
 Setting the length to 1 will turn the averaging off. With less
 averaging, there is more noise on the data.
 
 The range for the averaging is 1-40.
 
 The default value is 4.
 
.. modbus:function:: BrickletLoadCell.get_moving_average

 :functionid: 9
 :emptyrequest: empty payload

 :response average: uint8

 Returns the length moving average as set by :modbus:func:`set_moving_average <BrickletLoadCell.set_moving_average>`.
 
.. modbus:function:: BrickletLoadCell.calibrate

 :functionid: 13
 :request weight: uint32

 :noresponse: no response

 To calibrate your Load Cell Bricklet you have to
 
 * empty the scale and call this function with 0 and
 * add a known weight to the scale and call this function with the weight in 
   grams.
 
 The calibration is saved in the EEPROM of the Bricklet and only
 needs to be done once.
 
 We recommend to use the Brick Viewer for calibration, you don't need
 to call this function in your source code.
 
.. modbus:function:: BrickletLoadCell.set_configuration

 :functionid: 15
 :request rate: uint8
 :request gain: uint8

 :noresponse: no response

 The measurement rate and gain are configurable.
 
 The rate can be either 10Hz or 80Hz. A faster rate will produce more noise.
 It is additionally possible to add a moving average
 (see :modbus:func:`set_moving_average <BrickletLoadCell.set_moving_average>`) to the measurements.
 
 The gain can be 128x, 64x or 32x. It represents a measurement range of
 ±20mV, ±40mV and ±80mV respectively. The Load Cell Bricklet uses an
 excitation voltage of 5V and most load cells use an output of 2mV/V. That
 means the voltage range is ±15mV for most load cells (i.e. gain of 128x
 is best). If you don't know what all of this means you should keep it at 
 128x, it will most likely be correct.
 
 The configuration is saved in the EEPROM of the Bricklet and only
 needs to be done once.
 
 We recommend to use the Brick Viewer for configuration, you don't need
 to call this function in your source code.
 
 The default rate is 10Hz and the default gain is 128x.
 
.. modbus:function:: BrickletLoadCell.get_configuration

 :functionid: 16
 :emptyrequest: empty payload

 :response rate: uint8
 :response gain: uint8

 Returns the configuration as set by :modbus:func:`set_configuration <BrickletLoadCell.set_configuration>`.
 
.. modbus:function:: BrickletLoadCell.get_identity

 :functionid: 255
 :emptyrequest: empty payload

 :response uid: char[8]
 :response connected_uid: char[8]
 :response position: char
 :response hardware_version: uint8[3]
 :response firmware_version: uint8[3]
 :response device_identifier: uint16

 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 :ref:`here <device_identifier>`.
 |device_identifier_constant|
 


Callback Configuration Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



.. modbus:function:: BrickletLoadCell.set_weight_callback_period

 :functionid: 2
 :request period: uint32

 :noresponse: no response

 Sets the period in ms with which the :modbus:func:`CALLBACK_WEIGHT <BrickletLoadCell.CALLBACK_WEIGHT>` callback is triggered
 periodically. A value of 0 turns the callback off.
 
 :modbus:func:`CALLBACK_WEIGHT <BrickletLoadCell.CALLBACK_WEIGHT>` is only triggered if the weight has changed since the
 last triggering.
 
 The default value is 0.
 
.. modbus:function:: BrickletLoadCell.get_weight_callback_period

 :functionid: 3
 :emptyrequest: empty payload

 :response period: uint32

 Returns the period as set by :modbus:func:`set_weight_callback_period <BrickletLoadCell.set_weight_callback_period>`.
 
.. modbus:function:: BrickletLoadCell.set_weight_callback_threshold

 :functionid: 4
 :request option: char
 :request min: int16
 :request max: int16

 :noresponse: no response

 Sets the thresholds for the :modbus:func:`CALLBACK_WEIGHT_REACHED <BrickletLoadCell.CALLBACK_WEIGHT_REACHED>` callback. 
 
 The following options are possible:
 
 .. csv-table::
  :header: "Option", "Description"
  :widths: 10, 100
 
  "'x'",    "Callback is turned off"
  "'o'",    "Callback is triggered when the weight is *outside* the min and max values"
  "'i'",    "Callback is triggered when the weight is *inside* the min and max values"
  "'<'",    "Callback is triggered when the weight is smaller than the min value (max is ignored)"
  "'>'",    "Callback is triggered when the weight is greater than the min value (max is ignored)"
 
 The default value is ('x', 0, 0).
 
.. modbus:function:: BrickletLoadCell.get_weight_callback_threshold

 :functionid: 5
 :emptyrequest: empty payload

 :response option: char
 :response min: int16
 :response max: int16

 Returns the threshold as set by :modbus:func:`set_weight_callback_threshold <BrickletLoadCell.set_weight_callback_threshold>`.
 
.. modbus:function:: BrickletLoadCell.set_debounce_period

 :functionid: 6
 :request debounce: uint32

 :noresponse: no response

 Sets the period in ms with which the threshold callback
 
 * :modbus:func:`CALLBACK_WEIGHT_REACHED <BrickletLoadCell.CALLBACK_WEIGHT_REACHED>`
 
 is triggered, if the threshold
 
 * :modbus:func:`set_weight_callback_threshold <BrickletLoadCell.set_weight_callback_threshold>`
 
 keeps being reached.
 
 The default value is 100.
 
.. modbus:function:: BrickletLoadCell.get_debounce_period

 :functionid: 7
 :emptyrequest: empty payload

 :response debounce: uint32

 Returns the debounce period as set by :modbus:func:`set_debounce_period <BrickletLoadCell.set_debounce_period>`.
 


.. _load_cell_bricklet_modbus_callbacks:

Callbacks
^^^^^^^^^

.. modbus:function:: BrickletLoadCell.CALLBACK_WEIGHT

 :functionid: 17

 :response weight: uint32


 This callback is triggered periodically with the period that is set by
 :modbus:func:`set_weight_callback_period <BrickletLoadCell.set_weight_callback_period>`. The response value is the weight
 as measured by the load cell.
 
 :modbus:func:`CALLBACK_WEIGHT <BrickletLoadCell.CALLBACK_WEIGHT>` is only triggered if the weight has changed since the
 last triggering.
 
.. modbus:function:: BrickletLoadCell.CALLBACK_WEIGHT_REACHED

 :functionid: 18

 :response weight: int16


 This callback is triggered when the threshold as set by
 :modbus:func:`set_weight_callback_threshold <BrickletLoadCell.set_weight_callback_threshold>` is reached.
 The response value is the weight as measured by the load cell.
 
 If the threshold keeps being reached, the callback is triggered periodically
 with the period as set by :modbus:func:`set_debounce_period <BrickletLoadCell.set_debounce_period>`.
 


