Hi, i am having a problem concerning this product:
i am using Arduino Mega to in order to get the raw image of the fingerprint and i connected it properly and successfully sent the command packet and received the response packet as an ack while the data packet in the datasheet saying i will receive 19200 Bytes of data for raw image.
so when i set the for loop to receive data to (256X256) bytes to receive HEX the data is less than (256X256) bytes
// constants won't change.
const int button1 = 3; //Define button to digital input pins
const int button2 = 4; //Define button to digital input pins
const int button3 = 5; //Define button to digital input pins
const int ledPin = 13;// the number of the LED pin
int f; // Counter for array position
int b=0;
byte ResponseData[38]; //Array to recieve data from serial port.
byte CommandPacket[12]; //Array to construct command packet
int previous =LOW;
uint16_t rawimageresponse;
int reading1 = 0;
int c;
//Call External libaries
//Items that are run once go here
void setup() {
pinMode(button1, INPUT);
pinMode(ledPin, OUTPUT);
//Serial.begin(38400); // Start serial comms for display out
Serial.begin(115200);
Serial1.begin(9600);// Start serial comms for scanner
baudrate ();
Serial1.end();
Serial1.begin(115200);
opencon();
Serial.print("FirmwareVersion: ");
for (f = 16; f < 20; f++)
{
Serial.print(ResponseData[f],HEX); //FirmwareVersion
}
Serial.println();
Serial.print("DeviceSerialNumber: ");
for (f = 20; f < 36; f++)
{
Serial.print(ResponseData[f],HEX); //SerialNumber
}
delay(1000);
f=16;
}
// Main Programme Loop
void loop() {
// read the state of the switch into a local variable:
int reading1 = digitalRead(button1);
if (reading1 == HIGH && previous == LOW)
{
Serial.println("LED ON");
digitalWrite(ledPin, HIGH);
Serial.println();
ledon();
previous = HIGH;
reading1=LOW;
capturefinger();
delay(5000);
getimage();
}
if(reading1 ==HIGH && previous == HIGH)
{
Serial.println("LED OFF");
digitalWrite(ledPin, LOW);
ledoff();
previous = LOW;
}
}
//Subroutines go here
void SendCmdPacket()
{
int a = 0; //Counter value
int checkvalue = 0;
//Calculate the value for the checksum; sum of the first ten command values in decimal
for (a = 0; a < 10; a++)
{
checkvalue = (checkvalue + CommandPacket[a]);
}
a= 0; //Reset the counter
// Assign the results of the checksum to the 12th and 11th values of the array
CommandPacket[10] = (lowByte(checkvalue));
CommandPacket[11] = (highByte(checkvalue));
// Print out values for debuging
Serial.println();
Serial.print("checksum value (Decimal):- ");
Serial.println(checkvalue);
Serial.print("checksum value (Hex):- ");
Serial.println(checkvalue, HEX);
//Serial.println(lowByte(checkvalue));
//Serial.println(highByte(checkvalue));
Serial.println();
//Write contents of array to scanner
Serial.println("Command sent to scanner:- ");
for (a = 0; a < 12; a++)
{
Serial1.write(CommandPacket[a]),HEX;
Serial.print(CommandPacket[a], HEX);
Serial.print(", ");
}
Serial.println();
delay(500);
a= 0; //Reset the counter
//Read data returned from the scanner and assemble into array ResponseData
if (Serial1.available() > 0 ){
for (a = 0; a < 38; a++)
{
ResponseData[a] = Serial1.read(),HEX;
}
a= 0; //Reset the counter
Serial.println();
Serial.println("Responce from scanner:- ");
for (a = 0; a < 12; a++){
Serial.print(ResponseData[a], HEX);
}
Serial.println();
a= 0; //Reset the counter
}
}
void SendCmdPacket1()
{
int a = 0; //Counter value
int checkvalue = 0;
//Calculate the value for the checksum; sum of the first ten command values in decimal
for (a = 0; a < 10; a++)
{
checkvalue = (checkvalue + CommandPacket[a]);
}
a= 0; //Reset the counter
// Assign the results of the checksum to the 12th and 11th values of the array
CommandPacket[10] = (lowByte(checkvalue));
CommandPacket[11] = (highByte(checkvalue));
// Print out values for debuging
Serial.println();
Serial.print("checksum value (Decimal):- ");
Serial.println(checkvalue);
Serial.print("checksum value (Hex):- ");
Serial.println(checkvalue, HEX);
//Serial.println(lowByte(checkvalue));
//Serial.println(highByte(checkvalue));
Serial.println();
//Write contents of array to scanner
Serial.println("Command sent to scanner:- ");
for (a = 0; a < 12; a++)
{
Serial1.write(CommandPacket[a]),HEX;
Serial.print(CommandPacket[a], HEX);
Serial.print(", ");
}
Serial.println();
delay(500);
a= 0; //Reset the counter
//Read data returned from the scanner and assemble into array ResponseData
if (Serial1.available() > 0 ){
/*for (a = 0; a<16; a++)
{
rawimageresponse = Serial1.read(),HEX;
Serial.print(rawimageresponse, HEX);
Serial.println();
}
a=0;*/
// Serial.print("%");
// Serial.println();
for( b=0;b<256;b++){
for (a=0;a<256;a++)
{
while (!Serial1.available()) ; // Wait until a character is available
rawimageresponse = Serial1.read();
Serial.print(rawimageresponse,HEX);
}
Serial.println();
a= 0; //Reset the counter
}
}}
void opencon()
{
CommandPacket[0] = ((byte)0x55); // Head1 :fixed
CommandPacket[1] = ((byte)0xAA); // Head2 :fixed
CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1
CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
//Set default values for the Dword set
CommandPacket[4] = ((byte)0x01); // Dword #1
CommandPacket[5] = ((byte)0x00); // Dword #2
CommandPacket[6] = ((byte)0x00); // Dword #3
CommandPacket[7] = ((byte)0x00); // Dword #4
CommandPacket[8] = ((byte)0x01); // Command code #1
CommandPacket[9] = ((byte)0x00); // Command Code #2
SendCmdPacket();
}
void baudrate()
{
CommandPacket[0] = ((byte)0x55); // Head1 :fixed
CommandPacket[1] = ((byte)0xAA); // Head2 :fixed
CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1
CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
CommandPacket[4] = ((byte)0x00); // Dword #1
CommandPacket[5] = ((byte)0xC2); // Dword #2
CommandPacket[6] = ((byte)0x01); // Dword #3
CommandPacket[7] = ((byte)0x00); // Dword #4
// Array values 8&9 define the command code. Check communication with scanner by getting S/N and F/W
CommandPacket[8] = ((byte)0x04); // Command code #1
CommandPacket[9] = ((byte)0x00); // Command Code #2
SendCmdPacket();
}
void ledon()
{
CommandPacket[0] = ((byte)0x55); // Head1 :fixed
CommandPacket[1] = ((byte)0xAA); // Head2 :fixed
CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1
CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
CommandPacket[4] = ((byte)0x01); // Dword #1
CommandPacket[5] = ((byte)0x00); // Dword #2
CommandPacket[6] = ((byte)0x00); // Dword #3
CommandPacket[7] = ((byte)0x00); // Dword #4
CommandPacket[8] = ((byte)0x12); // Command code #1 Request enrol count
CommandPacket[9] = ((byte)0x00); // Command Code #2
SendCmdPacket();
}
void capturefinger()
{
CommandPacket[0] = ((byte)0x55); // Head1 :fixed
CommandPacket[1] = ((byte)0xAA); // Head2 :fixed
CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1
CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
CommandPacket[4] = ((byte)0x01); // Dword #1
CommandPacket[5] = ((byte)0x00); // Dword #2
CommandPacket[6] = ((byte)0x00); // Dword #3
CommandPacket[7] = ((byte)0x00); // Dword #4
CommandPacket[8] = ((byte)0x60); // Command code #1 Request enrol count
CommandPacket[9] = ((byte)0x00); // Command Code #2
SendCmdPacket();
}
void getimage()
{
CommandPacket[0] = ((byte)0x55); // Head1 :fixed
CommandPacket[1] = ((byte)0xAA); // Head2 :fixed
CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1
CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
CommandPacket[4] = ((byte)0x00); // Dword #1
CommandPacket[5] = ((byte)0x00); // Dword #2
CommandPacket[6] = ((byte)0x00); // Dword #3
CommandPacket[7] = ((byte)0x00); // Dword #4
CommandPacket[8] = ((byte)0x62); // Command code #1 Request enrol count
CommandPacket[9] = ((byte)0x00); // Command Code #2
SendCmdPacket1();
}