Digital Safe Box (RP2040+W5100S+FingerPrint) Part 1
Digital Safe Box (RP2040+W5100S+FingerPrint) Part1: Software
Software Apps and online services
This is a module I bought a long time ago. This model can store 50 fingerprints, but the latest model can store and recognize 300 sets of fingerprints.
Q:
I want to develop a mini safebox with Raspberry Pi RP2040, based on Arduino, with W5100S Ethernet chip, a keyboard with 12 touch buttons, which are 0~9 and *, #. an OLED screen to display the status, and Fingerprint recognition. How can I?
ChatGPT:
Developing a mini safebox with the components you mentioned is an interesting project! It involves hardware integration, programming, and some electronics knowledge. Here's a general roadmap to help you get started:
Gather Components:Make sure you have all the necessary components: Raspberry Pi RP2040, W5100S Ethernet chip, touch buttons, OLED screen, fingerprint sensor, wires, power supply, etc.
Gather Components:Make sure you have all the necessary components: Raspberry Pi RP2040, W5100S Ethernet chip, touch buttons, OLED screen, fingerprint sensor, wires, power supply, etc.
Setup Raspberry Pi RP2040:Get the RP2040 ready by setting up the necessary software. You'll need a microSD card with a suitable operating system (like Raspberry Pi OS Lite) flashed onto it. Follow the official documentation to set it up.
Setup Raspberry Pi RP2040:Get the RP2040 ready by setting up the necessary software. You'll need a microSD card with a suitable operating system (like Raspberry Pi OS Lite) flashed onto it. Follow the official documentation to set it up.
Connect the Components:Wire up all the components according to their datasheets and pin configurations. For instance:
Connect the W5100S Ethernet chip to the RP2040's SPI pins.
Connect the OLED screen using I2C pins.
Connect the touch buttons to the RP2040's GPIO pins.
Wire up the fingerprint sensor according to its datasheet.
Connect the Components:Wire up all the components according to their datasheets and pin configurations. For instance: Connect the W5100S Ethernet chip to the RP2040's SPI pins. Connect the OLED screen using I2C pins. Connect the touch buttons to the RP2040's GPIO pins. Wire up the fingerprint sensor according to its datasheet.
Install Required Libraries:Depending on the components you're using, you might need to install libraries to communicate with them. These libraries will provide functions that allow you to interact with the devices effectively. For example:
Install libraries for the Ethernet chip (W5100S) to enable network communication.
Install libraries for the OLED screen to display status information.
Install libraries for the fingerprint sensor to capture and recognize fingerprints.
Install Required Libraries:Depending on the components you're using, you might need to install libraries to communicate with them. These libraries will provide functions that allow you to interact with the devices effectively. For example: Install libraries for the Ethernet chip (W5100S) to enable network communication. Install libraries for the OLED screen to display status information. Install libraries for the fingerprint sensor to capture and recognize fingerprints.
Write the Code:This is where the bulk of your work lies. You'll need to write code to:
Initialize and manage the Ethernet connection to allow remote access.
Interface with the OLED screen to display relevant information.
Handle the touch buttons' inputs to detect button presses.
Communicate with the fingerprint sensor to enroll and verify fingerprints.
Write the Code:This is where the bulk of your work lies. You'll need to write code to: Initialize and manage the Ethernet connection to allow remote access. Interface with the OLED screen to display relevant information. Handle the touch buttons' inputs to detect button presses. Communicate with the fingerprint sensor to enroll and verify fingerprints.
Integration and Logic:This is where you bring everything together. Implement the logic for the safebox, such as:
Requiring a valid fingerprint before granting access.
Requiring a correct PIN code entered through the touch buttons.
Displaying different statuses on the OLED screen (locked, unlocked, error messages, etc.).
Controlling the locking and unlocking mechanism based on valid inputs.
Integration and Logic:This is where you bring everything together. Implement the logic for the safebox, such as: Requiring a valid fingerprint before granting access. Requiring a correct PIN code entered through the touch buttons. Displaying different statuses on the OLED screen (locked, unlocked, error messages, etc.). Controlling the locking and unlocking mechanism based on valid inputs.
Testing and Debugging:Test your setup thoroughly. Use debugging tools, print statements, and other methods to identify and fix any issues that arise during testing.
Testing and Debugging:Test your setup thoroughly. Use debugging tools, print statements, and other methods to identify and fix any issues that arise during testing.
Enclosure and Finalization:Design and build a suitable enclosure for your mini safebox. Make sure to include appropriate openings for the components (OLED screen, fingerprint sensor, touch buttons, etc.). The enclosure should protect the components and give your project a polished look.
Enclosure and Finalization:Design and build a suitable enclosure for your mini safebox. Make sure to include appropriate openings for the components (OLED screen, fingerprint sensor, touch buttons, etc.). The enclosure should protect the components and give your project a polished look.
Security Considerations:Since this is a safebox, security is crucial. Ensure that you implement proper encryption and authentication mechanisms for remote access, fingerprint storage, and PIN entry.
Security Considerations:Since this is a safebox, security is crucial. Ensure that you implement proper encryption and authentication mechanisms for remote access, fingerprint storage, and PIN entry.
User Manual:Write a user manual that explains how to use the safebox, enroll fingerprints, set PIN codes, and troubleshoot common issues.
User Manual:Write a user manual that explains how to use the safebox, enroll fingerprints, set PIN codes, and troubleshoot common issues.
Remember that this project involves multiple components and technologies, so take it step by step. It's also a great opportunity to learn about hardware integration, networking, and interfacing with various devices. Good luck with your mini safebox project!
Q:
I am using arduino, Fingerprint module is connected to the soft serial port, the TX pin used is GPIO26, and the RX pin is GPIO27. The servo uses GPIO21 , Then please give me a reference code.
ChatGPT:
Sure, here's a reference code outline to get you started with your Arduino-based mini safebox project using the components you mentioned. Please note that this is a simplified example, and you might need to modify and expand it according to your specific hardware, libraries, and requirements.
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
// Pin definitions
#define FINGERPRINT_RX_PIN 26
#define FINGERPRINT_TX_PIN 27
#define OLED_RESET -1
#define OLED_SDA 4
#define OLED_SCL 5
#define SERVO_PIN 21
// Initialize components
SoftwareSerial fingerprintSerial(FINGERPRINT_RX_PIN, FINGERPRINT_TX_PIN);
Adafruit_SSD1306 display(OLED_RESET);
Servo servo;
void setup() {
// Initialize components
Serial.begin(9600);
fingerprintSerial.begin(57600);
display.begin(SSD1306_I2C_ADDRESS, OLED_SDA, OLED_SCL);
servo.attach(SERVO_PIN);
// Display initialization message
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Mini Safebox");
display.display();
delay(2000);
// Initialize servo position
servo.write(0); // Locked position
}
void loop() {
// Your main logic here
// Check for fingerprint input
if (fingerprintSerial.available()) {
// Read fingerprint data and process
// Add your fingerprint recognition logic here
// Example: if (recognizedFingerprint) { unlockSafebox(); }
}
// Check for touch button input
// Add your touch button logic here
// Display status on OLED
// Add OLED display logic here
}
void unlockSafebox() {
servo.write(90); // Unlock the safebox
delay(2000); // Keep it unlocked for 2 seconds
servo.write(0); // Lock the safebox again
}
Please note that this code is a starting point and might require modifications based on the specific libraries you are using, the behavior you want to achieve, and the fingerprint recognition library you are using (since fingerprint modules can vary in their APIs).
Also, remember that security is a critical aspect when dealing with safeboxes. Make sure to implement secure fingerprint storage and authentication mechanisms. Use proper encryption techniques when dealing with sensitive data.
As you work through the project, refer to the documentation of the libraries you're using and the datasheets of your components for more detailed information on their usage.
Q:
My test is based on the W5100S_EVB_PICO board, please add the Ethernet part, and I want to send the recognized fingerprint ID number to the IOT platform BLYNK after the fingerprint is recognized, please help me.
ChatGPT:
Sure, here's a complete integrated code example that combines fingerprint recognition, OLED display, Ethernet communication, and Blynk integration:
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
#include <SPI.h>
#include <Ethernet2.h>
#include <BlynkSimpleEthernet2.h>
// Pin definitions
#define FINGERPRINT_RX_PIN 23
#define FINGERPRINT_TX_PIN 24
#define OLED_RESET -1
#define OLED_SDA 4
#define OLED_SCL 5
#define SERVO_PIN 6
// Initialize components
SoftwareSerial fingerprintSerial(FINGERPRINT_RX_PIN, FINGERPRINT_TX_PIN);
Adafruit_SSD1306 display(OLED_RESET);
Servo servo;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address of your Ethernet shield
IPAddress ip(192, 168, 1, 100); // IP address of your Arduino
IPAddress server(192, 168, 1, 2); // IP address of your Blynk server
char auth[] = "YOUR_BLYNK_AUTH_TOKEN";
void setup() {
// Initialize components
Serial.begin(9600);
fingerprintSerial.begin(57600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
servo.attach(SERVO_PIN);
setupEthernet();
setupBlynk();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Mini Safebox");
display.display();
delay(2000);
servo.write(0); // Locked position
}
void loop() {
Blynk.run(); // Blynk communication
// Your main logic here
// Check for fingerprint input
if (fingerprintSerial.available()) {
int recognizedFingerprintID = readFingerprint(); // Replace with your fingerprint recognition logic
if (recognizedFingerprintID != -1) {
sendFingerprintToBlynk(recognizedFingerprintID);
}
}
// Other logic and communication here
// Display status on OLED
// Add OLED display logic here
}
void setupEthernet() {
Ethernet.begin(mac, ip);
}
void setupBlynk() {
Blynk.begin(auth, IPAddress(192, 168, 1, 2), 8080);
}
void sendFingerprintToBlynk(int fingerprintID) {
Blynk.virtualWrite(V1, fingerprintID); // Assuming you're using Virtual Pin V1
}
int readFingerprint() {
// Replace with your fingerprint recognition logic
// Return recognized fingerprint ID or -1 if not recognized
}
Remember to replace 'YOUR_BLYNK_AUTH_TOKEN' with your actual Blynk authentication token. Adjust the IP addresses, settings, and Virtual Pin according to your network configuration and Blynk project.
This code combines the various components and functionalities you described: fingerprint recognition, OLED display, Ethernet communication with the W5100S, and Blynk integration. It's important to note that this code is a template and you will need to implement your actual fingerprint recognition logic using the fingerprint module's library or commands.
Also, ensure you've installed the required libraries (SoftwareSerial, Adafruit_SSD1306, Servo, Ethernet2, BlynkSimpleEthernet2, etc.) through the Arduino Library Manager.
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "*******"
#define BLYNK_TEMPLATE_NAME "********"
#define BLYNK_AUTH_TOKEN "**************************"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Fingerprint.h>
#include <Servo.h>
BlynkTimer timer;
#define FINGERPRINT_RX_PIN 27
#define FINGERPRINT_TX_PIN 26
SoftwareSerial fingerprintSerial(FINGERPRINT_RX_PIN, FINGERPRINT_TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&fingerprintSerial);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Initialize components
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define SERVO_PIN 22
Servo servo;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 0, 1, 226);
void setup() {
servo.attach(SERVO_PIN);
// Initialize servo position
servo.write(360); // Locked position
// Initialize components
Serial.begin(9600);
fingerprintSerial.begin(57600);
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
// Display initialization message
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(24, 0);
display.println("Safebox");
display.setCursor(48, 16);
display.println("Lock");
display.display();
delay(2000);
Ethernet.init(17); // WIZnet W5100S-EVB-Pico
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
Blynk.begin(BLYNK_AUTH_TOKEN);
finger.getTemplateCount();
if (finger.templateCount == 0) {
Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
}
else {
Serial.println("Waiting for valid finger...");
Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
}
}
void loop() {
Blynk.run();
timer.run();
getFingerprintID();
delay(50); //don't ned to run this at full speed.
// Your main logic here
// Check for fingerprint input
if (fingerprintSerial.available()) {
// Read fingerprint data and process
// Add your fingerprint recognition logic here
// Example: if (recognizedFingerprint) { unlockSafebox(); }
}
// Check for touch button input
// Add your touch button logic here
// Display status on OLED
// Add OLED display logic here
}
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.fingerSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
unlockSafebox();
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
// Display initialization message
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(24, 0);
display.println("Safebox");
display.setCursor(32, 16);
display.println("ALARM");
// Send it to the server
Blynk.virtualWrite(V5, "ALARM!");
display.display();
for(int i=200;i<=800;i++) //用循环的方式将频率从200HZ 增加到800HZ
{
pinMode(6,OUTPUT);
tone(6,i); //在四号端口输出频率
delay(5); //该频率维持5毫秒
}
delay(4000);
noTone(6);
// Display initialization message
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(24, 0);
display.println("Safebox");
display.setCursor(48, 16);
display.println("lOCK");
display.display();
Blynk.virtualWrite(V5, "Lock!");
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;
}
void unlockSafebox() {
servo.write(180); // Unlock the safebox
// Display initialization message
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(24, 0);
display.println("Safebox");
display.setCursor(32, 16);
display.println("Unlock");
display.display();
// Send it to the server
Blynk.virtualWrite(V5, String("Found a Finger ID:" + String(finger.fingerID)));
delay(2000); // Keep it unlocked for 2 seconds
servo.write(360); // Lock the safebox again
// Display initialization message
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(24, 0);
display.println("Safebox");
display.setCursor(48, 16);
display.println("Lock");
display.display();
delay(2000);
// Send it to the server
Blynk.virtualWrite(V5, "Lock!");
}
Rcv Found message: