-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Hi,
I wired up a tinyRTC onto I2C bus 1 on a Raspberry Pi Pico and tried running the example. But it resulted in an error:
MicroPython v1.22.2 on 2024-02-22; Raspberry Pi Pico with RP2040
>>> from machine import I2C, Pin
>>> i2c = I2C(1)
>>> i2c.scan()
[80, 104]
>>> import ds1307
>>> ds = ds1307.DS1307(i2c)
>>> ds.datetime()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/ds1307.py", line 124, in datetime
TypeError: can't convert I2C to int
so, that would be:
...
124 | buf = self._i2c.readfrom_mem(self._addr, DATETIME_REG, 7)
...
expanded:
...
@property
def datetime(self) -> Tuple[int, int, int, int, int, int, int, int]:
"""
Get the current datetime
(2023, 4, 18, 0, 10, 34, 4, 108)
y, m, d, h, m, s, wd, yd
:returns: (year, month, day, hour, minute, second, weekday, yearday)
:rtype: Tuple[int, int, int, int, int, int, int, int]
"""
buf = bytearray(7)
buf = self._i2c.readfrom_mem(self._addr, DATETIME_REG, 7)
year = self._bcd_to_dec(buf[6]) + 2000
month = self._bcd_to_dec(buf[5])
day = self._bcd_to_dec(buf[4])
yearday = self.day_of_year(year=year, month=month, day=day)
return (
year,
month,
day,
self._bcd_to_dec(buf[2]), # hour
self._bcd_to_dec(buf[1]), # minute
self._bcd_to_dec(buf[0] & 0x7F), # second
self._bcd_to_dec(buf[3] - self._weekday_start), # weekday
yearday,
)
...
Any help is appreciated!
Metadata
Metadata
Assignees
Labels
No labels