Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

IO Pi ports

1 Views - Created 03/08/2023


Posted by:

eddieprice Avatar

I am using an IO Pi to control the pwm output from a PIC 12F629 microchip. The 629 has 6 GPIO pins, two are used for the pwm output and the other four are intended to be inputs to control the pwm output. I need a 4-bit port from the IO Pi expander board. Is that possible? I would imagine it means producing some code for the IO Pi. I want to be able to use the "write_port(port,0xXX)" instruction


Posted by:

andrew Avatar

United Kingdom

andrew Twitter  andrew Website  


If you wire up the first four pins from the bus on the IO Pi to your PIC micro you can use it as a four bit port with the write_port(port,0xXX) instruction.

The following python code would create an instance of the IOPi object on address 0x20 and set the first four pins to be high.

iobus = IOPi(0x20)

# set port 0 as outputs
iobus.set_port_direction(0, 0x00)

iobus.write_port(0, 0x0f)

If it is easier you can use a binary number instead of hex so you can see which of the pins are being set as high and low. The code below would set pins 1 and 3 as low and 2 and 4 as high.

iobus.write_port(0, 0b00001010)


Posted by:

eddieprice Avatar

Hi Andrew. Thanks for replying. Unfortunately I have wired the port up as pins 1,3,5,7 as one 4-bit port and pins 2,4,6,8 as the other port. I think I have found a way of doing it. I will set pins 2,4,6,8 to "0" and then output my code on pins 1,3,5,7 and then do the same with pins 1,3,5,7 set to "0" - not very elegant but it should work.

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.