LCD 1602A

LCD 1602A1.直接与Arduino相连2.通过转接板利用I2C的方式与Arduino相连1.直接与Arduino相连直接与Arduino相连的好处是不用现另外购买转接板,但这样造成的后果就是要大量占用Arduino的IO口。如果你的项目外接的传感器不多,那还好,但如果你需要外接很多个传感器或者其他配件,那你的IO口就会告急了~所需材料1xArduinoUNO1xLCD1…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

1.直接与Arduino相连

2.通过转接板利用I2C的方式与Arduino相连

1. 直接与Arduino相连

直接与Arduino相连的好处是不用现另外购买转接板,但这样造成的后果就是要大量占用Arduino的IO口。如果你的项目外接的传感器不多,那还好,但如果你需要外接很多个传感器或者其他配件,那你的IO口就会告急了~

所需材料

  • 1x Arduino UNO
  • 1x LCD 16×2
  • 1x 10KΩ旋转变阻器
  • 1x 面包板

接线示意图

LCD 1602A

 

 
LCD 1602A

加载库文件

  • 在Arduino IDE 1.6.2 或者以上版本中, 项目->加载库->管理库中搜索LiquidCrystal,然后安装即可。

示例代码

// 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

 

2.通过PCF8574T转接板与Arduino相连

通过此种方式,可以大大节省Arduino的IO口,前提是你还得购买一块PCF8574T转接板。

LCD 1602A

 


所需要材料

  • 1x Arduino UNO
  • 1x LCD 16×2
  • 1x PCF8574T转接板
  • 电烙铁、焊锡、松香等

接线

首先,把转接板焊接到LCD显示屏上(方向如上图)

LCD 1602A

  • SCL -> 最上面的口
  • SDA -> 第二个口

扫描I2C地址

将以下代码拷贝到Arduino IDE,并执行。然后选择工具->串口监视器,把右下角的波特率改为115200,即可读出I2C地址,如下图。

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
#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() {}

LCD 1602A

加载库文件

这里下载最新的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 
  lcd.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

本文摘自:http://www.jianshu.com/p/eee98fb5e68f

在这里感谢作者的贡献。

 

转载于:https://www.cnblogs.com/SATinnovation/p/8047240.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/190632.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • android 杀进程 方法,android中杀死进程的方法

    android 杀进程 方法,android中杀死进程的方法第一种方法:这个方法只能自杀,不能杀死其他进程~/*****************************************************杀死进程的第一种方法******************************…

  • SQL Server中的sp_executesql系统存储过程

    SQL Server中的sp_executesql系统存储过程sp_executesql语法 sp_executesql[@stmt=]stmt[    {,[@params=]N@parameter_name  data_type[,…n]}    {,[@param1=]value1[,…n]}] 参数[@stmt=]stmt 包含 Transact-SQL 语

  • 情感词典构建_文本情感分析的意义

    情感词典构建_文本情感分析的意义这是4个月前做的。受当时的知识水平的限制,还没有接触到机器学习和相关理论,记录一下作为以后备查。当然,如果你想看源码和资料,点击我。从结项到现在,博主一直在使用机器学习并结合相关论文进行情感极性分析(源码点我),效果远远好于本篇代码的效果。但是,本篇的数据处理和特征选择还是很有意义的,特此记录。摘要        当今社会媒体的发展导致了金融舆论数据的爆炸式增长。因此,针对金融舆论数据的情

  • java xml格式化_使用java将xml格式化

    java xml格式化_使用java将xml格式化将生成的xml用ie浏览器打开,就可以见到漂亮的缩进的xmlschema.但是每次都这样也不方便。在java程序中,直接使用jdk的javax.xml.transform.Transformer即可完成。而且如果有节点未被匹配,也能通过错误提示及时发现。先贴代码如下:importjava.io.File;importjava.io.StringReader;importjavax.xml….

  • Python数据分析的过程记录(二)

    Python数据分析的过程记录(二)Python数据分析的过程记录(二)文章目录Python数据分析的过程记录(二)一、需求介绍二、需求分析三、代码实现一、需求介绍二、需求分析三、代码实现

  • opencv中的merge函数

    opencv中的merge函数该函数用来合并通道原型voidmerge(constMat*mv,size_tcount,OutputArraydst);第一个参数是图像矩阵数组,第二个参数是需要合并矩阵的个数,第三个参数是输出voidmerge(constvector&mv,OutputArraydst);第一个参数是图像矩阵向量容器,第二个参数是输出,这种方法无需说

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号