Programing an arduino to control stepper

Hi,

I doing a project where I have a 43PT-AR display controlling a stepper motor with a arduino and motor shield. To control the stepper motor I have a slider on the display which should control the position of the stepper motor. I’m having problems trying to write the arduino program in which it controls the motor. I got the display to show the value of the slider but I need to get that value sent to the stepper. Right now I’m getting an error that says ‘class Stepper’ has no member named ‘write’. If anyone has any tips on has to get the display to control the stepper with the slider it would be greatly appreciated.

Thanks

#include <Stepper.h>

#include <genieArduino.h>

const int stepsPerRevolution = 100;
Stepper myStepper(stepsPerRevolution, 12,13);

// give the motor control pins names:
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

int Slider0 ;
int Stepperposition ;

Genie genie;
#define RESETLINE 4 // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below)
void setup()
{

Serial.begin(9600); //
genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display

genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events

pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
digitalWrite(RESETLINE, 1); // Reset the Display via D4
delay(100);
digitalWrite(RESETLINE, 0); // unReset the Display via D4

delay (3500); //let the display start up after the reset (This is important)

}

void loop()
{
static long waitPeriod = millis();
myStepper.write(stepperposition);//

genie.DoEvents(); // This calls the library each loop to process the queued responses from the display

if (millis() >= waitPeriod)
{
waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time.
}
}

void myGenieEventHandler(void)
{
genieFrame Event;
genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below

int slider_val = 0;

//If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
{
if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a Slider
{
if (Event.reportObject.index == 0) // If Slider0 (Index = 0)
{
slider_val = genie.GetEventData(&Event); // Receive the event data from the Slider0
genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value to to LED Digits 0
Stepperposition = genie.GetEventData(&Event);

}
}
}
}

You seem to have confused a servo, which you can send to a given position, with a stepper, which you can tell to take a certain number of steps. With a stepper you can't tell it to go to a position. You can only say go so many steps this way or that. It looks like what you want is a servo and not a stepper.

I changed myStepper.write to myStepper.step so it will work with a stepper motor. But when I uploaded the program and move the slider it still doesn’t move the motor. If anyone has any suggestions on how to get the slider to rotate the stepper motor it would be appreciated.

Thanks

#include <Stepper.h>

#include <genieArduino.h>

const int stepsPerRevolution = 100;
Stepper myStepper(stepsPerRevolution, 12,13);

// give the motor control pins names:
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

int Slider0 ;
int Stepperposition ;

Genie genie;
#define RESETLINE 4 // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below)
void setup()
{

Serial.begin(9600); //
genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display

genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events

pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
digitalWrite(RESETLINE, 1); // Reset the Display via D4
delay(100);
digitalWrite(RESETLINE, 0); // unReset the Display via D4

delay (3500); //let the display start up after the reset (This is important)

}

void loop()
{
static long waitPeriod = millis();
myStepper.step(Stepperposition);//

genie.DoEvents(); // This calls the library each loop to process the queued responses from the display

if (millis() >= waitPeriod)
{
waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time.
}
}

void myGenieEventHandler(void)
{
genieFrame Event;
genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below

int slider_val = 0;

//If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
{
if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a Slider
{
if (Event.reportObject.index == 0) // If Slider0 (Index = 0)
{
slider_val = genie.GetEventData(&Event); // Receive the event data from the Slider0
genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value to to LED Digits 0
Stepperposition = genie.GetEventData(&Event);

}
}
}
}

You need to post a link to the datasheet for your stepper motor. Also provide details of your motor power supply (volts and amps).

A motor shield is usually a poor choice for driving a stepper motor.

...R Stepper Motor Basics Simple Stepper Code

this is the stepper motor I’ using
http://meci.com/electrical/motors/applied-motion-products-stepping-motor-4017-915.html

To supply power I have 9V hooked up to the arduino board

How does the Genie device communicate with the Arduino? Is it using Serial? I2C? SPI?

        Stepperposition = genie.GetEventData(&Event);

It seems unlikely that GetEventData() returns an Event structure AND the position of the slider. Post a link to the genie library.

Jacob53: this is the stepper motor I' using http://meci.com/electrical/motors/applied-motion-products-stepping-motor-4017-915.html

To supply power I have 9V hooked up to the arduino board

That link does not say what current the motor needs. Please measure the coil resistance with your multimeter an report the value you get. Better still find the maker's datasheet and post a link to it.

Your comment about the 9v power supply does not provide any information about how the motor driver is powered. Please make a simple drawing showing all the connections and post a photo of the drawing. Please DO NOT use Fritzing.

In general stepper motors work better with higher voltages and that is why specialized stepper drivers are used. An the motor shield may be making things worse by preventing some of your 9 volts from getting to the motor.

...R