LCD plate - trying to read data from it

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

LCD plate - trying to read data from it

Postby bbkiwi » Thu Jan 31, 2013 9:55 pm

Hi,

I'm trying to add to the Python code to be able read data from the LCD namely: Read Busy Flag and Address Counter and
Read Data from RAM as described on pg. 24 and 58 in the data sheet HD44780.pdf

I have not been successful yet. It may be that I don't understand setting pins of the MCP23017 as input or output.

Any suggestions or references would be appreciated. Thanks.

In Adafruit_ChartLCDPlate.py I have added code similar to write4 but for reading. I've experimented with various combinations
of making pins input or output, but so far no luck. Also the hi and low 4 bits always turn out the same even though I give the enable
pulse twice. Also there is a bug related to the saving of the direction information (fix at end of this post)

Attempted routine to read
Code: Select all
   def readBFandACv(self):
        """ Send command  01 to LCD to read busy flag and Address counter """
        self.mcp.output(self.pin_rs, 0)
        self.mcp.output(self.pin_rw, 1) #set rw to 1
#  Configure pins for input optionally
        makeinput = 1 #1 to make input, 0 to leave as output pin
        self.pulseEnable() #send E pulse to set pins to 4 high bits BF,AC6,AC5,AC4
        if makeinput:
                for pin in self.pins_db:
                        self.mcp.config(pin,  self.INPUT)
        bits = range(8)
         # get the pins values
        for i in range(4):
            bt = self.mcp.inputnocheck(self.pins_db[::-1][i])
            bits[i]=bt
#           print i,bt,bits[i]

        # restore to pins to output (tried with and without)
        for pin in self.pins_db:
                self.mcp.config(pin,  self.OUTPUT)

        self.pulseEnable() #send E pulse to set pins to next 4 bits AC3,AC2,AC1,AC0

        if makeinput:
                for pin in self.pins_db:
                        self.mcp.config(pin,  self.INPUT)
        # get the pins values
        for i in range(4,8):
            bt = self.mcp.inputnocheck(self.pins_db[::-1][i-4])
            bits[i]=bt
#           print i,bt,bits[i]

        # restore to pins to output and rw to 0
        for pin in self.pins_db:
                self.mcp.config(pin,  self.OUTPUT)
        self.mcp.output(self.pin_rw, 0) # return rw to 0
#        print "Last :", bin(self.mcp.direction)[2:].zfill(16)
        return bits;


In Adafruit_MCP230xx.py added a version of input with assertion removed so can input from any
combination of input/output pins
Code: Select all
    def inputnocheck(self, pin):
        assert pin >= 0 and pin < self.num_gpios, "Pin number %s is invalid, only 0-%s are valid" % (pin, self.num_gpios)
        #assert self.direction & (1 << pin) != 0, "Pin %s not set to input" % pin
        print self.num_gpios, "pin ", pin
        if self.num_gpios <= 8:
            value = self.i2c.readU8(MCP23008_GPIOA)
        elif self.num_gpios > 8 and self.num_gpios <= 16:
            value = self.i2c.readU16(MCP23017_GPIOA)
            print value, bin(value)[2:].zfill(16)
            temp = value >> 8
            value <<= 8
            value |= temp
#bb fix return value & (1 << pin)
        return (value & (1 << pin))>>pin # to make 0 or 1


Bug in Adafruit_ChartLCDPlate.py
Code: Select all
    def config(self, pin, mode):
        if self.num_gpios <= 8:
            self.direction = self._readandchangepin(MCP23017_IODIRA, pin, mode)

# this code produces only 8 bits and loses the information about the input/output state of the
#other pins - the MCP23012_IODIRA and B are set correctly however
#the code that follows is my correction
#        if self.num_gpios <= 16:
#            if (pin < 8):
#                self.direction = self._readandchangepin(MCP23017_IODIRA, pin, mode)
#            else:
#                self.direction = self._readandchangepin(MCP23017_IODIRB, pin-8, mode)

        if self.num_gpios <= 16:
            if (pin < 8):
                # replace low bits
                self.direction = (self.direction >> 8)<<8 |  self._readandchangepin(MCP23017_IODIRA, pin, mode)
            else:
                # replace hi bits
                self.direction = (self.direction & 0xff) | self._readandchangepin(MCP23017_IODIRB, pin-8, mode) << 8
#       print "config ", pin, mode, self.direction, bin(self.direction)[2:].zfill(16)
        return self.direction
bbkiwi
 
Posts: 9
Joined: Thu Jan 31, 2013 9:08 pm

Re: LCD plate - trying to read data from it

Postby adafruit_support_bill » Fri Feb 01, 2013 6:28 am

Hi, Thanks for posting your findings so far. If you can post the bug-report to Github that would be very helpful also.
User avatar
adafruit_support_bill
 
Posts: 16083
Joined: Sat Feb 07, 2009 9:11 am

Re: LCD plate - trying to read data from it

Postby bbkiwi » Fri Feb 01, 2013 11:40 pm

I put it on github.
bbkiwi
 
Posts: 9
Joined: Thu Jan 31, 2013 9:08 pm


Return to Glowy things (LCD, LED, TFT, EL) purchased at Adafruit

Who is online

Users browsing this forum: No registered users and 5 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [108]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[34]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]