Directory of RSS feeds
Statistics

RSS feeds in the directory: 2818

Added today: 0

Added yesterday: 0

Hi-Tech / Hardware

Weather sensor for smart home Mysensors + Majordomo

Samopal.pro 23.04.2018 at 12:43

Weather station with NRF24L01 works for me for several years. Problems with the sensor. Several times in the rain sensor was no longer transmitting, but then everything was restored. Recently I was able to the indicator. Likely to oxidized contacts. Or posting somewhere disappeared. Still suspended mounting — not the most reliable things in the world. The main drawback of existing solutions is the lack of backend. I would like to be able to put all the data into a single system with the ability to display and use this information for other components of the smart home.

End of the long preamble. Next is an article about the new weather sensor at the base of the module with BME280, NRF24L01 Mysensors library and connected to the Majordomo server.

Technical specifications: Sensor temperature/humidity/pressure BME280 with I2C interface Controller Atmega328 (Atmega168) 8MHz internal resonator Radio module NRF24L01 2/4 GHz with Mysensors Protocol Powered by two AA batteries (Duration of operation from one set of not less than 2 years) Periodicity of sending data is 5 minutes, the Current consumption in sleep mode 11mkA Current consumption in the sending mode 20mA (led however), the duration of sending 200ms concept

the List of components: Atmega328P-PU (in the case DIP28) ~ $1.8 Radio module NRF24L01 ~ $0.85 Module I2C BME280 ~ $3.5 Resistor 1K Resistor 10K Led's any 3mm or 5mm Clock button Holder for two AA batteries ~ $0.35 a PLS Connectors to the Board

total of about $7

PCB

Board designed the program Sprint 6 Layers for the fabrication method of LLT (Laser-laminating technology) in single-sided PCB

the amount of the fee happened 20 x 55 mm

Case

Case designed to print on a 3D printer with the the top part was dull, to protect from falling precipitation. Cover with an access hole for the sensor BME280 bottom. Mount to the wall frame okaili any other vertical surface.

Software Library for Arduino Mysensors. NRF24 driver included in the Library for BME280 from SparkFun. Liked the presence of sleep mode for this sensor

it was Originally planned to power the NRF24 directly from batteries, but for some reason the library function sleep() didn't want to send NRF-ku in sleep mode. Not helped NRF24_PowerDown function()/NRF24_PowerUP().

the Consumption in sleep mode in the area was 1.2-2mA. Apparently the radio is still listened to live, in spite of the passive mode of fashion. Helped switching power NRF-key on a separate leg of the microcontroller. The benefit of mega in abundance. But there was other trouble. Once prescribed in the sketch:

#define MY_RF24_POWER_PIN 8

my sensor sent the first package presentation and the testimony of all of the parameters fell asleep in the sleep () function, but after the spill did not want to work. Debug mode showed the normal operation of the module, but the packets to the receiver did not come. Apparently lost and was not restored any settings of the module.

Helped direct hacking. From the library ripped initialization code NRF-key furnished in a separate function that was called after each awakening

void _ReInit(){

// Save static parent ID in eeprom (used by bootloader)

hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID);

// Initialise the transport layer

transportInitialise();

// Register transport=ready callback

transportRegisterReadyCallback(_callbackTransportReady);

// wait until transport is ready

(void)transportWaitUntilReady(MY_TRANSPORT_WAIT_READY_MS);

}

After that it worked like a clock. The module went into sleep mode with the consumption of 10-11 µa (or rather my device does not merit), then leaving it on a timer, and practiced read cycle parameters and sending a duration of 200 MS, blinking at this time led. Consumption BME280 was within the error of my tester, so to make it power the microcontroller output is not.

the Final sketch turned out so meteocenter:

#include

#include

#include

//temperature Sensor battery powered

// Enable debug prints

//#define MY_DEBUG

//#define DEBUG

// Enable passive mode

#define MY_PASSIVE_NODE

// Passive mode requires static node ID

#define MY_NODE_ID 60

#define MY_RF24_CE_PIN 9

#define MY_RF24_CS_PIN 10

#define MY_RF24_POWER_PIN 8

#define RF24_CHANNEL 76

#define MY_RADIO_NRF24

#include

BME280 bme;

// Define sensor node childs

#define CHILD_ID_VCC 0

#define CHILD_ID_TEMP 1

#define CHILD_ID_HUM 2

#define CHILD_ID_PRESS 3

MyMessage msgVcc(CHILD_ID_VCC, V_VOLTAGE);

MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);

MyMessage msgHum(CHILD_ID_HUM, V_HUM);

MyMessage msgPress(CHILD_ID_PRESS, V_PRESSURE);

// sleep Time between sending packages

#define TM_SLEEP 300000

// Time between restarts (0 if not needed)

#define TM_RESET 43200000

float readVcc();

_ReInit void();

void(* resetFunc) (void) = 0; // Reset MC function

void before(){

// Light a led

pinMode(15,OUTPUT);

digitalWrite(15,HIGH);

}

void presentation() {

// Send the sketch version information to the gateway and Controller

sendSketchInfo("Temp/num/press sensor", "1.0");

present(CHILD_ID_TEMP, S_TEMP,"Temperature,C");

present(CHILD_ID_HUM, S_HUM,"Humidity, %");

present(CHILD_ID_PRESS, S_BARO,"Pressure");

}

void setup(){

#ifdef DEBUG

Serial.begin(115200);

Serial.println("Reading basic values from BME280");

#endif

// Initialize BME280

Wire.begin();

bme.setI2CAddress(0x76); //Connect to a second sensor

if (bme.beginI2C() == false) {

#ifdef DEBUG

Serial.println("The sensor did not respond. Please check wiring.");

#endif

}

// Extinguish the led and go into the main loop

digitalWrite(15,LOW);

// BME280 translate into a low energopotreblenie

bme.setMode(MODE_SLEEP); //Sleep for now

}

void loop(){

digitalWrite(15,HIGH);

float vcc = readVcc();

bme.setMode(MODE_FORCED); //Sleep for now

float t = bme.readTempC();

float h = bme.readFloatHumidity();

float p = bme.readFloatPressure()/133;

float a = bme.readFloatAltitudeMeters();

bme.setMode(MODE_SLEEP); //Sleep for now

#ifdef DEBUG

Serial.print("Humidity: ");

Serial.print(h, 0);

Serial.print(" Pressure: ");

Serial.print(p, 0);

Serial.print(" Alt: ");

Serial.print(a, 1);

Serial.print(" Temp: ");

Serial.print(t, 2);

Serial.print(" Vcc: ");

Serial.print(vcc);

Serial.println();

#endif

_ReInit();

send(msgVcc.set(vcc,2));

send(msgTemp.set(t,1));

send(msgHum.set(h,0));

send(msgPress.set(p,0));

digitalWrite(15,LOW);

sleep( TM_SLEEP );

if( TM_RESET != 0L && millis() > TM_RESET ){

resetFunc();

}

}

/**

* Read supply voltage

*/

float readVcc() {

long result;

// Read 1.1 V reference against AVcc

ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);

delay(2); // Wait for Vref to settle

ADCSRA |= _BV(ADSC); // Convert

while (bit_is_set(ADCSRA,ADSC));

result = ADCL;

result |= ADCHProstie.

you can then use these objects in the panels and scenes interface to Majordomo.

Summarize

using the Mysensors library greatly simplifies the development and use of improvised devices in the smart home system.

by Itself BME280 was very interesting sensor. How to write smart people this sensor is much more progressive than the DHT22 (I'm not talking about DHT11).

In the near future I have planned to develop several devices with NRF24 and Mysensors. In the battery device plan to use the Atmega328/168 in TQFP housings, sensors and NRF24L01 mini powered by CR2032.

the sensor goes on combat duty for the

For those who want to repeat, post the drawings of the printed circuit Board and the housing and the sketch project

The post The Weather sensor for smart home Mysensors + Majordomo appeared first on homemade.pro.