PWM Rgb LED on the Photon

I am trying to get an RGB Led to flash the 3 colors.
I have some code which works fine on the Core and I used pins : A5 = Red, A6 = Green, A7 = Blue

I read this post about the changes in pins

So I plug the Photon into the same breadboard and I swap the pins : A4 = Red, A5 = Green, A7 = Blue
Except now only the Blue color shows.
Is there something else I need to do? Are the names A4 / A5 invalid (I would have expected an error if so).

The pin names are still valid and these pins should still work, but as stated in the thread you linked for A4 and A5 you have to ensure that you are not using PWM (or other timer functions) on D2 and D3 at the same time.

Provided of course you have got the LED wired correctly (suitable resistors for each individual color) and the sub LEDs do still live (test with digitalWrite()).

I’m not using any other pins. This is just a breadboard with the LED and resistors.

Can you show your code and test the individual sub LEDs?

e.g. swap the working blue LED over to the “not working” pins and the not working LEDs to A7.

My code is :

#include "RgbLedControl.h"

//#define RED_LED                 A5
//#define GREEN_LED               A6
//#define BLUE_LED                A7

#define RED_LED                 A4
#define GREEN_LED               A5
#define BLUE_LED                A7

// --------------------------------------------------------------------- RGB LED
RgbLedControl rgbLed (RED_LED, GREEN_LED, BLUE_LED);

void show_color(RgbLedControl::Color color);

void setup() {

void loop() {


void show_color(RgbLedControl::Color color) {
  int delay_ms = 100;
  rgbLed.setLedColor(delay_ms, 1000, 3000, color); 

My library files are from :

It is quite strange, it looks like only the A7 pin is sending 255
I can pull out the A7 wire and light up the other 2 colors with it.

I am just uncommenting the single show_color() call that I want to show the color of for a certain amount of time.

I think the sample code with only show_color(rgbLed.BLUE); active was the worst you could have chosen to post, when you ask why do I only see blue? :wink:

Could you just try to add a WHITE setting with all three pins 255?

The funny thing with PWM 255 is that it internally is not PWMed but gets converted into a digitalWrite(HIGH) (at least this was true, last time I went through the implementation of analogWrite() before HAL).

I mean I just uncomment the GREEN and then comment out the BLUE, but Green never shows, same with RED.

I tried adding the WHITE, but it just shows as BLUE.

I thought as much, but you never know :wink:

But as it should work, the cause might be something completely different.
Could you maybe add some serial debug statements that also print out the pin numbers for R, G and B?

Red Pin is 14
Green Pin is 15
Blue Pin is 17

I guess the most likely issue is a C problem since Im pretty bad at that, but I think its a subtle problem because it works on the Core. Or possibly a timing issue since the Photon is a lot faster.

There used to be a Photon PWM issue where the PWM always got reset/retriggered when analogWrite() was called and if this happened very rapidly it could be that the pin never actually PWMed but always was HIGH or LOW.

But this issue should have been solved already (pre 0.4.4) and should not hit when you do a 255.

On the other hand, just to be sure, try to only analogWrite() when the values change.

But for a quick test - which I should have suggested a lot earlier - just try flashing this

void setup()
  analogWrite(A4, 128);
  analogWrite(A5, 128);
  analogWrite(A7, 64);
void loop() { }

The LED doesnt light up.
My system version is 0.4.4

@Rockvole, couple of things for the docs:

On the Photon, this function works on pins D0, D1, D2, D3, A4, A5, WKP, RX and TX with a caveat: PWM timer peripheral is duplicated on two pins (A5/D2) and (A4/D3) for 7 total independent PWM outputs.

NOTE: pinMode(pin, OUTPUT); is required before calling analogWrite(pin, value); or else the pin will not be initialized as a PWM output and set to the desired duty cycle.

I think my code is doing that correctly in the constructor.

Can you try

void setup()
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);

  digitalWrite(A4, HIGH);
  digitalWrite(A5, HIGH);
void loop() { }

Sorry for missing the pinMode() before, but I’ve seen that your code did it anyhow.

Just checked and this is no longer true with HAL

I tried that and red and green are lit up.

Darn! I think I have to wait till I can get my hands on my Photons again to test things direct, rather than making you to test all my ridiculous ideas :wink:

I thought you Elites would get sent wheelbarrows full of Photons :wink:

@Rockvole, your issue is driving me NUTS!!! Now, I WILL have to test this out tonight. :angry:

1 Like