ARDUINO SERIAL READ.....

Thread Starter

AJIN NADH

Joined Dec 18, 2014
84
HI Team,
I tried to read a string send through the GPS device and on processing this String using the RX pin of ARDUINO UNO i tried to On/ off the led., But its Not working properly.
I read the string through terminal, and its reading properly.What may be problem
Regards,
Ajin nadh
 

tshuck

Joined Oct 18, 2012
3,534
HI Team,
I tried to read a string send through the GPS device and on processing this String using the RX pin of ARDUINO UNO i tried to On/ off the led., But its Not working properly.
I read the string through terminal, and its reading properly.What may be problem
Regards,
Ajin nadh
Problems may lie in:
  1. Code
  2. Hardware
For more specific answers, well need more information: schematic and code as a minimum.
 

Thread Starter

AJIN NADH

Joined Dec 18, 2014
84
Problems may lie in:
  1. Code
  2. Hardware
For more specific answers, well need more information: schematic and code as a minimum.
Hi
This is the code i used

Code:
int RED =  13;
int GREEN =  12;
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(19200);
  pinMode(RED,OUTPUT);
  pinMode(GREEN,OUTPUT);
}
void loop() {

String str = "";
  if(Serial.available() > 0)
  {
    str = Serial.readString();
if  (str.startsWith("Y", 5) )

{
  digitalWrite(RED, HIGH);
  digitalWrite(GREEN, LOW);
  Serial.print(str);
}
  else if (str.startsWith("N", 5))
{
   digitalWrite(GREEN, HIGH);
   digitalWrite(RED, LOW);
   Serial.print(str);
}
}
}
and the serial strings are "$W001N#" and $W001Y#
ITS PLANED TO ON THE GREEN LED WHEN $W001N# RECEIVES.
This code is getting when i receive using the Terminal. I think the code is not working, what may be the problem....

Moderatots note : Please use code tags for pieces of code
 
Last edited by a moderator:

MikeML

Joined Oct 2, 2009
5,444
I don't follow the code, but if I understand what you are doing, you have serial characters coming in at 19.2kbaud, and you are trying to display them on the serial monitor, which by default runs at 9.6kbaud. That will overrun, and you will garble or loose some of the characters...
 

tshuck

Joined Oct 18, 2012
3,534
According to the documentation on the Arduino website, string.startsWith only accepts one parameter: a string.

Provided your communications settings are correct, try using something like: str.startsWith("$W001N") and str.startsWith("$W001Y").

As Mike pointed out, nothing will work unless you have the correct settings.
 

Thread Starter

AJIN NADH

Joined Dec 18, 2014
84
Hi,
This is working correctly when i use the arduino board with an external supply( Not through the usb).
Thanks for the responses.
Regards,
Ajin nadh v a
 
Top