is this done at startup from the node? or for each message that will be send separately?
is it possible to configure that it has to transmit by a certain repeater node (so not shortest way, but best signal)?
thanks!
is this done at startup from the node? or for each message that will be send separately?
is it possible to configure that it has to transmit by a certain repeater node (so not shortest way, but best signal)?
thanks!
is it possible to use multiple repeaters?
so:
Gateway --> repeater node --> repeater node --> sensor node
do i have to do something special for this?
because i have a feeling this is not working for me :s
but anyway how to get the different dimmer value's from the controller stays the same and i am still troubling on that :s
@korttoma said:
My RGBW sketch is basically 4 dimmers also, take a look in this thread:
thanks for the reply!
I dont really get your code... you receive a byte from the controller? / you use a 'mode' to set your dimmers? my dimmers are 4 induvidual dimmers and dont have to work together ..
@rvendrame said:
@thomasdc , as simple as
// Channel Number int i = message.sensor;
Thank you very much for the reply!
can you expain it a litle more?
so i have 4 dimmers:
MyMessage dimmer1Msg(AC_pin1, V_DIMMER);
MyMessage light1Msg(AC_pin1, V_LIGHT);
MyMessage dimmer2Msg(AC_pin2, V_DIMMER);
MyMessage light2Msg(AC_pin2, V_LIGHT);
MyMessage dimmer3Msg(AC_pin2, V_DIMMER);
MyMessage light3Msg(AC_pin3, V_LIGHT);
MyMessage dimmer4Msg(AC_pin4, V_DIMMER);
MyMessage light4Msg(AC_pin4, V_LIGHT);
how do i get the vallue for each dimmer?
so how do i get an 'int i' for channel one, an 'int j' for channel two, and so on ?
where do i put the code? is it just behind the:
void incomingMessage(const MyMessage &message) {
if (message.type == V_LIGHT || message.type == V_DIMMER) {
? do i have to change something in the 'void incomming message' (see above)
big thanks!
hi!
after long searching and trying i managed to Build an 'MySensors' AC dimming node.
I bought this:
http://www.ebay.com/itm/4CH-AC-Dimmer-Module-Controller-Board-ARDUINO-RASPBERRY-Compatible-50-60Hz-/121752461158?ssPageName=ADME:X:RTQ:US:1123
and i use it to control my lightning.
regards, Thomas
It was working for 1 dimmer but now im am updating the code for '4' dimmers but i am having trouble with understanding...
this is the code so far:
/*
this is based on the sketch from Quocanhcgd
link: http://forum.mysensors.org/topic/1316/ac-dimmer-with-openhab
Tested With Domoticz, working fine 220V 50Hz
AC Light Control
Uses up and down buttons to set levels
makes use of a timer interrupt to set the level of dimming
*/
#include <SPI.h>
#include <MySensor.h>
#include <TimerOne.h>
#define SN "AC Dimmer control"
#define SV "1.0"
#define NODE_ID 30 //change to a number to assign a specific ID
#define FADE_DELAY 18 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
#define FADE_PERCENTAGE 5 //The percentage the fade level will be changed when a button is pressed
volatile int i=0; // Variable to use as a counter of dimming steps. It is volatile since it is passed between interrupts
volatile int j=0;
volatile int k=0;
volatile int l=0;
volatile boolean zero_cross=0; // Flag to indicate we have crossed zero
int AC_pin1 = 4; // Output to Opto Triac
int AC_pin2 = 5;
int AC_pin3 = 6;
int AC_pin4 = 7;
int freqStep = 75; // This is the delay-per-brightness step in microseconds. It allows for 128 steps
// If using 60 Hz grid frequency set this to 65
MySensor gw;
//Tuy chinh lai
static int currentLevel1 = 128; // Current dim level...
static int currentLevel2 = 128; // Current dim level...
static int currentLevel3 = 128; // Current dim level...
static int currentLevel4 = 128; // Current dim level...
uint8_t fadeLevel1 = 128; //used to store the fade level when using the buttons
uint8_t fadeLevel2 = 128:
uint8_t fadeLevel3 = 128;
uint8_t fadeLevel4 = 128:
MyMessage dimmer1Msg(AC_pin1, V_DIMMER);
MyMessage light1Msg(AC_pin1, V_LIGHT);
MyMessage dimmer2Msg(AC_pin2, V_DIMMER);
MyMessage light2Msg(AC_pin2, V_LIGHT);
MyMessage dimmer3Msg(AC_pin2, V_DIMMER);
MyMessage light3Msg(AC_pin3, V_LIGHT);
MyMessage dimmer4Msg(AC_pin4, V_DIMMER);
MyMessage light4Msg(AC_pin4, V_LIGHT);
void setup() { // Begin setup
Serial.begin(115200);
/// - Setup Mysensors
Serial.println( SN );
gw.begin( incomingMessage, NODE_ID, true);
// Register the LED Dimmable Light with the gateway
gw.present( AC_pin1, S_DIMMER );
gw.present( AC_pin2, S_DIMMER );
gw.present( AC_pin3, S_DIMMER );
gw.present( AC_pin4, S_DIMMER );
gw.sendSketchInfo(SN, SV);
// Pull the gateway's current dim level - restore light level upon sendor node power-up
gw.request( AC_pin1, V_DIMMER );
gw.request( AC_pin2, V_DIMMER );
gw.request( AC_pin3, V_DIMMER );
gw.request( AC_pin4, V_DIMMER );
//Setup AC PIN // Set the Triac pin as output
pinMode(AC_pin1, OUTPUT);
pinMode(AC_pin2, OUTPUT);
pinMode(AC_pin3, OUTPUT);
pinMode(AC_pin4, OUTPUT);
// Set the Triac pin as output
attachInterrupt(1, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
Timer1.initialize(freqStep); // Initialize TimerOne library for the freq we need
Timer1.attachInterrupt(dim_check, freqStep); // Go to dim_check procedure every 75 uS (50Hz) or 65 uS (60Hz)
// Use the TimerOne Library to attach an interrupt
}
void zero_cross_detect() {
zero_cross = true; // set flag for dim_check function that a zero cross has occured
i=0; // stepcounter to 0.... as we start a new cycle
digitalWrite(AC_pin1, LOW);
digitalWrite(AC_pin2, LOW);
digitalWrite(AC_pin3, LOW);
digitalWrite(AC_pin4, LOW);
}
// Turn on the TRIAC at the appropriate time
// We arrive here every 75 (65) uS
// First check if a flag has been set
// Then check if the counter 'i' has reached the dimming level
// if so.... switch on the TRIAC and reset the counter
void dim_check1() {
if(zero_cross == true) {
if(i>=fadeLevel1) {
digitalWrite(AC_pin1, HIGH); // turn on light
i=0; // reset time step counter
zero_cross=false; // reset zero cross detection flag
}
else {
i++; // increment time step counter
}
}
}
void dim_check2() {
if(zero_cross == true) {
if(j>=fadeLevel2) {
digitalWrite(AC_pin2, HIGH); // turn on light
j=0; // reset time step counter
zero_cross=false; // reset zero cross detection flag
}
else {
j++; // increment time step counter
}
}
}
void dim_check3() {
if(zero_cross == true) {
if(k>=fadeLevel3) {
digitalWrite(AC_pin3, HIGH); // turn on light
k=0; // reset time step counter
zero_cross=false; // reset zero cross detection flag
}
else {
k++; // increment time step counter
}
}
}
void dim_check4() {
if(zero_cross == true) {
if(l>=fadeLevel4) {
digitalWrite(AC_pin4, HIGH); // turn on light
l=0; // reset time step counter
zero_cross=false; // reset zero cross detection flag
}
else {
l++; // increment time step counter
}
}
}
void loop() {
gw.process();
}
void incomingMessage(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;
float percent_level;
percent_level = 128 - (requestedLevel * 1.28);
fadeToLevel( percent_level );
Serial.print( "Changing level to " );
Serial.print( requestedLevel );
Serial.print( ", from " );
Serial.println( currentLevel );
// Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
// gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0));
// gw.send( dimmerMsg.set(currentLevel) );
}
}
/***
* This method provides a graceful fade up/down effect
*/
void fadeToLevel( int toLevel ) {
Serial.print("toLevel Value: ");
Serial.println(toLevel);
int delta = ( currentLevel - toLevel ) < 0 ? 1 : -1;
Serial.print("delta Value: ");
Serial.println(delta);
while ( currentLevel != toLevel ) {
currentLevel += delta;
fadeLevel= ((int)currentLevel);
delay( FADE_DELAY );
}
}
I have trouble understanding this part:
void incomingMessage(const MyMessage &message) {
if (message.type == V_LIGHT || message.type == V_DIMMER)
all 4 dimmers are type V_LIGHT and V_DIMMER
how do i get the right dimmer value from the controller from each different dimmer?
someone who can help me with the rest of the code?
thanks!
were you (someone) able to debug the 'fading' funciton in the code? i think its a problem in the while loop in the arduino/mysensors code the while loop is done, but only when the while loop is comletely through , the 'dimvalue' gets updated/changed
EDIT:
this works!
/*
AC Light Control
Uses up and down buttons to set levels
makes use of a timer interrupt to set the level of dimming
*/
#include <SPI.h>
#include <MySensor.h>
#include <TimerOne.h>
#define SN "AC Dimmer control"
#define SV "1.0"
#define NODE_ID 30 //change to a number to assign a specific ID
#define FADE_DELAY 50 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
#define FADE_PERCENTAGE 5 //The percentage the fade level will be changed when a button is pressed
volatile int i=0; // Variable to use as a counter of dimming steps. It is volatile since it is passed between interrupts
volatile boolean zero_cross=0; // Flag to indicate we have crossed zero
int AC_pin = 6; // Output to Opto Triac
int freqStep = 75; // This is the delay-per-brightness step in microseconds. It allows for 128 steps
// If using 60 Hz grid frequency set this to 65
MySensor gw;
//Tuy chinh lai
static int currentLevel = 128; // Current dim level...
uint8_t fadeLevel = 128; //used to store the fade level when using the buttons
uint8_t upPreviousValue;
uint8_t downPreviousValue;
uint8_t powerPreviousValue;
MyMessage dimmerMsg(AC_pin, V_DIMMER);
MyMessage lightMsg(AC_pin, V_LIGHT);
// =Het tuy chinh lai
void setup() { // Begin setup
Serial.begin(115200);
/// - Setup Mysensors
Serial.println( SN );
gw.begin( incomingMessage, NODE_ID, true);
// Register the LED Dimmable Light with the gateway
gw.present( 6, S_DIMMER );
gw.sendSketchInfo(SN, SV);
// Pull the gateway's current dim level - restore light level upon sendor node power-up
gw.request( 6, V_DIMMER );
//Setup AC PIN
pinMode(AC_pin, OUTPUT); // Set the Triac pin as output
attachInterrupt(1, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
Timer1.initialize(freqStep); // Initialize TimerOne library for the freq we need
Timer1.attachInterrupt(dim_check, freqStep); // Go to dim_check procedure every 75 uS (50Hz) or 65 uS (60Hz)
// Use the TimerOne Library to attach an interrupt
}
void zero_cross_detect() {
zero_cross = true; // set flag for dim_check function that a zero cross has occured
i=0; // stepcounter to 0.... as we start a new cycle
digitalWrite(AC_pin, LOW);
}
// Turn on the TRIAC at the appropriate time
// We arrive here every 75 (65) uS
// First check if a flag has been set
// Then check if the counter 'i' has reached the dimming level
// if so.... switch on the TRIAC and reset the counter
void dim_check() {
if(zero_cross == true) {
if(i>=fadeLevel) {
digitalWrite(AC_pin, HIGH); // turn on light
i=0; // reset time step counter
zero_cross=false; // reset zero cross detection flag
}
else {
i++; // increment time step counter
}
}
}
void loop() {
gw.process();
}
void incomingMessage(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;
float percent_level;
percent_level = 128 - (requestedLevel * 1.28);
fadeToLevel( percent_level );
Serial.print( "Changing level to " );
Serial.print( requestedLevel );
Serial.print( ", from " );
Serial.println( currentLevel );
// Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
// gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0));
// hek comment: Is this really nessesary?
// gw.send( dimmerMsg.set(currentLevel) );
}
}
/***
* This method provides a graceful fade up/down effect
*/
void fadeToLevel( int toLevel ) {
Serial.print("toLevel Value: ");
Serial.println(toLevel);
int delta = ( currentLevel - toLevel ) < 0 ? 1 : -1;
Serial.print("delta Value: ");
Serial.println(delta);
while ( currentLevel != toLevel ) {
currentLevel += delta;
fadeLevel= ((int)currentLevel);
delay( FADE_DELAY );
//fadeLevel = toLevel;
}
}