Home MSP MSP-EXP432P401R LaunchPad and SHT31 humidity sensor example

MSP-EXP432P401R LaunchPad and SHT31 humidity sensor example

by shedboy71

In this example we show how to connect a SHT31 humidity sensor to a MSP-EXP432P401R LaunchPad, the example will use the Energia IDE.

I used a SHT31 module in this example, which you can see below

The SHT31 humidity sensor series takes sensor technology to a new level. As the successor of the SHT2x series it is determined to set the next industry standard in humidity sensing. The SHT3x humidity sensor series consists of a low-cost version with the SHT30 humidity sensor, a standard version with the SHT31 humidity sensor, and a high-end version with the SHT35 humidity sensor.

The SHT3x humidity sensor series combines multiple functions and various interfaces (I2C, analog voltage output) with a applications-friendly, very wide operating voltage range (2.4 to 5.5 V).

More info – SHT31 website

Connection

Here is a picture of the launchpad so you can see what pins we are referring to below in the table

launchpad pins1

launchpad pins1

Module Connection MSP432 Connection
SDA J1-10 SDA
SCL J1-9 SCL
Gnd J3-22 Gnd
Vcc J1-1 3.3v

Code

[codesyntax lang=”cpp”]

#include <Wire.h>

// SHT31 I2C address is 0x44(68)
#define Addr 0x44

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

void loop()
{
  unsigned int data[6];

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Send 16-bit command byte
  Wire.write(0x2C);
  Wire.write(0x06);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(300);

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Request 6 bytes of data
  Wire.requestFrom(Addr, 6);

  // Read 6 bytes of data
  // temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
  if (Wire.available() == 6)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
    data[2] = Wire.read();
    data[3] = Wire.read();
    data[4] = Wire.read();
    data[5] = Wire.read();
  }
  // Convert the data
  int temp = (data[0] * 256) + data[1];
  float cTemp = -45.0 + (175.0 * temp / 65535.0);
  float fTemp = (cTemp * 1.8) + 32.0;
  float humidity = (100.0 * ((data[3] * 256.0) + data[4])) / 65535.0;

  // Output data to serial monitor
  Serial.print("Temperature in Celsius :");
  Serial.print(cTemp);
  Serial.println(" C");
  Serial.print("Temperature in Fahrenheit :");
  Serial.print(fTemp);
  Serial.println(" F");
  Serial.print("Relative Humidity :");
  Serial.print(humidity);
  Serial.println(" %RH");
  delay(500);
}

[/codesyntax]

 

Output

Open the serial monitor and you should see something like this

Temperature in Celsius :29.97 C
Temperature in Fahrenheit :85.95 F
Relative Humidity :39.29 %RH
Temperature in Celsius :30.55 C
Temperature in Fahrenheit :86.98 F
Relative Humidity :44.32 %RH
Temperature in Celsius :30.93 C
Temperature in Fahrenheit :87.67 F
Relative Humidity :48.15 %RH
Temperature in Celsius :31.32 C
Temperature in Fahrenheit :88.38 F
Relative Humidity :51.27 %RH
Temperature in Celsius :31.48 C
Temperature in Fahrenheit :88.66 F
Relative Humidity :53.68 %RH

Links

1PCS/LOT SHT31 Temperature & SHT31-D Humidity Sensor module Breakout Weather for Arduino

You may also like