# Modbus / Temp Sensor and Rasp Pi through Node Red

**URL:** <https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353>\
**Category:** General\
**Created:** [19 July 2020 20:01 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353 "2020-07-19T20:01:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [19 July 2020 20:01 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/1 "2020-07-19T20:01:37Z")

</div>

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

> **[RS485-CAN-HAT-user-manuakl-en.pdf](https://www.waveshare.com/w/upload/2/29/RS485-CAN-HAT-user-manuakl-en.pdf)**
>
> 818.85 KB

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

I`m stuck at what to do - I`ve 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 I`m a newbie I`m 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.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [20 July 2020 04:08 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/2 "2020-07-20T04:08:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 08:09 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/3 "2020-07-20T08:09:59Z")

</div>

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 can`t just use the input gpio pins to take in any data it receives? I`m 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.

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 July 2020 10:13 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/4 "2020-07-20T10:13:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 10:49 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/5 "2020-07-20T10:49:20Z")

</div>

Okay I`m going to try that now ., thank you 🙂 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

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 11:03 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/6 "2020-07-20T11:03:01Z")

</div>

![20200720_115536](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/0/f0482723f23967e4b30a3e92947d908bd9b070d5.jpeg) ![20200720_115544](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/03ce2fa6224f5a76a489b7cc733cc37b92de7628.jpeg) ![20200720_115532](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/5956b0b179bc50b0c0d73fbe34a8b735d922115e.jpeg)

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

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 July 2020 11:11 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/7 "2020-07-20T11:11:14Z")

</div>

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)

 ![Modbus Config](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/c/1cef83d4db841c7cf99e90488cdf46e525acbf1d.jpeg) ![Modbus Temp](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5df6d532095fa1181cf0a790910041dddd8160ed.jpeg) ![Modbus Hum](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97be4fe6cc3fdb3c2259dae4d26dbd005f44d93c.jpeg)

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 11:32 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/8 "2020-07-20T11:32:00Z")

</div>

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](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.

 ![20200720_122253](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/aee5a882d6edc5c4acdb64bd7880a2d2e716fd27.jpeg) ![20200720_122239](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/7/f779cf04b14df462643560b23928f94567060313.jpeg) ![20200720_122307](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d48ded64d2ac182778572905c74eb9212ec0facc.jpeg)

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 July 2020 12:46 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/9 "2020-07-20T12:46:00Z")

</div>

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.

 ![Modbus Config1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/472d1853dfc23dc579d405bceb4f35efeba1a06e.jpeg)

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 13:07 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/10 "2020-07-20T13:07:01Z")

</div>

![20200720_140258](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f62ed8aeb19639f3de49b7d5549323ee6daa67ec.jpeg)

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 13:08 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/11 "2020-07-20T13:08:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 13:16 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/12 "2020-07-20T13:16:11Z")

</div>

The wiring is correct too

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 July 2020 13:48 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/13 "2020-07-20T13:48:06Z")

</div>

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

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/67b4551b41fbef6fd58a1c7fc4691f52f1069afe.jpeg "RS-WS-N01-8 Modbus Temperature and Humidity sensor") ](https://www.youtube.com/watch?v=tgLTkWAz5Is)

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 July 2020 13:50 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/14 "2020-07-20T13:50:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 14:02 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/15 "2020-07-20T14:02:08Z")

</div>

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

 ![20200720_145957](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d37ec9fe2723baacfb31204ba7baf6e45120659e.jpeg)

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 14:07 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/16 "2020-07-20T14:07:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 July 2020 14:17 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/17 "2020-07-20T14:17:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [20 July 2020 14:27 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/18 "2020-07-20T14:27:26Z")

</div>

That sounds familiar, the issue I was having with the GPIO was that the port was locked and you couldn`t disable it. I searched all weekend for something but couldn`t 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.

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 July 2020 14:53 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/19 "2020-07-20T14:53:41Z")

</div>

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

> **[Configuring The GPIO Serial Port On Raspbian Jessie and Stretch Including Pi...](https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3-4/)**
>
> The Raspberry Pi GPIO serial port configuration has changed under Jessie / Stretch / Buster and also with the Raspberry PI 3 / 4. How to set it up.

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [21 July 2020 07:51 UTC](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353/20 "2020-07-21T07:51:58Z")

</div>

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?

[Next page](https://discourse.nodered.org/t/modbus-temp-sensor-and-rasp-pi-through-node-red/30353.md?page=2)
