Trying to send text to LCD over i2c contrib

While pointing out the search options for another member looking to write to an LCD, I decided to try it myself.

I setup a Sainsmart 2004 LCD with I2C backpack onto my RPi.

Tested it with some Python code... yes, my setup is a bit "how ya doin" but it clearly is working :slight_smile:

Now the issue I have... I am trying out this contrib - node-red-contrib-lcd20x4-i2c as it best matches the hardware. It is older, but doesn't seem to state any version limits.

On that note, I am running NR v1.3.5

The issue I am running into is shear ignorance :blush: when interpreting the directions... in short form here...

This node will accept an object `msg.payload.msgs - Umm what?

Object format:

msg.payload = {
    msgs: [
        {
            msg: "string",
            pos: number,
            center: "boolean"
        },...

I tried many other random variations... but this doesn't throw a deploy error...

image

image

with actual text being...
{msgs: [{msg: "Hello",pos: 0,center: "false"}]};

No errors, but nothing on the LCD either.

Am I even injecting this correctly?

I rebooted the RPi (my go to for troubleshooting :stuck_out_tongue: ) and ran it again... this time I do get an error...

6/30/2021, 8:22:42 PMmsg : string[72]

"msgs Value not Defined: {msgs: [{msg: "Hello",pos: 0,center: "false"}]};"

6/30/2021, 8:22:42 PMmsg : string[46]

"Error Sending Message to LCD - See Error Above"

6/30/2021, 8:22:43 PM[node: 1e1df103.6cf1ef](http://10.10.3.13:1880/#)msg : error

"TypeError: Cannot read property 'stdin' of null"

So apparently I am NOT injecting the payload correctly? At a loss :frowning:

I tried a template node...

Position 0?? the template starts at 1

At this point I am just banging keys like a :monkey:

6/30/2021, 8:22:42 PMmsg : string[72]

"msgs Value not Defined: {msgs: [{msg: "Hello",pos: 0,center: "false"}]};"

6/30/2021, 8:22:42 PMmsg : string[46]

"Error Sending Message to LCD - See Error Above"

6/30/2021, 8:22:43 PM[node: 1e1df103.6cf1ef](http://10.10.3.13:1880/#)msg : error

"TypeError: Cannot read property 'stdin' of null"

The problem is the nested " in the line.

Someone else had that problem.

"{msgs: [{msg: "Hello",pos: 0,center: "false"}]};"

To help, stick a debug node just before that node and set it to show the whole message.

Copy that and paste it here.

6/30/2021, 9:48:40 PM[node: 37116244.613c4e](http://10.10.3.13:1880/#)msg.payload : string[48]

"{msgs: [{msg: "Hello",pos: 0,center: "false"}]};"

Looks the same coming out as it did going in :stuck_out_tongue:

Ok. (I'm not an expert)

First thing is I think you are using the wrong node.

template isn't the one you want.
I should have picked that up sooner, but I'm not running on all cylinders just now.

Try a function node.

Paste the example from the node's page into there and see what happens.

So basically open the function node, delete anything there and paste this:

msg.payload = {
    msgs: [
        {
            msg: "string",
            pos: number,
            center: "boolean"
        },
        {
            msg: "string",
            pos: number,
            center: "boolean"
        },
        {
            msg: "string",
            pos: number,
            center: "boolean"
        },
        {
            msg: "string",
            pos: number,
            center: "boolean"
        }
    ]
};

Give that a try.

I think that will go a long way to helping you.

Done... and nothing appeared on the debug, nor did the LCD node give any indication it received anything... just kept saying Stopped

image

No problems.

First thing - BTW, lucky I have one of these (or similar) so I am checking here myself and if I can get it working it would be great.

Ok, first big thing is the RED mark on the node.

if you run the command sudo i2cdetect -y 1 what do you see?

It should show you the address of the display. If that isn't set correctly: all bets are off.

Let's start with that. Sorry, but this is going to be a bit of a long way of doing it.
But I'm not doing too much else just now.

I don't think it is seeing the display.

image

Remember, I have tested OK with python code right on the RPi.

Ok, so you have the address set to 3F I guess?

Ok!

hang on.

Mine shows up as 72. But I guess that depends on other thigns.

What are the other two things? Do you know?

If you remove the display does the 3F go away?

1 Like

But whether any of the nodes I have tested (about 3 or 4 so far) can connect is a big, dunno

Ah, yeah, sorry. Apologies.

I think I went down this track and gave up.

I got someone else to help me write some code to display messages on the display.

That works 99.9% of the time.

I can share if you want.

image

Yes... one is a PWM board and the other is a BrightPi camera light. I have tested with them disconnected as well

The docs are poorly written IMO. the "boolean" designation is confusing.

I am suspicious it should be simply boolean.
so the line would actually be:

center: true or center: false`

Sure!!!... although the main goal was to learn how to properly inject these commands but if I can't get any results, then is it me or the node???

Thus might as well try some other way just to see it work, then I can go watch Netflix in peace (from the nagging..."did I do this???") in the back of my head :smiley:

I see Dave is also replying.

I am not going to say I am better than he is. I am still pretty much learning.

But it is a bit of python code and a couple of nodes (normal ones) needed to get it all working.

I'll let Dave get his post in and I will get the files needed.

No diff.... No error, but it looks like that is because noting ever left the function node.

I don't know if you are showing all the code in the function node, but it doesn't look as if it returns anything.
Surely there should be a return msg; at the very end ??
Also why have you got two outputs on the function node??

1 Like

Doh... even I should have realized that, having played with a few functions in the recent past.

Just playing around to see if it made any diff.

OOPS!

:wink:

Alas it hasn't solved the problem.
(See next post)

1 Like