cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Arduino (STM32duino) tutorial

ChahinezC
Lead

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. In this article we use a STM32 Nucleo board and an ST MEMS shield. 
 

Step 1: Getting started with STM32duino

This part is about running a simple example on STM32duino which is blinking a LED.  
 

      1.1. Arduino IDE software installation

Follow the Arduino Software installation link  and finish it by executing the exe file.

      1.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.
1312.jpg
  • 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. 

      1.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

      2.1. Select the board

From: “Tools -> Board part number”, choose Nucleo-L476RG.

      2.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

 

Step 3: 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.

       3.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-IKS01A2
LSM6DSL
LSM303AGR
HTS221
LPS22HB

  • Then, include the libraries in the IDE from “Sketch -> Include Library -> Add .ZIP Library” as presented below: 
1313.jpg

        3.2. Add the STM32 board to the IDE 

  • To start and run a project, it is mandatory to select the board working with, so select the Nucleo boards through “Tools -> Board -> STM32 Boards -> Nucleo-64”. 

  • Later select the appropriate board through “Tools -> Board part number -> Nucleo F030R833 

Warning:  
Please make sure to choose the right port connected to the board. 

         3.3. Generate the example and run the code 

  • From “File -> Examples -> STM32duino LSM303AGR” and generate the example on the Arduino IDE:  

X-NUCLEO_IKS01A2_LSM303AGR_DataLog_Terminal 

1314.jpg

  • 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: 
    1315.jpg

Video tutorial:

Disclaimer: STMicroelectronics does not provide support to these libraries.

For any support on these libraries, refer to the STM32duino forum and STM32duino GitHub.

 
 
Version history
Last update:
‎2024-09-04 07:51 AM
Updated by:
Contributors