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

Calculating dewpoint, code patch for .c file included #3

Open
wrwindsor opened this issue Aug 30, 2023 · 0 comments
Open

Calculating dewpoint, code patch for .c file included #3

wrwindsor opened this issue Aug 30, 2023 · 0 comments

Comments

@wrwindsor
Copy link

wrwindsor commented Aug 30, 2023

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)

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

No branches or pull requests

1 participant