Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One linefeed too many, in case the line is filled up to the last character (4x20 display) / CircuitPython Port #28

Open
CrossLAN opened this issue Jan 2, 2021 · 2 comments

Comments

@CrossLAN
Copy link

CrossLAN commented Jan 2, 2021

@dhylands
In a 4x20 display, if I fill the line to the last row, it skips the following line without replacement and the following line remains empty. This is independent of whether I put a \n at the end of the line or not.

If I fill the display only with 19 characters instead of the 20 possible characters, the line jump to the following line works.

Is this intentional or is it possible to turn it off?
Or am I doing something wrong?

Here is my code for testing

import board
import busio
from time import sleep, monotonic
from lcd.circuitpython_i2c_lcd import I2cLcd

# The PCF8574 has a jumper selectable address: 0x20 - 0x27
DEFAULT_I2C_ADDR = 0x26

def test_main():
    """Test function for verifying basic functionality."""
    print("Running test_main")
    i2c = busio.I2C(board.SCL, board.SDA)

    # circuitpython seems to require locking the i2c bus
    while i2c.try_lock():
        pass

    # 2 lines, 16 characters per line
    #lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)

    #4 lines, 20 characters per line
    lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 4, 20)

    while True:
        lcd.clear()
        lcd.move_to(0, 0)
        lcd.putstr("It works!\nSecond line\n")
        print("It works!\nSecond line\n")
        sleep(2)
        lcd.clear()
        lcd.move_to(0, 0)
        lcd.putstr("12345678901234567890\n123xxxx890123yyyy890\n")
        print("12345678901234567890\n123xxxx890123yyyy890\n")
        sleep(2)
        print("Ende\n")

#if __name__ == "__main__":
test_main()
@CrossLAN
Copy link
Author

CrossLAN commented Jan 3, 2021

@dhylands

I walked through your code and the following change in lcd_api.py will fix this issue:

    def putchar(self, char):
        """Writes the indicated character to the LCD at the current cursor
        position, and advances the cursor by one position.
        """
        if char != '\n':
            self.hal_write_data(ord(char))
            self.cursor_x += 1
        if self.cursor_x >= self.num_columns or char == '\n':
            self.cursor_x = 0
            if char == '\n':
                self.cursor_y += 1
            if self.cursor_y >= self.num_lines:
                self.cursor_y = 0
            self.move_to(self.cursor_x, self.cursor_y)

@CrossLAN
Copy link
Author

CrossLAN commented Jan 3, 2021

@dhylands I created a pull request #29 to get this fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant