Stitch Counter Bracelet
Indie Lee
Indie Lee
Stitch counter with the power off. It includes an OLED, rotary encoder, push button, and switch.
This project is intended to help me keep track of my stitches while I'm crocheting or knitting. It frees up some brainpower by recording my stitch count so that I don't have to do extra math when counting (like adding if I'm counting by twos, by threes) or try to remember how many stitches I've just counted after getting distracted. The stitch counter has a rotary encoder and push button that help navigate the OLED where I can increase the count and set the count increment.
Close up of stitch counter in use.
Stitch counter without wrist band.
Side view of the stitch counter.
Wearing the stitch counter on my wrist.
In this video, I show how to use the stitch counter while crocheting. The rotary encoder helps me toggle screens and set the count increment. The push button is used to increase the count and when held, can be used to reset the count to 0. When the OLED is turned off then turned back on, the screen returns to home page but the stitch count and count increment are still saved.
Working on debugging, the stitch count would increase without button press. Turns out, something was up with the Arduino Pro Micro board and I switched to an Arduino Feather.
Got all the components in place, just needed to work on the code. Switching to the feather solved debugging issues and ended up suiting my needs better! (a rechargeable battery!)
The mini rotary encoder arrived in the mail and I could swap out the large one I was using as a place holder.
< After everything was up and running, I worked on soldering everything together! A lot of miniaturizing had to happen, and organization of the components in a way that made sense to put on a wearable.
< Unhoused project I presented in the final critique. I attached an elastic fabric band a bit haphazardly, but I was glad to have something put together.
Response to comments: Here is some of the feedback I got when presenting my project!
"I’m curious if the button could be somewhere else so you don’t have to make a cross hand motion."
This was definitely one of the most difficult things I needed to decide when thinking about how I would design this project to be wearable and functional in the specific way I was looking for (I agree). Considering my hand placement and to what extent they are occupied while crocheting/knitting, I thought a bracelet would be the most accessible accessory. I decided on a wearable because if I had the stitch counter off to the side, I might have to make an even larger motion to click the count button. I considered making a ring that just had the count button, and would communicate wirelessly with an arduino off to the side, which would possibly minimize the motion, but using radio modules would have made it difficult to compact into something wearable. I had other options of maybe making the button a foot pedal instead, or making the counter voice activated, but pressing buttons is very fun and I wanted to retain this element. SO, I tried my best to address the button placement but I definitely think it can be improved. One limitation of it being on the right side of the OLED is that when I wear the bracelet on my right hand the buttons are even more out of reach so I would definitely play around with the button placement in future iterations.
"A housing would be nice, and would help keep the switch and inputs from getting moved/damaged, but for a first iteration its already really close to being small enough to use."
100% agree! I hope to come back to this project and work on housing. Obviously I want to actually use this project in my life so I'd love to make it more finished and durable. It would also help to do something about the floating switch.
Self critique pertaining to the project:
I'm pretty happy with how the project came out. It functions how I wanted it to which is great! My goals were to make something that is wearable and can help me count stitches in varying increments. But, I also had secondary goals that I would've loved to address. The biggest one being making housing and the overall presentation of it look cute. The OLED interface now is super simple looking and in the future I want to make it more visually interesting and maybe somehow incorporate the artsy craftsy theme. I'm also interested in incorporating more functions such as saving previous counts as data I can access after resetting the count to 0, and maybe adding a fun aspect to it where the screen becomes animated in some way when I hit a certain count in one "session" (like 100 or 200 stitches). I learned a lot from this project though so I'm happy with my first iteration.
What you learned about your own abilities and/or limitations:
There is so much to learn about coding and I definitely felt limited by my ability. I do like the learning process that comes with using new components but it is frustrating sometimes when I have a bug and the solution is super simple. Next time I would be less hesitant to use AI to help with my code but I think either way the process would be enjoyable.
Next steps:
Before building another iteration, I hope that I can finish this one! As mentioned above, I would add housing and work on the interface. In a future iteration, I might try to miniaturize the project even more but this will have to take more planning about which components to use. Based on my experience with my first iteration, I would make sure to consider how my components would fit together after soldering too.
/*
Project 2: Stitch Counter
60-223 Intro to Physical Computing
Indie Lee
This code is written for an electronic stitch counter, designed to help me
keep track of my stitches while knitting and crocheting. In these kinds of
projects, I often count in large increments to make counting how many stitches
I have in one row a lot faster, but I also often lose count! This project both
keeps track of my stitch count and enables me to count my stitches in
customizable increments.
This code was written by me, with support from component libraries, Joseph,
and ChatGPT.
Pin mapping:
Arduino pin | role | description
-------------------------------------
0 INT rotary encoder
1 INT rotary encoder
2 I2C OLED
3 I2C OLED
11 input rotary encoder button
12 input push button
13 input switch
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Encoder.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
const int SWITCHPIN = 13,
BUTTONPIN = 12,
ROTARYPIN = 11;
int screenstate = 0;
int stitchCount = 0;
int countInc = 1;
int buttonVal, switchVal, rotaryVal;
int lastButtonVal, lastRotaryVal;
unsigned long pressTime = 0;
const unsigned long holdTime = 1000;
Encoder myEnc(0, 1);
long oldPosition = 0;
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
pinMode(BUTTONPIN, INPUT_PULLUP);
pinMode(SWITCHPIN, INPUT_PULLUP);
pinMode(ROTARYPIN, INPUT_PULLUP);
lastButtonVal = digitalRead(BUTTONPIN);
lastRotaryVal = digitalRead(ROTARYPIN);
//OLED screen setup
Serial.begin(9600);
// Wait for display
delay(500);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
homescreen();
}
void loop() {
buttonVal = digitalRead(BUTTONPIN);
switchVal = digitalRead(SWITCHPIN);
rotaryVal = digitalRead(ROTARYPIN);
if (switchVal == LOW) {
display.ssd1306_command(SSD1306_DISPLAYON);
//turning the rotary encoder
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
newPosition = (newPosition / 2);
}
//SCREENSTATE 0
if (screenstate == 0) homescreen();
//turning the rotary encoder to toggle screen
if (newPosition != oldPosition && screenstate == 0) {
togglehomescreen();
oldPosition = newPosition;
}
//pressing the button to count stitches in screenstate 0 and 1
if (buttonVal == LOW && lastButtonVal == HIGH && (screenstate == 0 || screenstate == 1)) {
delay(50);
pressTime = millis(); //button is pressed, start the timer
lastButtonVal = buttonVal;
}
if (buttonVal == LOW && ((millis() - pressTime) >= holdTime)) {
stitchCount = 0;
}
if (buttonVal == HIGH && lastButtonVal == LOW && ((millis() - pressTime) < holdTime)) {
stitchCount += countInc;
}
//SCREENSTATE 1
if (screenstate == 1) togglehomescreen();
//turning the rotary encoder to toggle screen
if (newPosition != oldPosition && screenstate == 1) {
homescreen();
oldPosition = newPosition;
}
//pressing the rotary encoder button to switch screens
if (rotaryVal == LOW && lastRotaryVal == HIGH && screenstate == 1) {
delay(50);
setcountscreen();
lastRotaryVal = rotaryVal;
}
//SCREENSTATE 2
if (screenstate == 2) setcountscreen();
//twisting rotary encoder to increase count increment
if (newPosition > oldPosition && screenstate == 2) countInc++;
if (newPosition < oldPosition && screenstate == 2) countInc--;
if (countInc < 1) countInc = 1;
//pressing rotary encoder button to switch screens
if (rotaryVal == LOW && lastRotaryVal == HIGH && screenstate == 2) {
delay(50);
countscreen();
lastRotaryVal = rotaryVal;
}
//SCREENSTATE 3
if (screenstate == 3) countscreen();
//twisting the rotary encoder to toggle screens
if (newPosition != oldPosition && screenstate == 3) {
togglesetcountscreen();
oldPosition = newPosition;
}
//SCREENSTATE 4
if (screenstate == 4) togglesetcountscreen();
//twisting the rotary encoder to toggle screens
if (newPosition != oldPosition && screenstate == 4) {
setcountscreen();
oldPosition = newPosition;
}
//pressing rotary encoder button to switch screens
if (rotaryVal == LOW && lastRotaryVal == HIGH && screenstate == 4) {
screenstate = 0;
lastRotaryVal = rotaryVal;
}
//reset variables
lastButtonVal = buttonVal;
lastRotaryVal = rotaryVal;
oldPosition = newPosition;
} else {
display.ssd1306_command(SSD1306_DISPLAYOFF);
//reset variables
lastButtonVal = buttonVal;
lastRotaryVal = rotaryVal;
screenstate = 0;
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
}
}
}
void homescreen() {
screenstate = 0;
display.clearDisplay(); //clear display buffer
display.setTextSize(4); //4x scale text
display.setCursor(0, 10);
display.setTextColor(SSD1306_WHITE);
display.println(stitchCount);
display.setTextSize(1);
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); //draw inverse text
display.setCursor(0, 45);
display.println(F("stitch counter!!"));
display.setCursor(0, 56);
display.setTextColor(SSD1306_WHITE);
display.println(F("set count increment"));
display.display(); //display
}
void togglehomescreen() {
screenstate = 1;
display.clearDisplay();
display.setTextSize(4);
display.setCursor(0, 10);
display.setTextColor(SSD1306_WHITE);
display.println(stitchCount);
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 45);
display.println(F("stitch counter!!"));
display.setCursor(0, 56);
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
display.println(F("set count increment"));
display.display();
}
void setcountscreen() {
screenstate = 2;
display.clearDisplay();
display.setTextSize(4);
display.setCursor(0, 10);
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
display.println(countInc);
display.setTextSize(1);
display.setCursor(0, 56);
display.setTextColor(SSD1306_WHITE);
display.println(F("< back"));
display.display();
}
void countscreen() {
screenstate = 3;
display.clearDisplay();
display.setTextSize(4);
display.setCursor(0, 10);
display.setTextColor(SSD1306_WHITE);
display.println(countInc);
display.setTextSize(1);
display.setCursor(0, 56);
display.setTextColor(SSD1306_WHITE);
display.println(F("< back"));
display.display();
}
void togglesetcountscreen() {
screenstate = 4;
display.clearDisplay();
display.setTextSize(4);
display.setCursor(0, 10);
display.setTextColor(SSD1306_WHITE);
display.println(countInc);
display.setTextSize(1);
display.setCursor(0, 56);
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
display.println(F("< back"));
display.display();
}