M5STACK ATOM DTU LoRaWAN868 using Ardiuino IDE
2023-01-15 | By M5Stack
License: General Public License Arduino
* Thanks for the source code and project information provided by @KeHoSoftware(Achim Kern)
Things used in this project
Hardware components
M5Stack Atom DTU LoRaWAN Kit 868MHz (ASR6501)×1
M5Stack PIR Sensor Human Body Infrared PIR Motion Sensor (AS312)×1
Software apps and online services
Introduction
M5STACK recently released the ATOM DTU LoRaWAN868.The M5STACK ATOM can be programmed using Arduino IDE (2.0.4).
This tutorial shows you how to connect UNIT ENVIII, UNIT PIR to this system and how we transmit all that data to The Things Network V3. Your LCARS SmartHome SensorNode will be able to measure your environment data (temperature, humidity and pressure) and intruder motions. The LED in front of the ATOM will always inform you about the system status. Every 10 minutes we will send automatically sensor data to TTN - if you press the button - you can send messages manually. The PIR Unit will count motions between your sending periods.
LED WHITE - system is booting and joining TTN
LED BLUE - system has joined TTN and sending data
LED RED - intruder alert
LED GREEN - system actual in stand-by modeThe Arduino Code is well documented and compiled with the new IDE 2.0.4. Also, you will see very detailed DEBUG messages about every single step. We will and can easily expand the Code with more sensors like
CO2, PM10, Digital Light etc.
M5STACK ATOM DTU LoRaWAN868
ATOM DTU LoRaWAN868 is a LoRaWAN Programmable Data Transmission Unit (DTU) suitable for 868MHz frequency. The module adopts the ASR6501 scheme, which supports long-distance communication and has both ultra-low power consumption and high sensitivity. The module integrates the LoRaWAN protocol stack and adopts a serial communication interface (using AT command set for control). When used, it can be used as a collection node to access a large number of gateways for data collection and management. Integrate SMA external antenna interface to improve the communication quality and signal stability of the device. Unlike the DTU which generally only has the function of data transparent transmission, the ATOM DTU series adopts a more open architecture design. The controller ATOM LITE can modify the program at will according to the actual business. The whole machine reserves a variety of interfaces (RS485, I2C, custom interface) for user expansion, which is convenient for the rapid access of sensors and actuators. With its own guide rail clamping structure, it is perfectly embedded in various industrial control sites. A cost-effective solution for small data collection nodes.
Product Features
- ASR6501
- Operating frequency: 868MHz
- Serial communication: UART 115200bps (AT command)
- With super anti-interference ability, able to work normally in complex interference environment
- RS485 communication interface (with 12V input interface, internal integrated DCDC step-down 5V)
- Modbus Master/slave
- Strong signal access capability
- External antenna: SMA antenna interface
- Grove expansion interface: -I2C x1 -Custom x1
- Self-contained rail clamping
Sensors we will connect to the ATOM DTU LoRaWAN868
We will start to connect at first the sensors Unit ENVIII and PIR. You can later easily expand the code and include more sensors like CO2, PM10, Digital Light etc.
Unit ENVIII
ENV III is an environmental sensor that integrates SHT30 and QMP6988 internally to detect temperature, humidity, and atmospheric pressure data. SHT30 is a high-precision and low-power digital temperature and humidity sensor, and supports I2C interface (SHT30:0x44, QMP6988:0x70).QMP6988 is an absolute air pressure sensor specially designed for mobile applications, with high accuracy and stability, suitable for environmental data collection and detection types of projects.
This Unit communicates with ATOM Lite GROVE(I2C I/0 UART).
Product Features
- Simple and easy to use
- High accuracy
- I2C communication interface
- HY2.0-4P interface, support platform UIFlow , Arduino
- 2x LEGO compatible holes
Unit PIR
PIR is a human body infrared unit. It belongs to the "passive pyroelectric infrared detector". It detects the infrared radiation emitted and reflected by the human body or object. When infrared is detected, the output level is high, and it takes a while. Delay (high during the period and allow repeated triggers) until the trigger signal disappears (restores low).
This Unit communicates with ATOM DTU LoRaWAN868 GROVE PORT A.
Product Features
- Detects the distance: 500cm
- latency time: 2s
- Sensing range: < 100°
- Quiescent current: < 60uA
- Operating temperature: -20 - 80 °C
- GROVE interface, support UIFlow and Arduino
- Two Lego installation holes
Build Instructions
Our ATOM DTU LoRaWAN SensorNode is very easy to set up. The PIR sensor connects to the top PORT A and the ENVIII sensor to the bottom I2C I/O UART PORT of the Atom Lite.
If you like - you can build a nice construction with some LEGO parts as we do.
Compiling the Arduino Source Code
The Source Code of our ATOM DTU LoRaWAN TTN SensorNode is coded with the new Arduino 2.0 IDE - well documented - and shows DEBUG info for every step we take. You only have to edit your DEV EUI, APP EUI and APP KEY.
https://docs.arduino.cc/software/ide-v2/tutorials/getting-started-ide-v2
Please use Board "M5Stack-ATOM"
If you need to install M5Stack boards include
https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
in the Arduino preferences alternative board extensions. We need some external libraries - all info inside Source Code.
https://github.com/m5stack/M5Atom#include "M5Atom.h"
https://github.com/m5stack/M5-LoRaWAN#include "M5_LoRaWAN.h"
https://github.com/m5stack/M5Unit-ENV#include "M5_ENV.h"
Configuration of TTN V3
Follow the device registration tutorial from the TTN's website https://docs.m5stack.com/en/quick_start/lorawan/ttn create an account and register an app as well the device.
In your application check Integrations and please add Data Storage and MQTT. Next you should edit the Payload Format Uplink (decoder).
// we can change each end devive via port number
function Decoder(bytes, port)
{
var decoded = {};
if (port === 2)
{
if (bytes.length==6)
{
var tmp = (bytes[0]<<8 | bytes[1]);
var hum = (bytes[4]);
var pre = (bytes[2]<<8 | bytes[3]);
var motion = (bytes[5]);
decoded.env3_temperature = (tmp-5000)/100;
decoded.env3_pressure = pre/10;
decoded.env3_humidity = hum/2;
decoded.pir_motion = motion;
return decoded;
}
else
{
decoded.Status="JOIN - ATOM DTU LoRaWAN is online";
return decoded;
}
}
}
Application is booting
Application is booting
16:56:02.776 -> M5Atom initializing...OK
16:56:07.789 ->
16:56:07.789 ->
16:56:07.789 -> Starting...
16:56:07.789 -> M5ATOM_DTU_LoRaWan_OTAA_Node_01 Version 1.04
16:56:07.789 -> connected via LoRaWAN to TTN V3
16:56:07.789 ->
16:56:07.789 -> [x] Initializing M5Stack Atom_DTU_LoRaWAN868
16:56:07.789 -> [x] Initializing ENVIII Unit (SHT30 and QMP6988)
16:56:07.891 -> [x] Initializing PIR Unit
you should see then some more messages how we init the LoRaWAN system.
Finally you should see this in your serial monitor:
16:56:25.610 -> [?] CJOIN:OK
16:56:25.610 -> [x] LoRaWAN TTN V3 JOIN-OK
16:56:33.126 -> [x] sending first sensor data to TTN V3 ...
16:56:33.126 ->
16:56:33.126 ->
16:56:33.126 -> M5ATOM_DTU_LoRaWan_OTAA_Node_01 Version 1.04
16:56:33.126 ->
16:56:33.126 -> [x] ENVIII Pressure: 990.03
16:56:33.363 -> [x] ENVIII Temperature: 20.75
16:56:33.363 -> [x] ENVIII Humidity: 55.56
16:56:33.394 ->
16:56:33.394 -> [x] PIR Motion: 0
16:56:33.394 -> [x] actual TTN payload --> 1BA326AC6F00
16:56:33.394 -> [x] sending data to TTN V3 ...
16:56:33.497 -> [?]
16:56:38.491 -> [?] OK SENT:01
16:56:43.496 -> [?]
M5STACK ATOM DTU LoRaWAN868 connected to TTN standby mode
We hope all runs fine if you rebuild this nice LCARS SmartHome TTN Node. Next step you can do - include more sensors - grab MQTT sensor data with a Node-Red system - post data into an InfluxDB, visualize all with Grafana.
Schematics
Wiring Unit ENVIII and Unit PIR with M5STACK ATOM DTU LoRaWAN868
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum