ADAFRUIT_MCP23017 library and LCD 16x2 Display

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Good day all,

I made my own LCD shield for design reason.

I am using then Adafruit_MCP23017.h library. How do I map the rs or the en input from the LCD to an output from the MCP23017?

Read a button and switch a LED works.

But know I have the

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

line in my code. Here I have to replace the rs, en, d4, d5, d6, d7.

Regards


Andy

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by adafruit_support_bill »

The RGB LCD Shield uses the same chip to control a 16x2 lcd display.

You can find links to the schematic and library here: https://learn.adafruit.com/rgb-lcd-shield/downloads

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Thanks for your quick reply,

the adafruit shield is using B7, B5, B4, B3, B2 B1 for RS,EN,D4,D5,D6,D7.

My shield is using B2, B3,B4,B5,B6,B7.

Is there anyway where you can define your own ports to drive the LCD?

Regards

Andy

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

I had a look at the .cpp file

Do I have to change this part in the .cpp file?


from
// the I/O expander pinout
_rs_pin = 15;
_rw_pin = 14;
_enable_pin = 13;
_data_pins[0] = 12; // really d4
_data_pins[1] = 11; // really d5
_data_pins[2] = 10; // really d6
_data_pins[3] = 9; // really d7


to

// the I/O expander pinout
_rs_pin = 10;
_rw_pin = 14; //---->not used LCD pin connected to gnd
_enable_pin = 11;
_data_pins[0] = 12; // really d4
_data_pins[1] = 13; // really d5
_data_pins[2] = 14; // really d6
_data_pins[3] = 15; // really d7

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by adafruit_support_bill »

If those are the pins you are using, that should do it.

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Thanks a lot.

I'm busy trying this out.

Regards

Andy

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Nope,

didnt work out.

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Lets take another way.

I used the ADAFRUIT_MCP23017 library.

Here I could program it in this way that I press a button, connected to MCP pin 5 and toggle an output MCP output Nr. 8.

So o far that works.

Now I just need to declare the MCP outputs to RS,EN,D4,D5,D6,D7.

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

Code

----------------------------------------------------------------------------------------------------------

Code: Select all

#include <Wire.h>
#include "Adafruit_MCP23017.h"
#include <LiquidCrystal.h>

Adafruit_MCP23017 mcp;
void setup() {  
  mcp.begin();      // use default address 0
  mcp.pinMode(0, INPUT);    // Button UP
  mcp.pinMode(1, OUTPUT);   // NC
  mcp.pinMode(2, INPUT);    // Button Right
  mcp.pinMode(3, INPUT);    // Button Left
  mcp.pinMode(4, OUTPUT);   // Buzzer
  mcp.pinMode(5, INPUT);    // Button Down
  mcp.pinMode(6, OUTPUT);   // NC
  mcp.pinMode(7, OUTPUT);   // NC
  mcp.pinMode(8, OUTPUT);   // Green LED
  mcp.pinMode(9, OUTPUT);   // Red LED
  mcp.pinMode(10, OUTPUT);  // LCD RS 
  mcp.pinMode(11, OUTPUT);  // LCD EN
  mcp.pinMode(12, OUTPUT);  // LCD D4
  mcp.pinMode(13, OUTPUT);  // LCD D5
  mcp.pinMode(14, OUTPUT);  // LCD D6
  mcp.pinMode(15, OUTPUT);  // LCD D7
}


void loop() {
 
  mcp.digitalWrite(8, mcp.digitalRead(5));
  mcp.digitalWrite(4, mcp.digitalRead(0));
  mcp.digitalWrite(9, mcp.digitalRead(3));

 
}
----------------------------------------------------------------------------------------------------------------

That works so far.

I just want to include the LCD.

Regards

Andy
Last edited by adafruit_support_bill on Tue Sep 18, 2018 10:57 am, edited 1 time in total.
Reason: Please use [code] tags when submitting code to the forums

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by adafruit_support_bill »

You can't use the standard LiquidCrystal library - since it does not know how you communicate via the port expander.

The Adafruit_RGBLCDShield library shows how to do it.
https://learn.adafruit.com/rgb-lcd-shield/downloads

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Thanks for your reply,

I did change the adafruitRGBLCD_shield.cpp to my LCD pins.

// the I/O expander pinout
_rs_pin = 10;
_rw_pin = 255;
_enable_pin = 11;
_data_pins[0] = 12; // really d4
_data_pins[1] = 13; // really d5
_data_pins[2] = 14; // really d6
_data_pins[3] = 15; // really d7

_button_pins[0] = 0;
_button_pins[1] = 2;
_button_pins[2] = 3;
_button_pins[3] = 5;

but still doesn't work.

Any suggestions??

Regards


Andy

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by adafruit_support_bill »

Double-check you pin assignments. This code was developed and tested to work with our shields, we can't realistically support custom hardware.

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Good morning,

I do know and understand that you are only supporting your own products.

Just to finish up the post.

With the adafruit_mcp23017 library I can freely choose an input or an output. So far I did get it working by pressing a button and switch on a LED. But there is no possibility to drive the LCD with it.

With the adafruit_RGBLCDShield library there is a possibility to get the LCD working, I even could change my design from my own LCD shield, but in the .cpp file I couldnt see a possibility to address an output which I need for 2 LED and a buzzer.

What a pitty. Today I'm trying to do my best again.

Regards


Andy

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Maybe another hint from you if I may ask?

I managed to display text with the adafruitRGBshield library by editing the .cpp file and declared my rs,en,d4,d5,d6,d7 to the right MCP23017 pins. at the same I declared my inputs and outputs.

How can I read a button ( your buttons pull to ground and my ones to Vcc ) and how to address an output.

Using your example brings "LEFT RIGHT DOWN..." on the display with a flickering and only when I push all 4 buttons the display is stable.

Regards

Andy

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by adafruit_support_bill »

How can I read a button ( your buttons pull to ground and my ones to Vcc ) and how to address an output.
Use the digitalRead() and digitalWrite() functions in the Adafruit_MCP23017 library. They work the same way as the Arduino digitalRead and digitalWrite. If you look in the shield library, it is full of examples.

User avatar
arcomp
 
Posts: 12
Joined: Tue Sep 18, 2018 8:18 am

Re: ADAFRUIT_MCP23017 library and LCD 16x2 Display

Post by arcomp »

Good morning,

unfortunately using both librarys at the same time doesnt work:

-----------------------------------------------------------------------------------------------------------------------

Code: Select all

/*********************

Example code for the Adafruit RGB Character LCD Shield and Library

This code displays text on the shield, and also reads the buttons on the keypad.
When a button is pressed, the backlight changes color.

**********************/

// include the library code:
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>


// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
//Adafruit_MCP23017 mcp;

void setup() {
  // Debugging output
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  //mcp.begin();
  //mcp.pinMode(5, INPUT);
  //mcp.pinMode(8, OUTPUT);
  // Print a message to the LCD. We track how long it takes since
  // this library has been optimized a bit and we're proud of it :)
  int time = millis();
  lcd.print("Hello, world!");
  time = millis() - time;
  Serial.print("Took "); Serial.print(time); Serial.println(" ms");
 }
void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
 //mcp.digitalWrite(8, mcp.digitalRead(5));
 
}
---------------------------------------------------------------------------------------------------------------------------------------------------------

So either I have text on the LCD via the AdafruitRGBshield library or I have buttons and LED outputs via the Adafruit_MCP23017 library.

But working both together somehow doesn't work.


Regards

Andy
Attachments
LCD shield schematic.JPG
LCD shield schematic.JPG (96.03 KiB) Viewed 293 times
Last edited by adafruit_support_bill on Fri Sep 21, 2018 5:42 am, edited 1 time in total.
Reason: Please use [code] tags when submitting code to the forums

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”