st-4-esp32/examples/pulse_guide/pulse_guide.ino
Ryan Malloy 4c91fd4811 ESP32 ST-4 autoguider library with thread-safe pulse guiding
Port of arduino-st4 (Kevin Ferrare) to ESP32/PlatformIO with:
- FreeRTOS mutex protection at every layer (Pin, Axis, Pulse, Controller)
- Hardware timer pulse guiding with ISR-safe deferred stop pattern
- Backward-compatible serial protocol (57600 baud, #-terminated)
- Extended commands: PULSE, POS?, SYNC, STATUS?, VERSION?
- Optional WiFi/WebSocket control (gated by ST4_WIFI_ENABLED)
- Dead-reckoning position tracker using esp_timer microsecond precision

All 4 examples build clean against esp32dev target.
2026-02-17 19:46:03 -07:00

49 lines
1.4 KiB
C++

// ST4-ESP32 Pulse Guide Example
// Demonstrates hardware-timer pulse guiding with position tracking
//
// Send via serial (57600 baud):
// CONNECT# - connect to mount
// PULSE RA+ 500# - pulse RA+ for 500ms
// PULSE DEC- 1000# - pulse DEC- for 1 second
// POS?# - read current position
// STATUS?# - full status report
#include <ST4.h>
ST4Controller controller;
ST4Serial st4Serial;
void setup() {
Serial.begin(115200);
Serial.println("ST4 Pulse Guide Example");
controller.begin(
ST4_PIN_RA_PLUS, ST4_PIN_RA_MINUS,
ST4_PIN_DEC_PLUS, ST4_PIN_DEC_MINUS,
ST4_PIN_LED
);
st4Serial.begin(controller, Serial);
controller.connect();
Serial.println("Ready. Try: PULSE RA+ 500#");
}
void loop() {
st4Serial.update();
// Print position every 5 seconds while moving
static uint32_t lastPrint = 0;
if (millis() - lastPrint > 5000) {
lastPrint = millis();
if (controller.axisActive(ST4AxisId::RA) ||
controller.axisActive(ST4AxisId::DECLINATION) ||
controller.isPulseActive()) {
Serial.print("RA: ");
Serial.print(controller.position(ST4AxisId::RA), 6);
Serial.print(" DEC: ");
Serial.println(controller.position(ST4AxisId::DECLINATION), 6);
}
}
}