Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

bus2 addressing with C code

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

07/03/2017

Posted by:
rs232

rs232 Avatar

Hello,I'm trying to programming the IO PI PLUS with C language.My hello world program is a blinking led! I have jumpered correctly the IO PI PLUS board:0x20 bus10x21 bus2If I try to use 0x20 address all works correctly, but when I change it to 0x21 I have no the same result! :(This is my C code:#include <ABE_IoPi.h>int main(int argc, char **argv){ IOPi_init(0x21); // initialise one of the io pi buses on i2c address 0x21 set_port_direction(0x21,0, 0x00); // set the direction for bank 0 to be outputs set_port_direction(0x21,1, 0x00); // set the direction for bank 1 to be outputs write_port(0x21,1, 0xFF); while (1){ write_pin(0x21,0x1, 1); // turn pin 1 on and off at 1 second intervals usleep(1000000); write_pin(0x21,0x1, 0); usleep(1000000); } return (0);}I tried to use a python equivalent code and with this one, the 0x21 bus address works correctly.My led is blinking!#!/usr/bin/pythonfrom ABE_helpers import ABEHelpersfrom ABE_IoPi import IoPiimport timei2c_helper = ABEHelpers()i2c_bus = i2c_helper.get_smbus()bus = IoPi(i2c_bus, 0x21)bus.set_port_direction(0, 0x00)bus.write_port(0, 0x00)while True: bus.write_pin(1, 1) time.sleep(1) bus.write_pin(1, 0) time.sleep(1)Could you please let me know what's is wrong in my C code?thanksrs232.

07/03/2017

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hello

I just tried your code on an IO Pi Plus and it appears to be working correctly. Pin 1 on bus 2 was switching on and off.

Can you please check that you are using the most recent version of the IO Pi C library from our GitHub repository?

07/03/2017

Posted by:
rs232

rs232 Avatar

Hello Andrew,thanks for your reply.I think to have cloned last github version. But I'll check.Do you know some difference?rs232

07/03/2017

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

There was a bug with an earlier version of the library where it would not select the correct chip when writing to the IO Pi.

09/03/2017

Posted by:
rs232

rs232 Avatar

Hello Andrew,thanks for your reply.You were right, with the last github version it works!Many thanksrs232

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.