Problems with GPIO push button on self build emonPi

Sorry, no I haven’t had a chance to do it. I have just looked through the code again now and it’s not a straight forward edit as far as I can make out.

It certainly isn’t “its as simple as adding in 2 more feeds” I’m afraid.

On that point, you do not necessarily need to add more data feeds, that is an independent decision. Other users have made changes to the data that is displayed and with a bit of searching here on the forum you might find something to assist modifying the content displayed.

However, what you are actually needing is to change HOW the content is displayed, currently there are a number of pages of 2 lines each. To utilise the other 2 lines of your 4 line display, you essentially need to either show the same data over half as many pages or indeed, expand the data to fill half of each of the current pages, or somewhere in between.

Once the code is amended to fill 4 lines per page, I think it might be trivial to add feeds and/or pages. That is however, just my expectation, not a confirmed position.

It seems you are in luck with the library as that appears to have the ability to work with up to 4 lines,

but I have no idea where that lib came from or if it’s fully tested with 4 lines. All I know is what you see above.

In the emonPiLCD.py file you see there are numerous references to lcd[0] and lcd[1], these are the 2 lines for the existing display, to use all 4 lines of your display, lcd[2] and lcd[3] will need to be introduced for each page (either with new info/feeds or by rearranging the existing pages).

Since I do not have a display to test, nor am I familiar with the existing code, I’m not sure I how much use I’ll be to you. This is significantly less straightforward than the temperature stuff we’ve already done.

I’m struggling to understand the code, it seems the “lcd” class is defined twice, once as LCD in themiddle of the emonPiLCD.py file and also as lcd in the included lcddriver.py file, as far as I can tell the LCD isn’t used, but I can’t be sure. Maybe I’ll take another look another time, but I’m pretty busy and whilst i don’t mind helping you. I do not really have the time to write this for you. The temperature stuff was easy as I had experience and examples of my own to call on.

Thank you @pb66, fortunately I do understand what you are explaining to me here, as I have spent allot of time on Google looking at examples, lcd[0] ,LCD [1] got me a bit , as all the examples I came across use LCD Wright 1,2,3,4 line ect, never did I see LCD[0], [1], I did try adding , in under the feeds page lcd[2], LCD [3], adding a 3rd and 4th feed aswell, the script stops working.
On the UI administrator you can see that aswell.

I really do apriciated, every second you offer, thank you so much. If it were not for guys like you, I would not even have considered building this project, must say it has been one of the most rewarding to date. Thank you Paul

I tried this

        if r.get("feed1") is not None:
            lcd[0] = feed1_name + ':'  + r.get("feed1") + feed1_unit 
        else:
            lcd[0] = feed1_name + ':'  + "---"

        if r.get("feed2") is not None:
            lcd[1] = feed2_name + ':'  + r.get("feed2") + feed2_unit 
        else:
            lcd[1] = feed2_name + ':'  + "---"

		if r.get("feed3") is not None:
            lcd[2] = feed3_name + ':'  + r.get("feed3") + feed3_unit 
        else:
            lcd[2] = feed3_name + ':'  + "---"

		if r.get("feed4") is not None:
            lcd[3] = feed4_name + ':'  + r.get("feed4") + feed4_unit 
        else:
            lcd[3] = feed4_name + ':'  + "---"

gives
pi@emonpi:~/emonpi/lcd $ python  emonPiLCD.py
  File "emonPiLCD.py", line 271
    if r.get("feed3") is not None:
    ^
IndentationError: unexpected indent
pi@emonpi:~/emonpi/lcd $

Paul wrote earlier:

Just because it looks the same, does not mean it is the same. Check that you really do have exactly the correct indentation, not a mix of non-printing characters (tab, space, etc) that look the same to you but are not the same.

Also, check the line or lines immediately above the place where the error is reported.

I’m not a Python expert, (I leave that to PB)
but Python is flagging an indent that shouldn’t be there.

The
if r.get("feed3") is not None:
as well as the
if r.get("feed4") is not None:

lines are both indented, but the

if r.get("feed1") is not None:
and
if r.get("feed2") is not None:
lines are not indented.

i.e. if r.get ("feed3") should be aligned with the start of the if r.get ("feed1") line.
Same for the if r.get ("feed4") line.

@Bill.Thomson i think you right, because any comb of Lcd [2]or [3] the script stops working,just need to find a way around it to use all 4 lines, of the 20x4

I really do like this display as it seems to update faster than the 2x16

Progress is slow, allest i know it can do it as i altered the lcd.test.py, and 4 lines.

It looks like you are nearly there. Now you know how to make the text appear on all 4 lines, your next step is to move that into your real script, and the step after that is to change “test 456” to the number you want. Do the changes in small steps, change only one thing each time.

Just wish that it was displaying that in the, emonpiLCDPY.py file, i used the test.py script to do that, sure if you gave a monkey a keyboard he could have done that :smile: as soon as i add in lcd[2] or lcd [3] script fails. Its not in my nature to give up, but its driving me to drink :smile: just wish i could get a hold off @glyn.hudson, sure he knows.

        if r.get("feed1") is not None:
            lcd[0] = feed1_name + ':  '  + r.get("feed1") + feed1_unit 
        else:
            lcd[0] = feed1_name + ':  '  + "---"

        if r.get("feed2") is not None:
            lcd[1] = feed2_name + ':  '  + r.get("feed2") + feed2_unit 
        else:
            lcd[1] = feed2_name + ':  '  + "---"

        if r.get("feed1") is not None:
            lcd[2] = feed1_name + ':  '  + r.get("feed1") + feed1_unit 
        else:
            lcd[2] = feed1_name + ':  '  + "---"

        if r.get("feed2") is not None:
            lcd[3] = feed2_name + ':  '  + r.get("feed2") + feed2_unit 
        else:
            lcd[3] = feed2_name + ':  '  + "---"

How does it fail? Does it give an error? If it does, that should tell you where to start looking for the problem.
What is in test.py that is not in emonpiLCDPY.py ?

That is in that file


import lcddriver
import time

lcd = lcddriver.lcd(0x27)

lcd.backlight =1
lcd.lcd_display_string("emonPi", 1)
lcd.lcd_display_string("test 123",2)
time.sleep(5)
lcd.lcd_display_string("Backlight off", 1)
lcd.lcd_display_string("in 5 seconds..",2)
time.sleep(5)
lcd.backlight = 0
time.sleep(5)
lcd.backlight =1
lcd.lcd_clear()
lcd.lcd_display_string("Backlight on", 1)
lcd.lcd_display_string("end of test", 2)

I just added

       lcd.lcd_display_string("test 456",3)
       lcd.lcd_display_string("test 789",4)

I did try an add 1 line in

 lcd[1] = r.get("wlan:ip")
        elif eval(r.get("gsm:active")) or eval(r.get("eth:active")):
            page += 1
        else:
            lcd[0] = "WiFi:"
            lcd[1] = "NOT CONNECTED"
            lcd[2] = "WiFi:"

That drove it nuts, weird characters all over the show

So no errors, but also no head way, only success in the test.py file.

I was just passing through, briefly though looking at the original code, this bit

def __setitem__(self, line, string):
        if not 0 <= line <= 1:
            raise IndexError("line number out of range")

Looks like it limits the line count to 2. Try changing the 1 to 3.

Hi @pb66 give a sec ill try that

kill script

Ah, but you are going in the wrong direction. You want to display “test 456” from your emonPi program.

Forget (for now) "if r.get … " and write in there instead:

lcd[3] = “test 456”
lcd[4] = “test 789”

Does that display correctly?

give a sec ill try

 elif page == 6:
    # Get uptime
        with open('/proc/uptime', 'r') as f:
            seconds = float(f.readline().split()[0])
        r.set('uptime', seconds)

        lcd[0] = datetime.now().strftime('%b %d %H:%M')
        lcd[1] = 'Uptime %.2f days' % (seconds / 86400)
        lcd[3 or 2] = “test 456”
        lcd[4 or 3] = “test 789”

Dies as in the above screen shot

this works fine

        lcd[0] = "emonPi Build:"
        lcd[1] = sd_image_version

to

        lcd[1] = "emonPi Build:"
        lcd[0] = sd_image_version

Changes it around

Try

lcd[3] = ‘test 456’
lcd[4] = ‘test 789’

(Remember, I do not know Python, I am just using logic and experience of other languages.)