完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我知道 softserial 不稳定。无论如何,我尝试连接我的 esp12f 已经好几个小时了,以连接到指纹。我通过 pro mini 注册了指纹,设置了密码,一切正常。
但是连接到 esp-12f 不起作用。它只是进入 OTA 更新。这是我的草图: 代码:全选/*************************************************** 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 #include #include #include #include // Aus Wifi Mqtt #include #include #include #include #include SoftwareSerial mySerial(12, 13); //tx - mosi PIN 13 - rc503 grün - rx //rx - miso PIN 12 - rc503 gelb - tx Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial, "myPasswordInDigits"); //************************************************************************ /* Set these to your desired credentials. */ const char *ssid = "ssid"; //ENTER YOUR WIFI SETTINGS const char *password = "mypassword"; const char* mqttServer = "mymqtt"; // Broker PI const int mqttPort = 1883; // Broker PI Port const char* mqttUser = "FP"; // Broker PI Name const char* mqttPassword = "pwd"; // 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, 12, 13, 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); } // 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; } } |
|
相关推荐
1个回答
|
|
很难确定您的问题的确切原因,因为缺少详细信息。但是,以下是一些可能导致您的ESP-12f无法与指纹模块通信的原因:
1.软串口设置不正确:由于软串口不像硬件串口那样稳定,因此您需要确保正确设置了波特率、数据位和停止位。如果这些设置错误,则通信将不起作用。 2.引脚连接错误:请确保正确连接了指纹模块的TX和RX引脚。如果这些引脚连接错误,则通信将不起作用。 3.电源不足:如果您的ESP-12f没有足够的电源来供应指纹模块,则通信将不起作用。请确保为模块提供了足够的电源。 4.库不兼容:有时,不同的库可能不兼容,这可能导致通信错误。请确保您使用的库与您的硬件兼容。 5.固件问题:如果您的ESP-12f处于OTA更新模式,则它可能无法与指纹模块通信。请确保您的固件没有问题。 希望这些提示能够帮助您找到问题并解决它。 |
|
|
|
只有小组成员才能发言,加入小组>>
1034 浏览 1 评论
562浏览 6评论
470浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
454浏览 5评论
455浏览 4评论
428浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-4 16:57 , Processed in 0.732194 second(s), Total 46, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号