Hi I am using the tutorial and code on bme 680 weather sensor (https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-bme680-breakout) and I’m getting a reading below- any help would be great:
NameError: name ‘output’ not defined
Can you post the full code your running. If you put it between 3 ` and 3 more at the end it will keep the formatting. On my keyboard its the key just below the esc key with a ~ on it.
code
And welcome to Pimoroni Forums. =)
while True:
if sensor.get_sensor_data():
output = "{0:.2f} C,{1:.2f} hPa,{2:.2f} %RH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity)
if sensor.data.heat_stable:
print("{0},{1} Ohms".format(output, sensor.data.gas_resistance))
else:
print(output)
time.sleep(1)
This needs to be above the while true
import bme680
import time
sensor = bme680.BME680()
sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
sensor.select_gas_heater_profile(0)
while True:
Yes we have all that above the while true. The problem we are getting is ‘output is not defined’. Am I right in thinking; output = “{0:.2f} C,{1:.2f} hPa,{2:.2f} %RH”.format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity) is defining output?
Did you run the installer?
curl https://get.pimoroni.com/bme680 | bash
I think the issue is when “output” is called in the file, python doesn’t know what “output” is and is supposed to do? I’m no Python expert though.
@sandyjmacdonald may know what’s going wrong? Looks like he wrote that tutorial.
I have two BME680’s in use here, but I don’t call out string values. I do it like this.
if sensor.get_sensor_data():
p = sensor.data.pressure
p = round(p)
@mbain Can you post the complete code that you’re using, please, and I’ll try to replicate the error?