본문 바로가기

사물인터넷

Meet the Seeeduino XIAO

출처: https://dronebotworkshop.com/seeeduino-xiao-intro/

 

Meet the Seeeduino XIAO - Tiny but Powerful Arduino Alternative

The Seeeduino XIAO is a 32-bit Arduino-compatible microcontroller that can be programmed with the Arduino IDE. Today we will examine this 5-dollar wonder.

dronebotworkshop.com

Today we will take a look at the Seeeduino XIAO, a tiny microcontroller with impressive capabilities.

Introduction

When you need a microcontroller to bring your latest invention to life the first impulse is usually to grab an Arduino board, probably an Arduino Uno. It makes sense, the Arduino Uno is easy to work with, and the Arduino IDE is a familiar programming environment with a wealth of libraries and sample code that simplify development.

But for all of its advantages, the Arduino Uno is a pretty old piece of technology, dating back to around 2005. And it has limitations (such as speed or analog input resolution) that make it a poor choice for some designs.

So for more advanced projects or better-performing versions of existing designs, we can look at some other, more modern microcontroller boards.

We have already done that with the ESP32 boards, they are much more powerful than the ATMEGA328-based Arduino boards and have a wealth of additional features. And there are other selections as well, Arduino themselves have a range of more powerful microcontroller boards based upon 32-bit processors instead of the old 8-bit designs like the Uno.

The board we are looking at today is a very tiny and very inexpensive offering from Seeedstudio. Called the Seeeduino XIAO (pronounced “sh-ow”) it is a 32-bit Arduino-compatible module that can be used to update and improve your Arduino designs.

Incidentally, if you are wondering about the origins of the word XIAO, it is a type of Chinese flute that has been around for centuries.

Seeeduino XIAO

The Seeeduino line of microcontrollers from Seeedstudio are Arduino-compatible boards, kits, and peripherals. Many of them include “Grove” connectors, an interface standard used by Seeedstudio and some other manufacturers to simplify interfacing microcontrollers with external sensors and displays.

The Seeeduino XIAO is the latest entry (as of this writing) to this group of boards, and it’s also the smallest. In fact, it’s probably about the smallest Arduino-compatible board you’ve ever seen, with the exception perhaps of a few ATtiny85-based offerings. In performance, this thing is light years ahead of the ATtiny85.

The XIAO is available individually or in 3-packs, and it’s a quality build. The boards are packaged with some male header pins which you can solder in if you wish to use them, or you can just wire to the pins directly. The only connector on the board is a USB-C jack.

To understand the Seeeduino XIAO you really need to understand the microcontroller chip that powers it, the SAMD21. So let’s take a look at that before we hook up our XIAO.

SAMD21 MIcrocontroller

The heart of the tiny Seeeduino XIAO is the Atmel ATSAMD21 Cortex M0+ 32-bit microcontroller from Microchip. This tiny wonder has been around since 2012 and it has the following specifications:

  • 32-bit single-core processor
  • Clock speed up to 48MHz
  • 32KB SRAM
  • 256KB Flash Memory
  • 11 Digital I/O
  • 11 12-bit ADC Inputs
  • 1 DAC Output
  • Support for up to 120 touch channels
  • USB Device and Embedded host
  • Hardware RTC
  • 1.62V to 3.63V power supply
  • Extremely low power consumption
  • 6 serial communication modules (SERCOM) configurable as UART/USART, SPI or I2C

This processor is used in a number of other microcontroller boards, including the Arduino Zero , Arduino MKRZero and Arduino MKR 1000 boards. Seeedstudio also makes the Seeeduino Cortex-M0+ and Seeeduino Lotus Cortex-M0+, both of which support Grove connectors. Adafruit and Sparkfun also make boards using the SAMD21 microcontroller.

Seeeduino XIAO Pinouts

The Seeeduino XIAO is a tiny module with 14 output pins, as well as a few other surface connections.

Unlike most modules, the pins on the XIAO are numbered starting at 0 instead of 1, so the pins range from 0 to 13. This allows the pin numbers to correspond to the port numbers for the digital I/O and analog input connections.

Most of the pins on the Seeeduino XIAO serve multiple functions, so it is easier to examine them by dividing them into functional groups.

Power Connections

The ATSAMD21G18 processor is a 3.3-volt device, however, the XIAO has an onboard XC6206P3232MR DC-DC Power Converter to allow the board to be powered by 5-volts as well.

There are actually a few different ways of powering the Seeeduino XIAO:

  • The USB-C connector powers the XIAO from the attached computer.
  • You can apply 5-volts to pin 13, this will be reduced to 3.3-volts by the internal DC-DC converter.
  • You can apply 3.3-volts to pin 11.
  • You can use the VCC and GND connections underneath the XIAO and apply 3.7 to 5-volts. This is an ideal method of powering the XIAO with a small LiPo battery.

The power pins can be used as inputs or outputs, as they are attached across the DC-DC converter. If you power the XIAO with the USB-C connection then you can use the power pins as outputs, delivering 5-volts on pin 13 and 3.3-volts on pin 11.

If you apply 5-volts to pin 13 you can use pin 11 as a 3.3-volt output. You can also power the XIAO by providing your own 3.3-volt power supply and connecting it to pin 11 – in this case the 5-volt pin is non-functional.

Pin 12 is the Ground connection.

Analog Input Connections

The Seeeduino XIAO has 11 analog inputs, each connected to a 12-bit A/D converter.

Note that the maximum voltage you can apply to these inputs is 3.3-volts.

Digital I/O Connections

The XIAO also has 11 digital I/O pins, sharing the same pins as the analog inputs.

Remember, the Seeeduino XIAO I/O pins are 3.3-volt logic, and they are NOT 5-volt tolerant! If you need to interface with 5-volt logic devices you’ll need to use a level converter to avoid damaging the XIAO.

Other Connections

Many of the other pins on the XIAO module have additional functions.

  • DAC – (Pin 0) – This is the output of the Digital to Analog converter, which produces an analog output of 0 to 3.3-volts.
  • REF – (Pin 1) – This is the Reference Voltage for the 11 Analog to Digital Converters used by the analog inputs. It’s the equivalent of the AREF pin on the Arduino, and can accept a maximum of 3.3-volts.
  • SDA – (Pin 4) – The I2C Data line. Note the similar pinout to the Arduino Uno, which also used A4 as SDA.
  • SCL – (Pin 5) – The I2C Clock line. Again this is the same pinout as the Uno.
  • TX – (Pin 6) – The UART Transmit line.
  • RX – (Pin 7 ) – The UART Receive line.
  • SCK – (Pin 8) – The SPI bus clock line.
  • MISO – (Pin 9) – Master In Slave Out for the SPI bus.
  • MOSI – (Pin 10) – Master Out Slave In for the SPI bus.

Interrupts

Every pin on the Seeeduino XIAO can be used as an interrupt.

As you can see from the above illustration each pin has been assigned an interrupt number. However, before working with interrupts there are a few issues you need to be aware of:

  • Most of the interrupts are “maskable”, in other words, you can programmatically choose to ignore them.
  • The interrupt on pin 4 is non-maskable, it cannot be ignored programmatically.
  • Pins 5 and 7 share the same interrupt (INT_9).

Pulse Width Modulation (PWM)

With the exception of pin 0, all of the pins on the Seeeduino XIAO support PWM.

This makes the XIAO an ideal controller for LED’s, perfect for advanced wearable projects.

Other Features

In addition to the pinouts, we just covered there are a few other connections on the XIAO, as well as some indicator LEDs.

Top

The top of the Seeeduino XIAO has a number of prominent features.

The most prominent feature on the top of the XIAO is the USB-C connector. This is used for both power and data transfer.

To the left of the USB-C connector, you’ll see two pads labeled “RST”. The XIAO does not have a reset switch, instead, you need to short these two pins together to perform a reset.

You can do much more with these pins, by resetting twice in quick succession you can have the XIAO load a fresh copy of the bootloader.

To the right of the USB-C connector you’ll see four tiny surface-mount LEDs, labeled as follows:

  • L – (D13) – This is the User or Built-in LED. It is connected to data I/O pin 13, just as the built-in LED on the Arduino Uno is. This LED is yellow.
  • T – (D11) – This is the Transmit LED, it indicates transmit activity on the USB-C bus. It may also be addressed as data I/O pin 11. This LED is blue.
  • R – (D12) – This is the Receive LED, indicating activity on the USB-C bus. It may also be addressed as data I/O pin 12. This LED is also blue.
  • P – This is the power indicator, the LED is green.

Bottom

The underside of the Seeeduino XIAO also has a few extra pads for additional connections.

  • The SWCLK and SWDIO pads are the clock and data lines for the Serial Debug feature.
  • There are Reset and Ground pads, this duplicates the functionality of the pads on the top of the XIAO.
  • VIN and Ground were previously mentioned. This is another method of connecting power to the XIAO.

Working with the Seeeduino XIAO

Now that we have seen the hardware connections to the XIAO it’s time to learn how to program it. There are actually two ways to do this:

  • Using C++ and the Arduino IDE. It is also possible to use Platform IO.
  • Using CircuitPython, a Python subset enhanced for microcontrollers.

In this tutorial we will focus on using the Arduino IDE, future installments will explore other methods for programming the XIAO.

Setting up the Arduino IDE for the Seeeduino XIAO

Before we can use our Arduino IDE with the XIAO we will need to install another board manager. If you have worked with the ESP32 you will have performed a similar procedure.

Actually, there are two steps you’ll need to take – installing the new Board Manager and installing the XIAO board itself. Here is how to accomplish this.

1 – Install the Seeeduino SAMD21 Boards Manager

Seeed Studio has a board manager that works with the XIAO and with many other Seeeduino products. It can be installed as follows:

  1. Open the Arduino IDE.
  2. Click the File menu, and then click Preferences.
  3. The Preferences window will open.
  4. Locate the Additional Boards Manager URLs textbox, near the bottom of the Preferences window.

You’ll need to insert the following URL into the Additional Boards Manager URLs textbox:

https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json

  • If the Additional Boards Manager URLs textbox is empty then simply paste the above URL into the textbox.
  • If the Additional Boards Manager URLs textbox already has an entry then click on the button to the right of the textbox. This will open up a dialog box which will allow you to add additional board managers. Paste the above link into this box, below the other entry or entries. Click the modal boxes OK button when done.

Now you can click the OK button to accept the new entry and close the Preferences window. And you are now ready for the next step.

2 – Install the XIAO Board

Now that the new Boards Manager has been installed into your Arduino IDE you can perform the final step – installing the Seeeduino XIAO board itself.

  1. Open the Arduino IDE (you probably still have it open, that’s fine).
  2. Open the Tools item from the top menu and select Boards Manager.
  3. The Boards Manager window will open.

  1. In the filter textbox type “seeeduino xiao”
  2. The Seeed SAMD Boards package will be displayed
  3. Click the Install button to install the package. Be patient, as it can take a while!
  4. Click the Close button when you are done.

Once you have done this you should now be able to select Seeeduino XIAO from the list of Seeed SAMD Boards.

Hooking up the Seeeduino XIAO

The Seeeduino XIAO uses a USB-C connector for both power and data, so you will need a USB-C cable to connect it to your computer.

But you should be aware that not all USB-C cables will work, as many of these cables are exclusively for delivering power and won’t carry data.

A simple way to see if your USB-C cable is suitable is just to connect it up and then observe the ports listed in the Arduino IDE. The port connected to the XIAO will actually display “Seeeduino XIAO” within its description. If you don’t see that then your cable is not suitable.

One simple method of ensuring that you have the correct cable is to use a microUSB to USB-C adapter. This is the method I employed, and it works very well. Otherwise, you’ll need to look for a USB-C cable that is designed for both data and power.

Hello World

Now that you have your XIAO connected and your Arduino IDE modified all that is left to do is to test out the installation to ensure that everything is OK.

The easiest way to do this is to run the Blink sketch, the “Hello World” sketch in the land of Arduino!

The XIAO has a yellow LED labeled “L” beside the USB-C connector, and it is connected to pin 13 just like the built-in LED on the Arduino Uno. So the Blink sketch should run unmodified.

However, like many Arduino-compatible boards, the XIAO already comes from the factory with the Blink sketch installed. Powering up the device should result in the yellow “L” LED flashing at a rate of one second on, one second off. So uploading the Blink sketch as it is doesn’t really prove anything.

So before uploading I would suggest modifying the Blink sketch to increase the delay time in milliseconds (current value = 1000) to a different value, either 500 for a “fast blink” or 2000 for a slower one. This way the effect of loading the sketch will be more obvious.

Working with the XIAO is identical to working with the Arduino, at least as far as uploading sketches is concerned. Unlike many ESP32 models, there is no need for any action on the XIAO after the program compiles. You simply wait until you receive the message that the sketch has uploaded, just like the Arduino.

You might notice that the XIAO sketches take a bit longer to compile than the same sketch compiling for an Arduino, this is typical of external Boards Managers on the Arduino IDE.

Experiment a bit with the Blink sketch, you can also try a few of the other Arduino examples. Try running the Fade sketch after changing the pin number to 13 and see how it works!

Once you have satisfied yourself that you are able to load and run sketches on the Seeeduino XIAO then it’s time to move on and explore this microcontroller further.

Running Arduino Code on the Seeeduino XIAO

The Seeeduino XIAO has many similar features to the Arduino Uno, and a lot of the code written for the Uno (and other Arduino AVR boards) can run unmodified on the XIAO.

There are, however, a few differences – some of them subtle, some of them not so subtle!

A good way to explore the similarities and differences is to run some simple code to see how the XIAO reacts. So let’s do that!

Test Hookup

We are going to hook up a few simple components to our XIAO and run a few basic sketches.

This hookup will allow us to test some of the features of the XIAO, as well as expose a few of the differences between it and the Arduino. We’ll do that by running some very simple code and comparing it to the equivalent code on an Arduino.

Test Sketch 1 – Analog Input

Our first sketch tests the analog input function, using the XIAO’s 12-bit A/D converter.

/*
  Seeeduino XIAO Analog Input Demo
  xiao-analog-in-test.ino
  Displays operation of XIAO A/D converter
  Results displayed on Serial Monitor
 
  DroneBot Workshop 2020
  https://dronebotworkshop.com
*/
 
// Analog Input Pin
#define ANALOG_IN_PIN A2
 
// Integer to represent input value
int input_val;
 
void setup() 
{
  // Set A/D converter resolution to 12-bits
  analogReadResolution(12); 
  
  // Setup Serial Port
  SerialUSB.begin(9600);
}
 
void loop() 
{
  // Read the input value
  input_val = analogRead(ANALOG_IN_PIN);  
  
  
  // Print value to Serial Monitor
  SerialUSB.println(input_val);
  
  // Slight delay before repeating
  delay(10); 
  
}

This is an extremely simple sketch that simply reads the value from the potentiometer attached to analog input A2 and displays that value on the serial monitor.

We start by defining the analog input pi we are using, of course, you could use any of the 11 available analog inputs. I chose to use input A2. We also define an integer variable to hold the value read from the analog port.

The Setup is where we see things are a bit different from your typical Arduino sketch.

We have a statement in the Setup that sets the resolution of the A/D converter, it reads analogReadResolution(12);. This tells the XIAO that we want to use 12-bit resolution.

Without the above statement, the resolution will default to 10-bits, the same resolution as the Arduino has. I suspect this is designed like this to maintain backward compatibility with Arduino code.

The next difference is in the way we are setting up our serial monitor.

You’ll notice that we use the statement SerialUSB.begin(9600), instead of the more common Serial.begin(9600) that we would expect to see in our Arduino code.

SerialUSB is used with boards based upon the SAMD21 like the XIAO. It allows access to the native USB port on the microcontroller. And the baud rate of 9600 is just a place filler, in actual fact there is no speed setting but the Arduino compiler will produce an error if it doesn’t have a value here.

The Loop is pretty well what you would expect, we read the value from the analog port and assign it to our variable, then we send it to the serial monitor. After a short delay, we do it all over again.

Load the sketch onto your XIAO. If you experience difficulties (and I did repeatedly) you can resolve most of them by resetting the XIAO before uploading, you do that by shorting the two RST pads on the top of the board.

Once you have the sketch loaded on the XIAO open up the serial monitor and observe the results. Turning the potentiometer should produce results ranging from 0 to 4095, as we have set the A/D converter to 12-bits.

You can experiment with the analogReadResolution function and set it to different values to see the result. If set to 10 (or if the statement is eliminated) the output will range from 0 to 1023.

Test Sketch 2 – Digital I/O & Builtin LED

Here is another extremely simple sketch that we’ll be using to illustrate the differences between the Seeeduino XIAO and the Arduino Uno (and other Arduino AVR boards).

/*
  Seeeduino XIAO Digital I/O Demo
  xiao-digital-io-test.ino
  Displays operation of XIAO digital inputs and outputs
  Results displayed on serial monitor
 
  DroneBot Workshop 2020
  https://dronebotworkshop.com
*/
 
// Pushbutton input
#define BUTTON 7
 
// LED output
#define LED 9
 
// Variable to hold state of pushbutton
boolean buttonState;
 
void setup()
{
    // Setup the pushbutton as an input and enable internal pullup
    pinMode(BUTTON, INPUT_PULLUP);
    
    // Setup the LED as an output
    pinMode(LED, OUTPUT);
    
    // Also define the builtin LED as an output
    pinMode(LED_BUILTIN, OUTPUT);
    
    // Setup Serial Port
    SerialUSB.begin(9600);
 
}
 
void loop()
{
    // Get the pushbutton state and assign it to the variable
    buttonState = digitalRead(BUTTON);
    
    // Print pushbutton state to serial monitor
    SerialUSB.println(buttonState);
    
    // Set the LED according to pushbutton state
    digitalWrite(LED, buttonState);
    
     // Set the builtin LED according to pushbutton state
    digitalWrite(LED_BUILTIN, buttonState);
    

In this sketch, we are going to read the value of the pushbutton we have connected to pin 7 and will then write that value to both the LED on pin 9 and the built-in LED (the yellow one on the XIAO).

We start by defining constants to represent the pins that the pushbutton and LED are connected to. We also define a boolean that represents the current button state.

In the Setup, we use the pinMode function to set the pushbutton as an input and the two LEDs as outputs. Note that we invoke the XIAOs internal pullup resistor on the pushbutton input.

We also set up the SerialUSB port as we did in the previous sketch, again the “9600” is just really a placeholder to satisfy the Arduino IDE compiler.

In the Loop the buttonState variable is set either HIGH or LOW based upon the state of the pushbutton – if the button is pressed the input is LOW, otherwise, the internal pullup resistor keeps it high.

We then print the buttonState to the serial monitor and also use it to write to the two LEDs.

So far this probably seems pretty pointless, but when you run the sketch you’ll see why I added both LEDs.

Run the sketch and observe both LEDs. You will observe the following:

  • When the pushbutton has not been pressed the LED on pin 7 will be illuminated. The built-in LED, however, will be off. In this case, the output of the pushbutton is HIGH.
  • Press the pushbutton and the LED will extinguish. The built-in LED, on the other hand, will be illuminated. In this case, the output of the pushbutton is LOW.

So what we have observed is that the Builtin LED on the XIAO operates inversely from the Builtin LED on the Arduino AVR boards. It illuminates when its input is LOW and is off when it is HIGH.

If you’re designing a sketch that uses the built-in LED this is something that you’ll need to know!

BTW, the two blue LEDs (T and R) also exhibit the same behavior.

Test Sketch 3 – Analog Output

In this experiment, we will use a feature that is not present on the ATMEGA328P-based Arduino AVR boards, the analog output on pin A0.

The sketch I’m using, which is a modified version of a sample provided by Seeedstudio, uses both the analog output and one of the analog inputs. It produces an approximation of a sine wave on the output and then reads it back on the input. The result can be displayed on the Arduino IDE serial plotter.

/*
  Seeeduino XIAO Analog Output Demo
  xiao-analog-out-test.ino
  Displays operation of XIAO D/A converter
  Produces a sine wave on Analog output
  Reads result on analog input
  Results displayed on Serial Plotter
 
  Adapted from Seeeduino sketch on https://wiki.seeedstudio.com/Seeeduino-XIAO
 
  DroneBot Workshop 2020
  https://dronebotworkshop.com
*/
 
// Define Analog Out pin
#define DAC_PIN A0
 
// Define Analog In pin
#define ADC_PIN A4
 
// Float output to modify for sine wave
float outval = 0;
// Increment
float increment = 0.02;
 
 
void setup()
{
  // Set analog output resolution to 10-bits
  analogWriteResolution(10);
 
  // Set analog input resolution to 12-bits
  analogReadResolution(12);
 
  // Setup Serial Port
  SerialUSB.begin(9600);
}
 
void loop()
{
  // Generate a voltage value between 0 and 1023.
  // Offset by 511.5 (half-point)
  int dacVoltage = (int)(511.5 + 511.5 * sin(outval));
 
  // Increment
  outval += increment;
 
  // Output to DAC port
  analogWrite(DAC_PIN, dacVoltage);
 
  // Read DAC output on ADC input
  float voltage = analogRead(ADC_PIN) * 3.3 / 4096.0;
 
  // Print to serial plotter
  SerialUSB.println(voltage);
 
  // 1ms delay (change to change sine wave frequency)
  delay(1);
}

We start by defining the pins we will be using for both the analog (DAC) output and analog (ADC) input. If you wish you can move the analog input to another pin, but only pin A0 can be used as an analog output.

Next, we define a couple of floats, one that represents the output signal and another to represent an increment. We will change the level of the output signal on each increment to simulate a sine wave.

In the Setup, we are introduced to another new function, the analogWriteResolution function. As with the analogReadResolution function, this sets the DAC resolution to 10-bits, which is the maximum value for the XIAO DAC.

Now let’s move into the Loop.

Our DAC is a 10-bit unit, so we are going to divide our output into 1024 different levels from 0 to 1023. We establish the half-way point at 511.5 (1023 / 2), as our output cannot go below 0-volts.

The output value is then equal to our offset, plus the offset multiplied by the sine of the output value variable, which starts at zero. This value is assigned to the dacVoltage variable. We then increment the value by the amount we defined earlier.

The dacVoltage output is then written to the DAC using the analogWrite function, which many Arduino users will recognize as the same function we use for PWM output. When applied to the DAC this results in a different output voltage, instead of a different pulse width.

Now we read the voltage on our analog input, which of course is coming from our DAC. We do a bit of math to the results to read the actual voltage – 3.3 is the maximum voltage on the ADC and 4096.0 is the divisor, as this is a 12-bit ADC.

We then send this to the SerialUSB output, and we will use the serial plotter to display it. Of course, you could also display the output on the serial monitor, but it would just be a series of incrementing values and wouldn’t make much sense.

A delay at the end can be adjusted to set the output frequency.

Load the sketch onto your XIAO and then open the Serial Plotter. You should observe a crude approximation of a sine wave.

Seeeduino XIAO with Arduino Libraries Demo

We’ll finish off our introduction to the Seeeduino XIAO by running a sketch that uses libraries. As a bonus, we will also use an I2C device with our XIAO.

We are going to make use of the AM2320 I2C Temperature and Humidity sensor. We have used this device in other projects, physically it looks a lot like a DHT11/DHT22 sensor but this device uses the I2C bus.

I selected this device for the demo as it works with both 3.3-volt and 5-volt logic, an important consideration when using a 3.3-volt controller like the XIAO.

Hookup is very simple:

The two pull-up resistor values are not critical, you can use any value from 2.2k to about 10k. I used 4.7k resistors in my hookup.

AM2320 Libraries

We are going to be using a library from Adafruit to work with the AM2320. This library also requires a second Adafruit library to function.

The second library is the Adafruit Universal Sensor library. This is a sort of “master” library that contains many common functions and methods for working with a variety of Adafruit sensors. The Adafruit AM2320 library requires this library to function.

Here is how to go about installing these libraries:

  • Open your Arduino IDE (you probably still have it open from the last experiment).
  • Select the Sketch menu item from the top menu bar.
  • Select Include Library. A sub-menu will appear.
  • Choose Manage Libraries. The Library Manager window will open.
  • In the filter box type “AM2320”. The application is dynamic so there is no need to press enter.
  • Look for the Adafruit AM2320 Sensor Library in the results.
  • Hover to the right side of the listing to expose the Install button and click it.
  • If you already have the Adafruit Unified Sensor library installed then the installation of the AM2320 library will proceed.
  • If you don’t have the Adafruit Universal Sensor Library installed you’ll be prompted to install it along with the AM2320 Library. Choose this option and both libraries will be installed.
  • Close the Library Manager.

Now that we have our library installed we can test out our sensor.

AM2320 Test Sketch

We will be saving ourselves some typing (or cutting and pasting) by making use of the sample sketch included with the AM2320 library.

Here is how to load the sketch:

  • In the Arduino IDE click the File menu item on the top menu.
  • Scroll down to Examples. A sub-menu will appear.
  • Scroll down to the Examples from Custom Libraries and look for the Adafruit AM2320 Sensor Library. Click on it to remain in place.
  • There is only one example in here, called basic_AM2320. Select this, and the sketch will open.

The sketch is very simple.

#include "Adafruit_Sensor.h"
#include "Adafruit_AM2320.h"
 
Adafruit_AM2320 am2320 = Adafruit_AM2320();
 
void setup() {
  Serial.begin(9600);
  while (!Serial) {
    delay(10); // hang out until serial port opens
  }
 
  Serial.println("Adafruit AM2320 Basic Test");
  am2320.begin();
}
 
void loop() {
  Serial.print("Temp: "); Serial.println(am2320.readTemperature());
  Serial.print("Hum: "); Serial.println(am2320.readHumidity());
 
  delay(2000);
}

It starts by including both the Adafruit_Sensor and the Adafruit_AM2320 libraries. After that an object called am2320 is defined.

In the setup, the Serial port is opened at 9600bps. Note that we are using the Serial and not SerialUSB function, this also works with the Seeeduino XIAO. In this instance, it is important to set the speed of the Serial Monitor to match.

We also initialize the AM2320, and then move into the Loop.

The Loop is pretty simple, as all the ”heavy lifting” is performed by the libraries. We just call the readTemperature and readHumidity methods within a serial print statement, resulting in the temperature and humidity being displayed on the serial monitor.

A two-second delay is added at the end of the loop to allow the sensor to stabilize, and then everything repeats.

Upload the sketch to the XIAO and open the Serial Monitor at 9600bps. You should observe a reading of both temperature and humidity every two seconds.

This is another very simple example, but it shows how Arduino libraries and Arduino code can be ported to the Seeeduino XIAO without any modifications. You’ll find thousands of Arduino sketches that can be used directly like this.

Conclusion

The Seeeduino XIAO packs a lot of power into a very tiny package. Its low cost makes it ideal for a variety of hobbyist projects, and the ability to reuse old Arduino code makes it great for rapid application development.

You’ll be seeing more of the XIAO here in the DroneBot Workshop, so stay tuned!

&nbsp

Resources

Seeeduino XIAO Wiki – Seeed Studio’s wiki for the Seeeduino XIAO.

Overview of the XIAO – Excellent blog that really dissects the Seeeduino XIAO.

Code used in this article – A ZIP file containing the sketches I used with the Seeeduino XIAO.

Seeeduino XIAO Resources Roundup – From the Seeed Studio blog.

 

'사물인터넷' 카테고리의 다른 글

Using Keypads with Arduino  (0) 2021.07.04
Controlling AC Devices with Arduino  (0) 2021.07.04
Measure DC Voltage and Current with an Arduino  (0) 2021.07.04
74HC595 & 74HC165 with Arduino  (0) 2021.07.04
xno-6085ra  (0) 2021.01.23