hi
im trying to connect push button and Fingerprint to Arduino MEGA 2560
to do this
first push the button
second the fingerprint scanner will run to scan my fingerprint
after the fingerprint scan my finger it will pass the code and run function to receive string from serial port from arduino
between these step i make checkpoint to find and detect any error
when the arduino run it will print "Please Push button"
after i push the button the fingerprint scanner will run to scan my finger
after that arduion will print "Fingerprint Work Fine"
and the do serial receiving function
but thus never happen
and when i compile that after push the button fingerprint just pulse red light and never run again
if i edit the code and make this like commend "in the receiving from serial"
the code will work and run fine and the fingerprint scanner will run and scan my finger
and after that arduino will print "Fingerprint Work Fine"
char *token = strtok(inData, ","); // Get the first token
////////while(token)
{
values[index] = atoi(token); // convert the token to an int and store it in the array
index++; // Increment the index
token = strtok(NULL, ","); // Keep parsing the same string
}
if i disable while and make it comment the code will work fine ![]()
can someone tell me what the hell is happen in this code ![]()
there is no link between while in IF statement not activated to executed and the function of fingerprint
getFingerprintIDez();
also if i remove the comment and remove the finger function getFingerprintIDez();
the code will work fine when i push the button and arduino stop print "Please Push buttion"
is there bugs in Arduino IDE compiler
i try version 1.6 and i have the same problem
this is the code
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char dataPacket[64];
char inData[64];
byte index;
int d=0;
int ss=0;
#include <Adafruit_Fingerprint_MEGA.h>
int getFingerprintIDez();
#define mySerial Serial1
Adafruit_Fingerprint_MEGA finger = Adafruit_Fingerprint_MEGA(&mySerial);
int buttonState = 0;
const int buttonPin = 2;
void setup(void)
{
Serial.begin(9600);
finger.begin(57600);
}
void loop(void)
{
buttonState = digitalRead(buttonPin);
if (d==0){
Serial.println("Please Push Button");
if (buttonState == HIGH) {
d=1;
}
}
if(d==1){
getFingerprintIDez();
}
if(ss==1){
Serial.println("System Work Fine");
// Read all serial data available, as fast as possible
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 63)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
// We are here either because all pending serial
// data has been read OR because an end of
// packet marker arrived. Which is it?
if(started && ended)
{
// The end of packet marker arrived. Process the packet
int values[10]; // Array to hold the values
byte index = 0; // index into array
char *token = strtok(inData, ","); // Get the first token
while(token)
{
values[index] = atoi(token); // convert the token to an int and store it in the array
index++; // Increment the index
token = strtok(NULL, ","); // Keep parsing the same string
}
Serial.println("---------");
sprintf(dataPacket,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9]);
Serial.println(dataPacket);
Serial.println("---------");
Serial.flush();
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}
}
////########################################################################################
int getFingerprintIDez()
{
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
switch(finger.fingerID){
case 0:
Serial.println("Finger Work Fine ");
mySerial.end();
Serial1.end();
}
d=2;
ss=1;
return finger.fingerID;
}