Open bzfbd opened 2 years ago
Got the same weird behaviour from test.py. The RTC stores time/date values as BCD.
For every value pulled from the RTC, you have to convert the BCD encoded value to binary. For example:
seconds = bcd2bin(bus.read_byte_data(0x68, 0) & 0x7f)
with the following function:
def bcd2bin(value):
return value - 6 * (value >> 4)
Hope it helps.
Hi,
Greetings of the day !
Thanks for mentioning the issue, We have fixed the above issue in our latest commit.
@sbcshop then the issue can be closed :)
Hi everyone,
I am getting the following when trying test.py with Python 3.8.16 through pyenv:
❯ python test.py
Traceback (most recent call last):
File "test.py", line 55, in <module>
t[0] = t[0]&0x7F #sec
TypeError: 'int' object is not subscriptable
❯ python --version
Python 3.8.16
Any pointer will be greatly appreciated.
Thanks, Emanuel
I set the time and then uncommented that function call along with the print(t) and tried to read a few times but the results were anything but reliable. Has anyone seen this before?
python3.8 test.py
15/9/21 16:46:25 Wed
87.80000000000001 F / 31.0 C
(1 second real time, clock jumps 8s forward)
15/9/21 16:46:33 Wed
87.80000000000001 F / 31.0 C 15/9/21 16:46:34 Wed
87.80000000000001 F / 31.0 C 15/9/21 16:46:35 Wed
87.80000000000001 F / 31.0 C 15/9/21 16:46:37 Wed
87.80000000000001 F / 31.0 C 15/9/21 16:46:38 Wed
87.80000000000001 F / 31.0 C 15/9/21 16:46:39 Wed
87.80000000000001 F / 31.0 C 15/9/21 16:46:41 Wed
87.80000000000001 F / 31.0 C
python3.8 test.py
15/9/21 16:46:73 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:46:80 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:46:81 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:46:83 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:46:84 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:46:85 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:46:87 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:46:88 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:46:89 Wed
(whatever it read there isn't a second...; last I checked they wrapped at 60)
87.80000000000001 F / 31.0 C 15/9/21 16:47:1 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:2 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:3 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:5 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:6 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:8 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:9 Wed 87.80000000000001 F / 31.0 C
(and another jump)
15/9/21 16:47:16 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:17 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:19 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:20 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:21 Wed 87.80000000000001 F / 31.0 C 15/9/21 16:47:23 Wed