Knitting Counter, Calculator for Trapezoid Pattern
by pgeschwi in Circuits > Arduino
36 Views, 0 Favorites, 0 Comments
Knitting Counter, Calculator for Trapezoid Pattern

My wife asked me for help to (more or less) automating the calculation and knitting process for how many loops to add/drop per row for a certain knitting pattern. I should also say that this is an older knitting machine capable of reading pattern punch cards but besides that, no other gimmicks.
She was using Excel to calculate slopes, but as usual, the results are like "every second row, add 1.35 loops" or similar odd numbers. This is hard to put into some repetitive action. Keeping track and watching the row number to add/drop loops is error prone. I was scratching my head and envisioned scanning paper pattern and tracing these, matching against a sample, etc, etc.....
As usual, I was thinking overly complex and way beyond the real requirements. For simple pieces like knitting for the grand-kids or new pullover for some dolls she refurbishes, the required pattern were simple trapezoids.
So in general, we needed some sensor on the knitting machine detecting the direction of the sled, counting rows and if needed, an audible alert after every row requiring her to add/drop loops to reach the target number of loops and possible shift of the final row. From a calculation standpoint, easy to do. Detecting the sled and its direction is a task for hall sensors and a magnet fixed on the sled. I tried using a reed-relay, but scrapped that due to better sensitivity of the hall sensors.
The bigger issue was to create a streamlined user interface, asking for minimal data covering the pattern variations she needed.
Supplies





The task can easily be done by an old fashioned Arduino Nano or Arduino Uno. I had an Arduino Keypad Display Shield in my junk drawer, making this part very easy. I still used an Arduino Nano because I just had it available. Using an Uno would have made connections between the processor and the display shield much easier but needs a little more room. Whatever will work for you, the sketch would not need changing.
For detecting the moving sled, I used simple hall sensors and glued a fridge magnet on the sled. The fridge magnet is not very strong and should be 6mm (1/4 in) or less from the sensors. You can use a smaller but stronger Neodymium magnet in connection with a higher sensitivity hall sensor and possibly go as far as 12mm (1/2 in). This may be depending on the sled and where you can place the magnet without getting in the way. Since Neodymium magnets can be much smaller, mounting these is probably less of a headache. Please test the best location/distance so the hall sensors can detect the magnet reliably.
For the Hall Sensors I used type A1815 (less sensitive, older) or you can use A3144, which is the successor and more sensitive. Besides that, they are literally identical, both use a low-active output. There are many other types available, just make sure to check for the pin assignments. For this application we're using unipolar hall sensors, don't use a linear or bipolar type. The linear type is to measure field intensity and has an analog output, the bipolar version toggles between N/S fields and has a latching output. We just want to detect the presence of a magnetic field and return to normal when the field disappears.
To alert about adding/dropping loops, I used a simple passive buzzer which can be directly driven by the Arduino to play different pitch tones. I am announcing an increase of loops with two ascending tones and dropping a loop with a descending tone. I have to admit that the sounds are a flashback to old cell phones and ancient gaming consoles. While testing, I was annoying folks around me quite a bit. Luckily, you can adjust all these bleeping sounds to your liking.
Display:
- https://www.amazon.com/HiLetgo-Expansion-Backlight-4-5-5-5V-Duemilanove/dp/B00OGYXN8C/
Arduino Uno (matches the display shield):
- https://www.amazon.com/ATmega328P-Arduino-Compatible-Arduino-Voltage-Compatible/dp/B0D83J2TJJ/ref=sr_1_22_sspa?th=1
Arduino Nano:
- https://www.amazon.com/AYWHP-ATmega328P-Microcontroller-Compatible-Arduino/dp/B0DFGR288F/ref=sr_1_7_sspa?th=1
Unipolar Hall Sensors (like many of these simple items, they come in packages of 10 or 20):
- https://www.amazon.com/ALLECIN-Effect-AH3144E-Magnetic-Detector/dp/B0CZ6QXMZ2/ref=sr_1_1_sspa
Buzzer:
- https://www.amazon.com/Cylewet-Terminals-Electronic-Electromagnetic-Impedance/dp/B01NCOXB2Q/ref=sr_1_2
Site for all kind of melodies and sound combinations:
- https://github.com/robsoncouto/arduino-songs
I published a simple casing for the display and hall sensors and a magnet holder. The magnet holder will need adjustments depending on the one you'll use. There are two versions for the hall sensor. One has the cables centered (that's the one I used in the images above) and one with the cables on the small end. No matter how you mount these, best is to let the label face the magnet.
- https://www.tinkercad.com/things/3u5jkf00YpT-knitting-counter-calculator
Downloads
Supported Pattern

As mentioned earlier, the supported pattern are all trapezoid. The four categories matching the images number one to four are:
- Left edge straight, increase/decrease on the right edge.
- Centered, reduce/increase loops symmetrically.
- Right edge straight, increase/decrease on the left edge.
- Free form, target row shifted left/right relative to left edge of the first row. This is an universal form which includes the three above, but needs a bit more calculating. The above three are special shapes of a trapezoid.
The most used case is probably "centered" for which the target number of loops are centered relative to the start row.
Parameters needed for the first three, simple pattern:
- Number of loops at start, number of rows, target number of loops.
For the 4th pattern, we need one more data point:
- Number of loops at start, number of rows, target number of loops, offset of the target row relative to the left edge of the first row.
- This allows any free form trapezoid
I limited the maximum number of loops to 220 and the max offset to +/- 99. To change this, modify the 'maxLoops' parameter in the top portion of the sketch.
Wiring and Test


Wiring is straight forward, as shown in the diagram for an Arduino Nano. If you use an Arduino Uno, just plug the Display/Keypad Shield on top of the Uno and you should be done with display and button wiring. The two hall sensors and the buzzer are the only external connections. For connecting the two hall sensors, we need any 4-wire cable (VCC, GND, Sensor left, Sensor right)
If you happen to have swapped the two hall sensors during assembly, just swap the pin assignment for "HallL" and "HallR" in the sketch. Probably easier than rewiring.
To test the hall sensors and buttons, I added a debug setting. At line 24 you'll find:
which constantly prints the raw readings on the serial monitor for the keypad buttons. This debug setting also causes a beep if any of the hall sensors is detecting a magnetic field. This should help to find the best distance between magnet and the hall sensors.
Without any button pressed the reading should be 1000 or higher. Depending on the keypad resistors in use, there could be different readings. If these buttons do not act the way they should, you may need to change the thresholds defined in line 602 to match.
Then test the hall sensors and placement of the magnet. Once done, comment out the debug definition in line 24 to avoid beeping twice when the sled moves by the hall sensors.
I made a simple case for the display/keypad shield and the sensors and magnet holder in tinkercad as shown in the images above. Link is in the "Supplies" section.
Sample Setup and Operation














After switching on, a hello message will show on the screen and the buzzer is tested by playing three tones. The next screen is image "Example01" above, waiting for setting the number of loops of the first row. Using left/right buttons to navigate the pointer between the three digit number on the right and use the up/dn buttons to adjust the number of loops in the start row. Confirm by hitting "Select".
The next two screens are similar, asking for number of rows and the number of loops in the target row. Confirm with "Select".
The next screen is asking for the pattern, left aligned, centered, right aligned or left offset. Refer to chapter "Supported Pattern". The most used pattern is probably "Centered"
The image sequence above is using 25 loops for the first row, 20 rows height and the last row is set to 32 using a centered pattern. Since we're adding 7 loops distributed left and right, we should see one side growing by 4 and the other by 3. This depends if your first row is knitted starting with the sled on the left or right side.Usually, such small differences do not matter. Once confirmed with "Select", you'll see a "Ready, Go!" on the display.
For this demo, I placed the magnet (sled position) on the right side, this is my starting position. It does not make a difference if you start on the left if that is preferred. The two hall sensors will let the Arduino know which direction the sled has moved. You can check the detected direction on the bottom right of the display. If this is showing the opposite direction, either flip the hall sensor case or swap the two pin assignments in the sketch "HallL" and "HallR"
The next few images show a couple of rows in which you'll hear an alert tone and the number of loops to add/drop on the side the sled has arrived. The top row shows the row #, the caculated number of loops at this row and the current offset. For the three basic pattern, this offset is more a plausibility check. It shows the left offset based on the left margin of the first row. In this example, the last row is either 3 or 4 loops longer on the left and the right, 7 in total. The offset reading on the last image shows the last row begins 3 loops left of the leftmost loop of the first row. These "Row","Loop","Offset" details are only important if anything is going wrong while knitting and a row needs to be repeated if the thread has been kicked off the hooks or such. If this happens, you can step back/forward using the up/down buttons and continue at the row which is now correctly positiond after any issues have been fixed.
Once the "Done" jingle played, the target has been reached but this does not necessarily means the counter could not go on. If you continue, the calculations will continue using the same slopes.
On another note, if a pattern is let's say looking like an hour glass, wide on the top and bottom and smaller in the middle, just do the complete process in two parts. After finishing the first part, hit the reset button and continue with the second part.
On multiple requests of a single person (my wife), I added two languages, English and German. I left room for additional languages if anybody wants to add another one. Have a look at the skech at rows 30-52, defining strings for the display. the variable "Lge" (line 27) is selecting the column of the char matrix. 0=English, 1=German, 2 and 3 are unused.
I hope this little helper is useful for others as well, it is regularly used in this household.