I feel so elated to report I figured out my bumper problem. I had designed the connections to be active low using the internal pull-ups of the MCP23S17 but forgot this during my time away from my bot.
I used the (private/unsupported) PDALib.setDioBit(reg, pin) function to set the pull-ups and voila - I've got three working negative logic bumpers (rear, left, right). With the skirt on, this gives the bot 6 usable bump directions:
- front (left + right)
- left (and left front)
- right (and right front)
- left rear (left+rear)
- right rear (right+rear)
- rear
(The Pi Droid Alpha interface board maps the MCP23S17 DIO Bank A to be DIO 8-15, so Bank A Bits 0,1,2 are channel 8, 9, 10 in the program)
Here is my program:
# ############################# BUMPER TEST ################
import PDALib
import time
import sys
import signal
# ################# BUMPER TEST ###########
# Bumpers are on
# DIO 10 Left Front
# DIO 9 Right Front
# DIO 8 Rear
# Wired to use internal pull-ups of the MCP23S17
# Bumper value is negative logic - 0 means bumper activated, normal 1
# Encoders are on DIO 11 and 12
# ##################
# Callback and setup to catch control-C and quit program
def signal_handler(signal, frame):
print '\n** Control-C Detected'
PDALib.LibExit()
sys.exit(0)
# Setup the callback to catch control-C
signal.signal(signal.SIGINT, signal_handler)
# ##################
# Set up all DIO channels as input for now
for pin in range(8,23+1):
PDALib.pinMode(pin,PDALib.INPUT)
# Set internal pull-ups on bumper channels
PDALib.setDioBit( PDALib.DIO_GPPU, 0 ) # set pin 8 pull-up
PDALib.setDioBit( PDALib.DIO_GPPU, 1 ) # set pin 9 pull-up
PDALib.setDioBit( PDALib.DIO_GPPU, 2 ) # set pin 10 pull-up
# Loop displaying bumpers and encoders
while True:
for pin in range(8,12+1):
print "Pin:", pin, PDALib.digitalRead(pin)
print "\n"
time.sleep(1)
#end whilehttp://forums.mikronauts.com/viewtopic.php?f=49&t=63&p=250#wrap