0

RGB LCD Backpack GPA 5
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RGB LCD Backpack GPA 5

by ATE_ENG on Wed Jun 13, 2018 10:41 am

Looking at the diagram for the RGB LCD Shield Kit w/ 16x2 Character Display I don't see GPA5 being used on the LCD shield or any of the input buttons.

Image

Can I connect another switch (such as the Reed switch shown below) for use as soft reset button?

Image

Although this seems possible, I'm having trouble understanding the MCP23017-E/SP datasheet

If so, what #define would I need to add to the RGBLCDShield Library where:

Code: Select all | TOGGLE FULL SIZE
#define BUTTON_UP 0x08
#define BUTTON_DOWN 0x04
#define BUTTON_LEFT 0x10
#define BUTTON_RIGHT 0x02
#define BUTTON_SELECT 0x01
#define BUTTON_SFTRST 0x##


Furthermore, would I need to make any additional modifications?

ATE_ENG
 
Posts: 11
Joined: Wed Jul 26, 2017 8:38 am

Re: RGB LCD Backpack GPA 5

by adafruit_support_bill on Wed Jun 13, 2018 10:54 am

Bit 5 would be 0x10

adafruit_support_bill
 
Posts: 68481
Joined: Sat Feb 07, 2009 10:11 am

Re: RGB LCD Backpack GPA 5

by ATE_ENG on Wed Jun 13, 2018 11:04 am

adafruit_support_bill wrote:Bit 5 would be 0x10


According to the #define, isn't Bit 4 BUTTON_LEFT 0x10?

ATE_ENG
 
Posts: 11
Joined: Wed Jul 26, 2017 8:38 am

Re: RGB LCD Backpack GPA 5

by adafruit_support_bill on Wed Jun 13, 2018 11:15 am

Sorry, they are 0-relative, so bit 5 would be 0x20

adafruit_support_bill
 
Posts: 68481
Joined: Sat Feb 07, 2009 10:11 am

Re: RGB LCD Backpack GPA 5

by ATE_ENG on Wed Jun 13, 2018 11:32 am

adafruit_support_bill wrote:Sorry, they are 0-relative, so bit 5 would be 0x20


No Problem, Now I'm having trouble with this function

Code: Select all | TOGGLE FULL SIZE
uint8_t Adafruit_RGBLCDShield::readButtons(void) {
  uint8_t reply = 0x1F;

  for (uint8_t i=0; i<5; i++) {
    reply &= ~((_i2c.digitalRead(_button_pins[i])) << i);
  }
  return reply;
}


It seems like I need to change the initial value of reply in order to capture pin 5 setting it to 0x20 seems to capture a pin that is being held to ground.

ATE_ENG
 
Posts: 11
Joined: Wed Jul 26, 2017 8:38 am

Re: RGB LCD Backpack GPA 5

by adafruit_support_bill on Wed Jun 13, 2018 11:37 am

You need to mask in the extra bit to start - then loop through all of the bits you are trying to read:
Code: Select all | TOGGLE FULL SIZE
uint8_t Adafruit_RGBLCDShield::readButtons(void) {
  uint8_t reply = 0x3F;

  for (uint8_t i=0; i<6; i++) {
    reply &= ~((_i2c.digitalRead(_button_pins[i])) << i);
  }
  return reply;
}

adafruit_support_bill
 
Posts: 68481
Joined: Sat Feb 07, 2009 10:11 am

Re: RGB LCD Backpack GPA 5

by ATE_ENG on Wed Jun 13, 2018 12:18 pm

adafruit_support_bill wrote:You need to mask in the extra bit to start - then loop through all of the bits you are trying to read:
Code: Select all | TOGGLE FULL SIZE
uint8_t Adafruit_RGBLCDShield::readButtons(void) {
  uint8_t reply = 0x3F;

  for (uint8_t i=0; i<6; i++) {
    reply &= ~((_i2c.digitalRead(_button_pins[i])) << i);
  }
  return reply;
}


For posterity, I also had to modify RGBLCDShield::begin to
Code: Select all | TOGGLE FULL SIZE
for (uint8_t i=0; i<6; i++) {
      _i2c.pinMode(_button_pins[i], INPUT);
      _i2c.pullUp(_button_pins[i], 1);
    }


The modified library with the RGB LCD Shield Interrupt-On-Change modification Is attached.
Attachments
Adafruit_RGB_LCD_Shield_Library.zip
(14.79 KiB) Downloaded 5 times

ATE_ENG
 
Posts: 11
Joined: Wed Jul 26, 2017 8:38 am

Re: RGB LCD Backpack GPA 5

by adafruit_support_bill on Wed Jun 13, 2018 12:20 pm

Nice! Thanks for posting your code.

adafruit_support_bill
 
Posts: 68481
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.