Problem with PWM and IRremote on ESP8266

sunshine_bunnygirl17
Posts: 1
Joined: Thu Aug 17, 2023 8:46 pm

Problem with PWM and IRremote on ESP8266

Postby sunshine_bunnygirl17 » Thu Aug 17, 2023 8:59 pm

Hello,

I have encountered a problem in my code for ESP8266 (NodeMCU), it's a code that uses IR transmitter to control a diode at the desired PWM level.
  1. void setup() {
  2. pinMode(D1, OUTPUT); //LED
  3. pinMode(D2, INPUT); // TSOP1738
  4. }
  5.  
  6. void loop() {
  7. if (IrReceiver.decode()) {
  8. switch (IrReceiver.decodedIRData.decodedRawData) {
  9.  
  10. case 1935591058:
  11. x +=y;
  12. analogWrite(D1, x);
  13. break;
  14.  
  15. case 7520486194:
  16. x -=y;
  17. analogWrite(D1, x);
  18. break;
  19.  
  20. }
  21. IrReceiver.resume();
  22. }
  23. Serial.println(x);
  24. delay(100);
  25. }
The code is actually much longer and this is just a truncated snippet, but independent of this fact, the problem is that in order for the IR signals to be received, a PWM signal must not be generated. (Nowhere must the analogWrite(); function be run).

Once I comment out all analogWrite(); functions, the program accepts all signals and the value of x changes depending on the signal received. If the analogWrite(); function is present, IR signals are received until the analogWrite(); function is run.

I tried connecting the diode to all PWM pins, it behaves the same everywhere. I have also tried TSOP1738 on A0. No change.

On the AVR the same code works without problems. Why don't I use the AVR? Because it doesn't have PWM with 10bit resolution.

I have absolutely no idea how to solve this problem. Do you have a solution?

Second question, if this problem can't be solved with the conclusion that you simply can't receive IR signals and generate PWM at the same time on the ESP8266 board while you can on the AVR, will an I2C expander (e.g. PCA9685) solve this problem ?

Thank you!

Who is online

Users browsing this forum: No registered users and 15 guests