sohotcall

FPM10A GenImg Arduino Nano

Jul 1st, 2018
273
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. $ ./arduino-cli sketch new fingerprint
  3. $ nano $HOME/Arduino/fingerprint/fingerprint.ino
  4. Terus kopas, Ctrl+O Return save, Ctrl+X exit
  5. $ ./arduino-cli compile --fqbn arduino:avr:nano:cpu=atmega328old $HOME/Arduino/fingerprint/
  6. $ ./arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328old $HOME/Arduino/fingerprint/
  7. $ minicom -D /dev/ttyUSB0 -p 57600
  8. */
  9.  
  10. #include <SoftwareSerial.h>
  11.  
  12. SoftwareSerial mySerial(10, 11); // RX, TX
  13.  
  14. // GND-nya module nyambung ke GND
  15. // RX-nya module nyambung ke pin 11 (Software TX)
  16. //// Bila fingerprint module tidak 5V tolerant namun arduinonya 5V,
  17. //// ganti jadi GND -- Resistor -- Resistor -- Rx-nya module -- Resistor -- pin 11
  18. //// Resistor = 1 kOhm (contoh)
  19. // TX-nya module nyambung ke pin 10 (Software RX)
  20. // VCC-nya module nyambung ke 5V atau 3.3V (sesuai module fingerpint)
  21. // T_OUT sambung ke GPIO input microcontroller (LOW = ada touch)
  22. // T_3V3 nyambung ke 3.3V
  23.  
  24. void setup() {
  25.   Serial.begin(57600); // Serial connected to PC (USB), tengok di Serial Monitor
  26.   while (! Serial) {} //
  27.   mySerial.begin(57600); // Software serial connected to FPM10A
  28.  
  29.   // Countdown timer, 5 detik untuk membuka Serial Monnitor
  30.   uint8_t s;
  31.   s = 5;
  32.   while (s > 0){
  33.     Serial.print("Ready in ");
  34.     Serial.println(s);
  35.     delay(1000);
  36.     s--;
  37.   }
  38.   Serial.println("Now");
  39.  
  40.   // Countdown timer, 5 detik untuk naruh jari
  41.   s = 5;
  42.   while (s > 0){
  43.     Serial.print("Scan your fingerprint in ");
  44.     Serial.println(s);
  45.     delay(1000);
  46.     s--;
  47.   }
  48.   Serial.println("Now");
  49.  
  50.   // The GenImg command, memerintah module untuk melakukan scan
  51.   mySerial.write((uint8_t) 0xEF); // START
  52.   mySerial.write((uint8_t) 0x01); // START
  53.   mySerial.write((uint8_t) 0xFF); // ADDR
  54.   mySerial.write((uint8_t) 0xFF); // ADDR
  55.   mySerial.write((uint8_t) 0xFF); // ADDR
  56.   mySerial.write((uint8_t) 0xFF); // ADDR
  57.   mySerial.write((uint8_t) 0x01); // PID:01 (Command)
  58.   mySerial.write((uint8_t) 0x00); // LENGTH
  59.   mySerial.write((uint8_t) 0x03); // LENGTH
  60.   mySerial.write((uint8_t) 0x01); // DATA:01 (GenImg)
  61.   mySerial.write((uint8_t) 0x00); // SUM
  62.   mySerial.write((uint8_t) 0x05); // SUM
  63.   delay(1000); // waiting for result
  64.  
  65.   // The GenIm result, menerima result dari module dan menampilkan ke Serial Monitor
  66.   // Result should be something like EF 01 FF FF FF FF 07 00 03 00 00 0A
  67.   // Start:EF01, Addr:FFFFFFFF, PID:07 (Confirmation), Length:0003, Data:00 (OK), Sum:000A
  68.   Serial.println("Result:");
  69.   while (mySerial.available()){
  70.     uint8_t d = mySerial.read();
  71.     if (d < 0x0F)
  72.       Serial.print(0);
  73.     Serial.print(d, HEX);
  74.     Serial.print(' ');
  75.   }
  76.   Serial.println();
  77.  
  78.   // For command list, see https://pastebin.com/ezC4rmZy
  79. }
  80.  
  81. void loop() { }
RAW Paste Data