In my project for rotating the filter disc i am using a stepper motor, this motor will have a well defined home position by using hall effect sensor. I want to rotate the motor shaft 60 deg when it receives command from the LabView(VISA).
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. I would recommend using the technique in the third example.
Most stepper motors have 200 steps per revolution and cannot give exactly 60 deg. They could move either 33 or 34 steps. If you use microstepping the error will be smaller.
Thanks for the reply. I don't need exact 60 degrees with small error is Ok. I am using a hall effect sensor for obtaining the home position. After reaching the home position the motor has to rotate 60 degree whenever i give command from LabVIEW.
Janatagarage:
I am using a hall effect sensor for obtaining the home position. After reaching the home position the motor has to rotate 60 degree whenever i give command from LabVIEW.
Have you studied the links I gave you?
Have you written short Arduino programs to {a} move the stepper to the HOME position and {b} to move it N steps without any connection to LabView?
Then write a short program to receive data from LabView without any attempt to drive any motors.
#include <Stepper.h>
#include <CustomStepper.h>
const int hallPin = 12; // the number of the hall effect sensor pin1 for defining the home position
//const int hallPin2 = 14; // the number of the hall effect sensor pin2 for calculating no of levels the disc has to rotate
const int ledPin = 13; // the number of the LED pin
int hallState = 0; // variable for reading the hall sensor status
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); // initialize the stepper library on pins 8 through 11
CustomStepper stepper(8, 9, 10, 11);
void setup() {
myStepper.setSpeed(60); // set the speed at 60 rpm:
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
pinMode(hallPin, INPUT); // initialize the hall effect sensor pin as an input:
Serial.begin(9600); // initialize the serial port:
}
void loop() {
//stepper.run();
// read the state of the hall effect sensor:
hallState = digitalRead(hallPin);
if (hallState == LOW)
{
// turn LED on:
digitalWrite(ledPin, LOW);
Serial.println("HOME Position");
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
}
else
{
// turn LED off:
digitalWrite(ledPin, HIGH);
stepper.setDirection(STOP);
}
}
You can't have two stepper libraries at the same time.
Repair this and then you have to decide, if and what microstepping you will use.
Let's suppose, you use 1/4 microstepping.
Then a full revolution (= 360 degrees) requires 4*200 steps, thus 62 degrees will be reached after:
800 steps/360 * 62 = 138 steps (1/8 microstepping requires 276 steps, 1/16 -> 551)
Your pseudo code will look like:
Include the (right) library
Initiate the stepper (constructor)
Assign all needed pins (at least the one for the hall sensor and the LabView signal as inputs and the LED as output)
In setup() run the stepper to find the hall sensor signal (= 0 position) and stop it there
In loop() read the input pin of the LabView
When a signal was detected, send the calculated '62 degrees' steps
thanks for the reply. I am using my own driver . here is the updated code
#include <CustomStepper.h>
const int hallPin = 12; // the number of the hall effect sensor pin1 for defining the home position
const int ledPin = 13; // the number of the LED pin
const int Labviewpin1= 5;
int hallState = 0; // variable for reading the hall sensor statu
int Labviewstate = 0;
CustomStepper stepper(8, 9, 10, 11);
void setup() {
stepper.setRPM(30);
stepper.setSPR(200);
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
pinMode(hallPin, INPUT); // initialize the hall effect sensor pin as an input:
pinMode(Labviewpin1, INPUT); // initialize the hall effect sensor pin as an input:
Serial.begin(9600); // initialize the serial port:
hallState = digitalRead(hallPin); // read the state of the hall effect sensor:
if (hallState == LOW)
{
digitalWrite(ledPin, LOW); // turn LED on:
stepper.run();
delay(500);
}
else
{
digitalWrite(ledPin, HIGH); // turn LED off:
stepper.setDirection(STOP);
}
}
void loop() {
Labviewstate = digitalRead(Labviewpin1);
if (Labviewstate == HIGH)
{
stepper.setDirection(CW);
stepper.rotateDegrees(62.0);
}
else
{
stepper.setDirection(STOP);
}
}
Thanks for reply. By my understanding the code should work for my application. In my code i want to store the number of degrees the motor has rotated and no of times the arduino got command from LabIEW.
In my code i want to store the number of degrees the motor has rotated and no of times the arduino got command from LabIEW. whenever hall sensor was high these values( no of degrees the motor rotated and no of times labviewpin is high) should become zero.
I want to store the number of degrees the motor has rotated and no of times the arduino got command from LabIEW. whenever hall sensor was high these values( no of degrees the motor rotated and no of times labviewpin is high) should become zero. can u please suggest me how to start this??
The motor will rotate till the hall sensor is high, when it is high it will stop( this code i included in void setup)
the motor will rotate 62 when ever it receives signal from labview(this code i included in void loop)....
adding to this i want to write a code which stores the no of times the motor got command from labview and no of degrees the motor had rotated and whenever hall sensor was high these values( no of degrees the motor rotated and no of times labviewpin is high) should become zero....
Thanks for the reply. Code for moving the motor to HOME seems Ok for me. Whatever you suggested for counting the no of commands and degrees the motor move it will try to incorporate in my Final code.