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

IO Pi Plus programming C error "Failed to write to i2c device for write"

2436 Views - Created 07/03/2018

07/03/2018

Posted by:
Ben Vervoort

Users Avatar

Location:
Herenthout, Belgium

Hi,

I'm having some troubles getting my Raspberry Pi 3+ to work with the IO Pi Plus. I'm testing this IO expander for the first time, but always get following error: "Failed to write to i2c device for write"

Hardware:

- Instead of using the OI Pi Plus header, I used a few jumper wires for now to connect 5V, GND, SDA and SCL from the Pi to the OI Pi Plus.

- Also removed the solder jumper link already (I will use a seperate 5V power supply in the future).

- No changes to addresses, so 0x20 for IC 1 (000) and 0x21 for IC 2 (001).

Post image

Software:

- Pre loaded NOOBS

- Geany for C programming

- Installed the ABElectronics libraries

- ARM I2C enabled in raspi-config

I'm using the demo-iopiread.c code (see also /ABElectronics_C_Libraries). When compiling, I first got 5 warnings "implicit declaration of function" (strerror, write, read, close and usleep), by adding #include <unistd.h> to ABE_IoPi.c, I removed 3 warnings (write, read, close). Don't know how to get the 2 other warnings go away, but not really my concern for now, I guess.

When I run the demo code, one of the first things to execute is function IOPi_init(0x20)

Post image

Then function write_byte_data

Post image

And then when the code fails

Post image

 

I'm searching for hours now and can't figure out why I can't write/communicate to the MCP23017 .

I'm not even sure if this is an hardware or software problem. 

Can someone help me with this issue?

Thank you in advance

07/03/2018

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi Ben

Sorry, there was a bug with the IO Pi C library which was stopping it from compiling on the recent releases of Raspbian Linux.  I have updated the library and it should be working now, please can you download a new version from our github repository and see if it works on your Raspberry Pi?

You will also need to make sure the libi2c-dev package is installed for the code to compile.  You can download it using apt-get.

sudo apt-get install libi2c-dev

 

AB Electronics UK Tech Support

07/03/2018

Posted by:
Ben Vervoort

Users Avatar

Location:
Herenthout, Belgium

Hi Andrew,

thanks for the fast response! I replaced the libraries with the new you just updated and reinstalled libi2c-dev.

I tried the code again, but still got the same error "Failed to write to ic2 device for write".

I also switched to another IO Pi Plus board and retried, still the same problem.

 

07/03/2018

Posted by:
Ben Vervoort

Users Avatar

Location:
Herenthout, Belgium

but with the new code, all warnings after compiling are gone :)

07/03/2018

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Can you try running "sudo i2cdetect -y 1" and see if the IO Pi appears on the I2C bus?  It should show up as addresses 0x20 and 0x21.

If the board does appear on 0x20 and 0x21 can you try our python library and see if that can talk to the board.  If it does not appear then check the connections between the Raspberry Pi and the IO Pi to make sure it has a good ground and power connections.  You will need to connect the 3.3V pin as well as supplying 5V to the IO Pi as the 3.3V is used on the I2C level shifter circuit.

AB Electronics UK Tech Support

07/03/2018

Posted by:
Ben Vervoort

Users Avatar

Location:
Herenthout, Belgium

Applying the 3,3V to the IO Pi Plus did the trick!

I overlooked this while checking the schematic of the OI Pi Plus. And now it also shows up with the i2c detect

Thank you so much for you're quick help! 

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.