LCD显示屏与Arduino连接可以有两种方式:
直接与Arduino相连的好处是不用现另外购买转接板,但这样造成的后果就是要大量占用Arduino的IO口。如果你的项目外接的传感器不多,那还好,但如果你需要外接很多个传感器或者其他配件,那你的IO口就会告急了~
LCD直接与Arduino相连的接线图
LCD | Arduino | |
---|---|---|
RS | -> | 12 |
E | -> | 11 |
D4 | -> | 5 |
D5 | -> | 4 |
D6 | -> | 3 |
D7 | -> | 2 |
VCC | -> | 5V |
R/W | -> | GND |
GND | -> | GND |
LCD | 旋转变阻器 | |
---|---|---|
VCC | -> | 左边引脚 |
Vo | -> | 中间引脚 |
R/W | -> | 右边引脚 |
GND | -> | 右边引脚 |
参考文献// include the library code: #include 《LiquidCrystal.h》 // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); } void loop() { // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis()/1000); }
https://www.arduino.cc/en/Reference/LiquidCrystal
通过此种方式,可以大大节省Arduino的IO口,前提是你还得购买一块PCF8574T转接板。
首先,把转接板焊接到LCD显示屏上(方向如上图)
PCF8574T | Arduino | |
---|---|---|
GND | -> | GND |
VCC | -> | 5V |
SDA | -> | A4 |
SCL | -> | A5 |
如果你的A4,A5口已经被占用,那么你还可以接到Arduino最上面的两个没有标文字的IO口,即D0-D13那一排最上面的那两个口
将以下代码拷贝到Arduino IDE,并执行。然后选择工具->串口监视器,把右下角的波特率改为115200,即可读出I2C地址。
// I2C Scanner
#include 《Wire.h》
void setup() {
Serial.begin (115200); // Leonardo: wait for serial port to connect
while (!Serial) { }
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i 《 120; i++) {
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0) {
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
到这里下载最新的New LiquidCrystal,手动添加到你的 Arduino IDE中。(ps:记得修改你的I2C地址,把LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7);的0x3F改为你的真实地址)
参考文献/* Demonstration sketch for PCF8574T I2C LCD Backpack Uses library from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads GNU General Public License, version 3 (GPL-3.0) */ #include 《Wire.h》 #include 《LCD.h》 #include 《LiquidCrystal_I2C.h》 LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified backpack void setup() { // activate LCD module lcd.begin (16,2); // for 16 x 2 LCD module cd.setBacklightPin(3,POSITIVE); lcd.setBacklight(HIGH); } void loop() { lcd.home (); // set cursor to 0,0 lcd.print(" tronixlabs.com"); lcd.setCursor (0,1); // go to start of 2nd line lcd.print(millis()); delay(1000); lcd.setBacklight(LOW); // Backlight off delay(250); lcd.setBacklight(HIGH); // Backlight on delay(1000); }
http://www.instructables.com/id/Using-PCF8574-backpacks-with-LCD-modules-and-Ardui/?ALLSTEPS
链接:https://www.jianshu.com/p/eee98fb5e68f
PWM,英文名Pulse Width Modulation,是脉冲宽度调制缩写,它是通过调节占空比的变化来调节信号、能量等的变化。