Code Monkey home page Code Monkey logo

dimmable-light's People

Contributors

adisbladis avatar ajmansfield avatar di-strix avatar fabianoriccardi avatar fabiuz7 avatar per1234 avatar steeltkb avatar supremesports avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dimmable-light's Issues

D7 not declared in this scope

first attempt in arduinio with 1 dimmable light for an esp32, and getting both D5 and'D7' not declared in this scope errors?
Same error in all the other examples? is it my Arduino Mac setup perhaps?

Im assuming i'm making a schoolboy error in this yet would like a hand if possible.
ta
s

Zero cross deviations

Hi,

Jus trying to get all working correct with new hardware configuration. Zero cross signal is generated by HW just before actual zero cross. Can you point where we can correct delays to make it work correctly?
Managed to delay thyristor firing just near 100procent power by changing 10000 to 12000
#ifdef NETWORK_FREQ_FIXED_50HZ
uint16_t newDelay = 12000 - (uint16_t)(((uint32_t)bri * 10000) / 255);
Otherways it jumps back at the end of previous sinewave. But cant get correct lowest power value. Thyristor closes to early, not with 1-2 procent but 7-8 att the best.
Maybe its not best way to correct this zc discrepancy, but actually looking for advice how we can correct zc hardware errors.

How to tweak the brightness => delay (linearised or not)

I would like to tweak how the delay is generated based on the level value (0-255).

I saw the polynomial equation but fail to understand where it comes from and how to tweak it.

I did a sample of all possible values with the current algorithm:

// newLevel:  |    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|   33|   34|   35|   36|   37|   38|   39|   40|   41|   42|   43|   44|   45|   46|   47|   48|   49|   50|   51|   52|   53|   54|   55|   56|   57|   58|   59|   60|   61|   62|   63|   64|   65|   66|   67|   68|   69|   70|   71|   72|   73|   74|   75|   76|   77|   78|   79|   80|   81|   82|   83|   84|   85|   86|   87|   88|   89|   90|   91|   92|   93|   94|   95|   96|   97|   98|   99|  100|  101|  102|  103|  104|  105|  106|  107|  108|  109|  110|  111|  112|  113|  114|  115|  116|  117|  118|  119|  120|  121|  122|  123|  124|  125|  126|  127|  128|  129|  130|  131|  132|  133|  134|  135|  136|  137|  138|  139|  140|  141|  142|  143|  144|  145|  146|  147|  148|  149|  150|  151|  152|  153|  154|  155|  156|  157|  158|  159|  160|  161|  162|  163|  164|  165|  166|  167|  168|  169|  170|  171|  172|  173|  174|  175|  176|  177|  178|  179|  180|  181|  182|  183|  184|  185|  186|  187|  188|  189|  190|  191|  192|  193|  194|  195|  196|  197|  198|  199|  200|  201|  202|  203|  204|  205|  206|  207|  208|  209|  210|  211|  212|  213|  214|  215|  216|  217|  218|  219|  220|  221|  222|  223|  224|  225|  226|  227|  228|  229|  230|  231|  232|  233|  234|  235|  236|  237|  238|  239|  240|  241|  242|  243|  244|  245|  246|  247|  248|  249|  250|  251|  252|  253|  254|  255|
  // newDelay1: |10000| 9961| 9922| 9883| 9844| 9804| 9765| 9726| 9687| 9648| 9608| 9569| 9530| 9491| 9451| 9412| 9373| 9334| 9295| 9255| 9216| 9177| 9138| 9099| 9059| 9020| 8981| 8942| 8902| 8863| 8824| 8785| 8746| 8706| 8667| 8628| 8589| 8550| 8510| 8471| 8432| 8393| 8353| 8314| 8275| 8236| 8197| 8157| 8118| 8079| 8040| 8000| 7961| 7922| 7883| 7844| 7804| 7765| 7726| 7687| 7648| 7608| 7569| 7530| 7491| 7451| 7412| 7373| 7334| 7295| 7255| 7216| 7177| 7138| 7099| 7059| 7020| 6981| 6942| 6902| 6863| 6824| 6785| 6746| 6706| 6667| 6628| 6589| 6550| 6510| 6471| 6432| 6393| 6353| 6314| 6275| 6236| 6197| 6157| 6118| 6079| 6040| 6000| 5961| 5922| 5883| 5844| 5804| 5765| 5726| 5687| 5648| 5608| 5569| 5530| 5491| 5451| 5412| 5373| 5334| 5295| 5255| 5216| 5177| 5138| 5099| 5059| 5020| 4981| 4942| 4902| 4863| 4824| 4785| 4746| 4706| 4667| 4628| 4589| 4550| 4510| 4471| 4432| 4393| 4353| 4314| 4275| 4236| 4197| 4157| 4118| 4079| 4040| 4000| 3961| 3922| 3883| 3844| 3804| 3765| 3726| 3687| 3648| 3608| 3569| 3530| 3491| 3451| 3412| 3373| 3334| 3295| 3255| 3216| 3177| 3138| 3099| 3059| 3020| 2981| 2942| 2902| 2863| 2824| 2785| 2746| 2706| 2667| 2628| 2589| 2550| 2510| 2471| 2432| 2393| 2353| 2314| 2275| 2236| 2197| 2157| 2118| 2079| 2040| 2000| 1961| 1922| 1883| 1844| 1804| 1765| 1726| 1687| 1648| 1608| 1569| 1530| 1491| 1451| 1412| 1373| 1334| 1295| 1255| 1216| 1177| 1138| 1099| 1059| 1020|  981|  942|  902|  863|  824|  785|  746|  706|  667|  628|  589|  550|  510|  471|  432|  393|  353|  314|  275|  236|  197|  157|  118|   79|   40|    0|
  // newDelay2: | 9984| 9837| 9695| 9557| 9425| 9297| 9173| 9054| 8939| 8827| 8720| 8617| 8517| 8421| 8329| 8240| 8154| 8071| 7992| 7915| 7841| 7770| 7702| 7636| 7573| 7512| 7454| 7397| 7343| 7291| 7241| 7193| 7147| 7102| 7060| 7018| 6979| 6941| 6904| 6869| 6834| 6802| 6770| 6739| 6710| 6681| 6654| 6627| 6601| 6576| 6552| 6529| 6506| 6484| 6462| 6441| 6420| 6400| 6380| 6361| 6342| 6323| 6305| 6287| 6269| 6251| 6234| 6216| 6199| 6182| 6165| 6148| 6131| 6114| 6097| 6080| 6063| 6046| 6029| 6012| 5995| 5977| 5960| 5942| 5925| 5907| 5889| 5870| 5852| 5834| 5815| 5796| 5777| 5758| 5738| 5719| 5699| 5679| 5659| 5639| 5618|

with the normal dimmer, here are the matching brightness values to set to be at a apecific power level (in terms of watts):

  // newDelay1:
  // 25% power: 73 (29%)
  // 50% power: 106 (42%)
  // 75% power: 146 (57%)

same for the linearised version:

  // newDelay2:
  // 25% power: 33 (13%)
  // 50% power: 95 (37%)
  // 75% power: 163 (64%)

I would like to tweak (maybe much more the second version) in order to better match the power output to the resistive load.

This would be equivalent to have a function which, depending on the value, output the right voltage value maybe.

How many separate AC channels

Hi there, can you please answer?

How many separate AC channels can be controlled on arduino mega?
And how many separate AC channels can be controlled on ESP32?

Thanks in advance.
Best regards.

Phase set feature request

Could you add a feature to set the phase of individual lights for controlling lights across different electrical phases? i.e. phase 0 for sync pin phase, and phase 1 & 2 with a 3.33 and 6.66 ms delay respectively. Many thanks

Hardware questions

Hello Fabiano, thank you so much for the time and effort put into this library, I have a question related to the avr and rp2040, witch pins (gpio) could or should I use for the zero crossing signal and for the control output?

Crash esp32 PlatfotmIO

Hello, thanks for the quality work! The problem is that at the moment the library does not work in PlatformIO, interrupt zc (pin 13) causes a crash. This issue has been asked before, but still no solution. You will do a great good deed if you deal with this problem. Your library is the only one that can provide an acceptable level of flicker.

Flickering and odd behaviour

Hi,

Trying to use this on an ESP32. Using is on a 60 watt incandesent bulb, using the basic dimmable light example code. I'm using the standard robodyne triac dimmer module.

I can't seem to get it to work correctly as its very flickery and switches on and off.

I've tried setting the frequency to 50hz (I'm in the UK) by putting this at the top of the page #define NETWORK_FREQ_50HZ, but its still the same.

Am I missing something?

Thanks,

Rob Smart

More than 8ch

I'm using three RobotDyn 4ch dimmer boards all getting their power from a MeanWell 5V 3.4A power supply. Since they're connected to the same 230V 50Hz power outlet they also all have their zero-cross connected to the Ardiuno Uno GPIO 2.

In total I have 12 channels and if I mix the channels around spread across the boards the first 8 of the list work. I tested this by putting the last not working 4 channels in the beginning of the list and vice versa. Result was that the ones that did not work worked, and the others didn't.

Now I checked the source code and changed the on line 95 in file dimmable_light.h from 8 to 12, but to no avail. Does anybody know how to raise the limit of the maximum amount of channels?

esp32 problem

I use ESP32 with a dimmer built by me similar to RobotDyn dimmer uses MOC3021 and 4N25,
everything works fine except two things:
1-when i put brightness.set(0), my bulb shows a faded light ,also my fan has a strange small noise.
2- The dimmer does not start until i pull up and put in the electricity socket a couple of times.

Excessive zero crossing pulse width

The brightness behaves strangely.
At a brightness of value 1, it already has considerable intensity.
At values close to 213, 214 decreases sharply again, leaving a very low brightness.
At 255 the brightness is fully turned on again.

It seems to be running at a frequency of 60hz, when it is set to run at 50hz. On another occasion it worked without problems, I don't know now what the problem could be.

I am using an ESP8266 Wemos mini.

I hope you can help me.

PlatformIO fails to build for RP2040 using earlephilhower core (With workaround)

Describe the bug

Building with the following platformio.ini:

[env:rp2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
lib_deps =
  fabianoriccardi/Dimmable Light for Arduino@^1.6.0

fails due to conflicts with the built-in STL, which the dimmable-light documentation recommends solving by adding

lib_compat_mode = strict

to the platform.ini file.

However...

This still fails to build with the following error:

src/main.cpp:4:10: fatal error: dimmable_light.h: No such file or directory

Running pio build with the -v flag shows the following additional information:

LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ strict
Platform incompatible library /Parlor/Lauren/Projects/LARPANet-boards/Firmware/LampDimmer/.pio/libdeps/rp2040/ArduinoSTL
Platform incompatible library /Parlor/Lauren/Projects/LARPANet-boards/Firmware/LampDimmer/.pio/libdeps/rp2040/Dimmable Light for Arduino

For some reason, this library is not counted as being compatible with this platformio configuration.

Workaround

Through some trial and error, I was able to determine that lib_compat_mode = strict needs to be removed and lib_ldf_mode = off added, giving the following working platformio.ini:

[env:rp2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
lib_deps =
  fabianoriccardi/Dimmable Light for Arduino@^1.6.0
lib_ldf_mode = off

In theory lib_ldf_mode = chain+ or lib_ldf_mode = deep+ should work since the #include <ArduinoSTL.h> is properly #ifdef'd, but it doesn't for some reason.

Version Info

  • Library version: 1.6
  • Arduino core: earlephilhower rp2040 core
  • Enviroment/IDE: PlatformIO
  • Dimmer board: N/A
  • Board: Raspberry Pi Pico

No interrupts with ESP32 Rev 0

I am using 1_dimmable_light and I am not getting any response from the output. It seems that interrupts are not working. I have tried other code to verify that the interrupts work on the pin I am using (GPIO16). My sync input is a positive pulse just over 1mS and the period is 8.3mS. (60Hz)

Can you tell me how I could narrow down the problem?

I am a hardware designer and not a programmer. My programming skills are limited, but improving. :)


#include "dimmable_light.h"

const int syncPin = 16;
const int thyristorPin = 14;

DimmableLight light(thyristorPin);

// Delay between a brightness changement in millisecond
int period = 50;

void setup() {
  Serial.begin(115200);
  while(!Serial);
  Serial.println();
  Serial.println("Dimmable Light for Arduino: first example");
  
  Serial.print("Init the dimmable light class... ");
  DimmableLight::setSyncPin(syncPin);
  // VERY IMPORTANT: Call this method to start internal light routine
  DimmableLight::begin();
  Serial.println("Done!");
}

void loop() {
  for(int i=0;i<256;i++){
    light.setBrightness(i);

//  Serial.print("level ");
//  Serial.println(i);
    delay(period);
  }
}

setBrightness(0) does nothing some times

Greetings.

It seems like setting the brightness to 0 (or using the equivalent method turnOff()) don't work in certain cases.
The scenario I am trying to deal with right now is as follow:

  • Three lights initialized using the DimmableLight class, defined as an array (code below).
  • Turning on any one light works (lights[0].setBrightness(255)).
  • Turning on a second light works (lights[1].setBrightness(255)).
  • Turning on a third light doesn't work (lights[2].setBrightness(255)). Turning off one of the two previous lights turns on this third light (lights[1].setBrightness(0) causes lights[2] to turn on).

Another simpler case:

  • Three lights initialized using the DimmableLight class, defined as an array (code below).
  • Turning on light one works (lights[0].setBrightness(255)).
  • Turning it off doesnt work (lights[0].setBrightness(0))

I am using an ESP8266 (NodeMCU v1.0 board), arduino framework. Using dimmable_lights v.1.3.0
I also tested with v1.2.0, which works, but flickering is substantial when brightness is set to 255.

Test code:

#include <Arduino.h>
#include "dimmable_light.h"

// NUMBER OF CHANNELS
#define numChannels 3

// PIN SETTINGS
const byte syncPin = 12;
const byte outPin[numChannels] = { 14, 15, 16 };

// LIGHTS SETTINGS
DimmableLight lights[numChannels] = {
  {outPin[0]},
  {outPin[1]},
  {outPin[2]}
};

void setup(void) {
  Serial.begin(115200);
  Serial.println("");

  Serial.print("Init the dimmable light class... ");
  DimmableLight::setSyncPin(syncPin);
  DimmableLight::begin();
  Serial.println("Done!");
  Serial.println(String("Number of instantiated lights: ") + DimmableLight::getLightNumber());
}

void loop(void)
{
  lights[0].setBrightness(255);
  delay(2000);
  lights[0].setBrightness(0);
  delay(2000);
}

Phase Control

Hi,

First, thanks for a great library. I have been working with an ESP32, previously Arduino, and having mixed results achieving my aims. We've actually gone down the route of moving all of the interrupt / timings to electronics via a 555 timer, transistor, moc3011 and triac (BTA16), fed from the zero cross n4525/35. The main reason, due to the limitations of arduino / interrupts hogging all the resources.

All we need to provide now is which side of the sine wave we want (a digital HIGH or LOW) and how much power (PWM). However, I really would like to get this working, considering the time I have already put into it :)

I have a niche case where I need to phase control a 20v A/C supply to provide power to a DC motor that needs to run either way depending on which half of the sine wave is chopped. I can't change the the components as I am modding an already existing setup.

I have been testing with the first example 1_dimmable_light, and have got reasonable results by flipping a flag and dropping out of zero_cross_int() on every other interrupt, here: https://github.com/fabiuz7/Dimmable-Light-Arduino/blob/90b0ce35b698eb19beb955a3353c3bf091899e0c/src/thyristor.cpp#L288 I assumed this was a good place, guessing that was the job of the definition above (#ifdef FILTER_INT_PERIOD):

image

As you can see, I am getting random out of phase triggers, and the longer the brightening goes on the more out of phase pulses I get. Yellow is the interrupt and green is the anode on the MOC.

So, I moved on to the array / timer (Thyristor::setDelay). I attempted to skip entries there, which didn't work at all.

I feel like I am nearly there but would be very grateful for any insight, I am a seasoned programmer, but with easier languages. C is really forcing me to learn properly :) I do also want to be able to choose which half of the sine wave so I can get positive or negative to the DC motor.

Thanks for your time,

Andrew.

Code changes to allow max brightness of 4095?

The samd21 chip has the ability to read and write at 12 bits. I realize such a high resolution is overkill for something like that but I am working on a project where I want to output pwm at 12 bits along with using this dimmer module. It looks like I would need to make changes in dimmable_light.h or thyristor.cpp but not sure exactly where. Any input would be appreciated. thank you

ESP32 - IRAM interrupts

I noticed that the current implementation uses non IRAM functions in the ESP32 interrupts :

void ARDUINO_ISR_ATTR startTimerAndTrigger(uint32_t delay) {
timerWrite(timer, 0);
timerAlarmWrite(timer, delay, false);
timerAlarmEnable(timer);
timerStart(timer);
}
void ARDUINO_ISR_ATTR setAlarm(uint32_t delay) {
timerAlarmWrite(timer, delay, false);
// On core v2.0.0-2.0.1, the timer alarm is automatically disabled after triggering,
// so re-enable the alarm
timerAlarmEnable(timer);
}
void ARDUINO_ISR_ATTR stopTimer() {
timerStop(timer);
}

All the interrupt code needs to be placed into IRAM to avoid long latency or crash when the flash is locked.

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/intr_alloc.html#iram-safe-interrupt-handlers

Either replace the timer functions with specific isr timer functions from timer.h:

timer_group_set_alarm_value_in_isr(...)
timer_group_set_counter_enable_in_isr(...)
timer_group_enable_alarm_in_isr(...)

or with inlined low level functions from timer_ll.h :

#define TIMER_NUM  ( 2 )
#define TIMER_HW   ( TIMER_LL_GET_HW(TIMER_NUM / SOC_TIMER_GROUPS) )
#define TIMER_ID   ( TIMER_NUM % SOC_TIMER_GROUP_TIMERS_PER_GROUP )

timer_ll_set_counter_value(TIMER_HW, TIMER_ID, 0);
timer_ll_set_alarm_value(TIMER_HW, TIMER_ID, 5000);
timer_ll_set_alarm_enable(TIMER_HW, TIMER_ID, true);

MQTT lib doesn't compile with this library

I am trying to implement mqtt and i'm are facing compilation errors for the MQTTClient.h.
I'm using the 256dpi/MQTT@^2.5.0.
The code runs fine separately for MQTT and dimmable-light but only when i combine the both it throws up compilation errors.

This is the compilation terminal that I get.

Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\new_opnt.cpp.o Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\new_opv.cpp.o In file included from include/awsconnection.h:2:0, from src/main.cpp:1: C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:158:12: error: 'std::isinf' has not been de clared using std::isinf; ^ C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:159:12: error: 'std::isnan' has not been de clared using std::isnan; ^ In file included from C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiSTA.h:28:0, from C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:32, from include/awsconnection.h:3, from src/main.cpp:1: C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.h:46:14: error: 'function' in name space 'std' does not name a template type typedef std::function<void(system_event_id_t event, system_event_info_t info)> WiFiEventFuncCb; ^ C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.h:89:29: error: 'WiFiEventFuncCb' has not been declared wifi_event_id_t onEvent(WiFiEventFuncCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX); ^ In file included from C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:37:0, from include/awsconnection.h:3, from src/main.cpp:1: C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiClient.h:42:10: error: 'shared_ptr' in nam espace 'std' does not name a template type std::shared_ptr<WiFiClientSocketHandle> clientSocketHandle; ^ C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiClient.h:43:10: error: 'shared_ptr' in nam espace 'std' does not name a template type std::shared_ptr<WiFiClientRxBuffer> _rxBuffer; ^ Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\new_opvnt.cpp.o Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\numeric.cpp.o Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\ostream.cpp.o .pio\libdeps\esp32doit-devkit-v1\ArduinoSTL\src\ArduinoSTL.cpp:79:2: warning: #warning "printf() will not be functional on this platform." [-Wcpp] #warning "printf() will not be functional on this platform." ^ Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\ostream_helpers.cpp.o Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\queue.cpp.o Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\set.cpp.o In file included from .pio\libdeps\esp32doit-devkit-v1\ArduinoSTL\src\ArduinoSTL.h:12:0, from .pio\libdeps\esp32doit-devkit-v1\ArduinoSTL\src\ArduinoSTL.cpp:1: C:\Users\Administrator\.platformio\packages\framework-arduinoespressif32\cores\esp32/Arduino.h:158:12: error: 'std::isinf' has not been de clared using std::isinf; ^ C:\Users\Administrator\.platformio\packages\framework-arduinoespressif32\cores\esp32/Arduino.h:159:12: error: 'std::isnan' has not been de clared using std::isnan; ^ In file included from include/awsconnection.h:6:0, from src/main.cpp:1: .pio/libdeps/esp32doit-devkit-v1/MQTT/src/MQTTClient.h:51:14: error: 'function' in namespace 'std' does not name a template type typedef std::function<void(String &topic, String &payload)> MQTTClientCallbackSimpleFunction; ^ .pio/libdeps/esp32doit-devkit-v1/MQTT/src/MQTTClient.h:52:14: error: 'function' in namespace 'std' does not name a template type typedef std::function<void(MQTTClient *client, char topic[], char bytes[], int length)> ^ .pio/libdeps/esp32doit-devkit-v1/MQTT/src/MQTTClient.h:61:3: error: 'MQTTClientCallbackSimpleFunction' does not name a type MQTTClientCallbackSimpleFunction functionSimple = nullptr; Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\sstream.cpp.o ^ .pio/libdeps/esp32doit-devkit-v1/MQTT/src/MQTTClient.h:62:3: error: 'MQTTClientCallbackAdvancedFunction' does not name a type MQTTClientCallbackAdvancedFunction functionAdvanced = nullptr; ^ .pio/libdeps/esp32doit-devkit-v1/MQTT/src/MQTTClient.h:114:18: error: 'MQTTClientCallbackSimpleFunction' has not been declared void onMessage(MQTTClientCallbackSimpleFunction cb); ^ .pio/libdeps/esp32doit-devkit-v1/MQTT/src/MQTTClient.h:115:26: error: 'MQTTClientCallbackAdvancedFunction' has not been declared void onMessageAdvanced(MQTTClientCallbackAdvancedFunction cb); ^ Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\stack.cpp.o Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\stdexcept.cpp.o Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\streambuf.cpp.o Compiling .pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\string.cpp.o *** [.pio\build\esp32doit-devkit-v1\lib7c4\ArduinoSTL\ArduinoSTL.cpp.o] Error 1 *** [.pio\build\esp32doit-devkit-v1\src\main.cpp.o] Error 1 ======================================================= [FAILED] Took 5.85 seconds =======================================================

`DimmableLight::getDetectedFrequency()` returns wrong value on Robodyn AC Dimmer 24A

  • v1.6.0
  • Robodyn AC Dimmer 24A
  • Inspiration from example: 8_set_frequency_automatically.ino
  • Only using ZC pin (control pin is not used)
  • France, 50 Hz, 230V
  • Board: ESP32 NodeMCU (ESP32-D0WD-V3)

My code:

DimmableLight::setSyncPin(_pin); // ZC pin of Robodyn
DimmableLight::begin();

Calling after, each 5 sec: DimmableLight::getDetectedFrequency()

Returned value is 122.

I have another ZCD module (https://www.pcbway.com/project/shareproject/120_220VAC_Opto_Isolated_Zero_Cross_Detector_Module_for_DIN_Rail_Carrier_Mount_w_57a9f83e.html) and this one works perfectly.

Note: if I set FILTER_INT_PERIOD, getDetectedFrequency () return 0 for both Robodyn and this ZCD module.

ESP32 w/OTA - Guru Meditation Error: Core 1 panic'ed. When using OTA upload while light is on.

First let me say, THANK YOU for this library build! No other library gives me such a clean output to my LED lights with my ESP32 and RobotDyn Dimmer

Okay, here is what I am experiencing. When uploading new code using the OTA web interface, it gets to 13% or so and freezes. I then had the serial port open in Arduino when I tried the web interface and noticed I get "Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed)".

This ESP32 is handling a fair amount of code and devices so I used a spare ESP32 and did some bench testing. I have it down to only the AC Dimmer, this library and the OTA library while still having the issue.

I did also figure out that if I have the light turned off, then the OTA update works fine. So for now I have been making sure I turn the light off before I send an update to it. I had also noticed after sending code over the USB connection, it would sometimes crash and restart a time or two on the first boot.

I plan to try more troubleshooting over the weekend to give more details.

use mosfet not triac

Where do i alter the software so i can use a mosfet instate of a triac.
on ZCD detect i need to set high the light pin, after time elapes the light pin needs to go low.

not hard in my opinion, but a nice to have futher.

first i go see what the output displays on my scoop.

Adafruit ESP32 Feather crash on examples

Hello, I'm trying this lib after having tried RBDDimmer on ESP32 and seeing that this one seems more promising regarding flickering issue.

I actually can't get it to work the basic examples, using an Adafruit ESP32 Feather, using output pin 12 and zerocross pin 39.

here is the output of the serial monitor :

Dimmable Light for Arduino: first example
Init the dimmable light class... Done!
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4008116e  PS      : 0x00060e31  A0      : 0x800813fa  A1      : 0x3ffbee1c  
A2      : 0x0000251c  A3      : 0x000000c7  A4      : 0x0000251b  A5      : 0x0000251c  
A6      : 0x000000c8  A7      : 0x00000000  A8      : 0x00010000  A9      : 0x00000000  
A10     : 0x00000001  A11     : 0x400811d0  A12     : 0x3ffb91f0  A13     : 0x3ffb2650  
A14     : 0x3ffc18ac  A15     : 0x3ffb91cc  SAR     : 0x00000020  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x0001001c  LBEG    : 0x40085f08  LEND    : 0x40085f13  LCOUNT  : 0xffffffff  


Backtrace:0x4008116b:0x3ffbee1c |<-CORRUPTED




ELF file SHA256: 0000000000000000

Rebooting...

Is there a list of authorized / unauthorized pins for output / zerocross ?

Thank you

Crashes on the ESP32 with SPIFFS

I am facing a crash when using SPIFFS with Library.
The SPIFFS locks the cash when used and the timer interrupts still working, So the problem happened.
I search for this problem and found a solution in ESP32 Forum It is summarized in the following:
adding DRAM_ATTR to ISR maybe fix this problem, But I can't apply it because DRAM_ATTR should apply on Static Variables Used by ISR As far as I understand.

AC 60Hz

Hello, how can I use this library on a 220v (60Hz) voltage network with an ESP32?

Problemen bij compileren programma MEGA2560

Hoi,
Wij gebruiken dimmable-light.h , met een mega 2560 R3 programma altijd gewerkt. Bij de laatste aankoop van mega2560 krijgen bij het compileren volgende boodschap.
"
Arduino: 1.8.16 (Windows 10), Board:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
In file included from C:\Users\ginovdv\Documents\Arduino\libraries\ArduinoSTL-1.3.3\src\limits.cpp:20:0:

C:\Users\ginovdv\Documents\Arduino\libraries\ArduinoSTL-1.3.3\src\limits:24:2: warning: #warning limits header is nowhere complete or accurate [-Wcpp]

#warning limits header is nowhere complete or accurate

^~~~~~~

new.cpp.o (symbol from plugin): In function `operator new(unsigned int)':

(.text+0x0): multiple definition of `std::nothrow'

libraries\ArduinoSTL-1.3.3\new_handler.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

Fout bij het compileren voor board Arduino Mega or Mega 2560

Dit rapport zou meer informatie bevatten met
"Uitgebreide uitvoer weergeven tijden compilatie"
optie aan in Bestand -> Voorkeuren.
"
Ben eindeloos, wie kan mij helpen aub?

problem with running on esp32

Hi.
the library works fine on esp8266, I haven't noticed any problems.

I wanted to use esp32 now, but it doesn't run on esp32. ESP keeps resetting when I connect ZC to any defined gpio.

ESP32 Flicker solution

Thanks for the work on this project. I can see that you expended a lot of time and effort.

When I tried your library, I noticed some flicker in a regular incandescent bulb. (I also got a compiling error because of a missing ';' in dimmable_light_linerizable.h line 62 .

While investigating a slightly different approach for an ESP32 project, I discovered that my zero crossing interrupt fired on both the rising and falling edges, even though it was set to fire on the RISING. I discovered this by measuring the interval between interrupts. Some were 8300 microseconds and some were 475 microseconds. I didn't seem to get any that were 7800.

I made the following changes to thyrister.cpp, which pretty much eliminated the flicker. This was only on a simple demo platform so I don't know if any other causes my exist.

#elif defined(ARDUINO_ARCH_ESP32)
void IRAM_ATTR zero_cross_int(){
// inserted
static unsigned long now = 0;
if(micros()-now < 1000) return;
now = micros();
//end inserted
#else

lamp wrongly dark under very specific conditions, Uno 8 lamps krida

Describe the bug

The sketch shows a bug I have seen in dimmable_lights.h

What I see is this:

If half the lamps are set to value X, and half are set to X+1,
and digitalRead() is in the sketch (even uncalled!)
then the ones set to X are displayed dark.

In this sketch I set them alternating ABABABAB, but I've
seen same behavior for AAAABBBB; likely any order.
If they're not half-and-half, the one with fewer
works ok. (or maybe one with greater, my observations
got confused)

Conditions:

Using 8 lamps on a Krida controller, on Arduino Uno
and ONLY if a digitalRead() function call is present,
even if the digitalRead() hasn't been called.

(Perhaps digitalRead() has some setup code or interrupt contention... ?)

Hardware and software used

  • Library version: 1.6.1
  • Arduino core: 1.8.6
  • Enviroment/IDE: Arduino IDE 2.2.1
  • Dimmer board: Krida 8
  • Board: Arduino UNO, the classic

Using board 'uno' from platform in folder: /Users/poly/Library/Arduino15/packages/arduino/hardware/avr/1.8.6
Using core 'arduino' from platform in folder: /Users/poly/Library/Arduino15/packages/arduino/hardware/avr/1.8.6


I'm pasting the sketch in here, apologies if that isn't the convention, this is my first github bug report! :)

/**
[email protected] 2024-02-23

This sketch shows a bug I have seen in dimmable_lights.h

What I see is this:

If half the lamps are set to value X, and half are set to X+1,
then the ones set to X are displayed dark.

In this sketch I set them alternating ABABABAB, but I've
seen same behavior for AAAABBBB; likely any order.
If they're not half-and-half, the one with fewer
works ok. (or maybe one with greater, my observations
got confused)

Conditions:

Using 8 lamps on a Krida controller, on Arduino Uno
and ONLY if a digitalRead() function call is present,
even if the digitalRead() hasn't been called.

*/

#include <dimmable_light.h> // library "Dimmable Light" 1.6

#define ALL_EIGHT_LAMPS 1 // bug happens if using 8 lamps. fewer works ok.
#define READPIN 12
#define INCLUDE_A_DIGITAL_READ 1

// the 8 pins used by the Krida 8-channel dimmer
DimmableLight dl1(11);
DimmableLight dl2(10);
DimmableLight dl3(9);
DimmableLight dl4(8);
#if ALL_EIGHT_LAMPS
DimmableLight dl5(7);
DimmableLight dl6(6);
DimmableLight dl7(5);
DimmableLight dl8(4);
#endif

void setup() {
DimmableLight::setSyncPin(3);
DimmableLight::begin();
pinMode(READPIN, INPUT_PULLUP);

Serial.begin(115200);
delay(200);
Serial.print("\n\n");
Serial.print("Dimmable Light bug with Krida 8 channel controller\n\n");
#if INCLUDE_A_DIGITAL_READ
Serial.println("digitalRead() is linked in, we see bug of half lamps off in some cases");
#else
Serial.println("no digitalRead(), all lamps appear on as desired & expected");
#endif
}

/// set lamps alternating brightnesses a and b
void setEm(uint8_t a, uint8_t b, uint16_t wait) {
Serial.print("lamps ");
Serial.print(a, HEX);
Serial.print(", ");
Serial.print(b, HEX);
Serial.println("");

dl1.setBrightness(a);
dl2.setBrightness(b);
dl3.setBrightness(a);
dl4.setBrightness(b);
#if ALL_EIGHT_LAMPS
dl5.setBrightness(a);
dl6.setBrightness(b);
dl7.setBrightness(a);
dl8.setBrightness(b);
#endif

delay(wait);
}

static int loops = 0;
void loop() {
loops++;

#if INCLUDE_A_DIGITAL_READ
// this wont actually do a read for a long, long time
// but just linking in the function seems
// to cause the four-lights-dark bug.
if(loops == 6000)
{
Serial.println("------> digital read happening! <------");
digitalRead(READPIN);
}
#endif

setEm(0x81, 0x80, 2000); // different by 1 step -- one lamp off
setEm(0x80, 0x81, 2000);
setEm(0x82, 0x80, 2000); // different by 2 steps, works ok

Serial.print(loops);
Serial.println(" completed. let's go again.");
}

Cannot compile the code for UNO or ESP8266

Hi, I am not able to compile the example code for any board. Is there an update required for this library or am I missing something. please help.
For Arduino Uno I get the following compile error :
C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\ArduinoSTL\src\del_opnt.cpp:25:56: error: 'nothrow_t' in namespace 'std' does not name a type _UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) throw() { ^~~~~~~~~ "C:\\Users\\U0031929\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\My Data\\OneDrive\\Documents\\Circuits\\Sketches\\libraries\\Dimmable_Light_for_Arduino\\src" "-IC:\\My Data\\OneDrive\\Documents\\Circuits\\Sketches\\libraries\\ArduinoSTL\\src" "C:\\My Data\\OneDrive\\Documents\\Circuits\\Sketches\\libraries\\ArduinoSTL\\src\\del_ops.cpp" -o "C:\\Users\\U0031929\\AppData\\Local\\Temp\\arduino_build_797941\\libraries\\ArduinoSTL\\del_ops.cpp.o" C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\ArduinoSTL\src\del_ops.cpp:25:50: error: 'std::size_t' has not been declared _UCXXEXPORT void operator delete(void* ptr, std::size_t) throw(){ ^~~~~~ Using library Dimmable_Light_for_Arduino at version 1.4.0 in folder: C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino Using library ArduinoSTL at version 1.1.0 in folder: C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\ArduinoSTL exit status 1 Error compiling for board Arduino Uno.

For ESP8266 I get the following errors:
C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c: In function 'hw_timer_arm': C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c:34:13: warning: 'RTC_REG_WRITE' macro is deprecated 34 | RTC_REG_WRITE(FRC1_LOAD_ADDRESS, US_TO_RTC_TIMER_TICKS(val)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c: In function 'hw_timer_init': C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c:73:13: warning: 'RTC_REG_WRITE' macro is deprecated 73 | FRC1_AUTO_LOAD | DIVDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT); | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c:76:13: warning: 'RTC_REG_WRITE' macro is deprecated 76 | DIVDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT); | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c:80:9: warning: 'hw_timer_isr_cb' is deprecated: Use IRAM_ATTR in place of ICACHE_RAM_ATTR to move functions into IRAM [-Wdeprecated-declarations] 80 | ETS_FRC_TIMER1_NMI_INTR_ATTACH(hw_timer_isr_cb); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c:50:30: note: declared here 50 | static ICACHE_RAM_ATTR void hw_timer_isr_cb(void) | ^~~~~~~~~~~~~~~ C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c:82:9: warning: 'hw_timer_isr_cb' is deprecated: Use IRAM_ATTR in place of ICACHE_RAM_ATTR to move functions into IRAM [-Wdeprecated-declarations] 82 | ETS_FRC_TIMER1_INTR_ATTACH(hw_timer_isr_cb, NULL); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ C:\My Data\OneDrive\Documents\Circuits\Sketches\libraries\Dimmable_Light_for_Arduino\src\hw_timer_esp8266.c:50:30: note: declared here 50 | static ICACHE_RAM_ATTR void hw_timer_isr_cb(void) | ^~~~~~~~~~~~~~~

jitter

hello,
Thanks for doing this. Initially, I wrote my own program. It works but I see about 350 microsecond jitter of the gate pulse. I thought it might be the digitalWrite command. So I down loaded your library. It's also working but I still see the same jitter. I am using the H11AA1 for ZC detection. The ZC pulse does not seem to have any jitter. Thoughts? thank you.

Where the unordered map comes from?

Hello,

You've used unordered_map in your library, which means that compiling it necessarily leads to an error like this:

/home/arsene/Arduino/libraries/Dimmable_Light_for_ESP/src/dimmable_light_manager.h:32:25: fatal error: unordered_map: No such file or directory
#include <unordered_map>
^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.

Could you please document which third-party library you used to get the functionality of unordered map? It doesn't seem to be neither ArduinoSTL by Mike Matera, nor Embedded Template Library by John Wellbelove, so which one should be included?

Full-wave mode implementation

I would be interested by a Full-wave mode implementation like Circuitar, in order to provide another algorithm limiting harmonic effects.

I will try to implement it.

Does not work with Wifi on ESP8266

Love this library a lot. now i meant to connect to wifi.

unfortunately when i am trying to combine it with the tzapu/WiFiManager library my (otherwise empty) project cant compile.

Using platformio, wemos d1 mini esp8266...

platformio.ini:

[env:d1_mini]
platform = [email protected]
board = d1_mini
framework = arduino

lib_ldf_mode = deep+ # for wifimanager lib
lib_deps = 
    tzapu/WiFiManager@^0.16.0
	fabianoriccardi/Dimmable Light for Arduino@^1.5.0

main.cpp:

#include <Arduino.h>
void setup(){}
void loop(){}

Error Output:

Processing d1_mini (platform: [email protected]; board: d1_mini; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Removing unused dependencies...
Library Manager: Installing fabianoriccardi/Dimmable Light for Arduino @ ^1.5.0
Unpacking  [####################################]  100%
Library Manager: Dimmable Light for [email protected] has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing ArduinoSTL
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/d1_mini.html
PLATFORM: Espressif 8266 (2.3.0) > WeMos D1 R2 and mini
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 @ 2.20601.191124 (2.6.1) 
 - tool-esptool @ 1.413.0 (4.13) 
 - tool-esptoolpy @ 1.20800.0 (2.8.0) 
 - toolchain-xtensa @ 2.40802.191122 (4.8.2)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 44 compatible libraries
Scanning dependencies...
Dependency Graph
|-- WiFiManager @ 0.16.0
|-- Dimmable Light for Arduino @ 1.5.0
Building in release mode
Compiling .pio/build/d1_mini/src/main.cpp.o
Generating LD script .pio/build/d1_mini/ld/local.eagle.app.v6.common.ld
Compiling .pio/build/d1_mini/libacb/ArduinoSTL/ArduinoSTL.cpp.o
Compiling .pio/build/d1_mini/libacb/ArduinoSTL/abi/abi.cpp.o
In file included from /Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Arduino.h:246:0,
                 from src/main.cpp:1:
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Updater.h:53:13: error: 'function' in namespace 'std' does not name a type
     typedef std::function<void(size_t, size_t)> THandlerFunction_Progress;
             ^
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Updater.h:121:19: error: expected ';' at end of member declaration
     UpdaterClass& onProgress(THandlerFunction_Progress fn);
                   ^
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Updater.h:121:56: error: expected ')' before 'fn'
     UpdaterClass& onProgress(THandlerFunction_Progress fn);
                                                        ^
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Updater.h:204:5: error: 'THandlerFunction_Progress' does not name a type
     THandlerFunction_Progress _progress_callback;
     ^
In file included from src/main.cpp:1:0:
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Arduino.h:251:12: error: 'std::isinf' has not been declared
 using std::isinf;
            ^
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Arduino.h:252:12: error: 'std::isnan' has not been declared
 using std::isnan;
Compiling .pio/build/d1_mini/libacb/ArduinoSTL/algorithm.cpp.o
            ^
Compiling .pio/build/d1_mini/libacb/ArduinoSTL/associative_base.cpp.o
Compiling .pio/build/d1_mini/libacb/ArduinoSTL/bitset.cpp.o
Compiling .pio/build/d1_mini/libacb/ArduinoSTL/char_traits.cpp.o
*** [.pio/build/d1_mini/src/main.cpp.o] Error 1
.pio/libdeps/d1_mini/ArduinoSTL/src/ArduinoSTL.cpp:79:2: warning: #warning "printf() will not be functional on this platform." [-Wcpp]
 #warning "printf() will not be functional on this platform."
  ^
In file included from /Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Arduino.h:246:0,
                 from .pio/libdeps/d1_mini/ArduinoSTL/src/ArduinoSTL.h:12,
                 from .pio/libdeps/d1_mini/ArduinoSTL/src/ArduinoSTL.cpp:1:
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Updater.h:53:13: error: 'function' in namespace 'std' does not name a type
     typedef std::function<void(size_t, size_t)> THandlerFunction_Progress;
             ^
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Updater.h:121:19: error: expected ';' at end of member declaration
     UpdaterClass& onProgress(THandlerFunction_Progress fn);
                   ^
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Updater.h:121:56: error: expected ')' before 'fn'
     UpdaterClass& onProgress(THandlerFunction_Progress fn);
                                                        ^
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Updater.h:204:5: error: 'THandlerFunction_Progress' does not name a type
     THandlerFunction_Progress _progress_callback;
     ^
In file included from .pio/libdeps/d1_mini/ArduinoSTL/src/ArduinoSTL.h:12:0,
                 from .pio/libdeps/d1_mini/ArduinoSTL/src/ArduinoSTL.cpp:1:
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Arduino.h:251:12: error: 'std::isinf' has not been declared
 using std::isinf;
            ^
/Users/heartwerker/.platformio/packages/[email protected]/cores/esp8266/Arduino.h:252:12: error: 'std::isnan' has not been declared
 using std::isnan;
            ^
*** [.pio/build/d1_mini/libacb/ArduinoSTL/ArduinoSTL.cpp.o] Error 1
======================================================================================================================= [FAILED] Took 3.02 seconds =======================================================================================================================

 *  The terminal process "platformio 'run', '--environment', 'd1_mini'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

any ideas??????

Activating filtering prevents frequency detection

  • I'd like to use frequency detection
  • I am using a Robodyn and ESP32 (so not a nice pulse), so I set semiPeriodShrinkMargin == 400

When using freq detection + filtering, semiPeriodLength == 0 so this code always makes the function return because the comparison leads to true because there is a comparison with an unsigned and signed value.

#ifdef FILTER_INT_PERIOD
    // Filters out spurious interrupts. The effectiveness of this simple
    // filter could vary depending on noise on electrical networ.
    if (diff < semiPeriodLength - Thyristor::semiPeriodShrinkMargin) { return; }
#endif

This code could be fixed like that, but the problem is that wrong "diff" could end up in the queue, so I don't really know how to fix that.

#ifdef FILTER_INT_PERIOD
    // Filters out spurious interrupts. The effectiveness of this simple
    // filter could vary depending on noise on electrical networ.
    if (semiPeriodLength && diff < semiPeriodLength - Thyristor::semiPeriodShrinkMargin) { return; }
#endif

With this fix, I can see the "wrong" detected frequencies.

It seems to me that filtering is quite linked to DimmableLightLinearized::setFrequency(), meaning as soon as we need filtering, we also need to set a frequency value we with it is good for where we are, so that filtering can work properly.

#if defined(ESP32) && defined (FILTER_INT_PERIOD)
  // https://github.com/fabianoriccardi/dimmable-light/wiki/Notes-about-specific-architectures#interrupt-issue
  Thyristor::semiPeriodShrinkMargin = 400;
#endif
  
  DimmableLightLinearized::setFrequency(ZCDConfig.getGridFrequency());
  DimmableLightLinearized::frequencyMonitorAlwaysOn(true);
  DimmableLightLinearized::setSyncPin(_pin);
  DimmableLightLinearized::begin();

ESP8266/RobotDyn

Thanks for this nice library.
Unfortunately, I doesn't seem to work for me. Everything compiles and flashes fine in the Arduino IDE. I don't seem to be getting my circuit to work. I use the ubiquitous RobotDyn 1 channel dimmer and an ESP8266 12F NodeMCU.
No light, whatever the sketch...

  • I have checked the board and the thyristor pin is operational, so is the zero cross pin (I can read values coming in using serial.read() so I assume this side is fine as well).
  • I have tried different Nodemcu boards of the same type, with the same result.
  • I have tried changing a few parameters in the thyristor.cpp file but this didn't change anything.
  • I have also tried to downgrade my Esp8266 framework version to older versions with no effect.
  • I have completely removed the Arduino IDE and downloaded the libraries again in case something was cached somewhere that would cause the issue with no success either.
    I think the timing doesn't get recognised for some reason, the cause of which I am at a loss to find.

I am using a Mac, latest OS version, the latest version of the Arduino IDE, ESP8266 Framework 2.7.4, and the current Dimmable lights code from GitHub.
Would anyone have any idea?
Many thanks

comments

There is a TriacDimmer library for AVR, which uses timer capture instead of the external interrupt. I use it in AVR version of my project, which controls a heater.

Here I have my AVR Triac control demo sketches.

For SAMD Arduino I have in my project a dimmer library for SAMD architecture.

The use of delayMicroseconds in interrupt is not good. You should set a new timer to end the pulse or use a timer wave output which creates a pulse.

I will try your library with esp8266 for esp8266 version of my heater regulator.

Arduino Nano (AVR): OK. Arduino Nano 33 iot (SAMD): flickering.

Describe the bug
When I use the Arduino Nano (AVR), the dimmer works very well, without fickering. When I use the Arduino Nano 33 iot (SAMD), there is flickering in my house mains. (I used an oscilloscope and I observe that the trigger pulse period from Arduino Nano 33 iot to the RobotDYN dimmer (TRIAC) is not always constant.) I get the same behavior whether I use [1_dimmable_light], [2_dimmable_lights] or [7_linearized_dimmable_light].

The application is a heater. See the HW and SW used below.

Hardware and software used

Arduino 1.8.19

  • Library version: [1.6.0]
  • Arduino core: [Arduino SAMD v1.8.13]
  • Enviroment/IDE: [Arduino IDE]
  • Dimmer board: [RobotDYN 2-channel]
  • Board: [Arduino Nano 33 IoT]

Selected 60Hz network frequency

THDi calculation

THDi can be calculated based on the power factor and phase angle (deplacement factor).

Since we know in the dimmer library the time when the dimmer is activated, is there a way to derive the angle to get the cosPhi ?

      // https://fr.electrical-installation.org/frwiki/Indicateur_de_distorsion_harmonique_:_facteur_de_puissance
      const float phi = 0; // TODO: find angle
      const float pf = getTotalPowerFactor();
      return sqrt(pow(cos(phi), 2) / pow(pf, 2) - 1);

Add feature to measure frequency

Hello , Thanks for Great library.
I request you to add function to measure the duration between two consecutive zero crossing interrupt and determine the frequency based on this interval.

regards

DimmableLightLinearized dim zero

If "DimmableLightLinearized" is set to zero, it still consumes ca 3% power (measured). With "DimmableLight", zero brightness means zero power. I would expect the same for DimmableLightLinearized.

Add "Count Mode" similiar to Circuitar

Dear Fabiano,

would it be possible to integrate a "Count Mode" similar as in the Circuitar Dimmer library? This is the mode that uses complete half-waves to dim. That would be very helpful.

Regards from Germany,

Johannes

Create new release

Looking through the commits there have been many fixes, impovements, and modifications over the past few years. Unfortunately the last build was in 2019. Anyone installing this from the Arduino IDE won't get the benefits of this hard work. Thanks :)

LED Flickering (9600rate)

Hi,

I've just tried your example with one light using robotdyn AC dimmer and esp8266 and I'm getting a lot of flickering.

Could it be because my board baud rate is 9600 instead of 115200?

Thank you.

Not working with MySensors

This library doesn't work with MySensor lib,
main.cpp.o (symbol from plugin): In function atexit':
(.text+0x0): multiple definition of main'

Example code
`#define MY_GATEWAY_SERIAL

#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>
#include <dimmable_light.h>
#include <Wire.h>
#include <PCF8574.h>

const int SYNC_PIN = 2;
const int AC_PIN = 3;

DimmableLight light(AC_PIN);

int brightness = 0;
int fadeAmount = 5;

byte dim1 = 0;

const int period = 1000;

void setup() {
Serial.println();
Serial.println("Dimmable Light for Arduino: second example");
Serial.println();

Serial.begin(115200);
DimmableLight::setSyncPin(SYNC_PIN);
DimmableLight::begin();
}

void loop() {
for (brightness = 0; brightness <= 100; brightness += fadeAmount) {
dim1 = (int)(brightness / 100. * 255);
Serial.println(dim1);
light.setBrightness(dim1);
delay(period);
}

// Rozjasnianie
for (brightness = 100; brightness >= 0; brightness -= fadeAmount) {
dim1 = (int)(brightness / 100. * 255);
Serial.println(dim1);
light.setBrightness(dim1);
delay(period);
}
}
`

  • Library version: everyone
  • Arduino core: 1.8.3
  • Enviroment/IDE: Arduino IDE
  • Dimmer board:
  • Board: nano

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.