GPIO relay not working

My nymea:core is on a pi0 (if that has any significance).
From python I can turn my relay on/off, so the wiring, input voltage etc. are correct.

When I add a generic GPIO output (raspberry, not beaglebone), I have the following issues:

  • GPIO output cannot be reconfigured (for instance when trying to change active high from true to false): "Uh oh Something went wrong setting up this thing".
  • When I add a GPIO output it turns the relay on immediately (no matter if I set active high true or false) as I hear the relay click.
  • When I switch the power of the GPIO (both from uncategorized device or from a linked device, like generic power socket), the software displays the power switched, but the relay does not click and the output is not flipped after the initial click - regardless of the active high setting.

I am not sure if I make a mistake somewhere or if there is a bug somewhere.

Thanks.

Edit: I popped the SD card into my pi3 and the GPIO still does not work. I’m pretty sure I misunderstand something, or idk.

Anybody who could at least tell me where I can get started? I’m really not big in C++, don’t really understand the plugin source.

Hey, I have just tried the GPIO output on a Raspberry Pi 4, don’t have a Zero at hand but that should not make a difference.

I’ve connected a relay to 3.3V, GND and GPIO 26 (Pin 37). Then I went to Configure things → + and added a GPIO output for Raspberry pi. I did not change any of the parameters (active low and such). It did not instantly go on and I can successfully switch it.

For the reconfiguration, that might be a bug in the gpio plugin… In any case, reconfigure is the same as removing and adding again, except the ID will be kept the same.

Not sure why it wouldn’t work for you right now. Some guesses:

  • Do you perhaps have any other software running that blocks the GPIOs? How did you install nymea? Using the nymea image or installing it on top of another setup?
  • When configuring a new GPIO thing in nymea, it will write the according GPIO number to /sys/class/gpio/export. Which in turn should make a file for this GPIO appear in /sys/class/gpio/gpio. Then, for switching it, it would write 0 (for off) and 1 (for on) to that file. If active low is enabled, those values will be inverted. You could try verifying if those files exist, and perhaps trying to export a gpio manually using echo 26 | sudo tee /sys/class/gpio/export and then switching it with echo 1 | sudo tee /sys/class/gpio/gpio26 and see if that works or not.
1 Like

Thanks, your help is very much appreciated! :slight_smile:
I made a fresh install and I was experiencing the same issue. Then I realized that You were hooking up VCC to 3.3V as opposed to 5V. Changing that, it works!

Now, what confused me (and it still does) is that with this simple-basic python script below I was able to control the relay normally (with 5V VCC). If you have the mental capacity, any chance you could elaborate on why nymea requires different wiring? :slight_smile: I’m thinking it might have to do something with internal pull up/down resistors, but not sure. My dummy script was:

import RPi.GPIO as GPIO
import time

channel = 4

# GPIO setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.OUT)

def relay_on(pin):
    GPIO.output(pin, GPIO.HIGH)

def relay_off(pin):
    GPIO.output(pin, GPIO.LOW)

if __name__ == '__main__':
    try:
        relay_on(channel)
        time.sleep(1)
        relay_off(channel)
        time.sleep(1)
    except KeyboardInterrupt:
	print("There was a keyboard interrupt")
    except:
        print("There was a mysterious error")
    finally:
        GPIO.cleanup()

Subtext: My relay is a 5V relay and I recall making a circuitry for it to work from nodeMCU devices (no 5V and I recall they did not work with 3.3 -might be wrong there), so I was quite sure I had to hook it up to the 5V pin. In any case, I changed the VCC from 5V to 3.3V and now I can flip the relay from nymea. Cheers!

Hmm, this is weird… I would have thought it shouldn’t matter, assuming the device can deal with both. I’ve just moved my relay to the 5V pin (without reconfiguring it in nymea) and it still works, but apparently the model I have can deal with 3 - 48V VCC…

I’ve skimmed over the RPi.GPIO python module code and while I’m not completely sure, I guess it does indeed depend on the pull resistors. The python module seems to directly hook into the kernels memory for the GPIO (/dev/gpiomem or /dev/mem), while nymea uses the userspace gpio files (/sys/class/gpio/…). Afaict, the memory mapping approach allows to individually configure the pull resistors and the python module does seem to do so [1], while the sysfs files will somehow automatically determine what to do from the activeLow flag, but to be honest this is just guesswork at this point.

[1] raspberry-gpio-python / Code / [08048d] /source/c_gpio.c

1 Like

Thanks for putting in that extra effort to help me out! :slight_smile:

1 Like