{"id":30342172,"url":"https://github.com/simplefoc/Arduino-FOC","last_synced_at":"2025-08-18T10:03:48.111Z","repository":{"id":36999084,"uuid":"173681491","full_name":"simplefoc/Arduino-FOC","owner":"simplefoc","description":"Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library","archived":false,"fork":false,"pushed_at":"2025-08-11T13:39:54.000Z","size":10735,"stargazers_count":2431,"open_issues_count":70,"forks_count":620,"subscribers_count":81,"default_branch":"master","last_synced_at":"2025-08-13T10:05:20.719Z","etag":null,"topics":["arduino","arduino-foc","arduino-library","arduino-simplefoc","bldc-motor","bldc-motor-controller","bldc-motors","encoder","foc","foc-algorithm","low-cost","motor","stepper-library","stepper-motor","stepper-motor-control","vector-control"],"latest_commit_sha":null,"homepage":"https://docs.simplefoc.com","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplefoc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-03-04T05:49:09.000Z","updated_at":"2025-08-13T06:27:06.000Z","dependencies_parsed_at":"2023-01-17T12:47:33.282Z","dependency_job_id":"65d43715-ded2-4adf-a7d2-b8d1b5d311d1","html_url":"https://github.com/simplefoc/Arduino-FOC","commit_stats":{"total_commits":964,"total_committers":45,"mean_commits":21.42222222222222,"dds":"0.34232365145228216","last_synced_commit":"c72f063f3d2d2e26d49a22a7383310cf8f88134b"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/simplefoc/Arduino-FOC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplefoc%2FArduino-FOC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplefoc%2FArduino-FOC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplefoc%2FArduino-FOC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplefoc%2FArduino-FOC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplefoc","download_url":"https://codeload.github.com/simplefoc/Arduino-FOC/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplefoc%2FArduino-FOC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270843625,"owners_count":24655424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","arduino-foc","arduino-library","arduino-simplefoc","bldc-motor","bldc-motor-controller","bldc-motors","encoder","foc","foc-algorithm","low-cost","motor","stepper-library","stepper-motor","stepper-motor-control","vector-control"],"created_at":"2025-08-18T10:02:01.633Z","updated_at":"2025-08-18T10:03:48.089Z","avatar_url":"https://github.com/simplefoc.png","language":"C++","funding_links":[],"categories":["硬件_其他","C++"],"sub_categories":["资源传输下载"],"readme":"# SimpleFOClibrary - **Simple** Field Oriented Control (FOC) **library** \u003cbr\u003e \n### A Cross-Platform FOC implementation for BLDC and Stepper motors\u003cbr\u003e based on the Arduino IDE and PlatformIO \n\n[![AVR build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/arduino.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/arduino.yml)\n[![STM32 build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/stm32.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/stm32.yml)\n[![ESP32 build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/esp32.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/esp32.yml)\n[![RP2040 build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/rpi.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/rpi.yml)\n[![SAMD build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/samd.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/samd.yml)\n[![Teensy build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/teensy.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/teensy.yml) \n[![MBED build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/arduino_mbed.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/arduino_mbed.yml)\n\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/simplefoc/arduino-foc)\n![GitHub Release Date](https://img.shields.io/github/release-date/simplefoc/arduino-foc?color=blue)\n![GitHub commits since tagged version](https://img.shields.io/github/commits-since/simplefoc/arduino-foc/latest/dev)\n![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/m/simplefoc/arduino-foc/dev)\n\n[![arduino-library-badge](https://www.ardu-badge.com/badge/Simple%20FOC.svg)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/askuric/library/Simple%20FOC.svg)](https://registry.platformio.org/libraries/askuric/Simple%20FOC)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![status](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d/status.svg)](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d)\n\n\nWe live in very exciting times 😃! BLDC motors are entering the hobby community more and more and many great projects have already emerged leveraging their far superior dynamics and power capabilities. BLDC motors have numerous advantages over regular DC motors but they have one big disadvantage, the complexity of control. Even though it has become relatively easy to design and manufacture PCBs and create our own hardware solutions for driving BLDC motors the proper low-cost solutions are yet to come. One of the reasons for this is the apparent complexity of writing the BLDC driving algorithms, Field oriented control (FOC) being an example of one of the most efficient ones.\nThe solutions that can be found on-line are almost exclusively very specific for certain hardware configuration and the microcontroller architecture used.\nAdditionally, most of the efforts at this moment are still channeled towards the high-power applications of the BLDC motors and proper low-cost and low-power FOC supporting boards are very hard to find today and even may not exist. \u003cbr\u003e\nTherefore this is an attempt to: \n- 🎯 Demystify FOC algorithm and make a robust but simple Arduino library: [Arduino *SimpleFOClibrary*](https://docs.simplefoc.com/arduino_simplefoc_library_showcase)\n  - \u003ci\u003eSupport as many \u003cb\u003emotor + sensor + driver + mcu\u003c/b\u003e combinations out there\u003c/i\u003e\n- 🎯 Develop modular and easy to use FOC supporting BLDC driver boards\n   - For official driver boards see [\u003cspan class=\"simple\"\u003eSimple\u003cspan class=\"foc\"\u003eFOC\u003c/span\u003eBoards\u003c/span\u003e](https://docs.simplefoc.com/boards)\n   - Many many more boards developed by the community members, see [\u003cspan class=\"simple\"\u003eSimple\u003cspan class=\"foc\"\u003eFOC\u003c/span\u003eCommunity\u003c/span\u003e](https://community.simplefoc.com/)\n\n\u003e NEXT RELEASE 📢 : \u003cspan class=\"simple\"\u003eSimple\u003cspan class=\"foc\"\u003eFOC\u003c/span\u003elibrary\u003c/span\u003e v2.3.5 \n\u003e\n\u003e - ESP32 bugfix \n\u003e   - after the low-level API changes in the Arduino-ESP32 core [PR447](https://github.com/simplefoc/Arduino-FOC/pull/447)\n\u003e   - Pin is not configured [PR458](https://github.com/simplefoc/Arduino-FOC/pull/458)\n\u003e   - C6 MCPWM bugfix [PR440](https://github.com/simplefoc/Arduino-FOC/pull/440)\n\u003e - New fuctionality\n\u003e   - HybridStepperMotor added to the main library [PR457](https://github.com/simplefoc/Arduino-FOC/pull/457) - [see in docs](https://docs.simplefoc.com/steppermotor)\n\u003e   - Motor characterisation (phase resistance and inductance) [PR436](https://github.com/simplefoc/Arduino-FOC/pull/436) - [see in docs](https://docs.simplefoc.com/bldcmotor#how-can-i-measure-the-phase-resistance-and-inductance)\n\u003e - SAMD21 support for low-side current sensing [PR479](https://github.com/simplefoc/Arduino-FOC/pull/479)\n\u003e - RP2350 support [PR435](https://github.com/simplefoc/Arduino-FOC/pull/435) [PR468](https://github.com/simplefoc/Arduino-FOC/pull/468)\n\u003e - STM32\n\u003e   - New driver code [PR442](https://github.com/simplefoc/Arduino-FOC/pull/442)\n\u003e   - Low-side current sensing support for H7 family [PR460](https://github.com/simplefoc/Arduino-FOC/pull/460)\n\u003e - Docs\n\u003e   - Hybrid stepper motor example [see in docs](https://docs.simplefoc.com/stepper_control_shield)\n\u003e   - Sensorless FOC example [see in docs](https://docs.simplefoc.com/sensorless_foc_nucleo_example)\n\u003e   - A short guide to synchronous loop - [see in docs](https://docs.simplefoc.com/real_time_loop)\n\u003e - See the complete list of bugfixes and new features of v2.3.5 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/12) \n\n\n\n\n## Arduino *SimpleFOClibrary* v2.3.5\n\n\u003cp align=\"\"\u003e\n\u003ca href=\"https://youtu.be/Y5kLeqTc6Zk\"\u003e\n\u003cimg src=\"https://docs.simplefoc.com/extras/Images/youtube.png\"  height=\"320px\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\nThis video demonstrates the *Simple**FOC**library* basic usage, electronic connections and shows its capabilities.\n\n### Features\n- **Easy install**: \n   - Arduino IDE: Arduino Library Manager integration\n   - PlatformIO\n- **Open-Source**: Full code and documentation available on github\n- **Goal**: \n   - Support as many [sensor](https://docs.simplefoc.com/position_sensors) + [motor](https://docs.simplefoc.com/motors) + [driver](https://docs.simplefoc.com/drivers) + [current sense](https://docs.simplefoc.com/current_sense)   combination as possible.\n   - Provide the up-to-date and in-depth documentation with API references and the examples\n- **Easy to setup and configure**: \n   - Easy hardware configuration \n   - Each hardware component is a C++ object (easy to understand) \n   - Easy [tuning the control loops](https://docs.simplefoc.com/motion_control)\n   - [*Simple**FOC**Studio*](https://docs.simplefoc.com/studio) configuration GUI tool\n   - Built-in communication and monitoring\n- **Cross-platform**:\n   - Seamless code transfer from one microcontroller family to another \n   - Supports multiple [MCU architectures](https://docs.simplefoc.com/microcontrollers):\n      - Arduino: UNO R4, UNO, MEGA, DUE, Leonardo, Nano, Nano33 ....\n      - STM32\n      - ESP32\n      - Teensy\n      - many more ...\n\n\u003cp align=\"\"\u003e \u003cimg src=\"https://docs.simplefoc.com/extras/Images/uno_l6234.jpg\"  height=\"170px\"\u003e  \u003cimg src=\"https://docs.simplefoc.com/extras/Images/hmbgc_v22.jpg\" height=\"170px\"\u003e  \u003cimg src=\"https://docs.simplefoc.com/extras/Images/foc_shield_v13.jpg\"  height=\"170px\"\u003e\u003c/p\u003e\n\n\n## Documentation\nFull API code documentation as well as example projects and step by step guides can be found on our [docs website](https://docs.simplefoc.com/).\n\n![image](https://user-images.githubusercontent.com/36178713/168475410-105e4e3d-082a-4015-98ff-d380c7992dfd.png)\n\n\n## Getting Started\nDepending 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.\n\n- Full library installation [Docs](https://docs.simplefoc.com/library_download)\n- PlatformIO [Docs](https://docs.simplefoc.com/library_platformio)\n\n### Arduino *SimpleFOClibrary* installation to Arduino IDE\n#### Arduino Library Manager \nThe simplest way to get hold of the library is directly by using Arduino IDE and its integrated Library Manager. \n- Open Arduino IDE and start Arduino Library Manager by clicking: `Tools \u003e Manage Libraries...`.\n- Search for `Simple FOC` library and install the latest version.\n- Reopen Arduino IDE and you should have the library examples in `File \u003e Examples \u003e Simple FOC`.\n\n#### Using Github website \n- Go to the [github repository](https://github.com/simplefoc/Arduino-FOC)\n- Click first on `Clone or Download \u003e Download ZIP`. \n- Unzip it and place it in `Arduino Libraries` folder. Windows: `Documents \u003e Arduino \u003e libraries`.  \n- Reopen Arduino IDE and you should have the library examples in `File \u003e Examples \u003e Simple FOC`.\n\n#### Using terminal\n- Open terminal and run\n```sh  \ncd #Arduino libraries folder\ngit clone https://github.com/simplefoc/Arduino-FOC.git\n```\n- Reopen Arduino IDE and you should have the library examples in `File \u003e Examples \u003e Simple FOC`.\n\n## Community and contributing\n\nFor all the questions regarding the potential implementation, applications, supported hardware and similar please visit our [community forum](https://community.simplefoc.com) or our [discord server](https://discord.gg/kWBwuzY32n).\n\nIt is always helpful to hear the stories/problems/suggestions of people implementing the code and you might find a lot of answered questions there already! \n\n### Github Issues \u0026 Pull requests\n\nPlease do not hesitate to leave an issue if you have problems/advices/suggestions regarding the code!\n\nPull requests are welcome, but let's first discuss them in [community forum](https://community.simplefoc.com)!\n\nIf you'd like to contribute to this project but you are not very familiar with github, don't worry, let us know either by posting at the community forum , by posting a github issue or at our discord server.\n\nIf you are familiar, we accept pull requests to the dev branch!\n\n## Arduino code example\nThis is a simple Arduino code example implementing the velocity control program of a BLDC motor with encoder. \n\nNOTE: This program uses all the default control parameters.\n\n```cpp\n#include \u003cSimpleFOC.h\u003e\n\n//  BLDCMotor( pole_pairs )\nBLDCMotor motor = BLDCMotor(11);\n//  BLDCDriver( pin_pwmA, pin_pwmB, pin_pwmC, enable (optional) )\nBLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8);\n//  Encoder(pin_A, pin_B, CPR)\nEncoder encoder = Encoder(2, 3, 2048);\n// channel A and B callbacks\nvoid doA(){encoder.handleA();}\nvoid doB(){encoder.handleB();}\n\n\nvoid setup() {  \n  // initialize encoder hardware\n  encoder.init();\n  // hardware interrupt enable\n  encoder.enableInterrupts(doA, doB);\n  // link the motor to the sensor\n  motor.linkSensor(\u0026encoder);\n  \n  // power supply voltage [V]\n  driver.voltage_power_supply = 12;\n  // initialise driver hardware\n  driver.init();\n  // link driver\n  motor.linkDriver(\u0026driver);\n\n  // set control loop type to be used\n  motor.controller = MotionControlType::velocity;\n  // initialize motor\n  motor.init();\n  \n  // align encoder and start FOC\n  motor.initFOC();\n}\n\nvoid loop() {\n  // FOC algorithm function\n  motor.loopFOC();\n\n  // velocity control loop function\n  // setting the target velocity or 2rad/s\n  motor.move(2);\n}\n```\nYou can find more details in the [SimpleFOC documentation](https://docs.simplefoc.com/).\n\n## Example projects\nHere are some of the *Simple**FOC**library* and *Simple**FOC**Shield* application examples. \n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://youtu.be/Ih-izQyXJCI\"\u003e\n\u003cimg src=\"https://docs.simplefoc.com/extras/Images/youtube_pendulum.png\"  height=\"200px\" \u003e\n\u003c/a\u003e\n\u003ca href=\"https://youtu.be/xTlv1rPEqv4\"\u003e\n\u003cimg src=\"https://docs.simplefoc.com/extras/Images/youtube_haptic.png\"  height=\"200px\" \u003e\n\u003c/a\u003e\n\u003ca href=\"https://youtu.be/RI4nNMF608I\"\u003e\n\u003cimg src=\"https://docs.simplefoc.com/extras/Images/youtube_drv8302.png\"  height=\"200px\" \u003e\n\u003c/a\u003e\n\u003ca href=\"https://youtu.be/zcb86TRxTxc\"\u003e\n\u003cimg src=\"https://docs.simplefoc.com/extras/Images/youtube_stepper.png\"  height=\"200px\" \u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n\n## Citing the *SimpleFOC* \n\nWe are very happy that *Simple**FOC**library* has been used as a component of several research project and has made its way to several scientific papers.  We are hoping that this trend is going to continue as the project matures and becomes more robust! \nA short resume paper about *Simple**FOC*** has been published in the Journal of Open Source Software: \n\u003cp\u003e\n  \u003cb\u003e\u003ci\u003eSimpleFOC\u003c/i\u003e\u003c/b\u003e: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors.\u003cbr\u003e\n  A. Skuric, HS. Bank, R. Unger, O. Williams, D. González-Reyes\u003cbr\u003e\nJournal of Open Source Software, 7(74), 4232, https://doi.org/10.21105/joss.04232\n\u003c/p\u003e\n\nIf you are interested in citing  *Simple**FOC**library* or some other component of *Simple**FOC**project* in your research, we suggest you to cite our paper:\n\n```bib\n@article{simplefoc2022,\n  doi = {10.21105/joss.04232},\n  url = {https://doi.org/10.21105/joss.04232},\n  year = {2022},\n  publisher = {The Open Journal},\n  volume = {7},\n  number = {74},\n  pages = {4232},\n  author = {Antun Skuric and Hasan Sinan Bank and Richard Unger and Owen Williams and David González-Reyes},\n  title = {SimpleFOC: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors},\n  journal = {Journal of Open Source Software}\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplefoc%2FArduino-FOC","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplefoc%2FArduino-FOC","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplefoc%2FArduino-FOC/lists"}