Measured results of an XBee wireless sensor device are displayed a LCD on Nucleo board with an XBee coordinator which is in API mode.
Dependencies: TextLCD mbed xbee sample04_sens
Please refer to the following site for the details:
- http://developer.mbed.org/users/bokunimowakaru/code/xbee/wiki/Homepage (English)
- http://www.geocities.jp/bokunimowakaru/diy/xbee/xbee-nucleo.html (Japanese)
Diff: main.cpp
- Revision:
- 7:a3769f9f7dfc
- Parent:
- 5:173a41d73454
- Child:
- 8:a114c798d954
--- a/main.cpp Fri Sep 26 12:44:30 2014 +0000 +++ b/main.cpp Fri Sep 26 13:23:26 2014 +0000 @@ -26,7 +26,7 @@ #include <xbee.h> #include "TextLCD.h" -#define FORCE_INTERVAL 10 // 1~254 データ要求間隔 +#define FORCE_INTERVAL 100 // 1~254 データ要求間隔 TextLCD lcd(PA_9, PC_7, PB_5, PB_4, PB_10, PA_8); // rs, e, d4-d7 byte dev_sens[8]; // IEEE Address @@ -57,37 +57,26 @@ lcd.cls(); // メイン処理 - while(1){ // 永久に受信する + while(1){ // 永久に受信する if(dev_en){ if(trig<=0){ - lcd.locate(12,0); - lcd.printf("Trig"); - wait(0.1); - if(xbee_force(dev_sens)==0){ // デバイスdev_sensへデータ要求 - lcd.locate(10,0); - lcd.printf("Error"); - lcd.locate(14,1); - lcd.printf("%02X",(byte)trig); - } + lcd.locate(12,0); lcd.printf("Trig"); wait(0.1); + xbee_force(dev_sens); // デバイスdev_sensへデータ要求 trig = FORCE_INTERVAL; - lcd.locate(12,0); - lcd.printf(" "); + lcd.locate(12,0); lcd.printf(" "); } }else{ - lcd.cls(); - lcd.printf("Waiting for XBee"); - wait(1); + lcd.cls(); lcd.printf("Waiting for XBee"); + wait(0.5); lcd.cls(); } trig--; /* データ受信(待ち受けて受信する) */ - lcd.locate(14,1); lcd.printf("RX"); - xbee_rx_call( &xbee_result ); // データを受信します。 - lcd.locate(14,1); lcd.printf(" "); - switch( xbee_result.MODE ){ // 受信したデータの内容(MODE値)に応じて - case MODE_RESP: // sensorからの応答の場合に照度と温度を表示 - case MODE_GPIN: // 周期方式でデータ受信した場合も想定 + xbee_rx_call( &xbee_result ); // データを受信します。 + switch( xbee_result.MODE ){ // 受信したデータの内容(MODE値)に応じて + case MODE_RESP: // sensorからの応答の場合に照度と温度を表示 + case MODE_GPIN: // 周期方式でデータ受信した場合も想定 if( bytecmp( dev_sens , &(xbee_result.FROM[0]) ,8 ) == 0 && xbee_result.STATUS == STATUS_OK ){ // 照度測定結果 value = xbee_sensor_result( &xbee_result, LIGHT);