serial lcd module arduino free sample
The Serial LCD Kit includes all the parts you need to add a serial "backpack" to a 16x2 LCD. The kit includes a pre-programmed ATmega328 microprocessor, which reads a serial stream of data and (after a little heavy-lifting) instantly displays it on the LCD. Interfacing the Serial LCD with an Arduino, or other serial-enabled devices, allows you to easily print GPS coordinates, short messages or any other information onto the LCD.
This tutorial will cover everything you need to know to get up and running with the Serial Enabled LCD Kit. We"ll first go over assembly so you can turn that bag-o-parts into something that hopefully resembles any pictures you may have seen of the kit.
Following assembly, we"ll touch on how to actually use the Serial LCD Kit. Specifically, we"ll go over how you"d use the thing with everybody"s favorite development board, Arduino. There"ll be example code galore, and you can even make your own LCD clock! It"s gonna be pretty crazy...
Finally, you"ll need something to send a serial stream of data to the display. An Arduino works great (any variety, this isn"t limited to the Uno) if you want to automate the serial data stream. FTDI breakouts or RS-232 level shifters work if you just want to connect the display to your computer and send data via a terminal program. For what it"s worth, this tutorial will focus on connecting the display to an Arduino.
The goal of the Serial LCD Kit is to make controlling an LCD simple and to make wiring to it even simpler. If you wanted, you could abstain from using the serial backpack and wire an Arduino directly up to the LCD. To that point, there are loads of great examples, and even some Arduino libraries, that make interfacing a microcontroller directly to an LCD very easy. However, because the LCD is driven by a parallel interface, those examples require a tangle of wires and anywhere from 6 to 11 pins of the Arduino to control the thing.
The microcontroller on the Serial LCD Kit takes care of all of that nasty wiring, so you only need one pin to control the LCD. The Serial LCD"s on-board microcontroller parses any incoming commands or characters, and then sends the proper data to the LCD over the multi-wire parallel interface. It"s a magic black box, and you don"t have to care how it does its job, just that it does it. So let"s get it built...
What you"ve got in front of you right now is not yet a Serial LCD Kit. First, we"ve got to turn that bag of parts into a Serial LCD Kit, which will require soldering. If you"ve never soldered before, don"t fret! This is one of the easier soldering projects, every part is through-hole, and well-spaced. If this is your first time though, I"d encourage you to take a trip over to one of our excellent soldering tutorials before picking up the iron.
First, pick out the big, ferrari-red PCB. See how one side has white silkscreen printed onto it? This is the top of the PCB. You"ll stick almost every part in on this side and solder the pins to the opposite side. The only time we"ll stray from that is when soldering the LCD, which is the last step.
Wait...something"s missing...oh, hi LCD! To connect the LCD to the PCB, we"ve included a straight 16-pin header with the kit. You"ll need to solder this header to both the PCB and the LCD. Solder it first to the LCD, stick the shorter pins into the LCD. Make sure the longer legs are extended out from the back of the LCD and solder all 16-pins on the top side of the LCD. Effort to keep the pins as perpendicular to the LCD as possible.
With the header soldered to the LCD,you"ll finally be able to connect the display to the PCB. Remember, we"re sticking this part into the bottom side of the PCB, and soldering to the top. Solder up all 16 pins, and that should be it.
Before you can display anything on the LCD, you"ll have to connect something to it. Only three wires are necessary to use the Serial LCD Kit: RX, GND and VCC. Plug the included 3-wire jumper cable into its mating JST connector that you soldered onto the PCB. This color coded cable has two wires for power, and one for receiving serial data. The red and black wires correspond to +5V and GND, respectively, and the yellow wire is RX.
You"ll need to figure out how you"re going to powerthe LCD Kit. It doesn"t have a regulator on-board, so it"s up to you to supply a clean, regulated 5V power source. If you"re using an Arduino, you could power the Kit off of the 5V and GND pins – connect red to 5V and black to GND. Otherwise, there"s a ton of options out there for power; you could use a USB adapter, a 5V wall-wart, a breadboard power supply. The list just goes on. Just make sure you"re not supplying any more than 5V (a little less may work, but you"ll lose some brightness).
After powering the Serial LCD Kit, you should notice the backlight turn on. If the contrast is properly adjusted, you might see the splash screen flash for a second or two. Most likely though, the contrast won"t be set correctly, so you won"t see a splash screen. In that case, you may see anything from 32 white boxes to absolutely nothing. You"ll have to be quick about it, because the splash screen only remains for a couple seconds before going blank, but try turning the trimpot knob until you"ve got a good view of the characters on the LCD.
The "Serial" in the Serial LCD Kit can be a little confusing. What it really means is TTL serial, not to be confused with RS-232 serial. The voltage on the RX line should only go between 0 and +5V. If you"re using a microcontroller (like an Arduino) to talk with the LCD, then you most likely don"t have to worry. Just don"t hook up a PC"s serial port straight to the LCD and expect it to survive.
There"s a lot of components that are capable of sending TTL serial data. The most popular here at SparkFun are USB-to-Serial boards (like the FTDI Basic Breakout), or an Arduino. This tutorial is going to assume you have an Arduino for the next few examples. No Arduino? That"s cool. I get it; you"re not gonna conform to this passing fad. Feel free to read on, and try to port these examples to your platform.
Connect the Arduino to the Serial LCD as follows. If you have a wire stripper, you may want to expose a few millimeters more of wire to allow them to stick really nicely into the Arduino"s headers.
Here"s a simple example sketch, which uses the SoftwareSerial library (which is included with recent versions of Arduino) to instill our Arduino with more than just the one, hardware, serial port. Now we can use the hardware serial port to listen to the serial monitor, and the second serial port can be used to talk to the LCD.
Now, plug in your Arduino and upload the code. Open up the serial monitor, and make sure it"s set to 9600. Type “Hello, world” into the serial monitor and send it over to the Arduino. The LCD should echo your greeting. Take the LCD for a test drive, discover all the characters it can display!
You"ll quickly notice, that the code is severely lacking any sort of clear display command, but don"t think for a second that the Serial LCD Kit doesn"t have a clear display command. It"s got commands up the wazoo! The Serial LCD Kit is set up to accept commands that control the backlight, baud rate, and all sorts of display functionality, like clearing the screen. Have a look at the Kit"s “datasheet”, which lists all of the characters and commands you can send to the display. I wrote that, but I understand if it"s all gobbledygook to you right now.
The commands are divided into three groups: backlight, baud rate, and special commands. Each command requires that you send at least two bytes to the display. For instance to set the backlight, you first have to send the backlight control byte (0x80, or decimal 128) followed by a byte with any value from 0 to 255. Sending a 0 will turn the backlight completely off, 255 will turn it all the way on, 127 will set it to about 50%, and so on. The backlight setting is stored in the Serial LCD Kit"s memory and will be restored when the LCD is turned off and on.
What we really care about right now, though, is clearing the display, which requires a special command. To issue a special command to the LCD, you first have to send 0xFE (or decimal 254) which tells the display to go into special command mode, and wait for a data byte. The clear display command is 0x01 (or decimal 1), that command should be sent immediately after sending the special command byte. So to clear the display we need to send two bytes: 254 (0xFE) followed by 1 (0x01). Check out the datasheet link for all of the special commands. You can do all sorts of fun stuff: scroll the display, turn it on/off and control the cursor.
Our next piece of example code, Serial_LCD_Kit_Clock, delves into sending special commands to the LCD with an Arduino. There are individual functions that clear the display (clearDisplay()), set the backlight (setBacklight(byte brightness)), and set the cursor (setLCDCursor(byte cursor_position)), feel free to copy these and add them to any code you"d like.
The code sets up a digital clock. If you want it to be accurate, you have to set the time in the variables above before uploading the code to the Arduino. The same hookup as before should do.
Now then, that should be enough to get you on your way to using the Serial LCD Kit with a serial interface. If you"re happy with that, and don"t want your mind blown, I suggest you stop reading here.
Oh, you"ve taken the red pill? Well then you get to learn the Serial LCD Kit"s very deep, dark secret. It may not look anything like one, but the LCD Kit is actually Arduino-compatible. It has an ATmega328, just like the Arduino, and that ATmega328 has a serial bootloader, just like an Arduino. It can be programmed via a USB-to-Serial board. This means you can hook up all sorts of sensors, blinkies and other I/O to the Kit itself, while continuing to use the LCD to display any info you"d like. The 6-pin serial programming port on the right hand side of the PCB can be connected to an FTDI Basic Breakout.
With the FTDI board connected, and Arduino open, simply select the corresponding COM port in the Tools>Serial Port menu, and select Arduino Duemilanove or Nano w/ ATmega328 under the Tools>Boards menu. Though it probably won"t look like it"s doing anything, try uploading Blink, change the LED pin to 9 to at least see the backlight of the LCD flick on and off. Remember, you can download the Serial LCD Kit firmware here. If you ever want to turn it back into a Serial LCD, upload it to the LCD like you would any sketch.
If you want to be really adventurous, and get the most out of the Serial LCD Kit, I"d recommend first taking a trip over to where the Serial LCD Kit"s source code is hosted and getting a good idea how the code works. That firmware is written as an Arduino sketch, and uses a great little Arduino library named LiquidCrystal to control the LCD. The LiquidCrystal library makes controlling the LCD with an Arduino super-simple.
You should also get a good feeling for the kit"s schematic. There are a few Arduino pins that can only be used with the LCD (4-9), but pins 10-13, and all of the analog pins can be used with any device you"d normally connect to an Arduino. The available pins are all broken out on the bottom of the PCB.
Remember, this part is all very extracurricular. Don"t feel at all required to use your Serial LCD Kit as an Arduino. I just wanted to let you know what"s possible with this kit.
Serial LCD Clock Example Sketch - Displays a digital clock on the Serial LCD. This is a good example of how to use special commands, like clear, with the display.
Now I"ll leave you and your Serial LCD Kit in peace. I hope you"ve learned a good amount about the display. I also hope you"re left with questions and ideas about what you"re going to do with it next. If you"ve still got questions about the display, or comments about the tutorial, please drop them in the comments box below or email us.
The Arduino family of devices is features rich and offers many capabilities. The ability to interface to external devices readily is very enticing, although the Arduino has a limited number of input/output options. Adding an external display would typically require several of the limited I/O pins. Using an I2C interface, only two connections for an LCD character display are possible with stunning professional results. We offer both a 4 x 20 LCD.
The character LCD is ideal for displaying text and numbers and special characters. LCDs incorporate a small add-on circuit (backpack) mounted on the back of the LCD module. The module features a controller chip handling I2C communications and an adjustable potentiometer for changing the intensity of the LED backlight. An I2C LCD advantage is that wiring is straightforward, requiring only two data pins to control the LCD.
A standard LCD requires over ten connections, which can be a problem if your Arduino does not have many GPIO pins available. If you happen to have an LCD without an I2C interface incorporated into the design, these can be easily
The LCD displays each character through a matrix grid of 5×8 pixels. These pixels can display standard text, numbers, or special characters and can also be programmed to display custom characters easily.
Connecting the Arduino UNO to the I2C interface of the LCD requires only four connections. The connections include two for power and two for data. The chart below shows the connections needed.
The I2C LCD interface is compatible across much of the Arduino family. The pin functions remain the same, but the labeling of those pins might be different.
Located on the back of the LCD screen is the I2C interface board, and on the interface is an adjustable potentiometer. This adjustment is made with a small screwdriver. You will adjust the potentiometer until a series of rectangles appear – this will allow you to see your programming results.
The Arduino module and editor do not know how to communicate with the I2C interface on the LCD. The parameter to enable the Arduino to send commands to the LCD are in separately downloaded LiquidCrystal_I2C library.
Before installing LiquidCrystal_I2C, remove any other libraries that may reside in the Arduino IDE with the same LiquidCrystal_I2C name. Doing this will ensure that only the known good library is in use. LiquidCrystal_I2C works in combination with the preinstalled Wire.h library in the Arduino editor.
To install the LiquidCrystal_I2C library, use the SketchSketch > Include Library > Add .ZIP Library…from the Arduino IDE (see example). Point to the LiquidCrystal_I2C-master.zip which you previously downloaded and the Library will be installed and set up for use.
Several examples and code are included in the Library installation, which can provide some reference and programming examples. You can use these example sketches as a basis for developing your own code for the LCD display module.
There may be situations where you should uninstall the Arduino IDE. The reason for this could be due to Library conflicts or other configuration issues. There are a few simple steps to uninstalling the IDE.
The I2c address can be changed by shorting the address solder pads on the I2C module. You will need to know the actual address of the LCD before you can start using it.
Once you have the LCD connected and have determined the I2C address, you can proceed to write code to display on the screen. The code segment below is a complete sketch ready for downloading to your Arduino.
The code assumes the I2C address of the LCD screen is at 0x27 and can be adjusted on the LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,16,2); as required.
This function turns off any characters displayed to the LCD. The text will not be cleared from the LCD memory; rather, it is turned off. The LCD will show the screen again when display() is executed.
Scrolling text if you want to print more than 16 or 20 characters in one line then the scrolling text function is convenient. First, the substring with the maximum of characters per line is printed, moving the start column from right to left on the LCD screen. Then the first character is dropped, and the next character is displayed to the substring. This process repeats until the full string has been displayed on the screen.
The LCD driver backpack has an exciting additional feature allowing you to create custom characters (glyph) for use on the screen. Your custom characters work with both the 16×2 and 20×4 LCD units.
To aid in creating your custom characters, there are a number of useful tools available on Internet. Here is a LCD Custom Character Generator which we have used.
This tutorial shows how to use the I2C LCD (Liquid Crystal Display) with the ESP32 using Arduino IDE. We’ll show you how to wire the display, install the library and try sample code to write text on the LCD: static text, and scroll long messages. You can also use this guide with the ESP8266.
Additionally, it comes with a built-in potentiometer you can use to adjust the contrast between the background and the characters on the LCD. On a “regular” LCD you need to add a potentiometer to the circuit to adjust the contrast.
Before displaying text on the LCD, you need to find the LCD I2C address. With the LCD properly wired to the ESP32, upload the following I2C Scanner sketch.
After uploading the code, open the Serial Monitor at a baud rate of 115200. Press the ESP32 EN button. The I2C address should be displayed in the Serial Monitor.
Displaying static text on the LCD is very simple. All you have to do is select where you want the characters to be displayed on the screen, and then send the message to the display.
The next two lines set the number of columns and rows of your LCD display. If you’re using a display with another size, you should modify those variables.
Scrolling text on the LCD is specially useful when you want to display messages longer than 16 characters. The library comes with built-in functions that allows you to scroll text. However, many people experience problems with those functions because:
In a 16×2 LCD there are 32 blocks where you can display characters. Each block is made out of 5×8 tiny pixels. You can display custom characters by defining the state of each tiny pixel. For that, you can create a byte variable to hold the state of each pixel.
In summary, in this tutorial we’ve shown you how to use an I2C LCD display with the ESP32/ESP8266 with Arduino IDE: how to display static text, scrolling text and custom characters. This tutorial also works with the Arduino board, you just need to change the pin assignment to use the Arduino I2C pins.
We hope you’ve found this tutorial useful. If you like ESP32 and you want to learn more, we recommend enrolling in Learn ESP32 with Arduino IDE course.
This module works with at least the LiquidCrystal I2C and LiquidCrystal_PCF8574 libraries available in the Arduino library manager. Address 0x3F worked for me since the A0, A1, and A2 jumpers are not shorted.
Google for LCM1602 and you will find many pages that mention the board - including the pinouts stated above and sample programs using the Arduino library.
I liked the idea of the 4-wire interface, but I was disappointed that no documentation was available for this part. However after a night of hacking I got it to work with my Arduino Uno. I thought Id pass along the following information to spare others the trouble.
On the software side, you have to download and install a new LiquidCrystal_I2C library for Arduino, which has the capability to talk to the LCD display over the I2C bus. Heres a link to the library. Follow the example code for the DFRobot board, which turns out to have the same configuration as this LCD, and it should fire right up for you. The LCD has white characters on a backlit blue background, and looked great.
Liquid Crystal displays or LCDs have been used in electronics equipment since the late 1970s. LCD displays have the advantage of consuming very little current And they are ideal for your Arduino projects.
In this article and in the accompanying video I’ll show you how easy it is to add an LCD display to your next Arduino design. I’ll also show you a very popular Arduino Shield that has a keypad which you can use in your projects as well.
Today LCD displays are used in a variety of items from test equipment to televisions. They’re inexpensive and versatile, this makes them ideal for all sorts of designs.
LCD displays do not emit light. Instead they block the passage of light, like little windows which open and shut the let light through. The liquid crystals used inside LCD displays are sandwiched between two layers of polarized material. By changing the orientation of the liquid crystals they allow light to pass or they block the light entirely.
Because transmissive LCD displays (the type we will be using) work by blocking light they require a backlight. Several methods have been used to create back lights including electroluminescent panels and fluorescent tubes. these days the most common form of backlight is an LED, in fact so-called LED televisions are usually just LCD screens with an LED backlight system.
Another type of LCD display, the passive-matrix display, does not require a backlight, it works using reflected light. This type of display is often found in digital watches.
The principles of liquid crystals were discovered in the late 1880s but work on Modern LCD displays did not begin until the mid-1960s. a number of patents were filed in the early 1970s and in 1973 the Sharp Corporation introduced LCD displays for calculators.
The first color LCD displays were developed in the early 1980s but production units were not commonly available until the mid-1990s. By the late 1990s LCD displays were quite common.
A number of LCD displays are available for experimenters. These low-cost monochrome displays are ideal for use with microcontrollers like the Arduino and micro computers like the Raspberry Pi.
The LCD1602 display module is a very popular and inexpensive LCD display. It is available in a number of different colors such as blue yellow and green and can easily be connected to an Arduino or Raspberry Pi.
Brightness– This is the input for the brightness control voltage, which varies between 0 and 5 volts to control the display brightness. On some modules this pin is labeled V0.
Because the LCD module uses a parallel data input it requires 8 connections to the host microcontroller for the data alone. Add that to the other control pins and it consumes a lot of connections. On an Arduino Uno half of the I/O pins would be taken up by the display, which can be problematic if you want to use the I/O pins for other input or output devices.
We will begin our experiments by hooking up the LCD1602 to an Arduino Uno and running a few of the example sketches included with the Arduino IDE. This will allow you to get familiar with the display without needing to write any code.
We need to hookup our LCD display to our Arduino. The display can use any of the Arduino digital I/O pins as it has no special requirements, but if you hook it up as I’ve illustrated here you can run the example sketches without needing to make any modifications.
In addition to the LCD1602 display ands the Arduino Uno you will need a 10K trimpot ot potentiometer, this is used a s a brightness control for the display. You’ll also need a 220 ohm resistor to drop the voltage for the displays LED backlight.
The Arduino IDE includestheLiquidCrystallibraryand this library has a number of example sketches. I’ll go over three of them here but you can also try the other ones.
The sketch starts with a number of credits and a description of the required hardware hookup. You’ll note that this is the same hookup you just performed on your Arduino and LCD module.
We then initialize an object that we call “lcd” using the pinouts of the LCD display. If you decide to hook up your display to different pins then you’ll need to modify this section.
That ends the loop, so we start back at the top of the loop and repeat. The result will be a counter on the second line that counts seconds from the htime the Arduino was last reset.
Load the sketch up to your Arduino and observe your display. If you don’t see anything try adjusting the brightness control that you wired to the display.
The second example we will try isthe Scroll sketch. Scrolling is a useful technique when you can’t get your text to fit on one line of the LCD display.
The Custom Character demonstration requires one additional component to be wired to the Arduino, a potentiometer (10K or greater) wired up to deliver a variable voltage to analog input pin A0.
As with the previous sketches we examined this one starts by loading theLiquidCrystallibrary and defining an object calledlcdwith the connection information for the display. It then moves on to define the custom characters.
Finally the setup routine ends by printing a line to the first row of the LCD display. The line makes use of two of the custom characters, the “heart” and the “smiley”.
We begin by reading the value of the voltage on pin A0 using the ArduinoanalogReadfunction. As the Arduino has a 10-bit analog to digital converter this will result in a reading ranging from 0 to 1023.
We then use an Arduinomapfunction to convert this reading into a range from 200 to 1000. This value is then assigned to an integer calleddelayTime, which as its name implies represents a time delay period.
One thing you may have noticed about using the LCD display module with the Arduino is that it consumes a lot of connections. Even in 4-wire mode there are still a total of seven connections made to the Arduino digital I/O pins. As an Arduino Uno has only 14 digital I/O pins that’s half of them used up for the display.
In other cases you would need to resort to using some of the analog pins as digital pins or even moving up to an Arduino Mega which has many more I/O pins.
But there is another solution. Use the I2C bus adapter for the LCD display and connect using I2C. This only consumes two I/O pins and they aren’t even part of the set of digital I/O pins.
The bus has evolved to be used as an ideal method of communicating between microcontrollers, integrated circuits, sensors and micro computers. You can use it to allow multiple Arduinos to talk to each other, to interface numerous sensors and output devices or to facilitate communications between a Raspberry Pi and one or more Arduinos.
In I2C communications there is the concept of Master and Slave devices. There can be multiples of each but there can only be one Master at any given moment. In most Arduino applications one Arduino is designated Master permanently while the other Arduinos and peripherals are the Slaves.
The I2C Adapter for the LCD display is a tiny circuit board with 16 male header pins soldered to it. These pins are meant to be connected directly to the 16-pin connection on the LCD1602 display (or onto other displays that use the same connection scheme).
The device also has a 4-pin connector for connection to the I2C bus. In addition there is a small trimpot on the board, this is the LCD display brightness control.
Most Arduino Unos also have some dedicated pins for I2C, these are internally connected to A4 and A5 and are usually located above the 14 digital I/O pins. Some models of the Uno have additional I2C connectors as well.
Note how much easier it is to use the I2C connection, which does not consume any of the Arduino Unos 14 digital I/O pins. Since A4 and A5 are being used for the I2C bus they can’t be used as analog inputs in this configuration.
Load this sketch into your Arduino then open your serial monitor. You’ll see the I2C address of your I2C LCD display adapter. You can then make note of this address and use it in the sketches we’ll be looking at now.
In order to run the subsequent sketches you’ll need to install another library. This is theNewLiquidCrystallibrarywhich, as its name implies, is an improved version of the LiquidCrystal library packaged with your Arduino IDE.
The sketch starts by loading the ArduinoWirelibrary. This is the Arduino library that facilitates communications over I2C and it’s part of your Arduino IDE installation.
On the next line we define the connections to the LCD display module from the I2C Adapter,. Note that these are NOT the connections from the Arduino, they are the connections used by the chip on the adapter itself.
Load the sketch and run it on your Arduino. If you can’t get it to work check out the address and connection information to be sure you have it right.
As you can see the DHT22 is connected with its output tied to pin 7 of the Arduino. The other two connections are 5 volts and ground. Note that pin 3 of the DHT22 is not used.
This sketch also makes use of theDHTlibrary from Adafruit. We used this library in a previous article, “Using the HC-SR04 Ultrasonic Distance Sensor with Arduino” so you may want to take a look at that one in order to get it installed.
The key thing to note is that this library is dependant upon another Adafruit library, theirUnified Sensorlibrary. Both can be installed using the Library Manager in your Arduino IDE.
The sketch is similar to our demo sketch in that it creates an “lcd” object with the I2C and display connection information. It also defines a couple of parameters for the DHT22 sensor, as well as some floating variables to hold the temperature and humidity values.
So far we have used the LCD1602 display module for all of our experiments. For our final demonstration we’ll switch to a popular Arduino shield that contains a LCD1602 along with some push buttons.
The LCD Keypad Shield is available from several different manufacturers. The device fits onto an Arduino Uno or an Arduino Mega and simplifies adding an LCD display to your project.
The Reset button is simply connected to the Arduino Reset pin and works just like the Reset button on the Arduino itself. This is common on many shields as the shields physically cover the Reset button.
Instead the buttons are connected to a resistor array that acts as a voltage divider. The entire array is connected to the Arduino’s analog A0 pin. One pin for five push buttons.
Note that the LCD is being used in 4-wire mode. The LCD itself is the same one used on the LCD1602 module, so all of the code for that module will work with the LCD Keypad Shield as well.
Now that you know how the LCD Keypad module works and which Arduino pins it uses all that remains is to install it onto your Arduino and load the demo sketch.
One thing – once the shield is installed on the Arduino you won’t have easy access to the unused I/O pins to connect any sensors or output devices you may want to use (although the demo sketch doesn’t need anything else connected). There are a couple of ways to get around this:
Use a shield that exposes the pins for prototyping before you install the LCD Keypad shield. In the video associated with this article I use a “Screw Shield” that brings all of the Arduino I/O pins out to a series of screw connectors. There are other similar shields. Using one of these shields is the easiest way to work with the LCD Keypad shield, as well as other Arduino shields.
The sketch begins by including theLiquidCrystallibrary. You can use the original one or the one includes with theNewLiquidCrystallibrary. We then set up an object with the LCD connections, note that these are just hard-coded as they won’t change.
Next we define a number of constants, one for each of the push buttons. Note that nothing is defined for the Reset button as it simply mimics the Arduino Reset button, however a constant is defined for the “none” condition.
After that we define a function calledread_LCD_buttons(). This function reads the value on analog port A0 and returns an integer corresponding to the button integers we defined earlier. Note that the function adds approximately 50 to each of the manufacturers specified values to account for intolerances in the resistors in the voltage divider.
We start the loop by placing the cursor 9 spaces over on the second line. We then use themillisfunction to display a counter that counts the time since the Arduino was reset. This is to test the Reset button.
We then call ourread_LCD_buttons()function and use it to display the value of the push button, right before the counter. Then we end the loop and do it again.
Load the code onto the Arduino and run it. You should see the value of each button as you press it, along with a counter that increments each second. If you press Reset the counter should reset itself back to zero.
As you can see LCD displays are pretty simple to use thanks to the availability of some excellent libraries for the Arduino. As these displays are also very inexpensive they will make an ideal addition to many of your Arduino projects.
And finally the LCD Keypad Shield is a convenient method of adding both a display and a simple keypad to your project, no wiring or soldering required.
In most electronic systems, it is necessary to provide information in the visual form for a convenient user interface. The most commonly used displays in electronic systems are LED, LCD and TFT. Amongst these, an LCD display is the most cost-effective solution as it can display alphanumeric characters along with special user-defined symbols. It also contains an integrated controller which frees up the main microprocessor from the task of refreshing the display and improves overall system throughput. But at the same time it requires a large number of pins for interfacing with the system, which consume a lot of microcontroller’s ports.
The presented serial LCD module can convert any 16×2 alphanumeric LCD display to a serial LCD which communicates with the main controller using serial communication technique. The brightness of LCD backlight can also be controlled. If the text exceeds 16 characters, the remaining text automatically accommodates in the second line. The serial LCD module communicates on 9600 standard baud rate, which is compatible with all microcontrollers. Fig. 1 shows the author’s prototype of the serial LCD module.
Fig. 2 shows the circuit of the serial LCD module connected to Arduino Uno (Board1) using only one wire. Microcontroller ATmega8 (IC1) works with an 8MHz internal oscillator. It uses no-xtal bootloader which provides Arduino compatibility without 16MHz external crystal. Using 8MHz internal oscillator reduces hardware and improves power efficiency. IC1 uses its serial port to communicate with the main controller (Arduino Uno in this case). It acts as a bridge between the main controller and the LCD.
ATmega8 can be replaced by ATmega168/328 without changing the code, but the bootloader will need to be changed. Table I indicates the connections between IC1 and LCD1. The supply to the module is provided by the Arduino Uno itself as shown in Fig. 2.
Arduino Uno board. Arduino is an open source electronics prototyping platform based on flexible, easy-to-use hardware and software. It is intended for artists, designers, hobbyists and anyone interested in creating interactive objects or environments. Arduino Uno is a board based on ATmega328 microcontroller. It comprises 14 digital input/output (I/O) pins, six analogue inputs, a USB connection for programming the on-board microcontroller, power jack, an ICSP header and a reset button. It is operated with a 16MHz crystal oscillator and contains everything needed to support the microcontroller. It is very easy to use as the user simply needs to connect it to a computer with a USB cable or power it with an AC-to-DC adaptor or battery to get started. The microcontroller on the board is programmed using Arduino programming language and Arduino development environment.
The software for the serial LCD module is written in Arduino programming language. Follow the steps below to burn the bootloader and the firmware in IC1:
1. All the required software is provided in EFY DVD and at source.efymag.com. Put the ATmega8 (IC1) chip in Arduino Uno board and follow the instructions: click here. The fuse bits are 0xCA and 0xD4. Program lock bits as 0x0F so that the bootloader is not overwritten every time you flash new firmware.
3. Restart Arduino IDE (Arduino-0022) and you will see a new entry ([email protected]) in the ‘Boards’ menu. Copy the provided code in Arduino IDE and select board as atmega8-noxal.
5. Remove ATmega8 chip from the Uno board and place back the original microcontroller. Put the programmed ATmega8 chip in the provided PCB and your serial LCD module is ready to use. If you wish to use ATmega168/328, you must choose proper bootloader and board before uploading. Sketch is compatible with all these microcontrollers.
You can use serial LCD library if you want to drive the serial LCD module using Arduino Uno. For that, connect the board with the module as shown in Fig. 2 and copy the library (serialLCD) to the libraries folder of Arduino IDE.
A single-side PCB for serial LCD module is shown in Fig. 3 and its component layout in Fig. 4. Assemble the circuit on the recommended PCB to minimise any assembly errors. Use IC base for ATmega8.
To test the circuit for proper functioning, verify correct 5V supply at TP1 with respect to TP0. The serial data to the LCD module can be seen at TP2 using an oscilloscope.
In this tutorial, I’ll explain how to set up an LCD on an Arduino and show you all the different ways you can program it. I’ll show you how to print text, scroll text, make custom characters, blink text, and position text. They’re great for any project that outputs data, and they can make your project a lot more interesting and interactive.
The display I’m using is a 16×2 LCD display that I bought for about $5. You may be wondering why it’s called a 16×2 LCD. The part 16×2 means that the LCD has 2 lines, and can display 16 characters per line. Therefore, a 16×2 LCD screen can display up to 32 characters at once. It is possible to display more than 32 characters with scrolling though.
The code in this article is written for LCD’s that use the standard Hitachi HD44780 driver. If your LCD has 16 pins, then it probably has the Hitachi HD44780 driver. These displays can be wired in either 4 bit mode or 8 bit mode. Wiring the LCD in 4 bit mode is usually preferred since it uses four less wires than 8 bit mode. In practice, there isn’t a noticeable difference in performance between the two modes. In this tutorial, I’ll connect the LCD in 4 bit mode.
Here’s a diagram of the pins on the LCD I’m using. The connections from each pin to the Arduino will be the same, but your pins might be arranged differently on the LCD. Be sure to check the datasheet or look for labels on your particular LCD:
Also, you might need to solder a 16 pin header to your LCD before connecting it to a breadboard. Follow the diagram below to wire the LCD to your Arduino:
All of the code below uses the LiquidCrystal library that comes pre-installed with the Arduino IDE. A library is a set of functions that can be easily added to a program in an abbreviated format.
In order to use a library, it needs be included in the program. Line 1 in the code below does this with the command #include
Now we’re ready to get into the programming! I’ll go over more interesting things you can do in a moment, but for now lets just run a simple test program. This program will print “hello, world!” to the screen. Enter this code into the Arduino IDE and upload it to the board:
TheLiquidCrystal() function sets the pins the Arduino uses to connect to the LCD. You can use any of the Arduino’s digital pins to control the LCD. Just put the Arduino pin numbers inside the parentheses in this order:
This function sets the dimensions of the LCD. It needs to be placed before any other LiquidCrystal function in the void setup() section of the program. The number of rows and columns are specified as lcd.begin(columns, rows). For a 16×2 LCD, you would use lcd.begin(16, 2), and for a 20×4 LCD you would use lcd.begin(20, 4).
This function clears any text or data already displayed on the LCD. If you use lcd.clear() with lcd.print() and the delay() function in the void loop() section, you can make a simple blinking text program:
Similar, but more useful than lcd.home() is lcd.setCursor(). This function places the cursor (and any printed text) at any position on the screen. It can be used in the void setup() or void loop() section of your program.
The cursor position is defined with lcd.setCursor(column, row). The column and row coordinates start from zero (0-15 and 0-1 respectively). For example, using lcd.setCursor(2, 1) in the void setup() section of the “hello, world!” program above prints “hello, world!” to the lower line and shifts it to the right two spaces:
You can use this function to write different types of data to the LCD, for example the reading from a temperature sensor, or the coordinates from a GPS module. You can also use it to print custom characters that you create yourself (more on this below). Use lcd.write() in the void setup() or void loop() section of your program.
The function lcd.noCursor() turns the cursor off. lcd.cursor() and lcd.noCursor() can be used together in the void loop() section to make a blinking cursor similar to what you see in many text input fields:
Cursors can be placed anywhere on the screen with the lcd.setCursor() function. This code places a blinking cursor directly below the exclamation point in “hello, world!”:
This function creates a block style cursor that blinks on and off at approximately 500 milliseconds per cycle. Use it in the void loop() section. The function lcd.noBlink() disables the blinking block cursor.
This function turns on any text or cursors that have been printed to the LCD screen. The function lcd.noDisplay() turns off any text or cursors printed to the LCD, without clearing it from the LCD’s memory.
This function takes anything printed to the LCD and moves it to the left. It should be used in the void loop() section with a delay command following it. The function will move the text 40 spaces to the left before it loops back to the first character. This code moves the “hello, world!” text to the left, at a rate of one second per character:
Like the lcd.scrollDisplay() functions, the text can be up to 40 characters in length before repeating. At first glance, this function seems less useful than the lcd.scrollDisplay() functions, but it can be very useful for creating animations with custom characters.
lcd.noAutoscroll() turns the lcd.autoscroll() function off. Use this function before or after lcd.autoscroll() in the void loop() section to create sequences of scrolling text or animations.
This function sets the direction that text is printed to the screen. The default mode is from left to right using the command lcd.leftToRight(), but you may find some cases where it’s useful to output text in the reverse direction:
This code prints the “hello, world!” text as “!dlrow ,olleh”. Unless you specify the placement of the cursor with lcd.setCursor(), the text will print from the (0, 1) position and only the first character of the string will be visible.
This command allows you to create your own custom characters. Each character of a 16×2 LCD has a 5 pixel width and an 8 pixel height. Up to 8 different custom characters can be defined in a single program. To design your own characters, you’ll need to make a binary matrix of your custom character from an LCD character generator or map it yourself. This code creates a degree symbol (°):
In this project, I will show you how to interface a 128X64 Graphical LCD with Arduino UNO. This particular LCD Module is based ST7920 LCD Controller. So, we will first see a little bit about the Graphical LCD Module and its LCD Controller ST7920.
In the previous Arduino project, I have interfaced a Nokia 5110 LCD Module with Arduino. It is also a graphical LCD which can display some basic bitmap images and graphics. But the issue with Nokia 5110 LCD Module is its resolution.
At 84 x 48 pixels, the Nokia 5110 LCD can be used for implementing a menu-based user interface. Due to its small size, the resulting menu will be limited to 3 or 4 items per page.
If we want a bigger display with more real estate to work with, then the obvious choice is to go for the bigger and better 128×64 Graphical LCD Module.
As a demonstration, after making all the hardware connections, I will display a bitmap image on the Graphical LCD Module. If you are interested in implementing a simple 16×2 Alpha-Numeric LCD with Arduino, then check out this tutorial.
At first glance, the 128×64 Graphical LCD Module seems like a bigger brother to the famous 16×2 LCD or 20×4 LCD Modules, with their similar construction and almost similar pin layout.
But there is a significant difference between those two. 16×2 or 20×4 LCDs are essentially character displays. They can only display alpha-numeric characters and some simple custom characters that are confined to a 5×8 matrix.
By using different combinations of pixels, we can basically display characters of various sizes. But the magic doesn’t end there. You can display images and graphics (small animations) as well. In a 128×64 LCD Module, there are 64 rows and 128 columns.
There are several versions of the Graphical LCD in the market. Even though the usage, application and implementations are almost identical, the main difference lies in the internal LCD Controller used to drive the dot matrix display.
Some of the commonly used LCD Controllers are KS0108, SSD1306, ST7920, SH1106, SSD1322, etc. The pin out of the final LCD Module might vary depending on the LCD Controller used. So, please verify the LCD Controller as well as the pin out before making a purchase.
The Graphical LCD Module I purchased consists of ST7920 Controller. It is manufactured by Sitronix and supports three types of bus interfaces i.e., 8-bit mode, 4-bit mode and Serial interface.
If you have used 16×2 LCD Display earlier, then you might be familiar with both 4-bit as well as 8-bit parallel interfaces. The serial interface is something new and we will explore this option in this project.
As I already mentioned, double-check with the manufacturer about the pinout of the Graphical LCD Module. The following table describes the pinout of the 128×64 LCD Module that I have.
Now that we have seen a little bit about the Graphical LCD and its controller ST7920, let us now proceed with interfacing the 128×64 Graphical LCD with Arduino. I will implement a simple circuit to demonstrate how easy it is to interface the LCD and Arduino using very few external components.
In Serial Mode, we need only three pins for the actual data transfer. They are RS, RW and E. RS acts as Chip Select Pin in Serial Communication. RW and E acts as Serial Data IN and Serial CLK pins respectively.
So, connect the RS, RW and E of the LCD to Digital IO pins 10, 11 and 13 of Arduino UNO. Also, in order to select the Serial Interface Mode, the PCB pin must be connected to GND.
The remaining connections are similar to a traditional 16×2 LCD. VCC and GND are connected to 5V and ground of the power supply. VO is connected to the wiper of a 10KΩ POT while the other two terminals of the POT are connected to 5V and GND respectively.
I have used the above “The Office” logo. Remember that the resolution of the 128×64 LCD is, well 128×64 pixels. So, the maximum image size should be 128×64. So, using Microsoft Paint, I have brought down the resolution of the above image to 128×64 pixels and also saved it as Monochrome Bitmap Image.
Before writing the code, you need to download a special library called “U8g2”. In the Arduino IDE, go to Tools -> Manage Libraries… Search for “u8g2” and install the latest version. It is a complex library and its github page consists of all the necessary documentation.
A simple project for interfacing the 128×64 Graphical LCD with Arduino is implemented here. Instead of displaying plain characters, I have displayed a bitmap image on the LCD to show its capability.
As we all know, though LCD and some other displays greatly enrich the man-machine interaction, they share a common weakness. When they are connected to a controller, multiple IOs will be occupied of the controller which has no so many outer ports. Also it restricts other functions of the controller. Therefore, LCD1602 with an I2C bus is developed to solve the problem.
I2C bus is a type of serial bus invented by PHLIPS. It is a high performance serial bus which has bus ruling and high or low speed device synchronization function required by multiple-host system. The blue potentiometer on the I2C LCD1602 (see the figure below) is used to adjust the backlight for better display. I²C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted.
Step 3:Since in some code, the libraries needed are not included in Arduino, so you need to add them before compiling. Unzip the downloaded file. Copy the folders under the Library folder to the libraries folder in Arduino (if you cannot find the path in Arduino, open Arduino IDE, click File ->Preferences, and you can see the path in the Browse box, as shown in the following diagram). Compile the program.