LoRa-1262 Module
LoRa1262Module provides LoRa communication through the Module13.2
LoRa-1262 radio. The radio uses the module M-Bus SPI bus and an M5IOE1
controller on I2C for reset, antenna-switch, and power control.
Support the following product:
The constructor accepts an initialized machine.I2C bus. When i2c is
omitted, the module uses module.mbus.i2c1. The M5IOE1 address must be in
the range 0x71 through 0x74.
Note
Attach a suitable antenna before transmitting. The supported RF frequency range is 850000–930000 kHz.
UiFlow2 Example
Sender
Open the cores3_lora1262_tx_example.m5f2 project in UiFlow2. The example sends a message once per second and displays the message and send timestamp.
UiFlow2 Code Block:
Receiver
Open the cores3_lora1262_rx_example.m5f2 project in UiFlow2. The example starts continuous reception and displays the decoded payload, RSSI, SNR, and receive timestamp.
UiFlow2 Code Block:
MicroPython Example
Sender
This example initializes LoRa1262Module with the default M-Bus I2C bus,
sends a message once per second, and displays the send timestamp.
1import os, sys, io
2import M5
3from M5 import *
4from module import LoRa1262Module
5import time
6
7
8title0 = None
9label_t = None
10label_tx = None
11label_ts = None
12label_time = None
13lora1262_0 = None
14
15
16count = None
17message = None
18
19
20def setup():
21 global title0, label_t, label_tx, label_ts, label_time, lora1262_0, count, message
22
23 M5.begin()
24 Widgets.setRotation(1)
25 Widgets.fillScreen(0x222222)
26 title0 = Widgets.Title("LoRa1262 Module Tx", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.Montserrat18)
27 label_t = Widgets.Label("Send:", 5, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
28 label_tx = Widgets.Label("hello", 65, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
29 label_ts = Widgets.Label(
30 "timestamp:", 5, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18
31 )
32 label_time = Widgets.Label("1", 118, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
33
34 count = 0
35 lora1262_0 = LoRa1262Module(pin_cs=0, pin_busy=2, pin_irq=14, address=0x74)
36
37
38def loop():
39 global title0, label_t, label_tx, label_ts, label_time, lora1262_0, count, message
40 M5.update()
41 message = str("Module LoRa1262 ") + str(count)
42 lora1262_0.send(message, None)
43 label_tx.setText(str(message))
44 label_time.setText(str(time.ticks_ms()))
45 count = count + 1
46 time.sleep(1)
47
48
49if __name__ == "__main__":
50 try:
51 setup()
52 while True:
53 loop()
54 except (Exception, KeyboardInterrupt) as e:
55 try:
56 from utility import print_error_msg
57
58 print_error_msg(e)
59 except ImportError:
60 print("please update to latest firmware")
Receiver
This example registers a receive callback, starts continuous reception, and displays the decoded payload, RSSI, and SNR.
1import os, sys, io
2import M5
3from M5 import *
4from module import LoRa1262Module
5import time
6
7
8title0 = None
9label_r = None
10label_rx = None
11label_rssi = None
12label_rssi_v = None
13label_snr = None
14label_snr_v = None
15label_t = None
16label_time = None
17lora1262_0 = None
18
19
20lora1262_data = None
21rssi = None
22snr = None
23
24
25def lora1262_0_receive_event(received_data):
26 global \
27 title0, \
28 label_r, \
29 label_rx, \
30 label_rssi, \
31 label_rssi_v, \
32 label_snr, \
33 label_snr_v, \
34 label_t, \
35 label_time, \
36 lora1262_0, \
37 lora1262_data, \
38 rssi, \
39 snr
40 lora1262_data = received_data
41 label_rx.setText(str(lora1262_data.decode()))
42 rssi = lora1262_data.rssi
43 snr = (lora1262_data.snr) / 4
44 label_rssi_v.setText(str(rssi))
45 label_snr_v.setText(str(snr))
46 label_time.setText(str(time.ticks_ms()))
47
48
49def setup():
50 global \
51 title0, \
52 label_r, \
53 label_rx, \
54 label_rssi, \
55 label_rssi_v, \
56 label_snr, \
57 label_snr_v, \
58 label_t, \
59 label_time, \
60 lora1262_0, \
61 lora1262_data, \
62 rssi, \
63 snr
64
65 M5.begin()
66 Widgets.setRotation(1)
67 Widgets.fillScreen(0x222222)
68 title0 = Widgets.Title("LoRa1262 Module Rx", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.Montserrat18)
69 label_r = Widgets.Label("Recv:", 5, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
70 label_rx = Widgets.Label(" ", 65, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
71 label_rssi = Widgets.Label("RSSI:", 5, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
72 label_rssi_v = Widgets.Label(" ", 65, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
73 label_snr = Widgets.Label("SNR:", 5, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
74 label_snr_v = Widgets.Label(" ", 65, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
75 label_t = Widgets.Label(
76 "timestamp:", 5, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18
77 )
78 label_time = Widgets.Label("1", 118, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18)
79
80 lora1262_0 = LoRa1262Module(pin_cs=0, pin_busy=2, pin_irq=14, address=0x74)
81 lora1262_0.set_rx_callback(lora1262_0_receive_event)
82 lora1262_0.start_recv()
83
84
85def loop():
86 global \
87 title0, \
88 label_r, \
89 label_rx, \
90 label_rssi, \
91 label_rssi_v, \
92 label_snr, \
93 label_snr_v, \
94 label_t, \
95 label_time, \
96 lora1262_0, \
97 lora1262_data, \
98 rssi, \
99 snr
100 M5.update()
101
102
103if __name__ == "__main__":
104 try:
105 setup()
106 while True:
107 loop()
108 except (Exception, KeyboardInterrupt) as e:
109 try:
110 from utility import print_error_msg
111
112 print_error_msg(e)
113 except ImportError:
114 print("please update to latest firmware")
API
- class module.lora1262.LoRa1262Module(i2c=None, pin_cs=1, pin_irq=10, pin_busy=2, address=113, freq_khz=868000, bw='250', sf=8, coding_rate=8, preamble_len=12, syncword=18, output_power=10)
Bases:
LoRa868V12ModuleCreate a Module13.2 LoRa-1262 object.
The module uses the M-Bus SPI bus and a caller-supplied I2C bus. M5IOE1 controls SX1262 reset on G2, antenna-switch enable on G3, and LoRa power on G5.
- Parameters:
i2c (machine.I2C) – Initialized I2C bus used to access the M5IOE1.
pin_cs (int) – SX1262 chip-select MCU pin.
pin_irq (int) – SX1262 DIO1 MCU pin.
pin_busy (int) – SX1262 BUSY MCU pin.
address (int) – M5IOE1 I2C address, from 0x71 through 0x74.
freq_khz (int) – RF frequency in kHz, from 850000 through 930000.
bw (str) – LoRa bandwidth in kHz.
sf (int) – Spreading factor, from 6 through 12.
coding_rate (int) – Coding rate denominator, from 5 through 8.
preamble_len (int) – Preamble length, from 5 through 255 symbols.
syncword (int) – Sync word, from 1 through 255.
output_power (int) – Output power in dBm, from -9 through 22.
UiFlow2 Code Block:

MicroPython Code Block:
import M5 from module import LoRa1262Module, mbus M5.begin() lora1262 = LoRa1262Module(mbus.i2c1, address=0x71)
- set_freq(freq_khz=868000)
Set the RF frequency.
- Parameters:
freq_khz (int) – RF frequency in kHz, from 850000 through 930000.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.set_freq(868000)
- set_sf(sf)
Set the LoRa spreading factor.
- Parameters:
sf (int) – Spreading factor, from 6 through 12.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.set_sf(8)
- set_bw(bw)
Set the LoRa bandwidth.
- Parameters:
bw (str) – Bandwidth in kHz. Supported values are
"7.8","10.4","15.6","20.8","31.25","41.7","62.5","125","250", and"500".- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.set_bw("250")
- set_coding_rate(coding_rate)
Set the forward-error-correction coding rate.
- Parameters:
coding_rate (int) – Coding-rate denominator, from 5 through 8.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.set_coding_rate(8)
- set_syncword(syncword)
Set the LoRa sync word.
- Parameters:
syncword (int) – Sync word, from 1 through 255.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.set_syncword(0x12)
- set_preamble_len(preamble_len)
Set the LoRa preamble length.
- Parameters:
preamble_len (int) – Preamble length, from 5 through 255 symbols.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.set_preamble_len(12)
- set_output_power(output_power)
Set the LoRa output power.
- Parameters:
output_power (int) – Output power in dBm, from -9 through 22.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.set_output_power(10)
- send(packet, tx_at_ms=None)
Send a LoRa packet.
- Parameters:
- Returns:
Send timestamp in milliseconds.
- Return type:
UiFlow2 Code Block:



MicroPython Code Block:
timestamp = lora1262_0.send("Hello LoRa1262")
- recv(timeout_ms=None, rx_length=255, rx_packet=None)
Receive one LoRa packet.
- Parameters:
- Returns:
Received packet, or
Nonewhen the receive times out.- Return type:
RxPacket | None
UiFlow2 Code Block:


MicroPython Code Block:
packet = lora1262_0.recv()
- start_recv()
Start continuous LoRa reception.
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.start_recv()
- Return type:
None
- set_tx_callback(callback)
Register a callback for completed transmissions.
- Parameters:
callback (callable) – Function called without arguments after a packet has been transmitted.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
def on_transmit(): print("transmitted") lora1262_0.set_tx_callback(on_transmit)
- set_rx_callback(callback)
Register a callback for received packets.
- Parameters:
callback (callable) – Function receiving an
RxPacketafter a valid packet is received.- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
def on_receive(packet): print(packet.decode(), packet.rssi, packet.snr / 4) lora1262_0.set_rx_callback(on_receive)
- standby()
Put the SX1262 in standby mode.
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.standby()
- Return type:
None
- sleep()
Put the SX1262 in sleep mode.
UiFlow2 Code Block:

MicroPython Code Block:
lora1262_0.sleep()
- Return type:
None
- irq_triggered()
Return whether an SX1262 IRQ has triggered.
- Returns:
Truewhen an interrupt has triggered since the last send or receive operation started.- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
interrupted = lora1262_0.irq_triggered()
- deinit()
Put the radio to sleep and disable module power controls.
MicroPython Code Block:
lora1262_0.deinit()
- Return type:
None


