text:
Assembly on the Arduino: IO registers
Question: What registers do I use to access the IO on the Arduino Uno when I am using assembly for programming?
Background:  I was interested in practicing my assembly language skills on the Arduino (I thought it would be easier to turn LEDs on/off than to worry about console IO).  From doing a preliminary search, I have found that the AVR toolchain can be used to program the Arduino.  Yet, I don't quite know how to find the corresponding registers for the IO pins.

The datasheets for the AVR microcontrollers are reasonably good to read. Just Google for the exact controller on your Arduino (eg. ATmege328) and find the "Complete" datasheet on the atmel.com website. Don't download the "Summary", it doesn't include a lot of information. Download the datasheet from atmel.com, that is the only location with the most recent documentation.
There are three registers used in basic IO (check the chapter called "I/O-Ports"):
Where n is a port identifier, a letter ranging from A, B, C, ... depending on the number of IO pins your controller has. Each bit in each register represents a single GPIO pin (yes, you need some basic knowledge on binary to fully understand this).

DDRn, Data Direction Register: This basically configures a pin for either input (0) or output (1).
PORTn, Port n Data Register: When a pin is set as output, the related bit toggles the output pin high (1) or low (0). When configured as input, this enables a weak pull up resistor on the output pin.
PINn,  Port n Input Register: Use this register to read the current level on a pin that is configured as input.

This. Step 1: Stop thinking of it as an arduino. It's not. It's a ATmega MCU on a PCB. 2. Read the datasheet. 3. No really, read the datasheet.

Ah... that is exactly what I needed.  I think I spent so much time looking for Arduino-targeted tutorials, that I forgot I was simply programming an AVR controller, and could use its datasheet.

Check this out: http://arduino.cc/en/Reference/PortManipulation
Also: http://arduino.cc/en/Hacking/PinMapping168
As for other ports and pins, check put the datasheet for your controller, they're really useful to people who can understand them! :)

Link only answers are not useful for the site, as we are not trying to establish a repository of links. Moreover, link only answer are useless if the link ever goes down in the future. It would be better to summarize or paraphrase the content within the answer itself so that users can find what they need here itself or at the very least gain sufficient context so as to be able to find solutions themselves.


text:
How do I figure out if my board is approaching end of life?
I have a uno that I have been using for 3 years now. I will be using it again in a rather critical project in which failure on the part of the board could be rather expensive and dangerous. So, I would like to be sure that the board is not approaching end of life or going to fail anytime soon. Is there any reliable way to figure out how long the board will function without failing or reduction in performance?

"failure on the part of the board could be rather expensive and dangerous". Define expensive and define dangerous. Maybe an Arduino is not the best fit for your application, maybe you need to design in a fail safe mechanism.

@jippie Think small UAVs and/or other small to medium robots.

Unfortunately, there isn't much way to really determine "wear" in the context of solid-state electronics.
Probably the things that are most likely to fail are the electrolytic capacitors and the connectors.

First, if you're using an ATmega CPU for something that could possibly injure someone CONTACT ATMEL AND TALK ABOUT SAFETY PRECAUTIONS. The ATmega CPU used in most of the arduino models is not rated for use in such situations.
In EVERY datasheet:

Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.

Now, realistically, this is probably mostly lawyer repellent, but you should still take appropriate precautions.
Really, while there isn't anything on a common arduino board that really wears out except the connectors, why are you trying to save $30 at a potential huge cost? Just buy a new board.
I'd also strongly reccomend you chose a board with a SMT ATmega328P, since that removes the IC socket contacts from the list of concerns. If possible, also remove the pin-headers, and solder wires to the board directly. Try to minimize connectors, since they are frequent points of failure.

One of the sections of the Arduino that is likely to become unreliable over time is its memory. There are three pools of memory in the microcontroller used on avr-based Arduino boards:

Flash memory (program space), is where the Arduino sketch is stored.
SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs.
EEPROM is memory space that programmers can use to store long-term information.

The memory is one part of the board that can be checked and verified, and thus evaluated for reliability/health. A very basic way to check memory would be to write a certain 8-bit pattern (byte character) over every address in the memory and then read the value present from every address. If the value that was written matches the value that is read, then that specific 8 bit block in memory is functioning correctly at the present moment.
Wear in ROM memory usually occurs in a blockwise pattern i.e. n*8-bit blocks become degraded over time. So, for a 2K byte ROM chip, the health of the chip can be estimated by writing and reading from every byte on the chip, and calculating the percentage of correctly functioning blocks. If the percentage of failed blocks is significant (15%-20%), that means that the memory is likely to fail soon.
The test code can be written using separate methods for each of the memory sections.
SRAM
Any variables declared statically or dynamically are allocated on the SRAM. So, we could declare a large character array (~2000) and fill every element with 255 (all bits 1). Then, we could attempt to read each of those elements and see if the value being read is indeed 255.
EEPROM
The EEPROM can be manipulated using the EEPROM library. The library provides functions to read and write from specific locations in the EEPROM. So, all memory addresses can be tested by simply looping over the entire memory
space. This operation will require 500 writes and reads.
Depending on the board usage, EEPROM is most likely to fail first but is not critical to board operation.
Flash
Data can be stored on the flash memory using the PROGMEM directive. Similar to SRAM, a large array can be declared and initialized here. Then, values can be read and checked.

This concentrates just on the microcontroller, which is highly unlikely to be the least reliable bit on the board. The flash is rated to 10k cycles - this is very hard to achieve. Also the test would only prove that it is working now, not when put into the application. It's much easier surely to just validate the program memory once programmed, or the EEPROM?

I'd question the phrase "One of the sections of the Arduino that is likely to become unreliable over time is its memory." - the flash can do 10k cycles, the EEPROM 100k cycles. That's a lot of writing.

@Cybergibbons Memory intensive applications can end up doing 100+ writes per minute. Not common, but possible when using a large number of sensors. The test would give us a percentage of the memory that is working correctly. I dont have specific knowledge of the ROM chips on the Arduino, but many ROMs have the ability of spreading read and write cycles across the chip. The effect of this is that when even some memory locations degrade, it is a sign that the entire chip will degrade soon. Even if the R/W cycles are not spread, even then, if certain areas start to fail, then it is a sign that..

atleast parts of the chip have undergone significant wear making the chip partly unreliable. In either case, evaluating the entire range of memory available is quite a reliable method to figure out current state of the chip, which can give an indication of failure in the near future. Yes, this will not tell  me if the chip will fail in the next project, but in the case of a dangerous or expensive application, I certainly would not put a chip to work that has an increased likelihood of failure.

If you are writing to EEPROM or flash hundreds of times a minute, you are looking at a lifetime of under a day though. That's just inappropriate use. There is no wear levelling in an ATmega.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
What is the best way to unit test my code without controller?
I want to unit test my Arduino code. Ideally, I want to execute and test my code without uploading it to the board. What tools or libraries can help me with this?
There is an Arduino emulator in development which could be useful, but it doesn't yet seem to be ready for use.

Unit testing and running the code in an emulator are quite different things however.

Yes, there are two questions here, one is about unit testing arduino code, and the other about emulators for the arduino to execute the code. Maybe create a specific question for each, especially the unit testing one that has not been addressed before.

You can easily simulate your Arduino code using the famous Proteus ISIS.
You just will have to search for the specific Arduino simulation library for Proteus.
Here you a small tutorial of how to make this thing done:
First, identify the path the Arduino IDE generates the hex file to?
for example if you are using the official IDE you will find the hex file location in the "arduino IDE path/lib/preferences.txt"
Or if you are using Arduino ERW which I recommended the most on windows! So you can simply open the output folder by "Sketch > Copy HEX file as path".
Second, download the Arduino library from Here. Then copy ARDUINO.LIB and ARDUINO.IDX to folder "library" in the install directory Proteus.
Third, open ISIS and you should be able to find the component.
Please find this image of the worksheet after finishing the above steps, and simulation works just fine!

And as a head start for you, please find this small memo I prepared for the Arduino Uno Pins Layout:
0-14: I/O
A0-A5: Analog

We can use analog as digital:
=============================
Pinout:
00: Rx      | Can't be used as I/O if I wrote in the code Serial.begin
01: TX      |
02: Interrupt
03: Interrupt & PWM
04:
05: PWM
06: PWM
07:
08:
09: PWM
10: PWM & SPI
11: PWM & SPI
12: SPI
13: SPI
A0:
A1:
A2:
A3:
A4: TWI
A5: TWI

I always try to isolate the hardware logic from the rest of the domain logic.
Classes (or whatever) from domain logic can be programmed in c++ (with the known arduino restrictions like exceptions or std lib) and can be tested with gtest.
When these classes are tested, simply instance from arduino program excluding the main with tests.
If your project is pure hardware this solution will not help you very much, but if you have your own algorithms, protocols...etc, test them with Google test will save you hours of on board testing and memory problems with unexpected results and your software will gain in quality.

Yes, this is an important point in SW dev that is almost always skipped in arduino development. Testing small units of your code can save hours of time if your project has complex functions or algorithms.

Have you looked at the AVR simulator that's part of Atmel Studio? Considering Atmel designed the processor, the simulation may very well be running the HDL that was used to produce the MCU itself.
I suspect if you're doing something involved enough to be using unit-testing, you should probably stop thinking of your device as an "Arduino", but rather "An ATmega MCU on a PCB". There are much more information and tools available about ATmega CPUs in general then Arduinos.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
What's the best way to put in a database sensors data's
I have not already started to try but I'm a good webmaster and I'm just asking which way is more suitable for sending and keeping data from sensors and I/0 state in a database.
Here are some points:

Post versus get
MySQL or others types
Security layers
Graphics render of data's (google API?)
PHP, ruby, JavaScript...
Able to send data request's to Arduino's
Ethernet shield, wifi, I2c ???
Access via Android app...

Anyway, the goal here is to know pros and cons of integrate all my Arduino through database.

This is really vague, and really only tangentially related to arduinos at all.

It depends on your skills and what you have in your Arduino "box".
Let's assume you have an ethernet or WiFi shield.
I would go with a PHP script (I'm a PHP dev, but any language will fit) that accepts POST requests sent by the board and store them in a SQLite db.
Why SQLite instead of MySQL? Well, it's just a matter of data portability. You copy the SQLite file or send it via email and you're done: there are plenty of clients out there to read your db, in *nix based machines is frequently integrated in the OS.
MySQL requires a sort of "infrastructure" to be written/read.


text:
How to prevent breaking my Arduino by mistake?
What is the best practice to make my Arduino circuit more robust against prototyping mistakes (like shorting pins)? I don't want the controller to release its blue magic smoke while experimenting with it, what precautions can I make while designing a circuit?

Not best practices, but an alternative approach:
Consider the Ruggeduino instead of a standard Arduino. At a price ($39.95) comparable with the equivalent Arduino, the Ruggeduino offers:

Resettable fuse on each GPIO pin, i.e. all GPIO pins are protected from short-circuit to ground or other pins
All GPIO pins withstand 24 Volts
Reverse voltage protection (-30 V) on Vin
Microcontroller overcurrent protection
3.3V and 5V outputs on the board are over-current and short-circuit protected

Besides the above points specific to the question, the boards are designed to survive harsh environments and various mistakes. Also, the clock is more precise than on the Arduino.

I don't know if there's one best practice, but the following might be helpful:

Limit the voltage on input pins to 5.5 V maximum.
Do not short IO pins.
Use pullup or pulldown resistors when conecting switches or pushbuttons.
Respect the current limits (for each pin and in total). Use resistors.
The Arduino is just the brain, not the power station. If you have to drive higher loads, use simple transistors, Darlington arrays, etc.

Something that could be attached to bullet point 4: Yes, LEDs need resistors. :)  This has to be the most common Arduino mess-up ever.

I believe LEDs do not need an resistor if you have other means of limiting current or voltage.

Don't move any wires with the power on. Way too many boards are damaged that way.

Just because you have to be careful doesn't mean you can't do it; I have moved, connected, and disconnected wires all while powered up without any ill effects (other than an occasional required reboot). I have even soldered to a powered board. Sometimes troubleshooting wins over the 'correct' way to do things; a blanket prohibition smells like cargo-cultism.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Can I program for Arduino without having a real board?
I would like to start the development of some basic Arduino projects but I don't own an Arduino board yet. Is there a way I can write my code and emulate/test it using a desktop computer so after my board arrives I just have to upload and run my project on it?

I’m interested too, did you find one that plays well with the Arduino IDE? that is, detected by the IDE as if it was a board, with all its functionality.

I am interested in the free online Wokwi Arduino Simulator for the reasons that it runs on both windows, MAC and mobile browsers. It runs on AVR8js based engine and is also made open-source. can you review this?

There are a whole slew of Arduino simulators out there, many free, and some paid products as well.

The CodeBlocks Arduino development environment includes a free Arduino simulator, still under development but functional.
Simuino simulates the Arduino Uno and Mega pins - not a pretty-looking realistic simulator, but it works.
The Python based Arduino Simulator is another option, that plays well with the official IDE
Virtronics Simulator for Arduino looks promising, but I don't see why I would pay $14.99 for it, when I could buy one or more actual Arduino clones for that price

Many other Arduino simulators are out there if you search, and new ones are being announced, even crowdfunded, all the time.

as a note, those are not emulators but simulators, the most important difference is that it does not run the code on a AVR virtual machine (like what qemu does), but binds the Arduino functions to native code. So basically they won't be able to run native AVR stuff and register/timer behavior will not be the same as on real AVR hardware. See the difference well explained in that answer. It is, though, theoretically possible to emulate Arduino Due code with qemu.

You "don't see why [one] would pay $14.99 for it, when [one] could buy one or more actual Arduino clones for that price"? I can tell you why: because the hardware doesn't have a built-in debugger with the features that can be provided by a simulator.

The Arduino Simulator piqued my interest, but unfortunately appears to have no files related to it on the sourceforge site. Am I missing something, or has it become deprecated since you wrote your answer?

As noted in above comment, there are no files in the arduino simulator source forge site. Is there a website for it or is there another simulator that works well in mac, with official IDE?

Simuino is terrible, unprofessional and useless.  They have no clue how to code.  Arduino Simulator has no releases.  CodeBlocks is Windows only. Simulator for Arduino isn't open-source.

I like to use circuits.io aka TinkerCAD for this.
It's cloud based and has some nice features including PCB design and collaboration.
IMO the Arduino simulation and capability is impressive and intuitive.

It is very nice and clean and basic functionality is really impressive, easy to use and powerful. However many common parts (including LCD and temperature sensors) are not supported yet. I doubt you can test anything but very basic designs at this stage. I hope this will get better over time.

I gave it a quick try and found it very impressive for a free product. I don't know its limitations in terms of simulation realism, but the editor is very friendly and just placing a led into the proper slot automagically created code with the correct pin and a blinking loop!

even my choice would be 123d but my only complain about this site is they don't add new components. It would be really great if they can have some new components on their list

The electronic labs part of circuits.io site has moved to tinkercad.com, where you can find it under circuits.

The answer is outdated

I have edited it and updated the links.

free Arduino simulator is free, based on open-source AVR8js, and works on Android, iPhone, Windows and Linux. Can you please first check it out and then update your answer. This helps to reach so many Arduino users who are looking for a good arduino simulator with examples. In many aspects, it is better than Tinkercad.

Plenty of options exist in the world of electronics simulators, but circuits.io aka TinkerCAD is probably the most versatile one out there.

You can compose your circuit on a virtual breadboard which looks just like real.
You can actually watch a LED blinking or press a button during real-time simulation rather than struggling with abstract waveforms.
You can combine digital devices like a 555 timer or shift registers with (interactive) analog components like resistors and LEDs.
You can program an Arduino and simulate the microcontroller together with your analog circuit around it.
You can debug an Arduino: when the simulator reaches your breakpoint, the simulation is paused and you can easily check every variable in your code and every voltage or current in your circuit.
You can use and observe different communication protocols like UART, I2C and SPI.
You can pause the simulation in the middle of an I2C sequence by putting a breakpoint in the driver code (e.g. interrupt service routine for I2C events)
It's FREE!

This is an example circuit that has with an IR Remote and an LCD Screen.
Disclaimer: We are the makers of 123D Circuits

How does it play with the Arduino IDE? would it be available to flash, debug, etc?

Be aware that no simulator will reproduce real-life situations. There have been plenty of posts on the Arduino forum about problems with code or electronics, which turn out to be something subtle, such as:

Timing issues
Race conditions (related/dependent events not always happening in the same order)
Voltage levels, eg. floating input pins
Driving motors which drop the Arduino voltage enough that it resets
Not having decoupling capacitors
Input pins being in an "undefined" state (eg. 2.5V on a pin where 2 or less V is LOW and 3V or more is HIGH)
Problems with interrupt handlers, such as variables not being declared volatile
Voltage spikes due to not having flyback diodes on motors
The processor resetting once more than 10 LEDs are turned on because the current draw exceeds the amount the hardware can supply
Interrupt handlers taking 10 µS to process an interrupt when only 9 µS is available.

By their nature simulators can't reproduce all of this. Even if they could, would you think to toggle the "insert random noise from motors" option?

As for getting ready for the board to arrive, download the IDE and start programming. You can get libraries installed, code written and free of syntax errors, organize it neatly, and be generally ready for the big day when the hardware is in your hands.

Have fun and enjoy experimenting with your Arduino!

This is a good troubleshooting checklist for when a circuit is misbehaving seaport appearit "logically" correct.

There is one point I would like to thank you for. The bounce effect of the pushbuttons creating so many problems for beginners unless addressed. inspired b your list, I had asked to add this feature in the wokwi and now the simulator supports bounce feature in the push buttons!

You can use Yenka (free for home use) to simulate Arduino, PIX, PIXACE and other boards with digital, analog and serial I/O. It provides a lot of components and sample projects.
Screenshot:

Can it be programed, debugged from the Arduino IDE?

Edit 2:
Please hit the like button to support free Arduino simulator
I am working with the new Wokwi Arduino Simulator. Wokwi Arduino simulator is based on AVR8js engine which is made open-source. You can find the link here
Following are the main features of the simulator
•   Supports multiple file projects
•   Supports the Arduino libraries
•   Whatever compiles on the Arduino IDE will compile on the simulator
•   Supported by all browsers
•   Compiles with latest Arduino IDE
•   Supports FastLED and many other peripherals
•   No download or installation needed
•   Easy to share the code and project with just a single click
•   Smart - Code Autocompletion, Code auto-formatting are supported
•   Provides standard library demo examples
•   Project can be compiled on RUN on Mobile browsers as well
•   Tries to be closer to real circuits – Example – Button bounce like in real hardware
•   Supports Arduino Mega, Arduino Nano, Arduino UNO, ATtiny85
•   Supports assembly instruction execution
•   Provides LED power and FPS features for FastLED projects
•   Supports a plethora of Arduino peripherals for the project – Ultrasonic sensors, Slide switches, NeoPixel matrix, Potentiometer, Servo motors, SSD1306 OLED displays, temperature and humidity sensors, rotary dialer, membrane keypad and more
•   Serial monitor is supported as well
A few Arduino Examples
Simon game using ATTiny85, buttons, buzzer, and LEDs
Project link: https://wokwi.com/arduino/projects/285525640477671948
•   Note the use of the same pins for both output and input
•   The code can be written for ATTiny85 the same way how it is written for Arduino

Slide switch demo example
Project link: https://wokwi.com/arduino/projects/292033853022798344
The slide switch can also be used as an ON-OFF switch

Simple Piano Example
Project link: https://wokwi.com/arduino/projects/291958456169005577
Plays several notes based on Arduino built-in library support

Max7219 LED dot matrix Arduino UNO project Example
Project link: https://wokwi.com/arduino/projects/290144516831183368
Supports concatenation of the Max7219 modules

HC-SR04 Ultrasonic sensor Example
Project link: https://wokwi.com/arduino/projects/290056311044833800
A very useful project to build several interesting projects (RADAR 3D mapping and more  )

Bounce feature example in Arduino Simulator
Project link: https://wokwi.com/arduino/projects/288332630964830728
Bounce is the basic problem in most beginner projects. That can create multiple input triggers, unwanted noise and makes the project to misbehave. Sometimes can be difficult to identify without proper debug or measurement tools. Knowing about the bounce in switches and tips and tricks on how to solve it is an interesting study for every beginner hobbyist.

LCD1602 display example in Wokwi Arduino Simulator
Project link: https://wokwi.com/arduino/projects/287736345015616008
LCD1602 is one of the best HMI and has been here for a long time. It helps in debugging projects during run time, we can also use it along with a keypad to make a completely practical HMI (human-machine interface). Very easy to use, and easy to learn about programming.

FastLED example with FPS and LED power
Project link: https://wokwi.com/arduino/projects/287736345015616008
Second link: https://wokwi.com/arduino/projects/281176629596652040
FastLED is a second revolution in the history of LEDs. It was never easier than now to program multiple LEDs with just one Arduino Pin. With the growing FastLED community (reddit, wokwi-Discord, and others) and FastLED examples and libraries, This is one of the most important elements in the wokwi Simulator.

Temperature and humidity sensor, Real time clock module example
Project link: https://wokwi.com/arduino/projects/287736345015616008

Serial Monitor example
Project link: https://wokwi.com/arduino/projects/286653669554782732
The serial plotter is a very useful feature when working with analog peripherals.

Adafruit SSD1306 Library Adafruit SSD1306 Library
Adafruit DHT Sensor Library
Another DHT library from GitHub
FastLED example Library
SSD1306 GitHub example
Arduino Servo Library
Task Scheduler Library
Simon Game, Electronic Safe Example
LCDGFX on Arduino Example
SSD1306 Library Examples

The Arduino simulator is free for the Arduino Community to use. We are adding more elements one after the other. It is free and we invite you to try it as well.
Please leave a comment to add more libraries or features as well

Yes, you can, try using Proteus ISIS for simulating your code...
For full emulation of Arduino, there is a shareware program called VBB (Virtual BreadBoard), I tried it too and it was nice.
Edit: You can check my detailed tutorial here on how to simulate on Proteus ISIS

I believe this website has a list of both emulators and simulators along with their price and availability.
Update:
Since some users mentioned there are broken links in that website, here's a selection of emulators I found. Note that some descriptions may have been taken from the mentioned link:

Emulino: Is an open source linux based software in early development that emulates Arduino-specific MCUs.
Emulare: is a general purpose hardware emulator. It aims to provide a central interface to build electronic simulations for embedded software development. At present emulare focuses on the ATMega line of microcontrollers (Arduino UNO has the ATMega processor).
SimAVR: is a new AVR simulator for linux, or any platform that uses avr-gcc. The simulator loads ELF files directly, and there is even a way to specify simulation parameters directly in the emulated code using an .elf section. It supports emulation of many ATMega processors and it is mentioned that it's easy to even add new ones.
Amtel Studio: This doesn't seem to mention the term emulation, but it is a sophisticated IDE to debug your code for many platforms specially Arduino. Atmel Studio 7 features seamless one-click import of projects created in the Arduino development environment. Your sketch, including any libraries it references, will be imported into Studio 7 as a C++ project. Once imported, you can leverage the full capabilities of Studio 7 to fine-tune and debug your design. Atmel Studio 7 fully supports the powerful embedded debugger on the Arduino Zero board. For other Arduino boards, shield-adapters that expose debug connectors are available, or switch to one of the many available Xplained-Mini/PRO boards to fully leverage the Atmel HW eco-system.

You can still use simulators such as EasyEDA to test your code and in most cases be able to run it on the device. But note that given the nature of electronic components, you may have to provide external resistors, capacitors etc to get the expected results.

Link only answers not a good thing here because they will be useless when the linked site goes down. Please write a summary and also make sure that your answer adds value and not just repeating the ones we already have.

I agree with @totymedli - if that link goes dead the answer becomes useless. Please summarize, at least, the emulators mentioned and the current price. You can start lines with an asterisk to make bullet points, if that helps.

Virtualbreadboard has a new VBB4Arduino 'Two Arduino's' edition which includes BOTH a JVM Arduino emulator AND a AVR Instruction set simulator with examples that cover almost all of the Arduino distribution examples and a bunch of peripheral hardware - LCD's, WS2812 Neo LEDS, Motors, Servo's, Logic Analyser and more.
http://www.virtualbreadboard.com
Disclaimer: I am the author of Virtual Breadboard

You could e.g. use my simulator.
It is especially suitable for PLC-like applications, where multitasking is achieved by cyclic evaluation of interconnected circuit-like objects: Timers, Markers, Latches, Oneshots and Registers.
You can use it to simulate your controlled system as well, as becomes clear from the examples in the download. It has modest visualisation capacities, can draw timing charts, and allows you to access and alter c.q. force all variables in real time during a running simulation. Also you can freeze time. When you're satisfied with the behavior of your control it generates the C code to be uploaded to an actual Arduino.
https://pypi.python.org/pypi/SimPyLC

a way I can write my code and emulate/test it using a desktop computer

If you mean being able to "unit test" using a desktop computer, I can offer a library I wrote called arduino_ci.
It doesn't offer emulation.  You would express your tests in code.  For example, here is a test pulled from the reference documentation that validates the data written to a port:
unittest(pin_history)
{
  GodmodeState* state = GODMODE();
  int myPin = 3;
  state->reset();            // pin will start LOW
  digitalWrite(myPin, HIGH);
  digitalWrite(myPin, LOW);
  digitalWrite(myPin, LOW);
  digitalWrite(myPin, HIGH);
  digitalWrite(myPin, HIGH);

  // pin history is queued in case we want to analyze it later.
  // we expect 6 values in that queue.
  assertEqual(6, state->digitalPin[1].size());
  bool expected[6] = {LOW, HIGH, LOW, LOW, HIGH, HIGH};
  bool actual[6];

  // convert history queue into an array so we can verify it.
  // we expect to find 6 values: the 5 we set, plus the initial LOW
  // and this is where/how we assert that
  int numMoved = state->digitalPin[myPin].toArray(actual, 6);
  assertEqual(6, numMoved);

  // verify each element
  for (int i = 0; i < 6; ++i) {
    assertEqual(expected[i], actual[i]);
  }
}

In practice, you would probably not be calling the digitalWrite functions directly -- you'd call a function in your library, then verify that the "world state" (represented here by the GODMODE construct) matches what you expected your library to do.

Yes you can, and fairly easily. There is a wonderful online simulation (completely free) called TinkerCAD. It has an excellent breadboard simulation, with parts like transistors, LEDs, ICs, and Arduino. You can program the Arduino and run it all in a live simulation that includes interactive inputs (pushbuttons, DIP switches, etc.).

[Edit: The following text refers to functionality that has been moved to Circuits.io, namely Eagle PCB]
That's not all. It also includes in a separate tab schematics for your circuit, and another tab for PCB design of your breadboard circuit! Or, you can just make your schematics from scratch and make your PCB from there.
You can have your circuit designs made and you can buy them. You can do all of this in circuits.io, and you aren't risking messing up your actual Arduino. It also has warning indicators in the simulation (for example, if you didn't use enough resistance on an LED, or an IC).

An alternative to simulators are services similar to online compilers like coliru, which allow users to build and run their code on a remote system. This approach has the same limitations as online compilers:

The hardware configuration and state cannot be altered remotely, except for explicitly defined interfaces.

The changes to the hardware state cannot be observed, again, except for explicitly defined interfaces.

Typically, most online compilers provide users with access to command line and process STDOUT. On Arduino, providing remote access to the serial port would provide a similar degree of control: users would be able to observe and control their running sketch through UART, but would not be able to connect/remove wires, push buttons, act on external sensors, etc.
Surprisingly, I couldn't find any such online services, so I ended up writing my own - HW Farm. If you have a web server and Arduinos you can connect to it, you can install HW Farm on it and let people access those Arduinos through a web interface. I also host such a server myself, which has a single Arduino Mega with a bunch of I2C devices connected to it. You can try it out, but don't expect it to be online and available all the time.


text:
Compatibility between Arduino and Arduino clones
In a project I am using a Seeeduino v3.0 as an Arduino clone. On the seeeduino website it says that

It is based on the Duemilanove schematic, 100% compatible to its existing program, shield and IDEs.

In fact I never had any problems with shields or the IDE.
My question is now: Is the seeeduino and other clones really 100% compatible? The seeeduino board was considerable cheaper then an arduino.

Over the years I have used original Arduino boards as well as a multitude of clones of varying provenance, from the excellent InduinoX that is listed on the Arduino site as an official compatible board, to the very well-made Chinese Meduino Nano Enhancement (3.3 / 5 Volt switchable), to dirt-cheap clones from eBay that are sometimes better constructed than the official boards.
There is nothing unique or sophisticated about the Arduino board: It's basically just the microcontroller (atMEGA328, atMEGA1280, SAM3X8E or others) and its minimal support hardware. Not much that can go wrong with that little, really.
The two common elements that ensure compatibility across these boards are:

The Arduino bootloader
Support for the board within the official Arduino software distribution

The bootloader can be replaced with a better or more up-to-date version if one is available for the microcontroller on your board.
The support files can either be found online, or minor edits to the nearest similar board's files can provide the requisite support for the Arduino environment.
In short: Yes, clones typically work just as well as the original Arduino, and clones with enhanced features often work far better while retaining compatibility (e.g. InduinoX)

BTW playground.arduino.cc is a community wiki, not the official site. AFAIK, there is no list of official compatible boards.

If you closely look at the Arduino circuit diagram, You'll notice that it is little more than power supply, a USB-serial interface and the microcontroller itself.
The 'hard' part for compatibility is getting the board layout right (which connector goes where on the circuit board), and to load a compatible bootloader in the chip (which is free/open software, so why bother making your own?).
I've used several el-cheapo Arduino clones and apart from apparent physical construction (one feels a bit flimsy), they all work just like the 'real thing'. I guess the major difference between original and clone is the quality of the board, the used components and quality of assembly.

Check twice !
Most clones are exact clones with copies of the flaws that original Arduino board had. Like for example Arduino Nano not having proper RESET and TEST pin connection of FT232RL USB-serial bridge. This flaw may lead to FT232RL not responding to PC and was eventually fixed in later revisions of Arduino Nano board. Some clones were not updated.
Another "not exactly Arduino clones" example are numerous boards with CP2102 USB to serial bridge instead of FT232RL. This may pass unnoticed, but may give frustration when one clone board connects and works with your PC, but another generates system complains on missing drivers.
So again - be prepared !

I have found that most clones will do what you expect them to do, but as x4mer states in his answer, be prepared.
The most annoying issue, and even then it is quite minor, is that a lot of Chinese clones do not use an ATMega for the USB and instead use a CH340G.  These chips, while fine when connecting to a PC running Windows 7, have great difficulties with the drivers on OS X, and end up just not being recognised. It is possible to find a driver for the CH340G, but when I installed it, it immediately crashed the MacBook, upon plugging in the cloned UNO..!
I had to buy three or four clones on eBay until I got an Uno with an actual 16u2 implementing the USB interface, which would actually be recognised by the MacBook Pro, and would allow me to code using the Arduino IDE running on OS X.
Before that, I had to use a Wintel laptop.


text:
Does Arduino Uno R3 require cooling in a closure?
I was looking at getting an enclosure to house my Arduino Uno R3, but I'm not sure if I should also attach a fan.  Does anyone have experience with this?  It doesn't look like much heat is being generated, but with no ventilation except some slits in the enclosure, there won't be much air circulation without a fan.  My concern with adding a fan was the fact that I'd need to power it.

If you aren't running any other current-hungry peripherals e.g. motors within the enclosure, you won't need a fan or other cooling, for a typical (not hyper-insulated) enclosure.

The biggest heat culprit on the Uno would be its internal voltage regulator(s). If you can power 5V from an external regulated source it will keep things cooler in the box. Especially if you have a horde of sensors drinking power from the Uno board.

The only times I had an AVR run hot was when I applied reverse power to it. You'll be fine without a fan for the Arduino board itself, as long as you don't run power hungry peripherals from it.
Probably the only thing you really need to check (apart from absolute maximum ratings: 40mA max per IO pin and 200mA max for the whole microcontroller) is the on board voltage regulator (usually three pin device with a heat sink soldered down to the PCB) if you power it from a voltage > 7V or so.

No, You shouldn't need any type of cooling device such as a fan as long as the case has a few holes in order to allow the heat to rise out of the case. I do not recommend using cases that are completely sealed, unless you are using it in an environment that has things that could hard the Arduino such as  ROVs or Nuclear waste facility (although I don't know why you would be at one in the first place).

Outdoors, marine, and underwater applications also require sealed cases.

One of my friends actually has a job working at a nuclear power plant.

@Cybergibbons excellent point regarding the outdoors... hmm.


text:
Why can't I upload a sketch while other components/devices are connected to my Uno?
I wanted to make a fairly simple circuit which would flash a series of LEDs in sequence, using my Arduino Uno (more specifically, a SainSmart clone). I wrote my sketch and it compiled fine. After that, I connected 8 LEDS+resistors to pins 0 through 7, and then connected the Uno to my computer via USB.
I've uploaded sketches successfully in the past, so I'm sure my settings and drivers etc. are correct. However, when I tried to upload my sketch this time, it didn't work.
I tried removing everything I'd connected to the Arduino's pins, and suddenly the upload worked again.
Why does this happen? Does it mean I have to disconnect everything from the board every time I upload a sketch?

The problem is specifically pins 0 and 1. Although they can be used as regular digital IO pins, they also serve as the RX and TX pins for the Uno's serial port. The USB connection (for uploading sketches etc.) is routed to the same pins internally. Unfortunately that means anything connected on pins 0 and 1 can interfere with the serial connection, preventing communication via USB.
In short, it's not necessary to disconnect everything when uploading a sketch. It should only be necessary to disconnect anything from pins 0 and 1. Rather than going through that hassle every time a sketch is uploaded though, it may be best just to avoid using those pins unless necessary (e.g. you run out of other pins, or your project needs a serial connection to another device).

Nice way to teach the community.

Since the Arduino is also programmed by SPI, which resides on pins 10-13, it is also possible to prevent it from uploading on these pins

Well written Q&A! I would love to see more such posts from you :)

@TheDoctor - Incorrect! The SPI pins are only relevant if you're using an In-System-Programmer. The bootloader programming mechanism does not require the SPI pins at all. Unless you're hooking up a separate, hardware programming tool, this is not something you need to worry about.

" Peter R. Bloomfield " I used to upload sketch in my arduino uno by connecting Rx and Tx pin but my sketch get uploaded.
Actually problem is arduino uno driver may be deleted in your case

This was intended as a reference question. The same person asked and answered the question. I doubt his problem is that the driver was deleted.


text:
Is there an Arduino simulator that runs on Mac OS X?
I need to simulate my Arduino project with other circuit components before implementing the project. Is there a decent simulator that runs on Mac platform?

There is a decent program called Simulator for Arduino made by Virtronics. Although it is made to run only in windows, you could run it in a WINE environment. WINE allows windows programs to be ran in Mac and Linux OS.

Ouch - "Pointers not implemented - some sketches with pointers may run but generally pointers don't work"

I'll try to install on Mac and see if it works

web-based Arduino simulator from wokwi,com will even work on Mobile platform. It is easier than ever to keep learning Arduino and tinkering with the projects


text:
Is there a limit on how much current a pin can sink?
I've been experimenting with an 8x8 LED matrix controlled by an Arduino Uno. As I think is typical, the matrix uses a common anode for each row, and a common cathode for each column.
At the moment, I've got all the matrix pins connected directly to IO pins on the Uno, and I haven't had any problems lighting the LEDs one-by-one. Going through the whole matrix like this makes updates a little slow though, meaning the LEDs aren't as bright as I'd like.
As far as I know, I can't safely light up an entire row at once, because an individual pin on the Uno isn't capable of sourcing enough current to drive 8 separate LEDs at the same time (requiring at least 10mA each to be bright enough).
It occurred to me that the reverse might be safer. If I light up an entire column at a time, then each pin only has to source enough current for one LED, which should be no problem. However, it relies on one pin potentially sinking the current from all 8, totalling at least 80mA.
Is this possible, or am I going to fry my board?

What exact display are you using (datasheet) and are you using series resistors with it? Maybe you fry hour display rather than your Arduino.

There's no part-number on it so I don't have the exact datasheet. I've assumed each LED has a forward voltage of 2V, and am conservatively using 390 ohm series resistors at the moment (while testing). That means I'm driving them at around 8mA each I think.

that should be just fine.

Could you go into a little more detail about what you are doing, please.  The reason why I'm asking is because I want to do the same thing, and I'm a newbie.  I am RTFMing and your question was the highest hit for my search.  I am jeffsilverm@gm4il.c0m.  thank you.

am I going to fry my board?

Pretty likely outcome. Here's why:
The Arduino Uno uses the atMEGA328 microcontroller, which has an absolute maximum rating of 40 mA source or sink per GPIO. Also, the total current through the supply or ground rails (i.e. the total of all current OP wants the GPIO pins to sink, or source) is rated to a maximum of 150 200 mA.
Realistically, the current graphs in the atMEGA328 datasheet do not even go all the way to 40 mA, hence it is safest to restrict the current to perhaps 20 mA total per GPIO.
In other words, whether a GPIO is used as source or sink, the limits remain pretty low, and in practice, should be kept much lower than the absolute maximum ratings. Even below absolute maximum, running a microcontroller to too high a temperature reduces its life expectancy.
Solution:
Use either BJTs, MOSFETs, or some driver IC such as the ULN2003 to actually drive the current through the LEDs.

Where did you find the 150mA max. for the package? I have a 200mA under absolute maximum ratings.

@jippie I goofed :-)

I'm going to steal my answer from when I answered this question on the last arduino SE attempt.

This is a bit complex. Basically, there are a number of limiting factors:
The IO lines from the microcontroller (i.e. the analog and digital pins) have both an aggregate (e.g. total) current limit, and an per-pin limit:

From the ATmega328P datasheet.
However, depending on how you define the Arduino "Pins", this is not the entire story.
The 5V pin of the arduino is not connected through the microcontroller. As such, it can source significantly more power. When you are powering your arduino from USB, the USB interface limits your total power consumption to 500 mA. This is shared with the devices on the arduino board, so the available power will be somewhat less.
When you are using an external power supply, through the barrel power connector, you are limited by the local 5V regulator, which is rated for a maximum of 1 Amp. However, this it also thermally limited, meaning that as you draw power, the regulator will heat up. When it overheats, it will shut down temporarily.
The 3.3V regulated output is able to supply 150 mA max, which is the limit of the 3.3V regulator.

In Summary

The absolute maximum for any single IO pin is 40 mA (this is the maximum. You should never actually pull a full 40 mA from a pin. Basically, it's the threshold at which Atmel can no longer guarantee the chip won't be damaged. You should always ensure you're safely below this current limit.)
The total current from all the IO pins together is 200 mA max
The 5V output pin is good for ~400 mA on USB, ~900 mA when using an external power adapter

The 900 mA is for an adapter that provides ~7V. As the adapter voltage increases, the amount of heat the regulator has to deal with also increases, so the maximum current will drop as the voltage increases. This is called thermal limiting

The 3.3V output is capable of supplying 150 mA.

Note - Any power drawn from the 3.3V rail has to go through the 5V rail. Therefore, if you have a 100 mA device on the 3.3V output, you need to also count it against the 5V total current.

Note: This does not apply to the Arduino Due, and there are likely some differences for the Arduino Mega. It is likely generally true for any Arduino based off the ATmega328 microcontroller.

Thanks for the summary!  It answered my question super fast!


text:
Is there a color LCD display for an arduino?
I currently have a Mega2560 with the LCD4884 Shield. The Shield is good for putting out text and simple pixel images. But I am wondering if there is something that has a full range of colours that would work with the Arduino? The screen size would only have to be a few inches in size.

I would personally think of this a shopping recommendation. To answer your question: https://www.google.com/#q=arduino+color+lcd

There are actually several shields that have color screens on them. Many of the shields are just regular mini TFT displays, however there are also touch screen ones.
Here is one from Adafruit that includes a MicroSD holder and a Joystick.
Here is one from Radio Shack that features a 2.8 inch screen with touch capabilities
As far as screen size, many of the screens are only about an 1 inch across, however the biggest I have ever been able to find are 2.8 in.

The 1.8" TFT from Adafruit with joystick & MicroSD is my favorite thing ever! Display + User Input. Majenko developed an epic library for it: https://github.com/cacycleworks/chipKIT_ST7735

Here is one from Elechouse in China on eBay, $30 3.2" TFT Color LCD with touch stylus and using the Adafruit GFX library.  Demo worked first try, instructions and software on the eBay page.

@Bob How responsive is it? Does it take a few moments to load new pictures? Resistive touchscreen?

@Anon you mean responsive to touch?  Interactive animation?  I don't recall any want for responsiveness but I only fired the demo up once.  I recall seeing a photo image and using the stylus in a simple "draw" program like in the eBay photos.  I could connect and load it again if you have anything specific you'd like me to look for.  I only got it working in the Arduino IDE, hadn't yet ported it to my favored AtmelStudio IDE.

There's also a 2.2" Adafruit TFT.
The nice things about the Adafruit displays are:
i) library support for both the display and the graphics core library. So it's easy to get it up and running.
The built in frame buffer reduces resource requirements on Arduino.

Another very cool screen is the official Arduino TFT LCD Screen. (Datasheet if you're curious.)
It's a 1.77" screen, with a resolution of 160x128. It has a micro-SD slot in it, which is easily accessible. It is a color screen, with up to 18 bit per pixel.
The extremely nice thing with this screen is that since it's officially supported, you don't need to do anything extra to support it. The official Arduino TFT library works perfectly with it. However, according to Jameco:

Library Update: There is a known issue with the TFT library supplied
  in IDE versions 1.0.5 and 1.5.4 Beta. You will need to replace the
  library. We have zipped up the updated TFT library for both versions
  available here. Just delete the existing library and copy in the
  replacement for the appropriate IDE version and restart the IDE. (IDE
  v1.0.5 or v1.5.4)

So beside that minor fix, everything should be easy and quick to work with. This page has some code samples which should make it easy to work with.


text:
Why is the regulator very hot?
We have an LED strip connected to output 6 and is powered by the Uno board itself.  Shouldn't be drawing too much current, only have 10 elements on the LED strip.  While this LED strip is connected to the Uno, I noticed that the regulator is getting very hot.
One thing we haven't done yet is to power the LED strips from an external source, which will be necessary since there will be many strips.  At the moment, the students are simply trying to debug their program with the small strip.

Most led strips draw a lot of current

How much resistance is present along with the LEDs?

How do you power the Arduino?

@jippie IIRC, the students are using one or both:  the USB input to the Uno, and sometimes the DC power in also, from an AC adapter.

What output voltage does the adapter supply?

Are you using a resistor in between the LEDs and pin 6?

I strongly suggest that you get a DMM and measure the current drawn by the board when powering the led strip. Google for ways to measure current with a DMM, as it can be tricky if you never done it before. Then, compare the value to those specified by the voltage regulator datasheet. The current should be within those values shown in the "Electrical Characteristics", and well below those from "Absolute Maximum Ratings".

How hot is "very hot"?  Warm to touch?  Physical damage upon contact with skin?

@anorton Quite painful to touch, so the immediate reaction is to move your hand back, but no skin burn in that short amount of time.

@Ricardo Can you make that advice into an answer?  Measuring the actual current draw beats guessing any day.

When a circuit is hot, it's very likely that it is drawing too much current. It may be a component that's getting more current than it's designed for, or a PCB track, or a wire.
So, before you do anything else, I strongly suggest that you get a DMM and measure the current drawn by the board when powering the led strip. Google for ways to measure current with a DMM, as it can be tricky if you never done it before.
Then, compare the value to those specified by the voltage regulator datasheet. The current should be within those values shown in the "Electrical Characteristics", and well below those from "Absolute Maximum Ratings".

All of the answers are excellent, but I'm picking yours since you explicitly say to measure the amps.

If you power the Arduino with an external power supply the on board regulator has to dissipate the voltage difference between input and 5VDC at the total current you draw from the board.
As Klaus Warzecha wrote in an answer to another question

The Arduino is just the brain, not the power station.

If the output voltage of your power supply is 12V, then the regulator will be dissipating 12-5V = 7 V at the total current drawn. Total dissipated power for eg. 150mA (just an estimate) would be P = V × I = 7 × 0.150 = 1W
The regulator will be pretty hot from dissipating 1W.
Mind you that the current is not limited to 150mA, enough LEDs can easily increase current and power. If the regulator is stressed (often) enough, sooner or later it will fail. It is better practice to power any load directly from the external power supply, taking the higher voltage into account.

A regulator normally get hot when is driven a current near to the maximum that could be driven, and its a normal thing the regulator keep warm.
A normal regulator like LM7805 could work until 125 C°.
If you try to drive more current that it can probably it will burn, so, maybe its time to you change your power supply to an external one to keep safe your Arduino board.


text:
Is it possible to upload a program from a tablet?
Is there any easy way to upload a program/sketch from an iPad or Android tablet without adding extra an shield (Bluetooth or Wi-Fi)?
If not, can it be done using shield? Which shield is preferred?
Also what are the IDE options available?

Related: http://arduino.stackexchange.com/questions/40/what-are-the-other-ides-for-arduino

"Which shield is preferred?" is a little to subjective without any criteria to base it on

I figured out a way to do this without having to port the compiler to iOS. It only works with the arduino Yún, but the Yún can send code to other arduinos with an spi cable.

Install an SSH app on your device so you can communicate with the arduino
Using that, install Ino on your Yún, a command line arduino compiler
Create a file, put your code in it, then save it
use Ino to upload your code!

kind of confusing, but it could work!

Unfortunately Apple doesn't allow apps that implement programming languages. This being said, it is unclear why they would not allow an app that has to do with the Arduino IDE due to the fact that the code doesn't actually run on the Ipad itself.
See here for more Info.
As far as an Android IDE, I have heard that there are a few people working on different IDEs that sends the code to the Arduino over the internet, although they have not been released yet, and the details are still a bit unclear.
Source:
http://forum.arduino.cc/index.php?topic=61305.0

Some arduino-eqsue systems already support programming via-Wifi -- Electric Imp comes to mind.

This comment is a bit old. There are many IDEs in the App Store these days including Python, Rust and Javascript to name a few.

You can always upload to the Arduino via Bluetooth.

You must have a bluetooth chip/shield (any should do) and a PC that has bluetooth (or a table that can compile, most likely an Android tablet)
You must change the BT baud rate to the same as normal arduino upload, which is 19200 (default BT baud is 9600).
Connect the BT to Pin 0 and 1 so act the same as having a USB cord connected
Connect a wire to the reset pin to allow remote resetting the arduino to statup the bootloader

There must be a delay before
hitting the reset pin as the bootloader must be active when hitting
the upload button.

Enjoy

For a more detailed description please read: http://ame2.asu.edu/staff/kidane/ArdWilessBtProg.pdf

Since your question is only about uploading, this will work with a Yun

compile your sketches with the IDE on your pc
for each hex file, copy it to the yun and run merge-sketch-with-bootloader.lua PATH_TO_HEX_FILE
manage to connect to the Yun from your tablet via SSH
once logged in, run run-avrdude PATH_TO_HEX_FILE

Is there any easy way to upload a program/sketch from an iPad or
  Android tablet without a shield (Bluetooth or Wi-Fi)?

If you don't mind re-writing your program in an interpreted language,
one option is:

Install an interpreter on the Arduino, perhaps using the standard Arduino IDE running on a standard desktop PC -- like the bootloader, this only needs to be done once.

Then:

Use your favorite terminal emulator on the tablet
Somehow link the Arduino and the Android together, and tell the terminal emulator to talk over that link.(*)
Tell the terminal emulator to send the (more-or-less human-readable plain text) program to the interpreter over the link. (No compiler necessary on the tablet).

(*) There are several different ways to make this link; some of them are mentioned at How do I write an Arduino sketch and an Android application to talk to each other over a standard USB cable? .

i have been trying out arduinodroid - it's an ide that claims you can upload to your arduino from it. you need an OTG cable (on the go) and to be honest i never actually managed to upload from arduinodroid but others seem to be able to...
my arduino is currently not talking to my computer - a bootloader problem it seems - so i'm getting hold of an AVR ISP MKii - with one of them it is apparently possible to send from terminal ide - an android app, will feedback when and if i get it to work.

I have tried android app to programming Arduino Uno via bluetooth, simply by adding Bluino_Shield to your Arduino Uno. This link app https://play.google.com/store/apps/details?id=com.bluino.bluinoloader

Yes, you can upload over BLE with free(mium) iOS app - Apploader
http://www.apploader.info


text:
Programming an Arduino using Python, rather than C/C++
I am not very skilled with the C Language and I was wondering if there is a way in which python could be used to program an Arduino. This would most likely require a different IDE in order to be able to debug the scripts them self.

There are couple alternatives for programming Arduino, one of them is BitLash and there is a basic interpreter. There are couple options when you search the Internet, but learning C/C++ will pay off in the end.

Thanks, I am actually getting a bit better at C, just not as good as I am with Python.

related, more general question: "Arduino programming options other than C++"

Is a raspberry PI an option?

It's going to be extremely difficult to get any kind of Python script running directly on the Arduino. The reason is that it's an interpreted language, so you would need the interpreter on-board in addition to the plain text script. There's probably not going to be enough memory for all of that.
Your best bet would probably be finding a way to compile a Python script to native machine code (which is how C/C++ works). I believe there are projects around to do something like that for other platforms, but (as far as I know) none which does it successfully for Arduino yet.
You might find some more useful information on this question at Stack Overflow: Is there a way to "compile" Python code onto an Arduino (Uno).

Yes, it is (somewhat) possible to program the Arduino using Python. One such project on Github is the Python Arduino Prototyping API v2. It provides very basic functionality such as digital I/O and analog I/O.
This can be used for very simple projects.

*This project is a bit of a hack at "programming" the board using the serial connection. It passes the commands over the serial connection to a sketch running on the board which then "executes" the Python command.

So the board has to be plugged into a computer in order to actually run the code?

@JVarhol Oddly, yes.

Well, that pretty crappy. It would be easier to use a Raspberry Pi.

There is a project which brings a Python virtual machine to micro-controllers, including the Arduino Mega.
Here's a quote from the Ardunio Mega README, which gives a feel for what this could be like (though, I've not tested this!):

The following is an example session using ipm::
ipm> import avr, sys
ipm> avr.ddrA(0xff)
ipm> avr.portA(0)       # Pins 22-29 all at 0 V
ipm> avr.portA(0xa5)
ipm> sys.heap()
(2622, 7424)

I have used pyserial with great success in controlling the pins on the arduino.  Your workstation (laptop, etc) runs a python script that then communicates in real time to the arduino.
It's not quite the same as running the script directly on the arduino but I was doing quite a bit more than I thought the arduino could handle (some music analysis, hitting a REST api, etc).

Another option to consider is the Arduino Yun. In addition to the AVR chip which most Arduinos have, it also includes a MIPS chip running Linux. Since it's linux, you can easily run python code, and any pure-python package can be easily installed.
However, all the interesting input/output capability is on the AVR chip, not on the MIPS chip. Projects such as Autobahn and LininoIO solve this problem by running a special program on the AVR chip which performs I/O operations under instruction from the MIPS chip.

Yes,its possible with the recent new ArduinoPro H7 which has abilities to upload a written programme in Python and JavaScript and its a dual core,32bit.

Java Script? really? did you try it?

We know this is an open issue in Arduino programming and in the embedded world in general.
There are various solutions available on the market like MicroPython but most of them are dedicated to specific boards and don't allow to keep the system real-time.
We are working on a solution!
VIPER is a Python Virtual Machine for Arduino DUE and all ARM 32 bit architectures that runs on top of a real-time operating system.
This means that you can develop Python scripts that can be exexuted by Arduino DUE, UDOO, Spark (all boards) and also on the new ST nucleo boards.
Moreover if you need high performances and you re skilled in C you can develop real-time modules for VIPER that can be called and managed by the Python scripts.
You can see VIPER in action here http://bit.ly/kickviper

It’s not an open issue. python is a horrible indentation language.

Yes. Python can be used to program an Arduino, simply by importing pyfirmata, which can interface the arduino with Python.

True. But that isn't what the OP is asking for.

I disagree. Using firmata is effectively "programming an Arduino" using python. In fact I was surprised to see nobody else suggested it. From a beginner's point of view it's pretty much the same. I'm thinking of using it to help teach my son programming as python is a bit easier than C.

You could learn from C (AVR) how sensors work but it needs much more time.
Arduino IDE Code and Python Code for Arduino use C Code functions to make things simple.
Python and Arduino IDE if use Firmata they use serial communication and you think you code self.

You gotta use pyfirmata because that's the only way to make your son a PRO engineer who makes robots. Also, python can do more advanced stuff so use pyfirmata.


text:
Is it possible to find the time taken by millis?
The function millis would be running in the span of 100+ microseconds or less. Is there a reliable way to go about measuring the time taken by a single millis call?
One approach that comes to mind is using micros, however, a call to micros will include the time taken by the function call of micros itself as well, so depending on how long micros takes, the measurement for millis may be off.
I need to find this as an application I am working on requires accurate time measurements for every step taken in the code, including millis.

Can you clarify what you are asking here? Are you trying to get accurate times from millis() or are you trying to work out how long it takes to call the function millis()?

@Cybergibbons How long a call to miilis takes.

If you want to know exactly how long something will take, there is only one solution: Look at the disassembly!
Starting with the minimal code:
void setup(){};

volatile uint16_t x;
void loop()
{
  x = millis();

}

This code compiled and then fed into avr-objdump -S produces a documented disassembly. Here are the interesting excerpts:
void loop() produces:
000000a8 <loop>:
  a8:   0e 94 a7 00     call    0x14e   ; 0x14e <millis>
  ac:   60 93 00 01     sts 0x0100, r22
  b0:   70 93 01 01     sts 0x0101, r23
  b4:   80 93 02 01     sts 0x0102, r24
  b8:   90 93 03 01     sts 0x0103, r25
  bc:   08 95           ret

Which is a function call (call), four copies (which copy each of the bytes in the uint32_t return value of millis() (note that the arduino docs call this a long, but they are incorrect to not be explicitly specifying the variable sizes)), and finally the function return.
call requires 4 clock cycles, and each sts requires 2 clock cycles, so we have a minimum of 12 clock cycles just for function call overhead.
Now, lets look at the disassembly of the <millis> function, which is located at 0x14e:
unsigned long millis()
{
    unsigned long m;
    uint8_t oldSREG = SREG;
 14e:   8f b7           in  r24, 0x3f   ; 63

    // disable interrupts while we read timer0_millis or we might get an
    // inconsistent value (e.g. in the middle of a write to timer0_millis)
    cli();
 150:   f8 94           cli
    m = timer0_millis;
 152:   20 91 08 01     lds r18, 0x0108
 156:   30 91 09 01     lds r19, 0x0109
 15a:   40 91 0a 01     lds r20, 0x010A
 15e:   50 91 0b 01     lds r21, 0x010B
    SREG = oldSREG;
 162:   8f bf           out 0x3f, r24   ; 63

    return m;
}
 164:   b9 01           movw    r22, r18
 166:   ca 01           movw    r24, r20
 168:   08 95           ret

As you can see, the millis() function is fairly simple:

in saves the interrupt register settings (1 cycle)
cli turns off the interrupts (1 cycle)
lds copy one of the 4 bytes of the current value of the milli counter into a temporary register (2 clock cycles)
lds Byte 2 (2 clock cycles)
lds Byte 3 (2 clock cycles)
lds Byte 4 (2 clock cycles)
out restore interrupt settings (1 clock cycle)
movw shuffle registers around (1 clock cycle)
movw and again (1 clock cycle)
ret return from subroutine  (4 cycles)

So, if we add them all up, we have a total of 17 clock cycles in the millis() function itself, plus a call overhead of 12, for a total of 29 clock cycles.
Assuming a 16 Mhz clock rate (most arduinos), each clock cycle is 1 / 16e6 seconds, or 0.0000000625 seconds, which is 62.5 nanoseconds. 62.5 ns * 29 = 1.812 microseconds.
Therefore, the total execution time for a single millis() call on most Arduinos will be 1.812 microseconds.

AVR Assembly reference
As a side-note, there is space for optimization here! If you update the unsigned long millis(){} function definition to be inline unsigned long millis(){}, you would remove the call overhead (at the cost of slightly larger code size). Furthermore, it looks like the compiler is doing two unnecessary moves (the two movw calls, but I haven't looked at it that closely).
Really, considering the function call overhead is 5 instructions, and the actual contents of the millis() function is only 6 instructions, I think the millis() function should really be inline by default, but the Arduino codebase is rather poorly optimized.

Here is the full disassemby for anyone interested:
sketch_feb13a.cpp.elf:     file format elf32-avr

Disassembly of section .text:

00000000 <__vectors>:
    SREG = oldSREG;

    return m;
}

unsigned long micros() {
   0:   0c 94 34 00     jmp 0x68    ; 0x68 <__ctors_end>
   4:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
   8:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
   c:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  10:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  14:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  18:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  1c:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  20:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  24:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  28:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  2c:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  30:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  34:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  38:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  3c:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  40:   0c 94 5f 00     jmp 0xbe    ; 0xbe <__vector_16>
  44:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  48:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  4c:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  50:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  54:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  58:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  5c:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  60:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>
  64:   0c 94 51 00     jmp 0xa2    ; 0xa2 <__bad_interrupt>

00000068 <__ctors_end>:
  68:   11 24           eor r1, r1
  6a:   1f be           out 0x3f, r1    ; 63
  6c:   cf ef           ldi r28, 0xFF   ; 255
  6e:   d8 e0           ldi r29, 0x08   ; 8
  70:   de bf           out 0x3e, r29   ; 62
  72:   cd bf           out 0x3d, r28   ; 61

00000074 <__do_copy_data>:
  74:   11 e0           ldi r17, 0x01   ; 1
  76:   a0 e0           ldi r26, 0x00   ; 0
  78:   b1 e0           ldi r27, 0x01   ; 1
  7a:   e2 e0           ldi r30, 0x02   ; 2
  7c:   f2 e0           ldi r31, 0x02   ; 2
  7e:   02 c0           rjmp    .+4         ; 0x84 <.do_copy_data_start>

00000080 <.do_copy_data_loop>:
  80:   05 90           lpm r0, Z+
  82:   0d 92           st  X+, r0

00000084 <.do_copy_data_start>:
  84:   a0 30           cpi r26, 0x00   ; 0
  86:   b1 07           cpc r27, r17
  88:   d9 f7           brne    .-10        ; 0x80 <.do_copy_data_loop>

0000008a <__do_clear_bss>:
  8a:   11 e0           ldi r17, 0x01   ; 1
  8c:   a0 e0           ldi r26, 0x00   ; 0
  8e:   b1 e0           ldi r27, 0x01   ; 1
  90:   01 c0           rjmp    .+2         ; 0x94 <.do_clear_bss_start>

00000092 <.do_clear_bss_loop>:
  92:   1d 92           st  X+, r1

00000094 <.do_clear_bss_start>:
  94:   ad 30           cpi r26, 0x0D   ; 13
  96:   b1 07           cpc r27, r17
  98:   e1 f7           brne    .-8         ; 0x92 <.do_clear_bss_loop>
  9a:   0e 94 f0 00     call    0x1e0   ; 0x1e0 <main>
  9e:   0c 94 ff 00     jmp 0x1fe   ; 0x1fe <_exit>

000000a2 <__bad_interrupt>:
  a2:   0c 94 00 00     jmp 0   ; 0x0 <__vectors>

000000a6 <setup>:
  a6:   08 95           ret

000000a8 <loop>:
  a8:   0e 94 a7 00     call    0x14e   ; 0x14e <millis>
  ac:   60 93 00 01     sts 0x0100, r22
  b0:   70 93 01 01     sts 0x0101, r23
  b4:   80 93 02 01     sts 0x0102, r24
  b8:   90 93 03 01     sts 0x0103, r25
  bc:   08 95           ret

000000be <__vector_16>:
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ISR(TIM0_OVF_vect)
#else
ISR(TIMER0_OVF_vect)
#endif
{
  be:   1f 92           push    r1
  c0:   0f 92           push    r0
  c2:   0f b6           in  r0, 0x3f    ; 63
  c4:   0f 92           push    r0
  c6:   11 24           eor r1, r1
  c8:   2f 93           push    r18
  ca:   3f 93           push    r19
  cc:   8f 93           push    r24
  ce:   9f 93           push    r25
  d0:   af 93           push    r26
  d2:   bf 93           push    r27
    // copy these to local variables so they can be stored in registers
    // (volatile variables must be read from memory on every access)
    unsigned long m = timer0_millis;
  d4:   80 91 08 01     lds r24, 0x0108
  d8:   90 91 09 01     lds r25, 0x0109
  dc:   a0 91 0a 01     lds r26, 0x010A
  e0:   b0 91 0b 01     lds r27, 0x010B
    unsigned char f = timer0_fract;
  e4:   30 91 0c 01     lds r19, 0x010C

    m += MILLIS_INC;
  e8:   01 96           adiw    r24, 0x01   ; 1
  ea:   a1 1d           adc r26, r1
  ec:   b1 1d           adc r27, r1
    f += FRACT_INC;
  ee:   23 2f           mov r18, r19
  f0:   2d 5f           subi    r18, 0xFD   ; 253
    if (f >= FRACT_MAX) {
  f2:   2d 37           cpi r18, 0x7D   ; 125
  f4:   20 f0           brcs    .+8         ; 0xfe <__vector_16+0x40>
        f -= FRACT_MAX;
  f6:   2d 57           subi    r18, 0x7D   ; 125
        m += 1;
  f8:   01 96           adiw    r24, 0x01   ; 1
  fa:   a1 1d           adc r26, r1
  fc:   b1 1d           adc r27, r1
    }

    timer0_fract = f;
  fe:   20 93 0c 01     sts 0x010C, r18
    timer0_millis = m;
 102:   80 93 08 01     sts 0x0108, r24
 106:   90 93 09 01     sts 0x0109, r25
 10a:   a0 93 0a 01     sts 0x010A, r26
 10e:   b0 93 0b 01     sts 0x010B, r27
    timer0_overflow_count++;
 112:   80 91 04 01     lds r24, 0x0104
 116:   90 91 05 01     lds r25, 0x0105
 11a:   a0 91 06 01     lds r26, 0x0106
 11e:   b0 91 07 01     lds r27, 0x0107
 122:   01 96           adiw    r24, 0x01   ; 1
 124:   a1 1d           adc r26, r1
 126:   b1 1d           adc r27, r1
 128:   80 93 04 01     sts 0x0104, r24
 12c:   90 93 05 01     sts 0x0105, r25
 130:   a0 93 06 01     sts 0x0106, r26
 134:   b0 93 07 01     sts 0x0107, r27
}
 138:   bf 91           pop r27
 13a:   af 91           pop r26
 13c:   9f 91           pop r25
 13e:   8f 91           pop r24
 140:   3f 91           pop r19
 142:   2f 91           pop r18
 144:   0f 90           pop r0
 146:   0f be           out 0x3f, r0    ; 63
 148:   0f 90           pop r0
 14a:   1f 90           pop r1
 14c:   18 95           reti

0000014e <millis>:

unsigned long millis()
{
    unsigned long m;
    uint8_t oldSREG = SREG;
 14e:   8f b7           in  r24, 0x3f   ; 63

    // disable interrupts while we read timer0_millis or we might get an
    // inconsistent value (e.g. in the middle of a write to timer0_millis)
    cli();
 150:   f8 94           cli
    m = timer0_millis;
 152:   20 91 08 01     lds r18, 0x0108
 156:   30 91 09 01     lds r19, 0x0109
 15a:   40 91 0a 01     lds r20, 0x010A
 15e:   50 91 0b 01     lds r21, 0x010B
    SREG = oldSREG;
 162:   8f bf           out 0x3f, r24   ; 63

    return m;
}
 164:   b9 01           movw    r22, r18
 166:   ca 01           movw    r24, r20
 168:   08 95           ret

0000016a <init>:

void init()
{
    // this needs to be called before setup() or some functions won't
    // work there
    sei();
 16a:   78 94           sei

    // on the ATmega168, timer 0 is also used for fast hardware pwm
    // (using phase-correct PWM would mean that timer 0 overflowed half as often
    // resulting in different millis() behavior on the ATmega8 and ATmega168)
#if defined(TCCR0A) && defined(WGM01)
    sbi(TCCR0A, WGM01);
 16c:   84 b5           in  r24, 0x24   ; 36
 16e:   82 60           ori r24, 0x02   ; 2
 170:   84 bd           out 0x24, r24   ; 36
    sbi(TCCR0A, WGM00);
 172:   84 b5           in  r24, 0x24   ; 36
 174:   81 60           ori r24, 0x01   ; 1
 176:   84 bd           out 0x24, r24   ; 36
    // this combination is for the standard atmega8
    sbi(TCCR0, CS01);
    sbi(TCCR0, CS00);
#elif defined(TCCR0B) && defined(CS01) && defined(CS00)
    // this combination is for the standard 168/328/1280/2560
    sbi(TCCR0B, CS01);
 178:   85 b5           in  r24, 0x25   ; 37
 17a:   82 60           ori r24, 0x02   ; 2
 17c:   85 bd           out 0x25, r24   ; 37
    sbi(TCCR0B, CS00);
 17e:   85 b5           in  r24, 0x25   ; 37
 180:   81 60           ori r24, 0x01   ; 1
 182:   85 bd           out 0x25, r24   ; 37

    // enable timer 0 overflow interrupt
#if defined(TIMSK) && defined(TOIE0)
    sbi(TIMSK, TOIE0);
#elif defined(TIMSK0) && defined(TOIE0)
    sbi(TIMSK0, TOIE0);
 184:   ee e6           ldi r30, 0x6E   ; 110
 186:   f0 e0           ldi r31, 0x00   ; 0
 188:   80 81           ld  r24, Z
 18a:   81 60           ori r24, 0x01   ; 1
 18c:   80 83           st  Z, r24
    // this is better for motors as it ensures an even waveform
    // note, however, that fast pwm mode can achieve a frequency of up
    // 8 MHz (with a 16 MHz clock) at 50% duty cycle

#if defined(TCCR1B) && defined(CS11) && defined(CS10)
    TCCR1B = 0;
 18e:   e1 e8           ldi r30, 0x81   ; 129
 190:   f0 e0           ldi r31, 0x00   ; 0
 192:   10 82           st  Z, r1

    // set timer 1 prescale factor to 64
    sbi(TCCR1B, CS11);
 194:   80 81           ld  r24, Z
 196:   82 60           ori r24, 0x02   ; 2
 198:   80 83           st  Z, r24
#if F_CPU >= 8000000L
    sbi(TCCR1B, CS10);
 19a:   80 81           ld  r24, Z
 19c:   81 60           ori r24, 0x01   ; 1
 19e:   80 83           st  Z, r24
    sbi(TCCR1, CS10);
#endif
#endif
    // put timer 1 in 8-bit phase correct pwm mode
#if defined(TCCR1A) && defined(WGM10)
    sbi(TCCR1A, WGM10);
 1a0:   e0 e8           ldi r30, 0x80   ; 128
 1a2:   f0 e0           ldi r31, 0x00   ; 0
 1a4:   80 81           ld  r24, Z
 1a6:   81 60           ori r24, 0x01   ; 1
 1a8:   80 83           st  Z, r24

    // set timer 2 prescale factor to 64
#if defined(TCCR2) && defined(CS22)
    sbi(TCCR2, CS22);
#elif defined(TCCR2B) && defined(CS22)
    sbi(TCCR2B, CS22);
 1aa:   e1 eb           ldi r30, 0xB1   ; 177
 1ac:   f0 e0           ldi r31, 0x00   ; 0
 1ae:   80 81           ld  r24, Z
 1b0:   84 60           ori r24, 0x04   ; 4
 1b2:   80 83           st  Z, r24

    // configure timer 2 for phase correct pwm (8-bit)
#if defined(TCCR2) && defined(WGM20)
    sbi(TCCR2, WGM20);
#elif defined(TCCR2A) && defined(WGM20)
    sbi(TCCR2A, WGM20);
 1b4:   e0 eb           ldi r30, 0xB0   ; 176
 1b6:   f0 e0           ldi r31, 0x00   ; 0
 1b8:   80 81           ld  r24, Z
 1ba:   81 60           ori r24, 0x01   ; 1
 1bc:   80 83           st  Z, r24
#if defined(ADCSRA)
    // set a2d prescale factor to 128
    // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
    // XXX: this will not work properly for other clock speeds, and
    // this code should use F_CPU to determine the prescale factor.
    sbi(ADCSRA, ADPS2);
 1be:   ea e7           ldi r30, 0x7A   ; 122
 1c0:   f0 e0           ldi r31, 0x00   ; 0
 1c2:   80 81           ld  r24, Z
 1c4:   84 60           ori r24, 0x04   ; 4
 1c6:   80 83           st  Z, r24
    sbi(ADCSRA, ADPS1);
 1c8:   80 81           ld  r24, Z
 1ca:   82 60           ori r24, 0x02   ; 2
 1cc:   80 83           st  Z, r24
    sbi(ADCSRA, ADPS0);
 1ce:   80 81           ld  r24, Z
 1d0:   81 60           ori r24, 0x01   ; 1
 1d2:   80 83           st  Z, r24

    // enable a2d conversions
    sbi(ADCSRA, ADEN);
 1d4:   80 81           ld  r24, Z
 1d6:   80 68           ori r24, 0x80   ; 128
 1d8:   80 83           st  Z, r24
    // here so they can be used as normal digital i/o; they will be
    // reconnected in Serial.begin()
#if defined(UCSRB)
    UCSRB = 0;
#elif defined(UCSR0B)
    UCSR0B = 0;
 1da:   10 92 c1 00     sts 0x00C1, r1
#endif
}
 1de:   08 95           ret

000001e0 <main>:
#include <Arduino.h>

int main(void)
 1e0:   cf 93           push    r28
 1e2:   df 93           push    r29
{
    init();
 1e4:   0e 94 b5 00     call    0x16a   ; 0x16a <init>

#if defined(USBCON)
    USBDevice.attach();
#endif

    setup();
 1e8:   0e 94 53 00     call    0xa6    ; 0xa6 <setup>

    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
 1ec:   c0 e0           ldi r28, 0x00   ; 0
 1ee:   d0 e0           ldi r29, 0x00   ; 0
#endif

    setup();

    for (;;) {
        loop();
 1f0:   0e 94 54 00     call    0xa8    ; 0xa8 <loop>
        if (serialEventRun) serialEventRun();
 1f4:   20 97           sbiw    r28, 0x00   ; 0
 1f6:   e1 f3           breq    .-8         ; 0x1f0 <main+0x10>
 1f8:   0e 94 00 00     call    0   ; 0x0 <__vectors>
 1fc:   f9 cf           rjmp    .-14        ; 0x1f0 <main+0x10>

000001fe <_exit>:
 1fe:   f8 94           cli

00000200 <__stop_program>:
 200:   ff cf           rjmp    .-2         ; 0x200 <__stop_program>

Wow, great answer! +1

1) The four sts should not be counted as call overhead: this is the cost of storing the result in a volatile variable, which you would normally not do. 2) On my system (Arduino 1.0.5, gcc 4.8.2), I don't have the movws. Then the cost of calling millis() is: 4 cycles of call overhead + 15 cycles in millis() itself = 19 cycles total (≈ 1.188 µs @ 16 MHz).

@EdgarBonet - That doesn't make sense, x is a uint16_t. It should be 2 copies at most if that is the cause. Anyways, the question is how long does millis() take when used, not when called while ignoring the result. Since any practical use is going to involve doing something with the result, I forced the result to be stored via volatile. Normally, the same effect would be achieved by the later use of the variable that is set to the return value of the call, but I didn't want to have that extra call taking up space in the answer.

This uint16_t in the source does not match the assembly (4 bytes stored into RAM). You probably posted the source and disassembly of two different versions.

@ConnorWolf Amazing answer and explanation. Thank you!

Write a sketch that millis 1000 times, not by making a loop, but by copy and paste. Measure that and compare it to the actual expected time. Mind you that that the results may vary with different versions of the IDE (and its compiler in particular).
Another option is to toggle an IO pin before and after the millis call, then measure the time for a very small value and a somewhat larger value. Compare the measured timings and calculate the overhead.
The most accurate way is to take a look at the disassembly listing, the generated code. But that is not for the faint of heart. You'll have to carefully study the datasheet how long each instruction cycle takes.

How would you measure the time taken by 1000 millis() calls?

You do know millis() is supplied by an interrupt on timer0 that increments an internal variable every tick?

@TheDoctor I mixed up with delay, you are right. But the idea stays the same, you can time a large number of calls and average them. Turning off the interrupts globally may not be a very good idea though ;o)

Make sure your data set is large enough as printing characters to the Serial take a few milliseconds themselves. I don't remember the exact time, but I think it's something like ~0.6ms per character sent to Serial.

@Steven10172 you can time an empty string against a 1000-times string (or more), then you know the delta and the measurement is more accurate.

I second calling millis repeatedly and then comparing actual vs. expected.
There will be some minimal overhead, but it will diminish in significance the more times you call millis().
If you look at
C:\Program Files (x86)\Arduino\Arduino ERW 1.0.5\hardware\arduino\cores\arduino\wiring.c

You can see that millis() is very tiny at only 4 instructions (cli is simply # define cli()  \__asm__ \__volatile__ ("cli" ::)) and a return.
I'd call it about 10 million times using a FOR loop which has a volatile as the conditional. The volatile keyword will prevent the compiler from attempting any optimization on the loop itself.
I don't guarantee the following to be syntactically perfect..
int temp1,temp2;
temp1=millis();
for (volatile unsigned int j=0;j<1000000;++j){
temp2=millis();}
Serial.print("Execution time = ");
Serial.print((temp2-temp1,DEC);
Serial.print("ms");

my guess is that takes ~900ms or about 56us per call to millis. ( I don't have an aruduino handy ATM.

You should change int temp1,temp2; to volatile int temp1,temp2; to prevent the compiler from potentially optimizing them away.

Good call on the volatile. I definitely meant to put that in and then didn't.
I should have also mentioned that the way to do a more proper benchmark is to run an empty loop, record that execution time, then run the loop again while doing work. Subtract the difference, divide by the number of iterations, and there is your highly accurate execution time.

That kind of benchmark only works on a system that does not ever pre-empt your code execution. The arduino environment by default has periodic interrupts that will execute periodically. A better solution would be to toggle a pin on every execution, and use a high-resolution timer of some sort to measure the toggle rate when running and not running the code in question, take the minimum execution time over a number of samples for each, subtract the baseline, and treat that as your execution time. Assuming your execution time is shorter then the minimum time-between interrupts.