User Tools

Site Tools


module:micropython:esp32uartpcuc:esp32uartpcuc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
module:micropython:esp32uartpcuc:esp32uartpcuc [2021/12/21 10:10] – [Version] omdevelopmodule:micropython:esp32uartpcuc:esp32uartpcuc [2022/09/13 11:58] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== MicroPython: Esp32Uart ======+====== MicroPython: Esp32UartPCUC ======
 [[http://www.openhardsoftware.de/ | Open Hard- & Software]] [[http://www.openhardsoftware.de/ | Open Hard- & Software]]
 [ [
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/Responses für lokale Hardware-Ressourcen(BreadBoard!): 
 +    * LedSystem 
 +    * LedQuad(Uart1, Wlan, Bt, (Lan)) 
 +    * LCDisplayI2C(PCF8574, I2C) 
 +    * Temperature / Humidity(DHT22: CLK, DATA, 5V0, GND) 
 +    * 4x4 KeyPad (entsprechend IT01-FrontKeys) 
 +    * Pressure/Humidity 
 +    * GetChipID (Examples-Esp32-GetChipID) 
 + 
 + 
 +==== UCSystem ==== 
 +  * LCDisplayI2C((PCF8574, I2C) 
 +  * Quertz-Keyboard(PS/2, 5V, CLK, DATA, GND): 
 +    * Paul Stoffregen Arduino-Library **PS2Keyboard** 
 +    * {{https://www.pjrc.com/teensy/td_libs_PS2Keyboard.html|PS2Keyboard}} 
 + 
 +==== CommandReceiver(relative to Esp32) ==== 
 +  * PC-[Uart1]: Command<->Response 
 +  * PC/Tablet/Handy-[Wlan]: Command<->Response 
 +  * PC/Tablet/Handy-[Bt]: Command<->Response 
 +  * Extension later: PC-[Lan]: Command<->Response 
 + 
 +==== Dispatcher(relative to Esp32) ==== 
 +  * LocalSystemDispatcher[Spi, I2C, Gpio]:  
 +  * ExternalControllerDispatcher[Uart2]: Command<->Response 
 +==== Dataflow ==== 
 + 
 +<code> 
 +   MainLoop = True 
 +    while (MainLoop): 
 +        #-------------------------------------------------- 
 +        # Esp32<-Uart1-Usb<-PC 
 +        #-------------------------------------------------- 
 +        # From PC: receive command -> Pass to Local or UC as command 
 +        CommandLine = UartPC.ReadLine() # RxLines-Fifo 
 +        AnalyseCommandLine(CommandLine) # -> ChildUC 
 +        # #-------------------------------------------------- 
 +        # # Esp32<-Bt-Usb/Serial<-PC 
 +        # #-------------------------------------------------- 
 +        # CommandLine = BtPC.ReadLine() # RxLines-Fifo 
 +        # AnalyseCommandLine(CommandLine) # -> ChildUC 
 +        # #-------------------------------------------------- 
 +        # # Esp32<-Wlan<-PC 
 +        # #-------------------------------------------------- 
 +        # CommandLine = WlanPC.ReadLine() # RxLines-Fifo 
 +        # AnalyseCommandLine(CommandLine) # -> ChildUC 
 +        # # #-------------------------------------------------- 
 +        # # # Esp32<-Lan<-PC 
 +        # # #-------------------------------------------------- 
 +        # # CommandLine = LanPC.ReadLine() # RxLines-Fifo 
 +        # # AnalyseCommandLine(CommandLine) # -> ChildUC 
 +        # 
 +        # 
 +        #ResponseLine = '! command parameter0 .. parametern' # <- ChildUC 
 +        #-------------------------------------------------- 
 +        # PC<-Uart1/Bt/Wlan/Lan<-Esp32<-Local 
 +        #-------------------------------------------------- 
 +        ResponseLine = LocalSystem.ReadLine() # RxLines-Fifo 
 +        UartPC.TransmitResponse(ResponseLine) 
 +        BtPC.TransmitResponse(ResponseLine) 
 +        WlanPC.TransmitResponse(ResponseLine) 
 +        LanPC.TransmitResponse(ResponseLine) 
 +        #-------------------------------------------------- 
 +        # Esp32<->Uart2<->UC(Stm32) 
 +        #-------------------------------------------------- 
 +        ResponseLine = UartUC.ReadLine() # RxLines-Fifo 
 +        UartPC.TransmitResponse(ResponseLine) 
 +        BtPC.TransmitResponse(ResponseLine) 
 +        WlanPC.TransmitResponse(ResponseLine) 
 +        LanPC.TransmitResponse(ResponseLine) 
 +   # 
 +</code> 
 + 
  
 ==== Links ==== ==== Links ====
Line 19: Line 108:
 **Ausgabe MicroPython-Terminal Esp32CheckUart.py** **Ausgabe MicroPython-Terminal Esp32CheckUart.py**
 <code python> <code python>
->>>Running ...Esp32CheckUart.py 
->>> *** Esp32CheckUart: begin 
-CBUartOnTxLine[000 <command>] 
-CBUartOnRxLine[000 <command>] 
-CBUartOnTxLine[111 <command> <parameter0>] 
-CBUartOnTxLine[222 <command> <parameter0> <parameter1>] 
-CBUartOnRxLine[111 <command> <parameter0>] 
-CBUartOnTxLine[333 <command> <parameter0> <parameter1> <parameter2>] 
-CBUartOnRxLine[222 <command> <parameter0> <parameter1>] 
-CBUartOnTxLine[444 <command> <parameter0> <parameter1> <parameter2> <parameter3>] 
-CBUartOnRxLine[333 <command> <parameter0> <parameter1> <parameter2>] 
-CBUartOnTxLine[555 <command>] 
-CBUartOnRxLine[444 <command> <parameter0> <parameter1> <parameter2> <parameter3>] 
-CBUartOnTxLine[666 <command> <parameter0>] 
-CBUartOnRxLine[555 <command>] 
-CBUartOnTxLine[777 <command> <parameter0> <parameter1>] 
-CBUartOnRxLine[666 <command> <parameter0>] 
-CBUartOnTxLine[888 <command> <parameter0> <parameter1> <parameter2>] 
-CBUartOnRxLine[777 <command> <parameter0> <parameter1>] 
-CBUartOnTxLine[999 <command> <parameter0> <parameter1> <parameter2> <parameter3>] 
-CBUartOnRxLine[888 <command> <parameter0> <parameter1> <parameter2>] 
-CBUartOnRxLine[999 <command> <parameter0> <parameter1> <parameter2> <parameter3>]   
-*** Esp32CheckUart: end 
->>> 
 </code> </code>
  
Line 48: Line 113:
 **Main-Program: Esp32CheckUart.py** **Main-Program: Esp32CheckUart.py**
 <code python> <code python>
-# 
-import time as TIM 
-# 
-import Define as DEF 
-import Uart as UART 
-# 
-#------------------------------------------------------------------- 
-#   Callback - Uart 
-#------------------------------------------------------------------- 
-def CBUartOnRxLine(rxline): 
-    print('CBUartOnRxLine[{}]'.format(rxline)) 
-# 
-def CBUartOnTxLine(txline): 
-    print('CBUartOnTxLine[{}]'.format(txline)) 
-# 
-#------------------------------------------------------------------- 
-#   Main - Uart 
-#------------------------------------------------------------------- 
-if ('__main__' == __name__): 
-    print('*** Esp32CheckUart: begin'    
-    # 
-    Uart = UART.CUart(DEF.ID_UART1, DEF.PIN_UART1_TX, DEF.PIN_UART1_RX) 
-    Uart.SetOnRxLine(CBUartOnRxLine) 
-    Uart.SetOnTxLine(CBUartOnTxLine) 
-    Uart.Open() 
-    # 
-    Uart.TxLine('000 <command>') 
-    Uart.TxLine('111 <command> <parameter0>') 
-    Uart.TxLine('222 <command> <parameter0> <parameter1>') 
-    Uart.TxLine('333 <command> <parameter0> <parameter1> <parameter2>') 
-    Uart.TxLine('444 <command> <parameter0> <parameter1> <parameter2> <parameter3>') 
-    Uart.TxLine('555 <command>') 
-    Uart.TxLine('666 <command> <parameter0>') 
-    Uart.TxLine('777 <command> <parameter0> <parameter1>') 
-    Uart.TxLine('888 <command> <parameter0> <parameter1> <parameter2>') 
-    Uart.TxLine('999 <command> <parameter0> <parameter1> <parameter2> <parameter3>') 
-    TIM.sleep(2.0) 
-    # 
-    Uart.Close() 
-    # 
-    print('*** Esp32CheckUart: end') 
-    # 
-# 
 </code> </code>
  
 **Library-Module: Uart.py** **Library-Module: Uart.py**
 <code python> <code python>
-# 
-import time 
-from machine import UART 
-# 
-import Define 
-import Lines as LIN 
-import Thread as THR 
-# 
-class CUart(): 
-    #--------------------------------------------------------- 
-    #   Constructor 
-    #--------------------------------------------------------- 
-    def __init__(self, uartid, txpin, rxpin): 
-        self.Uart = UART(uartid, tx=txpin, rx=rxpin) 
-        self.TxLines = LIN.CLines() 
-        self.RxLines = LIN.CLines()  
-        self.OnRxLine = None 
-        self.OnTxLine = None 
-        self.Thread = THR.CThread(self.CBOnStart, self.CBOnBusy, self.CBOnAbort, self.CBOnEnd) 
-        self.RxLine = '' 
-    #--------------------------------------------------------- 
-    #   Property 
-    #--------------------------------------------------------- 
-    def SetOnRxLine(self, onrxline): 
-        self.OnRxLine = onrxline 
-    def SetOnTxLine(self, ontxline): 
-        self.OnTxLine = ontxline 
-    #--------------------------------------------------------- 
-    #   Callback Thread 
-    #--------------------------------------------------------- 
-    def CBOnStart(self, thread): 
-        return 
-    def CBOnBusy(self, thread): 
-        while (THR.stBusy == thread.State): 
-            # first: RxData 
-            while (0 < self.Uart.any()): 
-                C = self.Uart.read(1) 
-                if (b'\r' == C) or (b'\n' == C): 
-                    if (0 < len(self.RxLine)): 
-                        self.RxLines.Push(self.RxLine) 
-                        self.RxLine = ''; 
-                else: 
-                    self.RxLine += C.decode("utf-8") 
-            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 + '\r\n') 
-                if (None != self.OnTxLine): 
-                    self.OnTxLine(Line) 
-    def CBOnAbort(self, thread): 
-        return 
-    def CBOnEnd(self, thread): 
-        return 
-    #--------------------------------------------------------- 
-    #   Management 
-    #--------------------------------------------------------- 
-    def Open(self): 
-        self.Uart.init(baudrate=115200)#, bits=8, parity=None, stop=1, cts=-1, rts=-1) 
-        self.Thread.Start()    
-        self.RxLine = '' 
-        return 
-    # 
-    def Close(self): 
-        self.Thread.Abort() 
-        self.Uart.deinit() 
-        return  
-    # 
-    def TxLine(self, line): 
-        self.TxLines.Push(line) 
-    # 
-# 
-#------------------------------------------------------------- 
-#   Uart - Main - Check Library 
-#------------------------------------------------------------- 
-def CBOnRxLine(rxline): 
-    print('CBOnRxLine[{}]'.format(rxline)) 
-# 
-def CBOnTxLine(txline): 
-    print('CBOnTxLine[{}]'.format(txline)) 
-# 
-if ('__main__' == __name__):     
-    print('*** CheckUart: begin') 
-    # 
-    Uart = CUart(Define.ID_UART1, Define.PIN_UART1_TX, Define.PIN_UART1_RX) 
-    Uart.SetOnRxLine(CBOnRxLine) 
-    Uart.SetOnTxLine(CBOnTxLine) 
-    Uart.Open() 
-    # 
-    Uart.TxLine('000asdf') 
-    Uart.TxLine('111asdf') 
-    time.sleep(2.0) 
-    # 
-    Uart.Close() 
-    # 
-    print('*** CheckUart: end') 
-#     
 </code> </code>
  
Line 200: Line 122:
 **Library-Module: Thread.py** **Library-Module: Thread.py**
 <code python> <code python>
-# 
-import time 
-import _thread as THR 
-# 
-# States - EStateThread : 
-stIdle = 0 
-stBusy = 1 
-stEnd = 2 
-# 
-class CThread(): 
-    # 
-    def __init__(self, onstart, onbusy, onabort, onend): 
-        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, [self]) 
-        return     
-    # 
-    def Abort(self): 
-        self.State = stEnd 
-        if (None != self.OnAbort): 
-            self.OnAbort(self) 
-        return 
-    # 
-    def CBOnExecute(self, thread): 
-        if (None != self.OnBusy): 
-            self.OnBusy(self) 
-        if (None != self.OnEnd): 
-            self.OnEnd(self) 
-        return 
-    # 
-#------------------------------------------------------------- 
-if ('__main__' == __name__): 
-    print('*** Check Thread: begin'        
-    # 
-    # Thread = CThread(CBOnStart, CBOnBusy, CBOnAbort, CBOnEnd) 
-    # Thread.Start() 
-    # time.sleep(5.0) 
-    # Thread.Abort() 
-    # 
-    print('*** Check Thread: end') 
-# 
 </code> </code>
  
 **Library-Module: Lines.py** **Library-Module: Lines.py**
 <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 
 </code> </code>
  
Line 292: Line 144:
 # #
 </code> </code>
- 
- 
- 
  
  
 ===== Entwicklung ===== ===== Entwicklung =====
  
-==== 211219 Esp32Uart ==== +==== 211221 Basis ==== 
-  * Version {{:module:micropython:Esp32Uart:2112191209_Esp32Uart_00V02.zip | 2112191209_Esp32Uart_00V02.zip}} +  *  
-==== 211218 : Esp32Uart ==== +=
-  * Uart0 (UsbPC) : Programmier-/Debug-Schnittstelle VSCode +
-  * Uart1 (PIN_UART1_RX(25) rückgekoppelt mit PIN_UART1_TX(26)) +
-  * Version {{:module:micropython:Esp32Uart:2112181850_Esp32Uart_00V01.zip | 2112181850_Esp32Uart_00V01.zip}}+
  
- 
-** Esp32Uart.py : Senden/Empfangen bei Tx/Rx-Kabel-Rückkopplung:** 
-<code python> 
->>> Running c:\Downloads\python\Esp32Uart\Uart.py 
->>> *** CheckUart: begin 
-CBOnTxLine[111asdf] 
-CBOnRxLine[111asdf] 
-CBOnTxLine[222asdf] 
-CBOnRxLine[222asdf] 
-CBOnTxLine[333asdf] 
-CBOnRxLine[333asdf] 
-*** CheckUart: end 
->>> 
-</code> 
- 
-==== 211217 : Erste Versuche ==== 
-  * Ausgliederung von [[:Module:MicroPython:CommandLineDispatcher:CommandLineDispatcher | CommandLineDispatcher]]  
- 
-**Uart-Pin-Assignment Esp32** in **Define.py** 
-<code python> 
-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 
-</code> 
 ----- -----
 [[http://www.openhardsoftware.de/ | Open Hard- & Software]] [[http://www.openhardsoftware.de/ | Open Hard- & Software]]
module/micropython/esp32uartpcuc/esp32uartpcuc.1640077816.txt.gz · Last modified: 2021/12/21 11:10 (external edit)