Hi,
Will try to explain my application. The application is a measuring device, having a measuring probe, and a stepper motor. The work sequence is basically as follows:
Request data from probe->
-> Send data to Excel ->
-> Rotate motor by given step->
-> Request new data from probe ->
-> Send data to Excel-> ..... and so on...
I am using Arduino Leonardo for this. It communicates to the probe over Serial1 and communicates with a PC (Excel) over Serial2 port. MS Excel talks through serial port using a plugin called PLX-DAQ (see Download - Parallax for details).
Problem is, if you check the code, you will see there are 3 lines commented out. This are the commands to run the motor. If I enable these lines, then all works (and the motor rotates), but there is no data passed to Excel. I am getting blank cells. I am not sure why it could be. I am guessing it is some timing issue, but cannot see what it is. With this lines commented out there is data passed to Excel. The library I am using to control the stepper is called AccelStepper (here's some info: AccelStepper Arduino Library, connecting Stepper Motors to Teensy).
Anyone, any thoughts? Appears like the stepper.run() command is not getting finished before data is being sent to Excel...?
Thanks,
Dan
int row = 0;
int Step = 111;
char command, data ;
char value[7]; //
#include <AccelStepper.h>
AccelStepper stepper(1,5,7); // Step pin #5, DIR pin #7
void setup() {
Serial.begin(128000); // opens serial port, sets data rate to 128000 bps
while (!Serial) {
; // wait for serial port to connect.
}
Serial1.begin(1200, SERIAL_7E1);
//================ RELAY SETUP ============//
pinMode (12,OUTPUT); //power supply to relay
digitalWrite(12,HIGH); //relay board ON
pinMode (13, OUTPUT); // relay signal
digitalWrite(13,HIGH); // relay OFF
//========================================//
//============= Stepper Setup ===========//
pinMode (6, OUTPUT); // Stepper DISABLE pin
digitalWrite(6, LOW); // Disable stepper
stepper.setMaxSpeed(100000);
stepper.setAcceleration(100000);
stepper.setSpeed(100000);
stepper.setMinPulseWidth(5);
//======================================//
}
void loop() {
command = 'V';
Serial.println("CELL,GET,Z3"); // Read command from Excel
delay(5);
command = Serial.read();
Serial.read();
Serial.read(); //empty buffer
if ((command == 'a') || (command == 'b') || (command == 'c')) // check whether first, second or third measurement is requested
{
digitalWrite(6, HIGH); // activate stepper
Serial.println("ROW,SET,2"); //set row 2 in Excel as first row to print
delay(2);
for(row=0; row < 90; row++)
{
digitalWrite(13,LOW); //activate relay - request data from probe
int value_place = 0; //string pointer
delay(50);
for(value_place =0; Serial1.available()>0; value_place++) // while data available - byte at a time as single character
{
delay(20);
value[value_place] = Serial1.read();
delay(1);
}
digitalWrite(13,HIGH); //deactivate relay
Serial.print("DATA,"); Serial.println(value); // print value to Excel
//stepper.move(Step); // define stepper move size
//stepper.runToPosition(); // Define stepper movement type: move stepper by Step. Wait until it's moving
//stepper.run(); // Actual move command of stepper
delay(10);
}
Serial.print("CELL,SET,Z4,"); Serial.println(command);
digitalWrite(6, LOW); // deactivate stepper
}
Serial.println("CELL,SET,Z3,V");
delay (100);
}
ExcelStepper.ino (2.29 KB)