Difference between revisions of "Liquid Crystal Displays with Explore M3"
Line 37: | Line 37: | ||
=Demo= | =Demo= | ||
+ | The same hookup can be used to interface 16x1, 16x4 and 20x4 displays. The only things that will change is | ||
+ | <syntaxhighlight> | ||
+ | lcd.begin(16, 2); //for 16x2 display | ||
+ | lcd.begin(16, 1); //for 16x1 display | ||
+ | lcd.begin(20, 4); //for 20x2 display | ||
+ | |||
+ | lcd.setCursor(0, 1); //can be used to set the cursor, according to the display size. | ||
+ | </syntaxhighlight> | ||
+ | |||
=References= | =References= | ||
* [https://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay LiquidCrystalDisplay tutorial on Arduino Website] | * [https://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay LiquidCrystalDisplay tutorial on Arduino Website] |
Revision as of 17:07, 8 June 2016
Character Liquid crystal displays are very handy and extremely simple to use. In this tutorial let us hook up 16x1, 16x2, 20x4 displays and test them with Explore M3. We will be using the LiquidCrystal Arduino library to accomplish this.
Contents
Hook up
There are various modes in which these displays can be connected to Explore M3 as shown below. It is combination of using 8 bit or 4 bits as database and using or not using the RW line on the display.
- LiquidCrystal(rs, enable, d4, d5, d6, d7)
- LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
- LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
- LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)
So lets use the first mode which needs the least of the pins. The potentiometer is used to set the display contrast and resistor limits current to the LCD back-light.
Code
// include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of rows and columns: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); } void loop() { // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis()/1000); }
Demo
The same hookup can be used to interface 16x1, 16x4 and 20x4 displays. The only things that will change is
lcd.begin(16, 2); //for 16x2 display lcd.begin(16, 1); //for 16x1 display lcd.begin(20, 4); //for 20x2 display lcd.setCursor(0, 1); //can be used to set the cursor, according to the display size.