nRF5 SDK for Thread and Zigbee v4.0.0
BLE UART and Zigbee Color Dimmer Light Switch Example

Table of Contents

This information applies to the following SoCs: nRF52833 and nRF52840.
This example requires the following SoftDevice: S140

Important: Before you run this example, make sure to program the SoftDevice.

This dynamic multiprotocol example application is based on the Color Dimmer Switch, a Zigbee Home Automation device. This device can turn on and off several compatible light bulbs, dim them, and change their color. With this example, the device supports dynamic switching between two protocols, BLE and Zigbee, at the same time (concurrently). Furthermore, this example makes use of Finding & Binding feature, which allows the device to discover its peers on the network.

This example uses at least three devices:

The light switch device operates through pressing buttons on the DK on the Zigbee network, and through the Nordic UART Service on the BLE network. Both networks are independent from each other. Three different Zigbee Endpoints are instantiated on the light switch (with numbers 1, 2, and 3), with the possibility to trigger Finding & Binding process on each of them.

To support both protocols at the same time, the Zigbee stack uses the 802.15.4 radio during the inactive time of the Bluetooth Low Energy radio (using Timeslot API). Depending on the Bluetooth Low Energy connection interval, the nRF52 SoC can spend up to 99% of the radio time on the Zigbee protocol. This is the same mechanism as the one used in Dynamic multiprotocol examples in Thread.

For more information on multiprotocol operation, refer to the Multiprotocol support with BLE/Bluetooth support section.

Note
  • Transmitting and receiving data does not break connection from any of the used radio protocols, either BLE or Zigbee.
  • Despite being based on the Color Dimmer Switch, the example does not necessarily need a Color Dimmable Bulb to operate. It can cooperate with any Zigbee device that uses On/Off cluster, Level Control cluster, Color Control cluster, or a combination of these clusters.
  • The light switch of this example can be used with the CLI Agent example to establish control with a light bulb.

Setup

You can find the source code in the following folder: <InstallFolder>\examples\multiprotocol\ble_zigbee\ble_zigbee_dynamic_light_switch_nus

To show the basic behavior of the device, you need two other examples that contain a Zigbee coordinator and a Zigbee light bulb. With these two examples, you can control the light bulb (On/Off and Level Control clusters). You can find these examples in Zigbee Light Control example.

Note
You can use the Arudino Joystick shield v1.A with this example. Plug it in the nRF52 Development Kit, define the ARDUINO_JOYSTICK_SHIELD_V1A in code, and control the device using the built-in Joystick.

Assignments

You can control the devices either with the buttons on the development kits or the NUS UART commands in the nRF Toolbox application. The NUS UART commands offer more options than the DK buttons.

LED assignments

The example uses LED assignments as described in Thread BSP LED and button reference for the following LEDs:

The following LEDs reserved for user application purposes are assigned in this example:

Button assignments

The following buttons reserved for user application purposes are assigned in this example:

BLE UART command assignments

The following BLE UART commands are configured in this example:

Command Effect
n Turns on the Zigbee light bulb.
f Turns off the Zigbee light bulb.
t Toggles the Zigbee light bulb on or off.
i Increases the brightness level of the Zigbee light bulb.
d Decreases the brightness level of the Zigbee light bulb.
sn Selects the next Endpoint.
sp Selects the previous Endpoint.
& Starts or stops the Finding & Binding procedure on the currently selected Endpoint.
h[vH]s[vS] Moves the Color Bulb to the desired value of Hue and Saturation, [vH] and [vS] respectively, indicated by decimal values (from 0 to 255).
Example: h25s150.
[v] [v] corresponds to a numeric value between 0 and 999. The command toggles the Zigbee light bulb after [v] seconds.
Example: 33.

Testing

For this example, prepare:

Configuring the boards

To evaluate the example, first configure the boards:

  1. Run the following commands to flash the Zigbee Coordinator example to one of the boards (edit the SoC and PCA numbers if you use nRF52833):
    $ cd <InstallFolder>/examples/zigbee/light_control/light_coordinator/hex
    $ nrfjprog -f nrf52 -r --program nrf52840_xxaa_pca10056.hex --chiperase
  2. Run the following commands to flash the Zigbee dimmable light bulb example to all remaining boards (edit the SoC and PCA numbers if you use nRF52833):
    $ cd <InstallFolder>/examples/zigbee/light_control/light_bulb/hex
    $ nrfjprog -f nrf52 -r --program nrf52840_xxaa_pca10056.hex --chiperase
  3. Build this light switch example according to the instructions in Building examples.
  4. Flash SoftDevice and this light switch example according to the instructions in Running examples.
  5. Turn on all boards as described in Zigbee Light Control example (Testing section, steps 3 to 5).
  6. Press the Finding and Binding button on the light bulb board to start the identifying process on it.
  7. Press the Button 4 on the light switch board to bind the bulb from the previous step to the selected endpoint.
  8. If you have more bulbs available, press Button 3 on the light switch board to switch to the next endpoint. LED4 on the light switch board changes the flashing pattern.
  9. Repeat steps 8-9 to bind the new bulb to the new endpoint.
    Note
    If you have a custom 3rd-party Color Dimmable Light Bulb, commission it to the network and put it into the Identify mode - you could change its color as well.
    The configuration of the boards is now complete.

Interacting with the boards

You can toggle the LED on the light bulb board bound to the currently selected endpoint in the network by pressing Button 1 and Button 2 on the light switch board.

After configuration, you can also start interacting with the boards using the nRF Toolbox application:

  1. On the smartphone, install nRF Toolbox for BLE.
  2. Open nRF Toolbox and select the UART application.
    nrftoolbox_dynamic_zigbee_uart_1.png
    nRF Toolbox - UART application
  3. Tap EDIT.
  4. Configure the following nine application buttons (also listed in the BLE UART command assignments table):
    • Configure command n
    • Configure command f
    • Configure command t
    • Configure command i
    • Configure command d
    • Configure command sn
    • Configure command sp
    • Configure command &
    • Configure command h12s34
      nrftoolbox_dynamic_zigbee_uart_2.png
      nRF Toolbox - UART application - Configure button
  5. When all buttons are configured, tap DONE.
  6. Tap CONNECT and select the Zigbee_Switch light switch device.
    nrftoolbox_dynamic_zigbee_uart_3.png
    nRF Toolbox - UART application after establishing the connection
  7. Observe that LED1 on the multiprotocol light switch board is turned on and stops blinking, which indicates that a BLE connection has been established.
  8. Test the application buttons by pressing the buttons you assigned in the application in step 4:
    • n and f commands: Press the corresponding buttons to turn the LED on the Zigbee light bulb node on and off, respectively.
    • t command: Press the corresponding button two times to toggle the LED on the Zigbee light bulb node on and off.
    • ssn and sp commands: Move through the endpoints with the corresponding buttons.
    • & command: Press the corresponding button to initiate the Finding & Binding procedure.
    • Hue and saturation command: Press the button configured to h12s34 to move to the predefined Hue and Saturation value.
    • i and d commands: Press the corresponding buttons to adjust the brightness level.

Testing the [v] command
To test the delayed toggle command ([v] command in the BLE UART command assignments table), add another button with the numeric command or create a separate configuration (screen).

nrftoolbox_dynamic_zigbee_uart_4.png
nRF Toolbox - Add configuration

For example, you can add buttons to toggle the light bulb after 1 (1 command), 3 (3 command), and 9 (9 command) seconds.

nrftoolbox_dynamic_zigbee_uart_5.png
nRF Toolbox - Delayed toggle commands

Documentation feedback | Developer Zone | Subscribe | Updated