# Arduino-FOC **Repository Path**: wave1021/Arduino-FOC ## Basic Information - **Project Name**: Arduino-FOC - **Description**: Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-09-10 - **Last Updated**: 2021-09-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Arduino Simple Field Oriented Control (FOC) library ![Library Compile](https://github.com/simplefoc/Arduino-FOC/workflows/Library%20Compile/badge.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![arduino-library-badge](https://www.ardu-badge.com/badge/Simple%20FOC.svg?)](https://www.ardu-badge.com/badge/Simple%20FOC.svg) Proper low-cost and low-power FOC supporting boards are very hard to find today and even may not exist. Even harder to find is a stable and simple FOC algorithm code for BLDC and Stepper motors capable of running on Arduino devices. Therefore this is an attempt to: - Demystify FOC algorithm and make a robust but simple Arduino library: [Arduino *SimpleFOClibrary*](https://docs.simplefoc.com/arduino_simplefoc_library_showcase) - Develop a modular BLDC driver board: [Arduino *SimpleFOCShield*](https://docs.simplefoc.com/arduino_simplefoc_shield_showcase). - ***New 📢:** Develop a modular Stepper motor board for FOC control:* Arduino StepperFOCShield > NEW RELEASE 📢: SimpleFOClibrary v2.0.2 > - Arduino MEGA 2560 support > - OSC example project by [@runger1101001](https://github.com/runger1101001) > - floating point bug - open loop velocity by [@ATILIUS-REGULUS](https://github.com/ATILIUS-REGULUS) > SimpleFOClibrary v2.0.1 > - ESP32 bugfix > - frequency setting > - pwm resolution > - 2PWM stepper class added `StepperMotor2PWM` > - some refactoring of examples ## Arduino *SimpleFOCShield*

### Features - **Plug & play**: In combination with Arduino SimpleFOClibrary - **Low-cost**: Price of €15 - [Check the pricing](https://www.simplefoc.com/simplefoc_shield_product) - **Max power 100W** - max current 5A, power-supply 12-24V - Designed for Gimbal motors with the internal resistance >10 Ω. - **Stackable**: running 2 motors in the same time - **Encoder/Hall sensor interface**: Integrated 3.3kΩ pullups (configurable) - **I2C interface**: Integrated 4.7kΩ pullups (configurable) - **Configurable pinout**: Hardware configuration - soldering connections - **Arduino headers**: Arduino UNO, Arduino MEGA, STM32 Nucleo boards... - **Open Source**: Fully available fabrication files - [how to make it yourself](https://www.simplefoc.com/arduino_simplefoc_shield_fabrication), ##### If you are interested in this board, order your version on this link: [Shop](https://www.simplefoc.com/simplefoc_shield_product)

## Arduino *SimpleFOClibrary*

This video demonstrates the *Simple**FOC**library* basic usage, electronic connections and shows its capabilities. ### Features - **Arduino compatible**: - Arduino library code - Arduino Library Manager integration - **Open-Source**: Full code and documentation available on github - **Easy to setup and configure**: - Easy hardware configuration - Easy [tuning the control loops](https://docs.simplefoc.com/motion_control) - **Modular**: - Supports as many [sensors, BLDC motors and driver boards](https://docs.simplefoc.com/supported_hardware) as possible - Supports multiple [MCU architectures](https://docs.simplefoc.com/microcontrollers): - Arduino: UNO, MEGA, any board with ATMega328 chips - STM32 boards: [Nucleo](https://www.st.com/en/evaluation-tools/stm32-nucleo-boards.html), [Bluepill](https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html) ... - ESP32 - Teensy boards - **Plug & play**: Arduino SimpleFOCShield

## Getting Started Depending on if you want to use this library as the plug and play Arduino library or you want to get insight in the algorithm and make changes there are two ways to install this code. - Full library installation [Docs](https://docs.simplefoc.com/library_download) - Minimal project builder [Docs](https://docs.simplefoc.com/minimal_download) ### Arduino *SimpleFOClibrary* installation to Arduino IDE #### Arduino Library Manager The simplest way to get hold of the library is directly by using Arduino IDE and its integrated Library Manager. - Open Arduino IDE and start Arduino Library Manager by clicking: `Tools > Manage Libraries...`. - Search for `Simple FOC` library and install the latest version. - Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`. #### Using Github website - Go to the [github repository](https://github.com/simplefoc/Arduino-FOC) - Click first on `Clone or Download > Download ZIP`. - Unzip it and place it in `Arduino Libraries` folder. Windows: `Documents > Arduino > libraries`. - Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`. #### Using terminal - Open terminal and run ```sh cd #Arduino libraries folder git clone https://github.com/simplefoc/Arduino-FOC.git ``` - Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`. ### *SimpleFOClibrary* minimal project builder For those willing to experiment and to modify the code I suggest using the minimal project builder [minimal branch](https://github.com/simplefoc/Arduino-FOC/tree/minimal). > This code is completely independent and you can run it as any other Arduino Sketch without the need for any libraries. All you need to do is: - Go to [minimal branch](https://github.com/simplefoc/Arduino-FOC/tree/minimal) - Follow the tutorial in the README file and choose only the library files that are necessary for your application. ## Arduino code example This is a simple Arduino code example implementing the velocity control program of a BLDC motor with encoder. NOTE: This program uses all the default control parameters. ```cpp #include // BLDCMotor( pole_pairs ) BLDCMotor motor = BLDCMotor(11); // BLDCDriver( pin_pwmA, pin_pwmB, pin_pwmC, enable (optional) ) BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8); // Encoder(pin_A, pin_B, CPR) Encoder encoder = Encoder(2, 3, 2048); // channel A and B callbacks void doA(){encoder.handleA();} void doB(){encoder.handleB();} void setup() { // initialize encoder hardware encoder.init(); // hardware interrupt enable encoder.enableInterrupts(doA, doB); // link the motor to the sensor motor.linkSensor(&encoder); // power supply voltage [V] driver.voltage_power_supply = 12; // initialise driver hardware driver.init(); // link driver motor.linkDriver(&driver); // set control loop type to be used motor.controller = ControlType::velocity; // initialize motor motor.init(); // align encoder and start FOC motor.initFOC(); } void loop() { // FOC algorithm function motor.loopFOC(); // velocity control loop function // setting the target velocity or 2rad/s motor.move(2); } ``` You can find more details in the [SimpleFOC documentation](https://docs.simplefoc.com/). ## Example projects Here are some of the *Simple**FOC**library* and *Simple**FOC**Shield* application examples.

## Documentation Find out more information about the Arduino SimpleFOC project in [docs website](https://docs.simplefoc.com/) ## Arduino FOC repo structure Branch | Description | Status ------------ | ------------- | ------------ [master](https://github.com/simplefoc/Arduino-FOC) | Stable and tested library version | ![Library Compile](https://github.com/simplefoc/Arduino-FOC/workflows/Library%20Compile/badge.svg) [dev](https://github.com/simplefoc/Arduino-FOC/tree/dev) | Development library version | ![Library Dev Compile](https://github.com/simplefoc/Arduino-FOC/workflows/Library%20Dev%20Compile/badge.svg?branch=dev) [minimal](https://github.com/simplefoc/Arduino-FOC/tree/minimal) | Minimal Arduino example with integrated library | ![MinimalBuild](https://github.com/simplefoc/Arduino-FOC/workflows/MinimalBuild/badge.svg?branch=minimal)