Atom DTU LoRaWAN-Series Base

This is the driver library for the Atom DTU LoRaWAN-Series Base to accept and send data from the LoRaWAN module.

Support the following products:

Atom DTU LoRaWAN470

Atom DTU LoRaWAN868

Atom DTU LoRaWAN915

UiFlow2 Example

LoRaWAN communication

Open the atoms3r_dtu_lorawan_example.m5f2 project in UiFlow2.

This example shows how to receive and send data using the Atom DTU LoRaWAN Base.

UiFlow2 Code Block:

example.png

Example output:

None

MicroPython Example

LoRaWAN communication

This example shows how to receive and send data using the Atom DTU LoRaWAN Base.

MicroPython Code Block:

 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 base import AtomDTULoRaWANBase
 9
10
11title0 = None
12base_lorawan470 = None
13
14
15def setup():
16    global title0, base_lorawan470
17
18    M5.begin()
19    title0 = Widgets.Title("LoRaWAN", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
20
21    base_lorawan470 = AtomDTULoRaWANBase(2, port=(5, 6))
22    base_lorawan470.set_join_mode(0)
23    base_lorawan470.config_otaa("xxxx", "xxxx", "xxxx")
24    base_lorawan470.set_frequency_band_mask("0400")
25    base_lorawan470.set_rx_window_param(0, 0, 505300000)
26    base_lorawan470.set_class_mode(2)
27    base_lorawan470.set_uplink_downlink_mode(1)
28    base_lorawan470.set_uplink_app_port(1)
29    base_lorawan470.join(1, 1, 20, 20)
30    print("LoRaWAN configuration complete")
31
32
33def loop():
34    global title0, base_lorawan470
35    M5.update()
36    if BtnA.isPressed():
37        print("Send Message")
38        base_lorawan470.send_data("11", 1, 15)
39
40
41if __name__ == "__main__":
42    try:
43        setup()
44        while True:
45            loop()
46    except (Exception, KeyboardInterrupt) as e:
47        try:
48            from utility import print_error_msg
49
50            print_error_msg(e)
51        except ImportError:
52            print("please update to latest firmware")

Example output:

None

API

AtomDTULoRaWANBase

class base.dtu_lorawan.AtomDTULoRaWANBase(id=1, port=None)

Bases: LoRaWAN_470

Create an AtomDTULoRaWANBase object

Parameters:
  • id (int) – The UART ID to use (0, 1, or 2). Default is 2.

  • port (list | tuple) – A list or tuple containing the TX and RX pin numbers.

UiFlow2 Code Block:

init.png

MicroPython Code Block:

from base import AtomDTULoRaWANBase

dtu_lorawan = AtomDTULoRaWANBase(0, (6, 5))
class driver.asr650x.LoRaWAN_470(uart, debug=False)

Bases: LoRaWAN_Asr650x

Create an LoRaWAN object.

Parameters:
  • tx (int) – The UART TX pin number.

  • rx (int) – The UART RX pin number.

  • debug (bool) – Whether to enable debug mode.

MicroPython Code Block:

from driver.asr650x import LoRaWAN_470

lora = LoRaWAN_470(tx=17, rx=16)
config_abp(devaddr, appskey, nwkskey)

Config the ABP join mode information.

Parameters:
  • devaddr (str) – The device address.

  • appskey (str) – The application session key.

  • nwkskey (str) – The network session key.

UiFlow2 Code Block:

config_abp.png

MicroPython Code Block:

lora.config_abp("0037CAE1FC3542B9", "70B3D57ED003B699", "67FA4ED1075A20573BCDD7594C458698")
get_abp_config()

Get the ABP join mode information.

Returns:

The ABP join mode information(devaddr, appskey, newskey).

Return type:

tuple

UiFlow2 Code Block:

get_abp_config.png

MicroPython Code Block:

lora.get_abp_config()
config_otaa(deveui, appeui, appkey)

Config the OTAA join mode information.

Parameters:
  • deveui (str) – The device EUI.

  • appeui (str) – The application EUI.

  • appkey (str) – The application key.

UiFlow2 Code Block:

config_otaa.png

MicroPython Code Block:

lora.config_otaa("0037CAE1FC3542B9", "70B3D57ED003B699", "67FA4ED1075A20573BCDD7594C458698")
get_otaa_config()

Get the OTAA join mode information.

Returns:

The OTAA join mode information(deveui, appeui, appkey).

Return type:

tuple

UiFlow2 Code Block:

get_otaa_config.png

MicroPython Code Block:

lora.get_otaa_config()
check_join_status()

Check the LoRaWAN network join status.

Returns:

The LoRaWAN network join status.

Return type:

bool

UiFlow2 Code Block:

check_join_status.png

MicroPython Code Block:

lora.check_join_status()

Check the data uplink status.

Returns:

The data uplink status.

Return type:

bool

UiFlow2 Code Block:

check_uplink_status.png

MicroPython Code Block:

lora.check_uplink_status()

Check downlink data, if have downlink data, return the message.

Parameters:

timeout (int) – The timeout time.

Returns:

False if no downlink data, otherwise return the downlink data.

Return type:

bool | str

UiFlow2 Code Block:

check_downlink_data.png

MicroPython Code Block:

lora.check_downlink_data()
class driver.asr650x.LoRaWAN_Asr650x(uart, debug=False)

Bases: object

Create an LoRaWAN object.

Parameters:
  • uart (machine.UART) – The UART object.

  • debug (bool) – Whether to enable debug mode.

MicroPython Code Block:

from driver.asr650x import LoRaWAN_Asr650x

lora = LoRaWAN_Asr650x(uart)
set_join_mode(mode)

Set the LoRaWAN join mode.

Parameters:

mode (int) – The LoRaWAN join mode.

UiFlow2 Code Block:

set_join_mode.png

MicroPython Code Block:

lora.set_join_mode(0)
set_frequency_band_mask(mask)

Set the frequency band mask.

Parameters:

mask (str) – The frequency band mask.

MicroPython Code Block:

lora.set_frequency_band_mask("0001")

Set the uplink and downlink frequency.

Parameters:

mode (int) – The uplink and downlink frequency.

MicroPython Code Block:

lora.set_uplink_downlink_mode(1)
set_class_mode(class_mode, branch=None, para1=None, para2=None, para3=None, para4=None)

Set the class mode, if the class mode is 0, the branch, para1, para2, para3, para4 will be ignored.

Parameters:
  • class_mode (int) – The class mode.

  • branch (int) – The branch selection.

  • para1 (int) – Set the beacon frequency, unit is Hz.

  • para2 (int) – Set the beacon data rate.

  • para3 (int) – Set ping frequency, unit is Hz.

  • para4 (int) – Set ping data rate.

MicroPython Code Block:

lora.set_class_mode(0, 0, 0, 0, 0, 0)
join(para1, para2=None, para3=None, para4=None)

Join the LoRaWAN network.

Parameters:
  • para1 (int) – 0 stop join, 1 start join.

  • para2 (int) – 0 close auto join, 1 open auto join.

  • para3 (int) – join interval, unit is second(7~255).

  • para4 (int) – join retry times(1~256).

UiFlow2 Code Block:

join.png

join_stop.png

MicroPython Code Block:

lora.join(1, 1, 8, 1)

lora.join(0)
send_data(payload, confirm=None, nbtrials=None)

Send data payload to LoRaWAN gateway.

Parameters:
  • payload (str) – The data to send.

  • confirm (int) – The confirm mode.

  • nbtrials (int) – The number of trials.

UiFlow2 Code Block:

send_data.png

MicroPython Code Block:

lora.send_data("Hello, World!", 1, 1)

Set the uplink app port.

Parameters:

port (int) – The uplink app port.

UiFlow2 Code Block:

set_uplink_app_port.png

MicroPython Code Block:

lora.set_uplink_app_port(1)
set_rx_window_param(rx1_offset, rx2_dr, rx2_freq)

Set the receive window parameter.

Parameters:
  • rx1_offset (int) – The RX1 offset.

  • rx2_dr (int) – The RX2 data rate.

  • rx2_freq (int) – The RX2 frequency.

MicroPython Code Block:

lora.set_rx_window_param(0, 0, 868100000)