Task 2: Actuation [Individual Contribution]
For this week, Fab Lab Bali aims to create a Semat Cutter. Semat, local language for bamboo straw is often used to create Canang (balinese offerings) and other Balinese craft. We are in the process of creating Canang Shooter: a stapler made of semat inserts, with the aim to simplify the process for the crafters without resorting to metal staplers that could harm the environment.
A key aspect of this project is providing pre-cut semat to serve as ammunition for the stapler. Therefore, for this assignment, we’re going to use the opportunity to design and build a machine geared towards this purpose, while also being versatile for other tasks beyond cutting semat.
As me & Tafia have limited knowledge of Machines, Eka made the initial sketch, inspired by how Wire Cutters work.
The system of the machine would function this way
Breaking down the function and the components in the sketch
- Rotary encoder will determine the amount of x mm for the Semat to be cut.
- A stepper motor will advance the Semat by x mm, inputted from the rotary encoder
- Once the semat has advanced by x mm, the servo will push the plier to cut the Semat.
Since Eka wass in charge of the automation process, he was working on the rotary encoder + OLED integration for the machine. I was assigned to work on the actuation process. So my job is to work on the
- Advancement Process
- Servo movement
System Diagram
To mimic how rotary encoder works - I use a potentiometer and button. This is the system diagram and Wokwi Simulation
Setting up: NEMA17 Stepper Motor
I highly recommend checking this tutorial to first set up your NEMA17 Stepper Motor
We are using an Arduino UNO as an MCU which has an operating voltage of 5V. Meanwhile the NEMA17 Stepper Motor requires a 12V-24V. The NEMA17 Stepper Motor will require an AC4988 driver which acts as an intermediary between the Arduino and the NEMA 17 stepper motor; providing the necessary current amplification, direction control, and microstepping functionality.
The AC4988 driver has a potentiometer where you can set the motor current limit. We want to do this because exceeding the current limit can overheat the motor windings, potentially damaging the motor or the driver IC.
Follow this tutorial to figure out your stepper motor current limit. I followed the video and set my current limit at 0.49V
Programming
//rotate stepper motor... on button pressed
//precise number of steps
//as defined by potentiometer
//by elaine & rico fa2024 apr7
#include <AccelStepper.h>
#include <Servo.h>
// Stepper motor pins
#define dirPin 5
#define stepPin 2
#define swPin 4
int potPin = A0;
int buttonState = 0;
Servo cutServo; //create instance object of servo class - called cutServo
// Define the stepper motor and the pins that are connected to
AccelStepper stepper1(1, stepPin, dirPin); // (Typeof driver: with 2 pins, STEP, DIR)
unsigned int stepStart = 0; //value will increase for every woire length cut
int stepAdd = 0; //adjust value to get desired wire length
void setup() {
Serial.begin(9600);
// Stepper Motor Parameter
stepper1.setMaxSpeed(1000); // Set maximum speed value for the stepper
stepper1.setAcceleration(500); // Set acceleration value for the stepper
stepper1.setCurrentPosition(0); // Set the current position to 0 steps
cutServo.attach(9);
pinMode (swPin, INPUT);
pinMode (potPin, INPUT);
}
void loop() {
//Grab value from potentiometer
stepAdd = analogRead (potPin);
//stepAdd = x; //insert custom step amount
Serial.println(stepAdd);
//check if button is pressed
buttonState = digitalRead (swPin);
// Move stepper motor the required number of steps in clock-wise direction when button pushed
//for (int i=0; i==qty; i++) { //... comment out next line and use this line when quantity value is received
if (buttonState == HIGH) {
advanceWire();
}
}
//steppermotor function
void advanceWire () {
stepper1.moveTo(stepStart);
stepper1.runToPosition ();
stepStart = stepStart + stepAdd ;
delay (1000);
cutWire();
delay(3000);
}
void cutWire () {
cutServo.write(0);
delay(500);
cutServo.write(90);
delay(500);
cutServo.write(0);
}
advanceWire()
As I mentioned earlier, I was using potentiometer and button to mimic the rotary encoder. The potentiometer controls the stepper motor to rotate a specific number of steps. Pressing the button will trigger the stepper motor to move according to the potentiometer input which signifies the desired length of Semat. This number of steps is determined by the stepAdd variable. Since the motor has to keep on turning from the same position it last was in, we have to create a variable called stepStart which adds the value of potentiometer with the last motor position.
cutWire()
The cutWire() function operates the servo motor to cut the Semat after the Semat has advanced from the Stepper Motor. It rotates the servo to perform the cutting action.
Debugging
As I mentioned earlier in my group assignment reflection… I had a 3 hour late night debugging session with Rico. The code was working in wokwi, however I couldn’t get anything to function irl. I wasn’t so sure which one was the culprit. So this was how I did my debugging process methodically.
Step 1. Unplug Everything.
I tried isolating different components at first because I didn’t want to rewire everything…but I couldn’t find the culprit. Don’t do that. Just unplug. Keep everything clean, let’s start with a fresh slate.
Step 2. Test out each components, one by one
2A. Test out Arduino UNO
Arduino was working just fine as I was able to upload the program into the UNO.
2B. Test out Program
There was no error in the program as shown by Arduino IDE.
2C. Test out just the Button
The button was not working as intended. So let’s debug. This was my first setup. I connected the button to the breadboard power rails. However the reading came out like this.
Check Wires
Let’s check if we have bad wiring. When I test it under the potentiometer - it was showing continuity so my wires are all working just fine
Plug directly to UNO
Instead of using the breadboard power rails, let’s plug the button directly to UNO.
And it worked!
It seemed like the CULPRIT so far is the Breadboard.... So I switched into a different breadboard and could use the button with the power rails
2D. Test out just the Servo
I ran a simple sweep command - the servo is moving. We want to debug the servo before moving into the stepper motor. As an incremental device add to the button…the Servo is a has fewer connections and code to add. Fewer connections and simpler code = easier time debugging if something doesn’t work
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Step 3. Test out Button + Servo
Now let us try to test out two components at once
//code by elaine
#include <Servo.h>
#define swPin 3
int buttonState = 0;
Servo ezServo;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (swPin, INPUT);
ezServo.attach (9);
}
void loop() {
buttonState = digitalRead (swPin);
if (buttonState == HIGH) {
Serial.println("ON");
ezServo.write(90);
delay(500);
} else {
Serial.println("OFF");
ezServo.write(0);
delay(100);
}
}
It works!
Step 4. Test Button + Servo + Stepper (ALL COMPONENTS)
Running the original code - I managed to get everything working. In the video I was using predetermined distance value - hencewhy there was no potentiometer.
Step 5: Figure out the culprit
Faulty Breadboard’s Power Rail
Prototype
Embedding the programming into the prototype - showing functionality of advancewire and cutwire in action