Search the Community
Showing results for tags 'LCD'.
Found 2 results
Hi everyone, I recently got a raspberry pi and have so far been able to display text on a 2x20 character LCD which I took out of an old credit card reader. Not much information could be found on the LCD module so a lot of the code which I wrote was trial and error to see what worked and what didn't work. Now I would like to read data from the LCD. Where would I begin to do that? I would also like to use my pi to "share files" from piratebay. Instead of "sharing files" from one of my windows machines which could potentially get a virus, I would like to use my pi instead. How would I go about doing this? Thanks, Andrew
Hello, 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 ): self.lcdInit() self.lcdCls() self.defaultFont=defaultFont self.defaultSmallFont=defaultSmallFont def lcdByte( self, d ): "Send a single byte to LCD. To be used by lcdCommand or lcdData" if type(d)==type('a'): d=ord(d) GPIO.output(DOG_CS, 0) #CS=0 for i in range(8): if d&128 > 0: GPIO.output(DOG_MOSI, 1) #MOSI=1 else: GPIO.output(DOG_MOSI, 0) #MOSI=0 d = d<<1 GPIO.output(DOG_CLK, 0) #SCK=0 #time.sleep(0.00001) GPIO.output(DOG_CLK, 1) #SCK=1 #time.sleep(0.001) GPIO.output(DOG_CS, 1) #CS=1 #time.sleep(0.01) def lcdCommand( self, d ): "Send a command byte to the LCD" GPIO.output(DOG_A0, 0) #A0=0 self.lcdByte(d) time.sleep(0.001) def lcdData( self, d ): "Send a data byte to the LCD" GPIO.output(DOG_A0, 1) #RS=1 self.lcdByte(d) def lcdDataSeq( self, t ): "Send a data sequence to the LCD stored in a list, tuple or string" for i in t: self.lcdData(i) def lcdCommandSeq( self, t ): "Send a command sequence to the LCD stored in a list, tuple or string" for i in t: self.lcdCommand(i) def lcdInit( self ): "GPIO and LCD initialization" # Initialize GPIO GPIO.setmode(GPIO.BCM) 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) time.sleep(0.01) GPIO.output(DOG_RES, 1) time.sleep(0.01) # Send init sequence init_seq = [ 0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x27, 0x81, 0x10, 0xAC, 0x00, 0xAF ] self.lcdCommandSeq(init_seq) 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): self.lcdPos(i,0) self.lcdDataSeq([0x00]*128) def bigRect( self ): "Paint a 1px wide rectangle at the edges of the screen, clear the rest." self.lcdPos(0,0) line = [0xff] + [0x01]*126 + [0xff] self.lcdDataSeq(line) line = [0xff] + [0x00]*126 + [0xff] for i in range(6): self.lcdPos(i+1,0) self.lcdDataSeq(line) self.lcdPos(7,0) line = [0xff] + [0x80]*126 + [0xff] self.lcdDataSeq(line) def printSmallText( self, t, font=None ): "Prints a text to actual position with a 8 bit font" if font==None: font=self.defaultSmallFont for c in t: b = ord(c) if font.has_key(: self.lcdDataSeq(font[b]) else: self.lcdDataSeq(font[0x20]) def printText( self, t, page=0, col=0, font=None ): "Prints a text with a choosen font to the specified location." if font==None: font=self.defaultFont for i in range(font["data"]/8): self.lcdPos(page+i, col) for c in t: b = ord(c) if not font.has_key(: b = 0x20 self.lcdDataSeq(font[b][i]) os.environ["TZ"]='GMT-1' lcd=DOGL(defaultFont=terminal16, defaultSmallFont=terminal8) lcd.bigRect() while True: lcd.lcdPos(2,30) lcd.printSmallText(time.strftime('%Y-%m-%d',time.localtime())) lcd.lcdPos(4,30) lcd.printText(time.strftime('%H:%M:%S',time.localtime()), 4, 15) It looks like this on my desk: I wish you all a good time with these little toys :-)