About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Search
Register or Sign In
Forum

Expander Pi IO

1935 Views - Created 05/10/2015

30/06/2015

Posted by:
allanwright

Users 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 time
import threading
import argparse
import pika
from ABE_helpers import ABEHelpers
from ABE_ExpanderPi import RTC
from ABE_ExpanderPi import ADC
from ABE_ExpanderPi import IO
from ABE_ExpanderPi import DAC
import time
import os

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

io = IO(bus) # create an instance of the IO class
rtc = 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

Users Avatar

Location:
United Kingdom

Users Twitter  Users 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 outputs on all of the pins except the first one, pin 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 )

AB Electronics UK Tech 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.