An I2C wrapper class for the AccelStepper library.
This class mimicks the original AccelStepper interface. It replicates most of its methods and transmits each method call via I2C to a slave running the AccelStepperI2C firmware. Functions and parameters without documentation will work just as their original, but you need to take the general restrictions into account (e.g. don't take a return value for valid without error handling).
|
| AccelStepperI2C (I2Cwrapper *w) |
| Constructor. More...
|
|
void | attach (uint8_t interface=AccelStepper::FULL4WIRE, uint8_t pin1=2, uint8_t pin2=3, uint8_t pin3=4, uint8_t pin4=5, bool enable=true) |
| Replaces the AccelStepper constructor and takes the same arguments. Will allocate an AccelStepper object on the slave's side and make it ready for use. More...
|
|
void | moveTo (long absolute) |
|
void | move (long relative) |
|
boolean | run () |
| Don't use this, use state machine instead with runState(). More...
|
|
boolean | runSpeed () |
| Don't use this, use state machine instead with runSpeedState(). More...
|
|
void | setMaxSpeed (float speed) |
|
float | maxSpeed () |
|
void | setAcceleration (float acceleration) |
|
void | setSpeed (float speed) |
|
float | speed () |
|
long | distanceToGo () |
|
long | targetPosition () |
|
long | currentPosition () |
|
void | setCurrentPosition (long position) |
|
void | runToPosition () |
| This is a blocking function in the original, it will only return after the target has been reached. This I2C implementation mimicks the original, but uses the state machine and checks for a target reached condition with a fixed frequency of 100ms to keep the I2C bus uncluttered. More...
|
|
void | runToNewPosition (long position) |
| This is a blocking function in the original, it will only return after the new target has been reached. This I2C implementation mimicks the original, but uses the state machine and checks for a target reached condition with a fixed frequency of 100ms to keep the I2C bus uncluttered. More...
|
|
boolean | runSpeedToPosition () |
| Don't use this, use state machine instead with runSpeedToPositionState(). More...
|
|
void | stop () |
|
void | disableOutputs () |
|
void | enableOutputs () |
|
void | setMinPulseWidth (unsigned int minWidth) |
|
void | setEnablePin (uint8_t enablePin=0xff) |
|
void | setPinsInverted (bool directionInvert=false, bool stepInvert=false, bool enableInvert=false) |
|
void | setPinsInverted (bool pin1Invert, bool pin2Invert, bool pin3Invert, bool pin4Invert, bool enableInvert) |
|
bool | isRunning () |
|
void | enableDiagnostics (bool enable) |
| Turn on/off diagnostic speed logging. Needs diagnostics enabled and a slave which was compiled with the DIAGNOSTICS compiler directive enabled. More...
|
|
void | diagnostics (diagnosticsReport *report) |
| Get most recent diagnostics data. Needs diagnostics enabled and a slave which was compiled with the DIAGNOSTICS compiler directive enabled. More...
|
|
void | enableInterrupts (bool enable=true) |
| Start or stop sending interrupts to master for this stepper. An interrupt will be sent whenever a state machine change occured which was not triggered by the master. At the moment, this could either be a target reached condition in runState() or runSpeedToPositionState(), or an endstop reached condition. More...
|
|
void | setEndstopPin (int8_t pin, bool activeLow, bool internalPullup) |
| Define a new endstop pin. Each stepper can have up to two, so don't call this more than twice per stepper. More...
|
|
void | enableEndstops (bool enable=true) |
| Tell the state machine to check the endstops regularly. If any of the (one or two) stepper's endstops is hit, the state machine will revert to state_stopped. To prevent overshoot, also the stepper's speed is set to 0 and its target to the current position. More...
|
|
uint8_t | endstops () |
| Read current raw, i.e. not debounced state of endstops. It's basically one or two digitalReads() combined in one result. More...
|
|
void | setState (uint8_t newState) |
| Set the state machine's state manually. More...
|
|
uint8_t | getState () |
| Read the state machine's state (it may have been changed by endstop or target reached condition). More...
|
|
void | stopState () |
| Will stop any of the above states, i.e. stop polling. It does nothing else, so the master is solely in command of target, speed, and other settings. More...
|
|
void | runState () |
| Will poll run(), i.e. run to the target with acceleration and stop the state machine upon reaching it. More...
|
|
void | runSpeedState () |
| Will poll runSpeed(), i.e. run at constant speed until told otherwise (see AccelStepperI2C::stopState(). More...
|
|
void | runSpeedToPositionState () |
| Will poll runSpeedToPosition(), i.e. run at constant speed until target has been reached. More...
|
|
void AccelStepperI2C::enableEndstops |
( |
bool |
enable = true | ) |
|
Tell the state machine to check the endstops regularly. If any of the (one or two) stepper's endstops is hit, the state machine will revert to state_stopped. To prevent overshoot, also the stepper's speed is set to 0 and its target to the current position.
An interrupt will be triggered, if interrupts are enabled, in that case I2Cwrapper::clearInterrupt() will then inform about the interrupt's cause. Independent of an interrupt, the master can use endstops() to find out if an endstop was hit and which one it was.
A "hit" condition is defined as an end stop switch becoming active. Nothing happens if it stays active or becomes inactive. A simple debouncing mechanism is in place. After a new flank (switch becoming active or inactive), it will ignore any further flanks for a set interval of 5 milliseconds, which should suffice for most switches to get into a stable state.
- Todo:
Find solution for moving a stepper out of an endstop's zone. implemented debounce and active-flank detection so that there's no danger of repeated interrupts being triggered while in an endstop's active zone.
- Parameters
-
enable | true (default) to enable, false to disable. |