We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Problems setting up python to read input from magnetic door sensor.

  • I am having issues with my python code converting it from raspsberry pi to onion.

    Here is the python from the raspberry pi:
    door_pin = 26
    GPIO.setup(door_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    and here is the onion code:
    pin = 14
    door_pin = onionGpio.OnionGpio(pin)
    status = door_pin.setINputDirection()
    value = door_pin.getValue()

    But no matter what I do I cannot get the value to read anything but 0 from the GPIO14. My magnetic sensor is a simple 2 wire setup. With one wire on the gpio and the other on gnd. Just like I have setup on mt Raspberry Pi. But I cannot seem to get it to work on the onion.

    Any ideas?

  • @John-Robinson You can't necessarily rely on GPIO pin input sates when not actively driven.
    I would suggest using a pull-up resistor on your pin 14 - around 10K Ohm will do.
    That way, when the switch is open, it will be pulled high; when the switch is closed it will be low

  • Yes thanks, I had just figured it out. šŸ™‚ šŸ‘

Looks like your connection to Community was lost, please wait while we try to reconnect.