DEV Community

codemee
codemee

Posted on • Edited on

用程式控制 Arduino UNO R4 WiFi 的 TX/RX 指示燈

Arduino UNO R4 WiFi 板很有趣, 上面的 RX/TX 指示燈是可以透過程式控制的, 在該開發板的套件上定義有 RX_LED/TX_LED 兩個常數, 如果你把這兩個常數印出來看:

void setup() {
  Serial.begin(9600);
  Serial.print("RX_LED->");
  Serial.println(RX_LED);
  Serial.print("TX_LED->");
  Serial.println(TX_LED);
}

void loop() {
}
Enter fullscreen mode Exit fullscreen mode

會得到以下的結果:

RX_LED->513
TX_LED->12
Enter fullscreen mode Exit fullscreen mode

不過這兩個數字看起來就不像是正確的腳位, 經過查詢網路, 找到大家說的腳位是 21 和 22, 不過這應該是 Arduino UNO R4 Minima 的腳位, 你可以在 ArduinoCore-renesas原始碼找到, 依循同樣的方式, 在 ArduinoCore-renesas 的 UNOWIFIR4 變化版本 中可以看到腳位應該是 TX->22, RX->23 才對:

byte led_tx = 22;
byte led_rx = 23;

void setup() {
  pinMode(led_tx, OUTPUT);
  pinMode(led_rx, OUTPUT);
}

void loop() {
  digitalWrite(led_tx, HIGH);
  digitalWrite(led_rx, LOW);
  delay(1000);
  digitalWrite(led_tx, LOW);
  digitalWrite(led_rx, HIGH);
  delay(1000);
}
Enter fullscreen mode Exit fullscreen mode

實際執行結果如下:

不過要注意的是因為線路的關係, 這兩個燈都是低電位亮燈, 而且 RX 亮度比 TX 低很多。另外, 如果啟用 Serial, 就無法控制這兩個指示燈了。

由於在 Arduino UNO R4 WiFi 上 RX__LED 與 TX_LED 並不是定義成上述的腳位, 顯然官方並沒有要讓你控制的意思, 如果你要使用這兩個 LED, 請自行擔負可能的風險。

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more