Adafruit fingerprint library example not wring with NodeMCU

Hello, everyone
I am trying to interface FPS R307 with Node MCU to get the fingerprint templates stored inside the fingerprint module.
The program gets compiled but when it is flashed on NODEmcu it shows gibberish data due to WDT reset
the output i get on serial is as follows -

"ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld"

The code I am uploading is -

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
SoftwareSerial mySerial(13, 15, false, 256);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
while(!Serial);
Serial.begin(57600);
Serial.println(“Fingerprint template extractor”);

// set the data rate for the sensor serial port
finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println(“Found fingerprint sensor!”);
} else {
Serial.println(“Did not find fingerprint sensor :(”);
while (1);
}

// Try to get the templates for fingers 1 through 10
for (int finger = 1; finger < 10; finger++) {
downloadFingerprintTemplate(finger);
}
}

uint8_t downloadFingerprintTemplate(uint16_t id)
{
Serial.println("------------------------------------");
Serial.print(“Attempting to load #”); Serial.println(id);
uint8_t p = finger.loadModel(id);
switch (p) {
case FINGERPRINT_OK:
Serial.print(“Template “); Serial.print(id); Serial.println(” loaded”);
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println(“Communication error”);
return p;
default:
Serial.print("Unknown error "); Serial.println(p);
return p;
}

// OK success!

Serial.print(“Attempting to get #”); Serial.println(id);
p = finger.getModel();
switch (p) {
case FINGERPRINT_OK:
Serial.print(“Template “); Serial.print(id); Serial.println(” transferring:”);
break;
default:
Serial.print("Unknown error "); Serial.println(p);
return p;
}

// one data packet is 267 bytes. in one data packet, 11 bytes are ‘usesless’ :smiley:
uint8_t bytesReceived[534]; // 2 data packets
memset(bytesReceived, 0xff, 534);

uint32_t starttime = millis();
int i = 0;
while (i < 534 && (millis() - starttime) < 20000) {
if (mySerial.available()) {
bytesReceived[i++] = mySerial.read();
}
}
Serial.print(i); Serial.println(" bytes read.");
Serial.println(“Decoding packet…”);

uint8_t fingerTemplate[512]; // the real template
memset(fingerTemplate, 0xff, 512);

// filtering only the data packets
int uindx = 9, index = 0;
while (index < 534) {
while (index < uindx) ++index;
uindx += 256;
while (index < uindx) {
fingerTemplate[index++] = bytesReceived[index];
}
uindx += 2;
while (index < uindx) ++index;
uindx = index + 9;
}
for (int i = 0; i < 512; ++i) {
//Serial.print(“0x”);
printHex(fingerTemplate*, 2);*

  • //Serial.print(", ");*

  • }*

  • Serial.println("\ndone.");*
    }
    void printHex(int num, int precision) {

  • char tmp[16];*

  • char format[128];*

  • sprintf(format, “%%.%dX”, precision);*

  • sprintf(tmp, format, num);*

  • Serial.print(tmp);*
    }
    void loop()
    {}
    Please help me, i tried with different baud rates and pin configurations, tried with different delays but actually unable to guess even , where the problem is getting place.
    Thankyou
    New programmer
    (sorry for awful english)

Your watchdog reset us probably due to the infinite loops - get rid of them.

Please remember to use code tags when posting code

thankyou …
it solved my problem …

n yeah code tags i ll take of that from now onwards

I'm facing the same problem with the same code. Can you help me out with where the infinite loop occurs in the code and what should i change?

Use delays where ever you feel your code is facing a lock down or a blockade. For example in the code you’ve posted, I’ve introduced a yield() in the for loop for the same reason and now it works just fine.

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
SoftwareSerial mySerial(13, 15, false, 256);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
while(!Serial);
Serial.begin(57600);
Serial.println(“Fingerprint template extractor”);

// set the data rate for the sensor serial port
finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println(“Found fingerprint sensor!”);
} else {
Serial.println(“Did not find fingerprint sensor :(”);
while (1);
}

// Try to get the templates for fingers 1 through 10
for (int finger = 1; finger < 10; finger++) {
downloadFingerprintTemplate(finger);
}
}

uint8_t downloadFingerprintTemplate(uint16_t id)
{
Serial.println("------------------------------------");
Serial.print(“Attempting to load #”); Serial.println(id);
uint8_t p = finger.loadModel(id);
switch (p) {
case FINGERPRINT_OK:
Serial.print(“Template “); Serial.print(id); Serial.println(” loaded”);
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println(“Communication error”);
return p;
default:
Serial.print("Unknown error "); Serial.println(p);
return p;
}

// OK success!

Serial.print(“Attempting to get #”); Serial.println(id);
p = finger.getModel();
switch (p) {
case FINGERPRINT_OK:
Serial.print(“Template “); Serial.print(id); Serial.println(” transferring:”);
break;
default:
Serial.print("Unknown error "); Serial.println(p);
return p;
}

// one data packet is 267 bytes. in one data packet, 11 bytes are ‘usesless’ :smiley:
uint8_t bytesReceived[534]; // 2 data packets
memset(bytesReceived, 0xff, 534);

uint32_t starttime = millis();
int i = 0;
while (i < 534 && (millis() - starttime) < 20000) {
if (mySerial.available()) {
bytesReceived[i++] = mySerial.read();
}
}
Serial.print(i); Serial.println(" bytes read.");
Serial.println(“Decoding packet…”);

uint8_t fingerTemplate[512]; // the real template
memset(fingerTemplate, 0xff, 512);

// filtering only the data packets
int uindx = 9, index = 0;
while (index < 534) {
while (index < uindx) ++index;
uindx += 256;
while (index < uindx) {
fingerTemplate[index++] = bytesReceived[index];
}
uindx += 2;
while (index < uindx) ++index;
uindx = index + 9;
}
for (int i = 0; i < 512; ++i) {
//Serial.print(“0x”);
printHex(fingerTemplate, 2);

yield();

//Serial.print(", “);
}
Serial.println(”\ndone.");
}

void printHex(int num, int precision) {
char tmp[16];
char format[128];

sprintf(format, “%%.%dX”, precision);

sprintf(tmp, format, num);
Serial.print(tmp);
}

void loop()
{}