コード例 #1
0
    def __init__(self,
                 data,
                 clock,
                 num_lines,
                 num_columns,
                 addr=DEFAULT_I2C_ADDR):

        self.i2c_addr = addr
        self.i2c = I2C(freq=100000, scl=clock, sda=data)
        self.i2c.writeto(self.i2c_addr, b'\0')

        self.buf = bytearray(2)
        self.command = bytearray(4)

        time.sleep(0.020)  # Allow LCD time to powerup
        self.hal_write_init_nibble(
            self.LCD_FUNCTION_RESET)  # Send reset 3 times
        time.sleep(0.005)  # need to delay at least 4.1 msec
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        time.sleep(0.001)
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        time.sleep(0.001)

        # Put LCD into 4 bit mode
        self.hal_write_init_nibble(self.LCD_FUNCTION)
        time.sleep(0.001)
        LcdApi.__init__(self, num_lines, num_columns)
        cmd = self.LCD_FUNCTION
        if num_lines > 1:
            cmd |= self.LCD_FUNCTION_2LINES
        self.hal_write_command(cmd)

        self.hal_backlight_on()
コード例 #2
0
    def __init__(self, i2c, i2c_addr, num_lines, num_columns):
        self.i2c = i2c
        self.i2c_addr = i2c_addr

        # Send IODIR address, set IODIR to all inputs, init all other registers 0
        self.i2c.send(b'\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00', self.i2c_addr)

        # Set pins GP1 through GP7 to output, leave GP0 as input
        self.i2c.mem_write(0x01, self.i2c_addr, IODIR)

        # Send reset 3 times
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        delay(5)    # need to delay at least 4.1 msec
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        delay(1)
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        delay(1)
        # Put LCD into 4 bit mode
        self.hal_write_init_nibble(self.LCD_FUNCTION)
        delay(1)
        LcdApi.__init__(self, num_lines, num_columns)
        cmd = self.LCD_FUNCTION
        if num_lines > 1:
            cmd |= self.LCD_FUNCTION_2LINES
        self.hal_write_command(cmd)
    def __init__(self, i2c, i2c_addr, num_lines, num_columns):
        self.i2c = i2c
        self.i2c_addr = i2c_addr

        # writeto IODIR address, set IODIR to all inputs, init all other registers 0
        self.i2c.writeto(self.i2c_addr, bytearray([0]))
        utime.sleep(0.002)
        # Set pins GP1 through GP7 to output, leave GP0 as input
        self.i2c.writeto_mem(self.i2c_addr, 0x01, "\x00")

        # writeto reset 3 times
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        utime.sleep(0.005)  # need to delay at least 4.1 msec
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        utime.sleep(0.001)
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        utime.sleep(0.001)
        # Put LCD into 4 bit mode
        self.hal_write_init_nibble(self.LCD_FUNCTION)
        utime.sleep(0.001)
        LcdApi.__init__(self, num_lines, num_columns)
        cmd = self.LCD_FUNCTION
        if num_lines > 1:
            cmd |= self.LCD_FUNCTION_2LINES
        self.hal_write_command(cmd)
コード例 #4
0
    def __init__(self, i2c, i2c_addr, num_lines, num_columns):
        self.i2c = i2c
        self.i2c_addr = i2c_addr

        # Send IODIR address, set IODIR to all inputs, init all other registers 0
        self.i2c.writeto(
            self.i2c_addr,
            bytearray([
                0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00
            ]))

        # Set pins GP1 through GP7 to output, leave GP0 as input
        self.i2c.writeto_mem(self.i2c_addr, IODIR, bytearray([0x01]))

        # Send reset 3 times
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(5)  # need to sleep_ms at least 4.1 msec
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(1)
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(1)
        # Put LCD into 4 bit mode
        self.hal_write_init_nibble(self.LCD_FUNCTION)
        sleep_ms(1)
        LcdApi.__init__(self, num_lines, num_columns)
        cmd = self.LCD_FUNCTION
        if num_lines > 1:
            cmd |= self.LCD_FUNCTION_2LINES
        self.hal_write_command(cmd)
コード例 #5
0
    def __init__(self, rs_pin, enable_pin=None, data_port=None, fourbit=True,
                 rw_pin=None, backlight_pin=None,
                 num_lines=2, num_columns=16):
        """Constructs the PIOLcd object. The xx_pin arguments must be machine.Pin
        objects. data_port is the number of the lowest order GPIO pin for data, which must
        be consecutive. fourbit tells, whether the display is connected in 4-bit or 8-bit mode.
        enable_pin is the GPIO number of the enable pin.
        The rw pin isn't used by this library, but if you specify it, then
        it will be set low.
        """
        self.rs_pin = rs_pin
        self.rw_pin = rw_pin
        self.backlight_pin = backlight_pin
        self._4bit = fourbit
        self.rs_pin.init(Pin.OUT)
        self.rs_pin.value(0)
        if self.rw_pin:
            self.rw_pin.init(Pin.OUT)
            self.rw_pin.value(0)
        if self.backlight_pin is not None:
            self.backlight_pin.init(Pin.OUT)
            self.backlight_pin.value(0)

        # activate the four bit state machine in single nibble mode
        self.sm = rp2.StateMachine(0, self._4bit_write, freq=1000000,
                        sideset_base=enable_pin, out_base=data_port, pull_thresh=4)
        self.sm.active(1)

        sleep_ms(20)   # Allow LCD time to powerup
        # Send reset 3 times
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(5)    # need to delay at least 4.1 msec
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(1)
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(1)
        cmd = self.LCD_FUNCTION
        if not self._4bit:
            cmd |= self.LCD_FUNCTION_8BIT
        self.hal_write_init_nibble(cmd)
        sleep_ms(1)

        if self._4bit is True:
            # switch to dual níbble mode mode by overriding pull_thresh
            self.sm.active(0)
            self.sm = rp2.StateMachine(0, self._4bit_write, freq=1000000,
                            sideset_base=enable_pin, out_base=data_port, pull_thresh=8)
            self.sm.active(1)
        else:
            # switch the state machine to 8 bit
            self.sm.active(0)
            self.sm = rp2.StateMachine(0, self._8bit_write, freq=1000000,
                            sideset_base=enable_pin, out_base=data_tbase)
            self.sm.active(1)

        LcdApi.__init__(self, num_lines, num_columns)
        if num_lines > 1:
            cmd |= self.LCD_FUNCTION_2LINES
        self.hal_write_command(cmd)
コード例 #6
0
 def __init__(self, i2c, i2c_addr, num_lines, num_columns, bl_i2c_addr):
     self.i2c = i2c
     self.i2c_addr = i2c_addr
     self.bl_i2c_addr = bl_i2c_addr
     # Put LCD into 4 bit mode
     self.hal_write_command(self.LCD_FUNCTION)
     delay(1)
     LcdApi.__init__(self, num_lines, num_columns)
     cmd = self.LCD_FUNCTION
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)
     # init backlight
     self.i2c.mem_write(0, self.bl_i2c_addr, 0) # MODE1
     self.i2c.mem_write(0, self.bl_i2c_addr, 1) # MODE2
コード例 #7
0
 def __init__(self, i2c, i2c_addr, num_lines, num_columns):
     self.i2c = i2c
     self.i2c_addr = i2c_addr
     self.i2c.send(0, self.i2c_addr)
     delay(20)  # Allow LCD time to powerup
     # Send reset 3 times
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     delay(5)  # need to delay at least 4.1 msec
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     delay(1)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     delay(1)
     # Put LCD into 4 bit mode
     self.hal_write_init_nibble(self.LCD_FUNCTION)
     delay(1)
     LcdApi.__init__(self, num_lines, num_columns)
     cmd = self.LCD_FUNCTION
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)
コード例 #8
0
ファイル: pyb_i2c_lcd.py プロジェクト: dhylands/python_lcd
 def __init__(self, i2c, i2c_addr, num_lines, num_columns):
     self.i2c = i2c
     self.i2c_addr = i2c_addr
     self.i2c.send(0, self.i2c_addr)
     delay(20)   # Allow LCD time to powerup
     # Send reset 3 times
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     delay(5)    # need to delay at least 4.1 msec
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     delay(1)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     delay(1)
     # Put LCD into 4 bit mode
     self.hal_write_init_nibble(self.LCD_FUNCTION)
     delay(1)
     LcdApi.__init__(self, num_lines, num_columns)
     cmd = self.LCD_FUNCTION
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)
コード例 #9
0
 def __init__(self, i2c, i2c_addr, num_lines, num_columns):
     self.i2c = i2c
     self.i2c_addr = i2c_addr
     self.i2c.writeto(self.i2c_addr, bytes([0]))
     utime.sleep_ms(20)  # Allow LCD time to powerup
     # Send reset 3 times
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     utime.sleep_ms(5)  # Need to delay at least 4.1 msec
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     utime.sleep_ms(1)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     utime.sleep_ms(1)
     # Put LCD into 4-bit mode
     self.hal_write_init_nibble(self.LCD_FUNCTION)
     utime.sleep_ms(1)
     LcdApi.__init__(self, num_lines, num_columns)
     cmd = self.LCD_FUNCTION
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)
コード例 #10
0
 def __init__(self, i2c, i2c_addr, num_lines, num_columns):
     self.i2c = i2c
     self.i2c_addr = i2c_addr
     self.i2c.writeto(self.i2c_addr, b'\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00')# modified
     self.i2c.writeto_mem(self.i2c_addr, IODIR, bytearray([0x01]))
     sleep_ms(20)   # Allow LCD time to powerup
     # Send reset 3 times
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(5)    # need to delay at least 4.1 msec
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(1)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(1)
     # Put LCD into 4 bit mode
     self.hal_write_init_nibble(self.LCD_FUNCTION)
     sleep_ms(1)
     LcdApi.__init__(self, num_lines, num_columns)
     cmd = self.LCD_FUNCTION
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)
コード例 #11
0
 def __init__(self, port, i2c_addr, num_lines, num_columns):
     self.port = port
     self.i2c_addr = i2c_addr
     self.bus = smbus.SMBus(port)
     self.bus.write_byte(self.i2c_addr, 0)
     time.sleep(0.020)  # Allow LCD time to powerup
     # Send reset 3 times
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     time.sleep(0.005)  # need to delay at least 4.1 msec
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     time.sleep(0.001)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     time.sleep(0.001)
     # Put LCD into 4 bit mode
     self.hal_write_init_nibble(self.LCD_FUNCTION)
     time.sleep(0.001)
     LcdApi.__init__(self, num_lines, num_columns)
     cmd = self.LCD_FUNCTION
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)
コード例 #12
0
ファイル: i2c_lcd.py プロジェクト: dhylands/python_lcd
 def __init__(self, port, i2c_addr, num_lines, num_columns):
     self.port = port
     self.i2c_addr = i2c_addr
     self.bus = smbus.SMBus(port)
     self.bus.write_byte(self.i2c_addr, 0)
     time.sleep(0.020)    # Allow LCD time to powerup
     # Send reset 3 times
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     time.sleep(0.005)   # need to delay at least 4.1 msec
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     time.sleep(0.001)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     time.sleep(0.001)
     # Put LCD into 4 bit mode
     self.hal_write_init_nibble(self.LCD_FUNCTION)
     time.sleep(0.001)
     LcdApi.__init__(self, num_lines, num_columns)
     cmd = self.LCD_FUNCTION
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)
コード例 #13
0
ファイル: a9_i2c_lcd.py プロジェクト: ens4dz/python_lcd
 def __init__(self, i2c, i2c_addr, i2c_id, num_lines, num_columns):
     self.i2c_id = i2c_id
     self.i2c = i2c
     self.i2c_addr = i2c_addr
     self.i2c.transmit(self.i2c_id, self.i2c_addr, bytearray([0]),
                       CMD_TIMEOUT)
     sleep_ms(20)  # Allow LCD time to powerup
     # Send reset 3 times
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(5)  # need to delay at least 4.1 msec
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(1)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(1)
     # Put LCD into 4 bit mode
     self.hal_write_init_nibble(self.LCD_FUNCTION)
     sleep_ms(1)
     LcdApi.__init__(self, num_lines, num_columns)
     cmd = self.LCD_FUNCTION
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)
コード例 #14
0
ファイル: esp32_gpio_lcd.py プロジェクト: henry90/EE-629_IoT
    def __init__(self,
                 rs_pin,
                 enable_pin,
                 d0_pin=None,
                 d1_pin=None,
                 d2_pin=None,
                 d3_pin=None,
                 d4_pin=None,
                 d5_pin=None,
                 d6_pin=None,
                 d7_pin=None,
                 rw_pin=None,
                 backlight_pin=None,
                 num_lines=2,
                 num_columns=16):
        """Constructs the GpioLcd object. All of the arguments must be machine.Pin
        objects which describe which pin the given line from the LCD is
        connected to.

        When used in 4-bit mode, only D4, D5, D6, and D7 are physically
        connected to the LCD panel. This function allows you call it like
        GpioLcd(rs, enable, D4, D5, D6, D7) and it will interpret that as
        if you had actually called:
        GpioLcd(rs, enable, d4=D4, d5=D5, d6=D6, d7=D7)

        The enable 8-bit mode, you need pass d0 through d7.

        The rw pin isn't used by this library, but if you specify it, then
        it will be set low.
        """
        self.rs_pin = rs_pin
        self.enable_pin = enable_pin
        self.rw_pin = rw_pin
        self.backlight_pin = backlight_pin
        self._4bit = True
        if d4_pin and d5_pin and d6_pin and d7_pin:
            self.d0_pin = d0_pin
            self.d1_pin = d1_pin
            self.d2_pin = d2_pin
            self.d3_pin = d3_pin
            self.d4_pin = d4_pin
            self.d5_pin = d5_pin
            self.d6_pin = d6_pin
            self.d7_pin = d7_pin
            if self.d0_pin and self.d1_pin and self.d2_pin and self.d3_pin:
                self._4bit = False
        else:
            # This is really 4-bit mode, and the 4 data pins were just
            # passed as the first 4 arguments, so we switch things around.
            self.d0_pin = None
            self.d1_pin = None
            self.d2_pin = None
            self.d3_pin = None
            self.d4_pin = d0_pin
            self.d5_pin = d1_pin
            self.d6_pin = d2_pin
            self.d7_pin = d3_pin
        self.rs_pin.init(Pin.OUT)
        self.rs_pin.value(0)
        if self.rw_pin:
            self.rw_pin.init(Pin.OUT)
            self.rw_pin.value(0)
        self.enable_pin.init(Pin.OUT)
        self.enable_pin.value(0)
        self.d4_pin.init(Pin.OUT)
        self.d5_pin.init(Pin.OUT)
        self.d6_pin.init(Pin.OUT)
        self.d7_pin.init(Pin.OUT)
        self.d4_pin.value(0)
        self.d5_pin.value(0)
        self.d6_pin.value(0)
        self.d7_pin.value(0)
        if not self._4bit:
            self.d0_pin.init(Pin.OUT)
            self.d1_pin.init(Pin.OUT)
            self.d2_pin.init(Pin.OUT)
            self.d3_pin.init(Pin.OUT)
            self.d0_pin.value(0)
            self.d1_pin.value(0)
            self.d2_pin.value(0)
            self.d3_pin.value(0)
        if self.backlight_pin is not None:
            self.backlight_pin.init(Pin.OUT)
            self.backlight_pin.value(0)

        # See about splitting this into begin

        sleep_ms(20)  # Allow LCD time to powerup
        # Send reset 3 times
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(5)  # need to delay at least 4.1 msec
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(1)
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(1)
        cmd = self.LCD_FUNCTION
        if not self._4bit:
            cmd |= self.LCD_FUNCTION_8BIT
        self.hal_write_init_nibble(cmd)
        sleep_ms(1)
        LcdApi.__init__(self, num_lines, num_columns)
        if num_lines > 1:
            cmd |= self.LCD_FUNCTION_2LINES
        self.hal_write_command(cmd)
コード例 #15
0
    def __init__(self, rs_pin, enable_pin, d0_pin=None, d1_pin=None,
                 d2_pin=None, d3_pin=None, d4_pin=None, d5_pin=None,
                 d6_pin=None, d7_pin=None, rw_pin=None, backlight_pin=None,
                 num_lines=2, num_columns=16):
        """Constructs the GpioLcd object. All of the arguments must be Pin
        objects which describe which pin the given line from the LCD is
        connected to.

        When used in 4-bit mode, only D4, D5, D6, and D7 are physically
        connected to the LCD panel. This function allows you call it like
        GpioLcd(rs, enable, D4, D5, D6, D7) and it will interpret that as
        if you had actually called:
        GpioLcd(rs, enable, d4=D4, d5=D5, d6=D6, d7=D7)

        The enable 8-bit mode, you need pass d0 through d7.

        The rw pin isn't used by this library, but if you specify it, then
        it will be set low.
        """
        self.rs_pin = rs_pin
        self.enable_pin = enable_pin
        self.rw_pin = rw_pin
        self.backlight_pin = backlight_pin
        self._4bit = True
        if d4_pin and d5_pin and d6_pin and d7_pin:
            self.d0_pin = d0_pin
            self.d1_pin = d1_pin
            self.d2_pin = d2_pin
            self.d3_pin = d3_pin
            self.d4_pin = d4_pin
            self.d5_pin = d5_pin
            self.d6_pin = d6_pin
            self.d7_pin = d7_pin
            if self.d0_pin and self.d1_pin and self.d2_pin and self.d3_pin:
                self._4bit = False
        else:
            # This is really 4-bit mode, and the 4 data pins were just
            # passed as the first 4 arguments, so we switch things around.
            self.d0_pin = None
            self.d1_pin = None
            self.d2_pin = None
            self.d3_pin = None
            self.d4_pin = d0_pin
            self.d5_pin = d1_pin
            self.d6_pin = d2_pin
            self.d7_pin = d3_pin
        self.rs_pin.init(Pin.OUT)
        self.rs_pin.value(0)
        if self.rw_pin:
            self.rw_pin.init(Pin.OUT)
            self.rw_pin.value(0)
        self.enable_pin.init(Pin.OUT)
        self.enable_pin.value(0)
        self.d4_pin.init(Pin.OUT)
        self.d5_pin.init(Pin.OUT)
        self.d6_pin.init(Pin.OUT)
        self.d7_pin.init(Pin.OUT)
        self.d4_pin.value(0)
        self.d5_pin.value(0)
        self.d6_pin.value(0)
        self.d7_pin.value(0)
        if not self._4bit:
            self.d0_pin.init(Pin.OUT)
            self.d1_pin.init(Pin.OUT)
            self.d2_pin.init(Pin.OUT)
            self.d3_pin.init(Pin.OUT)
            self.d0_pin.value(0)
            self.d1_pin.value(0)
            self.d2_pin.value(0)
            self.d3_pin.value(0)
        if self.backlight_pin is not None:
            self.backlight_pin.init(Pin.OUT)
            self.backlight_pin.value(0)

        # See about splitting this into begin

        sleep_ms(20)   # Allow LCD time to powerup
        # Send reset 3 times
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(5)    # need to delay at least 4.1 msec
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(1)
        self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
        sleep_ms(1)
        cmd = self.LCD_FUNCTION
        if not self._4bit:
            cmd |= self.LCD_FUNCTION_8BIT
        self.hal_write_init_nibble(cmd)
        sleep_ms(1)
        LcdApi.__init__(self, num_lines, num_columns)
        if num_lines > 1:
            cmd |= self.LCD_FUNCTION_2LINES
        self.hal_write_command(cmd)
コード例 #16
0
 def __init__(self,
              rs_pin,
              enable_pin,
              d0_pin=None,
              d1_pin=None,
              d2_pin=None,
              d3_pin=None,
              d4_pin=None,
              d5_pin=None,
              d6_pin=None,
              d7_pin=None,
              rw_pin=None,
              backlight_pin=None,
              num_lines=2,
              num_columns=16):
     self.rs_pin = rs_pin
     self.enable_pin = enable_pin
     self.rw_pin = rw_pin
     self.backlight_pin = backlight_pin
     self._4bit = True
     if d4_pin and d5_pin and d6_pin and d7_pin:
         self.d0_pin = d0_pin
         self.d1_pin = d1_pin
         self.d2_pin = d2_pin
         self.d3_pin = d3_pin
         self.d4_pin = d4_pin
         self.d5_pin = d5_pin
         self.d6_pin = d6_pin
         self.d7_pin = d7_pin
         if self.d0_pin and self.d1_pin and self.d2_pin and self.d3_pin:
             self._4bit = False
     else:
         self.d0_pin = None
         self.d1_pin = None
         self.d2_pin = None
         self.d3_pin = None
         self.d4_pin = d0_pin
         self.d5_pin = d1_pin
         self.d6_pin = d2_pin
         self.d7_pin = d3_pin
     self.rs_pin.init(Pin.OUT)
     self.rs_pin.off()
     if self.rw_pin:
         self.rw_pin.init(Pin.OUT)
         self.rw_pin.off()
     self.enable_pin.init(Pin.OUT)
     self.enable_pin.off()
     self.d4_pin.init(Pin.OUT)
     self.d5_pin.init(Pin.OUT)
     self.d6_pin.init(Pin.OUT)
     self.d7_pin.init(Pin.OUT)
     self.d4_pin.off()
     self.d5_pin.off()
     self.d6_pin.off()
     self.d7_pin.off()
     if not self._4bit:
         self.d0_pin.init(Pin.OUT)
         self.d1_pin.init(Pin.OUT)
         self.d2_pin.init(Pin.OUT)
         self.d3_pin.init(Pin.OUT)
         self.d0_pin.off()
         self.d1_pin.off()
         self.d2_pin.off()
         self.d3_pin.off()
     if self.backlight_pin is not None:
         self.backlight_pin.init(Pin.OUT)
         self.backlight_pin.off()
     sleep_ms(20)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(5)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(1)
     self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
     sleep_ms(1)
     cmd = self.LCD_FUNCTION
     if not self._4bit:
         cmd |= self.LCD_FUNCTION_8BIT
     self.hal_write_init_nibble(cmd)
     sleep_ms(1)
     LcdApi.__init__(self, num_lines, num_columns)
     if num_lines > 1:
         cmd |= self.LCD_FUNCTION_2LINES
     self.hal_write_command(cmd)