Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: johandg on January 25, 2020, 04:26:42 AM

Title: Anyone using an Arduino to receive up to 32 inputs?
Post by: johandg on January 25, 2020, 04:26:42 AM
1. An arduino Mega takes care of all other inputs than the ones (4 only) you absolutely need to use to run Mach3 (if you are using the parallel port)
2. The arduino sends a 32-bits binary stream of the inputs status , and sends also an output when Mach3 needs to look at this stream
3. The MacroPump macro, which runs continuously, checks the input which says 'Hi, there has been a change on your inputs'
4. If no change, the Macropump macro does nothing.
5. If change, the Macropump reads the stream, runs through the actual status of every input, and changes them accordingly.

This does affect the speed of Mach3, and slows it down & few millisecs.

Anyone?
Title: Re: Anyone using an Arduino to receive up to 32 inputs?
Post by: Tweakie.CNC on January 25, 2020, 04:51:23 AM
Sounds very interesting.

Tweakie.
Title: Re: Anyone using an Arduino to receive up to 32 inputs?
Post by: johandg on January 25, 2020, 06:17:47 AM
Yes, also possible with the USB controller, or what ever other controller you use. You only need to have a Com port. Most computers still have them, if not brought to the outside, it's on the main board. If not, then use a usb2serial adapter. Serial is available on every Arduino, the cheapest one being the Arduino Nano which supports 14 digital I/O's and costs a few bucks.

Anyone already done that? If so, please share, if not, I will make it and share it, if anyone is interested.
Title: Re: Anyone using an Arduino to receive up to 32 inputs?
Post by: TPS on January 30, 2020, 10:50:38 AM
https://www.machsupport.com/forum/index.php?topic=21105.0
Title: Re: Anyone using an Arduino to receive up to 32 inputs?
Post by: johandg on January 30, 2020, 02:44:03 PM
Great, this closes the topic. It has already been done. Thanks!
Title: Re: Anyone using an Arduino to receive up to 32 inputs?
Post by: brandonb on January 31, 2020, 08:31:19 AM
Most simple way would probably be to use Serial.print in the Arduino. Use it to send all the states of the inputs. Then connect the USB of the Arduino to the Mach4 Computer and create a lua script that does read from the COM port. Here is an example of reading data from the Arduino using c++ and Windows API:

https://playground.arduino.cc/Interfacing/CPPWindows/

You would just have to port it to lua. Just import the necessary API functions like here (http://lua-users.org/wiki/SerialCommunication), parse it and use mcSignalSetState() to assign the states to the user signals of Mach4.

I wish one could add I/O Devices too, so they would appear in the Configure > Controls > Input/Putput Signals Tabs as Devices. Allowing you to assign the pins of the arduino to the various inputs/outputs in these tabs. But this is not possible as Mach4 only allows to do that via plugins. Only OEMs can have access to the Plugins and Devices API of Mach4.