点亮1602LCD学习笔记
arduino吧
全部回复
仅看楼主
level 7
1602LCD网上买个,为了节省接线又买了块I2C板子直接用I2C接Mega2560的20、21管脚。
之后先新建一个程序下载查找地址;是0X3F. 注意并不是每个设备都一样。要看程序找到的地址。
#include <Wire.h>
void setup(){
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
}
void loop(){
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (address = 1; address < 127; address++ ){
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0){
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX);
Serial.println(" !");
nDevices++;
}else if (error == 4){
Serial.print("Unknow error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
2018年11月15日 06点11分 1
level 7
这样简单垓改网友的库代码基本就可以点亮了,在就深入学习里面的功能函数。
2018年11月15日 06点11分 2
level 7
通过串口发送字符给arduino显示
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
2018年11月15日 06点11分 3
level 7
用电脑串口给arduino的硬串口3发送数据,串口的2接Tx3 3接Rx3(也是14/15管脚)!但显示应该还需要转换!
2018年11月15日 08点11分 4
level 7
比如电脑端的串口软件发11 mega2560上就显示g
2018年11月15日 08点11分 5
level 7
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
Serial3.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial3.available()) {
// wait a bit for the entire message to arrive
delay(100);
lcd.print("Hello");
// clear the screen
lcd.clear();
// read all the available characters
while (Serial3.available() > 0) {
// display each character to the LCD
lcd.write(Serial3.read());
}
}
}
2018年11月15日 08点11分 6
level 7
该如下代码:用串口0,USB链接Mega2560,IDE的串口监视器发送数据,最后跟LCD显示一致。
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2);
int led=13;
void setup() {
// put your setup code here, to run once:
lcd.init(); // initialize the lcd
lcd.backlight();
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String inString="";
while(Serial.available()>0){
char inChar=Serial.read();
inString +=(char)inChar;
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
}
if(inString!=""){
Serial.print("Input String:");
Serial.println(inString);
lcd.print(inString);
}
2018年11月16日 02点11分 8
level 8
我记得好像小液晶也可以用u8g
2018年11月17日 00点11分 9
1