Three Entry-level Demos Help You Get Started with Wio Terminal Quickly: Adjust the Brightness of the LCD Using the Light Sensor, Play a Melody Using Buttons & Switch, and Make a TV Remote Controller with the IR Emitter

This post is translated by Seeed from Wio Terminal を使ってみた written by homemadegarbage (twitter: @H0meMadeGarbage). Thank you for sharing this with us! Visit their homepage for more interesting projects: homemadegarbage.com.

This post will be covered by:

  1. What is Wio Terminal
  2. Unboxing
  3. Coding with Arduino IDE
  4. Basic Functions
    • 4.1 Use Light Sensor to Control the Brightness of the Display
    • 4.2 Use Buttons, 5-way Switch, and Buzzer to Made an Instrument
    • 4.3 Use Infrared Emitter to Make a TV Remote Controller

1. What is Wio Terminal

Wio Terminal is an ATSAMD51-based microcontroller with wireless connectivity supported by Realtek RTL8720DN. Its CPU speed runs at 120MHz (Boost up to 200MHz). Realtek RTL8720DN chip supports both Bluetooth and Wi-Fi providing the backbone for IoT projects. The Wio Terminal itself is equipped with a 2.4” LCD Screen, onboard IMU(LIS3DHTR), Microphone, Buzzer, microSD card slot, Light sensor, and Infrared Emitter(IR 940nm).

Check more information:

Seeed Wio Terminal page
Schematics
Seeed Wiki

2. Unboxing

It contains Wio Terminal, USB Type-C Short Cable, and a User Manual.

You need to remove the protective films from the LCD display before use. By the way, on the transparent window ( for the IR Emitter and light sensor) on the back, a protective film is also attached. Don’t forget to remove it as well!

There is also a TELEC mark on the back.

When you connect the USB-C cable to the PC and turn on the power switch on the side, a game will start (which is really difficult…).

3. Coding with Arduino IDE

I bought Seeeduino Xiao, a SAMD21 Cortex M0+ based tiny Arduino Microcontroller a few days earlier and already set up the environment for Seeeduino boards (Previous post: Seeeduino XIAOを使ってみた), so we will skip this part and focus on some basic functions of Wio Terminal in this post.

About how to set up the environment for coding with the Arduino IDE, check this tutorial for detailed instructions.

4. Basic Functions

4.1 Use Light Sensor to Control the Brightness of the Display

In this demo, the brightness of the display color is controlled by the value of the light sensor. The value of the light sensor (0 to 1023) is converted to the blue brightness (0 to 31) of the display, and if the light sensor value is 50 or less, the display backlight will be turned off.

4.1.1 How to Set up

About how to configure light sensor, check here.

About how to set up the LCD display, check here.

And you will also need the following libraries:

Seeed_Arduino_LCD 
Adafruit Zero DMA

Sample code is as below:

#include"TFT_eSPI.h"
TFT_eSPI tft;
  #define LCD_BACKLIGHT (72Ul) 

void setup() {
  tft.begin();
  tft.setRotation(3);
  
  pinMode(WIO_LIGHT, INPUT);
  Serial.begin(115200);
 
}
 
void loop() {
   int light = analogRead(WIO_LIGHT);
   Serial.print("Light value: ");
   Serial.println(light);
   delay(50);
   if(light > 50){
    digitalWrite(LCD_BACKLIGHT, HIGH);
     tft.fillScreen(map(light, 0, 1023, 0, 31));
   }else{
     tft.fillScreen(0);
     digitalWrite(LCD_BACKLIGHT, LOW);
   }
}

4.2 Made an Instrument with Three Buttons, 5-way Switch, and Buzzer

I made an instrument with the three buttons on the top and the 5-way switch on the front and played a melody using the buzzer. As you can see on the screen, 5 music scales(C, D, E, F, G, A, B, C) are assigned to the buttons and switch.

4.2.1 How to Set up

About how to display the characters on the LCD screen, check here.

Also check the official wiki about how to configure buttons, 5-way switch, and buzzer.

Sample code is as below:

#include"TFT_eSPI.h"
#include"Free_Fonts.h" //include the header file

#define BUZZER_PIN WIO_BUZZER
  
TFT_eSPI tft;

int state = 0;
 
void setup() {
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK); 
 
  tft.setFreeFont(FSSBO24); 

  Serial.begin(115200);
  pinMode(WIO_KEY_A, INPUT_PULLUP);
  pinMode(WIO_KEY_B, INPUT_PULLUP);
  pinMode(WIO_KEY_C, INPUT_PULLUP);
  pinMode(WIO_5S_UP, INPUT_PULLUP);
  pinMode(WIO_5S_DOWM, INPUT_PULLUP);
  pinMode(WIO_5S_LEFT, INPUT_PULLUP);
  pinMode(WIO_5S_RIGHT, INPUT_PULLUP);
  pinMode(WIO_5S_PRESS, INPUT_PULLUP);

  pinMode(BUZZER_PIN, OUTPUT);
}

void loop() {
  if (digitalRead(WIO_KEY_C) == LOW) {
    state = 1;
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("C",140,100);
    playTone(1915, 500);
   }
   else if (digitalRead(WIO_KEY_B) == LOW) {
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("D",140,100);
    playTone(1700, 500);
   }
   else if (digitalRead(WIO_KEY_A) == LOW) {
    state = 3;
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("E",140,100);
    playTone(1519, 500);
   }else if (digitalRead(WIO_5S_UP) == LOW) {
    state = 4;
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("F",140,100);
    playTone(1432, 500);
   }
   else if (digitalRead(WIO_5S_DOWM) == LOW) {
    state = 5;
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("G",140,100);
    playTone(1275, 500);
   }
   else if (digitalRead(WIO_5S_LEFT) == LOW) {
    state = 6;
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("A",140,100);
    playTone(1136, 500);
   }
   else if (digitalRead(WIO_5S_RIGHT) == LOW) {
    state = 7;
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("B",140,100);
    playTone(1014, 500);
   }
   else if (digitalRead(WIO_5S_PRESS) == LOW) {
    state = 8;
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("C",140,100);
    playTone(956, 500);
   }else{
    tft.fillScreen(TFT_BLACK); 
   }
}


  void playTone(int tone, int duration) {
    for (long i = 0; i < duration * 1000L; i += tone * 2) {
        digitalWrite(BUZZER_PIN, HIGH);
        delayMicroseconds(tone);
        digitalWrite(BUZZER_PIN, LOW);
        delayMicroseconds(tone);
    }
}

4.3 Use Infrared Emitter to Make a TV Remote Controller

I used the IR Emitter and make a TV remote controller. In this demo, the volume is controlled by the up and down way of the 5-way switch, and you can also turn on or off the Television by simply pushing the switch.

4.3.1 How to Set up

About the configuration of the infrared emitter, check here.

(If you are interested in build a smart home with Amazon Echo & ESP8266, check my previous post here. )

Sample code is as below:

#include"TFT_eSPI.h"
#include"Free_Fonts.h" //include the header file

#include <IRLibSendBase.h>    // First include the send base
//Now include only the protocols you wish to actually use.
//The lowest numbered protocol should be first but remainder 
//can be any order.
#include <IRLib_P01_NEC.h>    
#include <IRLib_P02_Sony.h>   
#include <IRLibCombo.h>     // After all protocols, include this

TFT_eSPI tft;

IRsend mySender;

void setup() {
  Serial.begin(115200);
  
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK); 
 
  tft.setFreeFont(FSSBO24);
  
  pinMode(WIO_5S_UP, INPUT_PULLUP);
  pinMode(WIO_5S_DOWM, INPUT_PULLUP);
  pinMode(WIO_5S_LEFT, INPUT_PULLUP);
  pinMode(WIO_5S_RIGHT, INPUT_PULLUP);
  pinMode(WIO_5S_PRESS, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(WIO_5S_UP) == LOW) {
    mySender.send(NEC,0x001C630CF, 0);//NEC TV sound Up 
    Serial.println("send");
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("Sound UP",5,100);
    delay(1000);
  }
  else if (digitalRead(WIO_5S_DOWM) == LOW) {
    mySender.send(NEC,0x001C6B04F, 0);//NEC TV sound Down 
    Serial.println("send");
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("Sound Down",5,100);
    delay(1000);
  }else if (digitalRead(WIO_5S_LEFT) == LOW) {
    
  }else if (digitalRead(WIO_5S_RIGHT) == LOW) {
    
  }else if (digitalRead(WIO_5S_PRESS) == LOW) {
    mySender.send(NEC,0x001C6F00F, 0);//NEC TV power 
    Serial.println("send");
    tft.fillScreen(TFT_BLACK); 
    tft.drawString("POWER",20,100);
    delay(1000);
  }
  tft.fillScreen(TFT_BLACK); 
}

This post talked about some basic functions of Wio Terminal and there are still a lot of functions waiting for you to explore! Stay tuned with us and check more interesting projects from the community.

About Author

Calendar

May 2020
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031