RobotLabs
  • Welcome
  • ESP32
    • PlatformIO
      • 1.1 Arduino Basics
      • 1.2 Install PlatformIO
      • 2.1 GPIO - LED Blink
      • 2.2 GPIO - LED Multi
      • 2.3 GPIO - LED Button
      • 3.1 PWM - LED Fade
      • 3.2 ADC - Analog Input
      • 4.1 IIC - OLED
    • MicroPython
    • ESP32 Projects
  • ROS
    • ROS2 Jazzy
      • 1.1 Install ROS 2 Jazzy
      • 1.2 Install VS Code
      • 1.3 Save ROS code on GitHub
      • 2.1 Create a Mobile Robot with URDF and Visualize it
      • 2.3 Create Launch Files to Display the URDF in RViz
      • 2.4 Simulation with Gazebo
      • 2.5 Gazebo sensors
      • 2.6 Sensor fusion and SLAM
    • MoveIt2
      • Moveit 2 joint position control with keyboard
      • Moveit2 joint velocity control for Panda robot arm
    • Perception
      • PCL-ROS
  • FOC
    • SimpleFOC
      • Install simpleFOC Lib
  • Template
    • Markdown
    • Interactive blocks
    • OpenAPI
    • Integrations
Powered by GitBook
On this page
  • Installing SimpleFOClibrary with PlatformIO
  • Quick setup for pros
  • Detailed instructions
  • Prerequisites
  • Creating a project
  • Add SimpleFOClibrary to your project
  • Configure your project
  • Code away!
  • Advanced Usage
  1. FOC
  2. SimpleFOC

Install simpleFOC Lib

PreviousSimpleFOCNextMarkdown

Last updated 5 months ago

There are two ways to install this Arduino library, depending on your plans with the code and your particular application.

    • Plug & play functionality

    • Many examples

    • Easy to access through Arduino IDE

  • PlatformIO

    • Integration into the VSCode

    • Easier experimentation and interaction with the library source code directly

Installing SimpleFOClibrary with PlatformIO

Using SimpleFOC from PlatformIO is not hard at all! The following instructions should get you set up and compiling your code in a matter of minutes.

Quick setup for pros

You can use SimpleFOC in Arduino projects in PlatformIO. Just add the library via the library manager.

You will need this option in your platformio.ini file:

lib_archive = false

Detailed instructions

Prerequisites

  • You need an active internet connection throughout this process, until your project is set up.

  • Run Visual Studio Code, and install PlatformIO using the Extensions Manager:

  1. Select extension manager

  2. Enter “PlatformIO” in the search

  3. Choose PlatformIO extension from the list (should be the first result)

  4. Click install - after a few moments PlatformIO will be installed, you will be prompted to reload Visual Studio Code

Congratulations, you’re ready to start your first project!

Creating a project

To create a new project that uses SimpleFOC, use the following steps:

  1. Select the PlatformIO Menu on the left sidebar

  2. Choose Open to open the platformIO home screen

  3. Click “New Project”

You will be taken to the new project wizard:

  1. Give your project a name, e.g. simplefoc_test_project

  2. Choose your board. SimpleFOC supports many MCU architectures, see [hardware/mcus]

  3. Once you have chosen your board, make sure the Framework “Arduino” is selected. PlatformIO supports other Frameworks, but SimpleFOC is an Arduino Library and must be run in Arduino framework.

  4. Click finish

At this point, if it is the first project you are creating for this board, PlatformIO will download all the required compilers, tools and core library files. Depending on your internet speed, this can take quite a few minutes, so please be patient!

Add SimpleFOClibrary to your project

When everything is finished installing, you should be presented with a view like this:

You can now add the SimpleFOC library to the project:

  1. Click on the PlatformIO icon, and choose “Libraries” from the Menu

  2. Enter “Simple FOC” in the search

  3. Click on the library

  1. Click on “Add Library” to display the “Add Library” wizard

  1. Choose your project from the drop-down

  2. Click “Add” to add the library

Cool! The SimpleFOC library is now associated with your project.

Configure your project

Open the platformio.ini file in the root directory of your project. It should look something like this, depending on the board you chose:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:mkrwifi1010]
platform = atmelsam
board = mkrwifi1010
framework = arduino
lib_deps = askuric/Simple FOC@^2.2
lib_archive = false

IMPORTANT! ⚠️

You have to add the line lib_archive = false to make SimpleFOC compile correctly with PlatformIO.

You may also want to add some other options, like monitor_speed to set the serial port speed for debug output.

monitor_speed = 115200

The available options depend on your board, and we cannot cover them all here, but they are documented in PlatformIO’s documentation.

Code away!

You can begin to write your code in the src/main.cpp file.

Advanced Usage

PlatformIO makes it easy for you to use the source version of the SimpleFOC library. This lets you modify the code, or use the most recent “dev” branch version of the library to try out new features before they are officially released.

To use the source code version of the library, try the following steps:

  1. Using your favourite git client, clone the simplefoc library from https://github.com/simplefoc/Arduino-FOC.git

  2. This will create a folder “Arduino-FOC” on your file-system, containing the library source code

  3. Go to your PlatformIO project, and inside the project go to the lib folder. You can use your operating system’s shell, or the built-in shell in Visual Studio Code.

  4. Inside the lib folder of your project, create a symlink to your Arduino-FOC folder Mac/Linux: % ln -s /path/to/Arduino-FOC Windows: % mklink /J Arduino-FOC C:\path\to\Arduino-FOC

Note: If you had previously added the release version of the library to the project using PlatformIO’s library management, you will have to remove this reference from the platformio.ini file

First, install

Reference: SimpleFOC Docs

Full Arduino library installation
Visual Studio Code
https://docs.simplefoc.com/library_platformio