The discussion of the Alien series of films and the props used in them is the aim, but if it's got Big Bugs and Big Guns, then they are welcome too!





Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Build your own predator cannon
PostPosted: Sat Nov 11, 2017 4:14 pm 

Service Number: A05/TQ2.0.32141E1
Country: United States
OK, I think I have it working enough for my needs.

Code:
/*
 * Example 6
 * Nunchuck control for four servos and two button inputs
 * Honus 2007
 * This allows the use of a Wii nunchuck as an input device and is modified/extended from the original code
 * by Tod E. Kurt and Windmeadow Labs
 *2007 Tod E. Kurt, http://todbot.com/blog/
 *The Wii Nunchuck reading code is taken from Windmeadow Labs, http://www.windmeadow.com/node/42
 * ArduinoNunchuk.cpp - Improved Wii Nunchuk library for Arduino
 *
 * Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
 *
 * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
 *
 * Based on the following resources:
 *   http://www.windmeadow.com/node/42
 *   http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
 *   http://wiibrew.org/wiki/Wiimote/Extension_Controllers
 *   http://www.gammon.com.au/blink
 *
 */
// www.facebook.com/ArduinoCenter
// https://blog.underc0de.org/arduino-wii-nunchuck-servo-motores/
// Original Code base credited to Undercode
// Code adapted from Sean Maio Crybabyfx setup
//https://github.com/outcry27/crybabyFX
// Updated by knoxvilles_joker 2017
// http://facebook.com/knoxvillesjoker
// more instructions documented at
// http://alienslegacy.com
 

#include <Wire.h>
#include "ArduinoNunchuk.h"
#include <Servo.h>

//Creates the objects to control the servos
ArduinoNunchuk nunchuk = ArduinoNunchuk();

const int ledPin1 = 13;       // Control pin for LED 1
const byte ledPin2 = 12;       // Control pin for LED 2
const unsigned long ledPin2interval = 500;
unsigned long ledPin2timer;
const int servoPin1 = 9;      // Control pin for servo motor
const int servoPin2 = 11;      // Control pin for servo motor
const int servoPin3 = 10;      // Control pin for servo motor
const int servoPin4 = 6;      // Control pin for servo motor
// sound pins for firing sounds
const int firePin1 = 4;
const int firePin2 = 5;
const int firePin3 = 16;
const int startSoundPin = 17;
 int pulseWidth1 = 0;    // Amount to pulse the servo 1
 int pulseWidth2 = 0;    // Amount to pulse the servo 2
 int pulseWidth3 = 0;    // Amount to pulse the servo 3
 int pulseWidth4 = 0;    // Amount to pulse the servo 4
 int refreshTime = 20;  // the time in millisecs needed in between pulses
//Initializes the variables
int xjoystick;
int yjoystick;
int xtilt;
int ytilt;
long lastPulse1;
long lastPulse2;
long lastPulse3;
long lastPulse4;
int minPulse = 700;   // minimum pulse width
int loop_cnt=0;

void setup() {
  // put your setup code here, to run once:
// sound pins are setup before initialization of serial interfaces.
  // initialize the audio pins
  pinMode(startSoundPin, OUTPUT);
  pinMode(firePin1, OUTPUT);
  pinMode(firePin2, OUTPUT);
  pinMode(firePin3, OUTPUT);
  // set up the audio trigger pins to give a path to GND when set to OUTPUT
  analogWrite(startSoundPin, LOW);
  analogWrite(firePin1, LOW);
  analogWrite(firePin2, LOW);
  analogWrite(firePin3, LOW);

  pinMode(servoPin1, OUTPUT);  // Set servo pin as an output pin
  pinMode(servoPin2, OUTPUT);  // Set servo pin as an output pin
  pinMode(servoPin3, OUTPUT);  // Set servo pin as an output pin
  pinMode(servoPin4, OUTPUT);  // Set servo pin as an output pin
 
  pulseWidth1 = minPulse;      // Set the motor position to the minimum
  pulseWidth2 = minPulse;      // Set the motor position to the minimum
  pulseWidth3 = minPulse;      // Set the motor position to the minimum
  pulseWidth4 = minPulse;      // Set the motor position to the minimum
  pinMode(ledPin1, OUTPUT);  // sets the LED pin as output
  pinMode(ledPin2, OUTPUT);
  ledPin2timer = millis ();
  digitalWrite(ledPin1, LOW); // sets the LED pin LOW (turns it off)
  digitalWrite(ledPin2, LOW);

Serial.begin(19200);
 Serial.print("loading sound card init\n");
  delay(1000); 
  Serial.print("card initialized");
   //give the audio board time to power up.
  // Otherwise bootup sound will be called before audio
  // board is ready.
  // this plays an initialization sound.
  digitalWrite(startSoundPin, HIGH);
  //Serial.print("#00\n");
  delay(300);
  digitalWrite(startSoundPin, LOW);
  delay(300);
    //Initializes nunchuck and servos
  nunchuk.init();

}

void ledPin2toggle ()
  {
   if (digitalRead (ledPin2) == LOW)
      digitalWrite (ledPin2, HIGH);
   else
      digitalWrite (ledPin2, LOW);

  // remember when we toggled it
  ledPin2timer = millis (); 
  }  // end of toggleGreenLED

void loop() {
  // put your main code here, to run repeatedly:
  checkNunchuck1();
  updateServo1();   // update servo 1 position
  checkNunchuck2();
  updateServo2();   // update servo 2 position
  checkNunchuck3();
  updateServo3();   // update servo 3 position
  checkNunchuck4();
  updateServo4();   // update servo 4 position

   if(nunchuk.zButton == 1)  {    // light the LED if z button is pressed
    digitalWrite(ledPin1, HIGH);
    digitalWrite(firePin1, HIGH);
  //  Serial.print("#3\n");
    //  3 = 1
    delay(300);
    digitalWrite(ledPin1,LOW);
    digitalWrite(firePin1, LOW);
    delay(300);
   }

    if (nunchuk.cButton == 1)  {
      if ( (millis () - ledPin2timer) >= ledPin2interval) {
     ledPin2toggle ();
      }
    digitalWrite(firePin2, HIGH);
//  Serial.print("#4\n");
//  4 = 4
//    delay(300);
   
    digitalWrite(firePin2, LOW);
//    delay(300);
   }



    delay(1);        // this is here to give a known time per loop

 //Guardamos los valores que nos manda el Nunchuk en las variables
  xjoystick = nunchuk.analogX;
  xjoystick = constrain(xjoystick, 26, 226);
  xjoystick = map(xjoystick, 26, 226, 0, 180);
 
  yjoystick = nunchuk.analogY;
  yjoystick = constrain(yjoystick, 26, 226);
  yjoystick = map(yjoystick, 26, 226, 180, 0);
 
  xtilt = nunchuk.accelX;
  xtilt = constrain(xtilt, 320, 720);
  xtilt = map(xtilt, 320, 720, 180, 0);
 
  ytilt = nunchuk.accelY;
  ytilt = constrain(ytilt, 320, 720);
  ytilt = map(ytilt, 320, 720, 0, 180);
// This prints the serial status of the nunchuck.
  Serial.print ("Joystick X: ");
  Serial.print (xjoystick, DEC);
  Serial.print ("\t");
 
  Serial.print ("Joystick Y: ");
  Serial.print (yjoystick, DEC);
  Serial.print ("\t");
 
  Serial.print ("X: ");
  Serial.print (xtilt, DEC);
  Serial.print ("\t");
 
  Serial.print ("Y: ");
  Serial.print (ytilt, DEC);
  Serial.print ("\t");
 
  nunchuk.update();
 
  if (nunchuk.cButton == 1) {
    Serial.print("--C--  ");
  }
 
  if (nunchuk.zButton == 1) {
    Serial.print("--Z--  ");
  }
 
  if (nunchuk.cButton == 1 && nunchuk.zButton == 1) {
    Serial.print("--Z-C--");
  }


 
  Serial.print ("\r\n");


}

void checkNunchuck1()
{
  if( loop_cnt > 100 ) {  // loop()s is every 1msec, this is every 100msec
   


    float tilt = xjoystick;    // x-axis, in this case ranges from ~70 - ~185
    tilt = (tilt - 70) * 1.5;        // convert to angle in degrees, roughly
    pulseWidth1 = (tilt * 9) + minPulse; // convert angle to microseconds

//   servoPin1.write(xjoystick);
   
    loop_cnt = 0;  // reset for
  }
  loop_cnt++;
 
}

// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo1()
{
  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse1 >= refreshTime) {
    digitalWrite(servoPin1, HIGH);    // Turn the motor on
    delayMicroseconds(pulseWidth1);   // Length of the pulse sets the motor position
    analogWrite(servoPin1, LOW);    // Turn the motor off
    lastPulse1 = millis();            // save the time of the last pulse
  }
}

void checkNunchuck2()
{
  if( loop_cnt > 100 ) {  // loop()s is every 1msec, this is every 100msec
   
//    nunchuck_get_data();
//    nunchuck_print_data();

    float tilt = yjoystick;    // y-axis, in this case ranges from ~70 - ~185
    tilt = (tilt - 70) * 1.5;        // convert to angle in degrees, roughly
    pulseWidth2 = (tilt * 9) + minPulse; // convert angle to microseconds
   
    loop_cnt = 0;  // reset for
  }
  loop_cnt++;
 
}

// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo2()
{
  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse2 >= refreshTime) {
    digitalWrite(servoPin2, HIGH);   // Turn the motor on
    delayMicroseconds(pulseWidth2);   // Length of the pulse sets the motor position
    analogWrite(servoPin2, LOW);    // Turn the motor off
    lastPulse2 = millis();            // save the time of the last pulse
  }
}

void checkNunchuck3()
{
  if( loop_cnt > 100 ) {  // loop()s is every 1msec, this is every 100msec
   
//    nunchuck_get_data();
//    nunchuck_print_data();

    float tilt = xtilt;    // x-axis, in this case ranges from ~70 - ~185
    tilt = (tilt - 70) * 1.5;        // convert to angle in degrees, roughly
    pulseWidth3 = (tilt * 9) + minPulse; // convert angle to microseconds
   
    loop_cnt = 0;  // reset for
  }
  loop_cnt++;
 
}

// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo3()
{
  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse3 >= refreshTime) {
    digitalWrite(servoPin3, HIGH);   // Turn the motor on
    delayMicroseconds(pulseWidth3);   // Length of the pulse sets the motor position
    analogWrite(servoPin3, LOW);    // Turn the motor off
    lastPulse3 = millis();            // save the time of the last pulse
  }
}

void checkNunchuck4()
{
  if( loop_cnt > 100 ) {  // loop()s is every 1msec, this is every 100msec
   
//    nunchuck_get_data();
//    nunchuck_print_data();

    float tilt = ytilt;    // y-axis, in this case ranges from ~70 - ~185
    tilt = (tilt - 70) * 1.5;        // convert to angle in degrees, roughly
    pulseWidth4 = (tilt * 9) + minPulse; // convert angle to microseconds
   
    loop_cnt = 0;  // reset for
  }
  loop_cnt++;
 
}

// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo4()
{
  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse4 >= refreshTime) {
    digitalWrite(servoPin4, HIGH);   // Turn the motor on
    delayMicroseconds(pulseWidth4);   // Length of the pulse sets the motor position
    analogWrite(servoPin4, LOW);    // Turn the motor off
    lastPulse4 = millis();            // save the time of the last pulse
  }
}


_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sat Nov 11, 2017 4:24 pm 

Service Number: A05/TQ2.0.32141E1
Country: United States
OK I will break it down a little bit.

All servos are on PWM pins and use analogWrite() to move.

both LEDs are on digital pins. 13 is the activity led.

I tried dimming through a timer but instead ended up with a on off led switch via the cButton. This would work great for the laser.

the sound pins are on digital only pins. Analog PWM pins WILL NOT work with the fx soundboard. Audio will loop (play endlessly in sequence) if you use those pins. It was really annoying figuring that one out.

I am calling time on this and am calling it done enough. This uses nothing but off the shelf parts from adafruit. This is something anyone with a little soldering skills can do.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sat Nov 11, 2017 8:46 pm 

Service Number: A05/TQ2.0.32141E1
Country: United States
And unit in action:

https://www.youtube.com/watch?v=psYGErOg3WA&t=36s

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Nov 12, 2017 2:56 pm 

Service Number: A05/TQ2.0.32141E1
Country: United States
I am looking through ways to make it work.

options for brackets and arms for off the shelf stuff are as follows:
vexmotion robot kit
lego adapter kits
lego mindstorm robotic kit


For you parents out there the lego and vexmotion kits may be available at school and would be a good project for your children and be done much more simply than what I did.

Given my foster parent nature these kits would be awesome bonding activities for the various children that we host.

With all the automation and robotics that is the spark of discussion and interest for replacing menial jobs, this stuff is very important for the next generation to learn. Robotics is advancing rapidly and much of this will be easier and easier as time goes on. That gives me an appreciation for what they accomplished in the 80s.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Nov 12, 2017 3:35 pm 

Service Number: A05/TQ2.0.32141E1
Country: United States
Looks like actobotics might be a better option...

https://www.servocity.com/actobotics-attachment-ideas

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Apr 08, 2018 1:06 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
OK I have been working on getting the cannon setup. I have settled on one of these options for the lift arm:
https://www.servocity.com/sg-5485hb-bm- ... 75&440=476
https://www.servocity.com/cm-785hb-serv ... 97=3&198=9
https://www.servocity.com/4-5-9380th-18 ... 75&440=476

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Apr 08, 2018 1:20 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
These are some progress pics.

IMG_1113.jpg
IMG_1113.jpg [ 148.52 KiB | Viewed 7105 times ]

IMG_1114.jpg
IMG_1114.jpg [ 132.83 KiB | Viewed 7105 times ]

IMG_1115.jpg
IMG_1115.jpg [ 158.85 KiB | Viewed 7105 times ]

IMG_1116.jpg
IMG_1116.jpg [ 138.68 KiB | Viewed 7105 times ]

IMG_1117.jpg
IMG_1117.jpg [ 131.98 KiB | Viewed 7105 times ]


_________________
The impossible takes a while longer and goes over budget too...
Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Apr 08, 2018 1:21 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
My different versions.

IMG_1117.jpg
IMG_1117.jpg [ 131.98 KiB | Viewed 7105 times ]


_________________
The impossible takes a while longer and goes over budget too...
Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sat May 26, 2018 11:34 pm 

Service Number: A05/TQ2.0.32141E1
Country: United States
gearbox ordered. as I am inside bound due to nursing some poison ivy, I should make some more progress this weekend as I can't stand being stuck inside at home for long with nothing to do. I go batty...

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Thu Apr 11, 2019 1:33 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
OK, I am updating things and getting around to getting this worked out. https://forums.adafruit.com/viewtopic.php?f=31&t=124714

Apparently I can not get it to work without an FTDI board plugged in. I will be doing some inquiries and unearth where I messed up on the code.

Right now I am getting a speaker wired in to the other side in advance of getting this worked out.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Thu Apr 11, 2019 12:34 pm 

Location: Derby
Country: United Kingdom
looks really interesting. looking forward to seeing this progress.


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Mon Apr 15, 2019 7:06 pm 

Service Number: A05/TQ2.0.32141E1
Country: United States
OK, I have some parts on order for this. I think I am having draw issues and some capacitors may be the ticket. I will also look at switching back to the servo shield for the Arduino, but I will need to rewrite the code.

backpack upgrades are proceeding slowly. I have managed to stuff a 100 watt amp in the right side piece with controls and only had a 1/16" of clearance on some of the parts.

I had to add some spacing on the backpack pieces so I did not have constant pressure against my back as it was causing back and shoulder issues.

I rewired the existing lower tech setup and everything is quick disconnect via ethernet patch cables.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sat Apr 20, 2019 8:55 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
knoxvilles_joker wrote:
OK, I have some parts on order for this. I think I am having draw issues and some capacitors may be the ticket. I will also look at switching back to the servo shield for the Arduino, but I will need to rewrite the code.

backpack upgrades are proceeding slowly. I have managed to stuff a 100 watt amp in the right side piece with controls and only had a 1/16" of clearance on some of the parts.

I had to add some spacing on the backpack pieces so I did not have constant pressure against my back as it was causing back and shoulder issues.

I rewired the existing lower tech setup and everything is quick disconnect via ethernet patch cables.


OK, capacitors definately helped. Unfortunately with that specific setup I would need to create a custom board to properly route power and address the inductance issues.

I switched back to the servo shielf and after some code rehashing I was finally able to get it to work.

Code:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  550 // this is the 'maximum' pulse length count (out of 4096)

unsigned long ledPin2timer;
const int servoPin4 = 6;
const int ledPin1 = 13;       // Control pin for LED 1
const byte ledPin2 = 12;       // Control pin for LED 2

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  Serial.println("8 channel Servo test!");

  pwm.begin();
 
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates

  delay(10);
  Serial.println("starting");
  ledPin2timer = millis ();
 
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println("start");
pwm.setPWM(servoPin4, 0, SERVOMIN);
delay(1000);
Serial.println("extend");
pwm.setPWM(servoPin4, 0, SERVOMAX);
delay(1000);
Serial.println("end");
pwm.setPWM(ledPin1, 4096, 0);
delay(500);
pwm.setPWM(ledPin1, 0, 4096);
delay(500);
pwm.setPWM(ledPin2, 4096, 0);
delay(500);
pwm.setPWM(ledPin2, 0, 4096);
delay(500);

}


Code:
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 8 servos, one after the other on the
  first 8 pins of the PCA9685

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815
 
  These drivers use I2C to communicate, 2 pins are required to 
  interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/
#include "ArduinoNunchuk.h"
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
//Creates the objects to control the servos
ArduinoNunchuk nunchuk = ArduinoNunchuk();

#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  550 // this is the 'maximum' pulse length count (out of 4096)
 int pulseWidth1 = 0;    // Amount to pulse the servo 1
 int pulseWidth2 = 0;    // Amount to pulse the servo 2
 int pulseWidth3 = 0;    // Amount to pulse the servo 3
long lastPulse1;
long lastPulse2;
long lastPulse3;
int xjoystick;
int yjoystick;
int xtilt;
const int servoPin1 = 9;      // Control pin for servo motor
const int servoPin2 = 11;      // Control pin for servo motor
const int servoPin3 = 10;      // Control pin for servo motor
const int ledPin1 = 13;       // Control pin for LED 1
const byte ledPin2 = 12;       // Control pin for LED 2
const unsigned long ledPin2interval = 500;
unsigned long ledPin2timer;
 
const int servoPin4 = 6;      // Control pin for servo motor
 int pulseWidth4 = 0;    // Amount to pulse the servo 4
 long lastPulse4;
int minPulse = 700;   // minimum pulse width
int loop_cnt=0;
int ytilt;
 int refreshTime = 20;  // the time in millisecs needed in between pulses

void setup() {
//    pinMode(servoPin4, OUTPUT);  // Set servo pin as an output pin
  pulseWidth1 = minPulse;      // Set the motor position to the minimum
  pulseWidth2 = minPulse;      // Set the motor position to the minimum
  pulseWidth3 = minPulse;      // Set the motor position to the minimum
    pulseWidth4 = minPulse;      // Set the motor position to the minimum
   ledPin2timer = millis ();
  Serial.begin(9600);
  Serial.println("8 channel Servo test!");
   Serial.print("loading sound card init\n");
  delay(1000); 
  Serial.print("card initialized");
    //Initializes nunchuck and servos
  nunchuk.init();
  delay(10);
}

void loop() {
 
    checkNunchuck1();
  updateServo1();   
    checkNunchuck2();
  updateServo2();   
    checkNunchuck3();
  updateServo3();
    checkNunchuck4();
  updateServo4();   
  delay(10);

     if(nunchuk.zButton == 1)  {    // light the LED if z button is pressed
    pwm.setPWM(ledPin1, 4096, 0);
//    digitalWrite(firePin1, HIGH);
    delay(300);
    pwm.setPWM(ledPin1, 0, 4096);
//    digitalWrite(firePin1, LOW);
    delay(300);
   }

    if (nunchuk.cButton == 1)  {
    pwm.setPWM(ledPin2, 4096, 0);
    delay(300);   

   }
    else {
      pwm.setPWM(ledPin2, 0, 4096);
    }
 
  xjoystick = nunchuk.analogX;
  xjoystick = constrain(xjoystick, 26, 226);
  xjoystick = map(xjoystick, 26, 226, 0, 180);
 
  yjoystick = nunchuk.analogY;
  yjoystick = constrain(yjoystick, 26, 226);
  yjoystick = map(yjoystick, 26, 226, 180, 0);

  xtilt = nunchuk.accelX;
  xtilt = constrain(xtilt, 320, 720);
  xtilt = map(xtilt, 320, 720, 180, 0);
 
  ytilt = nunchuk.accelY;
  ytilt = constrain(ytilt, 320, 720);
  ytilt = map(ytilt, 320, 720, 0, 180);
// This prints the serial status of the nunchuck.
  Serial.print ("Joystick X: "); Serial.print (xjoystick, DEC); Serial.print ("\t");
  Serial.print ("Joystick Y: "); Serial.print (yjoystick, DEC); Serial.print ("\t");
  Serial.print ("X: "); Serial.print (xtilt, DEC); Serial.print ("\t");
  Serial.print ("Y: "); Serial.print (ytilt, DEC); Serial.print ("\t");
  nunchuk.update();
  if (nunchuk.cButton == 1) { Serial.print("--C--  ");  }
  if (nunchuk.zButton == 1) { Serial.print("--Z--  ");  }
  if (nunchuk.cButton == 1 && nunchuk.zButton == 1) { Serial.print("--Z-C--"); }
    Serial.print ("\r\n");
    }



   
void checkNunchuck1() { if( loop_cnt > 100 ) { float tilt = xjoystick; pulseWidth1 = map(xjoystick, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo1() { if (millis() - lastPulse1 >= refreshTime) { pwm.setPWM(servoPin1, 0, pulseWidth1); lastPulse1 = millis(); } }
void checkNunchuck2() { if( loop_cnt > 100 ) { float tilt = yjoystick; pulseWidth2 = map(yjoystick, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo2() { if (millis() - lastPulse2 >= refreshTime) { pwm.setPWM(servoPin2, 0, pulseWidth2); lastPulse2 = millis(); } }   
void checkNunchuck3() { if( loop_cnt > 100 ) { float tilt = xtilt; pulseWidth3 = map(xtilt, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo3() { if (millis() - lastPulse3 >= refreshTime) { pwm.setPWM(servoPin3, 0, pulseWidth3); lastPulse3 = millis(); } }
void checkNunchuck4() { if( loop_cnt > 100 ) { float tilt = ytilt; pulseWidth4 = map(ytilt, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo4() { if (millis() - lastPulse4 >= refreshTime) { pwm.setPWM(servoPin4, 0, pulseWidth4); lastPulse4 = millis(); } }

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sat Apr 20, 2019 9:02 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
I set it up to use the arduino compatible servo shield offered by adafruit. It is a stacking setup and substantially lowers the amount of needed wires to make things work. I had to completely rebuild the code from the ground up step by step. The LED functionality is not where I neccessarily want it but I can make do with things.

I just need to sort out some minor coding bugs but this is getting very close to getting finished and ready for prime time.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sat Apr 20, 2019 12:47 pm 
User avatar

Location: Cincinnati, OH
Service Number: A09/TQ2.0.12148G1
Country: United States
Keep us updated on your progress!

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Apr 21, 2019 1:27 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
I got the servos to reliably work. As far as audio triggers I will have to see if I can set the fx sound board to run in uart mode and use direct serial triggering.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Apr 21, 2019 5:51 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
OK, I got the code cleaned up, and a little more easily followed. I will come back later once I get the audio piece sorted to properly give all credit, that I had edited out but such credit was in the prior version as I was doing massive and major clean ups of the code getting it a little bit easier to follow

I will be trying to use a wave shield from adafruit. There is too much going on for the fx sound board to properly work in uart mode.

Code:
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 8 servos, one after the other on the
  first 8 pins of the PCA9685

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815
 
  These drivers use I2C to communicate, 2 pins are required to 
  interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/
#include "ArduinoNunchuk.h"
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
//Creates the objects to control the servos
ArduinoNunchuk nunchuk = ArduinoNunchuk();

#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  550 // this is the 'maximum' pulse length count (out of 4096)
int pulseWidth1 = 0;    // Amount to pulse the servo 1
int pulseWidth2 = 0;    // Amount to pulse the servo 2
int pulseWidth3 = 0;    // Amount to pulse the servo 3
long lastPulse1;
long lastPulse2;
long lastPulse3;
int xjoystick;
int yjoystick;
int xtilt;
const int SoundPin1 = 14;
const int SoundPin2 = 150;
const int servoPin1 = 9;      // Control pin for servo motor
const int servoPin2 = 11;      // Control pin for servo motor
const int servoPin3 = 10;      // Control pin for servo motor
const int ledPin1 = 13;       // Control pin for LED 1
const byte ledPin2 = 12;       // Control pin for LED 2
const int servoPin4 = 6;      // Control pin for servo motor
int pulseWidth4 = 0;    // Amount to pulse the servo 4
long lastPulse4;
int minPulse = 150;   // minimum pulse width
int loop_cnt=0;
int ytilt;
int refreshTime = 20;  // the time in millisecs needed in between pulses

void setup() {
 Serial.println("PWM Begin"); pwm.begin(); pwm.setPWMFreq(60);
// This moves all servos to minimum positions at start.  Good if you do not want overloaded servos 
  pulseWidth1 = minPulse; pulseWidth2 = minPulse; pulseWidth3 = minPulse; pulseWidth4 = minPulse;     
// This initializes the Serial interface functions 
  Serial.begin(9600); Serial.print("loading sound card init\n"); delay(1000); Serial.print("card initialized");
    //Initializes nunchuck and servos
  nunchuk.init();
  delay(10);
}

void loop() {
// This initializes the servo read and write functions 
    checkNunchuck1(); updateServo1(); checkNunchuck2(); updateServo2(); checkNunchuck3(); updateServo3(); checkNunchuck4(); updateServo4();   
// This checks if buttons are pressed and then turns on two separate LED elements
     if(nunchuk.zButton == 1)  { pwm.setPWM(ledPin1, 4096, 0); delay(300); pwm.setPWM(ledPin1, 0, 4096); delay(300); }
     if(nunchuk.zButton == 1)  { pwm.setPWM(SoundPin2, 4096, 0); delay(300); pwm.setPWM(SoundPin2, 0, 4096); delay(300); }
    if (nunchuk.cButton == 1)  { pwm.setPWM(ledPin2, 4096, 0);  delay(300); }
    else { pwm.setPWM(ledPin2, 0, 4096); }
// This sets and reads the output from the nunchuck and stores them as floating variables 
  xjoystick = nunchuk.analogX; xjoystick = constrain(xjoystick, 26, 226); xjoystick = map(xjoystick, 26, 226, 0, 180);
  yjoystick = nunchuk.analogY; yjoystick = constrain(yjoystick, 26, 226); yjoystick = map(yjoystick, 26, 226, 180, 0);
  xtilt = nunchuk.accelX; xtilt = constrain(xtilt, 320, 720); xtilt = map(xtilt, 320, 720, 180, 0);
  ytilt = nunchuk.accelY; ytilt = constrain(ytilt, 320, 720); ytilt = map(ytilt, 320, 720, 0, 180);
// This prints the serial status of the nunchuck.
  Serial.print ("Joystick X: "); Serial.print (xjoystick, DEC); Serial.print ("\t");
  Serial.print ("Joystick Y: "); Serial.print (yjoystick, DEC); Serial.print ("\t");
  Serial.print ("X: "); Serial.print (xtilt, DEC); Serial.print ("\t");
  Serial.print ("Y: "); Serial.print (ytilt, DEC); Serial.print ("\t");
  nunchuk.update();
  if (nunchuk.cButton == 1) { Serial.print("--C--  ");  }
  if (nunchuk.zButton == 1) { Serial.print("--Z--  ");  }
  if (nunchuk.cButton == 1 && nunchuk.zButton == 1) { Serial.print("--Z-C--"); }
    Serial.print ("\r\n");
    }
// These are the functions to check and set the PWM settings for the servos   
void checkNunchuck1() { if( loop_cnt > 100 ) { float tilt = xjoystick; pulseWidth1 = map(xjoystick, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo1() { if (millis() - lastPulse1 >= refreshTime) { pwm.setPWM(servoPin1, 0, pulseWidth1); lastPulse1 = millis(); } }
void checkNunchuck2() { if( loop_cnt > 100 ) { float tilt = yjoystick; pulseWidth2 = map(yjoystick, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo2() { if (millis() - lastPulse2 >= refreshTime) { pwm.setPWM(servoPin2, 0, pulseWidth2); lastPulse2 = millis(); } }   
void checkNunchuck3() { if( loop_cnt > 100 ) { float tilt = xtilt; pulseWidth3 = map(xtilt, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo3() { if (millis() - lastPulse3 >= refreshTime) { pwm.setPWM(servoPin3, 0, pulseWidth3); lastPulse3 = millis(); } }
void checkNunchuck4() { if( loop_cnt > 100 ) { float tilt = ytilt; pulseWidth4 = map(ytilt, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo4() { if (millis() - lastPulse4 >= refreshTime) { pwm.setPWM(servoPin4, 0, pulseWidth4); lastPulse4 = millis(); } }

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Mon Apr 22, 2019 4:56 pm 

Service Number: A05/TQ2.0.32141E1
Country: United States
Well, thank you adafruit for always expanding your product offerings.

I redid the wiring on the cannons so I could use an ethernet patch cables on the cannon assemblies.

These products are what I got:
https://www.adafruit.com/product/2912 in the cannon
https://www.adafruit.com/product/2913 in the backpack housing
https://www.adafruit.com/product/827 through coupler for quick disconnect

in cannon with clip down:
pins
1 servo negative
2 servo positive
3 servo signal
7 led positive
8 led negative

In bay backpack housing:
3 led positive
4 led negative
6 servo signal
7 servo positive
8 servo negative

This substantially lessons the wire mess and makes things a lot cleaner and more easily repaired/concealed.

I used a regular ethernet patch cable. If you use a straight through or cross over cable or coupler the pinouts will be different.

For the cable covers I use ribbed cable covers you can buy at auto parts stores.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun May 05, 2019 2:17 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
I think this is the final code update. I will have to work with the servo setup on the back pack now and see what I can get. In light of recent videos I have found I may convert to a single cannon setup with a linear actuator type setup, but we will see.

Code:
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 8 servos, one after the other on the
  first 8 pins of the PCA9685

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815
 
  These drivers use I2C to communicate, 2 pins are required to 
  interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 * Nunchuck control for four servos and two button inputs
 * Honus 2007
 * This allows the use of a Wii nunchuck as an input device and is modified/extended from the original code
 * by Tod E. Kurt and Windmeadow Labs
 *2007 Tod E. Kurt, http://todbot.com/blog/
 * Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
 *
 * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
 *
 * Based on the following resources:
 *   http://www.windmeadow.com/node/42
 *   http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
 *   http://wiibrew.org/wiki/Wiimote/Extension_Controllers
 * Based on the following resources:
 *   http://www.gammon.com.au/blink
 *
 */
// www.facebook.com/ArduinoCenter
// https://blog.underc0de.org/arduino-wii-nunchuck-servo-motores/
// Original Code base credited to Undercode
// Code adapted from Sean Maio Crybabyfx setup
//https://github.com/outcry27/crybabyFX
// Updated by knoxvilles_joker 2017
// http://facebook.com/knoxvillesjoker
// more instructions documented at
// http://alienslegacy.com
 
#include "ArduinoNunchuk.h"
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)
#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
//end servo shield declarations

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
//Creates the objects to control the servos
ArduinoNunchuk nunchuk = ArduinoNunchuk();

#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  550 // this is the 'maximum' pulse length count (out of 4096)
int pulseWidth1 = 0;    // Amount to pulse the servo 1
int pulseWidth2 = 0;    // Amount to pulse the servo 2
int pulseWidth3 = 0;    // Amount to pulse the servo 3
long lastPulse1;
long lastPulse2;
long lastPulse3;
int xjoystick;
int yjoystick;
int xtilt;
const int SoundPin1 = 14;
const int SoundPin2 = 150;
const int servoPin1 = 9;      // Control pin for servo motor
const int servoPin2 = 11;      // Control pin for servo motor
const int servoPin3 = 10;      // Control pin for servo motor
const int ledPin1 = 2;       // Control pin for LED 1
const byte ledPin2 = 12;       // Control pin for LED 2
const int servoPin4 = 5;      // Control pin for servo motor
int pulseWidth4 = 0;    // Amount to pulse the servo 4
long lastPulse4;
int minPulse = 150;   // minimum pulse width
int loop_cnt=0;
int ytilt;
int refreshTime = 20;  // the time in millisecs needed in between pulses

void setup() {
  Serial.begin(9600);
 Serial.println("PWM Begin"); pwm.begin(); pwm.setPWMFreq(60);
// This moves all servos to minimum positions at start.  Good if you do not want overloaded servos 
  pulseWidth1 = minPulse; pulseWidth2 = minPulse; pulseWidth3 = minPulse; pulseWidth4 = minPulse; nunchuk.init (); delay(1000);     
// This initializes the Serial interface functions 
  Serial.println("Adafruit VS1053 Library Test"); musicPlayer.begin();
  SD.begin(CARDCS); printDirectory(SD.open("/"), 0); musicPlayer.setVolume(20,20);
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT);
  delay(500); musicPlayer.startPlayingFile("/t00next0.wav"); delay(1500); //PLAYS INIT SOUND
}

void loop() {
// This initializes the servo read and write functions 
    checkNunchuck1(); updateServo1(); checkNunchuck2(); updateServo2(); checkNunchuck3(); updateServo3(); checkNunchuck4(); updateServo4();   
// This checks if buttons are pressed and then turns on two separate LED elements
    if (nunchuk.zButton == 1) { musicPlayer.startPlayingFile("/T03NEXT2.WAV"); delay(1900); }
    checkzbutton(); checkcbutton();   
// This sets and reads the output from the nunchuck and stores them as floating variables 
  xjoystick = nunchuk.analogX; xjoystick = constrain(xjoystick, 26, 226); xjoystick = map(xjoystick, 26, 226, 0, 180);
  yjoystick = nunchuk.analogY; yjoystick = constrain(yjoystick, 26, 226); yjoystick = map(yjoystick, 26, 226, 180, 0);
  xtilt = nunchuk.accelX; xtilt = constrain(xtilt, 320, 720); xtilt = map(xtilt, 320, 720, 180, 0);
  ytilt = nunchuk.accelY; ytilt = constrain(ytilt, 320, 720); ytilt = map(ytilt, 320, 720, 0, 180);
// This prints the serial status of the nunchuck.
  Serial.print ("Joystick X: "); Serial.print (xjoystick, DEC); Serial.print ("\t");
  Serial.print ("Joystick Y: "); Serial.print (yjoystick, DEC); Serial.print ("\t");
  Serial.print ("X: "); Serial.print (xtilt, DEC); Serial.print ("\t");
  Serial.print ("Y: "); Serial.print (ytilt, DEC); Serial.print ("\t");
  nunchuk.update();
  if (nunchuk.cButton == 1) { Serial.print("--C--  ");  }
  if (nunchuk.zButton == 1) { Serial.print("--Z--  ");  }
  if (nunchuk.cButton == 1 && nunchuk.zButton == 1) { Serial.print("--Z-C--"); }
    Serial.print ("\r\n");
    }
// button
void checkzbutton() { if(nunchuk.zButton == 1)  { pwm.setPWM(ledPin1, 4096, 0); delay(300); pwm.setPWM(ledPin1, 0, 4096); delay(300);  delay(300); }}
void checkcbutton() { if(nunchuk.cButton == 1)  { pwm.setPWM(ledPin2, 4096, 0); delay(3000);}  else {pwm.setPWM(ledPin2, 0, 4096); delay(300);  }}
// File listing helper
void printDirectory(File dir, int numTabs) { while(true) { File entry =  dir.openNextFile(); if (! entry) { break; } for (uint8_t i=0; i<numTabs; i++) { Serial.print('\t'); } Serial.print(entry.name()); if (entry.isDirectory()) { Serial.println("/"); printDirectory(entry, numTabs+1); } else { Serial.print("\t\t"); Serial.println(entry.size(), DEC); } entry.close(); } }
// These are the functions to check and set the PWM settings for the servos   
void checkNunchuck1() { if( loop_cnt > 100 ) { float tilt = xjoystick; pulseWidth1 = map(xjoystick, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo1() { if (millis() - lastPulse1 >= refreshTime) { pwm.setPWM(servoPin1, 0, pulseWidth1); lastPulse1 = millis(); } }
void checkNunchuck2() { if( loop_cnt > 100 ) { float tilt = yjoystick; pulseWidth2 = map(yjoystick, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo2() { if (millis() - lastPulse2 >= refreshTime) { pwm.setPWM(servoPin2, 0, pulseWidth2); lastPulse2 = millis(); } }   
void checkNunchuck3() { if( loop_cnt > 100 ) { float tilt = xtilt; pulseWidth3 = map(xtilt, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo3() { if (millis() - lastPulse3 >= refreshTime) { pwm.setPWM(servoPin3, 0, pulseWidth3); lastPulse3 = millis(); } }
void checkNunchuck4() { if( loop_cnt > 100 ) { float tilt = ytilt; pulseWidth4 = map(ytilt, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo4() { if (millis() - lastPulse4 >= refreshTime) { pwm.setPWM(servoPin4, 0, pulseWidth4); lastPulse4 = millis(); } }

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Mon May 20, 2019 2:42 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
I have some more parts on order to try and get the pan and tilt assembly put together. I am trying to mimic the AVP cannon setup I saw. I am looking at a combo of using gears and chain setups.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Jun 23, 2019 9:07 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
assembly is together. I had to cut things down to fix some counterbalance issues. I have things very close size wize to what we saw in the movies. I will have to research some beefier servos at a later point but I doubt folks want to spend a 100 on a single servo versus 40 when the things like to break every now and then.

I have shortened the millis delay down to 10 which appears to be the max the Arduino likes to support for a shortened period. I have a metro m4 on the way to see if I can shorten that further as the less delay I have the more realitime response that I will see on response to the controls.

I had to dial back the pwm on the winchboat servo as the full pulse cause for a full 400 some degrees of rotation and we only need about 90 some degrees of rotation. I may try to change gear ratios so that the gears are not quite so obvious as the torque on the winch servo is insane.

Code:
C-like:
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 8 servos, one after the other on the
  first 8 pins of the PCA9685

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815
 
  These drivers use I2C to communicate, 2 pins are required to
  interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 * Nunchuck control for four servos and two button inputs
 * Honus 2007
 * This allows the use of a Wii nunchuck as an input device and is modified/extended from the original code
 * by Tod E. Kurt and Windmeadow Labs
 *2007 Tod E. Kurt, http://todbot.com/blog/
 * Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
 *
 * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
 *
 * Based on the following resources:
 *   http://www.windmeadow.com/node/42
 *   http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
 *   http://wiibrew.org/wiki/Wiimote/Extension_Controllers
 * Based on the following resources:
 *   http://www.gammon.com.au/blink
 *
 */
// www.facebook.com/ArduinoCenter
// https://blog.underc0de.org/arduino-wii-nunchuck-servo-motores/
// Original Code base credited to Undercode
// Code adapted from Sean Maio Crybabyfx setup
//https://github.com/outcry27/crybabyFX
// Updated by knoxvilles_joker 2017
// http://facebook.com/knoxvillesjoker
// more instructions documented at
// http://alienslegacy.com
 
#include "ArduinoNunchuk.h"
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)
#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
//end servo shield declarations

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
//Creates the objects to control the servos
ArduinoNunchuk nunchuk = ArduinoNunchuk();

#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  530 // this is the 'maximum' pulse length count (out of 4096)
int pulseWidth1 = 0;    // Amount to pulse the servo 1
int pulseWidth2 = 0;    // Amount to pulse the servo 2
int pulseWidth3 = 0;    // Amount to pulse the servo 3
long lastPulse1;
long lastPulse2;
long lastPulse3;
int xjoystick;
int yjoystick;
int xtilt;
const int SoundPin1 = 14;
const int SoundPin2 = 150;
const int servoPin1 = 9;      // Control pin for servo motor
const int servoPin2 = 4;      // Control pin for servo motor
const int servoPin3 = 10;      // Control pin for servo motor
const int ledPin1 = 2;       // Control pin for LED 1
const byte ledPin2 = 12;       // Control pin for LED 2
const int servoPin4 = 5;      // Control pin for servo motor
int pulseWidth4 = 0;    // Amount to pulse the servo 4
long lastPulse4;
int minPulse = 150;   // minimum pulse width
int loop_cnt=0;
int ytilt;
int refreshTime = 3;  // the time in millisecs needed in between pulses

void setup() {
  Serial.begin(9600);
 Serial.println("PWM Begin"); pwm.begin(); pwm.setPWMFreq(60);
// This moves all servos to minimum positions at start.  Good if you do not want overloaded servos
  pulseWidth1 = minPulse; pulseWidth2 = minPulse; pulseWidth3 = minPulse; pulseWidth4 = minPulse; nunchuk.init (); delay(1000);     
// This initializes the Serial interface functions
  Serial.println("Adafruit VS1053 Library Test"); musicPlayer.begin();
  SD.begin(CARDCS);
//  printDirectory(SD.open("/"), 0);
  musicPlayer.setVolume(20,20);
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT);
  delay(500); musicPlayer.startPlayingFile("/t00next0.wav"); delay(1500); //PLAYS INIT SOUND
}

void loop() {
// This initializes the servo read and write functions
    checkNunchuck1(); updateServo1(); checkNunchuck2(); updateServo2();
    checkNunchuck3(); updateServo3();
    checkNunchuck4(); updateServo4();   
// This checks if buttons are pressed and then turns on two separate LED elements
    if (nunchuk.zButton == 1) { musicPlayer.startPlayingFile("/T03NEXT2.WAV"); delay(1900); }
    checkzbutton(); checkcbutton();   
// This sets and reads the output from the nunchuck and stores them as floating variables
  xjoystick = nunchuk.analogX; xjoystick = constrain(xjoystick, 26, 226); xjoystick = map(xjoystick, 26, 226, 0, 180);
  yjoystick = nunchuk.analogY; yjoystick = constrain(yjoystick, 26, 226); yjoystick = map(yjoystick, 26, 226, 180, 0);
  xtilt = nunchuk.accelX; xtilt = constrain(xtilt, 320, 720); xtilt = map(xtilt, 320, 720, 180, 0);
  ytilt = nunchuk.accelY; ytilt = constrain(ytilt, 320, 720); ytilt = map(ytilt, 320, 720, 0, 180);
// This prints the serial status of the nunchuck.
  Serial.print ("Joystick X: "); Serial.print (xjoystick, DEC); Serial.print ("\t");
  Serial.print ("Joystick Y: "); Serial.print (yjoystick, DEC); Serial.print ("\t");
  Serial.print ("X: "); Serial.print (xtilt, DEC); Serial.print ("\t");
  Serial.print ("Y: "); Serial.print (ytilt, DEC); Serial.print ("\t");
  nunchuk.update();
  if (nunchuk.cButton == 1) { Serial.print("--C--  ");  }
  if (nunchuk.zButton == 1) { Serial.print("--Z--  ");  }
  if (nunchuk.cButton == 1 && nunchuk.zButton == 1) { Serial.print("--Z-C--"); }
    Serial.print ("\r\n");
    }
// button
void checkzbutton() { if(nunchuk.zButton == 1)  { pwm.setPWM(ledPin1, 4096, 0); delay(300); pwm.setPWM(ledPin1, 0, 4096); delay(300);  delay(300); }}
void checkcbutton() { if(nunchuk.cButton == 1)  { pwm.setPWM(ledPin2, 4096, 0); delay(3000);}  else {pwm.setPWM(ledPin2, 0, 4096); delay(300);  }}
// File listing helper
//void printDirectory(File dir, int numTabs) { while(true) { File entry =  dir.openNextFile(); if (! entry) { break; } for (uint8_t i=0; i<numTabs; i++) { Serial.print('\t'); } Serial.print(entry.name()); if (entry.isDirectory()) { Serial.println("/"); printDirectory(entry, numTabs+1); } else { Serial.print("\t\t"); Serial.println(entry.size(), DEC); } entry.close(); } }
// These are the functions to check and set the PWM settings for the servos   
void checkNunchuck1() { if( loop_cnt > 10 ) { float tilt = xjoystick; pulseWidth1 = map(xjoystick, 0, 180, SERVOMIN, 265); loop_cnt = 0; } loop_cnt++; }
void updateServo1() { if (millis() - lastPulse1 >= refreshTime) { pwm.setPWM(servoPin1, 0, pulseWidth1); lastPulse1 = millis(); }
//if (pulseWidth1 <= 170) {pwm.setPWM(14, 0, 130);}
if (pulseWidth1 >= 200) {pwm.setPWM(14, 0, 530);} else {pwm.setPWM(14, 0, 230);}
}

void checkNunchuck2() { if( loop_cnt > 10 ) { float tilt = yjoystick; pulseWidth2 = map(yjoystick, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo2() { if (millis() - lastPulse2 >= refreshTime) { pwm.setPWM(servoPin2, 0, pulseWidth2); lastPulse2 = millis(); } }   
void checkNunchuck3() { if( loop_cnt > 10 ) { float tilt = xtilt; pulseWidth3 = map(xtilt, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo3() { if (millis() - lastPulse3 >= refreshTime) { pwm.setPWM(servoPin3, 0, pulseWidth3); lastPulse3 = millis(); } }
void checkNunchuck4() { if( loop_cnt > 10 ) { float tilt = ytilt; pulseWidth4 = map(ytilt, 0, 180, SERVOMIN, SERVOMAX); loop_cnt = 0; } loop_cnt++; }
void updateServo4() { if (millis() - lastPulse4 >= refreshTime) { pwm.setPWM(servoPin4, 0, pulseWidth4); lastPulse4 = millis(); } }

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Jul 27, 2019 12:21 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
Current revision on display reviewed:
https://youtu.be/42oK4IWrk5g
- note I will have to redo as the AI on youtube flagged something.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Sun Sep 15, 2019 5:44 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
I am still working on this. I will have to rewrite in circuit python at some point


Attachment:
9F366348-8613-401D-A960-ECE95E152BFA.jpeg
9F366348-8613-401D-A960-ECE95E152BFA.jpeg [ 569.11 KiB | Viewed 5302 times ]

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject: Re: Build your own predator cannon
PostPosted: Mon Sep 23, 2019 3:19 am 

Service Number: A05/TQ2.0.32141E1
Country: United States
The Alorium board seems to be a no go with the servo control using the fpga coprocessor. I had to make a custom proto shield setup to work with the alorium board.

I will look at the circuit python option as the pieces do seem to be capable of being integrated.

_________________
The impossible takes a while longer and goes over budget too...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Sep 30, 2019 3:53 pm 
GarageGeek
User avatar

Country: United States
that adafruit wave shield is exactly what I need I think. does it use up all the arduino uno pins? Id love to have lights and sound activate at the same time without a second arduino.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3  Next



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: