Skip to content

Instantly share code, notes, and snippets.

@vishnumaiea
Created March 20, 2019 09:36
Show Gist options
  • Save vishnumaiea/03e100d91e6e360aa971bc1e08b0ff9d to your computer and use it in GitHub Desktop.
Save vishnumaiea/03e100d91e6e360aa971bc1e08b0ff9d to your computer and use it in GitHub Desktop.
Test code to interface R307 Fingerprint Sensor with Arduino Due
//======================================================================//
//
// Description : Test code to interface R307 Fingerprint Sensor with
// Arduino Due. Due's second UART port (Serial1) is used
// to interface the R307.
//
//======================================================================//
void setup() {
Serial.begin(9600);
Serial1.begin(57600);
Serial.println("R307 Fingerprint Test");
}
void loop() {
byte serialBuffer [64] = {0};
int serialBufferLength = 0;
byte byteBuffer = 0;
int timeoutCounter = 0;
//EF 01 FF FF FF FF 01 00 07 13 FF FF FF FF 04 17 - VfyPwd packet
Serial.println("Sending VfyPwd packet..");
Serial1.write(0xEFU); //packet start - high byte first
Serial1.write(0x01U); //packet start - second byte
Serial1.write(0xFFU); //module address - 4 bytes
Serial1.write(0xFFU);
Serial1.write(0xFFU);
Serial1.write(0xFFU);
Serial1.write(0x01U); //package identifier
Serial1.write(byte(0)); //package length
Serial1.write(0x07U); //length = data/cmd bytes + checksum
Serial1.write(0x013U); //instruction code
Serial1.write(byte(0)); //4 byte password
Serial1.write(byte(0));
Serial1.write(byte(0));
Serial1.write(byte(0));
Serial1.write(byte(0));
Serial1.write(0x1BU);
// uint16_t packetChecksum = 0x01U + 0x00U + 0x03U + 0x0FU; //calculate checksum
// Serial.print("Checksum is ");
// Serial.println(packetChecksum);
// Serial1.write(uint8_t(packetChecksum >> 8)); //checksum
// Serial1.write(uint8_t(packetChecksum & 0xFFU));
while (timeoutCounter < 1000) {
if(Serial1.available()) {
byteBuffer = Serial1.read();
serialBuffer[serialBufferLength] = byteBuffer;
serialBufferLength++;
// Serial.print(byteBuffer, HEX);
// Serial.print(" - ");
timeoutCounter++;
delay(1);
}
else {
delay(1);
timeoutCounter++;
}
// if(timeoutCounter == 1000) {
// Serial.println();
// }
}
Serial.print("Response Length = ");
Serial.println(serialBufferLength);
Serial.print("Response = ");
for(int i=0; i<serialBufferLength; i++) {
Serial.print(serialBuffer[i], HEX);
if(i != (serialBufferLength-1)) {
Serial.print("-");
}
}
Serial.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment