Page 1 of 1
16x2 LCD displaying blocks when connected with MCP23017
Posted: Tue Jul 28, 2015 1:49 pm
by pkhandelwal
I am using a 16x2 LCD and have it connected with MCP23017 16-bit IO port expander. To display message to the LCD, I am using Adafruit LCD library. The also have a test python code to get it working with MCP23017. I have changed the pin according to the connections I have made but it seems to be displaying only blocks in the first row of the LCD. I tried different pins, but I can't get it to work.
LCD:
http://www.ebay.in/itm/16x2-Character-L ... 339a745a6c
Adafruit library:
https://github.com/adafruit/Adafruit-Ra ... it_CharLCD
Also I have I2C enabled on my Raspberry Pi 2
Any idea why this is happening or is there any step I am missing.
Thanks
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Tue Jul 28, 2015 2:33 pm
by DougieLawson
Try this:
https://github.com/DougieLawson/Raspber ... nified_LCD that's running right now on a RPi with a quick2wire MCP23017 I2C expansion board.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Tue Jul 28, 2015 2:51 pm
by pkhandelwal
Thanks! I will try and post the update here.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Tue Jul 28, 2015 3:35 pm
by pkhandelwal
One more thing, I am using python for development. Just wanted to know if there is something I can do with Python code from the Adafruit library to make it working.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Tue Jul 28, 2015 3:48 pm
by BMS Doug
pkhandelwal wrote:One more thing, I am using python for development. Just wanted to know if there is something I can do with Python code from the Adafruit library to make it working.
Yes.
(Blame Dougie Lawson for that answer, I just read something he linked).
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Tue Jul 28, 2015 3:57 pm
by BMS Doug
do you mean the
MCP23017 example code or the
LCD example code?
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Tue Jul 28, 2015 4:04 pm
by pkhandelwal
BMS Doug wrote:do you mean the
MCP23017 example code or the
LCD example code?
MCP23017 example. I am using the sample code from their git repo and have connected the pins as per the code. But when I run it, the LCD displays blocks in the first line of the LCD. I have checked and re-checked the wiring.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Tue Jul 28, 2015 7:40 pm
by FTrevorGowen
pkhandelwal wrote:BMS Doug wrote:do you mean the
MCP23017 example code or the
LCD example code?
MCP23017 example. I am using the sample code from their git repo and have connected the pins as per the code. But when I run it, the LCD displays blocks in the first line of the LCD. I have checked and re-checked the wiring.
I can't comment on any Python code (I use 'C' and my own MCP23017 interfaces) but if your "line of blocks" is like what I show here:
http://www.cpmspectrepi.webspace.virgin ... alLCD.html
then that suggests that the Python code is not initialising the display correctly. This may be a timing issue since I've found that some displays require longer "E-strobe" pulse lengths than may have been "hard-coded" in some programs, especially if the "4-bit" interface method is in use:
http://www.cpmspectrepi.webspace.virgin ... gData.html
Trev.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Wed Jul 29, 2015 11:29 am
by DougieLawson
Try using my C program, if that works then we know it's a bug in Adafruit's python library. If it doesn't work then it's a hardware problem.
The common hardware problem with LCDs is not wiring a 10K pot on the V0 pin. When the voltage on V0 isn't present (you get a blank display) when it is 5V0 you get nothing but blocks.

Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Wed Jul 29, 2015 3:04 pm
by pkhandelwal
DougieLawson wrote:Try using my C program, if that works then we know it's a bug in Adafruit's python library. If it doesn't work then it's a hardware problem.
The common hardware problem with LCDs is not wiring a 10K pot on the V0 pin. When the voltage on V0 isn't present (you get a blank display) when it is 5V0 you get nothing but blocks.

Thanks for the reply and sketch! I don't have a 10K pot. right now with me. V0 pin on my LCD is grounded. Will that work? When I use other Adafruit library to display text on LCD it work (when the LCD is connected directly to the PI). Or is it may be the LCD is not getting initialize correctly?
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Wed Jul 29, 2015 7:15 pm
by DougieLawson
You can't connect V0 directly to 5V0 or GND it has to have a voltage somewhere between 0 and 5V0. If it's grounded the display may not work.
Also check your other wiring very carefully, does it match the list of pins in the Adafruit library module?
Code: Select all
def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None):
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Thu Jul 30, 2015 1:59 pm
by pkhandelwal
This is the wiring I have done. As I mentioned, I don't have a 10k pot. right now with me. I will get it in a day or 2. The Adafruit library has a constructor which I am overriding by passing my pin numbers when I am initializing it.
This is the code I have for initializing:
Code: Select all
lcd = Adafruit_CharLCD(pin_rs=0, pin_e=1, pins_db=[4,5,6,7], GPIO=mcp)
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Thu Jul 30, 2015 2:55 pm
by JimmyN
I use 16x2 and 20x4 LCD's with the Adafruit library.
This is what I use:
Code: Select all
import Adafruit_CharLCD as LCD
lcd_rs = 27
lcd_en = 22
lcd_d4 = 25
lcd_d5 = 24
lcd_d6 = 23
lcd_d7 = 18
lcd_backlight = 4
lcd_columns = 16
lcd_rows = 2
# Initialize the LCD
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Thu Jul 30, 2015 3:06 pm
by Massi
i don't know the code, but are you sure this has not to be
?
if you swap datalines you'll get "something" on the display, but not what you expect (blocks and broken chars)
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Thu Jul 30, 2015 3:57 pm
by pkhandelwal
Massi wrote:
i don't know the code, but are you sure this has not to be
?
if you swap datalines you'll get "something" on the display, but not what you expect (blocks and broken chars)
I tried changing the pins, but still same blocks are being displayed on the LCD.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Thu Jul 30, 2015 11:01 pm
by DougieLawson
pkhandelwal wrote:
What's that MCP23017 doing there? Why are you trying to use the GPIO library when your LCD is connected on the MCP23017 on the I2C bus?
You need to find a python library that will drive an LCD on I2C (device 0x20) on GPIOA on the MCP23017.
My C code sample has a I2C version.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Thu Jul 30, 2015 11:36 pm
by Douglas6
Adafruit has a Python library for their 16x2 display wired to an MCP23017:
https://github.com/adafruit/Adafruit_Python_CharLCD.git. I'm not saying it's wired the same way.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Fri Jul 31, 2015 3:21 am
by pkhandelwal
DougieLawson wrote:pkhandelwal wrote:
What's that MCP23017 doing there? Why are you trying to use the GPIO library when your LCD is connected on the MCP23017 on the I2C bus?
You need to find a python library that will drive an LCD on I2C (device 0x20) on GPIOA on the MCP23017.
My C code sample has a I2C version.
I am using the code which Adafruit has in their repository:
https://github.com/adafruit/Adafruit-Ra ... XX_test.py
The code has a MCP230xx support and this is what I am using. I found this library yesterday. I will try this today and let you know the results. Thanks for the help

Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Fri Jul 31, 2015 3:22 am
by pkhandelwal
Thanks!! I will try it tonight and let you know.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Sat Aug 01, 2015 5:32 am
by pkhandelwal
Here it is what I have tried so far. I tried using DougieLawson's C library but it didn't worked either. I changed the wiring as suggested in the readme file before using Dougie's code. Compilation was successful, but when I execute the i2clcd noting
happened, the terminal just frozen up. I have to press CTRL+C to terminate the program.
I have used another Adafruit library for CharLCD which supports MCP23017 but it has also the same output i.e. displaying blocks.
What I can understand from all the inputs by all is that there are 3 possibilities of why I am not able to get it to work:
1. The time delay in initializing the LCD. The library I am using is just not going to work because of the time delay when using it with MCP23017.
2. The contrast pin should not be grounded and should be used with a 10K pot, which unfortunately I do not have it with me at the moment. I will have it one by Tuesday.
To me the first point looks pretty obvious. And maybe this is the problem only we face with PI2!
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Sat Aug 01, 2015 10:23 am
by DougieLawson
Check your Wiring.
My code uses GPIOB / OLATB
GPB0 (pin#1)

LCD_D4 (pin#11)
GPB1 (pin#2)

LCD_D5 (pin#12)
GPB2 (pin#3)

LCD_D6 (pin#13)
GPB3 (pin#4)

LCD_D7 (pin#14)
GPB4 (pin#5)

LCD_EN (pin#6)
GPB6 (pin#7)

LCD_RS (pin#4)
GPB7 (pin#8)

LCD_BL+ (pin#15)
LCD_BL- (pin#16) is wired through a resistor to GND.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Sat Aug 01, 2015 11:32 am
by pkhandelwal
DougieLawson wrote:Check your Wiring.
My code uses GPIOB / OLATB
GPB0 (pin#1)

LCD_D4 (pin#11)
GPB1 (pin#2)

LCD_D5 (pin#12)
GPB2 (pin#3)

LCD_D6 (pin#13)
GPB3 (pin#4)

LCD_D7 (pin#14)
GPB4 (pin#5)

LCD_EN (pin#6)
GPB6 (pin#7)

LCD_RS (pin#4)
GPB7 (pin#8)

LCD_BL+ (pin#15)
LCD_BL- (pin#16) is wired through a resistor to GND.
Yes, it worked!!

but the display shows some scrambled letters like ?, +, /, ??, 3 etc. Is it a problem of the contrast?
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Sat Aug 01, 2015 12:02 pm
by DougieLawson
If the letters are scrambled you've got GPB0-GPB3 wired to the wrong pins on the LCD.
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Sat Aug 01, 2015 12:22 pm
by pkhandelwal
I checked many times, but GPB0-GPB3 are wired correctly. What else I can check?
Re: 16x2 LCD displaying blocks when connected with MCP23017
Posted: Sat Aug 01, 2015 2:37 pm
by pkhandelwal
OK, I got it working!!
It was a wire problem. One of the data wire was faulty.
Thank you very much DougieLawson and all the guys for their time and inputs. Even though the problem came out to be a different one than I thought, I still learned new things from you guys.
Thanks a lot again
