Go Down

Topic: HarwareSerial.h (Read 2 times) previous topic - next topic

bhairu

#include<NewSoftSerial.h>
NewSoftSerial mySerial(2,3);

char c;

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop()
{
  Serial.Print("Key1");
  delay(1000);
  if (mySerial.available() > 0)
  {
    c=mySerial.Read();
  }
}

This is the code i compiled. But couldn't receive data "key1" to the variable c.
Could you check the output in your hardware, once shorting the pins i mentioned?

PaulS

Quote
But couldn't receive data "key1" to the variable c.

How do you know? What is connected to the software serial pins - 2 and 3?

bhairu

#include<NewSoftSerial.h>
NewSoftSerial mySerial(2,3);

char c;

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop()
{
  Serial.Print("Key1");
  delay(1000);
  if (mySerial.available() > 0)
  {
    c=mySerial.Read();
    delay(1000);
  }
Serial.print(c);
}

I could observe garbage values only. I tried with a single character, as well. That is, Serial.print('A'), instead of Serial.print("key1"). Still, i couldn't get the desired result.

bhairu

Software pin 'tx' (pin 3) is shorted to hardware 'rx' and Software pin 'rx' (pin 2) is shorted to hardware 'tx'

PaulS

The proper ratio of answers to questions is 1 to 1. Try again.

Go Up