Machsupport Forum
Third party software and hardware support forums. => Modbus => Topic started by: zafarsalam on November 20, 2012, 01:12:31 AM
-
Here's a simple tutorial describing the steps for setting analog input to Mach3 through Arduino. FRO and Spindle override are shown in the example. Any of the dro's in Mach3 can be controlled in this way.
Zafar
-
Good job works perfect
I am new to this and would like to put buttons and LED on the arduino but I can not run or signals the brain
can you help
Thanks
-
Good job works perfect
I am new to this and would like to put buttons and LED on the arduino but I can not run or signals the brain
can you help
Thanks
For this you'll have to make changes in arduino sketch, modbus settings and brains in Mach3. I'll get back to it in a day or two with that.
-
Hello Zafar
how to connect your analog input with this code
greeting
unsigned int CRC16, SEED, GP; //for CRC16
#define SEED 0xFFFF //initialization for CRC16
#define GP 0xA001 //generating polynomial
int in_buffer[8]; // receiving buffer
#define CycleStart 2; //MOD:0-D0
#define FeedHold 3; //MOD:0-D1
#define StopFile 4; //MOD:0-D2
#define SingleStep 5; //MOD:0-D3
#define ResumeFile 6; //MOD:0-D4
#define ZeroX 7; //MOD:0-D5
#define ZeroY 8; //MOD:0-D6
#define ZeroZ 9; //MOD:0-D7
void setup()
{
Serial.begin(9600); // Init serial communication
pinMode(2, INPUT); // Set pin to input
pinMode(3, INPUT); // Set pin to input
pinMode(4, INPUT); // Set pin to input
pinMode(5, INPUT); // Set pin to input
pinMode(6, INPUT); // Set pin to input
pinMode(7, INPUT); // Set pin to input
pinMode(8, INPUT); // Set pin to input
pinMode(9, INPUT); // Set pin to input
digitalWrite(2, HIGH); // Turn on pullup resistor
digitalWrite(3, HIGH); // Turn on pullup resistor
digitalWrite(4, HIGH); // Turn on pullup resistor
digitalWrite(5, HIGH); // Turn on pullup resistor
digitalWrite(6, HIGH); // Turn on pullup resistor
digitalWrite(7, HIGH); // Turn on pullup resistor
digitalWrite(8, HIGH); // Turn on pullup resistor
digitalWrite(9, HIGH); // Turn on pullup resistor
}
void loop()
{
if ( Serial.available() == 8 ) {
// read ModBus command from Mach3
for (int i=0; i < 8; i++) in_buffer[ i ] = Serial.read();
if ((in_buffer[0]== 0x01)&(in_buffer[1]== 0x04))
Reply_Inputs();
else
Reply_Error();
Serial.flush();
}
}
/// ----------------------- Functions -----------------------
void Reply_Inputs()
{
CRC16 = SEED;
int Inputs[] ={0x01, 0x04, 0x0A, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00};
Inputs[4] = (
((!digitalRead(9))<<7) |
((!digitalRead(8))<<6) |
((!digitalRead(7))<<5) |
((!digitalRead(6))<<4) |
((!digitalRead(5))<<3) |
((!digitalRead(4))<<2) |
((!digitalRead(3))<<1) |
((!digitalRead(2)) ) );
for (int i = 0; i < 13; i++)
{
Calc_CRC(Inputs, &CRC16);
}
Inputs[13]=CRC16;
CRC16=CRC16>>8;
Inputs[14]=CRC16;
for (int i=0; i < 15; i++) Serial.write(Inputs);
}
/// ---------------------------------------------------------
void Reply_Error()
{
int Error[] ={0x01, 0x84, 0x00, 0x43, 0x00};
for (int i=0; i < 5; i++) Serial.write(Error);
}
/// ---------------------------------------------------------
void Calc_CRC(unsigned char b, unsigned int* CRC)
{
int carry, i;
CRC[0] ^= b & 0xFF;
for (i=0; i<8; i++)
{
carry = CRC[0] & 0x0001;
CRC[0]>>=1;
if (carry) CRC[0] ^= GP;
}
}
/// ---------------------------------------------------------
-
I presume you want to use external buttons to control Mach3 through Arduino. For this you'll need to use Mach's brain too. I'll work out an Arduino sketch and the brain and post it here.
Zafar
-
Do I want to have foreign keys and 2 analog like you did in your case
thank you
greeting
-
You'll need foreign keys to short the pins 2,3,4....9 with the ground on arduino. No need to use the external pots if you don't need the fro and sso functions.
-
You'll have to make additions to the Arduino sketch like this
void setup()
{
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
}
void loop()
(
regs[0]=!digitalRead(2);
regs[1]=!digitalRead(3);
regs[2]=!digitalRead(4);
regs[3]=!digitalRead(5);
regs[4]=!digitalRead(6);
regs[5]=!digitalRead(7);
regs[6]=!digitalRead(8);
regs[7]=!digitalRead(9);
}
-
Regards To Far
I'm sad I did not understand
I want 2 analog inputs for potenciometa like you do and I make the 10 input.
Arduino cod 10 input functions
You with 2 analog inputs function. how to put them into one program Arduino cod
Brain is not a problem
Sorry for my bad english
greeting
-
I managed to put together two programs diginput 8 + 2analog
x + .x-.y + .y-.z + .z-.start, stop spindle% + -, feed rate + -
-
That's really great. I am out of country these days, so couldn't reply to your posts in time. Looks like you have figured it out yourself.
Or did you want these 8 switches on a single pot. This is possible too. Just use the map() and switch case functions in Arduino. See the command reference and examples on Arduino website.
Zafar
-
Thank you for this really great piece of arduino code! Reading arduino pins, and sending data to mach3 is awsome feature. Can you please point me on how to send data from mach3 to arduino?
I would like to send for example X position DRO value to arduino, and then print out data on display. Can I just define variable as double, and ecquire its value like this in loop:
my_variable=regs[10];
And then in mach3 brains select data input as X DRO, and then terminate as modbus address 10, and select it as Output?
Or does this code work only one way, from arduino to mach3, and some major code correction has to be done to work other way?
Thank you,
Simon
-
Zafar Bhai..u still out there?
-
Zafar Bhai..u still out there?
Yes right here in Malaysia. Will be back this Sunday.
-
hi! I need help from you zafarsalam
How to setup dro info on lcd connected to arduino modbus slave on arduino with shillings code modbus slave???
Ihave included wire.h and liquidcristali2c.h for lcd in arduino code.
From now I ned help for how to send data from mach3 -->>>brain-->>serial modbus plugin--->>>arduino modbus slave ?????
many users have this done but no documentation on arduino code, no info about serial plugin configs,
Help and thanks
-
hi! I need help from you zafarsalam
How to setup dro info on lcd connected to arduino modbus slave on arduino with shillings code modbus slave???
Ihave included wire.h and liquidcristali2c.h for lcd in arduino code.
From now I ned help for how to send data from mach3 -->>>brain-->>serial modbus plugin--->>>arduino modbus slave ?????
many users have this done but no documentation on arduino code, no info about serial plugin configs,
Help and thanks
I am out of country right now. Will give you some tips on it when back home by this weekend.
Zafar
-
Are you home Zafarsallam?
-
Yes. I am here. I haven't tried shillings code on modbus. I am using Vinny's code. You can download it from the link on this thread. I have used it to display Mach DROs on LCD screen with arduino. I'll fish out the code, tidy it up and share it here in a few days.
Zafar
-
Ok.thanks! I am waiting.
Can not find villy's code.
-
Ok.thanks! I am waiting.
Can not find villy's code.
Download the pdf file in the first post on this thread. The links are in there.
-
???[/img]Hello, how can I add jog c ++? I have used arduino, mach3, modbus. In the current mach3 I have added jogx ++, jogx, jog y ++, jogy, jogz ++, jogz -, joga ++, joga -,What is your email? I am 1040373253@qq.com
-
???[/img]Hello, how can I add jog c ++? I have used arduino, mach3, modbus. In the current mach3 I have added jogx ++, jogx, jog y ++, jogy, jogz ++, jogz -, joga ++, joga -,What is your email? I am 1040373253@qq.com
Use ButtonPress as the terminal lobe. Scan code 331 and 332 are for Jogging C axis.
Zafar
-
???[/img]Hello, how can I add jog c ++? I have used arduino, mach3, modbus. In the current mach3 I have added jogx ++, jogx, jog y ++, jogy, jogz ++, jogz -, joga ++, joga -,What is your email? I am 1040373253@qq.com
Use ButtonPress as the terminal lobe. Scan code 331 and 332 are for Jogging C axis.
Zafar
Thanks, I got it out. But I used the picture, the effect is very good
-
Hello Zafar..i'm a newbie on this, where can I get Vinys code? and should I just upload it to a clean Uno?
-
Download links are right there in the tutorial pdf.
Hello Zafar..i'm a newbie on this, where can I get Vinys code? and should I just upload it to a clean Uno?
-
Thanks , could you give me direcions if is it possible to use a digital trigger in modbus?
-
I Know this thread is old, but its exactly the information looking for - i just need some help on the subject - hopefully yall are still around. I did this mod, and it works great, only issue is the values are bouncing around very erratically. is there a fix for this? is it normal? will this cause issues in my programs with so many abrupt changes to feed rate and spindle speed?
-
Hi there,
I see this has been posted ages ago.
I want to do something similar with a ATC. It should send an integer value between 1 to 12 to the arduino every time it encounters the M6 Gcode
ex. M6 T0101 - should send "1" to the arduino.
Any idea how to do this?
-
hi zafarsalam, i am a new user too, i found your work on the application of potentiometers very useful and beautiful.
I tried to implement the code to add control buttons but failed.
I started from your sketch I implemented the entries but there is no way to make the buttons work.
Could you kindly explain to me and tell us where to go to edit the sketch?
-
I solved