PiFace_LCD node - really need help understanding why things are happening

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

This is more about the actual node.
The node code

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.

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:

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:

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:

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")

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)

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

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?

No, in here I am a Node-RED user

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

Original author at github? He may help?

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.

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

Try to look there

This is the first two lines:

import pifacecad
import sys

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

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

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

Nothing too exciting in there.

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

Have you checked in /usr/local/lib

Interesting.

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 $
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.

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.

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

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:

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.

1 Like

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