-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.tex
5215 lines (4171 loc) · 217 KB
/
index.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
%
\documentclass[
letterpaper,
DIV=11,
numbers=noendperiod]{scrreprt}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
% xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{5}
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{241,243,245}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.40,0.45,0.13}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\ExtensionTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.28,0.35,0.67}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.46,0.62}{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\NormalTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.07,0.07,0.07}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\KOMAoption{captions}{tableheading}
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{bookmark}{}{\usepackage{bookmark}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
\renewcommand*\contentsname{Table of contents}
\else
\newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
\renewcommand*\listfigurename{List of Figures}
\else
\newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
\renewcommand*\listtablename{List of Tables}
\else
\newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
\renewcommand*\figurename{Figure}
\else
\newcommand\figurename{Figure}
\fi
\ifdefined\tablename
\renewcommand*\tablename{Table}
\else
\newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\makeatletter
\@ifpackageloaded{tcolorbox}{}{\usepackage[skins,breakable]{tcolorbox}}
\makeatother
\makeatletter
\@ifundefined{shadecolor}{\definecolor{shadecolor}{rgb}{.97, .97, .97}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\makeatother
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
pdftitle={XIAO: Big Power, Small Board},
pdfauthor={Lei Feng, Marcelo Rovai},
colorlinks=true,
linkcolor={blue},
filecolor={Maroon},
citecolor={Blue},
urlcolor={Blue},
pdfcreator={LaTeX via pandoc}}
\title{XIAO: Big Power, Small Board}
\usepackage{etoolbox}
\makeatletter
\providecommand{\subtitle}[1]{% add subtitle to \maketitle
\apptocmd{\@title}{\par {\large #1 \par}}{}{}
}
\makeatother
\subtitle{Mastering Arduino and TinyML}
\author{Lei Feng, Marcelo Rovai}
\date{2023-12-08}
\begin{document}
\maketitle
\ifdefined\Shaded\renewenvironment{Shaded}{\begin{tcolorbox}[sharp corners, interior hidden, borderline west={3pt}{0pt}{shadecolor}, frame hidden, enhanced, breakable, boxrule=0pt]}{\end{tcolorbox}}\fi
\renewcommand*\contentsname{Table of contents}
{
\hypersetup{linkcolor=}
\setcounter{tocdepth}{2}
\tableofcontents
}
\bookmarksetup{startatroot}
\hypertarget{preface}{%
\chapter*{Preface}\label{preface}}
\addcontentsline{toc}{chapter}{Preface}
\markboth{Preface}{Preface}
From the expansive boards of the past, Arduino has come a long way and
entered the Seeed Studio XIAO series: thumb-sized yet power-packed,
opening a vast horizon for innovation. ``XIAO: Big Power, Small Board''
dives deep into these capabilities, guiding readers from the basics of
Arduino to intricate miniaturized projects. Whether readers want to
illuminate an LED or delve into Embedded Machine Learning (TinyML) with
XIAO boards and Edge Impulse Studio, this book covers them. Need for
prior knowledge? No worries! This book takes a hands-on, project-based
approach, ensuring readers grasp the concepts while implementing them.
By the end, they will be adept with XIAO and inspired by many
user-created projects showcasing the endless possibilities this small
board offers.
\bookmarksetup{startatroot}
\hypertarget{acknowledgments}{%
\chapter*{Acknowledgments}\label{acknowledgments}}
\addcontentsline{toc}{chapter}{Acknowledgments}
\markboth{Acknowledgments}{Acknowledgments}
We want to express our sincere gratitude to Jiamou Yang, Yanming Wen,
Mengdu Li, Chunchun Tian, Haixu Liu, Tianrui Wang, and Jianjing Huang
for their invaluable technical support and manuscript revisions. This
book would not have been possible without their contributions.
We extend our deepest gratitude to the entire TinyML4D Academic Network,
comprised of distinguished professors, researchers, and professionals.
Notable contributions from Marco Zennaro, Brian Plancher, José Alberto
Ferreira, Jesus Lopez, Diego Mendez, Shawn Hymel, Dan Situnayake, Pete
Warden, and Laurence Moroney have been instrumental in advancing our
understanding of Embedded Machine Learning (TinyML).
Special commendation is reserved for Professor Vijay Janapa Reddi of
Harvard University. His steadfast belief in the transformative potential
of open-source communities, coupled with his invaluable guidance and
teachings, has served as a beacon for our efforts from the very
beginning.
Acknowledging these individuals, we pay tribute to the collective wisdom
and dedication that have enriched this field and our work.
\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}
Illustrative images on the e-book and chapter's covers generated by
OpenAI's DALL-E via ChatGPT
\bookmarksetup{startatroot}
\hypertarget{introduction}{%
\chapter*{Introduction}\label{introduction}}
\addcontentsline{toc}{chapter}{Introduction}
\markboth{Introduction}{Introduction}
The Seeed Studio XIAO series represents a groundbreaking evolution in
the Arduino ecosystem, merging compactness with powerful performance.
Understanding and harnessing its capabilities are essential for any
enthusiast or professional in electronics and machine learning. With the
rapid progression of technology and the increasing demand for smaller,
more efficient devices, mastering XIAO and its integration with TinyML
is crucial. It presents a new frontier for innovation, allowing the
creation of sophisticated projects in spaces previously thought
impossible. This topic is paramount as it aligns with the future
trajectory of electronics, IoT, and machine learning, making it
indispensable for those aiming to stay at the forefront of technological
advancements.
\bookmarksetup{startatroot}
\hypertarget{about-this-book}{%
\chapter*{About this Book}\label{about-this-book}}
\addcontentsline{toc}{chapter}{About this Book}
\markboth{About this Book}{About this Book}
\hypertarget{audience}{%
\section*{Audience}\label{audience}}
\addcontentsline{toc}{section}{Audience}
\markright{Audience}
The primary audience for ``XIAO: Big Power, Small Board'' encompasses
hobbyists, students, educators, and professionals in electronics and
machine learning who want to explore and maximize the potential of
compact hardware platforms. Typically, these readers might hold
positions as electronics enthusiasts, DIY project creators, electronics
educators, or even junior embedded system developers. As they advance in
their careers, they might be eyeing roles such as electronics design
engineers, IoT developers, or machine learning hardware integrators.
Our audience possesses a basic understanding of electronics concepts but
may have yet to delve deep into Arduino programming or compact hardware
design. They likely have encountered standard beginner books on Arduino
or general electronics but might have yet to venture into specialized
hardware or TinyML. As for skills, they have some hands-on experience
with basic electronics or programming but haven't mastered the
intricacies of TinyML or advanced microcontroller functionalities.
\hypertarget{what-readers-will-learn}{%
\section*{What readers will learn}\label{what-readers-will-learn}}
\addcontentsline{toc}{section}{What readers will learn}
\markright{What readers will learn}
By the end of this book, the reader will understand:
\begin{itemize}
\item
The fundamentals of open-source hardware, focusing on the capabilities
of the Seeed Studio XIAO series.
\item
How to transition from basic to advanced electronic projects, starting
with simple LED controls and advancing to complex applications like
telemetry and voice keyword detection.
\item
The concepts behind prototype design and its practical implications in
product development.
\item
The intricacies of integrating various modules like the infrared
receiver, ultrasonic distance sensor, and RTC clock with the XIAO
platform.
\item
The significance and application of Tiny Machine Learning (TinyML),
emphasizing its transformative power in hardware like the XIAO
nRF52840 Sense and ESP32S3 Sense.
\item
Techniques to utilize advanced tools such as Edge Impulse Studio for
real-world applications like anomaly and object detection and video or
sound classification.
\end{itemize}
The reader will be able to:
\begin{itemize}
\item
Set up, program, and troubleshoot projects across all XIAO series
boards, advancing from basic hardware interactions to intricate
project designs.
\item
Convert abstract ideas into tangible electronic product prototypes,
leveraging the insights from the course.
\item
Design and implement intermediate-level projects such as a Smart Watch
and Air Piano using specialized sensors and modules.
\item
Harness the power of Wi-Fi and MQTT protocols with XIAO ESP32C3 for
cloud communications and data exchange.
\item
Deploy TinyML on different XIAO boards, executing tasks like image,
motion, and sound classification besides anomaly and object detection.
\item
Innovate and extend project ideas, drawing inspiration from a curated
collection of XIAO projects and adapting them for custom needs.
\end{itemize}
\hypertarget{software-dependencies}{%
\section*{Software dependencies}\label{software-dependencies}}
\addcontentsline{toc}{section}{Software dependencies}
\markright{Software dependencies}
\begin{itemize}
\item
\textbf{Arduino IDE}: Major updates or changes to the Arduino IDE
might affect content related to Arduino development and programming in
the book.
\item
\textbf{Seeed Studio XIAO Libraries}: Updates to libraries specific to
the XIAO series can influence the projects or example codes provided.
\item
\textbf{Edge Impulse Studio}: Significant updates or feature changes
on this platform would necessitate adjustments in the TinyML chapters.
\item
\textbf{MQTT Libraries/Protocols}: Any changes related to MQTT
libraries or the protocol itself could influence the content of
telemetry and commands.
\item
\textbf{ESP32 Libraries}: Updates to libraries used by the XIAO
ESP32C3 and ESP32S3 board may impact associated projects or examples.
\end{itemize}
\hypertarget{book-outline}{%
\section*{Book outline}\label{book-outline}}
\addcontentsline{toc}{section}{Book outline}
\markright{Book outline}
\begin{itemize}
\item
\textbf{Chapter 1: Introduction to Hardware and Programming} In this
chapter, readers start with basic programming on XIAO using Arduino
IDE. Through simple example programs, they will learn to control LED
lights, buttons, buzzers, and other electronic components, mastering
core programming concepts like digital I/O, analog I/O, tone
generation, and mapping values. By manually typing out code examples
line-by-line, they will develop strong coding habits and grasp
programming syntax.
\item
\textbf{Chapter 2: Project Practice for Beginners - Introduction to
Prototype Design} In this chapter, readers will learn the basics of
designing prototypes with XIAO through beginner-friendly projects.
They will start from an idea and quickly create a verification
prototype, focusing more on the practical application of code rather
than line-by-line analysis. By leveraging Arduino libraries, community
resources, and example programs, they will learn how to find and adapt
code snippets to achieve desired effects efficiently. Furthermore,
they will explore how to design the physical appearance of prototypes
by creatively combining electronic hardware with everyday items. The
key outcomes are grasping a project-based approach and developing
skills to build simple interactive prototypes.
\item
\textbf{Chapter 3: Intermediate Project Practice---Complex Projects}
In this chapter, readers will advance their prototyping skills by
creating sophisticated IoT projects with XIAO. They will implement
features like Wi-Fi connectivity, MQTT telemetry, and remote control
commands using the XIAO ESP32C3. Through complex builds like an
intelligent remote door, smartwatch, and air piano, you will hone
programming techniques for wireless communication, cloud integration,
and embedded control. Optional blueprints will be provided, but
readers are encouraged to explore creative enclosure designs with
alternative materials. The key outcomes are mastering intermediate IoT
prototyping and preparing for advanced tinyML applications.
\item
\textbf{Chapter 4: Project Practice Advanced - tinyML Application}
Among the XIAO series products, the Seeed Studio XIAO nRF52840 Sense
has Bluetooth 5.0 wireless connectivity, low power consumption, and
comes with onboard 6-axis IMU and PDM microphone sensors. The XIAO
ESP32S3 Sense further integrates a camera, digital microphone, and SD
card support. Those features make them powerful tools for TinyML
(Embedded Machine Learning) projects. TinyML solves problems in a
completely different way from traditional programming methods. This
chapter will introduce readers to this cutting-edge field by walking
through the entire machine-learning workflow from data collection,
training, and testing to deployment and inference using the Edge
Impulse Studio tool.
\item
\textbf{Chapter 5: Creative Experiments} Since its launch, the Seeed
Studio XIAO series has been widely acclaimed for its compact size,
powerful performance, and versatile product range. The maker community
has produced a large number of projects created with XIAO. Due to
space constraints, we have selected some outstanding projects made
with XIAO by our makers. These projects fully demonstrate the powerful
functions and wide applications of XIAO. Let us follow the makers'
steps, stimulate creativity, and explore the endless possibilities of
XIAO. Readers can draw inspiration from these projects, use
imagination, and explore new territories with XIAO.
\end{itemize}
\bookmarksetup{startatroot}
\hypertarget{introduction-to-hardware-and-programming}{%
\chapter{Introduction to Hardware and
Programming}\label{introduction-to-hardware-and-programming}}
In this unit, we will enter the world of electronics and programming and
explore how to control hardware through code. Starting with the example
program, Blink, we will learn how to light up an LED, turn the light on
and off through a button, control the sound of a passive buzzer, and so
on. In each task, we will master commonly used programming languages,
such as digital input/output, analog input/output, tone and map
functions, etc., and learn the primary usage of libraries. The programs
in this unit are relatively simple. During the learning process, write
the program code for each task by hand, develop good habits, and avoid
program upload failures due to errors in symbols or unfamiliar rules.
\bookmarksetup{startatroot}
\hypertarget{first-arduino-program-with-seeed-studio-xiao-blink}{%
\chapter*{1.1 First Arduino program with Seeed Studio XIAO:
Blink}\label{first-arduino-program-with-seeed-studio-xiao-blink}}
\addcontentsline{toc}{chapter}{1.1 First Arduino program with Seeed
Studio XIAO: Blink}
\markboth{1.1 First Arduino program with Seeed Studio XIAO: Blink}{1.1
First Arduino program with Seeed Studio XIAO: Blink}
Arduino is a globally popular open-source electronic prototyping
platform, including various models of Arduino development boards and the
Arduino IDE software platform. Because of its open, convenient, and
easy-to-start characteristics, it has become the first choice for many
software and hardware beginners. With it, you can quickly complete
project development and implement your own ideas. To date, Arduino has
introduced a variety of different models of controllers and numerous
peripheral modules, such as various sensors, actuators, expansion
boards, etc. These modules, when used with Arduino, can implement a
variety of interesting and practical projects. The Seeed Studio XIAO
series products we are learning about today are development boards
derived from Arduino. They belong to the Seeeduino series and are the
smallest members of this series. \#\# 1.1.1 Arduino IDE Text Editor We
need to program the hardware through the Arduino IDE text editor. If you
have not installed the Arduino IDE, you can go to the download page to
install it: 🔗 \href{https://www.arduino.cc/en/software}{Software}.
Simply put, the Arduino IDE (Integrated Development Environment) is a
programming software specifically designed for Arduino. Through it, we
can write and upload different programs for Arduino hardware. When we
open the Arduino IDE software, it will create a new file named sketch,
of course, we can rename it. \#\#\#\# For Windows Users The interface of
the Arduino IDE is very clean, and can be divided into four parts: menu
bar, toolbar, editing area, and debug window.
\includegraphics{index_files/mediabag/1684140531171-ced7db.jpeg}
\includegraphics{index_files/mediabag/1669014289466-69df6f.png-averageHue=-938834-clientId=u1e0121}Menu
bar: Includes files, edit, sketch, tools, and help, such as new, save,
example programs, select serial port, etc.
\includegraphics{index_files/mediabag/1669014346076-85c627.png-averageHue=-918633-clientId=u1e0121}
Horizontal toolbar: Contains several commonly used function buttons:
verify, upload, debug, board selection, serial plotter, and serial
monitor selection.
\includegraphics{index_files/mediabag/1669014391728-2a5bec.png-averageHue=-918533-clientId=u1e0121}Vertical
toolbar: Contains shortcuts to the project folder, board manager,
library manager, debug, and search.
\includegraphics{index_files/mediabag/1669017211350-66d61f.png-averageHue=-918533-clientId=uc9acbb}
Code editing area: This is where you write program code, just as we
usually type text in a Word window, write the program code in this area.
\includegraphics{index_files/mediabag/1669017227268-8d3619.png-averageHue=-918533-clientId=uc9acbb}Serial
monitor, output window: On the right side of the horizontal toolbar, you
can open or close the serial monitor window. \#\#\#\# For MAC Users
Except for the location of the menu bar (at the top), which is slightly
different from Windows users, all other tools and experiences are
basically the same.
\includegraphics{index_files/mediabag/1684139774017-9637ff.jpeg}
\hypertarget{adding-seeed-studio-xiao-to-arduino-ide}{%
\section*{1.1.2 Adding Seeed Studio XIAO to Arduino
IDE}\label{adding-seeed-studio-xiao-to-arduino-ide}}
\addcontentsline{toc}{section}{1.1.2 Adding Seeed Studio XIAO to Arduino
IDE}
\markright{1.1.2 Adding Seeed Studio XIAO to Arduino IDE}
\begin{quote}
\hypertarget{attention}{%
\subsection*{⚠️ Attention}\label{attention}}
\addcontentsline{toc}{subsection}{⚠️ Attention}
Due to space limitations, all parts about program code and hardware
connection in this course are based on Seeed Studio
\href{https://www.seeedstudio.com/Seeeduino-XIAO-Arduino-Microcontroller-SAMD21-Cortex-M0+-p-4426.html}{XIAO
SAMD21}. Most of the code in the course can be applied to all products
in the Seeed Studio XIAO series. If there are exceptions, they will be
additionally marked or explained for applicable hardware. If not marked,
they are applicable to multiple products.
\end{quote}
We need to add the Seeed Studio XIAO series products to the Arduino IDE
to start our learning journey.
\begin{itemize}
\tightlist
\item
For Windows users, first open your Arduino IDE, click on
``File→Preferences'' in the top menu bar, as shown in the figure, and
copy the following URL into ``Additional Boards Manager URLs''.
\item
For Mac users, first open your Arduino IDE, click on ``Arduino
IDE→Preferences'' in the top menu bar, as shown in the figure, and
copy the following URL into ``Additional Boards Manager URLs''.
\item
For Seeed Studio XIAO SAMD21, XIAO nRF52840, and XIAO nRF52840 Sense,
copy the link address below:
\url{https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json}
\item
For Seeed Studio XIAO RP2040, copy the link address below:
\url{https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json}
\item
For Seeed Studio XIAO ESP32C3, XIAO ESP32S3, copy the link address
below:
\url{https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json}
\end{itemize}
\begin{figure}[H]
{\centering \includegraphics{index_files/mediabag/1684140735129-effa8a.jpeg}
}
\end{figure}
If you frequently use multiple different models of XIAO at the same
time, you can click on the
\includegraphics{.pdf}\includegraphics[width=10mm,height=6mm]{images/chapter_1/icon.jpg}icon
on the right side of the address bar and add all three addresses above
to the board manager, as shown in the figure below.
\includegraphics{index_files/mediabag/1684140807895-8ef9ff.png-averageHue=-c6c9c9-clientId=u86b65a}
Next, click on ``Tools→Board→Board Manager'', enter the keyword
\texttt{Seeeduino\ XIAO} in the search bar, find
\texttt{Seeed\ SAMD\ Boards} in the appeared entries, and click
\texttt{INSTALL}.
\includegraphics{index_files/mediabag/1684142355010-1f3351.jpeg} When
the installation starts, you will see an output pop-up window. After the
installation is complete, an ``INSTALLED'' option will appear.
\begin{quote}
⚠️ Attention
\begin{itemize}
\tightlist
\item
Enter ``RP2040'' in the search bar to find the installation package
for Seeed XIAO RP2040.
\item
Enter ``XIAO nrf52840'' to find two installation packages: Seeed nRF52
Boards (for low-power projects) and Seeed nRF52 mbed-enabled Boards
(for higher power TinyML projects).
\item
Enter ``ESP32'' to find the installation package for esp32 by
Espressif Systems.
\end{itemize}
\end{quote}
\hypertarget{connecting-seeed-studio-xiao-to-arduino-ide}{%
\subsection*{Connecting Seeed Studio XIAO to Arduino
IDE}\label{connecting-seeed-studio-xiao-to-arduino-ide}}
\addcontentsline{toc}{subsection}{Connecting Seeed Studio XIAO to
Arduino IDE}
Connect XIAO to the computer with a data cable, as shown in the figure
below:
\includegraphics{index_files/mediabag/1615797195994-1d6944.png-averageHue=-efefee-height=962-id=ac}
Next, click on ``Tools→Board'', find ``Seeeduino XIAO'' and select it,
as shown in the figure below.
\includegraphics{index_files/mediabag/1684142575447-8cf375.png-averageHue=-89b575-clientId=u86b65a}
\begin{quote}
⚠️ Attention If your development board is XIAO nRF52840, please select
Seeed XIAO nrf52840. If your development board is XIAO nRF52840 Sense,
please select Seeed XIAO nrf52840 Sense. If your development board is
XIAO RP2040, please select Seeed XIAO RP2040. If your development board
is XIAO ESP32C3, please select XIAO\_ESP32C3. If your development board
is XIAO ESP32S3, please select XIAO\_ESP32S3.
\end{quote}
Check if the port connection is correct, if not, you need to select it
manually.
\begin{itemize}
\tightlist
\item
The serial port on Windows systems is displayed as ``COM+number'', as
shown in the figure below.
\item
On Mac or Linux systems, the serial port name is generally
/dev/tty.usbmodem+number or /dev/cu.usbmodem+number, as shown in the
figure below.
\end{itemize}
Now, we can start programming XIAO through the software.
\begin{quote}
\hypertarget{xiao-esp32c3-may-not-be-recognized-properly-in-arduino-ide-2-you-need-to-manually-specify-the-development-board-and-port.}{%
\subsubsection*{⚠️ XIAO ESP32C3 may not be recognized properly in
Arduino IDE 2, you need to manually specify the development board and
port.}\label{xiao-esp32c3-may-not-be-recognized-properly-in-arduino-ide-2-you-need-to-manually-specify-the-development-board-and-port.}}
\addcontentsline{toc}{subsubsection}{⚠️ XIAO ESP32C3 may not be
recognized properly in Arduino IDE 2, you need to manually specify the
development board and port.}
\end{quote}
\includegraphics{index_files/mediabag/1684219110243-6ef7e0.jpeg}
\textgreater{} When ESP32C3 is plugged into a PC with Arduino IDE 2, it
may not be able to automatically match the correct development board. As
shown in the figure below, the display is not XIAO ESP32 development
board, you need to manually specify. Choose ``Select Other Board \&
Port\ldots{}'' from the Port drop-down menu. Enter ``xiao'' in the
search bar of the development board, select the XIAO\_ESP32C3
development board from the filtered list below, and confirm after
selecting the port on the right.
\includegraphics{index_files/mediabag/1684219312231-9d33ce.jpeg}
\textgreater{} Now you can see that the development board and port are
in the correct state. \textgreater{}
\includegraphics{index_files/mediabag/1684219357868-bd5018.png-averageHue=-e8b64e-clientId=u112af1}
\begin{quote}
\hypertarget{reset-seeed-studio-xiao}{%
\subsection*{⚠️ Reset Seeed Studio XIAO}\label{reset-seeed-studio-xiao}}
\addcontentsline{toc}{subsection}{⚠️ Reset Seeed Studio XIAO}
Sometimes when the program upload fails, the Seeed Studio XIAO port may
disappear, and we need to perform a reset operation. The reset method
will be different for different models of XIAO.
\hypertarget{reset-of-seeed-studio-xiao-samd21}{%
\subsubsection*{Reset of Seeed Studio XIAO
SAMD21}\label{reset-of-seeed-studio-xiao-samd21}}
\addcontentsline{toc}{subsubsection}{Reset of Seeed Studio XIAO SAMD21}
\begin{itemize}
\tightlist
\item
Connect XIAO SAMD21 to your computer.
\item
Open ``Blink'' in the Arduino IDE sample program and click upload.
\item
While uploading, short circuit the RST pin in the figure once with
tweezers or a short wire.
\item
The reset is completed when the orange LED flashes and lights up.
\end{itemize}
\end{quote}
As shown in the figure below.
\includegraphics{index_files/mediabag/1684219420537-9556aa.gif-averageHue=-47918c-clientId=u112af1}
\textgreater{} Reset of Seeed Studio XIAO PR2040 \textgreater{} -
Connect Seeed Studio XIAO RP2040 to your computer. \textgreater{} -
Press the reset button marked with ``R'' once, the position is shown in
the figure below.
\includegraphics{index_files/mediabag/1684219597756-6dbd99.jpeg} If this
does not work, hold down the Boot button marked with ``B'', connect the
board to your computer while holding down the BOOT button, and then
release it to enter the bootloader mode. \textgreater{} \#\#\#\# Reset
of Seeed Studio XIAO nRF52840 and Sense version \textgreater{} - Connect
Seeed Studio XIAO nRF52840 or Sense version to your computer.
\textgreater{} - Press the reset button marked with ``RST'' once, the
position is shown in the figure below.
\includegraphics{index_files/mediabag/1684219636704-506e4c.jpeg} If this
does not work, you can quickly click it twice to enter the bootloader
mode.
\begin{quote}
\hypertarget{reset-of-seeed-studio-xiao-esp32c3}{%
\subsubsection*{Reset of Seeed Studio XIAO
ESP32C3}\label{reset-of-seeed-studio-xiao-esp32c3}}
\addcontentsline{toc}{subsubsection}{Reset of Seeed Studio XIAO ESP32C3}
\begin{itemize}
\tightlist
\item
Connect Seeed Studio XIAO ESP32C3 to your computer.
\item
Press the reset button marked with ``R'' once, the position is shown
in the figure below.
\end{itemize}
\end{quote}
\includegraphics{index_files/mediabag/1684224461683-7ba8c1.jpeg} If this
does not work, hold down the Boot button marked with ``B'', connect the
board to your computer while holding down the BOOT button, and then
release it to enter the bootloader mode.
\begin{quote}
\hypertarget{reset-of-seeed-studio-xiao-esp32s3}{%
\subsubsection*{Reset of Seeed Studio XIAO
ESP32S3}\label{reset-of-seeed-studio-xiao-esp32s3}}
\addcontentsline{toc}{subsubsection}{Reset of Seeed Studio XIAO ESP32S3}
\begin{itemize}
\tightlist
\item
Connect Seeed Studio XIAO ESP32S3 to your computer.
\item
Press the reset button marked with ``R'' once, the position is shown
in the figure below.
\end{itemize}
\end{quote}
\includegraphics{index_files/mediabag/1698388811596-f95d29.jpeg} If this
does not work, hold down the Boot button marked with ``B'', connect the
board to your computer while holding down the BOOT button, and then
release it to enter the bootloader mode.
\hypertarget{structure-of-arduino-programs}{%
\subsection*{Structure of Arduino
Programs}\label{structure-of-arduino-programs}}
\addcontentsline{toc}{subsection}{Structure of Arduino Programs}
Now that we have the development board, how can we write programs into
it to control its functions? That's when the Arduino IDE text editor
comes in handy. We've already introduced the interface functions of
Arduino IDE in the introduction, it's an important tool for writing and
uploading programs. Arduino programs consist of two basic functions:
\texttt{setup()} This function is called when the program begins. Use it
to initialize variables, pin modes, start using libraries, etc.
\texttt{setup()} runs only once each time the Arduino board is powered
on or reset.
\texttt{loop()} After the program in \texttt{setup()} is executed, the
program in \texttt{loop()} begins to execute. The program in
\texttt{loop()} runs repeatedly.
\includegraphics{index_files/mediabag/1684224618107-775f07.png-averageHue=-bd9641-clientId=u2787ef}
\textgreater{} Knowledge window: \textgreater{} - The contents after
``/* */'' and ``//'' are comments to help you understand and manage
code, the comments will not affect the normal operation of the program;
\textgreater{} - When writing programs, we need to use ``\{\}'' to wrap
a set of codes; \textgreater{} - After each line of code, use ``;'' as
an end symbol to tell the Arduino editor that this line of code
instruction is over.
\hypertarget{digital-signals-and-io-settings}{%
\subsection*{Digital Signals and I/O
Settings}\label{digital-signals-and-io-settings}}
\addcontentsline{toc}{subsection}{Digital Signals and I/O Settings}
Simply put, digital signals are signals represented in binary form of 0
and 1. In Arduino, digital signals are represented by high and low
levels, high level means digital signal 1, and low level means digital
signal 0. Seeed Studio XIAO has 11 digital pins, we can set these pins
to perform the function of inputting or outputting digital signals.
\includegraphics{index_files/mediabag/1684224782661-b9e9d1.jpeg} In
Arduino, you can use functions to set the status and function of pins.
Here are the basic steps to set pins through functions:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
First, determine the pin number of the pin you want to control.
\item
In the Arduino code, use the \texttt{pinMode()} function to set the
function of the pin, such as input or output. For example, to set the
pin to output mode, you can use the following code:
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\DataTypeTok{int}\NormalTok{ ledPin }\OperatorTok{=} \DecValTok{13}\OperatorTok{;} \CommentTok{// The pin to be controlled}
\DataTypeTok{void}\NormalTok{ setup}\OperatorTok{()} \OperatorTok{\{}
\NormalTok{ pinMode}\OperatorTok{(}\NormalTok{ledPin}\OperatorTok{,}\NormalTok{ OUTPUT}\OperatorTok{);} \CommentTok{// Set the pin to output mode}
\OperatorTok{\}}
\end{Highlighting}
\end{Shaded}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\tightlist
\item
Once you have set the pin to output mode, you can use the
\texttt{digitalWrite()} function to set the status of the pin, such as
setting it to high or low level. For example, to set the pin to high
level, you can use the following code:
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{digitalWrite}\OperatorTok{(}\NormalTok{ledPin}\OperatorTok{,}\NormalTok{ HIGH}\OperatorTok{);} \CommentTok{// Set the pin to high level}
\end{Highlighting}
\end{Shaded}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{3}
\tightlist
\item
If you set the pin to input mode, you can use the
\texttt{digitalRead()} function to read the status of the pin, such as
detecting whether it is high or low level. For example, to read the
status of the pin and save it to a variable, you can use the following
code:
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\DataTypeTok{int}\NormalTok{ buttonPin }\OperatorTok{=} \DecValTok{2}\OperatorTok{;} \CommentTok{// The pin to read the status from}
\DataTypeTok{int}\NormalTok{ buttonState }\OperatorTok{=} \DecValTok{0}\OperatorTok{;} \CommentTok{// The variable to save the status}
\DataTypeTok{void}\NormalTok{ setup}\OperatorTok{()} \OperatorTok{\{}
\NormalTok{ pinMode}\OperatorTok{(}\NormalTok{buttonPin}\OperatorTok{,}\NormalTok{ INPUT}\OperatorTok{);} \CommentTok{// Set the pin to input mode}
\OperatorTok{\}}
\DataTypeTok{void}\NormalTok{ loop}\OperatorTok{()} \OperatorTok{\{}
\NormalTok{ buttonState }\OperatorTok{=}\NormalTok{ digitalRead}\OperatorTok{(}\NormalTok{buttonPin}\OperatorTok{);} \CommentTok{// Read the status of the pin}
\OperatorTok{\}}
\end{Highlighting}
\end{Shaded}
By using functions like \texttt{pinMode()}, \texttt{digitalWrite()}, and
\texttt{digitalRead()}, you can easily set and control the status and
function of pins in Arduino. \#\# 1.1.3 Task 1: Run Blink to Make XIAO's
LED Flash Just as ``Hello World'' is the first section in all
programming languages, ``Blink'' is akin to ``Hello World'' in Arduino
programming. It is the key to our journey in learning Arduino. Arduino
provides many example codes to help us get started quickly, and Blink is
one of them. We can select ``File → Examples → 01.Basics → Blink'' in
the Arduino window to open the example program Blink.
\includegraphics{index_files/mediabag/1684226229927-10eec1.png-averageHue=-83907e-clientId=u2787ef}
After opening the example program, you can see the following code, which
implements the effect of LED flashing. You can see that the code has
orange and green color prompts, which proves that your input is correct.
Pay attention to the difference between uppercase and lowercase.
\includegraphics{index_files/mediabag/1684226225853-975917.png-averageHue=-f6f6f6-clientId=u2787ef}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{/*}
\CommentTok{ Blink}
\CommentTok{ Turns an LED on for one second, then off for one second, repeatedly.}
\CommentTok{ Most Arduinos have an on{-}board LED you can control. On the UNO, MEGA and ZERO}
\CommentTok{ it is attached to digital pin 13, on MKR1000 on pin 6. LED\_BUILTIN is set to}
\CommentTok{ the correct LED pin independent of which board is used.}
\CommentTok{ If you want to know what pin the on{-}board LED is connected to on your Arduino}
\CommentTok{ model, check the Technical Specs of your board at:}
\CommentTok{ https://www.arduino.cc/en/Main/Products}
\CommentTok{ modified 8 May 2014}
\CommentTok{ by Scott Fitzgerald}
\CommentTok{ modified 2 Sep 2016}
\CommentTok{ by Arturo Guadalupi}
\CommentTok{ modified 8 Sep 2016}
\CommentTok{ by Colby Newman}
\CommentTok{ This example code is in the public domain.}
\CommentTok{ https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink}
\CommentTok{*/}
\CommentTok{// the setup function runs once when you press reset or power the board}
\DataTypeTok{void}\NormalTok{ setup}\OperatorTok{()} \OperatorTok{\{}
\CommentTok{// initialize digital pin LED\_BUILTIN as an output.}
\NormalTok{ pinMode}\OperatorTok{(}\NormalTok{LED\_BUILTIN}\OperatorTok{,}\NormalTok{ OUTPUT}\OperatorTok{);}
\OperatorTok{\}}
\CommentTok{// the loop function runs over and over again forever}
\DataTypeTok{void}\NormalTok{ loop}\OperatorTok{()} \OperatorTok{\{}
\NormalTok{ digitalWrite}\OperatorTok{(}\NormalTok{LED\_BUILTIN}\OperatorTok{,}\NormalTok{ HIGH}\OperatorTok{);} \CommentTok{// turn the LED on (HIGH is the voltage level)}
\NormalTok{ delay}\OperatorTok{(}\DecValTok{1000}\OperatorTok{);} \CommentTok{// wait for a second}
\NormalTok{ digitalWrite}\OperatorTok{(}\NormalTok{LED\_BUILTIN}\OperatorTok{,}\NormalTok{ LOW}\OperatorTok{);} \CommentTok{// turn the LED off by making the voltage LOW}
\NormalTok{ delay}\OperatorTok{(}\DecValTok{1000}\OperatorTok{);} \CommentTok{// wait for a second}
\OperatorTok{\}}
\end{Highlighting}
\end{Shaded}
\hypertarget{code-analysis}{%
\subsubsection*{Code Analysis}\label{code-analysis}}
\addcontentsline{toc}{subsubsection}{Code Analysis}
\hypertarget{pinmodeled_builtin-output}{%
\paragraph*{\texorpdfstring{\texttt{pinMode(LED\_BUILTIN,\ OUTPUT);}}{pinMode(LED\_BUILTIN, OUTPUT);}}\label{pinmodeled_builtin-output}}
\addcontentsline{toc}{paragraph}{\texttt{pinMode(LED\_BUILTIN,\ OUTPUT);}}
The first thing the code does is to initialize \texttt{LED\_BUILTIN} as
an output pin in the \texttt{setup()} function. Most Arduino series
boards default the onboard LED to digital pin 13. The constant
\texttt{LED\_BUILTIN} connects the onboard LED to pin 13. \#\#\#\#\#
\texttt{digitalWrite(LED\_BUILTIN,\ HIGH);} In the \texttt{loop()}
function, we set the \texttt{LED\_BUILTIN} pin to the ``on'' state,
outputting 5V or 3.3V voltage to this pin, which can be represented by
\texttt{HIGH}. However, note that all I/O pins on XIAO are 3.3V. Do not
input a voltage exceeding 3.3V, or it may damage the CPU. \#\#\#\#\#
\texttt{digitalWrite(LED\_BUILTIN,\ LOW);} What comes on must turn off.
This statement sets the \texttt{LED\_BUILTIN} pin to the ``off'' state,
outputting 0V voltage to this pin, which can be represented by
\texttt{LOW}. \#\#\#\#\# \texttt{delay(1000);} This is a delay
statement. It means that the LED can maintain the ``on'' or ``off''
state for 1 second, because the parameter in the function is in
milliseconds, so 1000 milliseconds is 1 second. After controlling the
``on'' and ``off'' statements of the LED, a delay must be added, and the
waiting time should be the same to ensure that the LED flashes evenly.
\#\#\#\# Upload the Program Next, we will learn how to upload the
program. Use the data cable in the kit to connect XIAO to the computer,
as shown in the figure.
\includegraphics{index_files/mediabag/1616585195669-ba0d43.png-averageHue=-e8e7e4-height=350-id=XW}
Choose the serial port of the development board from the ``Tools'' bar.
For Windows users, it is generally COM3 or a larger number. Select it as
shown in the figure below.
If several ports are displayed for selection, unplug the data cable,
reopen the ``Tools'' bar, and the port that disappears is the XIAO port.
Reconnect the circuit board and then select this serial port. After
selecting the board and the serial port, you can see the controller
model and corresponding serial port that have been set up in the lower
right corner of the IDE interface.
\includegraphics{index_files/mediabag/1684307022559-5118c8.jpeg} In Mac
or Linux systems, the serial port name is generally
\texttt{/dev/tty.usbmodem+number} or \texttt{/dev/cu.usbmodem+number},
as shown in the figure below.
\includegraphics{index_files/mediabag/1684307463342-df84ff.jpeg} Next,
we can upload the program. Before uploading, we can click the
\includegraphics{index_files/mediabag/1674004781256-2ef9b2.png-averageHue=-5e999d-clientId=u44ac5a}
(verify button) to verify whether the program is correct. If
``Compilation Completed'' is displayed, the program is correct.
\includegraphics{index_files/mediabag/1684307793146-ee2330.jpeg} Click
the\includegraphics{index_files/mediabag/1674004809585-a88427.png-averageHue=-5c979b-clientId=u44ac5a}
(upload button), the debug window will display ``Compiling
Project→Upload''. When ``Upload Completed'' is displayed, you can see
the effect of the program running on XIAO, as shown in the upload
successful prompt window displayed on a Mac computer.