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/11/02 17:30] richard |
bdev:filamentextruder_recyclebot [2022/11/05 23:52] (current) richard |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Filament extruder recyclebot ====== | ====== Filament extruder recyclebot ====== | ||
+ | ====== filabotmega.ino ====== | ||
- | |||
- | Here is code for controlling 2 motors: | ||
< | < | ||
+ | #include < | ||
#include < | #include < | ||
#include < | #include < | ||
- | #define dirPin 4 | ||
- | #define stepPin 3 | ||
#define motorInterfaceType 1 | #define motorInterfaceType 1 | ||
- | const int stepsPinA = 2; | + | |
- | const int directionPinA = 3; | + | #define THERMISTOR_PINA A11 |
- | const int enablePinA = 4; | + | #define TEMPCONTROLA 10 |
- | const int stepsPinB = 5; | + | |
- | const int directionPinB = 6; | + | //Define the aggressive and conservative Tuning Parameters |
- | const int enablePinB = 7; | + | 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 | ||
+ | |||
+ | const int stepsPinC | ||
+ | const int directionPinC = 8; | ||
+ | const int enablePinC = 9; | ||
const int gobuttonA = A0; | const int gobuttonA = A0; | ||
const int stopbuttonA = A1; | const int stopbuttonA = A1; | ||
const int speedpotA = A2; | const int speedpotA = A2; | ||
- | const int gobuttonB = A3; | + | |
- | const int stopbuttonB = A4; | + | const int gobuttonB = A5; |
- | const int speedpotB = 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 directionA = 0; | ||
int directionB = 0; | int directionB = 0; | ||
+ | int directionC = 0; | ||
int ton = 0; | int ton = 0; | ||
Line 34: | Line 61: | ||
int buttonastate = 0; | int buttonastate = 0; | ||
int buttonbstate = 0; | int buttonbstate = 0; | ||
+ | int buttoncstate = 0; | ||
int afl = 0; | int afl = 0; | ||
int bfl = 0; | int bfl = 0; | ||
Line 56: | Line 84: | ||
pinMode(gobuttonB, | pinMode(gobuttonB, | ||
pinMode(stopbuttonB, | pinMode(stopbuttonB, | ||
+ | pinMode(speedpotC, | ||
+ | pinMode(gobuttonC, | ||
+ | pinMode(stopbuttonC, | ||
+ | |||
digitalWrite(enablePinA, | digitalWrite(enablePinA, | ||
digitalWrite(enablePinB, | digitalWrite(enablePinB, | ||
digitalWrite(directionPinA, | digitalWrite(directionPinA, | ||
digitalWrite(directionPinB, | digitalWrite(directionPinB, | ||
+ | digitalWrite(directionPinC, | ||
currpos = 0; | currpos = 0; | ||
} | } | ||
Line 65: | Line 98: | ||
void loop() { | 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) { | ||
+ | Serial.print(" | ||
+ | Serial.print(rawvalueA); | ||
+ | | ||
+ | Serial.println(celsiusA); | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
if (digitalRead(stopbuttonA) ==HIGH){ | if (digitalRead(stopbuttonA) ==HIGH){ | ||
Line 82: | Line 148: | ||
} else { bfl = 0; } | } else { bfl = 0; } | ||
- | if (digitalRead(gobuttonA) == HIGH){ | + | if (digitalRead(gobuttonA) == 1){ |
+ | | ||
| | ||
} | } | ||
Line 95: | Line 162: | ||
} else { bfl = 0; } | } else { bfl = 0; } | ||
- | if (digitalRead(gobuttonB) == HIGH){ | + | 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(" | ||
+ | | ||
+ | } | ||
+ | */ | ||
- | + | | |
- | + | ||
- | + | ||
- | + | ||
| | ||
{ | { | ||
Line 134: | Line 211: | ||
else if(com.equalsIgnoreCase(" | else if(com.equalsIgnoreCase(" | ||
Serial.println(" | 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 { | else { | ||
Line 149: | Line 244: | ||
| | ||
| | ||
- | //int stepdelay | + | val = analogRead(speedpotC); |
- | //Serial.print(" | + | |
- | //Serial.println(stepdelay); | + | |
} | } | ||
Line 187: | Line 282: | ||
} | } | ||
+ | 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) | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | </ | ||