• Log In
  • Register
  • Home
  • Gardening
  • General Interest
    • Health and Lifestyle
    • Reviews
  • Recipes
    • Beverages
    • Savoury
    • Sweet
  • Textiles
    • Knitting
    • Paper
    • Sewing
  • Upcrafting
  • Workshop
    • Electronics
    • Metal
    • Plastics
    • Repairs
    • Wood
  • About Us
  • Contact Us
  • Contributors
  • RSS Feed
  • May 24, 2013

Archives

  • March 2013
  • December 2012
  • October 2012
  • April 2012
  • February 2012
  • August 2011
  • July 2011
  • May 2011
  • April 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • December 2009
  • November 2009
  • October 2009
  • August 2009

Posts by date

May 2013
M T W T F S S
« Mar    
 12345
6789101112
13141516171819
20212223242526
2728293031  


CNC Sewing Machine – Part 2

July 24, 2010
By Andrew Lewis

I’ve been encouraged to post a little more about the sewing machine, so here is an update on progress. I’ve modified the Arduino code to accept direct input from a computer, so it is possible to run custom patterns of arbitrary length. I’ve written a quick python script that can take an image and convert it into a stitch pattern.

The communication system for the computer/Arduino interface is very basic:

  1. Computer waits until it receives the “X” character from the Arduino, then sends 2 bytes of information. Byte 1 is the needle position, and is a range between 0 and 64. Byte 2 is the feed direction and position, also ranged between 0 and 64 (32 is no movement – the material does not advance)
  2. The Arduino sets the servos into the correct positions when the needle is up, and then requests another 2 bytes by sending “X”

I intend to modify the code so that you can make use of the dials on the front of the machine. For example – sending the value 200 to the Arduino will tell the Arduino to read the value of the zigzag dial, and sending 210 will use the value of the feed dial. This way, it will be possible to set a general computer pattern and modify it in real-time at the machine.

The arduino will also return the value of the dials, so that you will be able to switch between patterns from a list stored in the PC.  This will make it easier to embroider letters and small symbols automatically.

I’ve covered up the electronics now that the paint has finally arrived, and I will be giving the body of the machine some TLC to cover up the rust stains and paint chips. Mechanically, the machine is in much better condition than it was. I have cleaned and oiled the mechanism, which has reduced the noise level considerably. I will raise the machine onto cork feet to help reduce noise.

I replaced the wire connecting the feed servo to the feed arm, because the twisted copper wire was too flexible. The replacement bar is made from steel with some nails brazed onto it to hook the servo and feed arm. The result is a much more accurate feed control.

The code I’m working on at the moment is here:

  1.  
  2. #include
  3. // needlesensor = 11, zigzag servo = 10, feed servo = 9
  4. // the lut is a lookup table to correct the polar / linear offset from the machinery
  5.  
  6. // these are the patterns, numbered 1-10. End of pattern is indicated by stitch value of 255 (valid number range for stitches is 64)
  7. const byte pattern[11][64] =
  8.   {
  9.     {}, // empty to soak up the zero index
  10.     {0, 10, 21, 32, 42, 53, 64, 53, 42, 32, 21, 10, 255},
  11.     {10, 32, 53, 32, 255},
  12.     {0, 0, 0, 0, 0, 32, 64, 64, 64, 64, 64, 255},
  13.     {10, 42, 21, 42, 64, 53, 32, 42, 32, 21, 32, 42, 64, 21, 32, 53, 21, 53, 32, 32, 64, 21, 10, 10, 42, 53, 32, 53, 10, 255},
  14.     {32, 42, 21, 53, 21, 53, 10, 64, 10, 64, 10, 64, 21, 53, 21, 53, 32, 42, 42, 32, 255},
  15.     {0, 10, 53, 64, 53, 10, 255},
  16.     {0, 21, 32, 42, 64, 42, 32, 21, 255},
  17.     {32, 37, 42, 48, 52, 56, 59, 62, 63, 64, 63, 62, 59, 56, 52, 48, 42, 37, 32, 26, 21, 16, 11, 7, 4, 1, 0, 0, 0, 1, 4, 7, 11, 16, 21, 26, 255},
  18.     {0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 64, 32, 64, 32, 64, 32, 64, 32, 64, 32, 255},
  19.     {0, 63, 2, 61, 4, 59, 6, 57, 8, 55, 10, 53, 12, 51, 15, 48, 17, 46, 19, 44, 21, 42, 23, 40, 25, 38, 27, 36, 29, 34, 29, 34, 27, 36, 25, 38, 23,
  20.     40, 21, 42, 19, 44, 17, 46, 15, 48, 12, 51, 10, 53, 8, 55, 6, 57, 4, 59, 2, 61, 0, 63, 255}
  21.   };
  22. byte lut[65] = {
  23.   0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 13, 14, 15, 16, 17, 18, 18, 19, 20, 21, 22, 22, 23, 24, 25, 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32,
  24.   33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 42, 44, 45, 47, 48, 50, 52, 53, 55, 57, 59, 60, 62, 64};
  25.  
  26. // set pin numbers:
  27. const byte buttonPin = 11;     // the number of the pushbutton pin
  28. const byte modePin = 6;        // zigzag when low
  29. const byte codePin = 7;        // direct serial mode when high
  30. const byte zigzagpotpin = 0;   // analog pin used to connect the potentiometer
  31. const byte feedpotpin = 1;     // analog pin used to connect the potentiometer
  32. const byte ledPin = 13;
  33.  
  34. // these are the settings perculiar to the machine
  35. // Change these for different machines
  36. const byte feedmin = 50;
  37. const byte feedmax = 105;
  38. const byte zigzagmin = 105;
  39. const byte zigzagmax = 169;
  40. const byte zigzagc = 132;
  41.  
  42. // create servo objects
  43. Servo feed;
  44. Servo zigzag;
  45.  
  46. int feedval;    // variable to read the value from the feed potentiometer
  47. int zigzagval;  // variable to read the value from the zigzag potentiometer
  48. boolean needlepos = LOW;
  49. boolean pulse = HIGH; // general heartbeat for zigzag function
  50.  
  51. // The programming variables
  52. boolean mode; // the mode select pin value
  53. boolean code; // the computer code select pin value
  54. byte pos;  // the position within the pattern
  55. byte prog; // the active pattern number, set by zigzag pot position.
  56. byte oldprog; // the program on last iteration. used to reset pos to zero if program changes.
  57. byte stitchpos;   // the position of the stitch, adjusted for machine using map
  58. byte prog_feed;  // byte to store serial input.
  59. byte prog_width;
  60.  
  61. void do_program(){
  62.   needlepos = digitalRead(buttonPin);                    // get the needle position
  63.   feedval = analogRead(feedpotpin);                      // reads the value of the feed pot
  64.   feedval = map(feedval, 0, 1023, feedmin, feedmax);     // scale it to use it with the servo
  65.  
  66.   zigzagval = analogRead(zigzagpotpin);                  // get the zigzag pot position
  67.   prog =  map(zigzagval, 0, 1023, 1, 10);                  // convert to 1-10 for program select  
  68.  
  69.   // check to see if the pattern has changed and look for the 999 end symbol in the pattern
  70.   if (prog != oldprog || pattern[prog][pos] == 255){
  71.     pos = 0;
  72.   }
  73.  
  74.   if (needlepos == HIGH) {
  75.     digitalWrite(ledPin, HIGH);
  76.     // set the stitch position
  77.     stitchpos = map(lut[pattern[prog][pos]], 0, 64, zigzagmin, zigzagmax);     // scale it to use it with the servo
  78.     Serial.println(int(pattern[prog][pos]));     Serial.println(int(lut[pattern[prog][pos]]));     Serial.println(int(stitchpos));
  79.     zigzag.write(stitchpos);  
  80.  
  81.     // move the feed if necessary
  82.     // get the feed value
  83.     feedval = analogRead(feedpotpin);                      // reads the value of the potentiometer
  84.     feedval = map(feedval, 0, 1023, feedmin, feedmax);     // scale it to use it with the servo
  85.     feed.write(feedval);                 // sets the servo position according to the scaled value
  86.  
  87.     // wait for needle to move down
  88.     while (needlepos == HIGH) { needlepos = digitalRead(buttonPin); }
  89.     pos = pos++; // increment the position
  90.     digitalWrite(ledPin, LOW);
  91.   }
  92.   oldprog = prog;
  93. }
  94.  
  95. void do_zigzag(){
  96.   needlepos = digitalRead(buttonPin);   // get the needle position
  97.  
  98.   if (needlepos == HIGH) {
  99.     // get the zigzag value
  100.     zigzagval = analogRead(zigzagpotpin);                          // reads the value of the potentiometer
  101.     digitalWrite(ledPin, HIGH);
  102.  
  103.     // decide whether to zig or zag
  104.     if (pulse == HIGH){
  105.         zigzagval = map(zigzagval, 0, 1023, zigzagmin, zigzagc);     // scale it to use it with the servo
  106.         zigzag.write(zigzagval);
  107.         pulse = LOW;
  108.     } else if (pulse == LOW) {
  109.         zigzagval = map(zigzagval, 0, 1023, zigzagmax, zigzagc);     // scale it to use it with the servo
  110.         zigzag.write(zigzagval);
  111.         pulse = HIGH;
  112.     }
  113.     // wait for needle to move down
  114.     while (needlepos == HIGH) { needlepos = digitalRead(buttonPin); }   // get the needle position
  115.   }
  116.  
  117.   if (needlepos == LOW) {
  118.     // get the feed value
  119.     feedval = analogRead(feedpotpin);                      // reads the value of the potentiometer
  120.     feedval = map(feedval, 0, 1023, feedmin, feedmax);     // scale it to use it with the servo
  121.  
  122.     digitalWrite(ledPin, LOW);
  123.     feed.write(feedval);                 // sets the servo position according to the scaled value
  124.     Serial.println(feedval,DEC);
  125.  
  126.     // wait for needle to move up
  127.     while (needlepos == LOW) { needlepos = digitalRead(buttonPin); }
  128.   }
  129. }
  130.  
  131. void setup()
  132. {
  133.   // initialize serial communication:
  134.   Serial.begin(9600);
  135.  
  136.   // attach the servos
  137.   feed.attach(9);
  138.   zigzag.attach(10);
  139.  
  140.   // move the servos into place
  141.   feed.write(feedmin);
  142.   zigzag.write(zigzagc);
  143.  
  144.   // setup the input for needle sensor
  145.   pinMode(buttonPin, INPUT);
  146.   pinMode(modePin, INPUT);
  147.  
  148. }
  149.  
  150. void loop()
  151. {
  152.   // choose mode
  153.   mode = digitalRead(modePin);
  154.   code = digitalRead(codePin);
  155.   if (code == HIGH){
  156.     do_code();
  157.   }else{
  158.     if (mode == LOW){
  159.       do_zigzag();
  160.     } else {
  161.       do_program();
  162.     }
  163.   }
  164. }
  165.  
  166. void do_code(){
  167.   // send X to get next chars
  168.   // send E for error
  169.  
  170.   // 0-64 is position
  171.   // 0-64 is direction
  172.   // get two bytes
  173.   // 1st byte is stitch position, 2nd is feed
  174.  
  175.   needlepos = digitalRead(buttonPin);                    // get the needle position
  176.  
  177.   // send ready and wait for a value
  178.   Serial.print("X");
  179.   while (Serial.available() < 2)
  180.   {// wait until we have 2 char
  181.    // exit if mode changes
  182.     code = digitalRead(codePin);
  183.     if (code == LOW){
  184.       return;
  185.     }
  186.   }
  187.  
  188.   // read the incoming character
  189.   prog_width = Serial.read();
  190.   prog_feed = Serial.read();
  191.  
  192.   // set the foot, then position the head when needle is up
  193.  
  194.   needlepos = digitalRead(buttonPin);                    // get the needle position
  195.   if (needlepos = HIGH){
  196.     digitalWrite(ledPin, HIGH);
  197.     stitchpos = map(lut[prog_width], 0, 64, zigzagmin, zigzagmax);     // scale stitch width to use it with the servo
  198.     feedval = map(prog_feed, 0, 64, feedmin, feedmax);              // scale feed value to use it with the servo
  199.  
  200.     feed.write(feedval);
  201.     zigzag.write(stitchpos);
  202.     while (needlepos == HIGH) { needlepos = digitalRead(buttonPin); }
  203.   }
  204.  
  205.   digitalWrite(ledPin, LOW);
  206.   while (needlepos == LOW) { needlepos = digitalRead(buttonPin); }
  207.  
  208. }
Share

Tags: arduino, cnc sewing machine, computer controlled sewing machine, upgrade sewing machine

One Response to “ CNC Sewing Machine – Part 2 ”

  1. Khalid on August 28, 2010 at 9:04 am

    Hi,
    Very interesting project :) .. I really like the way you have used the Arduino:)…
    I also did some work on CNC embroidery Machine.. I made a software that converts DST file to Gcode.. and you can then get beautiful embroidery work with CNC converted sewing machine.
    http://www.my-woodcarving.blogspot.com

    My software is free for all

Leave a Reply

Click here to cancel reply.

CAPTCHA Image
Refresh Image
*


− one = 6

Copyright © 2013 Upcraft.it. All Rights Reserved.
Magazine Basic theme designed by Themes by bavotasan.com.
Powered by WordPress.