Arduino and the LCD Breakout Board
The Color LCD Breakout Board, from SparkFun, is good starting point for experimenting with Arduino peripherals. It has two switches, a tri-color LED, and a 128x128 color LCD. The parts on the board are designed to work at 3.3v, so it also provides an opportunity to look at level-shifting between 5v and 3.3v. While I won't describe the process, I also used this exercise to try out Fritzing. Fritzing is a program for drawing connection diagrams and turning them into schematics and PCB layouts. It is a good way to create nice looking connection diagrams (top image to the left). The latest version for Linux, OSX, or MS-Windows, can be downloaded from the Fritzing Download page. There are three parts to this exercise. First we'll get the LED working, then connect up the switches, and finally setup and write to the LCD.
You can get the source code for the sketches from GitHub.
There is a lot more information about the LCD itself , but it is not referenced from the SparkFun page for this Color LCD Breakout Board. Instead check out the links on the SparkFun Color LCD 128x128 Nokia Knock-Off page.
You should have the Arduino IDE setup and configured on your computer. For the sketches below you will need version 1.0 or newer. I used version 1.0.3.
You will need to add header pins or wires to the Color LCD Breakout Board in order to connect it to the solderless breadboard. I chose to add header pins and remove two of the standoffs so that I could plug it directly in to the breadboard.
Figure 1: Connection Diagram
First we will hook up the Tri-Color LED and flash each of the colors.
The schematic shows that the anodes of the diodes are connected to 3.3v and that there are limiting resistors on the board. Since the Arduino UNO is a +5v device the LED will be reverse-biased (3.3 - 5 = -1.7v) when the output from the Arduino UNO is high. We don't have a part number for the LED so we can not look up the maximum rating, but it is typically several volts (LEDs have lower reverse bias limits than other diode types) so it should be OK for us to hook the STAT0-3 signals directly to the Arduino UNO.
We only need a few of the connections shown in Figure 1:
Ground: black wires
+3.3v: green wires
LED: blue wires
STAT0 to Pin 2
STAT1 to Pin 3
STAT2 to Pin 4
If the connections are correct, this sketch will flash the three components of the LED on, one at a time:
If your are using the code from GitHub and have installed it in your sketchbook directory, then you will find the sketch in the open menu as LED_Exercises->LED_Blink
Hook up the switches next.
From the schematic we see that switches short the S1 and S2 signals directly to ground. A pull-up resistor is needed so that the S1 and S2 signals are high when the switches are open. Since the signals are not used anywhere else, the internal pull-up resistors in the CPU on the Arduino will work just fine.
The test sketch for this section will turn the LED on when the switches are pressed, so in addition to the hookup listed above, we need two connections (purple wires in Figure 1 above):
S1 to Pin 5
S2 to Pin 6
This sketch will turn on the LED as follows (P=pressed):
If your are using the code from GitHub and have installed it in your sketchbook directory, then you will find the sketch in the open menu as LED_Exercises->SwitchTest
Getting the LCD hooked up and working is a bit more complicated. The issues include:
+3.3v to +5v level translation.
The LCD controller must be identified.
The display may need to be aligned.
Item 2 will be addressed by the gLCD library written and maintained by Tom Carpenter. Alternative libraries are can be found on the SparkFun product pages for the breakout board and the bare LCD. I chose Tom's because it is well documented and he is actively maintaining and improving the library.
+3.3v to +5v Level Translation
Since all the signals are unidirectional, level translation is straight forward and can be easily handled by a suitable buffer. The 74HC4050 Hex Non-Inverting Buffer is inexpensive and easy to use. We power the chip using the lower voltage (+3.3v) and then use one of the 6 buffers for each of the four (4) signals:
74HC4050:1 to +3.3v, blue wire
74HC4050:8 to GND, black wire
Ardino Pin 8 to 74HC4050:3, yellow wire
Ardino Pin 9 to 74HC4050:5, yellow wire
Ardino Pin 11 to 74HC4050:7,yellow wire
Ardino Pin 13 to 74HC4050:9,yellow wire
74HC4050:2 to RESET, orange wire
74HC4050:4 to CS, orange wire
74HC4050:6 to DIO, orange wire
74HC4050:10 to SCK, orange wire
+5V to VBATT, red wire
The wire colors are those shown in Figure 1, above, and the notation 74HC4050:N identifies pin N of the 74HC4050.
Install gLCD Library
The Arduino IDE expects libraries to be installed in specific locations based on the name of the library and the way it will be referenced in the code. The files that make up the gLCD library need to be located in the $HOME/sketchbook/libraries/gLCD/ directory. These command will download and install the version 3.4 (the one I used) of the library:
If the Arduino IDE was running, restart it. Look for gLCD under libraries:
Tom has included three example sketches with the library. These should work on with the Color LCD Breakout Board using the connections described above. When you are ready, read these sketches carefully to learn more about the how to use this versatile library. If you have trouble getting the LCD portion of the Color LCD Breakout Board working, Tom's example sketches are the best place to start looking for solutions.
LCD Setup and Alignment
While the example sketches included in the gLCD library are a great place to start, the following simplified sketch is the reference for the rest of this exercise.
Here is what you should see on the LCD after uploading the sketch:
Figure 2, gLCD_test sketch
Identify the LCD Controller
The Color LCD Breakout Board can come with either an Epson or a Phillips LCD Controller. It is not possible to determine the controller by visual examination and, since there are no output signals from the LCD Controller, it is not possible to determine the controller automatically. That leaves trial and error.
There are two lines in the sketch that you might have to change:
and more likely,
If you don't see anything like the display in Figure 2, the try the following:
Change HIGH_SPEED to NORMAL_SPEED in the first line.
If that doesn't work, then,
Change EPSON to PHILLIPS_1 in the second line.
If the second change (EPSON to PHILLIPS_1) works, then you should try setting the first line back to HIGH_SPEED (NORMAL_SPEED is really quite slow).
Should those two simple changes not work, then you will need to read the setup comments in the gLCD library examples for other configuration options.
There are three adjustments to make; rotation, offset and max size. Rotation is obvious and straight forward. The value in this line
is for the way I have the LCD breakout board plugged into the breadboard. Other valid rotation values are: ROTATION_0, ROTATION_90, and ROTATION_270.
The offset and max size are a bit more finicky. I suggest modifying the offset values first. Also note that I observed some problems with the display clear and filling large rectangles when the sum of the offset and the max pixels exceeded 131. So you may need to reduce the max values while adjusting the offsets.
The offset values set the position of the top left corner on the display. The outermost box is in red, so adjust the offsets until the top left pixel is red.
Once the offsets have been set, set the max values. The goal is to have a red box all the way around the display with no blue pixels outside the box. You might want to use a magnifying glass!
At this point you have checked out all the devices on the breakout board and you are ready to put it to use. What you use it for is up to your imagination- I'm thinking about a waterfall display for a software defined radio.