The RpiGpio interface allows you to use GPIO pins on a Raspberry Pi. The interface supports both INPUTS and OUTPUTS with various options. I've tried to cover all the types of I/O options that will
make this useful and easy to use. There are two ways of numbering the IO pins on a Raspberry Pi. The first is using the BOARD numbering system which equates to the physical pin numbers on the P1 header of the Raspberry Pi. The second is using the BCM numbering systems which equates to the Broadcom chip GPIO numbering scheme. The advantage of using the BOARD numbering system is that your hardware will always work, regardless of the board revision of the RPi. You will not need to rewire your connector or change your code. I have, however, noticed that many projects seem to use the BCM scheme. You may choose either one. GPIO pins on the 40 pin header are as follows: 3V3 (1) (2) 5V GPIO2 (3) (4) 5V GPIO3 (5) (6) GND GPIO4 (7) (8) GPIO14 GND (9) (10) GPIO15 GPIO17 (11) (12) GPIO18 GPIO27 (13) (14) GND GPIO22 (15) (16) GPIO23 3V3 (17) (18) GPIO24 GPIO10 (19) (20) GND GPIO9 (21) (22) GPIO25 GPIO11 (23) (24) GPIO8 GND (25) (26) GPIO7 GPIO0 (27) (28) GPIO1 GPIO5 (29) (30) GND GPIO6 (31) (32) GPIO12 GPIO13 (33) (34) GND GPIO19 (35) (36) GPIO16 GPIO26 (37) (38) GPIO20 GND (39) (40) GPIO21 Instance file syntax: You must set the board type to BOARD or BCM when you declare the interface. Declare the interface: Pytomation running on this raspberry pi with pin layout of type BCM rpi = RpiGpio(pin_layout='BCM', address=None, port=None, poll=None)
Pin_layout can be BCM or BOARD Address , port and poll time are not used yet, this interface only supports Pytomation running locally on the RPi. Set I/O pins: Telling Pytomation which pins to use and whether they are INPUT or OUPUT is done with the setPin command. The syntax is as follows: setPin(<pin
number>, <type>, pud=<string>, invert=<boolean>
,init=<string>, debounce=<integer>) pin number - (inputs or outputs) This is an integer value that relates to either the BOARD or the BCM pin depending on the pin_layout that was set when the interface was declared. type - (inputs or outputs) Type is a string value and declares whether the pin is an INPUT or OUTPUT. It must be either 'IN' or 'OUT' for input and output respectively. Optional arguments: pud=<string> - (inputs) Pud is a string value and declares whether the pin has a software pull up or pull down resister. The software pull up and pull down is supported in the Broadcom chipset of the Raspberry Pi. It must be passed as a value of pud='PULL_UP' or pud='PULL_DOWN' debounce =<integer> - (inputs) Debounce is a integer value and declares the time in milliseconds for the debounce. It ensures pins with pushbuttons etc that take time to settle will work.
invert=<boolean> - (inputs) Invert is a boolean value. This is commonly used when an input has a pull up resister and the pin is grounded to switch it. This obviously does NOT change the pin value, it inverts the state within Pytomation. The value can be True or False. Please not the case of the letters init=<string> - (outputs) Init is a string value. This option is added by including init='LOW' or init='HIGH'. This option adds an initial logic state to the OUTPUT pin when it is declared.
Examples: # These examples use type BOARD pins
# Set pin 3, GPIO-2 as INPUT with pull up resister, inverted state and
# 100ms debounce. rpi.setPin(3, 'IN', pud='PULL_UP', invert=True ,debounce=100)
# Set pin 5, GPIO-3 as INPUT with a pull down resister and 200ms debounce
rpi.setPin(5, 'IN', pud='PULL_DOWN', debounce=200)
# Set pin 7, GPIO-4 as OUTPUT, with initial value set to LOW state
rpi.setPin(7, 'OUT') or rpi.setPin(7, 'OUT', init='LOW')
# Set pin 7, GPIO-4 as OUTPUT, with initial value set to HIGH state
rpi.setPin(7, 'OUT', init='HIGH')
Please note that INVERT on an input is particularly useful when an input is pulled high and the pin must be grounded to operate. INVERT does not change the value of the pin, just the ON state within Pytomation. Using the pins in the instance file: This is used just like any other Pytomation interface. Example: #Inputs m_room_motion = Motion(address=17,
devices=rpi,
name="Room motion detectormytest")
# Outputs l_room_lamp = Light(address=26,
devices=(rpi),
name='Room Lamp')
|