Navigator
Embroiderino towards open source embroidery
Published: 2018-11-28 16:34:08

Introduction

Project main repository: git

Digital embroidery appeared in my interest long time ago when I was watching some videos about textile finishing, there was a sequence about sewing graphical details on fabrics with some CNC like sewing machine. The first thing I thought was: hmm that's looks cool and it just a electronic sewing machine, it does not look to be so complicated, probably somebody made it up. Quick search revealed a few projects, but without any sources or detailed description, sometimes it was rather buy it offer. Domestic embroidery machines solutions also seem to be relatively cheap, the stairs begin when you except faster speed, bigger work area and some more additional features. Embroidery design software prices also suggest that this market is a niche. In this article I will report and document my attempt to build this kind of machinery, this text might come in handy when you decide to clone or support the project. Of course it is not easy to even compare features and reliability of the machine from this guide with commercially available sets but if you are patient enough final work piece results are comparable. For less than 100$ you should end up with fully functional setup. As a name suggest this might be very first DIY embroidery machine but actually arduino board has more than enough processing power to control it.

General information

Project aim is to provide all needed to convert almost any sewing machine into digital embroidery machine, only straight stitch functionality is required. Very old machines turn out to be cheap and much less fragile from the new ones and they work well. Commercial machines with electronics failure etc. can be also modified and reused. Sewing machine must be fine tuned to save you frustration and produce best results, there is plenty of instructions how to do that, however in the last section I have described some notes from my observation. Machine is propelled by traditional stock brush AC motor (shipped with the machine) powered from mains network, however it is controlled by electronics in closed feedback loop servo manner. Some others attempts which I found on web use big stepper motor to run the machine, as it is easy to adopt for typical CNC control, as it is out of the shelf solution and needle position is precisely known all the time, there are no more advantages of that. Hoop position is set by actuator powered by two stepper motors, for fast movements its design cannot be bulky in assumption. Movement starts always when needle is in its upper dead position which is detected by typical IR light sensor encoder system and microcontroller interrupt. As a electronic controller AVR based boards like mentioned arduino or derivatives will work but additional shield board is needed to drive two steppers. For project purpose a dedicated firmware for microcontroller was developed, I can't see much sense in starting from scratch so one of minimalist printers firmware was a good point to start with. Firmware receives g-code instructions from host application via mcu UART interface, interprets them and executes. Host application runs on connected PC computer or on embedded computer board (like ex. raspberry PI). Software config is described later on.
Block diagram bellow summarizes flow of information within the system:

As it looks, there is as little peripheral components as possible. Sensors which are generating interrupts are connected through schmitt trigger to eliminate signal bouncing problems.

 

Mechanics

Main challenge here is to build fast 2D positioning system which is rigidly constrained to sewing machine. Project provides such solution suggestion applicable for most sewing machines, more information and instructions here. Aside from actuator a few necessary sensors must be mounted confidently, way to do it depends of sewing machine type. This can be accomplished within two manners: by interfering into machine construction (invasive way) or practically not.
Piece of chipboard was used as a basis where machine lays on in fixed position and hoop actuator is mounted to by four holders (plotter_mount.scad). Height of the hoop mounting point to suit the machine dimensions can be changed here by adjusting the height parameter of those mounts models before printing.

  
Hoop is keeped in place by two ergonomic for operation nuts, it is fast and decently easy to put it on or remove.

Notes about wiring and sensors for the machine are detailed in the next electronics section.
For best results sewing machine needs a special embroidery dedicated presser foot, it should start pressing the fabric only when needle is 2 mm above fabric. Higher distances might cause the fabric to being pressed and blocked too early, before hoop moment is complete, that correct foot timing is a problem for faster sewing speeds. Obviously machine built in transporter must be completely turned off.

Embroidery hoops can be 3D printed or bought, in last case additional adapter needs to be printed or fabricated. Printable adapter enclosed in project files (hoop_plotter_adapter.scad) is for printed hoops but it is a good point to start to reuse this file to design a other variant. Project encloses files for fully customizable hoop (hoop.scad), even the extra large 3d printed as a separate parts to fit most printers build platform volume (hoop_large.scad). Those parts are intended to be screwed together using 7x M3x30 screws and nuts.

Set of 3D printed parametric hoops, usable areas sizes: 60x75 mm, 110x120 mm, 145x230 mm.

 

Electronics

As a first diagram presents, electronics schematics is rather very simple. Many avr powered electronics boards can suit this demand. For the crucial moment detection an reliable optical sensor was utilized. For homing traditional mechanical switches work fine instead of optical. Schmitt triggers (chip 74HC14N) intermediary in interrupt circuits are very important for elimination of signal bouncing problems.
Servo circuit consists of standard AC/DC (up to 250V AC) brush motor with an rotary encoder on it, discrete PI regulator which is a part of microcontroller logic and motor power driver. Regulator sets the driver output value accordingly to measured encoder pulses and given speed value, so it solves a speed regulation problem. Professional machines probably control position instead of speed what is a different and more difficult issue but makes the whole thing run much dynamically and controllable. Note that there is no direction information since they are not needed, AC motor runs in only one defined by armature and stator windings connected in series. PI controller needs to be tuned by setting two values, default ones can but don't have to work for you, motor must run smoothly and without any big oscillations. PWM frequency needs to be checked as well, when motor runs on closely full speed with 50% or similar duty cycle then frequency is incorrect. Tuning procedure is in firmware related section.
Encoder wheel (file motor_encoder_parts.scad) is mounted to motor's shaft, but machine shaft might be as well. Optimal value for pulses per machine turn is 40-50 - which is doubled for square wave both edges detection.
Optical sensor is a simple integrated unit which is present in many desktop devices, printers, which is mounted on separate circuit board. Sensors output needs to be connected with atmega external interrupt no. 1 pin and power driver with any of timer0 muxable PWM pins!


Ac motor with rotary encoder mounted on it. Driver adapter is plugged into motor's plug socket.

Driver circuit is a AC rectifier and a power mosfet, driven by signal from optocoupler and voltage supplied from zener diodes. PCB for motor driver is made with KiCad, easy to etch and available in project repository (power_driver.pro). For safety and tidiness it is closed within printed casing box with direct plug in one side.

Needle position sensors are responsible for hoop movement triggering in the right moment. They can be mounted inside the machine to monitor shaft position or on the presser foot behind the needle. I wold highly recommend the first way (opposite to presented) because of more precise timing possibilities. Sensor has two outputs: one for change detection second for direction information, I have had checked out integrated precise sensor like this but problems occurs after some time when it becomes dirty from dust. Instead I have prepared a different one using discrete elements, it performed very well. There are just a two opto-transitors and one IR led diode, these can be recycled from old ball computer mouse. One line of the sensors output is connected to INT0 pin, second line to any of the configurable digital inputs.


First try with fully integrated sensor chip occurred to work not so well.

Correct timing adjustment for the sensor needs to be done. There are two positions to detect: when the needle is in its top dead position (but thread not fully pulled off) and where the thread is fully pulled off (take up lever top dead position) from the fabric and needle starts to move downwards. The first case is for quick short movements, the second for longer moments which are requiring the stop. It might seem better to start the hoop moment when needle just goes out of the material but it is not, thread which remained on hook causes the troubles here. When sensors are wired up, test them with some test embroidery pattern loaded and by manually turning the machine, when steppers are moving to its next position on every turn and in the moment when needle goes upwards then you got it right.

Picture presents sensor lines arrangements for linear flag or rotary wheel encoders. Row marked A is a moment when needle comes to its top dead position, row B is a combination for take up lever being on its top position when needle moves downwards.


Another advice, use 24-30V power supply for steeper motors, otherwise you have to lower the acceleration and speed. Commercial machines, even those like desktop printers, are using cheap motors, powered by good drivers and voltages around 45V. Higher speeds mean higher frequency whats increases the reactance of the motors windings so a higher voltage values are needed to keep the flow of same current value. Low current means low torque and troubles because of that, search for stepper motors rated for low voltages 3-2V.

 

Software

This is most important and expensive (to develop) part in embroiderino. Utilized software toolchain can be divided into three categories:

  • Digitizing environment where embroidery project is prepared with, produced output is simply set of stitching points and other instructions for the machine. This only one part does not belong to origins of development of this project. Surprisingly there is a very little choice for open-sourced tools like embroidermodder or inkscape extension inkstitch, only those two are worth mentioning. Any commercial software will work too for this purpose. Embroidermodder works well for conversions between different formats, so many existing patterns can be reused.
  • Machine control interface software (host), which is communicating with electronics within flat level instruction set. There is the place to set workable settings, load, display preview and validate project pattern. Adjustments like pattern location or rotation are necessary basic facilities.
  • Microprocessor firmware which is receiving instructions from host application and executes them by controlling the electronics parts. Basic functionality is to generate steering pulses for motors drivers, demandingly of the other conditions, this also involves routines like instruction buffering and speed planning.

Procedures for configuration and operation of the software from last two blocks are now described.

 

FIRMWARE
For the purposes of the embroiderino, teathimble is a firmware developed on top of teacup 3D printers firmware. It was the lightest and fastest piece of software for printers, not sure how it looks these days but after some relevant code cuts it even performed better than grbl but surely with much less additional features. For now only avr microcontrollers are supported, many "out of the shelf" electronics board configurations are absent and pinout must be configured manually. Firmware can be build and flashed via arduino IDE or enclosed makefile.

Most of the configuration is in config.h file where every option is described by a preceding comment, however a quick start guide bellow.

Set a plotter work area with these lines:

#define X_MIN                    0.0
#define X_MAX                    280.0

#define Y_MIN                    0.0
#define Y_MAX                    280.0

Steps per one meter to fit your pulleys drive setup:

#define STEPS_PER_M_X            87575
#define STEPS_PER_M_Y            87575

Plotter acceleration in mm/s^2:

#define ACCELERATION             2500

This is default and recommended serial communication speed:

#define BAUD                     115200

Activating this line increases the PWM frequency:

//#define FAST_PWM

For a more precise PWM configuration open sensors_control.c file and locate this line (FAST_PWM defined):

TCCR0B =  (TCCR0B & 0b11111000) | 0x02;

and change 0x02 to 0x03 or 0x01 - slow pwm.

Set a number of encoder pulses (doubled) per one machine shaft rotation:

#define PULSES_PER_TURN 84

Define the minimum, maximum workable and default (after reset or power on) machine speed in stitches per minute:

#define MIN_MOTOR_SPEED 80
#define MAX_MOTOR_SPEED 800
#define DEFAULT_MOTOR_SPEED 500


Adding a board pin setup

If your board configuration is present in boards.h header file then you can use it by defining relevant constant with config number:

#define MOTHERBOARD 2

If your setup has any slight differences it can by altered by changing relevant parts of this configuration in boards.h. New configuration can be added in boards or config header files, easiest way is to start editing definitions prepared in config.h.  It is everything between these definines:

#ifndef MOTHERBOARD
#define MOTHERBOARD
    #define X_STEP_PIN               PC3
    ...
#endif

Digital pin addresses can be defined in two manners: avr-lib style like PC3 above or arduino pin numbering style for example DIO10 where it just references 10th pin. Interrupts and PWM pins are imposed in advance. Define only one homing switch per axis, depending of the side on which they are located use ?_MIN_PIN or ?_MAX_PIN definition macros. Configuration can be checked manually by sending the command to machine in an arduino IDE serial port monitor. List of supported commands is here in readme.

Motor PI controller tuning

If you are not familiar with PI / PID controllers this guide might explain what is going on. You can start the tuning procedure from default values or very low ones - zero close. When speed is not stable and motor oscillates (slows down and accelerates over and over again), especially on low values, try changing kP constant a little bit. Increase it when motor has problem to reach desired speed and decrease it when the speed gets overshoot. If the motor runs stable but desired speed cannot be reached increase kI constant and check P again - for different speeds range. There is a Gcode command  M301 which becomes in handy while tuning the PI, it sets the factors current values and target motor speed, example: M301 S100 P40000 I2000.

Default (used after reset and power up) P and I factors for PI speed controller are defined here:

#define KP_FACTOR 40000
#define KI_FACTOR 2000

HOST
Control application is written for Python 3.x and uses Tkinter for GUI. Python tk and pyserial packages are a required dependencies. It will run almost everywhere, including computers dedicated for embedded systems, raspberry, bbone etc. To launch it just type python3 app.py, a main window should appear, on first run a machine configurations needs to be created but firstly brief overview. Window is divided into two regions: white canvas where embroidered pattern is shown and control region where there are two tabs with control widgets.
On the top additional menus bar is placed, on the bottom there is a text status bar which displays progress of most important actions. Machine control tab as a name suggests has all the options related to manipulation of the machine actions.
Hoop setup is important, because there is no limit when using preferred customized hoop which fits the job needs, always check if proper one is selected. Different setups can be stored and later selected from list when used. To add a new setup open the settings window (Edit>Settings), there are four parameters to type and check. Hoop dimensions (inner work area) and hoop origin (point 0,0), consider losses due to foot size when measuring and typing hoop size. Origin is a machine coordinate for which presser foot is under left bottom corner of hoop workarea. Type the name for new setup and click add button, existing setup can be updated with this button as well. Check if setup is correct, described later Go to mode might help a lot.

Of course to control the machine at first connection with the electronics needs to be established, select proper port and use connect button. Ports list can be updates within option in "File" menu. Next step after connecting is always to home the machine with home button, thanks to this electronics know what the position of the hoop is. Perform homing with hoop demounted, presser foot and needle up to prevent unwanted damage of colliding parts. By toggling "Go to" button a some special mode is activated, hoop is positioned in the place where you clicked on canvas when mode is on. It comes in handy when precise positioning for the sewing job is desirable. "Border path" button makes machine hoop to move around rectangle to show you where actually loaded embroidery pattern is going to take place. To load a pattern go to File>Open menu, two plain text formats are supported CSV (generated from embroidermodder) or raw Gcode. Analogously when saving the pattern, but if loaded file has any comments in it there is no guarantee to store them back. In case of gcode loading, because of non standardized variety of conventions only known and valid commands are accepted. When pattern is successfully loaded its preview should appear on canvas along with some information updated in machine control tab.

Those information are organized as follows:
tool changes (or thread color changes) - current change number / changes total,
tool points (stitches) left - until next tool change / until end,
estimated end time - until tool change / until end of sewing.


Path manipulation tab has some basic tools to adjust the pattern, from this point it can be moved, mirrored, scaled or rotated. To perform these operations toggle selected mode and click and drag on canvas, for rotation pivot point is where you clicked to start dragging. Scaling should be avoided since patterns are designed for thread thickness.
Use slider thing to limit the amount of stitches drawn in preview, it can be useful when analyzing the sewing progress.
When pattern seems to be prepared, machine threaded and foot lowered "Start job" button on machine tab does the thing, after start - all the manipulators commands are disabled. Pause button (same as start button) pauses the job and it can be resumed, stop button terminates it. Note that for now pause is not stopping machine immediately but when instruction buffer becomes empty (after 8 instructions by default). When thread needs to be trimmed or color to be changed, job is paused and proper message displayed. If for whatever reason you don't want those breaks they can be simply disabled by unchecking the relevant option check boxes. Sewing speed can be limited with speed limit slider. For now I preferred to operate at maximum speed of 800 stitches per minute, without any issues, it also worked when pushed above 1000 however this is untested range when the precision becomes affected. Firmware's speed planner curve can be stretched with max jump len value.

When starting a first stitch of sewing a thread tail might be a problem for some machines, if so then try don't making it longer than 3cm, hold the tail on start or just do first stitches manually turning the machine.
Test the working machine on a few jobs and test pieces before switching to real workpieces. There always are things that may go wrong, if machine jams, thread or needle breaks just turn off main motor power and fix the problem. Remove the hoop if necessary, put it back and turn on the motor power. This accident should not affect embroidery quality significantly. At current stage there is not any problem detecting mechanism. If those problems occurs too often then something is wrong. Next page is related to sewing machine checks.

 

  • 1
  • 2
Comments (2)
Eggert 2018-12-04 09:59:28
Hi, very nice build. I also plan to build an embroidery machine and found your page via the inkstitch discussion... Can you tell how much power the motor and rpm should have? My machine has none, and I want to start with a meaningful one...
markol 2018-12-14 22:19:57
@Eggert Just simple engineering calculations: assume machine and motor has a 1:5 transmission ratio, for 800 SPM you need 4000 RPM on motor. For brush motors its power and load are the speed limits (theoretically), typical domestic sewing machines motors are rated to 50-100 Watts. If you don't have any and don't want to play with high dangerous voltage find something under 50V and swap driver mosfet to different one capable to handle more amps.
Add a comment

For problems related questions please use issue tracker on git project repository (if any). Tags in comment will not work for now.