LoRa1262 电容
Cap LoRa1262 是一款专为 Cardputer-Adv 设计的高性能 LoRa 通信和 GNSS 全球导航扩展模块。
支持以下产品:
UIFLOW2 应用示例
发送端
在 UiFlow2 中打开 cardputer_adv_lora1262_cap_sender_example.m5f2 项目。
使用键盘输入要发送的文本,然后按 ENTER 键发送。
UiFlow2 代码块:
示例输出:
None
接收端
在 UiFlow2 中打开 cardputer_adv_lora1262_cap_receiver_example.m5f2 项目。
此示例接收并显示数据。
UiFlow2 代码块:
示例输出:
None
GPS 使用
在 UiFlow2 中打开 cardputer_adv_lora1262_cap_gps_example.m5f2 项目。
此示例演示如何使用 LoRa1262 Cap 的 GPS 功能。
UiFlow2 代码块:
示例输出:
None
MicroPython 应用示例
发送端
使用键盘输入要发送的文本,然后按 ENTER 键发送。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import MatrixKeyboard 9from cap import LoRa1262Cap 10from unit import KeyCode 11 12 13kb = None 14cap_lora1262 = None 15 16 17keycode = None 18key = None 19buf = None 20 21 22def kb_pressed_event(kb_0): 23 global kb, cap_lora1262, keycode, key, buf 24 keycode = kb.get_key() 25 if keycode >= 0x20 and keycode <= 0x7E: 26 key = chr(keycode) 27 buf = str(buf) + str(key) 28 M5.Lcd.printf(key) 29 elif keycode >= (KeyCode.KEYCODE_ENTER): 30 cap_lora1262.send(buf, None) 31 buf = "" 32 M5.Lcd.fillScreen(0x000000) 33 M5.Lcd.setCursor(0, 0) 34 M5.Lcd.printf("\n") 35 M5.Lcd.printf(">>>") 36 37 38def setup(): 39 global kb, cap_lora1262, keycode, key, buf 40 41 M5.begin() 42 Widgets.fillScreen(0x000000) 43 44 cap_lora1262 = LoRa1262Cap( 45 freq_khz=868000, 46 bw="250", 47 sf=8, 48 coding_rate=8, 49 preamble_len=12, 50 syncword=0x12, 51 output_power=10, 52 ) 53 kb = MatrixKeyboard() 54 kb.set_callback(kb_pressed_event) 55 M5.Lcd.setFont(Widgets.FONTS.DejaVu12) 56 M5.Lcd.setTextColor(0xFFFFFF, 0x000000) 57 M5.Lcd.setCursor(0, 0) 58 M5.Lcd.setTextScroll(True) 59 M5.Lcd.printf(">>>") 60 buf = "" 61 62 63def loop(): 64 global kb, cap_lora1262, keycode, key, buf 65 M5.update() 66 67 68if __name__ == "__main__": 69 try: 70 setup() 71 while True: 72 loop() 73 except (Exception, KeyboardInterrupt) as e: 74 try: 75 from utility import print_error_msg 76 77 print_error_msg(e) 78 except ImportError: 79 print("please update to latest firmware")
示例输出:
None
接收端
此示例接收并显示数据。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8import time 9from cap import LoRa1262Cap 10 11 12cap_lora1262 = None 13 14 15lora_data = None 16cur_time = None 17time_buf = None 18rx_text = None 19 20 21def cap_lora1262_receive_event(received_data): 22 global cap_lora1262, lora_data, cur_time, time_buf, rx_text 23 lora_data = received_data 24 cur_time = time.gmtime() 25 time_buf = "" 26 time_buf = str(time_buf) + str("[") 27 time_buf = str(time_buf) + str((cur_time[3])) 28 time_buf = str(time_buf) + str(":") 29 time_buf = str(time_buf) + str((cur_time[4])) 30 time_buf = str(time_buf) + str(":") 31 time_buf = str(time_buf) + str((cur_time[5])) 32 time_buf = str(time_buf) + str("] -> ") 33 M5.Lcd.print(time_buf, 0x33FF33) 34 rx_text = lora_data.decode() 35 M5.Lcd.print(rx_text, 0xFFFFFF) 36 M5.Lcd.printf("\n") 37 38 39def setup(): 40 global cap_lora1262, lora_data, cur_time, time_buf, rx_text 41 42 M5.begin() 43 Widgets.fillScreen(0x000000) 44 45 cap_lora1262 = LoRa1262Cap( 46 freq_khz=868000, 47 bw="250", 48 sf=8, 49 coding_rate=8, 50 preamble_len=12, 51 syncword=0x12, 52 output_power=10, 53 ) 54 cap_lora1262.set_irq_callback(cap_lora1262_receive_event) 55 M5.Lcd.setFont(Widgets.FONTS.DejaVu12) 56 M5.Lcd.setTextColor(0xFFFFFF, 0x000000) 57 M5.Lcd.setCursor(0, 0) 58 M5.Lcd.setTextScroll(True) 59 cap_lora1262.start_recv() 60 61 62def loop(): 63 global cap_lora1262, lora_data, cur_time, time_buf, rx_text 64 M5.update() 65 66 67if __name__ == "__main__": 68 try: 69 setup() 70 while True: 71 loop() 72 except (Exception, KeyboardInterrupt) as e: 73 try: 74 from utility import print_error_msg 75 76 print_error_msg(e) 77 except ImportError: 78 print("please update to latest firmware")
示例输出:
None
GPS 使用
此示例演示如何使用 LoRa1262 Cap 的 GPS 功能。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from cap import GPSCap 9 10 11label0 = None 12label1 = None 13label2 = None 14cap_lora1262 = None 15 16 17def setup(): 18 global label0, label1, label2, cap_lora1262 19 20 M5.begin() 21 Widgets.fillScreen(0x000000) 22 label0 = Widgets.Label("label0", 11, 16, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 23 label1 = Widgets.Label("label1", 11, 46, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 24 label2 = Widgets.Label("label2", 10, 77, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 25 26 cap_lora1262 = GPSCap(id=2) 27 28 29def loop(): 30 global label0, label1, label2, cap_lora1262 31 M5.update() 32 label0.setText(str(cap_lora1262.get_latitude())) 33 label1.setText(str(cap_lora1262.get_longitude())) 34 label2.setText(str(cap_lora1262.get_gps_time())) 35 36 37if __name__ == "__main__": 38 try: 39 setup() 40 while True: 41 loop() 42 except (Exception, KeyboardInterrupt) as e: 43 try: 44 from utility import print_error_msg 45 46 print_error_msg(e) 47 except ImportError: 48 print("please update to latest firmware")
示例输出:
None
API参考
class LoRa1262Cap
- cap.lora1262.LoRa1262Cap
LoRa868Cap的别名
class GPSCap
有关 GPS 功能,请参阅 GPSCap 类。



