A5 and A8 not independend on XIAO?!

Hi Community. I am new to Seeeduino XIAO and just received my first three units. I ordered them, because I needed a smaller alternative to a Wemos D1 mini to control several LEDs in an RC model.

I am trying to fade in and out eight LEDs independant of each other. I do the fading by setting the desired duration of the fade process, and then using millis() and setting the LED brightness according to the time elapsed.

The brightness is set by analogWrite(Pin, Brightness_between_0_and_255).

The code worked perfect on the Wemos D1 Mini.

What I discovered on the XIOA however is, that A5 and A8 seem to influence each other. No matter what brightness I write to A5, it will change the brighness of both A5 and A8 and vice versa.

I verified this by writing a sketch that sets all LEDs on the analog Pins 1,2,3,4,5,6,7, and 8 to full brightness (255) and then just repeatedly fading out and in the LED on PIN 5. However, the result ist both LEDs on Pin 5 and Pin 8 fading synchronously.

Is this supposed to be normal? All three units do the same .

Here is a video of what happens. The only LED that is controlled by my code is the one on A5.

Here is my code:

// macros for LED state
#define ON true
#define OFF false

// define LED PIN
const byte LED_PIN = A5;
bool ledState = OFF;

unsigned long fadeStartTime;

// parameters to control the effect
unsigned long FADE_IN_PERIOD = 1000; // fade in time
unsigned long ON_DURATION = 500; // time before we move to next LED
unsigned long FADE_OUT_PERIOD = 3000; // fade out time 
int brightness;

void setup() {
  // set A1through A8 as OUTPUT and to 255 brightness:
  pinMode(A1, OUTPUT);
  analogWrite(A1, 255);
  pinMode(A2, OUTPUT);
  analogWrite(A2, 255);
  pinMode(A3, OUTPUT);
  analogWrite(A3, 255);
  pinMode(A4, OUTPUT);
  analogWrite(A4, 255);
  pinMode(A5, OUTPUT);
  analogWrite(A5, 255);
  pinMode(A6, OUTPUT);
  analogWrite(A6, 255);
  pinMode(A7, OUTPUT);
  analogWrite(A7, 255);
  pinMode(A8, OUTPUT);
  analogWrite(A8, 255);
  // initialize fading
  fadeStartTime = millis();
}

void loop() {
  // only the LED on LED_PIN (=A5) is faded in and out by this code:

  unsigned long progress = millis() - fadeStartTime; 
  if (ledState == OFF)
  {
    // LED is off, we're fading out
    if (progress <= FADE_OUT_PERIOD) {
      brightness = 255 - (map(progress, 1, FADE_OUT_PERIOD, 0, 255));
    }
    else
    {
      ledState = ON;
      fadeStartTime = millis();
    }
  }
  else {
    // LED is on, we're fading in
    if (progress <= FADE_IN_PERIOD) {
      brightness = map(progress, 0, FADE_IN_PERIOD, 0, 255);
    }
    else{
      if (progress <= (FADE_IN_PERIOD + ON_DURATION)) {
        //do nothing LEDwill remain on
      }
      else
      {
         // start fade out
         ledState = OFF;
         fadeStartTime = millis();
      }
    }
  }
  analogWrite(LED_PIN, brightness);
}

Hi Hatrick, welcome to this forum,

Sorry you are having trouble with the XIAO, I have to say I really like it - it’s small, fast, has enough I/O, has one geinuine DAC and it’s not too expensive!

I am struggling a bit to follow your code, but may I suggest that you write a much simpler program just to turn on and off A5 and A8 alternately to check whether they are still affecting each other?

One thing that concerns me, I can’t exactly see from the video, but it looks as if you might be driving the LEDs directly from the XIAO outputs without a series resistor? If so, you could have damaged the hardware. I think the outputs are limited to 2mA and red LEDs have a voltage drop of around 1.8V so to limit the current to 2mA you should have series resistors of at least 750 Ohms in series with them. 2mA is enough to turn on high brightness LEDs, or if you want higher current use a transistor.

Hi, due to the resource limitation of the chip, some pins are multiplexed to achieve the function, so it will lead to the current situation. My suggestion is that the function pins (I2C SPI…) are not used as analog pins.
If you need more information please check this.