You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Discussion of the hardware of the LCD Shield Kit w/ 16x2 Character Display / Blue and White (adafruit.com/products/772)...

    First of all, why comes the MPC23017 I2C expander into play? For a similar reason as the HD44780 is there: to reduce the number wires to control the device (and to offload the driving device / mC) - bottom line to simplify the use. I while back I used the 8-bit Ubicon SX mC - RIP ;-) (originally SceniX, and now Qualcomm) - to drive the HD44780 and backlight LED directly as available from a similar product to Standard LCD 16x2 + extras - white on blue (adafruit.com/products/181). The module occupied a lot of I/O pins from the uC, even in the 4 bit (parallel) mode: at least 6 pins/wires - plus one more for the back light LED, if you want to control it(s brightness) through code. The savings of 4 lines vs the 8 bit parallel mode (total 10 respective 11 pins/wires) is paid with more complex code and slower update time (speed is relative, though).

    Using the MPC23017 I2C expander, one needs only two (2) pins/wires: one for serial clock (SCL) and one for serial data (SDA) - not counting the wires for ground (GND) and power (+5V). *Make sure that you always connect Espruino's and the 'shields''s GND, even when you suppply the 'shield' with a seperate power supply and not with Espruino's 5V. *

    Note, that multiple I2C devices can 'sit on the same I2C channel' of the mC, therefore, each of the I2C devices has an address defined by jumpers. The MPC23017 has 3 address lines - A0..A2 - which allow 8 of these to be on on single I2C channel. Btw, the MC23017 has a sibling MPC23S17 , which supports SPI connectivity with even faster serial communicaiton, but requires an additional line per chip to select the chip that is to communicate.

    If though something should talk back to the mC by interrupt, such as the event of a button press or release, one or two more wires/pins are required to connect to one or both interupt pins of the extender. The buttons can always be polled - asked whether theay are pressed or released - but polling is not a preferred approach, since it uses mC computing cycles and makes programming (more) complicated (Arduino 'people' claim the opposite, and they are right... depending the circumstances and the Arduino primarily supported 'loop model'). Espruino goes - and has to go - for the event / interrupt driven approach, which allows easily to add things due to the absence of the loop.

    Enough of the (philosphic) discussion.

    Let's look at the 'shield' hardware schematic to understand how we have to setup, configure, and talk to the MPC23017 I2C expander. See attachments ('photoshoped' from the 'only' available adafruit/Adafruit-RGB-LCD-shield/blob/master/adafruit_rgblcdshield.sch - LCD Shield 16x2 Chars schematic.

    We already know that we have to talk I2C to the expander. And we can see that we have to use address 0 - because A0..A3 are connected to GND. But what we have to talk can be seen how the GPX# - General io Pin of ports A and B (GPA0..7 and GPB0..7) are connected to the HD44780 LCD controler and the rest on the board, such as the back light LED and buttons.

    As @DrAzzy pointed out, the LCD controler operates in 4 bit (nibble) mode: only 4 of the 8 data lines that go to the LCD module (with the LCD controller and the actual LCD are connected): GPB1..GPB4 to D07..D04. Here the complete mapping:

    | GPA0 <---- Select button 0
    | GPA1 <---- Right / Eeast button 2
    | GPA2 <---- Down / South button 3
    | GPA3 <---- Up / North button 1
    | GPA4 <---- Left / West button 4
    | GPA5 ----- ??? NC (not connected)
    | GPA6 ----> Red LED
    | GPA7 ----> Green LED

    | GPB0 ----> Blue LED
    | GPB1 <---> DB7 (data bit 7 - and 3 in 4 bit mode)
    | GPB2 <---> DB6 (data bit 6 - and 2 in 4 bit mode)
    | GPB3 <---> DB5 (data bit 5 - and 1 in 4 bit mode)
    | GPB4 <---> DB4 (data bit 4 - and 0 in 4 bit mode)
    | GPB5 ----> E (enable - enables the controller)
    | GPB6 ----> RW (Read[high]/_Write[low] - read from or write to controller)
    | GPB7 ----> RS (_Reset[low] the controller)


    1 Attachment

    • LCDAF772_schema.png
About

Avatar for allObjects @allObjects started