0

I made an object named "mySerial" like this.

SoftwareSerial mySerial(2,3) //pin 2 = RX, pin 3 = TX

also I made pin 13 periodically(0.5 seconds) blink(HIGH/LOW), then the signal from pin 13 goes directly to pin 2 and pin 0(basic RX pin of UNO). I connected pin 0,2,13 directly with jumper wire.

and in the setup(), I wrote

Serial.begin(9600);

mySerial.begin(9600);

and in the loop(), I wrote

digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);

if(mySerial.available()){
    mySerial.println("mySerial!");
}
if(Serial.available()){
    Serial.println("Serial!");
}

when I compile this code and operate arduino, I can only see the "Serial!" on the serialmonitor. I think this means that the pin 0 can recognize the signal but the pin 2 cant' How can I solve this problem?

I can't find what I've missed. Please help me guys!

  • 1
    And what exactly is it you hope to achieve with that setup? It makes absolutely no sense to me whatsoever, and from my initial understanding "Serial!" on the serial monitor is all you can expect to get. – Majenko Nov 19 '15 at 12:16
  • I connected pin 0,2,13 directly with jumper wire. - why? You've lost me here. – Nick Gammon Jan 18 '16 at 20:02
1

Not the most scientific of approaches, and fundamentally flawed at any rate.

You've toggled the input twice over the period of one second, hardly an emulation of any serial port transmission and so one is letting you know there's been a change of state, the other is letting you know that it hasn't received any valid data.

In any case, when you attempt to read the port both will/should correctly give you nothing as a result because there was never anything there to begin with, nor is there anything coming in at the time.

If you want to test serial port comms like this, you are going to have to make a sketch for each scenario and use a real device to test it (like your actual serial port thru the Arduino IDE). Run some test, print the results and upload your second sketch and do it again.

You could even get a bit fancy and have a bit of fun with this and send a command to the arduino to turn off one serial port and turn the other one on, but that's got nothing to do with what you asked, so I won't be writing the code for that here ;)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.