========================================================
参考の記事
http://kuc-arc-f.com/agri/?product=product-post-3
========================================================
ARDUINO - RasPi で、シリアル通信行い。
給水指示から、リレー回路のON/OFF行います。
https://github.com/kuc-arc-f/arduino-mc-typ-03b
# リレー回路のON, pythonシリアルserver からのレスポンス解析
リレー開閉時間の設定。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(Serial.available() > 0){ | |
char c = Serial.read(); | |
mResponse3.concat(c); | |
}else{ | |
if(mResponse3.length() > 31){ | |
Serial.print("==== response ==== \n"); | |
String sRes4 = mResponse3.substring( 8 ); | |
Serial.println("res=" + sRes4); | |
Serial.print("==== response.END ==== \n"); | |
struct stParam param; | |
param.stat = sRes4.substring(0,1); | |
param.statCode = sRes4.substring(1,4); | |
param.moi_num = sRes4.substring(4,8); | |
param.vnum_1 = sRes4.substring(8, 9); | |
param.vnum_2 = sRes4.substring(9, 10); | |
param.vnum_3 = sRes4.substring(10,11); | |
param.vnum_4 = sRes4.substring(11,12); | |
param.kai_num_1= sRes4.substring(12,15); | |
param.kai_num_2= sRes4.substring(15,18); | |
param.kai_num_3= sRes4.substring(18,21); | |
param.kai_num_4= sRes4.substring(21,24); | |
Serial.println("stat=" + param.stat); | |
if(param.stat=="1"){ | |
if((param.vnum_1=="1") || (param.vnum_2=="1") || (param.vnum_3=="1") || (param.vnum_4=="1")){ | |
mSTAT =mSTAT_VALVE; | |
mValveGet =param.kai_num_1.toInt(); | |
if(param.vnum_1=="1"){ | |
Serial.print( "vnum_1.STart\n" ); | |
digitalWrite(RELAY_PIN , HIGH); | |
} | |
if(param.vnum_2=="1"){ | |
Serial.print( "vnum_2.STart\n" ); | |
digitalWrite(RELAY_PIN_2 , HIGH); | |
} | |
if(param.vnum_3=="1"){ | |
Serial.print( "vnum_3.STart\n" ); | |
digitalWrite(RELAY_PIN_3 , HIGH); | |
} | |
if(param.vnum_4=="1"){ | |
Serial.print( "vnum_4.STart\n" ); | |
digitalWrite(RELAY_PIN_4 , HIGH); | |
} | |
} | |
} //stat=1 | |
mResponse3=""; | |
} //mResponse3.length | |
} //Serial.available |
# リレー回路のoff, offまでの時間の監視
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String sCt = String(mCtOpen); | |
Serial.println("proc_valve=" + sCt); | |
if(mCtOpen >= mValveGet){ | |
digitalWrite(RELAY_PIN , LOW); | |
digitalWrite(RELAY_PIN_2 , LOW); | |
digitalWrite(RELAY_PIN_3 , LOW); | |
digitalWrite(RELAY_PIN_4 , LOW); | |
mResponse3=""; | |
mSTAT = mSTAT_CONECT; | |
mCtOpen=0; | |
} | |
mCtOpen ++; |
*) 開発者向けのまとめ記事
0 件のコメント:
コメントを投稿