XIAO - are pin 4 and pin 10 electrically connected? 100% reproduced on 3 boards

Hi, dear forum,

I can not believe, but either I have 3 buggy boards, or the problem is really systematic:

if you run the code:

void setup() {
  // put your setup code here, to run once:
  pinMode(4, OUTPUT);
  pinMode(10, OUTPUT);

//10 and 5 as well as 5 and 8

  analogWrite(4, 0);
  analogWrite(10, 255);
  lastMs = millis();

void loop() {

and measure the output on the pin 4, guess what you get? - PWM signal of 255
digitalWrite() works just fine.

the same situation is observed with the pins 5 and 8. Tested on 3 boards already :frowning:

I would be really thankful for any idea or a work around.

best wishes

Hello, which XIAO is it?

it is Seeeduino Xiao chip: “Seeeduino XIAO, Arduino Microcontroller, SAMD21 Cortex M0+”
this one: Seeeduino XIAO, Arduino Microcontroller, SAMD21 Cortex M0+, vorgelötet | Seeeduino XIAO, Arduino Microcontroller, SAMD21 Cortex M0+, vorgelötet | Kompatible Boards | Arduino | Dev. Boards | BerryBase

Is pin 4 a PWM pin? The original Arduino Uno for example only has PWM pins with number 3,5,6,9,10,11 - pin 4 is not a PWM pin.

Hi bernie0815,
the spec says that all pins are pwm.
The funny thing is that if I comment out one line, e.g.
//writePWM(10, dim);
then pin 4 works just fine. So I assume a hardware/software bug on pin 4.

i have located the problem - it looks like the pins 4 and 10 as well as 5 and 8 are electrically connected. I have adjusted the description of the issue above.

You have not assigned anything to pins 5 and 8, so they are floating (default is Input at High Impedance). Due to unknown paths in the chip, floating pins may or may not drift to particular values, which may (or, maybe, not) be influenced by what’s going on in nearby pins… Or they may “wander” from time to time.

Bottom line: you can’t depend on unassigned pins having any particular value.

Try the following.
Note that the DC values are nominal, assuming the 3.3V regulator gives exactly 3.3 Volts. On the XIAO that I used for this test, it’s 3.40, so the values on the meter are proportionally higher.

// PWM Test Code for SeeedStudio XIAO
// davekw7x
// February, 2022

    If you have a 'scope:            If you have a DC Voltmeter

    Pin   PWM Duty Cycle                 Pin    Voltage
   ----------------------                ---------------
    4        0.2                          4       0.66
    5        0.4                          5       1.31
    8        0.6                          8       1.97
   10        0.8                         10       2.63
void setup()

  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(10, OUTPUT);

  analogWrite(4, 51);
  analogWrite(5, 102);
  analogWrite(8, 153);
  analogWrite(10, 204);
  //lastMs = millis(); // What the heck is this supposed to do: It's not defined in your code.

void loop() 

Note, also, that the code you posted isn’t what you actually tested. (It won’t compile, due to the undefined variable lastMs.)

If you have further problems, it might be easier to get help if you paste your entire, exact sketch.



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

Citric (and O.P.) You’re right; I’m wrong. My testing was hurried and sloppy.

With a little more care, here’s what I found:
If you analogWrite(4,…) then analogWrite(10,…), the value written to 10 appears on both 4 and 10
If you analogWrite(10,…) then analogWrite(4,…) the value written to 4 appears on both 4 and 10

Similarly for 5 and 8.

Sorry about my previous conclusion.



my tests show that the following pins seems to be “PWM safe” :slight_smile:
1, 2, 3, 4, 5, 9

What does this mean?