Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Ensar Karabudak
Published © GPL3+

Raspberry Pi Pico W Cellular Security with Telegram Alert

Check the entered password on the keypad, and send a message to a Telegram channel using cellular connection on the Pico LTE.

IntermediateFull instructions provided2 hours957
Raspberry Pi Pico W Cellular Security with Telegram Alert

Things used in this project

Hardware components

Sixfab Pico LTE
Sixfab Pico LTE
×1
SparkFun Qwiic Keypad - 12 Button
SparkFun Qwiic Keypad - 12 Button
×1
SparkFun Qwiic OLED Display (0.91 in, 128x32)
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Code

Sending password check message to Telegram

MicroPython
from machine import I2C, Pin
from ssd1306 import SSD1306_I2C
from qwiic_keypad import QwiicKeypad
from time import sleep
from pico_lte.core import PicoLTE
from pico_lte.common import debug

# Establish the I2C connection
i2c = I2C(0, scl=Pin(13), sda=Pin(12))

# Configure the OLED display
oled = SSD1306_I2C(128, 32, i2c)

# Configure Qwiic Keypad
keypad = QwiicKeypad(i2c)

# Configure PicoLTE SDK
picoLTE = PicoLTE()

def send_text(text):
    oled.fill(0)
    
    x = (oled.width - len(text) * 8) // 2  # Calculate x coordinate to center text
    y = (oled.height - 8) // 2  # Set Y coordinate to center
    
    oled.text(text, x, y)
    oled.show()

def main():
    if not keypad.is_connected():
        raise Exception("The Qwiic Keypad device isn't connected to the system. Please check your connection.")

    print("Enter the password:")
    password = "2323"  # Set the password you set here
    entered_password = ""
    
    while True:
        # Clear the OLED display
        oled.fill(0)
        
        keypad.update_fifo()
        button = keypad.get_button()

        if button == -1:
            print("No keypad detected")
            sleep(1)

        elif button != 0:
            charButton = chr(int.from_bytes(button, "little"))
            if charButton == '#':
                entered_password = "" # Press # to reset the entered password
            elif charButton == '*':
                entered_password = entered_password[:-1]  # Press * to delete last character
            elif int.from_bytes(button, "little") != 0:
                entered_password += charButton
                

        oled.text("Enter Password:", 0, 0)
        oled.text(entered_password, 0, 10)
        oled.show()
        
        if len(entered_password) == len(password):
            if entered_password == password:
                send_text("-- SUCCESSFUL --")
                sleep(3)
                send_text("-Sending Message-")
                sleep(2)
                result = picoLTE.telegram.send_message("Password successful! Door unlocked.")
                if result["status"] == 0:
                    send_text("- Done! -")
                    sleep(4)
                else:
                    send_text("- Fail! -")
                    sleep(4)
                
            else:
                send_text("-- Try Again --")
                sleep(3)
                send_text("-Sending Message-")
                sleep(2)
                result = picoLTE.telegram.send_message("Invalid password. Access denied!")
                if result["status"] == 0:
                    send_text("- Done! -")
                    sleep(4)
                else:
                    send_text("- Fail! -")
                    sleep(4)
                entered_password = ""
            
            
            # Continue without clearing whether the password is entered correctly or incorrectly
            entered_password = ""

        sleep(.25)
        
        
if __name__ == "__main__":
    main()

Credits

Ensar Karabudak
8 projects • 9 followers
Contact

Comments

Please log in or sign up to comment.