ESP32 FireBeetle Board and Servo Motor

Hello,

I am currently doing a lock door using the FPM10A fingerprint sensor and a servo motor. I read that there might be a conflict between the software serial and servo libraries but when I verify the code I get no error.

The scope of this project is to make the servo motor rotate when I enroll the fingerprint which works but no movement from the servo.

When I used the Servo.h library it did not work with this board and I got an error, but for the ESP32Servo.h library it seems fine.

Here is the code:
#include <SoftwareSerial.h>
#include <FPM.h>
//#include <Servo.h>
#include <ESP32Servo.h>
//#include <PWMServo.h>

/* Enroll fingerprints */

/* pin #2 is IN from sensor (GREEN wire)

  • pin #3 is OUT from arduino (WHITE/YELLOW wire)
    */

int pos = 0;
SoftwareSerial fserial(14, 12);

FPM finger(&fserial);
FPM_System_Params params;

const int servoPin = 18; //servo motor conectat la pinul 18 de la ESP unde se trimit semnalele (pin de PWM-portocaliu)
Servo myservo; //creare variabila servo

void setup()
{

Serial.begin(9600);    
Serial.println("ENROLL test");
fserial.begin(57600);

ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
myservo.setPeriodHertz(50);   //cu frecventa se controleaza distanta pe care o parcurge si directia
myservo.attach(servoPin, 1000, 2000);   //servoPin inseamna ca servo motorul o sa fie pe pinul ala de acum incolo

if (finger.begin()) {
    finger.readParams(&params);
    Serial.println("Found fingerprint sensor!");
    Serial.print("Capacity: "); Serial.println(params.capacity);
    Serial.print("Packet length: "); Serial.println(FPM::packet_lengths[params.packet_len]);
} else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) yield();
}

/* just to find out if your sensor supports the handshake command */
if (finger.handshake()) {
    Serial.println("Handshake command is supported.");
}
else {
    Serial.println("Handshake command not supported.");
}

}

void loop()
{
Serial.println("Send any character to enroll a finger...");
while (Serial.available() == 0) yield();
Serial.println("Searching for a free slot to store the template...");
int16_t fid;
if (get_free_id(&fid))
enroll_finger(fid);
else
Serial.println("No free slot in flash library!");
while (Serial.read() != -1); // clear buffer
}

bool get_free_id(int16_t * fid) {
int16_t p = -1;
for (int page = 0; page < (params.capacity / FPM_TEMPLATES_PER_PAGE) + 1; page++) {
p = finger.getFreeIndex(page, fid);
switch (p) {
case FPM_OK:
if (*fid != FPM_NOFREEINDEX) {
Serial.print("Free slot at ID ");
Serial.println(*fid);
return true;
}
break;
case FPM_PACKETRECIEVEERR:
Serial.println("Communication error!");
return false;
case FPM_TIMEOUT:
Serial.println("Timeout!");
return false;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
return false;
default:
Serial.println("Unknown error!");
return false;
}
yield();
}

Serial.println("No free slots!");
return false;

}

int16_t enroll_finger(int16_t fid) {
int16_t p = -1;
Serial.println("Waiting for valid finger to enroll");
while (p != FPM_OK) {
p = finger.getImage();
switch (p) {
case FPM_OK:
Serial.println("Image taken");
break;
case FPM_NOFINGER:
Serial.println(".");
break;
case FPM_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FPM_IMAGEFAIL:
Serial.println("Imaging error");
break;
case FPM_TIMEOUT:
Serial.println("Timeout!");
break;
case FPM_READ_ERROR:
Serial.println("Got wrong PID or length!");
break;
default:
Serial.println("Unknown error");
break;
}
yield();
}
// OK success!

p = finger.image2Tz(1);
switch (p) {
    case FPM_OK:
        Serial.println("Image converted");
        break;
    case FPM_IMAGEMESS:
        Serial.println("Image too messy");
        return p;
    case FPM_PACKETRECIEVEERR:
        Serial.println("Communication error");
        return p;
    case FPM_FEATUREFAIL:
        Serial.println("Could not find fingerprint features");
        return p;
    case FPM_INVALIDIMAGE:
        Serial.println("Could not find fingerprint features");
        return p;
    case FPM_TIMEOUT:
        Serial.println("Timeout!");
        return p;
    case FPM_READ_ERROR:
        Serial.println("Got wrong PID or length!");
        return p;
    default:
        Serial.println("Unknown error");
        return p;
}

Serial.println("Remove finger");
delay(2000);
p = 0;
while (p != FPM_NOFINGER) {
    p = finger.getImage();
    yield();
}

p = -1;
Serial.println("Place same finger again");
while (p != FPM_OK) {
    p = finger.getImage();
    switch (p) {
        case FPM_OK:
            Serial.println("Image taken");
            break;
        case FPM_NOFINGER:
            Serial.print(".");
            break;
        case FPM_PACKETRECIEVEERR:
            Serial.println("Communication error");
            break;
        case FPM_IMAGEFAIL:
            Serial.println("Imaging error");
            break;
        case FPM_TIMEOUT:
            Serial.println("Timeout!");
            break;
        case FPM_READ_ERROR:
            Serial.println("Got wrong PID or length!");
            break;
        default:
            Serial.println("Unknown error");
            break;
    }
    yield();
}

// OK success!

p = finger.image2Tz(2);
switch (p) {
    case FPM_OK:
        Serial.println("Image converted");
        break;
    case FPM_IMAGEMESS:
        Serial.println("Image too messy");
        return p;
    case FPM_PACKETRECIEVEERR:
        Serial.println("Communication error");
        return p;
    case FPM_FEATUREFAIL:
        Serial.println("Could not find fingerprint features");
        return p;
    case FPM_INVALIDIMAGE:
        Serial.println("Could not find fingerprint features");
        return p;
    case FPM_TIMEOUT:
        Serial.println("Timeout!");
        return false;
    case FPM_READ_ERROR:
        Serial.println("Got wrong PID or length!");
        return false;
    default:
        Serial.println("Unknown error");
        return p;
}


// OK converted!
p = finger.createModel();
if (p == FPM_OK) {
    Serial.println("Prints matched!");
} else if (p == FPM_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
} else if (p == FPM_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
} else if (p == FPM_TIMEOUT) {
    Serial.println("Timeout!");
    return p;
} else if (p == FPM_READ_ERROR) {
    Serial.println("Got wrong PID or length!");
    return p;
} else {
    Serial.println("Unknown error");
    return p;
}

Serial.print("ID "); Serial.println(fid);
p = finger.storeModel(fid);
if (p == FPM_OK) {
    Serial.println("Stored!");
    return 0;
} else if (p == FPM_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
} else if (p == FPM_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
} else if (p == FPM_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
} else if (p == FPM_TIMEOUT) {
    Serial.println("Timeout!");
    return p;
} else if (p == FPM_READ_ERROR) {
    Serial.println("Got wrong PID or length!");
    return p;
} else {
    Serial.println("Unknown error");
    return p;
}

}

void sweep()
{
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(2000); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(2000); } // waits 15ms for the servo to reach the position
}

Skip software serial and use one of the 4 hardware serial port available on the ESP32.

That conflict is documented for the AVR platform and doesn't show up in an error during compilation but by unstable servo reactions. This problem might also exist for the ESP32 platform but as the processor is much faster and you definitely don't need a software serial you can avoid the problem altogether.

If it's fine for the ESP32Servo library what problem do you actually have?