Let’s try again!

Got a second one in today and it’s looking good. Hooked it up to an RPI 2 (or 3?) with a ribbon cable and ran a test-script that shows (and log) data every 30 seconds. So far so good!

Decently packaged for sensitive electronics!

I made a small python script that checks every 30 seconds (more or less) what the CPU temperature, sensor temperature and humidity is. That way you can easily check what the readings are connected directly to the board or like below.

20cm ribbon cable

Running it for 10 minutes gives below readings. First you should always ignore and after that it’s around 40% humidity. That feels about right for the house I live in, I’ll check it outside soon.

Direct readings, uncompensated.

Feel free to (re)use this simple script. I know little about python, so I am sure it can be done better, but it fits its purpose. Use at own risk and all that 😉

#!/usr/bin/env python
import os,time
from datetime	import datetime
from subprocess	import PIPE, Popen, check_output
from bme280 	import BME280

bme280 = BME280()
os.system('clear')

######################## RemBrand ########################
# temp_check.py created by Remco Brand
# Simple python script to check and compare the BME280 output.
# After a small delay (yes, I want it to start at a rounded
# minute ;-)) it will show and log the CPU Temperature, sensor
# temperature and humidity.
# 
# Created to quickly check the differences in readin of the
# Enviro+ board connected to the RPI directly or with a 10-20cm
# ribbon cable.
# 
# Data is logged to tab delimited temp_log.txt and overwritten
# on start. If you want to keep it, rename before starting again.
# It'll run for for some 10 minutes with 30 second intervals.
# 
# Use at your own risk etc etc and enjoy!
######################## RemBrand ########################

print ("Press Ctrl+C to exit!")

time.sleep(3)
os.system('clear')

def get_cpu_temperature():
	process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True)
	output, _error = process.communicate()
	output = output.decode()
	return float(output[output.index('=') + 1:output.rindex("'")])

def get_sensor_temperature():
	raw_temp = "{:.2f}".format(bme280.get_temperature())
	return raw_temp

def get_sensor_humidity():
	raw_hum = "{:05.2f}".format(bme280.get_humidity())
	return raw_hum

def regTemp(seconds):
	start = time.time()
	passed = 0
	x = 0
	print ("#\tdate\ttime (hh:mm:ss)\tcpu\tsensor\thumidity")
	with open('temp_log.txt', 'w') as tempLog:
		tempLog.write("#\tdate\ttime (hh:mm:ss)\tcpu\tsensor\thumidity\n")
	while passed < seconds:
		time.sleep(1)
		if ((datetime.now().strftime("%S")) == '59'):
			passed = 0
			while passed <= seconds:
				passed = time.time() - start
				x+=1
				print ("{}\t{}\t{}\t{}\t{}\t{}".format(x,(datetime.now().strftime("%d-%m")),(datetime.now().strftime("%T")),get_cpu_temperature(),get_sensor_temperature(),get_sensor_humidity()))
				with open('temp_log.txt', 'a') as tempLog:
					tempLog.write("{}\t{}\t{}\t{}\t{}\t{}\n".format(x,(datetime.now().strftime("%d-%m-%Y")),(datetime.now().strftime("%T")),get_cpu_temperature(),get_sensor_temperature(),get_sensor_humidity()))
				time.sleep(30)
regTemp(600)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.