0

Raspberry LCD 16x2 is working super slow! Please, help!
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Raspberry LCD 16x2 is working super slow! Please, help!

by creandotec on Wed Feb 13, 2019 10:38 am

Hi, I'm doing a very simple and basic project. I'm using the raspberry pi to create a little chronometer, the chronometer is working very well, I check it first using the console.
Once I start to use the lcd library, the chronometer gets a 1 sec delay for every two or three minutes. I solve that using a thread, now the chronometer keeps runing very well, but the lcd is not been updated properly.

I mean, in the console I see: 00:00:01, 00:00:002,...,00:00:59. But in the lcd the numbers are updated every two or three seconds! =S. This is making me crazy. Thanks for your help. I attach an extract of the code.

Code: Select all | TOGGLE FULL SIZE
class chronometerThread(threading.Thread):
    def __init__(self):
        #Variables que llevan el control del tiempo
        threading.Thread.__init__(self)
    def run(self):
        global _timer_running
        global hours
        global minutes
        global seconds
        global _time_counter
        global need_to_update_LCD

        while True:
            while _timer_running == True:
                result = time.time() - _time_counter
                if (result >= 1.0):
                    _time_counter = time.time() + (result - 1.0)
                    update_time()
                    #Llama a esta funcion para actualizar lo que se muestra en pantalla
                    need_to_update_LCD = True
                    check_outstanding_time()
                    #update_display(hours, minutes, seconds)
        return


Code: Select all | TOGGLE FULL SIZE
def update_display(hours, minutes, seconds):
    global lcd
    global need_to_update_LCD
    _time_string = "{0:02d}:{1:02d}:{2:02d}".format(hours, minutes, seconds)
    lcd.message = _time_string
    print(_time_string)
    need_to_update_LCD = False


Code: Select all | TOGGLE FULL SIZE
if _timer_running == True:

     if need_to_update_LCD:
     update_display(hours, minutes, seconds)


Regards!

creandotec
 
Posts: 1
Joined: Wed Feb 13, 2019 10:22 am

Re: Raspberry LCD 16x2 is working super slow! Please, help!

by adafruit_support_mike on Fri Feb 15, 2019 6:14 am

Threaded code is a lot of things, but 'simple' usually isn't on the list..

To debug threads, it's usually best to start by getting a trace of when each one performs a relevant action. Start by adding some code that produces other output (printed to STDOUT, signals on other pins, or whatever is most convenient) to see if this piece is executing as often as you think it should:

Code: Select all | TOGGLE FULL SIZE
if _timer_running == True:

     if need_to_update_LCD:
     update_display(hours, minutes, seconds)
There are at least three possible options:

- the 'if _timer_running' section isn't executing as often as you expect
- the 'if need_to_update_LCD' is failing when you think it shouldn't
- both conditions are doing what they should and are happening quickly, meaning something is wrong with update_display()

adafruit_support_mike
 
Posts: 55848
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.