diff --git a/docs/Advanced_development/en/QuecPythonBus/ExtInt.md b/docs/Advanced_development/en/QuecPythonBus/ExtInt.md index 9be8ab83a752416f55ef5a4d40520934ce29ab76..7ea23c703d82dfaf2186e274b433dd25456d7bcf 100644 --- a/docs/Advanced_development/en/QuecPythonBus/ExtInt.md +++ b/docs/Advanced_development/en/QuecPythonBus/ExtInt.md @@ -6,16 +6,17 @@ | ------- | ---------- | ------- | ------------------------------------------------ | | 1.0 | 2021-09-22 | Grey.Tu | Modified the initial version | | 1.1 | 2021-10-09 | Rivern | Added the advanced application of Helios Service | +| 1.2 | 2021-02-11 | Grey.Tu | correct errors in printing | In this article, it mainly introduces how to detect external interrupt via ExtInt from views of HW and SW designs. -About Specific info of API, please refer to [QuecPython-machine - ExtInt](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=extint). +About Specific info of API, please refer to [QuecPython-machine - ExtInt](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=extint). ### HW design The principle pf ExtInt is to detect the level conversion of external pin, that it to say there exists signal of edge up and edge down on pin. -![media_Extlnt_01(E)](media\media_Extlnt_01(E).png) +![media_ExtInt_1](media/media_ExtInt_1.jpg) The schematic diagram is similar with the key schematic diagram. @@ -23,9 +24,11 @@ The schematic diagram is similar with the key schematic diagram. ### SW design -First of all, we should confirm which PIN is used to control HW, then find out the relevant GPIO No. via the API class library on official website. For more details, please refer to [QuecPython-machine - ExtInt](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=extint). +First of all, we should confirm which PIN is used to control HW, then find out the relevant GPIO No. via the API class library on official website. For more details, please refer to [QuecPython-machine - ExtInt](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=extint). -Take the EC600S/N as an example, the PIN 10 is the GPIO 1. +![media_ExtInt_3](media/media_ExtInt_3.jpg) + +Take the EC600U as an example, the PIN 60 is the GPIO 4. Start to compile code, select related GPIO to initialize ExtInt. @@ -37,18 +40,16 @@ def callback(args): print('interrupt: {}'.format(args)) -extint13 = ExtInt(ExtInt.GPIO13, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, callback) # Create object -extint12 = ExtInt(ExtInt.GPIO12, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, callback) # Create object -extint13.enable() # Enable interrupt -extint12.enable() # Enable interrupt -print('Start GPIO: {}Interrupt. \r\n'.format(extint13.line())) -print('Start GPIO: {}Interrupt. \r\n'.format(extint12.line())) +extint = ExtInt(ExtInt.GPIO4, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, callback) # Create object +extint.enable() # Enable interrupt +print('Start GPIO: {}Interrupt. \r\n'.format(extint.line())) -# extint13.disable() # Disable interrupt -# extint12.disable() # Disable interrupt +# extint.disable() # Disable interrupt ``` -The matched code +![media_ExtInt_4](media/media_ExtInt_4.jpg) + +> Note: The running result of code displayed on screen-shot is based on EC600U_EVB 1.3 with GPIO 4corresponding to Pin 60 separately, which refers to the KEY 1 on EVB. ### The matched code @@ -127,16 +128,9 @@ def fun(para): print(para) #para[0] Pin name para[1]: 0 Long press, 1 Press down, 2 Press up -aa = KeyProcess(Pin.GPIO13, 1000, fun) #gpio13, 1000ms = long press, callback= fun -bb = KeyProcess(Pin.GPIO12, 3000, fun) +aa = KeyProcess(Pin.GPIO4, 1000, fun) #gpio13, 1000ms = long press, callback= fun """ ``` -![media_ExInt_02(E)](media\media_ExInt_02(E).png) - - - -![media_ExInt_05(E)](media\media_ExInt_05(E).png) -> Note: The running result of code displayed on screen-shot is based on EVB 1.3 with GPIO 12 and 12 corresponding to Pin 59 and 60 separately, which refers to the KEY 1 and 2 on EVB. diff --git a/docs/Advanced_development/en/QuecPythonBus/button.md b/docs/Advanced_development/en/QuecPythonBus/button.md index b7a2f3cc46bec50d1b40ae7eb9c64a8490089f6c..4e46ff50a73c2f7379df56e0868cf92e80496d8f 100644 --- a/docs/Advanced_development/en/QuecPythonBus/button.md +++ b/docs/Advanced_development/en/QuecPythonBus/button.md @@ -8,7 +8,7 @@ In this document, we may concentrate on how to detect the GPIO level from views of HW and SW designs. By reading through this text, you may learn about how to check the HW connection, compile code and verify test. -For more details about API, please refer to [QuecPython-machine - PIN](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=pin) +For more details about API, please refer to [QuecPython-machine - PIN](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pin) ## HW resource @@ -22,13 +22,13 @@ By configuring corresponding GPIO as the pull up (the input mode) , we can chang ## SW design -First of all, we should confirm which GPIO should be detected, then find out the relevant GPIO No. via the API class library on official website. Check the details on [QuecPython-machine - PIN](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=pin). +First of all, we should confirm which GPIO should be detected, then find out the relevant GPIO No. via the API class library on official website. Check the details on [QuecPython-machine - PIN](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pin). ![media_button_2](media/media_button_2.jpg) -Take the EC600S/N as an example, the PIN 10 is the GPIO 1. +Take the EC600U as an example, the PIN 60 is the GPIO 4. -As for the PIN 59 and PIN 60 on EC600x EVB, when it is the EC600S/N, the PIN 59 serves as GPIO 12 and PIN 60 as GPIO 13 separately. While it is the EC600U, the PIN 60 serves as GPIO 4, however, there is no corresponding GPIO to PIN 59; consequently, the button input test is invalid. +As for the While it is the EC600U, the PIN 60 serves as GPIO 4, however, there is no corresponding GPIO to PIN 59; consequently, the button input test is invalid. ### Code performance @@ -38,15 +38,14 @@ from machine import Pin if __name__ == '__main__': - gpio13 = Pin(Pin.GPIO13, Pin.IN, Pin.PULL_PU, 1) # Used on EC600S/N - # gpio13 = Pin(Pin.GPIO4, Pin.IN, Pin.PULL_PU, 1) # Used on EC600U + gpio = Pin(Pin.GPIO4, Pin.IN, Pin.PULL_PU, 1) while True: - if gpio13.read() == 0: + if gpio.read() == 0: utime.sleep_ms(10) - if gpio13.read() == 0: - while gpio13.read() == 0: + if gpio.read() == 0: + while gpio.read() == 0: pass - print("Press GPIO13") + print("Button press") pass ``` diff --git a/docs/Advanced_development/en/QuecPythonBus/buzzer.md b/docs/Advanced_development/en/QuecPythonBus/buzzer.md index 9679d85da8356595072d4cc996333f805007c48a..5c6946f629dda7390df544a3099e48739a5d1d48 100644 --- a/docs/Advanced_development/en/QuecPythonBus/buzzer.md +++ b/docs/Advanced_development/en/QuecPythonBus/buzzer.md @@ -6,10 +6,11 @@ |------|------|------|------| | 1.0 | 2021-03-20 | gary.zhou | Initial version | | 1.1 | 2021-09-15 | Grey.Tu | Modified active buzzer as passive buzzer | +| 1.2 | 2021-11-29 | Grey.Tu | correct errors in printing | In this document, it mainly introduces how to control passive buzzer via PWM and make it sound from HW design and SW design. After reading through this article, you will acquire how to use PWM. -About API details, please refer to [QuecPython-misc - PWM](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=pwm) +About API details, please refer to [QuecPython-misc - PWM](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pwm) ## HW introduction @@ -21,9 +22,9 @@ The "source" in active buzzer and passive buzzer does refer to vibration instead From the surface of a and b, it seems that both buzzers are similar. however, they vary in height. The Figure a shows the active buzzer with 9mm while the figure b is the passive buzzer with 8mm. The difference lies in that the passive buzzer is embedded with green EVB, while the active buzzer is sealed by chip-on-board without EVB. -![media_buzzer(1)](media\media_buzzer(1).png) +![media_buzzer_1](media/media_buzzer_1.jpg) - It is convenient to purchase one passive buzzer via Taobao. + It is to purchase one passive buzzer. ![media_buzzer_2](media/media_buzzer_2.jpg) @@ -39,85 +40,59 @@ The passive buzzer can be drove by PWM Switch transistor. what we should provide First of all, we should confirm which PIN is used to control HW, then find out the relevant PWM No. via the API class library on official website. -More details, please refer to [QuecPython-misc - PWM](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=pwm) . +More details, please refer to [QuecPython-misc - PWM](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pwm) . E. g. -| Module type | Corresponding pin | -| -------------------------------------- | ----------------- | -| EC600S/N ==> PWM2
EC600U ==> PWM0 | PIN 70 | +| Module type | Corresponding pin | +| --------------- | ----------------- | +| EC600U ==> PWM0 | PIN 70 | ### **Codes for test** ```python +from misc import PWM +import utime as time +import urandom as random +import log -Note: on EC600SCN platform, it supports a range of PWM0 to PWM3 at which whose pins are placed: - -PWM0 – Pin 52 - -PWM2 – Pin 70 - -PWM3 – Pin 69 - -""" - -# Obtain logger object +# Creating log object buzzer_log = log.getLogger("buzzer_test") -# DTransform the HZ into 10us level - +# Duration: ms +def outputpwm(HZ, duty_cycle, Duration): cycleTime = int((10000000/HZ)/10) highTime = int(cycleTime * duty_cycle) - - # Output the log with a level of debug - buzzer_log.debug( """out put pin70 cycleTime {0} * 10us, highTime {1} * 10us, Duration of {2}""" .format(cycleTime, highTime, Duration)) - pwm1 = PWM(PWM.PWM2, PWM.ABOVE_10US, highTime, cycleTime) + pwm1 = PWM(PWM.PWM0, PWM.ABOVE_10US, highTime, cycleTime) pwm1.open() - - # Sleep the duration - time.sleep_ms(Duration) pwm1.close() pass def test_Buzzer(): - - # Set log output level - + # Set the log output level log.basicConfig(level=log.DEBUG) - - # Cycle it for 10 times - + # Loop 10 times for i in range(10): - - # Genarate the floating point in the range of start to end randomly, the range can be decided from 0~1 on your own. - + # Random generation of floating point numbers in the start to end range, optionally, 0~1 duty_cycle = random.uniform(0.1, 0.8) - - # Suggested to output the PWM wave with a range of 2000-5000HZ. - # Generate one integar from start to end randomly - + # Suggested that the output2000~5000HZ_PWM waveform + # Generate a random start ~ end Integer between HZ = random.randint(2000, 5000) outputpwm(HZ, duty_cycle, 500) time.sleep_ms(1500) - pass if __name__ == "__main__": - - # Create a thread Check key status - test_Buzzer() - -# Download and run codes, the sound generated in the buzzer can be heard. ``` ## The matched codes diff --git a/docs/Advanced_development/en/QuecPythonBus/code/code_ExtInt.py b/docs/Advanced_development/en/QuecPythonBus/code/code_ExtInt.py index 241ccd79ca3130dce058c71b9577fac8dc4b6da7..c809acdd77710b2e51a80daf1c49e3f6aed7eb3d 100644 --- a/docs/Advanced_development/en/QuecPythonBus/code/code_ExtInt.py +++ b/docs/Advanced_development/en/QuecPythonBus/code/code_ExtInt.py @@ -1,29 +1,12 @@ from machine import ExtInt -import utime as time -# PIN脚及API介绍请参考 https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=extint -state = 10 # 测试次数 def callback(args): print('interrupt: {}'.format(args)) -def main(): - extint13 = ExtInt(ExtInt.GPIO13, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, callback) # 创建对象 - extint12 = ExtInt(ExtInt.GPIO12, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, callback) # 创建对象 - extint13.enable() # 使能中断 - extint12.enable() # 使能中断 - print('开启GPIO: {}中断. \r\n'.format(extint13.line())) - print('开启GPIO: {}中断. \r\n'.format(extint12.line())) - # 等待按键按下,触发 - while state: - time.sleep_ms(1) - pass - # 停止映射外部中断 - extint13.disable() # 关闭中断 - extint12.disable() # 关闭中断 - print("The main function has exited") +extint = ExtInt(ExtInt.GPIO4, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, callback) # Create object +extint.enable() # Enable interrupt +print('Start GPIO: {} Interrupt. \r\n'.format(extint.line())) - -if __name__ == "__main__": - main() +# extint.disable() # Disable interrupt diff --git a/docs/Advanced_development/en/QuecPythonBus/code/code_UART_CDC.py b/docs/Advanced_development/en/QuecPythonBus/code/code_UART_CDC.py index a8d288d5ef5c2687598f5a9bd78c390b6eb664ab..5ab92c748c49688687c59ba17354f2bd16a1252f 100644 --- a/docs/Advanced_development/en/QuecPythonBus/code/code_UART_CDC.py +++ b/docs/Advanced_development/en/QuecPythonBus/code/code_UART_CDC.py @@ -8,17 +8,6 @@ state = 1 uart_x = None usbcdc = None -# # | 参数 | 参数类型 | 说明 | -# # | -------- | ------- | ------------------ | -# # | CRITICAL | 常量 | 日志记录级别的数值 50 | -# # | ERROR | 常量 | 日志记录级别的数值 40 | -# # | WARNING | 常量 | 日志记录级别的数值 30 | -# # | INFO | 常量 | 日志记录级别的数值 20 | -# # | DEBUG | 常量 | 日志记录级别的数值 10 | -# # | NOTSET | 常量 | 日志记录级别的数值 0 | -# log.basicConfig(level=log.CRITICAL) # 设置日志输出级别 -# log = log.getLogger("Grey") # 获取logger对象,如果不指定name则返回root对象,多次使用相同的name调用getLogger方法返回同一个logger对象 - def uart_x_read(): global state @@ -26,14 +15,14 @@ def uart_x_read(): global usbcdc while state: - msglen = uart_x.any() # 返回是否有可读取的数据长度 - if msglen: # 当有数据时进行读取 - msg = uart_x.read(msglen) # 读取数据 - utf8_msg = msg.decode() # 初始数据是字节类型(bytes),将字节类型数据进行编码 + msglen = uart_x.any() # Returns whether there is a readable length of data + if msglen: # Read when data is available + msg = uart_x.read(msglen) # Read Data + utf8_msg = msg.decode() # The initial data is byte type (bytes), which encodes byte type data if "Grey" in utf8_msg: break else: - usbcdc.write("{}".format(utf8_msg)) # 发送数据 + usbcdc.write("{}".format(utf8_msg)) # send data utime.sleep_ms(1) state = 0 @@ -44,27 +33,27 @@ def usbcdc_read(): global usbcdc while state: - msglen = usbcdc.any() # 返回是否有可读取的数据长度 - if msglen: # 当有数据时进行读取 - msg = usbcdc.read(msglen) # 读取数据 - utf8_msg = msg.decode() # 初始数据是字节类型(bytes),将字节类型数据进行编码 + msglen = usbcdc.any() # Returns whether there is a readable length of data + if msglen: # Read when data is available + msg = usbcdc.read(msglen) # Read Data + utf8_msg = msg.decode() # The initial data is byte type (bytes), which encodes byte type data if "Grey" in utf8_msg: break else: - uart_x.write("{}".format(utf8_msg)) # 发送数据 + uart_x.write("{}".format(utf8_msg)) # send data utime.sleep_ms(1) state = 0 if __name__ == "__main__": uart_x = UART(UART.UART2, 115200, 8, 0, 1, 0) - usbcdc = UART(UART.UART3, 115200, 8, 0, 1, 0) + usbcdc = UART(UART.UART3, 115200, 8, 0, 1, 0) # It is unvalid to set the baudrate, while in communication, any baudrate is available - uart_x.write("Grey_测试") - usbcdc.write("Grey_测试") + uart_x.write("Grey_test") + usbcdc.write("Grey_test") - _thread.start_new_thread(uart_x_read, ()) # 创建一个线程来监听接收uart消息 - _thread.start_new_thread(usbcdc_read, ()) # 创建一个线程来监听接收CDC消息 + _thread.start_new_thread(uart_x_read, ()) # Create a thread to listen for receiving UART messages + _thread.start_new_thread(usbcdc_read, ()) # Create a thread to listen for receiving CDC messages while state: utime.sleep_ms(1) diff --git a/docs/Advanced_development/en/QuecPythonBus/code/code_button.py b/docs/Advanced_development/en/QuecPythonBus/code/code_button.py index 097c0992ad2c319c7eabecbc90f4caa34713697c..1d5e635af178fb750a4350440290cfd3f59667cb 100644 --- a/docs/Advanced_development/en/QuecPythonBus/code/code_button.py +++ b/docs/Advanced_development/en/QuecPythonBus/code/code_button.py @@ -3,13 +3,12 @@ from machine import Pin if __name__ == '__main__': - gpio13 = Pin(Pin.GPIO13, Pin.IN, Pin.PULL_PU, 1) # EC600S/N开发板使用 - # gpio13 = Pin(Pin.GPIO4, Pin.IN, Pin.PULL_PU, 1) # EC600U开发板使用 + gpio = Pin(Pin.GPIO4, Pin.IN, Pin.PULL_PU, 1) while True: - if gpio13.read() == 0: + if gpio.read() == 0: utime.sleep_ms(10) - if gpio13.read() == 0: - while gpio13.read() == 0: + if gpio.read() == 0: + while gpio.read() == 0: pass - print("GPIO13按下") - pass + print("Button press") + pass \ No newline at end of file diff --git a/docs/Advanced_development/en/QuecPythonBus/code/code_buzzer.py b/docs/Advanced_development/en/QuecPythonBus/code/code_buzzer.py index 5225c7bbaed9b85736d1dad9b7cd261fc11b6215..73f469e8a09c020b4e0f0b14a50ec68e7a2c0b49 100644 --- a/docs/Advanced_development/en/QuecPythonBus/code/code_buzzer.py +++ b/docs/Advanced_development/en/QuecPythonBus/code/code_buzzer.py @@ -3,81 +3,39 @@ import utime as time import urandom as random import log -# API https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=pwm -# 蜂鸣器模块 https://detail.tmall.com/item.htm?id=41251333522 -# 无源蜂鸣器-频率可控版 - -""" - -pwm0 = PWM(PWM.PWMn,PWM.ABOVE_xx,highTime,cycleTime) - -注:EC600SCN平台,支持PWM0-PWM3,对应引脚如下: - -PWM0 – 引脚号52 - -PWM1 – 引脚号53 - -PWM2 – 引脚号70 - -PWM3 – 引脚号69 - -""" - -# 获取logger对象 +# Creating log object buzzer_log = log.getLogger("buzzer_test") -# Duration 为 ms - +# Duration: ms def outputpwm(HZ, duty_cycle, Duration): - - # 将HZ 转化为 10us 级别 - cycleTime = int((10000000/HZ)/10) highTime = int(cycleTime * duty_cycle) - - # 输出debug级别的日志 - buzzer_log.debug( """out put pin70 cycleTime {0} * 10us, highTime {1} * 10us, Duration of {2}""" .format(cycleTime, highTime, Duration)) - pwm1 = PWM(PWM.PWM2, PWM.ABOVE_10US, highTime, cycleTime) + pwm1 = PWM(PWM.PWM0, PWM.ABOVE_10US, highTime, cycleTime) pwm1.open() - - # 休眠给定毫秒数的时间 - time.sleep_ms(Duration) pwm1.close() pass def test_Buzzer(): - - #设置日志输出级别 - + # Set the log output level log.basicConfig(level=log.DEBUG) - - # 循环遍历10次 - + # Loop 10 times for i in range(10): - - # 随机生成 start 到 end 范围内的浮点数,范围可以自己选择, 0~1 - + # Random generation of floating point numbers in the start to end range, optionally, 0~1 duty_cycle = random.uniform(0.1, 0.8) - - # 建议输出2000~5000HZ 的PWM波形 - # 随机生成一个 start 到 end 之间的整数 - + # Suggested that the output2000~5000HZ_PWM waveform + # Generate a random start ~ end Integer between HZ = random.randint(2000, 5000) outputpwm(HZ, duty_cycle, 500) time.sleep_ms(1500) - pass if __name__ == "__main__": - - # creat a thread Check key status - test_Buzzer() \ No newline at end of file diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_1.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_1.jpg index 41421feb83f7955a3de178e949d94ed47a6287ea..cf6d368d8dbe87eea00ddcba750dea410b43c76e 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_1.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_1.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_3.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_3.jpg index 5f7d9a8fdcc6186a90a06efeaced6fcf0e872fe4..3c6063497b470c4ec9f68dfa136a56e41fe5de04 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_3.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_3.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_4.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..12005e17aa06bf8ca000db460be0bb30b69593aa Binary files /dev/null and b/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_4.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_4.png b/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_4.png deleted file mode 100644 index 9c7c02e71eefe622f3b64448a7be22221d26bf8e..0000000000000000000000000000000000000000 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_4.png and /dev/null differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_5.png b/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_5.png deleted file mode 100644 index 0e21661495edfb3e563f30f2b9c118a4c99c8840..0000000000000000000000000000000000000000 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_ExtInt_5.png and /dev/null differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_UART_3.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_UART_3.jpg index 042fc4cfc8b4c1ccdc900ca31be90588cfcace38..f312ebcc7c2bc04954106c7f8f3e9c263e44edcb 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_UART_3.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_UART_3.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_button_2.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_button_2.jpg index 5f7d9a8fdcc6186a90a06efeaced6fcf0e872fe4..e68fc1d5f1ebc772be8d4431fab34bc0647dc204 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_button_2.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_button_2.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_button_4.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_button_4.jpg index 80bd9f7dd8497851cab1c8ea92455a595be6a9a7..2e63b9e29dc683fea579228b7fda06507ca202aa 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_button_4.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_button_4.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_buzzer_1.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_buzzer_1.jpg index 08655fb0aca59b86c0c8c0c856522fe0f440cd1a..4d29a3cf7d9f71fce80bb55373fa486fb8f84830 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_buzzer_1.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_buzzer_1.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_buzzer_2.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_buzzer_2.jpg index 04f1abf9f20c5d03199c9f018b7fb957cc5db9b4..b73ee663bccb8f77399042d8abaa89c12db8711e 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_buzzer_2.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_buzzer_2.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/uart.md b/docs/Advanced_development/en/QuecPythonBus/uart.md index 02d621623fc951cec4226bb98f0e47de390a03af..58759971b4d33005b09e42cb69732d87c131982f 100644 --- a/docs/Advanced_development/en/QuecPythonBus/uart.md +++ b/docs/Advanced_development/en/QuecPythonBus/uart.md @@ -2,13 +2,13 @@ ## Revision history -| Version | Date | Author | Description | -| ------- | ---------- | ------- | ------------------- | -| 1.0 | 2021-09-22 | Grey.tu | 初版Initial Version | +| Version | Date | Author | Description | +| ------- | ---------- | ------- | --------------- | +| 1.0 | 2021-09-22 | Grey.tu | Initial Version | In this document, it mainly focuses on QuecPython_UART. As a common and universal method, Uart is widely used in data interaction and full duplex transmission. After reading through this article, you will comprehensively learn about the setting parameter and application of UART on EC600X, including in EC600S , EC600N and EC600U. -For related API, please refer to [QuecPython-machine-UART](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=uart) +For related API, please refer to [QuecPython-machine-UART](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=uart) ## HW design @@ -32,23 +32,65 @@ We have already introduced the basic connection of physical UART on previous cha As the virtual serial communication port, the USB CDC port adapts the same protocol as UART. However, it does not the real UART. Without the UART baudrate on communication rate, it can identify automatically via USB protocol with faster transmission speed and unnecessity the burden of fixed baudrate. ```python +# import log +import utime +import _thread +import ubinascii from machine import UART -uart_x = UART(UART.UART2, 115200, 8, 0, 1, 0) -usbcdc = UART(UART.UART3, 115200, 8, 0, 1, 0) It is unvalid to set the baudrate, while in communication, any baudrate is available - -while True: - uart_x_msglen = uart_x.any() - if uart_x_msglen: - uart_x_msg = uart_x.read(uart_x_msglen) - uart_x_utf8_msg = uart_x_msg.decode() - usbcdc.write("{}".format(uart_x_utf8_msg)) - - usbcdc_msglen = usbcdc.any() - if usbcdc_msglen: - usbcdc_msg = usbcdc.read(usbcdc_msglen) - usbcdc_utf8_msg = usbcdc_msg.decode() - uart_x.write("{}".format(usbcdc_utf8_msg)) +state = 1 +uart_x = None +usbcdc = None + + +def uart_x_read(): + global state + global uart_x + global usbcdc + + while state: + msglen = uart_x.any() # Returns whether there is a readable length of data + if msglen: # Read when data is available + msg = uart_x.read(msglen) # Read Data + utf8_msg = msg.decode() # The initial data is byte type (bytes), which encodes byte type data + if "Grey" in utf8_msg: + break + else: + usbcdc.write("{}".format(utf8_msg)) # send data + utime.sleep_ms(1) + state = 0 + + +def usbcdc_read(): + global state + global uart_x + global usbcdc + + while state: + msglen = usbcdc.any() # Returns whether there is a readable length of data + if msglen: # Read when data is available + msg = usbcdc.read(msglen) # Read Data + utf8_msg = msg.decode() # The initial data is byte type (bytes), which encodes byte type data + if "Grey" in utf8_msg: + break + else: + uart_x.write("{}".format(utf8_msg)) # send data + utime.sleep_ms(1) + state = 0 + + +if __name__ == "__main__": + uart_x = UART(UART.UART2, 115200, 8, 0, 1, 0) + usbcdc = UART(UART.UART3, 115200, 8, 0, 1, 0) # It is unvalid to set the baudrate, while in communication, any baudrate is available + + uart_x.write("Grey_测试") + usbcdc.write("Grey_测试") + + _thread.start_new_thread(uart_x_read, ()) # Create a thread to listen for receiving UART messages + _thread.start_new_thread(usbcdc_read, ()) # Create a thread to listen for receiving CDC messages + + while state: + utime.sleep_ms(1) ``` Run above script code, the data transparency between UART2 and USB CDC PORT can be achievable.