Code: Select all
#!/usr/bin/python import RPi.GPIO as GPIO from time import sleep class HD44780: def __init__(self, pin_rs=24, pin_e=23, pins_db=[4, 17, 21, 22]): self.pin_rs = pin_rs self.pin_e = pin_e self.pins_db = pins_db GPIO.setmode(GPIO.BCM) GPIO.setup(self.pin_e, GPIO.OUT) GPIO.setup(self.pin_rs, GPIO.OUT) for pin in self.pins_db: GPIO.setup(pin, GPIO.OUT) self.clear() def clear(self): """ Blank / Reset LCD """ self.cmd(0x33) # $33 8-bit mode self.cmd(0x32) # $32 8-bit mode self.cmd(0x28) # $28 8-bit mode self.cmd(0x0C) # $0C 8-bit mode self.cmd(0x06) # $06 8-bit mode self.cmd(0x01) # $01 8-bit mode def cmd(self, bits, char_mode=False): """ Send command to LCD """ sleep(0.001) bits=bin(bits)[2:].zfill(8) GPIO.output(self.pin_rs, char_mode) for pin in self.pins_db: GPIO.output(pin, False) for i in range(4): if bits[i] == "1": GPIO.output(self.pins_db[::-1][i], True) GPIO.output(self.pin_e, True) GPIO.output(self.pin_e, False) for pin in self.pins_db: GPIO.output(pin, False) for i in range(4,8): if bits[i] == "1": GPIO.output(self.pins_db[::-1][i-4], True) GPIO.output(self.pin_e, True) GPIO.output(self.pin_e, False) def message(self, text): """ Send string to LCD. Newline wraps to second line""" for char in text: if char == '\n': self.cmd(0xC0) # next line else: self.cmd(ord(char),True) if __name__ == '__main__': lcd = HD44780() lcd.message(" I'm Raspberry Pi\n Take a byte!")
I got mine off eBay for £1.67 delivered free from china. Took 3 weeks though. But I have since bought 10 of them. I can sell you one for £4.50 (enough to cover import tax p & p etc plus small profit for my trouble )wh1p wrote:Thanks for all of your help I'm just wandering if any of you helpful people could link me to 16 x 2 display which either rs component or maplins in the UK sell which you know is definitely compatible or if you live in the UK and have setup a display on your raspberry pi where did you buy your component from? also just wandering if anyone is aware of a UK based seller who is selling the Raspberry Pi serial BoB circuit board?
Thanks to all those who have already provided me with information
we have resellers in the UK as wellwh1p wrote:Thanks and just wandering has anyone in the UK ever ordered from ad fruit as i am going to order the following product just wanted to get an idea of your experience of the time their products take to ship (from them to you)?
I will be ordering the following product and maybe a few other products they sell:
Any information would be nice but I don't mind if you guys don't have any experience with them.
http://www.raspberrypi.org/phpBB3/viewt ... o+breakoutwh1p wrote:just wandering if there is any chance you could guide me in the direction of making my own cobbler will certainly save me time and money .