libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
stepper.c File Reference

Example: control a stepper motor. More...

#include "stdio.h"
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include "libpruio/pruio.h"
#include "libpruio/pruio_pins.h"
Include dependency graph for stepper.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE   1
 Message for the compiler.
 
#define P1   P8_08
 The first pin of the stepper.
 
#define P2   P8_10
 The second pin of the stepper.
 
#define P3   P8_12
 The third pin of the stepper.
 
#define P4   P8_14
 The fourth pin of the stepper.
 
#define PIN_OUT(a, b, c, d)
 Set values of all four output pins. More...
 

Functions

int isleep (unsigned int mseconds)
 Wait for keystroke or timeout. More...
 
void move (pruIo *Io, int Rot)
 Make the motor move the next step. More...
 
int main (int argc, char **argv)
 The main function. More...
 

Detailed Description

Example: control a stepper motor.

This file contains an example on how to use libpruio to control a 4-wire stepper motor:

  • configure 4 pins as output
  • receive user action in loop
  • inform user about the current state
  • change motor direction
  • change motor speed
  • stop holded or in power off mode
  • move a single step (in holded mode)
  • quit

Find a functional description in section stepper.

Licence: GPLv3, Copyright 2014-2023 by Thomas{ doT ]Freiherr[ At ]gmx[ DoT }net

Compile by: gcc -Wall -o stepper stepper.c -lpruio

Since
0.0

Definition in file stepper.c.

Macro Definition Documentation

◆ PIN_OUT

#define PIN_OUT (   a,
  b,
  c,
  d 
)
Value:
if (pruio_gpio_setValue(Io, P1, a)) {printf("setValue P1 error (%s)\n", Io->Errr); break;} \
if (pruio_gpio_setValue(Io, P2, b)) {printf("setValue P2 error (%s)\n", Io->Errr); break;} \
if (pruio_gpio_setValue(Io, P3, c)) {printf("setValue P3 error (%s)\n", Io->Errr); break;} \
if (pruio_gpio_setValue(Io, P4, d)) {printf("setValue P4 error (%s)\n", Io->Errr); break;}
UInt32 c
The number of cycles for each test.
Definition: performance.bas:91
char * pruio_gpio_setValue(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::setValue().
float_t d
the measured duty cycle
#define P3
The third pin of the stepper.
Definition: stepper.c:41
#define P1
The first pin of the stepper.
Definition: stepper.c:37
#define P4
The fourth pin of the stepper.
Definition: stepper.c:43
#define P2
The second pin of the stepper.
Definition: stepper.c:39

Set values of all four output pins.

Definition at line 73 of file stepper.c.

Function Documentation

◆ isleep()

int isleep ( unsigned int  mseconds)

Wait for keystroke or timeout.

Parameters
msecondsTimeout value in milliseconds.
Returns
0 if timeout, 1 if input available, -1 on error.

Wait for a keystroke or timeout and return which of the events happened.

Definition at line 54 of file stepper.c.

Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

The main function.

create new driver structure

Definition at line 109 of file stepper.c.

Here is the call graph for this function:

◆ move()

void move ( pruIo Io,
int  Rot 
)

Make the motor move the next step.

Parameters
IoPointer to PruIo structure.
RotRotation direction (1 or -1).

This function sets 4 output pins for a stepper motor driver. It remembers the last step as static variable (starting at 0 = zero) and adds the new position to it. So the Rot parameter should either be 1 or -1 to make the motor move one step in any direction.

Definition at line 90 of file stepper.c.

Here is the caller graph for this function: