Problem with LCD over UART after firmware update
Posted: Sun Oct 23, 2016 8:19 pm
I was using a LCD display with an UART interface some time ago. Few days ago I've updated the firmware to latest and I've notices that the UART doesn't have .send() method any more, only .write()
I had a code like:
now with write I can't make it to work - LCD doesn't display anything. Are there any other UART changes?
My LCD class:
I had a code like:
Code: Select all
x.send(chr(1)+"some text"+chr(0xFF))
My LCD class:
Code: Select all
import pyb
class LCD(object):
END = chr(0xFF)
def __init__(self, device, rows, columns):
self.commands = {
'display_string': chr(1),
'set_cursor_position': chr(2),
'clear_line': chr(3),
'clear': chr(4),
'set_lcd_type': chr(5),
'backlight': chr(7)
}
self.device = device
self.rows = rows
self.columns = columns
self.connection = None
def configure(self):
self.connection = pyb.UART(self.device, 9600)
pyb.delay(1000)
self.execute_command('set_lcd_type', chr(self.rows) + chr(self.columns))
self.clear()
def clear(self):
self.execute_command('clear', '')
def clear_line(self, line):
self.execute_command('clear_line', chr(line))
def set_backlight(self, brightness):
self.execute_command('backlight', chr(brightness))
def set_cursor_position(self, row, column):
self.execute_command('set_cursor_position', chr(row) + chr(column))
def display_string(self, string):
self.execute_command('display_string', string)
def close(self):
self.connection.deinit()
def execute_command(self, command, payload):
self.connection.send(self.commands[command] + payload + self.END)
Code: Select all
def do_serial_demo():
lcd = LCD(3, rows=4, columns=20)
lcd.configure()
lcd.set_backlight(25)
accel = pyb.Accel()
while True:
lcd.clear()
lcd.set_cursor_position(1, 1)
lcd.display_string(str(accel.x()))
lcd.set_cursor_position(2, 1)
lcd.display_string(str(accel.y()))
pyb.delay(500)