MCP23008 LCD (Adafruit i2c Backpack)

94 views
Skip to first unread message

Alex Noble

unread,
Dec 12, 2016, 7:35:06 PM12/12/16
to Pi4J
Hey,


Has anyone been able to get the i2c lcd backpack from Adafruit working with pi4j?


I've tried using I2CLcdDisplay class, defining the pins (Not sure if I've got them right)


I've tried using the generic LCD class, but for some reason it crashes my i2c bus and stops everything working. (It fills every address up with a device, when obviously I've only got one)

I'm able to turn the LCD Backlight on and off if I provision a digital pin and set its state. So things are communicating.

I've tried hundreds of different things and I'm getting desperate. (It's for my finals)

I've managed to use the script provided by Adafruit in Python, Which works, But I need to do this in Java and I don't want to resort to executing a python script in java.

Any pointers would be greatly appreciated.

Thanks,

Alex Noble

unread,
Dec 12, 2016, 7:37:31 PM12/12/16
to Pi4J
Link to backpack in question:

Alex Noble

unread,
Dec 12, 2016, 7:51:49 PM12/12/16
to Pi4J
Some more info:

my code:

public static void main(String[] args) throws Exception {

 
// create gpio controller
 
final GpioController gpio = GpioFactory.getInstance();

 
// create custom MCP23008 GPIO provider
 
final MCP23008GpioProvider provider = new MCP23008GpioProvider(I2CBus.BUS_1, I2C_ADDRESS);

 
GpioPinDigitalOutput myOutputs[] = {
 gpio
.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_00),
 gpio
.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_01),
 gpio
.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_02),
 gpio
.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_03),
 gpio
.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_04),
 gpio
.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_05),
 gpio
.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_06),
 gpio
.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_07, PinState.LOW)
 
};

 
GpioLcdDisplay lcd = new GpioLcdDisplay(row, col, myOutputs[1].getPin(), myOutputs[2].getPin(), myOutputs[3].getPin(), myOutputs[4].getPin(), myOutputs[5].getPin(), myOutputs[6].getPin());


}




This is what I mean that a device appears on every address:


     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77

On Tuesday, 13 December 2016 00:35:06 UTC, Alex Noble wrote:

Andrew Chandler

unread,
Dec 13, 2016, 7:22:47 AM12/13/16
to Pi4J
Good morning!
If you can wait a day or so I should be able to help somewhat or at least try. What I can tell you right now is that the i2c lcd backpack was written for a different chipset but might be adaptable with dome work...there was example code under the examples projects if I recall correctly (it's been a little while since I wrote the class)
Question #1 -are you hooking up to the backpack with i2c or spi?

Question #2. - can you post your i2cdetect output?

Question #3. - when you wired the backpack to the lcd did you use 4 data lines or 8?

Alex Noble

unread,
Dec 13, 2016, 8:34:59 AM12/13/16
to Pi4J
Good afternoon!

Yes I can wait, I can work on the less LCD related things! :)

Question 1 - i2c

Question 2 - Not at the pi at the mo, but as shown above in a reply, thats my output once I ran the code, if I reboot and don't run the code it shows a device on 0x20, Once I've got home this evening I will reply with the exact outputs.

Question 3 - So all the wires I've got running from the backpack is ground, power, clk, and data. When I had the LCD running straight to GPIO, I was using 8 (I think??) wires. This was a few months back, I forget. I can give you a photo of what I've done when I've got home.

Thanks,
Alex

Alex Noble

unread,
Dec 13, 2016, 8:37:59 AM12/13/16
to Pi4J
Forgot to mention, I'm using a HD44780 LCD.

When directly used to GPIO I was using 4 data lines. (Looking at schematics I remember now) Only other wires I used was for backlight, ground, power etc.

synergi...@gmail.com

unread,
May 12, 2017, 2:37:12 AM5/12/17
to Pi4J
Hello, I have also tried to use MCP23008 (Adafruit LCD) with "GpioLcdDisplay" or "I2CLcdDisplay" but with no succes.
Communication with chip is OK and I can get backlight blink using following code adapted from Pi4J-MCP23008GpioExample.java.
Could somebody give some guidance?

import java.io.IOException;

import com.pi4j.gpio.extension.mcp.MCP23008GpioProvider;
import com.pi4j.gpio.extension.mcp.MCP23008Pin;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException;


public class MCP23008GpioExample {

    public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {

        System.out.println("<--Pi4J--> MCP23008 GPIO Example ... started.");

        // create gpio controller
        final GpioController gpio = GpioFactory.getInstance();

        // create custom MCP23008 GPIO provider
        final MCP23008GpioProvider provider = new MCP23008GpioProvider(I2CBus.BUS_1, 0x20);


        // provision gpio output pins and make sure they are all LOW at startup
        GpioPinDigitalOutput myOutputs[] = {
            gpio.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_00, "MyOutput-B0", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_01, "MyOutput-B1", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_02, "MyOutput-B2", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_03, "MyOutput-B3", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_04, "MyOutput-B4", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_05, "MyOutput-B5", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_06, "MyOutput-B6", PinState.LOW),
            gpio.provisionDigitalOutputPin(provider, MCP23008Pin.GPIO_07, "MyOutput-B7", PinState.LOW)
          };

        // keep program running for 20 seconds
        for (int count = 0; count < 10; count++) {
            gpio.setState(true, myOutputs[7]);
            Thread.sleep(1000);
            gpio.setState(false, myOutputs[7]);
            Thread.sleep(1000);
        }

        // stop all GPIO activity/threads by shutting down the GPIO controller
        // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
        gpio.shutdown();

        System.out.println("Exiting MCP23008GpioExample");
    }
}

Reply all
Reply to author
Forward
0 new messages