Hello Guest it is March 29, 2024, 03:01:29 AM

Author Topic: Modbus and Arduino Question  (Read 23384 times)

0 Members and 2 Guests are viewing this topic.

Modbus and Arduino Question
« on: September 11, 2016, 10:40:39 PM »
I am making a pendant to use with my CNC machine.  The pendant is using an Arduino Due for the brains with a 5" touchscreen.  I have a 16 button keypad and 2 small joysticks (each with a center button) connected as inputs.  I am connecting to Mach3 with the modbus protocol.  

I have programmed the touchscreen to allow selecting an axis, changing Jog Mode, cycling through the Jog Increment steps, zeroing selected axis, and zeroing all.

I need to add the spindle speed on the screen as I plan to move to a spindle with vfd and of course make an enclosure.

I actually have more inputs then I know what to do with. I am open to suggestions  :D

My question is...how can I, with the pendant, have Mach3  go to a specific Axis' zero position (not machine zero).
« Last Edit: September 11, 2016, 10:43:41 PM by ejjenkins »
Re: Modbus and Arduino Question
« Reply #1 on: September 11, 2016, 10:48:32 PM »
Some information to add...I have created brain files to get the DRO info from mach 3 and to pass the button presses and joystick movements.  Everything works great...I just need to have the machine go to a single axis zero location.

Any help would be appreciated.

Thank you.
Erik

Offline Tweakie.CNC

*
  • *
  •  9,196 9,196
  • Super Kitty
    • View Profile
Re: Modbus and Arduino Question
« Reply #2 on: September 12, 2016, 01:24:41 AM »
Excellent work Erik, that looks like it is going to be a really nice pendant.

Tweakie.
PEACE
Re: Modbus and Arduino Question
« Reply #3 on: September 12, 2016, 08:36:29 PM »
Thanks Tweakie.
Re: Modbus and Arduino Question
« Reply #4 on: September 13, 2016, 04:52:38 PM »
I had to write a macro and use OEM triggers to get the "Go To Selected Axis Zero" to work.

All is good now  :)
Re: Modbus and Arduino Question
« Reply #5 on: September 18, 2016, 10:04:32 PM »
I made an enclosure for my new pendant out of some thin (0.5" x 2") aluminum extrusion. The faceplate was a test in 1/8" hardboard, I plan to make the final one out of either aluminum or black ABS...I have both, but I am leaning towards the ABS. I think the black will look better with the aluminum framing.

Everything is working well now.  I switched to a different keypad with removable plastic covers for each button and a new label can be printed easily and the function of each button can also be changed quickly.  I have added the ability for user-defined macros as well.  I have three brain files setup to handle button presses as well as update the DROs on the screen. 
Re: Modbus and Arduino Question
« Reply #6 on: September 18, 2016, 11:12:04 PM »
Great job ejjenkins.

Will you share more info about your project.
Thanks
Re: Modbus and Arduino Question
« Reply #7 on: September 19, 2016, 04:54:30 PM »
Here are my notes at the top of the Arduino Sketch, it gives a bit of the info which makes this pendant function.  If you would like more info, please ask.
Code: [Select]
                                                                                                                     
// This is for a CNC Pendant to interact with my heavily modified 1000mm x 1000mm Inventables X-Carve using Mach 3 to control the machine.     
// I am using the Arduino Due for the brains of the pendant.  All Communication with Mach3 is accomplished             
// through the serial protocol modbus.  In Mach3 I have set up brains to handle the input and output to               
// the arduino.  One brain to handle output to the Pendant and two to handle button presses.  I have also configured   
// several OEMtriggers to handle the execution of macros in the M1000.m1s file.  The macro can execute the Probe Zero
// Z Axis, probe Zero All Axes, Got to Zero on X, Y, Z or A axis as well as user defined macros.                     
//                                                                                                                   
// I have the following hardware attached to the Arduino Due:                                                         
// 5" GLCD display and LCD Shield with a 800 x 480 resolution from SainSmart (using the UTFT libraries)               
// 16 button keypad attched as an analog keypad using only 1 analog pin on the Arduino as well as ground and 5v.       
// 2 joysticks, each attached to 2 analog pins and 1 digital pin for the center button.                               
//                                                                                                                     
//     Current keypad button functions are defined as:                                                                 
//                                                                                                                     
//        1: Reset             2: Cycle Start       3: Cycle Pause      4: Cycle Stop                                 
//        5: Home All          6: Rewind Program    7: Edit G-Code      8: Close G-Code                               
//        9: Probe Z Axis     10: Spindle On/Off   11: Jog On/Off      12: Toolpath On/Off                             
//       13: Select X Axis    14: Select Y Axis    15: Select Z Axis   16: Select A Axis                               
//                                                                                                                     
//                                                                                                                     
//  Here is a list of all the send and receive bits and what they are set for.  These are set within the Mach3         
//  brain files.                                                                                                       
//                                                                                                                     
// bitSet(rcd[0],0)  RefAll           bitSet(rcd[1],0)  Cycle Start      bitSet(rcd[2],0)  Jog Increment Cycle         
// bitSet(rcd[0],1)  Rewind File      bitSet(rcd[1],1)  Cycle Stop       bitSet(rcd[2],1)  Jog STEP                   
// bitSet(rcd[0],2)  Edit File        bitSet(rcd[1],2)  Reset            bitSet(rcd[2],2)  Jog CONT                   
// bitSet(rcd[0],3)  Jog X-Positive   bitSet(rcd[1],3)  Zero All         bitSet(rcd[2],3)  Probe Zero Z (OEMtrigger1) 
// bitSet(rcd[0],4)  Jog X-Negative   bitSet(rcd[1],4)  Zero X           bitSet(rcd[2],4)  Goto X Zero  (OEMtrigger2) 
// bitSet(rcd[0],5)  Jog Y-Positive   bitSet(rcd[1],5)  Zero Y           bitSet(rcd[2],5)  Goto Y Zero  (OEMtrigger3) 
// bitSet(rcd[0],6)  Jog Y-Negative   bitSet(rcd[1],6)  Zero Z           bitSet(rcd[2],6)  Goto Z Zero  (OEMtrigger4) 
// bitSet(rcd[0],7)  Jog Z-Positive   bitSet(rcd[1],7)  Zero A           bitSet(rcd[2],7)  Goto A Zero  (OEMtrigger5) 
// bitSet(rcd[0],8)  Jog Z-Negative   bitSet(rcd[1],8)  Jog Z-Right/Off  bitSet(rcd[2],8)  Zero X Axis                 
// bitSet(rcd[0],9)  Jog A-Positive   bitSet(rcd[1],9)  Jog Z-Left/Off   bitSet(rcd[2],9)  Zero y Axis                 
// bitSet(rcd[0],10) Jog A-Negative   bitSet(rcd[1],10) Jog A-Right/Off  bitSet(rcd[2],10) Zero Z Axis                 
// bitSet(rcd[0],11) Jog Y-Right/Off  bitSet(rcd[1],11) Jog A-Left/Off   bitSet(rcd[2],11) Zero A Axis                 
// bitSet(rcd[0],12) Jog Y-Left/Off   bitSet(rcd[1],12) Feedhold         bitSet(rcd[2],12)                             
// bitSet(rcd[0],13) Jog X-Right/Off  bitSet(rcd[1],13) Jog Off/On       bitSet(rcd[2],13)                             
// bitSet(rcd[0],14) Jog X-Left/Off   bitSet(rcd[1],14) Toolpath On/Off  bitSet(rcd[2],14)                             
// bitSet(rcd[0],15) Close File       bitSet(rcd[1],15) Spindle On/Off   bitSet(rcd[2],15)                             
//                                                                                                                     
// bits rcd[3-12], 0-15 are currently unused...there are a ton of unused bits still available.                         
//                                                                                                                     
//  Variables received from Mach3:                                                                                     
//                                                                                                                     
//  mcd[0] + mcd[1]  X-Axis location   - receiving one side of the decimal point in each data element.  Each one is   
//  mcd[2] + mcd[3]  Y-Axis location      converted to a signed float and displayed on the GLCD                       
//  mcd[4] + mcd[5]  Z-Axis location                                                                                   
//  mcd[6] + mcd[7]  A-Axis location                                                                                   
//  mcd[8] + mcd[9]  Jog Increment                                                                                     
//  mcd[10],0        Reset Status      - A simple toggle bit                                                           
//  mcd[10],1        Jog Mode          - A simple toggle bit                                                           
//  mcd[10],2-15 are currently unused                                                                                 
//  mcd[11]          Feedrate Overide  - An integer                                                                   
//  mcd[12]          Feedrate          - An integer                                                                   
//                                                                                                                     
// Currently there are 13 x 16 bit data elements to send and receive from Mach 3.  I am using all of the data         
// elements received from Mach 3 to update the DROs and Reset, Jog, Feedrate Overide and Feedrate.  If I want to       
// receive more information I will need to add more data elements.  to add Spindle Speed, I will need one more data   
// element as it will simply be an integer.
                                                                           
Re: Modbus and Arduino Question
« Reply #8 on: September 21, 2016, 08:09:43 PM »
I have had a few questions on how I am communicating with mach 3.  I am using the simple modbus slave library from here:  https://github.com/charlesbaynham/simple-modbus

In mach 3 I am using serial modbus non-plugin.

To pass the Axis coordinate DRO values to the LCD, I am using 2 Data elements...one for each side of the decimal point.

The brain to send the values are like this:

X-Position   ---   No Operation, Pass Signal   ---   MOD: 13            This is the Left side of the decimal point
X-Position   ---   Formula, (A*1000)-(int(A)*1000)   ---   MOD: 14  This is the Right side of the decimal point

Then I print to the LCD and format the results.

Make sense?
Re: Modbus and Arduino Question
« Reply #9 on: October 10, 2016, 02:47:49 PM »
Thanks ejjenkins