Hello Everyone, in this project we'll try to set up an alarm on the newly launch EncroPi RP2040-based USB smart dongle.
EncroPi IntroductionEncroPi is a multipurpose USB stick that is incredibly small, portable, and allows you to perform customized security to secure your data using symmetric and asymmetric encryption types. EncroPi is also built with a real-time clock that can be used to keep accurate timekeeping even if the device's main power source is disrupted.
EncroPi has a built-in Raspberry Pi RP2040 microcontroller that supports up to 16MB of off-chip Flash memory over a dedicated QSPI interface and has two quick cores, lots of on-chip RAM, and a port of TensorFlow Lite.
EncroPi Reviews- Introducing EncroPi - Explore Data Logging with Security Encryption & Real-time Clock
- EncroPi, a smart RP2040 Based Device with a variety of additional functions, has been introduced
- EncroPi - Create USB Encryption & Customize Encryption Algorithm with Real-time Data using @CircuitPython
Steps:
- Install Thonny on your system here we're using Raspberry Pi 400 Computer you can use any Single-board computer, Mac, or Windows PC
- Connecting EncroPi on Raspberry Pi 400 via USB as you can see in the image above.
- Installing Thonny you can download it from here
- Run the codes below on Thonny using micropython:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from machine import I2C
import time
import utime
from machine import Pin, UART,SPI
import time
import st7789
import vga1_8x16 as font1
import vga1_16x32 as font
import vga1_16x16 as font2
address = 0x68
register = 0x00
#sec min hour week day month year
CurrentTime = b'\x00\x58\x14\x05\x21\x06\x22' #00:00:10 friday 03/03/2022
week = ["Sun","Mon","Tues","Wed","Thur","Fri","Sat"];
bus = I2C(1) # i2c 1
spi = SPI(1, baudrate=40000000, sck=Pin(10), mosi=Pin(11))
tft = st7789.ST7789(spi,135,240,reset=Pin(12, Pin.OUT),cs=Pin(9, Pin.OUT),dc=Pin(8, Pin.OUT),backlight=Pin(13, Pin.OUT),rotation=1)
def PicoRTCSetTime():
bus.writeto_mem(int(address),int(register),CurrentTime)
def PicoRTCReadTime():
return bus.readfrom_mem(int(address),int(register),7);
def alarm(c,b,a):
h = int("%02x"%(c))
m = int("%02x"%(b))
s = int("%02x"%(a))
if h == 15 and m == 00 and s == 00:
tft.fill(0)
for i in range(5):
tft.fill_rect(0,0, 240,140, st7789.RED)
time.sleep(0.5)
tft.fill_rect(0,0, 240,140, st7789.GREEN)
time.sleep(0.5)
tft.fill_rect(0,0, 240,140, st7789.BLUE)
time.sleep(0.5)
tft.fill_rect(0,0, 240,140, st7789.YELLOW)
time.sleep(0.5)
tft.fill(0)
def info():
tft.init()
utime.sleep(0.2)
tft.text(font,"RP2040 RTC", 15,20)
tft.fill_rect(15, 60, 210,10, st7789.RED)
tft.text(font,"Real Time", 15,70,st7789.YELLOW)
tft.text(font,"Clock", 15,100,st7789.YELLOW)
tft.fill_rect(15, 140, 210, 10, st7789.BLUE)
time.sleep(2)
tft.fill(0) #clear screen
info()
#PicoRTCSetTime() #You can remove this line once time is set
while 1:
data = PicoRTCReadTime()
a = data[0]&0x7F #sec
b = data[1]&0x7F #min
c = data[2]&0x3F #hour
d = data[3]&0x07 #week
e = data[4]&0x3F #day
f = data[5]&0x1F #month
g = data[6]&0x3F #year
#dt = "20%x/%02x/%02x %02x:%02x:%02x %s" %(g,f,e,c,b,a,week[d-1])
t = "%02x:%02x:%02x %s" %(c,b,a,week[d-3])
d = "%02x/%02x/20%x"%(e,f,g)
print(t) #year,month,day,hour,min,sec,week
print(d)
alarm(c,b,a) # set alarm
tft.text(font,d, 15,20,st7789.WHITE)
tft.fill_rect(15, 60, 210,10, st7789.RED)
tft.text(font,t, 15,80,st7789.YELLOW)
time.sleep(1)
- You will get the output as you can see in the video below:
Save these files on EncroPi renaming them to "main.py"
now every time you connect EncroPi to USB you'll get the current date & time as long as Coin cells work. : )
Enjoy!
Comments
Please log in or sign up to comment.