lcd module tutorial supplier
The Serial Monitor is a convenient way to view data from an Arduino, but what if you want to make your project portable and view sensor values without access to a computer? Liquid crystal displays (LCDs) are excellent for displaying a string of words or sensor data.
This guide will help you in getting your 16×2 character LCD up and running, as well as other character LCDs (such as 16×4, 16×1, 20×4, etc.) that use Hitachi’s LCD controller chip, the HD44780.
As the name suggests, these LCDs are ideal for displaying only characters. A 16×2 character LCD, for example, can display 32 ASCII characters across two rows.
Character LCDs are available in a variety of sizes and colors, including 16×1, 16×4, 20×4, white text on a blue background, black text on a green background, and many more.
One advantage of using any of these displays in your project is that they are “swappable,” meaning that you can easily replace them with another LCD of a different size or color. Your code will need to be tweaked slightly, but the wiring will remain the same!
Before we get into the hookup and example code, let’s check out the pinout. A standard character LCD has 16 pins (except for an RGB LCD, which has 18 pins).
Vo (LCD Contrast) pin controls the contrast of the LCD. Using a simple voltage divider network and a potentiometer, we can make precise contrast adjustments.
RS (Register Select) pin is used to separate the commands (such as setting the cursor to a specific location, clearing the screen, etc.) from the data. The RS pin is set to LOW when sending commands to the LCD and HIGH when sending data.
R/W (Read/Write) pin allows you to read data from or write data to the LCD. Since the LCD is only used as an output device, this pin is typically held low. This forces the LCD into WRITE mode.
E (Enable) pin is used to enable the display. When this pin is set to LOW, the LCD ignores activity on the R/W, RS, and data bus lines; when it is set to HIGH, the LCD processes the incoming data.
The LCD has two separate power connections: one for the LCD (pins 1 and 2) and one for the LCD backlight (pins 15 and 16). Connect LCD pins 1 and 16 to GND and 2 and 15 to 5V.
Depending on the manufacturer, some LCDs include a current-limiting resistor for the backlight. It is located on the back of the LCD, close to pin 15. If your LCD does not contain this resistor or if you are unsure whether it does, you must add one between 5V and pin 15. It should be safe to use a 220 ohm resistor, although a value this high may make the backlight slightly dim. For better results, check the datasheet for the maximum backlight current and choose an appropriate resistor value.
Let’s connect a potentiometer to the display. This is necessary to fine-tune the contrast of the display for best visibility. Connect one side of the 10K potentiometer to 5V and the other to Ground, and connect the middle of the pot (wiper) to LCD pin 3.
That’s all. Now, turn on the Arduino. You will see the backlight light up. As you turn the potentiometer knob, you will see the first row of rectangles appear. If you have made it this far, Congratulations! Your LCD is functioning properly.
We know that data is sent to the LCD via eight data pins. However, HD44780-based LCDs are designed so that we can communicate with them using only four data pins (in 4-bit mode) rather than eight (in 8-bit mode). This helps us save 4 I/O pins!
The sketch begins by including the LiquidCrystal library. This library comes with the Arduino IDE and allows you to control Hitachi HD44780 driver-based LCD displays.
Next, an object of the LiquidCrystal class is created by passing as parameters the pin numbers to which the LCD’s RS, EN, and four data pins are connected.
In the setup, two functions are called. The first function is begin(). It is used to initialize the interface to the LCD screen and to specify the dimensions (columns and rows) of the display. If you’re using a 16×2 character LCD, you should pass 16 and 2; if you’re using a 20×4 LCD, you should pass 20 and 4.
In the loop, the print() function is used to print “Hello world!” to the LCD. Please remember to use quotation marks " " around the text. There is no need for quotation marks when printing numbers or variables.
The function setCursor() is then called to move the cursor to the second row. The cursor position specifies where you want the new text to appear on the LCD. It is assumed that the upper left corner is col=0 and row=0.
There are many useful functions you can use with LiquidCrystal Object. Some of them are listed below:lcd.home() function positions the cursor in the upper-left of the LCD without clearing the display.
lcd.scrollDisplayRight() function scrolls the contents of the display one space to the right. If you want the text to scroll continuously, you have to use this function inside a for loop.
lcd.scrollDisplayLeft() function scrolls the contents of the display one space to the left. Similar to the above function, use this inside a for loop for continuous scrolling.
lcd.display() function turns on the LCD display, after it’s been turned off with noDisplay(). This will restore the text (and cursor) that was on the display.
As previously discussed in this tutorial, a character is made up of a 5×8 pixel matrix; therefore, you must define your custom character within this matrix. You can define a character by using the createChar() function.
The CGROM stores the font that appears on a character LCD. When you instruct a character LCD to display the letter ‘A’, it needs to know which dots to turn on so that we see an ‘A’. This data is stored in the CGROM.
CGRAM is an additional memory for storing user-defined characters. This RAM is limited to 64 bytes. Therefore, for a 5×8 pixel LCD, only 8 user-defined characters can be stored in CGRAM, whereas for a 5×10 pixel LCD, only 4 can be stored.
After including the library and creating the LCD object, custom character arrays are defined. The array consists of 8 bytes, with each byte representing a row in a 5×8 matrix.
Previous examples connect the white LED backlight to power. The following example is specifically for those using an LCD with a RGB LED backlight. The only difference between the connection is the LED"s backlight on pins 15-18.
The lcd.begin(16,2) command set up the LCD number of columns and rows. For example, if you have an LCD with 20 columns and 4 rows (20x4) you will have to change this to lcd.begin(20x4).
The lcd.print("--message--") command print a message to first column and row of lcd display. The "message" must have maximum length equal to lcd columns number. For example, for 16 columns display max length is equal with 16 and for 20 columns display max length is equal with 20.
Thelcd.setCursor(0,1) command will set cursor to first column of second row. If you have an LCD 20x4 and you want to print a message to column five and third row you have to use: lcd.setCursor(4,2).
LCD, or Liquid Crystal Displays, are great choices for many applications. They aren’t that power-hungry, they are available in monochrome or full-color models, and they are available in all shapes and sizes.
Waveshare actually has several round LCD modules, I chose the 1.28-inch model as it was readily available on Amazon. You could probably perform the same experiments using a different module, although you may require a different driver.
The Waveshare Wiki does provide some information about the display and a bit of sample code for a few common controllers. It’s a reasonable support page, unfortunately, it is the only support that Waveshare provides(I would have liked to see more examples and a tutorial, but I guess I’m spoiled by Adafruit and Sparkfun LOL).
Open the Arduino folder. Inside you’ll find quite a few folders, one for each display size that Waveshare supports. As I’m using the 1.28-inch model, I selected theLCD_1inch28folder.
Once you do that, you can open your Arduino IDE and then navigate to that folder. Inside the folder, there is a sketch file namedLCD_1inch28.inowhich you will want to open.
Unfortunately, Waveshare doesn’t offer documentation for this, but you can gather quite a bit of information by reading theLCD_Driver.cppfile, where the functions are somewhat documented.
Here is the hookup for the ESP32 and the GC9A01 display. As with most ESP32 hookup diagrams, it is important to use the correct GPIO numbers instead of physical pins. The diagram shows the WROVER, so if you are using a different module you’ll need to consult its documentation to ensure that you hook it up properly.
The GC9A01 LCD module is a 1.28-inch round display that is useful for instrumentation and other similar projects. Today we will learn how to use this display with an Arduino Uno and an ESP32.
The LCD can be connected in the 4 bit as well as 8 bit mode. In the 4 bit mode we have to use only the 4 data pins while in the 8 bit mode we will have to use all the 8 data pins. You can do almost everything in the 4 bit mode, so in this example we are going to connect it in the 4 bit mode.
This is a Getting Started tutorial, that provides the reader with a broad overview on how to get a project working using the popular NRF24L01+ modules. In this project the user will set up two communication nodes. The “sender” node increments an internal counter and transmits this to the “receiver”. The counter signal is just an example and can easily be replaced with a more useful signal, such a sensor signal or otherwise. The receiver node waits to get the signal and once received displays it on the LCD. Before continuing to the next increment of the counter, the sender node waits to get an acknowledgment from the receiver to ensure the transmission was successful.
This tutorial is set up to utilize some of the features of the NRF-Shield and how they can be utilized. In that spirit, two different Arduino microcontrollers, two different NRF24L01+ versions, two different hardware selection pin configurations, and finally two different ways to power the RF communication modules are employed. With all these complementary differences, the flexibility of the NRF-Shield is explored. The user may wish to simplify this arrangement as they see fit, by reducing these various differences. Furthermore, in terms of advanced RF communication concepts the script is kept as simple as possible. There are many advanced concepts of RF communication that are not covered in this tutorial.
o In this tutorial one Standard-sized NRF24L01+ and one NRF24L01+PA+LNA is used. However, any of these three transceivers as shown in Fig. 1 would work for this tutorial.
Depending on which FTDI USB to TTL serial converter module is used, a special driver, such as the CH340 driver, might have to be installed. This is a well-documented driver for which there are many tutorials available. The tutorial we recommend is called “Tutorial: First time using the Nano Microcontroller” by PTSolns. However, if genuine Arduino microcontrollers are used no special driver will be required.
In this section the sender and receiver nodes are assembled. As mentioned above, the two nodes are set up differently in some key aspect in order to highlight particular features of the NRF-Shield. However, the user may wish to alter this setup as they see fit. The final product as will be done in this tutorial should look like similar to what is shown in Fig. 2.
The sender and receiver nodes are discussed in the following subsections. The hardware required to assemble these boards is included in the Deluxe package, excluding the RF modules, wires and the LCD.
Next, a 1X15 pin male header is soldered along the hardware selection pins. 2-pin jumper caps are placed on the following selections: 3V3, D9, D7, and D3. The 3V3 selection is to use the onboard 3.3V supply to power the module. D7 and D9 will be used in the corresponding script. D3, the interrupt pin, is not used in this tutorial.
Regarding the NRF module, the one used on the receiver node has a long PCB and a large antenna. If the RF module does not already have this, the user should solder 1X2 pin male headers onto the RF module on either side of the antenna footprint. In the corresponding footprint on the NRF-Shield, the user should solder 1X2 pin female header. TIP: It is easiest to first put into place these small headers and then soldering them. Although adding these 1X2 pin headers is not required, it is strong recommended as they add structural support for the RF module.
For the hardware selection pins, the following are set: VR, D10, D8, D2. The VR selection is to use the external voltage supply to power the module. This requires the user to install a 3.3V voltage regulator and two smoothing capacitors (these components are included in the Deluxe package). Note that the footprint for the voltage regulator is designed such that any permutation of the Vin, Vout, GND pins are accepted. This is useful in case the user wants to use a different regulator that has a different pinout configuration. It is generally a good idea to use the VR selection with the external voltage regulator when operating the RF module on max power (set in the script), as the NRF24L01+PA+LNA may draw too much current under certain situations that can result in unstable communication. As with the sender node, the receiver node does not utilize the interrupt pin (D2 in this case).
Finally, the user should solder a 4-pin screw terminal (included in the Deluxe package) on the I2C footprint #3 and connect the LCD. Note that the LCD is interfaced by the use of the “backpack”, which allows the LCD to be connected only by four wires through the I2C bus and power. Most LCD modules come with this backpack already installed.
The scripts for the sender and receiver in this tutorial have been reduced to the bare minimum. This is to keep the coding as simple as possible and get started as quickly as possible. However, the user is reminded that many of the details relating to the operation of RF modules are omitted.
The sender and receiver scripts are outlined below. Both the sender and receiver parts are contained in the same script. When uploading the sender side simply uncomment the line #define COMPILE_TX, and comment out the line #define COMPILE_RX and vice versa when uploading the receiver side. Further note that in this tutorial two different Arduino microcontrollers are used and hence the corresponding selection has to be made in the IDE software.
Notice in the script on lines 17 and 21 the CE and CSN pins are selected as they correspond to the respective hardware selection that was done in Section 4. Being able to select between different CE and CSN pins (as well as the interrupt, which is not used in this tutorial) is quite useful. Such as, for example, if a different part of the project/stack uses a pin that would otherwise have been required by the RF module had the hardware selection pins not been available on the board.
LCD character displays are useful for displaying information without the need for an external monitor. Common LCD character displays can be connected directly to the GPIO pins, but such an approach requires the use of up to 10 GPIO pins. For scenarios that require connecting to a combination of devices, devoting so much of the GPIO header to a character display is often impractical.
Many manufacturers sell 20x4 LCD character displays with an integrated GPIO expander. The character display connects directly to the GPIO expander, which then connects to the Raspberry Pi via the Inter-Integrated Circuit (I2C) serial protocol.
There are many manufacturers of LCD character displays. Most designs are identical, and the manufacturer shouldn"t make any difference to the functionality. For reference, this tutorial was developed with the SunFounder LCD2004.
The device address for the GPIO expander depends on the chip used by the manufacturer. GPIO expanders equipped with a PCF8574 use the address 0x27, while those using PCF8574A chips use 0x3F. Consult your LCD"s documentation.
Another using declaration creates an instance of Lcd2004 to represent the display. Several parameters are passed to the constructor describing the settings to use to communicate with the GPIO expander. The GPIO expander is passed as the controller parameter.
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.
The purpose of this guide is to get your 0.96″ color LCD display successfully operating with your Arduino, so you can move forward and experiment and explore further types of operation with the display. This includes installing the Arduino library, making a succesful board connection and running a demonstration sketch.