module:micropython:esp32uartpcuc:esp32uartpcuc
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| module:micropython:esp32uartpcuc:esp32uartpcuc [2021/12/21 10:09] – [Links] omdevelop | module:micropython:esp32uartpcuc:esp32uartpcuc [2022/09/13 11:58] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== MicroPython: | + | ====== MicroPython: |
| [[http:// | [[http:// | ||
| [ | [ | ||
| Line 8: | Line 8: | ||
| ] | ] | ||
| - | ===== Übersicht ===== | + | ===== Übersicht ===== |
| + | |||
| + | ==== IT01 ==== | ||
| + | * **1** **2** **3** **4** | ||
| + | * **5** **6** **7** **8** | ||
| + | * **9** **A** **B** **C** | ||
| + | * **0** **S** **T** **N** | ||
| + | |||
| + | ==== Neues Modul: 4x4 KeyPad (entsprechend IT01-FrontKeys) ==== | ||
| + | * 8x IOPin: 4x Input(34, 35, 36, 39) und 4x Output(12, 13, 14, 27) | ||
| + | |||
| + | |||
| + | |||
| + | ==== LocalSystem ==== | ||
| + | |||
| + | * Kapselung aller System-Variablen (CpuTemperature, | ||
| + | * Collector für Commands/ | ||
| + | * LedSystem | ||
| + | * LedQuad(Uart1, | ||
| + | * LCDisplayI2C(PCF8574, | ||
| + | * Temperature / Humidity(DHT22: | ||
| + | * 4x4 KeyPad (entsprechend IT01-FrontKeys) | ||
| + | * Pressure/ | ||
| + | * GetChipID (Examples-Esp32-GetChipID) | ||
| + | |||
| + | |||
| + | ==== UCSystem ==== | ||
| + | * LCDisplayI2C((PCF8574, | ||
| + | * Quertz-Keyboard(PS/ | ||
| + | * Paul Stoffregen Arduino-Library **PS2Keyboard** | ||
| + | * {{https:// | ||
| + | |||
| + | ==== CommandReceiver(relative to Esp32) ==== | ||
| + | * PC-[Uart1]: Command< | ||
| + | * PC/ | ||
| + | * PC/ | ||
| + | * Extension later: PC-[Lan]: Command< | ||
| + | |||
| + | ==== Dispatcher(relative to Esp32) ==== | ||
| + | * LocalSystemDispatcher[Spi, | ||
| + | * ExternalControllerDispatcher[Uart2]: | ||
| + | ==== Dataflow ==== | ||
| + | |||
| + | < | ||
| + | | ||
| + | while (MainLoop): | ||
| + | # | ||
| + | # Esp32< | ||
| + | # | ||
| + | # From PC: receive command -> Pass to Local or UC as command | ||
| + | CommandLine = UartPC.ReadLine() # RxLines-Fifo | ||
| + | AnalyseCommandLine(CommandLine) # -> ChildUC | ||
| + | # # | ||
| + | # # Esp32< | ||
| + | # # | ||
| + | # CommandLine = BtPC.ReadLine() # RxLines-Fifo | ||
| + | # AnalyseCommandLine(CommandLine) # -> ChildUC | ||
| + | # # | ||
| + | # # Esp32< | ||
| + | # # | ||
| + | # CommandLine = WlanPC.ReadLine() # RxLines-Fifo | ||
| + | # AnalyseCommandLine(CommandLine) # -> ChildUC | ||
| + | # # # | ||
| + | # # # Esp32< | ||
| + | # # # | ||
| + | # # CommandLine = LanPC.ReadLine() # RxLines-Fifo | ||
| + | # # AnalyseCommandLine(CommandLine) # -> ChildUC | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # PC< | ||
| + | # | ||
| + | ResponseLine = LocalSystem.ReadLine() # RxLines-Fifo | ||
| + | UartPC.TransmitResponse(ResponseLine) | ||
| + | BtPC.TransmitResponse(ResponseLine) | ||
| + | WlanPC.TransmitResponse(ResponseLine) | ||
| + | LanPC.TransmitResponse(ResponseLine) | ||
| + | # | ||
| + | # Esp32< | ||
| + | # | ||
| + | ResponseLine = UartUC.ReadLine() # RxLines-Fifo | ||
| + | UartPC.TransmitResponse(ResponseLine) | ||
| + | BtPC.TransmitResponse(ResponseLine) | ||
| + | WlanPC.TransmitResponse(ResponseLine) | ||
| + | LanPC.TransmitResponse(ResponseLine) | ||
| + | # | ||
| + | </ | ||
| + | |||
| ==== Links ==== | ==== Links ==== | ||
| ===== Version ===== | ===== Version ===== | ||
| - | {{: | + | {{: |
| ===== Beschreibung ===== | ===== Beschreibung ===== | ||
| Line 19: | Line 108: | ||
| **Ausgabe MicroPython-Terminal Esp32CheckUart.py** | **Ausgabe MicroPython-Terminal Esp32CheckUart.py** | ||
| <code python> | <code python> | ||
| - | >>> | ||
| - | >>> | ||
| - | CBUartOnTxLine[000 < | ||
| - | CBUartOnRxLine[000 < | ||
| - | CBUartOnTxLine[111 < | ||
| - | CBUartOnTxLine[222 < | ||
| - | CBUartOnRxLine[111 < | ||
| - | CBUartOnTxLine[333 < | ||
| - | CBUartOnRxLine[222 < | ||
| - | CBUartOnTxLine[444 < | ||
| - | CBUartOnRxLine[333 < | ||
| - | CBUartOnTxLine[555 < | ||
| - | CBUartOnRxLine[444 < | ||
| - | CBUartOnTxLine[666 < | ||
| - | CBUartOnRxLine[555 < | ||
| - | CBUartOnTxLine[777 < | ||
| - | CBUartOnRxLine[666 < | ||
| - | CBUartOnTxLine[888 < | ||
| - | CBUartOnRxLine[777 < | ||
| - | CBUartOnTxLine[999 < | ||
| - | CBUartOnRxLine[888 < | ||
| - | CBUartOnRxLine[999 < | ||
| - | *** Esp32CheckUart: | ||
| - | >>> | ||
| </ | </ | ||
| Line 48: | Line 113: | ||
| **Main-Program: | **Main-Program: | ||
| <code python> | <code python> | ||
| - | # | ||
| - | import time as TIM | ||
| - | # | ||
| - | import Define as DEF | ||
| - | import Uart as UART | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | def CBUartOnRxLine(rxline): | ||
| - | print(' | ||
| - | # | ||
| - | def CBUartOnTxLine(txline): | ||
| - | print(' | ||
| - | # | ||
| - | # | ||
| - | # Main - Uart | ||
| - | # | ||
| - | if (' | ||
| - | print(' | ||
| - | # | ||
| - | Uart = UART.CUart(DEF.ID_UART1, | ||
| - | Uart.SetOnRxLine(CBUartOnRxLine) | ||
| - | Uart.SetOnTxLine(CBUartOnTxLine) | ||
| - | Uart.Open() | ||
| - | # | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | TIM.sleep(2.0) | ||
| - | # | ||
| - | Uart.Close() | ||
| - | # | ||
| - | print(' | ||
| - | # | ||
| - | # | ||
| </ | </ | ||
| **Library-Module: | **Library-Module: | ||
| <code python> | <code python> | ||
| - | # | ||
| - | import time | ||
| - | from machine import UART | ||
| - | # | ||
| - | import Define | ||
| - | import Lines as LIN | ||
| - | import Thread as THR | ||
| - | # | ||
| - | class CUart(): | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | def __init__(self, | ||
| - | self.Uart = UART(uartid, | ||
| - | self.TxLines = LIN.CLines() | ||
| - | self.RxLines = LIN.CLines() | ||
| - | self.OnRxLine = None | ||
| - | self.OnTxLine = None | ||
| - | self.Thread = THR.CThread(self.CBOnStart, | ||
| - | self.RxLine = '' | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | def SetOnRxLine(self, | ||
| - | self.OnRxLine = onrxline | ||
| - | def SetOnTxLine(self, | ||
| - | self.OnTxLine = ontxline | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | def CBOnStart(self, | ||
| - | return | ||
| - | def CBOnBusy(self, | ||
| - | while (THR.stBusy == thread.State): | ||
| - | # first: RxData | ||
| - | while (0 < self.Uart.any()): | ||
| - | C = self.Uart.read(1) | ||
| - | if (b' | ||
| - | if (0 < len(self.RxLine)): | ||
| - | self.RxLines.Push(self.RxLine) | ||
| - | self.RxLine = ''; | ||
| - | else: | ||
| - | self.RxLine += C.decode(" | ||
| - | if (0 < self.RxLines.Count()): | ||
| - | Line = self.RxLines.Pop() | ||
| - | if (None != self.OnRxLine): | ||
| - | self.OnRxLine(Line) | ||
| - | # second: TxData | ||
| - | if (0 < self.TxLines.Count()): | ||
| - | Line = self.TxLines.Pop() | ||
| - | self.Uart.write(Line + ' | ||
| - | if (None != self.OnTxLine): | ||
| - | self.OnTxLine(Line) | ||
| - | def CBOnAbort(self, | ||
| - | return | ||
| - | def CBOnEnd(self, | ||
| - | return | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | def Open(self): | ||
| - | self.Uart.init(baudrate=115200)#, | ||
| - | self.Thread.Start() | ||
| - | self.RxLine = '' | ||
| - | return | ||
| - | # | ||
| - | def Close(self): | ||
| - | self.Thread.Abort() | ||
| - | self.Uart.deinit() | ||
| - | return | ||
| - | # | ||
| - | def TxLine(self, | ||
| - | self.TxLines.Push(line) | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | # Uart - Main - Check Library | ||
| - | # | ||
| - | def CBOnRxLine(rxline): | ||
| - | print(' | ||
| - | # | ||
| - | def CBOnTxLine(txline): | ||
| - | print(' | ||
| - | # | ||
| - | if (' | ||
| - | print(' | ||
| - | # | ||
| - | Uart = CUart(Define.ID_UART1, | ||
| - | Uart.SetOnRxLine(CBOnRxLine) | ||
| - | Uart.SetOnTxLine(CBOnTxLine) | ||
| - | Uart.Open() | ||
| - | # | ||
| - | Uart.TxLine(' | ||
| - | Uart.TxLine(' | ||
| - | time.sleep(2.0) | ||
| - | # | ||
| - | Uart.Close() | ||
| - | # | ||
| - | print(' | ||
| - | # | ||
| </ | </ | ||
| Line 200: | Line 122: | ||
| **Library-Module: | **Library-Module: | ||
| <code python> | <code python> | ||
| - | # | ||
| - | import time | ||
| - | import _thread as THR | ||
| - | # | ||
| - | # States - EStateThread : | ||
| - | stIdle = 0 | ||
| - | stBusy = 1 | ||
| - | stEnd = 2 | ||
| - | # | ||
| - | class CThread(): | ||
| - | # | ||
| - | def __init__(self, | ||
| - | self.State = stIdle | ||
| - | self.Thread = None | ||
| - | self.OnStart = onstart | ||
| - | self.OnBusy = onbusy | ||
| - | self.OnAbort = onabort | ||
| - | self.OnEnd = onend | ||
| - | return | ||
| - | # | ||
| - | def Start(self): | ||
| - | self.State = stBusy | ||
| - | if (None != self.OnStart): | ||
| - | self.OnStart(self) | ||
| - | self.ThreadID = THR.start_new_thread(self.CBOnExecute, | ||
| - | return | ||
| - | # | ||
| - | def Abort(self): | ||
| - | self.State = stEnd | ||
| - | if (None != self.OnAbort): | ||
| - | self.OnAbort(self) | ||
| - | return | ||
| - | # | ||
| - | def CBOnExecute(self, | ||
| - | if (None != self.OnBusy): | ||
| - | self.OnBusy(self) | ||
| - | if (None != self.OnEnd): | ||
| - | self.OnEnd(self) | ||
| - | return | ||
| - | # | ||
| - | # | ||
| - | if (' | ||
| - | print(' | ||
| - | # | ||
| - | # Thread = CThread(CBOnStart, | ||
| - | # Thread.Start() | ||
| - | # time.sleep(5.0) | ||
| - | # Thread.Abort() | ||
| - | # | ||
| - | print(' | ||
| - | # | ||
| </ | </ | ||
| **Library-Module: | **Library-Module: | ||
| <code python> | <code python> | ||
| - | # | ||
| - | # CLines : FirstIn-FirstOut | ||
| - | class CLines(list): | ||
| - | # | ||
| - | def __init__(self): | ||
| - | self = [] | ||
| - | # | ||
| - | def Count(self): | ||
| - | return len(self) | ||
| - | # | ||
| - | def Push(self, line): | ||
| - | self.append(line) | ||
| - | return | ||
| - | # | ||
| - | def Pop(self): | ||
| - | Line = '' | ||
| - | if (0 < self.Count()): | ||
| - | Line = self.pop(0) | ||
| - | return Line | ||
| </ | </ | ||
| Line 292: | Line 144: | ||
| # | # | ||
| </ | </ | ||
| - | |||
| - | |||
| - | |||
| ===== Entwicklung ===== | ===== Entwicklung ===== | ||
| - | ==== 211219 | + | ==== 211221 |
| - | * Version {{: | + | * |
| - | ==== 211218 : Esp32Uart ==== | + | = |
| - | * Uart0 (UsbPC) : Programmier-/ | + | |
| - | * Uart1 (PIN_UART1_RX(25) rückgekoppelt mit PIN_UART1_TX(26)) | + | |
| - | * Version {{: | + | |
| - | |||
| - | ** Esp32Uart.py : Senden/ | ||
| - | <code python> | ||
| - | >>> | ||
| - | >>> | ||
| - | CBOnTxLine[111asdf] | ||
| - | CBOnRxLine[111asdf] | ||
| - | CBOnTxLine[222asdf] | ||
| - | CBOnRxLine[222asdf] | ||
| - | CBOnTxLine[333asdf] | ||
| - | CBOnRxLine[333asdf] | ||
| - | *** CheckUart: end | ||
| - | >>> | ||
| - | </ | ||
| - | |||
| - | ==== 211217 : Erste Versuche ==== | ||
| - | * Ausgliederung von [[: | ||
| - | |||
| - | **Uart-Pin-Assignment Esp32** in **Define.py** | ||
| - | <code python> | ||
| - | ID_UART0 | ||
| - | PIN_UART0_TX = 1 # USB | ||
| - | PIN_UART0_RX = 3 # USB | ||
| - | # | ||
| - | ID_UART1 | ||
| - | PIN_UART1_RX = 25 # 9 - not usable | ||
| - | PIN_UART1_TX = 26 # 10 - not usable | ||
| - | # | ||
| - | ID_UART2 | ||
| - | PIN_UART2_RX = 16 | ||
| - | PIN_UART2_TX = 17 | ||
| - | </ | ||
| ----- | ----- | ||
| [[http:// | [[http:// | ||
module/micropython/esp32uartpcuc/esp32uartpcuc.1640077779.txt.gz · Last modified: 2021/12/21 11:09 (external edit)