- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Closed
Description
There are several ways in regular Python to display the degree symbol. You can simply insert u"\N{DEGREE SIGN}" . In micropython this appear to be unsupported. Sometimes you can cut and paste in °. Very simple, but in micropython this results in a funny A followed by °. Several other techniques have the same effect, funny A with degree symbol.
Is adding the degree symbol support a planned addition to micropython and for now is there a work-around?
Activity
dpgeorge commentedon Dec 17, 2020
Correct, unicode names are not supported (it would take many megabytes to store the mapping from name to unicode point/number).
I'm pretty sure it's supported, it is in the end just a unicode character. Eg:
That will print the degree symbol.
bill-orange commentedon Dec 17, 2020
@dpgeorge thanks for the response. I tested your solutions with this result.
u"\N{DEGREE SIGN}"
results in the error NotImplementedError: unicode name escapesdegree = chr(176) results in
°
when output to a web page through html. It works on the command line.Both approaches work fine in regular Python.
dpgeorge commentedon Dec 18, 2020
Yes, what I meant above is that this form is not supported in MicroPython. So you cannot do it this way.
How exactly is it being output to a web page, what is the code that reproduces the problem?
bill-orange commentedon Dec 18, 2020
I moved a copy of my files to GitHub. Take a look at BME280.py line 273 . To run this you would need to put your username and password in boot.py.
https://github.com/bill-orange/MicroPython/tree/main/BME280%20test
dpgeorge commentedon Dec 18, 2020
Thanks for posting the code.
I can't seem to reproduce any issue. On the unix port of MicroPython I can do:
Turning that into a HTML, you may need to use
°
?bill-orange commentedon Dec 18, 2020
bill-orange commentedon Dec 18, 2020
That worked. Thanks.
In main.py
<tr><td>Temp. Celsius</td><td><span class="sensor">""" + str(bme.temperature) + """°C</span></td></tr>
Merge pull request micropython#6700 from weblate/weblate-circuitpytho…
DrKRR commentedon May 23, 2023
The following MicroPython Program displays temperature in degree Celsius (symbol) on OLED
import ssd1306
from machine import Pin, SoftI2C
import time
import framebuf
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
Custom character bitmap
custom_bitmap = bytearray([0x00, 0x0e, 0x11, 0x11, 0x0e, 0x00, 0x00, 0x00])
Create a frame buffer from the custom bitmap
fb = framebuf.FrameBuffer(custom_bitmap, 8, 8, framebuf.MONO_HLSB)
t= b'45.2'
t1= t.decode()
Display custom bitmap on OLED
oled.fill(0) # Clear the display
Blit the frame buffer to the OLED display at position (0, 0)
oled.blit(fb, 95, 0)
oled.text("Temper= " + t1 + " " + "C", 0, 5)
Update the display
oled.show()
bruno1950 commentedon Apr 20, 2024
Hi, I'm an old (74) newbie of micropython and ESP32 and I'm trying to use an OLED SH1106 to display data from a BME280 sensor connected to an ESP32 working with uPY. While on the serial monitor the ° degree symbol is correctly printed I was not able to get it displayed on the SH1106. I tried both display.text("{:0.0f}°C".format(temperature), 0, 30) and display.text("{:0.0f}{}".format(temperature, chr(176)), 0, 30) but I keep on getting ValueError: unknown format code 'f' for object of type 'str'. Could you hel pme to fix this issue ? Thanks
peterhinch commentedon Apr 21, 2024
The solution depends on which display driver you're using. This one it is subclassed from FrameBuffer: this enables you to use fonts created with font_to_py. Such fonts can contain any glyph you like.
bruno1950 commentedon Apr 21, 2024
peterhinch commentedon Apr 21, 2024
The driver is designed to work as a Python package. It needs to be installed with
mpremote
as described here. That will create the right directory structure and installboolpalette.py
.bruno1950 commentedon Apr 21, 2024
peterhinch commentedon Apr 21, 2024
You won't regret the move. I ditched Arduino for MicroPython ten years ago and have never looked back.