Xiao boards not powering LEDs like past Xiao boards

I have two seeeduino Xiao that I bought about a year ago, and three that I bought last week. The ones I bought last week aren’t executing the code the same as the old ones.

For example. LEDs that are supposed to strobe are simply solid and all of the LEDs are extremely dim.

I tried resetting it, no luck. I uploaded a simple digitalWrite(6, HIGH) and even with that the LED is barely on.

Any suggestions for what I should check next?

Hi Erik_Fenner,
Are your XIAOs SAMD21?
Does a simple “blink” sketch work?
What is connected to port 6?

Your problem is a bit unusual, you can first try the “blink” example, and then replace a power supply to test

The blink sketch worked which led me to define the LED pins as outputs. That fixed the brightness issue. Not sure why that wasn’t needed on the old board.

Still working out some other bugs in the program.

Here’s what I’m working on if you’re interested:

#define SWITCH_PIN 10 // input for toggle switch
#define LED_PIN 7 // output to FET module
#define FADE_INTERVAL 30 // [ms] time between fade steps
#define NEXTFADE_INTERVAL 1500 // [ms] time between fade cycles

int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
int num_presses = 0;

byte target, current; // target and current pwm value
unsigned long time_for_fadestep;
unsigned long time_for_nextfade;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers

void setup() {{
pinMode(SWITCH_PIN, INPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
Serial.begin(9600);
// set initial LED state
}}

void loop()
{
// read the state of the switch into a local variable:
int reading = digitalRead(SWITCH_PIN);

// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you’ve waited long enough
// since the last press to ignore any noise:

// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it’s been there for longer than the debounce
// delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonState) {
  buttonState = reading;

  // only toggle the LED if the new button state is HIGH
  if (buttonState == HIGH) {
    // increment our count for number of times pressed
    num_presses += 1;
    Serial.println("button is being pressed!");
  }
}

}
// save the reading. Next time through the loop, it’ll be the lastButtonState:
lastButtonState = reading;

// button hasn't been pressed yet (or has been reset)
if (num_presses == 0)
{
  	digitalWrite(4, LOW);
  	digitalWrite(5, LOW);
  	digitalWrite(6, LOW);
  	digitalWrite(7, LOW);
    Serial.println("num_presses 0");
}
// button has been pressed once!
if (num_presses == 1)
{
    digitalWrite(4, HIGH);
  	digitalWrite(5, HIGH);
    Serial.println("num_presses 1"); 
}

// button has been pressed once!
if (num_presses == 2)
{
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
Serial.println(“num_presses 2”);

if (millis() > time_for_nextfade) {
time_for_nextfade = millis() + (unsigned long)NEXTFADE_INTERVAL;
if (current == 0) {
target = 20;
}}

if (current == 20) {
target = 0;
}

if (millis() > time_for_fadestep) {
time_for_fadestep = millis() + (unsigned long)FADE_INTERVAL;
if (current < target) current+=4;
if (current > target) current-=.5;
analogWrite(LED_PIN, current);
Serial.print(target);
Serial.print(" ");
Serial.println(current);
}
}
if (digitalRead(10) == HIGH && num_presses == 2)
{
Serial.println(“num_presses 2, resetting num_presses to 0”);
num_presses = 0;
}
}

When you connect your LEDs, set the PIN to output mode to get the best results.