We managed to get the stepper motor working. We used an Arduino Mega to control the stepper motor with an A4988 Driver, and an Arduino Uno to emit a digital signal to the other arduino to simulate the signal it will end up receiving from the ABB Robot.
Two ways to control the extrusion: time or step. Time is not reliable at all. Controlling the steps is the proper way to achieve a reliable extrusion length.
Below, a table with extrusion measurements.
Resources:
https://learn.adafruit.com/thermistor/using-a-thermistor
http://randomdamon.blogspot.com/2015/12/diy-hot-end-arduino-pid-control.html
Here the code we used for both arduinos:
////////////////ARDUINO MEGA. Listen to a signal coming from the other arduino and start the stepper motor.
const int pinVal = 2; // transfer the info to the motor // reads the info from the other //arduino (in the future from the robot) //const int caso = A0; // reads the length of the values from the robot const int stepPin = 5; const int dirPin = 4; int caso = 0; bool engine = true; //bool activar = engine; unsigned long duration; unsigned long time; int currentMillis = 0; int previousMillis = 0; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(pinVal, INPUT); pinMode(caso, OUTPUT); pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); digitalWrite(pinVal, HIGH); engine = true; } void loop() { //digitalWrite(stepPin, LOW); duration = pulseIn(pinVal, HIGH); // Serial.println("duration is: "); // Serial.print(duration); if(duration > 5000){ pulseIn(pinVal, HIGH); casoA(); // Serial.print("Time: "); // time = micros(); // Serial.println(time); // delay(1000); //retract(); pulseIn(pinVal, LOW); // if(activar == true){ // digitalWrite(stepPin, HIGH); // }else digitalWrite(stepPin, LOW); } else if(duration 1){ casoB(); // if(activar == true && stepPin == LOW){ // digitalWrite(stepPin, HIGH); // }else digitalWrite(stepPin, LOW); // Serial.println("holi"); // delay(3000); // digitalWrite(stepPin, LOW); } // digitalWrite(stepPin, LOW); else off(); } void casoA(){ // pulseIn(pinVal, LOW); if(engine == true){ // Serial.println("duration is: "); // Serial.print(duration); Serial.println("CASO A"); unsigned long currentMillis = millis(); for(int x = 0; x < 2400; x++) { // 200 steps at full driver step is 1 complete rotation // duration = pulseIn(pinVal, HIGH); digitalWrite(dirPin, LOW); digitalWrite(stepPin, HIGH); delayMicroseconds(5000); digitalWrite(stepPin,LOW); delayMicroseconds(5000); } int exTime = currentMillis - previousMillis; Serial.println("extrusion time is: "); Serial.print(exTime); previousMillis = 0; engine = false; } } void casoB(){ Serial.println("CASO B"); digitalWrite(dirPin, LOW); digitalWrite(stepPin, HIGH); delayMicroseconds(500); digitalWrite(stepPin,LOW); delayMicroseconds(500); } void off(){ pulseIn(pinVal, LOW); Serial.println("\nOFF"); digitalWrite(stepPin, LOW); //digitalWrite(dirPin, LOW); delay(5000); } void retract(){ Serial.println("retraction!!"); for(int x = 0; x <span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>< 400; x++) { digitalWrite(dirPin, HIGH); digitalWrite(stepPin, HIGH); delayMicroseconds(500); digitalWrite(stepPin,LOW); delayMicroseconds(500); } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ARDUINO UNO. This code reads the hot end and emits a signal
#include
// Analog output pin
#define outputPin 9
// thermistor analog pin
#define THERMISTORPIN A0
// how many samples to take and average
#define NUMSAMPLES 5
// how long between pid/sampling
#define SAMPLETIME 1000
//Define Variables we’ll be connecting to
double Setpoint, currentTemp, Output;
//Specify the links and initial tuning parameters
PID myPID(¤tTemp, &Output, &Setpoint,15,.3,0, DIRECT);
//////////////////////////////// FROM HERE BELOW SETTING TO SEND SIGNAL WHEN TEMPERATURE OK TO PRINT /////////////////
const int casoA = 3; // 10000 delay (speed of the robot) and rotate CW
const int casoB = 4; // 20000 delay and rotate CCW
int casos;
int vel = 0;
int dir = 1;
bool engine = true;
int val = 0;
int previousMillis = 0;
int currentMillis = 0;
long interval = 10000;
bool SENDSIGNAL = false;
////////////////////////////////////
void setup() {
Serial.begin(9600);
analogReference(EXTERNAL);
pinMode(outputPin, OUTPUT);
//initialize PID setpoint *C
Setpoint = 190;
//turn the PID on
myPID.SetMode(AUTOMATIC);
myPID.SetSampleTime(SAMPLETIME);
//pid Autotuner
pinMode(casoA, OUTPUT);
pinMode(casoB, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
// get incoming byte:
Setpoint = Serial.parseFloat();
}
uint8_t i;
double average = 0;
// take N samples in a row, with a slight delay
for (i = 0; i 2){
SENDSIGNAL = false;
digitalWrite(casoA, LOW);
}
}
/////////////////////////////////////////////////
// if(SENDSIGNAL == true){
// Serial.print(SENDSIGNAL);
//
// unsigned long currentMillis = millis();
// if(currentMillis – previousMillis interval){
// digitalWrite(casoA, LOW);
// }
// // else if(currentMillis – previousMillis > interval){
// // digitalWrite(casoA, LOW);
// // }
//
// //delay(20000);
// //analogWrite(casoA,255);
// //
// // digitalWrite(casoB, HIGH);
// // analogWrite(casoB, 100);
// previousMillis = 0;
// }
///////////////////////////////////////////////////
}
double inputToResistance(double input) {
// funtion to convert the input value to resistance
// the value of the ‘other’ resistor
double SERIESRESISTOR = 10000;
input = 1023 / input – 1;
return SERIESRESISTOR / input;
}
double resistanceToC(double resistance) {
// funtion to convert resistance to c
// temp/resistance for nominal
double THERMISTORNOMINAL = 118000;
double TEMPERATURENOMINAL = 25;
// beta coefficent
double BCOEFFICIENT = 3950;
double steinhart;
steinhart = resistance / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C
return steinhart;
}