From: Tyler Peppy <61562476+T-622@users.noreply.github.com> Date: Fri, 9 Apr 2021 16:20:27 +0000 (-0400) Subject: Merge pull request #6 from n0n3nt1ty/main X-Git-Url: https://vault307.fbx.one/gitweb/RPI-PICO-I2C-LCD.git/commitdiff_plain/25cec0dd31b884b4141a6e649d45befae612706f?hp=956a0c32a4fbe580e472e93aa4957e2730ef8ed5 Merge pull request #6 from n0n3nt1ty/main Update pico_i2c_lcd.py for GC Code --- diff --git a/pico_i2c_lcd.py b/pico_i2c_lcd.py index d81ee85..fd83b8b 100644 --- a/pico_i2c_lcd.py +++ b/pico_i2c_lcd.py @@ -1,4 +1,5 @@ import utime +import gc from lcd_api import LcdApi from machine import I2C @@ -35,6 +36,7 @@ class I2cLcd(LcdApi): if num_lines > 1: cmd |= self.LCD_FUNCTION_2LINES self.hal_write_command(cmd) + gc.collect() def hal_write_init_nibble(self, nibble): # Writes an initialization nibble to the LCD. @@ -42,14 +44,17 @@ class I2cLcd(LcdApi): byte = ((nibble >> 4) & 0x0f) << SHIFT_DATA self.i2c.writeto(self.i2c_addr, bytes([byte | MASK_E])) self.i2c.writeto(self.i2c_addr, bytes([byte])) + gc.collect() def hal_backlight_on(self): # Allows the hal layer to turn the backlight on self.i2c.writeto(self.i2c_addr, bytes([1 << SHIFT_BACKLIGHT])) + gc.collect() def hal_backlight_off(self): #Allows the hal layer to turn the backlight off self.i2c.writeto(self.i2c_addr, bytes([0])) + gc.collect() def hal_write_command(self, cmd): # Write a command to the LCD. Data is latched on the falling edge of E. @@ -64,6 +69,7 @@ class I2cLcd(LcdApi): if cmd <= 3: # The home and clear commands require a worst case delay of 4.1 msec utime.sleep_ms(5) + gc.collect() def hal_write_data(self, data): # Write data to the LCD. Data is latched on the falling edge of E. @@ -77,3 +83,4 @@ class I2cLcd(LcdApi): ((data & 0x0f) << SHIFT_DATA)) self.i2c.writeto(self.i2c_addr, bytes([byte | MASK_E])) self.i2c.writeto(self.i2c_addr, bytes([byte])) + gc.collect()