Wokwi and serial read

I've just joined this group and so this is my first question. I've been an Arduino user on and off (lots of off time) since the Duemilanove board first became available and I'm still using it. I have browsed questions relating to wokwi.

I see that serial.writes show up in the wokwi serial monitor but is it possible to enter serial.reads? If so where do I enter the bytes to be read?

int incomingByte;

void setup() {
  Serial.begin(9600); // Set baud rate
}

void loop() {
  if (Serial.available() > 0) { // Check if data is available
    incomingByte = Serial.read(); // Read the byte
    Serial.print("You sent: "); // Print a message
    Serial.println(incomingByte); // Print the received byte
    delay(1000);
  }
}

void setup() {
  Serial.begin(9600); // Set baud rate
  Serial.print("showing serial screen"); // Print a message
}

void loop() {
  if (Serial.available() > 0) { // Check if data is available
    byte incomingByte = Serial.read(); // Read the byte
    Serial.write(incomingByte); // Print the received byte
    //delay(10);
  }
}

Thank you for the quick reply. However, I still don't know where, or I can, enter a byte.

Although this example is for an ESP32, I believe it demonstrates the basic functionality that you are looking for:

PS The serial input box is at the bottom of the Simulation tab.

1 Like

It's not silly. Especially the part of wokwi where the serial monitor does not automatically start, so most of my sketches have something like

  Serial.befin(115200);
  Serial.println("Wake up!");

as the first lines in setup().

You can add to the diagram.json file

"serialMonitor": {
  "display": "always",
  "newline": "lf",
  "convertEol": false
}

and it will come up by itself, so to speak.

You can also have it start in serial plotter mode, which is handy when that's what you want ppl to look at.

See alla details here:

HTH

a7

1 Like

Thank you alto777. I had already tried adding that to the .jason file but it showed as an error. I'll look at it again. The serial monitor did start by itself anyway so maybe adding to the .jason file is unnecessary. I had played with the serial plotter, using a different sketch, and it worked as well.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.