Pages: 1 [2]   Go Down
Author Topic: HarwareSerial.h  (Read 2573 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#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?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49301
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49301
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What i expect is to receive those 4 characters "key1" through the software 'rx' pin, to a variable c, once it has been transmitted over the hardware 'tx'.
and what did you get?
and how did you check that?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I printed the variable to verify. But i could obtain garbage values only.
Serial.print(c); Check this code below:

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

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

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

Here in the serial monitor i got output as shown below:
A <a rectangular symbol> A <a rectangular symbol> ........
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49301
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are you printing the value of c whether you received any data, or not? Move that print() statement inside the if() block.

And, answer the questions. WHAT IS CONNECTED TO PINS 2 AND 3?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

pin 3 (software 'tx') connected to hardware 'rx'
pin 2 (software 'rx') connected to hardware 'tx'
Logged

Pages: 1 [2]   Go Up
Jump to: