First, preface:
In the above, the author systematically expounds the two driving modes of 1602, and simply mentions the Liquidcrystal Library of Arduino. In this article, the following two questions are explored in more depth: how can I minimize the 1602-to-Arduino port footprint? How should the Liquidcrystal library learn? Under the Arduino LCD1602 Comprehensive Study (under), the author intends to introduce a 1602 comprehensive experiment, with the aim of comprehensively applying and summarizing the contents of the previous article. Gossip less, the following begins to enter the text.
Second, reduce 1602 to Arduino end share population <1> not use I²c
In the above, the author introduces the use of eight-wire and four-wire drive respectively, and gives two kinds of connection methods. The wiring diagram is as follows:
In eight-wire drive mode, the total number of Arduino 16 ports, four-wire drive mode, although less than eight-wire drive mode four ports, but also reached a staggering 12. If the experiment is just for driving LCD1602 OK, but in other practical applications, this is intolerable. For this reason, how can we minimize the port occupancy? In the two wiring diagrams above, we used two power supplies, the five-v VSS and + 3.3v backlight. In fact, the backlight can be completely received by the + +, and the brightness will be higher. This is, in the actual use of the operation process, RW is generally low-level write. No special needs can be directly grounded. In addition, if we develop good wiring habits, the GND is connected together, so that only a GND port is used. Since we are going to use the example program that comes with Arduino, in order to match the circuit connection of the sample program, we have made some adjustments to the related pin connection, and the adjusted wiring diagram is as follows:
As you can see, the Arduino port can take up a lot less of this type of connection. Especially in four-wire drive mode, only 6 ports are removed from GND and +5v,lcd1602 exclusive.
<1> using I²c
I²c is a communication protocol developed by the former Philips (now NXP) company, which aims to reduce the wiring between chips. After the use of the i²c, connected to the Arduino on the line total only four, exclusive port only two!!!
But this model also has a lot of restrictions, listed as follows:
1. The LCD1602 to be used must be soldered to the LCD1602 i²c module first
The SDA (serial data) and SCL (serial clock) of the 2.I2C module can not be randomly connected. For Arduino Uno, SDA must answer A4,SCL must answer A5
Despite these limitations, there is no doubt that it has largely reduced the wiring between chips.
The I²C protocol is required to use I²C. Typically in Arduino, the control is completed by importing the LIQUIDCRYSTAL_I2C library. As the author does not have LCD1602 i²c module at hand, therefore, the relevant experiments in this skip, and other organic will be supplemented.
Thirdly, how should the Liquidcrystal library learn?
In the Arduino IDE, the official sample program is sufficient for you to complete the learning of liquidcrystal, such as: (All of these programs have a hardware connection that simplifies the same as the LCD1602 four-wire drive hardware connection above)
In addition, I share a good liquidcrystal document that can be used as a liquidcrystal instruction manual. The connection is as follows:
Click to view
Of course, if you want to drill down, open the Libraries folder in the Arduino folder, find the LiquidCrystal.cpp and header files LiquidCrystal.h carefully (provided you have a good C + + foundation).
Iv. a bug in the Liquidcrystal library and the corresponding workaround
In the process of learning Liquidcrystal Library, I found a bug in the Liquidcrystal library, and recorded the following:
<1>bug description
Example program Liquidcrystal->customcharacter no matter how to compile, even if the hardware a little trouble, the compilation is still an error. Such as:
The error message is as follows:
' void Setup () ' : Customcharacter: 119 ' write (int) ' is ambiguouse:\arduino\libraries\liquidcrystal/liquidcrystal.h:virtual size_ T Liquidcrystal::write (uint8_t) E:\Arduino\hardware\arduino\cores\arduino/print.h:£ º NOTE: size_t print::write (constChar*)
Error:call of overloaded ' write (int) ' is ambiguous
Translation: The overload of write is ambiguous. The error is obviously caused by unclear parameters.
The latter means that the problem is between Liquidcrystal::write (uint8_t) and size_t print::write (const char*) two methods.
The original code is as follows:
1#include <LiquidCrystal.h>2 3#include <LiquidCrystal.h>4 5 /*6 liquidcrystal library-custom characters7 8 demonstrates how to add custom characters on an LCD display. 9 The Liquidcrystal Library works with all LCD displays that isTen compatible with the Hitachi HD44780 driver. There is many of One them out there, and you can usually tell them by the 16-pin interface. A - This sketch prints "I - to the LCD. the - The circuit: - * LCD RS pin to digital pin - * LCD Enable pin to digital pin one + * LCD D4 PIN to digital pin 5 - * LCD D5 PIN to digital pin 4 + * LCD D6 PIN to digital pin 3 A * LCD D7 PIN to digital pin 2 at * LCD r/w pin to ground - * 10K potentiometer: - * Ends to + ground - * WIPER to LCD VO pin (pin 3) - * 10K poterntiometer on pin A0 - in created21 Mar - by Tom Igoe to Based on Adafruit ' s example at + Https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde - the This example code was in the public domain. * Http://www.arduino.cc/en/Tutorial/LiquidCrystal $ Panax Notoginseng Also Useful: - http://icontexto.com/charactercreator/ the + */ A the //include the library code: +#include <LiquidCrystal.h> - $ //Initialize the library with the numbers of the interface pins $Liquidcrystal LCD ( A, One,5,4,3,2); - - //Make some custom characters: the byteheart[8] = { - 0b00000,Wuyi 0b01010, the 0b11111, - 0b11111, Wu 0b11111, - 0b01110, About 0b00100, $ 0b00000 - }; - - bytesmiley[8] = { A 0b00000, + 0b00000, the 0b01010, - 0b00000, $ 0b00000, the 0b10001, the 0b01110, the 0b00000 the }; - in bytefrownie[8] = { the 0b00000, the 0b00000, About 0b01010, the 0b00000, the 0b00000, the 0b00000, + 0b01110, - 0b10001 the };Bayi the bytearmsdown[8] = { the 0b00100, - 0b01010, - 0b00100, the 0b00100, the 0b01110, the 0b10101, the 0b00100, - 0b01010 the }; the the bytearmsup[8] = {94 0b00100, the 0b01010, the 0b00100, the 0b10101,98 0b01110, About 0b00100, - 0b00100,101 0b01010102 };103 voidSetup () {104 //Create a new character the Lcd.createchar (0, heart);//Method 2:0 instead of 5106 //Create a new character107Lcd.createchar (1, smiley);108 //Create a new character109Lcd.createchar (2, Frownie); the //Create a new character111Lcd.createchar (3, Armsdown); the //Create a new character113Lcd.createchar (4, Armsup); the the //set up the LCD ' s number of columns and rows: theLcd.begin ( -,2);117 //Print a message to the LCD.118Lcd.print ("I"); 119 lcd.write (0);//Method One: Change to Lcd.write (0.0);
//Method 2:0 changed to 5 -Lcd.print ("arduino!");121Lcd.write (1);122 123 }124 the voidLoop () {126 //read the potentiometer on A0:127 intSensorreading =Analogread (A0); - //map The result to 200-1000:129 intDelaytime = Map (sensorreading,0,1023, $, +); the //set the cursor to the bottom row, 5th position:131Lcd.setcursor (4,1); the //draw the little Man, arms down:133Lcd.write (3);134 delay (delaytime);135Lcd.setcursor (4,1);136 //draw him arms up:137Lcd.write (4);138 delay (delaytime);139}
The author through analysis, and a number of access to information. Found this to be a bug in the Liquidcrystal library. The reason is related to the definition of unit8_t in LiquidCrystal.h.
Solutions to <2>bug
So far, the author through their own research and multi-search data, found three possible ways, respectively, described as follows:
1. change Lcd.write (0) in line 119 of the sample program to Lcd.write (0.0), which has been marked with red in the experimental code above.
2. When constructing a custom character from the Lcd.createchar () function in the sample program, the encoding starts at 1 and discards the 0 encoding. the 105 and 119 rows of 0 were changed to 5. The same is already indicated in the experiment code above with the blue Word.
3. Modify the LiquidCrystal.h header file. Although this method is more troublesome, but modify thoroughly, once and for all! The sample code without modification, the actual application can also be directly from 0 to encode, strongly recommend this method!!! Here's how to modify it:
Open the LiquidCrystal.h header file and comment out the using print::write of line 85th.
As shown: (the author opens with notepad++):
An integrated approach to LCD1602 under Arduino (middle)--how to reduce the connection of 1602, Liquidcrystal Library, liquidcrystal the solution of the bug in the library