# Problems with GPIO push button on self build emonPi

**URL:** <https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347>\
**Category:** Hardware\
**Created:** [5 March 2019 20:40 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347 "2019-03-05T20:40:21Z")\
**Posts on this page:** 20\
**Page:** 5

<div class="post-metadata">

**Author:** ![pb66](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/pb66/32/27_2.png) [@pb66](https://community.openenergymonitor.org/u/pb66)\
**Post date:** [28 March 2019 21:25 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/83 "2019-03-28T21:25:11Z")

</div>

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,

> <https://github.com/openenergymonitor/emonpi/blob/master/lcd/lcddriver.py#L97-L106>

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 the[middle of the emonPiLCD.py file](https://github.com/openenergymonitor/emonpi/blob/master/lcd/emonPiLCD.py#L360) and also as `lcd` in the [included lcddriver.py file](https://github.com/openenergymonitor/emonpi/blob/master/lcd/lcddriver.py#L55), 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.

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [29 March 2019 13:35 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/84 "2019-03-29T13:35:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [29 March 2019 17:22 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/85 "2019-03-29T17:22:49Z")

</div>

I tried this

```auto
        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 $
```

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [29 March 2019 19:42 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/86 "2019-03-29T19:42:06Z")

</div>

Paul wrote earlier:

> [@pb66](#):
>
> That’s most likely a copy and paste error. Python is very fussy about indentation, looking at the script there are 4 levels of indentation (plus no indentation). the `if temp >= sensor['on']:` line is on the 3rd level of indentation which means it probably must have 3 tabs or 12 spaces depending on what style you are using.
> 
> Beware of stray white space and or line endings altering things from what you see to what is seen by Python.

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.

---

<div class="post-metadata">

**Author:** ![Bill.Thomson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/bill.thomson/32/1834_2.png) [@Bill.Thomson](https://community.openenergymonitor.org/u/Bill.Thomson)\
**Post date:** [30 March 2019 02:17 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/87 "2019-03-30T02:17:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 07:43 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/88 "2019-03-30T07:43:37Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 14:31 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/89 "2019-03-30T14:31:35Z")

</div>

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

 ![4_%20lines](https://community.openenergymonitor.org/uploads/default/original/2X/e/e3c8eb076cb9f023af4d87601961f271b0cf5d53.jpeg)

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [30 March 2019 14:50 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/90 "2019-03-30T14:50:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 14:56 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/91 "2019-03-30T14:56:39Z")

</div>

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 😄 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 😄 just wish i could get a hold off @glyn.hudson, sure he knows.

```auto
        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 + ': ' + "---"
```

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [30 March 2019 15:10 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/92 "2019-03-30T15:10:37Z")

</div>

> [@tonertiffi](#):
>
> as soon as i add in lcd[2] or lcd [3] script fails.

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 ?

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 16:11 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/93 "2019-03-30T16:11:11Z")

</div>

That is in that file

```auto

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

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 16:13 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/94 "2019-03-30T16:13:41Z")

</div>

I just added

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

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 16:19 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/95 "2019-03-30T16:19:27Z")

</div>

I did try an add 1 line in

```auto
 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
```

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 16:21 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/96 "2019-03-30T16:21:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pb66](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/pb66/32/27_2.png) [@pb66](https://community.openenergymonitor.org/u/pb66)\
**Post date:** [30 March 2019 16:49 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/97 "2019-03-30T16:49:12Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 16:50 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/98 "2019-03-30T16:50:11Z")

</div>

Hi @pb66 give a sec ill try that

 ![test13](https://community.openenergymonitor.org/uploads/default/original/2X/e/efc78eddba7915ab905253a3d04fa7c2cb07d452.png)

kill script

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [30 March 2019 17:01 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/99 "2019-03-30T17:01:07Z")

</div>

> [@tonertiffi](#):
>
> I did try an add 1 line in

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?

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 17:02 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/100 "2019-03-30T17:02:50Z")

</div>

give a sec ill try

```auto
 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”
```

---

<div class="post-metadata">

**Author:** ![tonertiffi](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/tonertiffi/32/9427_2.png) [@tonertiffi](https://community.openenergymonitor.org/u/tonertiffi)\
**Post date:** [30 March 2019 17:08 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/101 "2019-03-30T17:08:26Z")

</div>

Dies as in the above screen shot

this works fine

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

to

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

Changes it around
```

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [30 March 2019 17:11 UTC](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347/102 "2019-03-30T17:11:39Z")

</div>

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

[Previous page](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347.md?page=4)

[Next page](https://community.openenergymonitor.org/t/problems-with-gpio-push-button-on-self-build-emonpi/10347.md?page=6)
