komatachia
Posts: 2
Joined: Sun Mar 27, 2016 1:11 am

RPi.GPIO Library causing Pi to freeze completely once a day

Fri Apr 01, 2016 4:30 pm

Hi all,

So I have an rpi 2 with the latest kernel running some Python code, and it's causing my system to freeze up randomly - usually after 24-30 hours, but sometimes within 20 minutes. In my debugging, I simplified the Python code so that all it does is use the GPIO pins in a loop. The way it is accessing the GPIOs is through a soft-i2c library I made which utilizes the RPi.GPIO library. My i2c library 'works' because the it can read/write i2c data to my peripherals properly, and I really have no idea what could be causing this issue.

When I say 'freeze', I mean that the entire RPi basically halts. HDMI goes away after a bit, the dongle LED stays at its last value (usually off, but sometimes on), the green SD card light stays at its last value (usually off, but sometimes on), and the red light stays on.

I have done a few months of testing and can confirm it's something to do with the python code, as I've tested the system in its most basic state with no HDMI display, no WiFi dongle, nothing at all attached to the RPi except power, and script automatically running on boot. The 5v rail is fine, even through 24-30 hours as I've done very long traces with my logic probes.

The only thing I can hypothesize is that there is some sort of contention between the output drivers since I am constantly changing pinmode for the 'SDA' line, and that one driver is sinking while the other is sourcing for some reason thus heating it up. But then if that's the case, why wouldn't the peripheral I2C have the same issue? It's using the same output buffers...

Anyhow, I've been trying to figure this out for ages and I really don't know what's wrong with it. Anybody seen anything similar and/or have a suggestion?

This code is likely not helpful, but here's a snippet of my GPIO abstraction layer which is the only part that actually writes/read pins and changes direction:

Code: Select all

    # Only use real functions when running on RPi
    @rpi_decorator
    def output(self, pin, value=None):
        if self.gpio_map[pin] != self.OUT:
            RPi.GPIO.setup(pin, RPi.GPIO.OUT)
            self.gpio_map[pin] = self.OUT
        if value==None:
            return RPi.GPIO.input(pin)
        RPi.GPIO.output(pin, value)
        
    @rpi_decorator    
    def input(self, pin):
        if self.gpio_map[pin] != self.IN:
            RPi.GPIO.setup(pin, RPi.GPIO.IN)
            self.gpio_map[pin] = self.IN
        return RPi.GPIO.input(pin)

Return to “Troubleshooting”