QWIIC Test
QwiicTest.ino
tests the I2C-based Stemma QT / QWIIC connector.
I chose to connect an SHT41 temperature & humidity sensor (5776) from Adafruit, as it’s an inexpensive QWIIC-compatible board that is easy to interface. You can connect any other I2C-based hardware to the connector, including the growing number of Stemma QT and QWIIC-based boards from Adafruit, Sparkfun, and other companies.
However, this test sketch is based on the Adafruit SHT41 example sketch and will not work with other sensors.
Install the Adafruit_SHT4X
Arduino Library and its dependencies through the Arduino IDE.
#define SDA 35#define SCL 36
#include "Adafruit_SHT4x.h"
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
void setup() { Serial.begin(115200); while(!Serial) delay(100);
Wire.begin(SDA, SCL);
// =======================
Serial.println("Adafruit SHT4x test"); if (! sht4.begin()) { Serial.println("Couldn't find SHT4x"); while (1) delay(1); } Serial.println("Found SHT4x sensor"); Serial.print("Serial number 0x"); Serial.println(sht4.readSerial(), HEX);
// You can have 3 different precisions, higher precision takes longer sht4.setPrecision(SHT4X_HIGH_PRECISION); switch (sht4.getPrecision()) { case SHT4X_HIGH_PRECISION: Serial.println("High precision"); break; case SHT4X_MED_PRECISION: Serial.println("Med precision"); break; case SHT4X_LOW_PRECISION: Serial.println("Low precision"); break; }
// You can have 6 different heater settings // higher heat and longer times uses more power // and reads will take longer too! sht4.setHeater(SHT4X_NO_HEATER); switch (sht4.getHeater()) { case SHT4X_NO_HEATER: Serial.println("No heater"); break; case SHT4X_HIGH_HEATER_1S: Serial.println("High heat for 1 second"); break; case SHT4X_HIGH_HEATER_100MS: Serial.println("High heat for 0.1 second"); break; case SHT4X_MED_HEATER_1S: Serial.println("Medium heat for 1 second"); break; case SHT4X_MED_HEATER_100MS: Serial.println("Medium heat for 0.1 second"); break; case SHT4X_LOW_HEATER_1S: Serial.println("Low heat for 1 second"); break; case SHT4X_LOW_HEATER_100MS: Serial.println("Low heat for 0.1 second"); break; }
}
void loop() { sensors_event_t humidity, temp;
uint32_t timestamp = millis(); sht4.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data timestamp = millis() - timestamp;
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C"); Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
Serial.print("Read duration (ms): "); Serial.println(timestamp);
delay(1000);}