Show Posts
Pages: [1] 2 3 4
1  Forum 2005-2010 (read only) / Troubleshooting / Re: AVR include directory on: August 10, 2008, 12:37:09 am
zzpza:
Is your code "#include avr/io.h" or "#include io.h"?  I would think that if the environment sets the avr directory as a default location, then telling to check the avr directory would return as the file not being there.  I don't know if this is the case, but worth a try.

-Jon
2  Forum 2005-2010 (read only) / Troubleshooting / Re: URGENT !!! PLS HELP can't upload on: September 05, 2008, 11:34:27 am
I get that error everytime I accidentally hit upload before I hit reset on my sanguino or if I wait too long after it first powers up.  In my case it just means my bootloader only waits 3 seconds for communication from my laptop.  If it doesn't receive anything it starts running my sketch that's already on it and I have to reset it to upload anything.
3  Forum 2005-2010 (read only) / Troubleshooting / Re: URGENT !!! PLS HELP can't upload on: September 05, 2008, 01:34:25 am
Well, starting with the basics, have you tried reseting your arduino or unplugging it from power, waiting several minutes, and plugging it back in for another try?
4  Forum 2005-2010 (read only) / Troubleshooting / Re: weird looping bug after setting register on: September 09, 2008, 02:43:33 am
My only suggestions right now are:
1. try putting any function into the loop() routine so that it has something to do.  I don't know if this will have any affect but it can't hurt to try.
2. create a specific ISR to assign to the analog comparator interrupt.  maybe this code is defaulting to setup() when the AC interrupt triggers and loops that.

Granted that i'm sure your actual program probably has both of these, but I don't know what else to suggest this late (bought to go to bed).  Good luck.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Is it possible to write the OSCCAL register? on: September 05, 2008, 01:54:09 am
I didn't think about using it for multiple chips.  That would be a perfect reason to use the EEPROM.
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: Is it possible to write the OSCCAL register? on: September 05, 2008, 01:37:08 am
If you know your calibration value I don't know why you'd have to write it to EEPROM first before you burn your code.  I would think you'd be able to hard code it into your sketch and write it directly, unless the OSCCAL register is located in EEPROM, which wouldn't make sense to me.
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Is it possible to write the OSCCAL register? on: September 04, 2008, 01:20:03 pm
I'll have to read the datasheet again to check, but if OSCCAL is just another register you should be able to write to it from arduino.  It should be no different than writing PORTB = 0xEF to set the portb register to 11101111 as an example.  The thing to check in the data sheet is about setting fuses and whether they have anything to do with the internal oscillator calibration.
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Is it possible to write the OSCCAL register? on: September 04, 2008, 01:19:04 am
Don't quote me on this, but I'm pretty sure you'd have to change the bootloader to change the clock frequency aswell as some of the arduino core. Can anyone else confirm?
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Very odd error on: September 04, 2008, 01:24:20 pm
I agree with mem, sounds like you've hit the ram wall as it were.  Move any constants you have into flash and hopefully that should fix your problem.  From what I've seen the "trash" text you're describing sounds like filling up the ram and then having the data get corrupted by writing over itself.

The playground has information on how to use EEPROM and the Flash ram aswell as how to tell how much RAM you have left to use:
http://www.arduino.cc/playground/Main/GeneralCodeLibrary
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP on: July 09, 2008, 05:40:14 pm
Quote
thanks for your suggestions!

I ve tested something and when I think the code could be working its telling me " expected ) befor { token "

here is the new ON/OFF fading code:

   
if  (average >= 600 )                                                   //if the average is high enough
   { led1val = 250;                                    //set the brightness of LED1 - its normal FULL SHINE without fade
      LED1ON = millis ();                                                 //store what time LED1 was turned on
    }                                            
 if (average < 600 && (millis () - LED1ON <= 25 )         // if the average has gone below this range and the time elapsed from the
                                                                                  // change of the condition is less or equal 25ms
   { do { led1val -= ledDecay;                                  // start with fading out
            analogWrite (ledPin1, led1val);                      // write the fading value  
         }        
     while (led1val > 0);                                               // untill the LED is completly OFF
    }  


I really didnt think that the fading could be so dificult.... smiley-razz
Nothing worked well yet... nonstop looped fading, or just little bit blinking.....

But thanks to your comments I slowly start to understand the data flow smiley



if  (average >= 600 )                                                   //if the average is high enough
   { led1val = 250;                                    //set the brightness of LED1 - its normal FULL SHINE without fade
      LED1ON = millis ();                                                 //store what time LED1 was turned on
    }                                            
 if (average < 600 && (millis () - LED1ON <= 25 ))         // if the average has gone below this range and the time elapsed from the
                                                                                  // change of the condition is less or equal 25ms
   { do { led1val -= ledDecay;                                  // start with fading out
            analogWrite (ledPin1, led1val);                      // write the fading value  
         }        
     while (led1val > 0);                                               // untill the LED is completly OFF
    }

You missed a ) in the if second if statement (see where I put the red one).
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP on: July 09, 2008, 11:12:00 am
Quote
Quijonsith thanks a lot!

I´ve tried your notes and here is the result:

1.)GOOD NEWS: map function is mostly working. I´ve made simple code to test it:

average=map(average, 170, 700, 0, 255);
analogWrite (ledPin1, average);

it is working, but only when IR is detcting something.
BUT when the space infront of the IR is empty ( so the measured data is about 160 -- so this might be remaped to 0) the LED is fully shining. Thats the first problem... smiley-razz

The result was that when I was in range, the LED lights on}OK thats GOOD!) and stay shining even when I moved out of the range... (thats BAD...)

So I ve tried simple test of the fading code:

if (average >= 600 )         //if the average is high enough and LED1 is not already on  
     { led1val=255;            // set the starting value to max  
       led1val -= ledDecay;  //  start fading out LED1's brightness
      analogWrite (ledPin1, led1val);  //set LED1 to it's brightness
     }


But the result was , the same - LED starts shinig and stay shining all the time and didnt react on anything....

3.) I ve noted that when LED puted on PWM+ (just pin6) and no specified data is send there, the LED is shining.
(i ve just declard it as output - nothing more...). Is it normal? But the PWM+ in pin 5 doesn´t do this....

To fix the new problem you could reverse all of your code, changing 255's to 0's and 0's to 255's aswell as changing to ledval-= to ledval+=, or you could do it the easy way and reverse your LED as it sounds to me like it's in backwards. smiley-wink

The millis() function returns the number of milliseconds since the program started, so it's like an internal clock.  So when it says LED1ON = millis(), if the program has been running for 7298319 milliseconds, that's what is stored in LED1ON.  Then later when you have if(millis() - LED1ON >= interval) it's comparing the current number of milliseconds since program start to LED1ON.  So "interval" is how many milliseconds the LED will stay on until it starts to fade out.

Using millis() instead of delay() allows the program to do other things (like compare the other ranges) while it waits to fade the LED, instead of sitting and doing nothing until it's time to fade the LED.  So using:
LED1ON = millis();
if(millis() - LED1ON >= interval);

is the same as:
delay(interval);

Only it lets your program keep running.  If the LED isn't fading out smoothly/slowly enough for you then you can decrease the subtraction, such as led1val-=1.  If it starts fading too soon, increase interval.

You could also hook a potentiometer up to another analog input and read it's value as interval, or do the same for the subtraction value, or both, and you would be able to adjust them while the program is running without having to rewrite your program every time.

Also:
if (average >= 600 )         //if the average is high enough and LED1 is not already on  
     { led1val=255;            // set the starting value to max  
       led1val -= ledDecay;  //  start fading out LED1's brightness
      analogWrite (ledPin1, led1val);  //set LED1 to it's brightness
     }


The problem with this test fade code is every time it runs it sets led1val to 255, so even though it subtracts afterwards, as long as you're >=600, led1val gets set to 255 again.  The subtraction and analogwrite should be outside the if statement.

Try my code again, but with the LED reversed from how it is now and try simply adjusting ledDecay and interval as I described.

Also, you are correct about using && in the if statement.  That's why I asked you to look it over smiley-wink.  I haven't programmed in a long time so I'm still remembering the syntax.

[edit]Also, here's the reference for millis():
http://www.arduino.cc/en/Reference/Millis[/edit]
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP on: July 09, 2008, 12:45:09 am
Quote
long time;                       // pocita cas millis od spusteni programu
long LED1ON = 0;                 // will store last time LED1 was used
int interval = 1;                // interval rozdilu mezi ON/OFF

void loop() {
   if (average >= 600)
      { ledval = 255;
       analogWrite (ledPin1, ledval);
        LED1ON = millis ();}
So far you defined your time tracking variables (though I didn't see the time variable used in your code).  Then you check if your reading is over 600.
If it is, you set your ledval = 255 (max analog output), then set the analog pin "ledPin1" to ledval, in other words turn on the led at full brightness.
Then you're recording the time, in milliseconds, that the led was turned on by setting LED1ON = millis().
Quote
     else
      {analogWrite (ledPin1, 250); }
      if (millis () - LED1ON == interval);
      ledval -= 25;
      {analogWrite (ledPin1, ledval);}
      if (ledval=0);
      {return;}
}
Then you have what happens if the average is not >=600.
First you have it set the ledPin1 output to 250, which is almost full on and not enough really difference to see it being dimmer than full on. So no matter what, you're turning that LED on and full brightness.
Next you're checking if the current time - LED1ON = interval.  Interval is set to 1, so you're checking if the current time is 1 millisecond greater than when LED1ON was set.  The problem there is the timing.  It would be very hard to have the interval actually = 1 millisecond.  This should be checking to see if millis() - LED1ON >= interval.
Next you're trying to gradually lower ledval by 25 and write that to ledPin1.
Finally, if ledval is 0, leave the routine.
Quote
Thanks a lot for any idea and suggestion!
P.S.: Sorry of my english - I am not native speaker....
Personally I think your english is excellent for not speaking it natively.  Sometimes the hardest thing to do is try smiley-wink
Now on to some code suggestions:

If I understand you correctly, you want the LED to turn on only when the value first gets to that range, then fade out, even if it's still in that range, and the problem is that your LED is staying on as long as the range is true.  If that's the case, here's how I would solve that problem aswell as making the LED fade reliably:

long LED1ON = 0;                 // will store last time LED1 was used
int interval = 1;                // interval rozdilu mezi ON/OFF
int LED1Trigger = 0;            //stores if LED1 is already on
int led1val = 0;                   //analog output for led1
int ledDecay = 25;              //how fast the leds fade to off
...

void loop() {
   if (average >= 600 & LED1Trigger == 0) //if the average is high enough and LED1 is not already on
      { led1val = 250;  //set the brightness of LED1
        LED1Trigger = 1;  //store the fact that LED1 is now on and average has not gone out of range

        LED1ON = millis ();}  //store what time LED1 was turned on
  if (average < 600 & LED1Trigger == 1)  //if the average has gone below this range and LED1 was already on
       {LED1Trigger = 0;}      //store the fact that average has gone out of this range
      if (millis () - LED1ON >= interval & led1val > 0);  //if it has been more than "interval" milliseconds since LED1 was turned on and LED1 has not dropped to 0 brightness
      {led1val -= ledDecay;}  //start fading out LED1's brightness

   analogWrite (ledPin1, led1val);  //set LED1 to it's brightness
}

A couple of notes:
ledDecay can be used the same for all ranges and LEDS.  Making it higher will of course make them fade faster.
The way this is setup, if you were to remake the code for all of your ranges this way (seperate variables for each range such as LED2Trigger, led2val, LED3Trigger, etc.) then you could have one led turn on while another one is still fading out, but none of them "should" stay on with this code unless you are rapidly moving in and out of the same range.

There are other modifications I could do to this code, such as making the LEDs fade out on a logarithmic scale instead of a linear one, but for now this should get you going unless I've missed something or messed up any of the syntax.  Please look over my code when you test it to make sure I didn't misspell any variables (ledDecay does not need to be made led1Decay, led2Decay, etc) and I haven't missed any symbols like {} or anything.

As far as maping your data from 170-700 to 0-255, you could use the map () function like this:
average = map(average, 170, 700, 0, 255);

This function works with integers.  See http://www.arduino.cc/en/Reference/Map

Hope this is what you are looking for.  I'd love to see some video of your LEDs in action if possible smiley-wink

Have fun with your project,
-Jon

PS:  Is this just something to experiment with or do you have a larger project/goal you're planning?
This actually gives me ideas to use this technique with audio as the source like you're using IR.  I like the idea of only turning on the first time the value is in range.
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP on: July 08, 2008, 10:15:01 pm
If all you need is to fade the LEDs out once they shouldn't be on, that's not very hard.  I'm at work right now, but when I get home tonight I'll work up a couple algorithms for you to try and see which you like better.

As far as the beginner questions, quite frankly I would consider this to be slightly above beginner and into the realm of intermediate atleast.  Beginner would be simply getting the LEDs to light smiley-wink
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP on: July 08, 2008, 01:41:05 pm
Hmm, it just occurred to me that the averaging routine as you originally wrote it, JURA, would properly average all the readings in the readings[] array, so my correction to your code is wrong.  My incorrection would merely track the current reading.  In otherwords, ignore the code I posted.  Sorry smiley-sad.  I'll have to analyze your code further and see what I can come up with.

Can you give a more detailed description of what happens with the hardware.  How exactly does each LED light in response to what your IR sensor reads?  Do the numbers you read from the serial port agree with what you're testing? Are you using an IR LED at different ranges to test the sensor?
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP on: July 08, 2008, 01:30:56 pm
Didn't know the declaration wasn't required.  Thanks ccarlson
Pages: [1] 2 3 4