Copy the sample code to a folder on the Raspberry Pi.
Open terminal, and then go to the folder you copied the sample.
Run the sample with the following command:
python3 env.py
Sample Code
env.py
#!/usr/bin/python#This sample demonstrates reading temperature, relative humidity, and air pressure data.#Install Sensor uHAT library with "pip3 install turta-sensoruhat"import timefrom turta_sensoruhat import Turta_Env_280#Variables#Sea level pressure in barslp =1000.0#Update this from weather forecast to get precise altitude#Initializeenv = Turta_Env_280.EnvironmentalSensor()try:whileTrue:#Hint: To get temperature, pressure and humidity readings at the same time,#call EnvironmentalSensor.read_tph() method.#Read & print temperatureprint("Temperature.....: "+str(round(env.read_temperature(), 1)) +"C")#Read & print humidityprint("Humidity........: %"+str(round(env.read_humidity(), 1)) +"RH")#Read & print pressureprint("Pressure........: "+str(round(env.read_pressure(), 1)) +"Pa")#Read & print altitudeprint("Altitude........: "+str(round(env.read_altitude(slp), 1)) +"m")#Rest a bitprint("-----") time.sleep(2.0)#Exit on CTRL+CexceptKeyboardInterrupt:print('Bye.')
Result
When you run the sample, it prints the environmental data. The example output should be like this: