Hello Guest it is April 28, 2024, 12:37:46 PM

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 - TheSuperior

Pages: « 1 2 3 4 »
11
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 28, 2022, 02:12:37 PM »
another thing, as I'm using Arduino mega with a CNC shield mounted at the top. Won't this interfere ?

12
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 28, 2022, 01:49:45 PM »
In the Arduino sketch you can do an if statement in the main loop. You can read the value of a register from Mach3 modbus or the state of a pin which can be connected to an output pin from Mach.

In the tool change macro you can either turn an output on and off to signal the arduino to start the tool change sequence. Or change the value of a user DRO which can be read in brains and then to modbus. Then you can do a while statement in the tool change macro which waits for the input from Arduino to finish the tool change macro.

So I'm trying to figure out how to do this,
in the m6start macro should i use sendserial() ?

Please help with what the if statement needs to contain?
In the sketch:

if (txenpin > 1) { // pin 0 & pin 1 are reserved for RX/TX
                Txenpin = txenpin; /* set global variable */
                pinMode(Txenpin, OUTPUT);
                digitalWrite(Txenpin, LOW);
        }

Do I have change these pins to use 18 and 19?

unsigned int Txenpin = 0;        /* Enable transmission pin, used on RS485 networks */

Then here is the code I use to capture the serial input. How do I modify this to capture what modbus sends or will it work as is?

void ReceiveData() {

  while (Serial.available()) {
    BlinkPattern(); 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
    //Serial.println(readString);  //so you can see the captured string
    //int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    Input = atoi(carray);
   
    readString="";
  }
 
}

13
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 28, 2022, 12:45:06 PM »
Thank you TPS. This seems as though it could be useful.

14
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 27, 2022, 02:27:47 PM »
I finally managed to rewrite the entire code without a single delay in it. Oky, let me see if I can follow, although I'd like to read the value of a register from Mach3 modbus? From value 1 to 12?  So then change the value in the user DRO which can be read in brains and then to modbus? Still I have no idea how to start writing that or incorporating it?

15
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 27, 2022, 07:19:54 AM »
So it only stops during the Delay() ? In that case it would not matter would it? As the arduino would wait for the serial Input? after that the Arduino executes the move completely independent of Mach3 and then continues again? I have added code in the m6tstart macro to move the tool changer away from the job, so the Arduino won't need to signal mach3 when it is done either as this will take some time to execute? after the change is done it can just run through the loop again and wait for the next command or tool change? Or am I completely wrong here? I feel I'm getting just so close yet so far. You have really been a great help, Thank you. I'm not sure what my next step is?

16
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 27, 2022, 03:14:10 AM »
Do you think the code inside of the setup will matter? the Delay() ? As those will only run with the initial startup? Also what is the reason for the program not to have the Delay() functions? how does this affect Mach3 exactly?

Furthermore if I figured out how to rewrite everything using timers? What else should I do in order to integrate this with your code?

17
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 26, 2022, 01:21:27 PM »
I did try that, after a lot of trial and error I managed to workout a  timer but the code does not work well in the loop as it becomes extremely slow.

The stepper library can not move the motor in the setup where the homing takes place either, so that is not going to work?

I wrote this sketch to test it before I add it to the main sketch and it works well as is:

//Include the Stepper library
#include <AccelStepper.h>

// Time periods between steps in milliseconds
const unsigned long Stepinterval =1;

const int solenoidPin = 53; //This is the solenoid output pin

const int home_switch = 52; // Pin 52 connected to Homing Switch (Sensor)

const byte stepPin = 2;
const byte dirPin = 5;
const byte enablePin = 8;

int StopHoming = 0;

// Variable holding the timer value so far.
unsigned long Steptimer;

AccelStepper x_stepper(AccelStepper::DRIVER, stepPin, dirPin);

void setup ()
  {

    Serial.begin(9600);
    pinMode(enablePin, OUTPUT);
    digitalWrite(enablePin, LOW);
    pinMode(solenoidPin, OUTPUT);
   
  Steptimer = millis ();
 
           

  }  // end of setup

void MoveStepper ()
  {
    digitalWrite(dirPin, HIGH);
   if (digitalRead (stepPin) == HIGH)
      digitalWrite (stepPin, LOW);
   else
      digitalWrite (stepPin, HIGH);

  Steptimer = millis (); 
 
  }  // end of MoveStepper



void loop ()
  {
   
                  if (!digitalRead(home_switch)==LOW){
                      if ( (millis () - Steptimer) >= Stepinterval){
                          MoveStepper ();         
                      }
}

}  // end of loop

But if I add it to my main sketch it's just extremely slow and has to run through the loop the whole time. It seems with controlling the motor and trying to home it there just is no alternative then delay() ?

18
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 26, 2022, 09:32:22 AM »
So i received this feedback from a user on the arduino forums:

A while loop is blocking by its very nature and a delay() in a while loop magnifies the length of the blocking

The solution is to use an if instead of a while and millis() for timing. No doubt you have seen the BlinkWithoutDelay example which uses this method

So, your code would in essence look like this

if the switch is activated
  if the step period has elapsed as measured using millis
    take a step
    save the time of the step
  end if
end if

A Timer is non-blocking and will also allow other code to run while this one is running which could be catastrophic as the ATC uses a solenoid pin, therefore is there any way to replace the Delay() and make it non-blocking code but not run the rest of the loop? any other method or function?

19
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 26, 2022, 09:05:25 AM »
Also I'm using a Mega with a CNC shield. It will not be possible for me to use pins 0 and 1

20
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 26, 2022, 09:04:27 AM »
Ah excellent, I'll purchase one of those, thank you.

The plan is:

The tool changer should be a standalone accesory for normal manual lathe operation as well. In other words. You can add it to any Lathe that is not CNC and use either the app, the buttons or the digital to control it. so I want to use an automatic tool changer on our lathes that are not CNC. I have been working on these Lathes for about 12 years now and even with a quick change it can really sometimes be a pain... It is just to make life a bit easier, and expand my knowledge in doing so. Oh and also make the wife angry... Also I want to be able to incorporate it on other systems as well such as GRBL. I'm a mechanical Engineer, so designing everything is pretty easy but when it comes to the programming side I really lack the skills and I consider myself to be a "noob" as they call it.

I have attached my arduino sketch.

I have read some posts about the timers and see now that the Delay() function is a really bad way to code. I'd say one of my biggest problems are where I move the stepper motor each step at a time and checking when my limit switch was activated. How do I replace those delays with a non-blocking timer? this is the segment of code I'm referring to:

while (!digitalRead(home_switch)==LOW) { // Do this until the switch is activated

    digitalWrite(dirPin, HIGH);
    digitalWrite(stepPin, LOW);
    delay(delayTime);                       
    digitalWrite(stepPin, HIGH);
    delay(delayTime);                       
   
  }

Also I have attached the sketch in txt format if you would like to give some pointers of where to start and incorporate this with your modbus sketch.

Pages: « 1 2 3 4 »