Go Down

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

bhairu

The reason why i wanted to use HardwareSerial.h was to use UART.Read().
I am using the same arduino board as the sender and receiver.
Sender is the hardware 'tx' pin.
Receiver is any of the port pin of arduino.

program:

#include<NewSoftSerial.h> // for software serial pins
NewSoftSerial mySerial(2,3); // sets port pin 2 as software 'rx' and pin 3 as software 'tx'
char c;
void setup()
{
Serial.begin(9600); //sets baud rate for hardware UART
mySerial.begin(9600); //sets baud rate for oftware UART
}
void loop()
{
Serial.Print("Key1"); //data sent via hardware 'tx' pin
delay(1000);
if(mySerial.available()>0)
  {
   c=mySerial.Read(); //data read via software 'rx' pin
   delay(1000);
  }
}

I shorted the harware 'tx' and software 'rx' pins; also the harware 'rx' and software 'tx' pins. But this code did not work. I even tried the other way around. That is, transmit via software 'tx' and receive via harware 'rx'. But that too did not work. The code for this arrangement is here:

void loop()
{
Serial.myPrint("Key1"); //data sent via software 'tx' pin
delay(1000);
if(Serial.available()>0)
  {
   c=Serial.Read(); //data read via hardware 'rx' pin
   delay(1000);
  }
}

robtillaart

Can you compile this code ???
Rob Tillaart

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

robtillaart

One question about your code (removed your comments)

Code: [Select]

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

char c; 

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

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

So you (1) print 4 characters over hardware serial and (2) read only one in software serial and you do nothing with it.

What do you expect to happen?




Code: [Select]

void loop()
{
Serial.[color=red]myPrint[/color]("Key1"); //does not exist!!!     mySerial.print("key1") might compile
delay(1000);
if(Serial.available()>0)
  {
   c=Serial.Read();
   delay(1000);
  }
}

for the rest same problem as before.

At least if you send 4 chars you need to read 4 chars.
Rob Tillaart

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

bhairu

Serial.myprint() was a mistake. Actual syntax is mySerial.print().

I could compile my code.

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'.

PaulS

Quote
I could compile my code.

Then, post your ACTUAL code.

Go Up