PWM on Pin36 on 4.1

Status
Not open for further replies.

jmkdouglas

New member
I am trying to use pin 36 as a PWM, and created the sample code below. The load2Servo.attach() method will return '0' based on the macro digitalPinHasPWM() in pins_arduino.h that does not allow pin 36. The Teensy 4.1 card shows that Pin 36 is useable for PWM. Can anyone tell me if I'm making a mistake, or if there is an error with pin 36?


Code:
#include <Arduino.h>
#include <PWMServo.h>
PWMServo load2Servo;
void setup() {
  Serial.begin(115200);
  delay(5000);
  int success2 = load2Servo.attach(36, 1000, 2000); 
  if (!success2){ Serial.println("load ESC servo 2 attach failed");  }
  if (success2) { Serial.println("load ESC servo 2 attach success"); }
}
void loop() {
  // put your main code here, to run repeatedly:
}

I'm using VSCode and PlatformIO, but I tried the code above directly in Arduino IDE as well.
 
I copied and pasted your code and ran on Arduino and configured for T4.1
and it worked for me.
screenshot.jpg
 
Thanks for looking. I see that pins_arduino.h has been updated to fix this problem as of two months ago at
https://github.com/PaulStoffregen/cores/blob/master/teensy4/pins_arduino.h.

I thought I had re-installed the latest TeensyduinoInstall.linux64, but whatever my Arduino IDE is pointing to must have the old version still. Manually correcting the PlatformIO library fixes the problem when compiling from VSCode. I can't figure out where the teensy library is for Arduino IDE on linux, but I don't really need that to work, so I'm calling this solved.
 
Status
Not open for further replies.
Back
Top