Install simpleFOC Lib
Last updated
Last updated
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
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.
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:
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:
Select extension manager
Enter “PlatformIO” in the search
Choose PlatformIO extension from the list (should be the first result)
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!
To create a new project that uses SimpleFOC, use the following steps:
Select the PlatformIO Menu on the left sidebar
Choose Open to open the platformIO home screen
Click “New Project”
You will be taken to the new project wizard:
Give your project a name, e.g. simplefoc_test_project
Choose your board. SimpleFOC supports many MCU architectures, see [hardware/mcus]
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.
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!
When everything is finished installing, you should be presented with a view like this:
You can now add the SimpleFOC library to the project:
Click on the PlatformIO icon, and choose “Libraries” from the Menu
Enter “Simple FOC” in the search
Click on the library
Click on “Add Library” to display the “Add Library” wizard
Choose your project from the drop-down
Click “Add” to add the library
Cool! The SimpleFOC library is now associated with 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:
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.
The available options depend on your board, and we cannot cover them all here, but they are documented in PlatformIO’s documentation.
You can begin to write your code in the src/main.cpp file.
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:
Using your favourite git client, clone the simplefoc library from https://github.com/simplefoc/Arduino-FOC.git
This will create a folder “Arduino-FOC” on your file-system, containing the library source code
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.
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