• Hello,

    I'm having some trouble getting infrared to correctly transmit from the Pico. Using the same PWM data (microseconds) and components I'm able to see it working using an arduino.

    The Pico is running 1v87 and I was unable to get the Pico infrared example transmitting (receiving is working and also reads the same values as the arudino).

    Minimal arduino sketch based on Arduino-IRremote

    [#include](https://forum.espruino.com/search/?q=%23include) <Arduino.h>
    
    [#define](https://forum.espruino.com/search/?q=%23define) SYSCLOCK  16000000
    [#define](https://forum.espruino.com/search/?q=%23define) IR_USE_TIMER2 
    
    unsigned int powerOn[] = { 
      3502,
      1750,
      etc...
      0
    };
    
    void setPwmFrequency(int khz) {
      const uint8_t pwmval = SYSCLOCK / 2000 / (khz); 
      TCCR2A = _BV(WGM20); 
      TCCR2B = _BV(WGM22) | _BV(CS20); 
      OCR2A = pwmval; 
      OCR2B = pwmval / 3;
    }
    
    void enablePwm() {
      (TCCR2A |= _BV(COM2B1));
    }
    
    void disablePwm() {
      (TCCR2A &= ~(_BV(COM2B1)));
    }
    
    void sendCommand(unsigned int command[], unsigned int size) {
      for (signed int i = 0; i < size - 1; i = i + 2) {
        enablePwm();
        delayMicroseconds(command[i]);
        disablePwm();
        delayMicroseconds(command[i + 1]);
      }
      disablePwm();
    }
    
    void setup() {
      pinMode(9, OUTPUT);
      digitalWrite(9, LOW); 
      setPwmFrequency(35);
    }
    
    void loop() {
      signed int size = sizeof(powerOn)/sizeof(int);
      sendCommand(powerOn, size);
      delay(5000);
    }
    

    Pico code

    function toMillis(i) {
       return i / 1000;
    }
    
    var powerOn = [
      3502,
      1750,
      etc...
      0
    ].map(toMillis);
    
    analogWrite(A5, 1, {freq:35000});
    digitalPulse(A6, 1, powerOn);
    digitalPulse(A6, 1, 0);
    analogWrite(A5, 0, {freq:35000}); // without this the IR LED never turns off
    

    Unfortunately I don't have an oscilloscope at hand to see what A5/A6 are actually outputting :(
    Am I missing something obvious?

    Thanks!

About

Avatar for Adam @Adam started