Go Down

Topic: duemilanove + Parallax Serial RFID Reader/Writer (Read 1 time) previous topic - next topic

RenRen

Is it possible to interface these two? Is it the same as the standard Parallax RFID Card Reader ? I hook them up the same and try some code I found online but nothing seem to happen

jada


RenRen

Oh sorry RFID Card Reader Serial : http://www.parallax.com/tabid/768/ProductID/114/Default.aspx and             RFID Read/Write Module, Serial: http://www.parallax.com/Store/Accessories/CommunicationRF/tabid/161/ProductID/688/List/0/Default.aspx?SortField=ProductName,ProductName

PaulS

They are both serial devices, so, yes, that can be connected to the Arduino.

Quote
Communication: asynchronous serial 9600 bps, (8N1); 5 V TTL-level, non-inverted

Oh, good. No intermediate converter chip needed.

Quote
I hook them up the same and try some code I found online but nothing seem to happen

The same as what? Are you trying to connect both the reader and the writer/reader at the same time? What code? After you connected the devices, what did you do? Which Arduino do you have?

Details, man, details. The more, the merrier.

RenRen

Sorry again. I hook up the reader/writer the same way you would hook up the regular writer and use this code :

Code: [Select]

#include <NewSoftSerial.h>

int val = 0;
char code[12];
char tag[12] = {'s', 'e', 'c', 'r', 'e', 't', 't', 'a', 'g', '!'};
int bytesread = 0;
#define rxPin 8
#define txPin 9 //dont need me
#define manual 1
#define auto 0
int automanuallock = auto;
#define unlocked 1
#define locked 0
int doorlockstatus = locked;
#define codeprintenabled 1
#define codeprintdisabled 0
int codeprintswitch = codeprintenabled;
#define powerPin 5
#define failPin 6
#define passPin 4
#define doorPin 3
#define enablePin 2
#define dooropentime 3000 // its in ms
void setup()
{
Serial.begin(9600); // Hardware serial for Monitor 9600bps
pinMode(enablePin,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(enablePin, LOW); // Activate the RFID reader
pinMode(powerPin, OUTPUT); // Connected to Blue LED to indicate reader is ready
pinMode(passPin, OUTPUT); // Connected to Green LED to indicate user is valid
pinMode(failPin, OUTPUT); // Connected to Red LED to indicate user is NOT valid
pinMode(doorPin, OUTPUT); // Connected to relay to activate the door lock
digitalWrite(powerPin, HIGH);
}
void loop()
{
digitalWrite(enablePin, LOW);
ReadRFID();
codeprint(); //(un)comment for rfid code via serial
digitalWrite(enablePin, HIGH);
check();
}
void ReadRFID()
{
NewSoftSerial RFID = NewSoftSerial(rxPin,txPin);
RFID.begin(2400);
if((val = RFID.read()) == 10)
{ // check for header
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
}
}
}
void check()
{
if(bytesread >= 10) { // if 10 digit read is complete
if(strcmp(code, tag) == 0) {
if (automanuallock == manual)
{
manualdoorlockorunlock();
}
else if (automanuallock == auto) {
doorauto();
}
}
else {
failandlockplus();
}
}
}
void codeprint(){
if (codeprintswitch == codeprintenabled)
{
Serial.println("TAG code is: ");
Serial.print(code);
}
}
//autolocks door
void doorauto()
{
Serial.println("Accepted");
Serial.println("Unlocked.");
digitalWrite(doorPin, HIGH);
digitalWrite(passPin, HIGH);
delay(dooropentime);
Serial.println("Locked");
digitalWrite(doorPin, LOW);
digitalWrite(passPin, LOW);
}
void manualdoorlockorunlock(){
if (doorlockstatus == locked)
{
doorunlock();
}
else if (doorlockstatus == unlocked) {
doorlock();
}
}
void doorunlock()
{
Serial.println("Accepted.");
Serial.println("Door unlocked.");
digitalWrite(doorPin, HIGH);
digitalWrite(passPin, HIGH);
doorlockstatus = unlocked;
delay(2000);
digitalWrite(passPin, LOW);
}
void doorlock()
{
Serial.println("Accepted.");
Serial.println("Door locked.");
digitalWrite(passPin, HIGH);
digitalWrite(doorPin, LOW);
doorlockstatus = locked;
delay(2000);
digitalWrite(passPin, LOW);
}
void failandlock()
{
Serial.println("Rejected.");
Serial.println("Door locked.");
digitalWrite(doorPin, LOW);
digitalWrite(failPin, HIGH);
delay(1000);
digitalWrite(failPin, LOW);
}
void failandlockplus()
{
if (doorlockstatus == locked)
{
Serial.println("Rejected.");
Serial.println("Door already locked.");
digitalWrite(failPin, HIGH);
digitalWrite(doorPin, LOW);
delay(1000);
digitalWrite(failPin, LOW);
}
else if (doorlockstatus == unlocked) {
Serial.println("Rejected.");
Serial.println("Door locked.");
digitalWrite(doorPin, LOW);
digitalWrite(failPin, HIGH);
doorlockstatus = 0;
delay(1000);
digitalWrite(failPin, LOW);
}
}
void fail()
{
Serial.println("Rejected.");
digitalWrite(failPin, HIGH);
delay(1000);
digitalWrite(failPin, LOW);
}
void pass()
{
Serial.println("Accepted.");
digitalWrite(passPin, HIGH);
delay(1000);
digitalWrite(passPin, LOW);
}
void reset()
{
Serial.println("Reset.");
digitalWrite(doorPin, LOW);
digitalWrite(failPin, LOW);
digitalWrite(passPin, LOW);
digitalWrite(powerPin, HIGH);
}


I found that here : http://www.mitchandstuff.com/?p=14
The code runs fine. The reader/writer lights up, but when I put a tag over it nothing happens.

PaulS

#5
Jan 16, 2011, 07:36 pm Last Edit: Jan 16, 2011, 07:43 pm by PaulS Reason: 1
Code: [Select]
NewSoftSerial RFID = NewSoftSerial(rxPin,txPin);
RFID.begin(2400);

Why are you creating a new instance of NewSoftSerial on every pass through loop? This should be done once before setup, and the begin call belongs in setup().

I tried viewing the user guide on the writer site. No go. I'm not particularly fond of watching an hour glass spin for 10 minutes.

RenRen

I have no clue remember this is not my code, and I'm relatively new to coding well C (I know my way around VB.net -_-"  lol) so thanks for point that out :D. and for all your help

:D

Go Up