I've got this fingerprint scanner from sparkfun
https://learn.sparkfun.com/tutorials/fingerprint-scanner-gt-521fxx-hookup-guide/all#example-code-for-arduino
and I'm trying to write my own code to send it commands
// sketch to send fingerprint scanner commands
// take in 5 words big endian, add up bytes for word checksum (not currently working, entering checksum also
// (simple summing of the individual byte, saved as word)
// send out 6 words little endian (swap bytes)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5); // (Arduino SS_RX = pin 4, Arduino SS_TX = pin 5)
byte incomingCommand[24]; // from Serial
byte outgoingCommand[24]; // to device
unsigned int outgoingWords[12];
unsigned int x;
byte newByte;
void setup() {
Serial.begin(115200);
mySerial.begin(9600);
Serial.println ("ready (.s are for entry readability only)");
}
void loop() {
if (Serial.available() > 23 ) { // read in big endian words, 5 words + checksum word
for (x = 0; x < 24; ++x) {
newByte = Serial.read();
if (newByte <= '9') { // 48 to 57 = 0 to 9
newByte = newByte - '0';
}
if (newByte >= 'A') { // 65 to 70 = A to F
newByte = newByte + 10 - 'A';
}
incomingCommand[x] = newByte;
}
Serial.print("inCommand + checksum: ");
for (x = 0; x < 24; ++x) {
Serial.print (incomingCommand[x], HEX); // display them
if ((x & 0x01) == 1) {
Serial.print (".");
}
}
Serial.println("");
for (x = 0; x < 6; ++x) { // swap the words
outgoingCommand[(x * 4) + 0] = incomingCommand[(x * 4) + 2];
outgoingCommand[(x * 4) + 1] = incomingCommand[(x * 4) + 3];
outgoingCommand[(x * 4) + 2] = incomingCommand[(x * 4) + 0];
outgoingCommand[(x * 4) + 3] = incomingCommand[(x * 4) + 1];
}
Serial.print ("to device: ");
for (x = 0; x < 24; ++x) {
Serial.print (outgoingCommand[x], HEX);
if ((x & 0x01) == 1) {
Serial.print (".");
}
mySerial.write (outgoingCommand[x]);
}
Serial.println("");
Serial.println("from device");
}
if (mySerial.available() > 0) {
Serial.print ("got ");
Serial.print (mySerial.read() );
}
}
Supposedly this code will "open", and send it the command to turn the LED on and off.
The messages are little endian, I am entering the message as big endian as that is what the document describes, and then converting it. Also makes it easier to follow.
I can enter AA5500010000000000010101
and confirm it puts that in the incomingCommand array as 24 bytes,
then swap the words in the outgoingCommand array as 24 bytes.
It seems to me that each byte now represents one nibble of a byte to be sent out to make up 12 bytes, and I can't figure out how to combine them to do that. I'm pretty sure what I am doing is not correct as I never get a reply from the unit. If I run the Blink example using the FPS_GT511C3.h library the module works.
Examples given:
FPS - Open
FPS - SEND: "55 AA 01 00 00 00 00 00 01 00 01 01"
FPS - RECV: "55 AA 01 00 00 00 00 00 30 00 30 01"
FPS - LED on
FPS - SEND: "55 AA 01 00 01 00 00 00 12 00 13 01"
FPS - RECV: "55 AA 01 00 00 00 00 00 30 00 30 01"
FPS - LED off
FPS - SEND: "55 AA 01 00 00 00 00 00 12 00 12 01"
FPS - RECV: "55 AA 01 00 00 00 00 00 30 00 30 01"
What I am seeing on the serial monitor
ready (.s are for entry readability only)
inCommand + checksum: AA.55.00.01.00.00.00.00.00.01.01.01.
to device: 55.AA.01.00.00.00.00.00.01.00.01.01.
from device
inCommand + checksum: AA.55.00.01.00.00.00.00.00.01.01.01.
to device: 55.AA.01.00.00.00.00.00.01.00.01.01.
from device
What I think I need to end up with
0x55AA (or 0x55 and 0xAA)
0x0001
0x0000
0x0000
0x0001
0x0101
How do I make the code do that?
Thanks
FPS_Blink.ino (3.81 KB)
FPS_GT511C3.h (13.9 KB)