匿名
未登录
登录
丢石头百科
搜索
查看“实验三十二:LCD1602 IIC显示实验”的源代码
来自丢石头百科
名字空间
页面
讨论
更多
更多
页面选项
查看
查看源代码
历史
←
实验三十二:LCD1602 IIC显示实验
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
*[[Basic Experiment Kits For Arduino]] *[[Basic Experiment Kits For Raspberry Pi]] == 模块说明 == === 对比度调节 === *通过在VO引脚接入电位器进行对比度调节,其中: **对比度最大时显示: ***[[File:实验三十二:LCD1602 IIC显示实验_对比度1.png|400px]] **对比度最小时显示: ***[[File:实验三十二:LCD1602 IIC显示实验_对比度2.png|400px]] *当调节电位器至合适位置后,显示如下情况时: **[[File:实验三十二:LCD1602 IIC显示实验_对比度3.png|400px]] **检查接线是否松动 **检查初始化程序是否正确 === 背光选择 === *可通过A K引脚是否接入VCC和GND,来控制是否背光显示。 **引脚A接入VCC,引脚K接入GND,打开背光时 ***[[File:实验三十二:LCD1602 IIC显示实验_背光2.png|400px]] **引脚A断开VCC或者引脚K端开GND,关闭背光时 ***[[File:实验三十二:LCD1602 IIC显示实验_背光1.png|400px]] === 地址选择 === *设备地址可通过三位拨码开关A0、A1、A2进行修改,具体如下: *[[File:实验三十二:LCD1602 IIC显示实验.png|600px]] == Arduino == === 电路连接 === *[[File:实验三十二:LCD1602 IIC显示实验_接线1.png|400px]] === 扫描设备IIC地址 === ==== 实验现象 ==== * 串口打印PCF8574的地址 ==== 主要程序 ==== <pre> #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 } </pre> === LCD显示 === ==== 实验现象 ==== *LCD1602第一行显示LCD1602 iic Test *LCD1602第二行显示by Diustou ==== 主要程序 ==== <pre> //LingShun lab #include <Wire.h> #include <LiquidCrystal_I2C.h> //引用I2C库 LiquidCrystal_I2C lcd(0x20,16,2); //此处修改IIC地址 void setup() { lcd.init(); // 初始化LCD lcd.backlight(); //设置LCD背景等亮 } void loop() { lcd.setCursor(0,0); //设置显示指针 lcd.print("LCD1602 iic Test"); //输出字符到LCD1602上 lcd.setCursor(0,1); lcd.print(" by DIUSTOU"); delay(1000); } </pre> == 树莓派 == === 电路连接 === *[[File:实验三十二:LCD1602 IIC显示实验_接线2.png|600px]] === 程序运行 === ==== Python ==== * 安装gpiozero库 **可以使下面命令来安装该库 <pre> sudo apt update sudo apt install python3-gpiozero </pre> :*其它树莓派上的系统可以使下面命令来安装该库: <pre> sudo pip3 install gpiozero </pre> :*运行以下语句可以查看树莓派GPIO口定义 <pre> pinout </pre> *打开IIC接口 <pre> sudo raspi-config 选择Interfaces oOptions -> I2C -> “Would you like the ARM I2C interface to be enabled?”选择Yes -> “The ARM I2C interface isenabled” 选择OK -> 选择finish </pre> *关闭树莓派。断电情况下,根据提供的电路连接将对应模块接入电路,启动树莓派 *查询LCD1602的地址 <pre> ls /dev/i2c-* sudo i2cdetect -y 1 </pre> *下载树莓派参考例程,将文件解压后拷贝放在用户名目录下,运行 <pre> cd raspberrypi/32/python_gpiozero python Display.py </pre> *此时可看见树莓派在正确运行程序,若想退出,按ctrl+C即可 *更多指令请查看[https://gpiozero.readthedocs.io/en/latest/installing.html gpiozero文档] == 例程下载 == *[[:File:Basic Experiment Kits For Arduino.zip|Arduino例程]] * [[:File:Basic Experiment Kits For Raspberry Pi.zip|树莓派5例程 python]] == 相关例程 == {{Arduino and Raspberry Pi Case}}
该页面使用的模板:
模板:Arduino and Raspberry Pi Case
(
查看源代码
)
模板:Study
(
查看源代码
)
返回至
实验三十二:LCD1602 IIC显示实验
。
导航
导航
首页
最近更改
随机页面
MediaWiki帮助
首页
首页
树莓派
主机
配件包
外壳
键鼠
电源
扩展板
显示屏
墨水屏
摄像模块
通信模块
继电器
电机驱动板
游戏机
产品分类
树莓派
Arduino
micro:bit
STM32
Espressif
WiFi模块
蓝牙模块
无线模块
LoRa模块
4G模块
GSM
GPRS
以太网
导航模块
北斗卫星
GPS
LCD
墨水屏
OLED
摄像头
USB模块
串口模块
RS232
RS485
CAN
传感器
温度模块
湿度模块
气压模块
继电器
电机模块
指纹模块
电平转换
音频模块
编程器
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志