Skip to content

Latest commit

 

History

History
85 lines (64 loc) · 2.21 KB

16x2LCD.md

File metadata and controls

85 lines (64 loc) · 2.21 KB
layout title permalink
code
16x2 LCD
/16x2LCD.htm

16x2 LCD

Learn how to use the 16x2 LCD shield with the Arduino Liquid Crystal Library.

Required Components

  • 16x2 LCD{:target="_blank"}
  • a resistor that provides your desired contrast (look at your LCD's spec sheet)

Hooking up Components

If you are using the 16x2 LCD listed above, follow the diagram below:

16x2

Create a new project

  1. Create a new project from the template.
  2. Go to Arduino's Liquid Crystal Library GitHub{:target="_blank"} and download the LiquidCrystal.cpp and LiquidCrystal.h files.
  3. Place the LiquidCrystal.cpp and LiquidCrystal.h files in your new project's folder via Windows Explorer
  4. Based on your 16x2 LCD you may need to specify other pins for use with the LiquidCrystal library.
  5. Replace the existing code in stdafx.h and main.cpp with the following code:

Code

stdafx.h

{% highlight C++ %} // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently //

#pragma once

#include "targetver.h"

#include <stdio.h> #include <tchar.h> #include "arduino.h" #include "LiquidCrystal.h" // we need this library for the LCD commands {% endhighlight %}

Main.cpp

{% highlight C++ %} // Main.cpp : Defines the entry point for the console application. //

#include "stdafx.h"

int RS = 4; int ENABLE = 5; int D0 = 6; int D1 = 7; int D2 = 8; int D3 = 9; LiquidCrystal lcd = LiquidCrystal(RS, ENABLE, D0, D1, D2, D3); // define our LCD and which pins to use

int _tmain(int argc, _TCHAR* argv []) { return RunArduinoSketch(); }

void setup() { Log(L"LCD Sample\n");

lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit (it calls clear at the end of begin)

lcd.setCursor(0, 0);
lcd.print("Hello!");

lcd.setCursor(0, 1);
lcd.print(3.14159, 4); // prints a double, the 2nd number is the digits to print after the .

}

void loop() { } {% endhighlight %}


« Return to Samples{:role="button"}{:class="btn btn-default"}