Hello Guest it is April 19, 2024, 02:57:56 AM

Author Topic: Using M-Codes to send signal to Arduino that controls solenoids  (Read 6424 times)

0 Members and 1 Guest are viewing this topic.

Using M-Codes to send signal to Arduino that controls solenoids
« on: December 01, 2010, 01:19:17 PM »
I have been tinkering with the Arduino platform for a while to control solenoids that are driving dispensers of liquids along a tool path.... So far I have had this system working independently of Mach3... So I have the g-code start and as the tool head is moving I start the arduino to actuate the solenoids.
This works well for some things, but I would like to be able to send output signals from the g-code itself... probably by using M codes.

I am currently using a k2cnc with 3 axis servo setup... with a 4 axis in the future when money allows.
So the parallel port is currently driving the mill.

I have been reading on the forum about so many things that are possible and I am looking for advice as to where I should focus my efforts.

Can I have serial output from Mach3 while g-code is running without interfering with Mach3's normal operations through the parallel interface?
I know that the spindle on/off (which is pin 16 on my K2CNC) and the coolant on/off (pin 1 - according to K2) are free to drive things through the use of MCodes... but it would be great to be able to have more than two free "outputs".

Thanks for any advice... I am really loving this forum... so many generous and knowledgeable folks. :)
Re: Using M-Codes to send signal to Arduino that controls solenoids
« Reply #1 on: December 01, 2010, 06:44:36 PM »
I'm not familiar with the Arduino, but Mach3 can control many things while running, and is only limited to 6 axis and 1 spindle as far as I know. What will limit you is the available outputs from your parallel port interface card in the machines controller box. If you have 4 free outputs, you can potentially control 4 external devices. If you need to extend the inputs/outputs further you must make use of a ModIO bus, but it is definitely possible. You should be fine, providing you have the outputs available.

As far as I know M codes would be the only way to control it directly from your part program.
Re: Using M-Codes to send signal to Arduino that controls solenoids
« Reply #2 on: December 01, 2010, 11:12:09 PM »
There is a Mach VB function to write to a serial port, but it's not well supported, and may well go away.

Regards,
Ray L.
Regards,
Ray L.

Offline Tweakie.CNC

*
  • *
  •  9,198 9,198
  • Super Kitty
    • View Profile
Re: Using M-Codes to send signal to Arduino that controls solenoids
« Reply #3 on: December 02, 2010, 06:33:29 AM »
ceramics,

There is a good chance you have more available Parallel Port Outputs than just the two you have mentioned but if you are programing the Arduino yourself then you can easily multiplex the signals. Two outputs can provide 3 functions and three outputs 7 functions and so on. You can incorporate the M Codes (to switch outputs on/off) within your GCode program quite easily with a simple editor such as Notepad.

I have been using Mach for a few years now and it's versatility just keeps growing.

Tweakie.
PEACE
Re: Using M-Codes to send signal to Arduino that controls solenoids
« Reply #4 on: December 02, 2010, 10:22:33 AM »
Thanks for all the quick replies... after digging around a little more, I am heading towards using a Pokey55 board so that I can have a lot of output pretty easily.
I really liked Tweakie's suggestion of multiplexing the signals from available parallel pins.  This seems like the best route except that I would be nice if I could actuate 14 separate solenoids.
Two solenoids are being used to pressurize or release pressure from individual liquid dispensers.
so since I need so many... the Pokey seems like a good route. 
I spoke with Arturo from CNC4PC and he was very helpful. 
This route may be more expensive and more complicated initially, but it will give me a lot of flexibility my needs change.
My goal is to have the machine "extrude" different colored ceramic glazes in particular patterns on top of plates, tiles, etc.
I will post some pictures for anybody interested as it comes together.
now I need to start learning about setting up the Mcodes to work with the Pokey.... I think this will be done with the VB function.
Thanks again

Offline Tweakie.CNC

*
  • *
  •  9,198 9,198
  • Super Kitty
    • View Profile
Re: Using M-Codes to send signal to Arduino that controls solenoids
« Reply #5 on: December 02, 2010, 10:55:25 AM »
ceramics,

Yes please post details of your project as you proceed, it sounds most interesting indeed. Also pictures would be nice, we all love pictures  ;D

Tweakie.
PEACE

Offline djc

*
  •  47 47
    • View Profile
Re: Using M-Codes to send signal to Arduino that controls solenoids
« Reply #6 on: December 05, 2010, 03:47:30 AM »
I hope I'm not speaking out of turn here, but what does the Arduino add in this case? You can drive solenoids directly from the parallel port. If you look on page 4-2 of the Mach manual, you see that a standard port has 12 outputs. Add a second port (easily the cheapest option) and you have 24 outputs available. In ports & pins, outputs, just map the standard outputs (up to 20 available) to the pins (see page 5-9). Make your own M code (say M201 for output 1, M202 for output 2 etc.) and you are in business (see p. 10-34 of mill manual and page 2 of Macro_Prog_Ref).

Offline Tweakie.CNC

*
  • *
  •  9,198 9,198
  • Super Kitty
    • View Profile
Re: Using M-Codes to send signal to Arduino that controls solenoids
« Reply #7 on: December 05, 2010, 04:10:16 AM »
H Djc,

You are, of course, quite right in what you say about the capabilities of Mach.
There are, however, some advantages in using sub processors for an application's additional sensing and switching functions thereby relieving some of the load from Mach, which is really quite busy enough with all it's step, direction and timings etc. It just enables complicated processes to run more smoothly.

Tweakie.
PEACE