Well, the new LCD4x40Bit-ShiftReg library is working quite well. I’m actually thinking about changing the actual name of the library but figure the above is too long. Maybe I should try something like LCD3Wire4x40 or something. Your thought are greatly appreciated!

So anyway, I added my Parallax RFID card to the setup and finally worked out the bug I was initially having with the code. For some reason the RFID code would freeze and not continue looping the loop(). I found out finally after trying everything like an idiot that I had the wrong setup for the initialization of attachInterrupt().  Apparently I had the mode set wrong to CHANGE and I should have had it set to LOW. Makes since now that I think about it. CHANGE would make it continue to go into the interrupt function over and over again. As soon as I changed the mode to LOW everything came together quickly.

So here are some pictures of the RFID + Arduino + Shift Register + LCD setup.

 Arduino + LCD w/Shift + Parallax RFID

Here is the ‘authorized card’ being read.

 Arduino + LCD w/Shift + Parallax RFID
Response for authorized tag on LCD screen.
 Arduino + LCD w/Shift + Parallax RFID

Reading an unauthorized card.
 Arduino + LCD w/Shift + Parallax RFID

Response on LCD from unauthorized card.
 Arduino + LCD w/Shift + Parallax RFID

Well there you have it. Now for the source code.

// Parallax-RFID-LCDShiftReg-0.0.2 RFID reader for Arduino with LCD output
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic
// And pieces from Arduino Playground <http://www.arduino.cc/playground/Learning/PRFID>
// And then modified again by thekidd <http://www.tekcrack.com/category/rfid>
// 25.04.2008 – Added modified LCD4x40Bit-ShiftReg connection to display RFID results.
//              Fixed attachInterrupt lockup problem. Was set to CHANGE mode. Now set to LOW mode.
// 12.04.2008 – Added interrupt to ensure program does not hang on RFID reader.

#include <avr/interrupt.h>
#include <SoftwareSerial.h>
#include <LCD4Bit.h>

#define rxPin 2
#define txPin 3
#define ledPin 13

// LCD Variables
int lcdLines = 4;    // number of lines in your display
int doutPin = 11;    // Dout pin
int strPin = 12;     // Strobe pin
int clkPin = 10;     // Clock pin

// RFID Variables
int  val = 0;
int bytesread = 0;
char code[10];
int flag = 0;
int granted = 0;

// setup construct for lcd
LCD4Bit lcd = LCD4Bit(lcdLines, doutPin, strPin, clkPin);

// set up a soft serial port
SoftwareSerial mySerial(rxPin, txPin);

void setup() {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);    // Set rxPin as INPUT to accept SOUT from RFID pin
  pinMode(txPin, OUTPUT);   // Set txPin as OUTPUT to connect it to the RFID /ENABLE pin
  pinMode(ledPin, OUTPUT);  // Let the user know whats up

  // set the data rate for the serial ports
  mySerial.begin(2400);    // RFID reader SOUT pin connected to Serial RX pin at 2400bps

  lcd.init();         // initialize lcd
  lcd.cursorTo(1,0);  // select first display controller, line 1 & 2
  lcd.clear();        // clear lines 1 & 2
  lcd.cursorTo(3,0);  // select second display controller, line 3 & 4
  lcd.clear();        // clear lines 3 & 4
 
  delay(100);

  defaultMsg();

  attachInterrupt(0, readRFID, LOW); // Setup interrupt for SOUT on RFID reader
  digitalWrite(txPin, LOW);           // Activate the RFID reader
}

void loop() {
  // Do Something

  goRFID(); 
}

void goRFID() {
  if (flag == 1) {
    delay(1000);
    lcd.cursorTo(1,0);
    lcd.clear();
    lcd.printIn("Welcome to DCA.");
    lcd.cursorTo(2,0);
    lcd.printIn("TAG code is: ");  // possibly a good TAG
    lcd.printIn(code);           // print the TAG code
    validateRFID(code);             // Determine if right tag used. */
    flag = 0;
    delay(5000);
    digitalWrite(txPin, LOW);           // Activate the RFID reader
    defaultMsg();
  } else {
    delay(1000);
    digitalWrite(txPin, LOW);           // Activate the RFID reader
    defaultMsg();
  }
}
   

void readRFID() {
  digitalWrite(ledPin, LOW);          // Turn off debug LED – Event triggered!
  if((val = mySerial.read()) == 10) { // check for header
    bytesread = 0;

    while(bytesread<10) {             // read 10 digit code
      val = mySerial.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) {             // If 10 digit read is complete
      digitalWrite(txPin, HIGH);      // deactivate RFID reader
      digitalWrite(ledPin, HIGH);     // activate LED to show an RFID card was read
      flag = 1;
    }

    bytesread = 0;
  }
}

void validateRFID(char* i) {
  if( strncmp(i,"0F0302A114", 10) == 0) {
    // if 10 digit code equals "0F0302A114"
    digitalWrite(ledPin, HIGH); 
    lcd.cursorTo(3,0);
    lcd.clear();
    lcd.printIn("Tag matches…Access Granted!");
    lcd.cursorTo(4,0);
    lcd.printIn("Firing squad avoided!");
    digitalWrite(ledPin, LOW);
  } else {
    lcd.cursorTo(3,0);
    lcd.clear();
    lcd.printIn("Tag Failed…Access Denied!");
    lcd.cursorTo(4,0);
    lcd.printIn("Firing squad deployed!");
    digitalWrite(ledPin, LOW);
  }
}

void defaultMsg() {
  // say something
  lcd.cursorTo(1,0);
  lcd.printIn("Welcome to DCA Corp.");
  lcd.cursorTo(2,0);
  lcd.printIn("Please swipe your access card.");
  lcd.cursorTo(3,0);
  lcd.printIn("* Unauthorized access is prohibitted *");
  lcd.cursorTo(4,0);
  lcd.printIn("** Disobedience meets firing squad! **");
}

You can also download the sketch file here.

Hope this is helpful.

del.icio.us:Arduino + LCD w/Shift + Parallax RFID digg:Arduino + LCD w/Shift + Parallax RFID spurl:Arduino + LCD w/Shift + Parallax RFID wists:Arduino + LCD w/Shift + Parallax RFID simpy:Arduino + LCD w/Shift + Parallax RFID newsvine:Arduino + LCD w/Shift + Parallax RFID blinklist:Arduino + LCD w/Shift + Parallax RFID furl:Arduino + LCD w/Shift + Parallax RFID reddit:Arduino + LCD w/Shift + Parallax RFID fark:Arduino + LCD w/Shift + Parallax RFID blogmarks:Arduino + LCD w/Shift + Parallax RFID Y!:Arduino + LCD w/Shift + Parallax RFID smarking:Arduino + LCD w/Shift + Parallax RFID magnolia:Arduino + LCD w/Shift + Parallax RFID segnalo:Arduino + LCD w/Shift + Parallax RFID

4 Responses to “Arduino + LCD w/Shift + Parallax RFID”

  1. on 03 Mar 2009 at 8:53 am Alexwebmaster

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

  2. on 12 May 2009 at 9:15 am Ron L.

    Hi,

    What kind of LCD screen should I get (do you have the part number)? Also where can I find a detailed version of the wiring schema (Arduino to LCD screen)?

    Great job on this project!

    Ron

  3. on 14 May 2009 at 1:36 pm TheKidd

    Hey Ron,

    The easiest LCD to use would be a serial LCD as it takes very little work to connect to the Arduino. I ended up using a Purdy LCD.

    Datasheet: http://www.purdyelectronics.com/pdf/AND791GST.pdf

    The current version of the LCD library I edited is meant to run with a 74HC595N Shift Register. You can find the latest library and the schematics for such a setup here: http://www.tekcrack.com/arduino-purdy-lcd-74hc595n-shift-register.html

    Pretty much any LCD screen with the Purdy configuration which has a HD44780 compatible controller on it will work. The reason for using the shift register on the above post was because my particular LCD screen has two LCD controllers on it. If you had a screen with just one controller, you could compare the changes between the code in the above post and this post: http://www.tekcrack.com/interfacing-arduino-with-a-purdy-lcd-4×40-modified-lcd4bit-library.html

  4. on 25 Dec 2009 at 8:45 pm atog

    Hello,,

    i have lcd 4*40, but i don’t have datasheet. at the backside of my lcd any 404A3 VER1.0 code. if my lcd is same with your lcd 4*40?
    If not right, please help me to identify my lcd. becouse i’m confuse to identification my lcd.
    i have any datasheet too, there are H4004 type, AMC 4004C, PC 4004-A etc.
    wel, i am endding my questions.
    thanks for your attentions,

    besregard,

    atog

Trackback URI | Comments RSS

Leave a Reply

CommentLuv badge
TekCrack uses CommentLuv Premium, which allows you to use your real name and then @Your Keywords (max of 3 keywords). You will need 3 previously approved comments for this to work. Click on the link above to get your own CL Premium Plugin - the best way to build back links and visitors to your website.

Stop Censorship