After a couple of months building LoRa field gateways and demo clients I figured a selection of sample projects (with analog, digital, I2C and serial sensors) to show how to use all these building blocks would useful for students, teachers & hobbyists.
This is an end-to-end demo using a duino device and one of my Windows 10 IoT Core LoRa field gateways to remotely monitor Carbon Dioxide(CO2) levels as an example of a serial connected sensor. I have based this project on a project suggested by a student at a maker class I run at a local co-ed school.
Students were talking about how stuffy some of the classrooms were and how this might affect learning.
There was also some discussion about how local schools were being re-built (post earthquake) as larger classrooms supervised by two or more teachers.
I also found some research into how CO2 levels varied for different designs of classroom and how this impacted on learning.
This project should be read in conjunction with my other Hackster projects.
The Duino DeviceTo keep things simple the sensor nodes are plug 'n' play, and use spare cellphone chargers to power the Arduino or Seeeduino device.
The duino client uses a SeeedStudio Grove - serial Carbon Dioxide Sensor(MH-Z16), base shield and a Dragino, MakerFabs or Elecrow LoRa shield.
The first step is to mount the Grove Base Shield on the Arduino and plug the Grove CO2 sensor into a UART socket. The seeedstudio wiki has step by step instruction and sample code which I had to fix (Jan 2019).
/*
This test code is write for Arduino AVR Series(UNO, Leonardo, Mega)
If you want to use with LinkIt ONE, please connect the module to D0/1 and modify:
// #include <SoftwareSerial.h>
// SoftwareSerial s_serial(2, 3); // TX, RX
https://www.winsen-sensor.com/products/ndir-co2-sensor/mh-z16.html
*/
#include <SoftwareSerial.h>
SoftwareSerial s_serial(2, 3); // TX, RX
#define sensor s_serial
const unsigned char cmd_get_sensor[] =
{
0xff, 0x01, 0x86, 0x00, 0x00,
0x00, 0x00, 0x00, 0x79
};
unsigned char dataRevice[9];
int CO2PPM;
void setup()
{
sensor.begin(9600);
Serial.begin(9600);
Serial.println("get a 'g', begin to read from sensor!");
Serial.println("********************************************************");
Serial.println();
}
void loop()
{
if(dataRecieve())
{
Serial.print(" CO2: ");
Serial.print(CO2PPM);
Serial.println("");
}
delay(10000);
}
bool dataRecieve(void)
{
byte data[9];
int i = 0;
sensor.flush();
//transmit command data
for(i=0; i<sizeof(cmd_get_sensor); i++)
{
sensor.write(cmd_get_sensor[i]);
}
sensor.flush();
//begin reveiceing data
if(sensor.available())
{
while(sensor.available())
{
for(int i=0;i<9; i++)
{
data[i] = sensor.read();
}
}
}
for(int j=0; j<9; j++)
{
Serial.print(data[j], HEX);
Serial.print(" ");
}
Serial.println("");
if (i != 9)
{
Serial.println("Error buffer length");
return false;
}
byte checksum = 0 ;
for(int j=1; j<8; j++)
{
checksum += data[j];
}
checksum=0xff-checksum;
checksum+=1;
if (checksum != data[8])
{
Serial.println("Error checksum");
return false;
}
if ( data[0] != 0xFF )
{
Serial.println("Error start byte");
return false;
}
if ( data[1] != 0x86 )
{
Serial.println("Error command");
return false;
}
CO2PPM = (int)data[2] * 256 + (int)data[3];
return true;
}
For the final deployment I am using the NDIR Software Sensor library from Sandbox Electronics.
Once the students are confident with building & deploying the code from the Arduino IDE the focus shifts to the LoRa wireless connectivity.
The students use my Hackster duino client sample as the basis of their application.
Pay attention to your local ISM band regulations and ensure that you are compliant with them, especially frequency, power levels and duty cycle requirements.
Send data as infrequently as possible and reduce the transmit power to the minimum level required for reliable data transmission. If interference is a problem change frequencies\sync word.
The Windows 10 IoT Core Field GatewayI have prebuilt LoRa telemetry field gateway Hackster projects for AdaFruit.IO and Azure IoT Hubs\Azure IOT Central. Once the field gateway is installed and running the Windows 10 IoT Core the ETW logging is useful for checking the sensor data is being received and getting the BCD representations of sensor identifiers.
For extension projects students will look at comparing the performance of different vendor's gas sensors, figuring out how to measure the impact of CO2 levels on learning, and building 3D-printed enclosures.
Comments