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(); } }