Temperature sensor RS485 MODBUS RTU? - Page 1
Forum section: electronics / beginners

author: onesixright
author_rank: Frequent Contributor
timestamp: November 22, 2018, 02:00:34 pm
content: Hi All,Maybe someone can shed some light on this. TBT didn't go threw the modbus rtu protocol, maybe thats where the problem liesJust a case of RTFM?I have a RS485 sensor, which I hooked to to a USB / RS485 adapter. Seems to work fine, but I don't fully understand how this operates.I connect the sensor, open an serial program, and data starts to flow. Basically it is pushed every second.Code:data:T: 22.2 H: 56.1T: 22.2 H: 56.1T: 22.2 H: 55.3T: 22.2 H: 55.3T: 22.2 H: 54.7T: 22.2 H: 54.7T: 22.2 H: 54.7T: 22.2 H: 54.1Now this I can easily parse, yet i thought I needed to pull the data out of the sensor? When I try that (pulling), i'm getting some checksum errors.Code:# Python 3import minimalmodbusinstr = minimalmodbus.Instrument('/dev/tty.SLAB_USBtoUART', 1, minimalmodbus.MODE_RTU)instr.serial.baudrate=9600print(instr.read_register(287, 1))# responseValueError: Checksum error in rtu mode: '.3' instead of 'M«' . The response is: 'T: 23.3' (plain response: 'T: 23.3')I tried changing registers, but it doesn't not seem to matter. I'm guesing the request is sent, yet since the sensor pushes on its own all gets mixed up.Since it was a cheap sensor from eBay, of course no datasheet. So i'm a bit in the dark how to configure this. Like changing the address (want to use multiple sensors on the bus).Maybe it's possible to change the mode, but without a proper databasheet it is hard. Or is this all speced in themodbus rtruprotocol?Anybody that knows whats going on?Thanks!Sensor:https://www.ebay.com/itm/RS485-Temperature-and-Humidity-Transmitter-Sensor-High-Precision-Monitor/123234164113?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

author: capt bullshot
author_rank: Super Contributor
timestamp: November 22, 2018, 02:31:04 pm
content: The data you receive from the sensor clearly isn't modbus. It's just some kind of readable ASCII.Better go ask the seller for some dokumentation how to switch the thing to Modbus mode and which registers to read / write (Modbus is all about registers, but there's no standard how to use the registers).

author: onesixright
author_rank: Frequent Contributor
timestamp: November 22, 2018, 03:09:04 pm
content: Quote from: capt bullshot on November 22, 2018, 02:31:04 pmWILCO.Thanks, yeah I got this feeling something is not right. So modbus (rtu) would not push on its own data right?

author: capt bullshot
author_rank: Super Contributor
timestamp: November 22, 2018, 04:13:11 pm
content: No. Modbus is a strict master/slave protocol, the master addresses a particular slave and asks for a register content, then the slave answers / the master writes a register, the slave confirms.

author: onesixright
author_rank: Frequent Contributor
timestamp: November 22, 2018, 04:17:38 pm
content: Quote from: capt bullshot on November 22, 2018, 04:13:11 pmThanks, thats what I thought.He did write:Quote

author: onesixright
author_rank: Frequent Contributor
timestamp: November 23, 2018, 07:55:55 am
content: Well found same sensor on banggood, they had some documentation that I could use.All works now.

author: bingo600
author_rank: Super Contributor
timestamp: November 25, 2018, 07:24:53 am
content: Link ??/Bingo

author: onesixright
author_rank: Frequent Contributor
timestamp: November 25, 2018, 10:15:14 am
content: Quote from: bingo600 on November 25, 2018, 07:24:53 amSame sensor:https://www.banggood.com/Modbus-RS485-Temperature-and-Humidity-Transmitter-Sensor-High-Precision-Monitoring-p-1159961.html?gmcCountry=CZ&currency=CZK&utm_source=googleshopping&utm_medium=cpc_elc&utm_content=zouzou&utm_campaign=pla-cz-ele-cs-pc&gclid=EAIaIQobChMI86fW-aTv3gIVSsKyCh1_KwM3EAQYAyABEgKD0vD_BwE&cur_warehouse=CNLink to the files:http://files.banggood.com/2018/04/software-and-protocol.zipThe short:- if you hookup to serial terminal program, its start spitting out the data in ASCII.- when you use with modbus protocol (as intended) it works: to read useinput_registers(reg 0 = temp, 1 = humidity)- change slave address: disconnect all sensors but the one you want to change and do awrite_registerwith address "0"- change slave id is stored (also after power loss)Tested withpymodbus(working)I have two sensors There is a little bit of a difference between the 2.Code:Query sensor on address #1It's 22.7C with 61.7% RHQuery sensor on address #2It's 23.0C with 54.8% RH