- Tue Feb 21, 2017 12:01 pm
#193512
Greetings Fellow Sparkfunions,
I have two Xbee Shields (sparkfun's) two Uno's, 2 Series 1 xbee's, a pot trim, and a Big Easy Driver.
My goal is to control two stepper motors using the above. I have followed the Big Easy Driver tutorials and using the Accel Stepper library per the tutorial. I am following particularly the Stepper motor with 3 buttons (left, stop, right) and the pot trim as speed control.
From the simple xbee shield tutorials I can get the shield and the explorer to work using the 1 LED to blink when using serial connection to the computer. However, I would like to use both xbee shields and not the explorer and take advantage of all the pins on the shields. My assumptions about purchasing them was all I had to do was attach the shields on top the UNO's with both UNO's using the same code. I would then put the motor driver on one of the shields and the pot trim with buttons on the other shield. Load the code on both and boom, they would work. I find this not to be the case. Is there anything that needs to be done in the Xbee configurations? So far, I have seen that I would need to open XCTU for both Xbee's and configure the pins direction and enable them. I am not sure about using settings like coordinator / end device to get access to the other pins on the Xbee shield hence my questions. What am I missing? Am I supposed to write code for the coordinator and code for the end device?
Code I'm using is below.
Any help is good help,
Thank you, Zwick (pinch)
I have two Xbee Shields (sparkfun's) two Uno's, 2 Series 1 xbee's, a pot trim, and a Big Easy Driver.
My goal is to control two stepper motors using the above. I have followed the Big Easy Driver tutorials and using the Accel Stepper library per the tutorial. I am following particularly the Stepper motor with 3 buttons (left, stop, right) and the pot trim as speed control.
From the simple xbee shield tutorials I can get the shield and the explorer to work using the 1 LED to blink when using serial connection to the computer. However, I would like to use both xbee shields and not the explorer and take advantage of all the pins on the shields. My assumptions about purchasing them was all I had to do was attach the shields on top the UNO's with both UNO's using the same code. I would then put the motor driver on one of the shields and the pot trim with buttons on the other shield. Load the code on both and boom, they would work. I find this not to be the case. Is there anything that needs to be done in the Xbee configurations? So far, I have seen that I would need to open XCTU for both Xbee's and configure the pins direction and enable them. I am not sure about using settings like coordinator / end device to get access to the other pins on the Xbee shield hence my questions. What am I missing? Am I supposed to write code for the coordinator and code for the end device?
Code I'm using is below.
Any help is good help,
Thank you, Zwick (pinch)
Code: Select all
// Example5 code for Brian Schmalz's Easy Driver Example page
// http://www.schmalzhaus.com/EasyDriver/EasyDriverExamples.html
#include <AccelStepper.h>
// Define the stepper and the pins it will use
AccelStepper stepper1(AccelStepper::DRIVER, 9, 8);
// Define our three input button pins
#define LEFT_PIN 4
#define STOP_PIN 3
#define RIGHT_PIN 2
// Define our analog pot input pin
#define SPEED_PIN 0
// Define our maximum and minimum speed in steps per second (scale pot to these)
#define MAX_SPEED 500
#define MIN_SPEED 0.1
void setup() {
// The only AccelStepper value we have to set here is the max speeed, which is higher than we'll ever go
stepper1.setMaxSpeed(10000.0);
// Set up the three button inputs, with pullups
pinMode(LEFT_PIN, INPUT_PULLUP);
pinMode(STOP_PIN, INPUT_PULLUP);
pinMode(RIGHT_PIN, INPUT_PULLUP);
}
void loop() {
static float current_speed = 0.0; // Holds current motor speed in steps/second
static int analog_read_counter = 1000; // Counts down to 0 to fire analog read
static char sign = 0; // Holds -1, 1 or 0 to turn the motor on/off and control direction
static int analog_value = 0; // Holds raw analog value.
// If a switch is pushed down (low), set the sign value appropriately
if (digitalRead(LEFT_PIN) == 0) {
sign = 1;
}
else if (digitalRead(RIGHT_PIN) == 0) {
sign = -1;
}
else if (digitalRead(STOP_PIN) == 0) {
sign = 0;
}
// We only want to read the pot every so often (because it takes a long time we don't
// want to do it every time through the main loop).
if (analog_read_counter > 0) {
analog_read_counter--;
}
else {
analog_read_counter = 3000;
// Now read the pot (from 0 to 1023)
analog_value = analogRead(SPEED_PIN);
// Give the stepper a chance to step if it needs to
stepper1.runSpeed();
// And scale the pot's value from min to max speeds
current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;
// Update the stepper to run at this new speed
stepper1.setSpeed(current_speed);
}
// This will run the stepper at a constant speed
stepper1.runSpeed();
}