GPIO & NPN sensor, can't get it working...

Moderator: leecollings

Post Reply
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

GPIO & NPN sensor, can't get it working...

Post 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!
User avatar
kiddigital
Posts: 437
Joined: Thursday 10 August 2017 6:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: GPIO & NPN sensor, can't get it working...

Post 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.
One RPi with Domoticz, RFX433e, aeon labs z-wave plus stick GEN5, ha-bridge 5.4.0 for Alexa, Philips Hue Bridge, Pimoroni Automation Hat
One RPi with Pi foundation standard touch screen to display Dashticz
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: GPIO & NPN sensor, can't get it working...

Post by nitpicker »

I referred to the Domoticz switch, indeed.

Is 'gpio exports' the same output as the 'cat'-methode?
User avatar
kiddigital
Posts: 437
Joined: Thursday 10 August 2017 6:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

GPIO & NPN sensor, can't get it working...

Post 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
One RPi with Domoticz, RFX433e, aeon labs z-wave plus stick GEN5, ha-bridge 5.4.0 for Alexa, Philips Hue Bridge, Pimoroni Automation Hat
One RPi with Pi foundation standard touch screen to display Dashticz
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: GPIO & NPN sensor, can't get it working...

Post 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 :roll:
User avatar
kiddigital
Posts: 437
Joined: Thursday 10 August 2017 6:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

GPIO & NPN sensor, can't get it working...

Post by kiddigital »

Code: Select all

cat /sys/class/gpio/gpio23/value
One RPi with Domoticz, RFX433e, aeon labs z-wave plus stick GEN5, ha-bridge 5.4.0 for Alexa, Philips Hue Bridge, Pimoroni Automation Hat
One RPi with Pi foundation standard touch screen to display Dashticz
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: GPIO & NPN sensor, can't get it working...

Post by nitpicker »

Too bad.. no signal is changing the value... maybe it must be a 'IN' instead of 'OUT'..?!
User avatar
kiddigital
Posts: 437
Joined: Thursday 10 August 2017 6:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

GPIO & NPN sensor, can't get it working...

Post by kiddigital »

If you expect an INput signal

Btw.. link to device on ali does not work (here at least)
One RPi with Domoticz, RFX433e, aeon labs z-wave plus stick GEN5, ha-bridge 5.4.0 for Alexa, Philips Hue Bridge, Pimoroni Automation Hat
One RPi with Pi foundation standard touch screen to display Dashticz
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: GPIO & NPN sensor, can't get it working...

Post 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
User avatar
kiddigital
Posts: 437
Joined: Thursday 10 August 2017 6:52
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: GPIO & NPN sensor, can't get it working...

Post 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.
One RPi with Domoticz, RFX433e, aeon labs z-wave plus stick GEN5, ha-bridge 5.4.0 for Alexa, Philips Hue Bridge, Pimoroni Automation Hat
One RPi with Pi foundation standard touch screen to display Dashticz
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

Re: GPIO & NPN sensor, can't get it working...

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests