Nouveau module récepteur nooLite MR1132 pour Arduino

image

nooLite . ? nooLite , , USB .

, MR1132, , , nooLite , , nooLite - , .

Dans cet article je vais vous parler du fonctionnement de ce module et vous donner un schéma de travail, à partir duquel vous pourrez facilement créer vos appareils sur le MR1132. Dans les articles suivants, je parlerai de l'intégration de ce module avec le système populaire Arduino Mega Server et des merveilleuses fonctionnalités qui apparaîtront en lien avec cette intégration.

Module


MR1132 , MT1132 ( , , ). , MT1132 , MR1132 .

, MT1132 3,3 , 5 ( 3,3- 5-), — 5 . .

image

La connexion est aussi simple que le module MT1132 - tension d'alimentation, masse et deux contacts RX et TX. Le RTS peut être tiré jusqu'à la tension d'alimentation, mais tout a fonctionné pour moi même sans connecter cette sortie.

Travail


Le module fonctionne via une interface série à une vitesse de 9600. Le module reçoit les commandes du contrôleur et, à son tour, émet les données reçues de l'air (des capteurs et des télécommandes nooLite).

Examinons de plus près ce point, afin que vous compreniez bien le fonctionnement de ce module.

, , «» «» nooLite, . . , nooLite PT112 ( 32, ) ( «» ).

- , ( ) .

Quant aux informations reçues par le module MR1132 des appareils nooLite, il existe un document séparé qui décrit le format de toutes les commandes possibles. Nous, dans le cadre de ce récit, de cette longue liste nous intéresserons aux équipes de capteurs de température, d'humidité et de mouvement. Ces commandes seront décrites en détail ci-dessous, en utilisant l'esquisse comme exemple.

Capteurs


Dans nos expériences, trois capteurs seront utilisés.

image

Capteur de température PT112 et capteur de température et d'humidité PT111. Ils se ressemblent et fonctionnent exactement de la même manière, la différence est que PT112 ne donne que des informations sur la température et PT111 donne des informations sur la température et l'humidité. Ces capteurs peuvent fonctionner soit en mode capteur simple, soit en mode thermostat et hygrostat, mais nous serons intéressés par un mode capteur simple.

image

Le troisième capteur est le PM111. Il s'agit d'un capteur de mouvement qui peut contrôler directement les unités d'alimentation nooLite, mais nous ne nous intéresserons qu'à nous en tant que source d'informations sur les mouvements et la présence de personnes dans la pièce.

Contrôleur



L'Arduino Mega 2560 sera utilisé comme contrôleur de contrôle et ses deux interfaces série - Serial (pour le contrôle visuel des informations) Serial2 (pour la communication avec le module récepteur). Serial1 est réservé au module émetteur MT1132.

image

Esquisse


Dans la section setup (), deux interfaces sont lancées, un message d'information sur le début de l'esquisse s'affiche et une commande est émise pour relier les appareils nooLite sur le canal zéro. Il s'agit d'une commande de test et vous pouvez la commenter ou la remplacer par une autre commande (par exemple, des liaisons sur un autre canal ou un déliement).

void setup() {
  Serial.begin(9600);
  Serial2.begin(9600);
  Serial.println("*** Start sketch ***");
  mrBind(0);
  //mrUnbind(0);
}

, , :

PT112
PT111
PM111

,

mrBind(0);
mrBind(1);
mrBind(2);

. , . .

loop() mrCheck(), «» MR1132 Serial2.

void mrCheck() {
  if (Serial2.available() == 8) {
    mrBuf[0] = Serial2.read();
    mrBuf[1] = Serial2.read();
    mrBuf[2] = Serial2.read();
    mrBuf[3] = Serial2.read();
    if (mrBuf[0] == 79 && mrBuf[1] == 75 && mrBuf[2] == 13 && mrBuf[3] == 10) {
      Serial.println("OK");
    } else {
        mrBuf[4] = Serial2.read();
        mrBuf[5] = Serial2.read();
        mrBuf[6] = Serial2.read();
        mrBuf[7] = Serial2.read();
        mrNewData();
      }
  }
}

Cette fonction remplit le tableau mrBuf [8] avec des données provenant du module ou transmet au message série «OK», émis par le module MR1132. En outre, le contenu du tableau mrBuf [8] est analysé conformément au format de données des commandes du système nooLite, et les fonctions d'esquisse correspondantes y sont impliquées.

La fonction mrNewData () extrait les données principales de la matrice mrBuf [8] et, en fonction de la commande entrante, envoie les informations nécessaires à Serial (canal, commande, température, humidité, état de la batterie du capteur, etc.).

void mrNewData() {
  mrClearData();
  mrPrintHeader();
  
  mrSetBindState();
  mrPrintBindState();
  mrSetChannel();
  mrPrintChannel();

  mrSetCommand();
  mrSetDatas();

  switch (mrCommand) {
    case 0:
      Serial.print("PIR command: ");Serial.println("OFF");
      break;
    case 2:
      Serial.print("PIR command: "); Serial.println("ON");
      break;
    case 21:
      mrSetDeviceType();
      mrPrintDeviceType();
      if (mrDeviceType == 1) {
        mrSetTemperature();
        mrPrintTemperature();
      }
      if (mrDeviceType == 2) {
        mrSetTemperature();
        mrPrintTemperature();
        mrSetHumidity();
        mrPrintHumidity();
      }
      break;
    default: 
      ;
  } // switch
  mrSetBatteryState();
} // newData()

, Print, Serial .

, mrBuf[8], nooLite:

mrSetTogl()
mrSetBindState() — (/)
mrSetReceiveBit()
mrSetChannel()
mrSetCommand()
mrSetFormat()
mrSetDeviceType()
mrSetDatas()
mrSetTemperature()- obtenir la valeur de température
mrSetHumidity () - obtenir la valeur d'humidité
mrSetBrightness () - obtenir la valeur d'éclairage
mrSetBatteryState () - l'état de la batterie du capteur

Vous pouvez voir les détails de la mise en œuvre de ces fonctions dans le code d'esquisse complet ci-dessous.

Voici le croquis complet.

Code d'esquisse complet
// TX2 16
// RX2 17
// TX1 18
// RX1 19

// nooLite MR1132 data
byte mrBuf[8];
int mrTogl = -1;
int mrBindState = -1;
int mrReceiveBit = -1;
int mrChannel = -1;
int mrCommand = -1;
int mrFormat = -1;
int mrData0 = -1;
int mrData1 = -1;
int mrData2 = -1;
int mrData3 = -1;
int mrDeviceType = -1;
int mrBatteryState = -1;
int mrHumidity = -1;
int mrBrightness = -1;
float mrTemp = -1.0;

// nooLite MR1132 bind/unbind

void mrSerialChannel(byte ch) {
switch (ch) {
case 0: Serial.println («0»); break;
case 1: Serial.println («1»); break;
case 2: Serial.println («2»); break;
case 3: Serial.println («3»); break;
case 4: Serial.println («4»); break;
case 5: Serial.println («5»); break;
case 6: Serial.println («6»); break;
case 7: Serial.println («7»); break;
case 8: Serial.println («8»); break;
case 9: Serial.println («9»); break;
case 10: Serial.println(«10»); break;
case 11: Serial.println(«11»); break;
case 12: Serial.println(«12»); break;
case 13: Serial.println(«13»); break;
case 14: Serial.println(«14»); break;
case 15: Serial.println(«15»); break;
case 16: Serial.println(«16»); break;
case 17: Serial.println(«17»); break;
case 18: Serial.println(«18»); break;
case 19: Serial.println(«19»); break;
case 20: Serial.println(«20»); break;
case 21: Serial.println(«21»); break;
case 22: Serial.println(«22»); break;
case 23: Serial.println(«23»); break;
case 24: Serial.println(«24»); break;
case 25: Serial.println(«25»); break;
case 26: Serial.println(«26»); break;
case 27: Serial.println(«27»); break;
case 28: Serial.println(«28»); break;
case 29: Serial.println(«29»); break;
case 30: Serial.println(«30»); break;
case 31: Serial.println(«31»); break;
} // switch
} // mrSerialChannel( )

void mrSerial2Channel(byte ch) {
switch (ch) {
case 0: Serial2.print(«00»); break;
case 1: Serial2.print(«01»); break;
case 2: Serial2.print(«02»); break;
case 3: Serial2.print(«03»); break;
case 4: Serial2.print(«04»); break;
case 5: Serial2.print(«05»); break;
case 6: Serial2.print(«06»); break;
case 7: Serial2.print(«07»); break;
case 8: Serial2.print(«08»); break;
case 9: Serial2.print(«09»); break;
case 10: Serial2.print(«10»); break;
case 11: Serial2.print(«11»); break;
case 12: Serial2.print(«12»); break;
case 13: Serial2.print(«13»); break;
case 14: Serial2.print(«14»); break;
case 15: Serial2.print(«15»); break;
case 16: Serial2.print(«16»); break;
case 17: Serial2.print(«17»); break;
case 18: Serial2.print(«18»); break;
case 19: Serial2.print(«19»); break;
case 20: Serial2.print(«20»); break;
case 21: Serial2.print(«21»); break;
case 22: Serial2.print(«22»); break;
case 23: Serial2.print(«23»); break;
case 24: Serial2.print(«24»); break;
case 25: Serial2.print(«25»); break;
case 26: Serial2.print(«26»); break;
case 27: Serial2.print(«27»); break;
case 28: Serial2.print(«28»); break;
case 29: Serial2.print(«29»); break;
case 30: Serial2.print(«30»); break;
case 31: Serial2.print(«31»); break;
} // switch
} // mrSerial2Channel( )

void mrPrintBind(byte ch) {
Serial.print(«Bind on channel „);
mrSerialChannel(ch);
}

void mrBind(byte ch) {
mrPrintBind(ch);
Serial2.print(“bind_mode_cell_»);
mrSerial2Channel(ch);
Serial2.write(3); // End of Text — B00000011(BIN)
}

void mrPrintUnbind(byte ch) {
Serial.println(«Unbind on channel „);
mrSerialChannel(ch);
}

void mrUnbind(byte ch) {
mrPrintUnbind(ch);
Serial2.print(“clear_one_cell_»);
mrSerial2Channel(ch);
Serial2.write(3);
}

void mrBindStop() {
Serial.println(«Bind mode off»);
Serial2.print(«bind_mode_off»);
Serial2.write(3);
}

void mrClearAll() {
Serial.println(«Clear all cell»);
Serial2.print(«clear_all_cell»);
Serial2.write(3);
}

// nooLite MR1132 print works

void mrPrintHeader() {
Serial.println();
}

void mrPrintDeviceType() {
Serial.print(«Device: „);
if (mrDeviceType == 1) {
Serial.println(“PT112»);
}
if (mrDeviceType == 2) {
Serial.println(«PT111»);
}
}

void mrPrintBindState() {
if (mrBindState == 1) {
Serial.print(«Bind State: „);
Serial.println(“ON»);
}
}

void mrPrintBatteryState() {
if (mrBatteryState == 1) {
Serial.print(«Battery State: „);
Serial.println(“LOW!»);
}
}

void mrPrintChannel() {
Serial.print(«Channel: „);
Serial.println(mrChannel);
}

void mrPrintTemperature() {
Serial.print(“Temp: „);
Serial.println(mrTemp);
}

void mrPrintHumidity() {
Serial.print(“Humidity: „);
Serial.println(mrHumidity);
}

// nooLite MR1132 data works

void mrClearData() {
mrTogl = -1;
mrBindState = -1;
mrReceiveBit = -1;
mrChannel = -1;
mrCommand = -1;
mrFormat = -1;
mrData0 = -1;
mrData1 = -1;
mrData2 = -1;
mrData3 = -1;
mrDeviceType = -1;
mrBatteryState = -1;
mrHumidity = -1;
mrBrightness = -1;
mrTemp = -1.0;
}

void mrSetTogl() {
byte b0 = bitRead(mrBuf[0], 0);
byte b1 = bitRead(mrBuf[0], 1);
byte b2 = bitRead(mrBuf[0], 2);
byte b3 = bitRead(mrBuf[0], 3);
byte b4 = bitRead(mrBuf[0], 4);
byte b5 = bitRead(mrBuf[0], 5);
mrTogl = 32*b5 + 16*b4 + 8*b3 + 4*b2 + 2*b1 + b0;
}

void mrSetBindState() {
mrBindState = bitRead(mrBuf[0], 6);
}

void mrSetReceiveBit() {
mrReceiveBit = bitRead(mrBuf[0], 7);
}

void mrSetChannel() {
mrChannel = mrBuf[1];
}

void mrSetCommand() {
mrCommand = mrBuf[2];
}

void mrSetFormat() {
mrFormat = mrBuf[3];
}

void mrSetDeviceType() {
byte tp1 = bitRead(mrBuf[5], 4);
byte tp2 = bitRead(mrBuf[5], 5);
byte tp3 = bitRead(mrBuf[5], 6);
mrDeviceType = 4*tp3 + 2*tp2 + tp1;
}

void mrSetDatas() {
mrData0 = mrBuf[4];
mrData1 = mrBuf[5];
mrData2 = mrBuf[6];
mrData3 = mrBuf[7];
}

void mrSetTemperature() {
byte t8 = bitRead(mrData1, 0);
byte t9 = bitRead(mrData1, 1);
byte t10= bitRead(mrData1, 2);
int temp2 = 1024*t10 + 512*t9 + 256*t8;

int temp = mrData0 + temp2;

byte t11 = bitRead(mrData1, 3);
if (t11 == 1) {
temp = (4096 — temp) * -1;
}
mrTemp = (float)temp / 10.0;
}

void mrSetBatteryState() {
mrBatteryState = bitRead(mrBuf[5], 7);
}

void mrSetHumidity() {
mrHumidity = mrData2;
}

void mrSetBrightness() {
mrBrightness = mrData3;
}

void mrNewData() {
mrClearData();
mrPrintHeader();

mrSetBindState();
mrPrintBindState();
mrSetChannel();
mrPrintChannel();

mrSetCommand();
mrSetDatas();

switch (mrCommand) {
case 0:
Serial.print(“PIR command: „); Serial.println(“OFF»);
break;
case 2:
Serial.print(«PIR command: „); Serial.println(“ON»);
break;
case 21:
mrSetDeviceType();
mrPrintDeviceType();
if (mrDeviceType == 1) {
mrSetTemperature();
mrPrintTemperature();
}
if (mrDeviceType == 2) {
mrSetTemperature();
mrPrintTemperature();
mrSetHumidity();
mrPrintHumidity();
}
break;
default:
;
} // switch
mrSetBatteryState();
} // newData()

void mrCheck() {
if (Serial2.available() == 8) {
mrBuf[0] = Serial2.read();
mrBuf[1] = Serial2.read();
mrBuf[2] = Serial2.read();
mrBuf[3] = Serial2.read();
if (mrBuf[0] == 79 && mrBuf[1] == 75 && mrBuf[2] == 13 && mrBuf[3] == 10) {
Serial.println(«OK»);
} else {
mrBuf[4] = Serial2.read();
mrBuf[5] = Serial2.read();
mrBuf[6] = Serial2.read();
mrBuf[7] = Serial2.read();
mrNewData();
}
}
}

void setup() {
Serial.begin(9600);
Serial2.begin(9600);
Serial.println("*** Start sketch ***");
mrBind(0);
//mrUnbind(0);
}

void loop() {
mrCheck();
} // loop()


Conclusion


, , , , MR1132 . nooLite .

0.15 Arduino Mega Server MR1132 - .

Source: https://habr.com/ru/post/fr393185/


All Articles