Hello Guest it is April 25, 2024, 11:44:17 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - M2rt

Pages: 1
1
Modbus / Re: My experiments with Mach3 ModBus and Arduino, Part I
« on: March 08, 2015, 10:34:10 AM »
Hi
Here arduino code. I had two arduinos, on in remote and other connected to computer with mach3 and radio link between.
Some of the comments ar in estonian.
CNCpult_rc2.ino is remote control unit code, can be connected directly to computer usb.
Used two arduino micro's.

good luck!

2
Modbus / Re: My experiments with Mach3 ModBus and Arduino, Part I
« on: January 08, 2014, 03:22:57 PM »
Is there simple way to control machine axis with analog joystick in brain?  ???

3
Modbus / Re: My experiments with Mach3 ModBus and Arduino, Part I
« on: January 08, 2014, 02:26:14 PM »
In case you want to use this library with Arduino Leonardo or Micro, you can use this library files.

Sorry abut my english.

4
Modbus / Re: My experiments with Mach3 ModBus and Arduino, Part I
« on: January 08, 2014, 01:53:30 PM »
Hi!
Thank you of this info. I'm building wireless remote controller for my router and this helped me to get started.

This remote controller what I'm building have, around 20 function buttons (under every button can save 2 functions), one analog joystick for X/Y jog, one potentiometer for feed override, small encoder for precise axis movement and 2x16 LCD screen for pos. info (bit to small).

First I tried to modify arduino code from this thread, but I wasn't able to increase the amount of modbus registers. Seemed to be some issue with arduino Serial.write.

Then I searched Arduino modbus library. I founded this library: SimpleModbusSlave http://code.google.com/p/simple-modbus/downloads/detail?name=SimpleModbusSlaveV8.zip&can=2&q=label%3AFeatured

It works me very well so I like to share it!  :)

It only suports modbus holding registres, but its ok atleast for me. If you want to use it with Arduino Leonardo or Micro ( as I did) then you need to modify this library. Otherwise serial over USB does not work.

Here one sample how to use this:

Arduino code:
Code: [Select]
// 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 info 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, holdingRegs);
//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);   //can be up to 15
  else bitClear(rcd[0],2);

  //Potens´iometers:
  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:
   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, 0);
   lcd.print("                ");
   lcd.setCursor(0, 0);
   lcd.print("X");
   lcd.setCursor(0, 1);
   lcd.print(Xpos);
   lcd.setCursor(0, 8);
   lcd.print("Y");
   lcd.setCursor(0, 9);
   lcd.print(Ypos);
   lcd.setCursor(1, 0);
   lcd.print("        ");
   lcd.setCursor(1, 0);
   lcd.print("Z");
   lcd.setCursor(1, 1);
   lcd.print(Zpos);
   */
}

Mach3 settings and test images :

Pages: 1