This is the source code for SenseCAP S2110 XIAO LoRaWAN SensorBuilder and it provides an open-source tool to build your own LoRaWAN sensors.
Now you can open Arduino IDE on the PC and start tinkering!
Step 1: Install the necessary sensor support library :
Grove_BMP280
Grove_Sunlight_Sensor
Seeed_Arduino_MultiGas
Seeed_Arduino_BME68x
Seeed_Arduino_UltrasonicRanger
Seeed_Arduino_MultiGas
arduino-i2c-scd4x
ArduinoRS485
ArduinoModbus
Step 2: Install Seeed Studio XIAO RP2040
board.
refer to Seeed Studio XIAO RP2040 with Arduino | Seeed Studio Wiki
Step 3: Add pin defines.
Add the following lines at the end of the C:\Users\${UserName}\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.1.0\variants\seeed_xiao_rp2040\pins_arduino.h
file.
// RS485
#define RS485_SERIAL_PORT Serial1
#define RS485_DEFAULT_DE_PIN D8
#define RS485_DEFAULT_RE_PIN D8
#define RS485_DEFAULT_TX_PIN 1
Step 1: Add a sensorNew.hpp
file to the src\sensor
folder for the new sensor.
Step 2: Define the sensor class and implement the init()
and sample()
functions.
The sensor class should inherits from the sensorClass
class, and implement the init()
and sample()
functions.
The init()
function is used to initialize the sensor, and than returns a register offset value for Modbus communication.
The sample()
function is used to read the sensor data, returns true when the data is valid, and returns false when the data is invalid.
Step 3: Include the sensorNEW.hpp
file and call it.
Add line #include "sensorNew.hpp"
to the src\sensor\sensorBuilder.hpp
file.
In the setup()
function of the sensorBuilder.ino
file, create the new sensor class object and call the SensorBuilder.addSensor()
function with it as an argument.
Refer to the following code :
void setup()
{
Serial.begin(9600);
SensorBuilder.check_grove();
/* sensor list */
sensorUltrasonic *ultrasonic = new sensorUltrasonic();
SensorBuilder.addSensor(ultrasonic);
// add new sensor to sensor list
sensorNew *newSensor = new sensorNew();
SensorBuilder.addSensor(newSensor);
SensorBuilder.begin();
}
NOTE: the Modbus register address for the new sensor will start from
0x0034
, the register bit width for each measurement value is 32, so the register address offset between two adjacent measurement values is 2.
Grove Sensor Name | Register Name | Register Address (Hexadecimal) |
Register Address (Decimal) |
---|---|---|---|
Grove - CO2 & Temperature & Humidity Sensor (SCD41) | Temperature | 0x0004 | 04 |
Humidity | 0x0006 | 06 | |
CO2 | 0x0008 | 08 | |
Grove - Light Sensor v1.2 | Light | 0x000A | 10 |
Grove - Flame Sensor | Flame | 0x000C | 12 |
Grove - Oxygen Sensor (MIX8410) | Oxygen | 0x000E | 14 |
Grove - Sunlight sensor (SI1151) | Light Intensity | 0x0010 | 16 |
Visible Light | 0x0012 | 18 | |
UV | 0x0014 | 20 | |
Grove Temperature and Barometer Sensor (BMP280) | Barometric Temperature | 0x0016 | 22 |
Atmospheric Pressure | 0x0018 | 24 | |
Height | 0x001A | 26 | |
Grove - Temperature Humidity Pressure Gas Sensor(BME680) | Temperature | 0x001C | 28 |
Atmospheric Pressure | 0x001E | 30 | |
Humidity | 0x0020 | 32 | |
Air Quality(VOC) | 0x0022 | 34 | |
Grove - Gas Sensor V2(Multichannel) | N02 | 0x0024 | 36 |
C2H50H | 0x0026 | 38 | |
VOC | 0x0028 | 40 | |
CO | 0x002A | 42 | |
Grove - UV Sensor | UV Intensity | 0x002C | 44 |
Grove - Turbidity Sensor Meter V1.0 | Turbidity | 0x002E | 46 |
Grove - TDS Sensor | TDS | 0x0030 | 48 |
Grove - Ultrasonic Ranger | Distance | 0x0032 | 50 |
Modbus register addresses 0x0000 to 0x0003 are reserved for storing module system information, where 0x0000 is the modbus address with a default value of 1 and a maximum value of 247, 0x0001 is the serial port baud rate with a default value of 96 (corresponding to 9600), and 0x0002 to 0x0003 are for software version.