Show Posts
Pages: [1] 2 3
1  Using Arduino / General Electronics / Re: Rocker Switch - SPST on-off Wiring Question on: April 24, 2013, 10:04:55 pm
Thanks strykeroz...this approach seems much simpler than the direction I was heading...

So I take the power supply from my 26 leds pass it through a 10 k resister and send it to a digital pin (32) which I read using digitalRead()...

I think I understand the theory of a pull down resistor, but am not sure how to wire it.

Do I attach digital pin (32) to another 10 k resistor that is connected to ground?

This is the code I plan to use read values and apply conditions based on LED states. Does this look right?

Code:
int inPin = 32; // LED power supply connected to digital pin 32 via 10k resistor
int val = 0;     // variable to store the read value

void setup()
{
  pinMode(inPin, INPUT);      // sets the digital pin 32 as input
}

void loop()
{

val = digitalRead(inPin);   // read the input pin

if(val==0){
//leds are OFF do something here
} else{
//leds are ON do something else here
}

}
2  Using Arduino / General Electronics / Rocker Switch - SPST on-off Wiring Question on: April 23, 2013, 10:13:04 pm
I got this SPST on-off rocker switch for a project I'm building...





https://www.sparkfun.com/products/11155

http://youtu.be/yLMBnXXo6pw?t=1m55s

My current set up:

I have 5V power going into the outer silver lead, the middle silver lead going to a bread board supplying power to 26 leds, and the gold lead going to ground. Everything works as it should when I toggle between the two position on the switch (leds toggle on and off)...

I would like to add some more functionality to the switch, by making it set a boolean in my Arduino sketch...

Does anyone have any advice on how to wire this switch to accomplish this task? Do I need to get a relay or can I accomplish this with the switch alone?

3  Using Arduino / Programming Questions / Re: Wave Shield + Mega + Multiple Servos (WAVHC + Servo Timer 2) on: February 11, 2013, 10:27:29 am
Hehe...I need separate stepper functions b/c I'll likely have to calibrate each servo individually. I actually don't plan on using all servos at the same time. I was just doing a test in the init() to see what would happen, and was curious why I was getting this behaviour. It'll will be great to have the option to use all servos at the same time now.
4  Using Arduino / Programming Questions / Re: Wave Shield + Mega + Multiple Servos (WAVHC + Servo Timer 2) on: February 11, 2013, 10:20:51 am
I now realize that the delay() in each function is probably causing issues, making the servos appear to rotate in queue. I'll use an interval AND millis() (http://arduino.cc/en/Tutorial/BlinkWithoutDelay) to set rotation and report back.
5  Using Arduino / Programming Questions / Re: Wave Shield + Mega + Multiple Servos (WAVHC + Servo Timer 2) on: February 11, 2013, 09:54:15 am
I solved my issues with multiple servos by using an external 5 V 1 AMP alternating PSU. I can now rotate 4 servos independently.

The one thing I noticed is that I have four stepper functions to control each servo. If I call all stepper functions at the same time, each servo will rotate as if they are in a queue and not at the same time. Is this because you can only use one servo at a time because they use same Timer (Servo Timer 2 uses Timer 2)?

Here's my code:


Code:

ServoTimer2 myservo1;
ServoTimer2 myservo2;
ServoTimer2 myservo3;
ServoTimer2 myservo4;

int servoPin1 = 6;//9;
int servoPin2 = 7;//10;
int servoPin3 = 8;//10;
int servoPin4 = 9;//10;
#define degreesToUS( _degrees) (_degrees * 6 + 900) // macro to convert degrees to microseconds
int pos = 50;    // variable to store the servo position
//servo vars

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
  Serial.println("slave setup");
 
  initServo();
}

void initServo()
{
  Serial.println("initServo");
 
  pinMode(servoPin1, OUTPUT);
  pinMode(servoPin2, OUTPUT);
  pinMode(servoPin3, OUTPUT);
  pinMode(servoPin4, OUTPUT);

  // set up servo pin
  myservo1.attach(servoPin1);
  myservo2.attach(servoPin2);
  myservo3.attach(servoPin3);
  myservo4.attach(servoPin4);
 
  stepper1();
  stepper2();
  stepper3();
  stepper4();
}


int stepper1(){
  Serial.println("stepper1");

  for(pos = 1400; pos < 1700; pos += 15)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 1700; pos>=1400; pos -=15)     // goes from 180 degrees to 0 degrees
  {                               
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

int stepper2(){
  Serial.println("stepper2");

  for(pos = 1400; pos < 1700; pos += 15)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 1700; pos>=1400; pos -=15)     // goes from 180 degrees to 0 degrees
  {                               
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

int stepper3(){
  Serial.println("stepper3");

  for(pos = 1400; pos < 1700; pos += 15)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo3.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 1700; pos>=1400; pos -=15)     // goes from 180 degrees to 0 degrees
  {                               
    myservo3.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

int stepper4(){
  Serial.println("stepper4");

  for(pos = 1400; pos < 1700; pos += 15)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo4.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 1700; pos>=1400; pos -=15)     // goes from 180 degrees to 0 degrees
  {                               
    myservo4.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
6  Using Arduino / Programming Questions / Re: Wave Shield + Mega + Multiple Servos (WAVHC + Servo Timer 2) on: February 03, 2013, 09:48:31 am
Here are links to the ServoTimer2 library I'm using.

ServoTimer2.h
http://pastebin.com/tjFBRen4

ServoTimer2.cpp
http://pastebin.com/a1DQyNQq

I guess the next test is to power the servos externally.
7  Using Arduino / Programming Questions / Re: Wave Shield + Mega + Multiple Servos (WAVHC + Servo Timer 2) on: February 03, 2013, 08:07:07 am
I tried using two different power sources for my Mega:

1) 9VDC 650 mAmp
2) 12VDC 2.5 A

which supply power to servos via 5V pin.


These are the servos:
http://fr.hobbytronics.co.uk/powerhd-3001hb
8  Using Arduino / Programming Questions / Re: Wave Shield + Mega + Multiple Servos (WAVHC + Servo Timer 2) on: February 03, 2013, 07:38:41 am
This is the sketch that is causing issues when I use the WAV shield:

http://pastebin.com/Ku7bXHFV

It excreeds maximum allowed length so I posted it on PasteBin.

What's curious is that this demo sketch uses the same hardware and libraries as me and appears to have no servo issues:

http://rayjk.com/sites/default/files/article-files/12-Halloween%20Pumpkin/HalloweenPumpkin.pde
9  Using Arduino / Programming Questions / Wave Shield + Mega + Multiple Servos (WAVHC + Servo Timer 2) on: February 02, 2013, 11:37:00 pm
I'm having issues getting two servos to work with a MEGA + WAV Shield using WAVHC and Servo Timer 2 libraries. The libraries use separate timers, so there should not be any timer conflicts.

Basically I can get myservo1 to work fine, but issues arise when I add a second servo. I have two servos attached to pins 6, 7...If I call stepper2()...myservo2 will rotate fine...BUT if I call stepper1(), both servos rotate when it should only be myservo1 that rotates.

If I remove the WAV shield and upload this simplified sketch everything works fine. I can call each stepper function separately and rotate each servo independently.

Code:

#include <ServoTimer2.h>  // the servo library

ServoTimer2 myservo1;
ServoTimer2 myservo2;
int servoPin1 = 6;
int servoPin2 = 7;
int pos = 50;    // variable to store the servo position

void setup() {
  initServo();
}

void initServo()
{
  Serial.println("initServo");
  
  pinMode(servoPin1, OUTPUT);
  pinMode(servoPin2, OUTPUT);
  
  // set up servo pin
  myservo1.attach(servoPin1);
  myservo2.attach(servoPin2);
  
  stepper1();
  delay(5000);
  stepper2();
  delay(5000);
  stepper1();
  stepper2();
}

void loop()
{
  
}


int stepper1(){
  Serial.println("stepper1");

  for(pos = 1400; pos < 1700; pos += 15)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 1700; pos>=1400; pos -=15)     // goes from 180 degrees to 0 degrees
  {                                
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

int stepper2(){
  Serial.println("stepper2");

  for(pos = 1400; pos < 1700; pos += 15)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 1700; pos>=1400; pos -=15)     // goes from 180 degrees to 0 degrees
  {                                
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

If anyone has any tips and suggestions on how to get multiple servos working independently with this setup please let me know.
10  Using Arduino / Programming Questions / Re: MegaServo + WAVHC Lib Conflict (WAV Shield and Servo working together) on: May 23, 2012, 02:24:06 pm
So if I'm using the Servo library and using pin 9 on my Mega like in my sketch above:

Code:
myservo.attach(9);

Then the timer being used should be 5 not 1?

Basically any pins from 1-11 used for servos should be using timer 5 on the Arduino Mega?

I've tried using pin 9 with the Servo library together with the WAVHC library and get this compiler conflict.

This is the error:

"Servo/Servo.cpp.o: In function `__vector_17':
/Applications/Arduino.app/Contents/Resources/Java/libraries/Servo/Servo.cpp:103: multiple definition of `__vector_17'
WaveHC/WaveHC.cpp.o:/Users/smjohn/Documents/Arduino/libraries/WaveHC/WaveHC.cpp:41: first defined here"

So far it seems the only route to get a servo working with the WAV shield is ServoTimer2.
11  Using Arduino / Programming Questions / MegaServo + WAVHC Lib Conflict (WAV Shield and Servo working together) on: May 16, 2012, 12:25:47 am
My problem:
I need the use the Adafruit WAV shield and a servo at the same time, but the WAVHC library cannot be used with the standard Servo library because they both use Timer1.

I've read a lot of posts about people using ServoTimer2 with the WAVHC libarary, but I can't get any of the ServoTimer2 examples to compile at all under Arduino 1.0 with all the usual library patches. This library seems to have a lot of conflicts with Arduino.h.

I read that the MegaServo library uses different timers so I was hoping it would be a work around.
http://arduino.cc/playground/Code/MegaServo

I'm getting an compiler error when I have a sketch that includes but the MegaServo library and WAVHC library.

"MegaServo/MegaServo.cpp.o: In function `__vector_17':
/Users/smjohn/Documents/Arduino/libraries/MegaServo/MegaServo.cpp:120: multiple definition of `__vector_17'
WaveHC/WaveHC.cpp.o:/Users/smjohn/Documents/Arduino/libraries/WaveHC/WaveHC.cpp:41: first defined here"

I'm using an Arduino Mega, with servo on pin 9.

Using the MegaServo lib alone works fine.

Code:
#include <MegaServo.h>
 
MegaServo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 50;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  for(pos = 50; pos < 110; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 110; pos>=60; pos-=1)     // goes from 180 degrees to 0 degrees
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  
   Serial.println(pos);
}


Anyone have any suggestions on how to resolve this conflict? It is a timer conflict? If yes, is there another way to get a servo to work with this WAV shield? I've tried writing to the servo pins directly (digitalWrite(servoPin, HIGH)), which allows me to use the WAVHC library at the same time. I would rather use an existing library to have more control over the servo. Is there a way to hack the standard servo library to not use Timer1?
12  Using Arduino / General Electronics / Re: 1 External Reset Button for 2 Arduino Megas Connected via I2C on: May 06, 2012, 12:52:11 am
Thanks for the help RuggedCircuits.
13  Using Arduino / General Electronics / 1 External Reset Button for 2 Arduino Megas Connected via I2C on: May 05, 2012, 11:28:28 pm
I'm attempting to make a one external reset button that will reset two Arduino Megas (master/slave setup) that are connected via I2C.

I'm using an illuminated arcade button.





It has three pins: com, normal open, normal closed.

I'm going to connect the com pin to ground and the normal open pin to the reset pin of the Master Arduino.

Will this setup reset both boards or will it only reset the Master board? Do I need to connect the reset pin of the Slave Arduino to the normal open pin on the switch? My goal is to reset BOTH board in the setup when you press the button.
14  Using Arduino / Programming Questions / Re: Mega (Master Writer)/ UNO (Slave Receiver) I2C Problem on: April 28, 2012, 10:05:26 pm
Thanks for clearing things up Nick. I think I'm understanding how the Wire library works now. Printing to serial was just for debuging purposes....I'll be commenting those lines out.
15  Using Arduino / Programming Questions / Re: Mega (Master Writer)/ UNO (Slave Receiver) I2C Problem on: April 28, 2012, 08:32:03 pm
Paul,

Eureka! It's working now..I can see my traces!

Thanks for following this thread and helping me out! Really appreciate it. I thought I had to use the MEGA's SDA (20) pin as the transmission param for the Wire library...

I guess the pin you pass in as a param for transmission is the pin you're targeting on the slave board?




Pages: [1] 2 3