So I'm back
1st sketch from this topic (with conversion) uploaded to Arduino...and still the same.
Have a look on my debug:
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 ?!?
Posts made by Plantex
-
RE: Dimmer sketches - array and multiple PWM led pins
-
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. -
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) ) ;
-
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] );
-
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 lineanalogWrite( 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)
-
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 ... -
RE: gateway serial and dimmer example
@MCF Maybe install an arduino software for raspbian and try to open serial monitor for gateway ?
-
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 ?
-
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 ! -
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 meQ1: 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)
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)); } }
-
RE: Dimmable LED help needed !
@Boots33 I think I wasn't precise enough.
So below the sketch which is working fine but for one LED stripe. It remembers the last dimmer value.
I 've changed it a little bit. It works better for me to receive and display in Domoticz a % dimmer value info instead of information ON/OFFsend(lightMsg.set(dimmerSetting > 0 ? 1 : 0), false) changed to send(dimmerMsg.set(dimmerSetting));
Now my target is to use the maximum quantity of PWM pins in Arduino MEGA (in total I need 16 so I think I am gonna need two Arduinos)
Anyway could You help me please to add extra LEDs into this 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 ); } }
-
RE: Dimmable LED help needed !
Hi
Instead of trying to solve the problem for 1 Led stripe I've decided to go with 6 pcs now - basically I'm gonna need this anyway to do my "high-end" stairs.So what I've done is I've combined Your sketch with some other especially the part with few led's declaration
// 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 #define MY_NODE_ID 153 #include <SPI.h> #include <MySensors.h> #define SN "DimmableLED" #define SV "1.1" #define noLEDs 6 const int LED_Pin[] = {3, 5, 6, 9, 10, 11}; //#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 = 100 ; MyMessage dimmerMsg(noLEDs, V_PERCENTAGE); MyMessage lightMsg(noLEDs, V_STATUS); /*** * Dimmable LED initialization method */ void setup() { // 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_PERCENTAGE ); } } void presentation() { // Register the LED Dimmable Light with the gateway for (int sensor=1; sensor<=noLEDs; sensor++){ present(sensor, S_DIMMER); wait(2); } sendSketchInfo(SN, SV); } /*** * Dimmable LED main processing loop */ void loop() { } /* void receive(const MyMessage &message) { if (message.type == V_LIGHT || message.type == V_DIMMER) { // Retrieve the power or dim level from the incoming request message int requestedLevel = atoi( message.data ); // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on] requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 ); // Clip incoming level to valid range of 0 to 100 requestedLevel = requestedLevel > 100 ? 100 : requestedLevel; requestedLevel = requestedLevel < 0 ? 0 : requestedLevel; Serial.print( "Changing level to " ); Serial.print( requestedLevel ); Serial.print( ", from " ); Serial.println( currentLevel ); fadeToLevel( requestedLevel ); // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value... send(lightMsg.set(currentLevel > 0)); // hek comment: Is this really nessesary? send( dimmerMsg.set(currentLevel) ); } } */ void receive(const MyMessage &message) { switch (message.type) { case V_STATUS: // message is from the switch if(message.getBool()){ fadeToLevel( dimmerSetting, message.sensor ); // turn light on at current dimmer level } else fadeToLevel( 0, message.sensor ); // 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, message.sensor ); // fade to the new dimmer setting send(lightMsg.set(dimmerSetting > 0 ? 1 : 0), false); // send switch state to controller , no ack requested break; } } /*** * This method provides a graceful fade up/down effect */ void fadeToLevel( int toLevel, int ledid ) { { int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1; while ( currentLevel != toLevel ) { currentLevel += delta; analogWrite( LED_Pin[ledid-1], (int)(currentLevel / 100. * 255) ); delay( FADE_DELAY ); } } }
So I have right now 6 LEDs in Domoticz connected to Arduino Mega 3,5,6,9,10,11 pins ( I hope all of them are PWM)
At first usage It behaves crazy - It's like every switch needs the first on and off sequence to start behave normally.
What happens then:
LED 1 ,2, 3, 5 - all work ok , every single one saves the last state when switch off/on , dimmer bar works fine
now the best part
LED 4 - when I switch it On (mouse click in Domoticz) LED is going ON (physically) but the same time LED 1,2,3 is going ON (but only in Domoticz so let's say they are virtually ON but in reality OFF) - dimmer bar LED 4 works ok , saves the last status, You can switch it off but 1,2,3 will be still ON (you have to click each one to take off the virtual status)
LED 6 - works very similar to 1,2,3,5 - when I move the dimmer bar to e.g. 15% LED it is reacting it is ok BUT suddenly after 1-2 seconds dimmer bar goes to full range (led still shines 15%)
LED 6 Is also unique - if I play with any of the switches and dimmer (1,2,3,4,5) this one is going virtually ON (domoticz reporting it is on - and its bar is going to full range)Please help me to understand where is this behavior coming from.
Honestly I am not a programmer I am not even sure If the sketch which I combined is anyhow feasible.
I had to add some messages so I added everywhere after Your dimmerSetting a line.. message.sensor - but I have no idea what it does. Not sure if it should be message.sensor or something else.fadeToLevel( dimmerSetting, message.sensor ) and this fadeToLevel( 0, message.sensor ) and this fadeToLevel( dimmerSetting, message.sensor
I am thinking maybe I can sacrifice "save the last dimmer value" - just to get this leds working normal
Help Anybody !
P.S
I can paste my debug but there is so many problems I dont even know which bahavior case ( LED 4 or LED 6 or LED1 etc..) I should paste from my debug -
RE: Dimmable LED help needed !
@Boots33
Thank YouI've uploaded Your sketch. I don't know why but LED went from 0 to 100% six times in a row, then it stayed on.
When I opened serial monitor in Arduino - it did the same (six times 0-100%) and my debug stopped on the line:2202 TSF:MSG:READ,0-0-153,s=0,c=2,t=3,pt=0,l=3,sg=0:666 8909 TSF:MSG:SEND,153-153-0-0,s=0,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
(666 interesting )
Then from Domoticz
Status of the switch was OFF but LED was actually physically ON - so I moved the bar to 33% and it did again (six times but this time from 100% to 33% and stayed on 33%)
After that It started to behave normally when I moved the bar to 56% and to 9%
So basically It works but every initial start whatever it is (uploading sketch, serial monitor, switch on from domoticz) it is doing 6 times complete range
Any Idea why it is doing that ?Right now I'm planning to extend it to few more led stripes but this will be next step.
Below my debug from the steps described above:
0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1 3 TSM:INIT 4 TSF:WUR:MS=0 11 TSM:INIT:TSP OK 13 TSF:SID:OK,ID=153 14 TSM:FPAR 51 TSF:MSG:SEND,153-153-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 128 TSF:MSG:READ,0-0-153,s=255,c=3,t=8,pt=1,l=1,sg=0:0 133 TSF:MSG:FPAR OK,ID=0,D=1 2058 TSM:FPAR:OK 2059 TSM:ID 2060 TSM:ID:OK 2062 TSM:UPL 2065 TSF:MSG:SEND,153-153-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 2071 TSF:MSG:READ,0-0-153,s=255,c=3,t=25,pt=1,l=1,sg=0:1 2076 TSF:MSG:PONG RECV,HP=1 2079 TSM:UPL:OK 2080 TSM:READY:ID=153,PAR=0,DIS=1 2085 TSF:MSG:SEND,153-153-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 2093 TSF:MSG:READ,0-0-153,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 2100 TSF:MSG:SEND,153-153-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1 2109 TSF:MSG:SEND,153-153-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 2116 TSF:MSG:READ,0-0-153,s=255,c=3,t=6,pt=0,l=1,sg=0:M 2123 TSF:MSG:SEND,153-153-0-0,s=0,c=0,t=4,pt=0,l=0,sg=0,ft=0,st=OK: 2131 TSF:MSG:SEND,153-153-0-0,s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=OK:DimmableLED 2141 TSF:MSG:SEND,153-153-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.1 2148 MCO:REG:REQ 2151 TSF:MSG:SEND,153-153-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 2158 TSF:MSG:READ,0-0-153,s=255,c=3,t=27,pt=1,l=1,sg=0:1 2163 MCO:PIM:NODE REG=1 2165 MCO:BGN:STP 2168 TSF:MSG:SEND,153-153-0-0,s=0,c=2,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 2174 MCO:BGN:INIT OK,TSP=1 2202 TSF:MSG:READ,0-0-153,s=0,c=2,t=3,pt=0,l=3,sg=0:666 8909 TSF:MSG:SEND,153-153-0-0,s=0,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1 267588 TSF:MSG:READ,0-0-153,s=1,c=1,t=3,pt=0,l=2,sg=0:33 267593 TSF:MSG:ACK REQ 267597 TSF:MSG:SEND,153-153-0-0,s=1,c=1,t=3,pt=0,l=2,sg=0,ft=0,st=OK:33 273975 TSF:MSG:SEND,153-153-0-0,s=0,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1 276599 TSF:MSG:READ,0-0-153,s=1,c=1,t=3,pt=0,l=2,sg=0:56 276604 TSF:MSG:ACK REQ 276609 TSF:MSG:SEND,153-153-0-0,s=1,c=1,t=3,pt=0,l=2,sg=0,ft=0,st=OK:56 276848 TSF:MSG:SEND,153-153-0-0,s=0,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1 281715 TSF:MSG:READ,0-0-153,s=1,c=1,t=3,pt=0,l=1,sg=0:9 281720 TSF:MSG:ACK REQ 281724 TSF:MSG:SEND,153-153-0-0,s=1,c=1,t=3,pt=0,l=1,sg=0,ft=0,st=OK:9 282206 TSF:MSG:SEND,153-153-0-0,s=0,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
-
Dimmable LED help needed !
Hi
I'm testing Dimmable LED Actuator --> https://www.mysensors.org/build/dimmer
Everything seems to work with Domoticz except one thing - It doesn't remember last dimming value (This is a feature I really need).
After switching the light off and back on , no matter what value was before it goes everytime to 100%
Figured out If I change the value 100 : 1 to 10 : 1 - It goes to 10% - but still It doesnt remember the last dimming value.// Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on] requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );```
I've found a sketch DimmableLight in My sensors examples which I would like to test unfortunately I cannot force it to work with LED stripe connected according to dimmer sketch( Mosfet , led pin 3 etc..)
Could someone help me please with the code ?
Which part is responsible for sending the information to LED_PIN 3 ? I tried to define LED pin3, also fade delay etc... to the below sketch - no luck.
Does it matter if the variables are V_LIGHT and V_DIMMER if the type is S_DIMMER ? (both sketches) Shouldn't it be V_STATUS and V_PERCENTAGE ?Any help very welcome !
Thanks in advance./** * 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 #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 "Dimable Light" #define SV "1.0" int16_t LastLightState=LIGHT_OFF; int16_t LastDimValue=100; 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) { Serial.println( "Light state: OFF" ); } else { 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)); } }
-
RE: RGB LED strip
Hello
I need some help !I've ordered few IRLZ44N Mosfets to play with Dimmable LED Actuator project.
Adafruit RGB LED stripe uses IRLB8721
Could You please tell me if I could use mentioned IRLZ instead of IRLB in case of described RGB project ?Thank You in advance.
-
RE: RFID and NRF24L01 Wireless Network Coding Issues
Could You please explain what do You mean by "Change that line in the getID() function to return 0;"
I am trying to run the sketch but I have the same problem as @Aron-SjΓΆberg.
Could You let me know which MFC library version I should use ?
-
RE: Relay control - bistable switch instead of monostable.
Thank You. Works perfect and reporting to Domoticz/Imperi Home.
-
RE: Relay control - bistable switch instead of monostable.
Yes, standard on/off switch
-
Relay control - bistable switch instead of monostable.
Hello
I'm using modified my-sensors sketch to control few relays. Arduino is connected via usb cable with Domoticz.
Everything works fine but the sketch is designed for monostable switch (doorbell type)
Point is I would like to use standard (bistable) switch instead of (monostable) doorbell switch.
Could You please help me with modifying the sketch ?!?
Thank You in advance.
Below the code.// 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 // Flash leds on rx/tx/err // #define MY_LEDS_BLINKING_FEATURE // Set blinking period // #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Inverses the behavior of leds // #define MY_WITH_LEDS_BLINKING_INVERSE // 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 // 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 <SPI.h> #include <MySensors.h> #include <Bounce2.h> // Enable repeater functionality for this node // #define MY_REPEATER_FEATURE #define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define RELAY_2 5 #define RELAY_3 6 #define RELAY_4 7 #define NUMBER_OF_RELAYS 4 // Total number of attached relays #define RELAY_ON 0 // GPIO value to write to turn on attached relay #define RELAY_OFF 1 // GPIO value to write to turn off attached relay #define BUTTON_PIN A1 #define BUTTON2_PIN A2 #define BUTTON3_PIN A3 #define BUTTON4_PIN A4 void before() { for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } Bounce debouncer = Bounce(); Bounce debouncer2 = Bounce(); Bounce debouncer3 = Bounce(); Bounce debouncer4 = Bounce(); void setup() { // Setup locally attached sensors delay(10000); // Setup the button. pinMode(BUTTON_PIN, INPUT_PULLUP); pinMode(BUTTON2_PIN, INPUT_PULLUP); pinMode(BUTTON3_PIN, INPUT_PULLUP); pinMode(BUTTON4_PIN, INPUT_PULLUP); // After setting up the button, setup debouncer. debouncer.attach(BUTTON_PIN); debouncer.interval(5); debouncer2.attach(BUTTON2_PIN); debouncer2.interval(5); debouncer3.attach(BUTTON3_PIN); debouncer3.interval(5); debouncer4.attach(BUTTON4_PIN); debouncer4.interval(5); //presentation(); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Relay", "1.0"); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_LIGHT); } } MyMessage msg(1, V_LIGHT); MyMessage msg2(2, V_LIGHT); MyMessage msg3(3, V_LIGHT); MyMessage msg4(4, V_LIGHT); void loop() { // Send locally attached sensor data here if (debouncer.update()) { // Get the update value. int value = debouncer.read(); // Send in the new value. if(value == LOW){ saveState(1, !loadState(1)); digitalWrite(RELAY_1, loadState(1)?RELAY_ON:RELAY_OFF); send(msg.set(loadState(1))); } } if (debouncer2.update()) { int value2 = debouncer2.read(); if(value2 == LOW){ saveState(2, !loadState(2)); digitalWrite(RELAY_2, loadState(2)?RELAY_ON:RELAY_OFF); send(msg2.set(loadState(2))); } } if (debouncer3.update()) { int value3 = debouncer3.read(); if(value3 == LOW){ saveState(3, !loadState(3)); digitalWrite(RELAY_3, loadState(3)?RELAY_ON:RELAY_OFF); send(msg3.set(loadState(3))); } } if (debouncer4.update()) { int value4 = debouncer4.read(); if(value4 == LOW){ saveState(4, !loadState(4)); digitalWrite(RELAY_4, loadState(4)?RELAY_ON:RELAY_OFF); send(msg4.set(loadState(4))); } } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
-
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.