/* This is the control program for a milling machine
* cross and lenght sled stepper motor.
* The stepper motor is controlled by an Arduino nano bord.
* The stepper motor controller two,
* Micro Stepper M545D types stepper motor drivers
* Created by Bala Takacs
* Date 2022.01.28
* Refresh 2023.10.05
* Version 2.0
*/
// Define pins
int SW_L = 5; //Switch left pin
int SW_R = 6; //Switch right pin
int PUL = 3; //PUL pin
int DIR = 4; //DIR pin
int ENA = 12; //ENA pin
int Relay = 11; //Relay pin
int spd = A1; //Potentiometer speed
int pd = 500; //Pulse delay period
int rt = 1000; //Relay delay time
void setup()
{
pinMode(SW_L, INPUT);
pinMode(SW_R, INPUT);
pinMode(PUL, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(Relay, OUTPUT);
digitalWrite(ENA, HIGH);
}
void loop()
{
pd = map((analogRead(spd)),0,1023,0,1000);
if(digitalRead(SW_L) == 0)
{
digitalWrite(Relay, HIGH);
delayMicroseconds(rt);
digitalWrite(DIR, HIGH);
digitalWrite(ENA, LOW);
digitalWrite(PUL, LOW);
delayMicroseconds(pd);
digitalWrite(PUL, HIGH);
//delayMicroseconds(pd);
}
if(digitalRead(SW_L) != 0)
{
digitalWrite(Relay, LOW);
delayMicroseconds(rt);
digitalWrite(ENA, HIGH);
}
}
/*void loop()
{
if (digitalRead(SW_L) == 0)
{
Left();
}
}
/*define SW_L = 5 //Switch left pin
#define SW_R = 6 //Switch right pin
#define PUL = 3 //PUL pin
#define DIR = 4 //DIR pin
#define ENA = 12 //ENA pin
#define Relay = 11 //Relay pin
int spd = A1; //Potentiometer speed
int pd = 500; //Pulse delay period
int rt = 1000; //Relay delay time
void setup()
{
DDRD |= (1 << PD3); //PUL pin set OUTPUT
DDRD |= (1 << PD4); //DIR pin set OUTPUT
DDRD &= (1 << PD5); //SW_L pin set INPUT
DDRD &= (1 << PD6); //SW_R pin set INPUT
DDRB |= (1 << PB3); //Relay switch pin
DDRB |= (1 << PB4); //ENA pin set OUTPUT
PORTB |= (1 << PB4); //ENA pin set HIGH
}
void loop()
{
if((PIND & (1 << PD5)) == 0) //Switch left LOW
{
Left();
}
if((PIND & (1 << PD6)) == 0) //Switch right low
{
Right();
}
}
void Left() // Left direction
{
pd = map((analogRead(spd)),0,1023,0,1000);
if((PIND & (1 << PD5)) == 0) //Switch left LOW
{
PORTB |= (1 << PB3); //Relay pin set HIGH
delayMicroseconds(rt);
PORTD |= (1 << PD4); //DIR pin set HIGH
PORTB &=~ (1 << PB4); //ENA pin set LOW
PORTD |= (1 << PD3); //PUL pin set HIGH
delayMicroseconds(pd);
PORTD &=~ (1 << PD3); //PUL pin set LOW
delayMicroseconds(pd);
}
if((PIND & (1 << PD5)) != 0) //Switch left not equel HIGH
{
PORTB |= (1 << PB4); //ENA pin set HIGH
delayMicroseconds(rt);
PORTB &=~ (1 << PB3); //Relay pin set LOW
}
}
void Right() // Right direction
{
pd = map((analogRead(spd)),0,1023,0,1000);
if((PIND & (1 << PD6)) == 0) //Switch right HIGH
{
PORTB |= (1 << PB3);
delayMicroseconds(rt);
PORTD &=~ (1 << PD4); //DIR pin set LOW
PORTB &=~ (1 << PB4); //ENA pin set LOW
PORTD |= (1 << PD3); //PUL pin set HIGH
delayMicroseconds(pd);
PORTD &=~ (1 << PD3); //PUL pin set LOW
delayMicroseconds(pd);
}
if((PIND & (1 << PD6)) != 0) //Switch right not equel HIGH
{
PORTB |= (1 << PB4); //ENA pin set HIGH
delayMicroseconds(rt);
PORTB &=~ (1 << PB3); //Relay pin set LOW
}
}*/
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
pot1:GND
pot1:SIG
pot1:VCC
stepper1:A-
stepper1:A+
stepper1:B+
stepper1:B-
drv1:ENABLE
drv1:MS1
drv1:MS2
drv1:MS3
drv1:RESET
drv1:SLEEP
drv1:STEP
drv1:DIR
drv1:GND.1
drv1:VDD
drv1:1B
drv1:1A
drv1:2A
drv1:2B
drv1:GND.2
drv1:VMOT
relay1:VCC
relay1:GND
relay1:IN
relay1:NC
relay1:COM
relay1:NO
vcc1:VCC
gnd1:GND
relay2:VCC
relay2:GND
relay2:IN
relay2:NC
relay2:COM
relay2:NO
r1:1
r1:2
r2:1
r2:2
sw1:1a
sw1:2a
sw1:3a
sw1:4a
sw1:5a
sw1:6a
sw1:7a
sw1:8a
sw1:8b
sw1:7b
sw1:6b
sw1:5b
sw1:4b
sw1:3b
sw1:2b
sw1:1b