Hardware Reference
In-Depth Information
8.
Now it's a very good time to double-check all your connections.
9.
Once the connection has been made, turn on the power to the shift register and the LCD. If
all has gone well you should see that the top row of your LCD has been filled out by blocks.
This is part of the startup sequence on all HD44780s and clones. This is a good sign. If you
don't see anything, go back and check your connections. Remember that things don't
often work the first time. If you have managed to let the magic smoke out, then off to the
shops for you: I guess you forgot to check your connections first!
You do want more than just a magic set of blocks on the LCD, right? This is where our next section comes in. I will
be using an open source application called lcdproc to drive the LCD.
Finding Your I2C Device
So the magic smoke is in and you're all ready to use the LCD. It's now time to access the I2C bus within Linux. By
default you may not have the I2C bus module loaded. To quickly check if you have I2C support loaded, run the
following command:
# ls /dev/i2c-*
This should return a listing of at least /dev/i2c-0 . In my case it listed nothing. Fedora will not autoload the I2C kernel
module. You can fix this in two ways. For a temporary fix you may just want to load the I2C kernel module. You can do
this via the following command:
# modprob i2c-dev
If you want Fedora to autoload the module on each boot, create a file in the /etc/sysconfig/modules/ directory
called i2c-dev.modules . Enter Listing 4-1 as shown.
Listing 4-1. Autoload Code for i2c-dev modules
#!/bin/bash
lsmod | grep -q i2c-dev || /sbin/modprobe i2c-dev >/dev/null 2>&1
Save the file and reboot your Raspberry Pi to check that the module was loaded. You now have access to the I2C
bus. Exciting times are ahead! How do you go about finding the LCD now that you have access to the bus? Recall that
it's connected to a bus with the address we set by pulling the address pins low. I did not calculate the address at that
time; I just pulled the address bits low. This seems like a bit of an issue if you cannot find the LCD. It might be on
another platform like the Arduino or another embedded device; lucky for you that you are running Linux. You can
use a handy command called i2cdetect to discover all I2C devices on a given bus. To be able to use this handy tool,
you're going to need to install the i2c-tools package.
To do this, simply run the following command:
# yum install -y i2c-tools
This package will install a few different tools; the main two we will be concerned with are i2cdetect and i2cset .
Ensure that you are the root user when you run the i2c-tools command as it needs access to the raw devices.
The first tool I want to show you is i2cdetect . This tool accepts an I2C bus as an input. It will then scan that bus
and report back any devices it finds. If you take a look at the output of the following command you should see
/dev/i2c-0 .
# ls /dev/i2c-*
 
Search WWH ::




Custom Search