|
|
|
|
@ -1,11 +1,11 @@
@@ -1,11 +1,11 @@
|
|
|
|
|
// Sensoren lesen
|
|
|
|
|
|
|
|
|
|
#include <arduino.h> |
|
|
|
|
#include <Arduino.h> |
|
|
|
|
#include "MessenSensoren.h" |
|
|
|
|
#include <Wire.h> |
|
|
|
|
#include "myi2c.h" |
|
|
|
|
#include "myI2C.h" |
|
|
|
|
#include "bme280.h" |
|
|
|
|
#include "bh1750.h" |
|
|
|
|
#include "BH1750.h" |
|
|
|
|
#include "hseSensorProtocol.h" |
|
|
|
|
|
|
|
|
|
#define I2C_POWER 5 // bei Feather M0
|
|
|
|
|
@ -15,126 +15,113 @@
@@ -15,126 +15,113 @@
|
|
|
|
|
HseSP hse(2, 60); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void init_Messen(void) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
void init_Messen() { |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
Serial.println("PowerOn I2C"); |
|
|
|
|
Serial.println("PowerOn I2C"); |
|
|
|
|
// I2C Power einschalten LoRa Transponder
|
|
|
|
|
pinMode(I2C_POWER,OUTPUT); |
|
|
|
|
digitalWrite(I2C_POWER, HIGH); |
|
|
|
|
delay(20); |
|
|
|
|
pinMode(I2C_POWER, OUTPUT); |
|
|
|
|
digitalWrite(I2C_POWER, HIGH); |
|
|
|
|
delay(20); |
|
|
|
|
|
|
|
|
|
Wire.begin(); |
|
|
|
|
Wire.begin(); |
|
|
|
|
|
|
|
|
|
// Hardware detection, liste was angeschlossen ist
|
|
|
|
|
Serial.println("I2C Hardware detection"); |
|
|
|
|
|
|
|
|
|
if ( I2C_Test(BME280_ADR) != 0xFF ) |
|
|
|
|
{ |
|
|
|
|
Set_I2C_Adresse(BME280_ADR); |
|
|
|
|
i = I2C_read8(BME280_REGISTER_CHIPID); |
|
|
|
|
Serial1.print(F("BMx280 Chip ID = 0x")); |
|
|
|
|
Serial1.print(i,HEX); |
|
|
|
|
if ( i== 0x58) Serial1.println(F(" = BMP280")); |
|
|
|
|
if ( i== 0x60) Serial1.println(F(" = BME280")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( I2C_Test(0x77) != 0xFF ) |
|
|
|
|
{ |
|
|
|
|
Serial.println("BMP180 gefunden"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( I2C_Test(0x38) != 0xFF ) |
|
|
|
|
{ |
|
|
|
|
Serial.println(F("AHT10 gefunden")); |
|
|
|
|
} |
|
|
|
|
Serial.println("I2C Hardware detection"); |
|
|
|
|
|
|
|
|
|
if (I2C_Test(BME280_ADR) != 0xFF) { |
|
|
|
|
Set_I2C_Adresse(BME280_ADR); |
|
|
|
|
i = I2C_read8(BME280_REGISTER_CHIPID); |
|
|
|
|
Serial1.print(F("BMx280 Chip ID = 0x")); |
|
|
|
|
Serial1.print(i, HEX); |
|
|
|
|
if (i == 0x58) Serial1.println(F(" = BMP280")); |
|
|
|
|
if (i == 0x60) Serial1.println(F(" = BME280")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (I2C_Test(0x77) != 0xFF) { |
|
|
|
|
Serial.println("BMP180 gefunden"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (I2C_Test(0x38) != 0xFF) { |
|
|
|
|
Serial.println(F("AHT10 gefunden")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// such BH1730
|
|
|
|
|
if ( I2C_Test(0x29) != 0xFF ) |
|
|
|
|
{ |
|
|
|
|
Serial.println("BH1730 gefunden"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (I2C_Test(0x29) != 0xFF) { |
|
|
|
|
Serial.println("BH1730 gefunden"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// such BH1750
|
|
|
|
|
if ( I2C_Test(0x23) != 0xFF ) |
|
|
|
|
{ |
|
|
|
|
Serial.println("BH1750 gefunden"); |
|
|
|
|
BH1750_Init(); |
|
|
|
|
} |
|
|
|
|
Serial.println("ende"); |
|
|
|
|
if (I2C_Test(0x23) != 0xFF) { |
|
|
|
|
Serial.println("BH1750 gefunden"); |
|
|
|
|
BH1750_Init(); |
|
|
|
|
} |
|
|
|
|
Serial.println("ende"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
|
void MessenSensoren(void) |
|
|
|
|
{ |
|
|
|
|
int i,status, error; |
|
|
|
|
float t,p,h; |
|
|
|
|
long lVisLux; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set_I2C_Adresse(BME280_ADR); |
|
|
|
|
i = I2C_read8(BME280_REGISTER_CHIPID); |
|
|
|
|
|
|
|
|
|
bme280_readCoefficients(); |
|
|
|
|
|
|
|
|
|
if ( i== 0x58) |
|
|
|
|
{ |
|
|
|
|
I2C_write8(BME280_REGISTER_CONTROL, 0x3F); |
|
|
|
|
delay(50); // gib ihm Zeit zum messen
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( i== 0x60) |
|
|
|
|
{ |
|
|
|
|
//Set before CONTROL_meas (DS 5.4.3)
|
|
|
|
|
I2C_write8(BME280_REGISTER_CONTROLHUMID, 0x05); //16x oversampling
|
|
|
|
|
I2C_write8(BME280_REGISTER_CONTROL, 0xB7); // 16x ovesampling, normal mode
|
|
|
|
|
delay(100); // gib ihm Zeit zum messen
|
|
|
|
|
} |
|
|
|
|
void MessenSensoren() { |
|
|
|
|
int i; |
|
|
|
|
float t, p, h; |
|
|
|
|
unsigned int lVisLux; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set_I2C_Adresse(BME280_ADR); |
|
|
|
|
i = I2C_read8(BME280_REGISTER_CHIPID); |
|
|
|
|
|
|
|
|
|
bme280_readCoefficients(); |
|
|
|
|
|
|
|
|
|
if (i == 0x58) { |
|
|
|
|
I2C_write8(BME280_REGISTER_CONTROL, 0x3F); |
|
|
|
|
delay(50); // gib ihm Zeit zum messen
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (i == 0x60) { |
|
|
|
|
//Set before CONTROL_meas (DS 5.4.3)
|
|
|
|
|
I2C_write8(BME280_REGISTER_CONTROLHUMID, 0x05); //16x oversampling
|
|
|
|
|
I2C_write8(BME280_REGISTER_CONTROL, 0xB7); // 16x ovesampling, normal mode
|
|
|
|
|
delay(100); // gib ihm Zeit zum messen
|
|
|
|
|
} |
|
|
|
|
// 35ms reicht beim BMP280
|
|
|
|
|
// 75ms warten bis BME280 den Druck gemessen hat
|
|
|
|
|
|
|
|
|
|
//----------------
|
|
|
|
|
t = bme280_readTemperature(); |
|
|
|
|
p = bme280_readPressure()/100.0; |
|
|
|
|
h = bme280_readHumidity(); |
|
|
|
|
I2C_write8(BME280_REGISTER_CONTROL, 0x3C); // Sleep Mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// such BH1750
|
|
|
|
|
if ( I2C_Test(0x23) != 0xFF ) |
|
|
|
|
{ |
|
|
|
|
// BH1750 = HY30 Licht Sensor
|
|
|
|
|
BH1750_Init(); |
|
|
|
|
lVisLux = BH1750_ReadLux(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( lVisLux > 65535) lVisLux = 654321; |
|
|
|
|
t = bme280_readTemperature(); |
|
|
|
|
p = bme280_readPressure() / 100.0f; |
|
|
|
|
h = bme280_readHumidity(); |
|
|
|
|
I2C_write8(BME280_REGISTER_CONTROL, 0x3C); // Sleep Mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print(F("Temp = ")); |
|
|
|
|
Serial.println(t); |
|
|
|
|
Serial.print(F("Druck = ")); |
|
|
|
|
Serial.println(p); |
|
|
|
|
Serial.print(F("Feuchte = ")); |
|
|
|
|
Serial.println(h); |
|
|
|
|
// such BH1750
|
|
|
|
|
if (I2C_Test(0x23) != 0xFF) { |
|
|
|
|
// BH1750 = HY30 Licht Sensor
|
|
|
|
|
BH1750_Init(); |
|
|
|
|
lVisLux = BH1750_ReadLux(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Serial.print(F("Vis = ")); |
|
|
|
|
Serial.println(lVisLux); |
|
|
|
|
if (lVisLux > 65535) lVisLux = 654321; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hse.reset(); |
|
|
|
|
//Ein Klimasensor hinzufügen
|
|
|
|
|
HseSP::ClimateSensor_t cs; |
|
|
|
|
cs.Temperature = t; //°C
|
|
|
|
|
cs.Humidity = h; //%
|
|
|
|
|
cs.Pressure = p; //hPa
|
|
|
|
|
cs.Illuminance = lVisLux; //lux
|
|
|
|
|
hse.addClimateSensor(&cs); |
|
|
|
|
Serial.print(F("Temp = ")); |
|
|
|
|
Serial.println(t); |
|
|
|
|
Serial.print(F("Druck = ")); |
|
|
|
|
Serial.println(p); |
|
|
|
|
Serial.print(F("Feuchte = ")); |
|
|
|
|
Serial.println(h); |
|
|
|
|
|
|
|
|
|
// hse.addVoltage(fUb/1000.0); // in Volt
|
|
|
|
|
// hse.addCounter(uiOnStd); // Zeit On
|
|
|
|
|
Serial.print(F("Vis = ")); |
|
|
|
|
Serial.println(lVisLux); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hse.reset(); |
|
|
|
|
//Ein Klimasensor hinzufügen
|
|
|
|
|
HseSP::ClimateSensor_t cs; |
|
|
|
|
cs.Temperature = t; //°C
|
|
|
|
|
cs.Humidity = h; //%
|
|
|
|
|
cs.Pressure = p; //hPa
|
|
|
|
|
cs.Illuminance = lVisLux; //lux
|
|
|
|
|
hse.addClimateSensor(&cs); |
|
|
|
|
|
|
|
|
|
// hse.addVoltage(fUb/1000.0); // in Volt
|
|
|
|
|
// hse.addCounter(uiOnStd); // Zeit On
|
|
|
|
|
} |
|
|
|
|
|