|
1)物料准备
Arduino UNO R3开发板1块 + USB方口线1根
Doit WiFi拓展板1块
公-母杜邦线2根
2)程序烧录
① Doit WiFi拓展板烧录AT固件;
② 将UNO开发板用USB方口线连上电脑,打开Arduino IDE,将程序烧录到UNO开发板上;
[mw_shl_code=cpp,true]#include <SoftwareSerial.h>
//本程序通过再UNO开发板上构造一个软串口(GPIO 10---RX, GPIO 11—TX),
//通过程序实现软串口与硬串口(gpio0-RX,gpio1-TX)即USB接口的数据透传转发功能
//由于WiFi拓展板的串口用杜邦线与UNO开发板的软串口用杜邦线对接,所以实现了两个开发
//板的硬串口(在同等电平幅值下)通过软串口作为中转的透传转发功能。
#define MAX_PACKETSIZE 128
SoftwareSerial softSerial(10, 11); // RX, TX
void doSerialTick()
{
//uartdata
static uint8_t buffSerial[MAX_PACKETSIZE];
static unsigned int buffSerialIndex = 0;
static unsigned long preSerialTime = millis();
uint8_t t = 0;
if (Serial.available()>0)
{
t = Serial.read();
buffSerial[buffSerialIndex++] =t ;
preSerialTime = millis();
if(buffSerialIndex>=MAX_PACKETSIZE - 1){
buffSerialIndex = MAX_PACKETSIZE-2;
preSerialTime = preSerialTime - 100;
}
}
if(buffSerialIndex > 0 && (millis() - preSerialTime >= 50 || t=='\n'))
{//data ready
buffSerial[buffSerialIndex]=0x00;
Serial.flush();
softSerial.write(buffSerial,buffSerialIndex);
buffSerialIndex = 0;
}
}
void dosoftSerialTick()
{
//uartdata
static uint8_t buffsoftSerial[ MAX_PACKETSIZE ];
static unsigned int buffsoftSerialIndex = 0;
static unsigned long presoftSerialTime = millis();
uint8_t t = 0;
if (softSerial.available() >0 )
{
t = softSerial.read();
buffsoftSerial[buffsoftSerialIndex++] = t ;
presoftSerialTime = millis();
if(buffsoftSerialIndex >= MAX_PACKETSIZE - 1){
buffsoftSerialIndex = MAX_PACKETSIZE-2;
presoftSerialTime = presoftSerialTime - 100;
}
}
if(buffsoftSerialIndex > 0 && (millis() - presoftSerialTime >= 50 || t =='\n'))
{//data ready
buffsoftSerial[buffsoftSerialIndex]=0x00;
// softSerial.flush();
Serial.write(buffsoftSerial,buffsoftSerialIndex);
buffsoftSerialIndex = 0;
}
}
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("start");
// set the data rate for the SoftwareSerial port
softSerial.begin(115200);
softSerial.println("AT+UART_DEF=9600,8,1,0,0");
delay(100);
softSerial.begin(9600);
}
void loop() { // run over and over
doSerialTick();
dosoftSerialTick();
}[/mw_shl_code]
3)硬件连接
再将Doit WiFi拓展板直插到UNO板上,在Doit WiFi拓展板上用杜邦线按以下规则连接:
Doit WiFi拓展板的Arduino部分 ---------------------- Doit WiFi拓展板的ESP13部分
(GPIO)11 -------------------------------------------- RX0
(GPIO)10 -------------------------------------------- TX0
具体连接如图:
然后将Doit WiFi拓展板右上角的两个开关拨到“OFF”端;
打开电脑的串口助手,选择对应端口号,
波特率设置为115200;勾上“发送换行”;
4)上电调试
在串口工具的输入窗口中,输入AT+RST,然后点击发送;观察串口接收窗口返回的信息;
例如:
发送复位命令:AT+RST(执行指令)
指令:AT
响应:OK
指令:AT+RST
响应:ready
现象如下:
其他指令同理操作即可;
|
|