This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
bdev:filamentextruder_recyclebot [2022/10/26 20:41] richard |
bdev:filamentextruder_recyclebot [2022/11/05 23:52] (current) richard |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Filament extruder recyclebot ====== | ====== Filament extruder recyclebot ====== | ||
+ | ====== filabotmega.ino ====== | ||
+ | |||
+ | < | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #define motorInterfaceType 1 | ||
+ | |||
+ | |||
+ | #define THERMISTOR_PINA A11 | ||
+ | #define TEMPCONTROLA 10 | ||
+ | |||
+ | //Define the aggressive and conservative Tuning Parameters | ||
+ | double aggKpA=150, aggKiA=0.5, aggKdA=0; | ||
+ | int thermoelectricval = 255; | ||
+ | int celsius; | ||
+ | int levelstreamon; | ||
+ | double settemp = 0; | ||
+ | double Setpoint, Input, Output, OutputA, OutputB, OutputC; | ||
+ | int tme = 250; | ||
+ | |||
+ | //Specify the links and initial tuning parameters | ||
+ | PID myPIDA(& | ||
+ | |||
+ | |||
+ | const int stepsPinA = 11; | ||
+ | const int directionPinA = 12; | ||
+ | const int enablePinA = 2; | ||
+ | |||
+ | |||
+ | const int stepsPinB = 3; | ||
+ | const int directionPinB = 4; | ||
+ | const int enablePinB = 5; | ||
+ | |||
+ | const int stepsPinC = 7; | ||
+ | const int directionPinC = 8; | ||
+ | const int enablePinC = 9; | ||
+ | |||
+ | const int gobuttonA = A0; | ||
+ | const int stopbuttonA = A1; | ||
+ | const int speedpotA = A2; | ||
+ | |||
+ | const int gobuttonB = A5; | ||
+ | const int stopbuttonB = A6; | ||
+ | const int speedpotB = A3; | ||
+ | |||
+ | const int gobuttonC = A7; | ||
+ | const int stopbuttonC = A10; | ||
+ | const int speedpotC = A4; | ||
+ | |||
+ | int directionA = 0; | ||
+ | int directionB = 0; | ||
+ | int directionC = 0; | ||
+ | |||
+ | int ton = 0; | ||
+ | |||
+ | int buttonastate = 0; | ||
+ | int buttonbstate = 0; | ||
+ | int buttoncstate = 0; | ||
+ | int afl = 0; | ||
+ | int bfl = 0; | ||
+ | |||
+ | String command; | ||
+ | long int currpos; | ||
+ | long int pos; | ||
+ | |||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | Serial.begin(115200); | ||
+ | pinMode(stepsPinA, | ||
+ | pinMode(directionPinA, | ||
+ | pinMode(enablePinA, | ||
+ | pinMode(stepsPinB, | ||
+ | pinMode(directionPinB, | ||
+ | pinMode(enablePinB, | ||
+ | pinMode(speedpotA, | ||
+ | pinMode(gobuttonA, | ||
+ | pinMode(stopbuttonA, | ||
+ | pinMode(speedpotB, | ||
+ | pinMode(gobuttonB, | ||
+ | pinMode(stopbuttonB, | ||
+ | pinMode(speedpotC, | ||
+ | pinMode(gobuttonC, | ||
+ | pinMode(stopbuttonC, | ||
+ | |||
+ | digitalWrite(enablePinA, | ||
+ | digitalWrite(enablePinB, | ||
+ | digitalWrite(directionPinA, | ||
+ | digitalWrite(directionPinB, | ||
+ | digitalWrite(directionPinC, | ||
+ | currpos = 0; | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | Input = read_temp(" | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | int rawvalue = analogRead(THERMISTOR_PINA); | ||
+ | int rawvalueA = rawvalue; | ||
+ | float celsiusA = read_temp(" | ||
+ | |||
+ | |||
+ | |||
+ | Serial.print("" | ||
+ | | ||
+ | digitalWrite(stepsPinA, | ||
+ | digitalWrite(directionPinA, | ||
+ | digitalWrite(enablePinA, | ||
+ | |||
+ | |||
+ | digitalWrite(stepsPinB, | ||
+ | digitalWrite(directionPinB, | ||
+ | digitalWrite(enablePinB, | ||
+ | |||
+ | digitalWrite(stepsPinC, | ||
+ | digitalWrite(directionPinC, | ||
+ | digitalWrite(enablePinC, | ||
+ | |||
+ | |||
+ | /* | ||
+ | if (levelstreamon == 1) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | if (digitalRead(stopbuttonA) ==HIGH){ | ||
+ | if (bfl == 0){ | ||
+ | if (directionA==0){directionA = 1; digitalWrite(directionPinA, | ||
+ | Serial.print(directionA); | ||
+ | Serial.println(" | ||
+ | bfl = 1; | ||
+ | } | ||
+ | } else { bfl = 0; } | ||
+ | |||
+ | if (digitalRead(gobuttonA) == 1){ | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | if (digitalRead(stopbuttonB) ==HIGH){ | ||
+ | if (bfl == 0){ | ||
+ | if (directionB==0){directionB = 1; digitalWrite(directionPinB, | ||
+ | Serial.print(directionB); | ||
+ | Serial.println(" | ||
+ | bfl = 1; | ||
+ | } | ||
+ | } else { bfl = 0; } | ||
+ | |||
+ | if (digitalRead(gobuttonB) == 1){ | ||
+ | Serial.println(" | ||
+ | | ||
+ | } | ||
+ | |||
+ | if (digitalRead(stopbuttonC) ==HIGH){ | ||
+ | if (bfl == 0){ | ||
+ | if (directionC==0){directionC = 1; digitalWrite(directionPinC, | ||
+ | Serial.print(directionC); | ||
+ | Serial.println(" | ||
+ | bfl = 1; | ||
+ | } | ||
+ | } else { bfl = 0; } | ||
+ | |||
+ | if (digitalRead(gobuttonC) == 1){ | ||
+ | Serial.println(" | ||
+ | | ||
+ | } | ||
+ | */ | ||
+ | |||
+ | |||
+ | | ||
+ | | ||
+ | { | ||
+ | char c = Serial.read(); | ||
+ | if (c== ' | ||
+ | { | ||
+ | currpos = parseCommand(command, | ||
+ | command = ""; | ||
+ | } | ||
+ | | ||
+ | else | ||
+ | { | ||
+ | command +=c; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | long int parseCommand(String com, long int currpos) | ||
+ | { | ||
+ | // | ||
+ | // | ||
+ | |||
+ | if(com.equalsIgnoreCase(" | ||
+ | | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | Serial.println(" | ||
+ | } | ||
+ | else if (com.substring(0, | ||
+ | settemp = com.substring(8).toDouble(); | ||
+ | Setpoint = settemp; | ||
+ | Serial.print(" | ||
+ | Serial.println(settemp); | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | | ||
+ | } | ||
+ | else if(com.equalsIgnoreCase(" | ||
+ | int rawvalue = analogRead(THERMISTOR_PINA); | ||
+ | float celsius = read_temp(" | ||
+ | | ||
+ | | ||
+ | } | ||
+ | else { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | int readpotentionmetersanity(){ | ||
+ | int val = analogRead(speedpotA); | ||
+ | | ||
+ | | ||
+ | val = analogRead(speedpotB); | ||
+ | | ||
+ | | ||
+ | val = analogRead(speedpotC); | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | int runnerA(){ | ||
+ | int stpper = 1; | ||
+ | int speed = analogRead(speedpotA); | ||
+ | int stepdelay = map(speed, 0, 1023, 1, 2000); | ||
+ | | ||
+ | speed = analogRead(speedpotA); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | if (digitalRead(stopbuttonA) ==HIGH){ break; } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | int runnerB(){ | ||
+ | int stpper = 1; | ||
+ | int speed = analogRead(speedpotB); | ||
+ | int stepdelay = map(speed, 0, 1023, 1, 2000); | ||
+ | | ||
+ | speed = analogRead(speedpotB); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | if (digitalRead(stopbuttonB) ==HIGH){ break; } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | int runnerC(){ | ||
+ | int stpper = 1; | ||
+ | int speed = analogRead(speedpotB); | ||
+ | int stepdelay = map(speed, 0, 1023, 1, 2000); | ||
+ | | ||
+ | speed = analogRead(speedpotC); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | if (digitalRead(stopbuttonC) ==HIGH){ break; } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | #define NUMTEMPS 20 | ||
+ | short temptable[NUMTEMPS][2] = { | ||
+ | {1, 841}, {54, 255}, | ||
+ | {107, 209}, | ||
+ | {160, 184}, | ||
+ | {213, 166}, | ||
+ | {266, 153}, | ||
+ | {319, 142}, | ||
+ | {372, 132}, | ||
+ | {425, 124}, | ||
+ | {478, 116}, | ||
+ | {531, 108}, | ||
+ | {584, 101}, | ||
+ | {637, 93}, | ||
+ | {690, 86}, | ||
+ | {743, 78}, | ||
+ | {796, 70}, | ||
+ | {849, 61}, | ||
+ | {902, 50}, | ||
+ | {955, 34}, | ||
+ | | ||
+ | }; | ||
+ | |||
+ | float read_temp(String sensor_type) | ||
+ | { | ||
+ | int THERMISTOR_PIN = 0; | ||
+ | if (sensor_type == " | ||
+ | THERMISTOR_PIN = THERMISTOR_PINA; | ||
+ | } | ||
+ | int rawtemp = analogRead(THERMISTOR_PIN); | ||
+ | float current_celsius = 0; | ||
+ | |||
+ | byte i; | ||
+ | for (i=1; i< | ||
+ | { | ||
+ | if (temptable[i][0] > rawtemp) | ||
+ | { | ||
+ | float realtemp | ||
+ | |||
+ | if (realtemp > 255) | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Overflow: We just clamp to 0 degrees celsius | ||
+ | if (i == NUMTEMPS) | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | </ | ||
Line 18: | Line 368: | ||
< | < | ||
- | #include < | ||
- | |||
#include < | #include < | ||
Line 27: | Line 375: | ||
#define motorInterfaceType 1 | #define motorInterfaceType 1 | ||
- | AccelStepper stepper = AccelStepper(motorInterfaceType, | ||
- | |||
- | |||
- | |||
- | //const float stepsperul = 230; // | ||
- | //const float stepsperul = 131.53; // | ||
- | //const float stepsperul = 272.12; // | ||
- | |||
- | |||
- | int turnon = 4; | ||
int enablePin = 9; | int enablePin = 9; | ||
int estepsPin = 3; | int estepsPin = 3; | ||
Line 42: | Line 380: | ||
int direction = 0; | int direction = 0; | ||
int ton = 0; | int ton = 0; | ||
- | |||
- | int elimitPin = A1; | ||
- | //int esteps = 1000; | ||
- | //int esteprate = 500; | ||
- | //int estepsincrement = 0; | ||
- | int estepcount = 0; | ||
- | |||
int speedpot = A5; | int speedpot = A5; | ||
- | |||
int buttona = A4; | int buttona = A4; | ||
int buttonb = A3; | int buttonb = A3; | ||
- | |||
- | |||
int buttonastate = 0; | int buttonastate = 0; | ||
int buttonbstate = 0; | int buttonbstate = 0; | ||
+ | int afl = 0; | ||
+ | int bfl = 0; | ||
- | |||
- | //float stepsperul = 23; // | ||
- | const float stepsperul = 131.43; | ||
- | |||
- | int acc = 30; | ||
String command; | String command; | ||
long int currpos; | long int currpos; | ||
Line 69: | Line 394: | ||
void setup() { | void setup() { | ||
// put your setup code here, to run once: | // put your setup code here, to run once: | ||
- | stepper.setMaxSpeed(1000*16); | ||
Serial.begin(115200); | Serial.begin(115200); | ||
- | |||
- | pinMode(turnon, | ||
- | digitalWrite(turnon, | ||
- | |||
pinMode(enablePin, | pinMode(enablePin, | ||
pinMode(directionPin, | pinMode(directionPin, | ||
pinMode(estepsPin, | pinMode(estepsPin, | ||
- | |||
- | |||
pinMode(speedpot, | pinMode(speedpot, | ||
pinMode(buttona, | pinMode(buttona, | ||
pinMode(buttonb, | pinMode(buttonb, | ||
- | |||
- | |||
digitalWrite(enablePin, | digitalWrite(enablePin, | ||
+ | digitalWrite(directionPin, | ||
currpos = 0; | currpos = 0; | ||
- | stepper.setAcceleration(acc); | ||
} | } | ||
void loop() { | void loop() { | ||
// put your main code here, to run repeatedly: | // put your main code here, to run repeatedly: | ||
- | + | buttonastate = digitalRead(buttona); | |
- | buttonastate = analogRead(buttona); | + | |
- | | + | |
/* | /* | ||
- | | + | |
- | | + | |
- | */ | + | |
- | if (buttonbstate < 1020){ | + | |
- | | + | |
- | } else { Serial.println("buttonbstate | + | */ |
- | if (buttonastate < 1020){ | + | if (buttonbstate ==HIGH){ |
- | Serial.println(" | + | |
- | } else { Serial.println("buttonastate | + | if (direction==0){direction = 1; digitalWrite(directionPin, |
+ | Serial.print(direction); | ||
+ | | ||
+ | bfl = 1; | ||
+ | } | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | /* | ||
- | if (digitalRead(buttona) == HIGH){ | ||
- | Serial.println(" | ||
- | if (ton==0){ton = 1; | ||
- | } | ||
- | if (digitalRead(buttonb) == HIGH){ | ||
- | Serial.println(" | ||
- | if (direction==0){direction = 1; | ||
- | } | ||
- | */ | ||
| | ||
{ | { | ||
Line 130: | Line 439: | ||
command = ""; | command = ""; | ||
} | } | ||
- | else | + | |
+ | | ||
{ | { | ||
command +=c; | command +=c; | ||
Line 143: | Line 453: | ||
// | // | ||
- | | + | |
- | String part1 = com.substring(0,com.indexOf(" | + | readpotentionmetersanity(speedpot); |
- | if (part1.equalsIgnoreCase(" | + | |
- | | + | |
- | String part3 = com.substring(com.indexOf(" | + | |
- | String part4 = com.substring(com.indexOf(" | + | |
- | int vpos = part2.toInt(); | + | |
- | pos = vpos * stepsperul; | + | |
- | int vfeed = part3.toInt(); | + | |
- | int feed = vfeed * stepsperul; | + | |
- | //int acc = part4.toInt(); | + | |
- | //int feed = vfeed; | + | |
- | int acc = feed/3; | + | |
- | if ((pos-currpos) < 0) { | + | |
- | feed = feed * -1; | + | |
- | } | + | |
- | moveacc((pos-currpos), | + | |
- | currpos = pos; | + | |
} | } | ||
- | | + | if(com.equalsIgnoreCase(" |
| | ||
- | } | + | |
- | else if(com.equalsIgnoreCase(" | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | } | + | |
- | else if(com.equalsIgnoreCase(" | + | |
- | | + | |
- | | + | |
- | pos = 0; | + | |
- | } | + | |
- | else if(com.equalsIgnoreCase(" | + | |
- | | + | |
- | | + | |
- | } | + | |
- | else if(com.equalsIgnoreCase(" | + | |
- | if (direction == 0){ | + | |
- | direction = 1; | + | |
- | } | + | |
- | | + | |
- | | + | |
} | } | ||
else if(com.equalsIgnoreCase(" | else if(com.equalsIgnoreCase(" | ||
- | Serial.println(" | + | Serial.println(" |
} | } | ||
else { | else { | ||
Line 195: | Line 468: | ||
} | } | ||
| | ||
- | } | ||
- | |||
- | |||
- | void moveacc(long int inc, int spd, int acc){ | ||
- | // | ||
- | | ||
- | | ||
- | | ||
- | stepper.setSpeed(spd); | ||
- | stepper.runSpeed(); | ||
- | } | ||
} | } | ||
int readpotentionmetersanity(int speedPin){ | int readpotentionmetersanity(int speedPin){ | ||
+ | int val = analogRead(speedPin); | ||
| | ||
- | | + | |
- | int val = analogRead(A2); | + | |
- | int stepdelay = map(val, 0, 1023, 1, 1000); | + | //int stepdelay = map(val, 0, 1023, 1, 1000); |
- | | + | //Serial.print(" |
- | | + | //Serial.println(stepdelay); |
} | } | ||
- | int movespeedadjust(int stepsPin, int direction, int directionPin, | + | int runner(int stepsPin, int directionPin, |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | } | + | |
- | | + | speed = analogRead(speedpot); |
- | | + | stepdelay |
- | int stepdelay = map(val, 0, 1023, 1, 1000); | + | //stepdelay = 100; |
- | | + | digitalWrite(stepsPin, |
- | int spd = analogRead(A2) * stepsperul; | + | delayMicroseconds(stepdelay); // Wait 1/2 a ms |
- | int acc = spd/3; | + | digitalWrite(stepsPin, |
- | | + | delayMicroseconds(stepdelay); // Wait 1/2 a ms |
- | | + | |
- | | + | |
- | int checker = digitalRead(limitPin); | + | |
- | | + | |
- | | + | |
- | } | + | |
} | } | ||
+ | | ||
} | } | ||
- | |||
- | int homing(int stepsPin, int directionPin, | ||
- | digitalWrite(directionPin, | ||
- | int checker = 1; | ||
- | int cnter = 0; | ||
- | int stpper = 1; | ||
- | | ||
- | checker = digitalRead(limitPin); | ||
- | if (checker == HIGH){ | ||
- | cnter = cnter + 1; | ||
- | } | ||
- | else { | ||
- | cnter = 0; | ||
- | } | ||
- | if (cnter > 4){ | ||
- | stpper = 0; | ||
- | } | ||
- | digitalWrite(stepsPin, | ||
- | delayMicroseconds(200); | ||
- | digitalWrite(stepsPin, | ||
- | delayMicroseconds(200); | ||
- | } | ||
- | | ||
- | | ||
- | digitalWrite(stepsPin, | ||
- | delayMicroseconds(1000); | ||
- | digitalWrite(stepsPin, | ||
- | delayMicroseconds(1000); | ||
- | } | ||
- | int stepcount = 0; | ||
- | return stepcount; | ||
- | } | ||
</ | </ | ||