-
Notifications
You must be signed in to change notification settings - Fork 12
Description
I tweaked the .c file to calculate the dewpoint. It's an approximation formula since we only have temp and RH, but it appeared to be a decent formula that works across the RH spread.
=== ===
--- SHT30.c.FCS 2023-08-29 19:57:07.350407411 -0500
+++ SHT30.c.new 2023-08-29 20:27:17.487321465 -0500
@@ -4,11 +4,18 @@
// This code is designed to work with the SHT30_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Humidity?sku=SHT30_I2CS#tabs-0-product_tabset-2
+// Dewpoint formula found here:
+// https://bmcnoldy.earth.miami.edu/Humidity.html
+
+// log() requires math library (libm), so compile as:
+// gcc SHT30.c -lm -o SHT30
+
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
+#include <math.h>
void main()
{
@@ -36,7 +43,7 @@
char data[6] = {0};
if(read(file, data, 6) != 6)
{
-
printf("Erorr : Input/output Erorr \n");
-
printf("Error : Input/output Error \n"); } else {
@@ -45,10 +52,14 @@
float cTemp = -45 + (175 * temp / 65535.0);
float fTemp = -49 + (315 * temp / 65535.0);
float humidity = 100 * (data[3] * 256 + data[4]) / 65535.0;
-
float dTemp = 243.04 * (log(humidity / 100) + ((17.625 * cTemp)/(243.04 + cTemp)))/(17.625 - log(humidity / 100) - ((17.625 * cTemp)/(243.04 + cTemp))); -
float dfTemp = dTemp * 9 / 5 + 32; // Output data to screen printf("Relative Humidity : %.2f RH \n", humidity); -
printf("Dewpoint in Celsius : %.2f C \n", dTemp); printf("Temperature in Celsius : %.2f C \n", cTemp); -
printf("Dewpoint in Fahrenheit : %.2f F \n", dfTemp); printf("Temperature in Fahrenheit : %.2f F \n", fTemp); }
}
=== ===
(holy cow did github mangle that)