Arduino集成zigbee無線通訊模塊

1. 硬件清單:php

arduino 101一個(http://www.dfrobot.com.cn/goods-1265.html)html

Dfrobot IO 傳感器擴展板 V7.1(http://www.dfrobot.com.cn/goods-791.html)git

zigbee模塊(深聯創新DL-LN33)兩塊 (https://deeplink.taobao.com/?spm=a1z10.1-c.0.0.XT2LAU)工具

CP2102模塊 USB轉TTL 一個oop

(https://detail.tmall.com/item.htm?id=520311054724&spm=a1z09.2.0.0.Q59lSj&_u=921ii2ufcf2)ui

LED燈一個(http://www.dfrobot.com.cn/goods-83.html)調試

杜邦線若干code

2. 實驗目的:htm

使用 arduino 101 經過串口(pin0-1,rx-tx)鏈接zigbee模塊,arduino使用usb串口線和PC鏈接,這個做爲A端。另外一端爲B,直接使用CP2102模塊鏈接zigbee模塊到PC。在B端PC上使用LN33自帶串口調試工具發送FE 05 91 90 53 0D 01 FF,A端zigbee模塊收到信號,經過串口把數據傳送到arduino,觸發arduino上的LED燈閃爍,而後再把收到的數據輸出到USB串口上。it

3. 組網圖:

4.

代碼:

unsigned char sendCmd[8]={0xfe, 0x05, 0x91, 0x90, 0x14, 0x10, 0x02, 0xff};//LN33 向
int ledPin = 13;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600); //USB serial port
  Serial1.begin(115200); //RX TX serial port

  pinMode(ledPin, OUTPUT);
}

void loop() {

   if (Serial1.available()) {
    digitalWrite(ledPin, HIGH); 

    Serial1.write(sendCmd, 8);
    
//    Serial.println(Serial1.read(),HEX); 
    myPtHex((char)Serial1.read());  
    while(Serial1.available()){
      myPtHex((char)Serial1.read()); 
    }
   }

   delay(100);   
   digitalWrite(ledPin, LOW);
   delay(100);
}

void myPtHex(int g){ // 把 g 最右邊 byte 印成 Hex 倆位
   int a = g& 0xf0;  // 左邊 4 bits
   a = a >> 4;  // 右移 4 bits
   int b = g& 0x0f;  // 右邊 4 bits
   char c = a < 10 ? a + '0' : a + 'A' - 10;
   Serial.print(c);
   c = b < 10 ? b + '0' : b + 'A' - 10;
   Serial.print(c);
}

 

參考:

http://www.arduino.cn/forum.php?mod=viewthread&tid=10858&extra=&highlight=%E8%BD%AF%E4%B8%B2%E5%8F%A3&page=1

arduino官方示例。

相關文章
相關標籤/搜索