Arduino Uno and Mega
Both the Arduino Uno and Mega have hardware support for the Serial protocol (USART). The Serial Monitor will automatically attach to the hardware serial port and detect the baud rate, so it’ll work out of the box without any special configuration. You can use Arduino’s Serial class to interact with the Serial monitor:Connecting to different serial ports (Mega)
The Arduino Mega has multiple hardware Serial ports. You can connect the Serial monitor to a different serial port by configuring the pins in diagram.json. For instance, to connectSerial2 to the serial monitor, add the following lines to the connections section in your diagram:
Replace
mega with the actual id of your wokwi-arduino-mega part. Note that you need to connect $serialMonitor:TX to the RX pin of the serial port, and $serialMonitor:RX to the TX pin of the serial port.ATtiny85 + SoftwareSerial
The ATtiny85 chip does not have a built-in hardware support for serial communication (UART). You can use a software implementation of the UART protocol to interact with the Serial monitor, using the “SoftwareSerial” library.Define the pins
Add the following lines to the Replace
connections section of your diagram.json file:tiny with the actual id of your wokwi-attiny85 part, and PB1/PB0 with the pin names that you would like to use.Configuring the Serial Monitor
You can configure the Serial Monitor by adding a"serialMonitor" section to your diagram.json file.
The default configuration is as follows:
When you add a
"serialMonitor" section, either add it after the last item in diagram.json, or make sure to add a comma after the closing curly brace. You can find a complete example here.Display
Thedisplay property configures when/how to display the serial monitor. The possible values are:
| Value | Description |
|---|---|
| auto | Display the Serial Monitor when there’s some output (the default) |
| always | Always display the Serial Monitor when simulation starts |
| never | Never display the Serial Monitor |
| plotter | Display the Serial Plotter when simulation starts |
| terminal | Display a terminal (using XTerm.js) |
Collapse
You can set the Serial Monitor to be collapsed by default when it opens, by adding the"collapse": true property to the "serialMonitor" section:
Newline
When you input a line of text in the Serial Monitor, the simulator sends that text to your program. Your program can read it usingSerial.read() and also some other Serial methods.
By default, the simulator also appends a line feed character (“\n”, ASCII code 10) to every line of text that it sends to your program. You can use the newline property to change this behavior and configure a different sequence of characters:
| Value | Characters | ASCII codes | Description |
|---|---|---|---|
| lf | ”\n” | 10 | Line feed (the default) |
| cr | ”\r” | 13 | Carriage return |
| crlf | ”\r\n” | 10 13 | Carraige return + linefeed |
| none | "" | Don’t append any characters to input lines |
Convert EOL
TheconvertEol property only applies to the “terminal” display mode. When set to true, the simulator will convert all line feed characters (“\n”) to carriage return + line feed (“\r\n”) before sending them to the terminal. This is useful when your code does not print a carriage return character after each line, and the serial terminal displays the output in a staggered way.