7856| 4
|
[项目] Arduino切线机剪线机 |
本帖最后由 Arduino_xy 于 2019-3-26 00:41 编辑 设置好所需长度和数量的线材后,自动完成切割。 硬件材料 1*Arduino UNO 1*电机驱动器 1*23步进电机 1*12v转5v稳压模块 1*支架、螺钉、垫片等 2*轮胎 灵感来源 人工线轴上拉出几千根长20cm的22awg电线并不是一件有趣的事。它很无聊,而且很容易出现不准确。需要2个人花上2天才能手动拉完706个22awg电线。如果你只有一个线轴(一次拉1个线),则需要更长的时间。使用Arduino切线机,你需输入所需的长度和数量,即可预先输入所需的长度和数量,就可以自动完成。 [mw_shl_code=applescript,true]#include <math.h> //#math #include <Servo.h> //From Library Servo servoMain; // Define Servo #include <SoftwareSerial.h> // soft serial for LCD #define stp 2 //define stepper #define dir 3 //define stepper #define MS1 4 //define stepper #define MS2 5 //define stepper #define MS3 6 //define stepper #define EN 7 //define stepper float a; //variable assignment qty float b; //variable assignment inches float c; //variable assignment required motor steps float W; //removed from functions for now, might need later. char junk = ' '; //any random character input. char val; // Data received from the serial port char user_input; int x; //Probably over loaded on assignments, not sure. Remove later and test. int y; int state; SoftwareSerial mySerial(0, 11); // pin 11 = TX void setup() // set up { pinMode(15, OUTPUT); // set the pin to input servoMain.attach(9); // servo on digital pin 9 pinMode(13, OUTPUT); // led on pin 13 pinMode(stp, OUTPUT); //B.E.D pinMode(dir, OUTPUT); //B.E.D pinMode(MS1, OUTPUT); //B.E.D pinMode(MS2, OUTPUT); //B.E.D pinMode(MS3, OUTPUT); //B.E.D pinMode(EN, OUTPUT); //B.E.D resetBEDPins(); //Set step, direction, microstep and enable pins to default states Serial.begin(9600); // set up Serial library at 9600 bps mySerial.begin(9600); // set up serial port for 9600 baud Serial.println("Lets Cut Some Wires!"); //welcome message in serial window Serial.println(""); Serial.flush(); //clear the input que. } void loop() { { mySerial.write(" "); // clear display mySerial.write(" "); mySerial.write(254); // move cursor to beginning of first line mySerial.write(128); mySerial.write("Solution Systems Feed n Cut!"); delay(2); } Serial.println("Enter Quantity, Press ENTER"); // user Input request qty while (Serial.available() == 0) ; // Wait here until input buffer has a character { a = Serial.parseFloat(); // new command in 1.0 forward Serial.print("a = "); Serial.println(a, DEC); while (Serial.available() > 0) // .parseFloat() can leave non-numeric characters { junk = Serial.read() ; } // clear the keyboard buffer } Serial.println("Enter Length in Inches, Press ENTER"); while (Serial.available() == 0) ; { b = Serial.parseFloat(); Serial.print("b = "); Serial.println(b, DEC); while (Serial.available() > 0) { junk = Serial.read() ; } // clear the keyboard buffer c = (float( b*26 )); Serial.print("Motor Steps = "); Serial.println(c, DEC); Serial.println(); } Serial.println("Ready to Begin? Press ENTER"); // user Input request Y or N? digitalWrite(EN, LOW); //Pull enable pin low to set FETs active and allow motor control while (Serial.available() == 0); // If data is available to read, { val = Serial.read(); // read it and store it in val if (val == 'y') { Serial.println("Here We Go!"); delay(10); for (a; a>0; a--){ // this step checks if the quantity entered (a) is greater than 0,... and deducts 1 from a. Feedft(); // if it is it repeats the step feed and cut function again. } } else { Serial.println("Restarting Setup..."); // otherwise restart } delay(10); // Wait 10 milliseconds for next reading } { junk = Serial.read() ; } // clear the keyboard buffer } //Reset Big Easy Driver pins to default states void resetBEDPins(){ digitalWrite(stp, LOW); digitalWrite(dir, LOW); digitalWrite(MS1, LOW); // leaving wired and in sketch for now, not using micro-step control at this time. digitalWrite(MS2, LOW); digitalWrite(MS3, LOW); digitalWrite(EN, HIGH); } //Functions void Feedft(){ Serial.println("Feeding Wire at default step mode."); digitalWrite(dir, LOW); //Pull direction pin low to move "forward" for(x= 1; x<c; x++){ //Loop the forward stepping enough times for motion to be visible digitalWrite(stp,HIGH); //Trigger one step forward delay(1); digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again delay(1); } //Need to add a stepper done moving function here!!!!!!!!!!!!!<================== ServoMainCut(); //Run the Cut Function delay(2000); Serial.println("Cutting Wire!"); //Fair Warning..... // RepeatCount(); //Run the repeat function { junk = Serial.read();} //Clear the keyboard buffer } //funtion Servo Cut void ServoMainCut(){ digitalWrite(13, HIGH); delay(100); digitalWrite(13, LOW); servoMain.write(177); // CUT!! Turn Servo Left to 176 degrees delay(750); // Wait 1.5 second servoMain.write(65); // Open Cutter Turn Servo Left to 65 degrees digitalWrite(13, HIGH); delay(100); digitalWrite(13, LOW); }[/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed