Knitting machine hacking: putting it all together

Previous knitting machine hacking posts: introduction, flashing the Arduino firmware

Thankfully, after the complicated process I went through getting my Arduino set up to work with the AYAB shield, actually connecting everything to the knitting machine was straightforward!

The video from AYAB showing how to open up your knitting machine and connect your Arduino is great and very clear. I had to snip a cable tie to get enough slack in some of the cables and remove a plastic clip from one of the connectors to get it to fit when connected to the shield, but it all worked out fine.

Since my knitting machine has a broken card reader anyway, I didn’t bother keeping it. I did keep the plastic outer case, but removed the electronics and display, which were just attached with a few screws. The empty space created is big enough to fit the Arduino and shield (though I have to disconnect some cables from the Arduino), which makes it much easier to store everything.

I was dying to find out if this was all going to work and I couldn’t find documentation for the command line control utility (though I’ve since figured it out), so I used the AYAB GUI running in an Ubuntu virtual machine1.

It took a bit of experimentation to get the knitting process initialized correctly, but it totally worked! I was ridiculously excited at this point, as you might imagine. (And yes, I did need a new sponge bar for my machine, which is very often the case with used knitting machines. Thankfully I had a spare!)

I did a lot of testing and experimenting without yarn as I was getting the hang of using the AYAB GUI. You don’t need to have yarn in the machine to test the needle controls—you can run the empty carriage back and forth to try out the process first.

Two things to note about the GUI that I figured out through trial and error: it only supports PNGs (as far as I can tell? JPGs are included in the example files, but they did’t work for me), and the file width needs to be smaller than the number of needles you’ve selected to work with.

It works! Actual knitting!

Here it is, video evidence of my newly-hacked knitting machine in action. (Also including a cameo from my cat Abe, who loves all things yarn-y and was very curious about this strange noisy machine.)

In case you couldn’t quite see what I knitted at the end of the video, here’s the source image (scaled up significantly; there is one pixel for each stitch so the original is 50 pixels wide):

A pixelated 'hello world' in script

And the finished product:

'Hello World' knit in white into brown fabric

What’s next

Since I wrote most of this post (in February, whoops) I’ve acquired a ribber for my knitting machine, which is a second set of needles that creates a lot more possibilities for knitting images into fabric.

I’d also really like to write my own GUI for my machine, probably in Node with a web interface. I have some UI ideas brewing …

  1. This worked fine using Parallels on my Mac; the only configuration neccessary is to tell Parallels to “pass through” the Arduino’s USB port to the VM from the Devices menu.

Knitting machine hacking: flashing the Arduino firmware

Wondering what this is about? See the introduction to my knitting machine hacking adventures.

Successfully flashing the firmware on my Arduino so I could use my AYAB shield took a bit of fiddling, especially because I’m running OSX instead of Linux.

I’ll list the straightforward (as I can manage) steps that actually worked first, for anyone else trying to do this, and the messy narrative version afterwards (since that’s the fun/infuriating part!).

If you use these instructions and run into problems, or have suggestions for improvements, please get in touch! I’m happy to help though I’m far from expert in these things (so while I hope these instructions won’t mess up your Arduino, I definitely can’t promise that). This is what worked for me, though.

How to install AYAB Arduino firmware on OSX

AYAB comes with a Python-based GUI, but I couldn’t get it to run successfully on my OSX machine, and it isn’t neccessary for flashing the Arduino firmware anyway. These instructions explain how to get the firmware image and use avrdude to flash the firmware from the command line.

I did this on OSX Yosemite (10.10) but my guess is it would work fine on any relatively recent version of OSX.

  1. Install avrdude 5.x (I used 5.11.1 specifically)
    Homebrew only has a formula for avrdude 6.x, but if you don’t want to build avrdude yourself, an older version is downloadable from Objective Development as part of their CrossPack toolkit. You need the 2012-11-28 release. Here is a direct link to the dmg file.

  2. Download or clone the AYAB software repo

  3. Find and edit avrdude.conf or download a corrected version
    The avrdude config provided by AYAB won’t work when used on a computer without parallel ports (which I’m pretty sure means any modern Mac).

    I put the modified version I used on Github if you’d like to download it.

    Alternately, to edit it yourself, find the config file in the repo at /plugins/ayab_plugin/firmware/avrdude.conf. Do a search and replace on this file, replacing any instances of par; with serbb;. (Thanks to this Arduino forum post for this fix.)

  4. Find firmware.hex in the AYAB repo
    The path relative to the AYAB repo root directory is /software/python/ayab/plugins/ayab_plugin/firmware/[KNITTING MACHINE MODEL]/[ARDUINO TYPE]/firmware.hex. You’ll need to pick the directories that match your knitting machine and Arudino. There are different files for the different combinations.

  5. Determine which USB port your Arduino is connected to
    Your Arduino needs to be connected to your computer via the USB cable for this command to work (and for the firmware flashing you will be doing shortly!).
    Running ls /dev/tty.usbmodem* should show you the correct serial port. (I think this is dependent on your OS version and Arduino model, so you may have to do a bit of Googling if this specific command doesn’t work.)

  6. Actually flash your firmware!
    Now you should have collected all of the information you’ll need. Here’s the avrdude command to run: avrdude -v -p atmega328p -C "[PATH TO AVRDUDE.CONF]" -c arduino -P [ARDUINO SERIAL PORT] -b115200 -D -Uflash:w:"[PATH TO FIRMWARE.HEX]":i

    A note: I have an Arduino Uno, and you may have to change the -p atmega328p too if you’re using an Arduino Mega, but I’m not sure.

So if all goes well, avrdude should do its thing and flash the firmware, and you’re ready to install your AYAB shield, yay!

How I figured all this out

In short: trial and error and a lot of Googling. (As with so many things!)

My previous Arduino experiments have been at the “making an LED blink” level, just to give you an idea of my familiarity with hardware things (and to explain all my fumbling around).

I started by trying to get the AYAB GUI to run on OSX, since it has a firmware flashing utility built in, but after an hour or so of fiddling with Python dependencies and trying to figure out how to install what it was was missing, I decided this wasn’t going to be a very productive direction.

Instead, I set up a Linux VM using Parallels (though I bet you could use VirtualBox for this too) and installed the GUI in that. This was much less painful and following the AYAB-provided instructions seemed to work.

This turned out to not be the case with the firmware flashing utility, however. The main part of the application, which you use to control the knitting machine once everything is set up, worked fine. But trying to run the firmware utility just gave me an error.

I’m not sure if using a virtual machine for firmware flashing would have worked, because I never got that far. Using pip to install AYAB (as per the instructions) doesn’t seem to install the avrdude utility the GUI runs behind the scenes, so it fails to do anything.

I figured this out from error messages in the debugging console that opens with the GUI, once I realized the console was actually providing me with useful information.

avrdude does seem to be in the repo, so I spent a while trying to manually copy it to the right directory so that the AYAB GUI could find it, but for whatever reason I couldn’t get this to work. While I was trying this, though, I realized that the console error messages also showed me exactly what the GUI was trying to do for me, which was run avrdude with a bunch of arguments.

A little bit of research into what avrdude does (since I’d never heard of it before) confirmed that running it was probably all I needed to do, and showed me what files from the AYAB repo I needed. (The command the GUI runs is the one I provide above in the step-by-step directions.)

And so I saved a copy of that command, and tried installing avrdude on OSX! (OSX because I’m not a very efficient Linux user, and I was worried the virtual machine stuff would mess things up.)

Homebrew’s version of avrdude didn’t like the config file from the AYAB repo, and then I realized that the avrdude version provided by AYAB was 5.x and Homebrew’s was 6.x—that seemed likely to be source of the problem. Since the avrdude.conf file was huge and I wasn’t entirely sure which parts were relevant or really what it was doing at all, I guessed it would be easier to try and find an older, compatible version rather than update the config for the new version.

After rummaging through a bunch of tutorials and search results and seeing if I could build an 5.x version of avrdude from source (nope) I eventually found the old version of CrossPack I linked to in my instructions.

Now I had a running, hopefully-compatible version of avrdude! So close! And yet still not quite there apparently!

Running avrdude with all the right (I hoped) arguments and file paths gave me the mysterious errors parallel port access not available in this configuration and programmer type not specified. Googling those errors turned up this forum post which seemed to describe exactly the problem I was having (and my laptop certainly doesn’t have a parallel port), so I tried the suggested solution.

And with that last change, it worked! avrdude ran for a minute or two and then I had a newly-flashed Arduino.

In retrospect, it is hilarious that I thought “just” buying an Arduino shield for my knitting machine might be too simple a project, and I wouldn’t feel very accomplished getting it to work. Definitely not the case! I felt pretty damn victorious by the time I was done with this part of the process.

Next up: installing the Arduino in the knitting machine and the moment of truth!

Adventures in knitting machine hacking

My love of combining technology and textiles is well-documented already, so it is likely unsurprising I’ve had my eye on knitting machine hacks for a while.

Knitting machines are strange beasts. The most common ones, the machines I am familiar with, were made by Brother in the 70s and 80s for home knitters and are no longer manufactured. In college I took two semesters of knitting classes1 that used them, and they are odd and finicky and it isn’t surprising they never quite caught on. They make fabric much faster than hand-knitting, but they also require a lot of skill to operate and they really aren’t anything close to automatic.

You can still do a lot of neat things with them, though, and they are a much more accessible textile-making tool than many of the others I learned to use. (Maybe someday I’ll have my own loom for weaving, but that seems pretty unlikely to happen while I live in a New York apartment.)

As far as hacks go, Becky Stern’s is probably the most well-known, but I found this disclaimer pretty intimidating2 (and I can use knitting machines and Python already!):

Working with these machines is very difficult. Before you begin, look at your life, and what choices brought you to this point. Are you proficient at using the knitting machine’s normal functions? Can you read and run Python scripts? Have you ever done any serial communication between your computer and another device before? If you answered “no” to any of these questions, work on these skills first before attempting to follow this guide.

I don’t have any hardware skills, and tackling a modification to an expensive knitting machine as a first project seems likely to end poorly.

Happily, some enterprising German hackers made an alternative knitting machine hack that seemed more approachable to my intimidated-by-hardware self. All Yarns Are Beautiful designed an Arduino shield that interfaces with electronic Brother machines. Even better, the process is nondestructive and reversible, and it supports a less expensive model than the 930e used in the Adafruit hack.

A few weeks ago I finally decided I wanted to make my own hacked machine, despite my fear I would buy all these parts and ultimately get nowhere. I got lucky and found a Brother 910 with a broken card reader on EBay. The 910 originally read patterns off of mylar cards, which meant the pattern functions were unusable, but made it perfect for my purposes—the AYAB Arduino replaces that component completely.

This week the machine and the shield arrived, and I’ve made a lot of progress! I’ve been keeping notes and will be following up this post with others about the whole process. (And, hopefully, some finished products!)

If you’d like to see a Brother 910 in action, I found this cool video of Karen Allen demonstrating how she uses one to make sweaters. (Though she’s using the original card reader for patterns, she’s done some knit hacking too! I’ve never seen someone use two carriages at once to knit with that many colors.)

  1. How cool is it you can study this in college? I still think it’s amazing. (Probably moreso now that I am not fighting with knitting machines at 2am though, hah.)

  2. Having now attempted this project, I will say the disclaimer isn’t wrong exactly, but I think you can do fine with two skills out of three. I would say one of those skills should be using a knitting machine, though, since they can be tricky enough on their own without the complication of a hack.

"Girly" games, programming, and the fractal gender binary

Last week GOG had the Creatures series of video games on sale, and I couldn’t resist getting a copy that would run on my current computer and spending an evening immersed in gaming nostalgia.

As a kid and a teenager, I was fortuate enough to have easy access to the family computer (and later my own machine), and I spent many happy hours raising imaginary animals, figuring out how to access the newsgroup, downloading game add-ons and trying to build my own.

A screenshot of the game Creatures

I was similarly fascinated with the Petz games, and loved breeding strange hybrid animals and trying my hand at editing the files that defined the appearance of the cats and dogs in the game. (If you want to see some amazing examples of the game being pushed to its limits, this tumblr is hilarious.) I learned how to build websites in part so I could share the things I had made.

Then I discovered MU*s, which, besides being ridiculously fun, greatly improved my writing ability and introduced me to friends I still have, over a decade later.

Looking back, I am amazed at all of the technological skills I learned in the context of playing these games I loved, that I would otherwise have been too intimidated to try. Editing Petz breeds required using a hex editor and reading documentation from others who had reverse-engineered the file format. MU*s had their own Lisp-like and Forth-based programming languages that I learned to use, as well as many admin commands inspired by UNIX. (Not that I realized that, at the time. The first time I used chmod on a web server many years later I was startled that it was familiar!)

What also amazes me is that I did all these things, and yet never really considered myself the kind of person who could be a programmer. I was nerdy, sure, but programming was this lofty skill that I was sure was probably beyond me.

It is hard to say now exactly why I felt that way (and I certainly don’t remember ever being explicity discouraged from liking technology or having a career in it), but it seems likely to me in retrospect that I knew these were “girly” games, and my activities were not things “real” people who were into technology would do. People who became programmers wrote Quake mods, not custom breedfiles so they could have horses in their virtual pet game.

I think this Sociological Images post by Lisa Wade on the fractal nature of the gender binary provides an interesting framework for thinking about this1. Playing games and creating your own add-ons for them is stereotyped as a masculine activity. But within that category there are more and less feminine games. First person shooters? Masculine (and, thus, cooler). Virtual pets? Feminine (and so not as cool). Even text-based RPGs, a very specific and tiny subcategory of games, have gender stereotypes: MUDs (which have stats and combat systems) are for dudes, while MUCKs (which are largely for free-form roleplay) have many more female players (or so everyone assumed when I played them, I’m not sure if it was actually true).

Even now that I am a programmer (and let’s pretend I didn’t feel a tiny bit hesitant saying that), this fractal nature of the gendering of things—and so also their relative value—reappears. Front-end web development seems to attract a greater proportion of women (though I admit I can’t find hard data on this), and I don’t think it is a coincidence it is considered “easier” than other programming specialties.

I don’t really have a neat conclusion to these thoughts, except that gender and the ways we categorize the world are complicated, and we still have a lot of work to do to make everyone feel welcome in technology (and everywhere else).

  1. Just to be clear, I think that assuming gender is binary sucks (besides being, oh, totally inaccurate), and I wish things weren’t socially classified this way. But these assumptions definitely exist.

Adding syntax highlighting to knitting patterns

A few weeks ago a coworker sent me Karen Shoop’s awesome essay about the similarities between knitting patterns and regular expressions. While thinking about that, as well the as the knitting chart generator I’m going to make someday, really, it occurred to me that syntax highlighting knitting patterns could be genuinely useful. So I tried it!

If you’re not familiar with knitting patterns, they use a semi-standardized set of symbols and shorthand to record exactly how to recreate a particular texture or garment. The pattern will tell you things like how many stitches you need, what sort of stich to make and when and how to add or remove stitches.

For example, here’s the top of a sock I’m working on. The top of the cuff looks different than the rest, which is the result of a different pattern of stitches. (There are two kinds of stitches in knitting, knit and purl, though they are really the same stitch flipped 180 degrees—the back of a knit stitch looks like a purl stitch, and vice versa.)

knit sock stitches

The knitting pattern abbreviation for the cuff (at the top of the photo) is this:

k1 p1 until end of round

That translates to “knit one stitch, then purl one stitch, then knit, then purl … until you get back to where you started”. (This sock is being knit as a tube, hence “round”.)

Instructions for the lower part of the sock are like this:

k3 p1 until end of round

Almost the same, but with a different ratio of knits and purls, which makes a different texture.

For another example, here’s a closeup of a hat I made. Same two stitches, but in more complicated patterns:

knit hat stitches

A section of that hat’s texture (the diagonal stripes) would be transcribed like this:

k2, p2 to end of round.
k1, (p2, k2) to 3 sts before end of round, p2, k1
(p2, k2) to end of round
p1, (k2, p2) to 3 sts before end of round, k2, p1

So you can see how that starts to get more challenging to read and follow. (The parentheses indicate a series of stitches you should repeat.)

Wikipedia has an interesting taxonomy of the kinds of knitting abbreviations, but that didn’t seem like the most practical way to highlight the different portions of knitting pattern instructions. Instead I thought about the things that most often cause me to make an error while following a pattern, the parts that should be more distinct from each other while reading. I came up with this list:

  • which kind of stitch to make (knit or purl)
  • portions of the pattern that repeat
  • adding or removing stitches

I wasn’t really interested in writing my own syntax highlighter (yet, anyway), so I used Prism.js and wrote my own knitting pattern language definition, giving each of those pattern features their own distinct color. (And, in a neat circling back around to the essay I linked to at the beginning of this post, I used regular expressions to do so!)

Here’s the more complicated pattern from above, this time with syntax highlighting:

k2, p2 to end of round.
k1, (p2, k2) to 3 sts before end of round, p2, k1
(p2, k2) to end of round
p1, (k2, p2) to 3 sts before end of rnd, k2, p1

Much easier to read, I think!

For another, more complicated, example, here’s a portion of this lace tank top pattern. This pattern includes increasing and decreasing stitches (the abbreviations in lime green and red), and repeated instructions (in orange).

k2, p2 to end of round.
Rnd 1: K1, *k4, sl1, k1, sl1, k5; rep from * to last st, k1. 
Rnd 2: K1, *k3, k2tog, yo, k1, yo, ssk, k4; rep from * to last st, k1. 
Rnd 3: K1, *(k3, sl1) twice, k4; rep from * to last st, k1. 
Rnd 4: K1, *k2, k2tog, yo, k3, yo, ssk, k3; rep from * to last st, k1. 
Rnd 5: K1, *k2, sl1, k5, sl1, k3; rep from * to last st, k1. 
Rnd 6: K1, *k1, k2tog, yo, k5, yo, ssk, k2; rep from * to last st, k1. 
Rnd 7: K1, *(k1, sl1, k2, sl1) twice, k2; rep from * to last st, k1.
Rnd 8: K1, *k2tog, yo, k1, yo, ssk, k1; rep from * to last st, k1. 
Rnd 9: K1, *sl1, k3, k1tbl, sl1, k4, sl1, k1; rep from * to last st, k1.
Rnd 10: K2tog, *yo, k3, yo, sl1, k2tog, psso; rep from * to last 6 sts, yo, k3, yo, ssk, k1. 
Rnds 11-12: Knit.

I’ve put my (pretty simple) language definition up on Github, if you’re interested in trying it out. I’m sure there is room for improvement in the regexes I’ve written, though this was definitely a great way to get practice with writing more complex ones than I typically do.