FREE Standard Delivery for orders over £35 (ex VAT)
Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

IO Pi ports

The IO Pi Plus is a 32 channel MCP23017 GPIO expander for the Raspberry Pi

03/08/2023

Posted by:
eddieprice

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

03/08/2023

Posted by:
andrew

andrew Avatar

Hi

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)

04/08/2023

Posted by:
eddieprice

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.