Jump to content

Welcome, Guest!


EA DOG glcd on RaspberryPi :-)

Recommended Posts



I've got my first little baby before Christmas, now it has 2 more brothers :-) I stared with different tasks for it, including some personal VPN and file backup stuff. These nice machines use very little power so I can afford to keep some running all the time. My other interest is to use RPi for some weather monitoring and home automation.


My first HW related play lead me to get a small LCD working. My choice was Electronic Assembly's DOG series. (EA-DOGL128-6) It's a cheap 128x64 LCD with SPI interface. The language of choice is Python. I decided to share this piece of code here, maybe it helps to someody. It's not a perfect nice piece of code but it just started to work :-)


#! /usr/bin/env python

import RPi.GPIO as GPIO
from font import *
import time
import os

DOG_MOSI    = 23    # PIN 36
DOG_CLK        = 25    # PIN 37
DOG_A0        = 22    # PIN 38
DOG_CS        = 24    # PIN 40
DOG_RES        = 17    # PIN 39

class DOGL():
   "Class to handle communication with EA DOGL128-6 and some basic operations"

   def __init__( self, defaultFont=None, defaultSmallFont=None ):

   def lcdByte( self, d ):
       "Send a single byte to LCD. To be used by lcdCommand or lcdData"
       if type(d)==type('a'):
       GPIO.output(DOG_CS, 0)            #CS=0
       for i in range(8):
           if d&128 > 0:
               GPIO.output(DOG_MOSI, 1)    #MOSI=1
               GPIO.output(DOG_MOSI, 0)    #MOSI=0
           d = d<<1
           GPIO.output(DOG_CLK, 0)        #SCK=0
           GPIO.output(DOG_CLK, 1)        #SCK=1
       GPIO.output(DOG_CS, 1)            #CS=1

   def lcdCommand( self, d ):
       "Send a command byte to the LCD"
       GPIO.output(DOG_A0, 0)            #A0=0

   def lcdData( self, d ):
       "Send a data byte to the LCD"
       GPIO.output(DOG_A0, 1)            #RS=1

   def lcdDataSeq( self, t ):
       "Send a data sequence to the LCD stored in a list, tuple or string"
       for i in t:

   def lcdCommandSeq( self, t ):
       "Send a command sequence to the LCD stored in a list, tuple or string"
       for i in t:

   def lcdInit( self ):
       "GPIO and LCD initialization"
       # Initialize GPIO
       GPIO.setup(DOG_CS, GPIO.OUT)
       GPIO.setup(DOG_CLK, GPIO.OUT)
       GPIO.setup(DOG_MOSI, GPIO.OUT)
       GPIO.setup(DOG_A0, GPIO.OUT)
       GPIO.setup(DOG_RES, GPIO.OUT)
       # Reset display
       GPIO.output(DOG_RES, 0)
       GPIO.output(DOG_RES, 1)
       # Send init sequence
       init_seq = [ 0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x27, 0x81, 0x10, 0xAC, 0x00, 0xAF ]

   def lcdPos( self, page, col ):
       "Move the cursor to page and col"
       self.lcdCommand(0xB0 + page)
       self.lcdCommand(0x10 + ((col&0xf0)>>4) )
       self.lcdCommand(0x00 + (col&0x0f) )

   def lcdCls( self ):
       "Clear the entire screen"
       for i in range(8):

   def bigRect( self ):
       "Paint a 1px wide rectangle at the edges of the screen, clear the rest."
       line = [0xff] + [0x01]*126 + [0xff]
       line = [0xff] + [0x00]*126 + [0xff]
       for i in range(6):
       line = [0xff] + [0x80]*126 + [0xff]

   def printSmallText( self, t, font=None ):
       "Prints a text to actual position with a 8 bit font"
       if font==None:
       for c in t:
           b = ord(c)
           if font.has_key(:

   def printText( self, t, page=0, col=0, font=None ):
       "Prints a text with a choosen font to the specified location."
       if font==None:
       for i in range(font["data"][2]/8):
           self.lcdPos(page+i, col)
           for c in t:
               b = ord(c)
               if not font.has_key(:
                   b = 0x20


lcd=DOGL(defaultFont=terminal16, defaultSmallFont=terminal8)

while True:
   lcd.printText(time.strftime('%H:%M:%S',time.localtime()), 4, 15)



It looks like this on my desk: post-1937-0-38737900-1362868990.jpg


I wish you all a good time with these little toys :-)

  • Like 1

Share this post

Link to post
Share on other sites

Some example of the fonts:

terminal16 = {\
   "data":    [ "Terminal", "monospaced", 16],\
   0x20:    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],\
   0x21:    [[0, 0, 0, 0, 124, 255, 255, 124, 0, 0, 0, 0], [0, 0, 0, 0, 0, 51, 51, 0, 0, 0, 0, 0]],\
   0x40:    [[0, 248, 254, 7, 243, 251, 27, 251, 251, 7, 254, 248], [0, 15, 31, 24, 51, 55, 54, 55, 55, 54, 3, 1]],\

  • Like 1

Share this post

Link to post
Share on other sites

Hi dbelikov,


I used this application: lcd-image-converter (http://code.google.com/p/lcd-image-converter/)

That time I used a Windows precompiled version but recently I managed to compile it for Linux also. It allowed me to configure the format of the bitmaps in a way that was easy to use with this controller. Than I needed to convert the resulting C code to python code, but that was rather just some easy text parsing exercise.


The bigger problem is finding the right font that can be converted into something that looks nice on that small pixel size. Terminal from Windows worked fine, meanwhile I found some other free, like "Apple ][", that renders ok in 8px size.


I tried to write my own python code using freetype library. It generates some bitmaps that I can interpret, but it's not easy to calculate the positioning of this bitmap in the final fixed bitmap. If anybody has experience with it and is willing to help than I'll be glad to share my code snipet.

  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

About Us

Bringing you the latest Raspberry Pi news, tutorials and user forum.

The Fruity Computer