serial print not working

Using the example code provided under the reference of serial.print syntax is not working with Arduino MKR 1010. No message or anything showed on my computer. Is that because of some settings in my computer?

/*
  Uses a for loop to print numbers in various formats.
*/
void setup() {
  Serial.begin(9600); // open the serial port at 9600 bps:
}

void loop() {
  // print labels
  Serial.print("NO FORMAT");  // prints a label
  Serial.print("\t");         // prints a tab

  Serial.print("DEC");
  Serial.print("\t");

  Serial.print("HEX");
  Serial.print("\t");

  Serial.print("OCT");
  Serial.print("\t");

  Serial.print("BIN");
  Serial.println();        // carriage return after the last label

  for (int x = 0; x < 64; x++) { // only part of the ASCII chart, change to suit
    // print it out in many formats:
    Serial.print(x);       // print as an ASCII-encoded decimal - same as "DEC"
    Serial.print("\t\t");  // prints two tabs to accomodate the label lenght

    Serial.print(x, DEC);  // print as an ASCII-encoded decimal
    Serial.print("\t");    // prints a tab

    Serial.print(x, HEX);  // print as an ASCII-encoded hexadecimal
    Serial.print("\t");    // prints a tab

    Serial.print(x, OCT);  // print as an ASCII-encoded octal
    Serial.print("\t");    // prints a tab

    Serial.println(x, BIN);  // print as an ASCII-encoded binary
    // then adds the carriage return with "println"
    delay(200);            // delay 200 milliseconds
  }
  Serial.println();        // prints another carriage return
}

xaviergao:
Using the example code provided under the reference of serial.print syntax is not working with Arduino MKR 1010. No message or anything showed on my computer. Is that because of some settings in my computer?

/*

Uses a for loop to print numbers in various formats.
*/
void setup() {
  Serial.begin(9600); // open the serial port at 9600 bps:
}

void loop() {
  // print labels
  Serial.print(“NO FORMAT”);  // prints a label
  Serial.print("\t");        // prints a tab

Serial.print(“DEC”);
  Serial.print("\t");

Serial.print(“HEX”);
  Serial.print("\t");

Serial.print(“OCT”);
  Serial.print("\t");

Serial.print(“BIN”);
  Serial.println();        // carriage return after the last label

for (int x = 0; x < 64; x++) { // only part of the ASCII chart, change to suit
    // print it out in many formats:
    Serial.print(x);      // print as an ASCII-encoded decimal - same as “DEC”
    Serial.print("\t\t");  // prints two tabs to accomodate the label lenght

Serial.print(x, DEC);  // print as an ASCII-encoded decimal
    Serial.print("\t");    // prints a tab

Serial.print(x, HEX);  // print as an ASCII-encoded hexadecimal
    Serial.print("\t");    // prints a tab

Serial.print(x, OCT);  // print as an ASCII-encoded octal
    Serial.print("\t");    // prints a tab

Serial.println(x, BIN);  // print as an ASCII-encoded binary
    // then adds the carriage return with “println”
    delay(200);            // delay 200 milliseconds
  }
  Serial.println();        // prints another carriage return
}

Quite possible something on your computer. Did you turn the IDE serial monitor on? There is a button or something on the screen to enable it.

Paul

Paul_KD7HB:
Quite possible something on your computer. Did you turn the IDE serial monitor on? There is a button or something on the screen to enable it.

Paul

Nope I have never seen that button. Is it in the Arduino IDE? Could you please show a screenshot of it?

Xavier

Nvm. I got it. Thanks

This is the Serial Monitor that comes on when we click on the 'Serial Monitor' icon located at the top-right-corner of the IDE.
SerialMonitor.png

I had the same trouble trying to port Mega sketches to an MKRZero. I found that Serial.print code in the setup() did not display anything on the serial monitor but Serial.print code worked fine if it was in loop(). I read everything I could find about the problem in the Forum for the last 4 years to no avail. One suggestion: Use SerialUSB.begin(9600); instead of Serial.begin(9600); made no difference whatsoever.

The solution turned out to be very simple. After
Serial.begin(9600); put
while(!SerialUSB); //Wait for Serial to be ready

Without this, the software progresses beyond all the Serial.print commands before the port is ready. With it, it makes sure that the Serial port is ready before you try to use it. Remember, the Zero and MKRZero are 32 bit and way-way faster than the Uno or Mega.

A problem arises with my suggestion that one waits for the Serial to be ready before the setup continues. When the MKRZero is running from battery or dumb USB there is no serial monitor and the program hangs. The solution is to use millis() to allow the while statement to escape. Thus, the setup code should include:

.
.
.
SerialUSB.begin(57600);
while (!SerialUSB && millis() < 500); //Wait for Serial to be ready
.
.
.