Building a graphical display for OpenEnergyMonitor

As a followup to my post on building an OpenEnergyMonitor system here is a description of two different remote displays I have made, one using a 128×64 pixel graphical LCD and one using a 4×20 line LCD.

The GLCD Version

The OpenEnergyMonitor project is working on a graphical display and I’ve based the code on their examples. For the emonGLCD they are using a serially connected JeeLabs based graphic LCD that uses the GLCD_ST7565 library, for the parallel SparkFun GLCD that I’m using I needed to use the KS0108 compatible GLCD library (formerly the KS0108 library) so modifications in both hardware and software were required.

To use a KS0108 based display you will need to download the GLCD library and copy it to your Arduino IDE library directory.

The first problem is that the KS0108 based screens use a lot of pins, 8 data pins and 5 command pins in addition to the power connections and the standard pinout uses several of the pins we will need for the RFM12B wireless module so the pin assignments must be changed.

We need digital pins 2 and 10 to 14 for the RFM12B so I made the following modifications; In the GLCD library directory edit config/ks0108_Arduino.h and change the definitions for the data pins to:

#define glcdData0Pin      14
#define glcdData1Pin      15
#define glcdData2Pin      16
#define glcdData3Pin      17
#define glcdData4Pin      4
#define glcdData5Pin      5
#define glcdData6Pin      6
#define glcdData7Pin      7

and change the command pins to:

#define glcdCSEL1      9
#define glcdCSEL2      8
#define glcdRW      3
#define glcdDI      19
#define glcdEN      18

Then wire your LCD as follows (NOT to the standard layout):
Note that this is for a “Pinout A” type KS0108 panel, for other variants you will have to alter the pins accordingly.

Arduino pin GLCD Function GLCD Pin Comment
5V +5 volts 1
GND GND 2
n/a Contrast in 3 Connect to wiper of 10k potentiometer
14 (alog 0) D0 4
15 (alog 1) D1 5
16 (alog 2) D2 6
17 (alog 3) D3 7
4 D4 8
5 D5 9
6 D6 10
7 D7 11
9 CSEL1 12
8 CSEL2 13
Reset Reset 14 Connect to reset
3 R_W 15
19 (alog 5) D_I 16
18 (alog 4) EN 17
n/a Contrast out 18 Connect to one leg of 10k potentiometer
n/a Backlight +5 19 Connect via 100 ohm resistor to +5v
GND Backlight Gnd 20 To ground and other leg of potentiometer

Due to changing the library to the KS0108 compatible one there are quite a few changes to make in the example emonGLCD Arduino sketch, you can get my modified version on GitHub here.

The GLCD library comes with a few basic fonts (in the fonts directory) but the larger digital style one I am using for the power reading is one I converted from a TTF font, you can download it here. If you want to convert fonts yourself there is a a free java app called GLCDFontCreator2 available here that will convert TTF fonts for use with this library.

As well as changing the commands to use the GLCD library I have moved the Dallas one wire temperature sensor to pin 1 and removed the green/red LED outputs which leaves us with one pin spare (digital 0) for future use which may be useful to add a mode change button to change what the display shows. I’ve also made the output to the serial monitor optional as if it is active with the temperature sensor connected on pin 1 it will prevent the temperature from being read and will output garbage anyway, you can re-enable it by changing #define SERIAL 0 to #define SERIAL 1 but you will need to disconnect pin 1 while it is running.

If you want to include the temperature sensor you will need a DS18B20 one wire temperature sensor and a 4.7K resistor plus the OneWire library and the DallasTemperature library installed in your Arduino libraries directory.

Connect the DS18B20 temperature sensor to pin 1 of the Arduino as shown below:

To receive the wireless signal from the transmitter a RFM12B and breakout board is required. The breakout board should be built with all the components the same as the one built for the Xino based OpenEnergyMonitor transmitter: With the board positioned with the headers at the bottom fit 3 x 4K7 resistors on the left and 3 x 10K on the right. Fit two 0.1uF/100nF ceramic capacitors in the C1 and C2 positions and a 10uF electrolytic capacitor in C4 (positive to the right hand side as marked on the board). Fit the MCP1702-33 to follow the orientation marked on the board and fit a 5 pin male header across the GND, SCK, SDO, SDI and SEL positions. When soldering the RFM12B to the breakout board you only need to solder the top 3 and bottom 3 pads on the left hand side and the bottom 2 on the right. Solder a 165mm length of solid core wire to the hole next to the top left pin of the RFM12B for use as an antenna.

Link the 5V pin on the RFM12B breakout board to the 5V on the Arduino and the IRQ pin to the Arduino’s D2 pin then plug the breakout board into the 8 way header on the Arduino so that it is across the GND and D10 pins.

Upload the sketch to the Arduino and you should start to see data on the display.

After testing everything out on a breadboard first I built the final device using a ProtoX prototype shield. The Proto X shield comes with 4 sets of standard header pins but I replaced the one where the RFM12B breakout board connects with a stackable header so it could be plugged in on top of the prototype board. I used an old IDE hard disk cable to connect the screen, cutting off one end and soldering the relevant connections to the prototype board which makes it easy to position and remove the display. The temperature sensor, resistors and contrast pot are also soldered to the prototype board.

The 4×20 LCD Version

While I was at it I knocked up a second version using a 4×20 character HD44780 LCD display connected via a SparkFun SerLCD serial LCD Backpack. The HD44780 compatible displays use a parallel connection natively so normally need 12 pins connecting but the useful serial backpack from SparkFun allows it to be connected via a serial connection requiring only 3 pins (5V, ground and data). They aren’t cheap compared to the cost of a 4×20 LCD but they are very handy.

The LCD is connected to the Arduino pin 1 and the DS18B20 temperature sensor is connected to pin 3 using the same connection as for the GLCD version above. You can download the sketch for this one here. Note that you will probably want to disconnect the pin 1 connection to the display while uploading to the Arduino otherwise it will spam the display with garbage and could potentially reconfigure the SerLCD if the right sequence hits it.

You can download my version of the emonGLCD Arduino sketch modified to work with a serial 4×20 LCD on GitHub here.


More pictures
 (click to enlarge)

    

Video of the GLCD in operation:

 

Parts used for the graphical display version Parts used for the 4 line LCD version
SparkFun LCD-00710 128×64 pixel LCD
Arduino compatible board
ProtoX prototype shield
RFM12B transceiver
Jeelabs RFM12B breakout boards
DS18B20 Temperature sensor
1 x 100 to 330 ohm resistor
3 x 10K resistors
4 x 4.7K resistors
2 x 0.1uF/100nF ceramic capacitors
1 x 10uF electrolytic capacitors
1 x MCP1702-33 low dropout 3.3V voltage regulator
1 x 10K potentiometer
1 x 5 way male header
1 x 165mm length of wire for antenna
Old IDE Cable
USB Power supply
HD44780 compatible 4×20 character LCD
SparkFun SerLCD backpack
Arduino compatible board
RFM12B transceiver
Jeelabs RFM12B breakout boards
DS18B20 Temperature sensor
3 x 10K resistors
4 x 4.7K resistors
2 x 0.1uF/100nF ceramic capacitors
1 x 10uF electrolytic capacitors
1 x MCP1702-33 low dropout 3.3V voltage regulator
1 x 5 way male header
1 x 165mm length of wire for antenna
USB  Power supply

 

Next Steps

Some sort of enclosure would be good and as both these units contain a temperature sensor and a transceiver and will be situated in different rooms of the house it would be nice if they could upload their readings to the emoncms web interface via the Nanode base station. I don’t know if this is feasible but in theory it sounds good and is something I will look into more.

There is also plenty of opportunity to display extra information on these displays such as usage over time, estimated energy costs, date, time etc. Maybe this information could be switchable via a mode button connected to that one remaining pin on the GLCD version.

 

Update 26 October

I’ve now made a case for the GLCD display using laser cut acrylic glued together with epoxy. This was my first time trying anything like this and it was mostly successful although if I was doing it again I would redesign the back cover and base so that it is easier to screw the Arduino board in place. I did get the front with the logo laser engraved into it but it didn’t turn out as well as I’d hoped with some burning around the edges of the letters so I flipped the front over and went with a stick on logo cut in a frosted vinyl with a vinyl cutting plotter. I’m pretty pleased with how it turned out overall.

You can download the .svg file for the case here.

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.