Hi! I am new in posting forum.
Please point my mistakes if there happen to be one.I have been debugging this problem for 3 days with no solution avails.
I have a python scripts that detect face and will post the detected face id to Serial. Arduino will read the Serial port and process the data to detect the user by its id. My problem is when the Python scripts detect faces, it will send a stream of face id of the user. When the Arduino want to read the Serial, it detect many face id have been detected because python scripts have been coded like this:
if(face detected):
serialWrite(id)
When the face detected, python scripts will write many faceId to the Serial port. When the arduino want to read this, its read like many face have been detected.
This is the code to read the Serial Monitor. Don't worry the about ACCESS:: because it's in the other file.
void ACCESS::recvSerial()
{
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true)
{
if (rc != endMarker)
{
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars)
{
ndx = numChars - 1;
}
}
else
{
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker)
{
recvInProgress = true;
}
}
}
char *ACCESS::getData()
{
if (newData == true)
{
Serial.print("\nData from python: ");
Serial.println(receivedChars);
newData = false;
}
return receivedChars;
}
char *faceConformation(int ID)
{
detectedFaces = true;
access = true;
char* temp_name = userAccess.GetUserName(0, name); // get user name
Serial.print( *temp_name + "face detected");
lcd.clear();
lcd.setCursor(0,0);
lcd.print(temp_name);
lcd.setCursor(0,1);
lcd.print("Face detected");
return temp_name;
}
i'm calling the function like this:
ACCESS userAccess;
void loop ()
{
userAccess.recvSerial();
receivedChars = userAccess.getData();
if(strcmp(receivedChars, "1") == 0) // one is the id
{
username = faceConformation(0);
}else if(strcmp(receivedChars, "2") == 0)
{
username = faceConformation(1);
}else if(strcmp(receivedChars, "3") == 0)
{
username = faceConformation(2);
}else if(strcmp(receivedChars, "4") == 0)
{
username = faceConformation(3);
}
if(access)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Welcome");
lcd.setCursor(0,1);
lcd.print(username);
Serial.print("\nAuthorized\n");
delay(3000); // maybe change this delay to a beep or delay with a beep
lcd.clear();
}
}
When the face is detected, the lcd.print("Welcome "); print many time until the faced from serial port is readed.
How to filter duplicate input from serial monitor to only detect single face detected?
sorry for my bad english