文档章节

[翻译中] 树莓派安装Adafruit 16x2 LCD屏幕和键盘

八宝粥
 八宝粥
发布于 2013/07/25 20:15
字数 2571
阅读 1661
收藏 4

概述

 

这是新的Adafruit扩展板套件, 可以轻松连接16X2 LCD显示屏. 我们的商店里有不少不错的LCD屏幕, 比如经典的蓝白款和其他RGB共阴极RGB共阳极屏幕. 不过这些LCD屏幕需要占用不少引脚, 6个控制LCD, 3个控制RGB背光. 这几乎把树莓派上可用的GPIO引脚都占满了! 

 

为了让大家能在项目中更简单的使用LCD屏幕, 我们设计开发了这块扩展板, 支持16x2 LCD屏幕, 3个背光引脚和5个按键引脚, 却只占用树莓派上的两个I2C引脚! 无需布线就能添加显示屏的绝佳方案. 

当你想搞个有交互接口的集成项目时来块这板子是不二选择. 四方向键加上选择键足以满足基本操作了. 

这板子在树莓派 - Model A和B上都可用.

需要的零件

检查下套件中的零件是否齐全. 要是我们发错了请联系support@adafruit.com进行替换!
ID1115parts_LRG.jpg

1) 电阻

套件中一共有三个电阻. 板子上标记RED和BLUE的地方需要用1/4W 5% 220欧姆的电阻 (红, 红, 棕, 金). 标记GREEN的需要用1/4W 5% 330欧姆的电阻 (橙, 橙, 棕, 金).

2) 电位计

一个10k微调电位器.

3) 按键

五个6mm触碰式按键.

4) i2c口扩展芯片

There is one of these MCP23017 i2c (16 input/output) port expander chips in the kit. This is how we are able to only use 2 R-Pi pins to run the entire LCD and buttons.  Click here for more info on this chip. 

5) Male Header Pins

There is one strip of 36 male header pins in the kit. These will be used to attach the LCD to the PCB.

6) Printed Circuit Board

There will be one PCB in the kit as shown above.

7) Raspberry Pi Plate Header

There will be one extra-tall 26 pin female header for plugging into the Pi

8) Bumper

There will be one rubber bumper as shown above

额外

LCD屏不包括在套件内, 请自行购买.
162rgblcdnegpurple.jpg
You can also use 16x2 LCDs or even OLEDs that are the same size that do not have an RGB backlight, or have no backlight at all.

安装

  • ID1115parts_LRG.jpg

Check the kit against the to verify you have all the parts necessary


We recently adjusted the kit so the buttons are on the right side instead of the left. The parts list is otherwise the same, its just a little more stable than before

  • 330place.jpg

Put the printed circuit board into a vise or board holder, heat up your soldering iron and make sure you're ready to go! 

We'll start with the first resistor GREEN - which has orange, orange, brown, gold bands on it. This resistor acts as the backlight control resistor for the green backlight pin.

Bend the resistor into a 'staple' and slide it into the slot marked GREEN on the PCB. Resistors do not have a direction so you can put it in 'either way' and it'll work find.



  • 330solder.jpg

  • 330solder.jpg330solder2.jpg330soldered.jpg

Bend the 'legs' of the resistor out so it sits flat against the PCB and flip it over.

This way the resistor won't fall out while soldering.

With your soldering iron heated up and ready, solder in both leads of the resistor. To do this, heat up the round ring pad and the wire lead at the same time for 2 or 3 seconds, then dip the end of the solder into the heated joint to melt it in.

Then remove the solder and the soldering iron.



  • 330clip.jpg

  • 330clip.jpg330clipped.jpg

Once the soldering is complete, we can clean up by clipping the leads of the resistor. This keeps them from shorting to something else. Use diagonal or flush cutters to clip the wires right above where the solder joint ends.
  • resplace.jpg

  • resplace.jpgresflip.jpg

Since you did so great with the first resistor, we'll place all of the rest now at the same time. 

The two 220 ohm resistors RED and BLUE - named because they are the backlight series resistors for the RGB backlights on the LCDs. These resistors are colored Red Red Brown Gold.

  • ressolder.jpg

  • ressolder.jpgressolder2.jpg

Solder the resistors just like you did with the first one.
  • resclip.jpg

  • resclip.jpgresclipped.jpg

Clip all the leads.
  • buttonplace.jpg

Next up we will place the buttons. These buttons are useful to send a signal to the Pi (say if you have a basic menu system). We have a 4-way 'direction pad' for up/down/left/right input and a button to the right called SELECT. These 5 buttons should be able to make 'talking' back to your project easy. These are connected to the I2C port expander chip so they require no extra pins on the Pi, our library does the work of reading whether they are pressed.

All the buttons are the same, and they should snap nicely into place. Press down onto each button until it snaps in and sits flat against the PCB.


We recently adjusted the kit so the buttons are on the RIGHT side instead of the left. The buttons snap in the same but they're on the right



  • butsolder.jpg

  • butsolder.jpgbutsolder2.jpgbutsolder3.jpg

Flip over the PCB and check that all the legs for the buttons are sticking out.

Solder each leg, taking care not to accidentally 'short' two button legs together. The ones for the directional pads are very close!
  • contrastplace.jpg

Next, place the 10K potentiometer (the orange-faced thing with three legs) into the spot above the RESET button. It will only fit one way. This is the contrast potentiometer which will adjust how dark the characters appear. All displays are slightly different so you'll adjust this once the display is soldered in.

The kit may come with two potentiometers - a big blue one for breadboarding the LCD and a smaller orange one for the shield kit. You can throw away or recycle the blue one, use only the orange one here!

We recently adjusted the kit to have the potentiometer in the center rather than the right, goes in the same way, just in the middle!

  • contrastsolder.jpg

Flip over the PCB and solder in the three legs of the potentiometer
  • chipplace.jpg

We're nearly done! Now we will place the I2C port expander chip. Double check that it has theMCP23017-E/SP marking on it. This is a 16-pin expander chip, that uses the i2c bus. That means you can send it commands using the i2c pins on an Pi and control 16 more digital pins! 5 of those pins go to the buttons, 6 go to the LCD control and 3 are used for the backlight (the remaining 2 are unused).

Unlike buttons or resistors, chips do have a direction and the must be put in the right way! First, use a flat table to carefully bend the legs of the chip so they are parallel. Then slip it into the silkscreened outline so that the notch at the end of the chip is on the right. Click the image to the left to make absolutely sure you've got it in the right way. Once you are sure, press the chip into place

We recently adjusted the kit so the chip is more to the left, its the same alignment, just shifted over

  • chipsolder.jpg

  • chipsolder.jpgchipsolder2.jpgchipdone.jpg

Flip over the PCB and solder in the 28 pins of the port expander.
  • stacky.jpg

Next we will attach the header, there is a standard 'extra tall' header included in the kit. However, if you want to attach a cobbler or GertBoard, etc to the plate, you may want to opt for one of our stacking headers, they're extra long so you can plug in an IDC cable on top!
  • bumper.jpg

  • bumper.jpgbumper.jpg

Before we solder in the header, remove the bumper from the backing and attach it on the underneath so its right over the Ethernet jack when the PCB is plugged in.

On kits where the buttons are on the left, put it right below the contrast pot, as shown. This will keep the pot from touching the Ethernet jack.

On kits where the buttons are on the right, put it right next to the buttons (it shouldnt overlap any button legs) sitting flat
  • headerplace.jpg

Place the 2x13 header onto your Pi, and slide the plate on top, it should fit perfectly.

  • headersolder.jpg

  • headersolder.jpgheadersolder2.jpgheadersoldered.jpg

Now we will solder all 26 pins for the plate - this will send power and data between the two boards and also provide a mechanical stability. You may need to hold the plate down with tape to get it sitting flat against the Pi. 

Solder in one pin, we suggest the top right, then check if the plate is sitting flat. If not, heat up the joint with one hand while stabilizing with the other until its right. 

Then solder the other 25 pins

  • headerplace.jpg

Finally, we place the LCD. 
Break off a piece of 18 or 16 pin header from the stick in the kit. If you have an RGB display, you'll need 18, for a blue&white you'll need 16

Place the header into the remaining slot with the long ends of the pins sticking UP. If you have only 16 pins, leave the two rightmost pads empty 
  • cdplace.jpg

  • cdplace.jpglcdsolder.jpglcdsolder2.jpglcdsoldered.jpg

Slide the LCD over the header so that it is perfectly centered over the four holes and the silkscreen.

The LCD should 'snap' in against the buttons

Solder all the pins!
  • lcdflip.jpg

  • lcdflip.jpglcdsolder.jpg

Flip over the assembly, carefully. Then solder in the 16 or 18 pins of header
  • ID1110_LRG.jpg

That's it! You're done soldering, now you just have to run the code in the Usage section next.

使用

The backlights will not turn on until you have the code running so don't be alarmed if nothing lights up when you plug in the plate! If you have a 'positive' style LCD, you may see some squares on the first line, that's normal 

设置I2C

For a more basic introduction to setting up I2C on your Pi then you may wish to take a diversion to this Adafruit tutorial:   http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

If you're using Occidentalis, you can skip this next step, but for Raspbian users, edit /etc/modules ( sudo nano /etc/modules) and add: 

i2c-bcm2708  
i2c-dev

to the end of the file. Then save and reboot to enable the hardware I2C driver.


Before you can get started with I2C on the Pi, you'll need to run through a couple quick steps from the console.  Just enter the following commands to add SMBus support (which includes I2C) to Python:

sudo apt-get install python-smbus 
sudo apt-get install i2c-tools

i2c-tools isn't strictly required, but it's a useful package since you can use it to scan for any I2C or SMBus devices connected to your board.  If you know something is connected, but you don't know it's 7-bit I2C address, this library has a great little tool to help you find it:

sudo i2cdetect -y 0 (if you are using a version 1 Raspberry Pi) 
sudo i2cdetect -y 1 (if you are using a version 2 Raspberry Pi)

i2cdetect.gif

This will search /dev/i2c-0 or /dev/i2c-1 for all address, and if an Adafruit LCD Plate is connected, it should show up at  0x20

Once both of these packages have been installed, you have everything you need to get started accessing I2C and SMBus devices in Python.

 

python示例代码

The LCD Pi Plate Python code for Pi is available on Github at  https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code

The easiest way to get the code onto your Pi is to hook up an Ethernet cable, and clone it directly using 'git', which is installed by default on most distros.  Simply run the following commands from an appropriate location (ex. "/home/pi"):

sudo apt-get install git 
git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git 
cd Adafruit-Raspberry-Pi-Python-Code 
cd Adafruit_CharLCDPlate

You will also need to install RPi.GPIO, the python library for Pi that allows easy GPIO access. On Raspbian, just run  

sudo apt-get install python- dev 
sudo apt-get install python-rpi. gpio

 

库测试

Once the code has be downloaded to an appropriate folder, and you have your LCD Plate properly connected, you can start with the basic demo display, which is run by simply executing the library file:

sudo python Adafruit_CharLCDPlate.py

If you have a rev 2 (512MB) Pi, or if you're not getting anything displaying, it might be due to the I2C bus number change in the Pi hardware. Edit Adafruit_CharLCD.py using a command like "nano Adafruit_CharLCD.py" and change the line 

lcd = Adafruit_CharLCDPlate(busnum = 0)

to 

lcd = Adafruit_CharLCDPlate(busnum = 1)

 

调整对比度

The plate uses a character LCD with an external contrast potentiometer. The first time you use it, adjust the potentiometer in the bottom right until you see the text clearly. If you don't upload code to the Pi, some boxes may appear instead, or you may see nothing at all.

 

Using the library code

Interfacing with the python example code is fairly easy! Inside the Adafruit_CharLCDPlate folder you'll find a  testLCD.py python script. The script does a few things, at the top it imports all the sub-modules. You'll need to have the  Adafruit_I2C.py, Adafruit_MCP230xx.py and  Adafruit_CharLCDPlate.pypython files to be in the same directory so be sure to copy them to your final destination.

Next it initializes the plate with  lcd = Adafruit_CharLCDPlate() - this creates the lcd object and starts communicating with the plate to set up the LCD and buttons

After initialization, you can clear the display with  lcd.clear() and write text with  lcd.message("text goes here") don't forget that its only 16 characters per line, and it does not automatically wrap lines. To insert a newline use the special '\n' character such as shown in the command:  lcd.message("Adafruit RGB LCD\nPlate w/Keypad!")

Next you can set the backlight with lcd.backlight(lcd.COLORNAME) where  COLORNAME is RED, YELLOW, GREEN, TEAL, BLUE, VIOLET for RGB LCD's or for monochrome LCDs, just use ON and OFF

Finally, you can ask the plate which buttons are pressed with buttonPressed(lcd.BUTTONNAME) where BUTTONNAME is LEFT RIGHT UP DOWN or  SELECT. This is not an interrupt-driven library so you can't have an interrupt go off when a button in pressed, instead you'll have to query the button in a loop. 

That's it! If you want to make detailed messages,  use the python string formatting commands to create a string and then write that string with  message()

下载

Adafruit's Pi Python codebase  
 
Check the Usage page for how to install the example python code directly from your Pi using git.   


© 著作权归作者所有

八宝粥
粉丝 50
博文 24
码字总数 35970
作品 0
程序员
私信 提问
加载中

评论(2)

素人派
素人派
这个图也太不清楚了吧,能给个清晰一点的吗?
素人派
素人派
学习了。
http://surenpi.com
远距离赏秋香,DIY树莓派望远镜

编者注:本项目来自Instructables,原作者为joshdont,转载请注明。 就像很多人说的,创客做的东西很多时候并没有什么用处,你甚至已经可以在市面上买到更便宜、更轻巧、功能更强大的成品,还...

吴攀
2015/12/07
0
0
DIY一个带WIFI的树莓派照相机

本文由 极客范 - Boyd Wang 翻译自 Phillip Burgess。欢迎加入极客翻译小组,同我们一道翻译与分享。转载请参见文章末尾处的要求。 概览 这个项目使用了Adafruit PiTFT触摸屏和树莓派摄像头模...

RagingTyphoon
2015/08/16
1K
0
[翻译完成] 树莓派LCD显示器适配器

我们之前发布了一款" 树莓派LCD显示器适配器 " , 你可以用我们的LCD屏(ITDB02-2.4E和ITDB02-2.8)直接连上树莓派使用. 在这里我们为这两款屏幕提供一些demo代码 – demo代码由Henning提供的U...

八宝粥
2013/06/29
3.1K
1
[翻译完成] 开源LCD触摸屏驱动

让树莓派支持uPD161704A和XPT2046芯片的240×320触摸屏驱动库 这个C库可以让你的树莓派支持µPD161704A和XPT2046芯片. µPD161704A是一个240 x 320像素LCD屏幕控制器 , XPT2046是搭配的触摸屏...

八宝粥
2013/06/29
1K
2
10 个最值得关注的树莓派博客

如果你正在计划你的下一个树莓派项目,那么这些博客或许有帮助。 网上有很多很棒的树莓派爱好者网站、教程、代码仓库、YouTube 频道和其他资源。以下是我最喜欢的十大树莓派博客,排名不分先...

作者: Ben Nuttall
2018/11/02
0
0

没有更多内容

加载失败,请刷新页面

加载更多

mysql-connector-java升级到8.0后保存时间到数据库出现了时差

在一个新项目中用到了新版的mysql jdbc 驱动 <dependency>     <groupId>mysql</groupId>     <artifactId>mysql-connector-java</artifactId>     <version>8.0.18</version> ......

ValSong
今天
5
0
Spring Boot 如何部署到 Linux 中的服务

打包完成后的 Spring Boot 程序如何部署到 Linux 上的服务? 你可以参考官方的有关部署 Spring Boot 为 Linux 服务的文档。 文档链接如下: https://docs.ossez.com/spring-boot-docs/docs/r...

honeymoose
今天
6
0
Spring Boot 2 实战:使用 Spring Boot Admin 监控你的应用

1. 前言 生产上对 Web 应用 的监控是十分必要的。我们可以近乎实时来对应用的健康、性能等其他指标进行监控来及时应对一些突发情况。避免一些故障的发生。对于 Spring Boot 应用来说我们可以...

码农小胖哥
今天
8
0
ZetCode 教程翻译计划正式启动 | ApacheCN

原文:ZetCode 协议:CC BY-NC-SA 4.0 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远。 ApacheCN 学习资源 贡献指南 本项目需要校对,欢迎大家提交 Pull Request。 ...

ApacheCN_飞龙
今天
5
0
CSS定位

CSS定位 relative相对定位 absolute绝对定位 fixed和sticky及zIndex relative相对定位 position特性:css position属性用于指定一个元素在文档中的定位方式。top、right、bottom、left属性则...

studywin
今天
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部