Expander Pi IO
The Expander Pi is an Analogue, Digital and RTC development Interface for the Raspberry Pi
30/06/2015
Posted by:
allanwright
import timeimport threadingimport argparseimport pikafrom ABE_helpers import ABEHelpersfrom ABE_ExpanderPi import RTCfrom ABE_ExpanderPi import ADCfrom ABE_ExpanderPi import IOfrom ABE_ExpanderPi import DACimport timeimport os
i2c_helper = ABEHelpers()bus = i2c_helper.get_smbus()
io = IO(bus) # create an instance of the IO classrtc = RTC(bus) # create a new instance of the RTC class
io.set_port_direction( 0, 1 )io.set_port_direction( 1, 1 )
print "Test I/O ports" toggle = 0;while True: toggle = 1 - toggle value = toggle * 255 io.write_port( 0, value ) io.write_port( 1, value ) print "Time: " + rtc.read_time_AMW() + "set ports to ", value time.sleep(2)
30/06/2015
Posted by:
andrew
set_port_direction takes a value between 0 and 255 for the second variable so you can set the direction of each pin individually.
On each pin a value of 0 sets the pin as an output while 1 sets it as an input so if you wanted to set pins 2, 4, 6 and 8 as inputs and 1, 3, 5 and 7 as outputs you would use a value of 170 or 0b10101010 in binary.
Where you are setting the value as 1 that is setting the port direction to be output on all of the pins except the first one, pins 1 and 9 which are being set as inputs. To set all of the pins as outputs try using a value of 0.
io.set_port_direction( 0, 0 )
io.set_port_direction( 1, 0 )
Forum Notice – Closure to New Posts
As part of our compliance with the UK’s Online Safety Act, the AB Electronics UK support forum is now closed to new posts and replies.
We understand the importance of continued support for our products, so if you have a technical query or require assistance, please use the Contact Form or consult our Knowledge Base for helpful articles and documentation.
We appreciate your understanding and continued support.
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.