Electro-Poleas
Posts: 9
Joined: Wed Feb 18, 2015 7:32 pm
Location: Spain
Contact: Website

LCD slight blink while refreshing

Sun Feb 22, 2015 11:03 am

Hi!

I'm having this issue with an LCD display using the Adafruit library. My program checks with a while loop if an input it's true or false. My question is if it's possible to make that blinking stop? This is the program:

Code: Select all

import RPi.GPIO as GPIO
import time
from Adafruit_CharLCD import Adafruit_CharLCD

GPIO.setmode(GPIO:BCM)
lcd = Adafruit_CharLCD()

GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
lcd.begin(16, 1)

while True:
      door = GPIO.input(5)
      lcd.clear()
      if door:
                  lcd.message ('Door Open')
      else:
                 lcd.message ('Door Closed')

      time.sleep(2)

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: LCD slight blink while refreshing

Sun Feb 22, 2015 11:24 am

You could try to check if it's already printed.

Code: Select all

import RPi.GPIO as GPIO
import time
from Adafruit_CharLCD import Adafruit_CharLCD

GPIO.setmode(GPIO:BCM)
lcd = Adafruit_CharLCD()

door_old = 0

GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
lcd.begin(16, 1)


while True:
    door = GPIO.input(5)
    lcd.clear()
      
    if door == 1 and (door_old != door) :
        print 'Door Open'
        door_old = door              
    else:
        if door_old != door:
            print 'Door Closed'
            door_old = door
Please correct me if something is wrong :?

Laurens

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: LCD slight blink while refreshing

Sun Feb 22, 2015 12:11 pm

Laurens-wuyts wrote:You could try to check if it's already printed.
That's along the right lines, but I think that will still keep blinking because of the lcd.clear() in the loop.

Perhaps something like this:

Code: Select all

import RPi.GPIO as GPIO
import time
from Adafruit_CharLCD import Adafruit_CharLCD

GPIO.setmode(GPIO:BCM)
lcd = Adafruit_CharLCD()

door_old = 2

GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
lcd.begin(16, 1)


while True:
    door = GPIO.input(5)
      
    if door == 1 and (door_old != door) :
        lcd.clear()
        lcd.message( 'Door Open' )
        door_old = door              
    else:
        if door_old != door:
            lcd.clear()
            lcd.message( 'Door Closed' )
            door_old = door
Note that I initially set "door_old" to 2 which is an invalid value so that the door status will be detected as changed whether it is open or closed when you start.

Electro-Poleas
Posts: 9
Joined: Wed Feb 18, 2015 7:32 pm
Location: Spain
Contact: Website

Re: LCD slight blink while refreshing

Sun Feb 22, 2015 12:25 pm

Hi! Thank you very much for your help.
I ran both codes and both worked. But the display still has that slight blinking every two seconds.

Electro-Poleas
Posts: 9
Joined: Wed Feb 18, 2015 7:32 pm
Location: Spain
Contact: Website

Re: LCD slight blink while refreshing

Mon Feb 23, 2015 4:43 pm

Probably the reason for the blinking is that the program is continuously checking if the inputs changes. Is it posible to modify the code to change the LCD output only if there is a change on the input?

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: LCD slight blink while refreshing

Mon Feb 23, 2015 4:57 pm

Electro-Poleas wrote:Is it posible to modify the code to change the LCD output only if there is a change on the input?
That's what our suggestions did. They compare the current state with the previous state and only display a message if they are different.

Electro-Poleas
Posts: 9
Joined: Wed Feb 18, 2015 7:32 pm
Location: Spain
Contact: Website

Re: LCD slight blink while refreshing

Mon Feb 23, 2015 5:05 pm

rpdom wrote:
Electro-Poleas wrote:Is it posible to modify the code to change the LCD output only if there is a change on the input?
That's what our suggestions did. They compare the current state with the previous state and only display a message if they are different.

:lol: Sorry about that. Well it didn't work I'm afraid to say. If your code does exactly that, I'm beggining to think that it's an electronic issue. I've tried to put a 100nF capacitor between VCC and VSS. Maybe the problem is that it's a cheap chinesse LCD. Idon't really know.

Thanks again for your help.

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: LCD slight blink while refreshing

Mon Feb 23, 2015 5:07 pm

Is it a flicker in the backlight or is it a flicker in the characters?

Laurens

Electro-Poleas
Posts: 9
Joined: Wed Feb 18, 2015 7:32 pm
Location: Spain
Contact: Website

Re: LCD slight blink while refreshing

Mon Feb 23, 2015 5:12 pm

Laurens-wuyts wrote:Is it a flicker in the backlight or is it a flicker in the characters?

Laurens

The characters are the ones flickering. And it's more pronounced in the characters on the right.

sysfrank
Posts: 1
Joined: Wed Nov 19, 2014 8:51 pm

Re: LCD slight blink while refreshing

Mon Sep 12, 2016 8:54 pm

So, I am having a similar problem. In my case, it is the backlight that is blinking. It happens every time I update the display. Any suggestions?

Return to “Troubleshooting”