Pages: [1]   Go Down
Author Topic: Software Serial  (Read 1546 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sketch_nov11b.cpp: In function 'void loop()':
sketch_nov11b:110: error: 'SoftwareSerial' was not declared in this scope
sketch_nov11b:110: error: expected `;' before 'RFID'
sketch_nov11b:111: error: 'RFID' was not declared in this scope







Code:
//BEGIN CODE

#define servoPin 4 // control pin for servo motor (White or yellow wire of servo)
#define minPulse 500 // minimum servo position (Open position)
#define maxPulse 2200 // maximum servo position (Closed position)
#define rxPin 8 // SOUT pin of RFID module
#define txPin 9
#define enable 2 // /ENABLE pin of RFID module
#define LED1 13 // LED output pin
#define LED2 12 // other LED output pin for two-way LED (yellow)
#define switchPin 7

boolean open = true; // default start up is to assume the lock is open
int val = 0;
char code[10];
int bytesread = 0;
int pulse, switchVal;

char tag1[11] = "0800335036"; // this is size 11 because it is a NULL terminating string
char tag2[11] = "0800330A99";
char tag3[11] = "0F03028B4F";



void LEDControl(int state){

switch (state){
case 1:
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
break;
case 2:
digitalWrite(LED2,HIGH);
digitalWrite(LED1,LOW);
break;
case 3:
for(int y=0;y<5;y++){
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
delay(250);
digitalWrite(LED2,HIGH);
digitalWrite(LED1,LOW);
delay(250);
}
}

}

boolean checkTag(char *tag){

for (int x=0;x<10;x++){
if( tag[x] != code[x]){
return false;
}
}
return true;
}

boolean findGoodTag(){
if (checkTag(tag1)){ return true;}
else if (checkTag(tag2)){ return true;}
else if (checkTag(tag3)){ return true;}

// Add more lines right here like the one above if you have more tags

else{
Serial.print("Bad tag: ");
Serial.println(code);
LEDControl(3);
return false;
}

}
void moveServo(){

if (open){
pulse = minPulse;
open = false;
LEDControl(1);
}
else if (!open){
pulse = maxPulse;
open = true;
LEDControl(2);
}

for (int x =1;x<150;x++){
delay (10); // don't know why this works, but it does
digitalWrite(servoPin, HIGH); // start the pulse
delayMicroseconds(pulse); // pulse width
digitalWrite(servoPin, LOW); // stop the pulse
}

}



void setup() {

pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pinMode(LED1,OUTPUT); // Set LED pin as output
pinMode(LED2,OUTPUT); // Set LED pin as output
Serial.begin(9600);
Serial.println("Begin");
pinMode(enable,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(enable, LOW); // Activate the RFID reader
pinMode(switchPin, INPUT);
}

void loop() {
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);

switchVal = digitalRead(switchPin);



if((val = RFID.read()) == 10)
{ // check for header
if(switchVal == HIGH){
Serial.println("Button");
moveServo();
}
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.read();
if((val == 10)||(val == 13))
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}



if((bytesread == 10) && (findGoodTag()))
{ // if 10 digit read is complete
digitalWrite(enable, HIGH); // dectivate the RFID reader
moveServo();
delay(500);
digitalWrite(enable, LOW); // Activate the RFID reader
}
}
}
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27088
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't you need to include some library calls in there somewhere too? Or did I just miss them?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

@CrossRoads
I think you mean header files, and yes there is a #include "SoftwareSerial.h" missing. As well it should be, since SoftwareSerial is obsolete.

maker007 should be using NewSoftSerial, instead.

Code:
void loop()
{
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);

Why do you want to create a new instance on every pass through loop?

Code:
if((val = RFID.read()) == 10)
{ // check for header
if(switchVal == HIGH){
Serial.println("Button");
moveServo();
}
If the end of the tag data was read, and the switch is held down move the servo.

Code:
if((bytesread == 10) && (findGoodTag()))
{ // if 10 digit read is complete
digitalWrite(enable, HIGH); // dectivate the RFID reader
moveServo();
delay(500);
digitalWrite(enable, LOW); // Activate the RFID reader
}
If the end of the tag data was read, and the tag is good, move the servo.

Two questions. Why are you moving the servo in the first block of code, even if the tag was not valid?

Why are you turning the RFID read off and on?

I lied. I have 3 questions. Is your tab key broken, or is the complete lack of indenting a copy/paste issue, or don't you understand the benefits of proper indenting?

OK, so that was three questions, for a total of 5. Oh, well...

Code:
char tag1[11] = "0800335036"; // this is size 11 because it is a NULL terminating string
char tag2[11] = "0800330A99";
char tag3[11] = "0F03028B4F";
When declaring and initializing in one step, the compiler will determine the size that the array needs to be. You do not have to explicitly set the size.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

its not my code!!!
http://scottzumwalt.blogspot.com/2008/06/arduino-rfid-door-lock.html
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
its not my code!!!
No, it is your question and people on this forum try to help you bringing this code "to live" again. They are not attacking you smiley  Mind you, the code seems to be > 2 years old and there has been quite some progress in the Arduino universe (where time is measured in micro's ...) . So try to understand the advice given and change your code accordingly to see if it works. If not just ask additional questions and explain what you have tried sofar.

Quote
It is also informative to read the comments on blogs ...
Rob
« Last Edit: November 13, 2010, 08:09:32 am by robtillaart » Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: