GPIO pins not responding properly

So, I am trying to get the gpio binding setup and nothing will change the state of the relays I have connected. I have a 16 relay board connected to the pins so I could see if ANY pins would work, Tried every suggestion I could find with GPIO permissions, libjna, services file… Eventually I added WiringPi and attempted to manipulate them from the terminal. When I change the state in the items file from active:high to low or vice versa the relay will click, same with WiringPi in the terminal, switching them from input to output… But no movement from a switch in the openhab UI or gpio write 5 0/1 in the terminal. I seem to be missing something and I am ready to trash the whole setup… help please.

@Lisker99 Maybe this helps.

1 Like

I think @Josar makes a good suggestion to have a look at my tutorial.
If you have WiringPi installed and tried some things with that, it is well possible that your pins are occupied.
Have a look at my tutorial (referenced by Josar) and just take it from the start

yup, did all of that, no dice.

If I change the active:low to high or vice versa the relay switches when I save the file, even tried sudo with wiringpi commands, nothing

@Lisker99 have you installed the GPIO Binding?

maybe try this steps. (I know its repeating from the simple GPIO example)

  1. Install the GPIO Binding with Paper UI.
  2. Add openhab to the gpio user group
sudo adduser openhab gpio
  1. make an items file
Switch GPIO_Output "Output Pin" {gpio="pin:11 force:yes"}
Contact GPIO_Input "Input Pin [%s]" {gpio="pin:9 activelow:yes"}
  1. make a sitemap file called GPIO.sitemap
sitemap GPIO label="GPIO" {

 Frame label="GPIO Pins" {
   Switch item=GPIO_Output
   Text item=GPIO_Input
  1. Use a cable to connect GPIO11(PIN23) and GPIO9(PIN21).
  2. Open your sitemap push the switch hopefully the Input will change.

If this does not work, it just did in my setup, there is some need to investigate further.

Try to list the groups openhab ist member of, you must find gpio there.

pi@raspberrypi:~ $ groups openhab
openhab : openhab audio video spi gpio

Try to get the pin change from the shell. And then as user openhab to find out if the user openhab can change the pin.

pi@raspberrypi:~ $ gpio -g write 11 0
pi@raspberrypi:~ $ sudo -u openhab gpio -g write 11 1

Thats all a have in mind.

PS: Sometimes a reboot works wonders.

1 Like

Ok, tried all that, nothing still. The numbers are irrelevant, I have 16 relays connected, systematically tried wiringpi numbers and the BCM numbers.
I can toggle it on and off with:
$ gpio mode 6 in
$ gpio mode 6 out
but nothing happens with:
$ gpio write 6 1
$ gpio write 6 0
$ gpio -g write 6 1
$ sudo gpio write 6 1
… ugh, this blows.

ok, new info.
I ran from the terminal mode out on 3 pins and changed their state and it verified they had in fact changed in readall, but no physical switch in the relay/light from the 0/1 command, only in/out command

@Lisker99 if you want to test the same pin without and with -g you have to change the number. So wiringpi pin 6 should be BCM 25

First you have to set the pin as output and then change its state from low to high or vice versa.

gpio -g mode 25 out
gpio -g write 25 0
gpio -g write 25 1

Most probably the relay you can switch was set as output by the openhab gpio binding.

How did you connect the relays? Did you connect the Pin and also ground for all relayes?

yup, got all that.

I know it isnt the number that is the issue, I did it 16 times with different numbers, they will turn on and off when I change the mode, not when I run the write command… Also I proved the mode is properly changing by running readall before and after…

I have flashed a new SD with noobs, installed Raspian and WiringPi without openhab and the same issue persists, so I am going to hit up a topic on an Rpi3 forum I guess

@Lisker99 lets try again.

Remove all relays, short two pins with a cable as mentioned in my example above. Now lets try to set one pin as input and one as output. And then test if this works.

pi@raspberrypi:~ $gpio -g mode 9 in
pi@raspberrypi:~ $gpio -g mode 11 out

pi@raspberrypi:~ $ gpio -g read 9
pi@raspberrypi:~ $ gpio -g write 11 1
pi@raspberrypi:~ $ gpio -g read 9
pi@raspberrypi:~ $ gpio -g write 11 0
pi@raspberrypi:~ $ gpio -g read 9

Does this work ? If yes, we are good to make the next test. Try the same as opnehab user.

pi@raspberrypi:~ $ sudo -u openhab gpio -g write 11 1
pi@raspberrypi:~ $ sudo gpio -g read 9
pi@raspberrypi:~ $ sudo -u openhab gpio -g write 11 0
pi@raspberrypi:~ $ sudo gpio -g read 9

If this works, go to the sitemap and see that the state of the input changes when you push the switch.

Then after we know the rpi and openhab works, or not, we proceed with the relays. Connect the Output pin and also the ground pin of the rpi to the relay. Also make sure your relay has proper supply with external VCC and ground. Try to switch it.

Which relays are you using, datasheet? What voltage do they need to trigger and how much current do they need.

ok, yes, directly back to the Pi it reads properly. Th -u wasn’t recognized, but I know that openhab"s sitemap can work, I re-wrote my items last night to use exec bindings to change the mode.

I am using a Sainsmart 16 relay board, driven by separate 12v, source
so, thinking not enough current to hold it on the gpio pins?
how do I fix that?

btw, I’m pumped that just worked, I feel like Ive been beating my head against the wall…

Just tested the relay board, the relays switch when they are pulled down, I put a jumper from a pin to ground and it switched. So, why would it be able to pull it down but not let it back up while in output mode? when I put it into Input mode it lets go high… internal setting?

I think I got it… just guessing here, the relay board is looking for 5v to hold it high, Rpi only giving 3.3. The board was supposed to be Rpi ready, guess that is not the case, but there is power back-fed from the board. Standing on the pins set as inputs there is 4v from the relay board… obviously not isolated.

@Lisker99 you need a transistor circuit to properly switch the relay off.

The board is isolated from the load circuit but not from the relay supply. Have a look on my sketch at the link above. There you will also find more instructions from the original thread poster how to properly set up a relay circuit. Just follow the links.

Please, just don’t answer the -u was not recognized. What was the issue? If this command does not work then the gpio binding does not work. You will have to write a exec binding and call a Skript with sudo. Which is not the right way, IMHO.

What is the message or behavior for

pi@raspberrypi:~ $ sudo -u openhab gpio -g write 11 1

To be frank you expect help, but offer no information besides. Your suggestion does not work. How should anyone find the culprit in the setup? Try to give proper answers with full explanation what you did and how it responded.

Besides that use code fence for better readability, use the menu at the upper side of the textbox and copy paste you shell lines between the triple quotation marks.

Code goes here

@Lisker99 just watched this Maybe it helps.