2
1

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.

Raspberry Pi3のSense HATをNode-REDでLチカさせる

Last updated at Posted at 2017-09-10

はじめに

Raspberry Pi3用のアドオンボードSense HATは、3Dジャイロ、加速度、磁力、温度、気圧、湿度の6センサーと8x8 RGB LEDマトリクス、5ボタンジョイスティックを搭載しています。

Raspberry Pi3のOSであるRaspbianにはNode-REDが搭載されています。RaspbianのNode-REDはSense HAT用のノードが登録されています。これを用いれば簡単にSense HATとの入出力を制御できそうです。まずは手始めにLチカからやってみます。

IoTの環境は以下の通りです。

環境 バージョン
デバイス Raspberry Pi 3 Model B
OS Raspbian Stretch(September 2017)
センサー Sense HAT
node.js v6.11.3
NodeRED v0.17.5

Raspberry Pi3でNode-REDを起動する

Raspberry Piのスタートボタンから、「プログラミング」->「Node-RED」で実行できます。
Node-REDはデフォルトで1880番ポートで動作するため、ブラウザでhttp://[RaspberryPiのIPアドレス]:1880/にアクセスすれば、Node-REDのエディタが表示されます。

さっそくLEDを点灯させてみよう

Node-REDを使ってSense HATのLEDを点灯させることは非常に簡単です。

入力ノードの「inject」とRaspberryPiノードの「Sense HAT」を配置して入出力を結合します。
SenseHAT_LED_01.png

「Sense HAT」ノードのペイロードを文字列に変更して、"Hello,World"を入力します。
SenseHAT_LED_SimpleMessage_02.png

デプロイして、入力ノードのボタンを押下します。
SenseHAT_LED_SimpleMessage_03.png

"Hello,World"という白色の文字列がスクロールしてLEDに表示されます。
LED_HW.gif

文字色を変えたい場合は入力値のmsgにcolorプロパティを追加し、HTMLカラー名、RGB、HEXなどで色を指定すればOKです。

SenseHAT_LED_SimpleMessage_04.png

座標指定でも点灯できます

SenseHATノードの入力に渡すmsg.payloadに、x座標,y座標,色というフォーマットの文字列を渡すと、指定した座標のLEDを任意の色に点灯することができます。
以下のようにカンマ区切りで複数の点灯をまとめて設定できます。座標はハイフンで範囲指定できます。

0-1,0-1,white,3-4,0-1,#FF69B4,6-7,0-1,#FFFF00,
0-1,3-4,#FFA500,3-4,3-4,blue,6-7,3-4,#FFB6C1,
0-1,6-7,#00FF00,3-4,6-7,red,6-7,6-7,#EE82EE

SenseHAT_LED_coordinate_01.png

おわりに

このように、Node-REDを使えば簡単にSense HATでLチカできます。センサーや外部サービスと連携し、それらの状態をLEDで通知することも簡単にできそうです。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?