Loading...
  Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Programming Questions / Re: Multiple LEDs blinking at different intervals plus servo sweep on: August 20, 2012, 10:05:17 pm
Thanks for the replies!  I haven't removed the LEDs yet, but the PING example returns very consistent readings.  I will try that next.  I am using a 4-pin (HC-SR04) sensor.

I have tried commenting out everything having to do with the LEDs and the serial info is still all over the place.  I am at a loss right now.  I will keep plugging away.

Thanks!
--e

I have also tried another Arduino (Duemilanove) with less LEDs and I get the same results.
2  Using Arduino / Programming Questions / Re: Multiple LEDs blinking at different intervals plus servo sweep on: August 20, 2012, 08:58:41 am
Thanks for the replies.  The range I was referring to is the limits of the ping (6600ms) not the range of the servo.  The servo has 180 degrees of motion and I don't think my code goes beyond this, correct?  I tried to sweep only 160 degrees in an earlier revision and that is what the commented code reflects, but this is in fact a 180 degree servo.  By verified, independently, do the package labels and product manuals count?  Other than that, the servo sweep example works fine.  The jitter/ pulse/ heating up I have issue with id when the motor does not completely STOP when the constraint of duration (6600) is reached.

The servo was pulsing (not completely off) when the sensor was reading around 6600 for duration.  While the sensor is consistently returning a value of less than 6600, the servo moves fluidly 180 degrees.


As far as what is :

Code:
  int sensorReading = digitalRead(pingPin);

Quote
What is this, in getDuration(), doing?

My friend that helped me clarify the code was working on a "buffer" where it looks for multiple readings longer than the expected duration.  The thought was to reduce the jitter, it was a variable to be called on in another idea. 

Basically another line I should have deleted before asking for advice.


My current goals are:
More accurate scaling/ reading of the ping sensor
----The readings bounce all over the place while the servo is connected.  Should I employ a greater than but less than range for this? 

If I could find out why the ping readings are inconsistent while the servo is connected I think the duration of 6600 would accurately "turn on and off" the device.  There is erratic behavior with the LEDs and the servo when it is "about to turn off".   

Is it possible that the LEDs (or even just the amount of them) is causing the PING sensor to not get consistent voltage from the 5v pin on the arduino?

Thanks for reading.
-e

3  Using Arduino / Programming Questions / Re: Multiple LEDs blinking at different intervals plus servo sweep on: August 19, 2012, 06:56:42 pm
I'm sorry.  I am not trying to waste anybody's time.  I should have removed the commented part,  It was in there from a previous revision.  I am not trying to offend anyone.  I am unaware if this is bad forum etiquette.

The servo would pulse and get hot while at the edge of the range.  I put in the detach to stop the servo's jitter while the ping is out of range.  Is there a better way to do this?

The serial.begin is commented because the servo AND the LED behavior was erratic with it un commented.  Is this normal?  No I did not read serial output with this commented.

Please suggest improvements.  I am trying to learn how to do this better, but don't know how to ask the right questions.
thanks
-e


 
4  Topics / Interactive Art / Re: Seedstudio Music Shield + Proximity Sensor? on: August 18, 2012, 11:39:20 pm
I haven't tried anything like that yet.  I am going to try some more with music shield soon too.  I have been tinkering with a random state for music shield so it doesn't always play songs in the loaded order, but haven't gone too far there either.

Good luck!  I will keep checking here to see what progresses too.
-e
5  Using Arduino / Programming Questions / Re: Multiple LEDs blinking at different intervals plus servo sweep on: August 18, 2012, 11:24:40 pm
Thanks for the help!!  I had a friend of mine help with my code.  I have a couple of questions that he couldn't answer. 

Now I have the ping sensor, servo, and LEDs mostly working.  However, while the servo is connected (and powered externally with grounds connected), the range on the ping sensor is inconsistent.  We verified this with serial monitor too.  I got most of what I wanted out of this sketch, but if anybody can suggest a "slicker" way to do any of this, or possibly help to explain why having the servo in the circuit causes anomalies, this would be awesome.

I'm not sure if this matters, but I am using the Mega 2560, as I quickly ran out of pins on my others.  If switching boards might help minimize conflict this is not a deal breaker.  Could another sensor be a better choice?

Thanks!
-e


Revised code:
Code:
const int pingPin = 20;
const int NUMLEDS = 18;
byte pin[NUMLEDS] = {
  2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
byte state[NUMLEDS] = {
  LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
unsigned long interval[NUMLEDS] = {
  400, 500, 1000, 722, 750, 325, 200, 800, 5000, 250, 1000, 300, 775 , 1000, 300, 500, 400, 250};
unsigned long time[NUMLEDS];
unsigned long servotime;

unsigned long degree_interval = 20;


#include <Servo.h>

Servo myservo; 

int servo_degree = 0; // variable to store the servo position
boolean forward = true;
long duration;

void setup()
{

  // initialize serial communication:
  //Serial.begin(9600);
 
  for (int i=0; i<NUMLEDS; ++i){
    pinMode(pin[i], OUTPUT);
  }

  myservo.attach(21);  // attaches the servo on pin 21 to the servo object
}

long getDuration(){
 
  int sensorReading = digitalRead(pingPin);
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  return duration;
}

void loop()
{
  //Serial.println();
  duration = getDuration();


  unsigned long m = millis();
 
  /*
  for(pos = 0; pos < 160; 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'

  }
  for(pos = 160; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'

  }
  */



    if (duration <= 6600){
     
     
      for (int i=0; i<NUMLEDS; ++i){
        if (m - time[i] > interval[i])
        {
          time[i] = m;
          state[i] = state[i] == LOW ? HIGH : LOW;
          digitalWrite(pin[i], state[i]);
        }
      }
     
     
      if( m - servotime >= degree_interval){
        myservo.attach(21);
        myservo.write(servo_degree);
       
        if(servo_degree >= 180){
          forward = false;
        }
        if(servo_degree <= 0){
          forward = true;
        }
       
        if(forward){
          servo_degree++;
        }
        else{
          servo_degree--;
        }
       
        servotime = m;
     
      }     
     
    }
    else{
      myservo.detach();
    }



}
6  Using Arduino / Programming Questions / Re: Multiple LEDs blinking at different intervals plus servo sweep on: August 15, 2012, 11:40:45 pm
Thank you!  I am in fact using pin 21 for the servo, I just didn't change the comment.  I will look into your suggestion.   I am very in experienced with this stuff, but i do want to learn.

Thanks!
-e

7  Using Arduino / Programming Questions / Re: Multiple LEDs blinking at different intervals plus servo sweep on: August 15, 2012, 10:27:31 pm


Ok.  I have made minute progress.  Here is the current code:


Code:
const int pingPin = 1;
const int NUMLEDS = 18;
byte pin[NUMLEDS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
byte state[NUMLEDS] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
unsigned long interval[NUMLEDS] = {100, 500, 1000, 722, 750, 325, 40, 800, 5000, 250, 1000, 1000, 1000, 50, 7500, 500, 400, 250};
unsigned long time[NUMLEDS];



#include <Servo.h>
 
Servo myservo; 
 
int pos = 0;   
 
void setup()

{
 for (int i=0; i<NUMLEDS; ++i)
   pinMode(pin[i], OUTPUT);

  myservo.attach(21);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
 
  int sensorReading = digitalRead(pingPin);
  long duration;
   pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
 
 
  unsigned long m = millis();
  for(pos = 0; pos < 160; 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'
   
  }
  for(pos = 160; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
   
  }
 
  {
 
if (duration <= 6600)
 for (int i=0; i<NUMLEDS; ++i)
   if (m - time[i] > interval[i])
   {
     time[i] = m;
     state[i] = state[i] == LOW ? HIGH : LOW;
     digitalWrite(pin[i], state[i]);
   }
if(duration >=6599)
myservo.write (0);
   
} }

First, the 6600 is arbitrary, but puts the distance pretty close to a kid knocking on a door and saying "trick or treat"

This does most of what I was hoping to accomplish.  I am able to flash many LEDs at different rates while the servo sweeps and it works with proximity.  I do have two unexpected results.  The servo continues to move (rapidly) back and forth while out of range (this is why I tried the
Code:
if(duration >2200) myservo.write (0)
, but it does not seem to change this), and the servo sweeps a bit erratic while in range (I am only going based on trial and error and have had some luck).  This is not a deal breaker, as I feel I have been moderately successful.

If someone could help me understand what I am doing wrong, and if there is any way to shorten/ revise my code that would be awesome.  I pretty much have the functionality I wanted, but I would like a more polished result.  I would also rather not burn up a servo too if there is a way to make it run properly. 

So I am in need of a tiny bit of guidance on making the servo sweep to take a bit longer, and stopping it when out of range.

Thanks!
-e
8  Using Arduino / Programming Questions / Re: Multiple LEDs blinking at different intervals plus servo sweep on: August 15, 2012, 07:16:28 pm
Thank you for the reply!!  I will look at that and do some experiments this evening.

I guess I should start by trying to adapt the servo sweep example to work without delay.  If I can do this, I can surely figure the rest out.  I am just picking up bits of info as I stumble around these forums.  I am trying to learn.  I need to read the knowledge base stuff and study up a bit.

I appreciate coaxing it out of me, instead of coding it for me.  I don't want to give up on this, I just don't know what I am doing and have little time to "play". 

Thanks!
-e
9  Community / Bar Sport / Re: OMG ! I am a God Member ! on: August 14, 2012, 09:27:25 pm
Congrats!!  It is often obvious based on post count alone how helpful someone is.  Sometimes there are those that post every waking thought, but for the most part those with as many posts as yourself know a thing or two.
-e
10  Using Arduino / Programming Questions / Re: Multiple LEDs blinking at different intervals plus servo sweep on: August 14, 2012, 09:18:22 pm
I just realized that I posted an earlier version of Mikal's code.  This is the one that I originally used FWIW:


Code:
/* Blink Multiple LEDs without Delay
*
* Turns on and off several light emitting diode(LED) connected to a digital
* pin, without using the delay() function.  This means that other code
* can run at the same time without being interrupted by the LED code.
*/
const int NUMLEDS = 18;
byte pin[NUMLEDS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
byte state[NUMLEDS] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
unsigned long interval[NUMLEDS] = {100, 500, 1000, 750, 750, 750, 750, 750, 5000, 250, 1000, 1000, 1000, 50, 7500, 500, 400, 250};
unsigned long time[NUMLEDS];

void setup()
{
 for (int i=0; i<NUMLEDS; ++i)
   pinMode(pin[i], OUTPUT);
}

void loop()
{
 unsigned long m = millis();

 for (int i=0; i<NUMLEDS; ++i)
   if (m - time[i] > interval[i])
   {
     time[i] = m;
     state[i] = state[i] == LOW ? HIGH : LOW;
     digitalWrite(pin[i], state[i]);
   }
}

Thanks~
-e
11  Using Arduino / Programming Questions / Multiple LEDs blinking at different intervals plus servo sweep on: August 14, 2012, 09:13:48 pm
Hello!  I am very out of practice with programming.  I am trying to prototype a robot Halloween costume for my almost 3 yr old.  I have adapted the sketch by mikalhart found here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1225593807
I have adapted the number of LEDs and the rates of flash (but I am pretty much using his code)  I love the idea that I can alter the blink of each in the array, but I am unsure of where to go next.

If nobody cares to click, I will post the sample code below. 

I would also love to have a servo sweep simultaneously (like an antenna or some other robot type device), but I am clueless as to how to implement this.

I have tried to simply cut and paste the servo sweep example into this sample code, and as many of you could imagine, the introduction of delay means the LEDs blink THEN the servo sweeps.

My original thought was to implement a ping sensor to "turn on" the costume (or off) at a certain distance, but I am lost and will graciously accept any help.  I have played with some other examples including the ping sensor (like parking assistants) that turn on LEDs, but blinky and servo are more important to the wife than proximity sensors.

I thank you for reading!  I am quite lost, so be gentle. smiley

Thanks!
-e

Mikal's code:

Code:
/* Blink Multiple LEDs without Delay
*
* Turns on and off several light emitting diode(LED) connected to a digital
* pin, without using the delay() function.  This means that other code
* can run at the same time without being interrupted by the LED code.
*/
int led1 = 13;                // LED connected to digital pin 13
int led2 = 12;
int value1 = LOW;                // previous value of the LED
int value2 = LOW;                // previous value of the LED
long time1 = millis();
long time2 = millis();

long interval1 = 1000;           // interval at which to blink (milliseconds)
long interval2 = 500;

void setup()
{
 pinMode(led1, OUTPUT);      // sets the digital pin as output
 pinMode(led2, OUTPUT);
}

void loop()
{
 unsigned long m = millis();

 if (m - time1 > interval1){
   time1 = m;

   if (value1 == LOW)
     value1 = HIGH;
   else
     value1 = LOW;

   digitalWrite(led1, value1);
 }

 if (m - time2 > interval2){
   time2 = m;

   if (value2 == LOW)
     value2 = HIGH;
   else
     value2 = LOW;

   digitalWrite(led2, value2);
 }
}

12  Using Arduino / Audio / Re: Piezo Element as Input/Output? on: March 03, 2012, 12:16:36 am
Has anyone seen Wayne and Layne's "tactile metronome"?  It uses PIC but does use piezo as in and out. 

Worth checking out to fish for ideas.
Post your results please.  I am curious to see what you are scheming!
-e
13  Using Arduino / Project Guidance / Re: 3 motor laser spirograph thingy on: July 03, 2011, 06:27:09 pm
So I wanted to share my "progress".  I have at this point 90% functionality but have just one question.  I now have a "random scene mode" (when all 3 pots are at max) that changes the image every 7 seconds.  And I am able to go back to "manual mode" by moving any pot away from max. 

The 7 second delay that holds the random image, however, means I don't have manual control until 7 seconds after moving pot away from max.

Is there an easy fix to ensure the device returns to manual mode sooner while leaving the 7 second "hold" of a random scene?

Here is my code:
   
Code:
#include <AFMotor.h>
    AF_DCMotor motor1(1);
   
    AF_DCMotor motor2(2);
   
    AF_DCMotor motor3(3);
   
    int potpin1 = 8;
    int potpin2 = 9;
    int potpin3 = 10;  // analog pin used to connect the potentiometer
    int i;
    int val1;
    int val2;
    int val3;          // variable to read the value from the analog pin

    void setup()
    {
      //Serial.begin(9600);           
    }

    void loop()
    {
     
      {
        val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
        val1 = map(val1, 0, 1023, 0, 255);   
        motor1.setSpeed(val1);      // sets the motor speed according to the scaled value
        motor1.run(FORWARD);
   
         
 
 
        val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
        val2 = map(val2, 0, 1023, 0, 255);   
        motor2.setSpeed(val2);      // sets the motor speed according to the scaled value
        motor2.run(FORWARD);
   
       
 
 
        val3 = analogRead(potpin3); // reads the value of the potentiometer (value between 0 and 1023)
        val3 = map(val3, 0, 1023, 0, 255);   
        motor3.setSpeed(val3);      // sets the motor speed according to the scaled value 
        motor3.run(FORWARD);
 


      if (val1 == 255 && val2 == 255 && val3 == 255)
       {
         motor1.setSpeed(random(0, 255));
         motor1.run(FORWARD);     
       

         motor2.setSpeed(random(0, 255));
         motor2.run(FORWARD);       
     

         motor3.setSpeed(random(0, 255));
         motor3.run(FORWARD);       
         delay(7000);
       }         

    delay(15);

   //Serial.println (val1);
   //Serial.println (val2);
   //Serial.println (val3);
      }}

You guys have been really helpful!
Thanks!!
-e
14  Using Arduino / Project Guidance / Re: two DC motors with diferent speed on: July 03, 2011, 06:13:13 pm
It might be overkill for that, but I like the adafruit motor shield which allows for 4dc motors or two steppers (other options as well) and I figured it out with a little help from users of this forum.

That Sparkfun one looks great if you don't need the other stuff.

Good luck!
-e

15  Using Arduino / Microcontrollers / Re: ardweeny programming on: July 03, 2011, 01:11:24 pm
Hey man thanks for the reply!

I have yet to get the ardweeny but I have already read conflicting reports.

Some would suggest that ardweeny and similar boards are looking for inverted data(1's in stead of o's or -5v in lieu of +5v)

I ordered a sparkfun programmer as I also have some Anarduino boards on the way and I will want to be able to program those too.  I will add some have said I could simply put the ardweeny in place of the ATmega on a duemilanove to program.  I have these things in quasi permanent projects so that is not currently an option.  I will however hack this rs232 cable to try once I get a chance and will post results.  I am cheap but far too impatient to not be able to program these boards.  

Thanks again!

If you can confirm or deny the rumors I have read that would help me by not wasting time in a fruitless effort though!
-e
Pages: [1] 2 3 ... 6