Project Overview

This model uses the Wio Terminal external Grove - Multichannel Gas Sensor v2 to collect different odor data and train the model to differentiate between cola, alcohol and air.

Expected results

The desired result is shown below, where the Wio Terminal displays the name of the currently detected alcohol, cola, in real time.

Material Preparation

To achieve the above, we need:
Hardware requirements:

Connection method:
Smell Recognition by using Grove-Multichannel Gas Sensor - 图1
Note
Before using it, the sensor needs to be preheated to achieve the internal chemical balance. The preheat voltage is consistent with its heating voltage VH. And the storage time and corresponding warm-up time are recommended as follows:
How Does Storage Time Affect The Recommended Warm-Up Time of This Sensor?

Storage time Recommended warm-up time
Less than 1 month No less than 24 hrs
1-6 months No less than 48 hrs
Over 6 months No less than 72 hrs

Project Steps

  1. Creating and Selecting Models
  2. Data Acquisition
  3. Training and Deployment
  4. Programming

    Project Steps

    1. Create and select models

    1.1 Create a “ Smell Recognition (Grove - Multichannel Gas Sensor v2)” model

    Click on “Create and select model”, click on “ Smell Recognition (Grove - Multichannel Gas Sensor v2)”, as shown in steps 1 and 2 below.
    Smell Recognition by using Grove-Multichannel Gas Sensor - 图2
    Enter a NAME according to the requirements.
    Smell Recognition by using Grove-Multichannel Gas Sensor - 图3
    Smell Recognition by using Grove-Multichannel Gas Sensor - 图4
    Click Ok and it will automatically jump to the Data Acquisition interface.

    1.2 View the model

    Smell Recognition by using Grove-Multichannel Gas Sensor - 图5

    2. Acquisition of data

    2.1 Default label

    Smell Recognition by using Grove-Multichannel Gas Sensor - 图6
    Smell Recognition by using Grove-Multichannel Gas Sensor - 图7

    2.2 Connect the device and upload the default data acquisition program in Codecraft

    When the Wio Terminal is connected, in the Codecraft surface, please clickimage.png, in the location shown below. This action will upload the default data acquisition programme.
    Smell Recognition by using Grove-Multichannel Gas Sensor - 图9
    The “Upload” pop-up window will appear, as shown in the figure below.
    Select the serial port number corresponding to the current Wio Terminal (not necessarily COM26 as shown in the figure) and click the “OK” button.
    image.png
    A pop-up window indicates that it is being uploaded, please wait…
    image.png
    The upload time is usually tens of seconds, and you will see the “Upload Successful” screen shown below when it is completed. This is shown in the image below.
    image.png
    Click “Roger” to close the upload success pop-up window above and return to the programming screen.

Smell Recognition by using Grove-Multichannel Gas Sensor - 图13 Caution

For the web version of Codecraft, if you don’t install or run the Device Assistant, you may get the message in the image below that you haven’t opened the Device Assistant yet. image.png In this case you can check this page for further information: Download, installation and “Device Assistance” Usage

2.3 Acquisition of data

There is a step-by-step introduction to data acquisition in the upper right hyperlink, follow the instructions to collect data.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图15
Attention:

  • Wio Terminal button location.
  • Animated gif has been accelerated, the actual action can slightly slow down.
  • Please notice the red tips.
  • When you move the mouse over the description text, there will be more detailed content.

Smell Recognition by using Grove-Multichannel Gas Sensor - 图16
Smell Recognition by using Grove-Multichannel Gas Sensor - 图17
Starting and finishing data acquisition according to the Wio Terminal display.
image.png This signal means data is being collected.
image.png
image.pngOK means collection is complete.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图21
Wio Terminal shows that the data acquisition is finished, and CodeCraft is still uploading the data, it will take 1~2s to transfer the data from Wio Terminal to CodeCraft.
Now, the data acquisition is finished.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图22
Click on “Training & Deployment”Smell Recognition by using Grove-Multichannel Gas Sensor - 图23

2.4 Collecting data from custom labels

Sampling data for custom labels is similar to the steps for capturing default labels

  • Add or modify the labels
  • Upload the data acquisition programme
  • Collect data
  1. Adding or modifying labels
  • Adding lables

In the LABLE screen, clickimage.png, positioned as shown in the image below.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图25
Enter the label name and click “OK”.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图26
The new label “coffee” is added to the tab bar after successful addition.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图27

  • Modify a label

You can change one of the default labels to a custom label name by modifying the label name.
Click on the label to be modified, a pop-up window will appear for modifying the label, just enter a new name.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图28
The old label will be replaced with the modified label name after modification.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图29

  1. Upload the data acquisition programme
  • Adding lables

We can define the five-way switch in the block to collect more than 3 kinds of smells.
In this case we add “coffee” block use the “up” switch in five-way switch.
coffee.png
image.png
image.png

  • Modify a label

Select the block, as the picture below, and change the block name from “cola” to “coffee”.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图33
After the successful change, it is shown as the following red box.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图34
Click “Upload” to upload the data acquisition programme.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图35
Select the serial port number corresponding to the current Wio Terminal (not necessarily COM26 as shown in the figure) and click the “OK” button, as shown in steps 1 and 2 below
image.png
A pop-up window indicates that it is being uploaded, please wait and relax…
Smell Recognition by using Grove-Multichannel Gas Sensor - 图37
The upload time is usually 10s, and you will see the “Upload Successfully” when it is completed. This is shown in the image below.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图38
Click “Roger” to close the upload success pop-up window above and return to the programming screen.

3. Training and deployment

3.1 Set neural network and parameters

Select the suitable neural network size: one of small, medium and large
Set parameters, set the number of training cycles (positive integer), learning rate (number from 0 to 1), minimum confidence rating(number from 0 to 1).
The interface provides default parameter values.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图39

3.2 Start training the model

Click “Start training”
Smell Recognition by using Grove-Multichannel Gas Sensor - 图40
When you click “Start training”, the interface will say “Loading…”.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图41

The duration of “Loading..” varies depending on the size of the selected neural network (small, medium and large) and the number of training cycles, and the larger the size of the network and the number of training cycles, the longer it will take, so please be patient.

You can also infer the waiting time by observing the “Log”. In the figure below, “Epoch: 7/60” indicates that the total number of training rounds is 60, and 7 rounds have been trained.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图42
After loading, you can see “TrainModel Job Completed” in the “Log”,and “Model Training Report” will be appeared to the interface.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图43

3.3 Observe the model performance to select the ideal model

In the “Model Training Report” screen, you can observe the training results, including the accuracy, loss, and performance of the model on Wio Terminal.
If the training results are not satisfactory, you can go back to the first step of training the model, select another size of the neural network, or adjust the parameter settings and train again until you get a model with satisfactory results.
Smell Recognition by using Grove-Multichannel Gas Sensor - 图44

3.4 Deploy the ideal model

In the “Model Training Report” screen, click image.png
Smell Recognition by using Grove-Multichannel Gas Sensor - 图46
Smell Recognition by using Grove-Multichannel Gas Sensor - 图47
Click “Ok” to jump to the “Programming” screen after the pop-up window indicates that the deployment is complete.
image.png

4. Use and programming

4.1 Write the program for using the model

In the “Programming” interface, click on “Use Model” to use the deployed model.
image.png
Try to use your model by writing the following programme.
cola_result.png

4.2 Upload the program to Wio Terminal

Click the “Upload” button.
image.png
Select the serial port number corresponding to the current Wio Terminal (not necessarily COM26 as shown in the figure) and click the “OK” button.
image.png
The first upload time is long and increases with the complexity of the model, so please be patient. The upload time for small models is about 4 minutes or longer(depend on your performance of your machine).
Smell Recognition by using Grove-Multichannel Gas Sensor - 图53
image.png

4.3 Wio Terminal test model

Description of result:
Even if the training model score reaches high still does not mean that the model is a good model. The phenomenon of a high score of the training model and poor prediction in actual use is called OVERFITTING, which is equivalent to the model memorizing the details of the training dataset rigidly and will not do the problem when facing new data, and is a problem that machine learning training models will encounter.
The solutions to this problem are:

  • Increase the dataset
  • Reduce the learning rate

Retrain the model again.

Save

Click on image.png
image.png
Modify the name and click Save.
image.png
image.png

You can view the saved works in “My projects”
image.png
Click on “cola” to see the corresponding work.
image.png