[Resolved]-Noob - Understanding Pins - Please Help

Hey folks,

I cannot seem to figure out why only the A3 pin is allowing me to output a value between 0-4095 and actually doing what I expect. All the other pins (A0-A5) do not output any voltage and as a result obviously do not light the LED.

I added the base code below. If I change the variable “ledPin” to any of the other analog pins 0-5 (other than A3) I get nothing.

According to the Photon datasheet A0-A7 should 12-bit GPIOs (among other things)…

int ledPin = A3;
int val = 0;
bool goingUp = true;

int brighten(int curVal){
  return curVal + 20;
}

int darken(int curVal){
  return curVal - 20;
}

void setup(){
  pinMode(ledPin, OUTPUT);
}

void loop(){
  Serial.begin();
  if (goingUp) {
    if (val > 4045) {
      goingUp = false;
    }
    val = brighten(val);
  } else {
    if (val < 2400) {
      goingUp = true;
    }
    val = darken(val);
  }
  analogWrite(ledPin, val);
  Serial.println(val);
  delay(10);
}

There are PWM pins and DAC pins.
A3 and A6 (aka DAC) are the only two pins with real DAC capability.

But the docs about analogWrite() are quite clear about the how and why.
https://docs.particle.io/reference/firmware/photon/#analogwrite-pwm-
vs.
https://docs.particle.io/reference/firmware/photon/#analog-output-dac-

And to actually dim an LED you do want to use PWM pins.

The 12bit analog capability of the pins A0~A7 (A6=DAC / A7=WKP) on the other hand only applies to analogRead() (=ADC)
https://docs.particle.io/reference/firmware/photon/#analogread-adc-

2 Likes

YES! Thank you @ScruffR, that’s exactly what I needed. I was buried in the docs but just didn’t read far enough down to get the link to the DAC piece. Thanks so much.

For anyone else that finds this thread, note that the code above is a DAC example and the code below is a PWM example. Differences are PWM PIN and PWM only steps from 0-255 not 0-4095 like DAC does.

int ledPin = D0;
int val = 0;
bool goingUp = true;

int brighten(int curVal){
  return curVal + 3;
}

int darken(int curVal){
  return curVal - 3;
}

void setup(){
  pinMode(ledPin, OUTPUT);
}

void loop(){
  Serial.begin();
  if (goingUp) {
    if (val > 255) {
      goingUp = false;
    }
    val = brighten(val);
  } else {
    if (val < 0) {
      goingUp = true;
    }
    val = darken(val);
  }
  analogWrite(ledPin, val);
  Serial.println(val);
  delay(10);
}
1 Like

Thanks for the help @ScruffR!