中文 | English
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.
Using the RTduino and Arduino libraries will be very easy through the RT-Thread Studio integrate development environment (IDE) with GUI configurations.
RTduino also allows users to directly run without a specific BSP supporting. Please see Chapter 5
Software Package: is RT-Thread side third party extension, and belongs to RT-Thread ecosystem.
Library: is Arduino side third party extension, and belongs to Arduino ecosystem.
Software package and library are the same meaning, but different names for RT-Thread and Arduino communities.
We will use STM32F103 BluePill BSP as an example to show how to use RTduino.
RTduino requires the minimum version of RT-Thread is 4.1.1
This vedio will also teach you how to import a BSP into RT-Thread Studio as a project
Please go to the RT-Thread repository to download the latest code
Download and install RT-Thread Studio IDE
Unzip the RT-Thread source code file and open RT-Thread Studio
File
-> Import
, and select RT-Thread BSP Project into Workspace
Browse
button and select the Blue Pill BSP folder: rt-thread\bsp\stm32\stm32f103-blue-pill
. This video also teaches you how to import a BSP project into RT-Thread Studio. Then, click Finish
button to let RT-Thread Studio to import the Blue Pill BSP project.RT-Thread Settings
. Then, click <<
button to show the configuration details.Hardware
, and select Compatible with Arduino Ecosystem (RTduino)
. Then, click the "hammer" button to compile the project. RT-Thread Studio will automatically download the RTduino and other dependency software packages and compile the whole 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 setup-loop framework, which is very common seen in an Arduino sketch?
Actually, the Arduino sketch is located in bsp/stm32/stm32f103-blue-pill/applications/arduino_main.cpp
, where is in the application
folder.
#include <Arduino.h>
void setup(void)
{
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(void)
{
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
Serial.println("Hello Arduino!");
delay(100);
}
You will see the LED is blinking and the serial terminal also shows "Hello Arduino!".
There are many other examples and demos at example folder
There are two main folders in RTduino: core and libraries.
You will find more information related a specific BSP Arduino pinout at: applications/arduino
folder. For Blue Pill BSP, it is located at here.
Notice: if has any question related the Arduino (third-party) libraries, please open an issue and report in this repository.
RTduino has supported most of Arduino build-in libraries, where is in the folder libraries/buildin
. The following table will show the details:
Library | Enable Macro | Note |
---|---|---|
Servo | RTDUINO_USING_SERVO | Enable by default if PWM is available. |
SPI | RTDUINO_USING_SPI | Enable by default if SPI is available. |
Wire | RTDUINO_USING_WIRE | Enable by default if I2C is available. |
USBSerial | RTDUINO_USING_USBSERIAL | Enable manually if is needed, and rely on the TinyUSB for RT-Thread software package automatically. |
In RT-Thread software center, there is a specific category for Arduino. RTduino community will register some important and frequent to use Arduino third party libraries to RT-Thread software package center, so that users can directly use those libraries with GUI configuration in RT-Thread Studio.
The following example will show how to enable Arduino Adafruit AHTx0 sensor driver library with a few clicks:
Please follow the previous chapter to import a project into RT-Thread Studio and select Compatible with Arduino Ecosystem (RTduino)
in RT-Thread Settings.
Please to go Software
column, and select Arduino libraries
category, and extend Sensors
sub-category of Arduino library. Then, select and enable the Adafruit AHTx0 Arduino driver library. RT-Thread Studio will help you to enable other dependency libraries, such as Adafruit Unified Sensor library, Adafruit BusIO library and so on.
arduino_main.cpp
file. Then, compile the project again and download the program into the board. You will see the current sensor data will show on the terminal. Now, we have successfully directly run Arduino library on RT-Thread.You also can directly import an Arduino library manually, which has not been registered into RT-Thread software package center. This operation also is very easy.
libraries\user
folder, and you don't need to decompress the ZIP file.Sync Sconscript to project
and click hammer to compile the project again.libraries\user
folder of the project group.pinMode
functionPWM, ADC or DAC feature pins cannot invoke pinMode
function to set as the GPIO, otherwise, the pins will lose the PWM, ADC or DAC features.
void setup() {
//pinMode(led_pin, OUTPUT); //Cannot use PinMode function, otherwise, led_pin will lose the PWM feature.
}
void loop() {
//Fading the LED
for(int i=0; i<255; i++){
analogWrite(led_pin, i);
delay(5);
}
for(int i=255; i>0; i--){
analogWrite(led_pin, i);
delay(5);
}
}
Arduino official document also suggests:
You do not need to call pinMode() to set the pin as an output before calling analogWrite().
The analogWrite function has nothing to do with the analog pins or the analogRead function.
If users use pinMode to set a PWM, ADC or DAC feature pin, RTduino also will gives an warning in terminal.
Of course, if the user already knows the consequences of doing so, it is completely possible to deliberately convert the PWM, ADC or DAC pins to ordinary IOs through the pinMode function.
Serial.begin()
Many Arduino example sketches ues Serial.begin(9600)
to initialize serials. However, in RTduino, it is highly suggested users to use Serial.begin()
, which is without bond parameter to initialize the serial, so that it can follow the original RT-Thread serial bond rate settings, which is 115200 by default for most of the BSPs. Unless you want to change the serial bond rate in RTduino sketch.
SPI.begin()
/ Wire.begin()
When operating SPI and Wire (I2C), the RT-Thread SPI and I2C devices called by default are defined in arduino_pin.h. When users use SPI and Wire libraries, they do not need to specify SPI and I2C devices, which is no different from using Arduino. If you use a non-default SPI/I2C, you only need to pass in the corresponding rt-thread device name in the initialization function, such as SPI.begin("spi1")
or Wire.begin("i2c1")
.
Some Arduino libraries will be adapted differently according to different architectures (including CPU architecture or different board structures). For RTduino, the recognition macro is ARDUINO_ARCH_RTTHREAD
. Please refer to this commit for adaptation.
https://github.com/RTduino/RTduino
https://gitee.com/rtduino/RTduino
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。