graycatlabs / PyBBIO

A Python library for Arduino-style hardware IO support on the Beaglebone
https://github.com/graycatlabs/PyBBIO/wiki
MIT License
251 stars 87 forks source link

Pullup resistors for input GPIO pins #14

Closed alanchrt closed 11 years ago

alanchrt commented 11 years ago

I'm having some difficulty getting the pullup resistor functionality to work on a security system I'm building for my home.

Here's the code:

from bbio import *
from EventIO import *

# Define delay times
TRIGGER_TIME = 30 # seconds
DEPART_TIME = 30 # seconds

# Define pin locations
BEEP_PIN = PWM1A
ARM_PIN = GPIO1_28
DISARM_PIN = GPIO0_7
FRONT_DOOR_PIN = GPIO2_12
SIDE_DOOR_PIN = GPIO2_13
BACK_DOOR_PIN = GPIO2_8
MOTION_SENSOR_PIN = GPIO2_9

class SecuritySystem(object):
    """The security system core."""
    def __init__(self):
        # Setup the event loop
        self.event_loop = EventLoop()

    def arm_button(self):
        # The arm button was pressed
        print "arm button"

    def disarm_button(self):
        # The disarm button was pressed
        print "disarm button"

    def setup(self):
        # Initialize IO pins
        pinMode(ARM_PIN, INPUT, 1)
        pinMode(DISARM_PIN, INPUT, 1)
        pinMode(FRONT_DOOR_PIN, INPUT, 1)
        pinMode(SIDE_DOOR_PIN, INPUT, 1)
        pinMode(BACK_DOOR_PIN, INPUT, 1)
        pinMode(MOTION_SENSOR_PIN, INPUT, 1)

        # Attach events
        self.event_loop.add_event(DigitalTrigger(ARM_PIN, LOW, self.arm_button, 300))
        self.event_loop.add_event(DigitalTrigger(DISARM_PIN, LOW, self.disarm_button, 300))

        # Start the event loop
        self.event_loop.start()

    def loop(self):
        # Print out ARM_PIN state
        print digitalRead(ARM_PIN)

ss = SecuritySystem()
run(ss.setup, ss.loop)

Even thought I have pull=1 for the pinMode, I still always get LOW values for the state of the pins. I can substitute any of the other pins for ARM_PIN in the loop with the same result.

I'm using an Ubuntu image (http://elinux.org/BeagleBoardUbuntu#Precise_12.04_armhf) and have successfully used the pullup resistors on this bone before with bonescript on Angstrom.

Any idea what could be preventing the pullup resistors from activating?

alexanderhiam commented 11 years ago

Thanks Alan. The issue was that when the DigitalTrigger initializes it call pinMode() on the trigger pin, but I had forgotten to allow for configuring pullup/pulldown resistors. Just fixed it and pushed the changes. Update PyBBIO then just add the pull arg where you're creating the DigitalTriggers like this:

  DigitalTrigger(ARM_PIN, LOW, self.arm_button, 300, pull=1)

This means you can also leave out the calls to pinMode() for those pins.

alanchrt commented 11 years ago

Awesome, this is perfect!