XN04 - Temp-Hum / Lum

XN04 - Temperature - Humidity - Ambient Light

X-NODE Temp-Hum / Lum is a module that allows measurement of 3 environmental variables: Temperature, Humidity and Ambient Light. Ideal for IoT projects requiring control and monitoring of closed systems, such as air conditioning, refrigeration chambers, or automatic lighting adjustments. This module simplifies designs by reducing the need for multiple devices, offering a compact and efficient solution for monitoring applications.

TABLE OF CONTENTS

I. How does it work?

The X-NODE Temp-Hum / Lum is a module that combines 2 sensors: a SHT40 from Sensirion® for measuring ambient temperature/humidity and an LTR-329ALS from LITEON® for measuring indoor brightness. It also comes with an integrated controller, that allows you to obtain these variables using a series of ASCII commands.

X-NODE Temp-Hum / Lum is compatible with the mikroBUS™ standard from Mikroe® for easy use with a large ecosystem of hardware development kits, and also features JST connectors compatible with the Qwiic® standard from SparkFun® for quick and easy I2C communication between various modules and development boards.

II. Hardware description

  1. SHT40 sensor from Sensirion®

  2. JST connectors compatible with Qwiic®

  3. LTR-329ALS sensor from LITEON®

  4. Hardware controller

  5. UART <> I2C communication ports

  6. X-NODE model

  7. X-NODE type

  8. mikroBUS™ standard connectors

  9. Jumper pad to enable native I2C communication* with the sensors.

  10. Hardware version: R2

  11. Main components on the X-NODE

Note: The X-NODE Temp-Hum / Lum includes a hardware controller to simplify implementation, however, if you wish to use the sensors' native I2C protocol, you must send the command to turn off the hardware controller (see usage) and solder the I2C-EN pads (9).

III. Specifications

Type

Temperature, humidity, and ambient light sensor

Applications

Development of IoT systems requiring monitoring within closed systems, such as air conditioning, refrigeration chambers, or automatic lighting adjustments.

Module 1

Manufacturer

Module 2

Manufacturer

Features

* Temperature and humidity sensor with detection from 0 °C to 85 °C with typical accuracy of +/- 0.2 °C and +/- 1.8% RH, automatic calibration, 0.5 mA consumption, and high signal-to-noise ratio. * Ambient light sensor with detection from 0.01 to 64 klx, 50 Hz/60 Hz noise suppression, and typical consumption of 90µA.

Interface

UART, I2C

Compatibility

mikroBUS™ standard and Qwiic® standard

Size

41 x 25.4 x 20.5 mm

Voltage

3.3 V

For complete technical information, you can download each manufacturer's specifications at the following links: SHT40 - LTR-329ALS

IV. Pinout

The following table shows the pinout of the X-NODE Temp-Hum / Lum with respect to the mikroBUS™ standard (the latter is in the two center columns).

V. Usage

For easy and quick use of the X-NODE, you can use the ASCII command set provided by the integrated hardware controller via UART serial communication, or more advanced use via the I2C protocol.

UART Protocol

Configuration

UART communication uses the following configuration:

  • Baud rate: 115,200 bps

  • Parity: None

  • Data bits: 8

  • Stop bits: 1

Syntax

The UART protocol allows sending instructions in plain ASCII text. Each instruction consists of the X-NODE identifier, a command, and an end-of-line.

Identifier

The ID identifier is made up of the X-NODE model, which can be found at point 6 in the Hardware description section, and is complemented by an index, which can be a letter from A to Z, by default is A. To connect more than one module of the same model in a system, you must configure a unique identifier for each module, allowing up to 26 modules of the same model to be connected via UART protocol*.

Command list

XN04A?

Checks if communication was established successfully. Response if successful: OK Response if error: XN04A=Error Example: XN04A=3 Error codes: 1: Temperature/humidity sensor error 2: Light sensor error 3: Both sensors errored

XN04A+V

Gets the current firmware version integrated in the X-NODE. Response: XN04A=Version Example: XN04A=2.0.0

XN04A+ID=(A-Z)

Changes the ID index to a different uppercase letter from A to Z. Once changed, you must use the new ID to change it again. Response: OK Example: XN04C+ID=H

XN04A+TW=(1-126)

Changes the factory I2C address to a different one, this only takes effect if the hardware driver is not disabled. The new address is written in decimal, selecting a value from 1 to 126. Response: OK Example: XN04A+TW=28

XN04A+GT

Gets the temperature value from the sensor. Returns the final value in °C with two decimals. Response: XN04A=VAL Example: XN04A=27.81

XN04A+GH

Gets the humidity value from the sensor. Returns a relative humidity (%) value. Response: XN04A=VAL Example: XN04A=80

XN04A+GL

Gets the light value from the sensor. Returns an ambient light value in Lux. Response: XN04A=VAL Example: XN04A=198

Advanced commands

XN04A+ETW=(0-1)

Enables (1) or disables (0) the device's I2C interface. Note: This setting is volatile, disconnecting power or sending the reset command will restore the I2C interface. Response: OK Example: XN04A+ETW=0

XN04A+SLP

Enables deep sleep mode to reduce power consumption, during deep sleep, the device will not respond to UART commands. To wake the device, send a logic low (0) to the WAKEUP/UPDI pin. Response: OK Example: XN04A+SLP

XN04A+RST

Resets the device, non-volatile values (e.g., ID, I2C address) are preserved, and volatile values return to default. Response: OK

XN04A+SP

Sets the temperature/humidity sensor precision to high (H)* (default), medium (M), or low (L), lower precision allows faster updates. Response: OK Example: XN04A+SP=L

XN04A+SH

Turns the humidity sensor heater on (1) or off (0). Use this if humidity readings are incorrect, enable the heater for at least 2 hours to repair the sensor. Response: OK Example: XN04A+SH=0

XN04A+SG

Sets the light sensor gain to 1 (1-64k lux, default), 2 (1-32k lux), 4 (1-16k lux), 8 (1-8k lux), 48 (1-1.3k lux), or 96 (1-600 lux), higher gain means lower range but higher precision. Response: OK Example: XN04A+SG=96

XN04A+SD

Turns the hardware controller for the sensors on (1) or off (0). Response: OK Example: XN04A+SD=1

XN04A+SN

Reads the serial number of the temperature and humidity sensor. Response: XN04A= Example: XN04A=4294900000

When reading temperature, humidity, or light, the following error responses may occur:

  • ERROR: Sensor communication error.

  • OL: Light value overflowed the register, set a lower gain if possible.

  • MEASURING: Sensor reading not finished, wait at least 20 ms for initialization.

  • HW_DRIVER_OFF: Hardware controller is not enabled.

End of line

The X-NODE will only respond to a command when a set of end-of-line characters are sent, each command must end with: <CR+LF>

  • CR means carriage return.

  • LF means line feed.

The combination <CR+LF> is a common way for computers to represent a new line, e.g., in a word processor to separate paragraphs.

For the X-NODE, <CR+LF> characters are used to identify the end of a command. If the identifier matches the node, the command exists, and it ends with <CR+LF>, the node will send a response.

Depending on your system, you must configure sending these characters differently.

UART Example Arduino Framework

Example code for XC01 - R5, see the manual to use our XC01 - R5 in Arduino IDE/PlatformIO

#include "Arduino.h"

float getVariable( const char * command ){
  // Clear the buffer
  if (Serial2.available()) {
    Serial2.read();
  }

  // Send the command
  Serial2.print(command);
  Serial2.println();

  // Wait for a response
  String variable_value = Serial2.readStringUntil('\n');

  // If the response starts with the ID, communication was successful
  if (!variable_value.startsWith("XN04A=")) {
    Serial.println("Error");
    return NAN;
  }

  // Convert ASCII value to decimal
  return variable_value.substring(variable_value.indexOf('=') + 1).toFloat();
}

void setup() {
  // Initialize serial monitor
  Serial.begin(115200);

  // Initialize UART communication on MikroBUS port
  Serial2.begin(115200, SERIAL_8N1, 9, 10);
}

void loop() {
  // Get environmental variable values

  // Send command to get temperature
  // \r\n represents <CR+LF> in C/C++
  float temp = getVariable("XN04A+GT\r\n");

  // Send command to get humidity
  float hum = getVariable("XN04A+GH\r\n");

  // Send command to get light
  float lum = getVariable("XN04A+GL\r\n");

  Serial.print("Temp: ");
  Serial.print(temp);
  Serial.println(" °C");
  Serial.print("Hum: ");
  Serial.print(hum);
  Serial.println(" %");
  Serial.print("Lum: ");
  Serial.print(lum);
  Serial.println(" lx");

  delay(1000);
}

I2C Protocol

To establish communication, you must know the I2C address of the X-NODE, the factory value is 0x04. I2C addresses are usually represented in hexadecimal, make sure to use the correct number system.

Configuration

  • Communication speed: 100 kHz - 400 kHz

  • Address: 7 bits

Note: Make sure you do not have another device with the same address on the I2C BUS, if so, remember that the X-NODE can change its I2C address with the XN04A+TW=(1-126) command.

Write

To write to a register of the X-NODE Temp-Hum / Lum, the I2C controller must perform the following operations:

  1. Send a start condition: The controller generates a logic low (0) on SDA while SCL remains high (1).

  2. Send the X-NODE address: The controller sends the 7-bit address.

  3. Send the operation type: The controller indicates if the operation is read (0) or write (1).

  4. Wait for an acknowledge (ACK): The controller waits for a logic low (0) as confirmation (Acknowledgment) that a target with the sent address exists on the I2C BUS. If no response (1), there was a communication error or the address is incorrect.

  5. Write n bytes of data: The controller writes n bytes in 8 bit (1 byte) sequences, MSB first. The target will send an ACK for each byte written.

  6. Send a stop condition: The controller releases the I2C BUS by generating a logic high (1) on SDA while SCL is high (1).

Read

To read from a register of the X-NODE Temp-Hum / Lum, the I2C controller must perform the following operations:

  1. Send a start condition: The controller generates a logic low (0) on SDA while SCL remains high (1).

  2. Send the X-NODE address: The controller sends the 7 bit address.

  3. Send the operation type: The controller indicates if the operation is read (0) or write (1).

  4. Wait for an acknowledge (ACK): The controller waits for a logic low (0) as confirmation (Acknowledgment) that a target with the sent address exists on the I2C BUS. If no response (1), there was a communication error or the address is incorrect.

  5. Read n bytes of data: The target will send n bytes in 8 bit (1 byte) sequences, MSB first, after receiving a byte, the controller must send an ACK to request another byte, or a NACK to indicate the end of transmission and request the target to release the BUS.

  6. Send a stop condition: The controller releases the I2C BUS by generating a logic high (1) on SDA while SCL is high (1).

Register list

In an I2C target, registers are memory addresses that allow configuring or obtaining data from the target. There are two types of operations: read (R) and write (W).

Register
Address (hex)
Type
No. Bytes
Description

TEMP

0x01

R

2

Gets the temperature value in °C*100, divide by 100 to get °C

HUM

0x02

R

2

Gets the relative humidity value * 100, divide by 100 to get percentage (0-100%)

LUM

0x03

R

2

Gets the ambient light (ALS) value in Lux

HEATER

0x04

R/W

1

Turns the humidity sensor heater on (1) or off (0). Use this if humidity readings are incorrect, enable the heater for at least 2 hours to repair the sensor.

PRECISION

0x05

R/W - NV

1

Sets the temperature/humidity sensor precision to high (3)* (default), medium (2), or low (1), lower precision allows faster data updates.

GAIN

0x06

R/W - NV

1

Sets the light sensor gain to 1 (1-64k lux, default), 2 (1-32k lux), 4 (1-16k lux), 8 (1-8k lux), 48 (1-1.3k lux), or 96 (1-600 lux). Higher gain means lower range but higher precision.

SERIAL_NUM

0x07

R

4

Reads the serial number of the temperature and humidity sensor

DRIVER

0x36

R/W - NV

1

Turns the hardware controller for the sensors on (1) or off (0)

STAT

0x37

R

1

XNODE status, 0x00 if no errors, any other value means communication error. Error codes: 1: Temperature/humidity sensor error 2: Light sensor error 3: Both sensors errored

FW

0x38

R

3

Firmware version, in major, minor, and patch: 0x02.0x00.0x00

UART_ID

0x39

R/W - NV

1

Reads and writes the ID index as a letter from A (0x41) to Z (0x5A)

TW_ADD

0x3A

R/W - NV

1

Reads and writes the device's I2C address from 1 (0x01) to 126 (0x7D). Requires a reset or a power-on sequence to be applied

UART_EN

0x3B

W

1

Enables (0x01) or disables (0x00) the device's UART interface

SLEEP

0x3C

W

1

Enables (0x01) or disables (0x00) deep sleep, the device will wake up if the master writes the device's I2C address on the BUS

RESET

0x3D

W

1

Writing 0x01 resets the device

WHO_AM_I

0x3E

R

2

First byte is the XNODE model, second byte is the hardware revision

Non-volatile registers (NV)

Non-volatile registers are stored in the device's EEPROM, meaning they retain their values even if the device is powered off.

TEMP, HUM, LUM register structure:

When reading temperature, humidity, or light, the following reserved values indicate errors:

  • 0xFFFF: Sensor communication error.

  • 0xFFFE: Light value overflowed the register, set a lower gain if possible.

  • 0xFFFD: Sensor reading not finished, wait at least 20 ms for initialization.

  • 0xFFFC: Hardware controller is not enabled.

I2C Example Arduino Framework

Example code for XC01 - R5, see the manual to use our XC01 - R5 in Arduino IDE/PlatformIO

#include <Arduino.h>
#include <Wire.h>

void setup() {
  // Initialize serial monitor
  Serial.begin(115200);

  // Set I2C communication pins
  Wire.setPins( 12, 13 );
  // Initialize I2C communication
  Wire.begin();
}

void loop() {
  // Get environmental variable values
  float temperature;
  float humidity;
  int lum;

  Wire.beginTransmission(0x04);
  Wire.write(0x01);
  if ( Wire.endTransmission() != 0) {
    delay(1000);
    return;
  }

  if (Wire.requestFrom(0x04, 2) != 2) {
    delay(1000);
    return;
  }

  // Divide by 100 to get value in Celsius
  temperature = ( (Wire.read() << 8) | Wire.read() )/100.0f;
  
  Wire.beginTransmission(0x04);
  Wire.write(0x02);
  if ( Wire.endTransmission() != 0) {
    delay(1000);
    return;
  }

  if (Wire.requestFrom(0x04, 2) != 2) {
    delay(1000);
    return;
  }

  // Divide by 100 to get value in percent relative humidity
  humidity = ( (Wire.read() << 8) | Wire.read() )/100.0f;

  Wire.beginTransmission(0x04);
  Wire.write(0x03);
  if ( Wire.endTransmission() != 0) {
    delay(1000);
    return;
  }

  if (Wire.requestFrom(0x04, 2) != 2) {
    delay(1000);
    return;
  }

  lum = ((Wire.read() << 8) | Wire.read());

  Serial.print("Temperature:");
  Serial.print(temperature);
  Serial.println(" C");
  Serial.print("Humidity:");
  Serial.print(humidity);
  Serial.println(" %");

  Serial.print("Light: ");
  Serial.print(lum);
  Serial.println(" lx");

  delay(1000);
}

VI. Downloads

Last updated