Verschiedenes > ESP8266

ESP-12f und Fingerprint

(1/5) > >>

MBHG:
Guten Morgen,

ich bastle schon seit längerer Zeit an einem ESP-12f und einem Fingerprint (r503 operiert auf 3.3v) und bin fast am verzweifeln.

Der Fingerprint ist mit dem ESP wie folgt verbunden:

tx - mosi PIN 13  - rc503 gelb - tx
rx - miso PIN 12  - rc503 grün - rx

rx - mosi PIN 13  - rc503 gelb - tx
tx - miso PIN 12  - rc503 grün - rx

Ich nutze das SoftwareSerial und bekomme einfach keine Verbindung. Die Rückmeldung über MQTT ist, dass kein Fingerprint verbunden ist. Prinzipiell funktioniert der Fingerprint. Hat  jemand einen Tipp für mich?


--- Code: ---/***************************************************
  This is an example sketch for our optical Fingerprint sensor

  Designed specifically to work with the Adafruit BMP085 Breakout
  ----> http://www.adafruit.com/products/751

  These displays use TTL Serial to communicate, 2 pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Adafruit_Fingerprint.h>
#include <SPI.h>
#include <Wire.h>
#include <WiFiClient.h>
#include <PubSubClient.h> // Aus Wifi Mqtt
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoOTA.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(13, 12);
//tx - mosi PIN 13  - rc503 gelb - tx
//rx - miso PIN 12  - rc503 grün - rx


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

//************************************************************************
/* Set these to your desired credentials. */
const char *ssid = "myssid";  //ENTER YOUR WIFI SETTINGS
const char *password = "mypwd";
const char* mqttServer = "myip"; // Broker PI
const int mqttPort = 1883; // Broker PI Port
const char* mqttUser = "FP"; // Broker PI Name
const char* mqttPassword = "mymqpwd"; // Broker PI Password

WiFiClient espClient;
PubSubClient client(espClient);
char* mqttio = "12345"; // Broker PI Wert
char* confidence = "67890"; // Broker PI Wert

uint8_t id;


//************************************************************************


void setup() 
{
  // Serial.begin(115200);
  // Serial.println("\n\nConnect to Wifi");
  connectToWiFi();

    // mqtt
  client.setServer(mqttServer, mqttPort);
  client.setCallback(callback);
 
  while (!client.connected()) {
  // Serial.println("Connecting to MQTT...");
 
  if (client.connect("ESP8266Client", mqttUser, mqttPassword )) {
 
    // Serial.println("connected"); 
 
  } else {
 
    // Serial.print("failed with state ");
    // Serial.print(client.state());
    // Serial.print("looking for update ");

  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH) {
      type = "sketch";
    } else { // U_FS
      type = "filesystem";
    }

    // NOTE: if updating FS this would be the place to unmount FS using FS.end()
    Serial.println("Start updating " + type);
  });
    ArduinoOTA.begin();
    while(1) {
      ArduinoOTA.handle();
      delay(50);
    }
 
  }
  }

 
 
  // Serial.println("\n\nAdafruit finger detect test");
  // set the data rate for the sensor serial port

  delay(1000);

  mySerial.begin(57600, SWSERIAL_8N1, 13, 12, false, 256, 256);
 
  finger.begin(57600);
 
  if (finger.verifyPassword()) {
    // Serial.println("Found fingerprint sensor!");
    // send command to turn on R503 led
    finger.led_control(1,100,2,1); // code(1-6),speed(1-255),color(1-R/2-B/3_P),time(1-255)

  } else {
    // Serial.println("Did not find fingerprint sensor :(");

   client.subscribe("Error");
   client.publish("Error", "No FP");

   
    delay(60000);
   
    // Serial.print("failed with state ");
    // Serial.print(client.state());
    // Serial.print("looking for update ");

  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH) {
      type = "sketch";
    } else { // U_FS
      type = "filesystem";
    }

    // NOTE: if updating FS this would be the place to unmount FS using FS.end()
    Serial.println("Start updating " + type);
  });
    ArduinoOTA.begin();
    while(1) {
      ArduinoOTA.handle();
      delay(50);
    }
   
  }

  finger.getTemplateCount();
  // Serial.print("Sensor contains "); // Serial.print(finger.templateCount); // Serial.println(" templates");
  // Serial.println("Waiting for valid finger...");

 
  client.subscribe("Fingerprint");
  client.publish("Fingerprint", "FP1");
 
}


void callback(char* topic, byte* payload, unsigned int length) {

// Serial.print("Message arrived in topic: ");
// Serial.println(topic);

// Serial.print("Message:");
for (int i = 0; i < length; i++) {
// Serial.print((char)payload[i]);
}

// Serial.println();
// Serial.println("-----------------------");

}


void loop()                     // run over and over again
{
  //check if there's a connection to WiFi or not
  if(WiFi.status() != WL_CONNECTED){
    connectToWiFi();
  }

  if (!client.connected()) {
    client.connect("ESP8266Client", mqttUser, mqttPassword );
  }
   
  if (getFingerprintIDez() == 9)  {
    delay(2000);
    getFingerprintEnroll();
  }
  delay(50);            //don't ned to run this at full speed.
}


// returns -1 if failed, otherwise returns ID #
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) {
    // send command to turn on R503 led
    finger.led_control(1,100,1,3); // code(1-6),speed(1-255),color(1-R/2-B/3_P),time(1-255)

    return -1;
  }
 
  // found a match!
  // Serial.print("Found ID #"); // Serial.print(finger.fingerID);
  // Serial.print(" with confidence of "); // Serial.println(finger.confidence);
  // send command to turn on R503 led
  finger.led_control(1,100,2,3); // code(1-6),speed(1-255),color(1-R/2-B/3_P),time(1-255)

  // mqtt
 
  sprintf(mqttio,"%d",finger.fingerID);
  sprintf(confidence,"%d",finger.confidence);
   
  client.subscribe("Confidence");
  client.publish("Confidence", confidence);
   
  client.subscribe("FingerprintNr");
  client.publish("FingerprintNr", mqttio);

  return finger.fingerID;
}

void connectToWiFi(){
    WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
    delay(1000);
    WiFi.mode(WIFI_STA);
    // Serial.print("Connecting to ");
    // Serial.println(ssid);
    WiFi.begin(ssid, password);
 
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      // Serial.print(".");
    }
    // Serial.println("");
    // Serial.println("Connected");
   
   
    // Serial.print("IP address: ");
    // Serial.println(WiFi.localIP());  //IP address assigned to your ESP
}







uint8_t getFingerprintEnroll() {

  // send command to turn on R503 led
  finger.led_control(1,100,3,3); // code(1-6),speed(1-255),color(1-R/2-B/3_P),time(1-255)

  id = min(finger.templateCount + 1, 127);
  int p = -1;
  // Serial.print("Waiting for valid finger to enroll as #"); // Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      // Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      // Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      // Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      // Serial.println("Imaging error");
      break;
    default:
      // Serial.println("Unknown error");
      break;
    }
  }


 
  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      // Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      // Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      // Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      // Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      // Serial.println("Could not find fingerprint features");
      return p;
    default:
      // Serial.println("Unknown error");
      return p;
  }

  // send command to turn on R503 led
  finger.led_control(1,100,3,3); // code(1-6),speed(1-255),color(1-R/2-B/3_P),time(1-255)

 
  // Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  // Serial.print("ID "); // Serial.println(id);
  p = -1;
  // Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      // Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      // Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      // Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      // Serial.println("Imaging error");
      break;
    default:
      // Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  // send command to turn on R503 led
  finger.led_control(1,100,3,3); // code(1-6),speed(1-255),color(1-R/2-B/3_P),time(1-255)

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      // Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      // Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      // Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      // Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      // Serial.println("Could not find fingerprint features");
      return p;
    default:
      // Serial.println("Unknown error");
      return p;
  }
 
  // OK converted!
  // Serial.print("Creating model for #");  // Serial.println(id);
 
  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    // Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    // Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    // Serial.println("Fingerprints did not match");
    return p;
  } else {
    // Serial.println("Unknown error");
    return p;
  }   
 
  // Serial.print("ID "); // Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    // Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    // Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    // Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    // Serial.println("Error writing to flash");
    return p;
  } else {
    // Serial.println("Unknown error");
    return p;
  }   
}
--- Ende Code ---






frank:
normaler weise werden doch rx/tx gekreuzt.
also, was der eine bei tx labert, soll der andere bei rx hören.

MBHG:
Hi Frank,

im Code ist es richtig, in meinem Kommentar falsch. Sorry, ich korrigiere es.

Gruss Marc

Papa Romeo:
Hallo MBHG,

ich denke du nutzt den Hardware SPI, da ich jetzt in deinem Programm auf Anhieb für SPI keine andere Zuweisung sehen kann ...

...leg mal Gelb vom Fingerprint auf GPIO14 und ändere SoftwareSerial auf mySerial(14, 12) ab und nutze Software SPI.

hier auch nochmal ein Beispielprogramm https://smarthome.family.blog/2020/09/18/fingerprint-r503-esp-mqtt-fhem/

LG
Papa Romeo

MBHG:
Hi Papa Romeo,

ich nutze das Softserial. Das HardwareSerial habe ich auch schon angetestet, aber hatte kein Erfolg.


--- Zitat von: Papa Romeo am 23 April 2021, 09:44:09 ---hier auch nochmal ein Beispielprogramm https://smarthome.family.blog/2020/09/18/fingerprint-r503-esp-mqtt-fhem/

--- Ende Zitat ---

Lustig, ist Deine Referenz auf meinen Blog - es gibt also Leute die es lesen ;D. In der Tat hatte ich es letztes Jahr einmal zum Laufen bekommen, aber es mit dem Setup in dem Link tut  es nicht mehr. Dann bin ich auf die Pins 12 und 13 umgestiegen oder auch das Hardwareserial. Aber das tut leider auch nicht.

Lieben Gruss Marc

Navigation

[0] Themen-Index

[#] Nächste Seite

Zur normalen Ansicht wechseln