Navigation

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

    Plantex

    @Plantex

    2
    Reputation
    22
    Posts
    516
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Plantex Follow

    Best posts made by Plantex

    • RE: gateway serial and dimmer example

      Hi @MCF

      I've just started a topic with two sketches for LED Dimmer. Have a look and test one of two sketches. 1st one is based on Yours with a little change to save the last dimmer status after on/off. 2nd is basing on Dimmable Light sketch (using EPROM to save the status).
      Good Luck !

      posted in Development
      Plantex
      Plantex
    • RE: DHT 11 Domoticz problem

      Thank You gohan

      Commenting MY_DEBUG solved the problem.

      Could You explain please what this function does ? should I always comment it/ delete ? or there are some reasons for using that ?

      Thanks in advance.

      posted in Domoticz
      Plantex
      Plantex

    Latest posts made by Plantex

    • RE: Dimmer sketches - array and multiple PWM led pins

      So I'm back
      1st sketch from this topic (with conversion) uploaded to Arduino...and still the same.
      Have a look on my debug: 0_1513801735803_test.jpg
      The last value was a 100% for like 2 seconds - then forced to be 99% and staying like this.
      I don't know , maybe I am trying to get something impossible ?!?

      posted in Development
      Plantex
      Plantex
    • RE: Dimmer sketches - array and multiple PWM led pins

      @dbemowsk
      In the beggining of this topic there are two sketches. The 1st one is using the method which You've pasted. The 2nd one is using Array. I will test 1st one again today later but I'm sure I've tried it yesterday and it didnt work ( I mean still 100% from Domo was Level 99 for node.
      Will test again and see where I am.
      Thank You for now.

      posted in Development
      Plantex
      Plantex
    • RE: Dimmer sketches - array and multiple PWM led pins

      @dbemowsk
      Ok
      Myself I dont make this conversion.
      Unfortunately I dont know how the data exchange between Domoticz-Gateway-Node looks like.
      I can see only the communication between Gateway-Node
      In my case the dimming values are written in array.
      Different way is to do it like this:

      analogWrite(LED_Pin[ledid1-1], (int)(currentLevel1 / 100. * 255) )  ;
      
      posted in Development
      Plantex
      Plantex
    • RE: Dimmer sketches - array and multiple PWM led pins

      @dbemowsk
      I am not sure what do You mean by numbers to percentage.
      I've checked few different led dimmer sketches and all of them behave the same : You move the dimmer bar in Domoticz to 100% but the node receives a value of 99...
      I've put the serial print to see the value (array) which is "delivered" to node.
      I am writing to a LED pin value LastDimValue-1 but printing LastDim1Value which is then displayed next to the text ON,Level: ...
      So again Domoticz bar 100% is displaying here a Level 99 ...

      analogWrite( LED_PIN1, dimlevels[LastDim1Value-1] );
          Serial.println( dimlevels[LastDim1Value] );
      

      0_1513764460157_domoticz 1.png

      posted in Development
      Plantex
      Plantex
    • RE: Dimmer sketches - array and multiple PWM led pins

      After searching for a solution I finally stayed with code below.

      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_RF24_CE_PIN 49
      #define MY_RF24_CS_PIN 53
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      
      #define CHILD_ID_LIGHT1 1
      
      #define EPROM_LIGHT1_STATE 1
      #define EPROM_DIMMER1_LEVEL 2
      
      #define LIGHT1_OFF 0
      #define LIGHT1_ON 1
      #define SN "DimableMacio"
      #define SV "1.0"
      
      #define LED_PIN1 3
      #define MAXDIMLEVELS                     100
      
      //#define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
      
      int16_t LastLight1State=LIGHT1_OFF;
      int16_t LastDim1Value=MAXDIMLEVELS;
      
      //int dimlevels=100
      int dimlevels[ MAXDIMLEVELS ] =  // PWM values used for translating home automation dimmer levels. This gives smoother transations
        {   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
           10,  11,  12,  13,  14,  15,  16,  17,  18,  19,
           20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
           30,  31,  32,  35,  39,  42,  46,  49,  52,  56,
           59,  62,  66,  69,  73,  76,  79,  83,  86,  89,
           93,  96, 100, 103, 106, 110, 113, 116, 120, 123,
          126, 130, 133, 137, 140, 144, 147, 150, 154, 157,
          160, 164, 167, 171, 174, 177, 181, 184, 187, 191,
          194, 197, 201, 204, 208, 211, 215, 218, 221, 225,
          228, 231, 235, 238, 242, 245, 246, 250, 251, 255};
          
      
      
      MyMessage light1Msg(CHILD_ID_LIGHT1, V_STATUS);
      MyMessage dimmer1Msg(CHILD_ID_LIGHT1, V_PERCENTAGE);
      
      void setup()
      {
        //Retreive our last light 1 state from the eprom
        int Light1State=loadState(EPROM_LIGHT1_STATE);
        if (Light1State<=1) {
          LastLight1State=Light1State;
          int Dim1Value=loadState(EPROM_DIMMER1_LEVEL);
          if ((Dim1Value>0)&&(Dim1Value<=100)) {
            //There should be no Dim value of 0, this would mean LIGHT_OFF
            LastDim1Value=Dim1Value;
          }
        }
      
        //Here you actualy switch on/off the light 1 with the last known dim level
        SetCurrentState2Hardware1();
        Serial.println( "Node nr 1 ready to receive messages..." );
        }
      
      void presentation() {
        // Register the LED Dimmable Light with the gateway
       //for (int sensor=1; sensor<=noLEDs; sensor++){
       present(CHILD_ID_LIGHT1, S_DIMMER);
       wait(2);
        sendSketchInfo(SN, SV);
        }
      
      void loop()
      {}
      
      void receive(const MyMessage &message) {
          
        if (message.type == V_STATUS) {
          Serial.println( "V_STATUS LED1 command received..." );
      
          int lstate1= atoi( message.data );
          if ((lstate1<0)||(lstate1>1)) {
            Serial.println( "V_STATUS LED1 data invalid (should be 0/1)" );
            return;
          }
          LastLight1State=lstate1;
          saveState(EPROM_LIGHT1_STATE, LastLight1State);
      
          if ((LastLight1State==LIGHT1_ON)&&(LastDim1Value==0)) {
            //In the case that the Light State = On, but the dimmer value is zero,
            //then something (probably the controller) did something wrong,
            //for the Dim value to 100%
            LastDim1Value=100;
            saveState(EPROM_DIMMER1_LEVEL, LastDim1Value);
          }
      
          //When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value
          //This means if you previously set the lights dimmer value to 50%, and turn the light ON
          //it will do so at 50%
        } else if (message.type == V_PERCENTAGE) {
          Serial.println( "V_PERCENTAGE LED1 command received..." );
          int dim1value= atoi( message.data );
          if ((dim1value<0)||(dim1value>100)) {
            Serial.println( "V_PERCENTAGE LED1 data invalid (should be 0..100)" );
            return;
          }
          if (dim1value==0) {
            LastLight1State=LIGHT1_OFF;
          } else {
            LastLight1State=LIGHT1_ON;
            LastDim1Value=dim1value;
            saveState(EPROM_DIMMER1_LEVEL, LastDim1Value);
          }
        } else {
          Serial.println( "Invalid command received..." );
          return;
        }
      
        //Here you set the actual light state/level
        SetCurrentState2Hardware1();
      }
      
      
      void SetCurrentState2Hardware1()
      {
        if (LastLight1State==LIGHT1_OFF) {
          analogWrite( LED_PIN1, dimlevels[0] );
          Serial.println( "Light state LED1: OFF" );
        } else {
          analogWrite( LED_PIN1, dimlevels[LastDim1Value-1] );
          Serial.println( dimlevels[LastDim1Value] );
          Serial.print( "Light state LED1: ON, Level: " );
          Serial.println( LastDim1Value );
        }
      
        //Send current state to the controller
        SendCurrentState2Controller1();
      }
      
      void SendCurrentState2Controller1()
      {
        if ((LastLight1State==LIGHT1_OFF)||(LastDim1Value==0)) {
          send(dimmer1Msg.set((int16_t)0));
        } else {
          send(dimmer1Msg.set(LastDim1Value));
        }
      }
      
      

      Question to anybody who can help with the last annoying thing
      When I move the dimmer bar in Domoticz to a % value - arduino responds with the same % (for example 21% on the screen from serial monitor attached below)
      BUT
      When I move the dimmer bar to 100% - arduino responds with value of 99 - then it is forcing (sending back an info) to Domoticz and the value on the bar is chaning from 100% (set by me) to 99% forced by Arduino.
      Question WHY ????????? 100% in Domoticz = 99% for Arduino ??????
      Even changing this line

      analogWrite( LED_PIN1, dimlevels[LastDim1Value - 1] );
      

      and removing the (minus) still the same behavior (but I can see on the monitor I am pulling different values from array which is good)

      PS. I tried to make the array bigger (like 101 cells and additional 255 value - still showing 99)
      0_1513719772522_Domoticz.png

      posted in Development
      Plantex
      Plantex
    • RE: Dimmer sketches - array and multiple PWM led pins

      @MCF
      Thanks for the sketch. It works pretty good. There is this one thing which is not working
      It contains

      // Pull the gateway's current dim level - restore light level upon sendor node power-up
      for (int sensor=1; sensor<=noLEDs; sensor++){
        request( sensor, V_DIMMER );
      

      I don't know why but it doesnt save the last dimming status. It's always on 100% after switching ON.

      I was trying to implement in your sketch

      saveState(EPROM_DIMMER_LEVEL, LastDimValue)
      

      but finished with nothing.
      Still looking for solution ... 😞

      posted in Development
      Plantex
      Plantex
    • RE: gateway serial and dimmer example

      @MCF Maybe install an arduino software for raspbian and try to open serial monitor for gateway ?

      posted in Development
      Plantex
      Plantex
    • RE: gateway serial and dimmer example

      @mcf
      One more thing.
      Probably this is obvious for lots of forum users but sometimes I had some problems with some sketches when uploaded to gateway-arduino (connected to Domoticz) and debugger was enabled.

      Try to comment out #define MY_DEBUG see if there is any change.

      From other side do You need that sketch on gateway ? maybe transfer it to node with nrf24 ?

      posted in Development
      Plantex
      Plantex
    • RE: gateway serial and dimmer example

      Hi @MCF

      I've just started a topic with two sketches for LED Dimmer. Have a look and test one of two sketches. 1st one is based on Yours with a little change to save the last dimmer status after on/off. 2nd is basing on Dimmable Light sketch (using EPROM to save the status).
      Good Luck !

      posted in Development
      Plantex
      Plantex
    • Dimmer sketches - array and multiple PWM led pins

      Hello Everyone
      Recently I'm fighting with LED dimmer (rookie in programming)
      I got to the point where (with help of @Boots33 - Thank You) I have two different sketches both work OK with saving the last dim status but..... only for 1 LED stripe
      Tried to implement an array as declaration of additional LED pins (there is a topic on the forum https://forum.mysensors.org/topic/4808/dimmable-led-actuator/6 ) but using this method... I finished with..
      1st sketch switching on/off crazy (one button in Domoticz switching a group of lights , some of them not working at all etc.. - >in summarry a mess !)
      2nd I didnt even get to the point of few leds - because there is already an array which is a little confusing for me

      Q1: Could somebody please have a look on both and advice which one is potentially (better written , less giving problems with multiple pins, I should focus on ?) and help me with declaration of extra pins ?? ( basically I'm trying to use all the PWM pins from Arduino Mega)

      Q2: There is already an array in 2nd sketch for the dimmer but I am not sure how it works and why somebody went this way (definition of maxdimlevels and dimlevels array) ??? is it possible to get rid of it ?

      Configuration - RPi, Domoticz, Uno Gateway + nrF24, Sensor node nrf24 connected to Mega , mosfets in breadboard (not soldered at all - so no damage) , external 12V for Mosfet Ledstripes -->7,5V Arduino , for testing purpose 6 led stripes connected to PWM pins
      (at present disconnected from GND all except 1st one - stripes are very bright and going crazy when not declared in Arduino)
      0_1512935926099_XxY.jpg

      1st sketch

      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_RF24_CE_PIN 49
      #define MY_RF24_CS_PIN 53
      
      #include <MySensors.h>
      
      #define SN "Dimmable_LED"
      #define SV "1.1"
      
      #define LED_PIN 3      // Arduino pin attached to MOSFET Gate pin
      #define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
      
      static int16_t currentLevel = 0;  // Current dim level...
      int dimmerSetting = 10 ;
      
      MyMessage dimmerMsg(0, V_PERCENTAGE);
      MyMessage lightMsg(0, V_STATUS);
      
      
      /***
      * Dimmable LED initialization method
      */
      void setup()
      {
       // Pull the gateway's current dim level - restore light level upon sendor node power-up
       //request( 0, V_PERCENTAGE );
      }
      
      void presentation()
      {
       // Register the LED Dimmable Light with the gateway
       present( 0, S_DIMMER );
      
       sendSketchInfo(SN, SV);
      }
      
      /***
      *  Dimmable LED main processing loop
      */
      void loop()
      {
      }
      
      void receive(const MyMessage &message) {
      switch (message.type) {
      
       case V_STATUS:                                           // message is from the switch
        if(message.getBool()){
          fadeToLevel( dimmerSetting );                         // turn light on at current dimmer level
        }
        else fadeToLevel( 0 );                                  // fade light to 0 (off)
       break;
      case V_PERCENTAGE:                                        // message is from the dimmer
        dimmerSetting = message.getInt();                       // get the new dimmer setting from the message
        fadeToLevel( dimmerSetting );                           // fade to the new dimmer setting
         send(dimmerMsg.set(dimmerSetting));                    // send switch  state to controller , no ack requested
        break;
        }
       }
      
      
      /***
      *  This method provides a graceful fade up/down effect
      */
      void fadeToLevel( int toLevel )
      {
      
       int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1;
      
       while ( currentLevel != toLevel ) {
         currentLevel += delta;
         analogWrite( LED_PIN, (int)(currentLevel / 100. * 255) );
         wait( FADE_DELAY );
       }
      } 
      

      2nd sketch based on MySensors generic dimmablelight (modified by me a little using gesture sensor 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 - January 30, 2015 - Developed by GizMoCuz (Domoticz)
       *
       * DESCRIPTION
       * This sketch provides an example how to implement a Dimmable Light
       * It is pure virtual and it logs messages to the serial output
       * It can be used as a base sketch for actual hardware.
       * Stores the last light state and level in eeprom.
       *
       */
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_RF24_CE_PIN 49
      #define MY_RF24_CS_PIN 53
      
      #include <MySensors.h>
      
      #define CHILD_ID_LIGHT 1
      
      #define EPROM_LIGHT_STATE 1
      #define EPROM_DIMMER_LEVEL 2
      
      #define LIGHT_OFF 0
      #define LIGHT_ON 1
      
      #define SN "DimableLightg"
      #define SV "1.0"
      
      #define LED_PIN 3      // Arduino pin attached to MOSFET Gate pin
      #define MAXDIMLEVELS                     100
      //#define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
      
      int16_t LastLightState=LIGHT_OFF;
      int16_t LastDimValue=MAXDIMLEVELS;
      
      int dimlevels[ MAXDIMLEVELS ] =  // PWM values used for translating home automation dimmer levels. This gives smoother transations
        {   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
           10,  11,  12,  13,  14,  15,  16,  17,  18,  19,
           20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
           30,  31,  32,  35,  39,  42,  46,  49,  52,  56,
           59,  62,  66,  69,  73,  76,  79,  83,  86,  89,
           93,  96, 100, 103, 106, 110, 113, 116, 120, 123,
          126, 130, 133, 137, 140, 144, 147, 150, 154, 157,
          160, 164, 167, 171, 174, 177, 181, 184, 187, 191,
          194, 197, 201, 204, 208, 211, 215, 218, 221, 225,
          228, 231, 235, 238, 242, 245, 246, 250, 251, 255 };
      
      MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT);
      MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
      
      void setup()
      {
      	//Retreive our last light state from the eprom
      	int LightState=loadState(EPROM_LIGHT_STATE);
      	if (LightState<=1) {
      		LastLightState=LightState;
      		int DimValue=loadState(EPROM_DIMMER_LEVEL);
      		if ((DimValue>0)&&(DimValue<=100)) {
      			//There should be no Dim value of 0, this would mean LIGHT_OFF
      			LastDimValue=DimValue;
      		}
      	}
      
      	//Here you actualy switch on/off the light with the last known dim level
      	SetCurrentState2Hardware();
      
      	Serial.println( "Node ready to receive messages..." );
      }
      
      void presentation()
      {
      //Send the Sketch Version Information to the Gateway
      	sendSketchInfo(SN, SV);
      	present(CHILD_ID_LIGHT, S_DIMMER );
       }
      
      void loop()
      {
      }
      
      void receive(const MyMessage &message)
      {
      	if (message.type == V_LIGHT) {
      		Serial.println( "V_LIGHT command received..." );
      
      		int lstate= atoi( message.data );
      		if ((lstate<0)||(lstate>1)) {
      			Serial.println( "V_LIGHT data invalid (should be 0/1)" );
      			return;
      		}
      		LastLightState=lstate;
      		saveState(EPROM_LIGHT_STATE, LastLightState);
      
      		if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) {
      			//In the case that the Light State = On, but the dimmer value is zero,
      			//then something (probably the controller) did something wrong,
      			//for the Dim value to 100%
      			LastDimValue=100;
      			saveState(EPROM_DIMMER_LEVEL, LastDimValue);
      		}
      
      		//When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value
      		//This means if you previously set the lights dimmer value to 50%, and turn the light ON
      		//it will do so at 50%
      	} else if (message.type == V_DIMMER) {
      		Serial.println( "V_DIMMER command received..." );
      		int dimvalue= atoi( message.data );
      		if ((dimvalue<0)||(dimvalue>100)) {
      			Serial.println( "V_DIMMER data invalid (should be 0..100)" );
      			return;
      		}
      		if (dimvalue==0) {
      			LastLightState=LIGHT_OFF;
      		} else {
      			LastLightState=LIGHT_ON;
      			LastDimValue=dimvalue;
      			saveState(EPROM_DIMMER_LEVEL, LastDimValue);
      		}
      	} else {
      		Serial.println( "Invalid command received..." );
      		return;
      	}
      
      	//Here you set the actual light state/level
      	SetCurrentState2Hardware();
      }
      
      void SetCurrentState2Hardware()
      {
      	if (LastLightState==LIGHT_OFF) {
          analogWrite( LED_PIN, dimlevels[0] );
      		Serial.println( "Light state: OFF" );
      	} else {
          analogWrite( LED_PIN, dimlevels[ LastDimValue - 1 ] );
      		Serial.print( "Light state: ON, Level: " );
      		Serial.println( LastDimValue );
      	}
      
      	//Send current state to the controller
      	SendCurrentState2Controller();
      }
      
      void SendCurrentState2Controller()
      {
      	if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
      		send(dimmerMsg.set((int16_t)0));
      	} else {
      		send(dimmerMsg.set(LastDimValue));
      	}
      }
      
      posted in Development
      Plantex
      Plantex