0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Nordic nRF52840 で Zigbee 照明とスイッチ

Last updated at Posted at 2020-03-22

前回の「Nordic nRF52840 で Zigbee」
https://qiita.com/nanbuwks/items/a2a357a8ac4db808f19d
では、照明のエンドデバイス を作り、Zigbee コーディネーター として Amazon Echo Plus を用いて遊びました。

今回は Amazon Echo Plus を使わず、3台の nRF52840 デバイスで

  • Zigbee コーディネーター
  • 照明エンドデバイス
  • スイッチエンドデバイス

を構成し、実験します。

環境

  • 開発ボード アオノドン2019(Raytac MDBT50Q / Nordic nRF52840 搭載) Zigbee エンドデバイスとして使用
  • 開発ボード MDBT50Q-DB (Raytac MDBT50Q / Nordic nRF52840 搭載) Zigbee コーディネーター として使用
  • IDE Segger Enbedid Studio
  • 開発PC Ubuntu 18.04LTS
  • SDK nRF5_SDK_for_Thread_and_Zigbee_v4.0.0_dc7186b

プログラム

examplesのzigbeeディレクトリ中に以下がある

├── app_utils
│ └── ws2812
├── experimental
│ ├── cli
│ ├── light_control
│ ├── multi_sensor
│ └── multi_sensor_freertos
├── light_control
│ ├── light_bulb
│ ├── light_coordinator
│ └── light_switch
└── ota
├── bootloader
├── client
└── experimental_server

このうち、以下を使用。

├── light_control
│ ├── light_bulb エンドデバイス・アオノドン2019で実行
│ ├── light_coordinator コーディネーター・MDBT50QDBで実行
│ └── light_switch エンドデバイス・アオノドン2019Fullで実行

照明エンドデバイス

アオノドン2019を使って実装します。
先の記事の通り、プログラムの変更を行って以下のように割当をします。今回はWS2812は接続しません。

プログラム上のシンボル ボード定義 ボード上の機能 GPIO割当 機能
ZIGBEE_NETWORK_STATE_LED BSP_BOARD_LED_2 オンボードLED青 GPIO0.15 Zigbee ネットワーク接続中:点灯
BULB_LED BSP_BOARD_LED_0 オンボードLED赤 GPIO0.13 調光照明として機能

コーディネーター

MDBT50Q DB を使います。プログラムの変更はなしで、IOは以下のように割り当てられています。

プログラム上のシンボル ボード定義 ボード上の機能 GPIO割当 機能
ZIGBEE_NETWORK_STATE_LED BSP_BOARD_LED_2 D3(オンボードLED青) GPIO0.15 Zigbee ネットワーク接続中:点灯
ZIGBEE_NETWORK_REOPEN_BUTTON BSP_BOARD_BUTTON_0 SW1 GPIO0.11 Used to reopen the network.

スイッチエンドデバイス

アオノドン2019を使って実装します。こちらもプログラムの変更は無しで進めます。

LED、ボタンの定義はこのようになっています。

プログラム上のシンボル ボード定義 ボード上の機能 GPIO割当 機能
ZIGBEE_NETWORK_STATE_LED BSP_BOARD_LED_2 オンボードLED青 GPIO0.15 Zigbee ネットワーク接続中:点灯(アオノドン2019では消灯)
BULB_FOUND_LED BSP_BOARD_LED_3 実装なし GPIO0.16 制御するライトを見つけたら点灯(アオノドン2019では消灯)
LIGHT_SWITCH_BUTTON_ON BSP_BOARD_BUTTON_0 / Button 1 黒ボタン GPIO0.11 Button ID used to switch on the light bulb.
LIGHT_SWITCH_BUTTON_OFF BSP_BOARD_BUTTON_1 / Button 2 12SW2ポート(右列ポート8) GPIO0.12 Button ID used to switch off the light bulb.
SLEEPY_ON_BUTTON BSP_BOARD_BUTTON_2 / Button 3 24SW3ポート(右列ポート9) GPIO0.24 Button ID used to determine if we need the sleepy device behaviour (pressed means yes).

このうち、アオノドン2019 は Button2 ( プログラム上では BSP_BOARD_BUTTON_1 ) および Button3 ( プログラム上では BSP_BOARD_BUTTON_2 )に相当するものが実装されておらず、代わりに 12SW2 および 24SW3 と表記したパッドに直接GNDを接触して試してみます。
また、LEDは逆相ですがこのまま進めます。

ロギング用UARTの設定

今回のプログラムでは、ログがUARTポートから出力されるようになっています。
3つのプログラム共、sdk_config.h では以下のように設定されています。


// <o> NRF_LOG_BACKEND_UART_BAUDRATE  - Default Baudrate
 
// <323584=> 1200 baud 
// <643072=> 2400 baud 
// <1290240=> 4800 baud 
// <2576384=> 9600 baud 
// <3862528=> 14400 baud 
// <5152768=> 19200 baud 
// <7716864=> 28800 baud 
// <10289152=> 38400 baud 
// <15400960=> 57600 baud 
// <20615168=> 76800 baud 
// <30801920=> 115200 baud 
// <61865984=> 230400 baud 
// <67108864=> 250000 baud 
// <121634816=> 460800 baud 
// <251658240=> 921600 baud 
// <268435456=> 1000000 baud 

# ifndef NRF_LOG_BACKEND_UART_BAUDRATE
# define NRF_LOG_BACKEND_UART_BAUDRATE 268435456
# endif

となっていて、 1000000 bps に設定されている。

IMG_20200322_210608.jpg

今回写真のように3台を同時にモニターしながら動作させた。
UARTの接続先としてCP2102 USBシリアルモジュールを使ったのだが速度が追いつかなくて文字化けした。フロー制御無しの設定なので、普通はこういうときにはフロー制御を施す。しかし通信のタイミングに影響が出る恐れを考慮し、ボーレートを下げることで対処した。
なお、写真ではCRS/RTS線を接続しているがこの信号は今回は使用しない。


# define NRF_LOG_BACKEND_UART_BAUDRATE 121634816

として、460800 bpsとした。
PC上での受信は以下のようにしてモニター。

 
picocom -b 460800  /dev/ttyUSB1

実行

照明エンドデバイス


<info> app: Set level value: 255
<info> app: Production configuration is not present or invalid (status: -1)
<info> app: Zigbee stack initialized
<info> app: Joined network successfully on reboot signal (Extended PAN ID: f4ce36264cca3f94, PAN ID: 0x2EAB)

スイッチエンドデバイス

<info> app: Production configuration is not present or invalid (status: -1)


<info> app: Zigbee stack initialized


<info> app: Joined network successfully (Extended PAN ID: f4ce36264cca3f94, PAN ID: 0x2EAB)


<info> app: Found bulb addr: 58215 ep: 10

コーディネーター
スイッチエンドデバイスが登録された時点で以下のように出る。


<info> app: Device update received (short: 0x0428, long: f4ce365035f26ad5, status: 0)
<info> app: Device authorization event received (short: 0x0428, long: f4ce365035f26ad5, authorization type: 1, authorization status: 2)
<info> app: New device commissioned or rejoined (short: 0x0428)
<info> app: Joining period extended.

スイッチエンドデバイスとして、Button 2 の代わりにアオノドンの 12SW2 パッド(GPIO0.12)をGNDにショートすると、OFF信号が送信されます。
image.png
以下はスイッチエンドデバイスのログ。


<info> app: Send ON/OFF command: 0

IMG_20200323_002850.jpg

写真は操作を受けて赤LEDが消灯した状態。

スイッチエンドデバイスの Button 1 としてアオノドンの黒ボタンを押すと、ON信号が送信されて、照明エンドデバイスのLED(赤)が点灯します。


<info> app: Send ON/OFF command: 1
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?