Coder Social home page Coder Social logo

sensirion / arduino-sht Goto Github PK

View Code? Open in Web Editor NEW

This project forked from winkj/arduino-sht

66.0 9.0 43.0 48 KB

Repository for Sensirion humidity and temperature sensor support on Arduino

License: BSD 3-Clause "New" or "Revised" License

C++ 99.65% C 0.35%
arduino temperature-sensor humidity-sensor sensor relative-humidity-sensors sensirion arduino-library i2c driver

arduino-sht's Introduction

arduino-sht

Repository for Sensirion humidity and temperature sensor support on Arduino

Supported sensors:

  • SHTC1
  • SHTC3
  • SHTW1
  • SHTW2
  • SHT2x (SHT20, SHT21, SHT25)
  • SHT3x-DIS (I2C)
  • SHT3x-ARP (ratiometric analog voltage output)
  • SHT85
  • SHT4x

For sht3x and sht4x there are specific drivers available in separate repositories.

Installation

The recommended way to install arduino-sht is through the Library Manager of the Arduino IDE. To access it, go to the Tools menu and select Manage Libraries..., and search for the library name there.

If you prefer to install it manually, you can download either via git or from the releases page and place it in your Arduino/libraries directory. After restarting the Arduino IDE, you will see the new SHTSensor menu items under libraries and examples.

Integrating it into your sketch

Assuming you installed the library as described above, the following steps are necessary:

  1. Import the Wire library like this: From the menu bar, select Sketch > Import Library > Wire
  2. Import the arduino-sht library: From the menu bar, select Sketch > Import Library > arduino-sht
  3. Create an instance of the SHTSensor class (SHTSensor sht;)
  4. In setup(), make sure to init the Wire library with Wire.begin()
  5. Also in setup(), call sht.init()
  6. If you want to use the serial console, remember to initialize the Serial library with Serial.begin(9600)
  7. Call sht.readSample() in the loop() function, which reads a temperature and humidity sample from the sensor
  8. Use sht.getHumidity() and sht.getTemperature() to get the values from the last sample

Important: getHumidity() and getTemperature() do not read a new sample from the sensor, but return the values read last. To read a new sample, make sure to call readSample()

Using an custom or alternative I2C port/Wire instance

Some Arduino boards have multiple predefined I2C ports; generally, the second port will be called Wire1.

The arduino-sht library allows to use an alternative interface; to do so, pass the port you want to use as an argument to sht.init(), like this:

  if (sht.init(Wire1)) {
      Serial.print("init(): success\n");
  } else {
      Serial.print("init(): failed\n");
  }

Example projects

See example project sht-autodetect

Usage with multiple SHT31 sensors

See example project multiple-sht-sensors

arduino-sht's People

Contributors

abrauchli avatar dhasenfratz avatar hmueller01 avatar jhahn96 avatar koepel avatar leoniefierz avatar mvdw avatar ndml28 avatar ohnics avatar per1234 avatar psachs avatar thunderstr1k3 avatar winkj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-sht's Issues

connect sensor to 2nd I2C bus

Hi, thanks a lot for this excellent library. I have a project where I want to connect two SHT30-sensors to an ESP32 and wonder whether it's possible to connect an SHT30 to the 2nd I2C bus of the ESP32. Did not find out whether it's possible to pass the bus as an argument to init() or to the constructur... Thanks for any hint!

Turn off the heater on the SHT40

I use SHT40 and if I measure I get 30°C. If I use the Adafruit_SHT4x.h library, I measure 23°C. I think the heater is on because if I use SHT4X_LOW_HEATER_100MS on the Adafruint I get 30°C. If I turn it off sht4.setHeater(SHT4X_NO_HEATER); I get back 23°C.

All examples generate a compile error

I'm running Arduino on Windows 10 and I get a compile error on all three of the example programs.
Here is the error message:
**Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x7855fb]

goroutine 1 [running]:
github.com/arduino/arduino-cli/legacy/builder.ResolveLibrary(0x118de5a0, 0x118c8bbd, 0xb, 0x118c8bbd)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/resolve_library.go:64 +0x14b
github.com/arduino/arduino-cli/legacy/builder.findIncludesUntilDone(0x118de5a0, 0x118f5d80, 0x88ed00, 0x11888090, 0x11a1d328, 0x11804d00, 0x0)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_find_includes.go:358 +0x3b6
github.com/arduino/arduino-cli/legacy/builder.(*ContainerFindIncludes).Run(0xdebc68, 0x118de5a0, 0xdebc68, 0x0)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_find_includes.go:152 +0x3e5
github.com/arduino/arduino-cli/legacy/builder.runCommands(0x118de5a0, 0x11873e1c, 0x20, 0x20, 0x409a01, 0xffffff, 0x0)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:210 +0xbd
github.com/arduino/arduino-cli/legacy/builder.(*Builder).Run(0x11873f40, 0x118de5a0, 0xdebbb4, 0x11806bb0)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:117 +0xb9c
github.com/arduino/arduino-cli/legacy/builder.RunBuilder(...)
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:226
main.main()
/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-builder/main.go:398 +0x6d2
C:\Program Files (x86)\Arduino\arduino-builder returned 2
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
**

SHT40 Raspberry Pi Pico Arduino Earle Phillhower

Hello, I have a problem with your library in arduino with Earle Phillpower library. I use your SHTSensor library, i think correctly but still not getting responses from SHT40. Can you please help me? (it is correctly wired - power 3,3V, pull up for SDA,SCL - 2,2kOhm resistors)

the SHT40 is connected to
GP14 --> PIN 19 on the Pico
GP15 --> PIN 20 on the Pico
`
#include <Wire.h>
#include "SHTSensor.h"

SHTSensor sht(SHTSensor::SHT4X);

float actualTemperature = 99.9;
float actualHumidity = 99.9;

void setup() {
pinMode(14,INPUT);
pinMode(15,INPUT);
Wire1.setSDA(14);
Wire1.setSCL(15);

Wire1.begin(0x44);

Serial.begin(9600);
while (!Serial)
delay(10);

if (sht.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM);
}

void loop() {
if (sht.readSample()) {
actualHumidity = sht.getHumidity();
Serial.print(actualHumidity, 2);
Serial.print("\n");
Serial.print(" T: ");
actualTemperature = sht.getTemperature();
Serial.print(actualTemperature, 2);
Serial.print("\n");
Serial.print("Reading SHT40 Data...OK\n");
} else {
Serial.print("Error in readSample()\n"); // this is being displayed in serial monitor - so sht.readSample() doesnt read anything
}
delay(1000);
}
`

[Problem]: sht31D not updated regularly when used on Arduino nano

Hello,

I used the example code on my Arduino Nano an call the getTermperature() + getHumidity() ervery 2 s.
But the Sensor values are never updated.
The Sensor was found on the Bus but, the values are not updated every period.

Is there an known Issue with the latest release?

[remove Compiler Warning]: caused by unused Variable in SHTSensor.h

Hi,

I have a proposal to remove a silly Compiler warning in line 160 of SHTSensor.h:

see here:

          virtual bool setAccuracy(SHTSensor::SHTAccuracy newAccuracy) {
                 return false;
          }

causes a silly compiler warning which can be prevented like:

          virtual bool setAccuracy(SHTSensor::SHTAccuracy newAccuracy) {
                (void) newAccuracy;
                return false;
          }

Unstable readings on the SHT85 sensor

I can't get stable readings on the SHT85 sensor.
I use the example code "sht-autodetect" and this is what is printed by the serial monitor:

Captura

And sometimes it doesn't even give me readings, it just gives me "Error in readSample()".
What could be going on?

SHT85 library for Particle Argon

I am trying to work the SHT-85 library that was developed for Arduino in Particle Argon. However, the function .readSample() does not work after I tried many ways to fix it. I was wondering, would it be possible that the Sensirion’s technical support could fix the library for Particle? SPS30 does have an uploaded library in Particle and it helps tons of beginners.

Thank you!

Bootloop

Hi,

I have followed the code as posted by borlowsky

Using a nodemcu-32s and uploaded the sketch below.

After upload I am receiving a bootloop.

rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0

Not sure where I went wrong on the code.

#include <Wire.h>
#include "SHTSensor.h"

#define I2C1_SDA 16 // I2C1 data pins
#define I2C1_SCL 17 // I2C1 data pins
#define I2C2_SDA 18 // I2C2 data pins
#define I2C2_SCL 19 // I2C2 data pins

SHTSensor sht1(SHTSensor::SHT3X);
SHTSensor sht2(SHTSensor::SHT3X);

TwoWire I2C1 = TwoWire(0);
TwoWire I2C2 = TwoWire(1);

void setup() {
// put your setup code here, to run once:

I2C1.begin(I2C1_SDA, I2C1_SCL, 10000);
I2C2.begin(I2C2_SDA, I2C2_SCL, 10000);

Wire.begin();
Serial.begin(9600);
delay(1000); // let serial console settle

// init on a specific sensor type (i.e. without auto detecting),
// does not check if the sensor is responding and will thus always succeed.

// initialize sensor on 1st bus
sht1.init(I2C1);

// initialize sensor on 2nd bus
sht2.init(I2C2);
}

void loop() {
// put your main code here, to run repeatedly:
// read from first sensor
if (sht1.readSample()) {
Serial.print("SHT1 :\n");
Serial.print(" RH: ");
Serial.print(sht1.getHumidity(), 2);
Serial.print("\n");
Serial.print(" T: ");
Serial.print(sht1.getTemperature(), 2);
Serial.print("\n");
} else {
Serial.print("Sensor 1: Error in readSample()\n");
}

// read from second sensor
if (sht2.readSample()) {
Serial.print("SHT2:\n");
Serial.print(" RH: ");
Serial.print(sht2.getHumidity(), 2);
Serial.print("\n");
Serial.print(" T: ");
Serial.print(sht2.getTemperature(), 2);
Serial.print("\n");
} else {
Serial.print("Sensor 2: Error in readSample()\n");
}

delay(1000);
}

First Reading "High" with autodetect example using SHT4x

Hi!

I just wanted to note an issue when using the example sht-autodetect with the SHT40. I'm not sure what the cause of the issue is, but when I use the SHT40 the first reading is not a proper value and gradually cools down while reading. It looks like the heater goes on for a short period or something like that. This issue doesn't happen when using the SHT3x series.
This is easily fixed by just using this line instead:

SHTSensor sht(SHTSensor::SHT4X);

Here is an example of what the issue looks like in the Serial:

15:46:14.342 -> init(): success
15:46:14.389 -> SHT:
15:46:14.389 ->   RH: 70.45
15:46:14.389 ->   T:  29.50
15:46:15.360 -> SHT:
15:46:15.360 ->   RH: 67.22
15:46:15.405 ->   T:  22.48
15:46:16.376 -> SHT:
15:46:16.376 ->   RH: 66.68
15:46:16.421 ->   T:  22.06
15:46:17.392 -> SHT:
15:46:17.392 ->   RH: 67.05
15:46:17.438 ->   T:  21.95
15:46:18.410 -> SHT:
15:46:18.410 ->   RH: 67.57
15:46:18.410 ->   T:  21.93
15:46:19.431 -> SHT:
15:46:19.431 ->   RH: 67.94
15:46:19.431 ->   T:  21.87
15:46:20.479 -> SHT:
15:46:20.479 ->   RH: 68.36
15:46:20.479 ->   T:  21.85
15:46:21.487 -> SHT:
15:46:21.487 ->   RH: 68.65
15:46:21.487 ->   T:  21.83
15:46:22.472 -> SHT:
15:46:22.472 ->   RH: 68.90
15:46:22.519 ->   T:  21.81
15:46:23.501 -> SHT:
15:46:23.501 ->   RH: 69.06
15:46:23.501 ->   T:  21.77

Any Ideas on how to possibly fix that?

Just a note: I'm using an Atmega328P on breadboard with Arduino IDE 1.8.19

Add type for SHTC3

The SHTC3 is already supported through autodetection or by manually choosing the SHTC1 driver, but we should add an explicit type for it (and document is as well)

No response from SHT85

I have not been able to successfully connect to the SHT85 via I2C

SHT85 is wired up correctly with 3v3 VCC and 10k pull up resistors on sda and scl.

When I run the auto detect example I get the following response:

init(): failed
Error in readSample()

I have also tried using the I2C_Scanner example to see if it was an address error but it finds nothing on the I2C bus.

The example works fine for the SHT31 but not SHT85.

Does the SHT85 have some strange requirements that make it incompatible with the standard Arduino wire library?

Can't able to download Sensirion library in arduino

Hello Everyone. I found an issue in downloading the Sensirion library in Arduino. When I compile the program Sensirion.h: No such file or directory comes. please help me. I am using this code:

#include <Sensirion.h>

const uint8_t dataPin = 9; // SHT serial data
const uint8_t sclkPin = 8; // SHT serial clock
const uint8_t ledPin = 13; // Arduino built-in LED
const uint32_t TRHSTEP = 5000UL; // Sensor query period
const uint32_t BLINKSTEP = 250UL; // LED blink period

Sensirion sht = Sensirion(dataPin, sclkPin);

uint16_t rawData;
float temperature;
float humidity;
float dewpoint;

byte ledState = 0;
byte measActive = false;
byte measType = TEMP;

unsigned long trhMillis = 0; // Time interval tracking
unsigned long blinkMillis = 0;

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
delay(15); // Wait >= 11 ms before first cmd
// Demonstrate blocking calls
sht.measTemp(&rawData); // sht.meas(TEMP, &rawData, BLOCK)
temperature = sht.calcTemp(rawData);
sht.measHumi(&rawData); // sht.meas(HUMI, &rawData, BLOCK)
humidity = sht.calcHumi(rawData, temperature);
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
}

void loop() {
unsigned long curMillis = millis(); // Get current time

// Rapidly blink LED.  Blocking calls take too long to allow this.
if (curMillis - blinkMillis >= BLINKSTEP) {  // Time to toggle the LED state?
    ledState ^= 1;
    digitalWrite(ledPin, ledState);
    blinkMillis = curMillis;
}

// Demonstrate non-blocking calls
if (curMillis - trhMillis >= TRHSTEP) {      // Time for new measurements?
    measActive = true;
    measType = TEMP;
    sht.meas(TEMP, &rawData, NONBLOCK);      // Start temp measurement
    trhMillis = curMillis;
}
if (measActive && sht.measRdy()) {           // Note: no error checking
    if (measType == TEMP) {                  // Process temp or humi?
        measType = HUMI;
        temperature = sht.calcTemp(rawData); // Convert raw sensor data
        sht.meas(HUMI, &rawData, NONBLOCK);  // Start humidity measurement
    }
    else {
        measActive = false;
        humidity = sht.calcHumi(rawData, temperature); // Convert raw sensor data
        dewpoint = sht.calcDewpoint(humidity, temperature);
        logData();
    }
}

}

void logData() {
Serial.print("Temperature = ");
Serial.print(temperature);

Serial.print(" C, Humidity = ");
Serial.print(humidity);

Serial.print(" %, Dewpoint = ");
Serial.print(dewpoint);
Serial.println(" C");

}

Error compiling in SparkFun ESP32

I have downloaded the library via .zip and imported it into Arduino IDE as I did with a few and those ones worked correctly.

When I import this library into the sketch and i try to run the code I always get the same error and I'm not able to fix it.

Here is the error i'm getting:

Arduino:1.8.10 (Mac OS X), Tarjeta:"ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1440824]

goroutine 1 [running]:
github.com/arduino/arduino-cli/legacy/builder.ResolveLibrary(0xc000118800, 0xc00020816b, 0xb, 0xc00020816b)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/resolve_library.go:64 +0x1d4
github.com/arduino/arduino-cli/legacy/builder.findIncludesUntilDone(0xc000118800, 0xc0004dac60, 0x1578ca0, 0xc000180cd0, 0xc00048eb70, 0xc0002a5500, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_find_includes.go:358 +0x3db
github.com/arduino/arduino-cli/legacy/builder.(*ContainerFindIncludes).Run(0x1bacff0, 0xc000118800, 0x1bacff0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/container_find_includes.go:152 +0x4e6
github.com/arduino/arduino-cli/legacy/builder.runCommands(0xc000118800, 0xc0006cbc20, 0x20, 0x20, 0x1, 0x5d6a0, 0x1bae720)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:210 +0xdf
github.com/arduino/arduino-cli/legacy/builder.(*Builder).Run(0xc0000a3e70, 0xc000118800, 0x1bacef0, 0xc0000937e0)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:117 +0xd28
github.com/arduino/arduino-cli/legacy/builder.RunBuilder(...)
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-cli/legacy/builder/builder.go:226
main.main()
	/home/jenkins/workspace/arduino-builder-all-cross-cli-inception/src/github.com/arduino/arduino-builder/main.go:398 +0x800
/private/var/folders/hb/gnqzxwy578d8j85vcl588lym0000gn/T/AppTranslocation/45A947C1-A4C3-4560-A826-6C5A53E6653F/d/Arduino.app/Contents/Java/arduino-builder retornó 2
Error compilando para la tarjeta ESP32 Dev Module.

Sorry for showing the error in Spanish but is how I firstly configured the IDE.

I tried reinstalling the library and other stuff but couldn't made it work.

I2C communication without clock stretching

Hi,

I have used this library with a Sensirion sensor without success. There is a initialization issue with the sensor.

Since the clock stretching has been disabled a delay has been added between the sensor measurement request and the measurement readout.
The current implemantation ignores this delay and send a I2C restart between the measurement request and the readout.

I propose to replace this:

if (Wire.endTransmission(false) != 0) {

by:

if (Wire.endTransmission() != 0) {

Thank you and best regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.