Navigation

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

    Posts made by ghislain

    • RE: Can't detect Interrupt on Arduino Mini Pro or can't wake MySensor ?

      This is my change and it is working, thank you for your help.

      /**
       * 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
       *
       * Simple binary switch example 
       * Connect button or door/window reed switch between 
       * digitial I/O pin 3 (BUTTON_PIN below) and GND.
       * http://www.mysensors.org/build/binary
       */
      
      
      // Enable debug prints to serial monitor
      //#define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      #define MY_RF24_PA_LEVEL RF24_PA_LOW
      #define MY_NODE_ID 8
      
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <Vcc.h>
      
      
      #define CHILD_ID_MAIL 0
      #define CHILD_ID_MAIL2 1
      #define CHILD_ID_VOLT 2                  // Child id for battery reading
      
      #define BUTTON_PIN 2  // Arduino Digital I/O pin for button/reed switch
      #define BUTTON2_PIN 3  // Arduino Digital I/O pin for button/reed switch
      #define SLEEP_TIME 1 * 60 * 1000UL
      
      
      
      int oldValueC1=-1;
      int oldValueC2=-1;
      boolean gwSend = true;
      
      const float VccMin   = 3;           // Minimum expected Vcc level, in Volts.
      const float VccMax   = 4;           // Maximum expected Vcc level, in Volts.
      const float VccCorrection = 1.0/1.0;  // Measured Vcc by multimeter divided by reported Vcc
      float batteryV = 0;
      int batteryPcnt = 0;
      Vcc vcc(VccCorrection);
      
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msgMail(CHILD_ID_MAIL,V_TRIPPED);
      MyMessage msgMail2(CHILD_ID_MAIL2,V_TRIPPED);
      MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);
      
      void setup()  
      {  
        // Setup the button
        pinMode(BUTTON_PIN, INPUT);
        pinMode(BUTTON2_PIN, INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN,HIGH);
        digitalWrite(BUTTON2_PIN,HIGH);
      
      
          #ifdef MY_DEBUG
            Serial.begin(115200);
          #endif    
        
       }
      
      void presentation() {
        // Register binary input sensor to gw (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        sendSketchInfo("BAL", "1.0");
        present(CHILD_ID_MAIL, S_DOOR);
        present(CHILD_ID_MAIL2, S_DOOR); 
        present(CHILD_ID_VOLT, S_MULTIMETER);
      }
      
      
      //  Check if digital input has changed and send in new value
      void loop() 
      {
        wait(100);
        // Get the update value
      uint8_t  volet = digitalRead(BUTTON_PIN);
      uint8_t  porte = digitalRead(BUTTON2_PIN);
        
        #ifdef MY_DEBUG
              Serial.println(volet);
              Serial.println(porte);
           #endif   
       
        if (volet != oldValueC1) {
           // Send in the new value
            gwSend = true;
      
           #ifdef MY_DEBUG
              Serial.println(volet);
           #endif   
           
           oldValueC1 = volet;
        }
      
          if (porte != oldValueC2) {
           // Send in the new value
            gwSend = true;
      
           #ifdef MY_DEBUG
              Serial.println(porte);
           #endif   
           
           oldValueC2 = porte;
        }  
          
          batteryV  = vcc.Read_Volts();
          batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
          send(msgVolt.set(batteryV, 2));
          sendBatteryLevel(batteryPcnt);
      
           #ifdef MY_DEBUG
              //delay(2000);
              Serial.println(batteryPcnt);
           #endif    
           
         
      
         if (gwSend == true) {
          
           send(msgMail.set(volet==LOW ? 1 : 0));
           send(msgMail2.set(porte==LOW ? 1 : 0));
           send(msgVolt.set(batteryV, 2));
           sendBatteryLevel(batteryPcnt);
           gwSend = false;
         }
        else {
        }
      
      sleep(0, FALLING, 1, FALLING, SLEEP_TIME);
      } 
      
      posted in Troubleshooting
      ghislain
      ghislain
    • RE: Can't detect Interrupt on Arduino Mini Pro or can't wake MySensor ?

      Thank you both for your answer.

      To resume what i want to do, i want to watch when mail is arrived in my outdoor mailbox, i will do that with 2 "door sensor".

      @Nca78 if i well understood that you say, interrupt was catched and wake up arduino but value1 (the status of the "door sensor") wasn't updated and so my code doesn't do anything and it fall asleep again. Is that correct ?

      I know, i just have one interrupt else i'm using 2, but it was for test with one firstly.

      I will try to do in another way as you say.

      thanks

      posted in Troubleshooting
      ghislain
      ghislain
    • Can't detect Interrupt on Arduino Mini Pro or can't wake MySensor ?

      Hi everybody,

      I spent several time trying to detect interrupt on arduino mini pro 3.3v 8mhz with Atmega328 with button but without success. I tryed to downgrade compiler in 1.6.9 but it doesn't work neither.
      If i remove sleep function it's working, but i need sleep because it a battery node for the mailbox...

      Each time i press the button, i can read that in the log in the serial monitor :

      2369 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
      2375 MCO:SLP:TPD
      2377 MCO:SLP:WUP=0
      2379 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
      2383 MCO:SLP:TPD
      2385 MCO:SLP:WUP=0
      2387 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
      2394 MCO:SLP:TPD
      

      But nothing else.

      Could someone helping me ?

      Thx,
      Ghislain

      This is my code :

      /**
       * 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
       *
       * Simple binary switch example 
       * Connect button or door/window reed switch between 
       * digitial I/O pin 3 (BUTTON_PIN below) and GND.
       * http://www.mysensors.org/build/binary
       */
      
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      #define MY_RF24_PA_LEVEL RF24_PA_LOW
      #define MY_NODE_ID 8
      
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      #include <Vcc.h>
      
      
      #define CHILD_ID_MAIL 0
      #define CHILD_ID_MAIL2 1
      #define CHILD_ID_VOLT 2                  // Child id for battery reading
      
      #define BUTTON_PIN 2  // Arduino Digital I/O pin for button/reed switch
      #define BUTTON2_PIN 3  // Arduino Digital I/O pin for button/reed switch
      #define SLEEP_TIME 1 * 60 * 1000UL
      
      
      // Variables' declaration
      const static uint32_t COUNTER = 60;  // en secondes
      unsigned long sendTime = 0; 
      unsigned long time = 0;
      Bounce debouncer = Bounce(); 
      Bounce debouncer2 = Bounce(); 
      int oldValueC1=-1;
      int oldValueC2=-1;
      boolean gwSend = true;
      
      const float VccMin   = 3;           // Minimum expected Vcc level, in Volts.
      const float VccMax   = 4;           // Maximum expected Vcc level, in Volts.
      const float VccCorrection = 1.0/1.0;  // Measured Vcc by multimeter divided by reported Vcc
      float batteryV = 0;
      int batteryPcnt = 0;
      Vcc vcc(VccCorrection);
      
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msgMail(CHILD_ID_MAIL,V_TRIPPED);
      MyMessage msgMail2(CHILD_ID_MAIL2,V_TRIPPED);
      MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);
      
      void setup()  
      {  
        // Setup the button
        pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
        pinMode(BUTTON2_PIN, INPUT_PULLUP);
        // Activate internal pull-up
        //digitalWrite(BUTTON_PIN,HIGH);
        //digitalWrite(BUTTON2_PIN,HIGH);
      
        // After setting up the button, setup debouncer
        debouncer.attach(DIGITAL_INPUT_SENSOR);
        debouncer2.attach(BUTTON2_PIN);
        debouncer.interval(5);
        debouncer2.interval(5);
      
          #ifdef MY_DEBUG
            Serial.begin(115200);
          #endif    
        
        batteryV  = vcc.Read_Volts();
        batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
      
      }
      
      void presentation() {
        // Register binary input sensor to gw (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        sendSketchInfo("BAL", "1.0");
        present(CHILD_ID_MAIL, S_DOOR);
        present(CHILD_ID_MAIL2, S_DOOR); 
        present(CHILD_ID_VOLT, S_MULTIMETER);
      }
      
      
      //  Check if digital input has changed and send in new value
      void loop() 
      {
        debouncer.update();
        debouncer2.update();
        
        // Get the update value
      uint8_t  value1 = debouncer.read();
      uint8_t  value2 = debouncer2.read();
        
       
        if (value1 != oldValueC1) {
           // Send in the new value
            gwSend = true;
      
           #ifdef MY_DEBUG
              Serial.println(value1);
           #endif   
           
           oldValueC1 = value1;
        }
      
          if (value2 != oldValueC2) {
           // Send in the new value
            gwSend = true;
      
           #ifdef MY_DEBUG
              Serial.println(value2);
           #endif   
           
           oldValueC2 = value2;
        }
      
       // **** Re-send value every X minutes **** 
          time = millis()/1000;
          
      //    if(time - sendTime >= COUNTER) {
      //    
      //    batteryV  = vcc.Read_Volts();
      //    batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
      //   
      //
      //     #ifdef MY_DEBUG
      //        delay(2000);
      //        Serial.println(batteryPcnt);
      //     #endif    
      //     
      //    gwSend = true;
      //    sendTime = time;
      //    }
      
         if (gwSend == true) {
          
           send(msgMail.set(value1==LOW ? 1 : 0));
           send(msgMail2.set(value2==LOW ? 1 : 0));
           send(msgVolt.set(batteryV, 2));
           sendBatteryLevel(batteryPcnt);
           gwSend = false;
         }
        else {
        }
      
      sleep(0, CHANGE, SLEEP_TIME);
      
      } ```
      posted in Troubleshooting
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      I am and you ? I can give you the sketch which is working for me with library i used.

      posted in Announcements
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      OK, i've no further idea to help you. But i think your sensor is dead. DId you try older or newer library to compile your project ?

      posted in Announcements
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      I supply it with 5v, are you sure it's a 3v3 version ?

      posted in Announcements
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      It worked for a while and now it doesn't ? no problem of power supply ? 3v3 ?

      posted in Announcements
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      Where did you buy your bmp180 ? you said the 3 you have make the same behavior ? something is wrong with the BMP sensor.

      posted in Announcements
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      Too bad, can you upload a basic example sketch in the library adafruit to read pressure and temperature, just to be sure there is the same behavior.

      posted in Announcements
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      Hi, i'm using this sketch and I had to modify it a little bit. But i'm at work and i haven't it.

      You defined the altitude to 688 meters in you sketch, are you sure, you said you're at 1014mbars. If you're really at 700m you should be near 930mbars not 1014mbars.

      posted in Announcements
      ghislain
      ghislain
    • RE: Parking Sensor & DHT22 combinated

      I make this sketch, it is working, code may be cleaner but it's working...

      Available on github : https://github.com/Gis70/MySensors/tree/master/ParkingTempHum_sensor

      posted in Development
      ghislain
      ghislain
    • RE: Parking Sensor & DHT22 combinated

      Yes, thanks guys.

      /**
        *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Compilation of DhtTemperature & Parking Sensor
       * 
       * DESCRIPTION
       * Parking sensor using a neopixel led ring and distance sensor (HC-SR04).
       * Configure the digital pins used for distance sensor and neopixels below.
       * NOTE! Remeber to feed leds and distance sensor serparatly from your Arduino. 
       * It will probably not survive feeding more than a couple of LEDs. You 
       * can also adjust intesity below to reduce the power requirements.
       * 
       * Sends parking status to the controller as a DOOR sensor if SEND_STATUS_TO_CONTROLLER 
       * is defined below. You can also use this _standalone_ without any radio by 
       * removing the SEND_STATUS_TO_CONTROLLER define.
       */
      
      #define SEND_STATUS_TO_CONTROLLER  // Put a comment on this line for standalone mode
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached Disabled
      #define MY_RADIO_NRF24
      #define MY_RF24_PA_LEVEL RF24_PA_LOW
      
      // Noeud de l'objet / Object Node
      #define MY_NODE_ID 1
      
      #include <Adafruit_NeoPixel.h>
      #include <NewPing.h>
      #include <SPI.h>
      #include <MySensors.h>
      #include <DHT.h> 
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 3
      
      #define NEO_PIN      8 // NeoPixels input pin
      #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
      
      #define NUMPIXELS      24 // Number of nexpixels in ring/strip
      #define MAX_INTESITY   5 // Intesity of leds (in percentage). Remember more intesity requires more power.
      
      // The maximum rated measuring range for the HC-SR04 is about 400-500cm.
      #define MAX_DISTANCE 150 // Max distance we want to start indicating green (in cm)
      #define PANIC_DISTANCE 15 // Mix distance we red warning indication should be active (in cm)
      #define PARKED_DISTANCE 100 // Distance when "parked signal" should be sent to controller (in cm)
      
      #define PARK_OFF_TIMEOUT 30000 // Number of milliseconds until turning off light when parked.
      
      // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
      // example for more information on possible values.
      
      Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEO_PIN, NEO_GRB + NEO_KHZ800);
      
      NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      // Sleep time between sensor updates (in milliseconds)
      // Must be >1000ms for DHT22 and >2000ms for DHT11
      static const uint64_t UPDATE_INTERVAL = 90000;
      
      // Force sending an update of the temperature after n sensor reads, so a controller showing the
      // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
      // the value didn't change since;
      // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
      static const uint16_t FORCE_UPDATE_N_READS = 60000;
      
      #define CHILD_ID_HUM 0  
      #define CHILD_ID_TEMP 1
      #define CHILD_ID 2
      
      float lastTemp;
      char lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      boolean metric = true; 
      
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msg(CHILD_ID,V_TRIPPED);
      DHT dht;
      
      unsigned long sendInterval = 5000;  // Send park status at maximum every 5 second.
      unsigned long lastSend;
      
      int oldParkedStatus=-1;
      
      unsigned long blinkInterval = 100; // blink interval (milliseconds)
      unsigned long lastBlinkPeriod;
      bool blinkColor = true;
      
      // To make a fading motion on the led ring/tape we only move one pixel/distDebounce time
      unsigned long distDebounce = 30; 
      unsigned long lastDebouncePeriod;
      int numLightPixels=0;
      int skipZero=0;
      
      
      void presentation()  {
        sendSketchInfo("ParkingTemperatureAndHumiditySensor", "1.0");
        present(CHILD_ID_TEMP, S_TEMP);
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID, S_DOOR, "Parking Status");
      
         metric = getControllerConfig().isMetric;
        }
      
      void setup() 
      {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
        }
        // Sleep for the time of the minimum sampling period to give the sensor time to power up
        // (otherwise, timeout errors might occure for the first reading)
        sleep(dht.getMinimumSamplingPeriod());
        
        Serial.println("Starting distance sensor");
        pixels.begin(); // This initializes the NeoPixel library.
        Serial.println("Neopixels initialized");
        }
      
      
      void loop() 
      {
        // Get temperature from DHT library
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT!");
        } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
          lastTemp = temperature;
             if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          // Reset no updates counter
          nNoUpdatesTemp = 0;
          temperature += SENSOR_TEMP_OFFSET;
          send(msgTemp.set(temperature, 1));
      
            } 
            else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
      
        // Get humidity from DHT library
        char humidity = dht.getHumidity();
        if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
          // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
          lastHum = humidity;
          // Reset no updates counter
          nNoUpdatesHum = 0;
          send(msgHum.set(humidity, 0));
          
            } 
            else {
          // Increase no update counter if the humidity stayed the same
          nNoUpdatesHum++;
        }
      
        
        unsigned long now = millis();
        unsigned int fullDist = (sonar.ping_median() / US_ROUNDTRIP_CM);
        
        int displayDist = min(fullDist, MAX_DISTANCE);
        if (displayDist == 0 && skipZero<10) {
          // Try to filter zero readings
          skipZero++;
        return;
        }
        // Check if it is time to alter the leds
        if (now-lastDebouncePeriod > distDebounce) {
          lastDebouncePeriod = now;
      
          // Update parked status
          int parked = displayDist != 0 && displayDist<PARKED_DISTANCE;
          if (parked != oldParkedStatus && now-lastSend > sendInterval) {
            if (parked)
              Serial.println("Car Parked");
            else
              Serial.println("Car Gone");
      #ifdef SEND_STATUS_TO_CONTROLLER
            send(msg.set(parked)); 
      #endif
            oldParkedStatus = parked;
            lastSend = now;
          }
      
          if (parked && now-lastSend > PARK_OFF_TIMEOUT) {
            // We've been parked for a while now. Turn off all pixels
            for(int i=0;i<NUMPIXELS;i++){
              pixels.setPixelColor(i, pixels.Color(0,0,0)); 
            }
          } else {
            if (displayDist == 0) {
              // No reading from sensor, assume no object found
              numLightPixels--;
            } else {
              skipZero = 0;
              int newLightPixels = NUMPIXELS - (NUMPIXELS*(displayDist-PANIC_DISTANCE)/(MAX_DISTANCE-PANIC_DISTANCE));
              if (newLightPixels>numLightPixels) {
                // Fast raise
                numLightPixels += max((newLightPixels - numLightPixels) / 2, 1);
              } else if (newLightPixels<numLightPixels) {
                // Slow decent
                numLightPixels--;
              }
            }
        
            if (numLightPixels>=NUMPIXELS) {
              // Do some intense red blinking 
              if (now-lastBlinkPeriod > blinkInterval) {
                blinkColor = !blinkColor;
                lastBlinkPeriod = now;
              }
              for(int i=0;i<numLightPixels;i++){
                pixels.setPixelColor(i, pixels.Color(blinkColor?255*MAX_INTESITY/100:0,0,0)); 
              }              
            } else {
              for(int i=0;i<numLightPixels;i++){
                int r = 255 * i/NUMPIXELS;
                int g = 255 - r;     
                // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
                pixels.setPixelColor(i, pixels.Color(r*MAX_INTESITY/100,g*MAX_INTESITY/100,0)); 
              }
              // Turn off the rest
              for(int i=numLightPixels;i<NUMPIXELS;i++){
                pixels.setPixelColor(i, pixels.Color(0,0,0)); 
              }
            }
          }
          pixels.show(); // This sends the updated pixel color to the hardware.
        }
      
            }
      
      

      This code is working. Variables was declared on 8b so max value at 255. Counter and timer can't take value above 255... Stupid.

      How can i do to only send new value if new value is just more or less 0.2Β°C for example ?

      posted in Development
      ghislain
      ghislain
    • RE: Parking Sensor & DHT22 combinated

      This is much better, but too much temperature and humidity value sended

      /**
        *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Compilation of DhtTemperature & Parking Sensor
       * 
       * DESCRIPTION
       * Parking sensor using a neopixel led ring and distance sensor (HC-SR04).
       * Configure the digital pins used for distance sensor and neopixels below.
       * NOTE! Remeber to feed leds and distance sensor serparatly from your Arduino. 
       * It will probably not survive feeding more than a couple of LEDs. You 
       * can also adjust intesity below to reduce the power requirements.
       * 
       * Sends parking status to the controller as a DOOR sensor if SEND_STATUS_TO_CONTROLLER 
       * is defined below. You can also use this _standalone_ without any radio by 
       * removing the SEND_STATUS_TO_CONTROLLER define.
       */
      
      #define SEND_STATUS_TO_CONTROLLER  // Put a comment on this line for standalone mode
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached Disabled
      #define MY_RADIO_NRF24
      #define MY_RF24_PA_LEVEL RF24_PA_LOW
      
      // Noeud de l'objet / Object Node
      #define MY_NODE_ID 1
      
      #include <Adafruit_NeoPixel.h>
      #include <NewPing.h>
      #include <SPI.h>
      #include <MySensors.h>
      #include <DHT.h> 
      
      // Set this to the pin you connected the DHT's data pin to
      #define DHT_DATA_PIN 3
      
      #define NEO_PIN      8 // NeoPixels input pin
      #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
      
      #define NUMPIXELS      24 // Number of nexpixels in ring/strip
      #define MAX_INTESITY   5 // Intesity of leds (in percentage). Remember more intesity requires more power.
      
      // The maximum rated measuring range for the HC-SR04 is about 400-500cm.
      #define MAX_DISTANCE 150 // Max distance we want to start indicating green (in cm)
      #define PANIC_DISTANCE 15 // Mix distance we red warning indication should be active (in cm)
      #define PARKED_DISTANCE 100 // Distance when "parked signal" should be sent to controller (in cm)
      
      #define PARK_OFF_TIMEOUT 30000 // Number of milliseconds until turning off light when parked.
      
      // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
      // example for more information on possible values.
      
      Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEO_PIN, NEO_GRB + NEO_KHZ800);
      
      NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      
      // Set this offset if the sensor has a permanent small offset to the real temperatures
      #define SENSOR_TEMP_OFFSET 0
      
      // Sleep time between sensor updates (in milliseconds)
      // Must be >1000ms for DHT22 and >2000ms for DHT11
      static const uint64_t UPDATE_INTERVAL = 5000;
      
      // Force sending an update of the temperature after n sensor reads, so a controller showing the
      // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
      // the value didn't change since;
      // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
      static const uint8_t FORCE_UPDATE_N_READS = 10;
      
      #define CHILD_ID_HUM 0  
      #define CHILD_ID_TEMP 1
      #define CHILD_ID 2
      
      float lastTemp;
      float lastHum;
      uint8_t nNoUpdatesTemp;
      uint8_t nNoUpdatesHum;
      boolean metric = true; 
      
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msg(CHILD_ID,V_TRIPPED);
      DHT dht;
      
      unsigned long sendInterval = 5000;  // Send park status at maximum every 5 second.
      unsigned long lastSend;
      
      int oldParkedStatus=-1;
      
      unsigned long blinkInterval = 100; // blink interval (milliseconds)
      unsigned long lastBlinkPeriod;
      bool blinkColor = true;
      
      // To make a fading motion on the led ring/tape we only move one pixel/distDebounce time
      unsigned long distDebounce = 30; 
      unsigned long lastDebouncePeriod;
      int numLightPixels=0;
      int skipZero=0;
      
      
      void presentation()  {
        sendSketchInfo("ParkingTemperatureAndHumiditySensor", "1.0");
        present(CHILD_ID_TEMP, S_TEMP);
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID, S_DOOR, "Parking Status");
      
         metric = getControllerConfig().isMetric;
        }
      
      void setup() 
      {
        dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
        if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
          Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
        }
        // Sleep for the time of the minimum sampling period to give the sensor time to power up
        // (otherwise, timeout errors might occure for the first reading)
        sleep(dht.getMinimumSamplingPeriod());
        
        Serial.println("Starting distance sensor");
        pixels.begin(); // This initializes the NeoPixel library.
        Serial.println("Neopixels initialized");
        }
      
      
      void loop() 
      {
          // Force reading sensor, so it works also after sleep()
        dht.readSensor(true);
        
        // Get temperature from DHT library
        float temperature = dht.getTemperature();
        if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT!");
        } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
          // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          // Reset no updates counter
          nNoUpdatesTemp = 0;
          temperature += SENSOR_TEMP_OFFSET;
          send(msgTemp.set(temperature, 1));
      
          #ifdef MY_DEBUG
          Serial.print("T: ");
          Serial.println(temperature);
          #endif
        } else {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
      
        // Get humidity from DHT library
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
        } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
          // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
          lastHum = humidity;
          // Reset no updates counter
          nNoUpdatesHum = 0;
          send(msgHum.set(humidity, 1));
          
          #ifdef MY_DEBUG
          Serial.print("H: ");
          Serial.println(humidity);
          #endif
        } else {
          // Increase no update counter if the humidity stayed the same
          nNoUpdatesHum++;
        }
      
        // Sleep for a while to save energy
       // sleep(UPDATE_INTERVAL); 
      
      
        unsigned long now = millis();
        unsigned int fullDist = (sonar.ping_median() / US_ROUNDTRIP_CM);
        
        int displayDist = min(fullDist, MAX_DISTANCE);
        if (displayDist == 0 && skipZero<10) {
          // Try to filter zero readings
          skipZero++;
        return;
        }
        // Check if it is time to alter the leds
        if (now-lastDebouncePeriod > distDebounce) {
          lastDebouncePeriod = now;
      
          // Update parked status
          int parked = displayDist != 0 && displayDist<PARKED_DISTANCE;
          if (parked != oldParkedStatus && now-lastSend > sendInterval) {
            if (parked)
              Serial.println("Car Parked");
            else
              Serial.println("Car Gone");
      #ifdef SEND_STATUS_TO_CONTROLLER
            send(msg.set(parked)); 
      #endif
            oldParkedStatus = parked;
            lastSend = now;
          }
      
          if (parked && now-lastSend > PARK_OFF_TIMEOUT) {
            // We've been parked for a while now. Turn off all pixels
            for(int i=0;i<NUMPIXELS;i++){
              pixels.setPixelColor(i, pixels.Color(0,0,0)); 
            }
          } else {
            if (displayDist == 0) {
              // No reading from sensor, assume no object found
              numLightPixels--;
            } else {
              skipZero = 0;
              int newLightPixels = NUMPIXELS - (NUMPIXELS*(displayDist-PANIC_DISTANCE)/(MAX_DISTANCE-PANIC_DISTANCE));
              if (newLightPixels>numLightPixels) {
                // Fast raise
                numLightPixels += max((newLightPixels - numLightPixels) / 2, 1);
              } else if (newLightPixels<numLightPixels) {
                // Slow decent
                numLightPixels--;
              }
            }
        
            if (numLightPixels>=NUMPIXELS) {
              // Do some intense red blinking 
              if (now-lastBlinkPeriod > blinkInterval) {
                blinkColor = !blinkColor;
                lastBlinkPeriod = now;
              }
              for(int i=0;i<numLightPixels;i++){
                pixels.setPixelColor(i, pixels.Color(blinkColor?255*MAX_INTESITY/100:0,0,0)); 
              }              
            } else {
              for(int i=0;i<numLightPixels;i++){
                int r = 255 * i/NUMPIXELS;
                int g = 255 - r;     
                // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
                pixels.setPixelColor(i, pixels.Color(r*MAX_INTESITY/100,g*MAX_INTESITY/100,0)); 
              }
              // Turn off the rest
              for(int i=numLightPixels;i<NUMPIXELS;i++){
                pixels.setPixelColor(i, pixels.Color(0,0,0)); 
              }
            }
          }
          pixels.show(); // This sends the updated pixel color to the hardware.
        }
      
            }
      

      How can i get out value of temp and hum out of the loop ?

      I can't put delay because the led ring need to be refreshed very fastly.

      posted in Development
      ghislain
      ghislain
    • RE: Parking Sensor & DHT22 combinated

      Hi, i'm very bad in code. So i tryied to assemble 2 sketches.

      Gateway is spammed yes...

      I think i need to store value of temperature and humidity, store value of parking sensor (car gone or car parked) and send everything together. It would be more clean. But i have no idea to do that.

      I'm not familiar neither with void loop / setup....

      Thanks

      posted in Development
      ghislain
      ghislain
    • Parking Sensor & DHT22 combinated

      Hi all,

      I'm trying to do a sketch with both combinated parking sensor and dht22 but i'm failed.
      Each sketch is working separetely but when i 'm trying together, dht22 values are bad.

      This is my sketch :

      /**
      * 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 - Created by Henrik Ekblad
      * 
      * DESCRIPTION
      * Parking sensor using a neopixel led ring and distance sensor (HC-SR04).
      * Configure the digital pins used for distance sensor and neopixels below.
      * NOTE! Remeber to feed leds and distance sensor serparatly from your Arduino. 
      * It will probably not survive feeding more than a couple of LEDs. You 
      * can also adjust intesity below to reduce the power requirements.
      * 
      * Sends parking status to the controller as a DOOR sensor if SEND_STATUS_TO_CONTROLLER 
      * is defined below. You can also use this _standalone_ without any radio by 
      * removing the SEND_STATUS_TO_CONTROLLER define.
      */
      
      #define SEND_STATUS_TO_CONTROLLER  // Put a comment on this line for standalone mode
      
      #include <Adafruit_NeoPixel.h>
      #include <NewPing.h>
      
      #ifdef SEND_STATUS_TO_CONTROLLER
      // Enable debug prints to serial monitor
      //#define MY_DEBUG 
      
      // Enable and select radio type attached Disabled
      #define MY_RADIO_NRF24
      #define MY_RF24_PA_LEVEL RF24_PA_LOW
      
      // Noeud de l'objet / Object Node
      #define MY_NODE_ID 1
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <DHT.h> 
      #endif
      
      #define DHTPIN 3
      #define DHTTYPE DHT22
      #define NEO_PIN      8 // NeoPixels input pin
      #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
      
      #define NUMPIXELS      24 // Number of nexpixels in ring/strip
      #define MAX_INTESITY   5 // Intesity of leds (in percentage). Remember more intesity requires more power.
      
      // The maximum rated measuring range for the HC-SR04 is about 400-500cm.
      #define MAX_DISTANCE 150 // Max distance we want to start indicating green (in cm)
      #define PANIC_DISTANCE 15 // Mix distance we red warning indication should be active (in cm)
      #define PARKED_DISTANCE 100 // Distance when "parked signal" should be sent to controller (in cm)
      
      #define PARK_OFF_TIMEOUT 30000 // Number of milliseconds until turning off light when parked.
      
      // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
      // example for more information on possible values.
      
      Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEO_PIN, NEO_GRB + NEO_KHZ800);
      
      NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      
      #ifdef SEND_STATUS_TO_CONTROLLER
      #define CHILD_ID_TEMP 0  
      #define CHILD_ID_HUM 1
      #define CHILD_ID 2
      
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msg(CHILD_ID,V_TRIPPED);
      
      float lastTemp;
      float lastHum;
      boolean metric = true; 
      
      #endif
      unsigned long sendInterval = 90000;  // Send park status at maximum every 5 second.
      unsigned long lastSend;
      
      int oldParkedStatus=-1;
      
      unsigned long blinkInterval = 100; // blink interval (milliseconds)
      unsigned long lastBlinkPeriod;
      bool blinkColor = true;
      
      // To make a fading motion on the led ring/tape we only move one pixel/distDebounce time
      unsigned long distDebounce = 30; 
      unsigned long lastDebouncePeriod;
      int numLightPixels=0;
      int skipZero=0;
      
      void setup() {
       Serial.begin(115200);
       Serial.println("Starting distance sensor");
       pixels.begin(); // This initializes the NeoPixel library.
       Serial.println("Neopixels initialized");
      }
      
      #ifdef SEND_STATUS_TO_CONTROLLER
      void presentation()  {
       sendSketchInfo("Parking & Temperature & Humidity Sensor", "1.0");
       present(CHILD_ID_TEMP, S_TEMP);
       present(CHILD_ID_HUM, S_HUM);
       present(CHILD_ID, S_DOOR, "Parking Status");
       }
      #endif
      
      void loop() {
       unsigned long now = millis();
       unsigned int fullDist = (sonar.ping_median() / US_ROUNDTRIP_CM);
        //Serial.println(fullDist);
       int displayDist = min(fullDist, MAX_DISTANCE);
       if (displayDist == 0 && skipZero<10) {
         // Try to filter zero readings
         skipZero++;
       return;
       }
       // Check if it is time to alter the leds
       if (now-lastDebouncePeriod > distDebounce) {
         lastDebouncePeriod = now;
      
         // Update parked status
         int parked = displayDist != 0 && displayDist<PARKED_DISTANCE;
         if (parked != oldParkedStatus && now-lastSend > sendInterval) {
           if (parked)
             Serial.println("Car Parked");
           else
             Serial.println("Car Gone");
      #ifdef SEND_STATUS_TO_CONTROLLER
           send(msg.set(parked)); 
      #endif
           oldParkedStatus = parked;
           lastSend = now;
         }
      
         if (parked && now-lastSend > PARK_OFF_TIMEOUT) {
           // We've been parked for a while now. Turn off all pixels
           for(int i=0;i<NUMPIXELS;i++){
             pixels.setPixelColor(i, pixels.Color(0,0,0)); 
           }
         } else {
           if (displayDist == 0) {
             // No reading from sensor, assume no object found
             numLightPixels--;
           } else {
             skipZero = 0;
             int newLightPixels = NUMPIXELS - (NUMPIXELS*(displayDist-PANIC_DISTANCE)/(MAX_DISTANCE-PANIC_DISTANCE));
             if (newLightPixels>numLightPixels) {
               // Fast raise
               numLightPixels += max((newLightPixels - numLightPixels) / 2, 1);
             } else if (newLightPixels<numLightPixels) {
               // Slow decent
               numLightPixels--;
             }
           }
       
           if (numLightPixels>=NUMPIXELS) {
             // Do some intense red blinking 
             if (now-lastBlinkPeriod > blinkInterval) {
               blinkColor = !blinkColor;
               lastBlinkPeriod = now;
             }
             for(int i=0;i<numLightPixels;i++){
               pixels.setPixelColor(i, pixels.Color(blinkColor?255*MAX_INTESITY/100:0,0,0)); 
             }              
           } else {
             for(int i=0;i<numLightPixels;i++){
               int r = 255 * i/NUMPIXELS;
               int g = 255 - r;     
               // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
               pixels.setPixelColor(i, pixels.Color(r*MAX_INTESITY/100,g*MAX_INTESITY/100,0)); 
             }
             // Turn off the rest
             for(int i=numLightPixels;i<NUMPIXELS;i++){
               pixels.setPixelColor(i, pixels.Color(0,0,0)); 
             }
           }
         }
         pixels.show(); // This sends the updated pixel color to the hardware.
       }
      DHT dht(DHTPIN, DHTTYPE,3); // Creation d'un objet dht dans la loop sinon les valeurs ne sont pas mesurΓ©es au rΓ©veil
       float temperature = dht.readTemperature();
       float humidity = dht.readHumidity();
       if (isnan(temperature)) {
           Serial.println("Impossible de lire la temperature sur le DHT");
       } else {
         if (temperature != lastTemp) {
           lastTemp = temperature;
           if (!metric) {
             temperature = dht.readTemperature(true);
           }
           
           Serial.print("T: ");
           Serial.print(temperature);
           Serial.print(" | H: ");
           Serial.println(humidity);
           send(msgTemp.set(temperature, 1));
           send(msgHum.set(humidity, 1));
         } else {
           Serial.println("Temperature identique => on force l'envoi");  
           Serial.print("T: ");
           Serial.print(temperature);
           Serial.print(" | H: ");
           Serial.println(humidity);
           send(msgTemp.set(temperature, 1));
           send(msgHum.set(humidity, 1));
         }
       }  
           }
      

      Somebody could help me ?

      Thank you some much guys

      posted in Development
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      I found some problems in code. I did make some change to be able to get value. I replace "float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;" by "float pressure = bmp.readPressure() / 100 ;"

      I'll make a PR on GitHub when everything will be well tested. πŸ™‚

      posted in Announcements
      ghislain
      ghislain
    • RE: πŸ’¬ Atmospheric Pressure Sensor

      i've got a problem, pressure always stay to 1013 mbar and i'm at 350m of altitude. Something is wrong but what ? I test the BMP180 alone and it said the good value.

      posted in Announcements
      ghislain
      ghislain