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);
}
}
3 Answers 3
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:
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.
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
-
I have done that, still no luck.mr-matt– mr-matt2016年02月19日 17:36:16 +00:00Commented Feb 19, 2016 at 17:36
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);
}
}
-
Same again, nothing...mr-matt– mr-matt2016年02月19日 17:37:29 +00:00Commented Feb 19, 2016 at 17:37
I'm typing just the number 1 and 0
- and then you pressed the Send button? Please addSerial.println ("Hello, world");
after theSerial.begin
line and see if that appears in the serial monitor.