The Shop > Electronics & IC Programing

Arduino programming, Mega 2560 ADK

<< < (3/4) > >>

Dawai:
Hi.

  thoughts?  I got a pair of $20 (UNO) micro controllers coming, three $12 lcd's displays with buttons made onto them, one for the one I have. Still need a Stepper drive and dc power supply, motor, gear train?? (sprockets and belts?)

  I have been doing the software for various things learning how to use them, write the programs. There are several people online running dividers, indexers with them. But most are "stingy" with the code. they want money for their work I guess?
  First two projects are definite, EDM is built, wires hanging out, capacitor bank, transformers SSR wired. I was modding it and missed out on a job recently with it.

/********************** project 1, division head, indexer ****************************
Variables in a divider head program..
Divisions of 360 degrees?
degrees to run per move,
steps per degree (for motor control, geckos have 10x micro-steps)
acceleration factor (for taking off smooth) (angle calc or add per step?)
Accel distance
deceleration factor (for stopping smooth) (angle or calc per step??)
Decel distance
Direction to run
Minimum speed
Maximum speed
Pulse width for drive (stepping)
Pulse width for direction

Button to move, or?? how to trigger a movement??
 
 MENUS on screen, move degrees? division? set up parameters, but it loses this each time it turns off.. so?? keep a battery in the system or?? I can add a SD camera card and read it??  more money , more complication.

NOW some of these things that have to be programmed must be done so according to the gear ratio of the motor to degrees turned.  Looking at one guy he used a laser pointing (bolted on) at a wall 20 feet away to get his "zero" and calculate the steps in a 360 degree movement.. "that figures out how I can calibrate my A axis here" too tied into my milling machine.

Components, $20 arduino, $12 LCD-keypad, box, Power supply, motor, gearbelt, pulleys, SD Card & reader?? opto22 PB4 card, modules.

//*********************************** project 2, control-timer for spot welder *****************************
MY SPOT welder Timer-control..
Wait on button-foot pedal.
TIME to solenoid clamp
SSR weld current on
time to weld current
time-out, turn off weld SSR
foot pedal up, release solenoid
repeat.
Transformer heat temperature?? display??

Components, $20 Arduino, $12 LCD-keypad, power supply, SSR, solenoid, air regulator, electrical box, PB4 opto22 card, foot switch, SJ cord, cord connectors, Thermistor?.

/****************************************************************************************
/********************* Project 3, EDM ******************************************************
Variables,

Distance to descend,
steps per inch
current to flow
Spark time
voltage bus read    (analog input)
voltage bus charge  (PWM output SSR)
voltage bus discharge (pwm output SSR)
coolant flow
Home switch
Capacitors heat.
transformers main switch (relay with safety)


//**************************** Spark welder, electrical discharge ********************************
Modded into edm previously..

//**************************** Carbide depositor *********************************************
reverse EDM polarity, CnC stipple requires multiple axis movements, co communication with Mach3 & Windows interface

//**************************** David Laser scanner drive ****************************************
Tilt laser servo,
rotary table
cnc table control w/Mach3 & Windows interface
Windows API call, camera interface w Mach3

//**************************** Laser pulse modulation, heat control ***********************************

Dawai:
Code runs for the SPOT welder sequence control..
UNO microControllers will be here next week, LCD's not wrote software for.
THIS prints the operation as now to the laptop..
Using a SSR (solid state relay), a opto22 PB4 rack, ODC modules, 24vdc solenoid to operate the clamp cylinder to clamp metal in HF (chinese) spot welder.

PROBLEM, spot welder has a very low duty factor, using automation it gets hot fast. Need to blow air through it, and monitor temperature with a thermistor, in the future..

THE working arduino code, as of this morning. cut, paste, modify the pins to suit your arduino model and connections, flip logic if your ttl boards are positive sourcing based instead of sinking logic.





/* Written by Cofer, NORF Gawgia, USA on 12-29-13
  I Modified code for creating a sequence timer for a spot welder, this unit
first applies a solenoid output to clamp the spot welder tongs, then times to close fully
and apply pressure, then the SSR fires for a timed output, the SSR times out then
the unit loops on one line till you lift your footpedal switch, then it resets to
the beginning of the program to loop for next sequence. THIS unit uses a PB4 Opto22
ttl-relay module based board, it SINKS the TTL power to turn on the modules, so it
appears reversed, would be if your output device is different.

 * Note: because most Arduinos have a built-in LED attached
 to pin 13 on the board, the LED is optional.
 */
int ledPin = 13;      // select the pin for the onboard LED
//int ClampTime = 0;  // variable to store the value coming from the sensor
int button1 = 38;  // change to reflect pins on the UNO
int button2 = 39;
int Solenoid1 = 48;
int SSR1 =49;
int footpedal = 41;
int buttonstate1;
int buttonstate2;
int Clamp_flg;

// variables for Timer variables
int ClampTime = 1000; // setpoint for clamp timer
int WeldTime = 5000 ; // variable for weld timer


void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
  pinMode(Solenoid1,OUTPUT);
  pinMode(SSR1,OUTPUT);
   pinMode(button1,INPUT);
   pinMode(button2,INPUT);
   pinMode(footpedal,INPUT);
  Serial.begin(19200);
  digitalWrite(Solenoid1,HIGH);
  digitalWrite(SSR1,HIGH);
 
}
void loop() {
     Clamp_flg = 1; // set the flag
 // alter setpoint in this menu
  if (digitalRead(button1) == HIGH and digitalRead(button2) == LOW ) {
    ClampTime = ClampTime + 10;
    Serial.println(ClampTime);
    delay(150);
  }
 
  if (digitalRead(button2) == HIGH and digitalRead(button1) == LOW ) {
    ClampTime = ClampTime - 10;
    Serial.println(ClampTime);
    delay(150);
  }
 
  if (ClampTime < 500){
   ClampTime = 500;
  }
 
   if (ClampTime > 5000 ){
   ClampTime = 5000;
  }
 
  // if foot switch then cycle turn the ledPin on
  while (digitalRead(footpedal) == LOW ) {
 
   
      Serial.print( " clamp solenoid on ");
      Serial.println(ClampTime);
      digitalWrite(ledPin, HIGH ); 
      // TURN ON SOLENOID to clamp
      digitalWrite(Solenoid1,LOW);
      delay(ClampTime);         
      // turn the ledPin off:       
      digitalWrite(ledPin, LOW);
      // TURN ON SSR 
      digitalWrite(SSR1,LOW);
      Serial.print(" Welding time ");
      Serial.println(WeldTime);
      delay(WeldTime);
      // OFF SSR
      digitalWrite(SSR1,HIGH);
      Serial.println(" Remove foot from pedal ");
     
      while (digitalRead(footpedal) == LOW );
      // stay here till footpedal up
      // OFF SOLENOID clamp
      digitalWrite(Solenoid1,HIGH);
     
  } 
}

RodW:

--- Quote --- MENUS on screen, move degrees? division? set up parameters, but it loses this each time it turns off.. so?? keep a battery in the system or?? I can add a SD camera card and read it??  more money , more complication.
--- Quote ---
I started with a rotary table Controller but got side tracked and never got back to It. I was able to add an SD card and a display to the ARDUINO.

The  ARDUINO, even the basic ones, have some flash RAM that you can use to permanently store system parameters.

There are some details on this forum about what I did. One day I will return to it...







--- End quote ---

--- End quote ---

Dawai:
Hi.
  THE divider is not as complicated project as I made it, I am working on it.

THE sainsmart lcd keypad came in, Squirrels in the CHINGLISH translation.
Pins are not exactly what they should set up as, THE drivers for #include libraries had me puzzled, they have to be in exactly the right directory to not give a error.  Had me scratching my head for a bit. Working great, highly visible 16x2 display with 5 useable buttons, one reset.. (blind man could hardly see) They throw a analog signal by using resistors, different numbers come back and the driver chooses what input.

I got a pretty good grasp of the millisecond timer now thou, grab it as a millis() call..store it in a variable, then compare to actual-desired time instead of locking the program in a "STOP RIGHT HERE" delay(ms) loop.  This will come in handy throwing a 6ms pulse to the stepper drive step pin..

Spot welder code works good enough to put in, I am awaiting the uno's to implement it. I'll start fabbing a panel for it.

'*************** code rewritten this morning 12-31-13 *****
/* Written by Cofer, NORF Gawgia, USA on 12-29-13
  I Modified code for creating a sequence timer for a spot welder, this unit
first applies a solenoid output to clamp the spot welder tongs, then times to close fully
and apply pressure, then the SSR fires for a timed output, the SSR times out then
the unit loops on one line till you lift your footpedal switch, then it resets to
the beginning of the program to loop for next sequence. THIS unit uses a PB4 Opto22
ttl-relay module based board, it SINKS the TTL power to turn on the modules, so it
appears reversed, would be if your output device is different. 12/31/13 Modified to
use the sainsmart keypad LCD. It connects A0 analog to buttons divided by resistors
to differentiate the buttons in voltages into the analog input. DF Robot code, plus
SainSmart Code, plus mine added by cut and paste.
(millis()/1000)
 */
#include <LiquidCrystal.h> // include this library of lcd operations
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,13,9,4,5,6,7);// Set up for my MEga 2560 pins
//**************************************************
int button1 = 38;  // change to reflect pins on the UNO
int button2 = 39;  // change button
int Solenoid1 = 48; // air solenoid clamp for welder
int SSR1 =49;       // SSR welder output   
int footpedal = 41; // foot pedal input
int buttonstate1;   // variable to store state in.
int buttonstate2;
int Clamp_flg;
long startTime;
long endTime;
//******************************************
// variables for Timer variables
int ClampTime = 9000; // setpoint for clamp timer
int WeldTime = 3000 ; // variable for weld timer
// set up the analog input pin for keypad
//int sensorPin = A0;    //
//int sensorValue = 0;  // variable to store the value coming from the sensor
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
// read the buttons ***************************
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 // input for analog voltage divider, multiple inputs for one A-Input
 if (adc_key_in < 50)   return btnRIGHT;
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT; 
 return btnNONE;  // when all others fail, return this...
}
void setup() {
   // set up the LCD's number of columns and rows:
  lcd.begin(16,2);  // set up the display type
  // Print a message to the LCD.
  lcd.print(0x00); // display off
  //delay(50);
  lcd.print(0x04); // display on
  lcd.print(0x01); // clear the display
  lcd.print(0x02); // reset to home
  lcd.print(0x04);
 // set up pins, inputs outputs
  pinMode(Solenoid1,OUTPUT);
  pinMode(SSR1,OUTPUT);
   pinMode(button1,INPUT);
   pinMode(button2,INPUT);
   pinMode(footpedal,INPUT);
  //Serial.begin(19200);
  digitalWrite(Solenoid1,HIGH);
  digitalWrite(SSR1,HIGH);
  //SetupScreen;
     lcd.setCursor(0, 0);
     lcd.print("Clamp Time "+ String(ClampTime));
     lcd.setCursor(0,1);
     lcd.print("Weld time  " + String(WeldTime));
     
     }
void loop()
{
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.setCursor(11, 0);
     lcd.print("     ");  //blank the space
     ClampTime = ClampTime + 10;
     lcd.setCursor(0, 0);
     lcd.print("Clamp Time " + String(ClampTime));
     delay(200);
     break;
     }
   case btnLEFT:
     {
     lcd.setCursor(11, 0);
     lcd.print("     ");  //blank the space
     ClampTime = ClampTime - 10;
     lcd.setCursor(0, 0);
     lcd.print("Clamp Time " + String(ClampTime));
     delay(200);
     break;
     }
   case btnUP:
     {
     lcd.setCursor(11, 1);
     lcd.print("     ");  //blank the space
     WeldTime = WeldTime + 10;
     lcd.setCursor(0,1);
     lcd.print("Weld time  " + String(WeldTime));
     delay(200);
     break;
     }
   case btnDOWN:
     {
     lcd.setCursor(11, 1);
     lcd.print("     ");  //blank the space
     WeldTime = WeldTime - 10;
     lcd.setCursor(0,1);
     lcd.print("Weld time  " + String(WeldTime));
     delay(200);
     break;
     }
   case btnSELECT:
     {
     //lcd.print("SELECT");
     Clamp_flg = 1; // set the flag
     break;
     }
     case btnNONE:
     {
     //lcd.print("NONE  ");
     break;
     }
 }
//******Confirm variables in tolerance
      if (WeldTime > 9999){
       WeldTime = 9999;
       }
       if (WeldTime < 500){
       WeldTime = 500;
       }
       if (ClampTime > 9999){
       ClampTime = 9999;
       }
       if (ClampTime < 500){
       ClampTime = 500;
       }
   
     
 
 
  // if foot switch then cycle turn the ledPin on
  while (Clamp_flg == 1){
  //while (digitalRead(footpedal) == LOW ) { // appears reversed logic
     // digitalWrite(ledPin, HIGH ); 
      // TURN ON SOLENOID to clamp
        startTime = millis(); 
        endTime = (ClampTime + millis());
        digitalWrite(Solenoid1,LOW);
     lcd.clear(); // clear the display
    while (millis() < endTime) {   
       lcd.setCursor(0, 0);
       lcd.print("Solenoid on " + String(endTime - millis()));
     delay(500); // slow down screen update
    }
      lcd.setCursor(0, 0);
      lcd.print("CLAMPED        ");
               
           
      // TURN ON SSR and count down 
      startTime = millis(); 
      digitalWrite(SSR1,LOW);  // turn the SSR module on
      endTime = (WeldTime + millis());
     
     while (millis() < endTime) {   
       lcd.setCursor(0, 1);
       lcd.print("SSR on " + String(endTime - millis()));
     delay(500); // slow down screen update
    }     
      // OFF SSR
      digitalWrite(SSR1,HIGH);
    // clean up display, status   
     lcd.clear(); // clear the display
     lcd.setCursor(0, 0);
     lcd.print("Solenoid on     ");
     lcd.setCursor(0, 1);
     lcd.print("SSR off         ");
    delay(5000);
      // stay looping here till pedal up
//while (digitalRead(footpedal) == LOW );
      // stay here till footpedal up
      // OFF SOLENOID clamp
      digitalWrite(Solenoid1,HIGH);
     //************ reset the screen *****
     lcd.clear();     
     lcd.print("Input Ready ");
     delay(5000);
     lcd.clear();     
     lcd.print("Clamp Time " + String(ClampTime));
     lcd.setCursor(0,1);
     lcd.print("Weld time  " + String(WeldTime));
     //************  reset the flag *********
      Clamp_flg = 0; // set the flag
     
  } 
}

Dawai:
division head software, good enough to run.
Will do a electrical drawing in a day or so, have to go visit some folks today.
I'd sure like to learn how to address the non-violatile memory ram in a arduino.
Perhaps I will make that tonights puzzle.. to figure out.

CODE written this morning.. using drivers to drive the lcd-keypad and stepper motor.. configuration of stepper is inline with beginning of code in pins, accel, max speed.. etc..
currently 10k long, UNO I purchased has 32k ram??? (due next week) tested on a mega 2560 and lcd-keypad, no steppers tied to it.
'*********** code starts here, cut and paste into arduino ide *******
/* Written by Cofer, NORF Gawgia, USA on 1-1-13
  divider runs a stepper motor, Much simplified by drivers
 */
#include <LiquidCrystal.h> // include this library of lcd operations
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,13,9,4,5,6,7);// Set up for my MEga 2560 pins
#include <AccelStepper.h>  // library to simplify the stepper mtr, drive
int AstepPin = 3;     // pin to pulse stepper drive
int AdirPin = 4;       // pin to turn on direction on stepper drive
long maxSpeed = 200000;      // max speed to driver
long accel = 2000;           // accel to driver
long realTime;      // floating timem to calculate delay from 
int aDiv = 10;         // number of steps to travel
long aDist = 0;       // product of 360degrees x stepsPerdegree div divisions
long aLoc;           // location in array of steps
long stepsPerdegree = 200;  // mechanical steps per degree ratio
boolean forrev;       // forward, reverse pin on stepper
boolean runButton;
boolean runFlg;
long endTime;
long updateScreen = 100;
// Define, 2=1st pos denotes 2 wire step & pulse or 4=4 coil driver
// second varible denotes first arduino pin
// third varible denotes second arduino pin
// fourth varible denotes third arduino pin
// fith varible denotes fourth arduino pin
AccelStepper stepper(2,AdirPin,AstepPin,5);
/* accelStepper(2Wire,pin1,pin2,pin3,pin4)*/
//**************************************************
//******************************************
// set up the analog input pin for keypad
//int sensorPin = A0;    //
//int sensorValue = 0;  // variable to store the value coming from the sensor
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
// read the buttons ***************************
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 // input for analog voltage divider, multiple inputs for one A-Input
 if (adc_key_in < 50)   return btnRIGHT;
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT; 
 return btnNONE;  // when all others fail, return this...
}
void setup() {
   // set up the LCD's number of columns and rows:
  lcd.begin(16,2);  // set up the display type
  //SetupScreen;
  // steps per degree??  Used to calculate steps to travel
  // maxSpeed??   Used to set speed at stepper moves
  // 360 multiply "steps per degree"  div divisions is "distance to travel"
    stepper.setMaxSpeed(maxSpeed);
    stepper.setAcceleration(accel);
     lcd.clear(); // clear the display
     lcd.setCursor(0, 0);
     lcd.print("Max Speed "+ String(maxSpeed));
     lcd.setCursor(0,1);
     lcd.print("accel  " + String(accel));
     delay(3000);
     lcd.clear(); // clear the display
     lcd.setCursor(0, 0);
     lcd.print("Pulses per degree ");
     lcd.setCursor(0,1);
     lcd.print(stepsPerdegree);
     delay(3000);
     lcd.clear(); // clear the display
     lcd.setCursor(0, 0);
     lcd.print("Step pin "+ String(AstepPin));
     lcd.setCursor(0,1);
     lcd.print("DIR pin " + String(AdirPin));
     delay(3000);
         
     
     endTime = millis(); // set the first screen update
     }
     
     
// main program loop     
void loop()
{
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
  // ********************* Right button ******************
   case btnRIGHT:
     {
     lcd.setCursor(11, 0);
     lcd.print("     ");  //blank the space
     aDiv = aDiv + 1;
     lcd.setCursor(0, 0);
     lcd.print(" Divisions " + String(aDiv));
     delay(1000);
     break;
     }
   //*************** Left Button *********************** 
   case btnLEFT:
     {
     lcd.setCursor(11, 0);
     lcd.print("     ");  //blank the space
     aDiv = aDiv - 1;
     lcd.setCursor(0, 0);
     lcd.print("Divisions " + String(aDiv));
     delay(1000);
     break;
     }
   //******** up button *** 
   case btnUP:
     {
     lcd.setCursor(11, 1);
     lcd.print("     ");  //blank the space
     maxSpeed = maxSpeed + 10;
     lcd.setCursor(0,1);
     lcd.print("Max Speed  " + String(maxSpeed));
     delay(500);
     break;
     }
   //********************* down button ****** 
   case btnDOWN:
     {
     lcd.setCursor(11, 1);
     lcd.print("     ");  //blank the space
     maxSpeed = maxSpeed - 10;
     lcd.setCursor(0,1);
     lcd.print("Max Speed  " + String(maxSpeed));
     delay(500);
     break;
     }
  //******************** Select button *****   
   case btnSELECT:
     {
     //lcd.print("SELECT");
     //** move code here
      if (stepper.distanceToGo() == 0){
       // Make sure we dont get 0 speed or accelerations
   delay(5);
        // math 360 multiply stepsPerdegree div divisions
        aDist = (((360 * stepsPerdegree) / aDiv) + stepper.currentPosition());
   stepper.moveTo(aDist); // set the driver distance to go
        delay(200);  // pause to reflect only one button press.
      }
     
     //************************
     break;
     }
    //******************* no button ***************************
     case btnNONE:
     {
     //lcd.print("NONE  ");
     break;
     }
 }   
 
//******Confirm variables in tolerance
      if (aDiv > 3600){
       aDiv = 3600;
       }
       if (aDiv < 2){
       aDiv = 2;
       }
       if (maxSpeed > 200000){
       maxSpeed = 200000;
       }
       if (maxSpeed < 50){
       maxSpeed = 50;
       }
    //************ reset the screen *****
   
        //timed loop to only update the screen so often 
        stepper.run(); // turn it over to the driver, update it
       
    if (millis() > endTime ) {   
       lcd.clear(); // clear the display
        lcd.setCursor(0, 0);
        lcd.print("Divisions " + String(aDiv));
        lcd.setCursor(0, 1);
        lcd.print("Steps " + String(stepper.distanceToGo()));
        delay(10);
        endTime = (updateScreen + millis());
    }       
                 
     
 
}

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version