Weather-and-light.py set to Fahrenheit

Hi. How can i set the weather-and-light.py to show the temperature in Fahrenheit? I know the formula is (°C × 9/5) + 32 = °F Exactly where do i add this?

Thanks!!

It would be right after the temperature is read from the BME280

 # Temperature
    temperature = bme280.get_temperature()

#your conversion code here

Then edit any line that references “temperature” to your new converted value for temp in F.
Lines like the following will have to be edited.

temp_string = f"{temperature:.0f}°C"
to something like this.
temp_string = f"{converted_value:.0f}°F"

There may be some other code to edit too, the min max temp bit etc.

Thank you! That works. I just need to sort out the referenced lines. I am a Pimoroni retailer in the US and all my customers are asking for this. If I ever get this all sorted out I will post the code on GitHub. New to python coding, if anyone else has any clues as to Celsius to Fahrenheit conversion it will be greatly appreciated.

Bright Ibeawuchi

Thinking about this some more, there may be an easier way.
Change the
temperature = bme280.get_temperature()
to
temp_c = bme280.get_temperature()

Then do a
temperature = (temp_c * 9/5) + 32
No having to edit all the references to “temperature”

Just the one edit of
temp_string = f"{temperature:.0f}°C"
to
temp_string = f"{temperature:.0f}°F"

I “think” that should do it?

Hi that changes the temp reading however it’s very high. The temp in my room is approx 75F the enviro shows 120F. Wouldn’t the cpu temp calculations need to be converted also? I tried tinkering with the cpu_temps = [get_cpu_temperature()] * 5 line. So far no luck.

Not sure if this has anything to do wit it but i cannot get the multiply x symbol to work. Throws an invalid character error. I use the *

The * is the correct symbol for multiplication.

I forgot all about the CPU temperature compensation code. I have removed that from my file as where my Pi Zero is, it doesn’t affect the readings. My Pi Zero isn’t under my Breakout Garden Mini and is far enough away from it that it doesn’t affect the temperature readings. Plus, being in Canada I use C anyway. That is probably what is messing up your temperature readings. You’ll have to also convert those to F.

I’d change
cpu_temps = [get_cpu_temperature()] * 5
to
cpu_temps_c = [get_cpu_temperature()] * 5

Then do a
cpu_temps = (cpu_temps_c * 9/5) + 32