esp8266与指纹传感器R305无法通信。

问题描述 投票:0回答:2

你好,我的问题是,当我把指纹传感器与我的esp8266连接时,它不能工作!我使用adafruit指纹传感器R305和esp模块esp8266 cp2102.我已经把vcc引脚连接到3.3v引脚,地引脚连接到groung,然后我把rx连接到rx引脚,tx连接到tx引脚。 我使用adafruit传感器库,但当我连接指纹时,它不做任何事情,我打算用这2个组件创建一个简单的指纹考勤系统,我用IFTTT应用程序创建了一个数据库,这是代码。

#include <BearSSLHelpers.h>
#include <CertStoreBearSSL.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiClientSecureAxTLS.h>
#include <WiFiClientSecureBearSSL.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiServerSecureAxTLS.h>
#include <WiFiServerSecureBearSSL.h>
#include <WiFiUdp.h>



#include <SoftwareSerial.h>

#include <Adafruit_Fingerprint.h>

#define rxPin 2
#define txPin 3

const char* NAME; // the name will be gievn in the code for each ID saved
const char* ID; // the ID that are save into the fingerprint sensor


String Event_Name = "FINGERPRINT "; // this is the name of the file of the database

String Key = "beStaVRpfye6wtonedU"; // this is my unique key for the database created

// Replace with your unique IFTTT URL resource
String resource = "/trigger/" + Event_Name + "/with/key/" + Key;

// Maker Webhooks IFTTT
const char* server = "maker.ifttt.com"; // here database is store

// Replace with your SSID and Password
char* ssid     = "Telecom-2"; //wifi name
char* pass = "X5NVY53V236k"; // wifi password
SoftwareSerial mySerial (rxPin, txPin);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); // communcation with the IoT and fingerprint sensor

void setup()
{
  Serial.begin(57600);
  mySerial.begin(57600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) {
      delay(1);
    }
  }
// the fingerpprint sensor will first starts
  finger.getTemplateCount();
  Serial.print("Sensor contains ");
  Serial.print(finger.templateCount);
  Serial.println(" templates");
  Serial.println("Waiting for valid finger...");

// meanwhile the esp8266 wifi module will start and conect to the wifi data given
  Serial.print("Connecting to: "); // connecting to a wifi avaible
  Serial.print(ssid);             // connecting to the given wifi name  
  WiFi.begin(ssid, pass);    // connection in progress 

  int timeout = 10 * 4; // 10 seconds
  while (WiFi.status() != WL_CONNECTED  && (timeout-- > 0)) {
    delay(250);
    Serial.print("Attempting to connect to SSID");
  }
  Serial.println("Connected");

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Failed to connect");
  }

  Serial.print("WiFi connected in: ");
  Serial.print(millis());
  Serial.print(", IP address: ");
  Serial.println(WiFi.localIP());
}

void loop()                     // run over and over again
{ // now the finger print sensor will wait for a register ID
  getFingerprintIDez();
  if (finger.fingerID == 1) //mean if the ID correspond to ID 1
  {

    Serial.print("!!--");
    Serial.println(finger.fingerID);
    NAME = "Sailen"; //therefore the name of sailen will appear as ID 1
    ID = "1";
    if (finger.confidence >= 60) // fingerprint test must over 60% of confidence
    {
      Serial.print("Attendace Marked for ");
      Serial.println(NAME);
      makeIFTTTRequest();
      // digital write - open the attendance
    }

  }

  if (finger.fingerID == 2 ) {
    Serial.print("!!--");
    Serial.println(finger.fingerID);
    digitalWrite(5, LOW);
    NAME = "Bob"; // therefore the name of bob will appear for ID 2
    ID = "2";
    if (finger.confidence >= 60) // fingerprint test must over 60% of confidence
    {
      Serial.print("Attendace Marked for ");
      Serial.println(NAME);
      makeIFTTTRequest();
      // digital write - open the door
    }      //don't ned to run this at full speed.

  }

}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  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!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);

  return finger.fingerID;
}

// 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)  return -1;

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID;
}

// Make an HTTP request to the IFTTT web service
void makeIFTTTRequest() {
  Serial.print("Connecting to "); // means connecting to my google database
  Serial.print(server);

  WiFiClient client;
  int retries = 5;
  while (!!!client.connect(server, 80) && (retries-- > 0)) {
    Serial.print(".");
  }
  Serial.println();
  if (!!!client.connected()) {
    Serial.println("Failed to connect...");
  }

  Serial.print("Request resource: ");
  Serial.println(resource);

// now that the IoT has access to the data base
// value 1 will be use for name and value 2 for which ID it is

  String jsonObject = String("{\"value1\":\"") + NAME + "\",\"value2\":\"" + ID
                      + "\"}"; // name and id is registered in the database

  client.println(String("POST ") + resource + " HTTP/1.1");
  client.println(String("Host: ") + server);
  client.println("Connection: close\r\nContent-Type: application/json");
  client.print("Content-Length: ");
  client.println(jsonObject.length());
  client.println();
  client.println(jsonObject);

  int timeout = 5 * 10; // 5 seconds
  while (!!!client.available() && (timeout-- > 0)) {
    delay(100);
  }
  if (!!!client.available()) {
    Serial.println("No response...");
  }
  while (client.available()) {
    Serial.write(client.read());
  }

  Serial.println("\nclosing connection");
  client.stop();
}`

我在youtube上看了一个类似这样的视频,但我的视频有点不一样https:/techiesms.comiot-projectsiot-attendance-system-without-website。

esp8266 fingerprint tx
2个回答
0
投票

如传感器的数据手册上所说。

电源电压: 3.6 - 6.0VDC 工作电流: 120mA max 峰值电流: 150mA max

所以你必须使用合适的电源或带升压转换器的accu pack,我建议最小4.5V,最小0.5A,以保证性能可靠。


0
投票

先生,我把指纹连接到5V的电源上,TX引脚连接到ESP的TX引脚,RXPIN也连接到ESP的RX引脚,但是没有工作。

© www.soinside.com 2019 - 2024. All rights reserved.