Reference

Last revision 2026/01/15

Library

Communication Protocol Description

Through the UART serial communication protocol, you can connect DFR0784 Gravity: Electrochemical Smart Gas Sensor Terminal to any controller with UART for data reading and sensor configuration.

Serial port parameter setting

Baud rate 9600
Data bit 8 bit
Check bit 1 bit

Communication protocol description

① 0x78——Modify terminal communication mode

The terminal has two communication modes, active uploading and question and answer. The factory default is active uploading mode, and data is sent every 1s.

Send

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Null Command Communication mode -- -- -- -- Check value
0xFF 0x01 0x78 Active upload mode: 0x03
Question and answer mode: 0x04
0x00 0x00 0x00 0x00 0x84
0x83

EXP. FF 01 78 04 00 00 00 00 83 (switch to question and answer mode)

Receive

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Command Back to calibration -- -- -- -- -- Check value
0xFF 0x78 Success: 0x01
Failure: 0x00
0x00 0x00 0x00 0x00 0x00 0x87
0x88

EXP. FF 78 01 00 00 00 00 00 87

② 0x85——Set gas type

Send

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Empty Command Gas type -- -- -- -- Check value
0xFF 0x01 0x85 0x00 0x00 0x00 0x00 0x00 0x7C

EXP. FF 01 85 00 00 00 00 00 7C (The gas type is switched to O2)

Receive

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Command Back to calibration Gas type -- -- -- -- Check value
0xFF 0x85 Success: 0x01
Failure: 0x00
0x00 0x00 0x00 0x00 0x00 0x7C
0x7B

EXP. FF 85 01 00 00 00 00 00 7C

Gas Type Table

Gas Type Command Gas Type Command
O2 0x00 NH3 0x06
CO 0x01 H2 0x07
H2S 0x02 HCL 0X08
NO2 0x03 SO2 0X09
O3 0x04 HF 0x0A
CL2 0x05 PH3 0x0B

③ 0x86——Read gas concentration data

In the question and answer mode, you need to send commands to read various parameters of the terminal. The method of reading the gas concentration is as follows.

Send

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Empty Command -- -- -- -- -- Check value
0xFF 0x01 0x86 0x00 0x00 0x00 0x00 0x00 0x7D

EXP. FF 01 86 00 00 00 00 00 7D

Receive

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Command Gas concentration
high bit
Gas concentration
low bit
Gas type -- -- -- Check value
0xFF 0x86 0x00 0x00 0x00 0x00 0x00 0x00 0x7C

EXP. FF 86 00 00 00 00 00 00 7C

Note: Gas concentration value (PPB)=High bit gas concentration×256+Low bit gas concentration. When converting to PPM: PPM=PPB/1000.

④ 0x87——Read terminal temperature data

In the question and answer mode, you need to read various parameters of the terminal by sending commands. The terminal integrates the thermistor, which can obtain the real-time temperature of the terminal. The way to read the terminal temperature is as follows.

Send

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Empty Command -- -- -- -- -- Check value
0xFF 0x01 0x87 0x00 0x00 0x00 0x00 0x00 0x7C

EXP. FF 01 87 00 00 00 00 00 7C

Receive

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Command Temperature data
high bit
Temperature data
low bit
-- -- -- -- Check value
0xFF 0x87 0x00 0x00 0x00 0x00 0x00 0x00 0x7B

EXP. FF 87 00 00 00 00 00 00 7B

Note: After obtaining the temperature value, the method of calculating the actual temperature value is as follows.
Convert temperature data to analog value: Temperature analog value = high bit temperature value × 256 + low bit temperature value
Convert temperature analog value to voltage: Temperature voltage value=temperature analog value×3/1024
Calculate the thermistor resistance by voltage: Thermistor resistance=temperature voltage value×10000/(3-temperature voltage value)
Calculate the temperature value by the resistance value of the thermistor: The actual temperature value=1/(1/273.15+25)+1/3380.13×log(Thermistor resistance/10000))-273.15

⑤ 0x88——Read temperature and gas concentration data in terminal

In the question and answer mode, you need to read various parameters of the terminal by sending commands, and the way to read the temperature and gas concentration data of the terminal is as follows.

Send

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Empty Command -- -- -- -- -- Check value
0xFF 0x01 0x88 0x00 0x00 0x00 0x00 0x00 0x7B

EXP. FF 01 88 00 00 00 00 00 7B

Receive

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Command Gas concentration
high bit
Gas concentration
low bit
Gas type Temperature data
high bit
Temperature data
low bit
-- Check value
0xFF 0x88 0x00 0x00 0x00 0x00 0x00 0x00 0x7A

EXP. FF 88 00 00 00 00 00 00 7A

Note: For the calculation method of gas concentration and temperature, see ③ and ④.

⑥ 0x89——Configure threshold alarm function

The terminal has a threshold alarm function, the alarm threshold and judgment logic can be configured. The configuration method is as follows.

Send

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Null Command Function switch setting Judgment logic settings Alarm concentration threshold
high bit
Alarm concentration threshold
low bit
-- Check value
0xFF 0x01 0x89 On: 0x01
Off: 0x00
Greater than threshold alarm: 0x01
Less than threshold alarm: 0x00
0x00 0x00 0x00 0x7B

EXP. FF 01 88 00 00 00 00 00 7B

Receive

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Command Return configuration result Function switch status Judgment logic state Alarm concentration threshold
low bit
Alarm concentration threshold
low bit
-- Check value
0xFF 0x89 Success: 0x01
Failure: 0x00
On: 0x01
Off: 0x00
Greater than threshold alarm: 0x01
Less than threshold alarm: 0x00
0x00 0x00 0x00 0x7A

EXP. FF 88 00 00 00 00 00 00 7A

⑦ 0x8A——The terminal actively uploads the data format

In the active upload mode, the terminal will upload data every 1s. The data format is as follows.

Receive

Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
Start bit Command Gas concentration value
high bit
Gas concentration value
low bit
Gas type
Temperature value
high bit
Temperature value
low bit
-- Check value
0xFF 0x8A 0x00 0x00 0x00 0x00 0x00 0x00 0x7A

Checksum calculation

Check value = (inverted (byte 1 + byte 2 + ··· ··· + byte 7) + 1

The reference routine is as follows:

/****************************************************************** 
* Function name: unsigned char FucCheckSum(uchar *i,ucharln)
* Function description: Sum check (reverse the sum of 1\2\3\4\5\6\7 of the sending and receiving protocol  + 1)
* Function description: reverse the sum of the array element 1 to the penultimate element and plus 1 (the number of elements must be greater than 2)
******************************************************************/
unsigned char FucCheckSum(unsigned char *i,unsigned char ln)
{ 
	unsigned char j,tempq=0; 
	i+=1; 
	for(j=0;j<(ln-2);j++) 
	{ 
		tempq+=*i; 
		i++; 
	} 
	tempq=(~tempq)+1; 
	return(tempq); 
}

API Description

[DFR0784 Gravity: Electrochemical Smart Gas Sensor Terminal] () There are two data reading modes: active upload and passive response. The factory default is active upload mode, and users can adjust them in the code according to their needs.

Mode selection function changeAcquireMode()

Modify the parameters in brackets of the "changeAcquireMode()" function to adjust the data sending mode.
"INITIATIVE" is the active upload mode. In the active upload mode, the sensor will automatically upload parameters every 1 second;
"PASSIVITY" is the passive response mode. In the passive response mode, the sensor will feedback the parameters only every time the data reading function is called.

gas.changeAcquireMode(gas.INITIATIVE)
/*
      gas.INITIATIVE            // Active upload mode
      gas.PASSIVITY             // Passive response mode
*/

Set the probe type function setGasType()

Set the probe type by the "setGasType()" function.

gas.setGasType(/*Gas type*/gas.O2);

Read the probe type function readGasType()

Through the "readGasType()" function, the probe type data stored in the terminal can be read.

gas.readGasType();

For probe compatible types and corresponding parameters, please refer to the table below.

Gas type CO O2 NH3 H2S NO2 HCL
Detection range (0-1000)ppm (0-25)%VOL (0-100)ppm (0-100)ppm (0-20)ppm (0-10)ppm
Resolution 1ppm 0.1%VOL 1ppm 1ppm 0.1ppm 0.1ppm
V0 voltage output range (0.6-3)V (1.5-0)V (0.6-3)V (0.6-3)V (2-0)V (2-0)V
Response time (T90) ≤30S ≤15S ≤150S ≤30S ≤30S ≤60S
Gas type H2 PH3 SO2 O3 CL2 HF
:-----------------------------: :-------------: :-------------: :-----------: :--------: :-----------: :----------:
Detection range (0-1000)ppm (0-1000)ppm (0-20)ppm (0-20)ppm (0-10)ppm (0-10)ppm
Resolution 1ppm 0.1ppm 0.1ppm 0.1ppm 0.1ppm 0.1ppm
V0 voltage output range (0.6-3)V (0.6-3)V (0.6-3)V (2-0)V (2-0)V (2-0)V
Response time (T90) ≤120S ≤30S ≤30S ≤120S ≤60S ≤60S

Gas concentration reading function readGasConcentration()

The feedback gas concentration value of the gas sensor can be read through the "readGasConcentration()" function.

gas.readGasConcentration(/*Gas type*/gas.O2);

Temperature reading function readTemp()

The onboard temperature sensor data can be read through the "readTemp()" function.

gas.readTemp();

Voltage reading function readVolatageData()

The original voltage output V0 of the gas probe can be read through the "readVolatageData()" function.

gas.readVolatageData();

Configure temperature compensation function setTempCompensation()

You can enable/disable the temperature compensation function through the "setTempCompensation()" function.

gas.setTempCompensation();
/*
  	gas.ON  	Turn on
  	gas.OFF		Turn off
*/

Threshold alarm function setThresholdAlarm()

You can configure the threshold alarm information through the "setThresholdAlarm()" function.

Note:

  • When the communication interface (I2C or UART) is disconnected, if you need to use the threshold alarm function, you should set the sensor mode to INITIATIVE active upload mode, otherwise the threshold alarm function will not be available. For the configuration method, please refer to the description of Mode selection function changeAcquireMode().
gas.setThresholdAlarm(gas.ON,1,200);
/*
	gas.ON  	Turn on
  	gas.OFF		Turn off
  	1			Alarm when greater than the set threshold
  	0			Alarm when less than the set threshold
  	200			Set threshold
*/

I2C address group configuration function changeI2cAddrGroup()

You can configure the I2C address group code and switch between different address groups through the "changeI2cAddrGroup()" function.

In order to prevent address conflicts when using multiple sensors, we have prepared 8 groups with a total of 23 addresses. If necessary, you can use the sample code "change_sensor_iic_addr.ino" to switch by modifying the group serial number configuration of "changeI2cAddrGroup()". After the serial port information displays "IIC addr change success!", power on again.

gas.changeI2cAddrGroup(i);
 /* 
 	i			Group number
 
  //Group serial number and DIP switch configuration table
  A0 A1Dial level    00    01    10    11
  Group number          Group address
    1            0x60  0x61  0x62  0x63
    2            0x64  0x65  0x66  0x67
    3            0x68  0x69  0x6A  0x6B
    4            0x6C  0x6D  0x6E  0x6F
    5            0x70  0x71  0x72  0x73
    6(Default address group) 0x74  0x75  0x76  0x77(default address)
    7            0x78  0x79  0x7A  0x7B
    8            0x7C  0x7D  0x7E  
 */

Other Supplementary Information

  • Do not plug or unplug the sensor on the module.
  • It is forbidden to directly solder the pins of the module, but the sockets of the pins can be soldered.
  • The module should avoid contact with organic solvents (including silica gel and other adhesives), paints, pharmaceuticals, oils and high-concentration gases.
  • The module must not be subjected to excessive shock or vibration.
  • The module needs to be warmed up for more than 5 minutes when powered on for the first time. It is recommended to warm up for more than 24 hours if it has not been used for a long time.
  • Do not apply this module to systems involving personal safety.
  • Do not install the module in environment with strong air convection.
  • Do not leave the module in high-concentration organic gas for a long time.
  • The data returned by the serial port of the module is the real-time concentration value in the current environment. If there is no standard gas, please do not try the calibration command. This command will clear the calibrated data, and the data returned by the serial port will be inaccurate.
  • To judge whether the module communication is normal, it is recommended to use a USB to TTL tool (communication level 3V) to observe and judge according to the communication protocol through the serial debugging assistant software.

Was this article helpful?

TOP