Jump to content


Photo

How to control a blaster with Arduino

brushless arduino stryfe servo

9 replies to this topic

#1 udsaxman

udsaxman

    Member

  • Members
  • 10 posts

Posted 24 May 2016 - 05:57 PM

*
POPULAR

I thought I would share some code I have cobbled together for controlling my brushless Stryfe with an arduino controller.  This allows for push button spin-up and you don't need to use a servo tester to control the motors which is always good.  Any suggestions are always welcome.   There is code included that allows you to hook a servo up to feed ammo into the flywheels for those of you who want to replace the pusher motors in your rapidstrikes with a servo. :)

 

Feel free to modify this like crazy and do all sorts of strange things with it.  This can be easily incorporated into ammo counters as well to have a single controller do both (any Arduino board is more than powerful enough to not blink at the task).

 

Latest version of code can always be found here: https://github.com/u...er/ArduNerf.ino

 

Code as of now:

 

//Arduino program to control a nerf blaster with brushless flywheels and a servo for feeding darts into the flywheels
//The pushbuttons I'm using in this example are OSEPP Push Button Modules  http://osepp.com/pro...-button-module/
//Arduino controller used during this development is an Intel Curie powered Arduino 101 https://www.arduino....ArduinoBoard101with an OSEPP SensorShield on top of it http://osepp.com/products/shield-arduino-compatible/sensor-shield/.  You will need to use OPTO ESCs and a seperate power feed for this setup!
//Also tested wih an ATMEGA2560 based Multiwii Flight Controller i had laying around http://www.readytoflyquads.com/multiwii-pro-2-0-flight-controller. To use this you will need to make sure one of your ESCs has a BEC built in.
//ESCs utilized here are http://www.hobbyking..._Firmware_.html.  


#include <Servo.h> //nice and simple, we are only utilizing one library for this project.  Servo handles everything we need it to

//declare servo objects that will be used throughout the rest of the project.
Servo ESC1;
Servo ESC2;
Servo feedServo;
//arm esc
// constants won't change. They're used here to
// set pin numbers:
const int spinButtonPin = 8;  // the number of the pin where the spin button is connected
const int feedButtonPin = 7;  // the number of the pin where the feed button is connected
const int ledPin = 13;      // the number of the LED pin
const int ESC1Pin = 5;      //piuninumber of the first ESC
const int ESC2Pin = 6;     //pin number of the second ESC
const int feedServoPin=9;  //pin number for the servo that will be pushing darts into the flywheels


// Variables will change:
int ledState = LOW;         // the current state of the output pin
int spinButtonState;             // used for storing the current reading from the spin input pin
int feedButtonState;             // used for storing the current reading from the feed input pin
int lastSpinButtonState = HIGH;   // the previous reading from the spin input pin - we instantiate it to the non-firing position to start the program
int lastFeedButtonState = HIGH;   // the previous reading from the feed input pin - we instantiate it to the non-firing position to start the program

//if not all your ESCs are the same, you may need an additonal variable but that shouldnt be necessary here.
int ESCMinSpeed = 1000;   //this varies by ESC.  Min speed must be low enough to arm.  Refer to speec controller's documentation for this
int ESCMaxSpeed = 1800;   //this varries by ESC.  You may want to set it slightly lower than the max supported to avoid overheating issues


void setup() {
  //setup the pins so we can use them for reading the button state.
  pinMode(spinButtonPin, INPUT);
  pinMode(feedButtonPin, INPUT);
  //set ledPin to output power to the LED
  pinMode(ledPin, OUTPUT);
  //set initial LED state
  digitalWrite(ledPin, ledState);
  //attach servos
  ESC1.attach(ESC1Pin);  
  ESC2.attach(ESC2Pin);
  feedServo.attach(feedServoPin);
  //write minimum speed to ESCs so they arm
  ESC1.writeMicroseconds(ESCMinSpeed);
  ESC2.writeMicroseconds(ESCMinSpeed);
  //wait 1 second for ESCs to arm
  delay(1000);
}

void loop() {
 
  // read the state of the switchs into a local variable:
  int spinReading = digitalRead(spinButtonPin);
  int feedReading = digitalRead(feedButtonPin);
 
      // check to see if you just pressed the button
      //only change speed if button state has changed
      if (spinReading != lastSpinButtonState) {
        if (spinReading == LOW) {
           ledState = HIGH;
           ESC1.writeMicroseconds(ESCMaxSpeed);
           ESC2.writeMicroseconds(ESCMaxSpeed);
        }
       if (spinReading == HIGH) {
          ledState = LOW;
          ESC1.writeMicroseconds(ESCMinSpeed);
          ESC2.writeMicroseconds(ESCMinSpeed);
        }
      }

      //if feed button has been pressed, start pushing darts out
      //What you write to the servos will vary greatly depending how you setup the feed mechanism.  
      //This example has the servo pushing a dart in when you push the button and then moving back to get ready to push the next one when yo let up on it.
      //In a rapidstrike or similar, you can just set ti to keep spinning while the button is pressed
      
      if (feedReading != lastFeedButtonState) {
        //if button is pressed, feed a dart in
        if (feedReading == LOW) {
          feedServo.write(180); //writes the server to full rotation
          }
        //return servo to the withdrawn state when button is released  
        if (feedReading == HIGH) {
          feedServo.write(0);
        }
      }
   
 
    // save the reading.  Next time through the loop,
    // it'll be the lastButtonState:
    lastSpinButtonState = spinReading;
    lastFeedButtonState = feedReading;
 
  // set the LED:
  digitalWrite(ledPin, ledState);

}

 

I attempted to attach the .ino file but the forums don't seem to be a big fan


  • 2

#2 TypicalSeattleModder

TypicalSeattleModder

    Member

  • Members
  • 34 posts

Posted 25 May 2016 - 12:05 AM

can you make a rapidstrike select fire code? Like semi auto, burst, full auto.


  • 0

#3 udsaxman

udsaxman

    Member

  • Members
  • 10 posts

Posted 25 May 2016 - 12:24 AM

Yes, it will require the use of a stepper motor though since continuous rotation servos are not terribly accurate and your won't get full auto out of a standard servo. I will update the github when I have time to write the code
  • 0

#4 Meaker VI

Meaker VI

    Member

  • Moderators
  • 1,192 posts

Posted 25 May 2016 - 09:11 AM

We do have a <code> bbs command:

I thought I would share some code I have cobbled together for controlling my brushless Stryfe with an arduino controller.  This allows for push button spin-up and you don't need to use a servo tester to control the motors which is always good.  Any suggestions are always welcome.   There is code included that allows you to hook a servo up to feed ammo into the flywheels for those of you who want to replace the pusher motors in your rapidstrikes with a servo. :)
 
Feel free to modify this like crazy and do all sorts of strange things with it.  This can be easily incorporated into ammo counters as well to have a single controller do both (any Arduino board is more than powerful enough to not blink at the task).
 
Latest version of code can always be found here: https://github.com/u...er/ArduNerf.ino
 
Code as of now:
 

//Arduino program to control a nerf blaster with brushless flywheels and a servo for feeding darts into the flywheels
//The pushbuttons I'm using in this example are OSEPP Push Button Modules  http://osepp.com/products/sensors-arduino-compatible/push-button-module/
//Arduino controller used during this development is an Intel Curie powered Arduino 101 https://www.arduino.cc/en/Main/ArduinoBoard101with an OSEPP SensorShield on top of it http://osepp.com/products/shield-arduino-compatible/sensor-shield/.  You will need to use OPTO ESCs and a seperate power feed for this setup!
//Also tested wih an ATMEGA2560 based Multiwii Flight Controller i had laying around http://www.readytoflyquads.com/multiwii-pro-2-0-flight-controller. To use this you will need to make sure one of your ESCs has a BEC built in.
//ESCs utilized here are http://www.hobbyking.com/hobbyking/store/__39708__Afro_ESC_30Amp_Multi_rotor_Motor_Speed_Controller_SimonK_Firmware_.html.  


#include <Servo.h> //nice and simple, we are only utilizing one library for this project.  Servo handles everything we need it to

//declare servo objects that will be used throughout the rest of the project.
Servo ESC1;
Servo ESC2;
Servo feedServo;
//arm esc
// constants won't change. They're used here to
// set pin numbers:
const int spinButtonPin = 8;  // the number of the pin where the spin button is connected
const int feedButtonPin = 7;  // the number of the pin where the feed button is connected
const int ledPin = 13;      // the number of the LED pin
const int ESC1Pin = 5;      //piuninumber of the first ESC
const int ESC2Pin = 6;     //pin number of the second ESC
const int feedServoPin=9;  //pin number for the servo that will be pushing darts into the flywheels


// Variables will change:
int ledState = LOW;         // the current state of the output pin
int spinButtonState;             // used for storing the current reading from the spin input pin
int feedButtonState;             // used for storing the current reading from the feed input pin
int lastSpinButtonState = HIGH;   // the previous reading from the spin input pin - we instantiate it to the non-firing position to start the program
int lastFeedButtonState = HIGH;   // the previous reading from the feed input pin - we instantiate it to the non-firing position to start the program

//if not all your ESCs are the same, you may need an additonal variable but that shouldnt be necessary here.
int ESCMinSpeed = 1000;   //this varies by ESC.  Min speed must be low enough to arm.  Refer to speec controller's documentation for this
int ESCMaxSpeed = 1800;   //this varries by ESC.  You may want to set it slightly lower than the max supported to avoid overheating issues


void setup() {
  //setup the pins so we can use them for reading the button state.
  pinMode(spinButtonPin, INPUT);
  pinMode(feedButtonPin, INPUT);
  //set ledPin to output power to the LED
  pinMode(ledPin, OUTPUT);
  //set initial LED state
  digitalWrite(ledPin, ledState);
  //attach servos
  ESC1.attach(ESC1Pin);  
  ESC2.attach(ESC2Pin);
  feedServo.attach(feedServoPin);
  //write minimum speed to ESCs so they arm
  ESC1.writeMicroseconds(ESCMinSpeed);
  ESC2.writeMicroseconds(ESCMinSpeed);
  //wait 1 second for ESCs to arm
  delay(1000);
}

void loop() {
 
  // read the state of the switchs into a local variable:
  int spinReading = digitalRead(spinButtonPin);
  int feedReading = digitalRead(feedButtonPin);
 
      // check to see if you just pressed the button
      //only change speed if button state has changed
      if (spinReading != lastSpinButtonState) {
        if (spinReading == LOW) {
           ledState = HIGH;
           ESC1.writeMicroseconds(ESCMaxSpeed);
           ESC2.writeMicroseconds(ESCMaxSpeed);
        }
       if (spinReading == HIGH) {
          ledState = LOW;
          ESC1.writeMicroseconds(ESCMinSpeed);
          ESC2.writeMicroseconds(ESCMinSpeed);
        }
      }

      //if feed button has been pressed, start pushing darts out
      //What you write to the servos will vary greatly depending how you setup the feed mechanism.  
      //This example has the servo pushing a dart in when you push the button and then moving back to get ready to push the next one when yo let up on it.
      //In a rapidstrike or similar, you can just set ti to keep spinning while the button is pressed
      
      if (feedReading != lastFeedButtonState) {
        //if button is pressed, feed a dart in
        if (feedReading == LOW) {
          feedServo.write(180); //writes the server to full rotation
          }
        //return servo to the withdrawn state when button is released  
        if (feedReading == HIGH) {
          feedServo.write(0);
        }
      }
   
 
    // save the reading.  Next time through the loop,
    // it'll be the lastButtonState:
    lastSpinButtonState = spinReading;
    lastFeedButtonState = feedReading;
 
  // set the LED:
  digitalWrite(ledPin, ledState);

}

 

I attempted to attach the .ino file but the forums don't seem to be a big fan


Maybe try zipping it? Not sure which file types this forum accepts, but I know forums usually try to just take .zip and some image formats.
  • 0

#5 udsaxman

udsaxman

    Member

  • Members
  • 10 posts

Posted 25 May 2016 - 05:18 PM

Its available off github and that version is more current anyways. So for the rapidstrike, there are some interesting challenges with that.  If going with stock brushed motors, it will need to go through a relay board to control the flywheels and a separate controller to run a stepper motor to ensure the selct fire works correctly (just calling different numbers of steps depending on the mode)  I will try to whip up the code tomorrow and see how that goes.


  • 0

#6 TypicalSeattleModder

TypicalSeattleModder

    Member

  • Members
  • 34 posts

Posted 26 May 2016 - 01:03 AM

What kind of stepper motor would you suggest?


  • 0

#7 udsaxman

udsaxman

    Member

  • Members
  • 10 posts

Posted 30 May 2016 - 02:46 PM

I looked around a bit and i dont know exactly yet.  I will probably pick up a rapid strike sometime soon and see what can fit in there.


  • 0

#8 RZRider

RZRider

    Member

  • Members
  • 40 posts

Posted 03 October 2016 - 04:34 PM

Could you control a stampede with arduino
  • 0

#9 DjOnslaught

DjOnslaught

    Member

  • Members
  • 350 posts

Posted 04 October 2016 - 04:56 PM

Could you control a stampede with arduino


Yes very easily. There is one in the mod category done by Kingbob. He did amazing things
  • 0

#10 jkovarovics

jkovarovics

    Member

  • Members
  • 7 posts

Posted 04 October 2016 - 09:51 PM

FWIW you can get away with running a single data wire to both your ESC's. It would clean up wiring and code a bit. I started with two thinking I would allow for slightly different speeds in each then went to one.

 

Also, you'd be fine with a brushed motor in a rapidstrike. No stepper necessary and to be honest, using a stepper assuming every step is successful is tough in an environment where some darts may not want to be pushed. You'll get slippage at some point and it all goes downhill. The key to select fire is the indexing switch with both a stepper and a brushed motor. I use the stepper/indexer combo in my blasters to give them some intelligence. If the pusher mech doesn't make it around to the switch in a certain number of steps it knows it's slipped, something didn't go well, reverse direction and spin back to home. If that doesn't happen in a certain number of steps, something is really wrong. Using a brushed motor is as simple as spin till the switch is flipped, you've fired a round, either do it again or wait for trigger release before firing again.


  • 0



Also tagged with one or more of these keywords: brushless, arduino, stryfe, servo

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users