LCD2004

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
remko2000
Normal user
Posts: 68
Joined: 28 Dec 2017, 15:56

LCD2004

#1 Post by remko2000 » 29 Sep 2020, 16:06

I connected an LCD2004 to a wemos d1 to show the info from a connected sensor (Z19b). I connected the display and the sensor to the 5V of the wemos (usb powered).
Some how the display went off after 2 minutes. I want it to stay on. I set Display Timeout: to 6000 secondes.
I use espversion mega-20190225. How do I set this to 'never out' ?

TD-er
Core team member
Posts: 4932
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#2 Post by TD-er » 29 Sep 2020, 16:34

Based on the (current) source code, if you set the timeout to 0, it would disable this feature.
So if that doesn't work on your build, you may want to check a more recent build.

remko2000
Normal user
Posts: 68
Joined: 28 Dec 2017, 15:56

Re: LCD2004

#3 Post by remko2000 » 29 Sep 2020, 17:35

yes! that does the job. Thx

remko2000
Normal user
Posts: 68
Joined: 28 Dec 2017, 15:56

Re: LCD2004

#4 Post by remko2000 » 10 Oct 2020, 09:31

I'm wondering, is there also a possibility tot connect a reset button by which I wake up my lcd (so I can read the values) and after some time the LCD fells ' in sleep' (I don't want to see the whole time a blue screen). How do I connect this reset button?

TD-er
Core team member
Posts: 4932
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#5 Post by TD-er » 10 Oct 2020, 12:42

Just looking at the code of the LCD plugin, I would think it is able to set a GPIO pin as a "Display Button" and also a "Display Timeout".

If that pin is pulled to GND, it will start a backlight timer, which will automatically turned off after set nr of seconds.

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#6 Post by bonti69 » 03 May 2021, 15:51

Nice feature "Display button". A push button to activate the backlight for few seconds...
"If that pin is pulled to GND, it will start a backlight timer, which will automatically turned off after set nr of seconds."
Now starts the troubles: yes,the digital input usually has some pullup resistor to 3.3v, internal or external. Well, I tried to use some PIR sensor connected to some gpio ,to wake-up the display when someone is around. The problem is the PIR digital output is a positive pulse, when is no movement the output is low, tied to ground, when detects movement, the output goes high...In this hardware connection,the "Display button" is most of the time low, so LCD backlight is on,never goes off.
If the gpio is declared as "switch input" and "Inversed Logic:" is enabled, the "value" state of the switch is inversed, but not working as "Display button"..."switch to ground will wake the LCD"...Is there any way to use those pir sensors without a hardware inverter? ( a npn transistor,between pir and esp8255 gpio or any other solution...).It would be useful an option to choose for gpio assigned as "Display button", positive or negative pulse, positive or negative edge, or "Inversed Logic" feature,in the LCD menu...

TD-er
Core team member
Posts: 4932
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#7 Post by TD-er » 03 May 2021, 15:59

To summarize:
The plugin should have an "inverted" option for that GPIO pin, as have numerous other plugins in ESPEasy.

TD-er
Core team member
Posts: 4932
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#8 Post by TD-er » 03 May 2021, 16:01

For now (until it has been fixed, just added an issue for it on GitHub) you could try to do it in rules.
Just "monitor" the pin in the rules and start a timer based on the movement.
When setting the timer you can give the command to turn on the backlight.
As soon as the timer has expired, you can give the command to turn off the light.

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#9 Post by bonti69 » 03 May 2021, 16:59

Yes, sir...
"Inverted logic" should be the simple and effective way for LCD display timeout, related to the state of one gpio assigned to wake up the backlight...making easier direct connection with a cheap pir motion sensor, or some touch sensor like this: https://alltopnotch.co.uk/product/ttp22 ... e-arduino/
I agree it can be done via rules, easily...thank you
At the beginning was a rule,indeed, light up on every minute, for 5 seconds
on Clock#Time=All,**:** do
lcdcmd,on
timerSet,1,5
endon
on Rules#Timer=1 do
lcdcmd,off
endon

I hope those little capacitive touch buttons can be modded via two soldered jumpers, to interface directly,but on PIR sensors ,no way...
TTP223-Mini-Red-Capacitive-Touch-Switch-Button-Self-lockNo-lock-Module-Arduino-232685837837-4.JPG
TTP223-Mini-Red-Capacitive-Touch-Switch-Button-Self-lockNo-lock-Module-Arduino-232685837837-4.JPG (213.79 KiB) Viewed 3218 times

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#10 Post by Ath » 03 May 2021, 22:31

I've created PR #3620 to enable your feature request. You can download a bin file from that link by getting the Binaries.zip file from the build-list at the bottom of that page (click on a Details link, look at the right side of that page for the 'Artifacts' dropdown)

Please report your findings here.
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#11 Post by bonti69 » 05 May 2021, 09:46

Suppose we have a LCD2004 display connected to a device.We have 4 rows available for some text. Let's say task1 is a task where LCD displays temperature,pressure,humidity. On same device we have connected a current sensor Energy (DC) - INA219. This sensor reports Voltage,Current,Power. Now we create Task2, Display - LCD2004, same display, where we can see the voltage,current,power. Now we connect an hardware switch, retained, when switch is on 0, task 1 is enabled,display show temperature,pressure,humidity when switch is 1,task 1 is disabled,task2 is enabled, the display will show voltage,current,power. Can be done with some rule? somehow?

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#12 Post by Ath » 05 May 2021, 09:59

Hi,

The LCD2004 plugin is fully multi-instance aware. You can have as many connected as long as memory of the ESP will handle.
If you need to have a separate Display Button for each, just use a different GPIO for each display/button combination.

When sending commands to a specific LCD, you must (and always can) prefix the command with the "[taskname]." prefix, so if you have a LCDTEMP and LCDPOWER defined, your commands, either from rules or via http, should be [lcdtemp].lcdcmd,on, or [lcdpower].lcd,4,1,"[INA219#Volt] V"

If you do not prefix with the taskname. moniker (square braces are optional) the command will be sent to the first display device found (from top to bottom) that handles the command, then stops.
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#13 Post by bonti69 » 05 May 2021, 10:14

Ath wrote: 03 May 2021, 22:31 I've created PR #3620 to enable your feature request. You can download a bin file from that link by getting the Binaries.zip file from the build-list at the bottom of that page (click on a Details link, look at the right side of that page for the 'Artifacts' dropdown)

Please report your findings here.
Sorry, please be more specific: how can update the plugin?...or what has to be done?

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#14 Post by Ath » 05 May 2021, 10:41

bonti69 wrote: 05 May 2021, 10:14
Ath wrote: 03 May 2021, 22:31 I've created PR #3620 to enable your feature request. You can download a bin file from that link by getting the Binaries.zip file from the build-list at the bottom of that page (click on a Details link, look at the right side of that page for the 'Artifacts' dropdown)

Please report your findings here.
Sorry, please be more specific: how can update the plugin?...or what has to be done?
- Open the link to the PR
- Select the "Checks" tab (between "Commits" and "Files changed")
- Open the Artifacts dropdown on the right side of that page (just above the big black section)
- Download the Binaries.zip file (549 MB !)
- Open that zip and select the configuration you would want to upload to your ESP, can be the same as you used before. It is 'hidden' inside a .zip with the same name. (Former test/TESTING builds are split into test_A..test_D, but this plugin is in nearly all builds as it is in the stable plugin set).
- Upload that .bin file to your ESP
- Please test the 'Inversed logic' option, now available on the Device Configuration page for the LCD2004 (when enabled, the GPIO pin should be made high (3.3V) to turn the display on).
- Report your findings here after testing, please, thank you very much.
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#15 Post by bonti69 » 05 May 2021, 11:47

Thank you,Ath
I'm stuck here,sorry
I don't know how to download firmware.bin
"Open the Artifacts dropdown on the right side of that page (just above the big black section)"
Sorry again
I have to sign in to github,maybe ?
Attachments
Screenshot_2021-05-05 [P012] Add Inversed option for display button by tonhuisman · Pull Request #3620 · letscontrolit ESPE[...].png
Screenshot_2021-05-05 [P012] Add Inversed option for display button by tonhuisman · Pull Request #3620 · letscontrolit ESPE[...].png (51.36 KiB) Viewed 3119 times

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#16 Post by Ath » 05 May 2021, 12:12

Ah, you probably need to create & login with a Github account to be able to see that option. (I'm always logged in to Github so I can see that link, sorry.)
Edit: Hm, I can only see that for my own PR's.

If you give the filename of the .bin file you need I can extract it for you and attach here
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#17 Post by bonti69 » 05 May 2021, 13:22

It's a wemos D1 R2 loaded with ESP_Easy_mega_20210223_normal_ESP8266_4M1M

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#18 Post by Ath » 05 May 2021, 14:10

Attached is the ESP_Easy_mega_20210504_normal_ESP8266_4M1M.bin file, as .zip packaged by Github (it's in a subdir of a subdir)
Last edited by Ath on 05 May 2021, 21:29, edited 1 time in total.
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#19 Post by bonti69 » 05 May 2021, 18:01

Inversed logic appears but not remain enabled after activation...
Screenshot_2021-05-05 ESP_Easy_WemosD1R2.png
Screenshot_2021-05-05 ESP_Easy_WemosD1R2.png (51.75 KiB) Viewed 3083 times

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#20 Post by bonti69 » 05 May 2021, 18:18

bonti69 wrote: 05 May 2021, 09:46 Suppose we have a LCD2004 display connected to a device.We have 4 rows available for some text. Let's say task1 is a task where LCD displays temperature,pressure,humidity. On same device we have connected a current sensor Energy (DC) - INA219. This sensor reports Voltage,Current,Power. Now we create Task2, Display - LCD2004, same display, where we can see the voltage,current,power. Now we connect an hardware switch, retained, when switch is on 0, task 1 is enabled,display show temperature,pressure,humidity when switch is 1,task 1 is disabled,task2 is enabled, the display will show voltage,current,power. Can be done with some rule? somehow?
No, I don't want to use 2 (two) LCD 2004, unless I have no option...Most of the time the LCD will display temperature,pressure,humidity. With INA219 connected I want to measure the power consumption of my environment devices: routers,ipcamera,switches,anything is plugged to mains and demand power...So, with a simple switch, *-* * or * *-* ,and two different alternative tasks, I will deactivate lcd with t,h,p sensor and activate lcd with current/voltage/power when I want to make some current/voltage measurement. Just a rule : on switch#state=0 enable task1 disable task2 endon ... on switch#state=1 disable task1 enable task2 endon ...something like that
later edit:
on switch#state=1 do
TaskEnable,task 5
TaskDisable,task 8
endon
on switch#state=0 do
TaskEnable,task 8
TaskDisable,task 5
endon

this don't work, displays data from both tasks
Solved: synthax error:
on switch#state=1 do
TaskEnable,5
TaskDisable,8
endon
on switch#state=0 do
TaskEnable,8
TaskDisable,5
endon

Bingo!
With a simple switch, two tasks on same LCD, more parameters can be displayed...otherwise two displays it would have been needed. Especially when second task is used occasionally...
Some troubles: LCD enter in some loop , device hang
If an output state is used to switch between the tasks, works perfectly...
on output0#out0=0 do
TaskEnable,5
TaskDisable,8
endon
on output0#out0=1 do
TaskEnable,8
TaskDisable,5
endon


Works, the "interval" was set to 1 sec, modified to 100 and works with a hardware switch,bistable.
MANDATORY!
Separate Switch input - Switch ❔ in two categories: digital input(switch,pushbutton) and digital output (on/off-relay or pwm/dimmer)
Clarify what "interval" means...
interval.png
interval.png (5.59 KiB) Viewed 3062 times

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#21 Post by Ath » 05 May 2021, 21:28

I made a typo in the settings, causing it not to be saved, sh*t happens.
New build (local) attached here.

NB: What's stopping you from keeping all 4 values on the display? It seems to fit just nicely.
Attachments
ESP_Easy_mega_20210505_normal_ESP8266_4M1M.zip
(603.88 KiB) Downloaded 23 times
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#22 Post by bonti69 » 05 May 2021, 22:00

Works now, inversed logic...taadaaa
Thank you,great job
Meantime,playing with LCD2004, came to me the idea to frame this nice display,via some command... like I already said, measurement of voltage/current/power is occasionally,not constant monitoring...
Something like that:
WhatsApp Image 2021-05-05 at 22.47.30.jpeg
WhatsApp Image 2021-05-05 at 22.47.30.jpeg (92.82 KiB) Viewed 3055 times
WhatsApp Image 2021-05-05 at 22.47.05.jpeg
WhatsApp Image 2021-05-05 at 22.47.05.jpeg (86.11 KiB) Viewed 3055 times
By the way, LCD2004 supports some scrolling?

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#23 Post by Ath » 05 May 2021, 22:18

bonti69 wrote: 05 May 2021, 22:00 Works now, inversed logic...taadaaa
Thank you,great job
Great, thanks for the feedback!
bonti69 wrote: 05 May 2021, 22:00 Meantime,playing with LCD2004, came to me the idea to frame this nice display,via some command... like I already said, measurement of voltage/current/power is occasionally,not constant monitoring...
You should be able to that using rules.
In pseudo-code:

Code: Select all

every second:
  count up by 1
  if count = 5
    flip a state
    if state = 1
      display 1st set of data
    else
      display 2nd set of data
    endif
    reset count
  endif
  display time on line 4
bonti69 wrote: 05 May 2021, 22:00 By the way, LCD2004 supports some scrolling?
Nope, unless that would be added to the code, or, again, by using some (rather complex, I'd expect,) rules.
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#24 Post by bonti69 » 05 May 2021, 22:21

Next project for LCD2004:
Dimming the backlight
On my display unit the backlight is driven from Vcc (5V) via a jumper to collector of a npn transistor with emitter grounded. The transistor base is driven from PCF 8574T via I2C (software on/off backlight)
Like this:
Zz5D5.jpg
Zz5D5.jpg (33.57 KiB) Viewed 3049 times
With another external transistor, collecter connected in parallel with the original,emitter to ground and with base connected to an available gpio of esp8266, configured as dimmer, maybe possible to create some effects like backlight proportional with illumination, dimming backlight to shut off etc.

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#25 Post by bonti69 » 05 May 2021, 22:34

You should be able to that using rules.
In pseudo-code:

Code: Select all

every second:
  count up by 1
  if count = 5
    flip a state
    if state = 1
      display 1st set of data
    else
      display 2nd set of data
    endif
    reset count
  endif
  display time on line 4
Sounds interesting with display 1st set of data and display 2nd set of data. Maybe you can develop further the plugin, my knowledge on programming is very limited...My method with two different task has a drawback, when changes the display, LCD2004, reload all data and black-out for a second ,displays "EspEasy" shortly, then come the final image...Go further, for you it's a piece of cake, two sets of data in the plugin...available when needed, moreover no hope for scrolling...

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#26 Post by bonti69 » 07 May 2021, 11:22

Improvement:
Connected hardware to esp:
one gpio assigned to a momentary pushbutton(active high)-gpio16
one LCD2004
one bme280 temp,humidity,pressure sensor
one ina219 voltage,current,power
Task on espeasy:
bme /task 6
ina /task 7
lcdtemp /task 5 (display LCD2004 with temperature,pressure,humidity on display from bme sensor),display button gpio16,display timeout 15
lcd power task 8 (display LCD2004 with voltage,current,power from ina sensor), display button gpio16, display timeout 60
What we want:
Short press on pushbutton wake up the lcd (lcdpower and lcdtemp are complementary,when one is enabled the orher is disabled)
Longpress on gpio16 toggle enable lcdtemp,disable lcdpower, next longpress disable lcdtemp,enable lcdpower and so one...
For the moment we set a rule to activate lcdpower for 60s or 120s ,on longpress, to make some measurement, after that lcd will revert to lcdtemp. Shortpress will wake the lcdtemp for 15s,display timeout...
How can be enable task5/disable task8 on longpress , then enable task8/disable task5 on next longpress ?
Is there a value for a task that indicates the task is enabled(1) or disabled (0) ?

Code: Select all

on switch#state=11 do  //longpress enable lcdpower
TaskEnable,7
TaskEnable,8
TaskDisable,5
timerSet,2,120
endon
on Rules#Timer=2 do
TaskEnable,5
TaskDisable,8
TaskDisable,7
endon

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#27 Post by Ath » 07 May 2021, 13:45

As I said before, I'd choose another solution, enabling and disabling tasks gives the ESPEasy logo stuff as the plugin is completely re-initialized when enabled.
Instead you should send the desired data to the display from the rules, as I sketched before. In general the command to send data there is 'LCD,<line>,<column>,"Text with [task#value]"' and you can optionally clear the display using the 'LCDCMD,clear'.
/Ton

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#28 Post by Ath » 07 May 2021, 20:57

- You only need a single LCD2004 task, no predefined lines values
- The Display button can be configured as desired, as well as the timeout (should be a multiple of 2 x the count (=10 sec) so both value sets are shown)

Code: Select all

on system#boot do
  loopTimerSet,3,1 // Start the 1 sec. timer
endon

on rules#timer=3 do // every second
  let,1,%v1%+1 // count up by 1
  if %v1% = 5 // Switch every 5 seconds
    let,1,0 // reset count
    let,2,=!%v2% // flip state
    if %v2%=1
      // display 1st set of data
      LCD,1,1,"Temperatura : [bpm#temperature#d3.2]"
      LCD,2,1,"Barometru :  [bpm#pressure#d4.2]"
      LCD,2,1,"Temp-ext :    [bpmext#temperature#d3.2]"
    else
      // display 2nd set of data
      LCD,1,1,"Power :     [ina#power#d3.2]"
      LCD,2,1,"Curent :     [ina#current#d2.3]"
      LCD,2,1,"Voltage :    [ina#voltage#d3.2]"
    endif
    LCD,4,1,"System time %systime%" // display time on line 4
  endif
endon
NB: Untested, I don't own such display
NB2: Might need some small adjustment to align the values correctly
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#29 Post by bonti69 » 07 May 2021, 22:23

Thanks for suggestions...
I understand now, no need for two LCD task, each of them with own sets of text/values, just send directly to LCD, the content of Line text. Needs more skil to manage rules,timers,variables etc...If I understand well. your code display 1st set of data for 5s then display 2nd set of data for another 5s and so on.
Now let's involve a pushbutton on gpio16, for example
Short press will wake up the lcd, used as display button,with 10sec display timeout .
Now ,using longpress via rules, pressing button for 2s, will display 1st set of data, until another 2s press will display 2nd set of data...
Please try the code...or correct my attempt

on switch#state=1 do // start push the button
timerSet,3,2 //start 2s timer
on rules#timer=3 do //after 2s
if switch#state=1 // check if still the button is pressed
let,2,=!%v2% // flip state
if %v2%=1
// display 1st set of data
LCD,1,1,"Temperatura : [bpm#temperature#d3.2]"
LCD,2,1,"Barometru : [bpm#pressure#d4.2]"
LCD,3,1,"Temp-ext : [bpmext#temperature#d3.2]"
else
// display 2nd set of data
LCD,1,1,"Power : [ina#power#d3.2]"
LCD,2,1,"Curent : [ina#current#d2.3]"
LCD,3,1,"Voltage : [ina#voltage#d3.2]"
endif
endon

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#30 Post by Ath » 08 May 2021, 14:20

NB: it would be more readable if you wrapped your code fragments in [ code ] [/ code ] tags (without the spaces), using the '</>'button in the toolbar above the forum editor

I've implemented as you requested:

Code: Select all

on switch#state do // every button press
  logentry,"Switch state %eventvalue%"
  if %eventvalue% = 1 // short press
    if %v1%=0 // Only if not on, if already on, extend on-time with another 10 seconds
      let,1,=!%v1% // flip state
    endif
    if %v1%=1
      lcdcmd,on
      TimerSet,3,10 // after 10 seconds turn off
    endif
  endif
  if %eventvalue% = 11 // Long press
    let,2,=!%v2% // flip mode
    if %v2%=1
      // display 1st set of data
      LCD,1,1,"Temperatura : [bpm#temperature#d3.2]"
      LCD,2,1,"Barometru :  [bpm#pressure#d4.2]"
      LCD,2,1,"Temp-ext :    [bpmext#temperature#d3.2]"
    else
      // display 2nd set of data
      LCD,1,1,"Power :     [ina#power#d3.2]"
      LCD,2,1,"Curent :     [ina#current#d2.3]"
      LCD,2,1,"Voltage :    [ina#voltage#d3.2]"
    endif
    LCD,4,1,"System time %systime%" // display time on line 4
    // turn display on for at least 10 more seconds
    lcdcmd,on
    TimerSet,3,10 // after 10 seconds turn off
  endif
endon

on rules#timer=3 do
  lcdcmd,off
  let,1,0 // state to off
endon
- Do not set a Display button (None)
- Do not set a Display Timeout value (0)
- Configure your button between 3.3V and GPIO 16 (D0), as a Switch, with these settings:
Screenshot - 08_05_2021 , 14_17_48.png
Screenshot - 08_05_2021 , 14_17_48.png (26.44 KiB) Viewed 2901 times
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#31 Post by bonti69 » 08 May 2021, 23:23

Thank you ,Ath
I'll try tomorrow the code
When you are deep involved in programming, you can do exactly what you want, on the shortest way. Unfortunately, I'm a beginner and my way is to squeeze out what the plugins can offer at the present time.More versatile the plugin is,more and various applications can be achieved,affordable to average user,with webUI configuration mostly...
You are involve in developping LCD plugin somehow?...or just crossing roads,accidentally
Thank again,kudos

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#32 Post by Ath » 09 May 2021, 10:31

bonti69 wrote: 08 May 2021, 23:23 You are involve in developping LCD plugin somehow?...or just crossing roads,accidentally
I've been involved in software development for over 35 years, and been using ESPEasy since about 3 years. Last year I started getting involved in developing improvements to several plugins and other features, resulting now in adding new plugins and features as well.
I'm not particularly involved in the LCD plugin, just picked up this small feature request, as TD-er is quite busy with other big projects.
Trying to add useful improvements where I can, just because I can and I like it :D
/Ton

TD-er
Core team member
Posts: 4932
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#33 Post by TD-er » 09 May 2021, 11:55

"Just because I can" is the best reason :)

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#34 Post by bonti69 » 09 May 2021, 13:56

Seems like Netherland is "ground zero" for ESP, also tasmota is born there...keep on walking

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#35 Post by bonti69 » 09 May 2021, 14:43

one small step for man one giant leap for mankind
Code works...but needs minor improvement
1.On power on the LCD displays only ESP Easy, until first longpress,after that displays first set of data...
2.Even the "interval" for LCD2004 plugin is set to 1s, the time is loaded only once,after longpress, then remain frozen...maybe all values are not refreshed,yes,checked... the values are loaded on longpress and remains unchanged forever,even the shortpress have no effect.
This is the code copy-paste from my device, with small corrections:

Code: Select all

on switch#state do // every button press
  logentry,"Switch state %eventvalue%"
  if %eventvalue% = 1 // short press
    if %v1%=0 // Only if not on, if already on, extend on-time with another 10 seconds
      let,1,=!%v1% // flip state
    endif
    if %v1%=1
      lcdcmd,on
      TimerSet,3,10 // after 10 seconds turn off
    endif
  endif
  if %eventvalue% = 11 // Long press
    let,2,=!%v2% // flip mode
    if %v2%=1
      // display 1st set of data
      LCD,1,1,"Temperatura :  [bmp#temperature]"
      LCD,2,1,"Barometru :  [bmp#pressure]"
      LCD,3,1,"Temp-ext :    [ds#temp]"
    else
      // display 2nd set of data
      LCD,1,1,"Power :       [ina#power]"
      LCD,2,1,"Curent :      [ina#current]"
      LCD,3,1,"Voltage :      [ina#voltage]"
    endif
    LCD,4,1,"System time %systime%" // display time on line 4
    // turn display on for at least 10 more seconds
    lcdcmd,on
    TimerSet,3,10 // after 10 seconds turn off
  endif
endon

on rules#timer=3 do
  lcdcmd,off
  let,1,0 // state to off
endon
The time problem can be solved easily by seting Line4 in the lcd plugin: System time %systime%, interval 1s... ok,working
More request: timeout for 2nd set of data want to be 60s, when I maka the current/power measurement
The 2nd set of data loaded every second or two,when I make the measures I want to see values quick
Like I said, Power measures are singular events, as needed to measure consumption, more of, The Ina plugin should be enabled during the measurement,after that ,no need to monitor anything,no mqtt,no database...

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#36 Post by bonti69 » 09 May 2021, 15:11

Da capo:
Connected hardware to esp:
one gpio assigned to a momentary pushbutton(active high)-gpio16
one LCD2004
one bme280 temp,humidity,pressure sensor
one ina219 voltage,current,power
Task on espeasy:
bme /task 6
ina /task 7
lcdtemp /task 5 (display LCD2004 with temperature,pressure,humidity on display from bme sensor),display button gpio16,display timeout 15
lcdpower task 8 (display LCD2004 with voltage,current,power from ina sensor), display button gpio16, display timeout 60

Code: Select all

on switch#state=11 do  //longpress enable lcdpower
TaskEnable,7  //enable ina
TaskEnable,8  //enable lcdpower
TaskDisable,5  //disable lcdtemp
timerSet,2,120  // 2minutes to make measurements
endon
on Rules#Timer=2 do  //after 2minutes revert to lcdtemp
TaskEnable,5  //enable lcdtemp
TaskDisable,8  //disable lcdpower
TaskDisable,7  //disable ina, don't need it anymore
endon
lcdtemp.png
lcdtemp.png (46.22 KiB) Viewed 2804 times
lcd power.png
lcd power.png (45.6 KiB) Viewed 2804 times
switch.png
switch.png (57.28 KiB) Viewed 2804 times
Works perfectly,displays time&data every second,you have 2 minutes for power measurement ,cannot switch back to temp&pressure readings, via longpress...I tried to use doubleclick instead and is ok, just some mindtwisted to use longpress AND doubleclick, in my opinion
KISS (keep it simple...)
Bingo,I do it myself,with your help:

Code: Select all

on switch#state=11 do  //longpress enable lcdpower
let,2,=!%v2%   // flip state
if %v2%=1
TaskEnable,7
TaskEnable,8
TaskDisable,5
else
TaskEnable,5
TaskDisable,8
TaskDisable,7
 endif
endon
And with 120s timeout in case you forget to switch back to lcdtemp

Code: Select all

on switch#state=11 do  //longpress enable lcdpower
let,2,=!%v2%   // flip state
if %v2%=1
TaskEnable,7
TaskEnable,8
TaskDisable,5
timerSet,2,120
else
TaskEnable,5
TaskDisable,8
TaskDisable,7
 endif
endon
on Rules#Timer=2 do  //switch back to lcdtemp after 2 minutes
TaskEnable,5
TaskDisable,8
TaskDisable,7
endon

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#37 Post by Ath » 09 May 2021, 17:34

I don't know why you keep returning to your 2xLCD devices setup, it's not needed, and has the side-effect of initializing the display when switching tasks.

The startup state isn't included in my last rules set, so that should be fixed then:

Code: Select all

on system#boot do
  lcdcmd,clear
  event,switch#state=1 // display on and start timer
  let,2,1 // second mode
  event,switch#state=11 // flip mode showing 1st set
endon
This code should be added to the last set of rules I published.
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#38 Post by bonti69 » 09 May 2021, 19:05

OK,now we have something on display after boot...done. Now we have to refresh data sended to display,or else will have the values captured on last flip change,forever. On temp/humid/baro will be sufficient 10s, maybe more...But on current/power we need fast reading , one/sec and fast display on this specific scenario...Plus enable/disable ina, we don't need every second interogation of ina sensor via I2C bus,then send data to LCD once/second, ONLY during measurement,otherwise ina can be disabled...
I'm sure YOU CAN solve all of that,but involves a lot of coding.
Getting to this point,one major improvement to this LCD2004 plugin,with no scrolling and framing, would be to implement in the plugin some frames/pages, aka set of data, with enable/disable option, and adressable via LCD command : LCD,<page>,<row>,<col>,<text>
frame lcd2004.jpg
frame lcd2004.jpg (199.33 KiB) Viewed 2784 times

TD-er
Core team member
Posts: 4932
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#39 Post by TD-er » 09 May 2021, 21:12

bonti69 wrote: 09 May 2021, 13:56 Seems like Netherland is "ground zero" for ESP, also tasmota is born there...keep on walking
Do you know that Theo and I only live 20 km apart? (Theo Arends as in the "TA" of Tasmota)
There are even pictures where we sit next to each other on Domotica Meetups :)

I guess the lack of really good weather and stubborn personality not willing to accept "that can't be done" (or "No way I am going to pay that much for something I can make myself") is a good breeding ground for nerdy projects :)

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#40 Post by bonti69 » 10 May 2021, 08:23

Holland uber alles
When I think of Netherlands I remember the 80's, my first steps on electronics , my first colour TV with delta CRT, from the 70's,with 200W power consumption, and all of that under the greatest name: Philips Semiconductor...https://en.wikipedia.org/wiki/Philips
maxresdefault.jpg
maxresdefault.jpg (56.39 KiB) Viewed 2736 times
7959101_radio-lampi-philips-si-lampi-rezerva_1.jpg
7959101_radio-lampi-philips-si-lampi-rezerva_1.jpg (131.99 KiB) Viewed 2733 times
Attachments
2pcs-PCB80C552-4-16WP-8Bit-UPC-ADC-PLCC68-PHILIPS.jpg
2pcs-PCB80C552-4-16WP-8Bit-UPC-ADC-PLCC68-PHILIPS.jpg (23.75 KiB) Viewed 2732 times

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#41 Post by Ath » 10 May 2021, 08:56

I won't be adding a paging feature to the LCD plugin any time soon. (Your suggestion is at least not not backward compatible)
We could try to find a way to update regularly from the rules (it is certainly doable), I'll try to work on that later.
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#42 Post by bonti69 » 10 May 2021, 09:47

Ath wrote: 10 May 2021, 08:56 I won't be adding a paging feature to the LCD plugin any time soon. (Your suggestion is at least not not backward compatible)
We could try to find a way to update regularly from the rules (it is certainly doable), I'll try to work on that later.
Why would not be back compatible? Just add some "page" parameter, optional, if the page is not defined, it will be ignored,by default and plugin remain the same...Maybe one tick "enable pages"
Of course refreshing data at regular interval is doable,few lines of codes...piece of cake for you
Till then, my method works nice, the only drawback is blank lcd, espeasy logo at changing task, few miliseconds, bearable...
You should buy an LCD2004, to play with...to get involved. It's a large display, generous , no need to use glasses :x
PS: Thanks again for your support!

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#43 Post by bonti69 » 10 May 2021, 10:07

One last word:
Hardware attachment of an LCD2004 I2C to a ESP8266 board
LCD 2004 requires 5V voltage supply. The i2c chip will work also at 5V . My LCD I2C board has also pullup resistors to Vcc, so the i2c lines will be pulled up to 5v also. Now , the ESP chip works at 3.3v,including the two gpio assigned to i2c bus. Normally, it requires a level shifter.
Doing some research, some official Espressif declare that ESP is 5v tolerant, on the gpio's at least.
https://ba0sh1.com/2016/08/03/is-esp826 ... -tolerant/
https://www.facebook.com/groups/1499045 ... cation=ufi
So ,the ESP supports those little current above 3.3v injected by LCD pullup resistors (4.7k)
On the I2C we may connect another I2C devices, tolerant or not to 5v bus levels.
On my board BME180 and INA 219 survived ,at least one day with no problem.
Anyway, after that I removed those 4k7 pullup resistors, for safety and long term reliability.
I2C-LCD-Module-Board.jpg
I2C-LCD-Module-Board.jpg (41.98 KiB) Viewed 2717 times
opencollector.png
opencollector.png (19.65 KiB) Viewed 2717 times
open-drain.jpg
open-drain.jpg (276.26 KiB) Viewed 2717 times

TD-er
Core team member
Posts: 4932
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LCD2004

#44 Post by TD-er » 10 May 2021, 11:07

bonti69 wrote: 10 May 2021, 09:47 [...]
Why would not be back compatible? Just add some "page" parameter, optional, if the page is not defined, it will be ignored,by default and plugin remain the same...Maybe one tick "enable pages"
[...]
There are several ways of "not being backwards compatible".
A lot of users switch between ESPEasy versions back and forth, so if we add a breaking change in settings of a plugin, the settings will be altered and cannot be used again in older versions.
If an older version is then used, all kinds of things may happen. For example if the settings are not checked for usable values, the ESP could crash (boot loop) or other things may no longer work as intended.
If this renders an unit unresponsive, it is very frustrating for a user to unmount the ESP to connect it to a PC to recover it.

Another way of being not backwards compatible can be related to how settings are being read from the flash.
For example if the current settings fit just in one part of the settings, but by extending it, you may need the "extended settings" part.
This then requires to switch to a different way of loading settings of that plugin/task. To remain compatible with older versions, you then must implement some very complex loading mechanism to load parts from the old location and parts from the new location, etc.
This is adding to the code size, adding unneeded complexity, and is a reall mess to maintain.

So without having to look at the code, I can imagine adding some seemingly trivial new features may not be so trivial to code.

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#45 Post by bonti69 » 10 May 2021, 11:18

The only way is UP
I agree with you, commander in chief.I have to, because my limited knowledge in programming. But, in that case, a gifted programmer can rebuild a new LCD2004 plugin, the existing one,less demanding,remains as is and the new,enhanced one, LCD frames, like OLED 1306 has...
frame lcd2004_cr.jpg
frame lcd2004_cr.jpg (33.09 KiB) Viewed 2702 times

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#46 Post by Ath » 13 May 2021, 11:20

Ath wrote: 10 May 2021, 08:56 ... update regularly from the rules (it is certainly doable), I'll try to work on that later.
This morning I had some time to rewrite the rules to control this LCD2004 display with 2 temperature sensors, an INA-219 DC power sensor and a button

This replaces the rules I provided earlier!

Code: Select all

// Read documentation at end of this rules set!

on rules#timer=4 do // Called often so placed at top
  if %v1%=1 // If display is on
    if %v2%=0 and %v4%=1
	  asyncEvent,DisplaySet1 // Add to queue
	endon
    if %v2%=1 and %v5%=1
	  asyncEvent,DisplaySet2 // Add to queue
	endon
    LCD,4,13,"%systime%" // update time only on line 4
  endif
endon

on bmp#all do // MUST have 'Single event with all values' enabled on task BMP
  let,4,1 // Set 1 to-display flag
endon

on ds#all do // MUST have 'Single event with all values' enabled on task DS
  let,4,1 // Set 1 to-display flag
endon

on ina#all do // MUST have 'Single event with all values' enabled on task INA
  let,5,1 // Set 2 to-display flag
endon

on DisplaySet1 do // display 1st set of data
  let,4,0 // Clear to-display flag
  LCD,1,1,"Temperatura : [bmp#temperature#d3.2]"
  LCD,2,1,"Barometru :  [bmp#pressure#d4.2]"
  LCD,2,1,"Temp-ext :    [ds#temp#d3.2]"
endon

on DisplaySet2 do // display 2nd set of data
  let,5,0 // Clear to-display flag
  LCD,1,1,"Power :     [ina#power#d3.2]"
  LCD,2,1,"Curent :     [ina#current#d2.3]"
  LCD,2,1,"Voltage :   [ina#voltage#d3.2]"
endon

on rules#timer=3 do // Turn-off display
  lcdcmd,off
  let,1,0 // state to off
endon

on switch#state do // every button press
  // logentry,"Switch state %eventvalue%"
  if %eventvalue% = 1 // short press
    if %v1%=0 // Only if not on, if already on, extend on-time with another %v3% seconds
      let,1,=!%v1% // flip state
    endif
    if %v1%=1
      lcdcmd,on
      TimerSet,3,%v3% // after %v3% seconds turn off
    endif
  endif
  if %eventvalue% = 11 // Long press
    let,2,=!%v2% // flip mode
    if %v2%=1
	  let,3,15 // timeout seconds
	  asyncEvent,DisplaySet1 // Add to queue
    else
	  let,3,60 // timeout seconds
	  asyncEvent,DisplaySet2 // Add to queue
    endif
    // turn display on for at least %v3% more seconds
    lcdcmd,on
    TimerSet,3,%v3% // after x seconds turn off
  endif
endon

// Split here, place the rest in Rules 2 file

on system#boot do
  lcdcmd,clear
  event,switch#state=1 // display on and start timer (time-out disabled)
  let,2,1 // second mode
  event,switch#state=11 // flip mode showing 1st set, start time-out timer
  LoopTimerSet,4,1 // 1 second timer
  LCD,4,1,"System time %systime%" // Show time on line 4
endon

// How to:
// Tasks / Devices: LCD2004 = LCD, BMP180 = bmp, DS18b20 = ds, INA219 = ina, SWITCH = switch
// LCD: display button: none, timeout: 0, Interval: 60, Lines 1..4: leave empty
// bme, ds & ina: enable 'Single event with all values' (even when only 1 value is available!)
// switch: GPIO-16, with Internal PullUp enabled (pull-down for GPIO-16), de-bounce: 50, Longpress: Active only on HIGH, 2000 msec, 'Single event with all values' OFF
//
// Rules variables/timers usage:
// v1 : on/off state display
// v2 : mode 0/1 0 = temperature, 1 = power
// v3 : display timeout in sec.
// v4 : any set 1 data updated
// v5 : any set 2 data updated
// timer 3 = display off
// timer 4 = 1 second timer

The code is a bit large, so I marked the spot where it can be split and the rest moved to Rules 2

There is quite extensive documentation in the script, essential configuration info too, copied here for clarity:

Code: Select all

// How to:
// Tasks / Devices: LCD2004 = LCD, BMP180 = bmp, DS18b20 = ds, INA219 = ina, SWITCH = switch
// LCD: display button: none, timeout: 0, Interval: 60, Lines 1..4: leave empty
// bme, ds & ina: enable 'Single event with all values' (even when only 1 value is available!)
// switch: GPIO-16, with Internal PullUp enabled (pull-down for GPIO-16), de-bounce: 50, Longpress: Active only on HIGH, 2000 msec, 'Single event with all values' OFF
//
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#47 Post by bonti69 » 14 May 2021, 15:10

Thank you,Ath
Much appreciate...
Genuine teacher.I love how you give explanations on every line of code.That means sharing the knowledge.
Kudos

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#48 Post by bonti69 » 16 May 2021, 11:55

Dear Ath,
When you have time,please do one more code for a new LCD2004 scenario:
Premise:
LCD2004 task, with GPIO16 as "display button", timeout 10s
BME280 sensor temperature,humidity,pressure
Another task,as "switch input" ,let's say gpio14, switch#state
What we want:
LCD2004 will display on 4 lines, main screen:
Temperatura : [bme#temperature]
Barometru : [bme#pressure]
Humidity : [bme#humidity]
Alarm : [switch#state ]

When you shortpress gpio16, diplay wake up for 10s ,after that goes black
Now involves gpio14.Let's say gpio14 is a switch connected to a residential alarm,some security entrance,some basement pump,smoke alarm whatever...a rare event,anyway
When switch attached to gpio16 changes state we want to diplay on the LCD some warning message,something like that:
WARNING:
Alarm ON (Pump ON,FIRE ON, ...or anything else) : date&time when switch#state =0
Alarm OFF (Pump OFF,FIRE OFF, ...or anything else) : date&time when switch#state =1
Check something

When switch#state happens, the LCD also remains ON until somebody longpress "display button" to switchback the LCD to the main screen.If the alarm switch happens more times before a longpress , the display will show the latest events.
What do you think, can be done?
Thanks

User avatar
Ath
Normal user
Posts: 891
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LCD2004

#49 Post by Ath » 16 May 2021, 13:23

I think I've given quite a few examples you can remodel to your taste, I'll keep it to suggestions for now, thank you.

A few tips:
- Do NOT use the Display button and Display Timeout settings on the display config if you want the display to stay on for a longer time.
- Use timers (8 available) and state variables (internal vars, set by Let,<var>,<value> and used like %v1% or [var#1] or [int#1], are available as long as memory serves) where appropriate.
- Use [ code ] [ /code ] tags around your code when publishing in the forum, not colors, the code tags makes it readable, the colors only add confusion

Oh, and remember, this is (mostly) software, nearly anything can be done. :)
/Ton

bonti69
Normal user
Posts: 71
Joined: 08 Apr 2021, 12:16

Re: LCD2004

#50 Post by bonti69 » 16 May 2021, 16:27

Dear Ath
ESPEasy,or Tasmota does not fill my life entirely.Let's say low-level hardware is my playground,somehow,my youth ,my formation are on that field.Unfortunatelly, my job did't alow me to perform neither on software,neither on hardware, so let's say esp is a kind of hobby. Flashed my first sonoff with tasmota almost 2 years ago , very happy to click/clack the relay...after that,step by step, with the help of they discord support, started to discover the power hidden "behind the hood".Not so easy,to learn from the scratch,with trial and error...Small projects,anyway,with specific task,not big home automation,mqtt,whatever...Then,a month ago,decided to try ESPeasy,somehow different approach,enhanced webgui,more accessible,more visible,but also with major (or minor) weak points.
Long story short,the goal of this alternative firmware is to be accessible to configure and use for a larger number of "normal,average" users, without high level on programming,just a good,versatile interface where anybody can achieve his goal from the device...A skilled programmer,like you,"can do almost everything", no need of "task", at console.Even for you,it's time consuming,involves trial and error,etc. For me (us) ,much more difficult...Maybe after a week can finish a project, but surely after 1 year,not be able to reproduce...So,a good,versatile,easy manageable dashboard will be always a priority. Remember that old and famous Nokia menu,of the 2000's models,well structured,intuitive...
At the end, respekt for all those who worked to get things as they are...
PS: tried "LCD,1,1,DateTime" but does not display "Datetime:2021-05-16 17:43:41" which results in console, only "Datetime"...what's the correct synthax?
Or: let,1,Datetime ...then LCD,1,1,[var#1]
''The <text> parameter must be a single command parameter. Meaning, it must be wrapped in quotes when using a space or comma as text.

If double quote characters are needed, wrap the parameter in single quotes or back quotes.

All template notations can be used, like system variables, or reference to a task value.''

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests