analogWrite with frequency on NodeMCU / ESP8266

Posted on
  • Hey folks,

    I have just received two NodeMCU boards and thanks to all the tutorials and great resources getting started with Espruino was a piece of cake - thank all of you for your efforts!

    I've managed to read IR codes sent out by various remotes using the IRReceiver module and I would like to replay them using the board and an IR LED.
    Unfortunately, however, (as it seems to me) I haven't been able to do so using analogWrite with a 38kHz frequency and digitalPulse. If I understand correctly, this is due to the lack of PWM support in Espruino for ESP8266, am I right? Although I've been using platforms like the Raspberry Pi etc. for several years, I'm quite new to the "low level stuff" and I'd just like to know, whether I got my head around this correctly.

    I guess due to Javascript's event loop nature and the required accuracy a pure JS implementation is not feasible, right?

    Possibly related (?): PWM? Anyone ever get it working? Even via peek/poke directly at control registers?

    Thanks in advance!

  • Yeah, the problem is that on ESP8266 there is no hardware PWM as far as I know. There is a hardware timer, but to make a pin change state you still need to do it using software. It means that realistically, reliable 38kHz soft PWM isn't an option right now.

    Someone could write some IR transmitter code in C, and then call it from JS like is done with the Neopixels, but it's a bit of a faff. Even with that, you can't transmit for too long or you'll interfere with WiFi/trigger the watchdog timer.

    The more sensible option is to use a microcontroller with hardware PWM on it, like the Espruino boards. I'll be releasing one with WiFi on soon now - I have hardware, there are just some software issues to sort out before I do a release.

  • Thanks for the quick reply, although that's a bit of a letdown, your announcement sounds promising ;)
    I'll definitely give it a shot, since I really like the JS programming approach.

  • Hey @Gordon, is there any update yet? AnalogWrite for 38Khz is feasible in ESP8266?

    Thanks
    Navas

  • It looked like there was a way to call code from IRQ but nobody has put any work into it as far as I know.

    Also - on ESP8266, digitalPulse is a bit of a hack - it's synchronous, whereas the 'proper' one is async. Actually getting that working properly for ESP8266 could end up being a nightmare - as I guess you want to use this for IR.

    You may:

    • be able to use SPI to emulate the bit pattern
    • be able to specify a massive Float32Array of bit times to digitalPulse, which includes all 38kHz pulses.

  • Hi
    reading the above, I see I'm not the only one with such troubles ( .. )
    I just ordered 2 Espruino WiFi to support the Espruino project, meanwhile I still wanna figure out a way to make this work on the ESP8266 platforms ( see my latest post: http://forum.espruino.com/conversations/­303540/ )

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

analogWrite with frequency on NodeMCU / ESP8266

Posted by Avatar for davdev @davdev

Actions