2

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
Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
Random Boo
  • 19
  • 1
  • What is it that 'doesn't work'? What do you expect to happen and what happens instead? Is there an error message? – nekomatic Feb 11 '20 at 14:47

2 Answers2

1

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

wallisers
  • 388
  • 3
  • 16
  • the "u" prefix is only present so that if your application or MicroPython overrides "time" , you can still access the micropython time module as "utime". In the absence of an override of the time namespace, time is the same as utime. – Patrick Mar 25 '20 at 17:24
0

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.

Random Boo
  • 19
  • 1
  • This appears to be an ongoing battle for MicroPython see GH Issue: https://github.com/micropython/micropython/issues/2724 – Patrick Mar 25 '20 at 17:26