Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions libraries/AW9523B/aw9523b_demo.py
Original file line number Diff line number Diff line change
@@ -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)))
52 changes: 52 additions & 0 deletions libraries/ESP8266/esp8266_demo.py
Original file line number Diff line number Diff line change
@@ -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")
10 changes: 5 additions & 5 deletions libraries/LTR-303ALS-01/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

------
Expand All @@ -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)
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions libraries/LTR-303ALS-01/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 基本功能使用
Expand All @@ -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)
Expand All @@ -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总线对象
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from machine import ExtInt


class itl_303als():
class ltr_303als():
i2c_log = None
i2c_dev = None
i2c_addre = 0x29
Expand Down Expand Up @@ -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())
Expand Down
45 changes: 45 additions & 0 deletions libraries/LTR-303ALS-01/ltr_303als_demo.py
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
46 changes: 46 additions & 0 deletions libraries/PL51NF001/PL51NF001_demo.py
Original file line number Diff line number Diff line change
@@ -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")
File renamed without changes.
59 changes: 59 additions & 0 deletions libraries/QMA7981/qma7981_demo.py
Original file line number Diff line number Diff line change
@@ -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))
Loading