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, 請自行擔負可能的風險。

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay