Skip to content

Serial and Serial1 in Arduino Code

Wokwi  

Ref. wokwi-pi-pico Reference

Wokwi
Pico Simulation
Wokwi
PicoW Simulation
ArduinoIDE
+ Pico Board
Serial X X Work
Serial1 Work Work X

Wokwi -> Simulation

Serial1 -> Work

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
void setup() {
  Serial1.begin(115200);
  Serial1.println("Pi Pico Serial Monitor example!");
  Serial1.println("-------------------------------");
}

byte value = 0;
void loop() {
  Serial1.print("Counter: ");
  Serial1.print(value);
  Serial1.print(", hex: ");
  Serial1.println(value, HEX);
  value += 1;
  delay(500);
}
Ref. Pi Pico Serial Monitor over UART Example alt text

Serial -> Doesn’t Work

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// void setup() {
//   Serial1.begin(115200);
//   Serial1.println("Pi Pico Serial Monitor example!");
//   Serial1.println("-------------------------------");
// }

// byte value = 0;
// void loop() {
//   Serial1.print("Counter: ");
//   Serial1.print(value);
//   Serial1.print(", hex: ");
//   Serial1.println(value, HEX);
//   value += 1;
//   delay(500);
// }

void setup() {
  Serial.begin(115200);
  Serial.println("Pi Pico Serial Monitor example!");
  Serial.println("-------------------------------");
}

byte value = 0;
void loop() {
  Serial.print("Counter: ");
  Serial.print(value);
  Serial.print(", hex: ");
  Serial.println(value, HEX);
  value += 1;
  delay(500);
}
alt text

Arduino IDE -> Upload to Raspberry Pi Pico board

Serial1 -> Doesn’t work

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
void setup() {
  Serial1.begin(115200);
  Serial1.println("Pi Pico Serial Monitor example!");
  Serial1.println("-------------------------------");
}

byte value = 0;
void loop() {
  Serial1.print("Counter: ");
  Serial1.print(value);
  Serial1.print(", hex: ");
  Serial1.println(value, HEX);
  value += 1;
  delay(500);
}
alt text

Serial -> Work

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// void setup() {
//   Serial1.begin(115200);
//   Serial1.println("Pi Pico Serial Monitor example!");
//   Serial1.println("-------------------------------");
// }

// byte value = 0;
// void loop() {
//   Serial1.print("Counter: ");
//   Serial1.print(value);
//   Serial1.print(", hex: ");
//   Serial1.println(value, HEX);
//   value += 1;
//   delay(500);
// }

void setup() {
  Serial.begin(115200);
  Serial.println("Pi Pico Serial Monitor example!");
  Serial.println("-------------------------------");
}

byte value = 0;
void loop() {
  Serial.print("Counter: ");
  Serial.print(value);
  Serial.print(", hex: ");
  Serial.println(value, HEX);
  value += 1;
  delay(500);
}
alt text


This is written in the Serial Monitor over UART

The Serial Monitor can also communicate with the Pi Pico over the physical UART interface. To configure the UART communication between the Raspberry Pi Pico and the Serial Monitor, add the following connections to your diagram.json file:

  "connections": [
    [ "$serialMonitor:RX", "pico:GP0", "", [] ],
    [ "$serialMonitor:TX", "pico:GP1", "", [] ],
    
  ]

The example assumes that the Pi Pico was defined with an id of “pico”, e.g.

  "parts": [
    {
      "type": "wokwi-pi-pico",
      "id": "pico",
      
    },
    
  ]

The use the Serial1 object in your code: initialize the port using Serial1.begin(115200), and then print messages with Serial1.println(). For example:

void setup() {
  Serial1.begin(115200);
  Serial1.println("Hello, world!");
}

void loop() { }

For a complete example, check out the Pi Pico Serial Monitor over UART Example.

But alt text

なんやねん