1.开发板
Arduino nano(168p)
2.屏幕
lcd1602,如果不加转接板的话会占用大量io,而且需要加可调电阻进行对比度调节。
3.转接板
这里使用的是pcf8574T转接板,通过i2c协议只占用两个io口,并且集成了可调电阻,使用起来非常方便。
4.库和代码
在Arduino下载lcd_i2c,注意作者,别下错了。
代码是示例里的,可以自行修改。
#include <LCD_I2C.h>
LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change according
void setup()
{
lcd.begin(); // If you are using more I2C devices using the Wire library use lcd.begin(false)
// this stop the library(LCD_I2C) from calling Wire.begin()
lcd.backlight();
}
void loop()
{
lcd.print(" Hello"); // You can make spaces using well... spaces
lcd.setCursor(5, 1); // Or setting the cursor in the desired position.
lcd.print("World!");
delay(500);
// Flashing the backlight
for (int i = 0; i < 5; ++i)
{
lcd.backlight();
delay(50);
lcd.noBacklight();
delay(50);
}
lcd.backlight();
lcd.clear();
delay(500);
}
5.连线
开发板 | 屏幕 |
A4 | SDA |
A5 | SCL |
GND | GDN |
3.3-5V | VCC |