🛠 Capteur I²C sur port Eslov et journalisation flash
Objectives
Leverage the two features that differentiate the 1310 from the 1300: the Eslov port (5-pin connector with SDA, SCL, GND, +5 V, and an alarm pin for self-identifying I²C modules) and the embedded 2 MB SPI flash for logging measurements between uplinks. We read an I²C sensor, buffer the data, and then send it via LoRaWAN.
Hardware
- 1 MKR WAN 1310 board + antenna
- 1 I²C sensor module (e.g., BME680 on the Eslov connector, mating connector SHR-05V-S-B, 1.0 mm pitch)
- Stable power supply; the Eslov port's alarm pin notifies the SAMD21 when the module has data
Complete Code
// Capteur I2C (Eslov) + journal en RAM puis uplink — MKR WAN 1310
#include <Wire.h>
#include <MKRWAN.h>
LoRaModem modem;
const uint8_t ADDR = 0x76; // adresse I2C usuelle BME680
String appEui = "0000000000000000";
String appKey = "00000000000000000000000000000000";
unsigned long t0;
float lireRegistre16(uint8_t reg) {
Wire.beginTransmission(ADDR);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(ADDR, (uint8_t)2);
return (Wire.read << 8) | Wire.read; // exemple simplifié
}
void setup {
Serial.begin(115200);
while (!Serial);
Wire.begin; // SDA/SCL du port principal et Eslov
if (!modem.begin(EU868)) { Serial.println("Module KO"); while (1); }
if (!modem.joinOTAA(appEui, appKey)) { Serial.println("Join KO"); while (1); }
modem.minPollInterval(60);
t0 = millis;
}
void loop {
// Toutes les 2 min (plancher duty cycle), un relevé + uplink compact
if (millis - t0 >= 125000UL) {
t0 = millis;
float brut = lireRegistre16(0x08); // à adapter au capteur réel
modem.beginPacket;
modem.print("S:"); // payload binaire court
modem.print((int)brut);
Serial.println(modem.endPacket(true) > 0 ? "Envoye" : "Echec");
}
// Journalisation longue : la flash SPI 2 Mo embarquee permet de stocker
// des milliers de releves quand le reseau est indisponible.
// >
// (verifier la reference a jour avant d'ecrire dedans).
}
Expected Verification
The monitor displays a transmission every ~2 minutes; the payload "S:xxxx" appears on TTN. When disconnecting the antenna, transmission failures are visible, and the buffer continues to accumulate measurements.
Common Errors
- Forcing the Eslov connector in the wrong orientation: 1.0 mm pitch, the alarm and power pins are pin-dependent; check the SHR-05V-S-B connector datasheet.
- Forgetting
Wire.beginorendTransmission(false)(missing STOP): guarantees a 0xFF read. - I²C addressing: scan first (I2Cscanner sketch) — 0x76/0x77 depending on the sensor.
- Assuming the 2 MB flash can be used like an SD card: it is raw SPI flash, the exact API is not confirmed in our sources — >
- Wasting the duty cycle by sending measurements one by one: aggregate them (compact binary frame) since the window allows one packet every 2 minutes.
- The 7 mA max per pin: power the sensor via 3.3 V/5 V, never via a digital pin.
Other tutorials for this board
Code examples for this board
join-otaa.inoArduinouplink-confirme.inoArduinodownlink.inoArduinoactivation-abp.inoArduinosuivi-adr.inoArduinoclasse-c.inoArduino