The Serial Monitor provides a way to send/receive information to/from your Arduino code. You can use it to view debug messages printed by your program, or to send commands that control your program.
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:
The serial monitor will only show once you print some output from your program. To change this behavior, see below.
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 connect
Serial2 to the serial monitor, add the following lines to the
connections section in your diagram:
mega with the actual id of your
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. This can be confusing, I know.
The ATtiny85 chip does not have a built-in hardware support for serial communication (USART). You can use a software implementation of the USART protocol to interact with the Serial monitor, using the "SoftwareSerial" library.
First, define the pins that will be used for Serial communication, by adding the following lines to the
connections section of your diagram.json file:
tiny with the actual id of your
wokwi-attiny85 part, and
PB0 with the pin names that you would like to use.
Then, configure the SoftwareSerial library accordingly:
Make sure the the pin names in your code match the ones in the diagram file. The first parameter
SoftwareSerial constructor should match the pin connected to
the second parameter should match the pin connected to
The baud rate must be set to 9600. This is hard coded in the simulator, and using a different value will get you garbage in the Serial monitor.
For a complete example, check out the ATtiny85 SoftwareSerial example project.
Note: if you just want to use the Serial monitor for printing debug messages, take a look at the TinyDebug library.
You can configure the Serial Monitor by adding a
"serialMonitor" section to your diagram.json file.
The default configuration is as follows:
display property configures when/how to display the serial monitor. The possible values are:
|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)|
When you input a line of text in the Serial Monitor, the simulator sends that text to your program.
Your program can read it using
Serial.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:
|lf||"\n"||10||Line feed (the default)|
|crlf||"\r\n"||10 13||Carraige return + linefeed|
|none||""||Don't append any characters to input lines|