RT-Thread born in 2006, it’s an open-source, neutral, and community-based real-time operating system (RTOS). The software has the characteristics of very low resource occupancy, high reliability, high scalability, can be greatly used in sensing nodes, wireless connection chips and many resource-constrained scenes, also widely applied in gateway, IPC, smart speakers, and many other high-performance applications.
RT-Thread is also considered as an IoT platform with its rich middle-tier components and great hardware and software ecosystem, with almost every key basic component required for IoT devices, such as network protocols, file systems, low power management, etc. It supports all mainstream compiling tools such as GCC, Keil, IAR, etc., and a variety of standard interfaces, such as POSIX, CMSIS, C++application environment, Micropython, and Javascript, easy for developers to port a wide range of applications. RT-Thread also offers great commercial support to all the mainstream CPU architectures such as ARM Cortex-M/R/A, RISC-V, MIPS, X86, Xtensa, etc.
RT-Thread Features✅Designed for resource-constrained devices, the minimum kernel requires only 1.2KB of RAM and 3 KB of Flash.
✅A variety of standard interfaces, such as POSIX, CMSIS, C++ application environment.
✅Has rich components and a prosperous and fast growing package ecosystem.
✅Elegant code style, easy to use, read and master.
✅High Scalability. RT-Thread has high-quality scalable software architecture, loose coupling, modularity, is easy to tailor and expand.
✅Supports high-performance applications.
✅Supports all mainstream compiling tools such as GCC, Keil and IAR.
✅Supports a wide range of architectures and chips.
Hardware and Software Components
✅Computer/Laptop
✅RT-Thread Studio IDE
✅RTduino
✅WCHISPstudio
✅CH32V208W-R0
✅20x4 LCD I2C Enabled
✅MQ-135 Gas Sensor
✅USB Type-C Cable (Not a Power Cable)
✅Assorted Jumper Wires (i.e., Male to Female, Female to Female)
A. System Requirements
Before starting the installation process, make sure your computer meets the system requirements for RT-Thread Studio IDE. Typically, these requirements include:
✅Operating System: Windows, Linux, or macOS
✅RAM: 4GB or higher recommended
✅Disk Space: Several GB of free space
✅Java Runtime Environment (JRE) installed (preferably version 8 or later)
Please be guided that in this procedure, we will be using a Windows 10 Operating System.
B. Download and Install RT-Thread Studio IDE
1. Click the provided link to proceed to the download page of the RT-Thread Studio IDE. Download page link: RT-Thread | Download
2. Open the downloaded installer or .exe file and follow the instructions provided there.
3. Wait until the installation is done. Once the installation is done, you can now use the RT-Thread Studio IDE.
- Click the provided link to proceed to the download page of the RT-Thread GitHub Repository. Download page link: RT-Thread/rt-thread: RT-Thread is an open source IoT real-time operating system (RTOS). (github.com)
- Click “Code” and “Download ZIP” buttons.
- Once download is done, extract the files into the preferred location. Remember the location of the extracted files because this will be used later of the procedure.
- Click the provided link to proceed to the download page of the RT-Thread Studio IDE. Download page link: WCHISPTool_Setup.exe — NanjingQinhengMicroelectronics (wch-ic.com)
- Open the downloaded installer or .exe file and follow the instructions provided there.
- Wait until the installation is done. Once the installation is done, you can now use the WCHISPStudio.
- Open the RT-Thread Studio.
- Click SDK Manager. Install the “RISC-V-GCC-WCH” toolchain support package. After the installation, close the SDK Manager.
3. Click on “File” tab on the upper left portion of the RT-Thread Studion then click on the “Import”.
4. Select the “RT-Thread Bsp Project into Workspace” and fill-up the necessary information as preferred. Bsp location should be the location of the ch32v208w-r0 under the extracted files from the “II. Getting Started with the System: Download the RT-Thread GitHub Repository” procedure. Click “Finish” button if everything is good to go.
V. Getting Started with the System: Configuration of the Compiler of the RT-Thread Studio for the CH32V208-R0 Development Board.
- Click “right click” on the project located at the left side of the RT-Thread Studio.
2. Select the “RISC-V-GCC-WCH” toolchain path.
3. Modify the Toolchain Prefix to “‘risc-none-embed-”. Do not forget the “-” at the end of the prefix or it won’t compile and build.
4. Add path to the tool settings.
5. Clear the miscellaneous.
6. Modify the “rtconfig_preinc.h” located at the workspace location of your imported BSP.
7. Modify the “drv_common.c” located at the workspace location of your imported BSP.
8. Compile and build the project. In this step, you should be able to successfully build your project.
- In this procedure, we will be using the WCHISPStudio since I do not have a WCH-Link.
- Open the WCHISPStudio.
- Connect the USB Type-C Cable to the computer/laptop you are using and the CH32V208W-R) Development Board. Press the “Download Button” first then power up the CH32V208-R0 development board so that the bootloader will run.
4. Choose the appropriate setting for your CH32V208W-R0 development board and select the “.bin/.elf” file of the compiled project. Click the “deprotect button” first if the MCU code protect is enabled before downloading the file. In this step, you should be able to successfully upload your compiled project into the CH32V208W-R0 development board.
What is RTduino?
RTduino is the Arduino ecosystem compatibility layer for RT-Thread RTOS. RTduino is the sub-community of RT-Thread community and the downstream project of Arduino. RTduino is an open source project which is compatible with Arduino APIs so that RT-Thread beginners can easily get start to use RT-Thread through Arduino APIs, which significantly reduces the difficulty of learning RT-Thread. Meanwhile, RT-Thread users also can directly run thousands of Arduino third party libraries on RT-Thread by using RTduino.
- Click on your project located at the left side of the RT-Thread Studio. Click on the “RT-Thread Settings”, then click “<<” button to show the configuration details.
2. Click “Hardware”, and select “Onboard Peripheral Driver” and then the “Compatible with Arduino Ecosystem (RTduino)”. Press “CTRL+S” to save the settings and then, click the “hammer” button to compile and build the project. RT-Thread Studio will automatically download the RTduino and other dependency software packages and compile the whole project.
3. Click on the “On-chip Peripheral Drivers” and select “Enable I2C Bus”. Set the i2c1 scl pin number to “26” and the i2c1 sda pin number to “27”. Press “CTRL+S” to save the settings and then, click the “hammer” button to compile and build the project.
Now, you have successfully create a RT-Thread Blue Pill Board project and allow you to directly use Arduino APIs to drive this board. However, where is the void setup() and void loop() functions, which is very common seen in an Arduino sketch?
Actually, the Arduino sketch is located in your project under “applications” folder then “arduino_main.cpp” file.
IX. Connections of the CH32V208W-R0Shown below is the Wiring Diagram of the proposed project, indoor air quality monitoring system.
- Click the provided links to proceed to the GitHub repository of the LiquidCrystal_I2C and MQ135.
GitHub repository of LiquidCrystal_I2C: johnrickman/LiquidCrystal_I2C: LiquidCrystal Arduino library for the DFRobot I2C LCD displays (github.com)
GitHub repository of MQ135: GeorgK/MQ135: Arduino library for the MQ135 (github.com) - Click “Code” and “Download ZIP” buttons of each of the GitHub Repository.
- Once download is done, copy the ZIP files into the “libraries\user” folder, and you don’t need to decompress the ZIP file.
4. Then, go to RT-Thread Studio, right click the project, select “Sync Sconscript to project” and click hammer to compile the project again.
#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
#include "MQ135.h"
#define PIN_MQ135 A5
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
MQ135 mq135_sensor(PIN_MQ135);
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Paul Rodolf P Castor");
lcd.setCursor(0, 1);
lcd.print("CH32V208W-R0 IAQMS");
lcd.setCursor(0, 2);
lcd.print("System Initializing");
lcd.setCursor(0, 3);
for (int i = 0; i < 20; i++)
{
lcd.print(".");
}
lcd.setCursor(0, 3);
for (int i = 0; i < 20; i++)
{
lcd.print(" ");
}
lcd.setCursor(8, 3);
lcd.print("DONE");
lcd.setCursor(0, 2);
for (int i = 0; i < 20; i++)
{
lcd.print(" ");
}
lcd.setCursor(0, 3);
for (int i = 0; i < 20; i++)
{
lcd.print(" ");
}
lcd.setCursor(0, 2);
lcd.print("Real-time Air Status");
}
void loop()
{
float rzero = mq135_sensor.getRZero();
float resistance = mq135_sensor.getResistance();
float ppm = mq135_sensor.getPPM();
lcd.setCursor(6, 3);
lcd.print(ppm);
lcd.setCursor(11, 3);
lcd.print("ppm");
}
XII: Documentation
Comments