User Tools

Site Tools


granular_gripper

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
granular_gripper [2019/07/29 15:57] – [Circuit] yuhanghegranular_gripper [2019/07/29 16:21] – [Programming] yuhanghe
Line 118: Line 118:
 ==== Programming ==== ==== Programming ====
  
-A link to the source code can be found <provide URL to your code, probably saved in this DASL Wiki>.+A link to the source code can be found {{:yuhang:gripper:vacuum_control1.zip| Arduino Code}}
 \\ \\
-The goal of the code is <brief explanation>.  It works in the following way +<code cpp | Switch.ino> 
-\\ +  String input; // for incoming serial data 
----- +  int command; 
-<!- Insert snippet of your code here.  Try to keep to less than 0.5 page long --> +  bool vac = false; //Switch condition for vacuum 
----- +  bool blow = false; //Switch condition for blow off 
-\\ +  bool off = true; //Switch condition for off 
-The snippet above serves to <fill in the blank>It does this by <fill in the blank>+   
-\\ +void setup() { 
----- +  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps 
-<!- Insert another snippet of your code here Try to keep to less than 0.5 page long --> +  pinMode(8, OUTPUT); //Assign port 8 and 9 as digital output 
----- +  pinMode(9, OUTPUT); 
-Nextthe code does <fill in the blank>.  It does this by <fill in the blank>  +  digitalWrite(9, HIGH); 
-<!-- Keep entering snippets of code and descriptions until you've given enough for a reader to understand how it works -->+  digitalWrite(8, HIGH); 
 +
 + 
 +void loop() { 
 +  // send data only when you receive data: 
 +  if (Serial.available() > 0) { 
 +    // read the incoming string: 
 +    input = Serial.readString(); 
 +    // read input data from the serial monitor 
 +    command = input.toInt(); 
 +    // enter a command of 1 to turn on and off vac 
 +      if (command == 1) { 
 +        vac = !vac; 
 +      } 
 +    // enter command of to turn on and off blow off 
 +      if (command == 3) { 
 +        blow = !blow; 
 +      } 
 +      /*Serial.print("vac: "); 
 +      Serial.println(vac); 
 +      Serial.print("blow: "); 
 +      Serial.println(blow); 
 +      Serial.print("off: "); 
 +      Serial.println(off);*/ 
 +         
 +    if (vac && blow || !vac && !blow) { 
 +      vac = false; 
 +      blow = false; 
 +      Serial.println("off"); 
 +      // due to circuit design, a HIGH digital output corresponds to off for the ejector signal 
 +      digitalWrite(9, HIGH); 
 +      digitalWrite(8, HIGH); 
 +    } 
 +    else if (blow) { 
 +      Serial.println("blow on"); 
 +      // digital pin 8 is connected to blow off 
 +      digitalWrite(8LOW); 
 +      digitalWrite(9, HIGH); 
 +      delay(300); 
 +      digitalWrite(8, HIGH); 
 +      blow = false; 
 +      vac = false; 
 +      Serial.println("off"); 
 +    } 
 +    else if (vac) { 
 +      Serial.println("vacuum on"); 
 +      // digital pin 9 is connected to vacuum 
 +      digitalWrite(9, LOW); 
 +      digitalWrite(8, HIGH); 
 +    } 
 +  
 +
 +</code> 
 +The command for the ejector controller is entered through Serial Monitor on the Arduino IDE accessed through the Tools menu on the top of IDE. 
 +Enter 1 in the command line to turn on vacuum
 +{{ :yuhang:gripper:vacuum_on.png |}} 
 +Enter 3 in the command line for a short blow off. 
 +{{ :yuhang:gripper:blow_off.png |}}
 // //
 // //
granular_gripper.txt · Last modified: 2019/07/29 16:22 by yuhanghe