cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Arduino (STM32duino) Tutorial

ChahinezC
Lead

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

      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-IKS01A2
LSM6DSL
LSM303AGR
HTS221
LPS22HB
  • Then, include the libraries in the IDE from “Sketch -> Include Library -> Add .ZIP Library” as presented below: 
1313.jpg

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

 

If you prefer a Video Tutorial watch the content available in the link

 
 
Version history
Last update:
‎2021-03-22 06:57 AM
Updated by: