Arduino + Processing + Sensirion SHT7# (Humidity/Temp sensor)
in
Integration and Hardware
•
1 year ago
Hi everybody,
I'm a newbie on Processing and Arduino. I would like to interface Arduino +SHT75 with Processing to get humidity and temperature data and show it on a GUI. I'm able to easily control the SHT75 sensor with the Arduino IDE and receive data using the Serial Monitor, after the sensor's library have been installed (
link).
Here is the Arduino 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");
- }
Thank you very very much!
1