PWM on XIAO SAMD21
In this second blog we will see our XIAO SAMD21 in action with the sensor boards we received in the kit. Before testing the sensors, I was very curious to try using PWM on the XIAO. For this reason I used “Fade” among the basic Arduino IDE examples.
In this case, to use the LED on the board, I slightly modified the code.
This time too there were no problems and the application worked perfectly.
/* Based on: "Fading" and using builtin LED This example shows how to fade an LED using the analogWrite() function. created 1 Nov 2008 by David A. Mellis modified 30 Aug 2011 by Tom Igoe This example code is in the public domain. https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fading */ void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { // fade in from min to max in increments of 5 points: for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(LED_BUILTIN, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(LED_BUILTIN, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } }
DHT20 Sensor
Now we will see our XIAO SAMD21 in action with the sensor boards we received in the kit.
The first board we will try is Temperature & Humidity Sensor V2.0 (DHT20). We will find the information on the site: Grove - Temperature & Humidity Sensor V2.0 (DHT20) - Seeed Studio
It is a very interesting sensor and its characteristics are these:
- High Accuracy:
- Temperature Accuracy:± 0.5 ℃
- Humidity Accuracy:± 3 % RH ( 25 ℃ )
- Wide measurement ranges:
- Measuring Range (Humidity):0 ~ 100% RH
- Measuring Range (Temperature):-40 ~ + 80 ℃
- Better compatibility:
- Digital output
- I²C interface
- Fully calibrated
- Excellent long-term stability
- Quick response and anti-interference capability
- Wide voltage support 2.5-5.5V DC
In order to use this temperature sensor in the Arduino IDE, we need to install the libraries related to the DHT20 sensor. Just do a search among the installable libraries to find the one we need to use this sensor. Once the DHT20 library has been installed, we will also find among the available examples some that use the DHT20.
The sensor output is of the I2C type and the connection to the Seeed Studio XIAO SAMD21 is immediate. Simply connect the sensor power supply to the 3V3 and GND PINS and connect the SDA and SCL terminals to the corresponding PINs.
Another sensor I'm interested in trying is the Grove - 3-Axis Digital Accelerometer(±1.5g). It also has very interesting features and can be used in many applications, for example 3-axis motion/orientation sensing, gesture detection including shake detection and tap detection.
First of all you need to load the library: GitHub - Seeed-Studio/Accelerometer_MMA7660: Seeed 3-Axis Digital Accelerometer(±1.5g) library.
Once the library has been installed, among the examples we will find: Accelerometer_MMA7660 which allows you to view the acceleration values detected on the three axes on the terminal. This obviously can be an excellent starting point for creating more complex applications.
Let's now try how this board works.
In this blog we saw an application of PWM using XIAO SAMD21 and then we tested two of the 5 sensors from the Seeed kit. In particular we used the two sensors with I2C connection and both worked very well without any configuration problems.