3D tryckt spruta Pump Rack (26 / 29 steg)
Steg 26: Instaling Firmware
Nu när du har pumpen wired och allt ihop, ansluta USB-kabeln till Arduino Nano till din dator och ladda upp den sprutpumpen kod.
Glöm inte att importera Acellstepper bibliotek till mappen Arduino.
Den final koden bör icke blockerande och bör ständigt kontrollera hallgivare av säkerhetsskäl.
Obs: Detta är inte den final koden, du kan använda den för att testa, jag kommer att uppdatera koden så snart jag kan.
#include < AccelStepper.h >
AccelStepper stepper (1, 9, 10); driver steg riktning
char userInput [21] = {hade ', '0', '0', '0', '0', '0', 'v', '0', '0', '0', '0',' 0',' v','0 ','0 ','0 ',' 0','0 ','d ','1 ', "\r"};
int deslocamento = 0; int volym = 0; int mspeed = 1; int mdirection = 0; int data = 0; int microstepping = 16. int msg_lenght = 0;
void setup() {Serial.begin(9600); stepper.setMaxSpeed(1000.0); stepper.setAcceleration(1000.0); stepper.setCurrentPosition(0);}
void loop() {
Delay(500);
om (data == 0) readuserdata();
om (data == 1) {
deslocamento = röding (userInput [1] - 48) * 10000 + char (userInput [2] - 48) * 1000 + char (userInput [3] - 48) * 100 + char (userInput [4] - 48) * 10 + char (userInput [5] - 48);
volym = röding (userInput [7] - 48) * 10000 + char (userInput [8] - 48) * 1000 + char (userInput [9] - 48) * 100 + char (userInput [10] - 48) * 10 + char (userInput [11] - 48);
mspeed = röding (userInput [13] - 48) * 10000 + char (userInput [14] - 48) * 1000 + char (userInput [15] - 48) * 100 + char (userInput [16] - 48) * 10 + char (userInput [17] - 48);
mdirection = röding (userInput [19] - 48);
om (mdirection == 0)
deslocamento =-1 * deslocamento;
annat
deslocamento = deslocamento;
Serial.println(""); Serial.Print (deslocamento, DEC); Serial.Print(""); Serial.Print (volym, DEC); Serial.Print(""); Serial.Print (mspeed, DEC); Serial.Print(""); Serial.println (mdirection, DEC);
stepper.setSpeed(mspeed);
stepper.setMaxSpeed(mspeed);
stepper.runToNewPosition(deslocamento*microstepping);
stepper.setCurrentPosition(0);
data = 0; deslocamento = 0; volym = 0; mspeed = 0; mdirection = 0;
för (int jag = 0; jag < = 21; i ++)
userInput [i] = 0;
}
}
void readuserdata() {
char tmp;
IF(Serial.available()) {
msg_lenght = Serial.available();
Serial.Print ("meddelandet längd =");
Serial.Print(msg_lenght);
om (msg_lenght == 20) {
tmp = Serial.read();
om (tmp == hade ") {
userInput [0] = tmp;
för (int jag = 1; jag < = msg_lenght; i ++) {
tmp=Serial.Read();
userInput [i] = char(tmp);
}
data = 1;
}
}
}
}