'how to send data to chip 2 of glcd automatically

So this is my code

import time
import RPi.GPIO as GPIO
import sensor
count = 0

# Look up table to display the given input starts from unicode 32
look_up = [[0x00, 0x00, 0x00, 0x00, 0x00, 0x00],  # Space
           [0x00, 0x00, 0x4f, 0x00, 0x00],        # !
           [0x00, 0x07, 0x00, 0x07, 0x00, 0x00],  # "
           [0x14, 0x7f, 0x14, 0x7f, 0x14, 0x00],  # #
           [0x24, 0x2a, 0x7f, 0x2a, 0x12, 0x00],  # $
           [0x23, 0x13, 0x08, 0x64, 0x62, 0x00],  # %
           [0x36, 0x49, 0x55, 0x22, 0x20, 0x00],  # &
           [0x00, 0x05, 0x03, 0x00, 0x00],        # '
           [0x00, 0x1c, 0x22, 0x41, 0x00],        # (
           [0x00, 0x41, 0x22, 0x1c, 0x00],        # )
           [0x14, 0x08, 0x3e, 0x08, 0x14, 0x00],  # *
           [0x08, 0x08, 0x3e, 0x08, 0x08, 0x00],  # +
           [0x50, 0x30, 0x00, 0x00],              # ,
           [0x08, 0x08, 0x08, 0x08, 0x08, 0x00],  # -
           [0x00, 0x60, 0x60, 0x00],              # .
           [0x20, 0x10, 0x08, 0x04, 0x02, 0x00],  # /
           [0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00],  # 0 0x30
           [0x40, 0x42, 0x7f, 0x40, 0x40, 0x00],  # 1
           [0x42, 0x61, 0x51, 0x49, 0x46, 0x00],  # 2
           [0x21, 0x41, 0x45, 0x4b, 0x31, 0x00],  # 3
           [0x18, 0x14, 0x12, 0x7f, 0x10, 0x00],  # 4
           [0x27, 0x45, 0x45, 0x45, 0x39, 0x00],  # 5
           [0x3c, 0x4a, 0x49, 0x49, 0x30, 0x00],  # 6
           [0x01, 0x71, 0x09, 0x05, 0x03, 0x00],  # 7
           [0x36, 0x49, 0x49, 0x49, 0x36, 0x00],  # 8
           [0x06, 0x49, 0x49, 0x29, 0x1e, 0x00],  # 9
           [0x00, 0x36, 0x36, 0x00, 0x00],        # :
           [0x00, 0x56, 0x36, 0x00, 0x00],        # ;
           [0x08, 0x14, 0x22, 0x41, 0x00],        # <
           [0x14, 0x14, 0x14, 0x14, 0x14, 0x00],  # =
           [0x00, 0x41, 0x22, 0x14, 0x08, 0x00],  # >
           [0x02, 0x01, 0x51, 0x09, 0x06, 0x00],  # ?
           [0x3e, 0x41, 0x5d, 0x55, 0x1e, 0x00],  # @
           [0x7e, 0x11, 0x11, 0x11, 0x7e, 0x00],  # A
           [0x7f, 0x49, 0x49, 0x49, 0x36, 0x00],  # B
           [0x3e, 0x41, 0x41, 0x41, 0x22, 0x00],  # C
           [0x7f, 0x41, 0x41, 0x22, 0x1c, 0x00],  # D
           [0x7f, 0x49, 0x49, 0x49, 0x41, 0x00],  # E
           [0x7f, 0x09, 0x09, 0x09, 0x01, 0x00],  # F
           [0x3e, 0x41, 0x49, 0x49, 0x7a, 0x00],  # G
           [0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00],  # H
           [0x00, 0x41, 0x7f, 0x41, 0x00],        # I
           [0x20, 0x40, 0x41, 0x3f, 0x01, 0x00],  # J
           [0x7f, 0x08, 0x14, 0x22, 0x41, 0x00],  # K
           [0x7f, 0x40, 0x40, 0x40, 0x40, 0x00],  # L
           [0x7f, 0x02, 0x0c, 0x02, 0x7f, 0x00],  # M
           [0x7f, 0x04, 0x08, 0x10, 0x7f, 0x00],  # N
           [0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00],  # O
           [0x7f, 0x09, 0x09, 0x09, 0x06, 0x00],  # P
           [0x3e, 0x41, 0x51, 0x21, 0x5e, 0x00],  # Q
           [0x7f, 0x09, 0x19, 0x29, 0x46, 0x00],  # R
           [0x26, 0x49, 0x49, 0x49, 0x32, 0x00],  # S
           [0x01, 0x01, 0x7f, 0x01, 0x01, 0x00],  # T
           [0x3f, 0x40, 0x40, 0x40, 0x3f, 0x00],  # U
           [0x1f, 0x20, 0x40, 0x20, 0x1f, 0x00],  # V
           [0x3f, 0x40, 0x38, 0x40, 0x3f, 0x00],  # W
           [0x63, 0x14, 0x08, 0x14, 0x63, 0x00],  # X
           [0x07, 0x08, 0x70, 0x08, 0x07, 0x00],  # Y
           [0x61, 0x51, 0x49, 0x45, 0x43, 0x00],  # Z
           [0x00, 0x7f, 0x41, 0x41, 0x00, 0x00],  # [
           [0x02, 0x04, 0x08, 0x10, 0x20, 0x00],  # \
           [0x00, 0x41, 0x41, 0x7f, 0x00],        # ]
           [0x04, 0x02, 0x01, 0x02, 0x04, 0x00],  # ^
           [0x40, 0x40, 0x40, 0x40, 0x40, 0x00],  # _
           [0x00, 0x00, 0x03, 0x05, 0x00],        # `
           [0x20, 0x54, 0x54, 0x54, 0x78, 0x00],  # a
           [0x7F, 0x44, 0x44, 0x44, 0x38, 0x00],  # b
           [0x38, 0x44, 0x44, 0x44, 0x44, 0x00],  # c
           [0x38, 0x44, 0x44, 0x44, 0x7f, 0x00],  # d
           [0x38, 0x54, 0x54, 0x54, 0x18, 0x00],  # e
           [0x04, 0x04, 0x7e, 0x05, 0x05, 0x00],  # f
           [0x08, 0x54, 0x54, 0x54, 0x3c, 0x00],  # g
           [0x7f, 0x08, 0x04, 0x04, 0x78, 0x00],  # h
           [0x00, 0x44, 0x7d, 0x40, 0x00],        # i
           [0x20, 0x40, 0x44, 0x3d, 0x00],        # j
           [0x7f, 0x10, 0x28, 0x44, 0x00],        # k
           [0x41, 0x7f, 0x40, 0x00],              # l
           [0x7c, 0x04, 0x7c, 0x04, 0x78, 0x00],  # m
           [0x7c, 0x08, 0x04, 0x04, 0x78, 0x00],  # n
           [0x38, 0x44, 0x44, 0x44, 0x38, 0x00],  # o
           [0x7c, 0x14, 0x14, 0x14, 0x08, 0x00],  # p
           [0x08, 0x14, 0x14, 0x14, 0x7c, 0x00],  # q
           [0x7c, 0x08, 0x04, 0x04, 0x00, 0x00],  # r
           [0x48, 0x54, 0x54, 0x54, 0x24, 0x00],  # s
           [0x04, 0x04, 0x3f, 0x44, 0x44, 0x00],  # t
           [0x3c, 0x40, 0x40, 0x20, 0x7c, 0x00],  # u
           [0x1c, 0x20, 0x40, 0x20, 0x1c, 0x00],  # v
           [0x3c, 0x40, 0x30, 0x40, 0x3c, 0x00],  # w
           [0x44, 0x28, 0x10, 0x28, 0x44, 0x00],  # x
           [0x0c, 0x50, 0x50, 0x50, 0x3c, 0x00],  # y
           [0x44, 0x64, 0x54, 0x4c, 0x44, 0x00],  # z
           [0x08, 0x36, 0x41, 0x41, 0x00],        # [
           [0x00, 0x00, 0x77, 0x00, 0x00],        # |
           [0x00, 0x41, 0x41, 0x36, 0x08, 0x00],  # ]
           [0x08, 0x08, 0x2a, 0x1c, 0x08, 0x00],  # <-
           [0x08, 0x1c, 0x2a, 0x08, 0x08, 0x00]]  # ->


class LCD_GPIO(object):
    # Timing constants for data latch
    E_PULSE = 0.00001
    E_DELAY = 0.00005

    # Pin map and set-up the GPIO pins
    def __init__(self, RST, RS, RW, E, CS1, CS2, D0, D1, D2, D3, D4, D5, D6, D7):
        self.CS1 = CS1
        self.CS2 = CS2
        self.RST = RST
        self.E = E
        self.RS = RS
        self.RW = RW
        self.D0 = D0
        self.D1 = D1
        self.D2 = D2
        self.D3 = D3
        self.D4 = D4
        self.D5 = D5
        self.D6 = D6
        self.D7 = D7
        GPIO.setwarnings(False)  # Disable warnings
        GPIO.setmode(GPIO.BCM)  # Use BCM GPIO numbers
        GPIO.setup(self.E, GPIO.OUT)  # E
        GPIO.setup(self.RW, GPIO.OUT)  # RW
        GPIO.setup(self.RS, GPIO.OUT)  # RS
        GPIO.setup(self.D0, GPIO.OUT)  # DB0
        GPIO.setup(self.D1, GPIO.OUT)  # DB1
        GPIO.setup(self.D2, GPIO.OUT)  # DB2
        GPIO.setup(self.D3, GPIO.OUT)  # DB3
        GPIO.setup(self.D4, GPIO.OUT)  # DB4
        GPIO.setup(self.D5, GPIO.OUT)  # DB5
        GPIO.setup(self.D6, GPIO.OUT)  # DB6
        GPIO.setup(self.D7, GPIO.OUT)  # DB7
        GPIO.setup(self.CS1, GPIO.OUT)  # CS1
        GPIO.setup(self.CS2, GPIO.OUT)  # CS2
        GPIO.output(self.RS, 0)
        GPIO.output(self.RW, 0)
        GPIO.output(self.E, 0)
        GPIO.output(self.CS1, 0)
        GPIO.output(self.CS2, 0)
        GPIO.setup(self.RST, GPIO.OUT)  # RST
        GPIO.output(self.RST, 0)
        time.sleep(0.002)
        GPIO.output(self.RST, 1)
        time.sleep(0.002)

    # Use IC1 of the display
    def useDisp1(self):
        GPIO.output(self.CS1, 1)  # Turn ON left controller
        GPIO.output(self.CS2, 0)  # Turn OFF right controller

    # Use IC2 of the display
    def useDisp2(self):
        GPIO.output(self.CS1, 0)  # Turn OFF left controller
        GPIO.output(self.CS2, 1)  # Turn ON right controller

    # Write data to be displayed to GPIO pins
    def data_write(self, value, mode):
        GPIO.output(self.RW, 0)
        GPIO.output(self.RS, mode)
        GPIO.output(self.D0, value & 0x01)
        GPIO.output(self.D1, value & 0x02)
        GPIO.output(self.D2, value & 0x04)
        GPIO.output(self.D3, value & 0x08)
        GPIO.output(self.D4, value & 0x10)
        GPIO.output(self.D5, value & 0x20)
        GPIO.output(self.D6, value & 0x40)
        GPIO.output(self.D7, value & 0x80)

        # Toggle Enable
        time.sleep(self.E_DELAY)
        GPIO.output(self.E, True)
        time.sleep(self.E_PULSE)
        GPIO.output(self.E, False)
        time.sleep(self.E_DELAY)

        # Checking if the controller is busy
        GPIO.setup(self.D7, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.output(self.RW, 1)
        GPIO.output(self.RS, 0)
        time.sleep(self.E_DELAY)
        GPIO.output(self.E, True)
        time.sleep(self.E_PULSE)
        GPIO.output(self.E, False)
        time.sleep(self.E_DELAY)

        while GPIO.input(self.D7):
            pass
        GPIO.setup(self.D7, GPIO.OUT)  # DB7


class LCD12864(object):
    def __init__(self, pinmap):
        self.driver = pinmap
        self.glcd_init()

    # Set row address and write it as command
    def set_row(self, value):
        self.driver.data_write(0xB8 | (value & 0x07), 0)

    # Set column address and write it as command
    def set_column(self, value):
        self.driver.data_write(0x40 | (value & 0x3F), 0)

    # Clear all the data in IC1 and IC2
    def glcd_clr(self):
        self.driver.useDisp1()
        for y in range(8):
            self.set_row(y)
            self.set_column(0)
            for i in range(64):
                self.driver.data_write(0x00, 1)

        self.driver.useDisp2()
        for y in range(8):
            self.set_row(y)
            self.set_column(0)
            for i in range(64):
                self.driver.data_write(0x00, 1)

    # Command to turn ON the display
    def glcd_init(self):
        self.driver.useDisp1()
        self.driver.data_write(0x3F, 0)
        self.driver.useDisp2()
        self.driver.data_write(0x3F, 0)

    # IC selection based on user input
    def select_chip(self, value):
        if value == 1:
            self.driver.useDisp1()
        elif value == 2:
            self.driver.useDisp2()

    # Read the data from look up table and write it based on input
    
def glcd_print(self, data):
    data1 = str(data)
    for i in range(len(data1)):
        length = (ord(data1[i]) - 32)
        for j in range(len(look_up[length])):
            self.driver.data_write(look_up[length][j], 1)


if __name__ == "__main__":
    driver = LCD_GPIO(RS=4, RW=7, E=8, D0=9, D1=10, D2=11, D3=14,
                      D4=15, D5=17, D6=18, D7=25, CS1=22, CS2=23, RST=24)  # Set GPIO pins
    lcd = LCD12864(pinmap=driver)
    lcd.glcd_clr()                                                 # Clear display
    lcd.glcd_init()                                                # Initialize the display                                          
                                                                   # Select IC1 or IC2 based on requirements
    while True:
        temp, hum = sensor.dht()   
        lcd.select_chip(1)                                         # read sensor data
        lcd.set_row(0)                                             # select row on which data to be displayed
        lcd.set_column(0)                                          # select column on which data to be displayed
        lcd.glcd_print("Temp:")
        lcd.glcd_print(temp)
        lcd.glcd_print("C")

here data is displayed on based on inputs I give in lcd.select_chip(2) i tried with whatever knowledge i have to automatically write long string using both chips but nothing worked

what I want to do here is both chips have 64 pixels and my each characters are take max of 6 pixels as you can see in look-up table so after these 64 pixels are filled chip2 should be activated and remaining data should be written in it

for example if my string is "Hello how are you?" "Hello how ar" will be written chip1 and remaining data i.e., "e you?" should be written chip2 but in my case it is not happening please help

edit:

def glcd_print(self, data):
        data1 = str(data)
        for i in range(len(data1)):
            length = (ord(data1[i]) - 32)
            for j in range(len(look_up[length])):
                self.driver.data_write(look_up[length][j], 1)

IC selection

# Use IC1 of the display
def useDisp1(self):
    GPIO.output(self.CS1, 1)  # Turn ON left controller
    GPIO.output(self.CS2, 0)  # Turn OFF right controller

# Use IC2 of the display
def useDisp2(self):
    GPIO.output(self.CS1, 0)  # Turn OFF left controller
    GPIO.output(self.CS2, 1)  # Turn ON right controller

manual chip selection

     def select_chip(self, value):
            if value == 1:
                self.driver.useDisp1()
            elif value == 2:
                self.driver.useDisp2()

This part is responsible for writing data in GLCD and if the string length is less than 64 pixels it will Display properly on Chip1 or 2 based on input given but after if the string is long i.e., if it consumes more than 64 pixels then i want to automatically activate chip2 to display remaining string which was not written in Chip 1

pictures when string is within 64 pixels range

when string length is more that 64 the string was "Hello how are you?"

I used this code for reference

PS: I know i shouldn't be asking for a code but i tried so much but was not able to achieve it



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source