Thursday, August 1, 2013

A LCD display my RPi and RPi-Monitor

I saw on the internet that it is possible to use a LCD to display information from the Raspberry Pi. RPi-Monitor is gathering a lot of information and it could be interesting to have such an information available without a computer. So I decided to purchase a PCD8544 from dx.com.

Photo from Flickr Attribution cc-by by arduinolabs

This post is describing how to acquire, connect and use such a component with he Raspberry Pi and gives an example showing how to connect it with RPi-Monitor.



Step 1: The acquisition


I found on the Internet a site reselling the PCD8544 for few euros (dx.com). After a moment of hesitation, I decided to give a try and I purchased it. It was the 16th of may.

The 27th of may, I received a e-mail saying that my purchase was partially shipped, one element is no more available (I've been reimbursed) and a last element will be sent later...

I finally received all my good 4 weeks after the initial purchase order. This site doesn't contradict its reputation: It delivers the good but you have to be patient... very patient ;-).

PCD8544 LCD screen


Step 2: The connection

The PCD8544 comes in two parts (the lcd screen and the pins) that need to be soldered together. Once done, it can be installed in the breadboard as shown in the drawing bellow:

Schema made with Fritzing (fritzing.org)
Note: If you want to reproduce this assembly, check carefully the pin order, it may be different.


Step 3: The preparation

My first goal is to test this new display. I look on the internet and find different solution using Python or C. After few tries, I decided to use Python based on the information shared into this post.

To use the PCD8544 display we need to install few software and load a kernel module.

First, let's install wiringpi2 from drogon.net
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
Once wiringpi is installed, it is possible to test it with the following command:
gpio readall
 +-----+-------+------+----+-Rev2-----+----+------+-------+-----+
 | wPi |  Name | Mode | Val| Physical |Val | Mode | Name  | wPi |
 +-----+-------+------+----+----++----+----+------+-------+-----+
 |     |  3.3v |      |    |  1 || 2  |    |      | 5v    |     |
 |   8 |   SDA |   IN | Lo |  3 || 4  |    |      | 5V    |     |
 |   9 |   SCL |   IN | Lo |  5 || 6  |    |      | 0v    |     |
 |   7 | GPIO7 |   IN | Lo |  7 || 8  | Lo | ALT0 | TxD   | 15  |
 |     |    0v |      |    |  9 || 10 | Lo | ALT0 | RxD   | 16  |
 |   0 | GPIO0 |   IN | Hi | 11 || 12 | Hi | OUT  | GPIO1 | 1   |
 |   2 | GPIO2 |   IN | Lo | 13 || 14 |    |      | 0v    |     |
 |   3 | GPIO3 |   IN | Hi | 15 || 16 | Lo | OUT  | GPIO4 | 4   |
 |     |  3.3v |      |    | 17 || 18 | Lo | OUT  | GPIO5 | 5   |
 |  12 |  MOSI | ALT0 | Hi | 19 || 20 |    |      | 0v    |     |
 |  13 |  MISO | ALT0 | Hi | 21 || 22 | Hi | IN   | GPIO6 | 6   |
 |  14 |  SCLK | ALT0 | Hi | 23 || 24 | Lo | ALT0 | CE1   | 10  |
 |     |    0v |      |    | 25 || 26 | Lo | ALT0 | CE1   | 11  |
 +-----+-------+------+----+----++----+----+------+-------+-----+
Now, install the python binding of wiringpi:
sudo apt-get install python-dev python-imaging python-imaging-tk python-pip
sudo pip install wiringpi2
The program we will use require spidev to be activated. The kernel module should then be activated.
To do so, comment the line blacklist spi-bcm2708 by adding a heading # in the file /etc/modprobe.d/raspi-blacklist.conf then reboot the Raspberry Pi to activate this module.

Finally install spidev python library:
sudo pip install spidev
The prerequisite are now installed. In next chapter we will see how to install the python library in charge of driving the PCD8544 LCD and how to use it.

Step 4: The installation

Into Raspberry Pi forum, an interesting post catch my attention. I used it as the base to control the LCD.
The library written Richard Hull's is also interesting I then took this as a example to create module that can be directly installed on the Raspberry Pi.
This pcd8544 library resulting is available into its own dedicated repository in github.
To install it, execute the following commands:
git clone https://github.com/XavierBerger/pcd8544.git
cd pcd8544
./setup.py clean build 
sudo ./setup.py install
 You can now test the installation with the proposed examples:
cd examples
./pi_logo.py
 If installation works properly, you should see the following screen:

You can try to execute other examples to see what the library is capable to do with this LCD.


Step 5: The utilization

As I said in introduction, RPi-Monitor is gathering a lot of information and some of them may be interesting to have without having to start a PC. Information are made available from the embedded web server. To get and display the information we then just have to create a web client and use the library to display.

For people interesting about learning development I did comment my code:
This code is dedicated to extract the living room temperature and humidity from RPi-Monitor information.
Copy this code into a file (rpimonitor-testlcd.py) the make this file executable (chmod +x rpimonitor-testlcd.py) then execute (./rpimonitor-testlcd.py) it to see:



10 comments :

  1. first of all, thanks for the rpi-monitor, a great application with lots of possibilities. I've bought myself an lcd screen, tested with your tutorial and it works! now I'm going to implement more rpimonitor functionality into it.

    ReplyDelete
    Replies
    1. I did start the same kind of project: RPi-Monitor-LCD. If you are curious about my current development, you can have a look to my github repository. Nothing is documented yet but some feature are starting to be operational... to be continued ;-)

      Delete
    2. I'll definitely have a look at your work. Thanks

      Delete
  2. Nearly good ... I had to change this :

    sudo pip install wiringpi2 to install the wiringpi in addition (the python script are calling wiringpi and not wiringpi2 module)

    Thanks for this :-)

    ReplyDelete
    Replies
    1. Good point, I'll fix that either in this doc or in code.

      Delete
    2. It's the pcd8544 library that causes the problem. It uses the wiringpi library, not wiringpi2

      Delete
    3. Exactly, I took some time to fix it but it is done now

      Delete
  3. I've mingled into your code for displaying data onto LCD screen and came up with my own script that doesn't depend on RPi-Monitor (though it is a GREAT tool!). Here it is: http://www.bartbania.com/index.php/lcd-display-with-rpi-and-room-temperature/
    Thanks for the inspiration!

    ReplyDelete
  4. Very nice work!

    I just forked the pcd8544 library and did a port to java, since I use Java for my robot project.

    Thanks for sharing!

    Daniel

    ReplyDelete
  5. Hi there! I just used your library, but after setup, I can't run any of the example programs.
    I get this error:
    "
    Traceback (most recent call last):
    File"./clock.py",line 24 in
    lcd.cls()
    AttributError: 'module' object has no attribute 'cls'
    "

    Do you have any idea why that's happening?

    Thanks!
    Hector

    ReplyDelete