Anda di halaman 1dari 23

Display for Arduino

Jiang Jiang
TVETI at A.A. 2019
Liquid Crystal Display

20×04 LCD 16×02 LCD

Chinese LCD
I2C Bus Communication Protocol
What is I2C:
- Inter Integrated Circuit
The reference design is a bus with a clock (SCL) and data (SDA) lines with 7-bit
addressing. The bus has two roles for nodes: master and slave.
1602LCD Uno
Build Circuit GND GND
Type B
VCC 5V
Type A SDA SDA
SCL SCL
Find LCD Address
Type sketch as figure or download and run
‘I2C_find_address.ino’, then get LCD address in ‘Serial
monitor’.
Install Libraries
• Libraries provide extra functionality for use in sketches, e.g. working
with hardware or manipulating data.
• We can search libraries online.
Install Libraries
• Or download libraries from https://www.arduinolibraries.info/
Install Libraries
• Or download libraries from https://www.arduinolibraries.info/
Install Libraries
• Get LiquidCrystal_I2C.zip file

Sketch > Include Library > Add .ZIP Library


Select LiquidCrystal_I2C.zip
Functions of LiquidCrystal_I2C library
Function Name Explanation
LiquidCrystal_I2C(add, columns, rows) create an LCD object and specify the address and dimensions.
Init() initialize the lcd
backlight() open the backlight
setCursor (column, row) set the cursor to specified column and row
print() print a message to the LCD
clear() clears LCD screen and positions cursor in the upper-left corner of the display.
display() turns on the LCD screen and displays any text or cursors
noDisplay() turns off any text or cursors printed to the LCD
scrollDisplayLeft() scrolls the contents of the display one space to the left
scrollDisplayRight() scrolls the contents of the display (text and cursor) one space to the right
leftToRight() causes text to flow to right from cursor, as if the display is left-justified (default).
rightToLeft() causes text to flow to the left from the cursor, as if the display is right-justified.
autoscroll() turns on automatic scrolling of the LCD.
createChar() create and display custom characters on the LCD
Sketch result: 2 rows of strings scroll left
Study from Example:Open example sketch ‘CustomChars’ and upload, then observe it.
Note: Don’t save changes of Example.
Study from Example:Open example sketch ‘SerialDisplay’ and upload, then use
‘Serial Monitor’ to send string to LCD.
SSD1306 OLED (Organic Light Emitting Diode)
OLDE is super-light, almost paper-thin, theoretically flexible, and produce a brighter and
crisper picture.

128×32 monochrome OLED

Color OLED
128×64 monochrome OLED

Memory map (128×64)


Build Circuit

SSD1306 Uno
GND GND
VCC 3.3V
SDA SDA
SCL SCL
Find I2C Address
• Run ‘I2C_find_address.ino’ and find address
Install Libraries
• Install ‘Adafruit_GFX_Library’ and ‘Adafruit_SSD1306’
Functions of Adafruit_GFX_Library
Function Name Explanation
setCursor(x, y) set text cursor location
setTextColor() parameter WHITE for the dark background and BLACK for bright background
setTextSize() Set font size (starting from 1)
Static Text Sketch

create an object of
Adafruit_SSD1306 with I2C

You can modify increase textsize


Try setTextColor(BLACK, WHITE);
Moving Text Sketch You can scroll the display
horizontally by calling
startscrollright() & startscrollleft()
functions and diagonally by calling
startscrolldiagright() &
startscrolldiagleft(). All these
functions accept two parameters
viz. start page and stop page.
Refer to OLED Memory Map
section for explanation of the
pages.

try following code


Moving Text Sketch You can scroll the display
horizontally by calling
startscrollright() & startscrollleft()
functions and diagonally by calling
startscrolldiagright() &
startscrolldiagleft(). All these
functions accept two parameters
viz. start page and stop page.
Refer to OLED Memory Map
section for explanation of the
pages.

try following code


Study from Example:Open example sketch ‘ssd1306_128×64_i2c’ and upload, then
observe it.

Pay attention I2C address


Displaying Bitmap ‘drawbitmap.ino’ sketch

Bitmap
Code
Displaying Bitmap
1. Run ‘image2cpp’

2. Select image
Displaying Bitmap
3. Copy code

4. Paste code

Anda mungkin juga menyukai