Adjust Python examples

Try the following and see what happens
unicornhatmini.set_pixel(int(seconds_progress), 6, 255, 255, 255)

1 Like

That might have worked, now the next error is closer to the end with the missing attribute 'write_string'. That’s sth to look after tomorrow, and maybe by the time your Unicorn HAT Mini arrives the clock is working.

(seconds_progress) is I think the value for x. Which changes as the seconds tick by.
And 6 is the row y, which never changes.
and then the color values.

Your latest error is likely the brightness=BRIGHTNESS line

  scrollphathd.write_string(
        time.strftime("%H:%M"),
        x=0,                   # Align to the left of the buffer
        y=0,                   # Align to the top of the buffer
        font=font5x5,          # Use the font5x5 font we imported above
        brightness=BRIGHTNESS  # Use our global brightness value

I’d just remove it and see what happens.

EDIT: if needs the color info try
r, g, b = (255, 255, 255)
or
r, g, b = 255, 255, 255

Good morning! Sadly your solution didn’t work, gives me this error:

File "./clock.py", line 76
    r, g, b = (255, 255, 255)  # Use our global brightness value
    ^
SyntaxError: positional argument follows keyword argument

If I leave the brightness=BRIGHTNESS I get this one:

Traceback (most recent call last):
    File "./clock.py", line 71, in <module>
        unicornhatmini.write_string(
AttributeError: 'UnicornHATMini' object has no attribute 'write_string'

So my guess is that this error comes because the __init__.py doesn’t have the write_string attribute. Hopefully I have time later today to work more on this, and see if I can copy (& edit) the write_string from the Scroll HAT Mini its __init__.py

If you leave the Brightness line “and” the r, g, b = (255, 255, 255) line out what happens?

Just a FYI, in case you didn’t know. Any text with a # in front of it is ignored. It’s just a comment that doesn’t do anything code wise.

I still get the same error, will try to somehow get the write_string inserted functional in the Unicorn HAT Mini its __init__.py. That text with a # is ignored I already knew, but thanks :)

edit: after putting the write_string and clear rect (later in the script, but also not in the Unicorn HAT Mini library) is still get the AttributeError: 'UnicornHATMini' object has no attribute 'write_string' or when I leave that part in the script I get AttributeError: 'UnicornHATMini' object has no attribute 'clear_rect'.

So what goes wrong here? Because I expect errors because of the simple copy&paste of attributes from Scroll HAT Mini to Unicorn HAT Mini but not the error that it doesn’t have the attribute at all.

The Scroll Phat HD function reference is here.
http://docs.pimoroni.com/scrollphathd/
Which lists those commands and what arguments they expect.
Unfortunately all I can find for the Unincorn Mini is as folows


clear_rect may have to be replaced with unicornhatmini.clear()?

The current issue may be that the Unicorn Mini uses SPI and for the most part PIL to do the graphic bits.

By the way, for somebody that claims to have no python skills, your doing pretty dammed good. ;) =)

Phil @gadgetoid are you out there buddy? We could sure some help writing a string value to this new bit of kit?

@placebo83 have a look see at this thread and see if it helps any.

The clear_rect is different than the clear(), since the Scroll HAT Mini has also the clear attribute in its __init__.py. Although I tried it just to see what happens and in combination with leaving the write_string part out I don’t get an error anymore, I get a pixel blinking, moving around “randomly” (it’s probably not random, but one pixel doesn’t give much information) in the bottom line of the Unicorn HAT Mini.

Skills are growing fast here with all of your explanations and reading those scripts bit by bit :)

I guess for now I will also copy the __init__.py in the same folder as the clock.py (as I did for the font) and change the script. And look for hints in the references and linked thread you gave.
I also found out that depending on how long I let the script run I get 1 or 2 different error messages, will look after them too.

Sadly I won’t have too much time the next days, but will try to get some things done and keep you folks updated (and also hope @gadgetoid shows up 😎).

Hopefully mine will show up soon and I can join the fun. =)
At some point I’ll be looking for what you have so far, code wise.

Back again for a bit, but no new insights. I end up with the error:

Traceback (most recent call last):
  File "./clock.py", line 71, in <module>
    unicornhatmini.write_string(
AttributeError: 'UnicornHATMini' object has no attribute 'write_string'

I copied the def write_string from the Scroll HAT Mini (ok to be precise it’s from the Scroll PHAT HD, afaik there is no library for the Scroll HAT Mini) its init.py, and copied into the Unicorn HAT Mini its init.py, rebooted the Pi but still get the same error. I also put the init.py in the same folder as the clock.py script, but it didn’t change anything. Any idea what could be the problem?

For some reason the UnicornHATMini def of write_string doesn’t seem to be getting picked up, are you certain you replaced the init.py in the UnicornHATMini’s library folder? You might need to upload the code somewhere so we can take a poke through it.

I double checked it and the def write_string is there. I changed it on the Pi itself, but now also on my copy of the repository so you can see how I did it: https://github.com/placebo83/unicornhatmini-python

Ah, right, do you see line 161 which starts if __name__ == "__main__":? That’s a function which checks if the module is being run as a script directly, and then does some fancy demo stuff. However, if you’re importing the module into another script that doesn’t ever get run, so your function isn’t ever declared.

Try moving the function to line 159ish, after the get_shape function but before if __name__ == "__main__":.

I did as you told, first in my repository, then on the Pi, checked, rebooted, checked again but still the same problem :(
Luckily I just assembled my pan/tilt HAT and it’s working like a charm, so when I get frustrated with this I tinker a bit around with that one and a Sphero RVR

Hmm. My UnicornMini has just been delivered, if I get time I’ll have a poke at this over the weekend.

Ok, good luck with it! The clock is a nice use for it imho.

Still waiting for mine to show up, unfortunately. Its been about 30 days since it shipped via Royal Mail. All this Covid stuff is messing things up. I usually get stuff in about 2 weeks, sometimes a little longer. Hopefully it shows up in time for me to also play around with it over the weekend.