# PiFace\_LCD node - really need help understanding why things are happening

**URL:** <https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803>\
**Category:** General\
**Created:** [27 July 2020 22:40 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803 "2020-07-27T22:40:29Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [27 July 2020 22:40 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/1 "2020-07-27T22:40:29Z")

</div>

This is a whole new take on my other post about PiFace CAD hat.

This is more about the actual node.  
[The node code](https://github.com/erfanjahanshahlo/node-red-contrib-pifacecad)

But I have modified it for reasons I hope to explain shortly.

So I am nearly making a node. But I don't want to really claim that. I am just trying to understand how an existing node works because I have an upcoming need for it to do a lot more than was intended.

At the start I used the node to play with my PiFace HAT. It worked in it allowed me to send messages to the screen.  
And it did that. Though how I did it was really a long trip.  
I would send a message, parse the message and use a .... script to run a python script to then parse the message and print it on the screen.

This was a long time ago and the messages were simple enough. It seemed to work.

Time has moved on.

But given the node's README file says:

> _ **To work with lcd node:** _ Here's how to send data to this node.

```auto
ROW,COL:YOUR TEXT

```

> for clear lcd send `1,1:` to the node to clear lcd.  
> Be careful not to use any spaces in any of these commands.

Alas there was a problem that the code as given didn't allow positioning of the text on the screen.

That took me a long time to work out, but I did finally get it working to do that.

(I'll leave out some stuff to what happened as I am not exactly sure now myself.)

Now we get to "now", and I am really wanting to use this node. Though it may be easier for me to actually make a node myself. Not sure.

So, I want to position text on the screen and it works. (Or so I remember)  
Now, I want to send a more complex message - like the time, or date.  
In the form:  
08:44:33 for the time  
and  
29/07/20 for the date

So, the time option just failed miserably. I can't send a `:` in the message because when the real message is parsed it uses a `:` as a delimiter.

I went into the code and changed the delimiter from `:` to `@`. I don't need any `@` on the display.

So then I could print the time on the screen.  
The date caused a bit of trouble with the `/`, but using `{{{ }}}` rather than `{{ }}` solved that problem. (Thanks @zenofmud)

Two down, more to come.

All of this is/was being tested initially from the CLI running in the node's directory.

So the command would be:  
`python pfc_lcd/py 5,1@08:44:33`  
and it would display at that position.

I wrote a flow to allow me to inject the date and time (separately) and they worked. (But there's a _Gremlin_ in that story. I'll get back to that soon.)

Then I went on to send stuff like:  
`python pfc_lcd.py 2,2@"Hello there" ` and that too would work.

It all came crashing down when I made an `inject` node to send that message.

All I see is `"Hello/#` on the screen.

**WHY?**

Looking into the `pfc_lcd.js` files I see this line:  
`text = msg.payload.replace(" ", "#/@$%");`

**And** looking a bit harder at the github page there is this:

> Be careful not to use any spaces in any of these commands.

Ah! Ok. So it wasn't just like between the positions, or the `:`, but **anywhere** in the line.

But hang on! That doesn't make sense!

I have my CLI open in: `pi@PIFACE:~/.node-red/node_modules/node-red-contrib-pifacecad $` and am running the python script.

I get that if I do:  
`python pfc_lcd.py 1,1@Hello there`  
all I will see is `Hello`

But if I enter:  
`pythono pfc_lcd.py 1,1@"Hello there"`  
I see `Hello there`

So what's going on?

Other things I did / tried:

Statusquo if I make the message `Hello_there` it works. Yeah, no big deal in that.

Then I delete the line:  
`text = msg.payload.replace(" ", "#/@$%");`

Still not getting what I want.

- The other _Gremlin_ I mentioned.  
It says:

> for clear lcd send `1,1:` to the node to clear lcd.

Tautological, I agree, but......

I send:  
`1,1@Message`  
Then send:  
`2,2@Another`

The screen is wiped when the second message is sent.

I can't see how/why this is happening.

Digging into the python code I see:

```auto
else:
    cad.lcd.clear()

```

Hmmmmmm..... Ok. So somehow this `else` is being activated.

Deleting the two lines has no effect on the display being wiped when the next message is sent.

Please, if you are still reading: Help me.

## update:

I restarted (actually that didn't work. I had to stop it and start it.) Node-Red and I am getting an error:  
`ReferenceError: text is not defined at PFC_LiquidCrystal._inputCallback (/home/pi/.node-red/node_modules/node-red-contrib-pifacecad/pfc_lcd.js:8:53)`

Into which I am looking now.

I'm guessing that is: line:column.  
(But that aside, if I run the `pfc_lcd.py` file from the CLI, it works. No errors.)

## Further update:

Rebooting the machine and all that.

This is the error I see in Node-Red:

```auto
Error: Command failed: python2 "/home/pi/.node-red/node_modules/node-red-contrib-pifacecad/pfc_lcd.py" 1,1@HelloTraceback (most recent call last): File "/home/pi/.node-red/node_modules/node-red-contrib-pifacecad/pfc_lcd.py", line 29, in <module> raise TypeError("The entered text is not correct")TypeError: The entered text is not correct

```

Ok line 29.

That is the one that is basically:

```auto
except:
    raise TypeError("The entered text is not correct")

```

But I don't know if it means PHYSICALLY line 29, or the 29'th line of valid code. (Excluding comments)

The stuff I am sending into it is exactly the same as always. Just now it is deciding it is "not correct")

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [28 July 2020 03:53 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/2 "2020-07-28T03:53:37Z")

</div>

You have a try as well?  
They have to be in pair so to say, it is a try and except block, always like (finally not needed but good to have sometimes)

```auto
try:
    try the stuff
except:
    stuff failed
finally:
    always do this stuff

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2020 03:57 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/3 "2020-07-28T03:57:39Z")

</div>

_Luckily_ it has started to behave itself again.

But now I am stuck with not being able to position the cursor on the screen.

And as I don't know where this `import pifacecad` file is, I am also stuck.

It also seems that if I change the python I am using the error changes.  
But for now all I am typing is `python`.

Are you a python person?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [28 July 2020 03:58 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/4 "2020-07-28T03:58:43Z")

</div>

> [@Trying\_to\_learn](#):
>
> Are you a python person?

No, in here I am a Node-RED user

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2020 03:59 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/5 "2020-07-28T03:59:21Z")

</div>

Had to ask. The node uses python and it is not playing fair with what it does.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [28 July 2020 04:00 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/6 "2020-07-28T04:00:22Z")

</div>

Original author at github? He may help?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2020 04:02 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/7 "2020-07-28T04:02:30Z")

</div>

Yeah, it was not really that well supported.

Originally it was meant for bigger things. It is for the PiFace CAD display hat.

It had (or said it had) stuff for the buttons and the display.

The node didn't have the button stuff and I mentioned it. Rather than add the missing files, the README file was edited and the reference to the buttons was deleted.

So I am not going to really hold out much hope on that front.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [28 July 2020 04:04 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/8 "2020-07-28T04:04:47Z")

</div>

> [@Trying\_to\_learn](#):
>
> And as I don't know where this `import pifacecad` file is, I am also stuck.

I have many of my python site-packages installed in /home/pi/.local/lib

Try to look there

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2020 04:07 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/9 "2020-07-28T04:07:15Z")

</div>

This is the first two lines:

```auto
import pifacecad
import sys

```

So: who/what/where is this _pifacecad_? Is it a file or a directory?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [28 July 2020 04:12 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/10 "2020-07-28T04:12:46Z")

</div>

Is file that you must have installed when you installed the dependencies, right?

```auto
sudo apt-get install python{,3}-pifacecad

```

And it looks like it is installed for use with python3

Again, browse the .local directory, I believe you will find it there even if it's boring

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2020 04:15 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/11 "2020-07-28T04:15:42Z")

</div>

Nothing too exciting in there.

```auto
pi@PIFACE:~/.local $ ls
lib share
pi@PIFACE:~/.local $ ls -r | grep pifacecad
pi@PIFACE:~/.local $ 

```

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [28 July 2020 04:23 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/12 "2020-07-28T04:23:39Z")

</div>

Have you checked in /usr/local/lib

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2020 05:10 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/13 "2020-07-28T05:10:39Z")

</div>

Interesting.

```auto
pi@PIFACE:/usr/local/lib $ ls python3.4/dist-packages/
paho paho_mqtt-1.3.0.egg-info pifacecad pifacecad-2.0.8.egg-info pifacecommon pifacecommon-4.2.2.egg-info
pi@PIFACE:/usr/local/lib $ ls python3.4/dist-packages/pifacecad
core.py __init__.py ir.py lcd.py __pycache__ tools version.py
pi@PIFACE:/usr/local/lib $

```

```auto
pi@PIFACE:/usr/local/lib $ ls python2.7/dist-packages
mooltipy paho_mqtt-1.5.0.egg-info pifacecommon pifaceio.py pyusb-1.0.0b2.egg-info
mooltipy-1.0.0.egg-info pifacecad pifacecommon-4.2.2.egg-info pifaceio.pyc serial
paho pifacecad-2.0.8.egg-info pifaceio-1.25.egg-info pyserial-2.7.egg-info usb
pi@PIFACE:/usr/local/lib $ ls python2.7/dist-packages/pifacecad
core.py core.pyc __init__.py __init__.pyc ir.py ir.pyc lcd.py lcd.pyc tools version.py version.pyc
pi@PIFACE:/usr/local/lib $ 

```

A `pifacecad` directory in two of them but no actual `pifacecad` file.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 July 2020 06:07 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/14 "2020-07-28T06:07:12Z")

</div>

ARGH!

So `import pifacecad` is a pointer to the directory.

All the _commands_ are in the files below it.

Which is kind of good.

I found a heap of commands but didn't understand how/why they were there.

So there is a `lcd` file and it has all the commands for the LCD.

Again: Fine.

But how worrying is it when the commands listed there don't work?

I am bashing my head trying to position the cursor on the screen.  
It did work earlier on then stopped.

And why is it when I print something new on the screen, the screen is wiped before the new stuff is printed?

That should be evident in the command `print()` (say) and I would see that before it does that it does a `clear_screen()`.

Or something like that.

Yet, I seem to be chasing ghosts.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [28 July 2020 09:53 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/15 "2020-07-28T09:53:35Z")

</div>

To @krambriw, please see this response as well: [When running Python scripts, how to you set which version of Python is being used? - #4 by afelix](https://discourse.nodered.org/t/when-running-python-scripts-how-to-you-set-which-version-of-python-is-being-used/30810/4)

I read through the source code of this node earlier, both the python code as well as the JavaScript, and I can’t say I’m impressed by the code quality or how hardcoded the hacks are that make it work. Like the following line:

> [@Trying\_to\_learn](#):
>
> `text = msg.payload.replace(" ", "#/@$%");`

It’s giving me the shivers. The author of the node appears to not know of a better way to pass an argument containing spaces to a python program, so they replace every space with `"#/@$%"` on the JavaScript side, then on the python side replace it back with a space.  
Since the script is using python2 hardcoded and I haven’t seen any special code, I’m pretty sure it’s also going to crash if you try adding unicode characters, something as simple as a `ça va` in your text might crash the script/node.

---

<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:** [26 September 2020 09:53 UTC](https://discourse.nodered.org/t/piface-lcd-node-really-need-help-understanding-why-things-are-happening/30803/16 "2020-09-26T09:53:36Z")

</div>

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