(二十六)msp430进阶:XBee S2(ZigBee)与MSP-EXP430G2 TI Launchpad连接

释放双眼,带上耳机,听听看~!

介绍

(二十六)msp430进阶:XBee S2(ZigBee)与MSP-EXP430G2 TI Launchpad连接

XBee S2模块

 

XBee  (ZigBee) 无线电基于  IEEE 802.15.4  (定义低速率无线个域网(LR-WPAN)的操作的技术标准)标准,它被设计用于点对点等无线通信。

ZigBee  是基于IEEE 802.15.4的规范,用于高级通信协议,用于创建   具有低功率数字无线电的个人局域网

以下是XBee无线电设备的主要功能,

  • 它们工作在2.4 GHz(非许可无线电频段)无线电频率上。
  • 低数据速率(≈250Kbps)。
  • 低功耗(1mW,6mW,250mW等)。
  • 短距离无线通信(90米,750米,1英里等)。

因此,它们用于家庭自动化,无线传感器网络,工业控制,医疗数据收集,楼宇自动化等。 

电路连接图

(二十六)msp430进阶:XBee S2(ZigBee)与MSP-EXP430G2 TI Launchpad连接

XBee电路图连接

 

(二十六)msp430进阶:XBee S2(ZigBee)与MSP-EXP430G2 TI Launchpad连接

XBee路由器(或终端设备)图

 

在这里,我们已将XBee S2连接到MSP-EXP430G2。此API在API模式下配置为协调器,API启用设置为1(您也可以将API启用设置为2,它将使用转义字符和数据)。

协调器接收的数据显示在16×2 LCD上,该LCD与MSP-EXP430G2连接。

另一个XBee设备在API模式下配置为路由器,API启用设置为1(您也可以将API启用设置为2,它将使用转义字符和数据)。对两个XBee设备使用相同的API启用设置。(您也可以在API模式下将此设备配置为终端设备)。

开关连接到路由器(或终端设备)XBee模块的引脚DIO1(模块上的引脚19),引脚配置为数字输入。

电位器给出1.2V并接地到其固定端子,电位器的可变端子连接到路由器(或终端设备)XBee模块的引脚AD2(模块的引脚18),并且引脚配置为模拟输入。

IO采样(IR)速率可以根据应用的要求设置,例如100毫秒。

所有配置和设置均使用Digi International提供的X-CTU软件完成。

路由器(或终端设备)XBee模块根据IR设置定期发送电位计和开关的IO样本。协调器接收此数据,并在MSP-EXP430G2 TI Launchpad中上传Sketch,解析收到的数据并从中提取IO样本信息。

它显示在16×2 LCD上,因此可以验证工作情况。

 

在这里,我们将使用XBee库。虽然该库适用于Arduino,但它也适用于MSP-EXP430G2 TI Launchpad

点击下载库:

提取库并将其添加到Energia IDE的库文件夹路径中。

有关如何将自定义库添加到Enegia IDE并使用其中的示例的信息,请参阅    “基础知识”部分中的“ 将库添加到Energia IDE ”。

在这里,我们通过修改作者给出的用于接收S2模块的IO样本的示例程序来创建。这些修改基本上取代了带LCD的串口进行调试,因为只有一个串口可用,并且在使用软件串口时无法使用。

 

程序

#include <XBee.h>
#include <LiquidCrystal.h>

/* Create object named lcd of the class LiquidCrystal */
LiquidCrystal lcd(10, 9, 8, 14, 13, 12, 11);  /* For 4-bit mode */

XBee xbee = XBee(); /* Create an object named xbee(any name of your choice) of the class XBee */

ZBRxIoSampleResponse ioSamples = ZBRxIoSampleResponse(); 
/* Create an object named ioSamples(any name of your choice) of the class ZBRxIoSampleResponse */

bool lcd_clear = 0;
bool xbee_sample = 1;

void setup() {
  Serial.begin(9600); /* Define baud rate for serial communication */
  xbee.setSerial(Serial); /* Define serial communication to be used for communication with xbee */
  lcd.begin(16,2);  /* Initialize 16x2 LCD */
  lcd.clear();  /* Clear the LCD */
  lcd.setCursor(0,0);  /* Set cursor to column 0 row 0 */
  lcd.print("XBee Demo"); /* Print data on display */
  delay(1000); 
  lcd.clear();
}

void loop() {
  bool analog, digital;
if(lcd_clear)
  {
    lcd.clear();
    lcd_clear = 0;
    xbee_sample = 1;
  }
if(xbee_sample)
  {
    lcd.setCursor(0,0);
    lcd.print("POT : ");
    lcd.setCursor(0,1);
    lcd.print("Switch : ");
    xbee_sample = 0;
  }
  xbee.readPacket(); /* Read until a packet is received or an error occurs */
if(xbee.getResponse().isAvailable()) /* True if response has been successfully parsed and is complete */
  {if(xbee.getResponse().getApiId()==ZB_IO_SAMPLE_RESPONSE) /* If response is of IO_Sample_response type *//* Get the IO Sample Response */
if (ioSamples.containsAnalog()) { /* If Analog samples present in the response */
        analog = 1;
      }else0;
      }
if (ioSamples.containsDigital()) { /* If Digital samples present in the response */
        digital = 1;
      }else0;
      }      
/* Loop for identifying the analog samples present in the received sample data and to print it */if(analog)
      {for (int i = 0; i <= 4; i++) { /* Only 4 Analog channels */if (ioSamples.isAnalogEnabled(i)) { /* Check Analog channel mask to see if the any pin is enabled for analog input sampling */
            lcd.setCursor(6,0);            
            lcd.print(ioSamples.getAnalog(i),DEC);
            lcd.print("   ");
          }
        }
      }else6,0);            
        lcd.print("No Data");
      }

余下程序:

完整程序下载

给TA打赏
共{{data.count}}人
人已打赏
msp430/Arduino-进阶

(二十五)msp430进阶:OLED图形显示器与MSP-EXP430G2 TI Launchpad连接

2019-7-5 22:12:02

PHPoC-PHP编程

(十四)Hello, World! – 使用HTML5 Canvas绘图—PHPoC

2019-1-9 22:03:32

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
'); })();