Hello all,
i am a newbie in the field of arduino. i was trying to control a stepper motor(with 27:1 gear ratio)(details of the motor link) with 3 buttons (1 to move it clockwise a specified number of steps, another to move it anti clockwise the same number of steps and another button to take the stepper back to the home postion from the current position).The motor is used to tilt an L bracket that could carry a load.The aim is to tilt the bracket and the load its holds by 5 degrees every time a button is pressed.Currently I have succeeded in getting all the 3 buttons do their specified job.. However when LCD(LCM1602C) is used along with this set up a problem arises. even the basic hallo word program fails .All i get is some weird special characters. I am pretty sure the connections are fine... as the motor part alone (LCD part of code commented)and the LCD part alone works perfectly fine.
Could some one kindly advice me on how to proceed.
i am also posting my code along with the post.
Kind regards
#include <Stepper.h> // Including the stepper library
#include <LiquidCrystal.h> // Including the LCD library
const int stepsPerRevolution = 200; // Depends on the specific motor
// Has to be modified if the motor is altered
const int homeButton = 7; // Naming the arduino pins
const int cwSwitch = 19; // Naming the arduino pins
const int ccwSwitch = 14; // Naming the arduino pins
const int pwmA = 3; // Naming the arduino pins
const int pwmB = 11; // Naming the arduino pins
const int brakeA = 9; // Naming the arduino pins
const int brakeB = 8; // Naming the arduino pins
const int dirA = 12; // Naming the arduino pins
const int dirB = 13; // Naming the arduino pins
boolean switchStatecw = LOW; // Delcaring the clockwise rotation switch state and initializing it
boolean switchStateccw = LOW; // Delcaring the counter-clockwise rotation switch state and initializing it
boolean switchStatehomeButton = LOW; // Delcaring the counter-clockwise rotation switch state and initializing it
long stepcounter = 0; // Delcaring variable to count the steps rotated-hels to determine the current position
//LiquidCrystal stagelcd(1, 10, 2, 4, 5, 6); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
Stepper stageStepper(stepsPerRevolution, dirA, dirB); // Initialization of the stepper library
void setup() { // The setting up function which sets the environment for the repeat loop
while (!Serial); //to delay the serial interface untill the terminal window is opened
// the Direction pins solely determine the motor rotation sense
pinMode(pwmA, OUTPUT); // Setting the pulse width modulation pin of A channel to output mode
pinMode(pwmB, OUTPUT); // Setting the pulse width modulation pin of B channel to output mode
pinMode(brakeA, OUTPUT); // Setting the brake pin of A channel to output mode
pinMode(brakeB, OUTPUT); // Setting the brake pin of B channel to output mode
pinMode(homeButton, INPUT); // Setting the home button pin to input mode
pinMode(cwSwitch, INPUT); // Setting the clockwise rotation switch pin to input mode
pinMode(ccwSwitch, INPUT); // Setting the counter-clockwise rotation switch pin to input mode
digitalWrite(pwmA, HIGH); // Setting the PWM A pin to ON state
digitalWrite(pwmB, HIGH); // Setting the PWM B pin to ON state
digitalWrite(brakeA, LOW); // Disabling the brake of A channel
digitalWrite(brakeB, LOW); // Disabling the brake of B channel
Serial.begin(9600); // initialize the serial port:
//stagelcd.begin(16, 2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
// stagelcd.print("hello, world!");
// Printing on to the serial monitor
Serial.println("Enter Custom number of steps to override the button function :");
Serial.println("positive number for clockwise rotation and negative number for counterclockwise rotation");
stageStepper.setSpeed(50); // best practise - set speed for multiple steps
} // End of setup function
void loop() { // Code that keeps repeating
switchStatecw = digitalRead(cwSwitch); // Interruptiong the continuous loop to get external input
switchStateccw = digitalRead(ccwSwitch); // Interruptiong the continuous loop to get external input
switchStatehomeButton = digitalRead(homeButton); // Interruptiong the continuous loop to get external input
if (Serial.available()) // This block of if state ment is to give the option of roationg
//the motor a custom number of steps from the serial interface
{
Serial.println("current step is");
Serial.println(stepcounter);
int serialStep = Serial.parseInt();
stageStepper.step(serialStep);
stepcounter = stepcounter + serialStep;
Serial.println("updated step is");
Serial.println(stepcounter);
}
if (switchStatecw == HIGH)
{
stageStepper.step(74);
//accestagestepper.move(74);
stepcounter = stepcounter + 74;
Serial.println("updated step is");
Serial.println(stepcounter);
}
if (switchStateccw == HIGH)
{
stageStepper.step(-74);
stepcounter = stepcounter - 74;
Serial.println("updated step is");
Serial.println(stepcounter);
}
if (switchStatehomeButton == HIGH)
{
if (stepcounter >= 0)
{
stageStepper.step(-stepcounter);
Serial.println("moving counter clockwise to Zero");
stepcounter = 0;
Serial.println("current position is");
Serial.println(stepcounter);
}
else
{
stageStepper.step(-stepcounter);
Serial.println("moving clockwise to Zero");
stepcounter = 0;
Serial.println("current position is");
Serial.println(stepcounter);
}
}
// // set the cursor to column 0, line 1
// // (note: line 1 is the second row, since counting begins with 0):
// stagelcd.setCursor(0, 1);
// // print the number of seconds since reset:
// stagelcd.print(millis() / 1000);
} //End of Loop

