8x2 LCD display I2C MCP23017 connections and code help.

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
I am trying to use an LCD display with my MCP23017 IC and Arduino UNO Rev 3 board but I can't find anything about the appropriete connections. The A0 , A1 and A2 pins of the MCP23017 are all connected to ground and reset pin to 5V. I use the LiquidCrystal_I2C.h library with the "Hello World" example but I think also the code needs modifications that I cant find out on my own ... Please help ....

P.S. Since I am not allowed to upload the .ino file I will just copy and paste the code here...

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}


void loop()
{
}
 

KeithWalker

Joined Jul 10, 2017
3,603
I am trying to use an LCD display with my MCP23017 IC and Arduino UNO Rev 3 board but I can't find anything about the appropriete connections. The A0 , A1 and A2 pins of the MCP23017 are all connected to ground and reset pin to 5V. I use the LiquidCrystal_I2C.h library with the "Hello World" example but I think also the code needs modifications that I cant find out on my own ... Please help ....

P.S. Since I am not allowed to upload the .ino file I will just copy and paste the code here...

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}


void loop()
{
}
Hi, I am not familiar with the MCP23017 i2c interface chip but I have wotked with the Arduino and LCD displays that use the HD44780 interface with the LiquidCrystal_I2C library. There is a dedicated library for the MCP23017 at Github thet might help you:
https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library
 
Last edited:
Can you provide the model number of the display and something like a schematic of how it is connected?

You can see just by comments in the example code for the library that you should probably be using a line like this:
LiquidCrystal_I2C lcd(0x27, 8, 2);

Do you know that the I2C address is 0x27?

The more information that you can provide, the higher the likelihood that you can get the problem solved.
 

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
The code isn't mine .. It is provided as an example of the library . The address of the MCP23017 is 0x20 and this is the datasheet both for MCP and the LCD . I have no scematic because I havent got a program to make one ... I may try to make one on "drawing" on my computer..
 

Attachments

KeithWalker

Joined Jul 10, 2017
3,603
The code isn't mine .. It is provided as an example of the library . The address of the MCP23017 is 0x20 and this is the datasheet both for MCP and the LCD . I have no scematic because I havent got a program to make one ... I may try to make one on "drawing" on my computer..
Do you get anything showing on the display or is it completely blank?
How have you connected Pin 3 on the display ( VO ) ?. This pin is used to set the correct contrast on the display. I usually connect it to the sliding contact of a 10 K ohm potentiometer, the ends of which are connected between +5V and ground. The contrast of the characters can be optimised by adjusting the pot. Without this you may not see anything on the display.
 
Last edited:

dendad

Joined Feb 20, 2016
4,635
One problem you will have is the connections between the MCP23017 and the display. There is no standard, so you will need to find out what MCP23017pins go where on the display.
Until you find that out, you will have great trouble driving it.
The Arduino code needs to have that info to work. I have used Ebay I2C LCDs and now make sure I just get the same ones each time as the connections seem to depend on the manufacturer. And I have deleted all libraries other than the one I finally got to work.
Are you making this display setup yourself or is it a commercial one?
I think the libraries for the Arduino expect the PCF8574 chip, not the MCP23017. Have a look at the LiquirCrystal_I2C.cpp file and you will see what pins the chip expects to be connected to the LCD.
This is part of what I have in the LiquidCrystal_I2C.cpp file.....

Code:
// Default library configuration parameters used by class constructor with
// only the I2C address field.
// ---------------------------------------------------------------------------
/*!
@defined
@abstract  Enable bit of the LCD
@discussion Defines the IO of the expander connected to the LCD Enable
*/
#define EN 6  // Enable bit

/*!
@defined
@abstract  Read/Write bit of the LCD
@discussion Defines the IO of the expander connected to the LCD Rw pin
*/
#define RW 5  // Read/Write bit

/*!
@defined
@abstract  Register bit of the LCD
@discussion Defines the IO of the expander connected to the LCD Register select pin
*/
#define RS 4  // Register select bit

/*!
@defined
@abstract  LCD dataline allocation this library only supports 4 bit LCD control
mode.
@discussion D4, D5, D6, D7 LCD data lines pin mapping of the extender module
*/
#define D4 0
#define D5 1
#define D6 2
#define D7 3

But some libraries let you specify the connections too...
Code:
include <LiquidCrystal_I2C.h>
#include <LCD.h>

// set the LCD address to 0x27 for a 16 chars 2 line display
// A FEW use address 0x3F
// Set the pins on the I2C chip used for LCD connections:
//  addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
Getting the I2C LCD running can be frustrating. It was for me, until I settled on one version.
I hope that helps.
 
Last edited:
I have not interfaced an LCD in that fashion, but I think that you will, in the end, be able to get this working because some searching suggests that many have.

Here is one such example.

Here is an Arduino I2C library with specific support for the MCP23017.

Hope it helps.
 

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
The MCP chip has A and B pins (as shown on the datasheet) . Which pins should I try connecting the lcd to ? A or B ?
I have a 10K Ohm resistor on VO (pin 3) of the LCD to manage the contrast
I know that I am not supposed to use the MCP for this project but this chip offers many pins and I can also connect and control multiple devices with it if needed .
When I connect the lcd to the chip it only displays on the first row 8 white rectangulars
I ve tested the LCD when connected directly to the arduino and it work fine
 
Last edited:

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
But some libraries let you specify the connections too...
Getting the I2C LCD running can be frustrating. It was for me, until I settled on one version.
I hope that helps.
How do I understand which pins it refers to ? The MCP has A and B type pins . On which should I connect the LCD to ?
 

dendad

Joined Feb 20, 2016
4,635
The LiquidTWI2.cpp file in the link...
Here is an Arduino I2C library with specific support for the MCP23017.
The port pins for the LCD will be,
PB0 ... LCD_LB (not used for your display)
PB1 ... LCD_D7
PB2 ... LCD_D6
PB3 ... LCD_D5
PB4 ... LCD_D4
PB5 ... LCD_EN
PB6 ... LCD_RW
PB7 ... LCD_RS

Code:
//MCP23017 - Adafruit RGB LCD Shield
// bit pattern for the burstBits function is
//
//  B7 B6 B5 B4 B3 B2 B1 B0 A7 A6 A5 A4 A3 A2 A1 A0 - MCP23017
//  RS RW EN D4 D5 D6 D7 LB LG LR BZ B4 B3 B2 B1 B0
//  15 14 13 12 11 10 9  8  7  6  5  4  3  2  1  0
#define M17_BIT_RS 0x8000
#define M17_BIT_RW 0x4000
#define M17_BIT_EN 0x2000
#define M17_BIT_D4 0x1000
#define M17_BIT_D5 0x0800
#define M17_BIT_D6 0x0400
#define M17_BIT_D7 0x0200
If this works ok for your display or not, I do not know, as it is for a colour one. It may drive the same, or it may not.
As I mentioned before, most I2C displays do not use the MCP23017, so you may have some fun getting it going.

I know that I am not supposed to use the MCP for this project but this chip offers many pins and I can also connect and control multiple devices with it if needed .
You can use multiple chips on the same I2C bus by changing the address pins so there would be no problem running a "standard" PCF8574 8 bit I2C chip for the LCD, and another for inputs and outputs. But using just one MCP23017 is a bit more elegant, as long as you can figure out the code to drive it.
 
Last edited:

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
nope it still doesn't work...I used the code that you gave me with the appropriate modifications (LCD was 16x2 , changed at 8x2) tried different pins added a 10kOhm potentiometer for contrast . The only thing that I get displayed is the white rectangulars . Again tested the LCD without I2C works fine . Is there a code that I can specify the pins on my own ? Should I just give up with the MCP and buy a different IC and if so which IC should I get ?
 

dendad

Joined Feb 20, 2016
4,635
Are you still using the MCP23017?
The code is probably not for that chip, but for an PCF8574A, unless you have found a different library.
Firstly, test to see if you can actually drive the IC.
Try looking at the pins to see if they are changing. Do you have an oscilloscope? If not, add an LED with a 1K series resistor to a pin of the IC and see if you can wink it.
These boards use the PCF8574A chip.
https://www.ebay.com.au/itm/IIC-I2C...444751?hash=item2ccdbf90cf:g:PFgAAOSwp7taYGWC
All the I2C character LCDs with the external boards I've seen do.
 
Last edited:

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
Done the LED experiment the chip works fine . Only problem , every code I found online uses all PA and PB pin ... Makes all PA or PB pins OUTPUTS , blinks either all PA or PB . No code uses just one pin...
 

dendad

Joined Feb 20, 2016
4,635
I have not tried it but look at this site...
https://www.best-microcontroller-projects.com/mcp23017.html

This section shows how their library drives each pin, just the same as an Arduino pin.

Library Operation
Pin definition for MCP23017 library
Note: In the library pins are labelled from 0 to 15 where:

pin 0 is bit 0 of port A
pin 7 is bit 7 of port A
pin 8 is bit 0 of port B
pin 15 is bit 7 of port B

MPC23017 I/O control functions
Single Bit I/O

Similar member functions to the pin controls on the Arduino are used to control the MCP23017 pins:

mcp.pinMode(0, OUTPUT);
mcp.digitalWrite(0,HIGH);
mcp.digitalRead(0);


So this above is the same as the Arduino.
 
Top