Coder Social home page Coder Social logo

pedrorovi / picostepper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dasenb/picostepper

0.0 0.0 0.0 42 KB

A Library to drive stepper motors using the Raspberry Pi Pico (RP2040)

License: GNU General Public License v3.0

C 77.41% CMake 22.59%

picostepper's Introduction

PicoStepper

A Library to drive stepper motors using the Raspberry Pi Pico (RP2040)

Installation

Add the picostepper folder to your project and adjust your CMakeLists.txt file on the basis of the CMakeLists.txt file in this repository. Then include picostepper.h in your code.

Examples

Blocking Movement

#include "picostepper.h"

int main() {
  uint base_pin = 10;
  PicoStepper device = picostepper_init(base_pin, FourWireDriver);

  uint steps = 4000;
  bool direction = true;
  uint delay = 1;
  int delay_change = 0;

  while (true)
  {
    picostepper_move_blocking(device, steps, direction, delay, delay_change );
    sleep_ms(5000);
  }

}

Non-Blocking Movement

#include "picostepper.h"

void movement_finished(PicoStepper device) {
  picostepper_move_async(device, 100, &movement_finished);
}

int main() {
  uint base_pin = 10;
  PicoStepper device = picostepper_init(base_pin, FourWireDriver);

  uint delay = 5;
  bool direction = true;
  bool enabled = true;
  uint steps = 10;


  picostepper_set_async_delay(device, delay);
  picostepper_set_async_direction(device, direction);
  picostepper_set_async_enabled(device, enabled);

  picostepper_move_async(device, steps, &movement_finished);

  while (true) {
    // Accelerate
    for (size_t i = 100; i > 0; i--)
    {
      picostepper_set_async_delay(device, i);
      sleep_ms(10);
    }

    //Deaccelerate
    for (size_t i = 0; i < 100; i++)
    {
      picostepper_set_async_delay(device, i);
      sleep_ms(10);
    }
  }
}

Hardware

For a device the lowest GPIO-Pin number is supplyed as the base-pin. The base-pin and the consecutive pins (depending on the driver-type) are then assigned to the picostepper. It is not possible to freely choose all individual pins independently.

Currently only one driver is implemented. The FourWireDriver is used to control drivers that require a direction-signal (DIR), an inverted direction-signal (!DIR), a step-signal (PUL) and an inverted step-signal (!PUL). Other devices can be supported easily by creating a corresponding PIO-program for the signal-generation. I plan to do so but pull requests are highly welcome.

picostepper's People

Contributors

dasenb avatar aidancrowther avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.