Display the degree character in Micro python?

Some here will get a kick out of this.
I had this Micro Python code.

    display.rectangle(0, 80, (scaled_temp), 19)
    display.circle((scaled_temp), 89, 9)
    display.text("{:0.0f}c".format(temperature), 0, 40, scale=4)
    display.text(describe_temperature(temperature), 150, 40, scale=4)
    display.circle((scaled_temp), 89, 5) 

I wanted to add the degree cymbal to
display.text("{:0.0f}c".format(temperature), 0, 40, scale=4)
print(chr(176)) will display °
I could not figure out how to use / add that in my line of code.
So I did a copy past of that character from the Thonny output, to my code, and lol it worked.
display.text("{:0.0f}°c".format(temperature), 0, 40, scale=4)

If there is a keyboard combo for this i have no idea what it is. And I’d still like to know how it should have been done. =) Code wise.

This info may also be important.

import picographics
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_RGB332
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, rotate=0, pen_type=PEN_RGB332)

odds are, the font doesn’t support it… in which case you’d need a different/custom font. AFAICT most fonts in mPython are doing well to support basic ASCII. No clue here how to edit fonts.

I know Swedish uses an overring for some characters, and Irish uses an over dot, so fonts aimed at those might work. Alternatively some English fonts place the asterisk character high and it’s usually included.

That’s stuff I’m not up to speed on, as they say.
If I put print(chr(176)) in my code, Thonny outputs the ° in the shell window.
And clip and pasting the ° into my code gets it displayed correctly on my SPI LCD.
Trying to add the (chr(176)) to my code failed, which made me try the clip and past of the ° from the shell window to my code. I actually chucked to myself when it worked. =)

I have it doing what I wanted. I just used what I call trickery to get there. ;)

I’ve included an extra font, in three sizes, in this project. Easy to add to any project. The extended character set includes the degree symbol, Greek letters and much more.

It does not need the Pimoroni extras and includes simple graphics commands.

Hey Tony, how’s it going? I almost did an @Tonygo2 on this one. I’ll likely garb some of your custom fonts at some point.

That’s what I like about hanging out here. If you don’t have those skills, somebody else here usually does. =)

Life long learning. Keeps the brain working thinking about all this stuff. Much more fun than a crossword!.

Glad you are back in action. Keep warm over there!

1 Like

Lurking in the background these days, lol. Keeping the brain working thinking is why I do this stuff. One of the main reasons anyway.

Hi Alpha,

I stumbled across this same issue, and found that the deg symbol is in the Pimoroni uf2 now.
I just used character map to insert “°” you could copy paste that one to your code, without the quotes, as I’m sure you’re aware.

It will display as seen in the very rough and ready photo below. Hope that helps.


Yeah, I just did a clip and past into my code.

1 Like

This is a port of the above code that runs on my Tufty. I will be adding an RV3028 to it at some point to display Date and time. When I unplug the USB port it displays the Battery voltage and % remaining across the top.

Same thing happens on my Tufty clone above. The date display is replaced with Battery % remaining.

1 Like

::wipes egg off face:: I read that wildly wrong… no more “I’ll just check the forums real quick before I do X” for me.

I think the proper handling is either the way you ended up doing it*, or the more explicit
display.text("{:0.0f}{}c".format(temperature,chr(176)), 0, 40, scale=4)
or even
display.text("{:0.0f}{:c}c".format(temperature,176), 0, 40, scale=4)

*chr( # ) should map to unicode for any supported character, so instead of print copy paste you can directly insert the character. the method to do so is specific to the OS (and sometime certain programs support other methods). Wikipedia lists the most common methods

1 Like

Worked, and was how I had originally intended to do it. Just couldn’t figure out the right syntax.

Same 🙃 I really shouldn’t post in a rush. The true Pythonic method has been discovered. I am merely a student here!

I could have worded that first post a bit better I think.
All input (pun intended =) is welcome.
Ops the ) in the =) gave me a syntax error? :P

it doesn’t help that there are three competing format options in python (four if you count print( x, y ))… and to be honest I can never remember which is preferred in mPython, other than $# being depreciated for everything.

for a language that’s supposed to be simple, human readable, and aspires to “clean code” it sure does have a lot of inconsistent and puzzling gotchas (the preference for spaces, ‘from’ imported classes succesfully referencing external functions, and lack of proper do/while are all things that currently make me twitch)

I have blocks of code I borrowed from example code I got here and there. I know what they do, but have no idea how they do it? ;) If there in the right place at the right time, in my code, they work. Which works for me. =)
If I was younger I’d likely spend more time trying to dissect it. I do do that sometimes if I really want to tweak it a lot.

On a sort of side note. I am partially color blind, I have a Red Green Color Deficiency. I can see red and green. But telling green from yellow is a challenge for me on things like RGB LED matrixes. I can not see turquois, it either looks green or blue to me.

What it means for me is trusting that my code is actually displaying green when I think it should, or displaying yellow when I think it should.

Or tweaking the RGB values so “I” can see a distinct difference. The side effect of that, is when I’m showing off what I built, and explaining how it works. I get “but that’s not green” etc comments. ;)

You know, you just gave me an idea… I’ve seen so many of those color charts for what people with different vision are supposed to see, and it just struck me that the space between specific colors must be compressed (less separate tints) in something like red/green deficiency… I bet it would be possible to write some code that could mimic that and shift colors away from the weaker range into the stronger one, or vice versa. I’ll have to give it some thought but I bet it could not only simulate it, but also invert it making colors seem more vibrant. gonna have to let this idea stew for a bit, thanks

Reflected versus illuminated probably factors into it. Mixing pigments is a totally different ballgame versus mixing light. ;) Mixing Red and Green paint isn’t going to get you yellow, lol.
Mixing wavelengths of light also gets you colors that aren’t in the rainbow.
Purple isn’t a real color. ;)
The color purple is unlike all others, in a physical sense (zmescience.com)

Optics: Why is mixing of paint colors different from mixing light colors? - Bing video