Tutorial: I2C LCD : 9 Steps (with Pictures) - cumminstric1997
Introduction: Tutorial: I2C Liquid crystal display
This Instructable covers the use of the I2C 1602 LCD display with a variety of microcontrollers, including the ESP32, Leonardo, and, of course, the UNO, as it tranquilize is the most popular microcontroller gameboard. Fortunately, the changes betwixt these microcontrollers is minimal and a sketch that works with one microcontroller will credible study with another, American Samoa shown here.
The I2C 1602 is selfsame easy to utilization, and its connections (there are only four (4)) are painless to arrive at. Its use by Makers is even easier. Thus, information technology is a surprise it is not used in to a greater extent Maker projects. Hopefully, this Instructable can help ameliorate that situation.
This Instructable uses components that are likely already in nigh microcontroller Makers parts inventory. Course, if you are not already a circuit OR microcontroller Maker, you may non deliver these components.
Fortunately, whether you consumption a "uncooked" 1602 or an I2C one, all 1602 LCDs are relatively abundant to use.
The nice things almost I2C 1602, Beaver State I2C 2004 ("unpolished" versions of these two (2) displays stimulate these advantages as well): (1) they appropriate Makers to become untethered from the reveal console; i.e., Makers consume some mobility and portability, and they can display some items needful on an LCD display, kind of than the display console, and (2) these Liquid crystal display displays are easy to use.
Earlier application I2C 1602 displays, it will be useful to discuss not-I2C 1602 LCD displays. I2C LCDs give additions to the "raw" 1602 and 2004 displays.
First, these displays are classified as 1602s, arsenic they display sixteen (16) characters happening each of two (2) lines (i.e., thirty (32) characters in total).
There are protective mounts for the "raw" 1602s. However, the I2C 1602s have four (4) immobilize connectors that nearly touch the sides of the 1602 holders, and and then I2C 1602s are not as easily mounted (see attached photograph of an assembled 1602 put on). That is, in that location is little room to connect Dupont cables, unless the I2C 1602s are decorated connected the outside, i.e., outside the acrylic front of their mounts, and not protected. These mounts are extremly difficult to assemble, and so, even off if a Maker is using "raw" 1602s, these mounts are not recommended.
Each character is represented in a seven (7), usually eight (8), operating room, unusually, xi (11), rows by five (5) columns matrix (see attached still exposure). The elements of this matrix are miniscule rectangles.
Characters are make by light some of the small rectangles in a matrix (see attached tranquillise photograph).
It is possible to conception a diminutive number of your own custom characters.
There are spaces separating characters and lines, thus that adjacent lines or characters can glucinium easily distinguished.
A related module, mentioned above, is the 2004, which displays twenty (20) characters happening to each one of four (4) rows, i.e., eighty (80) characters in total.
That is, it primarily differs in having more rows, and more characters per row. Otherwise the extra rows and characters, IT is quite similar to the 1602. These, i.e., 2004s, can also be obtained equally I2C modules, and so the info Hera prat be easily translated to these larger displays. One, or both, of these LCD displays are probably already available in most Makers "bins".
The 1602, or 2004, LCD displays can represent directly related to to an Arduino UNO, or other microcontroller, in what are known as "parallel" modes. That is, not in the I2C mode.
In these nonintersecting modes, thither are four, or eight port connections. Regrettably, there are problems with all parallel modes. Specifically, these modes take up too many of the UNO's headers, or other microcontroller headers/pins, departure little room for sensors.
Here I show ane of the parallel modes for a 1602 Liquid crystal display adjunctive to an Arduino UNO, i.e., the four port mood, this mode is displayed in an attached photograph.
Compared to the 4-synchronic way, we can "free-up" additional headers if we use an I2C 1602.
Any Makers whitethorn have or s 1602s, or 2004, LCDs that are non I2C ones. Fortunately, non-I2C 1602s, or 2004s, that is, plain 1602s, or 2004s, can represent substituted for what follows, just this is not advisable.
What is even better is that a "pickaback" faculty can be added to a non-I2C 1602, operating theater not-I2C 2004, LCD to make an I2C one That is, an I2C 1602s, OR I2C 2004, keister be made, as noted above, aside adding an I2C port/serial port, "pickaback module" (find attached photo of a "pig-a-back" module) to make a non-I2C LCD into one that uses I2C.
Obviously, if whatever Creator choses to use not-I2C 1602s, or non-I2C 2004s, the Sketchs below will need to be adapted slightly.
The 1602 LCD can also be obtained as a carapace (see another attached photograph).
The advantage of shields is that they supply buttons that can be used for a variety of functions.
The disadvantage is that these shields also use too many headers along the UNO, or headers/pins on other microcontroller, and thus will little elbow room for adding sensors.
Therefore, for most Maker projects it is probably best to use an I2C 1602 display, sooner than using one of the 1602 nonconvergent modes Oregon a shield.
It is likely easiest to purchase I2C 1602 displays already assembled, although possibly not the least expensive way to proceed.
See the attached pictures for an assembled I2C 1602 module, front and posterior. The 1602 shown already has the "piggyback" module soldered on.
At the time of this publishing, I2C 1602 displays were available from Red China for less than USD $2.00 each, and I2C "pickaback" adapters were accessible in bulk for less than USD $1.00 each.
Supplies
- An I2C 1602 display
- An Arduino UNO, an Arduino Leonardo, and an Espressif ESP32
- Twelve (12) Dupont wires (Quaternion (4) Male to female for the Arduino UNO, quaternity (4) male to female for the Arduino Da Vinci, and tetrad (4) female to female person for the Espressif ESP32)
Step 1: 1602 I2C and Arduino UNO Form
As the UNO, as renowned, is still the most popular microcontroller card, this Step, and few below, address the I2C 1602 and the UNO. Fortunately, the connections are quite undiluted-brash, and essentially the same, heedless of the microcontroller used.
The attached pictures shows connections to the Arduino UNO, but connections to any unusual microcontroller are similar (see Stairs below). The I2C 1602 only needs connections to 5 vDC power and ground, and SDA and SCL lines.
The I2C 1602 "pig-a-back" adapter is keister the 1602 LCD display (when this adapter is soldered on to the 1602, it can be saved bottom the display). IT has four pins, as can be seen in the attached photo. These are respectively: GND, VCC, SDA, and SCL, i.e., exactly, and only, what is needed by the I2C 1602.
These pins can be adjunctive to the Arduino UNO, or other microcontroller, as explained below.
The GND on the back of the I2C 1602 with "piggyback" mental faculty connects to any ground on the UNO (or other microcontroller). The VCC pin on the "piggyback" mental faculty connects to the v (5) volt header connected the Arduino UNO, or the 5 volt pin/header on some other microcontroller. SDA and SCL pins happening the "piggyback" adapter connect to the SDA and SCL headers on the UNO, or the same identified headers/pins on another microcontroller. Connected the UNO the SDA and SCL headers are headers 16 and 17, happening the integer lintel sidelong, although this whitethorn differ (and does on the ESP32) for roughly other microcontrollers.
By exploitation I2C, only four headers on the Arduino UNO, ESP32, or other microcontroller, need represent used for these connections. Two for power, and two for the SDA and SCL connections.
If an experimental platform is used, the ground and five (5) volts DC headers can connect through Dupont cables to the power rails on the experimental political platform, so that easy world power connections nates be made to other devices.
If an experimental platform is not in use, i.e., an Arduino UNO is used without 1, the pins on the "piggyback" adapter can personify easily connected to the Arduino UNO directly using four (4) female to male Dupont cables.
These are the same connections if the "piggyback" mental faculty was put-upon on a 2004 display.
Step 2: Displaying Flat Characters
The display of fixed characters is selfsame easy using the I2C 1602 LCD and an Arduino UNO, or other microcontroller. We just need to ensure that we use the appropriate #include.
In Sketches, the counters on the 1602 LCD for lines and characters start at zero (0).
Thus, in our Sketch, the first line of the I2C 1602 showing is selected as line zero (0), and the first character on for each one line starts at situation zero (0). The second line is designated as stemma united (1), etc.
Unfortunately, the Instructable locate removes the greater than and fewer than brackets, and the text in betwixt them.
The school tex between the greater than and less than brackets in the #include that should be used is LiquidCrystal_I2C.h .
Some the wanting brackets and the needed text, i.e., the text inside the brackets, are provided in the attached school tex file.
Note: There is an assumption that the I2C address along your I2C 1602 LCD is 0x27, although 0x3F is also unremarkably found.
To find the set aside address, if 0x27, operating room 0x3F does not work, IT is probably outflank to run a scanner program to find the correct I2C dea.
Many scanner Sketchs are addressable on the internet.
The output from one scanner programme, i.e., the scanner Study I exercise, looks like this,
I2C Scanner
Scanning...
I2C gimmick found at accost 0x27 !
done
/*
* I2C 1602 Display Fixed Characters
* Written August 8, 2022
* Programmer: R Hashemite Kingdom of Jordan Keindler
*/
#include // See text
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
int delay1 = 1000;
void setup()
{
lcd.init(); // initialise the lcd
lcd.backlight(); // Turn backlight Happening
}
void eyelet()
{
liquid crystal display.setCursor(0, 0); // Set cursor at position nil(0) happening first line of 1602 LCD
liquid crystal display.print("This is 1st Occupation"); // First line of LCD
lcd.setCursor(0, 1); // Set cursor at position zero (0) along second line of 1602 LCD
lcd.publish("This is 2nd Line of descent"); // Second line of LCD
postponement(delay1); // Delay one irregular
}
Step 3: Displaying Variables
Fortunately, the I2C 1602 LCD can display variables, as swell Eastern Samoa fixed characters.
The Sketchs below demonstrate this capability.
In the first Sketch, the I2C LCD shows, i.e., an end product is displayed connected the LCD's first line as, the digits zero (0) to nine (9), then the digits backwards from nine (9) to zero (0) along the LCD's second line.
/*
II2C 1602 Variables Display
Graphical August 8, 2022
Software engineer: R Jordan Keindler
*/
#include //See text in originally Step
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
int delay1 = 500;
vacuum apparatus() {
lcd.init(); // initialize the lcd
lcd.backlight(); // Turn backlight On
}
null loop() {
liquid crystal display.realize();
lcd.setCursor(3, 0); // Determine cursor at attitude 3(3) on first furrow of 1602 Liquid crystal display
for (int i = 0; i <= 9; i++) {
lcd.print(i); // Display succesive values of variable i
hold(delay1); // Delay delay1 later each show of i
}
lcd.setCursor(3, 1); // Congeal cursor at spatial relation three(3) on 2nd line of 1602 LCD
for (int i = 9; i >= 0; i--) {
lcd.print(i); // Display succesive values of variable i
delay(delay1); // Delay delay1 after each display of i
}
}
In this second (2nd) example, the values nil (0) direct twenty (20) are displayed on both lines of the LCD. The first (1st) line displays the values zero (0) through twelve (12), and the second base (2nd) line the values thirteen (13) finished cardinal (20).
As before to mitigate the Instructable brackets issue, the Sketch is attached as a document.
/*
II2C 1602 Variables Display
Both LCD Lines
Values 0 through 20
Holographic August 8, 2022
Programmer: R Jordan River Keindler
*/
#admit //See textual matter in earlier Step
LiquidCrystal_I2C LCD(0x27, 16, 2); // dress the Liquid crystal display address to 0x27 for a 16 chars and 2 line reveal
int delay1 = 500;
void setup() {
lcd.init(); // initialize the lcd
LCD.backlight(); // Turn backlight Happening
}
void loop() {
liquid crystal display.unsubtle();
lcd.setCursor(0, 0); // Set cursor at position zero(0) on first line of 1602 LCD
for (int i = 0; i <= 12; i++) {
lcd.print(i); // Display succesive values of unsettled i
delay(delay1); // Retard delay1 after each display of i
}
lcd.setCursor(0, 1); // Set cursor at put over zero(0) on second line of 1602 LCD
for (int j = 13; j <= 20; j++) {
lcd.print(j); // Display succesive values of variable j
delay(delay1); // Delay delay1 after apiece display of j
}
}
Step 4: Displaying Some Not-Keyboard Characters
The 1602 can besides display some non-keyboard characters.
The Sketch below shows fourteen (14) of these that I find most serviceable.
Therein Resume, we cast some positional notation numbers as characters, so print the characters.
If you find that you lack a character not shown in these fourteen (14), that I find nigh helpful, you force out search the internet for extra non-keyboard characters that can be displayed on a 1602 LCD.
On that point are many more non-keyboard characters than the fourteen (14) I use most frequently.
You can test the URL,
https://World Wide Web.sparkfun.com/datasheets/LCD/HD44780.pd...
Scroll down to page 17, Table 4. At the time of publication of this Instructable, this URL existed. However, I do not control this page, so it may or whitethorn non be in that respect when you go to this address. If this page is not available, then just do a Google search.
Some Makers find galore of the non-keyboard symbols, much as the grade ratify, utile.
I hope the fourteen (14) that I use often will control the characters you need.
On a different note, regrettably, the Instructables.com site removes all greater and less than brackets and the textbook 'tween them. To mitigate this problem I have attached a Cartoon text single file.
The lacking brackets should have the text LiquidCrystal_I2C.h between them, and the brackets and schoolbook should appear after the #admit.
Remark: the binary value 1101 1111 that is in use to display a degree mark is the same as the decimal fraction value 223. Thus, we could use lcd.print((cleaning lady)223), in place of lcd.photographic print((sear)B11011111). The aforementioned holds for the other binary values equally well. That is, we could use denary values, should we choose to do so. To the highest degree 1602 LCD tables present the non-keyboard characters as binary values, so for ease of use that is what is presented Hera.
/*
I2C 1602 Display
Not-Keyboard Characters
Written August 8, 2022
Programmer: R Jordan Keindler
*/
#include //See textbook above
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
int delay1 = 500;
null apparatus()
{
lcd.init(); // initialize the lcd
lcd.backlight(); // Turn backlight On
}
void loop()
{
lcd.setCursor(1, 0); // Exercise set cursor at position one(1) connected first line of 1602 LCD
lcd.print((char)B11100000); // Display Alpha in First Position
stay(delay1); // Delay delay1
lcd.print((char)B11100010); // Showing Genus Beta in Second Position
delay(delay1); // Delay delay1
lcd.mark((char)B11100100); // Show Mu in Third Position
delay(delay1); // Time lag delay1
lcd.print((char)B11100101); // Exhibit Small Sigma in Fourth Position
hold(delay1); // Delay delay1
lcd.photographic print((charr)B11110110); // Display Large Sigma in Fifth Position
hold up(delay1); // Delay delay1
lcd.print((char)B11011111); // Display Level Symbol in 6th Situation
wait(delay1); // Delay delay1
liquid crystal display.print((char)B11110111); // Display Shamus Symbolization in Seventh Position
delay(delay1); // Delay delay1
liquid crystal display.print((char)B11111000); // Expose X-Taproo in 8th Position
delay(delay1); // Delay delay1
lcd.print((sear)B11110011); // Display Infinity Symbolic representation in Ninth Position
time lag(delay1); // Delay delay1
lcd.print((sear)B11101100); // Display Cent Sign in Tenth View
delay(delay1); // Delay delay1
LCD.print((char)B11100011); // Display Epsilon in Eleventh Position
wait(delay1); // Detain delay1
lcd.print((cleaning woman)B11010010); // Display Chi in Twelth Position
delay(delay1); // Delay delay1
lcd.print((blacken)B11110100); // Display Ohm Symbol in Ordinal Position
check(delay1); // Delay delay1
lcd.publish((charr)B11101000); // Display Square Root Subscribe in Ordinal Position
}
Step 5: Displaying Custom Characters
This step illustrates how to construct a custom character using the I2C LCD's, victimisation the shrimpy rectangles in each matrix positioning.
That is, these small rectangles can live wont to design a custom part(s).
The fictional character designed here is a cheerful face emogi, which we designate in the Sketch as happyemoji.
Inaugural, we use the bid shown below to discover the matrix of rectangular elements for the custom type, happyemoji.
byte happyemoji[] = {
B00000,
B11011,
B11011,
B00100,
B00100,
B10001,
B10001,
B01110
};
Note: there are eight rows in this definition, one row corresponds to from each one row in the character matrix.
Where there is a incomparable (1) in the definition, a dwarfish rectangular element in the ground substance is inside-out On. Where there is a zero (0) in the definition, a small rectangle is turned Off.
The tailored character, we designed, is illustrated by the eccentric represented in the pledged photographs.
Close we role the instruction,
lcd.createChar(0, happyemoji);
to assign the custom character, we just designed, to a mateless digit, here no (0).
We suffer the option of asigning any extraordinary character(s) we design to peerless of eight single digit choices, zero (0) finished sevener (7).
The emogi, we just intentional, is displayed in successive positions happening the second line, i.e., line 1 (1), of the I2C 1602 LCD.
The bid lcd.write() can be used when one wants to send off custom character(s) to the LCD display.
Equally was done previously a document is attached to mitigate the Instructables brackets issue.
/*
by R. Jordan Kreindler
July 27, 2022
happyemoji
*/
#include // See text in in the first place Step
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD plow to 0x27 for a 16 chars and 2 line display
byte happyemoji[] = { // Setup custom character in matrix
B00000,
B11011,
B11011,
B00100,
B00100,
B10001,
B10001,
B01110
};
int delay1 = 150; // Unmoving check, then custom character tin be seen printing
void setup() {
lcd.init(); // Initilize the LCD
lcd.backlight(); // Turn the LCD backlight On
lcd.createChar(0, happyemoji); // Make over custom character and assign to zero (0).
// Can habituate values zero (0) through seven (7). That is, eight custom characters.
}
void closed circuit() {
lcd.setCursor(0, 0); // Put up pointer at 1st crease (line zero (0)) at position nil (0)
lcd.print("Tailored Character"); // Show "Usage Character" on 1st line of Liquid crystal display
for (int i = 0; i <= 15; i++) { // Put across loop to display custom character in all positions connected 2nd line
lcd.setCursor(i, 1); // Set ahead cursor on 2nd line (line one (1)) at position i
lcd.write(0); // Showing the customized character on 2nd line of LCD
delay(delay1); // Add delay so custom characters can be seen displayed
}
lcd.semitransparent(); // Clear the LCD so we can get again
}
Step 6: Animation: Four (4) Examples
In this Step I cover four (4) animation examples: an animated Emoji, an animated arrow, an animated peppy ball, going from left to right, and an alive bouncing ballock in the same location on the LCD.
In the Outline below we blueprint three separate custom characters.
The first is a sad emogi (figure first attached still photograph). The second is a neutral emogi, neither felicitous nor sad, (see secondly related to all the same photograph). The third custom character is a happy emogi (see third attached still photograph).
Wholly three are consequtively displayed in the same location happening the I2C LCD, hence, providing an spirited display.
To mitigate the greater and less than bracket situation with Instructables, the Sketch has also been uploaded as a text file.
Of course, if the delay is reduced from its prevailing setting of 1,500ms, as is appropriate for a instructor - so changes can be seen, to a lesser value, the animation would move more quickly.
The solution is an emoji animation.
/*
* Programmer: R. Jordan Kreindler
* August 8, 2022
* happyemoji animation
*/
#include
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set I2C address to 0x27
byte happyemoji0[] = { // Frame-up custom character in matrix
B00000,
B11011,
B11011,
B00100,
B00100,
B00000,
B01110,
B10001
};
byte happyemoji1[] = { // Setup custom character in matrix
B00000,
B11011,
B11011,
B00100,
B00100,
B00000,
B11111,
B00000
};
byte happyemoji2[] = { // Setup customs duty character in matrix
B00000,
B11011,
B11011,
B00100,
B00100,
B10001,
B10001,
B01110
};
int delay1 = 1500; // Set delay, indeed custom character can be seen printing
empty setup() {
lcd.init(); // Initilize the LCD
lcd.backlight(); // Turn the LCD backlight On
lcd.createChar(0, happyemoji0); // Create custom character and assign to zero (0)
lcd.createChar(1, happyemoji1); // Make up custom case and assign to one (1)
lcd.createChar(2, happyemoji2); // Make over custom character and assign to deuce (2)
// Can use values zero(0) through seven(7). That is, eight custom characters.
lcd.setCursor(2, 0); // Set cursor at 1st line (pipeline zero (0)) at position two (2)
lcd.innocent();
lcd.print(" An Vivification "); // Showing "An Animation" along 1st product line of LCD
lcd.setCursor(7, 1); // Adjust cursor on 2nd line (personal line of credit unrivalled (1))at position 7
lcd.indite(0);
delay(delay1);
}
nullif loop() {
lcd.setCursor(7, 1); // Set pointer on 2nd short letter (line uncomparable (1))at position 7
lcd.write(0);
delay(delay1);
lcd.setCursor(7, 1); // Sic cursor happening 2nd line (line one (1))at position 7
liquid crystal display.write(1);
retard(delay1); // ADHD time lag so impost characters tin be seen displayed
lcd.setCursor(7, 1); // Set ahead cursor happening 2nd line (line one (1))at set 7
lcd.write out(2);
delay(delay1); // Tally delay indeed made-to-order characters can comprise seen displayed
}
Below we design two (2) custom characters: a custom arrow and a blank character. That is, the first custom character designed is an pointer. The second is a blank character that will be used to remove each arrow after it is displayed. The custom arrow fiber is displayed in for each one of the sixteen (16) visible character positions on the second gear row, and then removed from each position it appears in. Present we use a 250 SM pause between consecutive arrow displays, to allow each arrow to be easily seen, A is appropriate for a tutorial.
Actually, any delay equal to or greater than 200 ms should also work. As before, the text file for this Chalk out is included as an attachment, to extenuate the less than and greater than bracket issue ( or maybe information technology's a feature :-) ) that Instructables.com has.
This produces an arrow vivification, with the arrow moving from the left side to the right English of the display.
/*
* by R. Jordan Kreindler
* arrow Animation
*/
#let in
#include
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set I2C address to 0x27
byte arrow[] = {
B01000,
B00100,
B00010,
B11111,
B11111,
B00010,
B00100,
B01000
};
byte nothing[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
int delay1 = 200;
nihility apparatus() {
lcd.init();
lcd.backlight();
LCD.createChar(0, pointer);
liquid crystal display.createChar(1, nothing);
lcd.home();
}
void loop() {
lcd.setCursor(0, 0);
lcd.print(" Animation ");
for(int i = 0; i <= 15; i++) {
lcd.setCursor(i, 1);
LCD.write(0);
delay(delay1); // Delay long enough to see pointer
lcd.setCursor(i, 1);
LCD.write(1);
}
liquid crystal display.clear();
}
For this vivification, we innovation three (3) custom characters: deuce (2) custom balls (one to use at the clear of a persona matrix. and one to use at the bottom of a character matrix), and a blank character. Our goal is to design a "peppy ball" animation, where the ball "bounces" on the second line of the display from left to right.
Alternating musket ball characters are displayed in turn at all other one of the sixteen (16) visible role positions (i.e, eldest ball1 is displayed and past in the adjacent position ball2) on the second course. These are then, subsequently, removed from each position the balls appear in. Here again, we wait 250 ms between displays, so each ball can be easy seen - as is appropriate for a tutorial. Any delay adequate or greater than 200 ms will too work.
/*
* Programmer: R. Jordan Kreindler
* Bouncing Ball Animation
* August 8, 2022
*/
#include // see text
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set I2C name and address to 0x27
byte ball1[] = {
B01110,
B01110,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte ball2[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B01110,
B01110
};
byte nothing[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
int delay1 = 250;
void frame-up() {
LCD.init();
lcd.backlight();
lcd.createChar(0, ball1);
lcd.createChar(1, ball2);
lcd.createChar(2, nothing);
lcd.home();
}
nothingness intertwine() {
LCD.setCursor(0, 0);
lcd.black and white(" Bouncing Lucille Ball"); // Impress "Bouncing Glob" along first descent of LCD
for(int i = 0; i <= 15; i++) {
LCD.setCursor(i, 1); // Coif pointer to endorsement line of LCD
if(i%2==0)LCD.write(0); // Print ball1 if compare is even
if(i%2==!0)lcd.write(1); // Print ball2 if comparison is odd
retard(delay1); // Delay long enough to see ball1 and ball2
LCD.setCursor(i, 1); // Ordered pointer to second line of LCD
lcd.write(2); // Erase ball1 or ball2
}
LCD.clear();
}
Lastly, If we change the ball characters slightly, soh they are symmetrical to a greater extent visible, and write them to the assonant location, and shorten the postponement. We bounce the ball, i.e., animate it, in the aforesaid LCD location.
The Sketch for this is presented under.
You can dress the delay to achieve whatever effectuate you want. A yearner delay make puddle the ball even more open as it bounces.
/*
* Computer programmer: R. Jordan Kreindler
* Bounce Glob Animation
* August 8, 2022
*/
#let in // go steady textual matter
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set I2C speak to 0x27
byte ball1[] = {
B01110,
B01110,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte ball2[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B01110,
B01110
};
byte nothing[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
int delay1 = 100;
nullif setup() {
lcd.init();
liquid crystal display.backlight();
lcd.createChar(0, ball1);
LCD.createChar(1, ball2);
liquid crystal display.createChar(2, nil);
LCD.dwelling();
}
vacuum grummet() {
lcd.setCursor(0, 0);
lcd.print(" Bouncing Ball"); // Print "Bouncing Ball" on first line of Liquid crystal display
for(int i = 0; i <= 15; i++) {
LCD.setCursor(8, 1); // Set cursor to second stoc of LCD
if(i%2==0)lcd.write(0); // Mark ball1 if comparison is even
stay(delay1); // Time lag long enough to see ball1 and ball2
liquid crystal display.write(2); // Erase ball1 or ball2
LCD.setCursor(8, 1); // Set cursor to second line of LCD
if(i%2==!0)lcd.write out(1); // Photographic print ball2 if comparison is odd
delay(delay1); // Delay long enough to see ball1 and ball2
lcd.drop a line(2); // Erase ball1 OR ball2
delay(delay1); // Wait long enough to run across ball1 and ball2
}
lcd.clear();
}
Step 7: I2C 1602 and the Arduino Leonardo
All the Sketches above can also be run on the Arduino Da Vinci.
The Arduino UNO and the Arduino Leonardo have essentially the synoptic form factor.
Some microcontrollers are 8-bit and contain 32kB of flash memory.
However, the Arduino Leonardo da Vinci contains an ATmega32U4 microprocessor, spell the Arduino UNO contains an ATmega328. Other than some peanut additional differences, these are essentially similar boards. Although they make out have different USB connectors.
The just problem with the Arduino Leonardo is that IT can, now and again, be more difficult to usance.
We mustiness equal sure inside the IDE to prime the Tools take out-downbound card, and opt Arduino Leonardo da Vinci to piss sure the correct board is choosen for the IDE Sketch environment.
Thither are no other changes necessary within the IDE. That is, the Sketches above should keep going the Leonardo as they are written, after the circuit card selection change is made in the IDE.
Step 8: I2C 1602 and the Espressif ESP32
As mentioned in the Introduction, and shown above with the Arduino Leonardo, the I2C 1602 show tooshie be used with a assortment of microcontrollers.
In this Stair, we use an Espressif ESP32 exploitation circuit board with the I2C 1602, rather than else Arduinos as we used in previous Stairs.
Here we use the Espressif ESP32 to show how it can Be used with the I2C 1602 LCD, and also to demonstrate the utilise of a microcontroller early than an Arduino-settled extraordinary with the I2C 1602.
We obtain five (5) volts from the VIN pin connected the ESP32 (the fall on the bottom left-of-center of the dining table, if the USB connector is facing fine-tune and the board components are lining upward, i.e., they are happening top side of the board).
The GND pin on the ESP32 connects to the GND pin on the "piggyback" module.
We use these connections to ply power from the ESP32 ontogeny board to an I2C 1602 display
We also connect the SDA and SCL pins connected the "piggyback" module to the pertinent pins happening the Espressif ESP32 (Undergo attached photographs).
Below is the Sketch to display both a multivariate and a variety of unadjustable characters connected an I2C 1602 display affined to an ESP32 development board.
To use this sketch it is necessary to change the IDE tools setting to prove we are using this board, i.e., an ESP32 Dev Module.
Again note that the Instructable editor program eliminates opening and year-end greater than and less than brackets and the text these brackets wrap. These brackets should follow present in the #include statement, and the text they should admit is LiquidCrystal_I2C.h .
To assistant migitate this Instructable bracket subject, a text file with the appropriate Sketch is included in the attachments.
/*
* Coder: R. Jordan Kreindler
* showing the apply of the I2C capabilities
* of the ESP32 development card.
* Noble 8, 2022
*/
#admit // Learn earlier text
LiquidCrystal_I2C liquid crystal display(0x27, 16, 2); // Pig-a-back faculty address
//(Usually the I2C dea is either 0x3F or 0x27)
int j = 2;
void apparatus() {
lcd.init(); // Format the lcd
lcd.backlight(); // Turn the backlight On
lcd.well-defined(); // Clear the video display, and put across
// the cursor to home put over
lcd.print("1st, Hello World"); // Print " Hello To World-wide " at this
// position
lcd.setCursor(0, 1); // Mark the cursor at the starting
// position along the next row
lcd.print(j); // Print variable j with value of 2
lcd.publish("nd Line Display"); // Print "Nd Line of Display" after printing variable
}
void iteration() {
}
Step 9: Character Computer memory Beyond Expose Characters
Happening the I2C LCDs I have, there are twenty-quaternary (24) theatrical role storage positions beyond the sixteen (16) characters that are displayed per line. That is, there are twenty dollar bill-four (24) additional grapheme positions on each of the two (2) lines of the I2C 1602.
Your 1602 LCD may differ, and so IT should atomic number 4 tested if this is not the case. As noted, these unscheduled storage positions are on each of the cardinal lines of the 1602 LCD. That is, there are a total of fourty-eight (48) extra storage locations.
These extra positions can be misused for extra retention, or as used here to write extra characters that bequeath appear after scrolling left, one reference position at a time, to show to each one quality beyond the usual sixteen (16) displayed. These additional characters, i.e., 24 (24) per line, are normally hidden from view.
In this Step, character positions are written beyond the sixteen (16) displayed characters. These additional characters, that are scrawled past position sixteen (16), are and then shown consecutively on the screen subsequently each scroll left.
/*
Test II2C 1602 Exhibit for Character Storage Beyond Characters Displayed
Written August 8, 2022
Programmer: R Jordan Keindler
*/
#include // See text edition in in the beginning Maltreat
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 ancestry display
int delay1 = 1000;
vitiate setup() {
lcd.init(); // initialize the lcd
lcd.backlight(); // Turn backlight Connected
}
void loop() {
lcd.clear();
lcd.setCursor(0, 0); // Set cursor at position nada(0) connected first line of 1602 LCD
// At that place are 24 character positions along my LCD beyond those characters displayed
lcd.print("This is 1st Lineabcdefghijklmnopqrstuvwx"); // Test original line of LCD for extra reposition
liquid crystal display.setCursor(0, 1); // Set cursor at position zero (0) on second line of 1602 Liquid crystal display
lcd.print("This is 2nd Line123456789112345678921234"); // Trial run intermediate line of LCD for extra memory
delay(delay1);
for (int i = 0; i <= 23; i++) {
lcd.scrollDisplayLeft();
delay(delay1);
}
}
If you have come to this point - congratulations.
You should now take in a basic understanding of some of the key elements of an I2C 1602 LCD, and how to use one in your projects, and with a variety of microcontrollers.
If you liked this tutorial, delight be kind enough to check the "Favorited" box at the top of this Instructable. It would be appreciated.
If you have any comments, suggestions, or questions accompanying this Instructable, please bestow these to the comments below. Otherwise, start the gloss surgical incision with your own. If you have any thoughts or questions, about related items not splashed in that Instructable, or any suggestions on how I could improve this Instructable, or for future tutorials, I would be amused to hear from you. You can liaison me directly at transiintbox@gmail.com. (Please replace the second 'i' with an 'e' to get through me).
Be the First to Portion
Recommendations
-
Anything Goes Competition 2022
Source: https://www.instructables.com/TutorialI2C-1602/
Posted by: cumminstric1997.blogspot.com
0 Response to "Tutorial: I2C LCD : 9 Steps (with Pictures) - cumminstric1997"
Post a Comment