this is my first code on processing java finger print sensor on arduino

edited June 2014 in Share Your Work
import processing.serial.*;
import java.util.Date;

int inByte;
int col = 50 ;
PImage img1;

int curr, prevSec;
int offset;

Serial myPort;
PrintWriter output, input;
BufferedReader reader;
String[] line;


int prev = 0;
int oldInByte=0;
int offSet=0;

String _day, _month, _year, _hour, _minute, _second;
String _path =".txt";
String s1;

String[] userNames;
int index=0;
String[][] lists ;

void setup()
{
  size(800, 400);
  background(255, 255, 0);
  textSize(32);
  //input = createWriter("ReadUserID.txt");
  int var=1;
  _day = str(day());
  _month = String.valueOf(month());
  _year = String.valueOf(year());
  _hour = str(hour());
  _minute = str(minute());
  _second = str(second());

  //  s1 = _year+'/'+_month+'/'+_day+'/'+_month+_year+_path;
  s1 =_year+"year"+'/'+_month+"month"+'/'+_day+"day"+'/'+_hour+'.'+_minute+_path;


  output = createWriter(s1); 
  output.println(" txt file generated by fingerPrintExporter - v.2.0");
  output.println("");
  output.println("#####################################################");
  output.println(";Date/Time:"+month()+'/'+day()+'/'+year()+"\t"+ hour()+':'+minute()+':'+second()); 
  output.println("#####################################################");
  reader = createReader("ReadUserId.txt");

  // String lastModified = new Date(f.lastModified()).toString();
  //  frameRate(12);

  img1 = loadImage("500px-Print_Sensor.jpg");

  // create a font with the third font available to the system:
  PFont myFont = createFont(PFont.list()[9], 30);
  textFont(myFont);
  printArray(Serial.list());

  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
  //  noLoop();

  userNames = loadStrings("ReadUserId.txt");
}


int cntr;
void draw()
{


  background(#ffffff);
  image(img1, 500, 0); 


  text("Finger Print Id Detector /2014", 5, 20);
  text(millis()/60000+" min", col, 75);
  if (inByte==255 ) {
    text("Recieved data: < >\n", col, 100);
    text("< Place your Finger !...>", 500, 200);
  } else text("Recieved data:< "+inByte+" >", col, 100);
  fill(#000000);
  if (inByte==255 || inByte==0)text("reading new  id ", col, 200);
  else text("ID "+inByte+" belong to : ..  ", col, 200);
  text("Date:"+day()+"/"+month()+"/"+year()+"    \t"+"Time:"+hour()+":"+minute()+":"+second(), 500, 250);
  // text("Time:"+hour()+":"+minute()+":"+second(),col,150);
  s1  = "name:";
  // output.println(s1);
  if (prev>254)prev=254;
  if (prev<=0)prev = 0;
  text("Last."+userNames[prev], col, 300);



  output.flush();
}

void serialEvent(Serial myPort)
{
  inByte = myPort.read();
  if (inByte>0 && inByte<255)prev = inByte;
  if (prev!=curr) {
    curr = prev; 
    output.println("-------------------------------------------");
    output.println( "\t"+hour()+":"+minute()+":"+second()+"\t "+userNames[prev-1]);
  }
}

void keyPressed() {
  output.flush();  // Writes the remaining data to the file
  output.close();  // Finishes the file
  exit();  // Stops the program
}

Comments

  • // arduino code #include <EEPROM.h>

    #include <Adafruit_Fingerprint.h>
    #include  <LiquidCrystal.h>
    #include <SoftwareSerial.h>
    
    //    LCD Defintion pins
    ///////////////////////////////////////////////////
    #define RS  8
    #define EN  9
    #define D4  4
    #define D5  5
    #define D6  6
    #define D7  7
    //////////////////////////////////////////////
    LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
    //////////////////////////////////////////
    /////////////////////////////////////////////////
    //  keys Defintions
    #define KEY_ADC_CH 0
    int key     = 0;
    int adc_key_in  = 0;
    #define btnRIGHT  0
    #define btnUP     1
    #define btnDOWN   2
    #define btnLEFT   3
    #define btnSELECT 4
    #define btnNONE   5
    
    byte btnCntr = 0;
    ////////////////////////////////////////////////////////
    // read the buttons
    int read_buttons()
    {
      adc_key_in = analogRead(KEY_ADC_CH);      // read the value from the sensor
      // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
      // we add approx 50 to those values and check to see if we are close
      if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
      // For V1.1 us this threshold
      if (adc_key_in < 50)   return btnRIGHT;
      if (adc_key_in < 250)  return btnUP;
      if (adc_key_in < 450)  return btnDOWN;
      if (adc_key_in < 650)  return btnLEFT;
      if (adc_key_in < 850)  return btnSELECT;
    
      return btnNONE;  // when all others fail, return this...
    }
    
    ////////////////////////////////////////////////
    SoftwareSerial mySerial(12, 13);
    Adafruit_Fingerprint finger(&mySerial);
    
    uint8_t getFingerprintEnroll(uint8_t id);//
    int getFingerprintIDez();
    
    void clearLine2()
    {
      lcd.setCursor(0, 1);
      lcd.print("                ");
      lcd.setCursor(0, 1);
    }
    
    void clearLine1()
    {
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 0);
    }
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      // Serial.println("fingertest");
     // EEPROM.write(0,1);
    
    
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
      lcd.print("FPrint Reader ");
      delay(2000);
      lcd.clear();
    
      finger.begin(57600);
      lcd.setCursor(0, 0);
      lcd.print("ScanFPrint");
      if (finger.verifyPassword()) {
    
        lcd.clear();
        lcd.print("findFPrintReader");
      }
      else {
        lcd.clear();
        lcd.print("didnt find FP");
        while(1);
      }
    
      delay(3000);
      lcd.clear();
    
    }
    
    int offSet=0;
    int adr = 0;
    
    
    
    void loop() {
      // put your main code here, to run repeatedly:
    
      lcd.setCursor(0, 0);
      lcd.print("Type ID:");
      static   uint8_t id = 0;
    
      while (true) {
        while (read_buttons() == btnNONE)
        {
          int res = getFingerprintIDez();
          if(offSet!=res){
          offSet = res;
          Serial.write(res);   // send data to path serial out put
          }
    
        }
        char c = read_buttons();
        bool ret = 0;
        switch (c)
        {
          case btnUP  : id++; break;
          case btnDOWN: id--; break;
          case btnSELECT: ret = true; break;
        }
    
        lcd.setCursor(8, 0);
        lcd.print("   ");
        lcd.setCursor(8, 0);
        lcd.print(id, DEC);
        delay(500);
        if (ret) break;
      }
      delay(500);
    
    
      while (! getFingerprintEnroll(id));
    
    }
    
    ////////////////////////////////////////////
    uint8_t getFingerprintEnroll(uint8_t id) {
      uint8_t p = -1;
    
      // lcd.print("Waiting for vID");
    
      while (p != FINGERPRINT_OK) {
        clearLine2();
        p = finger.getImage();
        switch (p) {
          case FINGERPRINT_OK:
            lcd.print("Image taken");
            break;
          case FINGERPRINT_NOFINGER:
            lcd.print(".");
            break;
          case FINGERPRINT_PACKETRECIEVEERR:
            lcd.print("CommunicationErr");
            break;
          case FINGERPRINT_IMAGEFAIL:
            lcd.print("Imaging error");
            break;
          default:
            lcd.print("Unknown error");
            break;
        }
      }
    
      // OK success!
      clearLine2();
      p = finger.image2Tz(1);
      switch (p) {
        case FINGERPRINT_OK:
          lcd.print("Image converted");
          break;
        case FINGERPRINT_IMAGEMESS:
          lcd.print("Image too messy");
          return p;
        case FINGERPRINT_PACKETRECIEVEERR:
          lcd.print("Communication error");
          return p;
        case FINGERPRINT_FEATUREFAIL:
          lcd.print("No features");
          return p;
        case FINGERPRINT_INVALIDIMAGE:
          lcd.print("No features");
          return p;
        default:
          lcd.print("Unknown error");
          return p;
      }
      clearLine2();
      lcd.print("Remove finger");
      delay(2000);
      p = 0;
      while (p != FINGERPRINT_NOFINGER) {
        p = finger.getImage();
      }
    
      p = -1;
      clearLine2();
      lcd.print("PlaceFingerAgain");
      while (p != FINGERPRINT_OK) {
        clearLine2();
        p = finger.getImage();
        switch (p) {
          case FINGERPRINT_OK:
            lcd.print("Image taken");
            break;
          case FINGERPRINT_NOFINGER:
            lcd.print(".");
            break;
          case FINGERPRINT_PACKETRECIEVEERR:
            lcd.print("CommunicationError");
            break;
          case FINGERPRINT_IMAGEFAIL:
            lcd.print("Imaging error");
            break;
          default:
            lcd.print("Unknown error");
            break;
        }
      }
    
      // OK success!
      clearLine2();
      p = finger.image2Tz(2);
      switch (p) {
        case FINGERPRINT_OK:
          lcd.print("Image converted");
          break;
        case FINGERPRINT_IMAGEMESS:
          lcd.print("Image too messy");
          return p;
        case FINGERPRINT_PACKETRECIEVEERR:
          lcd.print("CommunicationErr");
          return p;
        case FINGERPRINT_FEATUREFAIL:
          lcd.print(" no FP features");
          return p;
        case FINGERPRINT_INVALIDIMAGE:
          lcd.print(" no FP features");
          return p;
        default:
          lcd.print("Unknown error");
          return p;
      }
    
    
      // OK converted!
      clearLine2();
      p = finger.createModel();
      if (p == FINGERPRINT_OK) {
        lcd.print("Prints matched!");
      } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
        lcd.print("Communication error");
        return p;
      } else if (p == FINGERPRINT_ENROLLMISMATCH) {
        lcd.print("FP did not match");
        return p;
      } else {
        lcd.print("Unknown error");
        return p;
      }
      clearLine2();
      p = finger.storeModel(id);
      if (p == FINGERPRINT_OK) {
        lcd.print("Stored!");
      } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
        lcd.print("Communication error");
        return p;
      } else if (p == FINGERPRINT_BADLOCATION) {
        lcd.print("no store location");
        return p;
      } else if (p == FINGERPRINT_FLASHERR) {
        lcd.print("Error write flash");
        return p;
      } else {
        lcd.print("Unknown error");
        return p;
      }
    
    }
    
    /////////////////////////////////////////////////////////
    // returns -1 if failed, otherwise returns ID #
    int getFingerprintIDez() {
      uint8_t p = finger.getImage();
      if (p != FINGERPRINT_OK)  return -1;
    
      p = finger.image2Tz();
      if (p != FINGERPRINT_OK)  return -1;
    
      p = finger.fingerFastSearch();
      if (p != FINGERPRINT_OK)  return -1;
    
      // found a match!
      clearLine2();
      lcd.print("Found ID :");
      lcd.print(finger.fingerID, DEC);
      //  Serial.print(" with confidence of "); Serial.println(finger.confidence);
    
      //Serial.print("Found ID #"); Serial.print(finger.fingerID); 
      //Serial.print(" with confidence of "); Serial.println(finger.confidence);
      return finger.fingerID;
    }
    
  • hi to all

Sign In or Register to comment.