Page 1 of 1
GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 16:31
by nitpicker
Searched whole internet reading lots of blogs and posts from this and other forums, but I still can't get it working...
I have the following
device:
Voltage: DC 6-36V
Output current: 300mA
3 Wire
Polarity: NPN
Detection Distance: 4 mm
Ouput Status: Normally Open
The sensor is working, every time metal is detected, the led on top of the sensor is lightning up. I installed the Domoticz hardware
Generic sysfs GPIO and added the following in a file named sysfs_init.sh (like
ubee did). The following settings are in the file:
- echo 23 > /sys/class/gpio/export
- echo out > /sys/class/gpio/gpio23/direction
- echo 1 > /sys/class/gpio/gpio23/active_low
Too bad, the switch doesn't do anything... Who can help me out? Very appreciated!
Re: GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 16:52
by kiddigital
Which switch are you refering to? Domoticz switch?
Does it work on the Pi itself? If you ‘cat’ the state of the GPIO pin from sysgpio, you should see there if the state does change.
Re: GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 17:44
by nitpicker
I referred to the Domoticz switch, indeed.
Is 'gpio exports' the same output as the 'cat'-methode?
GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 17:55
by kiddigital
From the top of my head (unable to test right now):
cat /sys/class/gpio/gpio23
Should show the value from the sensor.
To test use something like
watch -n 1 ‘cat /sys...’
That should execute the command every 1 second so you have your hands free to play with the sensor

Re: GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 19:06
by nitpicker
kiddigital wrote: ↑Friday 30 October 2020 17:55
cat /sys/class/gpio/gpio23
I don't believe this works... or it is not working at all from my end

GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 19:17
by kiddigital
Re: GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 20:11
by nitpicker
Too bad.. no signal is changing the value... maybe it must be a 'IN' instead of 'OUT'..?!
GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 20:16
by kiddigital
If you expect an INput signal
Btw.. link to device on ali does not work (here at least)
Re: GPIO & NPN sensor, can't get it working...
Posted: Friday 30 October 2020 20:56
by nitpicker
I don't know for sure it has to be... an IN or OUT signal... the link here is fine, but another time:
link
Re: GPIO & NPN sensor, can't get it working...
Posted: Saturday 31 October 2020 9:28
by kiddigital
For me the link gives the same result, it goes to a certain page and directly redirects to ali homepage.
But based on your description your sensor ‘detects’ something so it has to be an INput.
Re: GPIO & NPN sensor, can't get it working...
Posted: Sunday 01 November 2020 12:15
by nitpicker
Changed the settings to:
- echo 21 > /sys/class/gpio/export
- echo in > /sys/class/gpio/gpio21/direction
- echo 1 > /sys/class/gpio/gpio21/active_low
Changed to GPIO port 21, because with port 23 the led did not lighten up. With port 21 the sensor led works as expected.
Now there is no switch created in Domoticz when I add the Generic sysfs GPIO hardware again... and watch -n 0.5 cat /sys/class/gpio/gpio21/value doesn't show a changing value..
gpio exports:
GPIO Pins exported:
21: in 0 none