msellers
04-27-2009, 05:30 PM
If your application might benefit from being able to change the channel of a node in the field without using a PC running Portal, one solution is to add jumper straps from GPIO pins to ground. By "strapping" the board for a particular channel at powerup, the channel can be changed by your end user. This example uses GPIO pins to represent a binary value as shown:
1: GPIO 18 (pin 20)
2: GPIO 17 (pin 19)
4: GPIO 16 (pin 18)
8: GPIO 15 (pin 17)
If you want Channel 6 for example, add a jumper strap onto 2 and 4 to ground those pins. If you want channel 9, strap 1 and 8 to ground, and so on.
The following code in startup will then set the channel when powered up or reset.
def startupEvent():
setPinDir(15,False) #set to inputs
setPinDir(16,False)
setPinDir(17,False)
setPinDir(18,False)
setPinPullup(15,True) #enable pullups
setPinPullup(16,True)
setPinPullup(17,True)
setPinPullup(18,True)
chan = 15 - (peek(0x04) & 0x0F) #read all 4 pins as a nibble
setChannel(chan)
snappyGen.setHook(SnapConstants.HOOK_STARTUP, startupEvent)
This also works with several 16-position rotary switches when the Common pin is grounded and the 1,2,4 and 8 value pins are connected as shown above.
1: GPIO 18 (pin 20)
2: GPIO 17 (pin 19)
4: GPIO 16 (pin 18)
8: GPIO 15 (pin 17)
If you want Channel 6 for example, add a jumper strap onto 2 and 4 to ground those pins. If you want channel 9, strap 1 and 8 to ground, and so on.
The following code in startup will then set the channel when powered up or reset.
def startupEvent():
setPinDir(15,False) #set to inputs
setPinDir(16,False)
setPinDir(17,False)
setPinDir(18,False)
setPinPullup(15,True) #enable pullups
setPinPullup(16,True)
setPinPullup(17,True)
setPinPullup(18,True)
chan = 15 - (peek(0x04) & 0x0F) #read all 4 pins as a nibble
setChannel(chan)
snappyGen.setHook(SnapConstants.HOOK_STARTUP, startupEvent)
This also works with several 16-position rotary switches when the Common pin is grounded and the 1,2,4 and 8 value pins are connected as shown above.