However often a traditional LCD is more useful, and surely is more cheap than a touchscreen solution.
Here one way to connect a traditional LCD and use it in projects, like the TeirmiLab one.
This article describes how to connect a traditional LCD but with RGB capabilities to the Raspberry Pi B.
We need :
- Raspberry Pi B or Raspberry Pi B+
- RGB 16x2 LED display
- MCP23017 I2C GPIO expander
It is possible to hook a display without the need of the GPIO expander, however a normal LCD uses at least 6 signals. 9 if the LCD display is an RGB one like the one used for this project.
Considering that the Raspberry Pi B doesn't have many GPIO available and that usually the speed required to handle the display is not critical, using a chip like the MCP23017 make sense.
In this way it will be enough to "hook" the chip to the I2C bus, leaving all the Raspberry Pi GPIO free for other use.
Considering that the Raspberry Pi B doesn't have many GPIO available and that usually the speed required to handle the display is not critical, using a chip like the MCP23017 make sense.
In this way it will be enough to "hook" the chip to the I2C bus, leaving all the Raspberry Pi GPIO free for other use.
Let see a schematic.
Software
There are many ways to control the hardware.
For now I found a ready-to-use Python library published by Adafruit that is working nicely.
Again, the important thing is that control an LCD is not a critical task, so a python script is Ok.
Maybe in future I'll explore the possibility to control it directly in C.
Python
To use our display we need to install some code in our Raspberry.Here a quick step-by-step guide (see Adafruit tutorials for a more detailed and easy instructions) :
- sudo apt-get update
- sudo apt-get install build-essential python-dev python-smbus python-pip
- sudo apt-get install i2c-tools
- sudo pip install RPi.GPIO
- cd ~
- git clone https://github.com/adafruit/Adafruit_Python_CharLCD.git
- cd Adafruit_Python_CharLCD
- sudo python setup.py install
Before to be able to use it, we need to be sure a configuration file is correctly set-up.
Execute : sudo nano /etc/modules
and if the file exists, add these two lines in the end.
i2c-bcm2708
i2c-bcm2708
i2c-dev
Save the file then open another one in edit.
Execute : sudo nano /etc/modprobe.d/raspi-blacklist.conf
Execute : sudo nano /etc/modprobe.d/raspi-blacklist.conf
In this file comment out the two lines showed below, adding # at the beginning:
#blacklist spi-bcm2708
#blacklist i2c-bcm2708
Reboot Raspberry : sudo shutdown -r now
or : sudo reboot
At this point everything should be installed in order to use the display.
First is better to run an utility to see if the I2C GPIO expander is seen correctly.
sudo i2cdetect -y 1
The command should display a table and in the table should be present a 0x20 address.
pi@raspberrypi ~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi ~ $
If so, the chip is correctly seen by Raspberry.
pi@raspberrypi ~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi ~ $
If so, the chip is correctly seen by Raspberry.
To test if the display is working you can execute a test script :
- cd Adafruit_Python_CharLCD/examples
- sudo ./char_lcd_mcp.py
Some test messages should be displayed on the LCD display.
Troubleshooting
It is possible to have some problems installing the libraries.Here a couple of tips and resolutions.
apt-get missing
If you start from a fresh installation of Raspbian, especially a lite version, before to start to follow the instructions above, be sure to execute :
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get update
It is important because updating the first time, include more repo on apt-get.
python build fail
If during the python building of the library you have this errors :
python ./setup.py build
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-3.5.1.zip
Extracting in /tmp/tmpw6UbTx
Traceback (most recent call last):
File "./setup.py", line 4, in
use_setuptools()
File "/home/pi/Adafruit_Python_CharLCD/ez_setup.py", line 128, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "/home/pi/Adafruit_Python_CharLCD/ez_setup.py", line 108, in _do_download
_build_egg(egg, archive, to_dir)
File "/home/pi/Adafruit_Python_CharLCD/ez_setup.py", line 57, in _build_egg
with archive_context(archive_filename):
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/pi/Adafruit_Python_CharLCD/ez_setup.py", line 88, in archive_context
with get_zip_class()(filename) as archive:
File "/usr/lib/python2.7/zipfile.py", line 770, in __init__
self._RealGetContents()
File "/usr/lib/python2.7/zipfile.py", line 813, in _RealGetContents
raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file
this happens because for some magic reason :) the python script screw up the download of a zipped file.
In my case the file was setuptools-3.5.1.zip.
Doing an ls -l showed up to be 122 byte big !! Definitively NOT a zip file.
The workaround was quite easy actually.
The workaround was quite easy actually.
- remove the file : sudo rm setuptools-3.5.1.zip
- manually download the file :
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.5.1.zip - Re-execute the build : sudo python ./setup.py build
Examples
Be aware about the type of kit you are using.
On the examples area there are different examples depending the type of display in use.
To test the basic display, use : char_lcd_mcp.py
To test the kit with RGB display and pushbutton use : char_lcd_plate.py
No comments:
Post a Comment