diff --git a/platformio.ini b/platformio.ini index b1a0652..68d6a0c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -78,5 +78,23 @@ extends = env:promicro16, debug [env:uno_cnc_shield] board = uno extends = env:A4988driver -build_flags = -DPIN_DRIVER_SLEEP=8 -DPIN_DRIVER_DIR=5 -DPIN_DRIVER_STEP=2 -DONE_WIRE_BUS=3 -DBTN_OUT=4 -upload_port = /dev/ttyACM0 \ No newline at end of file +build_flags = + -DUSE_DRIVER + # using x-header + -DPIN_DRIVER_SLEEP=8 + -DPIN_DRIVER_DIR=5 + -DPIN_DRIVER_STEP=2 + -DPIN_DRIVER_SLEEP_INVERTED=true + # Connect temp sensor to CodeEn + -DONE_WIRE_BUS=A3 + # Connect buttons to Z/Y limit switch + -DBTN_IN=10 + -DBTN_OUT=11 + # Connect speed poti to Abort + -D BTN_POTI_SPEED=A0 + # enable debug, RX/TX on Hold/Resume + -DDEBUG + -DDEBUG_RX=A1 + -DDEBUG_TX=A2 +upload_port = /dev/ttyACM0 +monitor_port = /dev/ttyUSB0 \ No newline at end of file diff --git a/src/arduino-motorfocus.cpp b/src/arduino-motorfocus.cpp index 319e650..1d185c4 100644 --- a/src/arduino-motorfocus.cpp +++ b/src/arduino-motorfocus.cpp @@ -7,31 +7,66 @@ #include #include "DummySerial.h" +// button and button speed config +#ifndef BTN_IN #define BTN_IN 7 +#endif +#ifndef BTN_OUT #define BTN_OUT 8 +#endif +#ifndef BTN_POTI_SPEED #define BTN_POTI_SPEED A0 +#endif + #define BTN_MIN_SPEED 8 #define BTN_MAX_SPEED 512 #define BTN_ACCEL_FACTOR 1.05f +// driver config +#ifndef PIN_DRIVER_SLEEP #define PIN_DRIVER_SLEEP 4 +#endif + +#ifndef PIN_DRIVER_DIR #define PIN_DRIVER_DIR 3 +#endif +#ifndef PIN_DRIVER_STEP #define PIN_DRIVER_STEP 5 +#endif + +#ifndef PIN_DRIVER_SLEEP_INVERTED +#define PIN_DRIVER_SLEEP_INVERTED false +#endif +#ifndef PIN_DRIVER_DIR_INVERTED +#define PIN_DRIVER_DIR_INVERTED false +#endif + +#ifndef PIN_DRIVER_STEP_INVERTED +#define PIN_DRIVER_STEP_INVERTED false +#endif + +// one wire bus / temperature sensor config +#ifndef ONE_WIRE_BUS #define ONE_WIRE_BUS 2 +#endif #define PERIOD_US 2000 + // Maximum motor speed multiplicator in steps per second #define SPEED_MULTIPLICATOR 30 // Motor acceleration in steps per second per second #define ACCELERATION 100 -// #define USE_DRIVER - -// #define DEBUG +#ifndef DEBUG_RX +#define DEBUG_RX A1 +#endif +#ifndef DEBUG_TX +#define DEBUG_TX A2 +#endif #ifdef DEBUG -SoftwareSerial debugSerial(9, 10); +SoftwareSerial debugSerial(DEBUG_RX, DEBUG_TX); #else DummySerial debugSerial; #endif @@ -90,6 +125,7 @@ void setup() #ifdef USE_DRIVER debugSerial.println("Using A4988 driver"); stepper.setEnablePin(PIN_DRIVER_SLEEP); + stepper.setPinsInverted(PIN_DRIVER_DIR_INVERTED, PIN_DRIVER_STEP_INVERTED, PIN_DRIVER_SLEEP_INVERTED); stepper.disableOutputs(); isEnabled = false; #endif