diff --git a/libraries/AW9523B/aw9523b_demo.py b/libraries/AW9523B/aw9523b_demo.py new file mode 100644 index 0000000..a3ea235 --- /dev/null +++ b/libraries/AW9523B/aw9523b_demo.py @@ -0,0 +1,61 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: AW9523B GPIO expansion chip demo + +Copyright 2024 - 2024 quectel +''' +from machine import I2C +import utime +from usr.aw9523 import AW9523 + + +if __name__ == "__main__": + i2c_dev = I2C(I2C.I2C1, I2C.STANDARD_MODE) + + # Interrupt callback + def int_callback(pin_data): + pin, level = pin_data + print("Pin {} level changed! Current: {}".format(pin, "High" if level else "Low")) + + # Initialize AW9523B, address 0x58, interrupt pin 1 + expander = AW9523(i2c_dev, int_pin=1, int_callback=int_callback) + + # Configure pin 0-3 as output, set low + for i in range(4): + expander.pin(i, mode=0, value=0) + + # Configure pin 8-11 as input, enable interrupt + for i in range(8, 12): + expander.pin(i, mode=1, interrupt_enable=1) + + # LED blink on pin 0 + for _ in range(5): + expander.pin(0, value=1) + print("Pin 0: High") + utime.sleep_ms(500) + expander.pin(0, value=0) + print("Pin 0: Low") + utime.sleep_ms(500) + + # Read input pins + for i in range(8, 12): + level = expander.read(i) + print("Pin {} level: {}".format(i, "High" if level else "Low")) + + # Read all pin states + print("All pins: {}".format(bin(expander.gpio))) diff --git a/libraries/ESP8266/esp8266_demo.py b/libraries/ESP8266/esp8266_demo.py new file mode 100644 index 0000000..0d4db9e --- /dev/null +++ b/libraries/ESP8266/esp8266_demo.py @@ -0,0 +1,52 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: ESP8266 WiFi module demo + +Copyright 2024 - 2024 quectel +''' +from machine import UART +import utime +from usr.esp8266 import Esp8266_ap + + +if __name__ == "__main__": + # Initialize ESP8266 via UART2 with SLIP protocol + esp = Esp8266_ap(UART.UART2) + print("ESP8266 init success") + + # Configure WiFi AP: set SSID and password + ret = esp.set_ap(name='MyWiFiAP', pwd='12345678') + if ret == 0: + print("AP configured successfully") + else: + print("AP configuration failed") + + # Enable WiFi and setup routing + ret = esp.wifi_on() + if ret == 0: + print("WiFi network is up") + else: + print("WiFi network startup failed") + + # Keep running + try: + while True: + utime.sleep(10) + except KeyboardInterrupt: + esp.wifi_off() + print("WiFi module stopped") diff --git a/libraries/LTR-303ALS-01/README.md b/libraries/LTR-303ALS-01/README.md index 8689e2c..3cc6945 100644 --- a/libraries/LTR-303ALS-01/README.md +++ b/libraries/LTR-303ALS-01/README.md @@ -24,13 +24,13 @@ Before using the LTR303ALS module, ensure proper hardware connections: ```python from machine import I2C, ExtInt -import itl_303als +import ltr_303als # Initialize I²C interface (standard mode on I2C1) i2c = I2C(I2C.I2C1, I2C.STANDARD_MODE) # Initialize sensor (address 0x29, interrupt on GPIO32, falling edge trigger, threshold 100 lux) -als = itl_303als(i2c, 0x29, ExtInt.GPIO32, 100, itl_303als.IRQ_FALLING) +als = ltr_303als(i2c, 0x29, ExtInt.GPIO32, 100, ltr_303als.IRQ_FALLING) ``` ------ @@ -54,7 +54,7 @@ als.set_threshold(200) ```python # Configure interrupt trigger mode (rising/falling edge) -als.config_interrupt(itl_303als.IRQ_RISING) +als.config_interrupt(ltr_303als.IRQ_RISING) # Set interrupt persistence condition (trigger after 10 consecutive detections) als.set_persist(0x0A) @@ -77,12 +77,12 @@ print(f"Calibrated Threshold: {calibrated}") ## Class and Method Reference -### `itl_303als` Class +### `ltr_303als` Class #### Constructor ```python -itl_303als(i2c_bus, i2c_addr=0x29, int_pin=None, threshold=100, int_mode=IRQ_FALLING) +ltr_303als(i2c_bus, i2c_addr=0x29, int_pin=None, threshold=100, int_mode=IRQ_FALLING) ``` - `i2c_bus`: I²C bus object. diff --git a/libraries/LTR-303ALS-01/README_zh.md b/libraries/LTR-303ALS-01/README_zh.md index b1d4e1c..a064d92 100644 --- a/libraries/LTR-303ALS-01/README_zh.md +++ b/libraries/LTR-303ALS-01/README_zh.md @@ -20,13 +20,13 @@ ```python from machine import I2C, ExtInt -import itl_303als +import ltr_303als # 初始化I2C接口(使用I2C1标准模式) i2c = I2C(I2C.I2C1, I2C.STANDARD_MODE) # 初始化传感器(地址0x29,中断引脚GPIO32,下降沿触发,阈值100lux) -als = itl_303als(i2c, 0x29, ExtInt.GPIO32, 100, itl_303als.IRQ_FALLING) +als = ltr_303als(i2c, 0x29, ExtInt.GPIO32, 100, ltr_303als.IRQ_FALLING) ``` ### 2. 基本功能使用 @@ -46,7 +46,7 @@ als.set_threshold(200) ```python # 配置中断触发模式(上升沿/下降沿) -als.config_interrupt(itl_303als.IRQ_RISING) +als.config_interrupt(ltr_303als.IRQ_RISING) # 设置中断持续条件(连续10次检测有效) als.set_persist(0x0A) @@ -65,12 +65,12 @@ print(f"Calibrated threshold: {calibrated}") ## 类和方法参考 -### `itl_303als` 类 +### `ltr_303als` 类 #### 构造函数 ```python -itl_303als(i2c_bus, i2c_addr=0x29, int_pin=None, threshold=100, int_mode=IRQ_FALLING) +ltr_303als(i2c_bus, i2c_addr=0x29, int_pin=None, threshold=100, int_mode=IRQ_FALLING) ``` - `i2c_bus`: I2C总线对象 diff --git a/libraries/LTR-303ALS-01/Itr_303als.py b/libraries/LTR-303ALS-01/ltr_303als.py similarity index 97% rename from libraries/LTR-303ALS-01/Itr_303als.py rename to libraries/LTR-303ALS-01/ltr_303als.py index 4c70263..b812a82 100644 --- a/libraries/LTR-303ALS-01/Itr_303als.py +++ b/libraries/LTR-303ALS-01/ltr_303als.py @@ -29,7 +29,7 @@ from machine import ExtInt -class itl_303als(): +class ltr_303als(): i2c_log = None i2c_dev = None i2c_addre = 0x29 @@ -137,7 +137,7 @@ def user_cb_test(light): if __name__ == "__main__": # GPIO32 GPIO8 - als_dev = itl_303als(ExtInt.GPIO32, 100, user_cb_test, intr_output_mode=itl_303als.IRQ_FALLING) + als_dev = ltr_303als(ExtInt.GPIO32, 100, user_cb_test, intr_output_mode=ltr_303als.IRQ_FALLING) for i in range(20): print("test 1 ",i) print("read data:", als_dev.read()) diff --git a/libraries/LTR-303ALS-01/ltr_303als_demo.py b/libraries/LTR-303ALS-01/ltr_303als_demo.py new file mode 100644 index 0000000..a0c2948 --- /dev/null +++ b/libraries/LTR-303ALS-01/ltr_303als_demo.py @@ -0,0 +1,45 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: LTR-303ALS-01 ambient light sensor demo + +Copyright 2024 - 2024 quectel +''' +from machine import ExtInt +import utime +from usr.ltr_303als import ltr_303als + + +if __name__ == "__main__": + # Light interrupt threshold callback + def light_callback(light): + ch1, ch0 = light + print("Light interrupt triggered! CH1: {}, CH0: {}".format(ch1, ch0)) + + # Initialize LTR-303ALS-01 with interrupt on GPIO32, threshold 100, falling edge + als = ltr_303als(ExtInt.GPIO32, 100, light_callback, + intr_output_mode=ltr_303als.IRQ_FALLING) + print("LTR-303ALS-01 init success") + + # Read ambient light data 10 times + for i in range(10): + data = als.read() + if data: + print("Reading {}: CH1: {}, CH0: {}".format(i + 1, data[0], data[1])) + else: + print("Reading {}: data not ready".format(i + 1)) + utime.sleep(1) diff --git a/libraries/MCP23017/mcp_test.py b/libraries/MCP23017/mcp23017_demo.py similarity index 100% rename from libraries/MCP23017/mcp_test.py rename to libraries/MCP23017/mcp23017_demo.py diff --git a/libraries/PL51NF001/PL51NF001_demo.py b/libraries/PL51NF001/PL51NF001_demo.py new file mode 100644 index 0000000..b3a45b2 --- /dev/null +++ b/libraries/PL51NF001/PL51NF001_demo.py @@ -0,0 +1,46 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: PL51NF001 NFC temperature tag demo + +Copyright 2024 - 2024 quectel +''' +from usr.PL51NF001 import PL5NF001 + + +if __name__ == "__main__": + # Initialize PL51NF001 with GPIO bit-banging (CLK=GPIO9, DIO=GPIO8) + nfc = PL5NF001() + print("PL51NF001 init success") + + # Send command and read temperature data + nfc.start_signal() + nfc.write_data(0x00) + nfc.wait_ack() + nfc.write_data(0x01) + nfc.wait_ack() + + # Read 81 data bytes with ACK, then final byte with NACK + for i in range(81): + data = nfc.read_byte(1) + print("Byte {}: {}".format(i, data)) + + last = nfc.read_byte(0) + print("Final byte: {}".format(last)) + + nfc.stop_signal() + print("Read complete") diff --git a/libraries/PL51NF001/READMD_zh.md b/libraries/PL51NF001/README_zh.md similarity index 100% rename from libraries/PL51NF001/READMD_zh.md rename to libraries/PL51NF001/README_zh.md diff --git a/libraries/QMA7981/qma7981_demo.py b/libraries/QMA7981/qma7981_demo.py new file mode 100644 index 0000000..8f04f50 --- /dev/null +++ b/libraries/QMA7981/qma7981_demo.py @@ -0,0 +1,59 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: QMA7981 accelerometer demo + +Copyright 2024 - 2024 quectel +''' +from machine import ExtInt +import utime +from usr.qma7981 import qma7981 + + +if __name__ == "__main__": + # Interrupt callback + def motion_callback(event, data): + event_map = { + qma7981.SIG_MOT_INT: "Significant motion", + qma7981.ANY_MOT_INT_X: "Any motion X", + qma7981.ANY_MOT_INT_Y: "Any motion Y", + qma7981.ANY_MOT_INT_Z: "Any motion Z", + qma7981.NO_MOT_INT: "No motion", + qma7981.HAND_RAISE_INT: "Hand raise", + qma7981.HAND_DOWN_INT: "Hand down", + qma7981.STEP_INT: "Step", + } + print("Event: {}, Data: {}".format(event_map.get(event, "Unknown"), data)) + + # Initialize QMA7981 with INT1 on GPIO33, falling edge trigger + sensor = qma7981(motion_callback, INT1=ExtInt.GPIO33, + INT1_output_mode=qma7981.IRQ_FALLING) + print("QMA7981 init success") + + # Enable any motion interrupt with threshold 200 + sensor.set_any_motion_intr(True, threshod=200, sample_times=1) + + # Read acceleration data 10 times + for i in range(10): + acc = sensor.readacc() + print("Reading {}: X={:.2f} Y={:.2f} Z={:.2f} mg".format( + i + 1, acc[0], acc[1], acc[2])) + utime.sleep(1) + + # Read step count + steps = sensor.readstep() + print("Step count: {}".format(steps)) diff --git a/libraries/RC522/mfrc522_demo.py b/libraries/RC522/mfrc522_demo.py new file mode 100644 index 0000000..81e6220 --- /dev/null +++ b/libraries/RC522/mfrc522_demo.py @@ -0,0 +1,50 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: RC522 RFID module demo + +Copyright 2024 - 2024 quectel +''' +from machine import Pin +import utime +from usr.mfrc522 import Mfrc522_spi + + +if __name__ == "__main__": + # Initialize RC522 via SPI, RST on GPIO12, IRQ on GPIO11 + reader = Mfrc522_spi(pin_rst=Pin.GPIO12, pin_irq=Pin.GPIO11) + print("RC522 init success") + + # Read card ID + card_id = reader.read_id() + print("Card ID: {}".format(card_id)) + + # Read data from block 0x01 + data = reader.Mfrc522_Read(0x01) + if data: + print("Block 0x01 data: {}".format(data)) + + # Write data to block 0x01 + write_data = [0x00, 0x0A, 0x10, 0x00, 0x0C, 0x00, 0xA0, 0x05, + 0x00, 0x40, 0x40, 0x00, 0x10, 0x20, 0x00, 0x00] + reader.Mfrc522_Write(0x01, write_data) + print("Data written to block 0x01") + + # Read back and verify + read_back = reader.Mfrc522_Read(0x01) + if read_back: + print("Verify read: {}".format(read_back)) diff --git a/libraries/RDA5807/rda5807_demo.py b/libraries/RDA5807/rda5807_demo.py new file mode 100644 index 0000000..05bf93d --- /dev/null +++ b/libraries/RDA5807/rda5807_demo.py @@ -0,0 +1,64 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: RDA5807 FM radio demo + +Copyright 2024 - 2024 quectel +''' +from machine import Pin +import utime +from usr.rda5807 import RDA5807 + + +if __name__ == "__main__": + # Initialize RDA5807 with GPIO bit-banging I2C (CLK=GPIO2, DIO=GPIO3) + radio = RDA5807(rdaclk=Pin.GPIO2, rdadio=Pin.GPIO3) + print("RDA5807 init success") + + # Set volume to 10 (0-15) + radio.vol_set(10) + print("Volume set to 10") + + # Set frequency to 101.1 MHz (unit: 10KHz) + radio.freq_set(10110) + print("Frequency set to 101.1 MHz") + utime.sleep(2) + + # Get signal strength + rssi = radio.rssi_get() + print("Signal strength (RSSI): {}".format(rssi)) + + # Auto seek next channel + freq = radio.seek_channel() + print("Found channel: {} (10KHz)".format(freq)) + + # Enable bass boost + radio.bass_set(1) + print("Bass boost enabled") + + # Mute + radio.mute_set(1) + print("Muted") + utime.sleep(1) + + # Unmute + radio.mute_set(0) + print("Unmuted") + + # Disable FM + radio.fm_enable(0) + print("FM radio disabled") diff --git a/libraries/TM1650/tm1650_demo.py b/libraries/TM1650/tm1650_demo.py new file mode 100644 index 0000000..aff902c --- /dev/null +++ b/libraries/TM1650/tm1650_demo.py @@ -0,0 +1,61 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: TM1650 7-segment display demo + +Copyright 2024 - 2024 quectel +''' +from machine import Pin +import utime +from usr.tm1650 import Tm1650 + + +if __name__ == "__main__": + # Initialize TM1650 with GPIO bit-banging (DIO=GPIO13, CLK=GPIO12) + tube = Tm1650(Pin.GPIO13, Pin.GPIO12) + print("TM1650 init success") + + # Turn on display + tube.on() + + # Show all segments + tube.all_show() + utime.sleep(1) + + # Clear all + tube.all_clear() + utime.sleep(1) + + # Show number + tube.show_num(1234) + utime.sleep(1) + + # Show negative number + tube.show_num(-537) + utime.sleep(1) + + # Show string + tube.show_str("HEL0") + utime.sleep(1) + + # Show decimal point at position 2 + tube.show_dp(2) + utime.sleep(1) + + # Turn off display + tube.off() + print("Demo complete") diff --git a/libraries/battery/README.md b/libraries/battery/README.md index 7a2ed6f..f226083 100644 --- a/libraries/battery/README.md +++ b/libraries/battery/README.md @@ -1,6 +1,6 @@ # Battery Module User Guide -[[中文](./README-zh.md)] +[[中文](./README_zh.md)] ## Introduction diff --git a/libraries/battery/README_zh.md b/libraries/battery/README_zh.md new file mode 100644 index 0000000..4dd3613 --- /dev/null +++ b/libraries/battery/README_zh.md @@ -0,0 +1,166 @@ +# 电池功能模块 用户指导手册 + +[[English](./README.md)] + +## 简介 + +> 该模块用于查询当前设备的电池电量与电压, 设备的充电状态。 + +## API说明 + +### 实例化对象 + +**示例:** + +```python +from battery import Battery + +adc_args = (adc_num, adc_period, factor) +chrg_gpion = 0 +stdby_gpion = 1 + +battery = Battery(adc_args=adc_args, chrg_gpion=chrg_gpion, stdby_gpion=stdby_gpion) +``` + +**参数:** + +|参数|类型|说明| +|:---|---|---| +|adc_args|tuple|元素1: [ADC通道](https://python.quectel.com/doc/API_reference/zh/peripherals/misc.ADC.html#%E5%B8%B8%E9%87%8F), 元素2: ADC循环读取次数, 元素3: 计算系数, 可选| +|chrg_gpion|int|CHRG (引脚 1):漏极开路输出的充电状态指示端。可选| +|stdby_gpion|int|STDBY (引脚 5):电池充电完成指示端。可选| + +### set_charge_callback + +> 充电事件回调函数 + +**示例:** + +```python +def charge_callback(charge_status): + print(charge_status) + +res = battery.set_charge_callback(charge_callback) +``` + +**参数:** + +|参数|类型|说明| +|:---|---|---| +|charge_callback|function|充电事件回调函数, 回调函数参数为设备充电状态: 0-未充电;1-充电中;2-充电完成| + +**返回值:** + +|数据类型|说明| +|:---|---| +|bool|`True`成功, `False`失败| + +### set_temp + +> 设置当前设备所处工作环境温度, 用于计算设备电池电量 + +**示例:** + +```python +res = battery.set_temp(20) +``` + +**参数:** + +|参数|类型|说明| +|:---|---|---| +|temp|int/float|温度值, 单位:摄氏度 | + +**返回值:** + +|数据类型|说明| +|:---|---| +|bool|`True`成功, `False`失败| + +### voltage + +> 查询电池电压 + +**示例:** + +```python +battery.voltage +# 523 +``` + +**返回值:** + +|数据类型|说明| +|:---|---| +|int|电池电压, 单位mV。| + +### energy + +> 查询电池电量 + +**示例:** + +```python +res = battery.energy +# 100 +``` + +**返回值:** + +|数据类型|说明| +|:---|---| +|int|电池电量百分比, 0~100。| + +### charge_status + +> 查询充电状态 + +**示例:** + +```python +battery.charge_status +# 1 +``` + +**返回值:** + +|数据类型|说明| +|:---|---| +|int|0-未充电
1-充电中
2-充电完成| + +## 使用示例 + +```python +from battery import Battery + +# 实例化对象 +adc_args = (adc_num, adc_period, factor) +chrg_gpion = 0 +stdby_gpion = 1 +battery = Battery(adc_args=adc_args, chrg_gpion=chrg_gpion, stdby_gpion=stdby_gpion) + +def charge_callback(charge_status): + print(charge_status) + +# 设置充电状态回调函数 +battery.set_charge_callback(charge_callback) +# True + +# 设置当前设备温度 +temp = 30 +battery.set_temp(temp) +# True + +# 获取当前电池电压 +battery.voltage() +# 3000 + +# 获取当前电池电量 +battery.energy() +# 100 + +# 获取当前充电状态 +battery.charge_status() +# 1 + +``` \ No newline at end of file diff --git a/libraries/battery/battery_demo.py b/libraries/battery/battery_demo.py new file mode 100644 index 0000000..65bf181 --- /dev/null +++ b/libraries/battery/battery_demo.py @@ -0,0 +1,46 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: Battery management demo + +Copyright 2024 - 2024 quectel +''' +from machine import I2C +import utime +from usr.battery import Battery + + +if __name__ == "__main__": + # Initialize battery (use Power.getVbatt, no ADC args) + # If using ADC: adc_args = (ADC.ADC0, 10, 0.0) + battery = Battery() + + # Set environment temperature + battery.set_temp(25) + + # Charge status callback + def charge_callback(status): + status_map = {0: "Not charging", 1: "Charging", 2: "Charge complete"} + print("Charge status: {}".format(status_map.get(status, "Unknown"))) + + # Read battery info 5 times + for i in range(5): + print("=== Reading {} ===".format(i + 1)) + print("Voltage: {}mV".format(battery.voltage)) + print("Energy: {}%".format(battery.energy)) + print("Charge status: {}".format(battery.charge_status)) + utime.sleep(2) diff --git a/libraries/bmp280/bmp280_demo.py b/libraries/bmp280/bmp280_demo.py new file mode 100644 index 0000000..5d5181d --- /dev/null +++ b/libraries/bmp280/bmp280_demo.py @@ -0,0 +1,40 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: BMP280 barometric pressure sensor demo + +Copyright 2024 - 2024 quectel +''' +from machine import I2C +import utime +from usr.bmp280 import BMP280 + + +if __name__ == "__main__": + i2c_dev = I2C(I2C.I2C0, I2C.STANDARD_MODE) + + # Initialize BMP280, default address 0x76 + sensor = BMP280(i2c_dev, 0x76) + sensor.init() + + # Read temperature and pressure 5 times + for i in range(5): + temp, press = sensor.read_data() + print("=== Reading {} ===".format(i + 1)) + print("Temperature: {:.2f} C".format(temp)) + print("Pressure: {:.2f} hPa".format(press)) + utime.sleep(2) diff --git a/libraries/bmp280/bst-bmp280-ds001.pdf b/libraries/bmp280/bst-bmp280-ds001.pdf new file mode 100644 index 0000000..a784d91 Binary files /dev/null and b/libraries/bmp280/bst-bmp280-ds001.pdf differ diff --git a/libraries/ch423s/READMEzh.md b/libraries/ch423s/README_zh.md similarity index 100% rename from libraries/ch423s/READMEzh.md rename to libraries/ch423s/README_zh.md diff --git a/libraries/ch423s/ch423s_demo.py b/libraries/ch423s/ch423s_demo.py new file mode 100644 index 0000000..9353cfa --- /dev/null +++ b/libraries/ch423s/ch423s_demo.py @@ -0,0 +1,57 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: CH423S I/O expander demo + +Copyright 2024 - 2024 quectel +''' +from machine import Pin +import utime +from usr.ch423s import Ch423s + + +if __name__ == "__main__": + # Initialize CH423S with GPIO bit-banging I2C (SCL=GPIO12, SDA=GPIO13) + expander = Ch423s(Pin.GPIO12, Pin.GPIO13) + print("CH423S init success") + + # Configure GPIO0-7 as output mode + expander.config(dir=1) + print("GPIO set to output mode") + + # Blink pin 5 five times + for i in range(5): + expander.gpio_pin(pin=5, value=1) + print("Pin 5: High, GPIO state: {}".format(bin(expander.read_gpio()))) + utime.sleep_ms(500) + expander.gpio_pin(pin=5, value=0) + print("Pin 5: Low, GPIO state: {}".format(bin(expander.read_gpio()))) + utime.sleep_ms(500) + + # Set all GPIO high then low + expander.gpio(0xFF) + print("All high: {}".format(bin(expander.read_gpio()))) + utime.sleep_ms(500) + expander.gpio(0x00) + print("All low: {}".format(bin(expander.read_gpio()))) + + # Open-drain output demo + expander.reset() + expander.config(odr=1) + expander.gpo_h(0x0F) + expander.gpo_l(0xF0) + print("Open-drain mode: high=0x0F, low=0xF0") diff --git a/libraries/keyscan/keyscan_demo.py b/libraries/keyscan/keyscan_demo.py new file mode 100644 index 0000000..fcb10a4 --- /dev/null +++ b/libraries/keyscan/keyscan_demo.py @@ -0,0 +1,47 @@ +# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +''' +@Author: QuecPython +@Date: 2024 +@Description: Key scan demo + +Copyright 2024 - 2024 quectel +''' +from machine import Pin +from usr.keyscan import Key + + +if __name__ == "__main__": + k1_pin = Pin.GPIO4 + k2_pin = Pin.GPIO30 + + def event_cb(k, event): + name = "k1" if k.pin == k1_pin else "k2" + if event == Key.Event.PRESSED: + print("{} pressed".format(name)) + elif event == Key.Event.RELEASED: + print("{} released after {} seconds".format(name, k.sec)) + elif event == Key.Event.LONG_PRESSED: + print("{} long pressed for {} seconds".format(name, k.sec)) + + # Key1: press/release detection, continuous mode, active low + Key(k1_pin, Key.WorkMode.CONTINUOUS, 20, 0, + Key.Event.PRESSED | Key.Event.RELEASED, event_cb) + + # Key2: press/release/long press at 2s, 4s, 6s + Key(k2_pin, Key.WorkMode.CONTINUOUS, 20, 0, + Key.Event.PRESSED | Key.Event.RELEASED, event_cb, [2, 4, 6]) + + print("Key scan started, waiting for input...")