“如何与其它Microduino模块连接”的版本间的差异

来自Microduino Wikipedia
跳转至: 导航搜索
实验方式
第1行: 第1行:
 
==目的==
 
==目的==
*本教程通过对Microduino-Zigbee与其它Microduino模块连接的介绍,方便读者灵活使用Microduino系列产品。
+
*用AT指令调试Microduino-Zigbee模块时,串行通讯口为D2、D3脚。如何连接Microduino-Zigbee模块与其它Microduino模块实现AT指令的调试?本教程给出了三种连接方式,方便读者灵活使用Microduino系列产品。
 +
 
 
==设备==
 
==设备==
 
*'''[[Microduino-Zigbee/zh]]'''
 
*'''[[Microduino-Zigbee/zh]]'''

2014年10月26日 (日) 17:52的版本

目的

  • 用AT指令调试Microduino-Zigbee模块时,串行通讯口为D2、D3脚。如何连接Microduino-Zigbee模块与其它Microduino模块实现AT指令的调试?本教程给出了三种连接方式,方便读者灵活使用Microduino系列产品。

设备

实验方式

Microduino-USBTTL与Microduino-Zigbee

Microduino-USBTTL与Microduino-Zigbee不能直接叠加。 连接方式应为

Microduino-USBTTL Microduino-Zigbee
GND GND
3V3 3V3
RX0 D2
TX1 D3

实物连接见下图

确认导线连接无误后插入USB数据线,然后打开串口调试助手。串口调试助手下载:文件:Com assist.rar 串口调试助手软件界面见下图:

串口如果没有打开,可以点击串口号的列表框按钮查询。发送新行的复选框应该选上对勾。在字符串输入框输入“+++”,点击发送,可以看到Zigbee模块回馈的信息了。 笔者用的波特率是9600。可以输入AT+BAUD=0X设定Zigbee模块的波特率,输入AT+SRST点击发送后重启Zigbee模块可以保存设置值,下次上电无需再设置了。 更多输入指令(AT指令)的含义会在后续文档中介绍。


Microduino-USBTTL与Microduino-Core与Microduino-Zigbee

Microduino-USBTTL与Microduino-Core与Microduino-Zigbee三个模块可以直接叠加。叠加后需要在Microduino-Core的程序中写入程序,用到SoftwareSerial库。 程序如下:

/*
 core hardware(RX0,TX1) =9600
 core software(D2,D3)=9600  must match with cc2530 setup.when change cc2530 baud  rate
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
String myStringSoftCom="";
String myStringHardCom="";
void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() // run over and over
{
     while (Serial.available() > 0)  
    {
      myStringHardCom += char(Serial.read());
      delay(2);
    }
     mySerial.println(myStringHardCom); 
     myStringHardCom="";
     while (mySerial.available() > 0)  
    {
     myStringSoftCom += char(mySerial.read());
     delay (2);
    }
     if (myStringSoftCom.length() > 0)
    {   
         Serial.println(myStringSoftCom);
         myStringSoftCom="";
    }
    delay(100);
}

因为Microduino-core自带重启按钮,通过AT指令设定完参数后,可以点击重启按钮,设置好的参数会自动保存。


Microduino-USBTTL与Microduino-Core+与Microduino-Zigbee

三个模块可以直接叠加。程序如下

String myStringSerial1="";
String myStringSerial="";
void setup()  
{
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() // run over and over
{
     while (Serial.available() > 0)  
    {
      myStringSerial += char(Serial.read());
      delay(2);
    }
     Serial1.println(myStringSerial); 
     myStringSerial="";
     while (Serial1.available() > 0)  
    {
     myStringSerial1 += char(Serial1.read());
     delay(2);
    }
     if (myStringSerial1.length() > 0)
    {   
         Serial.println(myStringSerial1);
         myStringSerial1="";
    }
    delay(100);

}

结果

  • 输入AT指令,在串口调试助手或是Arduino IDE自带的串口中观察数据。调用SoftwareSerial库时,在115200波特率下会有乱码。