Incubator : Arduino + MeArm

Page 1

MeArm


Contents 1_Introduction 1.a_Software Description & Examples 1.b_Architectural Hypotheses 1.c_Initial Explorations 2_Implementation 2.a_Learning Arduino/Processing 2.b_The Algorithm 2.c_Prototypes 2.d_Conclusion 3_Refinement 3.a_Observed Qualities 3.b_Selection Criteria (3D objects) 3.c_Discussion 4_Appendix 4.a_Software Experiments 4.b_Meshing Experiments 5_Commented Code


Izyan Rawi_s3460455 Deborah Sing-Ling Lee_s3462542


Right: Grant Stewart Below: Grant Stewart, 2015

Introduction This a collaborative drawing project, where two robots come together to create a drawing on a roll of butter paper. One is a clumsy robotic arm powered by four hobby servos and made up of acrylic parts, and the other is a singular, bipolar stepper motor that turns at 1.8 degrees with each step. Together, they attempt to help their human draw out creative ideas in his/her time of need. The two robots rely on the Arduino board, an open-source electronics platform based on easy-to-use hardware and software. It is envisioned for anyone of any age level making interactive projects. Given the Arduino’s ability to develop interactive projects while communicating with software running on the computer, it provides the opportunity to develop a sketch and/or code that can tell the robots what to do. The intention of this unique and rather motley combination is to manipulate the existing relationship between the formal and informal. In a certain sense, the clumsy robotic arm acts as the clueless client that’s not entirely sure of his/her ideas, and the professional stepper motor acts as the architect that has the ability to refine the rough ideas. To create packaged deal that could eventually be sold as a commercial product, a couple of 3D printed forms were created alongside the robots. These 3D prints were formed through Rhinoceros 5.0, Grasshopper, Meshlab, 3D Coat. One of the prints acts as the ‘new and improved’ MeArm claw that

doubles as a pen holder and the other acts As the weeks passed, the initial intention of as a housing/casing for the breadboard, Ar- the project turned into one that would reduino, and the unpresentable jumper wires. quire the use of a WiFi shield, as we had hoped to connect the Arduino to Twitter and Throughout the course of the semester, have it read and write strings of text through there was a significant development in soft- the user’s’ tweets. However, it proved to be ware, coding and electronic skills. With the too much of a challenge as we faced budhelp of multiple open resources online and get problems and issues with the different guidance from several individuals, we were Arduino libraries. able to construct a MeArm and connect its four servos to the breadboard and Arduino, But despite the absence of the WiFi function, as well as power up the two stepper motors the cohesiveness of the MeArm and the via a motor shield and a 12V battery pack. stepper motors’ partnership is something that we didn’t expect, and it’s really interestWe struggled with the coding at first, as it ing to see such unique ‘individuals’ working was the first time we were dealing with Ardu- so well together. ino sketches and hacking Arduino through Processing. Trying to understand the setups The project still hopes to achieve the ‘collaband loops proved to be a headache, but ev- orative drawing’ on a bigger scale, through erything was able to come together as we the use of an online form so that it could be dedicated a significant amount of time to the controlled by anyone with internet connecproject and eventually, we developed a code tion or by Twitter users directing the MeArm that runs the MeArm and the stepper motors and stepper motors, telling them where to simultaneously. go and what to draw.



Left: Fritzing diagram connecting servo Right: Shawn Wallace, 2009 (detail) Opposite page: Shawn Wallace, 2009

Software Description & Examples The applied software for this project were give it further instructions. As we studied the Arduino, Rhinoceros, 3D Coat and Meshlab. code, we began to understand how various inputs, such as angle degrees and delay Arduino is an open-source computer soft- time would change MeArm responses. ware and hardware company that designs and manufactures kits for the construction Due to the lack of sufficient knowledge of digital devices. The ability of the Arduino about the MeArm’s code, we were unable has enabled the company to design kits that to tell the MeArm to move to a specific are able to build interactive objects that can place and/or location and that limited the sense and control the physical world. Due MeArm’s movements. We wanted to take it to the wide availability of its software and beyond our limited knowledge and enable hardware, the company has successfully the MeArm to move in way that would allow established a project and user community it to draw beautiful images on paper. for those in the electronic, engineering and As the MeArm had been around for a while product/industrial design industry. as an open-source project, many other inWe started out by looking at some example dividuals had begun developing their own Arduino codes online that were created by MeArm and sharing the information online. Phenoptix, the producer of MeArm, as we wanted to gain a better understanding of the hardware before moving forward. Over time, we began to install Arduino libraries created by other parties and were able to include them in our own code. One of the first few codes we tried out was one that told the MeArm to sweep left and right, up and down, and had the claw open and close which is also a standard procedure to ensure all four servos are working properly. It was our first attempt at exploring the MeArm’s movement and how we could

One of the many projects we found was of the MeArm being controlled using sensor camera. Although it looked fairly simple, we realized that we needed to have a deeper understanding of the servos’ angles in order to tell the MeArm where to move to apart from being financially impossible to get ourselves sensor camera.

We also worked with Rhinoceros and Meshlab to develop the 3D prints of the new claw and the housing for the hardware. Enlisted software has aided us to create peculiar objects, intended to keep people wondering on the whole project. We used Rhinoceros and Grasshopper to create the model, 3D Coat suggests different viable materials and Meshlab is used to test strength of produced mesh since minimum thickness can go as low as 0.7mm.



Right: Zachary Schoch, 2011. A structure made using robotic arm. Below: Zachary Schoch, 2011. A structure made using robotic arm.

Architectural Hypothesis The most exciting aspect of this project is the collaborative effort between the MeArm and the two stepper motors. With the MeArm acting as the clueless client and the stepper motors acting as the experienced architect, it is very similar to having two polar opposite architects attempting to work on the same project together. Despite the Arduino’s versatility, it is quite hard to imagine it as a viable tool in creating architecture. Though it might help in creating concepts and design ideas, it is best used in creating projects that make use of electronics and robotics. But with the rapid growth of technology, the Arduino might one day be able to develop and expand architectural objects. Since the Arduino is capable of powering stepper motors that can eventually produce accurate drawings, it would be great if the Arduino could power a drawing tool that produces detailed construction drawings, so that architects and designers would be able to print out their drawings in real time. We intend to combine the individual codes for the MeArm and stepper motors into one merged code. With both loops running at the same time, the two robots will be able to function simultaneously and fulfil the intended collaboration.

With this approach, it just might be possible for the MeArm to draw clumsy loops on a roll of paper that will be rotated constantly by one stepper motor, and the other motor would be the experienced architect adding in perfect lines/curves to refine the MeArm’s initial drawing.



Left: Initial 3d exploration using Grasshopper + Rhino + Meshlab Right: Section of 3d structure

Initial Explorations Since the four servos of the MeArm need to be powered by the Arduino board, we started off by identifying poles and pins before referring to several servo fritzing diagrams. Once the servos were connected to the breadboard and Arduino via jumper wires, we began to look at example Arduino codes for running the MeArm. As mentioned before, the first code we explored was only able to produce basic movements for the MeArm that were not capable of producing any drawings. The next code we needed to build was for the stepper motors. The examples we found online looked simple enough but much like the MeArm, we had to understand the wiring and hardware before we could move forward. Since we had a motor shield on hand, we soldered pin heads to the shield and stacked it on top of the Arduino before running some stepper tests.

We managed to unite Arduino with WiFi shield which lead us to accessing our Twitter account. As we were trying to enable MeArm to fetch tweets, the code started to get complicated and beyond our knowledge ability. As time passes, our aim kept changing yet it gets more interesting. We almost forgot we started off with plain zero knowledge in coding and making a drawbot. Until week 10, we made our mind to build a drawbot made up of MeArm and two stepper motors which we already had since week 2. Witnessing MeArm and stepper motors move simultaneously is a form of satisfaction for both of us. The exploration of 3D forms for the housing and claw began using a manipulated sphere, tweaked, pulled, pinched and stretched to come up a shell to fit in Arduino, breadboard and motorshield. Holes are punched on the shell surface for jumper wires. A new claw is also designed because existing claw is not able to hold pen properly. We initiate our claw design using paper clay experimenting with shapes and sizes to achieve the most stable and has strongest grip. A pen holder permanently attached to the claw is believed to be the best design.


Left: Arduino Mega 2560 Right: Assembling servo to MeArm base Bottom: Testing and debugging each servo


Top: Details of gear to move paper roll and pen holder Below: Details of wiring and stacking motorshield + Arduino

Implementation The main technical ambition of this project is to have an Arduino sketch/code that effectively runs the MeArm and the two stepper motors simultaneously. This means that the Arduino board needs to have a motor shield stacked on top of it, and doing this requires two separate power supplies and lots of jumper wires. A breakdown of the hardware used for this project includes the following:- MeArm - Servos (x4) - 12V 200x Stepper Motors (x2) - Arduino Mega 2560 R3 board (x2) - Adafruit Motor Shield v2.3 - Breadboard - Stepper motor (x2) Jumper wires - USB cable - 6V battery pack (for the Arduino) - 12V battery pack (for motor shield) - AA 1.5V battery (x14) The current code runs on a loop, with angles, rotations, speed and acceleration specified in the ‘setup’. It also relies heavily on codes derived from examples included in Adafruit’s Stepper Motor Library as well as Arduino’s own Servo library.

Each servo of the MeArm is connected to pins 1 through 4 on the PWM side of the Arduino board, and the stepper motors are connected to terminal port #1 (M1 and m2) and terminal port #2 (M3 and M4) respectively. In terms of power, the board is powered up by a 9V battery pack that consists of four AA batteries measuring at 1.5V each, and the shield is running on a 12V battery pack with the same AA batteries. This seemingly high voltage for a small robot is necessary for the stepper motors to run. Referring to a code provided in stepper motor library, we began to explore and experiment with different speed, delay, acceleration and rotation direction. While for MeArm, we had referred to a code that makes MeArm to write ‘ARDUINO’ and draw infinity sign. We work our way from these codes. During the whole coding process, we rely on imaginary Cartesian plane to locate coordinate of movement points. Meshlab is used solely on predicting strength of new claw as well as an object to case all the electronic parts.



Top: Testing RGB LED using Ethernet shield Bottom: Writing ‘ARDUINO’ using MeArm

Learning Arduino/Processing Building up the code with little to no prior knowledge of coding was a tough challenge. Phenoptix, Github, Instructables, and Adafruit were the key online tutors in our learning process and we owe much of our progress to them. The instructions provided were a little hard to understand in the beginning, but they soon became a huge help as we explored the tools first-hand. If we were to pass this project to other students we would suggest them to make best use of mentioned online tutorials as they are a bunch of generous and kind people, of whom always willing to provide assistance. One of the first codes we came across was one for servos. In the examples, we began to understand how the servo could move from between 0 to 360 degrees, and each limit set determined how far the servo would move from its beginning angle. This example was an effective tool in understanding the basis of servo movement, but we needed something more elaborate to help define intuitive movement that could eventually produce a drawing. We also explored the examples provided in Adafruit’s Stepper Motor Library, where we began to understand that our stepper motors at hand turn 200 steps per revolution, at 1.8 degrees per step. We learned how to specify the direction of the turn, as well as its speed and revolution. As simple as the example was, it was more than enough for us to create the ‘experienced architect’ robot.

The first approach -after all four servos are proven to be functioning properly- was to control MeArm by hacking Arduino using Processing and control its movement using mouse control. It was somehow a mysterious failed attempt even everything (baud rate, COM port, board selection, etc.) is checked in place. After looking at the examples and trying to expand them, the code with the most design potential is the one for multi stepper motors. In this code, we are able to control multiple stepper motors simultaneously, with each stepper motor being run on a different setup. This functionality, coupled with the stepper motors’ incredible accuracy, have resulted in numerous drawings of outstanding quality, as evidenced by multiple videos of ‘drawbots’ run by stepper motors.



Elevations MeArm elevations



Left. :Photo of Prototype CNC in progress Below. Photos of Electronic component testing

The Algorithm The initial plan was to have a single Arduino board power the MeArm and the two stepper motors, with one merged code running everything together. Unfortunately, we ran into some difficulties and have decided upon using two separate boards for the MeArm and stepper motors respectively. MeArm This code runs on the Servo library and the first section specifies which pins the servos are connected to, their beginning angles, as well as their names: Amotor (claw), Bmotor (base), Cmotor (right arm), Dmotor (left arm). In the ‘setup’, we specified the delays for each servo, where we tell them specifically when to move and when to stop. The following ‘movetopoint’ function is an instruction for the base, and the ‘penup’ function is to tell the servos how to lift the pen away from the surface of the paper roll. Before we could tell the MeArm what to draw, we first had to determine how we would instruct the MeArm to move. By using the x and y coordinates, we were able to determine both the starting and ending point of each line and/or curve. The following setups; labelled as ‘drawHeart’, ‘drawArduino’ etc, are specific functions that tell the MeArm what to draw. In the screenshots shown, the x and y coordinates of the servos are specified for each drawing instruction.

Lastly, the loop determines which function or drawing we want the MeArm to perform on paper. In this screenshot shown, only the ‘drawArduino’ and ‘drawinfinity’ functions are in loop. Stepper Motors This code runs on a few libraries: ‘AccelStepper’, ‘Wire’ and ‘Adafruit_MotorShield’. The first section specifies the address of the two stepper motors, their steps per revolution, as well as which ports they are connected to. In this case, the stepper motor that moves the pen is at port 1, and the stepper motor that turns the paper roll is at port 2. Before we could move on to the setup, we had to specify the turn direction and the step type. The turn directions alternate between forward (clockwise) and backward (counter-clockwise), and the ‘steptype’ ‘microstep’ is applied to both steppers as it has little vibrations and provides steady rotations. In the ‘setup’, we specified the speed, acceleration and turn angle. For example, stepper1 has a speed of 200 and an acceleration of 100. It’s destination is 100, which means it will turn for 100 degrees forward before moving backwards for another 100 degrees. The ‘loop’ function is a simple one that just runs what has already been specified in the ‘setup’ function’.



Prototype The following images show testings of the MeArm and the stepper motors drawing out their lines and/or curves. Before we arrived at the current angles for the MeArm, the lines drawn were rather messy and illegible, but now they’re rather crisp and clear. As for the stepper motors, it just took a bit of experimentation with the turn angles and speed to reach the ideal setup.


Conclusion Through the weeks of research and experimentation, we were able to run an effective code for both the MeArm and the stepper motors. It took a lot of patience and understanding of the codes and their functions, and we had to have a lot of patience to make the project come to fruition.

forward to successfully grabbing and receiving strings of texts from tweets sent in by Twitter users, but due to our very limited expertise, abundantly unexplored libraries and a lack of time, we couldn’t complete that part of the project.

Not only were we able to configure the hardware and make it work, but we were also able to package it into a possible product. We designed a mini table that acts as a storage space for the hardware and the paper roll; a new 3D printed pen holder for the MeArm made from laser sintered nylon, as well as an operable housing for the boards and wires, also 3D printed. Though we started off with a strong idea and proposition, it felt like a huge undertaking when we began to take a good look at the hardware required for our project. The unexpected complexity was overwhelming and difficult, which is interesting because in architecture we deal with projects on a much bigger scale as compared to robots controlled by chipboard. One of the limiting factors that resulted in the lack of Twitter users able to send in drawing instructions through their tweets was the time spent on developing the design intent. When the semester first started, we had only intended to have the MeArm as a drawing assistant and it wasn’t until mid-semester where the ‘Twitter-controlled collaborative drawing project’ was suggested to us. We had really looked

Looking back at what we’ve developed from the base examples we’ve referred to, it amazes us to see the progress we’ve been able to make throughout the semester. We were able to edit the necessary functions and setups to suit the requirements of our project, and made it work.


Left. : Image of Experiment 1 with single material Below. Photos of Testing Prototype

Refinement If we could refine the project and take it to another level, we would implement the idea of having a Twitter-controlled drawing machine. In the second half of the semester, we had purchased a CC3000 WiFi shield, which was unfortunately not compatible with a number of Arduino WiFi projects we found online as a majority of them required the official WiFi shield, which was too costly for our budget. With the right library, we could establish a connection to Twitter and instruct online users on how they could instruct the MeArm to move via their own tweets. The tweets for the MeArm could be specified with a hashtag and the MeArm would effectively act upon those instructions.




Observed Qualities The performance of mesh design is given more attention despite its simplicity. Clean and neat 3D objects proven to have better performance to house the intended electronic boards


Opposite page: Iterations of 3d print casing

Selection Criteria (3D print) The final selection of 3D prints is judged upon its ability to perform the intended functions. Our final prints are expected to be able to hold pen firmly and cage our boards and delicate wiring neatly. This cage could also sit steadily on flat surface and will provide so much ease in terms of mobility. Our previous 3D print iteration happens to be a bit small to chug in Arduino board together with breadboard and battery pack. The housing appears to be a geodesic dome but with careful process, the housing design is operable without involving much more screws and nuts. Shapeways has tonnes of material ranging from nylon to rose gold. We opt for the most basic material since its durability is enough for our envisioned function aside from it being the cheapest on the list. This material is so strong even wall thickness is only 0.7mm and it is amazingly lightweight.



Right: Sandy Noble, 2012. Abe Polygraph

Discussion In the end of this semester, we have come up with a complex drawbot working with each other but producing contrasting line work qualities. Curating these line works could help architects with conceptual ideas or explaining the clientdesigners relationship.

and using walkers as input instead of running in pre-written code. The most significant obstacles we faced along the semester are to provide the right library using boards and shields we own. We had spent greater portion of time to figure out library rather than writing our own strings of code. We are quite confident if we have more time without any other commitments running aside, we definitely could produce more versatile code.

Given our drawbot be placed in an environment where more MeArm or stepper motor, more complex outcome is expected. Having MeArm to draw various kinds of line or shapes, the produced drawing would have more ‘looseness’ in As we had managed to step a foot in internet, we quality. figured we might go further than just changing If the semester runs longer and more time could colour of RGB LED. For instance, telling coordibe devoted to code, this project could be con- nates to MeArm as well as z-axis to control pen trolled via Twitter or other social media as en- or brush pressure. visioned earlier. Another way to improvise this project is to integrate Processing with Arduino



Appendix



Mesh experiment_01 Unnecessarily complex voxel



Mesh experiment_02 Unnecessarily complex voxel



Mesh experiment_03 Final selection for 3d print based on its stability and available void



Sweep servo

Software experiments

//QUADSweep //edited from the original code by BARRAGAN #include “Servo.h” Servo myservo; // create servo object to control a servo, a maximum of eight servo objects can be created Servo mysecondservo; // servo 2 Servo mythirdservo; // servo3 Servo myfourthservo; // servo4 int pos = 0; // variable to store the servo position void setup() { myservo.attach(10); // attaches the servo on pin 9 to the servo object mysecondservo.attach(11); // attaches the servo on pin 10 to the servo object mythirdservo.attach(12); // attaches the servo on pin 8 to the servo object myfourthservo.attach(13); // attaches the servo on pin 11 to the servo object } void loop() { for(pos = 30; pos < 140; pos += 1) // goes from 0 degrees to 90 degrees in steps of 1 degree

{ { myservo.write(pos); // tell servo to go to position in variable ‘pos’ mythirdservo.write(pos); // tell servo to go to position in variable ‘pos’ delay(40); // waits 40ms for the servo to reach the position } { mysecondservo.write(pos); // tell servo to go to position in variable ‘pos’ myfourthservo.write(pos); // tell servo to go to position in variable ‘pos’ delay(10); } } for(pos = 90; pos>=130; pos-=1) // goes from 90 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable ‘pos’ mythirdservo.write(pos); // tell servo to go to position in variable ‘pos’ delay(40); // waits 40ms for the servo to reach the position } for(pos = 90; pos>=130; pos-=1) // goes from 90 degrees to 0 degrees { mysecondservo.write(pos); // tell servo to go to position in variable ‘pos’ myfourthservo.write(pos); // tell

servo to go to position in variable ‘pos’ delay(10); // waits 10ms for the servo to reach the position } }


1 SERVO /* Sweep by BARRAGAN <http://barraganstudio.com> Adapted by Philip van Allen <philvanallen. com> for the VarSpeedServo.h library (October 2013) This example code is in the public domain Sweep a servo back and forth from 0-180 degrees, 180-0 degrees Uses the wait feature of the 2013 version of VarSpeedServo to stop the code until the servo finishes moving Note that servos usually require more power than is available from the USB port - use an external power supply! */ #include <VarSpeedServo.h> VarSpeedServo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created const int servoPin =9; void setup() { myservo.attach(servoPin); // attaches the

servo on pin 9 to the servo object myservo.write(0,255,true); // set the intial position of the servo, as fast as possible, wait until done } void loop() { myservo.write(180,255,true); // move the servo to 180, max speed, wait until done // write(degrees 0-180, speed 1-255, wait to complete truefalse) myservo.write(0,30,true); // move the servo to 180, slow speed, wait until done }


Mouse control through Processing //Processing

import processing.serial.*; int xpos=90; point (0-180) int ypos=90; point (0-180) Serial myPort;

fill(255, 0, 0); //rgb value so RED rect(180, 175, mouseX-180, 10); //xpos, //set x servo’s value to mid ypos, width, height fill(0, 255, 0); // and GREEN //set y servo’s value to mid rect(175, 180, 10, mouseY-180); update(mouseX, mouseY); // Create object from Serial class }

void setup() { size(900, 900); //make our canvas 200 x 200 pixels big frameRate(100); String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port myPort = new Serial(this, portName, 9600); } void draw() { if (mousePressed == true) { //if we clicked in the window myPort.write(‘1’); //send a 1 println(“haiSheep”); } else { //otherwise myPort.write(‘0’); //send a 0 } fill(0); rect(0, 0, 360, 360);

void update(int x, int y) { //Calculate servo postion from mouseX xpos= x/2; ypos = y/2; //Output the servo position ( from 0 to 180) myPort.write(xpos+”x”); myPort.write(ypos+”y”); }


Mouse control through Processing //Arduino

import processing.serial.*; int xpos=90; //set x servo’s value to mid point (0-180) int ypos=90; //set y servo’s value to mid point (0-180) Serial myPort; // Create object from Serial class void setup() { size(900, 900); //make our canvas 200 x 200 pixels big frameRate(100); String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port myPort = new Serial(this, portName, 9600); }

void draw() { if (mousePressed == true) { //if we clicked in the window myPort.write(‘1’); //send a 1 println(“haiSheep”); } else { //otherwise myPort.write(‘0’); //send a 0 }

fill(0); rect(0, 0, 360, 360); fill(255, 0, 0); //rgb value so RED rect(180, 175, mouseX-180, 10); //xpos, ypos, width, height fill(0, 255, 0); // and GREEN rect(175, 180, 10, mouseY-180); update(mouseX, mouseY); } void update(int x, int y) { //Calculate servo postion from mouseX xpos= x/2; ypos = y/2; //Output the servo position ( from 0 to 180) myPort.write(xpos+”x”);

Mouse control through Processing //Arduino-3servos

myPort.write(ypos+”y”); } #include <Servo.h> Servo yservo; Servo xservo; //set initial values for x and y int ypos = 0; int xpos = 0;

void setup() { xservo.attach(10); //(analog pin 0) for the x servo yservo.attach(11); //(analog pin 1) for the y server Serial.begin(9600); // 19200 is the rate of communication Serial.println(“Rolling”); // some output for debug purposes. } void loop() { static int v = 0; // value to be sent to the servo (0-180) if ( Serial.available()) { char ch = Serial.read(); // read in a character from the serial port and assign to ch switch (ch) { // switch based on the value of ch case ‘0’...’9’: // if it’s numeric* v = v * 10 + ch - ‘0’; /* so if the chars sent are 45x (turn x servo to 45 degs).. v is the value we want to send to the servo and it is currently 0 The first char (ch) is 4 so 0*10 = 0 + 4 - 0 = 4; Second char is 4; 4*10 = 40 + 5 = 45 - 0 = 45; Third char is not a number(0-9) so we drop through... */ break; case ‘x’: // if it’s x /* ....and land here where we send the value of v which is now 45 to the x servo and then reset v to 0 */ xservo.write(v); v = 0; break; case ‘y’: yservo.write(v); v = 0; break; } } }


RGB LED



Writing ARDUINO

#define AmotorPin 1 #define BmotorPin 2 #define CmotorPin 3 #define DmotorPin 4 int A_angle = 100; // Claw int B_angle = 84; // Base 84 int C_angle = 80; // Right arm 60 int D_angle = 110; // Left arm int mode = 0; int Bcycle = 150; int rot = 1; int x0 = 20; int y0 = 120; int z0 = 160; int x1 = 20; int y1 = 120; int z1 = 160; bool pendown = false;

Bmotor.write(30); delay(150); Dmotor.attach(DmotorPin); Dmotor.write(D_angle); motormove(4, D_angle, 160); delay(150); motormove(3,110,60); motormove(4,103,110); motormove(2,140,20);

void setup() { Amotor.attach(AmotorPin); Amotor.write(A_angle); delay(150); Cmotor.attach(CmotorPin); Cmotor.write(C_angle); delay(150); Bmotor.attach(BmotorPin);

//4 //3 //4 //2

} void movetopoint(int x, int y) { z1 = 106 + (x - 126); motormove(2, y0, y); //2 motormove(3, x0, x); //3 if(x<122)z1=90; if (pendown) { motormove(4, z0, z1); //4 z0 = z1; } y0 = y; x0 = x;

#include <Servo.h> Servo Amotor; Servo Cmotor; Servo Bmotor; Servo Dmotor;

movetopoint(x, y);

Cmotor.attach(CmotorPin); Cmotor.write(C_angle); delay(150); Bmotor.attach(BmotorPin); Bmotor.write(30); delay(150); Dmotor.attach(DmotorPin); Dmotor.write(D_angle); motormove(4, D_angle, 160); delay(150); motormove(3,110,60); motormove(4,103,110); motormove(2,140,20);

if (xx > x) { #define AmotorPin 1 #define BmotorPin 2 #define CmotorPin 3 #define DmotorPin 4 int A_angle = 100; // Claw int B_angle = 84; // Base int C_angle = 60; // Right arm int D_angle = 110; // Left arm int mode = 0;

//4 //3 //4 //2

} int Bcycle = 150; int rot = 1; int x0 = 20; int y0 = 120; int z0 = 160; int x1 = 20; int y1 = 120; int z1 = 160; bool pendown = false;

}

void movetopoint(int x, int y) { z1 = 106 + (x - 126); motormove(2, y0, y); //2 motormove(3, x0, x); //3 if(x<122)z1=90; if (pendown) { motormove(4, z0, z1); //4 z0 = z1; }

#include <Servo.h> void penup() { motormove(4, z0, 160); motormove(3, x0, 60);

//4 //3

x0 = 100; z0 = 160; pendown = false; } void drawline(int x, int y, int xx, int yy) { pendown = true; // x0=x;y0=y;

Servo Amotor; Servo Cmotor; Servo Bmotor; Servo Dmotor;

void setup() { Amotor.attach(AmotorPin); Amotor.write(A_angle); delay(150);

y0 = y; x0 = x; }

void penup() { motormove(4, z0, 160); motormove(3, x0, 60); x0 = 100; z0 = 160;

//4 //3


pendown = false;

pendown=true; movetopoint(140,44); // movetopoint(147,41); void drawline(int x, int y, int xx, int yy) { movetopoint(147,46); pendown = true; movetopoint(152,47); // x0=x;y0=y; movetopoint(152,49); movetopoint(x, y); movetopoint(152,50); movetopoint(150,51); if (xx > x) { movetopoint(147,52); float dy = (float)(yy - y) / (xx - x); movetopoint(144,53); for (int i = x; i < xx; i++) { movetopoint(145,54); movetopoint(i, y + dy * (i - x)); movetopoint(142,53); } drawline(142,53,132,49); } drawline(132,49,124,44); else if (xx < x) { // movetopoint(126,40); float dy = (float)(yy - y) / (xx - x); drawline(124,44,140,34); for (int i = x; i > xx; i--) { // movetopoint(140,26); movetopoint(i, y + dy * (i - x)); drawline(140,36,145,38); } // movetopoint(145,28); } // movetopoint(146,27); else { // movetopoint(148,35); if(y<yy){ // movetopoint(149,31); for(int i=y;i<yy;i++){ drawline(145,38,153,42); movetopoint(x,i); movetopoint(153,44); } movetopoint(153,45); } drawline(153,46,138,48); else{ // movetopoint(149,37); for(int i=y;i>yy;i--){ // movetopoint(148,38); movetopoint(x,i); // movetopoint(146,39); } // movetopoint(138,43); } penup(); } } void loop() { } motormove(4,110,160); //drawHELLO(); // drawALING(); void drawHeart(){ drawHeart(); }

//drawHeart(); // drawArduino(); penup(); //drawinfinity(); //motormove(4,134,160); //motormove(3,150,60); // motormove(2,140,20); delay(2000);

} } else { switch (motor) { case 1: for (int i = st; i >= ed; i--) { Amotor.write(i); delay(20); } break; case 2: for (int i = st; i >= ed; i--) { Bmotor.write(i); delay(20); } break; case 3: for (int i = st; i >= ed; i--) { Cmotor.write(i); delay(20); } break; case 4: for (int i = st; i >= ed; i--) { Dmotor.write(i); delay(20); } break; } }

} void motormove(int motor, int st, int ed) { if (st < ed) { switch (motor) { case 1: for (int i = st; i <= ed; i++) { Amotor.write(i); delay(20); } break; case 2: for (int i = st; i <= ed; i++) { Bmotor.write(i); delay(20); } break; case 3: for (int i = st; i <= ed; i++) { Cmotor.write(i); delay(20); } break; case 4: for (int i = st; i <= ed; i++) { Dmotor.write(i); delay(20); } break;

}


Final code

z0 = z1; /*-----( Import needed libraries )-----*/ /*--- MEARM LIBRARY ---*/ #include <Servo.h> /*--- STEPPER MOTOR LIBRARY ---*/ #include <AccelStepper.h> #include <Wire.h> #include <Adafruit_MotorShield.h> #include “utility/Adafruit_ PWMServoDriver.h” Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers //Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200, 1); //spr, port # //Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);

/*-----( Declare Constants and Pin Numbers )-----*/ /*--- MEARM PIN NUMBERS ---*/ #define AmotorPin 1 #define BmotorPin 2 #define CmotorPin 3 #define DmotorPin 4

int mode = 0;

void setup() /****** SETUP: RUNS ONCE ******/ int Bcycle = 150; { int rot = 1; /*--- MEARM SETUP ---*/ Amotor.attach(AmotorPin); int x0 = 20; Amotor.write(A_angle); int y0 = 120; delay(150); int z0 = 160; Cmotor.attach(CmotorPin); int x1 = 20; Cmotor.write(C_angle); int y1 = 120; delay(150); int z1 = 160; Bmotor.attach(BmotorPin); bool pendown = false; Bmotor.write(30); delay(150); /*--- STEPPER MOTOR OBJECTS ---*/ Dmotor.attach(DmotorPin); void forwardstep1() { Dmotor.write(D_angle); myStepper1->onestep(FORWARD, motormove(4, D_angle, 160); //4 MICROSTEP); delay(150); } motormove(3,110,60); //3 void backwardstep1() { motormove(4,103,110); //4 myStepper1->onestep(BACKWARD, motormove(2,140,20); //2 MICROSTEP); } /*--- STEPPER MOTOR SETUP ---*/ // wrappers for the second motor! //AFMSbot.begin(); // Start the bottom void forwardstep2() { shield myStepper2->onestep(FORWARD, AFMStop.begin(); // Start the top shield MICROSTEP); } stepper1.setMaxSpeed(200.0); void backwardstep2() { stepper1.setAcceleration(100.0); myStepper2->onestep(BACKWARD, //stepper1.setSpeed(50); MICROSTEP); stepper1.moveTo(100); //stepper will } move forward and backward with 24

/*--- STEPPER MOTOR CONSTANTS /*-----( Declare Variables )-----*/ ---*/ Adafruit_StepperMotor *myStepper1 = /*--- MEARM VARIABLES ---*/ AFMStop.getStepper(200, 1); //spr, port # Servo Amotor; Adafruit_StepperMotor *myStepper2 = Servo Cmotor; AFMStop.getStepper(200, 2); Servo Bmotor; Servo Dmotor; /*-----( Declare objects )-----*/ /*--- MEARM OBJECTS ---*/ //specify mearm servo angles int A_angle = 90; // Claw int B_angle = 64; // Base 64 int C_angle = 40; // Right arm 40 int D_angle = 110; // Left arm 110

stepper2.setMaxSpeed(300.0); stepper2.setAcceleration(10.0); //stepper1.setSpeed(50); stepper2.moveTo(1000000); //ideal speed for paper roll } //--(end setup )---

} y0 = y; x0 = x; }

void penup() { motormove(4, z0, 160); motormove(3, x0, 60);

//4 //3

x0 = 100; z0 = 160; pendown = false; } void drawline(int x, int y, int xx, int yy) { pendown = true; // x0=x;y0=y; movetopoint(x, y); if (xx > x) { float dy = (float)(yy - y) / (xx - x); for (int i = x; i < xx; i++) { movetopoint(i, y + dy * (i - x)); } } else if (xx < x) { float dy = (float)(yy - y) / (xx - x); for (int i = x; i > xx; i--) { movetopoint(i, y + dy * (i - x)); } } else { if(y<yy){ for(int i=y;i<yy;i++){ movetopoint(x,i); } } else{ for(int i=y;i>yy;i--){ movetopoint(x,i); } }

/****** THE FOLLOWING ARE SETUPS FOR /*--- STEPPER MOTOR VARIABLES ---*/ THE MEARM ******/ AccelStepper stepper1(forwardstep1, void movetopoint(int x, int y) { backwardstep1); z1 = 106 + (x - 126); AccelStepper stepper2(forwardstep2, motormove(2, y0, y); //2 backwardstep2); motormove(3, x0, x); //3 if(x<122)z1=90; } /*-------------------------*/ if (pendown) { motormove(4, z0, z1); //4 }


void drawArduino(){ //A penup(); drawline(170,116,110,121); //x,y,xx,yy //drawline(110,121,126,126); penup(); drawline(170,116,110,110); //drawline(110,110,124,110); penup(); drawline(130,120,130,109); penup(); //r drawline(140,106,106,106); //drawline(127,106,138,106); penup(); drawline(135,106,135,97); penup(); //d drawline(150,96,107,96); penup(); drawline(130,96,130,106); drawline(130,106,109,104); drawline(109,104,109,91); penup(); //u drawline(138,92,107,94); drawline(107,94,107,86); drawline(107,86,138,88); //drawline(146,90,107,83); penup(); //i drawline(138,80,107,80); penup(); drawline(144,81,142,81); penup(); //n drawline(140,75,107,75); drawline(107,75,143,77); drawline(143,77,142,67); drawline(142,67,107,68); penup(); //o drawline(138,63,107,65); //i drawline(107,65,107,57); //-> drawline(107,57,145,60); //i drawline(145,60,138,70); //<// penup(); }

void drawinfinity(){ drawline(153,51,145,58); drawline(145,58,135,58); drawline(135,58,126,55); drawline(126,55,126,48); drawline(126,48,155,32); drawline(155,32,155,28); drawline(155,28,135,23); drawline(135,23,126,28); drawline(126,28,123,40); drawline(123,40,153,53); drawline(153,53,153,58); penup(); drawline(138,53,134,39); penup(); drawline(144,51,128,52); penup(); drawline(135,38,135,25);

} break; case 3: for (int i = st; i >= ed; i--) { Cmotor.write(i); delay(20); } break; case 4: for (int i = st; i >= ed; i--) { Dmotor.write(i); delay(20); } break;

} //--(end main loop )--/*-----( Declare User-written Functions )-----*/ /****** THE FOLLOWING ARE FUNCTIONS FOR THE MEARM ******/

void motormove(int motor, int st, int ed) { if (st < ed) { switch (motor) { case 1: for (int i = st; i <= ed; i++) { Amotor.write(i); delay(20); } break; case 2: for (int i = st; i <= ed; i++) { } Bmotor.write(i); delay(20); void loop() /****** LOOP: RUNS CONSTANTLY } ******/ break; { case 3: for (int i = st; i <= ed; i++) { /*--- MEARM LOOP ---*/ Cmotor.write(i); delay(20); motormove(4,110,160); //what to write/draw } drawArduino(); break; penup(); case 4: drawinfinity(); for (int i = st; i <= ed; i++) { motormove(4,134,160); Dmotor.write(i); motormove(3,150,60); delay(20); motormove(2,140,20); } delay(1000); break; } /*--- STEPPER MOTOR LOOP ---*/ } // Change direction at the limits else { for(int i =0;i<200;i++){ switch (motor) { if (stepper1.distanceToGo() == 0) case 1: stepper1.moveTo(-stepper1.curfor (int i = st; i >= ed; i--) { rentPosition()); Amotor.write(i); delay(20); if (stepper2.distanceToGo() == 0) } stepper2.moveTo(-stepper2.curbreak; rentPosition()); case 2: for (int i = st; i >= ed; i--) { stepper1.run(); Bmotor.write(i); stepper2.run(); delay(20); }

} } }

//*********( THE END )***********


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.