twocats
Posts: 3
Joined: Fri Jan 06, 2017 3:32 pm

Pi4J MCP23017 gives "Failed to select slave device"

Fri Jan 06, 2017 3:47 pm

Hi All,
I have a raspberry B rev2 (revision 000f from /proc/cpuinfo)
I'm running Raspbian GNU/Linux 8 (jessie) kernel 4.4.37+ #936 Fri Dec 9 16:53:10 GMT 2016 armv6l
/boot/config has dtoverlay=mcp23017 (with or without this the error still occurs)
(with the dtoverlay) the MCP23017 device is recognised and is presented to the /sys FS as
/sys/devices/platform/soc/20804000.i2c/i2c-1/1-0020/gpio/gpiochip496

using the example MCP23017GpioExample code - having changed the provider line to:

Code: Select all

provider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x20);
when i run

Code: Select all

java -cp pi4j-example-1.2-SNAPSHOT.jar:pi4j-core-1.2-20161229.215408-19.jar:pi4j-device-1.2-20161229.215426-19.jar:pi4j-gpio-extension-1.2-20161229.215417-19.jar MCP23017GpioExample
I get the error :

Code: Select all

<--Pi4J--> MCP23017 GPIO Example ... started.
Exception in thread "main" com.pi4j.io.i2c.I2CIOException: Failed to select slave device!
	at com.pi4j.io.i2c.impl.I2CBusImpl.selectBusSlave(I2CBusImpl.java:284)
	at com.pi4j.io.i2c.impl.I2CBusImpl.runBusLockedDeviceAction(I2CBusImpl.java:243)
Any thoughts?

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

Re: Pi4J MCP23017 gives "Failed to select slave device"

Fri Jan 06, 2017 7:59 pm

Is your MCP23017 connected correctly? Have you tied the A0, A1 & A2 pins to GND?

What does i2cdetect -y 1 show?
You may need to use sudo apt-get install i2c-tools to get that program available for you.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

twocats
Posts: 3
Joined: Fri Jan 06, 2017 3:32 pm

Re: Pi4J MCP23017 gives "Failed to select slave device"

Fri Jan 06, 2017 8:40 pm

Yes its connected correctly - I can control it directly using the /sys filing system.
It will happily read and change the output. Either by just simple command line commands
or via python.

i2c shows this :

Code: Select all

i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
which in case the formatting is incorrect shows I have 2 devices - the MCP at address 0x20 and the RTC at 0x68

If on the command line I do

Code: Select all

echo 496 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio496/direction
echo 1 > /sys/class/gpio/gpio496/value 
sleep 1 
echo 0 > /sys/class/gpio/gpio496/value 
it will change the output correctly.
likewise I can do the same and it will read correctly.

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

Re: Pi4J MCP23017 gives "Failed to select slave device"

Fri Jan 06, 2017 9:39 pm

That 'UU' status means the device has been captured by the kernel and isn't available for userspace programs. So if your Java program doesn't use the /sys filesystem interface you'll need to remove that overlay for the MCP23017 and reboot.

The stuff here: https://github.com/Pi4J/pi4j/blob/maste ... ample.java doesn't need the overlay. It uses /dev/i2c-1 driving that with the Java native interface (JNI) code in com_pi4j_wiringpi_I2C.c.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

twocats
Posts: 3
Joined: Fri Jan 06, 2017 3:32 pm

Re: Pi4J MCP23017 gives "Failed to select slave device"

Fri Jan 06, 2017 11:55 pm

Ace that works!
(I've black listed gpio_mcp23s08 as well for good measure!)
Thanks!

Return to “Java”