Sensor RS485 Communication Description: I Wiring Diagram 4 3 2 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Sensor RS485 Communication Description

I Wiring diagram

4 3 2 1

Port number Function Explanation


PIN1 VCC External power supply> 2W DC 10~24V positive
PIN2 GND External power supply> 2W DC 10~24V negative

PIN3 RS485B 485 interface line B; (Note: it does not connect for WiFi
version )
PIN4 RS485A 485 interface line A; (Note: it does not connect for WiFi
version )

II Communication Protocol

1. Communication Convention
Baud rate:9600
Data bit:8
Parity check: no
Stop bit:1
Data flow control: no
CRC check,CRC-16 0xA001-RTU standard,L is in the front, H is in the back.
All operation or response commands are hexadecimal data.
2. Frame format description
2.1 Gas sensor value data frame format. The default device address is 0x02.
00 01 02 03 04 Check 0 to 4 bits

Device Function Gas Gas


Gas type(see table) CRC-16L CRC-16H
address code concentration H concentration L

02 03 05

Gas type code table:


Type Code Type Code Type Code Type Code
PM1.0 0x05 CO2 0x09 SO2 0x0D Temperature 0x11
PM2.5 0x06 VOC 0x0A NO2 0x0E Humidity 0x12
PM10 0x07 HCHO 0x0B CO 0x0F Wind speed and direction 0x04

O2 0x08 O3 0x0C NH3 0x10


Gas concentration value = ( gas concentration high * 256 + gas concentration low) * resolution

Resolution:
Type Resolution Unit
PM1.0 1 ug/m3
PM2.5 1 ug/m3
PM10 1 ug/m3
CO2 1 ppm
VOC 1 ppb
HCHO 1 ppb
SO2 1 ppb
NO2 1 ppb
Temperature 0.1 degrees Celsius ℃
Humidity 1 %
Wind speed 0.01 m/s
Wind direction 0.01 Due north is 0 degrees, clockwise angle value

For example Rx:02 03 11 00 EE 8D CD


0x02 is the device address; 0x03 is the function code; 0x11 is sensor type, temperature sensor; detection value is
0x00 EE; EE is decimal 238, temperature = 238 × resolution 0.1 = 23.8 degrees Celsius.

2.2 Read the anemometer data. The factory default device address is 0x01. The anemometer can only work in
query feedback mode.
Name/nu
mber of 0 1 2 3 4 5 Check 0 to 5 bits
bytes
Read Read
Device Function Read start Read start
number of number of CRC-16L CRC-16H
address code address H address L
data H data L
Read wind
speed and 01 03 00 00 00 02 C4 0B
direction
Tx:01 03 00 00 00 02 C4 0B
Rx:01 03 04 00 C1 60 AE 02 73
Name/nu
mber of 0 1 2 3 4 5 6 Check 0 to 6 bits
bytes
Wind Wind
Device Functio Wind Wind
Data type direction direction CRC-16L CRC-16H
address n code speed H speed L
H L
Read wind
speed and 01 03 04 00 C1 60 AE 02 73
direction
Value = (high bit * 256 + low bit) * resolution; wind speed 0x00 C1 resolution is 0.01, wind speed = 1.93 m/s; wind
direction 0x60 AE resolution is 0.01, wind direction = 247.5 degrees. (The wind direction is 0 degrees from true north,
and the angle is clockwise.)

2.3 Configure the active upload mode. The gas sensor can be operated in two modes: active upload and query
feedback. The anemometer can only work in query feedback mode.
The gas sensor has two working modes, one of which is optional, the device factory default: address 0x02, working
mode is automatic, the interval time is 5 seconds;
Mode: active upload mode 0x01, query feedback mode 0x00.
Name/number 0 1
2 3 4 5 6 Check 0 to 6 bits
of bytes
command command word
Registe Registe word H L
Functi
Device r r Workin (Active (Active CRC-1
on CRC-16H
address address address g mode upload time upload time 6L
code
H L interval in interval in
seconds) seconds)
Configuration
command
02 06 00 50 01 00 05 B8 65
(active sending
mode)
Configuration: Device 0x02 is the active upload mode, and the upload interval is 5 seconds. (Interval time can be
selected from 1 to 65535 seconds), the configuration command must have a time, and the time cannot be 0.
Tx: 02 06 00 50 01 00 05 B8 65
Rx:02 06 00 5001 00 05 B8 65(Return command successfully)
Note: According to the characteristics of RS485, the active upload detection data mode is suitable when there is only one
sensor connected to the bus, and the query feedback mode should be used when multiple sensors are connected.
2.4 Gas sensor configuration query feedback mode
Name/number
0 1 2 3 4 5 6 Check 0 to 6 bits
of bytes
Functi Register Register Worki
Device
on address address ng Reservation Reservation CRC-16L CRC-16H
address
code H L mode
Configuration
command
02 06 00 50 00 00 00 29 A6
(active
sending mode)
Choose one of two working modes.
Tx: 02 06 00 50 00 00 00 29 A6
Rx:02 06 00 50 00 00 00 29 A6(Return command successfully)
When working in query mode, if no query command is received after waiting for 15 minutes, the sensor will enter a
low-power sleep mode. It starts to work when the query command is received again. After sleep, the first query
command is received, and the returned sensor detection value is 0. You need to wait 30 to 60 seconds before sending the
query command again to get the correct detection value. If the sensor is not required to enter sleep mode, the query
command interval is less than 15 minutes.

2.5 Query gas detection value command in gas sensor query feedback mode
00 01 02 03 04 05 Check 0 to 5 bits
Device Register Register Read number Read number
Function code CRC-16L CRC-16H
address address H address L of data H of data L
02 03 00 03 00 05 75 FA
Read address 0x02:
Tx:02 03 00 03 05 75 FA
Response see 2.1

2.6 Device address setting


00 01 02 03 04 05 Check 0 to 5 bits
Device Register Register Target address Target address
Function code CRC-16L CRC-16H
address address H address L H L
01 06 00 66 00 02 E8 14

Example: Set 0x01 to 0x02


Tx:01 06 00 66 00 02 E8 14(original address 0x01,New address 0x02)
Rx:02 06 00 66 00 02 E8 27(Set successfully. Yellow is the new address)

2.7 Query address command when the sensor address is unknown (used when the 485 bus is only connected to the
sensor)
Name/nu 0 1
mber of 2 3 4 5 Check 0 to 5 bits
bytes
Device Function Read start Read start Read Read CRC-16L CRC-16H
address code address H address L number of number of
data H data L
Query
device FA 03 00 66 00 02 31 9F
address
FA,that is 250, is the general address. When the address is unknown, the address 250 can be used to obtain the real
device address, and 00 66 is the register of the device address.
For the correct query command, the device will respond. For example, the response data is: 01 03 02 07 12 3A 79.
The format analysis is shown in the following table:
Tx:FA 03 00 66 00 02 31 9F
Rx:01 03 02 07 12 3A 79
Name/nu
mber of 0 1 2 3 4 Check 0 to 6 bits
bytes
Device
Function code Data type Model code CRC-16L CRC-16H
address
Query
device 01 03 02 07 12 3A 79
address

In the response data, the first byte 01 indicates that the real address of the current device is, 0x07 12, converted to
decimal 1810, which means that the main model code of the current device is 1810.

2.8 Query working mode commands when the sensor working mode is unknown
Name/number of 0 1
2 3 4 5 Check 0 to 5 bits
bytes

Read Read
Device Function Read start Read start CRC-16 CRC-16
number of number of
address code address H address L L H
data H data L

Query working
02 03 00 50 00 02 C4 29
mode
Tx:02 03 00 50 00 02 C4 29
If Rx:02 03 00 50 00 00 05 E9 F0
Name/number 0 1 4
2 3 5 6 Check 0 to 6 bits
of bytes
Read Read Worki Active Active
Functi
Device start start ng reportin reportin CRC-1 CRC-1
on
address address address mode g time g time 6L 6H
code
H L H L
Query working
02 03 00 50 00 00 05 E9 F0
mode
Device 0x02, the reporting interval of active upload mode is 5 seconds.
If Rx:02 03 00 50 01 00 00 E9 A5
Device 0x02, query feedback mode.

2.9 CRC check,CRC-16 0xA001-RTU standard,L is in the front, H is in the back.


CRC check algorithm:
/* CRC lookup table*/
const uint8_t table_CRC_h[]= {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40
};

const uint8_t table_CRC_l[] = {


0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,
0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,
0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
0x11, 0x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, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,
0x40
};

//parameter 1: updata Data buffer to participate in verification


//parameter 2: len The length of the data to be verified
//return value :Calculated 16-bit CRC value
uint16_t calc_CRC16 (uint8_t *updata, uint16_t len)
{
uint8_t crc_h = 0xff;
uint8_t crc_l = 0xff;
uint16_t uindex = 0;

while (len--) {
uindex = crc_h ^* updata++;
uindex = crc_h ^* updata++;
crc_h = crc_l ^ table_CRC_h[uindex];
crc_l = table_CRC_l[uindex];
}
return (crc_h << 8 | crc_l);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy