fehrenbach
Posts: 10
Joined: Mon Dec 08, 2014 5:30 am

MCP23017 I2C C Code

Tue Jan 27, 2015 6:43 am

I am attempting to interface a MCP23017 to the Raspberry Pi using C code. I can communicate with the device using Linux i2c-tools commands icset and icget.

The problem is that I'm having difficulty finding C code that I can understand that will do the same thing. The code needs to let me specify the register that I read or write to using a variable. I have seen simple code that interfaces with a PCF8574 but it doesn't seem to let me specify the register that I am communicating to within the device.

Paul

User avatar
DougieLawson
Posts: 40789
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MCP23017 I2C C Code

Tue Jan 27, 2015 8:09 am

Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
BAStumm
Posts: 134
Joined: Fri Aug 23, 2013 3:37 pm
Location: Loon Lake, WA USA
Contact: Website

Re: MCP23017 I2C C Code

Tue Jan 27, 2015 8:36 pm


fehrenbach
Posts: 10
Joined: Mon Dec 08, 2014 5:30 am

Re: MCP23017 I2C C Code

Thu Jan 29, 2015 5:14 am

Thanks,

I'm having a problem with header locations. My program is in ...programming/i2c
I use the -lwiringPi option at the end of the compile line. I get a compile error cannot find -lwiringPi.
I'm somewhat new to C and have also tried to locate copies of the wiringPi.h and mcp23017.h files in /usr/local/include
That doesn't work either.

User avatar
DougieLawson
Posts: 40789
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MCP23017 I2C C Code

Thu Jan 29, 2015 11:09 am

Have you installed wiringPi? It's not a built-in component.

http://wiringpi.com/download-and-install/
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Return to “C/C++”