“Stepper Motor Control”的版本间的差异

来自Microduino Wikipedia
跳转至: 导航搜索
Pkj讨论 | 贡献
(Created page with "{| style="width: 800px;" |- | ==Objective== The course will show you how to control stepper motor via “Processing”. ==Equipment== *'''Microduino-Core''' *'''Micro...")
(没有差异)

2014年6月6日 (五) 07:54的版本

Objective

The course will show you how to control stepper motor via “Processing”.

Equipment

Microduino-A4982

  • Other Hardware Equipment
    • A USB cable
    • A pegboard
    • A copper cylinder and a screw
  • Welding tools
    • Electric iron
    • Tin solder
    • Wire
    • Tweezer


Schematic

Stepper motor.jpg

Program

https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/MicroduinoStepperControl

https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/ProcessingStepperControl

Debugging

The hardware buildup is similar to that of the DC motor in the 38th advanced course: http://www.microduino.cc/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E5%8D%81%E5%85%AB%E8%AF%BE--Microduino_%E6%AD%A5%E8%BF%9B%E7%94%B5%E6%9C%BA%E9%A9%B1%E5%8A%A8/zh

  • Step 1:Cut pegboard with the right size;


  • Step 2:Make sure a right base location and weld the circuit according to the schematic;
洞洞板焊法
正面
反面
  • Building the circuit
ok

Step 3:Here is the code needed: The code of the two ends (Processing and Microduino)

Microduino:

//Read serial data

 void loop() {
   if(Serial.available())
   {
     command=Serial.read();
     Serial.println(command);
     if(command=='l') {//The stepper motor turns left if the data sent from Processing is 'l' 
       stepper.setSpeed(motorSpeed);
       stepper.runSpeed();
     } 
     else if(command=='r') {//The stepper motor turns right if the data sent from Processing is 'r' 
       stepper.setSpeed(-motorSpeed);
       stepper.runSpeed();
     }
     else {
       stepper.stop();//otherwise, it will stop turning
     }
   }
 }


Processing:

//Monitor the mouse during drawing function.

 void draw() 
 {
   background(0);
   image(img,0,0);
   noFill();
   if("left".equals(turning)) {
     rect(30,80,150,210);
     fill(0);        //Specify font color
     text ( "turn left" ,250,20); 
     port.write("l");
   }else if("right".equals(turning)) {
     rect(320,90,150,200);
     fill(0);        //Specify font color
     text ( "turn right" ,250,20); 
     port.write("r");
   }
 }

//Move the mouse and judge if it it inside the selection area

 // When the mouse is moved, the state of the turning is toggled.
 void mouseMoved() {
   if (mouseX > 30 && mouseX < 180 && mouseY > 80 && mouseY < 290) {
     turning = "left";
     cursor(HAND);
   }
   else if (mouseX > 320 && mouseX < 470 && mouseY > 90 && mouseY < 290) {
     turning = "right";
     cursor(HAND);
   }
   else {
     turning = "turning";
     cursor(ARROW);
   }
 }

Step 4:Download the code and pass the compiling.

Step 5:Put the mouse on the “boy in the left” and the “girl in the right” to see the response of the stepper motor after the system goes well.

Result

When putting the mouse on the “boy in the left”:

When putting the mouse on the “girl in the right”:

The stepper motor will turn in the appropriate direction


Video