Hello readers, we hope you all are doing great. Welcome to the 1st lecture of Section 4 in the ESP32 Programming Series. In this section, we will interface the ESP32 module with common Embedded modules(i.e. LCD, Keypad, RTC etc.).
In today's tutorial, we will interface ESP32 with a 16x2 LCD and will display data using both Data Mode and I2C Mode. LCD is the most commonly used embedded module in IoT Projects. It is used to display different types of data i.e. sensor readings, warning messages, notifications etc.
Before going forward, let's first have a look at what is LCD and How it works:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | ESP32 | Amazon | Buy Now |
LCD(Liquid Crystal Display) is a type of electronic display module that is used in a wide variety of applications and devices such as calculators, computers, mobile phones, TVs, etc. There are different types of LCDs available for commercial use. Today, we are going to use the most simple one i.e. 16x2 LCD, shown in the below figure:
This 16x2 LCD has 16 columns and 2 rows, so in total of 32 blocks to display characters. Each Block can display a single character at a time. We can display text in different styles on this LCD i.e. blinking, scrolling etc. Another variant of this LCD is 20x4 LCD and as the name suggests, it has 20 columns and 4 rows and so can display 80 characters at a time. The operating principle of both of these LCDs is quite similar. So, if you are working with a 20x4 LCD, you can still follow this tutorial.
Let's have a look at the LCD pinout:
Both 16x2 and 20x4 LCDs have 16 pins each, used to control 7 write on these LCDs. Among these 16 pins, we have:
LCD Pinout and its working is shown in the below table:
LCD Pinout |
||||
---|---|---|---|---|
Pin No. | Name | Working | ||
1 |
GND(Ground) |
Connected to Ground Terminal. |
||
2 |
Vcc(+5V) |
Connected to +5V. |
||
3 |
VE |
To Control the LCD Contrast. |
||
4 |
RS(Register Select) | If RS=0(GND), LCD operates in Data Mode and we can write characters on the LCD. |
||
If RS=1(+5V), LCD Command Mode gets activated and we can send commands to LCD i.e. erase, new line etc.. |
||||
5 |
R/W(Read & Write) | R/W=0(GND) enables the write operation on the LCD. (So, we normally keep this pin LOW, as we are interested in printing on the LCD). | ||
R/W=1(+5V) enables the read operation on the LCD. |
||||
6 |
EN(Enable) |
Enables the LCD to operate, so it should be kept HIGH. |
||
7 |
Data Pin 0 |
LCD has a total of 8 Data Pins(D0-D7) | ||
8 |
Data Pin 1 |
|||
9 |
Data Pin 2 |
|||
10 |
Data Pin 3 |
|||
11 |
Data Pin 4 |
|||
12 |
Data Pin 5 |
|||
13 |
Data Pin 6 |
|||
14 |
Data Pin 7 |
|||
15 |
LED+ |
Connected to +5V. Turn on the backlight LED. |
||
16 |
LED- |
Connected to GND. |
Now, let's interface the LCD with ESP32:
There are two methods to interface ESP32 with a 16x2 LCD:
In the Data Mode, we use the LCD Data Pins and send data serially, while in the I2C mode, we solder an I2C adapter with the LCD, which acts as a bridge and maps I2C data coming from the microcontroller to the Data Pins. Let's first interface ESP32 and LCD via Data Pins:
As we discussed earlier, LCD has 8 Data Pins used to communicate with the Microcontroller. There are two ways to send data from the Microcontroller to the LCD:
In complex projects, where you are dealing with multiple sensors & modules, its quite difficult to spare 8 Pins for LCD interfacing. So, normally 4-Pin method is preferred, which we are going to design next:
Here are the components required to interface LCD with ESP32:
Now, let's design the ESP32 LCD Circuit Diagram:
[Image]
As you can see in the above figure:
Here's our hardware setup for ESP32 LCD Interfacing:
[Image]
Now let's design the Programming Code to print a simple message on the LCD:
We are using Arduino IDE to compile and upload code in the ESP32 module. If you haven't installed it yet, please read How to Install ESP32 in Arduino IDE. Here's the code to print a message on the LCD:
#include
LiquidCrystal lcd(22,23,5,18,19,21);
void setup()
{
lcd.begin(16, 2);
lcd.clear();
// go to row 0 column 5, note that this is indexed at 0
lcd.setCursor(5,0);
lcd.print("ESP32");
// go to row 1 column 0, note that this is indexed at 0
lcd.setCursor(0,1);
lcd.print (" TheEnggProjects");
}
void loop()
{
}
#include
LiquidCrystal lcd(22,23,5,18,19,21);
In the Setup() Function:
lcd.begin(16, 2);
So, if you are using a 20x4 LCD, you should change its arguments to 20 and 4, as shown below:
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(5,0);
lcd.print("ESP32");
lcd.setCursor(0,1);
lcd.print (" TheEnggProjects");
As you can see, the LCD code is quite simple and I hope now you can easily print on the LCD. So, let's check the results:
Fig. 6
Sol. : Check the EN pin.
Fig. 7
This concludes the tutorial. We hope you found this of some help and also hope to see you soon with a new tutorial on ESP32.
Tech tools can make or break a business in this day and age, regardless of the industry or niche a venture is in. As such, it’s vital to source the best possible technologies that will help you make your organization the best it can be and the most likely to reach its goals. As you invest in technology, it pays to avoid some common mistakes.
Many entrepreneurs have a detailed business plan they created when they began or bought their business, but they fail to plan much for technology. It’s essential to have a vision and strategy for your technological needs so you don’t keep jumping from one system, app, or product to another with no clarity on why you need certain programs.
A lack of planning can add to your total costs, too, since you’re more likely to have to keep buying new software to try to find the right things to suit your needs, rather than understanding from the start what’s required. Consider the various areas of your business and what you need in each.
For example, think about your sales and marketing processes, HR and payroll requirements, finance and accounting needs, where you’re up to with strategic sourcing in 2022, customer service plans, and more. Where possible, invest in tech tools that can be used across different parts of your organization and that will integrate well, too.
With so many different tech products coming out all the time, it’s easy to be like a bowerbird and get distracted by shiny new objects in this field that seem fun and interesting. However, focusing on trends and the latest gear rather than what’s actually the best fit for your company and needs is a common mistake.
Going down this path will mean you likely end up spending a lot more money than you need to on technology and buying devices or programs that aren’t suited to your business or are simply irrelevant. Instead, refer back to your tech plan to see if new products will provide the solutions you’re after and, if not, appreciate what they offer but don’t bother buying them.
If you feel called to test a new offering, at least sign up for a free trial so you don’t have to outlay money on it. You can always cancel after the zero-cost introductory period if you can tell you really won’t use the software or that it doesn’t do enough for your needs.
Another common mistake many business owners and managers make is not creating a budget for technological items at the start of the calendar or financial year. When you have a budget in place, you stop and think twice before signing up for a subscription service when it releases or the latest gadget you hear other entrepreneurs talking about.
A set budget specifically for tech goods keeps you on track financially and keeps you and your team accountable. Keep in mind, too, that every new tool you buy needs setting up and learning in some way, which is time-consuming. When you adhere to a budget, you’re less likely to end up getting bogged down with too many things to wrap your head around.
Unfortunately, though, many people get so busy with general day-to-day tasks that they forget about this area or think it’s something they can consider later (a time that never really comes until the worst happens). If you want to protect your firm’s and customers’ data from prying eyes and stop hackers from charging you ransom or stealing money, you need to spend plenty of time and energy upgrading your company’s security processes.
Invest in quality, comprehensive security software and firewalls that protect devices and accounts. Ensure all computers and programs are kept updated at all times so there are fewer security gaps for hackers to take advantage of. Train your staff to be very careful about what links they click on and emails they open. They should choose solid passwords that can’t be easily guessed. Proper codes are at least eight characters in length, made up of a mixture of numbers, letters, and symbols, and changed every so often.
Other mistakes to avoid include rushing into purchases, neglecting free downloadable tools, and not testing systems enough before going live or otherwise implementing them. Be wary of considering price only when evaluating products, as customer support, security, scalability, and other factors also matter.
Technology can help us considerably to run our ventures but only when we invest in suitable options. Think about all these errors that others have made before you when buying tech tools so you can save yourself cash, headaches, and time.