Z-Uno +BME280

Данный раздел предназначен для русскоязычных пользователей. Если вы владеете английским, рекомендуем также просмотреть общую ветку обсуждений на английском.
Post Reply
Clie
Posts: 11
Joined: 06 Jun 2017 12:58

Z-Uno +BME280

Post by Clie »

Всем привет.
Хочу попользовать девайс + HC2 для мониторинга домашней теплицы.
Сегодня пытался подружить Z-Uno с BME280, но что-то пошло не так :(
Вот скетч:

Code: Select all

#include "Wire.h"
#include "ZUNO_BMP280.h"

#define Switch1 11
#define Switch2 12

byte CurrentSwitchValue1;
byte CurrentSwitchValue2;
int humidity;      // here we will store the humidity
int temperature;   // here we will store the temperature
int pressure;   // here we will store the pressure
ZUNO_BMP280 bmp;

ZUNO_SETUP_CHANNELS(
  ZUNO_SWITCH_BINARY(getter1, setter1),
  ZUNO_SWITCH_BINARY(getter2, setter2),
  ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(getterTemperature),
  ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterHumidity),
  ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterPressure)
  );


void setup() {
  pinMode(Switch1, OUTPUT); 
  pinMode(Switch2, OUTPUT);
  bmp.begin();
  Serial.begin(9600);
  if (!bmp.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
}
  
void loop() {
  delay(1000);

  humidity = bmp.readHumidityH10()/10;
  temperature = bmp.readTemperature();
  pressure = bmp.readPressureHgMM10()/10;
  
  Serial.print("Temperature ");
  Serial.print(temperature);
  Serial.println(" *C");
    
  Serial.print("Pressure ");
  Serial.print(pressure);
  Serial.println(" mm");

  Serial.print("Humidity ");
  Serial.print(humidity);
  Serial.println(" %");

  delay(10000);
}

byte getterTemperature() {
  return temperature;
}

byte getterHumidity() {
  return humidity;
}

byte getterPressure() {
  return pressure;
}


void setter1(byte value) {
  digitalWrite(Switch1, (value > 0) ? LOW : HIGH);
  CurrentSwitchValue1 = value; }
byte getter1(){return CurrentSwitchValue1;}


void setter2(byte value) {
  digitalWrite(Switch2, (value > 0) ? LOW : HIGH);
  CurrentSwitchValue2 = value;}

byte getter2(){return CurrentSwitchValue2;}

HC2 не видит BME совсем :(
BME280.JPG
BME280.JPG (42.89 KiB) Viewed 5726 times
На сериал вроде ок
BMe280-2.JPG
BMe280-2.JPG (19.99 KiB) Viewed 5726 times

Что я делаю не так?
Спасибо за помощь.

Clie
Posts: 11
Joined: 06 Jun 2017 12:58

Re: Z-Uno +BME280

Post by Clie »

Нашел косяк в Definitions
определил давление - влажностью
попробовал поменять на
ZUNO_SENSOR_MULTILEVEL_ATMOSPHERIC_PRESSURE
не компилится :(
Поменял на :
ZUNO_SENSOR_MULTILEVEL_BAROMETRIC_PRESSURE

несколько раз пробовал исключить- добавить
В HC2 не работает :(
отображает температуру при добавлении в HC2 - больше не обновляется
давление и влажность не отображает
беда :(

p0lyg0n1
Posts: 181
Joined: 04 Aug 2016 07:14

Re: Z-Uno +BME280

Post by p0lyg0n1 »

Здравствуйте!
Ну во 1-ых при обновлении данных необходимо отправить Report на контроллер, чтобы тот узнал новое значение.
zunoSendReport(номер_канала);
См. справку https://z-uno.z-wave.me/Reference/zunoSendReport/
в Вашем случае это 3,4,5 каналы:
добавьте перед delay(10000) в loop код:

Code: Select all

       // ...
	zunoSendReport(3); 
	zunoSendReport(4); 
	zunoSendReport(5); 
	
	// ... 
	delay(10000);
Напишите, получилось ли у Вас. Мы можем попробовать на нашем HC2, но в целом скетч выглядит правильным, кроме того, что он не отправляет значения на контроллер.

С уважением,
Александр.

4709700
Posts: 3
Joined: 27 Sep 2019 10:13

Re: Z-Uno +BME280

Post by 4709700 »

Доброго! Получилось ли подружить BME280 ?

User avatar
10der
Posts: 80
Joined: 08 Jul 2016 00:23
Location: Ukraine - Berkeley, CA

Re: Z-Uno +BME280

Post by 10der »

Clie wrote:
23 Nov 2019 23:30


несколько раз пробовал исключить- добавить
В HC2 не работает :(
Untitled.png
Untitled.png (30.5 KiB) Viewed 4396 times

Code: Select all

#include "Wire.h"
#include <ZUNO_BMP280.h>
#include "ZUNO_BH1750.h"

// C:\Users\olegd\AppData\Roaming\Arduino15\packages\Z-Uno\hardware\zw8051\

#define DEBUG

ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);
#ifdef DEBUG
ZUNO_SETUP_DEBUG_MODE(DEBUG_ON);
#endif

ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(getterTemp)                                   //1

  , ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_RELATIVE_HUMIDITY,
                           SENSOR_MULTILEVEL_SCALE_PERCENTAGE_VALUE,
                           SENSOR_MULTILEVEL_SIZE_ONE_BYTE,
                           SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS,
                           getterHum)                                               //2

  , ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_LUMINANCE,
                           SENSOR_MULTILEVEL_SCALE_LUX,
                           SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
                           SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS,
                           getterLum)                                               //3

  , ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_BAROMETRIC_PRESSURE,
                           SENSOR_MULTILEVEL_SCALE_KILO_PASCAL,
                           SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
                           SENSOR_MULTILEVEL_PRECISION_ONE_DECIMAL, getterPressure)   //4

  , ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_MOTION, getterMotion)                //5

  , ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1)                                //6
  , ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2)                                //7

);

#define ZUNO_CHANNEL_TEMP         1
#define ZUNO_CHANNEL_HUM          2
#define ZUNO_CHANNEL_LUM          3
#define ZUNO_CHANNEL_PRESSURE     4
#define ZUNO_CHANNEL_MOTION       5

#define ZUNO_CHANNEL_SWITCH_1     6
#define ZUNO_CHANNEL_SWITCH_2     7

#define ZUNO_CHANNEL_RESERVED_2   8
#define ZUNO_CHANNEL_RESERVED_3   9
#define ZUNO_CHANNEL_RESERVED_4   10

// BH1750 address on the bus: BH1750_I2CADDR_L = 0x23
#define BH1750_I2CADDR  BH1750_I2CADDR_L

#define MAX_RELAYS 2
struct RelayState_s
{
  BYTE  pin;
  BYTE  state;
};

// 9 & 10 PINS used as I2C

#define MOTION_PIN    22

// LED pin number
#define LED_PIN       13

#define SWITCH1_PIN   19
#define SWITCH2_PIN   20

#define SWITCH_ON 0xff
#define SWITCH_OFF 0

// timer values
#define T_REPORT      30000

ZUNO_BMP280 bmp280;
BH1750 bh1750;

// Global variables to store data reported via getters
unsigned long WaitMillis_tReport;

word relaxMotion = 0;
word lastLumiValue = 0;
byte lastTemperatureValue = 0;
byte lastHumValue = 0;
int lastPressureValue = 0;
// variable to store current motion state
byte lastMotionValue = 0;

// Arduino Digital I/O pin numbers for ZUNO
RelayState_s relays[] = {
  {SWITCH1_PIN, 0},
  {SWITCH2_PIN, 0},
};

boolean InitDone = false;

void myInit() {
  // initial setup for timer values
  WaitMillis_tReport      = millis() + 5000;
}

//------------------------------------------

void setup() {

#ifdef DEBUG
  Serial.begin(9600);
  Serial.println("start");
#endif

  pinMode(LED_PIN, OUTPUT);     // set LED pin as output
  pinMode(MOTION_PIN, INPUT);   // set motion pin as input

  for (int i = 0; i < MAX_RELAYS; ++i) {
    pinMode(relays[i].pin, OUTPUT);
    digitalWrite(relays[i].pin, HIGH);
#ifdef DEBUG
    Serial.print(i + 1);
    Serial.print(" PIN: ");
    Serial.print(relays[i].pin);
    Serial.println(" should be OFF");
#endif
  }

  bmp280.begin(0x76);
  bh1750.begin(BH1750_CONTINUOUS_HIGH_RES_MODE, BH1750_I2CADDR);
}

void loop() {

  if (InitDone != true) {
    myInit();
    InitDone = true;
  }

  byte currentMotionValue;
  word currentLumiValue;

  int16_t currentTemperatureValue;
  int16_t currentHumValue;
  int32_t currentPressureValue;

  // ------------- Trigger motion and wait for relax (about 5 sec) before report idle --------------------

  currentMotionValue = digitalRead(MOTION_PIN);
  if (currentMotionValue != lastMotionValue) { // if motion state changes
    lastMotionValue = currentMotionValue; // save new state
    zunoSendReport(ZUNO_CHANNEL_MOTION); // send report over the Z-Wave to the controller
    if (currentMotionValue == HIGH) {     // is there is motion
#ifdef DEBUG
      Serial.println("Motion detected");  // send message over USB
      //digitalWrite(LED_PIN, HIGH);        // turn LED on
#endif
    } else {                              // if motion ended
#ifdef DEBUG
      Serial.println("Motion stopped");   // send message over USB
      //digitalWrite(LED_PIN, LOW);         // turn LED off
#endif
    }
  }

  // ---------------------   update values and send out reports  ----------------
  if ( (long)( millis() - WaitMillis_tReport ) >= 0) {
    // Loop for reports with timer every T_REPORTS

    currentTemperatureValue = bmp280.readTemperatureC100() / 100;
    currentHumValue = bmp280.readHumidityH10() / 10;
    currentPressureValue = bmp280.readPressurePa() / 100;
    currentLumiValue = bh1750.readLightLevel(BH1750_I2CADDR);

    //------------------------ Read temperature value --------------------------------
    if ((currentTemperatureValue > (lastTemperatureValue + 0)) || (currentTemperatureValue < (lastTemperatureValue - 0))) {
      lastTemperatureValue = currentTemperatureValue;
      zunoSendReport(ZUNO_CHANNEL_TEMP);        // report the temperature
    }
    //------------------------ Read humidity value --------------------------------
    if ((currentHumValue > (lastHumValue + 0)) || (currentHumValue < (lastHumValue - 0))) {
      if (currentHumValue != 0) {
        lastHumValue = currentHumValue;
      }
      zunoSendReport(ZUNO_CHANNEL_HUM);         // report the relative humidity
    }
    //------------------------ Read pressure value --------------------------------
    if ((currentPressureValue > (lastPressureValue + 0)) || (currentPressureValue < (lastPressureValue - 0))) {
      lastPressureValue = currentPressureValue;
      zunoSendReport(ZUNO_CHANNEL_PRESSURE);        // report the pressure
    }
    //------------------------ Read light level Luminosity --------------------------------
    if ((currentLumiValue > (lastLumiValue + 5)) || (currentLumiValue < (lastLumiValue - 5))) {
      lastLumiValue = currentLumiValue;
      zunoSendReport(ZUNO_CHANNEL_LUM);         // report the luminance
    }

#ifdef DEBUG
    Serial.print("Temperature:");
    //Serial.fixPrint(currentTemperatureValue, 2);
    Serial.print(currentTemperatureValue);
    Serial.println(" *C");

    Serial.print("Pressure:");
    //Serial.fixPrint(currentPressureValue, 1);
    Serial.print(currentPressureValue);
    Serial.println(" hPa");

    Serial.print("Humidity:");
    //Serial.fixPrint(currentHumValue, 1);
    Serial.print(currentHumValue);
    Serial.println(" %");

    Serial.print("Light: ");
    Serial.print(currentLumiValue);
    Serial.println(" Luх");
#endif

    //------------------------ DONE --------------------------------
    WaitMillis_tReport += T_REPORT;  // set next timer value
  }
  delay(200);  // wait at least 200 ms
}
//====================================================================================================================

byte getterMotion() {
  if (lastMotionValue == 1) {    // if motion is detected
    return 0xff;                 // return "Triggered" state to the controller
  } else {                       // if motion stopped
    return 0;                    // return "Idle" state to the controller
  }
}

byte  getterTemp() {
  return lastTemperatureValue;
}

word  getterLum() {
  return lastLumiValue;
}

byte  getterHum() {
  return lastHumValue;
}

int32_t getterPressure() {
  return lastPressureValue;
}

// ------------- Switches -------------------
void setterSwitch1(byte value) {
#ifdef DEBUG
  Serial.print("Switch1: ");
  Serial.println(value);
#endif
  digitalWrite(relays[0].pin, (value > 0) ? LOW : HIGH );
  relays[0].state = value;
}

byte  getterSwitch1() {
#ifdef DEBUG
  Serial.print("+Switch1: ");
  Serial.println(relays[0].state);
#endif
  return relays[0].state;
}

void setterSwitch2(byte value) {
#ifdef DEBUG
  Serial.print("Switch2: ");
  Serial.println(value);
#endif
  digitalWrite(relays[1].pin, (value > 0) ? LOW : HIGH );
  relays[1].state = value;
}

byte  getterSwitch2() {
#ifdef DEBUG
  Serial.print("+Switch2: ");
  Serial.println(relays[1].state);
#endif
  return relays[1].state;
}

//---------------------------------------------------------


Post Reply