Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for SHT31 Temp/Humidity Sensor #161

Open
barista123 opened this issue Feb 1, 2021 · 2 comments
Open

Adding support for SHT31 Temp/Humidity Sensor #161

barista123 opened this issue Feb 1, 2021 · 2 comments

Comments

@barista123
Copy link

Hardware details
Is it possible to add support for the SHT31 Temp/Humidity Sensor, it is an i2c sensor.
https://www.adafruit.com/product/2857

Benefits
I previously used DHT sensors, but they quickly failed in my application (greenhouse) due to humidity issues. This sensor seems to be more reliable and accurate. I am simplifying my install and would like to move this sensor to pi-mqtt-gpio if possible.

Python library
Adafruit python library
https://github.com/adafruit/Adafruit_CircuitPython_SHT31D

Context
Thanks. The project is great.

@barista123
Copy link
Author

barista123 commented Feb 2, 2021

I do not know how to program in Python, but I was able to scrap together a script that pulls the data from the sht31 and publishes via mqtt. Right now, the script is outside pi-mqtt-gpio and is being run via Crontab (I know ugly, but getting the job done). Not sure if it would help. (Sorry about formatting, not sure how to fix or to publish code.

#!/usr/bin/env python3

import smbus
import paho.mqtt.client as mqtt
import os
import time

# Start the i2c bus and label as 'bus'
bus = smbus.SMBus(1)

# Send the start conversion command to the SHT31
bus.write_i2c_block_data(0x44, 0x2C, [0x06])

time.sleep(0.5)

# SHT31 address, 0x44(68)
# Read data back from 0x00(00), 6 bytes
# Temp MSB, Temp LSB, Temp CRC, Humididty MSB, Humidity LSB, Humidity CRC
data = bus.read_i2c_block_data(0x44, 0x00, 6)

# Convert the data
temp = data[0] * 256 + data[1]
cTemp = round(-45 + (175 * temp / 65535.0),2)
fTemp = round(-49 + (315 * temp / 65535.0),2)
humidity = round(100 * (data[3] * 256 + data[4]) / 65535.0,2)

# This is the Publisher

client = mqtt.Client()
client.username_pw_set("user", "password")
client.connect("broker",1883,60)
client.publish("sensor/fTemp", fTemp);
client.publish("sensor/cTemp", cTemp);
client.publish("sensor/humidity", humidity);
client.disconnect();

@flyte
Copy link
Owner

flyte commented Feb 26, 2021

Thanks, we'll get that module built at some point, but it'll only be on the new version that we're testing at the moment. I'll respond back to this issue once the module's built.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants