Software serial

You can post your problem related to Arduino Projects here. We will try our best to help you out.
Post Reply
Brown
Posts: 8
Joined: Fri Mar 03, 2017 1:10 pm

Software serial

Post by Brown » Fri Mar 03, 2017 2:10 pm

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);
}
}
}

Junaid_Shahid
Posts: 110
Joined: Tue Feb 14, 2017 9:00 am

Re: Software serial

Post by Junaid_Shahid » Fri Mar 03, 2017 2:11 pm

Brown wrote:
Fri Mar 03, 2017 2:10 pm
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);
}
}
}
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/Soft ... ialExample

HOW TO USE ARDUINO SOFTWARE SERIAL ?

Post Reply