All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 "../c_wrapper/pruio.h"`
`#include "../c_wrapper/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

Licence: GPLv3

Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net

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

Definition in file stepper.c.

## Macro Definition Documentation

#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;}
P2
#define P2
The second pin of the stepper.
Definition: stepper.c:39
P1
#define P1
The first pin of the stepper.
Definition: stepper.c:37
P3
#define P3
The third pin of the stepper.
Definition: stepper.c:41
pruio_gpio_setValue
char * pruio_gpio_setValue(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::config().
P4
#define P4
The fourth pin of the stepper.
Definition: stepper.c:43
d
VAR d
The direction value.
Definition: stepper.bas:99

Set values of all four output pins.

Definition at line 73 of file stepper.c.

## Function Documentation

int isleep | ( | unsigned int | mseconds | ) |

Wait for keystroke or timeout.

Parameters

  mseconds | Timeout 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:

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:

void move | ( | pruIo * | Io,
|  | int | Rot
| ) |  |

Make the motor move the next step.

Parameters

  Io | Pointer to PruIo structure.
  Rot | Rotation 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: