Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

Expander Pi IO

2706 Views - Created 05/10/2015


Posted by:

allanwright Avatar

I don't know if this is a bug, a hardware problem or my mistake, but I am running the following code in the Adafruit IDE. It just toggles all of the pins in each IO port on the Expander Pi from 1 to 0. All of the pins are working except pin 1 and pin 9 (ie. pin 0 of each port) which appear to be floating. Any suggestions?
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)


Posted by:

andrew Avatar

United Kingdom

andrew Twitter  andrew Website  

The problem appears to be with the io.set_port_direction( 0, 1 ) and io.set_port_direction( 1, 1 ).

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 )

Sign in to post your reply

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.