Reputation: 19
I have a Python script controlling a Fibonacci clock that works great on the Raspberry Pi 4B, however, when I transfer the code to a PyBoard using MicroPython (which I'm completely new to) it doesn't work. Below is the part I believe to be the error. ...
import datetime
import time
import sys
from time import sleep
while 1:
t = datetime.datetime.now()
hr = t.hour
mn = t.minute
if (hr==00) or (hr==12):
hr = 12
bulb1Red()
else:
bulb1White()
mn5 = mn%5
if (mn5 == 0):
mn = mn/5
else:
mn = mn-mn5
mn = mn/5
if(hr > 12):
hr = hr-12
Upvotes: 2
Views: 899
Reputation: 19
I managed to get the above effect using RTC and works great except even with a battery permanently connected to the Pyboard, I appear to lose an hour every night, which is pretty poor for a clock, thus I have gone back to using the Raspberry Pi.
Upvotes: 0
Reputation: 388
I suppose this is due to the fact, that MicroPython is not a 1-to-1 copy of CPython. Most libraries are not implemented and the ones that left are condensed to a minimum and are named differently. Speaking general, programming a Fibonacci clock should work with the RTC of the PyBoard, but you have to tweak your script a little.
You have to use MicroPython-specific libraries. datetime
, time
and sys
do not exist in MicroPython. E.g. use utime
for time related functions. See: https://docs.micropython.org/en/latest/library/utime.html
Upvotes: 1