0

I have a very basic script that is supposed to display something to the serial monitor but no matter what I try the serial monitor won't display anything...I;ve watched about 5 tutorials now and each one has failed to display anything. Any ideas what I'm doing wrong?

Here is my code:

char rx_byte;

void setup() {
  Serial.begin(115200);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}

void loop() {
  if(Serial.available() > 0){
    rx_byte = Serial.read();
    Serial.print("You typed: ");
    Serial.println(rx_byte);
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
  }
}
13
  • Are you typing anything into the serial monitor? What baud rate is the serial monitor set to? Commented Feb 19, 2016 at 8:29
  • I'm typing just the number 1 and 0, according to the tutorial I watched that should turn the LED on/off. The baud rate is set the same as what is in my code. Commented Feb 19, 2016 at 17:37
  • I'm typing just the number 1 and 0 - and then you pressed the Send button? Please add Serial.println ("Hello, world"); after the Serial.begin line and see if that appears in the serial monitor. Commented Feb 19, 2016 at 20:31
  • Yes then I pressed the send button. I tried putting that line in after Serial.begin and still nothing... Commented Feb 19, 2016 at 20:42
  • Well, solve that first. No point typing and pressing Send if nothing appears. What Arduino do you have? What version of the IDE? Commented Feb 19, 2016 at 20:43

3 Answers 3

2

Which one are you using?

The one closest to the reset button, I believe its the native...

This is more confusing than I realized. The Due has two ports:

Due ports


Programming port

For programming, the programming port is easiest to use. And you can "talk" to the serial port using Serial, like this:

void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Hello, world!");
  }  // end of setup

void loop ()
  {
  }  // end of loop

Native USB port

This lets you emulate USB devices (eg. keyboard, mice). However if you want to use it for Serial communications you need to use a different class SerialUSB like this:

void setup ()
  {
  SerialUSB.begin(115200);
  while (!SerialUSB) ; // wait for it to become ready
  SerialUSB.println ("Starting ...");
  }  // end of setup

unsigned long i;

void loop ()
  {
  SerialUSB.print ("Hello, world! Count = ");
  SerialUSB.println (++i);
  delay (1000);
  }  // end of loop

It also helps to wait for the serial port to become ready, as I did in setup. Otherwise you may miss the first 10 lines or so of serial output.

1

You have to change the baud rate at the right bottom corner of the serial monitor to 115200 which you have assigned initially. I have tested it and It doesn't matter if its int/char

1
  • I have done that, still no luck. Commented Feb 19, 2016 at 17:36
0

Try replacing the line char rx_byte; with int rx_byte=0;. Use Serial.println(rx_byte,DEC);

int rx_byte=0;

void setup() {
  Serial.begin(115200);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}

void loop() {
  if(Serial.available() > 0){
    rx_byte = Serial.read();
    Serial.print("You typed: ");
    Serial.println(rx_byte,DEC);
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
  }
}
1
  • Same again, nothing... Commented Feb 19, 2016 at 17:37

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.