Hi
I'm currently working on a 3D scanner, where I rotate a platfrom with a stepper and after every step my camera should make a picture. I use the arduino to control my stepper and all the rest happens with LabVIEW. With my LabVIEW program I always want to send a serial command to my arduino to do 1 step, than I would like to take a picture in my LabVIEW program and then send the serial command again to the arduino to do 1 step, taking another picture and so on. The amount of steps I want to do is inserted in the LabVIEW program. I made both the LabVIEW program and the C-code for my arduino, but since I'm new to arduino I guess I made a mistake there. I guess the problem is at the part where I read my serial port.
#include <Stepper.h>
#define number_of_steps 48 // value of steps on your motor
Stepper myStepper(number_of_steps,8,9,10,11); // init stepper library
int received_data[0]; // allocate memory for data over serial
void setup()
{
Serial.begin(9600); // init serial port
}
void loop()
{
while(Serial.available() < 1) {} // wait until 1 byte is available on serial port
for(int i=0;i<1;i++) {
received_data[i] = Serial.read(); // read 1 byte
}
if(received_data[0] == 1) // clockwise revolution
{
myStepper.step(1); // step in clockwise direction
delay(5);
Serial.print("DONE stepping in CW direction for ");
Serial.print(1);
Serial.print(" steps!"); // output status message
}
else if(received_data[0] == 2) // counter clockwise revolution
{
myStepper.step(-1); // step in counter clockwise direction
delay(5);
Serial.print("DONE stepping in CCW direction for ");
Serial.print(1);
Serial.print(" steps!"); // output status message
}
else Serial.print("ERROR!"); // output error message
}
My Labview program sends the turn direction via the serial bus to my arduino, it waits for 300ms and than it reads the serial print for 1 second. After that happened it repeats itself (loop) for n-steps I did insert in my program.
Is there a problem in the serial read commands (I don't understand the for(int i=0;i<1;i++) )?
Is there a timing problem between the LabVIEW program and the arduino?
Should I send another command Instead of sending the turn direction everytime?
Can someone please help me.
Kind regards
Ruts