最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

arduino - Can I define a software serial on this rs485 shield? - Stack Overflow

programmeradmin0浏览0评论

According to the sample code of the RS485 shield, it uses the default serial port to write and read, however I want to use a software serial. Can it be possible? I have also attached the schematics of the board. If yes, what pins to use and will they have to be wired separately

int led = 13;
int EN = 2;  //Definition RS485 shield enable terminal (the 2nd digital IO ports),
//high for the sending state, the low level of receiving state
void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(EN, OUTPUT);
}
void loop() {
  int temp;
  digitalWrite(EN, LOW);  //Enable low, RS485 shield waiting to receive data
  if (Serial.available()) {
    temp = Serial.read();
    if (temp == 'V') {
      digitalWrite(led, 1 - digitalRead(led));
      digitalWrite(EN, HIGH);  //Enable high, RS485 shield waiting to transmit data
      Serial.println("OK");
      delay(10);  //Delay for some time, waiting for data transmitted
    }
  }
}

发布评论

评论列表(0)

  1. 暂无评论