Arduino Projects DISCUSSION

Software serial

Started by syedzainnasir Software serial
1 replies 248 views 2 participants
Latest activity · 03 Mar 2017

Software serial

syedzainnasir Arduino Projects Forum
#1
Every time I try to bring softwareserial into my code I get this error:

In function 'void setup()':
error: expected unqualified-id before '.' token

I've searched the forum and references and cann't figure out what I'm doing wrong. thanks


my code looks like this:
#include <SoftwareSerial.h>



int val = 0;
char code [10];
int byteread = 0;
int EnPin = 2;

void setup()
{
Serial.begin(2400);
pinMode(2,OUTPUT);
SoftwareSerial(7,8);
SoftwareSerial.begin(9600);

}

void loop()
{

digitalWrite(EnPin,LOW);
if (Serial.available()>0)
{
if((val = Serial.read()) == 10)
{
byteread=0;
while (byteread < 10)
{
if (Serial.available()>0)
{
val = Serial.read();
if ((val == 10) || (val == 13))
{
break;
}
code[byteread]=val;
byteread++;
}
}
if (byteread==10)
{
Serial.print("Tag code is ");
Serial.println(code);
}
digitalWrite(EnPin,HIGH);
delay(500);
}
}
}

Community replies 1

Re: Software serial

#2
[quote=Brown post_id=260 time=1488550253 user_id=84] Every time I try to bring softwareserial into my code I get this error:

In function 'void setup()':
error: expected unqualified-id before '.' token

I've searched the forum and references and cann't figure out what I'm doing wrong. thanks


my code looks like this:
#include <SoftwareSerial.h>



int val = 0;
char code [10];
int byteread = 0;
int EnPin = 2;

void setup()
{
Serial.begin(2400);
pinMode(2,OUTPUT);
SoftwareSerial(7,8);
SoftwareSerial.begin(9600);

}

void loop()
{

digitalWrite(EnPin,LOW);
if (Serial.available()>0)
{
if((val = Serial.read()) == 10)
{
byteread=0;
while (byteread < 10)
{
if (Serial.available()>0)
{
val = Serial.read();
if ((val == 10) || (val == 13))
{
break;
}
code[byteread]=val;
byteread++;
}
}
if (byteread==10)
{
Serial.print("Tag code is ");
Serial.println(code);
}
digitalWrite(EnPin,HIGH);
delay(500);
}
}
} [/quote]
SoftwareSerial doesn't work quite the same way as the regular Serial. You need to declare an instance of it, then call begin(), etc. on that instance not on SoftwareSerial. See the example at: http://www.arduino.cc/en/Reference/SoftwareSerialExample

[url=http://www.theengineeringprojects.com/2017/01/use-arduino-software-serial.html]HOW TO USE ARDUINO SOFTWARE SERIAL ?[/url]
TEP COMMUNITY