Excel to Arduino to Stepper Motor

Hi,

I'm a mechanical engineering student trying to control a stepper motor. I have got it working (arduino uno, PBL3717a driver) and can run the example code working with my motor.

/*
 Stepper Motor Control - one revolution

 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 8 - 11 of the Arduino.

 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.


 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe

 */

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}

Now what i am trying to do is control the steps of the motor using a button in excel. I have a table of positions in my spreadsheet and i can make it calculate how many steps are required to move to the new desired position (based on where it was last etc).

The idea is, on excel you type in the location you want and press a "go" button, excel calculates what the motor needs to do then sends the calculated steps to the motor via the COM 3 port. I have searched online and there are strong suggestions that this is possible, but i am at a loss on how to actually go forward with this. I can use a bit of VB (beginner level but i do get it) and i managed to make a driver board and i have 3d printed a bunch of stuff to create a test rig.

I would be extremely grateful if anyone could help, my current google searches keep leading to guides on extracting info from an arduino to excel, whereas i want to send data from excel to the Uno.

If there is any more info you guys need, let me know :slight_smile:

Real time control from Excel might not be pretty...

The simplest solution might be:

  1. Create a standalone program which takes command line arguments and sends these to the COM port.
    There is an example for this in C++:
    Arduino Playground - CPPWindows

  2. In your VBA script in excell use 'shell' to run the other program. You could be fancy and wait for completion... or find a way to insert a delay

roughly:
shell "path\program.exe arguments...."

Maybe you can do this with Firmata if you can access & control serial ports from within Excel.

Excel seems like a very perverse tool to use for this - is using it a requirement or something?

Not trying to revive this topic, just noting for anyone that curiously looks here that Roberto Valgolio's Arduino_Excel_12 would allow this. In your Arduino code you could poll a cell that an Excel activex or form button flags as a boolean true for example, and based on that, then have the Arduino code grab the data from the appropriate cells, reset the boolean cell as false, and do whatever.