Last active
December 2, 2017 13:18
-
-
Save asukiaaa/d2940ce70fee061297ae26a77181d9e9 to your computer and use it in GitHub Desktop.
I2C LCD controller library for AQM1602. I created pip library, so prease use it. https://github.com/asukiaaa/asukiaaa_py_i2c_lcd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smbus | |
I2C_BUS_NUM = 1 | |
I2C_LCD_ADDR = 0x3e | |
LCD_SET_DDRAM_ADDR = 0x80 | |
class I2cLcd: | |
i2c = "" | |
address = "" | |
register_setting = 0x00 | |
register_display = 0x40 | |
col_num = 16 | |
def __init__(self, bus_num, address): | |
self.address = address | |
self.i2c = smbus.SMBus(bus_num) | |
# init | |
self.i2c.write_i2c_block_data( self.address, self.register_setting, [0x38, 0x39, 0x14, 0x70, 0x56, 0x6c] ) | |
self.i2c.write_i2c_block_data( self.address, self.register_setting, [0x38, 0x0c, 0x01] ) | |
def setCursor(self, col, row): | |
row_offset = [ 0x00, 0x40 ] | |
self.i2c.write_byte_data( self.address, self.register_setting, LCD_SET_DDRAM_ADDR | (col + row_offset[row]) ) | |
def write(self, str): | |
counter = 0 | |
for c in list(str): | |
self.i2c.write_byte_data( self.address, self.register_display, ord(c) ) | |
counter += 1 | |
if counter >= self.col_num: | |
break | |
if __name__ == "__main__": | |
lcd = I2cLcd(I2C_BUS_NUM, I2C_LCD_ADDR) | |
lcd.setCursor(0,0) | |
lcd.write("Hello") | |
lcd.setCursor(3,1) | |
lcd.write("World") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment