Added RTC for Inkpltae5
This commit is contained in:
parent
b4008a3677
commit
5477f30992
39
Examples/Inkplate5/RTC.py
Normal file
39
Examples/Inkplate5/RTC.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||||
|
|
||||||
|
# Include all the required libraries
|
||||||
|
from inkplate5 import Inkplate
|
||||||
|
from soldered_logo import *
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||||
|
# For 2-bit grayscale, see basicGrayscale.py
|
||||||
|
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
# Initialize the display, needs to be called only once
|
||||||
|
display.begin()
|
||||||
|
|
||||||
|
# Clear the frame buffer
|
||||||
|
display.clearDisplay()
|
||||||
|
|
||||||
|
# This has to be called every time you want to update the screen
|
||||||
|
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||||
|
display.display()
|
||||||
|
|
||||||
|
# This is how to set the RTC's time
|
||||||
|
# Arguments are hour, minute, seconds
|
||||||
|
display.rtcSetTime(9,39,10)
|
||||||
|
# And this is the date
|
||||||
|
# Arguments are weekday, day in month, month and year
|
||||||
|
display.rtcSetDate(5,9,2,2024)
|
||||||
|
|
||||||
|
# Show the set time
|
||||||
|
print(display.rtcGetData())
|
||||||
|
|
||||||
|
# Let's wait 10 seconds
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
# Let's see if the time has updated
|
||||||
|
print(display.rtcGetData())
|
18
i2c_scanner.py
Normal file
18
i2c_scanner.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Scanner i2c en MicroPython | MicroPython i2c scanner
|
||||||
|
# Renvoi l'adresse en decimal et hexa de chaque device connecte sur le bus i2c
|
||||||
|
# Return decimal and hexa adress of each i2c device
|
||||||
|
# https://projetsdiy.fr - https://diyprojects.io (dec. 2017)
|
||||||
|
|
||||||
|
import machine
|
||||||
|
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
|
||||||
|
|
||||||
|
print('Scan i2c bus...')
|
||||||
|
devices = i2c.scan()
|
||||||
|
|
||||||
|
if len(devices) == 0:
|
||||||
|
print("No i2c device !")
|
||||||
|
else:
|
||||||
|
print('i2c devices found:',len(devices))
|
||||||
|
|
||||||
|
for device in devices:
|
||||||
|
print("Decimal address: ",device," | Hexa address: ",hex(device))
|
93
inkplate5.py
93
inkplate5.py
|
@ -58,6 +58,14 @@ EPD_LE = const(0x00000004) # in W1Tx0
|
||||||
EPD_CKV = const(0x00000001) # in W1Tx1
|
EPD_CKV = const(0x00000001) # in W1Tx1
|
||||||
EPD_SPH = const(0x00000002) # in W1Tx1
|
EPD_SPH = const(0x00000002) # in W1Tx1
|
||||||
|
|
||||||
|
# Some constants for the RTC
|
||||||
|
RTC_I2C_ADDR = 0x51
|
||||||
|
RTC_RAM_by = 0x03
|
||||||
|
RTC_DAY_ADDR = 0x07
|
||||||
|
RTC_SECOND_ADDR = 0x04
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Inkplate provides access to the pins of the Inkplate 5 as well as to low-level display
|
# Inkplate provides access to the pins of the Inkplate 5 as well as to low-level display
|
||||||
# functions.
|
# functions.
|
||||||
|
|
||||||
|
@ -181,6 +189,70 @@ class _Inkplate:
|
||||||
cls.temperatureInt = int.from_bytes(cls._temperature, "big", True)
|
cls.temperatureInt = int.from_bytes(cls._temperature, "big", True)
|
||||||
return cls.temperatureInt
|
return cls.temperatureInt
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def rtc_dec_to_bcd(cls, val):
|
||||||
|
return (val // 10 * 16) + (val % 10)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def rtc_bcd_to_dec(cls, val):
|
||||||
|
return (val // 16 * 10) + (val % 16)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||||
|
data = bytearray([
|
||||||
|
RTC_RAM_by,
|
||||||
|
170, # Write in RAM 170 to know that RTC is set
|
||||||
|
cls.rtc_dec_to_bcd(rtc_second),
|
||||||
|
cls.rtc_dec_to_bcd(rtc_minute),
|
||||||
|
cls.rtc_dec_to_bcd(rtc_hour)
|
||||||
|
])
|
||||||
|
|
||||||
|
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||||
|
rtcYear = rtc_yr - 2000
|
||||||
|
|
||||||
|
data = bytearray([
|
||||||
|
RTC_RAM_by,
|
||||||
|
170, # Write in RAM 170 to know that RTC is set
|
||||||
|
])
|
||||||
|
|
||||||
|
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||||
|
|
||||||
|
data = bytearray([
|
||||||
|
RTC_DAY_ADDR,
|
||||||
|
cls.rtc_dec_to_bcd(rtc_day),
|
||||||
|
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||||
|
cls.rtc_dec_to_bcd(rtc_month),
|
||||||
|
cls.rtc_dec_to_bcd(rtcYear),
|
||||||
|
])
|
||||||
|
|
||||||
|
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def rtc_get_rtc_data(cls):
|
||||||
|
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||||
|
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||||
|
|
||||||
|
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||||
|
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||||
|
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||||
|
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||||
|
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||||
|
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||||
|
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||||
|
|
||||||
|
return {
|
||||||
|
'second': rtc_second,
|
||||||
|
'minute': rtc_minute,
|
||||||
|
'hour': rtc_hour,
|
||||||
|
'day': rtc_day,
|
||||||
|
'weekday': rtc_weekday,
|
||||||
|
'month': rtc_month,
|
||||||
|
'year': rtc_year
|
||||||
|
}
|
||||||
|
|
||||||
# _tps65186_write writes an 8-bit value to a register
|
# _tps65186_write writes an 8-bit value to a register
|
||||||
@classmethod
|
@classmethod
|
||||||
def _tps65186_write(cls, reg, v):
|
def _tps65186_write(cls, reg, v):
|
||||||
|
@ -393,10 +465,10 @@ class InkplateMono(framebuf.FrameBuffer):
|
||||||
data = int(fb[ix])
|
data = int(fb[ix])
|
||||||
ix -= 1
|
ix -= 1
|
||||||
w1ts0[0] = lut[data >> 4]
|
w1ts0[0] = lut[data >> 4]
|
||||||
#w1tc0[0] = EPD_CL
|
# w1tc0[0] = EPD_CL
|
||||||
w1tc0[0] = off
|
w1tc0[0] = off
|
||||||
w1ts0[0] = lut[data & 0xF]
|
w1ts0[0] = lut[data & 0xF]
|
||||||
#w1tc0[0] = EPD_CL
|
# w1tc0[0] = EPD_CL
|
||||||
w1tc0[0] = off
|
w1tc0[0] = off
|
||||||
|
|
||||||
# display_mono sends the monochrome buffer to the display, clearing it first
|
# display_mono sends the monochrome buffer to the display, clearing it first
|
||||||
|
@ -415,8 +487,8 @@ class InkplateMono(framebuf.FrameBuffer):
|
||||||
ip.clean(2, 1)
|
ip.clean(2, 1)
|
||||||
ip.clean(0, 11)
|
ip.clean(0, 11)
|
||||||
|
|
||||||
#w1ts0 = ptr32(int(ESP32_GPIO + 4 * W1TS0))
|
# w1ts0 = ptr32(int(ESP32_GPIO + 4 * W1TS0))
|
||||||
#w1tc0 = ptr32(int(ESP32_GPIO + 4 * W1TC0))
|
# w1tc0 = ptr32(int(ESP32_GPIO + 4 * W1TC0))
|
||||||
|
|
||||||
# the display gets written N times
|
# the display gets written N times
|
||||||
t1 = time.ticks_ms()
|
t1 = time.ticks_ms()
|
||||||
|
@ -767,7 +839,7 @@ class Inkplate:
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
def initSDCard(self):
|
def initSDCard(self):
|
||||||
_Inkplate.SD_ENABLE.digitalWrite(0)
|
_Inkplate.SD_ENABLE.digitalWrite(0)
|
||||||
try:
|
try:
|
||||||
|
@ -786,7 +858,7 @@ class Inkplate:
|
||||||
def SDCardSleep(self):
|
def SDCardSleep(self):
|
||||||
_Inkplate.SD_ENABLE.digitalWrite(1)
|
_Inkplate.SD_ENABLE.digitalWrite(1)
|
||||||
time.sleep_ms(5)
|
time.sleep_ms(5)
|
||||||
|
|
||||||
def SDCardWake(self):
|
def SDCardWake(self):
|
||||||
_Inkplate.SD_ENABLE.digitalWrite(0)
|
_Inkplate.SD_ENABLE.digitalWrite(0)
|
||||||
time.sleep_ms(5)
|
time.sleep_ms(5)
|
||||||
|
@ -830,6 +902,15 @@ class Inkplate:
|
||||||
def einkOff(self):
|
def einkOff(self):
|
||||||
_Inkplate.power_off()
|
_Inkplate.power_off()
|
||||||
|
|
||||||
|
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||||
|
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||||
|
|
||||||
|
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||||
|
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||||
|
|
||||||
|
def rtcGetData(self):
|
||||||
|
return _Inkplate.rtc_get_rtc_data()
|
||||||
|
|
||||||
def readBattery(self):
|
def readBattery(self):
|
||||||
return _Inkplate.read_battery()
|
return _Inkplate.read_battery()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue