Help Publishing data Particle Cloud

Hi All,

I am new to the particle system and C/C++ I come from a background in Fortran, VBA, and Python and figured I can pick up most of what I need from looking at working code and examples and modifying what I need. I am using the SparkFun HTU21D to read humidity and temperature. Tested the code on an Arduino board and the code works. I figured ok I get this. read up on publishing data to the cloud and the code lines needed. Well when I modified the code to reflect the what I thought was correct I do not get the same results as with the Arduino. instead I get 988.000. I did a second test were I just publish a integer “23” and that worked. Can someone help please. Below is the code that I modified in the sparkfun-htu21d-f.ino file

 HTU21D Humidity Sensor Example Code
 By: Nathan Seidle
 SparkFun Electronics
 Date: September 15th, 2013
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
 Uses the HTU21D library to display the current humidity and temperature
 Open serial monitor at 9600 baud to see readings. Errors 998 if not sensor is detected. Error 999 if CRC is bad.
 Hardware Connections (Breakoutboard to Arduino):
 -VCC = 3.3V
 -SDA = A4 (use inline 330 ohm resistor if your board is 5V)
 -SCL = A5 (use inline 330 ohm resistor if your board is 5V)


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

//Create an instance of the object
HTU21D myHumidity;

void setup()
  Serial.println("HTU21D Example!");


void loop()
  float humd = myHumidity.readHumidity();
  float temp = myHumidity.readTemperature();
  //float temp1 = 5/9*(myHumidity.readTemperature()-32);
//  Particle.publish(" time: ",millis, PUBLIC);
//  Serial.print("Time:");
//  Serial.print(millis());
  Particle.publish(" Temperature:", (temp, 1), PUBLIC);
//  Serial.print(" Temperature:");
//  Serial.print(temp, 1);
//  Serial.print("F");
 Particle.publish("humidity", String(humd), PRIVATE);
//  Serial.print(" Humidity:");
//  Serial.print(humd, 1);
//  Serial.print("%");


You’re sure this is 988 and not 998? Just asking because 998 is error value for ERROR_I2C_TIMEOUT, which might indicate a potential wiring issue. I notice you’re also not checking the return value of myHumidity.begin(), so if the board couldn’t talk to the sensor at all you wouldn’t know.

1 Like

Hi you are right it is 998. I had the sensor plugged into the xenon the same as the arduino board in the example on sparkfun. then I looked on the community and read that for I2C I needed to have the sensor SDA to D1 and the SCL to D0. I did this and still am getting the 998 error.

I’d suggest first checking the return on the begin(). You can call it multiple times, so it could start your loop() for now:

void loop() {
  if (!myHumidity.begin()) {
    Particle.publish("no-sensor", PRIVATE);
  // check temperature

If you look in small writing on the top of the board you should see SDA and SCL listed. It’s the opposite to how you listed them SDA = D0 and SCL = D1. Does it work if you switch them around?


Thank you it turns out you were right is was the connection of the pins. Now it is working smoothly transmitting data! I really appreciate your help.

1 Like

Awesome! Glad to hear it. Thank you for posting the follow up.