pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

LoRa868

Example

from m5stack import *
from m5ui import *
from uiflow import *
import module

setScreenColor(0x222222)

packet_size = None
check = None

lora868 = module.get(module.LORA868)

def lora868_callback(size):
  global packet_size, check
  packet_size = size
  if packet_size:
    check = lora868.read_packet()
    print(check)
  pass

def buttonA_wasPressed():
  global packet_size, check
  lora868.set_begin_packet()
  lora868.write_packet([0x48, 0x65, 0x6C, 0x6C, 0x6F])
  lora868.set_end_packet()
  pass
btnA.wasPressed(buttonA_wasPressed)

lora868.init_lora_module(cs=5, rst=13, irq=34)
lora868.set_lora_config(freq=868000000, band=125000, TxPow=17, sync=0x34, spreadfactor=7, crate=5, preamble=8, CRC=False)
lora868.set_receive_callback_handler(lora868_callback)

API

import module
lora868 = module.get(module.LORA868)
lora868.init_lora_module(cs=5, rst=13, irq=34)
  • Initialize the LoRa module and specify the relevant CS, RST, IRQ pins
lora868.set_lora_config(freq=868000000, band=125000, TxPow=17, sync=0x34, spreadfactor=7, crate=5, preamble=8, CRC=False)
  • Initialize LoRa configuration:

    • freq:operating frequency
    • band:
      • 7.8 kHz
      • 10.4 kHz
      • 15.6 kHz
      • 20.8kHz
      • 31.25 kHz
      • 41.7 kHz
      • 62.5 kHz
      • 125 kHz
      • 250 kHz
      • 500 kHz
    • TxPow:
      • 0-20dBm
    • sync:synchronized characters
    • spreadfactor:
      • 6-12
    • crate:C/R:
      • C/5-8
    • preamble:preamble length
    • CRC:Whether to enable CRC checking
  • Please refer to sx127x datasheet for detailed configuration parameter meanings and ranges.

lora868.write_str_packet('')
  • Send String Data Frame
lora868.set_begin_packet()
  • Initialize data frame
lora868.write_packet([0x48, 0x65, 0x6C, 0x6C, 0x6F])
  • Write data to the data frame buffer
lora868.set_end_packet()
  • Finish editing the data frame, and execute the transmission
lora868.set_receive_callback_handler(lora868_callback)
  • Initialize the receive callback function
def lora868_callback(size):
  global packet_size
  packet_size = size
  pass
  • Define the receive callback function, the incoming value is the size of the data frame. And through the following data reading, RSSI reading, SNR reading and other related APIs, get the data frame content in the callback.
lora868.read_str_packet()
  • Receives data and converts it to a string
lora868.read_packet()
  • Receive raw data Bytearray
lora868.get_rssi()
  • Get current data frame RSSI value
lora868.get_snr()
  • Get the current data frame SNR value
lora868.set_sleep_mode()
  • Go to sleep mode
lora868.set_standby_mode()
  • Entering standby mode
On This Page