Upload successfully but not get anything - [solved]

Hi, I am a newbie to Arduino and was trying to just print some random numbers. However, I am not getting anything. Could you please let me know what are the possible solutions?

void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.println(random(100));
  delay(500);
}

Probably need to wait a bit for the communications to actually be set up before using. Try waiting for a second.

1 Like

Make sure the Serial Monitor is also set to 9600. BTW, I set mine to 115200 almost always both in the monitor and the Serial.begin(115200)

1 Like

Did you connect the Native USB port, too?

I am using 9600 and set the Serial Monitor at 9600 as well.

Yes, everthing is connected and uploaded successfully.

1 Like

Hi @Abbassi007. In your screenshot, you have the "Output" view selected instead of the "Serial Monitor" view. So it might be that the numbers are being printed as expected, but you just aren't looking in the right place for them.

Please click on the "Serial Monitor" tab in the bottom panel of the Arduino IDE window and then check to see if you now see the numbers printed:

1 Like

@ptillisch Yes, in Serial Monitor I am not getting anything.

I see the problem now. The Due has two USB sockets:

šŸ“·

DueUSBPorts.jpg by Arduino - CC BY-SA 4.0

If you want to communicate with the computer via the "Programming Port", you use the Serial object in your code, as you have done. But if you want to communicate with the computer via the "Native USB Port", then you must instead use the undocumented SerialUSB object in your code.

I see from the screenshot that you are using the "Native USB Port" so you must change all occurrences of Serial in your sketch to SerialUSB.

After doing that, upload the sketch to your board again. Hopefully you will now see the expected output in Serial Monitor.

Thank you very much @ptillisch. Everything is working now.

You are welcome. I'm glad it is working now.

Regards, Per

1 Like

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