Cant control L298n and Ac Light Dimmer in same time on nodemcu esp8266

Excuse me everyone, i have a trouble with my IoT project, i have L298n Module to control my Fan speed and Ac Light Dimmer Module(robotdyn) to control my Light Intensity in nodemcu esp8266. I cant control two modules in same time, when i set value of l298N my fan is on but the AC light Dimmer is off. please anyone help me, sorry for my bad english

this is my code

#include <RBDdimmer.h>//
#define outputPin  12 //D6
#define zerocross  14 //D5

dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer

//define pin L298N
int ENA = D1;
int IN1 = D2;

void setup() {
//pinMode L298N
  pinMode(IN1, OUTPUT);
  pinMode(ENA, OUTPUT);
  digitalWrite(IN1, HIGH);

  //Dimmer initialisation
  dimmer.begin(NORMAL_MODE, ON);
}

void lamp() {
  dimmer.setPower(80);
}


void fan() {
  int pwm = 900;
  digitalWrite(IN1, HIGH);
  analogWrite(ENA, pwm);
}

void loop() {
  lamp();
  fan();
}

The best thing you can do to help us is post the Schematic, not a frizzy drawing. Include a linked parts list and the schematic should show all connections, including power and ground. What are the power sources?

Pretty good chance that the RBDdimmer.h library uses the same timer as the software PWM on the ESP (swPWM is all it has) There aren't that many timers available on an ESP. Anyway, with a bit of help from google, yes PWM disables timer1 which is the timer being used by RBDDimmer So, even though i also want to see the schematic just to verify all is OK (it is possible that there are more causes) You have a software issue. I saw a PWM that uses timer1 specifically, but that is obviously not going to work. My suggestion is that instead of using the RBDdimmer library that uses a timer, you 'poll' for elapsed time (after the zero-cross) instead. On the other hand, this will only work fine until you start to set up something like a webserver on the same board, are you planning to do that ?

Since there really is only 2 timers on an ESP8266 i just had another idea. How about just adding a bit of code to 'void ICACHE_RAM_ATTR onTimerISR()' inside of RBDdimmer.h to take care of the PWM signal. You will be limited to the frequency used by the RBDdimmer, and you will also have to declare a variable and a function to modify it (it's not a beginners project), but it would safely resolve your issue.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.