Small 8x2 LCD

advertisement
Small 8x2 LCD
2015 Adrian Krag
Objective
Some of our teams need small displays. We offer the LCM 1602 - This is a nice display, but it is
a bit big and it takes a lot of power for the backlight. They can be a bit expensive, but there are
often sales that offer them at a lower price. It has a
major advantage that it includes a PCF8572 Serial to
parallel converter which allows it to be controlled
with the I2C Serial interface. The display has 16 pins,
the bare minimum required to run the chip would be
7 plus power and ground. The PCF8572 reduced the
pin requirements to 2.
This project considers a smaller low
power alternative. This display is
available from a number of suppliers.
Prices vary from $2 to about $8. The
only disadvantage of this part is that
like the larger cousin, it has 14 pins, and it would take at least 7 of the Arduino
pins to connect it. The basic Arduino has a very small number of digital pins and often projects
don't have that many to spare. Ideally we would have a small circuit that could make it work just
like the LCM1602.
A simple schematic, a chip and a printed circuit board and we
would have the equivalent of the part we
have become comfortable with and know
how to use, only a whole lot smaller.
This can be used to show temperature and
humidity, or a whole range of sensor data for projects that require a small
foot print for a display.
This little display can be a gift for teams that want
to make a small project with a text display. 8
Characters is not much, but often it's enough.
The key to making this work is the port expander.
The following is from the write up from the
Advanced class from the summer of 2014.
PCF8574 Port Expander - optional material for those who really want to know.
To keep the Arduino cost down the designers used a low cost microprocessor with only 28 pins.
Well, by the time you count a few ground and power pins, the Tx and Rx so you can program it,
add a few reset pins you are not left with a lot pins you can use. Then of course, you want a few
analog input pins and that doesn't leave very many. An LCD alone takes 8 of them. Stepper
motors take 4 each. Pretty quick you can find yourself without enough pins to finish your project.
you could go to a bigger Arduino, but they aren't cheap.
You might consider the port expander. Today
we are working with the PCF8574, this is the
device that is used on the LCM1602 display With this device the Arduino only needs to use
2 pins, not 8. The PCF8574 is an 8 pin port
that can be used as an input or output which
will give us 8 more digital pins. The
connection the Arduino requires only A4 and
A5. We use the Wire library to read and write
this device. The Wire library integrates the I2C
serial communications interface.
First a word about I2C which is InterIntegrated Circuit. This interface allows you to
send data from one device to another. The controlling device (called the master, and in this case
the Arduino) sends out a string of bits to the responding device (called the slave, and in this case
the new set of port pins).
When the Arduino talks to the slave device it
sends out a series of bits. If we want to set the 8
new port pins to set them as high or low, the
Arduino tells all devices that it is starting a
message, then it sends out the address of the
device, and it sends the 8 1s or 0s, that we want to
put on the new port pins.
We can notice several things from the diagram.
First the master does something unusual, the data
transitions from high to low when the clock is high.
Normally we only allow the data to change when
the clock is low. This strange event tells the slave
that we are going to start a communication. After this the Master sends 7 bits of address. The
first 4 are the same for all PCF8754 devices. The last 3 are unique.
After the address the Master sends a High if it wants to send data to the slave, Low if it wants the
slave to send data back. The master then waits for the slave to pull the data line High. After the
Acknowledge, the master either sends or receives 8 data bits and one last acknowledge. All of
these bits are stable when the clock is high and only change when the clock is low. After all of
this, there is another abnormal event. The data transitions from low to high when the clock is
High. This indicates that we are done with our communications.
The wires connecting the Arduino to any I2C device are power (+5V),
ground (Gnd), and a data wire (SDA connected to A4) and a clock
wire (SCL connected to A5). We don't count the power and ground
wires because there are lots of those. We can put lots of slave
devices on the same clock and data wires. We can put up to 8
PCF8475 ports on one Arduino. That adds up to 64 extra digital pins.
Look at the chip - the first 3 pins are the address pins. We tie these high or low to create a
number from 0 to 7. The last 3 bits of the address in the communication must be the same as
these three bits. We need to know this number. The next 4 pins 4 to 7 are the first 4 digital pins.
Pins 9 to 12 are the last 4. The other two pins we care about are SDA connected to Arduino A4
and SCL connected to A5.
Let's get back to what we need to do to talk to this device. Let's look at some of the commands
that we can use with the Wire library. First of all we must have the line at the beginning of the
program. #include <Wire.h>
This allows the program to use the Wire library routines. Just as with the serial monitor we need
to have the begin statement.
Wire.begin (); // this initializes the I2C
communications - this is like Serial.begin(9600);
To get data from the external device we use
Wire.requestTransmission(address, number); // in
this case, address is the 7 bit address of the device.
For the PCF8754 this address is 0100??? - where
the 3 question marks are the 3 pins on the device.
number is the number of bytes we want the device
to send. Our address is 32 - which in binary is
B0100000. In this case, these 3 pins are all tied to
ground.
Next we wait for results - Just like
Serial.available(); we use Wire.available(); This
returns TRUE if we have received a byte, FALSE if
we need to continue to wait. Finally we can use the
Wire.read(); to take a byte out of the buffer.
To talk to the device we use Wire.begin (); // this
initializes the I2C then we start with Wire.beginTransmission(32); // this opens the
communication channel and tells our device that data is coming. Next we use
Wire.write("Text"); or Wire.write(byte); just like we would use Serial.write("Hello"); if we were
talking to the serial monitor.
Since the PCF8574 is a one byte port extender, we would want to write one byte (8 bits) to our
new external port. These will become the HIGHs and LOWs on the port pins.
Lastly, we terminate with Wire.endTransmission(); to tell the external device we are done.
Conclusion
If you need one of these, or have any questions please call me - Adrian Krag ak@thecije.org
Download