breadboard
docs

Example project · Builds & projects

Uno R4 · physical Serial1 peers

Two boards exchange bytes over crossed D1 TX and D0 RX wires at 9600 baud, then 1 Mbaud. Select each board in Serial to read the received decimal values. Reset the simulation to repeat; edit the first board’s sketch in Code.

The Uno R4 · physical Serial1 peers circuit as rendered by the simulator

How it works

Two UNO R4 WiFi boards run the same sketch and talk through their hardware serial ports. On the UNO R4, Serial is the USB console that you read in the monitor, and Serial1 is a separate UART on header pins D0 (RX) and D1 (TX). The wires cross: each board's D1 transmit pin goes to the other board's D0 receive pin, and a third wire joins the two grounds, so both boards share one voltage reference.

setup() calls exchangeAt() twice. Each call starts Serial1 at a baud rate, writes three bytes, waits with flush() until they have left the transmitter, and then listens for 20 ms. It prints the baud rate and then each byte that arrives, as a decimal number. The first round sends 0x55, 0x00 and 0xFF at 9600 baud; the second sends 0xA5, 0x5A and 0x3C at 1,000,000 baud. Both boards start together and send the same bytes, so each one receives exactly what the other sent. The bits travel as voltage levels on the solved D0 and D1 nets.

What to watch

Select each board in Serial. Both show the same two lines: 9600 85 0 255, then 1000000 165 90 60. These are the decimal values of the three bytes that each board received at each speed. The sketch runs once; press Restart to repeat the exchange.

What's on the bench

  • 2× Arduino Uno R4

How it's wired

  • Arduino Uno R4 · gnd2→Arduino Uno R4 · gnd
  • Arduino Uno R4 · d1→Arduino Uno R4 · d0
  • Arduino Uno R4 · d1→Arduino Uno R4 · d0

The code

This Arduino C++ sketch lives in Code; sign in and press Compile & upload to build real firmware for the emulated board.

// Breadboard UNO R4 P5 solved-pin Serial1 acceptance fixture.

static void exchangeAt(uint32_t baud, const uint8_t *tx, size_t length) {
  Serial1.begin(baud);
  Serial1.write(tx, length);
  Serial1.flush();

  uint32_t started = millis();
  Serial.print(baud);
  while (millis() - started < 20) {
    if (Serial1.available()) {
      Serial.print(' ');
      Serial.print(Serial1.read());
    }
  }
  Serial.println();
  Serial1.end();
}

void setup() {
  Serial.begin(115200);
  static const uint8_t kSlow[] = {0x55, 0x00, 0xff};
  static const uint8_t kFast[] = {0xa5, 0x5a, 0x3c};
  exchangeAt(9600, kSlow, sizeof(kSlow));
  exchangeAt(1000000, kFast, sizeof(kFast));
}

void loop() {}

Firmware licence

Notice: this firmware uses the LGPL-licensed Arduino core library

arduino-unor4wifi-serial1.bin is statically linked with ArduinoCore-renesas 1.6.0, in Breadboard's port of its UNO R4 WiFi variant to Renesas FSP 5.3.0. Parts of that core are licensed under the GNU Lesser General Public License, version 2.1 or (at your option) any later version ("the Library"). Breadboard distributes this firmware under terms that permit you to modify the work for your own use and to reverse engineer it for debugging such modifications.

Try this

  • Probe the first board's D1 in Scope and press Restart. The first byte, 0x55, together with its start and stop bits, makes the line change level on every bit, about 104 µs apiece at 9600 baud.
  • Change the bytes in kSlow in Code, then sign in and press Compile & upload. Code edits the first board only, so the peer prints your new values, while the first board still receives 85 0 255.
  • Remove the first board’s D1-to-peer-D0 wire, add a 10 kΩ pull-up from the peer’s D0 to its 5 V pin, and press Restart. The peer’s lines now show only the baud rates.

Related projects