Hello Guest it is October 17, 2019, 04:52:17 AM

Author Topic: Simple tutorial on analog inputs with Arduino  (Read 40048 times)

0 Members and 1 Guest are viewing this topic.

Simple tutorial on analog inputs with Arduino
« 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
Re: Simple tutorial on analog inputs with Arduino
« Reply #1 on: January 19, 2013, 08:13:00 AM »
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
Re: Simple tutorial on analog inputs with Arduino
« Reply #2 on: January 20, 2013, 02:47:55 AM »
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.
Re: Simple tutorial on analog inputs with Arduino
« Reply #3 on: April 09, 2015, 04:08:34 PM »
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;
   }
}
/// ---------------------------------------------------------
Re: Simple tutorial on analog inputs with Arduino
« Reply #4 on: April 10, 2015, 07:24:40 AM »
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
Re: Simple tutorial on analog inputs with Arduino
« Reply #5 on: April 10, 2015, 07:51:01 AM »
Do I want to have foreign keys and 2 analog like you did in your case
thank you
greeting
Re: Simple tutorial on analog inputs with Arduino
« Reply #6 on: April 10, 2015, 11:41:53 AM »
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.
Re: Simple tutorial on analog inputs with Arduino
« Reply #7 on: April 10, 2015, 12:05:05 PM »
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);
}
Re: Simple tutorial on analog inputs with Arduino
« Reply #8 on: April 10, 2015, 12:31:07 PM »
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
Re: Simple tutorial on analog inputs with Arduino
« Reply #9 on: April 13, 2015, 12:02:29 PM »
I managed to put together two programs diginput 8 + 2analog
x + .x-.y + .y-.z + .z-.start, stop spindle% + -, feed rate + -