StepperUNO Library 1.4: Difference between revisions

From lechacal
Jump to navigation Jump to search
Line 62: Line 62:


==Motor Control==
==Motor Control==
===void speed(int speed_m1);===
===void set_speed(uint16_t step_delay)===
Set the motor speed.
Set the motor speed.


speed_m1 must be the delay between each step in milliseconds.
step_delay is the delay between steps in microseconds.
 
===uint8_t set_speed_rpm(float rpm)===
 
Set the motor speed.
 
rpm is the rotation speed.
 
This function will check for minimum speed to avoid a step_delay larger than 65535. Returns 0 is successful. 1 otherwise.


===void setDirection(bool dir);===
===void setDirection(bool dir);===
Line 80: Line 88:
Perform one single step.
Perform one single step.


===void stop();===
===void start();===
Stop the motor.
Stop the motor.


===uint8_t address;===
===void stop()===
Stop the motor. Will slow down and stop if acceleration is on.
 
===void brute_stop()===
Stop the motor immediately regardless of acceleration.


i2c address of the MCU controlling the motor. Usually 0x04 or 0x05.
===void begin(uint8_t _address, uint16_t n_step)===
Initialiser to be used in Setup section of Arduino. ''address'' parameter is the i2c address of the motor controller. Usually 0x04 or 0x05.


===void begin(uint8_t _address);===
n_step is the number of steps per revolution the motor executes. See relevant datasheet. This should be modified accordingly if microstepping.
Initialiser to be used in Setup section of Arduino. address parameter is the i2c address of the motor controller. Usually 0x04 or 0x05.


===bool running;===
===bool running;===

Revision as of 21:03, 3 March 2021

under construction...

Installation

Download the zip file from Stepper_UNO_v1.0#Files.
Copy the StepperUNO folder in the sketchbook/library directory.

Configuration

Open the config.h file in the library/stepperUNO folder.
Change the KEYPAD_VERSION value as needed. Value should be 0 1 or 2. If you do not know just try one or the other and see how the button reacts.

Function list

Keypad

If the keypad does not reply correctly on the left/right/up/down/select button then a calibration should be performed. Values should be changed in the .h file of the library.

uint8_t ReadKey()

This function should be called as often as possible. Typically inside the main loop. This will update the Keypad.state variable with one of the defined event below.

#define PRESSED_NONE    0
#define PRESSED_RIGHT   1
#define PRESSED_UP      2
#define PRESSED_DOWN    3
#define PRESSED_LEFT    4
#define PRESSED_SELECT  5

#define RELEASED_NONE   6
#define RELEASED_RIGHT  7
#define RELEASED_UP     8
#define RELEASED_DOWN   9
#define RELEASED_LEFT   10
#define RELEASED_SELECT 11

Note this function does not manage the RST button. Use RstReadKey instead.

bool RstReadKey()

Same as above but for the RST button only.

The RST button is a special case. It has its own pin to the arduino mcu.

#define PRESSED_RST       12
#define RELEASED_RST      13
#define LONG_PRESSED_RST  14
#define LONG_RELEASED_RST 15

On a conventional Arduino UNO these LCD keypad will connect the RST button directly to the reset of the arduino. This is a waste in our opinion and we have re-routed this button for using it on something more useful.

uint8_t state

Event state. Will be equal to one of the define listed above once an event has occurred.

uint8_t rst_state

Same as state but for the RST button only.

void closeEvent()

Must be called once all action have been executed for a given event.

void rst_closeEvent()

Must be called once all action have been executed for a given event on the RST button.

Motor Control

void set_speed(uint16_t step_delay)

Set the motor speed.

step_delay is the delay between steps in microseconds.

uint8_t set_speed_rpm(float rpm)

Set the motor speed.

rpm is the rotation speed.

This function will check for minimum speed to avoid a step_delay larger than 65535. Returns 0 is successful. 1 otherwise.

void setDirection(bool dir);

Set the direction.

void enable();

Enable the motor. Holds torque on the motor.

void disable();

Disable the motor. Allows the motor to spin freely.

void step();

Perform one single step.

void start();

Stop the motor.

void stop()

Stop the motor. Will slow down and stop if acceleration is on.

void brute_stop()

Stop the motor immediately regardless of acceleration.

void begin(uint8_t _address, uint16_t n_step)

Initialiser to be used in Setup section of Arduino. address parameter is the i2c address of the motor controller. Usually 0x04 or 0x05.

n_step is the number of steps per revolution the motor executes. See relevant datasheet. This should be modified accordingly if microstepping.

bool running;

Indicates if the motor is running.

bool direction;

Indicates the motor direction.