Using the XIAO SD12 to blink LEDs.
Fritz of breadboard set up attached.
Coding done in Arduino IDE V 2.1.1
The code is pretty simple.
//SEEED XIAO blink sketch 240928
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(0, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(0, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(1, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}
Test One. Run code as shown.
Expected Result: Both LEDs blink.
Actual Result: Neither LEDs blink.
Test Two. Comment out 'pinMode(1, OUTPUT);'
Expected Result: Only LED 0 blinks
Actual Result: Both LEDs blink.
Test Three. Comment out 'pinMode(1, OUTPUT);' and 'digitalWrite(1, HIGH)... delay(500);' (lines 17-20)
Expected Result: Only LED 0 blinks
Actual Result: Both LEDs blink.
Test Four. Comment out 'pinMode(0, OUTPUT); (All other code as shown.)
Expected Result: Only LED 1 blinks
Actual Result: Both LEDs blink.
Test Five. Comment out 'pinMode(0, OUTPUT);' and 'digitalWrite(0, HIGH)... delay(500);' (lines 12-15)
Expected Result: Only LED 1 blinks
Actual Result: Both LEDs blink.
As the difference between the expected and actual results indicate
the outcomes are baffling.
Following up on the tests of the XIAO sketch using the Arduino IDE:
Test Six. Removed Setup and Loop for LEDs 0 & 1; Added LEDs 2 thru 10
Expected Result: Nine LEDs blink as expected.
Actual Result: Nine LEDs blink as expected.
Test Seven. Sketch coded for LEDs 2 thru 10; added Setup for LEDs 0 & 1
Expected Result: Nine LEDs blink as expected.
Actual Result: Nine LEDs blink as expected.
Test Seven. Sketch coded for LEDs 2 thru 10; added Setup and Loop for LEDs 0 & 1
Expected Result: Eleven LEDs blink.
Actual Result: Nine LEDs blink. LEDs 0 and 1 do not blink
This is a video of the nine LEDs oscillating.
Video link
So the conclusion is there is something odd about pins 0 and
1 on the XIAO SD12. Have scoured the SEEED site for some
sort of answer to no avail. And SEEED Studio is not very
responsive to queries in this matter.
If somebody has any knowledge or insight it would be
most appreciated.
I don't think so.
Anyway, I ran your first sketch on my Xiao SAMD21 (most likely candidate!) and it works "as expected." Could you have shorted pins 0 and 1 when adding the header pins?
One thing to beware of is that AVRs had a behavior that digitalWrite(PIN, HIGH) when the pin was in INPUT mode would enable the pull-up resistors, and most subsequent cores (including Seeed's SAMD) have tried to maintain this behavior (at significant performance cost. Sigh.)
And pins default to INPUT mode.
So if you leave out the pinMode() calls, you'll end up switching pins from high impedance ("off", or "input" mode) and "internal pullup" (slightly HIGH.) With modern high-brightness LEDS, this is likely to result in a visible but lower-brightness "blink."
(note that these LEDs have built in resistors.)
(This assumes that when you say "both LEDs blink", you mean that the blink consecutively as requested by the code, not simultaneously. )
Sorry 'bout the confusion caused by the typos on the name of the
microcontroller. westfw is correct. The name is XIAO SAMD21.
In my defense the name has changed. It was once called
Seeeduino XIAO.
The name is important because if we are talking about two
different MCs the specs and datasheets would be different.
And westfw was also insightful:
'Could you have shorted pins 0 and 1 when adding the header pins?'
The XIAO SAMD21 can be purchased with or without the
header pins installed. Was pretty sure the unit tested
had factory-installed headers. But working on westfw's
hunch an inspection of the header solders revealed a solder
bridge. Not sure if the bridge came from the factory or from me,
but anyway, removed the bridge and now Test Seven from Post#2
above works as expected. That is, all eleven LEDs oscillate
as programmed.
Finally, although it is pretty well proven that the defect was
hardware, not software, since Mr. Westfield was generous enough
to provide the excellent Sketch with an Array, the code was downloaded,
compiled and uploaded to the unbridged XIAO SAMD21.
The Sketch with an Array abridges the code from 74 to 15 lines.
A test of the Sketch with an Array ran as expected except
D5 oscillated twice and D6 did not operate at all. Looks
like D5 was duplicated in the array exposition. Easy fix.
Well 'Finally' was written but a question remains.
The Sketch with an Array begins with
'#include <Arduino.h>'
From what is seen in the research on that library
things are a bit divided. Some say it is necessary to get access to
a host of routines, methods and definitions to make
a sketch run smoothly.
The Sketch with an Array was run with the include
commented out and the test ran normal.
Others say the Arduino library is necessary but not if
the sketch is being compiled in the Arduino IDE. The library
is necessary if the sketch is being compiled in other IDEs,
such as VS Code/Platformio or eclipse.
But it is only one line so maybe it's no big deal.
Yeah. "Xiao" has become a "form factor" with a number of different CPU chips, much like "Nano" or "Feather." Neat, but potentially confusing (and Adafruit calls theirs "QT Py xxx"...)
since Mr. Westfield was generous enough to provide the excellent Sketch with an Array
The Arduino IDE will automatically #include <Arduino.h> for your .ino files. You'll need to add it yourself if you add .cpp files to your project (beginners probably shouldn't do that!) I can't speak for "other IDEs" - there are too many of them to generalize!