PiicoDev_BME280 How to show only 2 decimal values?

Hi, im a novice with micro python and I’ve been playing with the pico and the PiicoDev starter kit. I have a project set up with the BME280 the RGB LEDS’s and the OLED display all works how I intended it to except I would like to display the result to 2 decimal places.

I have looked in the driver for the BME280 but can’t seem find where or how to do this. Any support on this would be much appreciated. I have attached a image of the project I have set up which shows the extended numerical values.

4 Likes

Hi Daniel,

It’s been a while since I’ve worked in MicroPython, but IIRC Python’s builtin .format tool works:

I’m pretty sure I used it to trim text to display on a PiicoDev OLED, but it was months ago.

Give it a go and maybe someone who knows for sure can correct me :slight_smile:
-James

2 Likes

I think you can use the round() function to round a number to x decimals.

round(value, 2)

2 Likes

Hi Daniel,

How did you go on this one? If you’re having trouble I implemented the method suggested by James (string .format) and it looks like it works just fine :slight_smile:

from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_SSD1306 import *
from PiicoDev_Unified import sleep_ms

display = create_PiicoDev_SSD1306()
bme = PiicoDev_BME280()

while True:
    display.fill(0)
    hum = "Hum: {:.2f}".format(bme.values()[2])
    display.text(hum, 0, 0, 1)
    display.show()


Keen to see how you got on :slight_smile:

1 Like