Home Intel Galileo Connect a Si7021 I2C Sensor to an Intel Galileo

Connect a Si7021 I2C Sensor to an Intel Galileo

by shedboy71

In this example we connect a Si7021 I2C Humidity and Temperature Sensor to an Intel Galileo

The Si7021 I2C Humidity and Temperature Sensor is a monolithic CMOS IC integrating humidity and temperature sensor elements, an analog-to-digital converter, signal processing, calibration data, and an I2C Interface. The patented
use of industry-standard, low-K polymeric dielectrics for sensing humidity enables the construction of low-power, monolithic CMOS Sensor ICs with low drift and hysteresis, and excellent long term stability.

The humidity and temperature sensors are factory-calibrated and the calibration data is stored in the on-chip non-volatile memory. This ensures that the sensors are fully interchangeable, with no recalibration or software changes required. The Si7021 is available in a 3×3 mm DFN package and is reflow solderable. It can be used as a hardware- and software-compatible drop-in upgrade for existing RH/ temperature sensors in 3×3 mm DFN-6 packages, featuring precision sensing over a wider range and lower power consumption. The optional factory-installed cover offers a low profile, convenient means of protecting the sensor during assembly (e.g., reflow soldering) and throughout the life of the product, excluding liquids (hydrophobic/oleophobic) and particulates.

The Si7021 offers an accurate, low-power, factory-calibrated digital solution ideal for measuring humidity, dew-point, and temperature, in applications ranging from HVAC/R and asset tracking to industrial and consumer platforms.

Precision Relative Humidity Sensor – ± 3% RH (max), 0–80% RH
High Accuracy Temperature Sensor – ±0.4 °C (max), –10 to 85 °C
0 to 100% RH operating range
Up to –40 to +125 °C operating range
Wide operating voltage (1.9 to 3.6 V)
Low Power Consumption – 150 µA active current, 60 nA standby current

Parts List

Label Part Type
Part1 Intel Galileo Gen2
Part4 Adafruit Si7021 Temp Humidity

 

Layout

 

Code

This is from https://github.com/ControlEverythingCommunity/SI7021/blob/master/Arduino/SI7021.ino , I did not want to use other libraries this time

[codesyntax lang=”cpp”]

#include <Wire.h>

// SI7021 I2C address is 0x40(64)
#define Addr 0x40

void setup()
{
  // Initialise I2C communication as MASTER
  Wire.begin();
  // Initialise serial communication, set baud rate = 9600
  Serial.begin(9600);

  // Start I2C transmission
  Wire.beginTransmission(Addr);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(300);
}

void loop()
{
  unsigned int data[2];
  
  // Start I2C transmission
  Wire.beginTransmission(Addr);
  // Send humidity measurement command, NO HOLD MASTER
  Wire.write(0xF5);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(500);
    
  // Request 2 bytes of data
  Wire.requestFrom(Addr, 2);

  // Read 2 bytes of data
  // humidity msb, humidity lsb 
  if(Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
  }
    
  // Convert the data
  float humidity  = ((data[0] * 256.0) + data[1]);
  humidity = ((125 * humidity) / 65536.0) - 6;

  // Start I2C transmission
  Wire.beginTransmission(Addr);
  // Send temperature measurement command, NO HOLD MASTER
  Wire.write(0xF3);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(500);
    
  // Request 2 bytes of data
  Wire.requestFrom(Addr, 2);
  
  // Read 2 bytes of data
  // temp msb, temp lsb
  if(Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
  }

  // Convert the data
  float temp  = ((data[0] * 256.0) + data[1]);
  float cTemp = ((175.72 * temp) / 65536.0) - 46.85;
  float fTemp = cTemp * 1.8 + 32;
   
  // Output data to serial monitor
  Serial.print("Relative humidity : ");
  Serial.print(humidity);
  Serial.println(" % RH");
  Serial.print("Temperature in Celsius : ");
  Serial.print(cTemp);
  Serial.println(" C");
  Serial.print("Temperature in Fahrenheit : ");
  Serial.print(fTemp);
  Serial.println(" F");
  delay(500);
}

[/codesyntax]

Testing

Open up a serial monitor and you should see something like this

Temperature in Celsius : 26.45 C
Temperature in Fahrenheit : 79.60 F
Relative humidity : 40.44 % RH
Temperature in Celsius : 29.43 C
Temperature in Fahrenheit : 84.97 F
Relative humidity : 40.63 % RH
Temperature in Celsius : 30.78 C
Temperature in Fahrenheit : 87.40 F
Relative humidity : 40.73 % RH
Temperature in Celsius : 31.54 C
Temperature in Fahrenheit : 88.77 F
Relative humidity : 40.79 % RH

 

Links

Si7021 Humidity Sensor with I2C Interface for Arduino

You may also like