Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pimatic-lcd] Development / Discussion / Usage #271

Open
koffienl opened this issue Sep 23, 2014 · 55 comments
Open

[pimatic-lcd] Development / Discussion / Usage #271

koffienl opened this issue Sep 23, 2014 · 55 comments

Comments

@koffienl
Copy link

Received my I2C 16x2 LCD today.
Took some time to get it working, but for now I can see status of a device on the LCD, directly controlled with pimatic :)

https://www.youtube.com/watch?v=t4Nu4YMaxwk

@sweetpi
Copy link
Contributor

sweetpi commented Sep 23, 2014

Very nice, do you share the script?

@koffienl
Copy link
Author

https://www.youtube.com/watch?v=zH_5zz72d30

Basicly I created a python script that split the arguments in 2 vars, and then display them as line1 and line2. No errorchecking at all for now.
From there it was easy, just create a ShellSwitch to execute the script.
Now also created a rule to display the temperature :)

Will post script tommorow

@leader21
Copy link
Contributor

looks very promising! 👍

@sweetpi
Copy link
Contributor

sweetpi commented Sep 23, 2014

I find it amazing myself how easily it is to do with pimatic without writing an plugin :D

Would be a good page for the guide :)

@koffienl
Copy link
Author

This is the python script I made:

from lcd_display import lcd
import sys

lines = str(sys.argv[1])

if lines == "off" :
  my_lcd = lcd()
  my_lcd.backlight_off();
  quit()

if lines.find('~')==-1 :
  lines = str.replace(lines, '_', ' ')
  lineslen = len(lines)

  if lineslen > 16 :
    lines = lines[0:16]

  my_lcd = lcd()
  my_lcd.display_string(lines, 1)
else :
  lines = str.replace(lines, '_', ' ')
  line1, line2 = lines.split('~', 1)

  line1len = len(line1)
  line2len = len(line2)
  if line1len > 16 :
    line1 = line1[0:16]

  if line2len > 16 :
    line2 = line2[0:16]

  my_lcd = lcd()
  my_lcd.display_string(line1, 1)
  my_lcd.display_string(line2, 2)

If the first argument only is the word 'off' the it will turn the backlight off.
If you need a space in the line, use a _ , it will be converted, If you need something on line 2, us a ~ to divide the arguments in 2 lines.
If a line is more than 16 characters, only the first 16 are used.

I used this lib : http://www.gejanssen.com/howto/i2c_display_2004_raspberrypi/index.html#mozTocId243378
I bought this LCD : http://www.ebay.com/itm/221439853893?_trksid=p2060778.m2749.l2648&ssPageName=STRK%3AMEBIDX%3AIT

@sweetpi
Copy link
Contributor

sweetpi commented Sep 24, 2014

@koffienl
Copy link
Author

Found it ;)

Examples :
sudo python lcd.py off Will turn the backlight off
sudo python lcd.py line_1 Wille display "line 1"
sudo python lcd.py line_1~line_2 Will display"line 1" and on the second "line 2"
sudo python lcd.py ~line_2 Will display "line 2" on only line 2

To continues display the temperature, use something like this:
IF $syssensor1.temperature != $prevtemp
THEN execute "sudo python /home/pi/i2c/lcd_test.py temperatuur:~$syssensor1.temperature" and after 2 seconds $prevtemp = $syssensor1.temperature

@sweetpi
Copy link
Contributor

sweetpi commented Sep 24, 2014

Very nice, can be used as long as nobody has developed a "native" plugin.

Another pro tip: Don't use <code>...</code>. Use just the "Fenced code blocks", I pointed to (much more readable imho).

@koffienl
Copy link
Author

@camillo777
Copy link

The pimatic shell script plugin is really awesome and could replace many other scripts and plugins!

@leader21
Copy link
Contributor

leader21 commented Oct 2, 2014

@koffienl : did you use a logic level converter to connect the display to the raspberry i2c or don't you need it?

@koffienl
Copy link
Author

koffienl commented Oct 2, 2014

Nope, you can directly connect it to the pi,thanks to the LCD I2C interface

@sweetpi
Copy link
Contributor

sweetpi commented Oct 2, 2014

I just put all into a gitrepo to have all together, also did some changes so that it worked probably with my 4x20 display: https://github.com/sweetpi/python-i2c-lcd

Maybe its usefull for someone.

I will continue to play with: https://github.com/wilberforce/lcd-pcf8574

@sweetpi
Copy link
Contributor

sweetpi commented Oct 3, 2014

I made the LCD-node module pimatic ready: https://github.com/sweetpi/i2c-lcd
@koffienl: Could you test if it is working with you LCD as well?

@koffienl
Copy link
Author

koffienl commented Oct 3, 2014

Cool, I will try some. Not sure where and how to start yet :)

@sweetpi
Copy link
Contributor

sweetpi commented Oct 3, 2014

npm install i2c-lcd
cd i2c-lcd
node ./lib/test.js

@koffienl
Copy link
Author

koffienl commented Oct 3, 2014

Yes, it works :)
Allthough it takes a second or 2 to get some text, but I guess that is due to node.je and would not be the issue when running in pimatic?

@sweetpi
Copy link
Contributor

sweetpi commented Oct 3, 2014

Great, yes, I think its the startup time of node (JavaScript just-in-time compilation).

@sweetpi
Copy link
Contributor

sweetpi commented Oct 3, 2014

@koffienl
Copy link
Author

koffienl commented Oct 4, 2014

Very nice!
Will test as soon as I return later this day

@koffienl
Copy link
Author

koffienl commented Oct 4, 2014

Confirmed working, great job! Awesome

Noticed that all the characters that don' fit are lost. Maybe you can make line scroll when it is more then the characers that fit?

@sweetpi
Copy link
Contributor

sweetpi commented Oct 4, 2014

Thanks, I had the same idea :)

@koffienl
Copy link
Author

koffienl commented Oct 4, 2014

This is really really cool. Hope to finish some working stuff today where my LED pushbuttonns and LCD will all work together in pimatid :)

@leader21
Copy link
Contributor

leader21 commented Oct 5, 2014

actually i'm having a little time to play around with the pimatic-lcd plugin, but having an issue with the pimatic-lcd plugin. my lcd is a 1602 with adress 0x27 as i2cdetect confirms. the test.js output shows "raspberry pi" and switches to date and time. so i guess, this is all correctly installed.
so when i try to set up a rule with pimatic, i have some errors. please have a look at the links below (sorrry something's not working with the picture upload at the moment)
http://www.youscreen.de/qlhfw72-pimatic-lcd-test-1.jpg
http://www.youscreen.de/qvpnl15-pimatic-lcd-test-2.jpg

do i need to set the i2c adress of the display somewhere in the scripts or where could be the mistake?

@sweetpi
Copy link
Contributor

sweetpi commented Oct 5, 2014

Pushed a update and published pimatic-lcd 0.8.2, which should fix the issue. I handled the case, that the text is too long to be displayed (cut-off) and the case that is is to short (pad with space), but did forget the case, where it fits exactly (just use the text!) :D.

@leader21
Copy link
Contributor

leader21 commented Oct 5, 2014

got it to work!! my fault - just forgot to add user pi to i2c group, that did the job ...
allright, then I'll start messing around a bit on the bluescreen ^^

@leader21
Copy link
Contributor

leader21 commented Oct 5, 2014

hm... just wondering how to get this to work : having a switch connected to a lamp. how can i display a text on the lcd that shows "lamp on" or "lamp off" when switched?
tried with a simple rule IF $pilight.funkdose1.state is switched on THEN display "lamp on" on lcd line 2 for 5 seconds
but this rule won't be accepted since "is switched on" won't be recognised by the rule management...

@sweetpi
Copy link
Contributor

sweetpi commented Oct 5, 2014

IF pilight.funkdose1 is switched on THEN display "lamp on" on lcd line 2 for 5 seconds

Do you have really a "." in your id? :D

should work, see: http://pimatic.org/guide/usage/rules/

@leader21
Copy link
Contributor

leader21 commented Oct 5, 2014

puuh ... sorry, thing i need to wake up now ;) sure it's pilight-funkdose1 ! thanks for your patience ^^
very good job!! works perfectly!

@leader21
Copy link
Contributor

leader21 commented Oct 5, 2014

you should change the title of this issue to pimatic-lcd support for leader ^^
short question - i am switching the LCD backlight on and off within every rule like this :
IF ... THEN turn LCD backlight on and display "Device switched on" on lcd line 2 for 15 seconds and turn LCD backlight off after 16 seconds
isn't there some easier way to turn the LCD backlight on and off maybe automatically? if you're having a time period in rules like display text for x minutes, the backlight should turn on and off itself imho. the rule itself won't be so complex for this relative simple task anymore then.

@leader21
Copy link
Contributor

leader21 commented Oct 5, 2014

just tried with IF ... THEN turn LCD on and display "Switched on" for 15 seconds and turn LCD off after 16 seconds seems to be the same as turn turn LCD backlight on / off. there's no difference for me.

@koffienl
Copy link
Author

koffienl commented Oct 5, 2014

OK, then there should be a check in the plugin to allways turn on the LCD/backlight when displaying text :)

@leader21
Copy link
Contributor

leader21 commented Oct 6, 2014

as i wanted to update to pimatic-lcd 0.8.2 via gui i received this error information :
http://www.youscreen.de/cwgoa42-pimatic-lcd-update.jpg

@sweetpi
Copy link
Contributor

sweetpi commented Oct 6, 2014

OK, then there should be a check in the plugin to allways turn on the LCD/backlight when displaying text :)

I'm using the turn off and on in another way. I want to have it turned on when I'm sitting in front of it and turned of if I'm away, so I need to have explicit control over off and on (the lcd displays constantly informations). I will think about adding a "auto-mode" for the lcd backlight.

as i wanted to update to pimatic-lcd 0.8.2 via gui i received this error information :

You can't update "git cloned" modules with npm. Run "git pull" inside the module or remove the module and restart pimatic to fetch the npm registry version.

@leader21
Copy link
Contributor

leader21 commented Oct 6, 2014

sorry, didn't know about that, thought it was an issue to the update system, since pimatic-lcd is relatively new.
anyway i was up to update manually and removed the pimatic-lcd directory and restarted. all's good now.

@koffienl
Copy link
Author

koffienl commented Oct 6, 2014

This is really really cool. Hope to finish some working stuff today where my LED pushbuttonns and LCD will all work together in pimatic :)

Finally got some stuff working: https://www.youtube.com/watch?v=xKKDnquih-0

What it does: I have a pushbutton (no physical on/off state) and a fake device (a variable). When the device is ON, the LED is full on, and the LCD displays it is on.
When the button is pushed while on: the LED ring fades to off, the LCD displays OFF and the device is turned to off. When pushed again, it will glow to full state, display ON on the LCD and switch the fake device to on.

The goal on this setup is, that the switch is not physical connected to something, only to pimatic. So you can use the button to switch a device on or off, but the device could also be switched on/off from rules or with the GUI.
The display and LED ring should reflect the state of the deivce, so when a rule turns the device off, the LED ring will fade out (and allows you to turn it back to on by pressing the button again).

@leader21
Copy link
Contributor

leader21 commented Oct 6, 2014

that's a very interesting and promising idea!

@koffienl
Copy link
Author

koffienl commented Oct 6, 2014

Added a cool idea to the setup ;)

When you press the button for at least 2 seconds, the LED ring wil blink 4 times (so you now the long press is detected) and it will turn the device on for xx time.
Offcourse you could let it do anything with the long press, but I needed something to turn it on/off and let the device run for a specific time.
Build in extra validation, so the long press (and blinking) only works when the device is allready off.

@sweetpi sweetpi changed the title Now this is getting cool :D [pimatic-lcd] Development / Discussion / Usage Oct 8, 2014
@leader21
Copy link
Contributor

there's one really annoying thing. everytime i do a reboot the lcd lights up and stays lighted until it is triggered from pimatic via rule. (can this be confirmed by anyone?)
would it be possible to check at pimatic startup if a pimatic-lcd is installed and a lcd is connected? maybe pimatic can display something like "Pimatic starting ..." during the startup process , the lcd will clear and the backlight will turn off after a while.

@sweetpi
Copy link
Contributor

sweetpi commented Oct 11, 2014

A condition for IF pimatic has started THEN ... would solve the problem, because you could make a rule or?

@koffienl
Copy link
Author

Would be really nice to have a option to detect if pimatic just has been started

@leader21
Copy link
Contributor

OMG! it's so simple ... ;) thanks for this hint!! it seems to work

@sweetpi
Copy link
Contributor

sweetpi commented Oct 11, 2014

OMG! it's so simple ... ;) thanks for this hint!! it seems to work

ehh what? I did not implement it yet...

@koffienl
Copy link
Author

Would like to add a suggestion : Add a option to rules it they are permitted to run upon starting pimatic. With that option you put the load for one time at the framework instead of changing a lot of rules and adding it to the cron plugin.

Asking this option has been on my whishlist, but hadn't much prio :)

@leader21
Copy link
Contributor

I solved my problem with a workaround using ping plugin. If raspberry-pi is present then display pimatic has started for 60 seconds. I put this rule on top of the rules list. Otherwise some other rule containing display text would overwrite the display output. That did the Job. Sure, an option for if pimatic has started would be better and could be usefull

@sweetpi
Copy link
Contributor

sweetpi commented Oct 11, 2014

I solved my problem with a workaround using ping plugin. If raspberry-pi is present then display pimatic has started for 60 seconds. I put this rule on top of the rules list. Otherwise some other rule containing display text would overwrite the display output. That did the Job. Sure, an option for if pimatic has started would be better and could be usefull

Cool idea.

@koffienl
Copy link
Author

Reminder : if you want to use this plugin, edit you /etc/modules and add the following 2 lines:

i2c-bcm2708 
i2c-dev

After a reboot you can use your LCD.

@Thanquol
Copy link

Hello everyone,

i'd like to post the temperature on my 4x20 LCD.

i2cdetect detects the LCD at /dev/i2c-1 0x27
the example-script python2 ./display.py line_1line_2line_3~line_4 works fine

Than i created a rule:
IF $pilight-Beet1-temperature.temperature changes
THEN display "BLA" on lcd line 1

-> just gives me the error:
Error on evaluation of rule condition of rule test: Cannot write to device
[/code]

What am i doing wrong?

Thanks a lot,
Florian

@leader21
Copy link
Contributor

did you install the lcd plugin?
use this code at the plugin section to install and use it.
but first stop the pimatic daemon, edit the config.json and restart again.

    {
      "plugin": "lcd",
      "bus": "/dev/i2c-1",
      "rows": 4,
      "cols": 20
    },

after that you should be able to use the lcd like you have described above.
if it does not work, go to the pimatic/node_modules directory and delete the pimatic-lcd directory and restart pimatic. the plugin will be reinstalled then.

good luck!

@Thanquol
Copy link

Awesome!!!

Deleting the pimatic-lcd folder and restarting the service did the trick!

Thanks a lot :-)

@sweetpi sweetpi closed this as completed Jan 27, 2015
@sweetpi sweetpi reopened this Jan 27, 2015
@Thanquol
Copy link

And another question:

if i'm displaying something like
display "Status: $Heizmatte1.state" on lcd line 1
the output on the display is: --Status: true--
can i modify the output to -- Status: on-- ?

@Icesory
Copy link
Contributor

Icesory commented Jan 27, 2015

make a rule like this
if Heizmatte1.state is true and ... then display "Status: an/on/eingeschaltet/etc."
and a second rule for the off state

@Thanquol
Copy link

sometimes the easiest solutions are the best....
Thanks :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants