Why is my lcd crashing :(

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jackpf
 
Posts: 5
Joined: Fri May 09, 2014 4:19 am

Why is my lcd crashing :(

Post by jackpf »

Hi,

I have a program driving an lcd plate (the one with an mcp23017) using the wiringPi library that runs as a daemon on boot. This is all great, but after about 2 days (always roughly the same amount of time) the lcd will stop updating and the buttons become unresponsive. Restarting the program will not suffice, and I have to physically unplug my pi to fix it. I have debugged it with valgrind and fixed all memory errors (however i do get warnings about using ioctl with no direction or size bits set, but i dont think this is causing any issues because the lcd starts up fine). I am in the process of testing and debugging it with gdb but since it takes 2 days to crash its a slow process!

The basic outline of the program is it has two threads, one updating the screen once a second with information, and another polling the buttons every second and piping any key presses to the main thread. It appears that the thread polling the buttons is what crashes. Using 'top' I can see both processes are still running, however the one polling the buttons is using 0% cpu constantly (when running it usually uses about 0.5%) so I'm not sure what's wrong. If gdb doesn't give me any clues I'll be stumped.

Source code:
https://github.com/jackpf/PiLCD/blob/master/lcd.c

Does anybody have any experience with this, or maybe some suggestions on how to figure out what's causing this? Is there some sort of issue with having two separate processes polling/writing to the lcd?

Thanks for any help!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Why is my lcd crashing :(

Post by adafruit_support_rick »

How do you know it's crashed? You press a button and nothing happens? So, probably, the button event is what kills it, since key_listener doesn't do anything until you release the button.

One place where I can see an obvious problem is that both threads call lcd_led. Is it the select button that kills it, do you think? If so, what I would do is comment out the call to lcd_led in key_handler, and see if that makes the problem go away.

The other obvious place for a problem is that both threads access 'display' simultaneously. I can imagine you getting a bogus value in 'display'.

You should guard references to 'display' and lcd_led with mutexes to prevent simultaneous access.

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Why is my lcd crashing :(

Post by adafruit_support_bill »

Two threads trying to write to the i2c bus at the same time could leave the bus in an invalid state. One thread may be hung waiting for some bus event that will never happen. As Rick says, you need to prevent simultaneous access.

jackpf
 
Posts: 5
Joined: Fri May 09, 2014 4:19 am

Re: Why is my lcd crashing :(

Post by jackpf »

Ah this makes sense, I'll give it a go. Thank you very much for the advice!

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”