Photon and si7021

I have a Photon with a si7021 using the ported Adafruit_Si7021 libraries the project also has the DIY Mall 0.96 I2C display. The si7021 displays on the display correctly. My questions are as follows.

si7021 Code:

#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();
int Tempature = 0;
int TempF = 0;

void setup()   {
sensor.begin();
}

void loop() {

// Tempature measurement
  Tempature = (sensor.readTemperature();
  TempF = (( Tempature*9.0)/5.0+32.0);

//Display Temp and Hum on OLED
  display.print("Hum: "); display.println(sensor.readHumidity(), 2);
  display.setCursor(0,40);
  display.print("Tmp: "); display.println(sensor.readTemperature(), 2);

Particle.publish("Tempature", String(Tempature) + " °C", 60, PRIVATE);

}
  1. When I create the Photon.publish is shows a reading of 2 °C?

  2. Why can I not convert it to °F?

  1. What’s the question? Is 2 degrees C incorrect?
  2. You did convert it to F with, TempF = (( Tempature*9.0)/5.0+32.0); So, what’s the problem?
2 Likes
  1. Yes 2 was incorrect.
  2. When I used the TempF it didn’t work.

I found a different library to use instead of using the Adafruit_Si7021 I used Particle_Si7021. The conversion is in the .cpp.

New Code:

#include "Particle_Si7021.h"
SI7021 sensor;


void setup()   {
sensor.begin();
}

void loop() {

// temperature is an integer in hundredths
  int temperature = sensor.getFahrenheitHundredths();
  temperature = temperature / 100;

// humidity is an integer representing percent
  int humidity = sensor.getHumidityPercent();

//Display Temp and Hum on OLED
  display.print("Hum: "); display.println(humidity);
  display.print("Tmp: "); display.println(temperature);

  Particle.publish("Tempature", String(temperature) + " °F", 60, PRIVATE);

}
  1. So why the question mark on statement 1?
  2. What didn't work? Did you get no value or a wrong value?

yes they all seem to be the wrong values.

In the si7021 library, the return types for temperature and humidity are float, not int. Please try again with your variables declared and float type and see if that helps.

2 Likes

Change of project…

I am fixing to implement the Nextion 2.4 Enhanced display. I have the first few screens built and I am wanting to test.

If I change the names of the objects in the .hmi I use then new name correct?