# Temperature with MAX31855

**URL:** https://discourse.nodered.org/t/temperature-with-max31855/52498
**Category:** General
**Created:** [21 October 2021 08:27 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498 "2021-10-21T08:27:31Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Blu3](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@Blu3](https://discourse.nodered.org/u/Blu3)
#### Post date: [21 October 2021 08:27 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/1 "2021-10-21T08:27:31Z")

</div>

Hi Everyone,

I currently have a problem that seems to have been addressed here more often in the forum.

I would like to read the temperature of a type-K thermocouple using a MAX31855 and a Raspberry.

Unfortunately there is only one node for the MAX31865.

Is there a simple solution for this?

Thank you

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [21 October 2021 08:38 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/2 "2021-10-21T08:38:57Z")

</div>

> [@Blu3](#):
>
> Unfortunately there is only one node for the MAX31865.

Does that one not work then?

---

<div class="post-metadata">

### Author: ![Blu3](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@Blu3](https://discourse.nodered.org/u/Blu3)
#### Post date: [21 October 2021 08:50 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/3 "2021-10-21T08:50:13Z")

</div>

Unfortunately no,  
I have tested it but it is only for the pt100/1000 thermometer.  
As i want to use a Typ-K thermocouple this doesnt work

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [21 October 2021 09:17 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/4 "2021-10-21T09:17:22Z")

</div>

Oh, I see what you mean, that is for 31865 and you want 31855.  
How are you proposing to connect to the chip?

---

<div class="post-metadata">

### Author: ![Blu3](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@Blu3](https://discourse.nodered.org/u/Blu3)
#### Post date: [21 October 2021 09:21 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/5 "2021-10-21T09:21:56Z")

</div>

> **[max31855-thermocouple-python-library.pdf](https://cdn-learn.adafruit.com/downloads/pdf/max31855-thermocouple-python-library.pdf)**
>
> 662.89 KB

hope it is ok to post this link.

Iam trying now to use the described way in the document.  
As soon as it comes to the software it is difficult for me because I have little knowledge of programming. Therefore, I had the hope that it is somehow possible with nodered.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [21 October 2021 09:38 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/6 "2021-10-21T09:38:16Z")

</div>

If the board has a python library then it may well be that the best way to access it from node-red is via the python library, so get that going first then ask again and someone will help you get it from there into node-red, probably via MQTT.

---

<div class="post-metadata">

### Author: ![Blu3](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@Blu3](https://discourse.nodered.org/u/Blu3)
#### Post date: [22 October 2021 08:24 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/7 "2021-10-22T08:24:48Z")

</div>

Thank you so far,  
I have now made it so that it works using the python library. So with the help of the python function, the temperature is raised.

Unfortunately I do not know how to work with MQTT. Is this the only way to transfer the information to Node Red?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [22 October 2021 08:51 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/8 "2021-10-22T08:51:37Z")

</div>

> [@Blu3](#):
>
> Unfortunately I do not know how to work with MQTT. Is this the only way to transfer the information to Node Red?

What does your python s/w do? If you run it in a terminal does it display the temperature and exit?

How often do you need to read the temperature?

---

<div class="post-metadata">

### Author: ![Blu3](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@Blu3](https://discourse.nodered.org/u/Blu3)
#### Post date: [22 October 2021 08:58 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/9 "2021-10-22T08:58:13Z")

</div>

```auto
import time
import board
import digitalio
import adafruit_max31855

spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5)

max31855 = adafruit_max31855.MAX31855(spi, cs)
while True:
    tempC = max31855.temperature
    tempF = tempC * 9 / 5 + 32
    print("Temperature: {} C {} F ".format(tempC, tempF))
    time.sleep(2.0)

```

as you see i get the temperature in °C and F. At the moment i get it every 2 seconds

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [22 October 2021 09:05 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/10 "2021-10-22T09:05:15Z")

</div>

You could run that in an Exec node, set to `Output while the command is running` and you should get the values appearing in messages on the output. I suggest amending the python so it only sends the number though, otherwise you will have to strip off the extra bits in node-red. In the command use the full path to python (probably /usr/bin/python) and also the full path to your script. I think you also need to tell python to use unbuffered mode, which means including `-u ` in the command.

---

<div class="post-metadata">

### Author: ![Blu3](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@Blu3](https://discourse.nodered.org/u/Blu3)
#### Post date: [3 November 2021 10:43 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/11 "2021-11-03T10:43:55Z")

</div>

Unfortunately, I have not been able to do much lately, but I am not getting anywhere. Could you describe your execution in more detail? Because the Python programming does not work in Node Red. Means I send the data via MQTT and take it back up in Node Red and work with the exec Node?  
Thank you

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [3 November 2021 14:14 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/12 "2021-11-03T14:14:54Z")

</div>

> [@Blu3](#):
>
> Because the Python programming does not work in Node Red.

Why not?

You have two options (probably more).

1. Get the python program running in node-red. You have not said what the problem is.
2. Run it as a separate process, outside of node-red, communicating with node-red via MQTT. Then you do not need an exec node at all. See this for an excellent introduction to MQTT [MQTT Essentials - All Core Concepts Explained](https://www.hivemq.com/mqtt-essentials/)

---

<div class="post-metadata">

### Author: ![Blu3](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@Blu3](https://discourse.nodered.org/u/Blu3)
#### Post date: [4 November 2021 09:24 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/13 "2021-11-04T09:24:43Z")

</div>

![2021-11-04-101808_1920x1080_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/2440104cff33f752aa4fcf2e96d9b43256a67842.png)

I tried it first simply with the python function node. I suspect that this do not has access to the pyhton library i installed?

To be honest i dont knoe how to handle the exec node. It would be great if it could work without MQTT. Could you give me a short example with the exec node?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [4 November 2021 10:01 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/14 "2021-11-04T10:01:14Z")

</div>

Does your python program run from the CLI on your pi?  
If so, have you modified it to work with MQTT?

If the answer to both of those is YES, then you can use an `mqtt-in` node in your flow to subscribe to the topic the python program is publishing to.

If you don't know how to use MQTT with python, there are lots of tutorials out there (google 'python mqtt tutorial) and here is one of them:

> **[MQTT Beginners Guide](https://medium.com/python-point/mqtt-basics-with-python-examples-7c758e605d4)**
>
> The IOT protocol explained with Python examples

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [4 November 2021 10:39 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/15 "2021-11-04T10:39:50Z")

</div>

> [@Blu3](#):
>
> Could you give me a short example with the exec node?

Initially all you should have to do is to put the command you run from the command line into an exec node, but specify the full path the the python command and also the full path to the python file. Add debug nodes on all outputs of the exec node, give them names so you can tell which output is which, and set them Output Complete Message and see what happens. Maybe a good idea to initially modify the python to just run once rather than looping.

However, it really would be better to use MQTT, you will not regret the few hours needed to understand and use MQTT. Particularly if you intend to keep using node-red.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [3 January 2022 10:40 UTC](https://discourse.nodered.org/t/temperature-with-max31855/52498/16 "2022-01-03T10:40:50Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
