Display pi sensor data to i2c lcd


Hi all,

Sorry, for such a noob question, but I’m really stuck here. I have very little (no) programming experience prior to discovering node red last year. I’ve successfully created a few projects, the biggest controlling a window air conditioner to cool a walk-in cooler down to 45 degrees with notifications, etc.

I would like to use this lcd to display the cooler temperature and the air conditioner coil temp. I have ds18b20 sensors getting this data.

I’ve tried every i2c node I can find, and every sample flow on this site. I’ve successfully gotten the screen to print out pre-defined text, or the current date/time using This flow although my screen is 2 lines.

Where I’m stuck is figuring out how to display the data from the sensor instead of pre-defined text. I assume this is because the msg type is incorrect for how the flow is set up, but I’m not sure?

I would really appreciate any help - I’ve spent an embarrassing amount of time on what I thought would be a very simple part of my project!

Edit: the display is a generic 16x2 lcd with I2C board from aliexpress.


The flow you posted is passed a string in msg.payload. Is that the bit you do not know how to do?

If so then in what form do you have the data from the sensor. Show us the flow you have so far, just the bits getting the value and preparing to pass it to that function.


Thanks Colin!

I'll post the flow when I'm home from work. I believe the DS18b20 node outputs a number. I have a feeling this is simple, and I tried a Change node, but I obviously am doing something wrong.

Ideally I'd be able to have the LCD display: Coil Temp: (temp value) and other data on line 2, but at this point I'm not picky haha.


If it produces a number then you don't need to post the flow, you just need to convert the number to a string. I expect you can do that with a Change node and jsonata but the simpler way might just be a function node containing something like

msg.payload = msg.payload.toFixed(2)
return msg

which will convert the number to a string with two fractional digits. Obviously you can use something other than 2.
Feed that into a debug node to make sure it looks right, then pass it to the display node.


Thanks Colin! This is working perfectly - I added the text I wanted in front of the temp reading as well.

Now to figure out how to put other data on line 2... haha

Thank you again!!


often with those displays you can just keep writing and eventually it will spill onto line 2 ... not ideal but hey ...
Normally there is also a position cursor command that lets you move the cursor to a set point - (like to the start of the second line (usually starting from 0 so the second line will be called 1 :slight_smile: ) and then you can write again...