其他分享
首页 > 其他分享> > ATOM DTU实现485通信

ATOM DTU实现485通信

作者:互联网

接法:

 

 代码:

#include <M5Atom.h>

#define RX_PIN      33
#define TX_PIN      23
char temp;
void setup() {
  M5.begin(true,true,true);
  Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);  //Set the baud rate of serial port 2 to 115200,8 data bits, no parity bits, and 1 stop bit, and set RX to 16 and TX to 17.  设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX为16,TX为17
}  

void loop() {
  if(Serial2.available()){
    temp = char(Serial2.read());
    if(temp == '1')
     M5.dis.drawpix(0, 0x0000ff);//显示蓝色
    else if(temp == '2')
     M5.dis.drawpix(0, 0x00ff00);//显示绿色
  }
  delay(100);
}

结果:可以实现向485接口发送1,DTU亮蓝色灯;发送2,DTU亮绿色灯

标签:TX,PIN,RX,M5,temp,ATOM,485,DTU
来源: https://www.cnblogs.com/ykts/p/15882453.html