Hardware Concept
My plan is to develop two hardware modules, the first LoRa module would contain the MKR WAN 1310 with the Nicla Vision and the second module would contain the Nicla Sense. The second module would connect to the first via a 6 conductor cable that would provide +5V, GND, I2C SDA/SCL, and 2 GPIO. My thought is that the first module would mount at the top of the hive near the solar panel and the second with the environment sensors would mount somewhere in the interior.
Nicla as a shield
I had not realized that the Nicla boards were designed with pinouts such that they can mount directly onto MKR boards - until I read this tutorial Nicla Sense ME - Use as MKR shield which uses a MKR WiFi 1010.
Looking at the board pinouts, the power (+5V,GND), the I2C (SDA/SCL), and UART (TX/RX) pins align when the Nicla is mounted at the top end of the MKR WAN 1310 connectors.
So, this makes connections in the LoRa module much easier - just plug the Nicla on top. I added a proto board with a socket for the MKR WAN 1310 so that I could interface a plug-in connector to module 2. This also provides space for a small LiPo battery in case I want to use this module without the solar module. The picture below shows the Nicla Sense ME mounted on the MKR WAN 1310 (I don't have the Nicla Vision board yet). This is the configuration that I used to test the connection to the Things Stack.
Then I printed a case to house the boards. I added mounting holes at the back so that I could add mounting adapters later.
The cutout in the cover exposes the entire top of the Nicla board where the camera, microphone, and other sensors would be.
A closeup of the assembly mounted in the case.
And the assembly mounted on a tripod with the cover on and off.
Code used for Things Stack test
Nicla_Sense_as_shield.ino
#include "Arduino.h" #include "Arduino_BHY2.h" // Set DEBUG to true in order to enable debug print #define DEBUG false void setup(){ #if DEBUG Serial.begin(115200); BHY2.debug(Serial); #endif BHY2.begin(NICLA_I2C, NICLA_AS_SHIELD); } void loop(){ // Update and then sleep BHY2.update(100); }
MKR1310_Nicla_Sense_THPG_TTN.ino
#include "Arduino.h" #include "Arduino_BHY2Host.h" #include <MKRWAN.h> #include "arduino_secrets.h" // Please enter your sensitive data in the Secret tab or arduino_secrets.h String appEui = SECRET_APP_EUI; String appKey = SECRET_APP_KEY; LoRaModem modem; // SensorXYZ accel(SENSOR_ID_ACC); Sensor temperature(SENSOR_ID_TEMP); Sensor humidity(SENSOR_ID_HUM); Sensor pressure(SENSOR_ID_BARO); Sensor gas(SENSOR_ID_GAS); void setup() { // debug port Serial.begin(115200); // while(!Serial); BHY2Host.begin(false, NICLA_AS_SHIELD); // accel.begin(); temperature.begin(); humidity.begin(); pressure.begin(); gas.begin(); // change this to your regional band (eg. US915, AS923, ...) if (!modem.begin(US915)) { Serial.println("Failed to start module"); while (1) {} }; Serial.print("Your module version is: "); Serial.println(modem.version()); Serial.print("Your device EUI is: "); Serial.println(modem.deviceEUI()); int connected = modem.joinOTAA(appEui, appKey); // delay (3 * 60 * 1000); // if (!connected) { // Serial.println("Something went wrong; are you indoor? Move near a window and retry"); // while (1) {} // } while(!connected){ Serial.println("Retry..."); if(!modem.joinOTAA(appEui, appKey)){ Serial.println("Fail"); } else{ break; } }; // Set poll interval to 60 secs. modem.minPollInterval(60); // NOTE: independent of this setting, the modem will // not allow sending more than one message every 2 minutes, // this is enforced by firmware and can not be changed. } void loop() { static auto printTime = millis(); BHY2Host.update(); int temp = temperature.value() * 100; int humid = humidity.value() * 100; int press = pressure.value() * 100; int gs = gas.value() * 100; int err; if (millis() - printTime >= 60000) { byte payload[4]; payload[0] = highByte(humid); payload[1] = lowByte(humid); payload[2] = highByte(temp); payload[3] = lowByte(temp); modem.beginPacket(); modem.write(payload, 16); err = modem.endPacket(true); if (err > 0) { Serial.println("Message sent correctly!"); } else { Serial.println("Error sending message :("); Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength"); Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)"); } printTime = millis(); // Serial.println(String("Acceleration values: ") + accel.toString()); Serial.println(String("temperature: ") + String(temperature.value(),3)); Serial.println(String("humidity: ") + String(humidity.value(),3)); Serial.println(String("pressure: ") + String(pressure.value(),3)); Serial.println(String("gas: ") + String(gas.value(),3)); Serial.println(""); } }