hello everyone. i currently make try to make a simple project. uno with fingerprint reader. as startup i try to add fingerprint.
at first. i try run the fingerprint reader + uno with X-CTU only. i use the terminal of the X-CTU. i sent the command code of the reader. and the reader reply with correct respond code & success operation code.
as u can see in the picture, the first 8 bytes {0x4D, 0x58, 0x10, 0x03, 0x40, 0x00, 0x00, 0xF8} is the command code for add fingerprint. then the reader reply 6 bytes correct respond code, {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7}. later the reader reply 7 bytes success operation code, {0x4D, 0x58, 0x30, 0x02, 0x40, 0x31, 0x48}.
then, i try make the program. so that it follow exactly what the reader respond as i tested above. i manage to make the code. by using X-CTU. i key the respond code, the arduino program able to detect the 6 bytes of the correct respond code & 7 bytes of success operation.
however, when i try to combine them both, it doesn't being to be happen. the arduino uno transmit the command code. but, the reader doesn't respond to that code. i believe there is a problem with my code. but, i don't have any idea where's the problem. with all, regards.
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,4,5,6,7);
byte addFingerPrint[] = {0x4D, 0x58, 0x10, 0x03, 0x40, 0x00, 0x00, 0xF8}; // 8 bytes
byte respondCorrect[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7}; // 6 bytes
byte operationSuccess[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x31, 0x48}; // 7 bytes
byte timeOut[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x33, 0x4A}; // 7 bytes
byte processFailure[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x34, 0x4B}; // 7 bytes
byte parameterError [] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x35, 0x4C}; // 7 bytes
byte respond[6],operation[7],a,b,c,d;
void setup() {
// initialize serial:
Serial.begin(57600);
// set up the LCD's number of columns and rows:
lcd.begin(8, 2);
displayLCD();
addFinger();
correctRespond();
operationSuccesful();
}
void displayLCD(){
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Fingerprint Reader");
}
void addFinger(){
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Add Fingerprint");
// write the 8bytes array of the command code
Serial.write(addFingerPrint, sizeof(addFingerPrint));
//delay(2000);
}
void correctRespond() {
// Now, reply contains all 6 bytes
for(byte n=0; n<6; n++)
{
while(Serial.available() == 0) {}; // Wait for a byte
respond[n] = Serial.read();
a = memcmp(respondCorrect, respond, sizeof(respondCorrect));
if (a>0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Wrong ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Respond ");
}
else if (a<0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Wrong ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Respond ");
}
else {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Correct ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Respond ");
}
}
delay(2000);
}
void operationSuccesful() {
// Now, reply contains all 7 bytes
for(byte n=0; n<7; n++)
{
while(Serial.available() == 0) {}; // Wait for a byte
operation[n] = Serial.read();
b = memcmp(operationSuccess, operation, sizeof(operationSuccess));
if (b==0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Operation");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Success ");
}
else {
c = memcmp(processFailure, operation, sizeof(processFailure));
if (c==0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Process ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Failure ");
}
else {
d = memcmp(parameterError, operation, sizeof(parameterError));
if (d==0) {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Parameter");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Error ");
}
else {
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Time ");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print a message to the LCD.
lcd.print("Out ");
}
}
}
}
delay(2000);
}
void loop() {
}