# Adjust Python examples

**URL:** <https://forums.pimoroni.com/t/adjust-python-examples/13954>\
**Category:** Support\
**Created:** [May 19, 2020, 2:48pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954 "2020-05-19T14:48:29Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 23, 2020, 7:45pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/21 "2020-05-23T19:45:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![placebo83](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/placebo83/32/6800_2.png) [@placebo83](https://forums.pimoroni.com/u/placebo83)\
**Post date:** [May 23, 2020, 7:50pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/22 "2020-05-23T19:50:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 23, 2020, 7:51pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/23 "2020-05-23T19:51:43Z")

</div>

(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.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 23, 2020, 7:58pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/24 "2020-05-23T19:58:46Z")

</div>

Your latest error is likely the brightness=BRIGHTNESS line

```auto
  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

---

<div class="post-metadata">

**Author:** ![placebo83](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/placebo83/32/6800_2.png) [@placebo83](https://forums.pimoroni.com/u/placebo83)\
**Post date:** [May 24, 2020, 4:01am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/25 "2020-05-24T04:01:50Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 24, 2020, 8:56am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/26 "2020-05-24T08:56:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![placebo83](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/placebo83/32/6800_2.png) [@placebo83](https://forums.pimoroni.com/u/placebo83)\
**Post date:** [May 24, 2020, 4:55pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/27 "2020-05-24T16:55:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 24, 2020, 6:00pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/28 "2020-05-24T18:00:32Z")

</div>

The Scroll Phat HD function reference is here.  
[http://docs.pimoroni.com/scrollphathd/](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

> <https://github.com/pimoroni/unicornhatmini-python/blob/master/REFERENCE.md>

  
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. ;) =)

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 24, 2020, 6:03pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/29 "2020-05-24T18:03:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 24, 2020, 6:04pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/30 "2020-05-24T18:04:18Z")

</div>

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

> [@Simple way to display a variable on Unicorn Hat HD](https://forums.pimoroni.com/t/simple-way-to-display-a-variable-on-unicorn-hat-hd/7299):
>
> Hi, I’ve got my BME680 set up on a PHAT STACK with my Unicorn HAT HD. I want to combine the two and display the air quality reading on my Unicorn Hat HD. Typically the number will be a percentage say 95%. Is there a simple way to achieve this as I’ve searched through various scripts and can only see text being displayed. Thanks in advance Scott

---

<div class="post-metadata">

**Author:** ![placebo83](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/placebo83/32/6800_2.png) [@placebo83](https://forums.pimoroni.com/u/placebo83)\
**Post date:** [May 24, 2020, 6:29pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/31 "2020-05-24T18:29:21Z")

</div>

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 😎).

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 24, 2020, 7:22pm UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/32 "2020-05-24T19:22:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![placebo83](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/placebo83/32/6800_2.png) [@placebo83](https://forums.pimoroni.com/u/placebo83)\
**Post date:** [May 28, 2020, 10:14am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/33 "2020-05-28T10:14:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)\
**Post date:** [May 28, 2020, 10:20am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/34 "2020-05-28T10:20:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![placebo83](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/placebo83/32/6800_2.png) [@placebo83](https://forums.pimoroni.com/u/placebo83)\
**Post date:** [May 28, 2020, 10:33am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/35 "2020-05-28T10:33:54Z")

</div>

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](https://github.com/placebo83/unicornhatmini-python)

---

<div class="post-metadata">

**Author:** ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)\
**Post date:** [May 28, 2020, 10:39am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/36 "2020-05-28T10:39:17Z")

</div>

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__":`.

---

<div class="post-metadata">

**Author:** ![placebo83](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/placebo83/32/6800_2.png) [@placebo83](https://forums.pimoroni.com/u/placebo83)\
**Post date:** [May 28, 2020, 10:56am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/37 "2020-05-28T10:56:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)\
**Post date:** [May 28, 2020, 10:58am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/38 "2020-05-28T10:58:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![placebo83](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/placebo83/32/6800_2.png) [@placebo83](https://forums.pimoroni.com/u/placebo83)\
**Post date:** [May 28, 2020, 10:59am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/39 "2020-05-28T10:59:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [May 28, 2020, 11:18am UTC](https://forums.pimoroni.com/t/adjust-python-examples/13954/40 "2020-05-28T11:18:06Z")

</div>

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.

[Previous page](https://forums.pimoroni.com/t/adjust-python-examples/13954.md?page=1)

[Next page](https://forums.pimoroni.com/t/adjust-python-examples/13954.md?page=3)
