I’m a complete beginner in the Arduino world, and have just bought the SF Inventors Kit V3.2. I’m working my way through the projects and have noticed something - the sketch runs, then stops briefly, then runs again. This is, I assume the ‘loop’ doing its thing.
An example, I’ve done a project that flashes 5 LED’s in sequence from 1 to 5, then goes down from 5 to 1 stops for a second then start again. Why does it stop? Why does it not keep cycling up and down. Is it my inexperience? I would have expected the sketch to keep going until stopped by the user.
The reason I’m asking this is, if you wanted to switch on some lighting,say, for a number of hours, which I assume would not be a very long sketch, it wouldn’t be very good for them to be switching on and off every few seconds.
Will all be revealed further down the learning curve? I hope so because I’m hoping to do some interesting things around my home with one or more of these devices.
An example, I’ve done a project that flashes 5 LED’s in sequence from 1 to 5, then goes down from 5 to 1 stops for a second then start again. Why does it stop? Why does it not keep cycling up and down.
There's nothing in the code above that should cause the behavior you've described. Each LED should blink on for 0.25 secs then go out. They should "count up" and then "down" and repeat, w/o any pause between up and down or one cycle to the next.
lyndon:
I haven’t used Arduino’s much. Is there a configuration for how often loop() is called?
It repeats every (however as long as the code in *loop()* takes to execute) usecs/msecs. In this case the *delay()* statements dominate the time it takes the MCU to execute the other code statements.
… the sketch runs, then stops briefly, then runs again. …
How briefly are we talking about? Can you insert a similar single blink of the build-in led (pin 13) in the setup function. So we can tell if the pause is due to the Arduino resetting or not. As Setup() happens only once after reset. If it blinks more than once then it is likely a power/hardware shortcircuit problem. If it blinks only once then it must be in the software. (though I agree, I can’t see it in what is posted) Or you have one led reversed and doesn’t light up when it should.
[EDIT]I didn’t read [the other thread yet. As the 13 led already blinks it must be due to a reset somehow. no need to do the above, as the code doesn’t use that built-in led. Buying another redboard won’t help. Atleast not until we can rule out if the (probable) shortcircuit is a mistake you made. If we can confirm that the redboard is defective then it’s time to go back to the shop with it.
Please consolidate your new responses to one thread, and post pictures of you setup/wires/everything in it. This looks like something draws too much current and the Arduino goes into brown-out reset. If you have a volt-meter or oscilloscope (probably not) at your disposal please use it to confirm what goes on with Vcc.](Sparkfun Red Board - SparkFun Electronics Forum)
Generally pictures are more steady and less fuzzy. So, I’d prefer pictures. (after selecting for quality) Though 20 Megapixels (or whatever the standard of cameras is thesedays) are overkill.
Sparkfun allows upload to the forum as attachments, so no need to look for online hosting of them.
MAX said: The reason I’m asking this is, if you wanted to switch on some lighting,say, for a number of hours, which I assume would not be a very long sketch, it wouldn’t be very good for them to be switching on and off every few seconds.
On any scratch built project collect as many ideas as you can. I do not want to interfere with your **Arduino learning** but this **$5** product may be a cost-effective add-on for you or someone else. It has an adjustable up to one-hour ON period when the trigger lead is briefly brought to ground. Operating at 12 volts may be a draw back for your app but the relay isolation is perfect for switching on lights. I bought one to test on my chicken coop door experiment and for remote battery efficiency it was not quite right. It arrived in seven days from China to California.
I was thinking about the excessive current angle, and thought that I’d been running my 2009 Mac Book Pro on battery while doing thes sketches. So maybe that was the problem - unlikely, but ther you go. So tried the whole setup with the MBP on mains, USB out into a powered hub, Red Board into the hub, wired up the 5 LED’s etc, uploaded - no change. Still the ‘resetting’. I was just about to get the meters out check Volts/Amps when I thought ‘do you have to shut down the IDE?’. Err… No, it made no difference. What did though was unplugging the USB lead from the MBP. All sorted, perfect sequencing LED’s.
Did I feel stupid? Absolutely, however in my defence, no where in all the articles,vids,books does,it say ‘Unplug the USB’.
Obviously it didn’t’t occur to me that this had to be done - when I upload a program to the HVAC controllers that I work on, I don’t need to unplug the Ethernet or serial ports to get the program going. But, I suppose I’m not being fair on the Arduino - £25 of board against £1600 of (only) a communication board - no I/O.
So, many thanks again to all of you who took the time to reply. I feel now I can get on with learning properly.
Weird, I never heard that happening either. I never unplug my USB… Never had any issues who’ve described. But, I never used a laptop with Arduino before, just a PC.
It kept resetting when the MBP was supplying USB power to the redboard (mains or standalone battery powered made no difference) .
It kept resetting when the MBP was connected to the powered USB hub (for lets say serial comms) while the redboard was powered from the USB hub.
Only when the redboard was powered from the USB hub alone and nothing else connected to it, it works correctly.
That doesn’t add up considering power flow, ground loops, USB vs external power in cutt-off circuitry of the Redboard.
The only way I can somehow explain this is if the MBP does some toggling on the DTR signal of the serial port. That could explain the resetting. As I have no experience with the MBP (or any Apple products for that matter) I’m at a loss why it would do this.
The hub makes no difference, I don’t think it’s a power issue, especially with these light loads: if the Mac is left connected after the upload it resets the board.
It looks, as you suggest, the Mac is doing some kind of polling and it’s upsetting the Red Board.
I’ve got a kosher Arduino Uno, bought yesterday, so will see how that performs, and maybe in the future I’ll load the IDE onto a Win PC with Win 7 and see how that performs.
But for now I’m going concentrate on learning the programming and making something useful.
I’ve got a kosher Arduino Uno, bought yesterday, so will see how that performs, …
I’m not confident. It also uses the DTR signal to cause a reset. But it uses a different chip to do the USB to Serial translation (no FTDI FT323x) and so different drivers so who knows.
If you want to do more tests eventually, connecting a LED with 1 Kohm series resistor (or more for less brightness) between reset and 5 volt (cathode towards reset) would prove when the Redboard is deliberately reset by either the switch, or the serial connection Auto-reset.
You’re correct Valen. The kosher Uno does exactly the same, so it must be the Mac.
Will give it a try one day.
So…presently battling with a variation of the LED sequencing sketch, but instead of just switching them to full brightness, it ramps the brightness up then down then steps to the next one. I think I’m getting there slowly…
Tried a few more simple sketches, everything ok till I got to the sketches that require the serial.begin() to opened up. Obviously if I’ve got to disconnect the MAC to run the sketch without the resetting, I can’t see the feedback from the serial port!
Have installed the IDE on a Win 7 - the Red Board will not communicate at all, Win says there is no driver needs or been found. Tried the kosher Uno - works perfectly.
Last test is a sketch that needs the serial.begin(). If that’s ok I’ll be using the PC.