Modbus / Temp Sensor and Rasp Pi through Node Red

Hi guys,

I`m having some real trouble trying to sort a project at the moment -

I have the waveshare can hat connected to my pi hoping to read data from a Rs485 sht20 temp sensor.

The can hat

The sensor-
http://www.bizkit.ru/wp-content/uploads/2018/11/Temperature-and-humidity-transmitter-SHT20-sensor-Modbus-RS485.pdf

Im stuck at what to do - Ive connected the can hat via the gpio pins and tried to get the modbus to speak to it via node red. There are python libraries used in the user manual but as Im a newbie Im not sure how I can use these to read registers?

I also have a wingoneer usb2 to rs485 stick that I could use instwad, I`ve tried connecting that to the pi yet the serial again wont read it?

Any advice would be greatly appreciated.

Are you familiar with python? I find that using the recommended solution is a good starting point to get things working. So if there are any test scripts or example scripts you can use to validate that the hardware is working correctly, completely, then integrating it into NR will be easier.

I have a lot of sensors that are not yet in NR, but I had python scripts that worked with the various sensors so I wrote a few python scripts that use MQTT communication, which NR can interface with, once you get comfortable with NR and MQTT. Overtime, I will retire the python, for more node.js and NR native code/scripting.

I can definitely help you with getting any existing python scripts using MQTT, if you want to try to do that before jumping fully into NR. Looking at the PDF, it seems like taking the send and receive python scripts and adding to them MQTT communication, might be an option.

1 Like

Thanks for the advice! Can Node Red only talk via MQTT to the CAN HAT ? The can hat is used by the gpio pins so how come I cant just use the input gpio pins to take in any data it receives? Im still a bit confused by all this. I thought it would be as smple as connecting it via the gpio pins and using the gpio in node on node red to communicate. I`m not familiar with setting up communications via python so any advice would be much appreciated.

There could be a simpler solution. The sensor you have is a Modbus device and the datasheet has all the connection information ( 9600, N, 8, 1), so you could plug your USB to RS485 converter into the Pi and then use the node-red-contrib-modbus node to communicate with the sensor. No need to use a hat or connect GPIO

Okay I`m going to try that now ., thank you :slight_smile: How exactly will the modbus know what data to recieve from the sensor? Would I not need to code something so that rs485 communicates properly to the register? Apologises as I am a newbie so any help - even a break down of how to do this would be really handy, especially the A/ B connections on the sensor to the pi

These are the results I`m getting - what is needed for the address , quantity and poll rate? Also the error message says Econnrefused?

USB to RS485 adapter is maked A+ and B- on the back of the screw terminals
Communications set up is 9600 , N, 8, 1 (you have baud rate set at 115200)
Default modbus address of device is 1
Temperature modbus address is 1 and Humidity is 2 ( you have set address 8)

1 Like

Thank you so much for this - really kind of you. So the USB I`m using is this ,https://www.amazon.co.uk/WINGONEER-USB-485-Converter-Adapter-Window-1/dp/B016IG6X7I

and ive matched everything in your pictures - theres still no response? No error messages or anything, how could I get the data from the sensor?

Attached is my wiring as well.

Can you identify A+ and B- on the USB to Rs485 adapter and on the sensor, are these correct?
In the Modbus config you need to ensure the correct usb port is selected. This will be different depending on which port your adapter is plugged in to. Use the search button and a drop down box will show available devices. This is usually USB0 etc.

1 Like

I also tried a modbus serial in rs485 node that is giving a timed out error each time?

The wiring is correct too

There is a detailed video on this sensor and integration to Node Red. It seems that the comms parameters in the sensor need to be changed. There is a link to the Node Red flow that was used.
Have a look at that

1 Like

The example flow is in the flow library
https://flows.nodered.org/flow/670ba131f74bd127d884aab2a580bffb

Thank you so much- will check that out now! I tried using a modbus serial port node especially for rs485 which seems to give me data.( see attached) I`m not sure what the format of this data is though , as the data given seems very different to whats provided in the datasheet

Ahh what a coincidence , it refers to the serial node! Must not work with the standard modbus reader. Regarding the AMA0 and S0 ports, if I wish to communicate with the CAN hat in the future what input would this be? If its connected via the GPIO pins would I need to use the dev/ttys0 or dev/ttyAMA0 ? I would ideally like to use it via the can hat?

The sensor should work with both the serial node and the modbus node. You can see in your screen shot a buffer with some values. These probably need to be converted as shown in the video and the example flow. I have used the GPIO serial ports on a Pi but there was an issue relating to disabling the serial console. I am not sure of the exact details but you could check on the Pi forums.

1 Like

That sounds familiar, the issue I was having with the GPIO was that the port was locked and you couldnt disable it. I searched all weekend for something but couldnt find any other forum on it. A lot of the tutorials online put it as simple as just connecting the hat to the gpio pins and selecting dev/ttys0 but it just doesnt work.

This is the article I used to get a modbus RS485 "hat" to work on a Pi3. It worked fine so I would think you would need to do something similar to get the CAN hat to work

1 Like

Thank you for this - you`ve been so helpful. I more or less followed all these steps and kept getting a port not open error for the serial port connection - this sounds like the issue you were having regarding disabling the serial console - do you remember how you got round this issue please?