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 automaticly sensor data to TTN - if you pess the button - you can send messages manualy. 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 mode
The 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
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.
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
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
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.
The Source Code of our ATOM DTU LoRaWAN TTN SensorNode is coded with the new Arduino 2.0 IDE - well documented - and shows DEBUG infos to every step we make. 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 infos 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"
Follow the device registration tutorial from the TTN's website https://www.thethingsindustries.com/docs
m5-docs (m5stack.com)
to 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
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 -> [?]
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.
Greetings Achim Kern
Comments