Arduino connected to RPi3, temp/humidity sensor HTU21D-F

IT WORKED!!! It wasn’t sending because I added an errant serial print in there from last night.

For anyone seeing this in the future or who had any issues, download the HTU21D-F sensor files from Adafruit’s github, test sensor to make sure it’s working, then use the following sketch for reporting temperature on virtual pin 4 (converted to degrees F here, just remove the math for C) and humidity on virtual pin 5. Big thanks to @Neoxelox and @adam for helping out here!!!

#include "CayenneSerial.h"
#include <Wire.h>
#include "Adafruit_HTU21DF.h"

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "ENTER_TOKEN_HERE";


Adafruit_HTU21DF htu = Adafruit_HTU21DF();

void setup()
{
  // Serial.begin(9600);
  Cayenne.begin(token);
  htu.begin();
}

void loop()
{
  Cayenne.run();
  delay(100);
}


CAYENNE_OUT(V4){
Cayenne.virtualWrite(V4, (htu.readTemperature() * 1.8 + 32));
}

CAYENNE_OUT(V5){
Cayenne.virtualWrite(V5, htu.readHumidity());
}
2 Likes