diff --git a/docs/Advanced_development/en/QuecPythonBus/LED.md b/docs/Advanced_development/en/QuecPythonBus/LED.md index e1c782ce142f75c2db0fc56d9115a70a3039a423..039e1f79cd7de7abc120095976a2bc9bbee156b8 100644 --- a/docs/Advanced_development/en/QuecPythonBus/LED.md +++ b/docs/Advanced_development/en/QuecPythonBus/LED.md @@ -2,13 +2,13 @@ ## Revision history -| Version | Date | Author | Description | -| ------- | ---------- | ------ | --------------- | -| 1.0 | 2021-09-15 | Grey | Initial Version | +| Version | Date | Author | Description | +| ------- | ---------- | ------- | --------------- | +| 1.0 | 2022-02-14 | Grey.Tu | Initial Version | In this article, we mainly focus on how to manipulate external components via GPIO from views of HW and SW designs. By reading it, you will learn about checking HW connection relationship, compiling codes and verify test theory. -As for specific API info, please refer to [QuecPython-machine - PIN](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=pin) +As for specific API info, please refer to [QuecPython-machine - PIN](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pin) ## HW description @@ -20,13 +20,9 @@ As one of the most commonly used peripherals, the GPIO can be used to output hig ## 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 info, please refer to [QuecPython-machine - PIN](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=pin). +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 info, please refer to [QuecPython-machine - PIN](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pin). -Take the EC600S/N as an example, the PIN 10 is the GPIO 1. - -Start to compile codes. - -Add following codes on **.py** file to read/write GPIO. +Start to compile codes. Add following codes on **.py** file to read/write GPIO. ```python IOdictRead = {} # Record the initialized GPIO port @@ -65,7 +61,7 @@ LED4 = Pin.GPIO4 # Define LED pin LED5 = Pin.GPIO5 # Define LED pin ``` -对某一个引脚实现控制:Control one certain pin +Control one certain pin: ```python def IO_On(gpioX): # Set the pin as 0 @@ -75,7 +71,7 @@ def IO_Off(gpioX): # Set the pin as 1 ``` -对全部引脚实现控制:Control all pins +Control all pins: ```python def IO_All_Off(): # Set all pins as 1 @@ -96,15 +92,20 @@ import utime def main(): while True: - IO_All_Off() # Off IO_On(LED1) # On + IO_All_Off() # Off + IO_On(LED1) # On utime.sleep_ms(200) # Latency - IO_All_Off() # Off IO_On(LED2) # On + IO_All_Off() # Off + IO_On(LED2) # On utime.sleep_ms(200) # Latency - IO_All_Off() # Off IO_On(LED3) # On + IO_All_Off() # Off + IO_On(LED3) # On utime.sleep_ms(200) # Latency - IO_All_Off() # Off IO_On(LED4) # On + IO_All_Off() # Off + IO_On(LED4) # On utime.sleep_ms(200) # Latency - IO_All_Off() # Off IO_On(LED5) # On + IO_All_Off() # Off + IO_On(LED5) # On utime.sleep_ms(200) # Latency ``` diff --git a/docs/Advanced_development/en/QuecPythonBus/code/code_LED.py b/docs/Advanced_development/en/QuecPythonBus/code/code_LED.py index 80821f9f2b9f0285a3d728d004a4b991497cc57a..150dc48f536b83d87a3610ccd3cfb4c79350417a 100644 --- a/docs/Advanced_development/en/QuecPythonBus/code/code_LED.py +++ b/docs/Advanced_development/en/QuecPythonBus/code/code_LED.py @@ -1,13 +1,13 @@ -# 实验1: 跑马灯 -# API资料参考连接: https://python.quectel.com/wiki/#/zh-cn/api/?id=pin +# Name of experiment: horse race lamp +# API connection: https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pin from machine import Pin import utime -IOdictRead = {} # 记录已经初始化的GPIO口 -IOdictWrite = {} # 记录已经初始化的GPIO口 +IOdictRead = {} # Record the GPIO ports that have been initialized +IOdictWrite = {} # Record the GPIO ports that have been initialized def GPIO_Read(gpioX, Pull=Pin.PULL_DISABLE, level=1): @@ -34,22 +34,22 @@ def GPIO_Write(gpioX, level, Pull=Pin.PULL_DISABLE): gpioIO.write(level) -LED1 = Pin.GPIO1 # 定义LED引脚 -LED2 = Pin.GPIO2 # 定义LED引脚 -LED3 = Pin.GPIO3 # 定义LED引脚 -LED4 = Pin.GPIO4 # 定义LED引脚 -LED5 = Pin.GPIO5 # 定义LED引脚 +LED1 = Pin.GPIO1 # Define LED pin +LED2 = Pin.GPIO2 # Define LED pin +LED3 = Pin.GPIO3 # Define LED pin +LED4 = Pin.GPIO4 # Define LED pin +LED5 = Pin.GPIO5 # Define LED pin -def IO_On(gpioX): # 某个引脚置0 - GPIO_Write(gpioX, 0) # 调用写函数 +def IO_On(gpioX): # Set the pin as 0 + GPIO_Write(gpioX, 0) # Call write function -def IO_Off(gpioX): # 某个引脚置1 - GPIO_Write(gpioX, 1) # 调用写函数 +def IO_Off(gpioX): # Set the pin as 1 + GPIO_Write(gpioX, 1) # Call write function -def IO_All_Off(): # 全部引脚置1 +def IO_All_Off(): # Set all pins as 1 IO_Off(LED1) IO_Off(LED2) IO_Off(LED3) @@ -59,21 +59,21 @@ def IO_All_Off(): # 全部引脚置1 def main(): while True: - IO_All_Off() # 灭 - IO_On(LED1) # 亮 - utime.sleep_ms(200) # 延时 - IO_All_Off() # 灭 - IO_On(LED2) # 亮 - utime.sleep_ms(200) # 延时 - IO_All_Off() # 灭 - IO_On(LED3) # 亮 - utime.sleep_ms(200) # 延时 - IO_All_Off() # 灭 - IO_On(LED4) # 亮 - utime.sleep_ms(200) # 延时 - IO_All_Off() # 灭 - IO_On(LED5) # 亮 - utime.sleep_ms(200) # 延时 + IO_All_Off() # Off + IO_On(LED1) # On + utime.sleep_ms(200) # Latency + IO_All_Off() # Off + IO_On(LED2) # On + utime.sleep_ms(200) # Latency + IO_All_Off() # Off + IO_On(LED3) # On + utime.sleep_ms(200) # Latency + IO_All_Off() # Off + IO_On(LED4) # On + utime.sleep_ms(200) # Latency + IO_All_Off() # Off + IO_On(LED5) # On + utime.sleep_ms(200) # Latency if __name__ == "__main__": diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_PIN_3.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_PIN_3.jpg index cb53a486ee169e810b4f3c6eda9cb39e0ca34e51..3dec1e4b63c45861e6deb193700d1a057a256bc4 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_PIN_3.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_PIN_3.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonBus/media/media_PIN_4.jpg b/docs/Advanced_development/en/QuecPythonBus/media/media_PIN_4.jpg index a553cc0beac6a4a072b8ab18b5de88c16c4ab451..c6aa503728016df64d0da649984e30acc004324b 100644 Binary files a/docs/Advanced_development/en/QuecPythonBus/media/media_PIN_4.jpg and b/docs/Advanced_development/en/QuecPythonBus/media/media_PIN_4.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/LCD.md b/docs/Advanced_development/en/QuecPythonSub/LCD.md index 8ac72dfb24239f911b03f7380b041ee6310a8888..eb725da47ae11859d0d5060e4845e66e64f0c0d9 100644 --- a/docs/Advanced_development/en/QuecPythonSub/LCD.md +++ b/docs/Advanced_development/en/QuecPythonSub/LCD.md @@ -4,7 +4,8 @@ |Version | date | author | change statement| | ---- | ---------- | ------- | -------- | -|1.0 | 2021-10-06 | grey. Tu | First Edition| +|1.0 | 2021-10-06 | Grey. Tu | First Edition| +|1.1 | 2022-01-14 | Grey.Tu | Fixed an issue where routine code could not be downloaded | This article mainly introduces LCD display based on ec600x and does a small experiment of LCD display. @@ -76,55 +77,55 @@ The interface in this example is implemented based on quecpthon's machine. LCD l ### LCD initialization function -This chapter encapsulates some API functions. Before introducing these APIs, let's take a look at the function interfaces provided in the firmware. Here we mainly introduce the LCD initialization function. Other functions are relatively simple. Please refer to: [quecpthon machine - LCD](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=lcd) 进行了解。 +This chapter encapsulates some API functions. Before introducing these APIs, let's take a look at the function interfaces provided in the firmware. Here we mainly introduce the LCD initialization function. Other functions are relatively simple. Please refer to: [quecpthon machine - LCD](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=lcd) . ```python -#lcd.lcd_ Init function parameter description -#lcd_ init_ Data: incoming LCD configuration command -#lcd_ Width: the width of the LCD screen. Width not exceeding 500 -#lcd_ High: the height of the LCD screen. Height not exceeding 500 -#lcd_ CLK: LCD SPI clock. SPI clock is 6.5k/13k/26k/52k -#data_ Line: number of data lines. The parameter values are 1 and 2. -#line_ Num: number of lines. The parameter values are 3 and 4. -#lcd_ Type: screen type. 0:rgb; 1:fstn。 -#lcd_ Invalid: pass in the configuration command of LCD locale -#lcd_ display_ On: pass in the configuration command of LCD screen -#lcd_ display_ Off: pass in the configuration command of LCD screen off -#lcd_ set_ Brightness: pass in the configuration command of LCD screen brightness. Set to none to indicate by LCD_ BL_ K controls the brightness (some screens are controlled by registers, and some are controlled by lcd_bl_k) +# lcd.lcd_ Init function parameter description +# lcd_ init_ Data: incoming LCD configuration command +# lcd_ Width: the width of the LCD screen. Width not exceeding 500 +# lcd_ High: the height of the LCD screen. Height not exceeding 500 +# lcd_ CLK: LCD SPI clock. SPI clock is 6.5k/13k/26k/52k +# data_ Line: number of data lines. The parameter values are 1 and 2. +# line_ Num: number of lines. The parameter values are 3 and 4. +# lcd_ Type: screen type. 0:rgb; 1:fstn。 +# lcd_ Invalid: pass in the configuration command of LCD locale +# lcd_ display_ On: pass in the configuration command of LCD screen +# lcd_ display_ Off: pass in the configuration command of LCD screen off +# lcd_ set_ Brightness: pass in the configuration command of LCD screen brightness. Set to none to indicate by LCD_ BL_ K controls the brightness (some screens are controlled by registers, and some are controlled by lcd_bl_k) lcd.lcd_init(lcd_init_data, lcd_width, lcd_hight, lcd_clk, data_line, line_num, lcd_type, lcd_invalid, lcd_display_on, lcd_display_off, lcd_set_brightness) ``` Next, the parameters of LCD initialization function are introduced through the actual code. ```python -from machine import LCD #Screen display module - -#Common color definitions -red = 0xF800 #gules -green = 0x07E0 #green -blue = 0x001F #blue -white = 0xFFFF #white -black = 0x0000 #black -purple = 0xF81F #purple -colour = white #Default background color - -#Screen parameters -screen_high = 240 #Screen height -screen_wide = 240 #Screen height -XSTART_H = 0xf0 #Start point X coordinate high byte register -XSTART_L = 0xf1 #Start point X coordinate low byte register -XEND_H = 0xE0 #End point X coordinate high byte register -XEND_L = 0xE1 #End point X coordinate low byte register -YSTART_H = 0xf2 #Start point y coordinate high byte register -YSTART_L = 0xf3 #Start point y coordinate low byte register -YEND_H = 0xE2 #End point y coordinate high byte register -YEND_L = 0xE3 #End point y coordinate low byte register - -#Screen initialization parameters -#Three elements in a tuple form a group, and each element in a single group is defined as follows: -#1: Type, 0 indicates command; 1 represents data; 2 indicates delay -#2: Length. If the type is 0, the length represents the amount of data after the command; If the type is 1, the length represents the length of the data -#3: Parameter value +from machine import LCD # Screen display module + +# Common color definitions +red = 0xF800 # gules +green = 0x07E0 # green +blue = 0x001F # blue +white = 0xFFFF # white +black = 0x0000 # black +purple = 0xF81F # purple +colour = white # Default background color + +# Screen parameters +screen_high = 240 # Screen height +screen_wide = 240 # Screen height +XSTART_H = 0xf0 # Start point X coordinate high byte register +XSTART_L = 0xf1 # Start point X coordinate low byte register +XEND_H = 0xE0 # End point X coordinate high byte register +XEND_L = 0xE1 # End point X coordinate low byte register +YSTART_H = 0xf2 # Start point y coordinate high byte register +YSTART_L = 0xf3 # Start point y coordinate low byte register +YEND_H = 0xE2 # End point y coordinate high byte register +YEND_L = 0xE3 # End point y coordinate low byte register + +# Screen initialization parameters +# Three elements in a tuple form a group, and each element in a single group is defined as follows: +# 1: Type, 0 indicates command; 1 represents data; 2 indicates delay +# 2: Length. If the type is 0, the length represents the amount of data after the command; If the type is 1, the length represents the length of the data +# 3: Parameter value init_data = ( 0, 0, 0x11, 0, 1, 0x36, @@ -203,11 +204,11 @@ init_data = ( 0, 0, 0x2c, ) -#Screen area display parameters -#Three elements in a tuple form a group, and each element in a single group is defined as follows: -#1: Type, 0 indicates command; 1 represents data; 2 indicates delay -#2: Length. If the type is 0, the length represents the amount of data after the command; If the type is 1, the length represents the length of the data -#3: Parameter value +# Screen area display parameters +# Three elements in a tuple form a group, and each element in a single group is defined as follows: +# 1: Type, 0 indicates command; 1 represents data; 2 indicates delay +# 2: Length. If the type is 0, the length represents the amount of data after the command; If the type is 1, the length represents the length of the data +# 3: Parameter value lcd_set_display_area = ( 0, 4, 0x2a, 1, 1, XSTART_H, @@ -222,11 +223,11 @@ lcd_set_display_area = ( 0, 0, 0x2c, ) -lcd = LCD() #create object -lcd_init_data = bytearray(init_data) #Conversion initialization parameter array -lcd_invalid = bytearray(lcd_set_display_area) #Conversion area setting parameter array +lcd = LCD() # create object +lcd_init_data = bytearray(init_data) # Conversion initialization parameter array +lcd_invalid = bytearray(lcd_set_display_area) # Conversion area setting parameter array self.lcd.lcd_init(lcd_init_data, screen_high, screen_wide, - 6500, 1, 4, 0, lcd_invalid, None, None, None) #Initialize LCD screen + 6500, 1, 4, 0, lcd_invalid, None, None, None) # Initialize LCD screen ``` ### Encapsulating API functions @@ -271,15 +272,15 @@ lcd_st7789v = st7789v.ST7789V(240, 240) *Parameters: -|Parameter | type | description| -| ------ | ------------ | ----------------------------- | -|X | integer | X axis starting point coordinate| -|Y | integer | Y axis starting point coordinate| -|Xsize | integer | width of characters to be displayed| -|Ysize | integer | height of the character to be displayed| -| ch_ Buf | tuple or list | stores the font data of the characters to be displayed| -|FC | 16 bit hex | font color, such as 0x0000 indicates black| -|BC | 16 bit hexadecimal | background color, such as 0xFFFF indicates white| +| Parameter | type | description | +| --------- | ------------------ | ------------------------------------------------------ | +| X | integer | X axis starting point coordinate | +| Y | integer | Y axis starting point coordinate | +| Xsize | integer | width of characters to be displayed | +| Ysize | integer | height of the character to be displayed | +| ch_ Buf | tuple or list | stores the font data of the characters to be displayed | +| FC | 16 bit hex | font color, such as 0x0000 indicates black | +| BC | 16 bit hexadecimal | background color, such as 0xFFFF indicates white | *Return value: @@ -341,60 +342,6 @@ Parameters: -#### Single Chinese character display - -> **lcd_st7789v.lcd_show_chinese(x, y, xsize, ysize, ch, fc, bc)** - -*Function: - - Chinese character display currently supports the font sizes of 16x16, 16X24 and 24x24 of several Chinese characters in the example. If you need to display other Chinese characters and other font sizes, you need to increase the font data of the corresponding size, and add the dictionary of the corresponding font in this function. - -*Parameters: - -|Parameter | type | description| -| ----- | ------------ | ----------------------------- | -|X | integer | X axis starting point coordinate| -|Y | integer | Y axis starting point coordinate| -|Xsize | integer | width of characters to be displayed| -|Ysize | integer | height of the character to be displayed| -|Ch | character | Chinese character to be displayed| -|FC | 16 bit hex | font color, such as 0x0000 indicates black| -|BC | 16 bit hexadecimal | background color, such as 0xFFFF indicates white| - -*Return value: - - nothing - - - -#### Chinese character string display - -> **lcd_st7789v.lcd_show_chinese_str(x, y, xsize, ysize, str, fc, bc)** - -*Function: - - Chinese character string display, display order, starting from left to right with the set starting coordinate. In the example, only a 16x16 font size of several Chinese characters used is provided. If users need characters of other sizes, they need to recreate the font and display it on ` LCD_ st7789v.lcd_ show_ Chinese (x, y, xsize, ysize, STR, FC, BC) ` interface adds support for new font libraries. - - Note: make sure that the incoming string can be displayed on the current line, that is, the value of the number of incoming Chinese characters multiplied by the width of a single Chinese character, plus the value of the starting coordinate X, cannot exceed the screen width, otherwise the program will directly report an error and prompt that it exceeds the display range. - -*Parameters: - -|Parameter | type | description| -| ----- | ------------ | ----------------------------------- | -|X | integer | X axis starting point coordinate| -|Y | integer | Y axis starting point coordinate| -|Xsize | integer | width of characters to be displayed| -|Ysize | integer | height of the character to be displayed| -|STR | string | Chinese character string to be displayed, such as' mobile communication '| -|FC | 16 bit hex | font color, such as 0x0000 indicates black| -|BC | 16 bit hexadecimal | background color, such as 0xFFFF indicates white| - -*Return value: - - None. - - - #### Show small size pictures > **lcd_st7789v.lcd_show_image(image_data, x, y, width, heigth)** @@ -502,10 +449,10 @@ If it is a network independent code, you can mask the wait_ network_ connected() ''' # checknet.wait_network_connected() - #user designation codes + # user designation codes '''######################【User code star】#####################################''' - #Display a 240 * 240 size picture + # Display a 240 * 240 size picture lcd_st7789v.lcd_show_image_file("usr/image.txt", 0, 0, 240, 240, 8) '''######################【User code end 】#####################################''' @@ -565,7 +512,7 @@ Pctolcd2002 is a character modeling software, which can generate font data of Ch (1) Open image2lcd software, click [open] button and select the picture to be displayed; -![media_lcd_8](media/media_lcd_8.png) +![media_lcd_8](media/media_lcd_8.jpg) (2) Select [C language array (*. C)] as the output data type, select [horizontal scanning] as the scanning mode, and select [16 bit true color] as the output gray level; @@ -575,24 +522,6 @@ Pctolcd2002 is a character modeling software, which can generate font data of Ch -### How to mold characters - -(1) Open pctolcd2002 software and click [mode] - [character mode (W)]; - -(2) Select font and set font size as required; - -![media_lcd_9](media/media_lcd_9.png) - -(3) Click the gear icon to enter the interface as shown below, select [negative code], [line by line], [forward] and [C51 format], and click OK; - -![media_lcd_10](media/media_lcd_10.png) - -(4) After entering the character to be molded, click generate font to get the corresponding font data, and save the font data to the dictionary according to the format in the example fonts.py file. - -![media_lcd_11](media/media_lcd_11.png) - - - ## Matching code - < a href = "code / lcd_file. Zip" target = "_blank" > Download experimental materials + Download experimental materials diff --git a/docs/Advanced_development/en/QuecPythonSub/code/LCD_file.7z b/docs/Advanced_development/en/QuecPythonSub/code/LCD_file.7z new file mode 100644 index 0000000000000000000000000000000000000000..64f58ec2fbb672b6c652012705888a1d4ebf3f45 Binary files /dev/null and b/docs/Advanced_development/en/QuecPythonSub/code/LCD_file.7z differ diff --git a/docs/Advanced_development/en/QuecPythonSub/code/LCD_file.rar b/docs/Advanced_development/en/QuecPythonSub/code/LCD_file.rar deleted file mode 100644 index de02cb7575b4a7cd7ab5a03f36bff6f3ab3af6d7..0000000000000000000000000000000000000000 Binary files a/docs/Advanced_development/en/QuecPythonSub/code/LCD_file.rar and /dev/null differ diff --git a/docs/Advanced_development/en/QuecPythonSub/code/code_ebf_smd4805.py b/docs/Advanced_development/en/QuecPythonSub/code/code_ebf_smd4805.py index ee9ac94fef04638b31b41e9a0017bf11a585210f..558fc17352dec53107aa96e044494f669bff056d 100644 --- a/docs/Advanced_development/en/QuecPythonSub/code/code_ebf_smd4805.py +++ b/docs/Advanced_development/en/QuecPythonSub/code/code_ebf_smd4805.py @@ -11,25 +11,23 @@ Copyright 2021 - 2021 quectel ''' """ -参考资料 +reference material 1. API -https://python.quectel.com/wiki/#/zh-cn/api/?id=pwm -https://python.quectel.com/wiki/#/zh-cn/api/?id=pin -2. 模块资料 +https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pwm +https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=pin +2. Module data https://item.taobao.com/item.htm?ft=t&id=543053172983 -步进电机驱动器 + 42步进电机 -2.1 模块开发资料 https://ebf-products.readthedocs.io/zh_CN/latest/module/motor/ebf-msd4805.html """ """ -引脚连接 -| 电机 | EC600开发板 | 对应的函数标号 | -| ---------- | ------------------ | ------- | -| ENA- (GPIO) | GPIO81 (引脚号16) | GPIO7 | -| DIR- (GPIO) | GPIO77 (引脚号15) | GPIO6 | -| PUL- (PWM) | GPIO2_1V8 (引脚号70) | PWM2 | -| ENA+ DIR+ PUL+ | 1V8(电源) | 无 | +Pin connection +| electrical machinery | development board | The corresponding function label | +| -------------------- | ----------------- | -------------------------------- | +| ENA- (GPIO) | GPIO81 (pin 16) | GPIO7 | +| DIR- (GPIO) | GPIO77 (pin15) | GPIO6 | +| PUL- (PWM) | GPIO2_1V8 (pin70) | PWM2 | +| ENA+ DIR+ PUL+ | 1V8(power supply) | 无 | """ @@ -61,21 +59,21 @@ class ebf_smd4805(): dev_log = None - # 步进电机的参数 - sm_para_step = None # 步进角度 - # 控制器的参数 - env_pin = None # 使能引脚 - dir_pin = None # 方向引脚 - pul_pwm = None # 脉冲输出引脚 - ctrl_divstep = None # 细分参数,具体请参考控制器手册 + # Parameters of stepping motor + sm_para_step = None # Step angle + # Parameters of controller + env_pin = None # Enable pin + dir_pin = None # Direction pin + pul_pwm = None # Pulse output pin + ctrl_divstep = None # For subdivision parameters, please refer to the controller manual def init(self, step, divstep): self.dev_log = log.getLogger("ebf_smd4805") self.env_pin = Pin(Pin.GPIO7, Pin.OUT, Pin.PULL_DISABLE, 0) self.dir_pin = Pin(Pin.GPIO6, Pin.OUT, Pin.PULL_DISABLE, 0) - # 配置电机的参数 + # Configure the parameters of the motor self.sm_para_step = step - # 配置控制器的参数 + # Configure the parameters of the controller self.ctrl_divstep = divstep def reset(self): @@ -84,23 +82,23 @@ class ebf_smd4805(): if self.pul_pwm is not None: self.pul_pwm.close() - # 根据频率 初始化PWM + # Initialize PWM according to frequency def outputpwm(self, HZ, duty_cycle): - # 将HZ 转化为 us 级别 + # Convert Hz to us level cycleTime = int(1000000/HZ) highTime = int(cycleTime * duty_cycle) return highTime, cycleTime - # 根据速度,设置PWM的输出 + # Set the output of PWM according to the speed def enable_pwm(self, speed): - # 1. 首先根据步进电机的步进角度,计算旋转一圈需要多少个脉冲 + # 1. First, calculate the number of pulses required for one revolution according to the stepping angle of the stepping Count_pulse = int(360/self.sm_para_step) self.dev_log.debug("sm motor step as {0}".format(Count_pulse)) - # 2. 根据控制器的细分参数,计算控制器控制步进电机旋转一圈,需要多少的脉冲 + # 2. According to the subdivision parameters of the controller, calculate the number of pulses required for the controller to control the stepper motor to rotate for one turn Count_pulse = int(Count_pulse * self.ctrl_divstep) - # 3. 最后计算出1秒旋转speed圈,需要多少个脉冲 , 换句话说 就是频率 + # 3. Finally, calculate how many pulses are needed to rotate the speed cycle in one second, in other words, the frequency Count_pulse = int(Count_pulse * speed) - # 4. 初始化PWM, 默认占空比%50 + # 4. Initialize PWM, default duty cycle% 50 highTime, cycleTime = self.outputpwm(Count_pulse, 0.1) self.dev_log.debug( """config frequency is {0}HZ,cycleTime {1}us, hightime {2}us""" @@ -114,9 +112,9 @@ class ebf_smd4805(): self.pul_pwm.close() pass - # speed 为速度, 每秒多少圈 - # Duration 为持续时间, ms - # dir 表示方向 + # Speed is the speed, how many laps per second + # Duration is the duration, Ms + # Dir indicates direction def run(self, speed, Duration, dir=DIR_CLOCKWISE): self.dir_pin.write(dir) self.dev_log.info( diff --git a/docs/Advanced_development/en/QuecPythonSub/code/code_i2c_aht10.py b/docs/Advanced_development/en/QuecPythonSub/code/code_i2c_aht10.py index e706b11aaf1531f036b4eaa2091c898fa18b26fb..4a9793c7c62a4319cb20ef358c6c4b4520ab6e47 100644 --- a/docs/Advanced_development/en/QuecPythonSub/code/code_i2c_aht10.py +++ b/docs/Advanced_development/en/QuecPythonSub/code/code_i2c_aht10.py @@ -4,8 +4,8 @@ Project: i2c File Created: Monday, 28th December 2020 5:17:28 pm Author: chengzhu.zhou ----- -Last Modified: Tuesday, 29th December 2020 9:01:35 pm -Modified By: chengzhu.zhou +Last Modified: Tuesday, 29th December 2021 9:01:35 pm +Modified By: Grey.Tu ----- Copyright 2020 - 2020 quectel ''' @@ -19,9 +19,8 @@ import utime as time 3. read data """ -# API 手册 http://qpy.quectel.com/wiki/#/zh-cn/api/?id=i2c -# AHT10 说明书 -# https://server4.eca.ir/eshop/AHT10/Aosong_AHT10_en_draft_0c.pdf +# API: https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=i2c +# AHT10: https://server4.eca.ir/eshop/AHT10/Aosong_AHT10_en_draft_0c.pdf class aht10class(): @@ -53,14 +52,14 @@ class aht10class(): def aht10_init(self, addre=0x38, Alise="Ath10"): self.i2c_log = log.getLogger(Alise) - self.i2c_dev = I2C(I2C.I2C1, I2C.STANDARD_MODE) # 返回i2c对象 + self.i2c_dev = I2C(I2C.I2C1, I2C.STANDARD_MODE) # Returns an i2C object self.i2c_addre = addre self.sensor_init() pass def aht10_transformation_temperature(self, data): r_data = data - # 根据数据手册的描述来转化温度 + # Convert the temperature as described in the data sheet humidity = (r_data[0] << 12) | ( r_data[1] << 4) | ((r_data[2] & 0xF0) >> 4) humidity = (humidity/(1 << 20)) * 100.0 @@ -98,7 +97,7 @@ def i2c_aht10_test(): ath_dev = aht10class() ath_dev.aht10_init() - # 测试十次 + # The test ten times for i in range(10): ath_dev.Trigger_measurement() time.sleep(1) diff --git a/docs/Advanced_development/en/QuecPythonSub/code/code_i2c_lis2dh12.py b/docs/Advanced_development/en/QuecPythonSub/code/code_i2c_lis2dh12.py index 0d80c9fa86eb2aca92c888702fbd3e24760eb2ec..57fb70da8f09460c30759f0b8822ff390193ddae 100644 --- a/docs/Advanced_development/en/QuecPythonSub/code/code_i2c_lis2dh12.py +++ b/docs/Advanced_development/en/QuecPythonSub/code/code_i2c_lis2dh12.py @@ -4,7 +4,7 @@ import _thread from machine import I2C from machine import Pin -# 寄存器地址 +# Register address LIS2DH12_OUT_X_L = 0x28 LIS2DH12_OUT_X_H = 0x29 LIS2DH12_OUT_Y_L = 0x2A @@ -13,7 +13,7 @@ LIS2DH12_OUT_Z_L = 0x2C LIS2DH12_OUT_Z_H = 0x2D LIS2DH12_FIFO_CTRL_REG = 0x2E -# 控制寄存器 +# Control register LIS2DH12_CTRL_REG1 = 0x20 LIS2DH12_CTRL_REG2 = 0x21 LIS2DH12_CTRL_REG3 = 0x22 @@ -23,19 +23,19 @@ LIS2DH12_CTRL_REG6 = 0x25 LIS2DH12_REFERENCE_REG = 0x26 LIS2DH12_STATUS_REG = 0x27 -# 状态寄存器 +# Status register LIS2DH12_STATUS_REG_AUX = 0x7 -# 中断寄存器 +# Interrupt register LIS2DH12_INT1_CFG = 0x30 LIS2DH12_INT1_SRC = 0x31 LIS2DH12_INT1_THS = 0x32 LIS2DH12_INT1_DURATION = 0x33 -# 身份寄存器 +# Identity register LIS2DH12_WHO_AM_I = 0x0F -# 单击有关的寄存器 +# Click the relevant register LIS2DH12_CLICK_CFG = 0x38 LIS2DH12_CLICK_SRC = 0x39 LIS2DH12_CLICK_THS = 0x3A @@ -43,7 +43,7 @@ LIS2DH12_TIME_LIMIT = 0x3B LIS2DH12_TIME_LATENCY = 0x3C -# 将其和外部的中断引脚绑定到一起。 +# Bind it to the external interrupt pin。 class lis2dh12(object): i2c_dev = None address = None @@ -54,9 +54,9 @@ class lis2dh12(object): self.dev_log = log.getLogger("I2C") self.address = slave_address self.i2c_dev = I2C(I2C.I2C1, I2C.STANDARD_MODE) - self.int_pin = Pin(Pin.GPIO14, Pin.IN, Pin.PULL_PU, 0) # 中断引脚, 根据硬件连接不同而改变 + self.int_pin = Pin(Pin.GPIO14, Pin.IN, Pin.PULL_PU, 0) # Interrupt pin, which changes according to different hardware connections self.sensor_init() - self.single_tap_enable() # 配置单击检测 + self.single_tap_enable() # Configure click detection self.start_sensor() pass @@ -72,40 +72,39 @@ class lis2dh12(object): def write_data(self, regaddr, data, debug=True): w_data = bytearray([regaddr, data]) - # 临时将需要传送的地址放在数据位 + # Temporarily put the address to be transmitted in the data bit self.i2c_dev.write(self.address, bytearray(0x00), 0, bytearray(w_data), len(w_data)) if debug is True: self.dev_log.debug(" write 0x{0:02x} to 0x{1:02x}".format(data, regaddr)) def sensor_reset(self): - # 重置chip + # Reset chip self.write_data(LIS2DH12_CTRL_REG5, 0x80) utime.sleep_ms(100) r_data = self.read_data(LIS2DH12_WHO_AM_I, 1) - # 确定重启成功 + # Confirm that the restart is successful while r_data[0] != 0x33: r_data = self.read_data(LIS2DH12_WHO_AM_I, 1) utime.sleep_ms(5) - self.dev_log.debug("传感器重置成功") + self.dev_log.debug("sensor reset succeeded") pass def sensor_init(self): - self.sensor_reset() # 1. 重置设备 - # 2. 初始化传感器 - self.write_data(LIS2DH12_CTRL_REG2, 0x04) # 使能高分辨率 - self.write_data(LIS2DH12_CTRL_REG3, 0x80) # 将中断引到INT1 引脚上面, 默认高电平有效 + self.sensor_reset() # 1. Reset the device; 2. Initialize the sensor + self.write_data(LIS2DH12_CTRL_REG2, 0x04) # Enable high resolution + self.write_data(LIS2DH12_CTRL_REG3, 0x80) # Lead the interrupt to the INT1 pin. The default high level is valid self.write_data(LIS2DH12_CTRL_REG4, 0x08) # ±2g, High-resolution mode def single_tap_enable(self): - self.write_data(LIS2DH12_CLICK_CFG, 0x15) # 使能 XYZ 三轴单击中断, - # self.write_data(LIS2DH12_CLICK_CFG, 0x10) # 使能 Z 轴单击中断, - self.write_data(LIS2DH12_CLICK_THS, 0x30) # 设置阈值 - self.write_data(LIS2DH12_TIME_LIMIT, 0x18) # 设置时间窗口限制 - self.write_data(LIS2DH12_TIME_LATENCY, 0x02) # 设置延时 + self.write_data(LIS2DH12_CLICK_CFG, 0x15) # Enable XYZ triaxial click interrupt + # self.write_data(LIS2DH12_CLICK_CFG, 0x10) # enables z-axis click interrupt + self.write_data(LIS2DH12_CLICK_THS, 0x30) # Set threshold + self.write_data(LIS2DH12_TIME_LIMIT, 0x18) # Set time window limit + self.write_data(LIS2DH12_TIME_LATENCY, 0x02) # Set delay def start_sensor(self): - self.write_data(LIS2DH12_CTRL_REG1, 0x77) # 设置ODR 400HZ ,enable XYZ. - # self.write_data(LIS2DH12_CTRL_REG1, 0x74) # 设置ODR ,enable Z轴. + self.write_data(LIS2DH12_CTRL_REG1, 0x77) # Set ODR 400HZ ,enable XYZ + # self.write_data(LIS2DH12_CTRL_REG1, 0x74) # Set ODR ,enable Z axis utime.sleep_ms(20) # (7/ODR) = 18ms def read_xyz(self): @@ -125,27 +124,27 @@ class lis2dh12(object): def exti_processing_data(self): value = self.int_pin.read() - if value == 1: # 检测到中断信号了 + if value == 1: # Interrupt signal detected self.processing_data() return 1 else: return 0 -# 参数说明 -# state: 是否使能中断读取. 1:使能; 0:不使能 -# delay: 延时时间(ms), 此参数在中断模式下无效 -# retryCount: 读取次数 +# Parameter description +# state: whether to enable interrupt reading. 1: enable; 0: not enabled +# delay: delay time (MS). This parameter is invalid in interrupt mode +# retryCount: number of reads def is2dh12_thread(state, delay, retryCount): - # | 参数 | 参数类型 | 说明 | - # | -------- | ------- | ------------------ | - # | CRITICAL | 常量 | 日志记录级别的数值 50 | - # | ERROR | 常量 | 日志记录级别的数值 40 | - # | WARNING | 常量 | 日志记录级别的数值 30 | - # | INFO | 常量 | 日志记录级别的数值 20 | - # | DEBUG | 常量 | 日志记录级别的数值 10 | - # | NOTSET | 常量 | 日志记录级别的数值 0 | - log.basicConfig(level=log.INFO) # 设置日志输出级别 + # | Parameter | parameter type | description | + # | --------- | -------------- | ------------------------- | + # | CRITICAL | constant | value of logging level 50 | + # | ERROR | constant | value of logging level 40 | + # | WARNING | constant | value of logging level 30 | + # | INFO | constant | value of logging level 20 | + # | DEBUG | constant | value of logging level 10 | + # | NOTSET | constant | value of logging level 0 | + log.basicConfig(level=log.INFO) # Set log output level dev = lis2dh12() dev.init(0x19) while True: @@ -158,7 +157,7 @@ def is2dh12_thread(state, delay, retryCount): retryCount -= 1 if retryCount == 0: break - print("检测结束退出") + print("detection end exit") if __name__ == "__main__": diff --git a/docs/Advanced_development/en/QuecPythonSub/ebf_smd4805.md b/docs/Advanced_development/en/QuecPythonSub/ebf_smd4805.md index 6bfc3c90e5cdf3018ebd0cac098e3ea6c8e0c835..08b8b1e222751c5be14555a80f9b9637a03b7b0c 100644 --- a/docs/Advanced_development/en/QuecPythonSub/ebf_smd4805.md +++ b/docs/Advanced_development/en/QuecPythonSub/ebf_smd4805.md @@ -4,7 +4,7 @@ |Version | date | author | change statement| | ---- | ---------- | ------- | -------- | -|1.0 | 2021-09-24 | grey. Tu | First Edition| +|1.0 | 2021-09-24 | Grey. Tu | First Edition| This article mainly describes the use of ec600x to drive the stepper motor controller to drive the stepper motor. @@ -84,21 +84,11 @@ The stepper motor driver can be connected by common anode / common cathode, and ## Software design ```python -#Pin connection -#|Function label corresponding to motor pin | ec600 development board || -# | ------------------- | --------------------- | ------------ | -#|ENA - (GPIO) | gpio81 (pin 16) | gpio7| -#|Dir - (GPIO) | gpio77 (pin 15) | gpio6| -#| PUL- (PWM) | GPIO2_ 1v8 (pin 70) | pwm2| -#|ENA + dir + pul + | 1v8 (power supply) | none| - from misc import PWM from machine import Pin import utime as time import urandom as random import log - - def delay_500us(): for i in range(600): pass @@ -116,25 +106,25 @@ DIR_CLOCKWISE = 0x1 DIR_ANTI_CLOCKWISE = 0x0 -class ebf_smd4805: +class ebf_smd4805(): dev_log = None - #Parameters of stepping motor - sm_para_step = None #Step angle - #Parameters of controller - env_pin = None #Enable pin - dir_pin = None #Direction pin - pul_pwm = None #Pulse output pin - ctrl_divstep = None #For subdivision parameters, please refer to the controller manual + # Parameters of stepping motor + sm_para_step = None # Step angle + # Parameters of controller + env_pin = None # Enable pin + dir_pin = None # Direction pin + pul_pwm = None # Pulse output pin + ctrl_divstep = None # For subdivision parameters, please refer to the controller manual def init(self, step, divstep): self.dev_log = log.getLogger("ebf_smd4805") self.env_pin = Pin(Pin.GPIO7, Pin.OUT, Pin.PULL_DISABLE, 0) self.dir_pin = Pin(Pin.GPIO6, Pin.OUT, Pin.PULL_DISABLE, 0) - #Configure the parameters of the motor + # Configure the parameters of the motor self.sm_para_step = step - #Configure the parameters of the controller + # Configure the parameters of the controller self.ctrl_divstep = divstep def reset(self): @@ -143,29 +133,28 @@ class ebf_smd4805: if self.pul_pwm is not None: self.pul_pwm.close() - #Initialize PWM according to frequency - @staticmethod - def outputpwm(hz, duty_cycle): - #Convert Hz to us level - cycleTime = int(1000000 / hz) + # Initialize PWM according to frequency + def outputpwm(self, HZ, duty_cycle): + # Convert Hz to us level + cycleTime = int(1000000/HZ) highTime = int(cycleTime * duty_cycle) return highTime, cycleTime - #Set the output of PWM according to the speed + # Set the output of PWM according to the speed def enable_pwm(self, speed): - #1. First, calculate the number of pulses required for one revolution according to the stepping angle of the stepping motor + # 1. First, calculate the number of pulses required for one revolution according to the stepping angle of the stepping Count_pulse = int(360/self.sm_para_step) self.dev_log.debug("sm motor step as {0}".format(Count_pulse)) - #2. According to the subdivision parameters of the controller, calculate the number of pulses required for the controller to control the stepper motor to rotate for one turn + # 2. According to the subdivision parameters of the controller, calculate the number of pulses required for the controller to control the stepper motor to rotate for one turn Count_pulse = int(Count_pulse * self.ctrl_divstep) - #3. Finally, calculate how many pulses are needed to rotate the speed cycle in one second, in other words, the frequency + # 3. Finally, calculate how many pulses are needed to rotate the speed cycle in one second, in other words, the frequency Count_pulse = int(Count_pulse * speed) - #4. Initialize PWM, default duty cycle% 50 - highTime, cycleTime = self.outputpwm(Count_pulse, 0.5) + # 4. Initialize PWM, default duty cycle% 50 + highTime, cycleTime = self.outputpwm(Count_pulse, 0.1) self.dev_log.debug( """config frequency is {0}HZ,cycleTime {1}us, hightime {2}us""" .format(Count_pulse, cycleTime, highTime)) - self.pul_pwm = PWM(PWM.PWM0, PWM.ABOVE_10US, + self.pul_pwm = PWM(PWM.PWM2, PWM.ABOVE_10US, int(highTime), int(cycleTime)) self.pul_pwm.open() pass @@ -174,17 +163,17 @@ class ebf_smd4805: self.pul_pwm.close() pass - #Speed is the speed, how many laps per second - #Duration is the duration, Ms - #Dir indicates direction - def run(self, speed, duration, dir1=DIR_CLOCKWISE): - self.dir_pin.write(dir1) + # Speed is the speed, how many laps per second + # Duration is the duration, Ms + # Dir indicates direction + def run(self, speed, Duration, dir=DIR_CLOCKWISE): + self.dir_pin.write(dir) self.dev_log.info( "Configure the motor to rotate {0} revolutions per second".format(speed)) self.enable_pwm(speed) self.env_pin.write(1) # delay - for i in range(int(duration * 4)): + for i in range(int(Duration * 4)): delay_250us() self.env_pin.write(0) @@ -198,12 +187,13 @@ def test_ebf_smd4805(): ebf_smd4805_dev = ebf_smd4805() ebf_smd4805_dev.init(step=1.8, divstep=2) for i in range(2, 10): - ebf_smd4805_dev.run(i, duration=1000, dir1=DIR_CLOCKWISE) + ebf_smd4805_dev.run(i, Duration=1000, dir=DIR_CLOCKWISE) print("test_ebf_smd4805 Function exit,!!!") pass if __name__ == "__main__": + # creat a thread Check key status test_ebf_smd4805() ``` diff --git a/docs/Advanced_development/en/QuecPythonSub/i2c_aht.md b/docs/Advanced_development/en/QuecPythonSub/i2c_aht.md index 8f6bc95c7c91d2876ac93e9ebafff3d962ede8df..492f781840bd1597f366ff8e910dd4839eb27e66 100644 --- a/docs/Advanced_development/en/QuecPythonSub/i2c_aht.md +++ b/docs/Advanced_development/en/QuecPythonSub/i2c_aht.md @@ -12,9 +12,9 @@ This article is mainly based on ec600x onboard temperature and humidity sensor a ## Hardware introduction -![media_i2c_aht_1](media/media_i2c_aht_1.png) +![media_i2c_aht_1](media/media_i2c_aht_1.jpg) -Aht10 is a high-precision, fully calibrated, chip encapsulated temperature and humidity sensor. The MEMS manufacturing process ensures that the product has high reliability and excellent long-term stability. The sensor consists of a capacitive humidity sensing element connected to a high-performance CMOS microprocessor. The product has the advantages of excellent quality, ultra fast response, strong anti-interference ability and high cost performance. For details, please refer to: [aht10 product manual A2 20201221. PDF](media\AHT10产品手册 A2 20201221.pdf) 。 +Aht10 is a high-precision, fully calibrated, chip encapsulated temperature and humidity sensor. The MEMS manufacturing process ensures that the product has high reliability and excellent long-term stability. The sensor consists of a capacitive humidity sensing element connected to a high-performance CMOS microprocessor. The product has the advantages of excellent quality, ultra fast response, strong anti-interference ability and high cost performance. For details. Aht10 communicates through I2C interface. According to the introduction of the manual. Just send the data in the following way to get the data. diff --git a/docs/Advanced_development/en/QuecPythonSub/i2c_lis2dh.md b/docs/Advanced_development/en/QuecPythonSub/i2c_lis2dh.md index 0cda491d4162584569028a4913149f14e3688b3b..42c82e73103551823178e3e9cb78df4e5b7d1a7c 100644 --- a/docs/Advanced_development/en/QuecPythonSub/i2c_lis2dh.md +++ b/docs/Advanced_development/en/QuecPythonSub/i2c_lis2dh.md @@ -16,7 +16,7 @@ This article is mainly based on ec600x_ IIC interface introduces the three-axis ![media_i2c_lis2dh_1](media/media_i2c_lis2dh_1.png) -Lis2dh12 is a 3-Axis linear accelerometer with ultra-low power consumption and high performance belonging to "nano" series, with standard output of digital I2C and SPI serial interface. The device has ultra-low power consumption working mode, which can realize advanced energy-saving, intelligent, sleep wake-up and sleep recovery functions. Lis2dh12 has a dynamic user selectable full scale of ± 2G / ± 4G / ± 8g / ± 16g, and can measure acceleration through an output data rate of 1 Hz to 5 kHz. The device can be configured to generate an interrupt signal through independent inertial wake-up / free fall events and through the position of the device itself. The threshold and timing of the interrupt generator can be dynamically set by the end user. Please refer to [lis2dh12. PDF] for details(media\LIS2DH12.pdf) 。 +Lis2dh12 is a 3-Axis linear accelerometer with ultra-low power consumption and high performance belonging to "nano" series, with standard output of digital I2C and SPI serial interface. The device has ultra-low power consumption working mode, which can realize advanced energy-saving, intelligent, sleep wake-up and sleep recovery functions. Lis2dh12 has a dynamic user selectable full scale of ± 2G / ± 4G / ± 8g / ± 16g, and can measure acceleration through an output data rate of 1 Hz to 5 kHz. The device can be configured to generate an interrupt signal through independent inertial wake-up / free fall events and through the position of the device itself. The threshold and timing of the interrupt generator can be dynamically set by the end user. Please refer to[LIS2DH12.pdf](media\LIS2DH12.pdf) 。 ### Hardware connection @@ -24,11 +24,11 @@ Pin function introduction: |Pin number | pin name | description | backup| | ------ | --------------------- | ------------------------------------------------------------ | ---- | -|1 | SCL < br / > SPC | IIC / SPI clock pin| -|2 | CS | SPI enable pin, which controls the chip communication mode< Br / > 1: IIC communication; 2: SPI communication| -|3 | SDO < br / > SA0 | SPI mode is the data output pin< Br / > IIC mode is the device slave address selection pin, 1:0x19; 0:0x18。 | | -|4 | SDA < br / > SDI < br / > SDO | IIC mode is the data pin< Br / > data input pin in standard SPI mode< Br / > it can also be used as the data output pin of SPI| -|5 | res | grounding is enough| +|1 | SCL
SPC | IIC / SPI clock pin|| +|2 | CS | SPI enable pin, which controls the chip communication mode
1: IIC communication; 2: SPI communication || +|3 | SDO
SA0 | SPI mode is the data output pin
IIC mode is the device slave address selection pin, 1:0x19; 0:0x18。 | | +|4 | SDA
SDI
SDO | IIC mode is the data pin
data input pin in standard SPI mode
it can also be used as the data output pin of SPI || +|5 | res | grounding is enough|| |6 | GND | land || |7 | GND | land || |8 | GND | land || @@ -95,7 +95,7 @@ import _thread from machine import I2C from machine import Pin -#Register address +# Register address LIS2DH12_OUT_X_L = 0x28 LIS2DH12_OUT_X_H = 0x29 LIS2DH12_OUT_Y_L = 0x2A @@ -104,7 +104,7 @@ LIS2DH12_OUT_Z_L = 0x2C LIS2DH12_OUT_Z_H = 0x2D LIS2DH12_FIFO_CTRL_REG = 0x2E -#Control register +# Control register LIS2DH12_CTRL_REG1 = 0x20 LIS2DH12_CTRL_REG2 = 0x21 LIS2DH12_CTRL_REG3 = 0x22 @@ -114,19 +114,19 @@ LIS2DH12_CTRL_REG6 = 0x25 LIS2DH12_REFERENCE_REG = 0x26 LIS2DH12_STATUS_REG = 0x27 -#Status register +# Status register LIS2DH12_STATUS_REG_AUX = 0x7 -#Interrupt register +# Interrupt register LIS2DH12_INT1_CFG = 0x30 LIS2DH12_INT1_SRC = 0x31 LIS2DH12_INT1_THS = 0x32 LIS2DH12_INT1_DURATION = 0x33 -#Identity register +# Identity register LIS2DH12_WHO_AM_I = 0x0F -#Click the relevant register +# Click the relevant register LIS2DH12_CLICK_CFG = 0x38 LIS2DH12_CLICK_SRC = 0x39 LIS2DH12_CLICK_THS = 0x3A @@ -134,7 +134,7 @@ LIS2DH12_TIME_LIMIT = 0x3B LIS2DH12_TIME_LATENCY = 0x3C -#Bind it to the external interrupt pin. +# Bind it to the external interrupt pin。 class lis2dh12(object): i2c_dev = None address = None @@ -145,9 +145,9 @@ class lis2dh12(object): self.dev_log = log.getLogger("I2C") self.address = slave_address self.i2c_dev = I2C(I2C.I2C1, I2C.STANDARD_MODE) - self.int_pin = Pin(Pin.GPIO14, Pin.IN, Pin.PULL_PU, 0) #Interrupt pin, which changes according to different hardware connections + self.int_pin = Pin(Pin.GPIO14, Pin.IN, Pin.PULL_PU, 0) # Interrupt pin, which changes according to different hardware connections self.sensor_init() - self.single_tap_enable() #Configure click detection + self.single_tap_enable() # Configure click detection self.start_sensor() pass @@ -163,40 +163,39 @@ class lis2dh12(object): def write_data(self, regaddr, data, debug=True): w_data = bytearray([regaddr, data]) - #Temporarily put the address to be transmitted in the data bit + # Temporarily put the address to be transmitted in the data bit self.i2c_dev.write(self.address, bytearray(0x00), 0, bytearray(w_data), len(w_data)) if debug is True: self.dev_log.debug(" write 0x{0:02x} to 0x{1:02x}".format(data, regaddr)) def sensor_reset(self): - #Reset chip + # Reset chip self.write_data(LIS2DH12_CTRL_REG5, 0x80) utime.sleep_ms(100) r_data = self.read_data(LIS2DH12_WHO_AM_I, 1) - #Confirm that the restart is successful + # Confirm that the restart is successful while r_data[0] != 0x33: r_data = self.read_data(LIS2DH12_WHO_AM_I, 1) utime.sleep_ms(5) -self.dev_ Log.debug ("sensor reset succeeded") + self.dev_log.debug("sensor reset succeeded") pass def sensor_init(self): - self.sensor_reset() #1. Reset the device - #2. Initialize the sensor - self.write_data(LIS2DH12_CTRL_REG2, 0x04) #Enable high resolution - self.write_data(LIS2DH12_CTRL_REG3, 0x80) #Lead the interrupt to the INT1 pin. The default high level is valid + self.sensor_reset() # 1. Reset the device; 2. Initialize the sensor + self.write_data(LIS2DH12_CTRL_REG2, 0x04) # Enable high resolution + self.write_data(LIS2DH12_CTRL_REG3, 0x80) # Lead the interrupt to the INT1 pin. The default high level is valid self.write_data(LIS2DH12_CTRL_REG4, 0x08) # ±2g, High-resolution mode def single_tap_enable(self): - self.write_data(LIS2DH12_CLICK_CFG, 0x15) #Enable XYZ triaxial click interrupt, - #self.write_ Data (lis2dh12_click_cfg, 0x10) # enables z-axis click interrupt, - self.write_data(LIS2DH12_CLICK_THS, 0x30) #Set threshold - self.write_data(LIS2DH12_TIME_LIMIT, 0x18) #Set time window limit - self.write_data(LIS2DH12_TIME_LATENCY, 0x02) #Set delay + self.write_data(LIS2DH12_CLICK_CFG, 0x15) # Enable XYZ triaxial click interrupt + # self.write_data(LIS2DH12_CLICK_CFG, 0x10) # enables z-axis click interrupt + self.write_data(LIS2DH12_CLICK_THS, 0x30) # Set threshold + self.write_data(LIS2DH12_TIME_LIMIT, 0x18) # Set time window limit + self.write_data(LIS2DH12_TIME_LATENCY, 0x02) # Set delay def start_sensor(self): - self.write_data(LIS2DH12_CTRL_REG1, 0x77) #Set ODR 400Hz, enable XYZ - #self.write_ Data (lis2dh12_ctrl_reg1, 0x74) # set ODR, enable Z axis + self.write_data(LIS2DH12_CTRL_REG1, 0x77) # Set ODR 400HZ ,enable XYZ + # self.write_data(LIS2DH12_CTRL_REG1, 0x74) # Set ODR ,enable Z axis utime.sleep_ms(20) # (7/ODR) = 18ms def read_xyz(self): @@ -216,27 +215,27 @@ self.dev_ Log.debug ("sensor reset succeeded") def exti_processing_data(self): value = self.int_pin.read() - if value == 1: #Interrupt signal detected + if value == 1: # Interrupt signal detected self.processing_data() return 1 else: return 0 -#Parameter description -#State: whether to enable interrupt reading. 1: enable; 0: not enabled -#Delay: delay time (MS). This parameter is invalid in interrupt mode -#Retrycount: number of reads +# Parameter description +# state: whether to enable interrupt reading. 1: enable; 0: not enabled +# delay: delay time (MS). This parameter is invalid in interrupt mode +# retryCount: number of reads def is2dh12_thread(state, delay, retryCount): - #|Parameter | parameter type | description| - # | -------- | ------- | ------------------ | - #|Critical | constant | value of logging level 50| - #|Error | constant | value of logging level 40| - #|Warning | constant | value of logging level 30| - #|Info | constant | value of logging level 20| - #|Debug | constant | value of logging level 10| - #|Notset | constant | value 0 of logging level| - log.basicConfig(level=log.INFO) #Set log output level + # | Parameter | parameter type | description | + # | --------- | -------------- | ------------------------- | + # | CRITICAL | constant | value of logging level 50 | + # | ERROR | constant | value of logging level 40 | + # | WARNING | constant | value of logging level 30 | + # | INFO | constant | value of logging level 20 | + # | DEBUG | constant | value of logging level 10 | + # | NOTSET | constant | value of logging level 0 | + log.basicConfig(level=log.INFO) # Set log output level dev = lis2dh12() dev.init(0x19) while True: @@ -249,7 +248,7 @@ def is2dh12_thread(state, delay, retryCount): retryCount -= 1 if retryCount == 0: break -Print ("detection end exit") + print("detection end exit") if __name__ == "__main__": diff --git "a/docs/Advanced_development/en/QuecPythonSub/media/AHT10\344\272\247\345\223\201\346\211\213\345\206\214 A2 20201221.pdf" "b/docs/Advanced_development/en/QuecPythonSub/media/AHT10\344\272\247\345\223\201\346\211\213\345\206\214 A2 20201221.pdf" deleted file mode 100644 index 6a56e59302e3132c056b617edcd091666b26911f..0000000000000000000000000000000000000000 Binary files "a/docs/Advanced_development/en/QuecPythonSub/media/AHT10\344\272\247\345\223\201\346\211\213\345\206\214 A2 20201221.pdf" and /dev/null differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_1.jpg b/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_1.jpg index 448e34941fce5f3a89174e42a3e97046c185294c..9054c6b4b5cddc1396d30ed3dadb4b57ce23f566 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_1.jpg and b/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_1.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_3.jpg b/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_3.jpg index d1b9b96a236ee53dbffc43848d4b390e667fb693..e081ace623ee62d8eab9ca397a24c01781a47f1b 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_3.jpg and b/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_3.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_4.png b/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_4.png index 1d10a7f41db0bf594df84ca39930b7d815c389c7..dc8d9f8534d3bb13cf98320235b8e204c8c771bd 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_4.png and b/docs/Advanced_development/en/QuecPythonSub/media/media_ebf_smd4805_4.png differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_1.jpg b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..750445e58c159f5370fcd5881a1bbf66ba7a4ff4 Binary files /dev/null and b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_1.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_1.png b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_1.png deleted file mode 100644 index c30d0412462ed18a0b01e53a16469760bf467fb8..0000000000000000000000000000000000000000 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_1.png and /dev/null differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_2.png b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_2.png index 4078a7a3eabcf523aa62f652543b5fe50ee7fd83..97114d5daa98d60a7a333c2452b1bbcf4c8af2c7 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_2.png and b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_aht_2.png differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_lis2dh_2.png b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_lis2dh_2.png index 08698e7d38e908646d19b28162fa72d9fb28bf31..63234c91a3a2665d7742e497e1a7c9ecccdca56a 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_lis2dh_2.png and b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_lis2dh_2.png differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_lis2dh_3.png b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_lis2dh_3.png index 28754c22552bf9e5dffdb9e9b92c9070111265ce..908e1a847adc1db098450958d745bc90a7dbf6bd 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_lis2dh_3.png and b/docs/Advanced_development/en/QuecPythonSub/media/media_i2c_lis2dh_3.png differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_10.png b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_10.png deleted file mode 100644 index ccf35bc2c93b6b6e256a9d3e4d5801ab44043500..0000000000000000000000000000000000000000 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_10.png and /dev/null differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_11.png b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_11.png deleted file mode 100644 index 97d81540415f1baed0db17cea9378f04585a3ed9..0000000000000000000000000000000000000000 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_11.png and /dev/null differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_2.jpg b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_2.jpg index ea54fd40a581c98c074d1a8f7816221158178f5b..7562f425f5aa6e0a398ba893d9d7a4ca2de6939c 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_2.jpg and b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_2.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_4.jpg b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_4.jpg index a1c4ad75deb812cc754f762eaf25c41180409a9e..dbed07784f982480e02ca588fd7de6fae4eb310e 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_4.jpg and b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_4.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_5.jpg b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_5.jpg index 6029ab10718625015444319b8758350c7e5040fa..aa26a833d4e70a7f899dd67fd1eb18c49a3ab082 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_5.jpg and b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_5.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_7.jpg b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_7.jpg index 1a800d1f51f28d925647c253278a5ccaa3a4447e..430303ab9703f2d5b8e6e4842406c3cc3dd653c5 100644 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_7.jpg and b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_7.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_8.jpg b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_8.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d1477b40fb19a75e02d4d3bb9939c807332e5b4f Binary files /dev/null and b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_8.jpg differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_8.png b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_8.png deleted file mode 100644 index e674bdaf038a89b3164e3ee2f5aa7c9749af33ac..0000000000000000000000000000000000000000 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_8.png and /dev/null differ diff --git a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_9.png b/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_9.png deleted file mode 100644 index 68cd167605cd6bc331ac9f921c5b3325d649f5fd..0000000000000000000000000000000000000000 Binary files a/docs/Advanced_development/en/QuecPythonSub/media/media_lcd_9.png and /dev/null differ diff --git a/docs/Quick_start/en/media/Quectel_sbs_Socket_course.png b/docs/Quick_start/en/media/Quectel_sbs_Socket_course.png index 45647602d435c7f31e6f6431ee862bad7f76fea9..5fbc107ab0d0db246652b547b6228ae8809bacba 100644 Binary files a/docs/Quick_start/en/media/Quectel_sbs_Socket_course.png and b/docs/Quick_start/en/media/Quectel_sbs_Socket_course.png differ diff --git a/docs/Quick_start/en/media/Quectel_sbs_Socket_relation.png b/docs/Quick_start/en/media/Quectel_sbs_Socket_relation.png index 9ffe2a127ce0932449577fccf47b65099faeefdf..bdb8e0e4765c50be1b39a80564343b69b0d1d5b2 100644 Binary files a/docs/Quick_start/en/media/Quectel_sbs_Socket_relation.png and b/docs/Quick_start/en/media/Quectel_sbs_Socket_relation.png differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_1.png b/docs/Quick_start/en/media/sbs_json_picture_1.png deleted file mode 100644 index 9cd67d6d5297fa1639abcc81a6ddaccfffef1c21..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_1.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_10.png b/docs/Quick_start/en/media/sbs_json_picture_10.png deleted file mode 100644 index 5604133ef3352c61a0b968dcee9761f2f7e7bc3a..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_10.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_2.png b/docs/Quick_start/en/media/sbs_json_picture_2.png deleted file mode 100644 index df317173c3f1a7dad03f2d9d2a2da169a9840d77..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_2.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_3.png b/docs/Quick_start/en/media/sbs_json_picture_3.png deleted file mode 100644 index 57e26aa96a7ee1b5f5b09314c6e2aed86f74fbba..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_3.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_4.png b/docs/Quick_start/en/media/sbs_json_picture_4.png deleted file mode 100644 index 9098be763e2becd22055e2f9cfb3099b647070c4..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_4.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_5.png b/docs/Quick_start/en/media/sbs_json_picture_5.png deleted file mode 100644 index 12f9622180d5321748f1e4d4fc5dcfd21e5e625d..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_5.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_6.png b/docs/Quick_start/en/media/sbs_json_picture_6.png deleted file mode 100644 index 0df2069766be663bc7105bbe46d663ebc4b5b0ad..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_6.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_7.png b/docs/Quick_start/en/media/sbs_json_picture_7.png deleted file mode 100644 index adb7828fa58fbedb678265e452059fb840cf6fc2..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_7.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_8.png b/docs/Quick_start/en/media/sbs_json_picture_8.png deleted file mode 100644 index 6968b04a40787be856b302874a2f724b1c75cd76..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_8.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_json_picture_9.png b/docs/Quick_start/en/media/sbs_json_picture_9.png deleted file mode 100644 index afb5724c7278216072d58b405bfff446b853c1d9..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_json_picture_9.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_1.png b/docs/Quick_start/en/media/sbs_socket_picture_1.png deleted file mode 100644 index 513d870ad8946658bcedc2cdcb4bf096a42ef399..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_1.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_10.png b/docs/Quick_start/en/media/sbs_socket_picture_10.png deleted file mode 100644 index f44eabdd18c9a9d3e52a4fe0b59c14669fdd6352..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_10.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_2.png b/docs/Quick_start/en/media/sbs_socket_picture_2.png deleted file mode 100644 index 0d93c15e64706c3f1fd6842c946253f9093d0d0c..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_2.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_3.png b/docs/Quick_start/en/media/sbs_socket_picture_3.png deleted file mode 100644 index da9914445e775ab6aae8a3b2b38fcc3477ed393c..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_3.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_4.png b/docs/Quick_start/en/media/sbs_socket_picture_4.png deleted file mode 100644 index 20eacf5ea3837b5daafb5755eef6a459ad376be6..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_4.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_5.png b/docs/Quick_start/en/media/sbs_socket_picture_5.png deleted file mode 100644 index 01b43cc768f6703d3b1e54f44b7cc3a1aa9cda33..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_5.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_6.png b/docs/Quick_start/en/media/sbs_socket_picture_6.png deleted file mode 100644 index ec4646739464a740ae9bf90c8fb7187cbec65db6..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_6.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_7.png b/docs/Quick_start/en/media/sbs_socket_picture_7.png deleted file mode 100644 index c524185af736bb2138c5ee76236883f91e93709b..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_7.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_8.png b/docs/Quick_start/en/media/sbs_socket_picture_8.png deleted file mode 100644 index b3d41386fccd82b6641eb4c34bd99b01d4c8a564..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_8.png and /dev/null differ diff --git a/docs/Quick_start/en/media/sbs_socket_picture_9.png b/docs/Quick_start/en/media/sbs_socket_picture_9.png deleted file mode 100644 index 884981ae1fb0ac2efb7ead8ebce1db6979001c3a..0000000000000000000000000000000000000000 Binary files a/docs/Quick_start/en/media/sbs_socket_picture_9.png and /dev/null differ diff --git a/docs/Quick_start/en/socket.md b/docs/Quick_start/en/socket.md index ee349753266fadb882ea9418ca36c61cc2bad1ab..6fc8f1cd82b8aea515f7c412b5781c270c95523f 100644 --- a/docs/Quick_start/en/socket.md +++ b/docs/Quick_start/en/socket.md @@ -2,11 +2,9 @@ ## Revision history -| Version | Date | Author | Description | -| ------- | ---------- | ------- | ------------------------------------------------------ | -| 1.0 | 2021-04-07 | Grey.Tu | Initial version, Socket usage | -| 1.1 | 2021-09-07 | Grey.Tu | Add Socket_Json data test | -| 1.1.2 | 2021-09-08 | Grey.Tu | Modified figure name and deleted the repeated contents | +| Version | Date | Author | Description | +| ------- | ---------- | ------- | --------------- | +| 1.0 | 2021-09-08 | Grey.Tu | Initial version | ## Application note of Socket @@ -22,13 +20,13 @@ Socket, from the view of logic, can be considered as the endpoint of individual Socket, a set of interfaces, is the abstraction layer between application layer and TCP/IP protocol family. In design mode, the Socket serves as a door and hides all complicated TCP/IP protocol family. From the view of user, the Socket can undertake the role to organize data for sake of complying with assigned protocol. -![sbs_socket_01(E)](media\sbs_socket_01(E).png) +![Quectel_sbs_Socket_relation](media/Quectel_sbs_Socket_relation.png) ### The Socket process As is known to all, either Unix or Linux treats everything as file, which can be done with following steps: Open the file, write/read it, finally, close it. However, the socket is originated from Unix. During the process, the server can be considered as web, and the user end can be thought as the browser which is going to get access to web. Thus, the whole process is corresponding to the steps as shown above. -![sbs_Socket_02(E)](media\sbs_Socket_02(E).png) +![Quectel_sbs_Socket_course](media/Quectel_sbs_Socket_course.png) ### About socket application @@ -139,143 +137,13 @@ Now that we have received one string of JSON format, you can deserialize it as a ## About QuecPython Socket API -For details, please refer to [usocket - socket module](https://python.quectel.com/wiki/#/zh-cn/api/pythonStdlib?id=usocket-socket模块) +For details, please refer to [usocket - socket module](https://python.quectel.com/wiki/#/en-us/api/pythonStdlib?id=usocket-socket模块) +For details, please refer to[ujson - JSON Code and Decode](https://python.quectel.com/wiki/#/en-us/api/pythonStdlib?id=ujson-json编码和解码) -## About QuecPython Socket API - -For details, please refer to[ujson - JSON Code and Decode](https://python.quectel.com/wiki/#/zh-cn/api/pythonStdlib?id=ujson-json编码和解码) - -## How to run Socket - -Before carrying out this test, we should learn about QecuPython. For details, please refer to [](https://python.quectel.com/doc/doc/sbs/zh/index.html). In this chapter, it introduces the Socket function via creating a TCP user terminal to connect Server on QuecPython. - -As the module serves as the TCP user terminal to connect server, there is a need to provide connecting server. In this chapter, we may just focus on Socket on the module. As for the rest of the server, you can learn about it by yourself. Approachable resources: [ai-thinker Transparent Transmission Cloud V1.0](http://tt.ai-thinker.com:8000/ttcloud) (http://tt.ai-thinker.com:8000/ttcloud);[Ghostyu pass-through platfor](https://cloud.iotxx.com/dashboard)(https://cloud.iotxx.com/dashboard) or other cloud platforms. After connecting the cloud platform to server, then data transmission, reception, disconnection and communication display will appear, which is suitable for pre-stage communication test. - -### Interaction test of Socket - -The [ai-thinker Transparent Transmission Cloud V1.0](http://tt.ai-thinker.com:8000/ttcloud) is high-efficient with an advantage of no other protocol suffixed. Before the test, please enter command interaction status via [](https://python.quectel.com/doc/doc/sbs/zh/index.html) and carry out the further steps. - -#### Import uscocket module and create a socket - -```python -import usocket -sock = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) -``` - -#### **Open [ai-thinker Transparent Transmission Cloud V1.0](http://tt.ai-thinker.com:8000/ttcloud) to check the IP address and port number to be connected.** - -![sbs_socket_03(E)](media\sbs_socket_03(E).png) - -**Note:** Since this server plays as the shared network resource, whose IP address and port will be retrieved if the device connection is not made within 3 minutes. As the FW connection should be done in this period, otherwise, there will be error. - -#### Build connection with server. - -```python -sock.connect(('122.114.122.174', 34187)) -``` - -**Note:** 1. IP address and port of API parameter should be as same as that in server. - - 2. The API parameter used to connect should be covered by brackets since the low layer will treat the IP address and port number as a parameter when importing. - - - -![sbs_socket_04(E)](media\sbs_socket_04(E).png) - -After sending command, what we can learn is that the module is visible on website; correspondingly, data interaction can be carried out. - -#### Upload data to module - -```python ->>> ret=sock.send('1234567890\r\n') ->>> print('send %d bytes' % ret) -send 12 bytes -``` - - - -![sbs_socket_06(E)](media\sbs_socket_06(E).png) - -It is vivid that you can see the data after uploading it to module. - -#### Server issues data - - - -![sbs_socket_07(E)](media\sbs_socket_07(E).png) - -After the server issued the data, the module can read it, please refer to the following figure: - -```python ->>> data=sock.recv(1024) ->>> print('recv %s bytes:' % len(data)) -recv 10 bytes: ->>> print(data.decode()) -0123456789 -``` -#### Disconnect - -```python -sock.close() -``` - -Once disconnection command is executed, the device on Server will be off-line, which is shown as next figure: - -![sbs_socket_10(E)](media\sbs_socket_10(E).png) - -Till now, the module who serves as TCP user end is connected to the server. - -### Send JSON code to test by Socket - -In basic interaction test of Socket, we have already introduced how to connect Socket to [ai-thinker Transparent Transmission Cloud V1.0](http://tt.ai-thinker.com:8000/ttcloud) . Next, we will introduce how to transmit/receive json data on [Ghostyu pass-through platform](https://cloud.iotxx.com/dashboard) via code and analyze it. - -#### Brief introduction on [Ghostyu pass-through platform](https://cloud.iotxx.com/dashboard) - - [Ghostyu pass-through platform](https://cloud.iotxx.com/dashboard) is different from [ai-thinker Transparent Transmission Cloud V1.0](http://tt.ai-thinker.com:8000/ttcloud) sightly. The device can be available only when the platform is built. When connecting, there is a need to carry out simple verification. - -##### Newly-built device - -![sbs_json_picture_1](media/sbs_json_picture_1.png) - -After entering it, please carry out via following sequence: Ghostyu direct connection -- direct connect device -- create direct connection device. Finally, you will enter the newly-built device surface. - -![sbs_json_picture_2](media/sbs_json_picture_2.png) - -Fill in the info and submit. **Note: as for the device number,** **it is preferred to be the IMEI of module since the uniqueness should be assured.** - -![sbs_json_picture_3](media/sbs_json_picture_3.png) -You can see the newly-built device in device manager, which is shown as above figure. - -##### Build connection - -The IP address and port to connect TCP are fixed, which is different from that in [ai-thinker Transparent Transmission Cloud V1.0](http://tt.ai-thinker.com:8000/ttcloud) . The sentence used to build connection with service end should be fixed as well when creating one socket. - -![sbs_json_picture_4](media/sbs_json_picture_4.png) - -```python -sock.connect(('115.29.240.46', 9000)) -``` - -After sending connection command, the module will get in touch with platform correspondingly; however, the connection to newly-built device has not been set up yet. If it is a must, the first message shall be **registration package** and the user end should send it to server for verification. - -![sbs_json_picture_5](media/sbs_json_picture_5.png) - -The command for registration package can be checked via device surface as described above. - -Take following device as an example, we can get connection with device via such commands. - -```python -sock.send('ep=868540051769632&pw=123456') -``` - -![sbs_json_picture_6](media/sbs_json_picture_6.png) - -Once the connection is established, the data interaction can be done smoothly. - -#### Codes of JSON transmission test +### Test Code ```python # Import module @@ -293,14 +161,14 @@ PROJECT_VERSION = "1.0.1" checknet = checkNet.CheckNetwork(PROJECT_NAME, PROJECT_VERSION) -# | Parameter| Parameter type | Illustration| -# | -------- | ------- | ------------------ | -# | CRITICAL | Constant| Numerical value of log record level 50| -# | ERROR | Constant| Numerical value of log record level 40| -# | WARNING | Constant| Numerical value of log record level 30| -# | INFO | Constant| Numerical value of log record level 20| -# | DEBUG | Constant| Numerical value of log record level 10| -# | NOTSET | Constant| Numerical value of log record level 0 | +# | Parameter | parameter | description | type | +# | --------- | --------- | ------------------------- | -------- | +# | CRITICAL | constant | value of logging level 50 | critical | +# | ERROR | constant | value of logging level 40 | error | +# | WARNING | constant | value of logging level 30 | warning | +# | INFO | constant | value of logging level 20 | info | +# | DEBUG | constant | value of logging level 10 | debug | +# | NOTSET | constant | value of logging level 0 | notset | log.basicConfig(level=log.NOTSET) # Set output level of log socket_log = log.getLogger("Socket") @@ -319,10 +187,6 @@ if __name__ == '__main__': sock = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) # Create one socket sock.connect(('115.29.240.46', 9000)) # Connect to platform - sock.send('ep=868540051769632&pw=123456') # Send registration package to connect device - connect_data = sock.recv(1024) # Read the result - if connect_data.decode() == '[iotxx:ok]': - socket_log.info('Socket Connect OK\r\n') # Original Dict Data socket_log.info('---------------Original Dict Data--------------') @@ -348,23 +212,8 @@ if __name__ == '__main__': ``` -#### Test scenario - -Run code, transform the Dict data to json data; finally, send json data to server correspondingly. - -![sbs_json_picture_7](media/sbs_json_picture_7.png) - -The server receives data and displays. - -![sbs_socket_11(E)](media\sbs_socket_11(E).png) - -The server sends data to user end as well as receives disconnection command. - - - -![sbs_socket_12(E)](media\sbs_socket_12(E).png) -Print the log issued by server and close connection. -![sbs_socket_13(E)](media\sbs_socket_13(E).png) +### instructions +Customers will be: "The sock. Connect ((9000) '115.29.240.46')" After replacing the IP address and port number with the value of their own server, the code can be downloaded to the module to run. \ No newline at end of file diff --git a/docs/sbs/en/BSP/SPI.md b/docs/sbs/en/BSP/SPI.md index 35bfb64c13079ed397a3abf62639b84109eb572d..c18772eec65ae89afd0a0ee1012f05a22c27b151 100644 --- a/docs/sbs/en/BSP/SPI.md +++ b/docs/sbs/en/BSP/SPI.md @@ -8,7 +8,7 @@ In this document, it mainly introduces how to use *QuecPython_SPI* on EC600X (EC600S, EC600N and EC600U are included). In addition, you can learn about the parameter settings and application notes of *EC600x_SPI*. -About API, please refer to [QuecPython-machine - spi](https://python.quectel.com/wiki/#/zh-cn/api/QuecPythonClasslib?id=spi) +About API, please refer to [QuecPython-machine - spi](https://python.quectel.com/wiki/#/en-us/api/QuecPythonClasslib?id=spi) ## Brief introduction on SPI @@ -20,17 +20,15 @@ As its name implies, SPI, the abbreviation of Serial Peripheral interface and de In SPI, it regulates that during the during the communication of two SPI devices, the Slave device shall be controlled by the Master device. One Master device can control several Slave devices by providing Clock and carrying out Salve Select. In addition, it is regulated the Clock of Slave device should be provided by Master device via SCK pin since the Slave device can't produce or control Clock. Furthermore, without Clock, it would be a failure for Slave device to run smoothly. +![media_SPI_1](media/media_SPI_1.jpg) -![media-SPI-01(E)](media\media-SPI-01(E).png) ### Synchronous -Master 设备会根据将要交换的数据来产生相应的时钟脉冲(Clock Pulse),时钟脉冲组成了时钟信号(Clock Signal),时钟信号通过时钟极性 (CPOL) 和 时钟相位 (CPHA) 控制着两个 SPI 设备间何时数据交换以及何时对接收到的数据进行采样,来保证数据在两个设备之间是同步传输的。 - The Master device will generate corresponding Clock Pulse according to the data should be exchanged, while the clock pulse makes up the clock signal. The clock signal uses CPOL and CPHA to control when data is exchanged between the two SPI devices and when the received data is sampled to ensure synchronous data transmission between the two devices. -![media_SPI_02(E)](media\media_SPI_02(E).png) +![media_SPI_2](media/media_SPI_2.jpg) ### Four communication modes @@ -40,8 +38,6 @@ The Master device will generate corresponding Clock Pulse according to the data According to the difference between **CPOL** and **CPHA**, SPI is embedded with four communication modes. -![media_SPI_3](media/media_SPI_3.jpg) - | SPI mode | CPOL | CPHA | SCK Clock when idle | Sampling moment | | -------- | ---- | ---- | ------------------- | --------------- | | 0 | 0 | 0 | Low level | Odd edge | @@ -51,9 +47,9 @@ According to the difference between **CPOL** and **CPHA**, SPI is embedded with -![media_SPI_04(E)](media\media_SPI_04(E).png) +![media_SPI_4](media/media_SPI_3.jpg) -![media_SPI_05(E)](media\media_SPI_05(E).png) +![media_SPI_5](media/media_SPI_4.jpg) @@ -106,7 +102,7 @@ while count: ### Test Result -![media_SPI_6](media/media_SPI_6.jpg) +![media_SPI_6](media/media_SPI_5.jpg) ## Matched code diff --git a/docs/sbs/en/BSP/code/code_SPI.py b/docs/sbs/en/BSP/code/code_SPI.py index 2eaef63c7a2a226912adb82b4a8cbf3113c415ea..7e06045f729d4922c04b1d759c0e666f655fbac7 100644 --- a/docs/sbs/en/BSP/code/code_SPI.py +++ b/docs/sbs/en/BSP/code/code_SPI.py @@ -3,15 +3,15 @@ import utime from machine import SPI from machine import Pin -# 屏蔽GNSS模块数据干扰. 由于EC600S/N的SPI_MISO与SPI_MOSI引脚还被复用为UART1. 开发板还连接GNSS模块L76K, 为了断开L76K吐数据对SPI通信的干扰, 需要添加下面两句代码. -gpio11 = Pin(Pin.GPIO11, Pin.OUT, Pin.PULL_PD, 0) # EC600S/EC600N使用 -gpio11.write(0) # EC600S/EC600N使用 +# Shield the data inteference of GNSS module. As the SPI_MISO and SPI_MOSI are multiplexed as UART1, A GNSS module (L76K)is also connected to EVB. In order to disconnect the inteference to SPI communition by data from L76K, followiing two lines of codes should be added. +gpio11 = Pin(Pin.GPIO11, Pin.OUT, Pin.PULL_PD, 0) # Used in EC600S/EC600N +gpio11.write(0) # Used in EC600S/EC600N w_data = "Grey" r_data = bytearray(len(w_data)) -count = 10 # 运行次数 -spi_obj = SPI(1, 0, 1) # EC600S/EC600N使用 -# spi_obj = SPI(0, 0, 1) # EC600U/EC100Y使用 +count = 10 # Running count +spi_obj = SPI(1, 0, 1) # Running count +# spi_obj = SPI(0, 0, 1) # Running count while count: count -= 1 diff --git a/docs/sbs/en/BSP/media/media_SPI_1.jpg b/docs/sbs/en/BSP/media/media_SPI_1.jpg index f9e636fa9fc329c164c2e2f42f31795b5c61abaf..bce081debb26d7540461a980724c99564442fc70 100644 Binary files a/docs/sbs/en/BSP/media/media_SPI_1.jpg and b/docs/sbs/en/BSP/media/media_SPI_1.jpg differ diff --git a/docs/sbs/en/BSP/media/media_SPI_2.jpg b/docs/sbs/en/BSP/media/media_SPI_2.jpg index 7ac14f0715250687e91e68bf13d5b98b4efac075..0721d35820433b53f2983d99a66f7bf863e6432c 100644 Binary files a/docs/sbs/en/BSP/media/media_SPI_2.jpg and b/docs/sbs/en/BSP/media/media_SPI_2.jpg differ diff --git a/docs/sbs/en/BSP/media/media_SPI_3.jpg b/docs/sbs/en/BSP/media/media_SPI_3.jpg index cf87c486c4832c74f3d20170f7cd64faf10d774a..a47dc750e018a26efc6e11b4af911adecc564b92 100644 Binary files a/docs/sbs/en/BSP/media/media_SPI_3.jpg and b/docs/sbs/en/BSP/media/media_SPI_3.jpg differ diff --git a/docs/sbs/en/BSP/media/media_SPI_4.jpg b/docs/sbs/en/BSP/media/media_SPI_4.jpg index 66b9a7b203f332146efb947dc5c550a98c413dd5..d7b63d6397ec270cd4dec7865a0b8beecf1d9483 100644 Binary files a/docs/sbs/en/BSP/media/media_SPI_4.jpg and b/docs/sbs/en/BSP/media/media_SPI_4.jpg differ diff --git a/docs/sbs/en/BSP/media/media_SPI_5.jpg b/docs/sbs/en/BSP/media/media_SPI_5.jpg index 88c9a0922849681691935bf954f22daf1123b45e..a41d5f821b017388e145b87efddbe0a9759f3619 100644 Binary files a/docs/sbs/en/BSP/media/media_SPI_5.jpg and b/docs/sbs/en/BSP/media/media_SPI_5.jpg differ diff --git a/docs/sbs/en/BSP/media/media_SPI_6.jpg b/docs/sbs/en/BSP/media/media_SPI_6.jpg deleted file mode 100644 index a41d5f821b017388e145b87efddbe0a9759f3619..0000000000000000000000000000000000000000 Binary files a/docs/sbs/en/BSP/media/media_SPI_6.jpg and /dev/null differ