ESP8266 一块
TTL转RS485模块 一个
上代码
#include <SoftwareSerial.h>
#define MYPORT_TX D5
#define MYPORT_RX D6
unsigned char item0[8] = {0x01, 0x06, 0x20, 0x01, 0x03, 0xE8, 0xD3, 0x74}; //频率为10HZ
unsigned char item1[8] = {0x01, 0x06, 0x20, 0x01, 0x07, 0xD0, 0xD0, 0x66}; //频率为20HZ
unsigned char item2[8] = {0x01, 0x06, 0x20, 0x01, 0x0B, 0xB8, 0xD4, 0x88}; //频率为30HZ
unsigned char item3[8] = {0x01, 0x06, 0x20, 0x01, 0x0F, 0xA0, 0xD6, 0x42}; //频率为40HZ
unsigned char item4[8] = {0x01, 0x06, 0x20, 0x01, 0x13, 0x88, 0xDE, 0x9C}; //频率为50HZ
unsigned char item5[8] = {0x01, 0x06, 0x20, 0x00, 0x00, 0x02, 0x03, 0xCB}; //指令为RUN
unsigned char item6[8] = {0x01, 0x06, 0x20, 0x00, 0x00, 0x01, 0x43, 0xCA}; //指令为STOP
unsigned char item7[8] = {0x01, 0x06, 0x20, 0x00, 0x00, 0x30, 0x82, 0x1E}; //指令为PWD/REV
String data = ""; // 接收到的16进制字符串
SoftwareSerial mySerial;
void setup()
{
mySerial.begin(9600, SWSERIAL_8N2, MYPORT_TX, MYPORT_RX, false);
Serial.begin(115200);
mySerial.listen(); //开启软串口监听
}
void loop()
{
delay(500); // 放慢输出频率
for (int i = 0 ; i < 8; i++) { // 发送命令
mySerial.write(item4[i]); // write输出
}
}