After A LOT of tweaking [mainly cause I don't know what I'm doing AND the cnc shieldS (emphasis on the S here) were duds] I've managed to fix the new nano cnc shield and get the thing running.
There is an "appropriate" board on its way.
Changed the set up a bit from where it started so I'm not sure if i have to start a new thread or keep it on this one.
Mainly changed to the board and shield from previous because i just couldnt get the program running how i wanted with the shield and it turns out the board itself seemed to be the problem (just like this one... wont name the brand tho)
Dunno how to post a video here so a pic it is:
Although it is working, the value on the LCD fluctuates randomly from about +/- 0.06. Could be the pot acting up so I'll replace it with another 10k Pot (B103) i have in the elegoo kit i bought.
The WORST part though is it often stops the cycle (right before refreshing the value on screen) as if its trying to process what's going on and then starts back up randomly (usually about 1 to 5 seconds).No idea if my frankencode is just asking too much of it so I figured I'd ask.
The 5v outputs for the LCD and the Pot are connected directly to the CNC Shield. Main power comes from a wall wart 12VDC 5A.
I did try going the encoder route (ky-40) instead of a potentiometer but could not get the thing to stay put on a single value and was reeeeeally discouraging me.
FrankenCode:
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
Servo cutservo;
//Stepper config
#define EN 8
//Direction pin (should be 5)
#define X_DIR 2
//Step pin (should be 2)
#define X_STP 5
//DRV8825
int delayTime=35; //Delay between each pause (uS)
int stps=6400;// Steps to move for one turn
int val = 0;
int previous = 0;
int long stpval = 0;
int long dispval = 0;
void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(10);
for (int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(stepperPin, LOW);
delayMicroseconds(delayTime);
}
}
void setup(){
cutservo.attach(11);
cutservo.write(30);// Start/Return servo position
pinMode(X_DIR, OUTPUT);
pinMode(X_STP, OUTPUT);
pinMode(EN, OUTPUT);
digitalWrite(EN, LOW);
Serial.begin(9600);
// Print a message to the LCD.
lcd.begin();
lcd.backlight();
lcd.setCursor(5,0);
lcd.print("Length:");
lcd.setCursor(6,1);
lcd.print(dispval/100.00);
}
void loop(){
val = analogRead(A7);
if ((val > previous+5) || (val < previous-5)){ //Lower some of the analog fluctuation but didnt work.
int long stpval=map(val,0,1023,5600,14400); //Change values on Pot to amount of microsteps for a range of turns.
int long dispval=stpval / 20.382 ; // Convert to length (using a higher number just so i can divide later and get decimals on LCD)
lcd.begin();
lcd.backlight();
lcd.setCursor(5,0);
lcd.print("Length:");
lcd.setCursor(6,1);
lcd.print(dispval/100.00);//Must divide by at least 10.00 to get the decimal points (for some reason)
step(true, X_DIR, X_STP, stpval); //X, (True)CClockwise, (false) Clockwise
previous = val;
cutservo.write(150);// Cut
delay(350);
cutservo.write(30);// Return
delay(350);
}
}
Thanks,