0% found this document useful (0 votes)
2K views

Arduino Code For SimpleModbusSlave

testing code for Arduino Code for SimpleModbusSlave communication protocol to communicate with Mach3 CNC software

Uploaded by

tacho_inc41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Arduino Code For SimpleModbusSlave

testing code for Arduino Code for SimpleModbusSlave communication protocol to communicate with Mach3 CNC software

Uploaded by

tacho_inc41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Modbus:

#include <SimpleModbusSlave.h> //http://code.google.com/p/simple-modbus/


const int HOLDING_REGS_SIZE = 22; // I use 22 registers, first 11 for sendidng i
nfo to Mach3
//and next 11 registers for receiving info from Mach3
unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array
int rcd[11]; //holds sending info
int mcd[11]; //holds received info
void setup(){
pinMode(13, OUTPUT); //indicator LED
//modbus_configure(&Serial, 115200, SERIAL_8N2, 2, 13, HOLDING_REGS_SIZE, hold
ingRegs);
//2 is slave address, 13 is indicator led pin (useless)
// with Arduino Micro I used modified library files and this line:
//modbus_configure(115200, SERIAL_8N2, 2, 13, HOLDING_REGS_SIZE, holdingRegs);
}
void loop(){
//Reads buttons:
if(digitalRead(4) == 1) bitSet(rcd[0],0);
else bitClear(rcd[0],0);
if(digitalRead(5) == 1) bitSet(rcd[0],1);
else bitClear(rcd[0],1);
if(digitalRead(6) == 1) bitSet(rcd[0],2);
else bitClear(rcd[0],2);
//Potensiometers:
rcd[3] = analogRead(A0);
rcd[4] = analogRead(A1);
//Other variables:
rcd[1] = 0x1111;
rcd[2] = 0x2222;
rcd[5] = 0x3333;
rcd[6] = 32767;
rcd[7] = 12345;
rcd[8] = 54321;
rcd[9] = 0;
rcd[10] = 1;
//Sending and receiving info:
for (int i=0; i < 11; i++)
holdingRegs[i] = rcd[i];
modbus_update();
for (int i=0; i < 11; i++)
mcd[i] = holdingRegs[i+11];
/* Writes cordinates to LCD:

//can be up to 15

float Xpos = mcd[0]+(mcd[1]/100.00);


float Ypos = mcd[2]+(mcd[3]/100.00);
float Zpos = mcd[4]+(mcd[5]/100.00);
lcd.setCursor(0,
lcd.print("
lcd.setCursor(0,
lcd.print("X");
lcd.setCursor(0,
lcd.print(Xpos);
lcd.setCursor(0,
lcd.print("Y");
lcd.setCursor(0,
lcd.print(Ypos);
lcd.setCursor(1,
lcd.print("
lcd.setCursor(1,
lcd.print("Z");
lcd.setCursor(1,
lcd.print(Zpos);
*/
}

0);
");
0);
1);
8);
9);
0);
");
0);
1);

You might also like