Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

ST7565 graphics?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ST7565 graphics?

by FuzzyWuzzie on Wed Jul 21, 2010 6:37 pm

Hullo,

I've got the ST7565 lcd up and running nicely (mucho gracias for including the 4050!). Only problem I'm having is getting my own image on the screen (the test program runs perfectly).

How did you create the image bmps? I tried using bmp2glcd, but the picture came out all distorted (parts of it were flipped all over). I also tried creating my own python script to do the task (below), but I couldn't get that to display properly either.

Code: Select all | TOGGLE FULL SIZE
from PIL import Image

def GetPixel(ls, x, y):
   return ls[(y * 128) + x]

def PutPixel(buffer, x, y):
   buffer[x+ (y/8)*128] |= (1 << (7-(y%8)))

im = Image.open("glcd.png")

px = list(im.getdata())

file = open("glcd.c", "w")

buffer = [0]*1024

for y in range(0, 64):
   for x in range(0, 128):
      if GetPixel(px, x, y) == 1:
         PutPixel(buffer, x, y)

file.write("static unsigned char __attribute__ ((progmem)) glcd_bmp[] = {\n")
for b in buffer:
   file.write(str(hex(b)) + ",")
file.write("};")
file.close()


Any tips? Thanks!

FuzzyWuzzie
 
Posts: 53
Joined: Wed Sep 30, 2009 10:37 pm

Re: ST7565 graphics?

by FuzzyWuzzie on Wed Jul 21, 2010 6:59 pm

Ok, I realized what my own program was doing - outputting the data in the wrong order. I fixed that up a bit and its working, so if anyone out there wants a tool for converting images into ST7565 graphics, you can use this (or write one yourself..):

Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/env python

import optparse
from PIL import Image

def GetPixel(ls, x, y):
   return ls[(y * 128) + x]

def PutPixel(buffer, x, y):
   buffer[x+ (y/8)*128] |= (1 << (7-(y%8)))

def ConvertImage(filename, verbose):
   try:
      im = Image.open(filename)
      px = list(im.getdata())
   except:
      print "Error: Failed to open input '" + filename + "'!!"
      return
      
   width = im.size[0]
   height = im.size[1]
   if width != 128 && height != 64:
      print "Error: Image is not proper dimensions (128x64)!!"
      return

   try:
      file = open(filename + ".c", "w")
   except:
      print "Error: Failed to open output '" + filename + ".c'!!"
      return
   
   if verbose:
      print "Files opened, parsing input..."

   buffer = [0]*1024

   for y in range(0, 64):
      for x in range(0, 128):
         if GetPixel(px, x, y) == 1:
            PutPixel(buffer, x, y)
   
   if verbose:
      print "Input file parsed!"
      print "Writing to output file..."

   file.write("static unsigned char __attribute__ ((progmem)) "+filename+"_bmp[] = {\n")
   for i in range(0, len(buffer)):
      file.write(str(hex(buffer[i])) + ",")
   file.write("};")
   file.close()
   
   if verbose:
      print "Done!"
      print "Information is stored in '" + filename + ".c'"
   
def main():
   parser = optparse.OptionParser()
   parser.add_option(   "-v", "--verbose",
                  dest="verbose", default=True,
                  help="Show detailed information about what's going on")
   (options, args) = parser.parse_args()
   if len(args) != 1:
      parser.error("incorrect input file!")
   else:
      ConvertImage(args[0], options.verbose)
   
if __name__ == '__main__':
   main()
   


Usage:
Code: Select all | TOGGLE FULL SIZE
glcd.py glcdImage.bmp


Where glcdImage.bmp only has 2 colours and is 128x64 px in size (this doesn't resize or anything). You can use any file format that PIL can convert - jpg, png, gif, bmp, etc.

FuzzyWuzzie
 
Posts: 53
Joined: Wed Sep 30, 2009 10:37 pm

Please be positive and constructive with your questions and comments.