This blog opener isn’t strictly about coding, but having some time off work recently I decided to do something that, for me, is pretty cool. What could possibly be cooler than displaying car data from my favourite racing simulator Live For Speed on an external LCD device!
The image on the right shows the finished display, showing the car speed, gear and fuel tank level. It’s updated in real-time using the game’s Outgauge system – Outgauge uses network packets to communicate with the world outside the game, and cool applications have been built to control external hardware devices, from real car gauges to full-motion simulators. The whole device is pretty simple, and cost me just shy of £20 for parts. The LCD device is an HD44780-compatible supertwist LCD display (model #N27AZ from Maplin), and then all you really need is a parallel cable and a power source. I’ve powered my device from three 1.5v AA batteries, so for convenience I added an on/off switch. You can also add a potentiometer to the contrast input to the device, but I chose not to since I want it to display at full contrast all the time.
The parallel cable was also a bit of a DIY project in itself. I couldn’t easily find (nor was willing to pay delivery for) a D25 male->male cable, but I did have a D25->C36 cable handy. So, I slaughtered one end of it, cut of the wires I didn’t need and wired a 25-pin plug on the end!
At the moment the device is powered on batteries, but I plan to change this so that it’s powered from a standard hard-disk connector. I’ve found that when configuring the LCD to display data on two lines the contrast dips considerably (which is why in the video below I’m displaying the data on only one line), and it’s been pointed out that this could be the batteries not being able to supply enough current.
Connecting to the LCD
The rest of the work is done in software. I used the excellent LFSLib to retrieve the data packets from Live For Speed, and my own custom library to interface with the LCD. There are a couple of methods you can use in .Net to send data through the parallel port, and I used the inpout32.dll method. This Win32 library contains two main functions – one to send data and one to receive data. Once you’ve got the hang of using the parallel port, controlling the LCD unit is a fairly straight-forward affair. You basically send a byte of data representing an instruction, send a high voltage to the ‘enable’ pin (causing the LCD to read and act upon the instruction) then clear the enable pin again. There’s an initialization sequence which you must follow, after which text data is sent by setting the RS pin to ‘high’ (letting it know you’re going to send data) and then sending each character in turn down the data pins (setting the ‘enable’ pin high after every character). The LCD will advance the cursor after every character. You can optionally tell the unit where you want to start the text from, in case you wanted to centre the text on the display.
My device is not without it’s issues (there’s a rant coming up in a future post about the BackgroundWorker object) but it was a fun project to work on, and you should have seen the smile on my face once I got it working! If you know a little bit about electronics and can solder, definitely give some thought to attempting a similar thing. I’ve included some references below which helped me get this up and running. The next thing for me to do is to make an enclosure for it, and put the project to bed.
Here’s the final result!
References:
- I/O Ports Uncensored: Part 1 Covers controlling the parallel port and connecting to a simple LED circuit.
- I/O Ports Uncensored: Part 2 Covers the circuit and pin-out of the HD44780-compatible display unit.
- Electronics Forum: Helped a great deal when I was learning how to do all this stuff, and troubleshoot problems that were arising.
