Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. scalpel
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    scalpel

    @scalpel

    7
    Reputation
    13
    Posts
    444
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    scalpel Follow

    Best posts made by scalpel

    • RE: What did you build today (Pictures) ?

      0_1509872915905_1509872882027363077820.jpg 0_1509872936514_1509872919572628002459.jpg

      Just simple, small temperature node.

      posted in General Discussion
      scalpel
      scalpel
    • RE: Standalone atmega328p and nrf24 not working.

      Awrgh! Sorry! Its working! There was small white jumper from previous project connected from VCC to CSN. Thank you for help.
      0_1502792677410_20170815_121950.jpg

      posted in Troubleshooting
      scalpel
      scalpel
    • RE: Combination of gateway and relay code

      I will try tomorrow. Thanks

      posted in Troubleshooting
      scalpel
      scalpel

    Latest posts made by scalpel

    • RE: Combination of gateway and relay code

      Need more tests, but looks like it works. Thanks

      posted in Troubleshooting
      scalpel
      scalpel
    • RE: Combination of gateway and relay code

      I will try tomorrow. Thanks

      posted in Troubleshooting
      scalpel
      scalpel
    • RE: Combination of gateway and relay code

      But if gateway receive some data from sensors, example temperature it stop beeping. Maybe while function should be in loop()?

      look

      2018-04-02 19:54:21.356 User: mietek initiated a switch command (771/Alarm/On) /<<---START BEEPING 👍
      2018-04-02 19:54:21.465 (ArduinoOdbiornik) Lighting 2 (Alarm)
      2018-04-02 19:54:21.588 Error: OTGW: Error received!
      2018-04-02 19:54:34.675 (OpenTherm) Temp (Control Setpoint)
      2018-04-02 19:54:34.682 (OpenTherm) General/Percentage (Maximum Relative Modulation Level)
      2018-04-02 19:54:34.688 (OpenTherm) Thermostat (Zadana ogrzewania)
      2018-04-02 19:54:34.694 (OpenTherm) General/Percentage (Modulacja palnika)
      2018-04-02 19:54:34.700 (OpenTherm) Temp (Isense)
      2018-04-02 19:54:34.708 (OpenTherm) Temp (Boiler Water Temperature)
      2018-04-02 19:54:34.714 (OpenTherm) Temp (DHW Temperature)
      2018-04-02 19:54:34.720 (OpenTherm) Temp (Outside Temperature)
      2018-04-02 19:54:34.725 (OpenTherm) Temp (Return Water Temperature)
      2018-04-02 19:54:34.731 (OpenTherm) Thermostat (DHW Setpoint)
      2018-04-02 19:54:34.735 (OpenTherm) Thermostat (Max_CH Water Setpoint)
      2018-04-02 19:54:51.739 Error: OTGW: Error received!
      2018-04-02 19:55:20.879 Error: OTGW: Error received!
      2018-04-02 19:55:21.434 (rflink) Temp (Zewnątrz)
      2018-04-02 19:55:32.899 (ArduinoOdbiornik) Temp (Parter) // <<--- STOP BEEPING👎

      posted in Troubleshooting
      scalpel
      scalpel
    • Combination of gateway and relay code

      Hi. I am an amateur programmer. I connected the buzzer to the gate and added the alarm functionality. It works but if the gateway gets some data from other sensor, the alarm stops working.

      /**
      * The MySensors Arduino library handles the wireless radio link and protocol
      * between your home built sensors/actuators and HA controller of choice.
      * The sensors forms a self healing radio network with optional repeaters. Each
      * repeater and gateway builds a routing tables in EEPROM which keeps track of the
      * network topology allowing messages to be routed to nodes.
      *
      * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
      * Copyright (C) 2013-2015 Sensnology AB
      * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
      *
      * Documentation: http://www.mysensors.org
      * Support Forum: http://forum.mysensors.org
      *
      * This program is free software; you can redistribute it and/or
      * modify it under the terms of the GNU General Public License
      * version 2 as published by the Free Software Foundation.
      *
      *******************************
      *
      * DESCRIPTION
      * The ArduinoGateway prints data received from sensors on the serial link.
      * The gateway accepts input on seral which will be sent out on radio network.
      *
      * The GW code is designed for Arduino Nano 328p / 16MHz
      *
      * Wire connections (OPTIONAL):
      * - Inclusion button should be connected between digital pin 3 and GND
      * - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
      *
      * LEDs (OPTIONAL):
      * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
      * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
      * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
      * - ERR (red) - fast blink on error during transmission error or recieve crc error
      *
      */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Set LOW transmit power level as default, if you have an amplified NRF-module and
      // power your radio separately with a good regulator you can turn up PA level.
      #define MY_RF24_PA_LEVEL RF24_PA_LOW
      
      // Enable serial gateway
      #define MY_GATEWAY_SERIAL
      
      // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
      #if F_CPU == 8000000L
      #define MY_BAUD_RATE 38400
      #endif
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
      
      // Inverses behavior of inclusion button (if using external pullup)
      //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
      
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Inverses the behavior of leds
      //#define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
      
      #include <MySensors.h>
      
      #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 1 // Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      
      void before()
      {
        
          pinMode(RELAY_1, OUTPUT);
          // Set relay to last known state (using eeprom storage)
          digitalWrite(RELAY_1, LOW);
        
      }
      void setup()
      {
      	// Setup locally attached sensors
       pinMode(A0, OUTPUT);
      }
      
      void presentation()
      {
      	// Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay", "1.0");
        present(1, S_BINARY);
        
      }
      
      void receive(const MyMessage &message)
      {
        // We only expect one type of message from controller. But we better check anyway.
         if (message.type==V_STATUS) {
        
          while (message.getBool() == 1){
          beep();
          }
         
          
          }
       
         
         
          // Write some debug info
          Serial.print("Incoming change for sensor:");
          Serial.print(message.sensor);
          Serial.print(", New status: ");
          Serial.println(message.getBool());
        }
      
      
      void loop()
      {
      	
      }
      
      
      void beep()
      {
          tone(A0, 4200); //Wygeneruj sygnał o częstotliwości 4000Hz na pinie A5  
          wait(100);  
          noTone(A0);
          wait(100);
          tone(A0, 4200); //Wygeneruj sygnał o częstotliwości 4000Hz na pinie A5  
          wait(100);  
          noTone(A0);
          wait(10000);
      
      }```
      posted in Troubleshooting
      scalpel
      scalpel
    • RE: What did you build today (Pictures) ?

      Hardcoded In attiny. Learn arduino irremote library.

      Pozdrawiam / regards

      posted in General Discussion
      scalpel
      scalpel
    • RE: What did you build today (Pictures) ?

      0_1511727705490_15117276954701212117694.jpg

      0_1511727729141_15117277179511389767526.jpg

      I use raspberry for watching television, movies etc. Today I build raspberry hat to turn on from remote control. Attiny85 recognizes programmed remote code and by optocoupler short circuit on pins.

      posted in General Discussion
      scalpel
      scalpel
    • RE: What did you build today (Pictures) ?

      Yes. Iron and B327 method 👍

      posted in General Discussion
      scalpel
      scalpel
    • RE: What did you build today (Pictures) ?

      0_1509872915905_1509872882027363077820.jpg 0_1509872936514_1509872919572628002459.jpg

      Just simple, small temperature node.

      posted in General Discussion
      scalpel
      scalpel
    • RE: BME280 temp/humidity/pressure sensor

      @yoshida said in BME280 temp/humidity/pressure sensor:

      > /**
      >  * The MySensors Arduino library handles the wireless radio link and protocol
      >  * between your home built sensors/actuators and HA controller of choice.
      >  * The sensors forms a self healing radio network with optional repeaters. Each
      >  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
      >  * network topology allowing messages to be routed to nodes.
      >  *
      >  * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
      >  * Copyright (C) 2013-2015 Sensnology AB
      >  * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
      >  *
      >  * Documentation: http://www.mysensors.org
      >  * Support Forum: http://forum.mysensors.org
      >  *
      >  * This program is free software; you can redistribute it and/or
      >  * modify it under the terms of the GNU General Public License
      >  * version 2 as published by the Free Software Foundation.
      >  *
      >  *******************************
      >  *
      >  * REVISION HISTORY
      >  * Version 1.0 - Henrik Ekblad
      >  * 
      >  * DESCRIPTION
      >  * Pressure sensor example using BMP085 module  
      >  * http://www.mysensors.org/build/pressure
      >  *
      >  */
      > 
      > // Enable debug prints to serial monitor
      > #define MY_DEBUG 
      > 
      > // Enable and select radio type attached
      > #define MY_RADIO_NRF24
      > //#define MY_RADIO_RFM69
      > 
      > #include <SPI.h>
      > #include <MySensors.h>  
      > #include <Wire.h>
      > 
      > // BME280 libraries and variables
      > // Bosch BME280 Embedded Adventures MOD-1022 weather multi-sensor Arduino code
      > // Written originally by Embedded Adventures
      > // https://github.com/embeddedadventures/BME280
      > #include <BME280_MOD-1022.h>
      > 
      > #define BARO_CHILD 0
      > #define TEMP_CHILD 1
      > #define HUM_CHILD 2
      > 
      > const float ALTITUDE = 184; // <-- adapt this value to your location's altitude (in m). Use your smartphone GPS to get an accurate value!
      > 
      > // Sleep time between reads (in ms). Do not change this value as the forecast algorithm needs a sample every minute.
      > const unsigned long SLEEP_TIME = 60000; 
      > 
      > const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" };
      > enum FORECAST
      > {
      >   STABLE = 0,     // "Stable Weather Pattern"
      >   SUNNY = 1,      // "Slowly rising Good Weather", "Clear/Sunny "
      >   CLOUDY = 2,     // "Slowly falling L-Pressure ", "Cloudy/Rain "
      >   UNSTABLE = 3,   // "Quickly rising H-Press",     "Not Stable"
      >   THUNDERSTORM = 4, // "Quickly falling L-Press",    "Thunderstorm"
      >   UNKNOWN = 5     // "Unknown (More Time needed)
      > };
      > 
      > float lastPressure = -1;
      > float lastTemp = -1;
      > float lastHum = -1;
      > int lastForecast = -1;
      > 
      > const int LAST_SAMPLES_COUNT = 5;
      > float lastPressureSamples[LAST_SAMPLES_COUNT];
      > 
      > 
      > // this CONVERSION_FACTOR is used to convert from Pa to kPa in the forecast algorithm
      > // get kPa/h by dividing hPa by 10 
      > #define CONVERSION_FACTOR (1.0/10.0)
      > 
      > int minuteCount = 0;
      > bool firstRound = true;
      > // average value is used in forecast algorithm.
      > float pressureAvg;
      > // average after 2 hours is used as reference value for the next iteration.
      > float pressureAvg2;
      > 
      > float dP_dt;
      > boolean metric;
      > MyMessage tempMsg(TEMP_CHILD, V_TEMP);
      > MyMessage humMsg(HUM_CHILD, V_HUM);
      > MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
      > MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
      > 
      > 
      > float getLastPressureSamplesAverage()
      > {
      >   float lastPressureSamplesAverage = 0;
      >   for (int i = 0; i < LAST_SAMPLES_COUNT; i++)
      >   {
      >     lastPressureSamplesAverage += lastPressureSamples[i];
      >   }
      >   lastPressureSamplesAverage /= LAST_SAMPLES_COUNT;
      > 
      >   return lastPressureSamplesAverage;
      > }
      > 
      > 
      > // Algorithm found here
      > // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
      > // Pressure in hPa -->  forecast done by calculating kPa/h
      > int sample(float pressure)
      > {
      >   // Calculate the average of the last n minutes.
      >   int index = minuteCount % LAST_SAMPLES_COUNT;
      >   lastPressureSamples[index] = pressure;
      > 
      >   minuteCount++;
      >   if (minuteCount > 185)
      >   {
      >     minuteCount = 6;
      >   }
      > 
      >   if (minuteCount == 5)
      >   {
      >     pressureAvg = getLastPressureSamplesAverage();
      >   }
      >   else if (minuteCount == 35)
      >   {
      >     float lastPressureAvg = getLastPressureSamplesAverage();
      >     float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      >     if (firstRound) // first time initial 3 hour
      >     {
      >       dP_dt = change * 2; // note this is for t = 0.5hour
      >     }
      >     else
      >     {
      >       dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value.
      >     }
      >   }
      >   else if (minuteCount == 65)
      >   {
      >     float lastPressureAvg = getLastPressureSamplesAverage();
      >     float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      >     if (firstRound) //first time initial 3 hour
      >     {
      >       dP_dt = change; //note this is for t = 1 hour
      >     }
      >     else
      >     {
      >       dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value
      >     }
      >   }
      >   else if (minuteCount == 95)
      >   {
      >     float lastPressureAvg = getLastPressureSamplesAverage();
      >     float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      >     if (firstRound) // first time initial 3 hour
      >     {
      >       dP_dt = change / 1.5; // note this is for t = 1.5 hour
      >     }
      >     else
      >     {
      >       dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value
      >     }
      >   }
      >   else if (minuteCount == 125)
      >   {
      >     float lastPressureAvg = getLastPressureSamplesAverage();
      >     pressureAvg2 = lastPressureAvg; // store for later use.
      >     float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      >     if (firstRound) // first time initial 3 hour
      >     {
      >       dP_dt = change / 2; // note this is for t = 2 hour
      >     }
      >     else
      >     {
      >       dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value
      >     }
      >   }
      >   else if (minuteCount == 155)
      >   {
      >     float lastPressureAvg = getLastPressureSamplesAverage();
      >     float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      >     if (firstRound) // first time initial 3 hour
      >     {
      >       dP_dt = change / 2.5; // note this is for t = 2.5 hour
      >     }
      >     else
      >     {
      >       dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value
      >     }
      >   }
      >   else if (minuteCount == 185)
      >   {
      >     float lastPressureAvg = getLastPressureSamplesAverage();
      >     float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      >     if (firstRound) // first time initial 3 hour
      >     {
      >       dP_dt = change / 3; // note this is for t = 3 hour
      >     }
      >     else
      >     {
      >       dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value
      >     }
      >     pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past.
      >     firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop.
      >   }
      > 
      >   int forecast = UNKNOWN;
      >   if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval.
      >   {
      >     forecast = UNKNOWN;
      >   }
      >   else if (dP_dt < (-0.25))
      >   {
      >     forecast = THUNDERSTORM;
      >   }
      >   else if (dP_dt > 0.25)
      >   {
      >     forecast = UNSTABLE;
      >   }
      >   else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05)))
      >   {
      >     forecast = CLOUDY;
      >   }
      >   else if ((dP_dt > 0.05) && (dP_dt < 0.25))
      >   {
      >     forecast = SUNNY;
      >   }
      >   else if ((dP_dt >(-0.05)) && (dP_dt < 0.05))
      >   {
      >     forecast = STABLE;
      >   }
      >   else
      >   {
      >     forecast = UNKNOWN;
      >   }
      > 
      >   // uncomment when debugging
      >   //Serial.print(F("Forecast at minute "));
      >   //Serial.print(minuteCount);
      >   //Serial.print(F(" dP/dt = "));
      >   //Serial.print(dP_dt);
      >   //Serial.print(F("kPa/h --> "));
      >   //Serial.println(weather[forecast]);
      > 
      >   return forecast;
      > }
      > 
      > 
      > void setup() {
      >   metric = getControllerConfig().isMetric;  // was getConfig().isMetric; before MySensors v2.1.1
      >   Wire.begin(); // Wire.begin(sda, scl)
      > }
      > 
      > void presentation()  {
      >   // Send the sketch version information to the gateway and Controller
      >   sendSketchInfo("BME280 Sensor", "1.6");
      > 
      >   // Register sensors to gw (they will be created as child devices)
      >   present(BARO_CHILD, S_BARO);
      >   present(TEMP_CHILD, S_TEMP);
      >   present(HUM_CHILD, S_HUM);
      > }
      > 
      > // Loop
      > void loop() {
      >   
      >   // need to read the NVM compensation parameters
      >   BME280.readCompensationParams();
      > 
      >   /* After taking the measurement the chip goes back to sleep, use when battery powered.
      >   // Oversampling settings (os1x, os2x, os4x, os8x or os16x).
      >   BME280.writeFilterCoefficient(fc_16);       // IIR Filter coefficient, higher numbers avoid sudden changes to be accounted for (such as slamming a door)
      >   BME280.writeOversamplingPressure(os16x);    // pressure x16
      >   BME280.writeOversamplingTemperature(os8x);  // temperature x8
      >   BME280.writeOversamplingHumidity(os8x);     // humidity x8
      > 
      >   BME280.writeMode(smForced);                 // Forced sample.  After taking the measurement the chip goes back to sleep
      >   */
      > 
      >   // Normal mode for regular automatic samples
      >   BME280.writeStandbyTime(tsb_0p5ms);         // tsb = 0.5ms
      >   BME280.writeFilterCoefficient(fc_16);       // IIR Filter coefficient 16
      >   BME280.writeOversamplingPressure(os16x);    // pressure x16
      >   BME280.writeOversamplingTemperature(os8x);  // temperature x8
      >   BME280.writeOversamplingHumidity(os8x);     // humidity x8
      >   
      >   BME280.writeMode(smNormal);
      >   
      >   while (1) {
      >     // Just to be sure, wait until sensor is done mesuring  
      >     while (BME280.isMeasuring()) {
      >   }
      >   
      >   // Read out the data - must do this before calling the getxxxxx routines
      >   BME280.readMeasurements();
      > 
      >   float temperature = BME280.getTemperatureMostAccurate();                    // must get temp first
      >   float humidity = BME280.getHumidityMostAccurate();
      >   float pressure_local = BME280.getPressureMostAccurate();                    // Get pressure at current location
      >   float pressure = pressure_local/pow((1.0 - ( ALTITUDE / 44330.0 )), 5.255); // Adjust to sea level pressure using user altitude
      >   int forecast = sample(pressure);
      >   
      >   if (!metric) 
      >   {
      >     // Convert to fahrenheit
      >     temperature = temperature * 9.0 / 5.0 + 32.0;
      >   }
      > 
      >   Serial.println();
      >   Serial.print("Temperature = ");
      >   Serial.print(temperature);
      >   Serial.println(metric ? " °C" : " °F");
      >   Serial.print("Humidity = ");
      >   Serial.print(humidity);
      >   Serial.println(" %");
      >   Serial.print("Pressure = ");
      >   Serial.print(pressure);
      >   Serial.println(" hPa");
      >   Serial.print("Forecast = ");
      >   Serial.println(weather[forecast]);
      >   Serial.println();
      > 
      > 
      >   if (temperature != lastTemp) 
      >   {
      >     send(tempMsg.set(temperature, 1));
      >     lastTemp = temperature;
      >   }
      > 
      > 
      >   if (humidity != lastHum) 
      >   {
      >     send(humMsg.set(humidity, 1));
      >     lastHum = humidity;
      >   }
      > 
      >   if (pressure != lastPressure) 
      >   {
      >     send(pressureMsg.set(pressure, 2));
      >     lastPressure = pressure;
      >   }
      > 
      >   if (forecast != lastForecast)
      >   {
      >     send(forecastMsg.set(weather[forecast]));
      >     lastForecast = forecast;
      >   }
      >   
      >   sleep(SLEEP_TIME);
      >   
      > }
      > }
      

      Added to sketch @yoshida battery state send, but its not sending it, please chek it:

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik Ekblad
       * 
       * DESCRIPTION
       * Pressure sensor example using BMP085 module  
       * http://www.mysensors.org/build/pressure
       *
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <SPI.h>
      #include <MySensors.h>  
      #include <Wire.h>
      
      // BME280 libraries and variables
      // Bosch BME280 Embedded Adventures MOD-1022 weather multi-sensor Arduino code
      // Written originally by Embedded Adventures
      // https://github.com/embeddedadventures/BME280
      #include <BME280_MOD-1022.h>
      
      #define BARO_CHILD 0
      #define TEMP_CHILD 1
      #define HUM_CHILD 2
      
      int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
      int oldBatteryPcnt = 0;
      
      const float ALTITUDE = 450; // <-- adapt this value to your location's altitude (in m). Use your smartphone GPS to get an accurate value!
      
      // Sleep time between reads (in ms). Do not change this value as the forecast algorithm needs a sample every minute.
      const unsigned long SLEEP_TIME = 300000; 
      
      const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" };
      enum FORECAST
      {
        STABLE = 0,     // "Stable Weather Pattern"
        SUNNY = 1,      // "Slowly rising Good Weather", "Clear/Sunny "
        CLOUDY = 2,     // "Slowly falling L-Pressure ", "Cloudy/Rain "
        UNSTABLE = 3,   // "Quickly rising H-Press",     "Not Stable"
        THUNDERSTORM = 4, // "Quickly falling L-Press",    "Thunderstorm"
        UNKNOWN = 5     // "Unknown (More Time needed)
      };
      
      float lastPressure = -1;
      float lastTemp = -1;
      float lastHum = -1;
      int lastForecast = -1;
      
      const int LAST_SAMPLES_COUNT = 5;
      float lastPressureSamples[LAST_SAMPLES_COUNT];
      
      
      // this CONVERSION_FACTOR is used to convert from Pa to kPa in the forecast algorithm
      // get kPa/h by dividing hPa by 10 
      #define CONVERSION_FACTOR (1.0/10.0)
      
      int minuteCount = 0;
      bool firstRound = true;
      // average value is used in forecast algorithm.
      float pressureAvg;
      // average after 2 hours is used as reference value for the next iteration.
      float pressureAvg2;
      
      float dP_dt;
      boolean metric;
      MyMessage tempMsg(TEMP_CHILD, V_TEMP);
      MyMessage humMsg(HUM_CHILD, V_HUM);
      MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
      MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
      
      
      float getLastPressureSamplesAverage()
      {
        float lastPressureSamplesAverage = 0;
        for (int i = 0; i < LAST_SAMPLES_COUNT; i++)
        {
          lastPressureSamplesAverage += lastPressureSamples[i];
        }
        lastPressureSamplesAverage /= LAST_SAMPLES_COUNT;
      
        return lastPressureSamplesAverage;
      }
      
      
      // Algorithm found here
      // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
      // Pressure in hPa -->  forecast done by calculating kPa/h
      int sample(float pressure)
      {
        // Calculate the average of the last n minutes.
        int index = minuteCount % LAST_SAMPLES_COUNT;
        lastPressureSamples[index] = pressure;
      
        minuteCount++;
        if (minuteCount > 185)
        {
          minuteCount = 6;
        }
      
        if (minuteCount == 5)
        {
          pressureAvg = getLastPressureSamplesAverage();
        }
        else if (minuteCount == 35)
        {
          float lastPressureAvg = getLastPressureSamplesAverage();
          float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
          if (firstRound) // first time initial 3 hour
          {
            dP_dt = change * 2; // note this is for t = 0.5hour
          }
          else
          {
            dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value.
          }
        }
        else if (minuteCount == 65)
        {
          float lastPressureAvg = getLastPressureSamplesAverage();
          float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
          if (firstRound) //first time initial 3 hour
          {
            dP_dt = change; //note this is for t = 1 hour
          }
          else
          {
            dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value
          }
        }
        else if (minuteCount == 95)
        {
          float lastPressureAvg = getLastPressureSamplesAverage();
          float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
          if (firstRound) // first time initial 3 hour
          {
            dP_dt = change / 1.5; // note this is for t = 1.5 hour
          }
          else
          {
            dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value
          }
        }
        else if (minuteCount == 125)
        {
          float lastPressureAvg = getLastPressureSamplesAverage();
          pressureAvg2 = lastPressureAvg; // store for later use.
          float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
          if (firstRound) // first time initial 3 hour
          {
            dP_dt = change / 2; // note this is for t = 2 hour
          }
          else
          {
            dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value
          }
        }
        else if (minuteCount == 155)
        {
          float lastPressureAvg = getLastPressureSamplesAverage();
          float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
          if (firstRound) // first time initial 3 hour
          {
            dP_dt = change / 2.5; // note this is for t = 2.5 hour
          }
          else
          {
            dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value
          }
        }
        else if (minuteCount == 185)
        {
          float lastPressureAvg = getLastPressureSamplesAverage();
          float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
          if (firstRound) // first time initial 3 hour
          {
            dP_dt = change / 3; // note this is for t = 3 hour
          }
          else
          {
            dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value
          }
          pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past.
          firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop.
        }
      
        int forecast = UNKNOWN;
        if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval.
        {
          forecast = UNKNOWN;
        }
        else if (dP_dt < (-0.25))
        {
          forecast = THUNDERSTORM;
        }
        else if (dP_dt > 0.25)
        {
          forecast = UNSTABLE;
        }
        else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05)))
        {
          forecast = CLOUDY;
        }
        else if ((dP_dt > 0.05) && (dP_dt < 0.25))
        {
          forecast = SUNNY;
        }
        else if ((dP_dt >(-0.05)) && (dP_dt < 0.05))
        {
          forecast = STABLE;
        }
        else
        {
          forecast = UNKNOWN;
        }
      
        // uncomment when debugging
        //Serial.print(F("Forecast at minute "));
        //Serial.print(minuteCount);
        //Serial.print(F(" dP/dt = "));
        //Serial.print(dP_dt);
        //Serial.print(F("kPa/h --> "));
        //Serial.println(weather[forecast]);
      
        return forecast;
      }
      
      
      void setup() {
        metric = getControllerConfig().isMetric;  // was getConfig().isMetric; before MySensors v2.1.1
        Wire.begin(); // Wire.begin(sda, scl)
        // use the 1.1 V internal reference
        #if defined(__AVR_ATmega2560__)
        analogReference(INTERNAL1V1);
        #else
        analogReference(INTERNAL);
        #endif
      }
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("BME280 Sensor", "1.6");
      
        // Register sensors to gw (they will be created as child devices)
        present(BARO_CHILD, S_BARO);
        present(TEMP_CHILD, S_TEMP);
        present(HUM_CHILD, S_HUM);
      }
      
      // Loop
      void loop() {
      
        
        
        // need to read the NVM compensation parameters
        BME280.readCompensationParams();
      
        /* After taking the measurement the chip goes back to sleep, use when battery powered.
        // Oversampling settings (os1x, os2x, os4x, os8x or os16x).
        BME280.writeFilterCoefficient(fc_16);       // IIR Filter coefficient, higher numbers avoid sudden changes to be accounted for (such as slamming a door)
        BME280.writeOversamplingPressure(os16x);    // pressure x16
        BME280.writeOversamplingTemperature(os8x);  // temperature x8
        BME280.writeOversamplingHumidity(os8x);     // humidity x8
      
        BME280.writeMode(smForced);                 // Forced sample.  After taking the measurement the chip goes back to sleep
        */
      
        // Normal mode for regular automatic samples
        BME280.writeStandbyTime(tsb_0p5ms);         // tsb = 0.5ms
        BME280.writeFilterCoefficient(fc_16);       // IIR Filter coefficient 16
        BME280.writeOversamplingPressure(os16x);    // pressure x16
        BME280.writeOversamplingTemperature(os8x);  // temperature x8
        BME280.writeOversamplingHumidity(os8x);     // humidity x8
        
        BME280.writeMode(smNormal);
        
        while (1) {
          // Just to be sure, wait until sensor is done mesuring  
          while (BME280.isMeasuring()) {
        }
        
        // Read out the data - must do this before calling the getxxxxx routines
        BME280.readMeasurements();
      
        float temperature = BME280.getTemperatureMostAccurate();                    // must get temp first
        float humidity = BME280.getHumidityMostAccurate();
        float pressure_local = BME280.getPressureMostAccurate();                    // Get pressure at current location
        float pressure = pressure_local/pow((1.0 - ( ALTITUDE / 44330.0 )), 5.255); // Adjust to sea level pressure using user altitude
        int forecast = sample(pressure);
        
        if (!metric) 
        {
          // Convert to fahrenheit
          temperature = temperature * 9.0 / 5.0 + 32.0;
        }
      
        Serial.println();
        Serial.print("Temperature = ");
        Serial.print(temperature);
        Serial.println(metric ? " °C" : " °F");
        Serial.print("Humidity = ");
        Serial.print(humidity);
        Serial.println(" %");
        Serial.print("Pressure = ");
        Serial.print(pressure);
        Serial.println(" hPa");
        Serial.print("Forecast = ");
        Serial.println(weather[forecast]);
        Serial.println();
      
      
        if (temperature != lastTemp) 
        {
          send(tempMsg.set(temperature, 1));
          lastTemp = temperature;
        }
      
      
        if (humidity != lastHum) 
        {
          send(humMsg.set(humidity, 1));
          lastHum = humidity;
        }
      
        if (pressure != lastPressure) 
        {
          send(pressureMsg.set(pressure, 2));
          lastPressure = pressure;
        }
      
        if (forecast != lastForecast)
        {
          send(forecastMsg.set(weather[forecast]));
          lastForecast = forecast;
        }
      
          int sensorValue = analogRead(BATTERY_SENSE_PIN);
          int batteryPcnt = sensorValue / 10;
          if (oldBatteryPcnt != batteryPcnt) {
          // Power up radio after sleep
          sendBatteryLevel(batteryPcnt);
          oldBatteryPcnt = batteryPcnt;
          }
          
        sleep(SLEEP_TIME);
        
      }
      }
      
      posted in Hardware
      scalpel
      scalpel
    • RE: Standalone atmega328p and nrf24 not working.

      Awrgh! Sorry! Its working! There was small white jumper from previous project connected from VCC to CSN. Thank you for help.
      0_1502792677410_20170815_121950.jpg

      posted in Troubleshooting
      scalpel
      scalpel