..
 #############################################################
 # 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       #
 #############################################################


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

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

.. _led_strip_bricklet_modbus:

Modbus - LED Strip Bricklet
===========================

This is the description of the :ref:`Modbus protocol <llproto_modbus>` for the :ref:`LED Strip Bricklet <led_strip_bricklet>`. General information and technical
specifications for the LED Strip Bricklet are summarized in its :ref:`hardware description
<led_strip_bricklet_description>`.

.. _led_strip_bricklet_modbus_api:

API
---

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




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



.. modbus:function:: BrickletLEDStrip.set_rgb_values

 :functionid: 1
 :request index: uint16
 :request length: uint8
 :request r: uint8[16]
 :request g: uint8[16]
 :request b: uint8[16]

 :noresponse: no response

 Sets the *rgb* values for the LEDs with the given *length* starting 
 from *index*.
 
 The maximum length is 16, the index goes from 0 to 319 and the rgb values
 have 8 bits each.
 
 Example: If you set
 
 * index to 5,
 * length to 3,
 * r to [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 * g to [0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] and
 * b to [0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 
 the LED with index 5 will be red, 6 will be green and 7 will be blue.
 
 .. note:: Depending on the LED circuitry colors can be permuted.
 
 The colors will be transfered to actual LEDs when the next
 frame duration ends, see :modbus:func:`set_frame_duration <BrickletLEDStrip.set_frame_duration>`.
 
 Generic approach: 
 
 * Set the frame duration to a value that represents
   the number of frames per second you want to achieve. 
 * Set all of the LED colors for one frame.
 * Wait for the :modbus:func:`CALLBACK_FRAME_RENDERED <BrickletLEDStrip.CALLBACK_FRAME_RENDERED>` callback.
 * Set all of the LED colors for next frame.
 * Wait for the :modbus:func:`CALLBACK_FRAME_RENDERED <BrickletLEDStrip.CALLBACK_FRAME_RENDERED>` callback.
 * and so on.
 
 This approach ensures that you can change the LED colors with
 a fixed frame rate.
 
 The actual number of controllable LEDs depends on the number of free
 Bricklet ports. See :ref:`here <led_strip_bricklet_ram_constraints>` for more
 information. A call of :modbus:func:`set_rgb_values <BrickletLEDStrip.set_rgb_values>` with index + length above the
 bounds is ignored completely.
 
.. modbus:function:: BrickletLEDStrip.get_rgb_values

 :functionid: 2
 :request index: uint16
 :request length: uint8

 :response r: uint8[16]
 :response g: uint8[16]
 :response b: uint8[16]

 Returns the rgb with the given *length* starting from the
 given *index*.
 
 The values are the last values that were set by :modbus:func:`set_rgb_values <BrickletLEDStrip.set_rgb_values>`.
 
.. modbus:function:: BrickletLEDStrip.set_frame_duration

 :functionid: 3
 :request duration: uint16

 :noresponse: no response

 Sets the frame duration in ms.
 
 Example: If you want to achieve 20 frames per second, you should
 set the frame duration to 50ms (50ms * 20 = 1 second). 
 
 For an explanation of the general approach see :modbus:func:`set_rgb_values <BrickletLEDStrip.set_rgb_values>`.
 
 Default value: 100ms (10 frames per second).
 
.. modbus:function:: BrickletLEDStrip.get_frame_duration

 :functionid: 4
 :emptyrequest: empty payload

 :response duration: uint16

 Returns the frame duration as set by :modbus:func:`set_frame_duration <BrickletLEDStrip.set_frame_duration>`.
 
.. modbus:function:: BrickletLEDStrip.get_supply_voltage

 :functionid: 5
 :emptyrequest: empty payload

 :response voltage: uint16

 Returns the current supply voltage of the LEDs. The voltage is given in mV.
 
.. modbus:function:: BrickletLEDStrip.set_clock_frequency

 :functionid: 7
 :request frequency: uint32

 :noresponse: no response

 Sets the frequency of the clock in Hz. The range is 10000Hz (10kHz) up to
 2000000Hz (2MHz).
 
 The Bricklet will choose the nearest achievable frequency, which may
 be off by a few Hz. You can get the exact frequency that is used by
 calling :modbus:func:`get_clock_frequency <BrickletLEDStrip.get_clock_frequency>`.
 
 If you have problems with flickering LEDs, they may be bits flipping. You
 can fix this by either making the connection between the LEDs and the
 Bricklet shorter or by reducing the frequency.
 
 With a decreasing frequency your maximum frames per second will decrease
 too.
 
 The default value is 1.66MHz.
 
 .. note::
  The frequency in firmware version 2.0.0 is fixed at 2MHz.
 
 .. versionadded:: 2.0.1~(Plugin)
 
.. modbus:function:: BrickletLEDStrip.get_clock_frequency

 :functionid: 8
 :emptyrequest: empty payload

 :response frequency: uint32

 Returns the currently used clock frequency as set by :modbus:func:`set_clock_frequency <BrickletLEDStrip.set_clock_frequency>`.
 
 .. versionadded:: 2.0.1~(Plugin)
 
.. modbus:function:: BrickletLEDStrip.set_chip_type

 :functionid: 9
 :request chip: uint16

 :noresponse: no response

 Sets the type of the led driver chip. We currently support
 the chips
 
 * WS2801 (``chip`` = 2801),
 * WS2811 (``chip`` = 2811) and
 * WS2812 (``chip`` = 2812).
 
 The WS2812 is sometimes also called "NeoPixel", a name coined by
 Adafruit.
 
 The default value is WS2801 (``chip`` = 2801).
 
 .. versionadded:: 2.0.2~(Plugin)
 
.. modbus:function:: BrickletLEDStrip.get_chip_type

 :functionid: 10
 :emptyrequest: empty payload

 :response chip: uint16

 Returns the currently used chip type as set by :modbus:func:`set_chip_type <BrickletLEDStrip.set_chip_type>`.
 
 .. versionadded:: 2.0.2~(Plugin)
 


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

.. modbus:function:: BrickletLEDStrip.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|
 


.. _led_strip_bricklet_modbus_callbacks:

Callbacks
^^^^^^^^^

.. modbus:function:: BrickletLEDStrip.CALLBACK_FRAME_RENDERED

 :functionid: 6

 :response length: uint16


 This callback is triggered directly after a new frame is rendered.
 
 You should send the data for the next frame directly after this callback
 was triggered.
 
 For an explanation of the general approach see :modbus:func:`set_rgb_values <BrickletLEDStrip.set_rgb_values>`.
 


