How to get started with STM32duino: An example using STM32 Nucleo board + ST MEMS shield
This FAQ concerns the STM32duino, after following this tutorial, it will be possible to get to know how to use STM32 Nucleo boards within the Arduino IDE and generate codes to run on them.
Step1: Getting started with STM32duino
This part is about running a simple example on STM32duino which is blinking a LED.
1. Arduino IDE software installation
Follow the Arduino Software
installation link and finish it by executing the exe file.
2. Configure the settings:
- First, launch Arduino IDE, then go to “File -> Preferences”.
- Add the following link in the “Additional Boards Manager URLs”: github link.
- Then configure the “Automatic proxy configuration URL”.
Now you can find the STM32duino package in the board manager and install it by following the next steps.
3. Add the STM32duino package
Select: “Tools -> Board-> Boards Manager” and install STM32 Cores.
After finishing this step, the STM32 package will be installed, and the different ST compatible boards will be added to the tool.
At this point, it is possible to debug different projects on compatible ST boards. In this example, it will be a blinking a LED on the Nucleo-L476RG.
Step 2: LED blinking on Nucleo-L476RG
1. Select the board
From: “
Tools -> Board part number”, choose
Nucleo-L476RG.
2. Select the sample project
From “File -> example -> 01. Basics”, choose Blink.
The project is uploaded, and the last thing is to connect the board, click on “Upload” and the LED will be blinking on the board.
Note:
You can change the delay options, to see the LED blinking with, for example, 2s blinking and 1s not, by setting the parameters in the while loop:
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for 2 seconds
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
Step3: Shield Insertion and sensors’ data display using X-NUCLEO-IKS01A2
The main target of this part is including ST MEMS shields within the STM32 Nucleo Boards and programming it through Arduino IDE with the goal of displaying the data got from the sensors.
The hardware used is Nucleo-F030R8 and X-NUCLEO-IKS01A2.
1. Adding the required Packages
- Add the STM32 Core package from “Tools -> Board-> Boards Manager”, after adding the link in the “Additional Board Manager” as previously mentioned.
Note:
The sensors present on the IKS01A2 are:
- LSM6DSL 3D accelerometer and 3D gyroscope
- LSM 303A GR 3D accelerometer and 3D magnetometer
- HTS221 humidity and temperature sensor
- LPS22HB pressure sensor
|
- Now, download the X-NUCLEO-IKS01A2 libraries and examples, that are required for executing them, from the links below:
X-NUCLEO-IKS01A2LSM6DSLLSM303AGRHTS221LPS22HB
- Then, include the libraries in the IDE from “Sketch -> Include Library -> Add .ZIP Library” as presented below:
2. Add the STM32 board to the IDE
Warning:
Please make sure to choose the right port connected to the board.
3. Generate the example and run the code
X-NUCLEO_IKS01A2_LSM303AGR_DataLog_Terminal
- After compiling the project, please Plug ST MEMS and environmental sensor shield X-Nucleo-IKS01A2 on Nucleo-F030R8.
Now the project is ready to run on the ST board.
-
To display the values got from the sensors, open the Arduino Terminal from “Tools -> Serial Port” and select the frequency to 9600 as presented in the code:
// Initialize serial for output.
SerialPort.begin(9600);
At this point, the data can be displayed on the serial monitor as follows:
If you prefer a Video Tutorial watch the content available in the link