Atom DTU NBIoT
This is the driver library for the ATOM DTU NBIoT to accept and send data from the DTU NBIoT.
Support the following products:
Note
Please ensure that the device supports the NB-IoT frequency bands in your area before use.
Note
Please ensure that the firmware version of SIM7020 is greater than or equal to 1752B12SIM7020C.
can be used to check the firmware version.
UiFlow2 Example
NBIoT HTTP Example
Open the atoms3_base_nbiot_http_example.m5f2 project in UiFlow2.
This example shows how to send HTTP request using the Atom DTU NBIoT.
UiFlow2 Code Block:
Example output:
Output of received NBIoT message data via serial port.
MQTT Example
Open the atoms3_base_nbiot_mqtt_example.m5f2 project in UiFlow2.
This example shows how to send MQTT message using the Atom DTU NBIoT.
UiFlow2 Code Block:
Example output:
Output of received NBIoT message data on screen.
MicroPython Example
NBIoT HTTP Example
This example shows how to send HTTP request using the Atom DTU NBIoT.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import UART 9from base import AtomDTUNBIoT 10from base import AtomRS485 11 12 13uart2 = None 14base_rs485 = None 15base_nbiot = None 16base_nbiot_http_req = None 17 18 19def setup(): 20 global uart2, base_rs485, base_nbiot, base_nbiot_http_req 21 22 M5.begin() 23 Widgets.fillScreen(0x000000) 24 25 uart2 = UART(2, baudrate=115200, bits=8, parity=None, stop=1, tx=5, rx=6) 26 base_rs485 = AtomRS485( 27 1, 28 baudrate=115200, 29 bits=8, 30 parity=None, 31 stop=1, 32 tx=7, 33 rx=8, 34 txbuf=256, 35 rxbuf=256, 36 timeout=0, 37 timeout_char=0, 38 invert=0, 39 flow=0, 40 ) 41 base_nbiot = AtomDTUNBIoT(uart2, verbose=False) 42 base_nbiot.connect(apn="cmnbiot") 43 while not (base_nbiot.isconnected()): 44 pass 45 base_nbiot_http_req = base_nbiot.post( 46 "http://httpbin.org/post", 47 json={"message": "Hello from M5Stack!", "status": "active"}, 48 headers={ 49 "Content-Type": "application/json", 50 "Custom-Header": "MyHeaderValue", 51 }, 52 ) 53 print((str("status code: ") + str((base_nbiot_http_req.status_code)))) 54 print((str("content: ") + str((base_nbiot_http_req.content)))) 55 56 57def loop(): 58 global uart2, base_rs485, base_nbiot, base_nbiot_http_req 59 M5.update() 60 61 62if __name__ == "__main__": 63 try: 64 setup() 65 while True: 66 loop() 67 except (Exception, KeyboardInterrupt) as e: 68 try: 69 from utility import print_error_msg 70 71 print_error_msg(e) 72 except ImportError: 73 print("please update to latest firmware")
Example output:
Output of received NBIoT message data via serial port.
MQTT Example
This example shows how to send MQTT message using the Atom DTU NBIoT.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4import os, sys, io 5import M5 6from M5 import * 7from base import AtomDTUNBIoT 8from hardware import UART 9from base import AtomRS485 10 11 12label0 = None 13base_nbiot = None 14uart2 = None 15base_rs485 = None 16base_nbiot_mqtt = None 17 18 19def base_nbiot_testtopic_a_event(data): 20 global label0, base_nbiot, uart2, base_rs485, base_nbiot_mqtt 21 label0.setText(str(data[1])) 22 23 24def setup(): 25 global label0, base_nbiot, uart2, base_rs485, base_nbiot_mqtt 26 27 M5.begin() 28 Widgets.fillScreen(0x000000) 29 label0 = Widgets.Label("label0", 4, 6, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 30 31 uart2 = UART(2, baudrate=115200, bits=8, parity=None, stop=1, tx=5, rx=6) 32 base_rs485 = AtomRS485( 33 1, 34 baudrate=115200, 35 bits=8, 36 parity=None, 37 stop=1, 38 tx=7, 39 rx=8, 40 txbuf=256, 41 rxbuf=256, 42 timeout=0, 43 timeout_char=0, 44 invert=0, 45 flow=0, 46 ) 47 base_nbiot = AtomDTUNBIoT(uart2, verbose=False) 48 base_nbiot.connect(apn="cmnbiot") 49 while not (base_nbiot.isconnected()): 50 pass 51 base_nbiot_mqtt = base_nbiot.MQTTClient( 52 "uiflow2-client", "mqtt.m5stack.com", port=1883, user="", password="", keepalive=0 53 ) 54 base_nbiot_mqtt.connect(clean_session=False) 55 base_nbiot_mqtt.subscribe("testtopic/a", base_nbiot_testtopic_a_event, qos=0) 56 57 58def loop(): 59 global label0, base_nbiot, uart2, base_rs485, base_nbiot_mqtt 60 M5.update() 61 base_nbiot_mqtt.check_msg() 62 63 64if __name__ == "__main__": 65 try: 66 setup() 67 while True: 68 loop() 69 except (Exception, KeyboardInterrupt) as e: 70 try: 71 from utility import print_error_msg 72 73 print_error_msg(e) 74 except ImportError: 75 print("please update to latest firmware")
Example output:
Output of received NBIoT message data on screen.
API
AtomDTUNBIoT
- class base.dtu_nbiot.AtomDTUNBIoT(uart, verbose=False)
Bases:
SIM7020Create an AtomDTUNBIoT object.
- Parameters:
uart (machine.UART) – The UART object to use.
verbose (bool) – Whether to print debug information.
UiFlow2 Code Block:

MicroPython Code Block:
from base import AtomDTUNBIoT from hardware import UART uart0 = UART(2, baudrate=115200, bits=8, parity=None, stop=1, tx=22, rx=19) dtu_nbiot = AtomDTUNBIoT(uart0, verbose=False)
Note
See
NBIOTUnitfor more details.
AtomRS485
Note
See AtomRS485 for more details.



