Display temp (18b20) on oled with just pi and nodered

This is to document my learning to use a ds18b20 temps sensor and displaying it to a OLED display using just node red installed in a Raspberry Pi 3. This may help other beginners like myself with the node red journey.

While this "temp and display thing" has been done many times before with python etc in the pi or in combination with esp8266 to drive the oled, i could not find any such implementation using just the PI and node red alone on the net.

In the process I learnt a bit about nodered. I have to acknowledge the nodered forum and in particular @knolleary for the advise given on the project.

Here is a very brief outline of the project:

Aim: To connect ds18b20 temp sensor and display to an Oled display using just a pi and node red.

Initial SETUP:

Install ds18b20: From palatte, find and Install ds18b20 node

Install Oled: Same for oled Node-red-contrib-oled

Enable 1 wire in pi with config

Enable 12c in pi with config

==============

HARDWARE:

hook up 18b20
image

=================
Hook up the oled
Data: (GPIO2); Clock (GPIO3)
image

===================

NODE-RED FLOW

  1. Set up the ds18b20 node to read temp every few sec and store it into a global variable. This is done with a function node that set the global variable" t1" to the payload.

image

declare global variable
image

Result: Now the temperature is in a global variable t1 for retrieval

=====================

Displaying the global variable on the oled:

The description of the oled node is a bit vague. The oled needs an i2c address, usually hex 3c in the node setup. Note: Just enter 3c and not 0x3c. To find the address: i2cdetect -y 1.
To display data to oled, the oled node needs a json object payload of:

{"size":3,"x":1,"y":1,"text":"text string to display"}.

So to display the global variable (t1), we need to:

  1. "get" the global variable and pass it tthe payload with a function node

var t1= global.get("t1");

msg.payload=t1

  1. Because the payload is numeric, we have to convert this numeric data to string, so another function node to convert number to string:

msg.payload=String(msg.payload). Note case sensitive, I was caught out using string.

  1. Another function node to add *C

msg.payload +=" *C";

  1. Finally a function to set up the json payload for the oled with the payload from the flow. refer to topic where Nick OLeary, @knolleary show me how. How to use oled node

image

  1. Just add an inject node at the beginning to update the temp every few secs.

nr3

The result.
It may not be the most elegant approach, but I learnt a lot and was fun.

PS: I also got the temperature to display on various remote oleds connected to esp8266(espeasy) via mqtt.

3 Likes

Hi @kenkoknz,

most images are not being displayed in my browser (Chrome both on desktop and mobile):
image
I can only see the image of the flow in point '5' and the last image. Don't know if this is a Discourse issue ...
Bart

I am having the same issue as Bart. So most images are also not displayed in my browser.

Images are linked to mail.google.com - you need to put it somewhere with public access.

Hi, I have edited the images link, let me know if visible.
Cheers

1 Like

thanks, all images are visible. :+1: