Update Stepper_A3967.md

This commit is contained in:
HomeSpan 2023-07-01 11:01:25 -05:00 committed by GitHub
parent 3985bed06d
commit 78fc05f601
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 80 deletions

View File

@ -1,85 +1,41 @@
# HomeSpan Status # Stepper_A3967
The optional ***homeSpan*** method, `void setStatusCallback(void (*func)(HS_STATUS status))`, can be used to create a callback function, *func*, that HomeSpan calls whenever its status changes. HomeSpan passes *func* a single argument, *status*, of type *HS_STATUS*, defined as follows: This is a derived class of **StepperControl** designed to operate stepper motors driven by a [Toshiba TB6612](https://www.adafruit.com/product/2448) chip, either with or without the use of ESP32 PWM pins. To use, add `#include "extras/Stepper_TB6612.h"` to the top of your sketch.
```C++ The Toshiba TB6612 is a generic motor driver providing direct control of two full H-bridges. Wiring is as follows (using Toshiba's names for each pin):
enum HS_STATUS {
HS_WIFI_NEEDED, // WiFi Credentials have not yet been set/stored
HS_WIFI_CONNECTING, // HomeSpan is trying to connect to the network specified in the stored WiFi Credentials
HS_PAIRING_NEEDED, // HomeSpan is connected to central WiFi network, but device has not yet been paired to HomeKit
HS_PAIRED, // HomeSpan is connected to central WiFi network and ther device has been paired to HomeKit
HS_ENTERING_CONFIG_MODE, // User has requested the device to enter into Command Mode
HS_CONFIG_MODE_EXIT, // HomeSpan is in Command Mode with "Exit Command Mode" specified as choice
HS_CONFIG_MODE_REBOOT, // HomeSpan is in Command Mode with "Reboot" specified as choice
HS_CONFIG_MODE_LAUNCH_AP, // HomeSpan is in Command Mode with "Launch Access Point" specified as choice
HS_CONFIG_MODE_UNPAIR, // HomeSpan is in Command Mode with "Unpair Device" specified as choice
HS_CONFIG_MODE_ERASE_WIFI, // HomeSpan is in Command Mode with "Erase WiFi Credentials" specified as choice
HS_CONFIG_MODE_EXIT_SELECTED, // User has selected "Exit Command Mode"
HS_CONFIG_MODE_REBOOT_SELECTED, // User has select "Reboot" from the Command Mode
HS_CONFIG_MODE_LAUNCH_AP_SELECTED, // User has selected "Launch AP Access" from the Command Mode
HS_CONFIG_MODE_UNPAIR_SELECTED, // User has seleected "Unpair Device" from the Command Mode
HS_CONFIG_MODE_ERASE_WIFI_SELECTED, // User has selected "Erase WiFi Credentials" from the Command Mode
HS_REBOOTING, // HomeSpan is in the process of rebooting the device
HS_FACTORY_RESET, // HomeSpan is in the process of performing a Factory Reset of device
HS_AP_STARTED, // HomeSpan has started the Access Point but no one has yet connected
HS_AP_CONNECTED, // The Access Point is started and a user device has been connected
HS_AP_TERMINATED, // HomeSpan has terminated the Access Point
HS_OTA_STARTED // HomeSpan is in the process of recveived an Over-the-Air software update
};
```
The ***homeSpan*** method `char* statusString(HS_STATUS s)`, is a convenience function for converting any of the above enumerations to short, pre-defined character string messages as follows: #### **Power Connections**
* *VCC* - connect to +3.3V on ESP32
* *VM* - connect to external DC power supply that will drive stepper motor (5-13V)
* *GND* (and *PGND1/PGND2*) - connect to GND on the ESP32, and to ground of external DC power supply
#### **Motor Connections**
* *AO1, AO2* - connect to the "A" coil of the stepper motor
* *BO1, BO2* - connect to the "B" coil of the stepper motor
#### **Control Connections**
* *AIN1, AIN2* - connect to two digital pins on the ESP32 - will control direction and state of coil *A*
* *BIN1, BIN2* - connect to two digital pins on the ESP32 - will control direction and state of coil *B*
* *PWMA, PWMB* - if using PWM, connect to two digital pins on the ESP32; if not, connect to +3.3V on ESP32 to pull high
* *STBY* - connect to +3.3V on ESP32 to pull high
```C++ The **Stepper_A3967** class includes two constructors:
const char* Span::statusString(HS_STATUS s){ * `Stepper_TB6612(int AIN1, int AIN2, int BIN1, int BIN2 [,{uint32_t priority, uint32_t cpu}] )`
switch(s){ * controls the driver board using only 4 digital pins from the ESP32, where the parameters specify the pin numbers. Supports the following step type modes:
case HS_WIFI_NEEDED: return("WiFi Credentials Needed");
case HS_WIFI_CONNECTING: return("WiFi Connecting");
case HS_PAIRING_NEEDED: return("Device not yet Paired");
case HS_PAIRED: return("Device Paired");
case HS_ENTERING_CONFIG_MODE: return("Entering Command Mode");
case HS_CONFIG_MODE_EXIT: return("1. Exit Command Mode");
case HS_CONFIG_MODE_REBOOT: return("2. Reboot Device");
case HS_CONFIG_MODE_LAUNCH_AP: return("3. Launch Access Point");
case HS_CONFIG_MODE_UNPAIR: return("4. Unpair Device");
case HS_CONFIG_MODE_ERASE_WIFI: return("5. Erase WiFi Credentials");
case HS_CONFIG_MODE_EXIT_SELECTED: return("Exiting Command Mode...");
case HS_CONFIG_MODE_REBOOT_SELECTED: return("Rebooting Device...");
case HS_CONFIG_MODE_LAUNCH_AP_SELECTED: return("Launching Access Point...");
case HS_CONFIG_MODE_UNPAIR_SELECTED: return("Unpairing Device...");
case HS_CONFIG_MODE_ERASE_WIFI_SELECTED: return("Erasing WiFi Credentials...");
case HS_REBOOTING: return("REBOOTING!");
case HS_FACTORY_RESET: return("Performing Factory Reset...");
case HS_AP_STARTED: return("Access Point Started");
case HS_AP_CONNECTED: return("Access Point Connected");
case HS_AP_TERMINATED: return("Access Point Terminated");
case HS_OTA_STARTED: return("OTA Update Started");
default: return("Unknown");
}
}
```
### Example: * FULL_STEP_ONE_PHASE
* FULL_STEP_TWO_PHASE
* HALF_STEP
```C++ * `Stepper_TB6612(int AIN1, int AIN2, int BIN1, int BIN2, int PWMA, int PWMB, [,{uint32_t priority, uint32_t cpu}])`
#include "HomeSpan.h" * controls the driver board using 4 digital pins and 2 PWM pins from the ESP32, where the parameters specify the pin numbers. Supports the following step type modes:
void setup(){ * FULL_STEP_ONE_PHASE
homeSpan.setStatusCallback(statusUpdate); // set callback function * FULL_STEP_TWO_PHASE
... * HALF_STEP
homeSpan.begin(); * QUARTER_STEP
... * EIGHTH_STEP
}
// create a callback function that simply prints the pre-defined short messages on the Serial Monitor whenever the HomeSpan status changes Both constructors support an *optional* final parameter consisting of a *brace-enclosed* pair of numbers. The first number in the braces specifies the *priority* of the background task used to control the stepper motor. The second number in the braces specifies the CPU (0 or 1) that **Stepper_A3967** will use to run the background control task (this number is ignored for single-processor chips). The default (and recommended) value of this optional final parameter is {1,0}.
void statusUpdate(HS_STATUS status){
Serial.printf("\n*** HOMESPAN STATUS CHANGE: %s\n",homeSpan.statusString(status));
}
```
You can of course create any alternative messsages, or take any actions desired, in *func* and do not need to use the pre-defined strings above.
--- ---
[↩️](Reference.md) Back to the Reference API page [↩️](../Stepper.md) Back to the Stepper Motor Control page