I2C - Display Data On LCD Screen

Preparation

  • AmebaD [AMB21 / AMB22 / AMB23 / BW16] x 1

  • I2C 2×16 LCD

Example

Normally there are many pins on an LCD display, as shown in below figure.

../../../../_images/image154.png

An LCD display can be equipped with an additional processing chip to process the data. The processing chip can connect to a microcontroller using the I2C interface.

AMB21 / AMB22 Wiring Diagram:

../../../../_images/image249.png

AMB23 Wiring Diagram:

../../../../_images/image2-14.png

BW16 Wiring Diagram:

../../../../_images/image2-32.png

BW16-TypeC Wiring Diagram:

../../../../_images/image2-41.png

Open the example in “File” “Examples” “AmebaWire” “LCD_HelloWorld”. Compile and upload to Ameba, then press the reset button. Then you can see “Hello World” in the first line, and “Ameba” in the second line displayed on the LCD screen.

../../../../_images/image31.jpeg

After 8 seconds, you can input to the Serial Monitor the string you would like to display on the LCD.

../../../../_images/image41.jpeg

For example, we enter “123456789” and press “Send”:

../../../../_images/image53.jpeg

Code Reference

The required settings of each model of LCD might be different, the constructor we use in this example is:

LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
                  uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
                  uint8_t backlighPin, t_backlighPol pol);

And the setting parameters are as follows:

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

The first parameter 0x27 is the address of I2C. Each of the following 8 parameters represents the meaning of each bit in a byte, i.e., En is bit 2, Rw is bit 1, Rs is bit 0, d4 is bit 4, and so forth.

Call backlight() to light the screen, Call setCursor(0, 0) to set the position of the cursor. LCD inherits the Print class, so we can use lcd.print() to output string on the screen.