工業製造
産業用モノのインターネット | 工業材料 | 機器のメンテナンスと修理 | 産業プログラミング |
home  MfgRobots >> 工業製造 >  >> Manufacturing Technology >> 製造プロセス

SmartThingsThingShieldを使用したIRブリッジの構築

コンポーネントと消耗品

>
Arduino UNO
× 1
SmartThings Shield for Arduino
× 1
IR発光LED
× 1
IRレシーバーダイオード
× 1
100オーム抵抗(オプション)
× 1

このプロジェクトについて

はじめに

シンプルなテレビのリモコンは、SmartThingsクラウドに接続すると、チャンネルを変更することができます。部品点数が少なく、すぐに利益が得られるこのプロジェクトは、プラットフォームを探索するための良い方法です。

ArduinoとThingShieldの背景

SmartThings ThingShieldを使用すると、Arduinoを使用してSmartThingsプロトタイプを簡単に作成できます。シールドは、Zigbeeプロトコルを介してSmartThingsハブにリンクしているUNOに直接接続します。シールドのスイッチを使用すると、ピン0、1、または2、3を使用してArduinoと通信するかどうかを選択できます。 ThingShieldはすでにピン6の使用を予約しています。

Arudinoの使用を開始する方法の詳細については、http://arduino.cc/en/Guide/Introduction

を参照してください。

ステップ1:必要になります

  • (x1)SmartThings Arduino ThingShield
  • (x1)Arduino Uno
  • (x1)IRレシーバー
  • (x1)IR発光LED
  • (x1)100オーム抵抗(オプション)


ステップ2:IRライブラリをダウンロードする

このプロジェクトは、KenShirriffによって開発された素晴らしいArduinoライブラリに依存しています。 https://github.com/shirriff/Arduino-IRremote

通常の方法でライブラリArduinoライブラリをインストールします。

http://arduino.cc/en/Guide/Libraries

インストールしたら、ピン9のタイマーを使用するようにIRRemoteInt.hを変更する必要があります。この例では、ThingShieldとの通信にピン3を使用しています。


ステップ3:Arduinoスケッチ

次に、スケッチをArduinoボードにアップロードします(コードセクションを参照)。


ステップ4:ビルド

ビルドはシンプルで簡単です。まず、Arduinoの上にThingShieldを接続します。下の図にはArduinoのみが示されていますが、ピンの配置はシールドが取り付けられている場合と同じです。

IRレシーバーの場合、対応するピンをアースと5Vに接続します。次に、データピンをArduinoピン11に接続します。IR発光LEDをピン9とアースに接続します。 LEDは信号を送信するために高速で点滅するため、Arduinoからの最大電流を処理できる可能性が高いため、この設計では100オームの抵抗はオプションです。継続的にオンにすると、同じ電流でLEDが切れてしまう可能性があります。


ステップ5:カスタムSmartThingsデバイスタイプの作成

次に、SmartThings IDEで、ThingShield用の新しいデバイスタイプを作成します。

[マイデバイスタイプ]セクションに移動し、右側の[新しいスマートデバイス]をクリックします。

新しいSmartDeviceを作成するには、2つの手順が必要です。まず、新しいデバイスタイプに上部の「IrBridge」に名前を付けます。後でSmartAppコードでSmartDeviceの名前を参照することに注意してください。

デバイスの属性(変数)とコマンド(関数)を定義する必要があります。このチュートリアルでは、2つのプログラム可能なボタンと1つの記録ボタンの属性とコマンドを作成します。示されている各属性とコマンドを追加します。 「作成」を選択して、デバイスのコーディングを続行します。

次に、デバイス定義をIDEのコードウィンドウにコピーします(コードセクションを参照)。上部の[保存]ボタンをクリックし、[公開]をクリックしてデバイスを利用できるようにします。


ステップ6:ThingShieldを新しいデバイスタイプに更新する

まだセットアップされていない場合は、ThingShieldをSmartThingsハブに追加してください。デバイスをペアリングするには、ThingShieldをArudinoに接続し、電源を入れます。シールドの「スイッチ」ボタンを6秒間押し続けます。 SmartThingsスマートフォンアプリで、[追加]ボタンを選択します。物理的な「スイッチ」ボタンをもう一度押すと、ハブがThingShieldを識別するのがわかります。

戻って、IDEで、ホーム画面の「デバイス」をクリックしてArduinoThingShieldに移動します。リストからデバイスを選択し、ページの下部にある[編集]ボタンをクリックします。 「タイプ」ドロップダウンメニューから、作成した新しいスマートデバイスタイプを選択します。後でデバイスを選択する必要がある場合は、デバイスに意味のあるラベル名を付けると便利です。更新を押して、デバイスを新しいデバイスタイプに設定します。

将来、カスタムデバイスタイプの更新を公開するときは、公開された更新後も、物理デバイスが正しいデバイスタイプに関連付けられたままであることを確認するために戻ってくる必要があることに注意してください。


ステップ7:SmartThingsアプリの作成

プロジェクトには、SmartApp自体というもう1つのコードがあります。 「MySmartApps」に移動し、右側のボタンをクリックして「NewSmartApp」を開始します。名前、説明、カテゴリ(「マイアプリ」)を付けます。 [作成]をクリックして、アプリのコーディングを続行します。

smartAppコードをコピーします(コードセクションを参照)。 [保存]を選択し、[公開]をクリックして、Smartthings iOSまたはAndroid(近日公開)アプリでSmartAppを利用できるようにします。

SmartDeviceタイプを「IrBridge」という名前で参照していることに注意してください。元々「IrBridge」という名前で使用していた元のスペースはありません。

 input "irDevice"、 "device.IrBridge" 

この行では、SmartAppで選択するオプションとして「IrBridge」タイプのデバイスのみを表示できます。使用されるキャメルケースは非常に特殊です。スマートアプリでデバイスタイプを参照する場合、名前からスペースが削除されます。最初の文字と元々スペースに続く文字は大文字になります。元の大文字と小文字に関係なく、他のすべては小文字です。


ステップ8:SmartAppを有効にする

SmartThingsスマートフォンアプリ内で、新しいSmartAppを新しいIRデバイスに関連付け、制御するスイッチを選択します。次に、[インストール]をクリックします。

アプリの各ボタンをプログラムするには、タイルの隅にある歯車をクリックして、タイルの詳細に移動します。大きな録音ボタンを選択します–それはあなたが録音モードにあることを示すために赤に変わります。次に、制御するタイル(再生/一時停止またはB)をクリックします。黄色に変わります。リモコンをThingShieldに向け、学習したいボタンを押します。 ThingShieldはそのコードをSmartThingsクラウドに送信し、SmartAppで選択したボタンに関連付けます。新しくプログラムされたボタンが緑色に変わり、録音ボタンが白色に戻ります。

次にリモコンのそのボタンを押すと、SmartAppのボタンに関連付けたスイッチが切り替わります。

コード

  • Arduinoスケッチ
  • デバイスの定義
  • smartAppコード
Arduinoスケッチ C / C ++
 // ********************************************* ******************************** /// @file /// @brief /// Arduino SmartThings IR Shield / / ************************************************* ****************************#include  //奇妙なワイヤー言語リンカーのため、TODOを設定する必要があります。このライブラリ全体をsmartthingsに吸収します#include  #include  // *************************** ************************************************** //ピンの定義| | | | | | | | | | | | | | | | | | | | | | | | | | | | | // VVVVVVVVVVVVVVVVVVVVV VVVVVVVV // ******************************************* **********************************#define PIN_LED 13#define PIN_RECV 11#define PIN_THING_RX 3#define PIN_THING_TX 2 // ************************************************ ***************************** //グローバル変数| | | | | | | | | | | | | | | | | | | | | | | | | | | | | // VVVVVVVVVVVVVVVVVVVVV VVVVVVVV // ******************************************* ********************************** SmartThingsCallout_t messageCallout; //関数forwarddecalarationSmartThings smartthing(PIN_THING_RX、PIN_THING_TX、messageCallout);を呼び出します。 // Constructorbool isDebugEnabled; //このexampleintstateLEDでデバッグを有効または無効にします。 // LEDIRrecvの最後の設定値を追跡する状態irrecv(PIN_RECV); IRsend irsend; decode_results結果; // *************************** ************************************************** // API関数| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | // VVVVVVVVVVVVVVVVVVVVV VVVVVVVVV // ******************************************* ********************************** void setup(){//グローバル変数のデフォルト状態を設定しますisDebugEnabled =true; stateLED =0; //以下に設定されているハードウェアピンの状態に一致します//ハードウェアピンを設定しますpinMode(PIN_LED、OUTPUT); // PIN_LEDを出力として定義digitalWrite(PIN_LED、LOW); //値をLOW(オフ)に設定してstateLED =0に一致させますif(isDebugEnabled){//デバッグシリアルポートを設定しますSerial.begin(9600); //ボーレート9600でシリアルを設定しますSerial.println( "setup .."); //開始時に「setup ..」を出力します} irrecv.enableIRIn(); //レシーバーを起動します} // ****************************************** *********************************** void loop(){// smartthingロジックを実行smartthing.run(); if(irrecv.decode(&results)){blue(); irrecv.resume(); //次の値を受け取りますSerial.println(results.value、HEX); // dump(&results); //例:smartthing.send( "HEX、XXXCODE");文字列irCmd; if(results.decode_type ==NEC){irCmd =String(results.value、HEX)+ "、" + "NEC" + String(results.bits、DEC)+ ":" + String(results.value、HEX); } else if(results.decode_type ==SONY){irCmd =String(results.value、HEX)+ "、" + "SNY" + String(results.bits、DEC)+ ":" + String(results.value、 HEX); } else if(results.decode_type ==RC5){irCmd =String(results.value、HEX)+ "、" + "RC5" + String(results.bits、DEC)+ ":" + String(results.value、 HEX); } else if(results.decode_type ==RC6){irCmd =String(results.value、HEX)+ "、" + "RC6" + String(results.bits、DEC)+ ":" + String(results.value、 HEX); } else {irCmd =String(results.value、HEX)+ "、" + "RAW" + String(results.bits、DEC)+ ":"; } Serial.println(irCmd); smartthing.send(irCmd); irCmd =""; }} // ********************************************** ******************************* void messageCallout(String message){smartthing.shieldSetLED(0、0、0); //デバッグが有効になっている場合は、受信したメッセージを出力しますif(isDebugEnabled){Serial.print( "Rx: '"); Serial.print(メッセージ); Serial.println( "'"); }文字列型=message.substring(0,3); int startCode =message.indexOf( ':');文字列lenStr =message.substring(3、startCode);文字列codeStr =message.substring(startCode + 1);符号なしの長いコード。 // 16進文字列を長いunsignedに変換しますif(type!="RAW")code =stringToNum(codeStr、16); // RAWでは機能しませんintlen =stringToNum(lenStr、10); //タイプごとに-NEC、SON、PAN、JVC、RC5、RC6など...最初の3 if(type =="NEC"){Serial.println( "NEC-SEND"); Serial.println(len); Serial.println(code、HEX); irsend.sendNEC(code、len); irrecv.enableIRIn(); } else if(type =="SNY"){irsend.sendSony(code、len); irrecv.enableIRIn(); } else if(type =="RC5"){irsend.sendRC5(code、len); irrecv.enableIRIn(); } else if(type =="RC6"){irsend.sendRC6(code、len); irrecv.enableIRIn(); }} // decode_results構造体をダンプします。//IRrecv ::decode()の後にこれを呼び出します// void *コンパイラの問題を回避します// voiddump(void * v){// decode_results * results =(decode_results *) vvoid dump(decode_results * results){int count =results-> rawlen; if(results-> decode_type ==UNKNOWN){Serial.print( "Unknown encoding:"); } else if(results-> decode_type ==NEC){Serial.print( "デコードされたNEC:"); } else if(results-> decode_type ==SONY){Serial.print( "Decoded SONY:"); } else if(results-> decode_type ==RC5){Serial.print( "デコードされたRC5:"); } else if(results-> decode_type ==RC6){Serial.print( "Decoded RC6:"); } else if(results-> decode_type ==PANASONIC){Serial.print( "Decoded PANASONIC-アドレス:"); Serial.print(results-> panasonicAddress、HEX); Serial.print( "値:"); } else if(results-> decode_type ==JVC){Serial.print( "Decoded JVC:"); } Serial.print(results-> value、HEX); Serial.print( "("); Serial.print(results-> bits、DEC); Serial.println( "bits)"); Serial.print( "Raw("); Serial.print(count、DEC); Serial.print( "):"); for(int i =0; i  rawbuf [i] * USECPERTICK、DEC); } else {Serial.print(-(int)results-> rawbuf [i] * USECPERTICK、DEC); } Serial.print( ""); } Serial.println( "");} // ***************************************** *************************************** //ローカル関数| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | // VVVVVVVVVVVVVVVVVVVVV VVVVVVVVV // ******************************************* ********************************** unsigned long stringToNum(String s、int base)// 10(10進数)、 16(hex {unsigned long i =0の場合); unsigned long value =0; unsigned long place =s.length(); char c; unsigned long sign =1; for(i; i  ='0' &&c <='9')// 0から9 {値+ =(c-'0 ')* exponent(base、place); } else if(c> ='A' &&((c-'A '+ 10) ='a' &&(c-'a '+ 10) 
デバイス定義 Groovy
 / ** * Smart Ir * *作成者:[email protected] *日付:2013-03-06 * / metadata {//シミュレータメタデータシミュレータ{} // UIタイル定義タイル{standardTile( "recStatus"、 "device.recStatus"、width:2、height:2、canChangeIcon:true、canChangeBackground:true){state "off"、label: 'record'、action: "record"、backgroundColor: "#ffffff" state "on" 、label: 'record'、action: "record"、backgroundColor: "#ff0000"} //これはセカンダリタイルです// set、unset、prog --green、white、yellow standardTile( "buttonA"、 "device.buttonAStatus "、幅:1、高さ:1、canChangeIcon:true、canChangeBackground:true){状態" unset "、ラベル: ''、アクション:" buttonA "、アイコン:" st.custom.buttons.play-pause "、backgroundColor : "#cccccc" //灰色の状態 "prog"、ラベル: ''、アクション: "buttonA"、アイコン: "st.custom.buttons.play-pause"、backgroundColor: "#FDE910" //黄色の状態 "set "、ラベル: ''、アクション:" buttonA "、アイコン:" st.custom.buttons.play-pause "、backgroundColor:"#79b821 "//緑} // set、unset、prog --green、white、yellow standardTile( "buttonB"、 "device.buttonBStatus"、width:1、height:1、canChangeIcon:true、canChangeBackground:true){state "unset"、label: ''、アクション: "buttonB"、アイコン: "st.custom.buttons.b"、backgroundColor: "#cccccc" //灰色の状態 "prog"、ラベル: ''、アクション: "buttonB"、アイコン: "st .custom.buttons.b "、backgroundColor:"#FDE910 "//黄色の状態" set "、ラベル: ''、アクション:" buttonB "、アイコン:" st.custom.buttons.b "、backgroundColor:"#79b821 "//緑} //可能なメインタイルmain([" buttonA "、" buttonB "])//これは複数のタイルの詳細の配列です([" recStatus "、" buttonA "、" buttonB "])}} / /着信デバイスメッセージを解析してイベントを生成しますdefparse(String description){log.trace "parse:" def value =zigbee.parse(description)?. text def codeParts =value.split(/、/)log.trace "code: $ {codeParts [0]} "// [0]は16進数、[1]は[1]の//再送、最初の3文字は型、その後にコードif(device.currentValue(" recStatus ") =="on")//レコードモード{log.trace "record enabled" if(device.currentValue( "lastButton")!=""){log.trace "最後のボタンがアクティブです" def buttonStatus ="$ {device。 currentValue( "lastButton")}ステータス "; def buttonHex ="$ {device.currentValue(" lastButton ")} Hex"; def buttonCode ="$ {device.currentValue(" lastButton ")} Code"; def result =[createEvent(name:buttonStatus、value: "set"、isStateChange:true)//ボタンを緑色に変える、createEvent(name:buttonHex、value:codeParts [0]、isStateChange:true)//コードを保存するcreateEvent(name:buttonCode、value:codeParts [1]、isStateChange:true)//コードを保存します、createEvent(name: "recStatus"、value: "off"、isStateChange:true)、createEvent(name: "lastButton"、 value: ""、isStateChange:true)//最後のボタンをリセット]結果を返す} else {log.trace "ボタンが選択されていません"}} else {//そうでない場合//ボタンと一致するかどうかを確認if(codeParts [ 0] ==device.currentValue( "buttonAHex")){// buttonAに関連するイベントを送信defresult =createEvent(name: "button"、value: "A"、isStateChange:true)log.debug "Parseが$を返しました{result?.descriptionText} "return result} else if(codeParts [0] ==device.currentValue(" buttonBHex ")){// buttonBに関連するイベントを送信defresult =createEvent(name:" button "、値: "B"、isStateChange:true)log.debug "解析が$ {result?.descriptionText}を返しました" return result}} def result =createEvent(name:null、value: "")return result} def record(){ //レコードモードに入るlog.debug "RecordMode change from $ {device.currentValue(" recStatus ")}" clearLast()//最後のボタンをクリアする//属性をオン/オフに切り替えるif(device.currentValue( "recStatus") =="on"){sendEvent(name: "recStatus"、value: "off"、isStateChange:true)//タイルの色が白に変わります} else {sendEvent(name: "recStatus"、value: "on"、isStateChange :true)//タイルの色が赤に変わります}} def buttonA(){log.debug "ButtonA Pressed" if(device.currentValue( "recStatus")=="on")//記録モードの場合、ボタンをに設定しますプログラムされる{clearLast()log.debug "ボタンAをプログラミングモードにする" // lastTile属性をtileAに設定//黄色に変更sendEvent(name: "buttonAStatus"、value: "prog"、isStateChange:true)sendEvent(name : "lastButton"、value: "buttonA"、isStateChange:true)} else if(device.cu rrentValue( "buttonAStatus")=="set")//設定されている場合は、保存されているコードを送信します{log.debug "Send buttonA Code" //リモートコードをブラスターに送信しますzigbee.smartShield(text: "$ {device .currentValue( "buttonACode")} ")。format()} else {log.debug"ボタンは現在$ {device.currentValue( "buttonAStatus")} "}} def buttonB(){clearLast()log.debug" ButtonBが押されました "if(device.currentValue(" recStatus ")==" on ")//記録モードの場合、プログラムするボタンを設定します{log.debug"プログラミングモードにボタンを置きます "// lastTile属性をtileAに設定します//黄色に変更sendEvent(name: "buttonBStatus"、value: "prog"、isStateChange:true)sendEvent(name: "lastButton"、value: "buttonB"、isStateChange:true)} else if(device.currentValue( " buttonBStatus ")==" set ")//設定されている場合は、保存されているコードを送信します{log.debug" Send buttonB Code "//リモートコードをブラスターに送信しますzigbee.smartShield(text:" $ {device.currentValue( "buttonBCode")} ")。format()} else if(device.currentValue(" buttonBStatus ")==" unset "){log.d ebug "ボタンは現在設定されていません"}} def clearLast(){if(device.currentValue( "lastButton")!=""){sendEvent(name: "$ {device.currentValue(" lastButton ")}"、value: "unset"、isStateChange:true)sendEvent(name: "lastButton"、value: ""、isStateChange:true)}} 
smartAppコード Groovy
 / ** * IRレシーバー**作成者:[email protected] *日付:2013-03-31 * / Preferences {section( "IRデバイスを選択..."){input "irDevice"、 "device .IrBridge "} section("ボタンAがオンまたはオフになります... "){input" switch1、 "capability.switch"、title: "This light"、required:false} section( "ボタンBがオンまたはオフになります... "){input" switch2 "、" capability.switch "、title:" This light "、required:false}} def installed(){log.debug" Installed with settings:$ {settings} "subscribe(irDevice 、 "button.B"、handleB)subscribe(irDevice、 "button.A"、handleA)} def updated(){log.debug "Updated with settings:$ {settings}" unsubscribe()subscribe(irDevice、 "button。 B "、handleB)subscribe(irDevice、" button.A "、handleA)} def handleA(evt){log.debug"受信ボタンA "if(switch1.currentValue(" switch ")==" on "){switch1 .off()} else {switch1.on()}} def handleB(evt){log.debug "received button B" if(switch2.currentValue( "switch")=="on"){ switch2.off()} else {switch2.on()}} 

製造プロセス

  1. RaspberryPiとPythonを使用したロボットの構築
  2. RaspberryPiでセグウェイを構築する
  3. データをどうすればいいですか?!
  4. Arduinoで水滴をキャプチャする
  5. K30センサーによるCO2モニタリング
  6. 1Sheeld / Arduinoとの盲ろう者のコミュニケーション
  7. Arduinoでコインアクセプターを制御する
  8. LEDを制御するBluetoothを搭載したArduino!
  9. Arduinoクラウドでどこからでもあなたの家の温度を知る!
  10. ArduinoでMAX30100ウェアラブルパルスセンサーを使用する
  11. インテリジェントな自動化による従業員体験の未来の構築