- 浏览: 2144330 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (1240)
- mac/IOS (287)
- flutter (1)
- J2EE (115)
- android基础知识 (582)
- android中级知识 (55)
- android组件(Widget)开发 (18)
- android 错误 (21)
- javascript (18)
- linux (70)
- 树莓派 (18)
- gwt/gxt (1)
- 工具(IDE)/包(jar) (18)
- web前端 (17)
- java 算法 (8)
- 其它 (5)
- chrome (7)
- 数据库 (8)
- 经济/金融 (0)
- english (2)
- HTML5 (7)
- 网络安全 (14)
- 设计欣赏/设计窗 (8)
- 汇编/C (8)
- 工具类 (4)
- 游戏 (5)
- 开发频道 (5)
- Android OpenGL (1)
- 科学 (4)
- 运维 (0)
- 好东西 (6)
- 美食 (1)
最新评论
-
liangzai_cool:
请教一下,文中,shell、C、Python三种方式控制led ...
树莓派 - MAX7219 -
jiazimo:
...
Kafka源码分析-序列5 -Producer -RecordAccumulator队列分析 -
hp321:
Windows该命令是不是需要安装什么软件才可以?我试过不行( ...
ImageIO读jpg的时候出现javax.imageio.IIOException: Unsupported Image Type -
hp321:
Chenzh_758 写道其实直接用一下代码就可以解决了:JP ...
ImageIO读jpg的时候出现javax.imageio.IIOException: Unsupported Image Type -
huanghonhpeng:
大哥你真强什么都会,研究研究。。。。小弟在这里学到了很多知识。 ...
android 浏览器
树莓派 1602A显示屏
下面代码本人测试过没有问题,开始运行完屏幕上什么也没有显示出来,后来调整了下电位器可以了,所以大家如果按着下面的做出来之后运行什么也没有显示的话,记得调整下电位器
LCD1602接线说明
VSS,接地
VDD,接5V电源
VO,液晶对比度调节,接电位器中间的引脚,电位器两边的引脚分别接5V和接地。
RS,寄存器选择,接GPIO14
RW,读写选择,接地,表示写模式
EN,使能信号,接GPIO15
D0,数据位0,4位工作模式下不用,不接
D1,数据位1,4位工作模式下不用,不接
D2,数据位2,4位工作模式下不用,不接
D3,数据位3,4位工作模式下不用,不接
D4,数据位4,接GPIO17
D5,数据位5,接GPIO18
D6,数据位6,接GPIO27
D7,数据位7,接GPIO22
A,液晶屏背光+,接5V
K,液晶屏背光-,接地
一共就两个文件
lcd1602.py
1602.py
将以上两个文件保存在同一个目录下,运行1602.py即可打印信息到LCD上。
自己看看代码就会用了
下面代码本人测试过没有问题,开始运行完屏幕上什么也没有显示出来,后来调整了下电位器可以了,所以大家如果按着下面的做出来之后运行什么也没有显示的话,记得调整下电位器
LCD1602接线说明
VSS,接地
VDD,接5V电源
VO,液晶对比度调节,接电位器中间的引脚,电位器两边的引脚分别接5V和接地。
RS,寄存器选择,接GPIO14
RW,读写选择,接地,表示写模式
EN,使能信号,接GPIO15
D0,数据位0,4位工作模式下不用,不接
D1,数据位1,4位工作模式下不用,不接
D2,数据位2,4位工作模式下不用,不接
D3,数据位3,4位工作模式下不用,不接
D4,数据位4,接GPIO17
D5,数据位5,接GPIO18
D6,数据位6,接GPIO27
D7,数据位7,接GPIO22
A,液晶屏背光+,接5V
K,液晶屏背光-,接地
一共就两个文件
lcd1602.py
#!/usr/bin/python # # based on code from lrvick and LiquidCrystal # lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py # LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp # from time import sleep class lcd1602: # commands LCD_CLEARDISPLAY = 0x01 LCD_RETURNHOME = 0x02 LCD_ENTRYMODESET = 0x04 LCD_DISPLAYCONTROL = 0x08 LCD_CURSORSHIFT = 0x10 LCD_FUNCTIONSET = 0x20 LCD_SETCGRAMADDR = 0x40 LCD_SETDDRAMADDR = 0x80 # flags for display entry mode LCD_ENTRYRIGHT = 0x00 LCD_ENTRYLEFT = 0x02 LCD_ENTRYSHIFTINCREMENT = 0x01 LCD_ENTRYSHIFTDECREMENT = 0x00 # flags for display on/off control LCD_DISPLAYON = 0x04 LCD_DISPLAYOFF = 0x00 LCD_CURSORON = 0x02 LCD_CURSOROFF = 0x00 LCD_BLINKON = 0x01 LCD_BLINKOFF = 0x00 # flags for display/cursor shift LCD_DISPLAYMOVE = 0x08 LCD_CURSORMOVE = 0x00 # flags for display/cursor shift LCD_DISPLAYMOVE = 0x08 LCD_CURSORMOVE = 0x00 LCD_MOVERIGHT = 0x04 LCD_MOVELEFT = 0x00 # flags for function set LCD_8BITMODE = 0x10 LCD_4BITMODE = 0x00 LCD_2LINE = 0x08 LCD_1LINE = 0x00 LCD_5x10DOTS = 0x04 LCD_5x8DOTS = 0x00 def __init__(self, pin_rs=14, pin_e=15, pins_db=[17, 18, 27, 22], GPIO = None): # Emulate the old behavior of using RPi.GPIO if we haven't been given # an explicit GPIO interface to use if not GPIO: import RPi.GPIO as GPIO self.GPIO = GPIO self.pin_rs = pin_rs self.pin_e = pin_e self.pins_db = pins_db self.GPIO.setmode(GPIO.BCM) self.GPIO.setwarnings(False) self.GPIO.setup(self.pin_e, GPIO.OUT) self.GPIO.setup(self.pin_rs, GPIO.OUT) for pin in self.pins_db: self.GPIO.setup(pin, GPIO.OUT) self.write4bits(0x33) # initialization self.write4bits(0x32) # initialization self.write4bits(0x28) # 2 line 5x7 matrix self.write4bits(0x0C) # turn cursor off 0x0E to enable cursor self.write4bits(0x06) # shift cursor right self.displaycontrol = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF self.displayfunction = self.LCD_4BITMODE | self.LCD_1LINE | self.LCD_5x8DOTS self.displayfunction |= self.LCD_2LINE """ Initialize to default text direction (for romance languages) """ self.displaymode = self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) # set the entry mode self.clear() def begin(self, cols, lines): if (lines > 1): self.numlines = lines self.displayfunction |= self.LCD_2LINE self.currline = 0 def home(self): self.write4bits(self.LCD_RETURNHOME) # set cursor position to zero self.delayMicroseconds(3000) # this command takes a long time! def clear(self): self.write4bits(self.LCD_CLEARDISPLAY) # command to clear display self.delayMicroseconds(3000) # 3000 microsecond sleep, clearing the display takes a long time def setCursor(self, col, row): self.row_offsets = [ 0x00, 0x40, 0x14, 0x54 ] if ( row > self.numlines ): row = self.numlines - 1 # we count rows starting w/0 self.write4bits(self.LCD_SETDDRAMADDR | (col + self.row_offsets[row])) def noDisplay(self): """ Turn the display off (quickly) """ self.displaycontrol &= ~self.LCD_DISPLAYON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def display(self): """ Turn the display on (quickly) """ self.displaycontrol |= self.LCD_DISPLAYON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def noCursor(self): """ Turns the underline cursor on/off """ self.displaycontrol &= ~self.LCD_CURSORON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def cursor(self): """ Cursor On """ self.displaycontrol |= self.LCD_CURSORON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def noBlink(self): """ Turn on and off the blinking cursor """ self.displaycontrol &= ~self.LCD_BLINKON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def noBlink(self): """ Turn on and off the blinking cursor """ self.displaycontrol &= ~self.LCD_BLINKON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def DisplayLeft(self): """ These commands scroll the display without changing the RAM """ self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVELEFT) def scrollDisplayRight(self): """ These commands scroll the display without changing the RAM """ self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVERIGHT); def leftToRight(self): """ This is for text that flows Left to Right """ self.displaymode |= self.LCD_ENTRYLEFT self.write4bits(self.LCD_ENTRYMODESET | self.displaymode); def rightToLeft(self): """ This is for text that flows Right to Left """ self.displaymode &= ~self.LCD_ENTRYLEFT self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) def autoscroll(self): """ This will 'right justify' text from the cursor """ self.displaymode |= self.LCD_ENTRYSHIFTINCREMENT self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) def noAutoscroll(self): """ This will 'left justify' text from the cursor """ self.displaymode &= ~self.LCD_ENTRYSHIFTINCREMENT self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) def write4bits(self, bits, char_mode=False): """ Send command to LCD """ self.delayMicroseconds(1000) # 1000 microsecond sleep bits=bin(bits)[2:].zfill(8) self.GPIO.output(self.pin_rs, char_mode) for pin in self.pins_db: self.GPIO.output(pin, False) for i in range(4): if bits[i] == "1": self.GPIO.output(self.pins_db[::-1][i], True) self.pulseEnable() for pin in self.pins_db: self.GPIO.output(pin, False) for i in range(4,8): if bits[i] == "1": self.GPIO.output(self.pins_db[::-1][i-4], True) self.pulseEnable() def delayMicroseconds(self, microseconds): seconds = microseconds / float(1000000) # divide microseconds by 1 million for seconds sleep(seconds) def pulseEnable(self): self.GPIO.output(self.pin_e, False) self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns self.GPIO.output(self.pin_e, True) self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns self.GPIO.output(self.pin_e, False) self.delayMicroseconds(1) # commands need > 37us to settle def message(self, text): """ Send string to LCD. Newline wraps to second line""" for char in text: if char == '\n': self.write4bits(0xC0) # next line else: self.write4bits(ord(char),True) if __name__ == '__main__': lcd = lcd1602() lcd.clear() lcd.message("hello world!")
1602.py
#!/usr/bin/python from lcd1602 import * from datetime import * import commands def get_cpu_temp(): tmp = open('/sys/class/thermal/thermal_zone0/temp') cpu = tmp.read() tmp.close() return '{:.2f}'.format( float(cpu)/1000 ) + ' C' def get_gpu_temp(): tmp = commands.getoutput('vcgencmd measure_temp|awk -F= \'{print $2}\'').replace('\'C','') gpu = float(tmp) return '{:.2f}'.format( gpu ) + ' C' def get_time_now(): return datetime.now().strftime(' %H:%M:%S\n %Y-%m-%d') def get_ip_info(): return commands.getoutput('ifconfig wlan0|grep inet|awk -Faddr: \'{print $2}\'|awk \'{print $1}\'') def get_mem_info(): total= commands.getoutput('free -m|grep Mem:|awk \'{print $2}\'') free = commands.getoutput('free -m|grep cache:|awk \'{print $4}\'') return 'MEM:\n ' + free +' / '+ total +' M' lcd = lcd1602() lcd.clear() if __name__ == '__main__': while(1): lcd.clear() lcd.message( get_ip_info() ) sleep(5) lcd.clear() lcd.message( get_time_now() ) sleep(5) lcd.clear() lcd.message( get_mem_info() ) sleep(5) lcd.clear() lcd.message( 'CPU: ' + get_cpu_temp()+'\n' ) lcd.message( 'GPU: ' + get_gpu_temp() ) sleep(5)
将以上两个文件保存在同一个目录下,运行1602.py即可打印信息到LCD上。
自己看看代码就会用了
发表评论
-
树莓派加无线网卡配置WIFI热点的方法
2018-09-25 00:04 1606配置网络 安装 dnsmasq ... -
树莓派u盘格式化后放进系统后不识别
2018-09-24 19:38 881树莓派u盘格式化后放进系统后不识别 diskgenius磁盘 ... -
一些常用的命令
2018-04-25 22:57 409#获得所有设备的功能,如带宽信息(2.4GHz,和5GHz), ... -
树莓派3B创建WiFi热点
2018-04-01 11:30 7530创建WiFi热点使用的GitHub上一个开源项目: http ... -
树莓派 - L298N模块 驱动直流电机
2018-03-18 16:45 2004单片机或树莓派一般使用 L298n 模块来驱动电机 。L298 ... -
树莓派驱动LCD12864显示屏
2018-03-11 16:49 1237适用于ST7920控制器的LCD12864显示屏,使用wiri ... -
树莓派 - MAX7219(数字倒计时) - python
2018-03-04 19:04 1160写了个倒计时 #!/usr/bin/env python ... -
树莓派 - MAX7219
2018-03-04 12:44 17241.基础:认识MAX7219 拿到MAX7219驱动的LED ... -
树莓派系列教程:红外遥控
2018-02-25 14:11 2742网上淘到了一个红外接 ... -
树莓派手动指定静态IP和DNS
2018-02-16 11:58 1260在把玩树莓派的过程中 ... -
树莓派 c获取树莓派CPU温度
2018-02-14 14:23 882C语言文件IO操作 新建一个名为cpu-temp.c文 ... -
树莓派GPIO控制--C语言篇
2018-02-14 13:58 1607一. 常用开源工程简介 树莓派内核中已经编译自带了gpio的 ... -
树莓派 远程看鱼眼摄像头
2018-02-12 21:12 1014mac电脑上最好下载vlc视频软件 有两种方式, 第一种: ... -
如何安装树莓派鱼眼摄像头模块
2018-02-12 13:58 1263安装树莓派摄像头模块 视频地址:http://www.wav ... -
树莓派使用RFID-RC522A读卡器对IC卡进行读写(通过 python)
2018-02-10 21:58 22341. 配置树莓派 首先需要运行raspi-config,开启 ... -
树莓派 - 点亮LED
2017-12-31 14:14 771先按照下面这个图 连线:(对于LED,负极的那面内部的铁片很大 ... -
树莓派新手入门教程 - node下使用gpio
2017-12-24 12:43 1046安装 Node 为了运行 Node 脚本,树莓派必须安装 N ...
相关推荐
lcd1602A显示屏资料,包括时序图等信息,芯片的接口定义等
对1602A的相关引脚介绍说明!及连接电路时需要的注意。 且附有单片机与之相关联的程序设计。
单片机c51驱动1602A液晶屏的驱动实验(C语言)
STM32通过I2C总线驱动1602显示屏以及使用旋转编码器实现数值增减
SMC1602A液晶显示模块DATASHEET使用说明书 SMC1602A 液晶显示模块的概述: SMC1602A 标准字符点阵型液晶显示模块(LCM),采用点阵型液晶显示器(LCD),可显示 16 个字符 X2 行西文字符, 字符尺寸为 2.95X4.35(WXH)mm...
单片机c51驱动1602A液晶屏的驱动实验
本 文 和 设 计 代 码 由 FPGA 爱 好 者 小 梅 哥 编 写,未 经 作 者 许 可,本 文 仅 允 许 网 络 论 坛 复 制 转 载,且 转 载 时 请 标明原作者。【工程源码】 LCD1602数据手册
中文的,还不错哦1602 PDF 液晶的PDF
STM32F103C8T6 读取DS18B20温度,以四线制驱动1602A显示。显示位数根据温度动态长度。HAL库编写
为树莓派连接LCD1602A液晶屏、蜂鸣器及引出GPIO、调试口等。新手学习制作,肯定有不少缺陷,仅供参考。
在树莓派上,通过gpio链接1602a 16*2 lcd。并显示字符。
详细的C语言描述的对1602A液晶显示模块的程序,加以详尽的注释
用AT89S51单片机实现的万年历,内容详细充实 包括1602液晶显示 和C语言程序
LCD1602A液晶显示芯片,资料讲述详细,有管脚图,外形尺寸,命令字等。
基于STM32F103(C51)芯片的液晶显示屏(LCD1602)资料与源码。亲测在战舰版、精英版、Mini版的正点原子上使用,使LCD1602达到可以和LCD屏一样,可以在任意有效坐标显示字。 文件列表:LCD(LCD1602A)原理图及说明书;...
液晶1602a的实验程序,欢迎大家来看看。喜欢的可以下载啊。
1602A液晶屏的驱动程序(C语言) C语言源程序 ** 1602A液晶屏驱动程序
用超声波模块测距,通过LCD1602A液晶显示屏显示距离
LCD1602A说明书 LCD1602A说明书 LCD1602A说明书
这里主要介绍了RT-C1602A液晶显示模块的外形尺寸,方框图,电源供应和引脚分配等。