Skip to content

15. Mechanical Design

For Group work, see: https://fabacademy.org/2020/labs/oulu/machine_projects/Team2/

Roles and responsibilities

  • Zhengya: Designing the drawing box and files for laser cutter, laser cutting
  • Xinhui: Laser cutting, assembling of the cut parts, 3D printing (designing and printing of the gears)
  • Noora: Documentation, making and updating the project page, designing the pen holder
  • Yazan: Coding, putting the whole thing together, testing and a short reflection.
  • Tatiana: Making components list, design and printing of the pen holder, assembling

Individual Work

After putting the whole thing together, and making sure that parts are in place … using some glue magic … it is time to get the machine to actually work.

Code

The code was written from scratch. The code uses Arduino Servo Library by including ‘#include ‘.

The library Allows Arduino/Genuino boards to control a variety of servo motors. It can control a great number of servos. It makes careful use of timers: the library can control 12 servos using only 1 timer.

See Also, Servo - attach().

Attaches the Servo variable to a pin.

Syntax:

  • servo.attach(pin)
  • servo.attach(pin, min, max)

Parameters:

  • servo: a variable of type Servo
  • pin: the number of the pin that the servo is attached to
  • min (optional): the pulse width, in microseconds, corresponding to the minimum (0-degree) angle on the servo (defaults to 544)
  • max (optional): the pulse width, in microseconds, corresponding to the maximum (180-degree) angle on the servo (defaults to 2400)

See Also, Servo - write()

Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement).

Syntax:

  • servo.write(angle)

Parameters:

  • servo: a variable of type Servo
  • angle: the value to write to the servo, from 0 to 180

Demos

The Servos can be connected to the Arduino Uno. Connect the 1st motor to pin2, the 2nd to pin4, and the 3rd to pin6.

Line Drawing

Upload the following sketch. The sketch will draw a line, in loop.

// Author: Yazan Barhoush

#include <Servo.h>

#define Y_MIN_ANGLE 30
#define Y_MAX_ANGLE 150

#define P_MIN_ANGLE 30
#define P_MAX_ANGLE 90

Servo servo_y;
Servo servo_p;

void setup() {
  servo_y.attach(6);
  servo_p.attach(2);
}

void loop() {

  servo_p.write(P_MAX_ANGLE);

  for(int i=Y_MIN_ANGLE; i<=Y_MAX_ANGLE; ++i) {
    servo_y.write(i);
    delay(15);
  }

  for(int i=Y_MAX_ANGLE; i>=Y_MIN_ANGLE; --i) {
    servo_y.write(i);
    delay(15);
  }
}

A video showing the machine drawing one line using servo_y.write()

line-drawing.mp4

Rectangle Drawing

Upload the following sketch. The sketch will draw a rectangle, in loop.

// Author: Yazan Barhoush

#include <Servo.h>

#define Y_MIN_ANGLE 30
#define Y_MAX_ANGLE 150

#define X_MIN_ANGLE 30
#define X_MAX_ANGLE 150

#define P_MIN_ANGLE 30
#define P_MAX_ANGLE 90

Servo servo_y;
Servo servo_x;
Servo servo_p;

void setup() {
  servo_y.attach(6);
  servo_x.attach(4);
  servo_p.attach(2);
}

void loop() {

  servo_p.write(P_MAX_ANGLE);

  for(int i=Y_MIN_ANGLE; i<=Y_MAX_ANGLE; ++i) {
    servo_y.write(i);
    delay(15);
  }

  for(int i=X_MIN_ANGLE; i<=X_MAX_ANGLE; ++i) {
    servo_x.write(i);
    delay(15);
  }

  for(int i=Y_MAX_ANGLE; i>=Y_MIN_ANGLE; --i) {
    servo_y.write(i);
    delay(15);
  }

  for(int i=X_MAX_ANGLE; i>=X_MIN_ANGLE; --i) {
    servo_x.write(i);
    delay(15);
  }
}

A video showing the machine drawing a rectangle using servo_y.write() and servo_x.write()

rect-drawing.mp4

Note

Drawing a circle can also follow the same principle. It can be done by drawing lines or, moving both servos together at the same time. See the “pixelated” image below: circle-drawing

Reflection

Even though this drawing machine satisfies the requirements for this week’s assignment, we did have bigger plans for it. The original idea was to draw more than rectangles within an Arduino Environment, but due to time limitation, we did not reach that stage; such drawing machine would have required an interface program that would allow for COM port communication and image processing capabilities e.g., the desired image would have been “pixelated” then mapped to each of the motors accordingly. Hopefully, we will get back to this after FabAcademy!

Files

https://gitlab.fabcloud.org/academany/fabacademy/2020/labs/oulu/students/yazan-barhoush/-/tree/master/docs/images/week15/code