Display the degree character in Micro python?

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

    describe_temperature(temperature)
    display.set_pen(tempcolor)
    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.set_pen(black)
    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)
display.set_backlight(1.0)
display.set_font("bitmap8") 

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.

Cheers.

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