So job one. Display some data without being connected to an LCD monitor.
Here are the parts that I've used. The job could be done without a few of them but I've added them for convenience or because they were part of a previous project and I didn't want to disassemble them...
LCD Display (HD44780 controller type, 2 line, 16 character)
Translucent blue project box
Chocolate block electrical connector
RS232 female PCB mount and breakout board
PCB mount potentiometer (pretty much any size you like over 10k)
PCB AA battery holder (capacity 3) and 3 AA batteries
Loads of male-female jumper wire
The LCD display I had already assembled from a previous Arduino project so there are no photos of that part of the build. It was wired according to this tutorial on the Arduino site. I added an extra connection to have the LCD backlight permanently on (5v to pin 15, pin 16 to ground). If I were doing it over again I'd perhaps add another pot to adjust the backlight or wire it in to the RS232 cable to control the backlight from the Pi.
All the wires from the LCD I fed into the choccy block connector, this way when I connect them to the RS232 cable I can choose a somewhat logical order for the pins as they are laid out on the breakout board.
Here is the assembled LCD display, in it's box with the RS232 cable attached. I drilled a hole in the cover for access to the contrast pot but once it's set it almost never needs adjusting.
The datasheet for the display says it is a 5v device, but I wasn't happy about using the 5v supply from the Pi as the display could draw more current than is recommended through the GPIO pins. Instead I use 3 AA batteries to power the display, so it's happy with 4.5v rather than 5, and only connect the RS (Register Select), E (Read/Write Enable strobe), and Data Bus pins to the Pi (as well as a connection to ground to complete the circuit). The Pi GPIO output is 3.3v and the display seems happy with this too which is good as it means I didn't have to mess about with level shifting.
The way I connected it up left the RS232 breakout board outputs as follows.
When it's ready to go in the car, the breakout board will be fixed into the Pi main box and the display will plug in from outside, this way the display can be shared around other projects as needed (like it is now) cutting down the expense of future endeavours.
After confirming the display was working by plugging in to an old Arduino project, the next job was to drive the thing from the Pi. Thankfully a couple of folks have already done the heavy lifting here. Gordon @ Drogon has created WiringPi, an Arduino compatible wiring library for the Raspberry Pi and marcoster has ported the LiquidCrystal library referenced in the tutorial link above. Double win!
After git cloning the marcoster code all I needed to do was make a few alterations to his main.c file around line 76-77
LiquidCrystal lcd(0, 4, 1, 21, 22, 23, 24); lcd.begin(20, 4);
In the original, a 4-line, 20-character display is used. I'm only using a 2-line, 16-character display and I've used different GPIO pins (for no reason other than personal preference). After alteration, my code, same line numbers...
LiquidCrystal lcd(24, 23, 4, 17, 21, 22); lcd.begin(16, 2);
The first 2 pin numbers are the RS and E connections to the LCD, the next 4 pins are the Data Bus connections (DB4-DB7 on the breakout board).
The pin numbers are using the BCM system, they are equivalent to GPIO 5,4,7,0,2,3 or header pins 18,16,7,11,13,15.
Other changes to main.c, removed lines 82-84 because the are writing to display lines which I don't have and changed the setCursor call on line 90 from (0,3) to (0,1) so the next write will start at character 0 on display line 1.
Compile the libraries, then the main program and we're ready to test.
g++ main.o LiquidCrystal.o wiringPi.o Print.o -o lcd_test
Connect up the Pi, breadboard and breakout board. I could wire the breakout board direct to the Pi with female-female jumpers but I'm moving the display between projects and doing it this way means when I come to re-wire it all I need to do is match up the colours rather than refer to the code to remind myself what pins I specified. Remember to connect the ground pins of the Pi and the battery pack.
Plug in the LCD and run the application, need to sudo the command so the app has rights to access the GPIO.
Ouput success. Next up, input.
Useful links (I am not affiliated with any of the following)
marcoster RPi LCD Library