3040 CNC Milling Machine Mods

Upgrades to 3040Z-DQ

Similar projects worth following
Purchased a 3040Z-DQ CNC Machine on ebay, as I needed one to produce a face plate for my Air Gesture Switch project. I felt the machine could be made much better, so I'm upgrading it and documenting the process here.

The "3040" stands for the working platform of 30cm by 40cm. The "Z-DQ" model uses NEMA23 stepper motors, ball screws for the axes, and has a 230W DC spindle motor.

These Chinese CNC machines on ebay are good quality and cheap, but require that you have a parallel port. Who actually has a parallel port on their modern PC?

I decided to replace the stepper controller and keep the power supply and spindle controller (for now).

After doing some research, I came across the TinyG stepper controller from Synthetos. TinyG uses USB, and works with an awesome G-Code sender and 3D simulator called Chilipeppr. Here is a video by John Lauer (creator of Chilipeppr), who's video inspired my mods.

Another thing I upgraded on this machine was the existing limit switch wiring. The limit switches were setup in parallel. This means that the TinyG would not know the difference between hitting min or max limits on different axes. Also the limit switches were wired up as Normally Open. Normally Closed is better for noise immunity.

I added WIFI connectivity, using a beaglebone black and WIFI dongle.

I have spindle ON/OFF control working in software and I'm currently in the process of getting speed control working in software. Stay posted for more info.

Visit the project logs to see what I've changed.

  • Blinky

    Johnny09/14/2015 at 05:56 4 comments

    I received the JP-1482 Dev boards from OSH Park today, assembled one and got a blinky program happening.

  • JP-1482 Dev Board

    Johnny08/19/2015 at 13:10 0 comments

    he STC micros arrived today and I've made a little dev board to program it and test new firmware. I will send the design files off before the end of the week.

  • Characterizing JP-1482 PWM Out

    Johnny07/28/2015 at 15:39 0 comments

    I've recorded how the PWM is behaving in relation to the resistance of the pot. If I decide to reprogram the STC micro, I might mimic this behavior. Firstly it's important to note that the PWM coming out of the micro is inverted, this get's inverted again after going through the opto and NPN transistor. For simplicity, I'll refer to the PWM as if it doesn't invert (as the motor sees it)..

    As you can see in the table below, the front pot's minimum setting (maximum resistance) is 3.312K and the PWM didn't start till the resistance dropped lower then 3.125K (about 1.7V at the voltage divider). The PWM duty started at about 20% and increased to 100% linearly as the resistance dropped to zero (0V). I also noticed changes to the pot, don't make an immediate change to the PWM. The PWM has a ramping effect. I turned the dial to where the PWM starts working and then turned the dial very fast to the maximum speed setting and it took 4 seconds to catch up. So that's 4 seconds to get from 20% duty to 100% duty. 80% change in 4 seconds is 1% per 50ms. This means the PWM won't increase faster than 1% per 50ms. Also I noted the PWM frequency to be 1.28KHz.

  • JP-1482 Spindle Controller Schematic

    Johnny07/27/2015 at 13:44 1 comment

    I've now reverse engineered the JP-1482 board and drawn a schematic of everything.

    The micro's connections:

    Control signals:

    Output to spindle and overcurrent detection:

    Power supplies and fan output:

  • STC15W408AS

    Johnny07/25/2015 at 14:00 11 comments

    I've found the datasheet for the mysterious STC15W408AS microcontroller on the spindle controller board. Turns out it's a 8051 at heart. The datasheet is well documented and is surprisingly in well written english. The device is super easy to program too, only need a USB to UART adapter, Keil C51 compiler, uVision4, and a STC ISP application. Hopefully I can read the program memory and save it as a backup. This may be the neater solution. Just program the micro to have the PWM feature. I'll do more reverse engineering and have a play I think.


    Johnny07/24/2015 at 22:55 0 comments

    So, I started working on designing a board to achieve spindle speed control in software, and also be able to turn it on/off. The spindle speed control works by passing the PWM through a low pass filter, then reading the DC voltage produced on an analog pin of a PIC micro. The micro then reads the value (most significant 7-bit's of 10 bits), and sends it to a digital pot. The digital pot contains an 8-bit data register (16-bit really with command byte) and is 10K and we need 5K, so that's why we are grabbing 7 bits (need 8 bits and grabbing 7-bits divides the value in half). The last log explains why I need to convert PWM to a resistive value (voltage divider). I've also added a feature for the Z auto level probe on the board. The issue there is, my system has been configured to work with Normally Closed limit switches and the act of probing, is a Normally Open operation. So I've made a little circuit to make probing mimic a NC switch. Some parts should arrive this week. I can then make sure it's working 100% before sending the gerber files to seeed studio.

  • Day 4

    Johnny07/15/2015 at 14:23 2 comments

    Added beaglebone black with wifi dongle and now it's wireless. All I needed to do was set the beaglebone black to start the serial port json server and wifi at startup. All that's required is plugging in the power and a way we go.

    Thanks to Chilipeppr being so portable (it's browser based). I can even control the CNC from an ipad or smartphone.

    Lastly I made the spindle able to be turned on and off in software with M3 and M5 commands.

    I tried getting the external PWM spindle control going, but it seems the microcontroller on the spindle controller board has not been configured for it (on this model) :(. The PWM sent to the motor is controlled by this micro by looking at a voltage divider's voltage, who's value changes via the 5K front pot (used as rheostat). From what I can see, the divider is 6K to 3.3v and 5K rheostat (pot) to ground. The external PWM pin on the board looks to goes through a lowpass filter and to an analog pin on the micro. Despite the different frequencies and duty cycles I tried on the PWM pin, I can't get it to work. I'm thinking of adding a small PIC that can read the PWM signal from the TinyG and control a digital potentiometer (as rheostat). I will add a small switch on the from of the case to select which pot to use (software or manual control). Not elegant, but will work fine.

  • Day 3

    Johnny07/15/2015 at 07:14 0 comments

    Here is the old limit switches.

    And here are the new ones. Notice now that I am using the limit switches as Normally-Closed. This is for better noise immunity and extra safety. Using NC switches has the added benefit that the machine will know if a wire comes loose on a limit switch.

  • Day 2

    Johnny07/15/2015 at 07:13 0 comments

    Now for wiring up.

    I also spent most of the day working out how to software control the spindle speed. The spindle controller board has pins for this (PWM) but not clear details on the function of the pins.

    I first replaced the connectors to ones I can work with.

    I did some quick reverse engineering of the spindle controller and hope to try this out at a later time.

  • Day 1

    Johnny07/15/2015 at 06:55 0 comments

    The first thing I did was inspect the existing controller and tried to get an understanding of the existing system.

    As you can see, the controller has three PCB boards inside. A 3 axis stepper controller (JP-382A), 4th axis controller (JP-1635A), and combined power supply and spindle controller (JP-1482). The controller box also has limit switches for x, y and z. Unfortunately they are wired in parallel, so the TinyG would not know the different between hitting the min or max limit on different axes (useful for homing).

    Next I removed the fan, and stepper controllers.

    I lined up the TinyG against the old heatsink and 3 holes lined up out of 4. Not bad.

    I drilled out the 4th hole and widened the holes just a bit for a better fit.

    I cut a piece of aluminum to connect the TinyG's heatsink pads to the old heatsink with thermal tape.

    Here is the final result. Notice I used M3 bolts with plastic spacers.

    Next I marked where the USB will poke out the back, drilled a hole and filed the hole square.

    Here's the result.

    Next I made a cover for the parallel port hole using a blank PCI-e slot cover.

    The next step was creating larger holes to fit 4 way aviation connectors to accommodate for new limit switch setup. That is, limit switches for min and max. To do this is used my Proxxon tool (like a dremel).

    Finally I put some anti-rust paint on the cut surfaces (because this enclosure is steal and will get cancer) and installed the new connectors.

View all 10 project logs

Enjoy this project?



swartskaap wrote 03/27/2016 at 18:49 point

I got the limit switches working. Tx!
All limit switches connected to one GND (red) wire to the TinyG GND-screw connector.
Each limit switch, the remainding wire soldered to an axis.  Fr example;
Y-max = y-max screw on TinyG.
Y-min = y-min screw on TinyG.
Z-min = z-min screw on TinyG.
In the config, for all axes setting min=Homing Only, and max=Limits Only.

HELP.. my engraving is much to large. I seems "Travel Per Revolution" is misconfigured.
My current setting Travel Per Revolution=3,2mm/rev.

Since we have 100% the same config, could you dump your settings, or share it via Dropbox?

  Are you sure? yes | no

Johnny wrote 03/27/2016 at 23:51 point

  Are you sure? yes | no

swartskaap wrote 04/24/2016 at 08:33 point

Yes, i have baal-screw. Exactly the same as your a CNC 3040Z-DQ.

My settings is like this. I'm unsure about vlues for 'Travel per Revolution' and 'Micro Steps'.

  Are you sure? yes | no

swartskaap wrote 03/25/2016 at 20:07 point

GREAT writeup. I was looking for this!! :)

Could you disclose the wiring for the limit switches?

I have exact the same CNC and TinyG. 

Whats the purpose of the yellow, white, red and black wires?

Which wire should be connected to GND, which is for min & max?

  Are you sure? yes | no

Johnny wrote 03/25/2016 at 23:56 point

Hey, thanks :). 

When using Normally Open limit switches, for the tinyg to recognise a limit has been reached (be it x-min, x-max, y-min, y-max, z-min or z-max) the particular limit input on the tinyg will be switched to 0V. Thats the job of the limit switch. 0V(GND) is connected to one end of the limit switch and the other to the input. The connection for a Normally Closed limit switch is identical. Just make sure you specify the type of limit switch in the tinyg settings or else your CNC won't run, it will think it's at a limi. When you use Normally Closed limit switches, the inputs see 0V (through the switch) when no limit has been reached and 3.3V (via pullup resister on the tinyg) when at the limit. I recommend you use Normally Closed limit switches, as they are more immune to noise and you will know if there is a open circuit to any of your limit switches.

  Are you sure? yes | no

Paulmkoenig wrote 11/29/2015 at 02:07 point

We have one and the first thing we did was gut the controls and mach 3 over the parallel port. tinyG seems to work pretty good in its place. 

The platen flatness is quite bad and we haven't fixed it yet. We measured .040 TIR.

We are trying to use it as a drag knife cutter for cutting polystyrene membranes cleanly. 

  Are you sure? yes | no

Johnny wrote 12/01/2015 at 08:18 point

Cool. Let me know how you go fixing the flatness. Could using the machine to mill a flat surface in the waste material work? I guess that would also unfortunately limit the size of the objects going on the bed to being smaller than the working limits.

  Are you sure? yes | no

qwertypop2005 wrote 10/11/2015 at 17:45 point

Interesting stuff Johnny.  I took a similar approach to controlling the spindle speed on one of these machines. You're effort looks a bit more refined than mine. Details of my offering are here.... 

Post 25

Keep up the good work!

  Are you sure? yes | no

Johnny wrote 12/01/2015 at 08:20 point

Hey, yeah I've seen that forum thread before in my googling travels. Nice solution, I originally was going to go down that path of using a digital rheostat, to replace the pot on the front via switch. It's a good solution.

  Are you sure? yes | no

lksch wrote 09/09/2015 at 07:39 point

Hey Johnny,

great Job! i have nearly the same model, but i'm stucked to get Spindle on/off working. 

I connected a arduino with grbl to the parralel port. I dont know what i have to do with the pwm connector on the JP-1482. Because of your shematic an pictures i tried to shortcut the

Sp on/of Sw+ and Sp on/off sw-. but nothing happend. Is the white ic on your cable to the this connector just an opto coupler?

On my board there is a  third yellow cable from the Poti to the Poti connector. Is that maybe the Problem. 

When i want to tur the Spindle on, must the poti be at an "on" postion.

i hope i was able to describe the problem and you find the time to give me some tipps.



  Are you sure? yes | no

Johnny wrote 09/09/2015 at 07:59 point

Hey Lars, thanks man :). Yeah what you saw was a opto-coupler. Those pins need to be shorted. To do this I used a opto-coupler as you saw. Those pins are actually the same as what's connected to the spindle on/off switch. So the dial still needs to be adjusted for the speed.

Hope that helps.


  Are you sure? yes | no

lksch wrote 09/09/2015 at 18:07 point

Hey Johnny,

Thank you! Now it works! 

  Are you sure? yes | no

RoboMonkey wrote 07/27/2015 at 14:23 point

I have nearly the exact model...did yours come with limit switches pre-installed?

If you get your head around how to make the spindle holder a bit more friendly, let me know.  I've used a harbor freight die grinder as a makeshift spindle, and it worked great...but I'd love to be able to customize the router.  Unfortunately since the spindle is only held on with 2 screws it makes it quite limiting for that.
Great work.

  Are you sure? yes | no

Sheldon wrote 07/27/2015 at 15:43 point

Rather coincidentally in the last couple of weeks I bought a near-identical model as well (same specs for steppers, spindle, ball-screws and it's even a 3040!), the only main difference is mine does not have limit switches, although it has the same PCB with all the components present (so not a hard upgrade for me).

Oh, and I didn't get a 4th axis so I don't have the additional stepper driver but it looks to be as simple as plugging it in as, like the limit switches, I've everything else ready.

I keep wondering about a spindle upgrade but, other than finding a replacement spindle of the same diameter, I think the only option would be to remove the entire Z-axis and cutting the existing mount off to replace it with a few tapped holes so a generic plate can be used.

  Are you sure? yes | no

Johnny wrote 07/28/2015 at 10:52 point

Hey, yeah mine came with limit switches, although the wiring was a bit dodgy. True, I did see a guy in a youtube video replace his spindle motor with a 2.2KW one. I believe he cut off the spindle clamp part making a flat face. Then he attached his own spindle mount onto the existing. I'll try find the video.

  Are you sure? yes | no

RoboMonkey wrote 07/28/2015 at 13:27 point

that'd be great.  I should post about my modification to allow the use of the Harbor Freight die grinder as a spindle.  No speed control, but chews through wood like a beaver!

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates