Pages: [1]   Go Down
Author Topic: ArduinoDuemila - Understand Setup (for rookie :) )  (Read 435 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
     I'm looking for informations relative to the globalfunction setup. I'm understanding the purpose of this function at high level. But I'm seeing strange behavior (behavior that I can't explain) : during program loading on the card some pins act "randomly". Imagine a led or a motor connected to the pins then they switch on/of "randomly". I'm curious and I've made some test : to try to avoid this (for easy usage during testing) I've move my setup code in my loop function but making attention that this code only execute one time and only one. But here, pin are not setted correctly (strangle voltage output taht can set on a LED).

  So my questions :
     - what is the exact actions done during setup ? and pin positionning mode (Input/output) ;
     - how to avoid random action during my code downloading in my Arduino.

   Imagine my card with a motor, I don't want my motor act during code load.

Sorry if I ask totally studid question here : I'm only play with the Arduino since a month (and I like it smiley ).

[Edit] : maybe I've  post in the wrong place !!! It'll be better in the Troubleshooting.
« Last Edit: September 09, 2010, 07:34:23 am by Simply_JB » Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino IDE performs some "magic" before it starts the gcc compiler, among which is adding this:

Code:
#include <WProgram.h>
int main(void)
{
   init();
   setup();    
   for (;;)
      loop();        
   return 0;
}
So don't let you become fooled by fancy ideas. What's inside init() you can find by looking into:
Arduino/Hardware/Arduino/Cores/Arduino/Wiring.c
« Last Edit: September 09, 2010, 08:12:03 am by mpeuser » Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The digital pin 13 may blink as the bootloader flashes it everytime the atmega is reseted, and the digital pins 0 and 1 will vary a lot as they are used to upload the sketch to the board using the usb-serial chip.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for theses replies I'll check this as soon possible to verify that my components are connected to given pins.
Logged

France
Offline Offline
Faraday Member
**
Karma: 36
Posts: 3430
There is an Arduino for that
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All the IOs are floating at power up (or at reset).
Inside Init() digital IOs are programmed as input by default so they are floating until you fixe their state as output in setup().
If you want your IOs put in some known state at power up, you should put pullup or pulldown resistors on each pin.
Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The startup is a very awkward situation.

This is a little bit OT but nevertheless should be discussed from time to time.. In one of my designs I needed a relay to switch on the power for the external devices after initialisation of the ports.
This has not only to do with undefined outputs but also with inputs. When external devices are already powered up and the Arduino is not, a much higher voltage (=5V) than Vdd (=0V) is seen at the inputs, which can easily destroy those pins...
Logged

France
Offline Offline
Faraday Member
**
Karma: 36
Posts: 3430
There is an Arduino for that
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When external devices are already powered up and the Arduino is not, a much higher voltage (=5V) than Vdd (=0V) is seen at the inputs, which can easily destroy those pins...
Should use buffers with hot plug capability on that pins
Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you give an example?
I think you like 4049/4050?
What with analog input?

I once considered 4066... In fact I dont remember why I discarded that. It looks like an excellent idea at the moment....
« Last Edit: September 10, 2010, 07:34:47 am by mpeuser » Logged

Pages: [1]   Go Up
Jump to: