Skip to content

Custom characters #9

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

Merged
merged 1 commit into from
Feb 20, 2017
Merged

Custom characters #9

merged 1 commit into from
Feb 20, 2017

Conversation

mcauser
Copy link
Contributor

@mcauser mcauser commented Feb 20, 2017

Custom characters are 5x8 pixels and can be created using a 8 byte bytearray, where the first element is the top row and last element is the bottom row of pixels. Least significant bit is the right edge pixel and only 5 bits of significance are used.

Happy Face (where .=0, #=1)
..... == 0b00000000 == 0x00
.#.#. == 0b00001010 == 0x0A
..... == 0b00000000 == 0x00
..#.. == 0b00000100 == 0x04
..... == 0b00000000 == 0x00
#...# == 0b00010001 == 0x11
.###. == 0b00001110 == 0x0E
..... == 0b00000000 == 0x00

lcd.custom_char(0, bytearray([0x00,0x0A,0x00,0x04,0x00,0x11,0x0E,0x00]))
lcd.putchar(chr(0))
lcd.putchar(b'\x00')

Side note: the characters are displayed from cg-ram by reference. Once you have printed a custom character to the screen, you can overwrite the custom character and all visible instances will also update. Useful for drawing animations and graphs.

img_9158b

lcd/lcd_api.py Outdated
"""Writes a custom character to the LCD"""
location &= 0x7
self.putchar(chr(location))

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lcd.putchar(chr(location)) does the same thing as lcd.putcustom(location)

Do you think we still need putcustom ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only extra benefit is restricting to 0-7.
I'll scrap it with an amend.

@dhylands
Copy link
Owner

It would be good to add mention of custom characters in the readme as well.

@mcauser
Copy link
Contributor Author

mcauser commented Feb 20, 2017

I was thinking an /examples folder, with 20+ examples I'm porting across

@mcauser
Copy link
Contributor Author

mcauser commented Feb 20, 2017

I'm also working on a SeeedStudio RGB LCD. Two I2C devices. One for the LCD and one for the backlight pwm driver. Separate PR coming shortly.

@dhylands
Copy link
Owner

That would be cool.

Perhaps put a README.md in the examples folder which has a summary of the example. I really liked the picture you posted with the battery gauge.

@mcauser mcauser force-pushed the custom_chars branch 2 times, most recently from 58f90bf to e71ab02 Compare February 20, 2017 12:53
@mcauser
Copy link
Contributor Author

mcauser commented Feb 20, 2017

img_9161b

lcd = I2cLcd(i2c, 0x27, 4, 20)

lcd.custom_char(0, bytearray([0x1F,0x10,0x17,0x14,0x14,0x14,0x14,0x14]))
lcd.custom_char(1, bytearray([0x1F,0x00,0x1F,0x00,0x00,0x00,0x00,0x00]))
lcd.custom_char(2, bytearray([0x1F,0x01,0x1D,0x05,0x05,0x05,0x05,0x05]))
lcd.custom_char(3, bytearray([0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05]))
lcd.custom_char(4, bytearray([0x05,0x05,0x05,0x05,0x05,0x1D,0x01,0x1F]))
lcd.custom_char(5, bytearray([0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x1F]))
lcd.custom_char(6, bytearray([0x14,0x14,0x14,0x14,0x14,0x17,0x10,0x1F]))
lcd.custom_char(7, bytearray([0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14]))

lcd.clear()
lcd.putstr(chr(0) + chr(1)*18 + chr(2))
lcd.putstr(chr(7))
lcd.move_to(19,1)
lcd.putstr(chr(3))
lcd.putstr(chr(7))
lcd.move_to(19,2)
lcd.putstr(chr(3))
lcd.putstr(chr(6) + chr(5)*18 + chr(4))

lcd.move_to(2,1)
lcd.putstr("Borders are more")
lcd.move_to(1,2)
lcd.putstr("fun than batteries")

@dhylands
Copy link
Owner

Sweet.

For the examples, it would probably be good to arrange them so that they take the lcd object as a parameter. That way they could be used with I2C/GPIO etc without having to edit them.

Perhaps something along the lines of say creating a borders.py example which contained:

def border_example(lcd):
    lcd.custom_char(0, bytearray([0x1F,0x10,0x17,0x14,0x14,0x14,0x14,0x14]))
    ...

and then to actually use the example:

>>> import border
>>> lcd = I2cLcd(i2c, 0x27, 4, 20)
>>> border.border_example(lcd)

@dhylands dhylands merged commit 50976ac into dhylands:master Feb 20, 2017
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

Successfully merging this pull request may close these issues.

2 participants