OLED 16x2 HD44780 woes
Posted: Thu Jan 30, 2014 10:51 am
Hi,
I'm having issues with this (http://www.midasdisplays.com/pdf/MCOB21605G1V.pdf) screen. I've used LCD version of this screen before with an arduino, the oled version is nice as it requires less wires and less current and no faffing about with contrast.
This is supposed to be a drop in replacement for 44780 but I cannot get the thing to work reliably, im having issues with stuff getting to the screen out of order, garbled and even some times I start the code and lines 1 and 2 are the wrong way around. Sometimes there's complete garbage on the screen and the only way to resolve that is to reboot everything (as removing the 5v supply going to the screen locks up the pi... not always but more often than not).
My wiring from the LCD pins is:
1 GND
2 +5v
3 DNC
4 GPIO25
5 GND
6 GPIO24
7..10 DNC
11 GPIO23
12 GPIO17
13 GPIO27
14 GPIO22
15 DNC
16 DNC
I've tried various libs, the Adafruit CharLCD and others, here is the code I am currently using
Can anyone see if I am doing something blatantly wrong or can anyone confirm that thy have managed to get one of these things working without issue?
I'm having issues with this (http://www.midasdisplays.com/pdf/MCOB21605G1V.pdf) screen. I've used LCD version of this screen before with an arduino, the oled version is nice as it requires less wires and less current and no faffing about with contrast.
This is supposed to be a drop in replacement for 44780 but I cannot get the thing to work reliably, im having issues with stuff getting to the screen out of order, garbled and even some times I start the code and lines 1 and 2 are the wrong way around. Sometimes there's complete garbage on the screen and the only way to resolve that is to reboot everything (as removing the 5v supply going to the screen locks up the pi... not always but more often than not).
My wiring from the LCD pins is:
1 GND
2 +5v
3 DNC
4 GPIO25
5 GND
6 GPIO24
7..10 DNC
11 GPIO23
12 GPIO17
13 GPIO27
14 GPIO22
15 DNC
16 DNC
I've tried various libs, the Adafruit CharLCD and others, here is the code I am currently using
Code: Select all
#!/usr/bin/python
import RPi.GPIO as GPIO
from time import sleep
class HD44780:
def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 27, 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(0x28); # 4bit mode
self.cmd(0x01) # clear DDRAM
self.cmd(0x0C) # display on, cursor off
self.cmd(0x80) # cursor @ 0,0
self.cmd(0x06) # entry 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, text1,text2):
""" Send string to LCD. Newline wraps to second line"""
text1 = text1.ljust(16, ' ');
text2 = text2.ljust(16, ' ');
self.cmd(0x80);
for char in text1:
self.cmd(ord(char),True)
self.cmd(0xC0) # next line
for char in text2:
self.cmd(ord(char),True)