Author Topic: issue with delay function  (Read 5634 times)

patcoyle

  • Newbie
  • *
  • Posts: 3
issue with delay function
« on: January 29, 2013, 10:57:36 pm »
I'm brand new, so this may be a simple operator error. However, in trying to get my DigiSpark going, I tried making the following revision to the DigiSpark Start example.

The simple intent is to send two short 5v pulses, followed by a longer delay in order to trigger two CHDK enabled Canon cameras via USB remote while allowing ample time for the cameras to save and be ready for next photo based on the next pair of trigger pulses.

For example of intended application to aerial photo-mapping see:
 http://publiclaboratory.org/notes/patcoyle/1-21-2013/balloon-mapping-meetup-saturday-11213-san-francisco

My issue is that based on visual observation of the on-board LED, the delay at the end of the loop doesn't seem to vary even when I dramatically increase it as shown in the code. I had earlier tried 5 and 10 seconds, with no apparent difference.

I sure appreciate the help. Thanks, Pat
I tried this: CHDK_trgr_bsd_on_Start3
***

Just running plugged into USB hub (but had verified the DigiSpark Start sketch ran ok after unplugging from USB and powering with 9V battery)
Issue is that increasing final delay, or even putting in multiple lines does not seem to change the loop cycle. Here is the code.

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  // pinMode(0, OUTPUT); //LED on Model B
  pinMode(1, OUTPUT); //LED on Model A (the model we have)   
}
// the loop routine runs over and over again forever:
void loop() {
              // intent is to trigger CHDK USB remote w pair of short on/off
              // pulses followed by a longer delay, then repeat
              // however, looking at LED, changing last line doesn't seem to vary delay
              // turn the 5V and LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  delay(100);               // wait for a 0.1 second
  // digitalWrite(0, LOW);    // turn the 5V and LED off by making the voltage LOW
  digitalWrite(1, LOW);
  // digitalWrite(0, HIGH);   // for 2nd time turn the 5V and LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  delay(100);               // wait for a 0.1 second
  // digitalWrite(0, LOW);    // turn the 5V and LED off by making the voltage LOW
  digitalWrite(1, LOW);
  delay(30000);               // wait for 30 seconds between pairs of on/off pulses, then repeat
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               // wait for 30 seconds between pairs of on/off pulses, then repeat
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               // wait for 30 seconds between pairs of on/off pulses, then repeat
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               // wait for 30 seconds between pairs of on/off pulses, then repeat
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
}

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: issue with delay function
« Reply #1 on: January 30, 2013, 12:18:05 am »
This is performing as expected for me.


I get one about 200ms pulse of the LED (since you don't have any delay between turning it off and back on between the two 100ms pulses)


Then I get a really really long delay - I put an LED pulse between each 30 seconds and checked against a clock as well.




Do you have your board set to Digispark (Tiny Core)?




patcoyle

  • Newbie
  • *
  • Posts: 3
Re: issue with delay function
« Reply #2 on: January 30, 2013, 10:19:48 am »
Thanks, I checked and per the instructions:
  • From the Tools menu selected Board→Digispark
  • From the Tools menu selected Programmer→Digispark
Then uploaded, but still don't get the long delay. I have three, so tried them all. Same thing. Any other tips or suggestions? Thanks again.

Tried adding a for loop to force the delay, as shown below:

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  // pinMode(0, OUTPUT); //LED on Model B
  pinMode(1, OUTPUT); //LED on Model A (the model we have)   
}

// the loop routine runs over and over again forever:
void loop() {
              // intent is to trigger CHDK USB remote w pair of short on/off
              // pulses followed by a longer delay, then repeat
              // however, looking at LED, chnging last line doesn't seem to vary delay
              // turn the 5V and LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  delay(100);               // wait for a 0.1 second
  // digitalWrite(0, LOW);    // turn the 5V and LED off by making the voltage LOW
  digitalWrite(1, LOW);
  // digitalWrite(0, HIGH);   // for 2nd time turn the 5V and LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  delay(100);               // wait for a 0.1 second
  // digitalWrite(0, LOW);    // turn the 5V and LED off by making the voltage LOW
  digitalWrite(1, LOW);
 
  // try a for loop to get delay

   for (int i=0; i <= 255; i++){ 
      delay(1000);
   }
 
  delay(30000);               // wait for 30 seconds between pairs of on/off pulses, then repeat
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               // wait for 30 seconds between pairs of on/off pulses, then repeat
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               // wait for 30 seconds between pairs of on/off pulses, then repeat
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               // wait for 30 seconds between pairs of on/off pulses, then repeat
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
  delay(30000);               //extras for testing
}

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: issue with delay function
« Reply #3 on: January 30, 2013, 12:24:43 pm »
Is this your entire code? No includes at the top? Your not including DigiUSB or anything like that?


Whatever is happening it isn't hardware related - it is something software for sure.


Are you running the latest software as well?


What operating system?

patcoyle

  • Newbie
  • *
  • Posts: 3
Re: issue with delay function
« Reply #4 on: January 30, 2013, 02:11:40 pm »
Thanks again, plugged into different USB port rather than the USB hub and got success.

The following now waits the 5 seconds, then blinks, repeatedly.

This is the entire code. Not sure if it is the latest software. Running on Windows 7 laptop.

Thanks for your patience and help! Pat


// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(1, OUTPUT); //LED on Model A (the model we have)   
}

// the loop routine runs over and over again forever:
void loop() {
              // intent is to trigger CHDK USB remote w pair of short on/off
              // pulses followed by a longer delay, then repeat
              // however, looking at LED, chnging last line doesn't seem to vary delay
              // turn the 5V and LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  delay(100);               // wait for a 0.1 second
              // turn the 5V and LED off by making the voltage LOW
  digitalWrite(1, LOW);
 
              // for 2nd time turn the 5V and LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  delay(100);               // wait for a 0.1 second
              // turn the 5V and LED off by making the voltage LOW
  digitalWrite(1, LOW); 
 delay(500);               //wait 0.5 sec
  delay(500);               //wait 0.5 sec
  delay(500);               //wait 0.5 sec
  delay(500);               //wait 0.5 sec
  delay(500);               //wait 0.5 sec
  delay(500);               //wait 0.5 sec
 delay(500);               //wait 0.5 sec
 delay(500);               //wait 0.5 sec
  delay(500);               //wait 0.5 sec
  delay(500);               //wait 0.5 sec
}

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: issue with delay function
« Reply #5 on: January 30, 2013, 02:34:47 pm »
This works as expected for me the light blinks once every 5 seconds - if that is not the result you are getting please try downloading a fresh copy of the software.

mmbutler

  • Newbie
  • *
  • Posts: 4
Re: issue with delay function
« Reply #6 on: January 31, 2013, 12:21:08 am »
I'm afraid I too am having problems with the delay() function. I'm having substantially the same problem as the original poster. My test case is simpler.


I loaded the recommended "first upload":  Examples --> Digispark --> Start code.


It worked, but I noticed that the flashing is not one second off and one second on; it's a bit faster than that. This made me curious.


I then changed the delays from 1000 to 4000, go through the disconnect, hit-upload-button, and reconnect-when-prompted; download appeared successful(?) but the rate of flashing is the same as before.


I note that the original poster tried a different USB connection, apparently to a root hub port rather than a secondary hub. I'll try that.
« Last Edit: January 31, 2013, 10:13:35 pm by mmbutler »

mmbutler

  • Newbie
  • *
  • Posts: 4
Re: issue with delay function
« Reply #7 on: January 31, 2013, 12:28:32 am »
[SOLVED. left in place as a log of some possible value to others; see last entry for resolution]

Nope, no difference using the root hub (core USB connections of my computer). I'm running Windows 7, 32-bit, current service pack and patches. The downloaded distribution zip file unpacked with no reported errors.

[Later] Cut out the delay() calls entirely. So now the loop ought to be running fast enough that I should see a flickering LED at approximately half-brightness compared to full-on. Blink rate is unchanged, roughly 39 flashes per minute.

Perhaps d/ls are failing silently from the perspective of the IDE? When I plug in the unit after the request I get a three-low-beeps tone that's what is normally heard when a USB device fails to initialize properly from Windows' perspective. I'll try to see if that happens in other circumstances.

[Later still] Hmm, OK, another Digispark that I've never tried to program is acting the same way (repetitive flashing). False diagnosis. I don't know what's going on yet but I'll dive in myself and see if it's just a driver problem. I will keep you advised.

[Conclusion] Yes. Driver problem. The documentation/tutorial might well be rewritten to let people know that the Digispark as-shipped from the factory defaults to blinking the LED at about 40 pulses per minute and that things like the three-low-tones and failure to change the blink rate are a clue that drivers might not have been installed correctly.

Perhaps that belongs in the troubleshooting section (and indeed, perhaps it /is!/ ;) )

« Last Edit: January 31, 2013, 01:15:16 am by mmbutler »