From 04b089d4b5e3e1e914de19dc98eeda08a0ab8072 Mon Sep 17 00:00:00 2001 From: NiamoR42 <74781726+NiamoR42@users.noreply.github.com> Date: Mon, 8 Aug 2022 17:49:54 +0200 Subject: [PATCH 1/3] update 28YBJ-48 pinout configuration on motorB --- configuration.ino | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/configuration.ino b/configuration.ino index 4946981..bef9a97 100644 --- a/configuration.ino +++ b/configuration.ino @@ -95,6 +95,11 @@ AccelStepper motorB(1,MOTOR_B_STEP_PIN, MOTOR_B_DIR_PIN); AccelStepper motorA(8, 6,8,7,9); AccelStepper motorB(8, 2,4,3,5); +// motorB has to be reversed regarding motorA +// this is what is working on my side : +AccelStepper motorA(8, A0,A2,A1,A3); +AccelStepper motorB(8, 5,3,4,2); + #endif void configuration_motorSetup() From b930feabba587a3db3b80677d78fc7c2cfaf4bc7 Mon Sep 17 00:00:00 2001 From: NiamoR42 <74781726+NiamoR42@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:01:05 +0200 Subject: [PATCH 2/3] update for 28YBJ-48 Stepper --- README.md | 3 + configuration.ino | 4 +- polargraph_server_a1.ino | 782 +++++++++++++++++++-------------------- 3 files changed, 395 insertions(+), 394 deletions(-) diff --git a/README.md b/README.md index f4ad7d0..b98dc72 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +update for 28YBJ-48 Stepper + +==================== polargraph_server_a1 ==================== diff --git a/configuration.ino b/configuration.ino index bef9a97..78cbb39 100644 --- a/configuration.ino +++ b/configuration.ino @@ -93,8 +93,8 @@ AccelStepper motorB(1,MOTOR_B_STEP_PIN, MOTOR_B_DIR_PIN); // DEFAULT_STEPS_PER_REV = 4076; // DEFAULT_MM_PER_REV = 63; -AccelStepper motorA(8, 6,8,7,9); -AccelStepper motorB(8, 2,4,3,5); +//AccelStepper motorA(8, 6,8,7,9); +//AccelStepper motorB(8, 2,4,3,5); // motorB has to be reversed regarding motorA // this is what is working on my side : AccelStepper motorA(8, A0,A2,A1,A3); diff --git a/polargraph_server_a1.ino b/polargraph_server_a1.ino index e529dad..8320ef9 100644 --- a/polargraph_server_a1.ino +++ b/polargraph_server_a1.ino @@ -1,392 +1,390 @@ -/** -* Polargraph Server for Arduino UNO and MEGA compatible boards. -* Written by Sandy Noble -* Released under GNU License version 3. -* http://www.polargraph.co.uk -* https://github.com/euphy/polargraph_server_a1 - - -CONFIGURATION!! Read this! Really. -================================== - -Kung fu is like a game of chess. You must think first! Before you move. - -This is a unified codebase for a few different versions of Polargraph Server. - -You can control how it is compiled by changing the #define lines below. - -There are five config sections: -1. Specify what kind of controller board you are using -2. Add some libraries if you have a MEGA -3. Specify what kind of motor driver you are using: - i. Adafruit Motorshield v1 - ii. Adafruit Motorshield v2 - iii. Discrete stepper drivers (eg EasyDriver, stepstick, Pololu gear).* - iv. Signal amplifier like a UNL2003* -4. Turn on some debugging code -5. Disable program features if you need to free up space - -* For motor drivers iii and iv, you will need to change the values in - configuration.ino to set the exact pins the drivers are wired up to. - -*/ - - -// 1. Specify what kind of controller board you are using -// ====================================================== -// UNO or MEGA. Uncomment the line for the kind of board you have. -#ifndef MICROCONTROLLER -#define MICROCONTROLLER MC_UNO -//#define MICROCONTROLLER MC_MEGA -#endif - - -// 2. Add some libraries if you have a MEGA -// ======================================== -// Uncomment the SPI and SD lines below if you have a MEGA. -// http://forum.arduino.cc/index.php?topic=173584.0 -//#include -//#include - - -// 3. Specify what kind of motor driver you are using -// ================================================== -// Only ONE set of lines below should be uncommented. - -// i. Adafruit Motorshield v1. The original, and still the best. -// ------------------------------------------------------------- -#define ADAFRUIT_MOTORSHIELD_V1 -#include - -// ii. Adafruit Motorshield v2. It's all squealy. -// ---------------------------------------------- -//#define ADAFRUIT_MOTORSHIELD_V2 -//#include -//#include -//#include "utility/Adafruit_PWMServoDriver.h" - -// iii. Using discrete stepper drivers? (eg EasyDriver, stepstick, Pololu gear) -// ---------------------------------------------------------------------------- -// Don't forget to define your pins in 'configuration.ino'. -//#define SERIAL_STEPPER_DRIVERS - -// iv. Using a signal amplifier like a UNL2003? -// -------------------------------------------- -// Don't forget to define your pins in 'configuration.ino'. -// #define UNL2003_DRIVER - - -// 4. Turn on some debugging code if you want horror -// ================================================= -//#define DEBUG -//#define DEBUG_COMMS -//#define DEBUG_PENLIFT -//#define DEBUG_PIXEL - - -// 5. Disable program features if you need to free up space -// ======================================================== -#define PIXEL_DRAWING -#define PENLIFT -#define VECTOR_LINES - - - -/* =========================================================== - These variables are common to all polargraph server builds -=========================================================== */ - -// ========================================================== -// Some microcontroller's names -#define MC_UNO 1 -#define MC_MEGA 2 - -#include -#include -#include -#include "EEPROMAnything.h" - -const String FIRMWARE_VERSION_NO = "1.2.1"; - -// EEPROM addresses -const byte EEPROM_MACHINE_WIDTH = 0; -const byte EEPROM_MACHINE_HEIGHT = 2; -const byte EEPROM_MACHINE_MM_PER_REV = 14; // 4 bytes (float) -const byte EEPROM_MACHINE_STEPS_PER_REV = 18; -const byte EEPROM_MACHINE_STEP_MULTIPLIER = 20; - -const byte EEPROM_MACHINE_MOTOR_SPEED = 22; // 4 bytes float -const byte EEPROM_MACHINE_MOTOR_ACCEL = 26; // 4 bytes float -const byte EEPROM_MACHINE_PEN_WIDTH = 30; // 4 bytes float - -const byte EEPROM_MACHINE_HOME_A = 34; // 4 bytes -const byte EEPROM_MACHINE_HOME_B = 38; // 4 bytes - -const byte EEPROM_PENLIFT_DOWN = 42; // 2 bytes -const byte EEPROM_PENLIFT_UP = 44; // 2 bytes - -// Pen raising servo -Servo penHeight; -const int DEFAULT_DOWN_POSITION = 90; -const int DEFAULT_UP_POSITION = 180; -static int upPosition = DEFAULT_UP_POSITION; // defaults -static int downPosition = DEFAULT_DOWN_POSITION; -static int penLiftSpeed = 3; // ms between steps of moving motor -const byte PEN_HEIGHT_SERVO_PIN = 9; //UNL2003 driver uses pin 9 -boolean isPenUp = false; - -// Machine specification defaults -const int DEFAULT_MACHINE_WIDTH = 650; -const int DEFAULT_MACHINE_HEIGHT = 650; -const int DEFAULT_MM_PER_REV = 95; -const int DEFAULT_STEPS_PER_REV = 400; -const int DEFAULT_STEP_MULTIPLIER = 1; - -// working machine specification -static int motorStepsPerRev = DEFAULT_STEPS_PER_REV; -static float mmPerRev = DEFAULT_MM_PER_REV; -static byte stepMultiplier = DEFAULT_STEP_MULTIPLIER; -static int machineWidth = DEFAULT_MACHINE_WIDTH; -static int machineHeight = DEFAULT_MACHINE_HEIGHT; - - -static float currentMaxSpeed = 800.0; -static float currentAcceleration = 400.0; -static boolean usingAcceleration = true; - -int startLengthMM = 800; - -float mmPerStep = 0.0F; -float stepsPerMM = 0.0F; - -long pageWidth = machineWidth * stepsPerMM; -long pageHeight = machineHeight * stepsPerMM; -long maxLength = 0; - -//static char rowAxis = 'A'; -const int INLENGTH = 50; -const char INTERMINATOR = 10; -const char SEMICOLON = ';'; - -float penWidth = 0.8F; // line width in mm - -boolean reportingPosition = true; -boolean acceleration = true; - -extern AccelStepper motorA; -extern AccelStepper motorB; - -boolean currentlyRunning = true; - -static char inCmd[10]; -static char inParam1[14]; -static char inParam2[14]; -static char inParam3[14]; -static char inParam4[14]; - -static byte inNoOfParams; - -char lastCommand[INLENGTH+1]; -boolean commandConfirmed = false; - -int rebroadcastReadyInterval = 5000; -long lastOperationTime = 0L; -long motorIdleTimeBeforePowerDown = 600000L; -boolean automaticPowerDown = true; -boolean powerIsOn = false; - -long lastInteractionTime = 0L; - -#ifdef PIXEL_DRAWING -static boolean lastWaveWasTop = true; - -// Drawing direction -const static byte DIR_NE = 1; -const static byte DIR_SE = 2; -const static byte DIR_SW = 3; -const static byte DIR_NW = 4; - -static int globalDrawDirection = DIR_NW; - -const static byte DIR_MODE_AUTO = 1; -const static byte DIR_MODE_PRESET = 2; -static byte globalDrawDirectionMode = DIR_MODE_AUTO; -#endif - -#if MICROCONTROLLER == MC_MEGA - #define READY_STR "READY_100" -#else - #define READY_STR "READY" -#endif - -#define RESEND_STR "RESEND" -#define DRAWING_STR "DRAWING" -#define OUT_CMD_SYNC_STR "SYNC," - -char MSG_E_STR[] = "MSG,E,"; -char MSG_I_STR[] = "MSG,I,"; -char MSG_D_STR[] = "MSG,D,"; - -const static char COMMA[] = ","; -const static char CMD_END[] = ",END"; -const static String CMD_CHANGELENGTH = "C01"; -const static String CMD_CHANGEPENWIDTH = "C02"; -#ifdef PIXEL_DRAWING -const static String CMD_DRAWPIXEL = "C05"; -const static String CMD_DRAWSCRIBBLEPIXEL = "C06"; -const static String CMD_CHANGEDRAWINGDIRECTION = "C08"; -const static String CMD_TESTPENWIDTHSQUARE = "C11"; -#endif -const static String CMD_SETPOSITION = "C09"; -#ifdef PENLIFT -const static String CMD_PENDOWN = "C13"; -const static String CMD_PENUP = "C14"; -const static String CMD_SETPENLIFTRANGE = "C45"; -#endif -#ifdef VECTOR_LINES -const static String CMD_CHANGELENGTHDIRECT = "C17"; -#endif -const static String CMD_SETMACHINESIZE = "C24"; -const static String CMD_GETMACHINEDETAILS = "C26"; -const static String CMD_RESETEEPROM = "C27"; -const static String CMD_SETMACHINEMMPERREV = "C29"; -const static String CMD_SETMACHINESTEPSPERREV = "C30"; -const static String CMD_SETMOTORSPEED = "C31"; -const static String CMD_SETMOTORACCEL = "C32"; -const static String CMD_SETMACHINESTEPMULTIPLIER = "C37"; - -void setup() -{ - Serial.begin(57600); // set up Serial library at 57600 bps - Serial.println("POLARGRAPH ON!"); - Serial.print("Hardware: "); - Serial.println(MICROCONTROLLER); - - #if MICROCONTROLLER == MC_MEGA - Serial.println("MC_MEGA"); - #elif MICROCONTROLLER == MC_UNO - Serial.println("MC_UNO"); - #else - Serial.println("No MC"); - #endif - configuration_motorSetup(); - eeprom_loadMachineSpecFromEeprom(); - configuration_setup(); - - motorA.setMaxSpeed(currentMaxSpeed); - motorA.setAcceleration(currentAcceleration); - motorB.setMaxSpeed(currentMaxSpeed); - motorB.setAcceleration(currentAcceleration); - - float startLength = ((float) startLengthMM / (float) mmPerRev) * (float) motorStepsPerRev; - motorA.setCurrentPosition(startLength); - motorB.setCurrentPosition(startLength); - for (int i = 0; i +//#include + + +// 3. Specify what kind of motor driver you are using +// ================================================== +// Only ONE set of lines below should be uncommented. + +// i. Adafruit Motorshield v1. The original, and still the best. +// ------------------------------------------------------------- +//#define ADAFRUIT_MOTORSHIELD_V1 +//#include + +// ii. Adafruit Motorshield v2. It's all squealy. +// ---------------------------------------------- +//#define ADAFRUIT_MOTORSHIELD_V2 +//#include +//#include +//#include "utility/Adafruit_PWMServoDriver.h" + +// iii. Using discrete stepper drivers? (eg EasyDriver, stepstick, Pololu gear) +// ---------------------------------------------------------------------------- +// Don't forget to define your pins in 'configuration.ino'. +//#define SERIAL_STEPPER_DRIVERS + +// iv. Using a signal amplifier like a UNL2003? +// -------------------------------------------- +// Don't forget to define your pins in 'configuration.ino'. +#define UNL2003_DRIVER + + +// 4. Turn on some debugging code if you want horror +// ================================================= +//#define DEBUG +//#define DEBUG_COMMS +//#define DEBUG_PENLIFT +//#define DEBUG_PIXEL + + +// 5. Disable program features if you need to free up space +// ======================================================== +#define PIXEL_DRAWING +#define PENLIFT +#define VECTOR_LINES + + + +/* =========================================================== + These variables are common to all polargraph server builds +=========================================================== */ + +// ========================================================== +// Some microcontroller's names +#define MC_UNO 1 +#define MC_MEGA 2 + +#include +#include +#include +#include "EEPROMAnything.h" + +const String FIRMWARE_VERSION_NO = "1.2.1"; + +// EEPROM addresses +const byte EEPROM_MACHINE_WIDTH = 0; +const byte EEPROM_MACHINE_HEIGHT = 2; +const byte EEPROM_MACHINE_MM_PER_REV = 14; // 4 bytes (float) +const byte EEPROM_MACHINE_STEPS_PER_REV = 18; +const byte EEPROM_MACHINE_STEP_MULTIPLIER = 20; + +const byte EEPROM_MACHINE_MOTOR_SPEED = 22; // 4 bytes float +const byte EEPROM_MACHINE_MOTOR_ACCEL = 26; // 4 bytes float +const byte EEPROM_MACHINE_PEN_WIDTH = 30; // 4 bytes float + +const byte EEPROM_MACHINE_HOME_A = 34; // 4 bytes +const byte EEPROM_MACHINE_HOME_B = 38; // 4 bytes + +const byte EEPROM_PENLIFT_DOWN = 42; // 2 bytes +const byte EEPROM_PENLIFT_UP = 44; // 2 bytes + +// Pen raising servo +Servo penHeight; +const int DEFAULT_DOWN_POSITION = 90; +const int DEFAULT_UP_POSITION = 180; +static int upPosition = DEFAULT_UP_POSITION; // defaults +static int downPosition = DEFAULT_DOWN_POSITION; +static int penLiftSpeed = 3; // ms between steps of moving motor +const byte PEN_HEIGHT_SERVO_PIN = 11;//9; //UNL2003 driver uses pin 9 +boolean isPenUp = false; + +// Machine specification defaults +const int DEFAULT_MACHINE_WIDTH = 490;//650; +const int DEFAULT_MACHINE_HEIGHT = 450;//650; +const int DEFAULT_MM_PER_REV = 32;//95; +const int DEFAULT_STEPS_PER_REV = 4076;//2038; //400; +const int DEFAULT_STEP_MULTIPLIER = 1; + +// working machine specification +static int motorStepsPerRev = DEFAULT_STEPS_PER_REV; +static float mmPerRev = DEFAULT_MM_PER_REV; +static byte stepMultiplier = DEFAULT_STEP_MULTIPLIER; +static int machineWidth = DEFAULT_MACHINE_WIDTH; +static int machineHeight = DEFAULT_MACHINE_HEIGHT; + + +static float currentMaxSpeed = 1500.0; +static float currentAcceleration = 600.0; +static boolean usingAcceleration = true; + +int startLengthMM = 300;//800; + +float mmPerStep = 0.0F; +float stepsPerMM = 0.0F; + +long pageWidth = machineWidth * stepsPerMM; +long pageHeight = machineHeight * stepsPerMM; +long maxLength = 0; + +//static char rowAxis = 'A'; +const int INLENGTH = 50; +const char INTERMINATOR = 10; +const char SEMICOLON = ';'; + +float penWidth = 0.8F; // line width in mm + +boolean reportingPosition = true; +boolean acceleration = true; + +extern AccelStepper motorA; +extern AccelStepper motorB; + +boolean currentlyRunning = true; + +static char inCmd[10]; +static char inParam1[14]; +static char inParam2[14]; +static char inParam3[14]; +static char inParam4[14]; + +static byte inNoOfParams; + +char lastCommand[INLENGTH+1]; +boolean commandConfirmed = false; + +int rebroadcastReadyInterval = 5000; +long lastOperationTime = 0L; +long motorIdleTimeBeforePowerDown = 600000L; +boolean automaticPowerDown = true; +boolean powerIsOn = false; + +long lastInteractionTime = 0L; + +#ifdef PIXEL_DRAWING +static boolean lastWaveWasTop = true; + +// Drawing direction +const static byte DIR_NE = 1; +const static byte DIR_SE = 2; +const static byte DIR_SW = 3; +const static byte DIR_NW = 4; + +static int globalDrawDirection = DIR_NW; + +const static byte DIR_MODE_AUTO = 1; +const static byte DIR_MODE_PRESET = 2; +static byte globalDrawDirectionMode = DIR_MODE_AUTO; +#endif + +#if MICROCONTROLLER == MC_MEGA + #define READY_STR "READY_100" +#else + #define READY_STR "READY" +#endif + +#define RESEND_STR "RESEND" +#define DRAWING_STR "DRAWING" +#define OUT_CMD_SYNC_STR "SYNC," + +char MSG_E_STR[] = "MSG,E,"; +char MSG_I_STR[] = "MSG,I,"; +char MSG_D_STR[] = "MSG,D,"; + +const static char COMMA[] = ","; +const static char CMD_END[] = ",END"; +const static String CMD_CHANGELENGTH = "C01"; +const static String CMD_CHANGEPENWIDTH = "C02"; +#ifdef PIXEL_DRAWING +const static String CMD_DRAWPIXEL = "C05"; +const static String CMD_DRAWSCRIBBLEPIXEL = "C06"; +const static String CMD_CHANGEDRAWINGDIRECTION = "C08"; +const static String CMD_TESTPENWIDTHSQUARE = "C11"; +#endif +const static String CMD_SETPOSITION = "C09"; +#ifdef PENLIFT +const static String CMD_PENDOWN = "C13"; +const static String CMD_PENUP = "C14"; +const static String CMD_SETPENLIFTRANGE = "C45"; +#endif +#ifdef VECTOR_LINES +const static String CMD_CHANGELENGTHDIRECT = "C17"; +#endif +const static String CMD_SETMACHINESIZE = "C24"; +const static String CMD_GETMACHINEDETAILS = "C26"; +const static String CMD_RESETEEPROM = "C27"; +const static String CMD_SETMACHINEMMPERREV = "C29"; +const static String CMD_SETMACHINESTEPSPERREV = "C30"; +const static String CMD_SETMOTORSPEED = "C31"; +const static String CMD_SETMOTORACCEL = "C32"; +const static String CMD_SETMACHINESTEPMULTIPLIER = "C37"; + +void setup() +{ + Serial.begin(57600); // set up Serial library at 57600 bps + Serial.println("POLARGRAPH ON!"); + Serial.print("Hardware: "); + Serial.println(MICROCONTROLLER); + + #if MICROCONTROLLER == MC_MEGA + Serial.println("MC_MEGA"); + #elif MICROCONTROLLER == MC_UNO + Serial.println("MC_UNO"); + #else + Serial.println("No MC"); + #endif + configuration_motorSetup(); + eeprom_loadMachineSpecFromEeprom(); + configuration_setup(); + + motorA.setMaxSpeed(currentMaxSpeed); + motorA.setAcceleration(currentAcceleration); + motorB.setMaxSpeed(currentMaxSpeed); + motorB.setAcceleration(currentAcceleration); + + float startLength = ((float) startLengthMM / (float) mmPerRev) * (float) motorStepsPerRev; + motorA.setCurrentPosition(startLength); + motorB.setCurrentPosition(startLength); + for (int i = 0; i Date: Mon, 8 Aug 2022 18:02:28 +0200 Subject: [PATCH 3/3] typo update on README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b98dc72..6554c4e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ update for 28YBJ-48 Stepper -==================== polargraph_server_a1 ====================