Skip to content

Internal temperature sensor

def internalTemp():
    ''' Read from ADC, convert raw values to Ceclcius via voltage. 
    '''
    sensor = ADC(4)
    adc_value = sensor.read_u16()
    adc_voltage = (3.3/65535) * adc_value 
    temperature = 27 - (adc_voltage - 0.706) / 0.001721
    return f"{round(temperature, 1)}C"

Humidity, pressure and temperature (BME280)

Using the sensor

# Read and return the compensated relative humidity.
# Result is in Q22.10 fixed-point format (1024 = 1% RH).
read_humidity() # For example 46387 (divided by 1024 gives 45.30, which is 45.30% RH)
# Return the relative humidity as a formatted percentage string.
humidity() # For example: 45.30%

# Read and return the compensated pressure.
# Result is in Pa * 256 (fixed-point format).
read_pressure() # For example: 25832456 (divided by 256 gives 100908.0, which is 1009.08 hPa)
# Return the pressure as a formatted string in hPa.
pressure() # For example: 1009.08hPa

# Read and return the compensated temperature.
# Result is in hundredths of a degree Celsius (0.01°C).
read_temperature() # For example: 2345 (meaning 23.45°C)
# Return the temperature as a formatted string in degrees Celsius.
temperature() # For example: 23.45C

In summary:

Function Example Return Meaning
read_temperature() 2345 23.45°C
temperature "23.45C" 23.45°C
read_pressure() 25832456 100908 Pa
pressure "1009.08hPa" 1009.08 hPa
read_humidity() 46387 45.30% RH
humidity "45.30%" 45.30% RH
# BME280
import BME280

i2c_bme = I2C(0, sda=Pin(4), scl=Pin(5), freq=100000) # BME tilkobling på pico
bme = BME280.BME280(i2c=i2c_bme)

Calibrating the sensors

Altitude calculations