|
| 1 | +LoRa868 v1.2 Module |
| 2 | +===================================== |
| 3 | + |
| 4 | +.. include:: ../refs/module.lora_sx1262.ref |
| 5 | + |
| 6 | +The LoRa868 v1.2 Module is part of the M5Stack stackable module series. It is a LoRa communication module that operates at a 900MHz frequency and utilizes the SX1262 chip solution. |
| 7 | + |
| 8 | +Support the following products: |
| 9 | + |
| 10 | +|Module LoRa868 v1.2| |
| 11 | + |
| 12 | + |
| 13 | +Micropython Example |
| 14 | +---------------------------- |
| 15 | + |
| 16 | +.. note:: Before using the following examples, please check the DIP switches on the module to ensure that the pins used in the example match the DIP switch positions. For specific configurations, please refer to the product manual page. The SPI configuration has been implemented internally, so users do not need to worry about it. |
| 17 | + |
| 18 | +Sender |
| 19 | +++++++++++++++++++++++++++++ |
| 20 | +send data |
| 21 | + |
| 22 | + .. literalinclude:: ../../../examples/module/lora_sx1262/cores3_lora_sx1262_tx_example.py |
| 23 | + :language: python |
| 24 | + :linenos: |
| 25 | + |
| 26 | +Receiver |
| 27 | +++++++++++++++++++++++++++++ |
| 28 | +receive data |
| 29 | + |
| 30 | + .. literalinclude:: ../../../examples/module/lora_sx1262/cores3_lora_sx1262_rx_example.py |
| 31 | + :language: python |
| 32 | + :linenos: |
| 33 | + |
| 34 | +UIFlow2.0 Example |
| 35 | +---------------------------- |
| 36 | + |
| 37 | +.. note:: Before using the following examples, please check the DIP switches on the module to ensure that the pins used in the example match the DIP switch positions. For specific configurations, please refer to the product manual page. The SPI configuration has been implemented internally, so users do not need to worry about it. |
| 38 | + |
| 39 | +Sender |
| 40 | +++++++++++++++++++++++++++++ |
| 41 | +send data |
| 42 | + |
| 43 | + |cores3_lora_sx1262_tx_example.png| |
| 44 | + |
| 45 | +.. only:: builder_html |
| 46 | + |
| 47 | + |cores3_lora_sx1262_tx_example.m5f2| |
| 48 | + |
| 49 | + |
| 50 | +Receiver |
| 51 | +++++++++++++++++++++++++++++ |
| 52 | +receive data |
| 53 | + |
| 54 | + |cores3_lora_sx1262_rx_example.png| |
| 55 | + |
| 56 | +.. only:: builder_html |
| 57 | + |
| 58 | + |cores3_lora_sx1262_rx_example.m5f2| |
| 59 | + |
| 60 | + |
| 61 | +class LoRaSx1262Module |
| 62 | +------------------------------ |
| 63 | + |
| 64 | +Constructors |
| 65 | +------------------------------ |
| 66 | + |
| 67 | +.. class:: LoRaSx1262Module(pin_rst: int = 5, \ |
| 68 | + pin_cs: int = 1, \ |
| 69 | + pin_irq: int = 10, \ |
| 70 | + pin_busy: int = 2, \ |
| 71 | + freq_khz: int = 868000, \ |
| 72 | + bw: str = "250", \ |
| 73 | + sf: int = 8, \ |
| 74 | + coding_rate: int = 8, \ |
| 75 | + reamble_len: int = 12, \ |
| 76 | + syncword:int = 0x12, \ |
| 77 | + output_power: int = 10) |
| 78 | + |
| 79 | + :param int pin_rst: (RST) Reset pin number. |
| 80 | + :param int pin_cs: (NSS) Chip select pin number. |
| 81 | + :param int pin_irq: (IRQ) Interrupt pin number. |
| 82 | + :param int pin_busy: (BUSY) Busy pin number. |
| 83 | + :param int freq_khz: LoRa RF frequency in KHz, with a range of 850000 KHz to 930000 KHz. |
| 84 | + :param str bw: Bandwidth, options include: |
| 85 | + "7.8": 7.8 KHz |
| 86 | + "10.4": 10.4 KHz |
| 87 | + "15.6": 15.6 KHz |
| 88 | + "20.8": 20.8 KHz |
| 89 | + "31.25": 31.25 KHz |
| 90 | + "41.7": 41.7 KHz |
| 91 | + "62.5": 62.5 KHz |
| 92 | + "125": 125 KHz |
| 93 | + "250": 250 KHz |
| 94 | + "500": 500 KHz |
| 95 | + :param int sf: Spreading factor, range from 7 to 12. Higher spreading factors allow reception of weaker signals but with slower data rates. |
| 96 | + :param int coding_rate: Forward Error Correction (FEC) coding rate expressed as 4/N, with a range from 5 to 8. |
| 97 | + :param int preamble_len: Length of the preamble sequence in symbols, range from 0 to 255. |
| 98 | + :param syncword: Sync word to mark the start of the data frame, default is 0x12. |
| 99 | + :param int output_power: Output power in dBm, range from -9 to 22. |
| 100 | + |
| 101 | + - ``pin_rst``: (RST) Reset pin number. |
| 102 | + - ``pin_cs``: (NSS) Chip select pin number. |
| 103 | + - ``pin_irq``: (IRQ) Interrupt pin number. |
| 104 | + - ``pin_busy``: (BUSY) Busy pin number. |
| 105 | + - ``freq_khz``: LoRa RF frequency in KHz, with a range of 850000 KHz to 930000 KHz. |
| 106 | + - ``bw``: Bandwidth, options include: |
| 107 | + - ``"7.8"``: 7.8 KHz |
| 108 | + - ``"10.4"``: 10.4 KHz |
| 109 | + - ``"15.6"``: 15.6 KHz |
| 110 | + - ``"20.8"``: 20.8 KHz |
| 111 | + - ``"31.25"``: 31.25 KHz |
| 112 | + - ``"41.7"``: 41.7 KHz |
| 113 | + - ``"62.5"``: 62.5 KHz |
| 114 | + - ``"125"``: 125 KHz |
| 115 | + - ``"250"``: 250 KHz |
| 116 | + - ``"500"``: 500 KHz |
| 117 | + - ``sf``: Spreading factor, range from 7 to 12. Higher spreading factors allow reception of weaker signals but with slower data rates. |
| 118 | + - ``coding_rate``: Forward Error Correction (FEC) coding rate expressed as 4/N, with a range from 5 to 8. |
| 119 | + - ``preamble_len``: Length of the preamble sequence in symbols, range from 0 to 255. |
| 120 | + - ``syncword``: Sync word to mark the start of the data frame, default is 0x12. |
| 121 | + - ``int output_power``: Output power in dBm, range from -9 to 22. |
| 122 | + |
| 123 | + UIFLOW2: |
| 124 | + |
| 125 | + |init.png| |
| 126 | + |
| 127 | +.. method:: set_irq_callback(callback) |
| 128 | + |
| 129 | + Set interrupt callback function. |
| 130 | + |
| 131 | + - ``callback``: The callback function to be executed when an interrupt occurs. |
| 132 | + |
| 133 | + **Note**: Call `start_recv()` to begin receiving data. |
| 134 | + |
| 135 | + UIFlow2.0 |
| 136 | + |
| 137 | + |set_irq_callback.png| |
| 138 | + |
| 139 | +.. method:: start_recv() |
| 140 | + |
| 141 | + Start receiving data. |
| 142 | + |
| 143 | + **Note**: This method initiates the process to begin receiving data. |
| 144 | + |
| 145 | + UIFlow2.0 |
| 146 | + |
| 147 | + |start_recv.png| |
| 148 | + |
| 149 | +.. method:: recv(self, timeout_ms=None, rx_length=0xFF, rx_packet=None) -> RxPacket |
| 150 | + |
| 151 | + Receive data. |
| 152 | + |
| 153 | + Attempt to receive a LoRa packet. Returns `None` if timeout occurs, or returns the received packet instance. |
| 154 | + |
| 155 | + - ``timeout_ms``: Timeout in milliseconds (optional). |
| 156 | + - ``rx_length``: Length of the data to be read. |
| 157 | + - ``rx_packet``: An instance of `RxPacket` (optional) to reuse. |
| 158 | + |
| 159 | + Returns an `RxPacket` object containing the received data. |
| 160 | + |
| 161 | + **Example:** |
| 162 | + |
| 163 | + :: |
| 164 | + |
| 165 | + data = recv() |
| 166 | + data = recv(timeout_ms=1000) |
| 167 | + data = recv(timeout_ms=1000, rx_packet=data) |
| 168 | + |
| 169 | + - `data.decode()`: Decode the received data. |
| 170 | + - `data.ticks_ms`: Timestamp of when the data was received. |
| 171 | + - `data.rssi`: Received signal strength (units: dBm). |
| 172 | + - `data.snr`: Signal-to-noise ratio (units: dB * 4). |
| 173 | + - `data.valid_crc`: CRC validity check. |
| 174 | + |
| 175 | + UIFlow2.0 |
| 176 | + |
| 177 | + |recv.png| |
| 178 | + |
| 179 | +.. method:: send(buf, tx_at_ms=None) -> int |
| 180 | + |
| 181 | + Send data. |
| 182 | + |
| 183 | + Send a data packet and return the timestamp after the packet is sent. |
| 184 | + |
| 185 | + - ``buf``: The data to be sent (supports string, list, tuple, or byte object). |
| 186 | + - ``tx_at_ms``: The timestamp in milliseconds when to send the data (optional). |
| 187 | + |
| 188 | + Returns a timestamp (result of `time.ticks_ms()`) indicating when the data packet was sent. |
| 189 | + |
| 190 | + **Example:** |
| 191 | + |
| 192 | + :: |
| 193 | + |
| 194 | + send("Hello World") # Send data immediately |
| 195 | + send("Hello World", 5000) # Send data at timestamp 5000 milliseconds |
| 196 | + |
| 197 | + UIFlow2.0 |
| 198 | + |
| 199 | + |send.png| |
| 200 | + |
| 201 | +.. method:: standby() |
| 202 | + |
| 203 | + Set module to standby mode. |
| 204 | + |
| 205 | + Puts the LoRa module into standby mode, consuming less power. |
| 206 | + |
| 207 | + UIFlow2.0 |
| 208 | + |
| 209 | + |standby.png| |
| 210 | + |
| 211 | +.. method:: sleep() |
| 212 | + |
| 213 | + Put the module to sleep mode. |
| 214 | + |
| 215 | + Reduces the power consumption by putting the module into deep sleep mode. |
| 216 | + |
| 217 | + UIFlow2.0 |
| 218 | + |
| 219 | + |sleep.png| |
| 220 | + |
| 221 | +.. method:: irq_triggered() -> bool |
| 222 | + |
| 223 | + Check IRQ trigger. |
| 224 | + |
| 225 | + Returns `True` if an interrupt service routine (ISR) has been triggered since the last send or receive started. |
| 226 | + |
| 227 | + UIFlow2.0 |
| 228 | + |
| 229 | + |irq_triggered.png| |
0 commit comments