ced2
July 25, 2024, 10:36am
#1
Hello,
I’ve just received an ammonia sensor (SKU 101990862, https://files.seeedstudio.com/products/101990862/RES/RS485%20NH3%20Sensor%20-%20Datasheet.pdf ) and I have some trouble configuring it.
My setup is as follows:
rs485 to usb dongle connected to a linux machine
NH3 sensor connected to the rs485 part of the dongle
I read values using python mimimalmodbus library (API for MinimalModbus — MinimalModbus 2.1.1 documentation ). I succeeded in reading temperature and humidity but I receive always a 0 value on ammonia.
I send this request:
and I receive always this response:
0F 03 04 00 00 00 00 15 F3
I put some ammonia on a tovel and put the tovel close to the sensor but the ammonia level didn’t change.
This is my code:
#!/usr/bin/env python
import minimalmodbus
import time
from pprint import pprint
minimalmodbus.BAUDRATE = 9600
# port name, slave address (in decimal)
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 15, debug = True)
#instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 15, debug = False)
instrument.serial.baudrate=9600
instrument.serial.bytesize = 8
#instrument.serial.parity = serial.PARITY_NONE
instrument.mode = minimalmodbus.MODE_RTU
instrument.serial.timeout = 1
while True:
# Register number, number of decimals, function code
# 0x2000 -> 8192 ammonia
# 0x2004 -> 8196 temp
# 0x2006 -> 8198 humidity
#pprint (instrument)
ammonia = instrument.read_float(8192,3,2,0)
temp = instrument.read_register(8196, 2, 3)
humidity = instrument.read_register(8198, 2, 3)
max_range = instrument.read_register(8200, 0, 3)
print (f"ammonia : {ammonia} ppm - temp: {temp} °C - humidity: {humidity}% - max_range: {max_range} ppm")
time.sleep(5)
Am I doing something wrong?
Thanks in advance
Andrea
I dont know much about that device and do not have that hardware… but did you check
Try reading Temp and Humidity
ced2
July 25, 2024, 11:39am
#4
Hello Christopher,
thanks for your answer. I read temperature and humidity correctly: here is an output from the program:
MinimalModbus debug mode. Will write to instrument (expecting 9 bytes back): 0F 03 20 00 00 02 CE E5 (8 bytes)
MinimalModbus debug mode. Clearing serial buffers for port /dev/ttyUSB0
MinimalModbus debug mode. No sleep required before write. Time since previous read: 5006.56 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: 0F 03 04 00 00 00 00 15 F3 (9 bytes), roundtrip time: 0.2 ms. Timeout for reading: 0.0 ms.
MinimalModbus debug mode. Will write to instrument (expecting 7 bytes back): 0F 03 20 04 00 01 CF 25 (8 bytes)
MinimalModbus debug mode. Clearing serial buffers for port /dev/ttyUSB0
MinimalModbus debug mode. No sleep required before write. Time since previous read: 5.81 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: 0F 03 02 0B 7E 56 95 (7 bytes), roundtrip time: 0.2 ms. Timeout for reading: 0.0 ms.
MinimalModbus debug mode. Will write to instrument (expecting 7 bytes back): 0F 03 20 06 00 01 6E E5 (8 bytes)
MinimalModbus debug mode. Clearing serial buffers for port /dev/ttyUSB0
MinimalModbus debug mode. No sleep required before write. Time since previous read: 5.84 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: 0F 03 02 10 1F 9D 8D (7 bytes), roundtrip time: 0.1 ms. Timeout for reading: 0.0 ms.
MinimalModbus debug mode. Will write to instrument (expecting 7 bytes back): 0F 03 20 08 00 01 0F 26 (8 bytes)
MinimalModbus debug mode. Clearing serial buffers for port /dev/ttyUSB0
MinimalModbus debug mode. No sleep required before write. Time since previous read: 6.02 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: 0F 03 02 00 64 D0 6E (7 bytes), roundtrip time: 0.1 ms. Timeout for reading: 0.0 ms.
ammonia : 0.0 ppm - temp: 29.42 °C - humidity: 41.27% - max_range: 100 ppm
As you can see from the last line, humidity and temp are ok, is hust ammonia that is always 0.
did you check the wireing? open the case… ? was the sensor connected to the case when you got it?
Hi there,
Looks like it’s broken?
Also does it require a warm up time? and what about some delay in between the T & H readings ?
I would try that also.
my .02
HTH
GL PJ
ced2
July 25, 2024, 3:48pm
#7
Hello Christopher,
yes I double checked cabling (I did cabling at least two times with no luck). I did not put any liquid on the sensor. Sensor was inside an electrical box so I didn’t touch it. I just don’t know what to think … I’m just a newby in this field so maybe I’m just making some rookie mistakes
1 Like
ced2
July 25, 2024, 3:54pm
#8
Hello JP,
thanks for answering. I added some delay (2 seconds) between each measurement with no luck.
The sensor requires a little warm up time:
ced2
July 26, 2024, 1:26pm
#9
I think I solved the issue: I was reading the correct register but the wrong number of bytes.
I modified this line of code:
# read_float(registeraddress: int, functioncode: int = 3, number_of_registers: int = 2, byteorder: int = 0)
ammonia = instrument.read_float(8192,3,2,0)
to
# read_float(registeraddress: int, functioncode: int = 3, number_of_registers: int = 2, byteorder: int = 0)
ammonia = instrument.read_float(8192,3,4,0)
This was written in the manual but I didn’t pay enough attention to it:
Now I receive a value which is not zero every time.
2 Likes
AWESOME… i knew it was something simple like that!
dont forget to update your comment for future reference (# in the code)