module:micropython:esp32displaykey:esp32displaykey
This is an old revision of the document!
Table of Contents
MicroPython: Esp32DisplayKey
Übersicht
KeyPad4x4
- 4×4 KeyPad: 8x IOPin: 4x Input(34, 35, 36, 39) und 4x Output(12, 13, 14, 27)
- Keyboard-KeyCode-Buffer: SIZE_KEYCODEBUFFER = 5
- minimale Zeitauflösung Erkennung einer Taste: TIME_KEYPRESSED = 0.1
- minimale Zeit zur Erkennung von Tastenwiederholungen: ZeitTIME_KEYREPETITION = 0.5
- Eigener Thread mit permanenter Tastatur-Abfrage
- MainLoop: periodische Abfrage GetKeyCode()
- Keys beim IT01:
Col : 0 1 2 3 Row 0 : [1]<24> [2]<40> [3]<72> [A]<136> Row 1 : [4]<20> [5]<36> [6]<68> [B]<132> Row 2 : [7]<18> [8]<34> [9]<66> [C]<130> Row 3 : [*]<17> [0]<33> [#]<65> [D]<129>
LCDisplayI2C
- Ansteuerung über I2C (PCF8574)
- Eigener Thread zur Verhinderung von Blockaden ohne time-sleep in MainLoop
- permanente Ausgabe von Zeilen/Spalten in DisplayThread
Version
Beschreibung
Ausgabe MicroPython-Terminal: Esp32CheckDisplayKey.py
>>> >>> *** CheckEsp32DisplayKey: begin 66 66 66 34 34 40 40 65 65 65 68 68 136 130 129 40 *** CheckEsp32DisplayKey: end >>>
Haupt-Module: Esp32CheckDisplayKey.py
# import time import machine # import Define as DEF import Thread as THR import LCDisplayI2C as LCD import ThreadDisplay as TDP import Keyboard4x4 as KBD # # #------------------------------------------------------------------ # Main #------------------------------------------------------------------ if ('__main__' == __name__): print('*** CheckEsp32DisplayKey: begin') # # Display I2CDisplay = machine.SoftI2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=2000000) LCDisplay = LCD.CLCDisplayI2C(I2CDisplay, DEF.I2CADDRESS_LCDISPLAY_T, \ DEF.LCDISPLAY_COUNT_ROWS, DEF.LCDISPLAY_COUNT_COLUMNS) ThreadDisplay = TDP.CThreadDisplay(I2CDisplay, LCDisplay) # Keyboard Keyboard = KBD.CKeyboard4x4(DEF.PIN_KEYBOARD_IN0, DEF.PIN_KEYBOARD_IN1, DEF.PIN_KEYBOARD_IN2, DEF.PIN_KEYBOARD_IN3, DEF.PIN_KEYBOARD_OUT0, DEF.PIN_KEYBOARD_OUT1, DEF.PIN_KEYBOARD_OUT2, DEF.PIN_KEYBOARD_OUT3) # Open ThreadDisplay.Open() Keyboard.Open() # # MainLoop .... for I in range(0, 10000): KC = Keyboard.GetKeyCode() if (0 < KC): print(KC) time.sleep(0.001) # # Close Keyboard.Close() ThreadDisplay.Close() # print('*** CheckEsp32DisplayKey: end') # #
Main-Program: Esp32CheckUart.py
Library-Module: Uart.py
Library-Module: .py
Library-Module: .py
Library-Module: .py
Library-Module: .py
Library-Module: .py
Library-Module: LCDisplay.py
# import time # class CLCDisplay: # HD44780 LCD controller command set LCD_CLR = 0x01 # DB0: clear display LCD_HOME = 0x02 # DB1: return to home position # LCD_ENTRY_MODE = 0x04 # DB2: set entry mode LCD_ENTRY_INC = 0x02 # --DB1: increment LCD_ENTRY_SHIFT = 0x01 # --DB0: shift # LCD_ON_CTRL = 0x08 # DB3: turn lcd/cursor on LCD_ON_DISPLAY = 0x04 # --DB2: turn display on LCD_ON_CURSOR = 0x02 # --DB1: turn cursor on LCD_ON_BLINK = 0x01 # --DB0: blinking cursor # LCD_MOVE = 0x10 # DB4: move cursor/display LCD_MOVE_DISP = 0x08 # --DB3: move display (0-> move cursor) LCD_MOVE_RIGHT = 0x04 # --DB2: move right (0-> left) # LCD_FUNCTION = 0x20 # DB5: function set LCD_FUNCTION_8BIT = 0x10 # --DB4: set 8BIT mode (0->4BIT mode) LCD_FUNCTION_2LINES = 0x08 # --DB3: two lines (0->one line) LCD_FUNCTION_10DOTS = 0x04 # --DB2: 5x10 font (0->5x7 font) LCD_FUNCTION_RESET = 0x30 # See "Initializing by Instruction" section # LCD_CGRAM = 0x40 # DB6: set CG RAM address LCD_DDRAM = 0x80 # DB7: set DD RAM address # LCD_RS_CMD = 0 LCD_RS_DATA = 1 # LCD_RW_WRITE = 0 LCD_RW_READ = 1 # def __init__(self, num_lines, num_columns): self.num_lines = num_lines if self.num_lines > 4: self.num_lines = 4 self.num_columns = num_columns if self.num_columns > 40: self.num_columns = 40 self.CursorY = 0 self.CursorX = 0 self.ImpliedNewline = False self.Backlight = True self.DisplayOff() self.BacklightOn() self.Clear() self.hal_write_command(self.LCD_ENTRY_MODE | self.LCD_ENTRY_INC) self.HideCursor() self.DisplayOn() # def Clear(self): self.hal_write_command(self.LCD_CLR) self.hal_write_command(self.LCD_HOME) self.CursorY = 0 self.CursorX = 0 # def ShowCursor(self): self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | self.LCD_ON_CURSOR) # def HideCursor(self): self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) # def BlinkCursorOn(self): self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | self.LCD_ON_CURSOR | self.LCD_ON_BLINK) # def BlinkCursorOff(self): self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | self.LCD_ON_CURSOR) # def DisplayOn(self): self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) # def DisplayOff(self): self.hal_write_command(self.LCD_ON_CTRL) # def BacklightOn(self): self.backlight = True self.hal_backlight_on() # def BacklightOff(self): self.backlight = False self.hal_backlight_off() # def MoveTo(self, cursory, cursorx): self.CursorY = cursory self.CursorX = cursorx Address = cursorx & 0x3f if cursory & 1: Address += 0x40 # Lines 1 & 3 add 0x40 if cursory & 2: # Lines 2 & 3 add number of columns Address += self.num_columns self.hal_write_command(self.LCD_DDRAM | Address) # def PutCharacter(self, character): if character == '\n': if self.implied_newline: self.implied_newline = False else: self.CursorX = self.num_columns else: self.hal_write_data(ord(character)) self.CursorX += 1 if self.CursorX >= self.num_columns: self.CursorX = 0 self.CursorY += 1 self.implied_newline = (character != '\n') if self.CursorY >= self.num_lines: self.CursorY = 0 self.MoveTo(self.CursorY, self.CursorX) # def PutText(self, text): for C in text: self.PutCharacter(C) # def custom_char(self, location, charmap): location &= 0x7 self.hal_write_command(self.LCD_CGRAM | (location << 3)) self.hal_sleep_us(40) for i in range(8): self.hal_write_data(charmap[i]) self.hal_sleep_us(40) self.MoveTo(self.cursor_y, self.cursor_x) # def hal_backlight_on(self): pass # def hal_backlight_off(self): pass # def hal_write_command(self, cmd): raise NotImplementedError # def hal_write_data(self, data): raise NotImplementedError # def hal_sleep_us(self, usecs): time.sleep_us(usecs) # #
Library-Module: Define.py
# #----------------------------------------- # Uart0 / 1 / 2 #----------------------------------------- ID_UART0 = 0 PIN_UART0_TX = 1 # USB PIN_UART0_RX = 3 # USB # ID_UART1 = 1 PIN_UART1_RX = 25 # 9 - not usable PIN_UART1_TX = 26 # 10 - not usable # ID_UART2 = 2 PIN_UART2_RX = 16 PIN_UART2_TX = 17 # #----------------------------------------- # LCDisplayI2C #----------------------------------------- I2CADDRESS_LCDISPLAY_T = 0x27 I2CADDRESS_LCDISPLAY_A = 0x3F # LCDISPLAY_COUNT_ROWS = 4 LCDISPLAY_COUNT_COLUMNS = 20 # #----------------------------------------- # Keyboard4x4 #----------------------------------------- PIN_KEYBOARD_IN0 = 39 PIN_KEYBOARD_IN1 = 36 PIN_KEYBOARD_IN2 = 34 PIN_KEYBOARD_IN3 = 35 PIN_KEYBOARD_OUT0 = 13 PIN_KEYBOARD_OUT1 = 12 PIN_KEYBOARD_OUT2 = 14 PIN_KEYBOARD_OUT3 = 27 # SIZE_KEYCODEBUFFER = 5 TIME_KEYPRESSED = 0.1 TIME_KEYREPETITION = 0.5 #
Entwicklung
211224 : Versuch zur Thread-Entkopplung
- Multithreading mit LCDisplay in MicroPython zeigt jetzt (hoffentlich) keine Mucken mehr….
- zweiter Thread zur Tastatur-Überwachung (ohne Blockade)
- Trick: die CommandExecutionTime-Blockaden des Displays in einen Thread auszulagern !
- Klasse CDisplay mit eigenem Thread self.Thread und CCommandList(Row, Col, Text)
- Commands:
- Clear()
- Write(R, C, T)
211223 : Basis
- ganz grosses Problem mit MultiThreading:
- Keyboard4x4 mit eigenem Key-Erkennungs-Thread
- Display mit eigenem Periodic-Display-Thread
- laufen nicht unabhängig voneinander !!! Ganz grosser MIST!!!!
Open Hard- & Software [ DokuWiki WebSites MediaWiki NextCloud ]
module/micropython/esp32displaykey/esp32displaykey.1640437468.txt.gz · Last modified: 2021/12/25 15:04 (external edit)