"""LCD test for the airband bridge (rev B). MicroPython on a Pico 2. Run it from the Mac, with the Pico on USB: uvx mpremote cp bridge/firmware/lcd.py :lcd.py + run bridge/firmware/lcd_test.py The 12 V supply must be on. USB powers the Pico but not the LCD. If the LCD has no power, the test waits up to a minute for it. What the LCD should show, in order: 1. every cell a solid block all 32 cells work 2. 0123456789ABCDEF / abcdefghijklmnop all four data lines carry the right bit 3. "Airband RX" / "LCD test OK" stays on the screen The Pico's green LED blinks while the test runs and stays on at the end. The LCD routine itself is in lcd.py. """ from machine import Pin import time from lcd import Lcd, wait_for_power, NAMES, BLOCK def check_lines(lcd): """Let all five lines go, then pull each low in turn. Returns a list of problems. This finds a line shorted to ground and two lines bridged together. It cannot see a line that simply isn't connected.""" lines = [lcd.rs] + lcd.data for line in lines: line.set(True) time.sleep_ms(2) idle = [line.read() for line in lines] print('released lines read:', ', '.join('{}={}'.format(n, v) for n, v in zip(NAMES, idle))) problems = [] for name, value in zip(NAMES, idle): if not value: problems.append(name + ' stays low when released: shorted to ground, or the LCD pin has no pull-up') for i, line in enumerate(lines): line.set(False) time.sleep_ms(1) for j in range(i + 1, len(lines)): if idle[j] and not lines[j].read(): problems.append('{} goes low when {} is pulled low: the two are bridged'.format(NAMES[j], NAMES[i])) line.set(True) time.sleep_ms(1) return problems def hold(led, seconds): for _ in range(int(seconds * 4)): led.toggle() time.sleep_ms(250) def main(): led = Pin('LED', Pin.OUT, value=1) lcd = Lcd() if not wait_for_power(lcd): print('PROBLEM: still no 5 V at the LCD. Nothing was written to it.') return problems = check_lines(lcd) for p in problems: print('PROBLEM:', p) if not problems: print('line check passed: no shorts to ground, no bridges') lcd.start() print('1/3 solid blocks') lcd.write(0, BLOCK * 16) lcd.write(1, BLOCK * 16) hold(led, 3) print('2/3 character rows') lcd.write(0, '0123456789ABCDEF') lcd.write(1, 'abcdefghijklmnop') hold(led, 4) print('3/3 final message') lcd.write(0, 'Airband RX') lcd.write(1, 'LCD test OK') led.value(1) print('done') main()