pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

LoRa433

案例程序

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

setScreenColor(0x222222)

packet_size = None
check = None

lora433 = module.get(module.LORA433)

def lora433_callback(size):
  global packet_size, check
  packet_size = size
  if packet_size:
    check = lora433.read_packet()
    print(check)
  pass

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

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

功能说明

import module
lora433 = module.get(module.LORA433)
lora433.init_lora_module(cs=5, rst=13, irq=34)
  • 初始化LoRa模组,并指定相关CS, RST, IRQ引脚
lora433.set_lora_config(freq=433000000, band=125000, TxPow=17, sync=0x34, spreadfactor=7, crate=5, preamble=8, CRC=False)
  • 初始化LoRa配置:

    • freq:工作频率
    • 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:同步字
    • spreadfactor:扩频因子:
      • 6-12
    • crate:C/R编码率:
      • C/5-8
    • preamble:前导码长度
    • CRC:是否开启CRC校验
  • 详细配置参数含义与作用范围请参考 sx127x datasheet

lora433.write_str_packet('')
  • 发送字符串数据帧
lora433.set_begin_packet()
  • 初始化数据帧
lora433.write_packet([0x48, 0x65, 0x6C, 0x6C, 0x6F])
  • 向数据帧buffer写入数据
lora433.set_end_packet()
  • 完成数据帧编辑, 执行发送
lora433.set_receive_callback_handler(lora433_callback)
  • 初始化接收回调函数
def lora433_callback(size):
  global packet_size
  packet_size = size
  pass
  • 定义接收回调函数, 传入值为数据帧数据大小。并通过下方数据读取, RSSI读取, SNR读取等相关API, 在callback中获取数据帧内容。
lora433.read_str_packet()
  • 接收数据, 并转换为字符串
lora433.read_packet()
  • 接收原始数据Bytearray
lora433.get_rssi()
  • 获取当前数据帧RSSI值
lora433.get_snr()
  • 获取当前数据帧SNR值
lora433.set_sleep_mode()
  • 进入睡眠模式
lora433.set_standby_mode()
  • 进入待机模式
On This Page