text:
Are all Arduino shields compatible with all Arduino boards?
Are all Arduino shields compatible with all Arduino boards? Like is the Wi-Fi one compatible with the Arduino Nano & Micro as well as the Uno, etc., or do I need to be careful when buying shields that they'll be compatible with my board? Also, the shields just plug into the boards, don't they?

When you want to choose a shield for your board you should check:
1- Pin-out, this one is the least concerning one , Most arduino boards are Shield pin-out compatible and you can verify it visually, for others, normally there are some converter boards (e.g for NANO), and in the worst case, building a converter board or wiring the shield to board is trivial in most situations.
2- Shield operating voltage should match your board's, most shields operate at 5V, 3.3V or both. Normally AVR-based boards (e.g. UNO, Mega, ...) operate at 5V and ARM based ones (e.g. Due, ...) operate at 3.3V, So we should choose the shield accordingly (just keep in mind that most shield are designed with Arduino UNO in mind so it's more likely that your shields operate at 5V).
3- Library, Lots of Libraries for Arduino shields bypass Arduino library abstraction (mostly for performance reasons) and use hardware specific features (e.g directly write on specific ports), here is source of some incompatibilities between your board and the shield, for example there are handful of TFT LCD shields in the market which their library only supports UNO boards, in these cases you should either port it to your board's (based on micro-controller model and it's architecture, sometimes its as easy as changing some pin/port definitions and sometimes as hard as writing the library from scratch).

For the most part, all the shields are compatible with all the boards that have a matching shield footprint. For example, the Uno, Leonardo, and the front half of the mega all have their header pins laid out in the standard arduino shield shape. If your board has this shield footprint, then all you have to do is plug the shield in on top and upload the right code to make it work.
The nano and micro have a different size and shape than a standard arduino, and so shields will not have a handy way of attaching to them. Since they do have standard arduino chips on them, they are technically compatible, but you would have to make your own wiring to attach them.

Can you point me to documentation that shows what I need to look for so I'll be able to work out whether shields and boards are compatible please?

All you have to do is look at a picture. If the pins on the board are shield shaped (like this: http://www.themaximitecomputer.com/max/Programs/Hardware/Dontronics/Arduino%20Reference/Arduino-Dimensions.jpg ) Then any arduino shield should work.


text:
What are the 5V and VIN pins for?
I believe I can supply the Arduino with power in three different ways:

Use USB. The design trusts the 5V to be regulated, and does not regulate it in any way.
Use a regulated power source, trusted to be 5V, and connect it to GND and 5V.
Connect an unregulated power source, eg a battery, to GND and VIN. This should be above 6.2V (since the dropout voltage is 1.2V) and preferably between 9V and 12V. There is a built-in regulator that will supply the Arduino with exactly 5V.

But can I use any of those pins to power other components. E.g. if the Arduino is powered with USB, can I use the 5V pin to power a diode? I thought I could, but the voltage is 4.70V, while the USB is 5.07V. The VIN is 4.26V btw.
Are the 5V and VIN only for powering the Arduino?

It's an Arduino Nano, so no barrel jack.

where and when were you getting those voltages? It could be a drop from measuring with and without other current flowing from USB (if you measured initially without the arduino). There should be a small drop as the USB input power does go across a fuse (F1 on schematic) and a mosfet (T1) before reaching the 5v pin.

I put the Nano in a breadboard. And I measure the voltages with a multimeter, which I put in the breadboard right next to the pins from the Arduino. I understand that there can be a voltage drop when there is a load, ie when there is a current. But there is no other load in my setup, than what is inside the Arduino itself.

I measure the 5.07V, by putting the multimeter on the points where the USB connector is soldered to the Arduino.

There is Feeding power to Arduino: the ultimate guide

No. You can draw power from the 5v and VIN pins on the arduino. VIN is the completely unaltered input power before the regulator (it will be useless if regulated 5v is supplied directly). Outputting power is what the 5v pin is intended to be used for, not as a power input.
From the arduino website:

5V. This pin outputs a regulated 5V from the regulator on the
  board. The board can be supplied with power either from the DC power
  jack (7 - 12V), the USB connector (5V), or the VIN pin of the board
  (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the
  regulator, and can damage your board. We don't advise it.

Yet, provided that you do not exceed 5.5 volts on the +5v pin, you can absolutely use it to supply the arduino.  You bear the responsibility of ensuring that you do not exceed 6v though.

I am still wondering how the USB power fits into this. Does the USB power bypass the regulator? I think it must otherwise there is too much of a voltage drop. So is powering the Arduino through the +5V pin the same as powering by USB? And does powering it through the +5V pin still also give the +3.3V?

you can input power into an arduino, up to 20 volt, via vin pin.

They can also be used to draw power from the barrel jack (Vin) or from USB or the on-board regulator (5V). The schematic of the board shows all exact power paths.

Ok, but then why does the 5V and VIN pins have lower voltages then? And wouldn't that be a problem for many applications? I imagine that if I used a LCD display rated at 5V, it could (potentially) be a problem that it only gets 4.70 or 4.26V?

Btw: I am not an electrical engineer, and I am not able to understand the schematics. Maybe one day :)

It gets a lower voltage because the traces on the board have non-zero resistance, which results in a voltage drop. Check the datasheets of all components to see what voltage range they can accept, but 4.70V should be fine for 99% of all 5V electronics.

5V pin can be used to power up shields like Bluetooth, RFID, ultrasonic sensors etc..
vin pin is used to power up the Arduino. For example, when using shields such as L298 motor shield which is providing 5V output while operating from 12V.

The MBR0520 Schotky Power Rectifier (Surface Mount
Schottky Power Rectifier) is connected in the Series path of 5v pin present on Nano which can handle maximum of 12V reverse voltage and according to datasheet 20v typical valur thus we can power ON arduino NANO using 5v pin also provided you supply proper 5v through any type of DC-DC Converter to it.
https://www.onsemi.com/pub/Collateral/MBR0520LT1-D.PDF
http://malylubo.sk/wp-content/uploads/2013/01/Arduino_Nano_Schematic-1024x676.png

source: Stack Exchange

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

sort: votes


text:
uBlox LEA 6H and UNO no data
While using NEO 6M and getting close-to-perfect accuracy, connecting the 3dr uBlox LEA 6H shows incoming characters, but gibberish data (at 38400) like it is connecting to a wrong baud rate (although it isn't, i've checked it with u-center and works when connected to Ardupilot).
So i guess it is some kind of configuration to show only certain parts of NMEA (if it is showing NMEA and not something else).

what accuracy does your ublox lea6h gps have? I want to control quadcopter and need to find 1 GPS module has the high accuracy( may be < 1m)

Your uBlox LEA 6H is most likly configured to use the UBX binary protocol and not NMEA at all. This protocol, as well as how to switch your LEA 6H between NMEA and UBX is in this document, from the uBlox website:
http://www.u-blox.com/images/downloads/Product_Docs/u-blox6_ReceiverDescriptionProtocolSpec_%28GPS.G6-SW-10018%29.pdf
You may be able to use the code from the ArduPilotMega project to communicate in UBX, they use the UBX protocol and the code is open source, but I can't guarantee its very good quality.

Using u-center, i'll try to change the output sentences. This pdf is extremely helpful!

You can configure the ublox lea6H GPS to read either through NMEA protocol or the UBX protocol. You just need to send some configuration messages. For good data rate it is better to use UBX protocol as it gives data in binary format inducing less delay.In case you need to test your device you can use my GPS code for arduino mega - customized ardupilot gps code  - UBX protocol.
https://github.com/ksskarthik/Team_Pushpak/blob/master/TP_GPS

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


text:
How to store gps values in EEPROM arduino?
I have two successfully working individual programs,
1.GPS coordinate extract program.
2.EEPROM saving and reading program.
now all I want to do is combine them both, whenever GPS location is updated ,I want to save that latitude data to EEPROM memory repalcing the previously saved data, but I guess my program is unable to save it,its just showing blank spaces when reading EEPROM,please help me guys..here is my code.
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define RXPin 8
#define TXPin 9
#define GPSBaud 9600
#define ConsoleBaud 9600

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

// The TinyGPS++ object
TinyGPSPlus gps;
#include <EEPROM.h>
int address = 0;
int read_value = 0;
char data;
void setup()
{
  Serial.begin(ConsoleBaud);
  ss.begin(GPSBaud);
  Serial.println("Previous value stored :");
  for(address = 0; address < 25; address ++)        // read the entire EEPROM memory
  {
    read_value = EEPROM.read(address);
    Serial.write(read_value);
  }
  Serial.println("\n");

}

void loop()
{

  while (ss.available() > 0)
    gps.encode(ss.read());

  if (gps.location.isUpdated() || gps.altitude.isUpdated())
  {
    Serial.print("Location: ");
    Serial.print(gps.location.lat(), 6);
    Serial.print(",");
    Serial.print(gps.location.lng(), 6);
    Serial.println("\n");

    data=(gps.location.lat(), 6);

    for(address = 0; address < 25;  )
    {
      EEPROM.write(address, data);
      address ++;
    }
  }
}

data=(gps.location.lat(), 6); just always stores 6 in data, this is what will be sotored on all 25 first locations of EEPROM. It looks you don't understand what you're doing with this code. I'd recommend taking a look at some basic C programming tutorial.

Consider TinyGPS++ over TinyGPS only if you are running on Due or processor which can take advantage of the higher precision of 64-bit “double” floating-point.
char data; should be double data;. You're wasting resources otherwise.
data=(gps.location.lat(), 6); isn't how you do it. You only need to specify precision when writing to Serial, like Serial.print(gps.location.lat(), 6);. Make it data = gps.location.lat();.
address ++; should be address = address <=512-sizeof(address) ? (address + sizeof(data)): 0 ;
address <=512-sizeof(address) ensures that the last value written to the EEPROM is written in it's entirety.
Alternatively, I would recommend this to save you data structure directly to EEPROM, and what @jfpoilpret mentions.

You might try using sprintf. First define a buffer:
char data[25];

Then use sprintf to print to the buffer:
sprintf(data, "Location: %.3f,%.3f\n", gps.location.lat(), gps.location.lon());

%.3f prints a float with 3 decimal places. Check out the printf reference for details.
Then write the buffer to EEPROM:
for(address = 0; address < 25; address++ )
{
  EEPROM.write(address, data);
}

Careful with lat() and lon(): those return a double not an int! Hence sprintf("...%d...") will not work unless you explicitly cast lat() and lon() return to int.

well spotted @jfpoilpret :P


text:
Communication between Arduino and iOS device
How can I get weight that has been measured by an Arduino device to show up on an iOS mobile or tablet device as a number?
Thanks.
Warmly,
N.

There are cables that let you plug in to the 30 pin connector and get a connection.
You could also use a BLE shield and write code for both platforms that communicate via BLE, or a WiFi shield.

There are a couple apps for this application but first you need the Arduino connected to the internet. It's called Iarduino and the instructables can be found here. I don't believe that you can communicate with your ios device with blue tooth. The app should allow for serial communication but I am not an expert on serial.

You can connect Bluetooth to IOS.

iOS doesn't support Serial over BlueTooth. So those cheap bluetooth modules don't work. There are other types of Bluetooth profiles do work, but are a bit harder to implement.

The last several generations of iDevices have supported Bluetooth Low Energy (BLE) with arbitrary peripherals, and encapsulating a (low rate) serial stream is possible.  They also support legacy bluetooth, but are locked down to only talk to "approved" peripherals - a restriction which does not apply to BLE.


text:
Arduino function to fade from one RGB color to the next
For my Arduino project I have a Neopixel RGB Strip with 72 LED's.
I can successfully change the colour of any of the LED's (at the moment I'm only setting the first one 0 for testing purposes) so I know my wiring isn't the problem here, it's my coding.
What I would like to do is be able to select a color and then another color and have the first color fade to the next color and so forth (much like the LIFX bulbs behave when using the iPhone application).
This is what I have at the moment:
I am logging output of all the variables to give you an indication of what's going on. I'm not 100% sure on where I'm going wrong or whether there's a much easier way to do what I'm after (I'm open to suggestions).
The function takes a parameter called command, which is a string separated by commas:
e.g. 255, 0, 0 (RED) or 0, 255, 0 (GREEN).
/*******************************************************************************
 * Function Name  : tinkerSetColour
 * Description    : Sets the strip with the appropriate colour
 * Input          : Pin and value
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 *******************************************************************************/
int Rstart = 0, Gstart = 0, Bstart = 0;
int Rnew = 0, Gnew = 0, Bnew = 0;

int tinkerSetColour(String command)
{
    sprintf(rgbString, "Rstart %i, Gstart %i, Bstart %i", Rstart, Gstart, Bstart);
    Spark.publish("rgb", rgbString);

    sprintf(rgbString, "Rnew %i, Gnew %i, Bnew %i", Rnew, Gnew, Bnew);
    Spark.publish("rgb", rgbString);

    // Clear strip.
    strip.show();

    int commaIndex = command.indexOf(',');
    int secondCommaIndex = command.indexOf(',', commaIndex+1);
    int lastCommaIndex = command.lastIndexOf(',');

    int red = command.substring(0, commaIndex).toInt();
    int grn = command.substring(commaIndex+1, secondCommaIndex).toInt();
    int blu = command.substring(lastCommaIndex+1).toInt();

    int Rend = red, Gend = grn, Bend = blu;

    sprintf(rgbString, "Rend %i, Gend %i, Bend %i", Rend, Gend, Bend);
    Spark.publish("rgb", rgbString);

    // Larger values of 'n' will give a smoother/slower transition.
    int n = 200;
    for (int i = 0; i < n; i++)
    {
        Rnew = Rstart + (Rend - Rstart) * i / n;
        Gnew = Gstart + (Gend - Gstart) * i / n;
        Bnew = Bstart + (Bend - Bstart) * i / n;

        // Set pixel color here.
        strip.setPixelColor(0, strip.Color(Rnew, Gnew, Bnew));
    }

    sprintf(rgbString, "Rnew %i, Gnew %i, Bnew %i", Rnew, Gnew, Bnew);
    Spark.publish("rgb", rgbString);

    Rstart = red, Gstart = grn, Bstart = blu;

    sprintf(rgbString, "Rstart %i, Gstart %i, Bstart %i", Rstart, Gstart, Bstart);
    Spark.publish("rgb", rgbString);

    return 1;
}

The problem is the colors are not fading between themselves.
Apologies if any of this is confusing. I can provide more information if necessary.
Here's the output selecting RED to begin with:
Rstart 0, Gstart 0, Bstart 0
Rnew 0, Gnew 0, Bnew 0
Rend 255, Gend 0, Bend 0
Rnew 253, Gnew 0, Bnew 0

Here's the output selecting GREEN directly afterwards:
Rstart 255, Gstart 0, Bstart 0
Rnew 253, Gnew 0, Bnew 0
Rend 0, Gend 255, Bend 0
Rnew 2, Gnew 253, Bnew 0

And then the output selecting BLUE after that:
Rstart 0, Gstart 255, Bstart 0
Rnew 2, Gnew 253, Bnew 0
Rend 0, Gend 23, Bend 255
Rnew 0, Gnew 25, Bnew 253

There is no delay in there. It will fade very quickly, add a delay e.g. 5ms with n = 200 for a 1 second fade:
int n = 200;
for (int i = 0; i < n; i++)
{
    Rnew = Rstart + (Rend - Rstart) * i / n;
    Gnew = Gstart + (Gend - Gstart) * i / n;
    Bnew = Bstart + (Bend - Bstart) * i / n;

    // Set pixel color here.
    strip.setPixelColor(0, strip.Color(Rnew, Gnew, Bnew));

    delay(5);
}

The other thing is your last value of n in the loop is 199, not 200, and thus Rnew etc don't have the correct final value. Change the comparison to be <= not <:
for (int i = 0; i <= n; i++)


text:
What is the execution context of the function registered via the Wire.onReceive() method?
I'm basically wondering if it's OK to Serial.write() or print in the function I register to be called when I2C data is received.  I can't seem to find the execution context or any warnings.
http://arduino.cc/en/Reference/WireOnReceive

Looking at twi.c in the Arduino libraries, it seems the callback function is called from within the I2C interrupt service routine (ISR). Any code in the call back will lengthen the ISR so it will have to be short. I don't think Serial.write will be too much of a problem; the TX interrupt will be delayed to the end of the I2C ISR which finishes straight after the callback and the Serial.write function is fairly short.
If you need to have a longer function run, you could instead have the callback store bytes in a ring buffer, then check for any available bytes in the main loop().. but this is what the Wire class helps with already.

Serial.write blocks if the serial buffer is full and waits for the buffer to have room before continuing. Conveniently, Serial.write checks to see if interrupts are disabled when it runs; If they are disabled, it runs the interrupt routines itself when a new character needs written to make space in the buffer, preventing lockup. In any case, if the buffer is full, printing on serial can take as long as it physically takes to output that many characters.

@BrettM thanks, I'll edit question with that (or edit it yourself and I will accept)


text:
Ruby and Arduino over Serial
I'm trying to send data over serial and pick it up in a ruby script. I'm using the serialport gem (https://rubygems.org/gems/serialport) as stated in the Arduino docs (http://playground.arduino.cc/Interfacing/Ruby).
My question is, I'm trying to print out some gyroscope data, particularly the x, y, and z. This is what my arduino sketch looks like:
void setup() {
  Serial.begin(9600);
  // ... do some gyro stuff here
}

void loop() {
  gyro.read();

  Serial.print((int)gyro.g.x);
  Serial.print(" ");
  Serial.print((int)gyro.g.y);
  Serial.print(" ");
  Serial.print((int)gyro.g.z);

  delay(500);
}

My ruby script is pretty straight forward as well:
require "serialport"
port_str = "/dev/tty.usbmodemfa141"
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
while true do
  message = sp.gets
  if message
    message.chomp!

    puts message
  end
end

However, the output that I get is choppy. What I mean by that is that the numbers don't come out as a single line as I intend:
52 9
5
250
 -28
 85
25
9 -5
1 69

Even if I replace it with "Hello World", it'll come out as:
He
llo
Wor
ld

or similar.
Any ideas why? Thanks in advance for any help.

Just use Serial.println() after printing all x y z.

Hey, thanks for replying. I think theres a little confusion as to what the problem is. I've edited the original question to show what the output I'm getting is now. It seems to be printing out on different lines.

The problem is then on your ruby code, as the Arduino program looks OK here.

Is your gyro project publicly available (e.g. on GitHub)?

Firstly, let's look into documentation for Ruby IO#gets:

Reads the next "line" from the I/O stream; lines are separated by sep ...

Secondly, look into documentation for Arduino Serial.print:

Prints data to the serial port as human-readable ASCII text ...

Finally, you don't print new line char \n in your "arduino sketch" above.
I recommend you to use Serial.println in the last line from your sketch:
void setup() {
  Serial.begin(9600);
  // ... do some gyro stuff here
}

void loop() {
  gyro.read();

  Serial.print((int)gyro.g.x);
  Serial.print(" ");
  Serial.print((int)gyro.g.y);
  Serial.print(" ");
  Serial.println((int)gyro.g.z);

  delay(500);
}

Yes Arduino code is fine although your should use println() as a terminator.
I think you should read the message into a tmpMessage var. If tmpMessage is empty then break out the loop otherwise concatenate tmpMessage into the message var.
Then print the message var after the loop when no more data arrives.
It must be ruby inserting the line breaks when you use puts


text:
Are there any reasons to pick Nano over Micro?
Nano is from 2008, and micro from 2012. Micro seems better on every parameter, in particular in having a better (I think) microcontroller, ATMega32u4, over ATMega328P.
However, all the shops I've checked out, both local and online, sell the Nano, and only some sell Micro. And Nano is always more expensive than Micro. E.g. at RS-Online 26GBP for Nano (link) and 16GBP for Micro (link).
Why do many shops only sell the inferior product?
Why is the older and less capable Nano more expensive?
Why would anyone buy the Nano over the Micro?

And why can I tag my question with "arduino-nano", but not with "arduino-micro"?

To create a tag, you'll need a reputation of at least 150.

Actually I know, but thanks :) What I meant is, obviously people on this site are asking questions more questions about Nano than about Micro. Obviously it could be because it has been around for longer, but still surprising to me, when Micro seems better in every aspect, and cheaper too.

It seems like there are lots of Nano clones, eg 6euros at DX.com. And I haven't seen any Micro clones. So if using clones, Nano is in fact much cheaper.

Look on ePrey. There are plenty of 5V Micro clones, cheaper than Nano clones. In fact, you have to go through about 100 Micro clones until you find a Nano clone (if you sort by lowest price), and maybe 80 5 volt Micros until you find a 3.3 volt Micro...

The main difference between the ATmega32u4 and the ATmega328P is that the 32u4 has onboard USB. When ATmega328P are used in an Arduino they are often coupled with an FTDI USB to serial chip. The FTDI chip is about $5 so this may be where the extra cost comes in.
Having the USB chip separate is actually not a bad thing:

The Atmega328P consumes less power than the ATmega32u4
FTDI chips are common, so the drivers are on most computers, whereas the 32u4 requires an .inf file to be loaded on Windows.
The FTDI chip uses the FTDI vendor and product ID and thus can be used in large-quantity commercial projects whereas the ATmega32u4 would require purchase of a vendor id and product id from the USB group. (My conclusion after reading around the net a bit, please correct if wrong).

I'd buy the NANO and STEER CLEAR of the micro with that 32u4 chip. The good ol' 328p chip also has a FTDI chip to handle USB to serial while the other chip handles it on its own. The problem is that the Micro's bootloader ONLY allows trying to program it with USB and requires a special driver. With Linux, only a few select versions have the needed driver. If your Linux version doesn't have the driver, you're out of luck. In that case, take it back or donate it to a hackerspace. You will NEVER make it work.
I was at the arduino.cc site about this and tried everything only to get increasingly annoyed about that lemon of a card. You know it's time to give up when you get flamed.

Nice to know about the Linux problems. I have programmed both Micro and Nano from Ubuntu without problems, but maybe I've been lucky this far.

However, if you need a 3 Volt device then you are obliged to go for a Micro, rather than a Nano.

It depends on what's your focus on. From pure microcontroller view, the 328P compared to the 32u4

is 4MHz faster
has two Touch Channels more
has picoPower technology
has an RTC
has a lower minimum supply voltage

If one or more of these features are essential for your project, the Nano may be the better choice.
Regarding the price:
I'm not sure if it can have such a high influence, but there may have been a technology shrink. That's why a modern 32bit micro is cheaper than an old-fashioned 8 or 16bit micro, at least in B2B pricing.

According to http://arduino.cc/en/Products.Compare, they are both 16MHz.

I'm not sure I understand what you mean by "technology shrink", could you explain?

The Arduino boards may both have a 16MHz oscillator populated, however the AtMega328P itself can be driven at up to 20MHz, according to Atmel's product comparison page. "Technology shrink" means a change in the production process to smaller silicon structures. For example, the Freescale S12 (16bit CPU) was built using 180nm process,  Renesas uses a 40nm process for the new RH850 (32bit CPU). Smaller structure = less silicon (plus other benefits). That's one reason why the RH850 is cheaper than the S12, but has much more features.


text:
Arduino: How does digitalRead read a value? And what is this value?
I have a Arduino Uno with 14 digital pins. I believe they have an output of 5V.
But they can also input values. I'm not sure of what exactly it reads when it does that (amperage, voltage ...). Also, how do they read it? How can such a tiny thing possibly know what it's receiving?
Just to provide a little more context to the reading part of this question, here's an example circuit. I have a 5V battery connected to an LED and a 220 Ohm resistor. Next thing in the circuit is a wire, which exits the main circuit and connects to a digital pin on the Arduino Uno (here it reads the value). Then the main circuit closes by connecting to ground.
Hope my question is clear enough :)

@NickAlexeev - there's nothing "Arduino" about this question to justify migrating it.  It's really a "how does a microcontroller work" question.

Modern digital electronics is made from many tiny electronic components called MOSFETs (a type of transistor). They can be switched on and off using a voltage, and a very small amount of current. They use the majority of the power when they are switching on and off; the rest of the time they use virtually no power. It this very low-power capability which allows us to make complex digital electronics.
Electronically, a MOSFET looks like a tiny capacitor, which triggers a very low-power switch, on and off. Once there is charge on the MOSFETs capacitor, the switch will stay on or off.
A modern large-scale processor, for example the type of device Intel makes, contains billions of MOSFETs, but requires less than 100W, and switches billions of times/second. So we can be confident that a MOSFET can be switched using much less than 1/10,000,000W. At 5V, that means 1/50,000,000A, or 0.000,000,02A, i.e. 0.02µA.
So, the input circuit, connected to an Arduino's pin has some protection, to protect the MOSFETs from static electricity (which could damage or destroy the capacitor), then a complementary pair of MOSFETs (called N-Chanel and P-Chanel). The input voltage switches one on, and the other off. It typically requires less than a micro-amp of current, but at a voltage close to ground or 5V. See pjc50's diagram.
So an Arduino input pin, connected to the 5V end of the resistor and LED will take a tiny amount of current, for a short time, to switch on.
If that pin is connected between the LED and resistor, at some voltage less than 5V, but more than 0V, then it might not switch fully. It might not give a reliable value of digital 0 or digital 1, and might switch high and low rapidly influenced by electrical noise in the environment.

Great explanation, thanks for taking your time to write this!

It measures voltage.
The input circuit is conceptually similar to this:

Voltages close to 5V will turn the lower transistor on and the upper one off.
Voltages close to 0V will turn the upper one on and the lower one off.
Voltages in the middle will turn both on to some extent, which is not recommended, and may be read as either 0 or 1 with a threshold in the middle.

"Such a tiny thing" contains tens or hundreds of thousands of transistors.

Great explanation, the image is really useful!

If somebody(like me) is looking for a explanation in terms of registers, the voltage at a pin when it's a digital input can be accessed with the PINx register, with a bit being used per a pin. Based on the value in the specific bit of the DDRx register, if it's 0 (an input), the voltage at the pin is represented by the bit in the PINx. When it's 1 (an output), the bit at the PINx register will be the value in the PORTx register for the specific bit(the value written). If the bit in the DDRx register for the pin is 0(an input), the bit in the PORTx register represents whether the internal pull-up resistor should be connected to the pin. x is used to mark the port (A,B, for example).
Edit: I've started working with the ATtiny10 for a specific, but most likely just-on-paper project. It has the separate PUEx register for the internal pull-ups. It has only 6 pins, with 4 or those being accessible as GPIOs. The pins have specific modes where every pin requires slightly different flag changes for changing the mode.

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


text:
Arduino Due SD Card
I have an Arduino Due and want to save data to an SD card. For this I use a 3.2 'display of ITead with integrated SD slot (http://imall.iteadstudio.com/im120419006.html). This I connected to the Arduino.
However, the Arduino doesn’t detect the SD card (I've tried two different cards and also reformatted both). I wired the three SD ports correctly to the SPI. I wired the CS output on to pin 4, 10 or 52 (each one once tested), without success. I have also tried using ICSP instead of SPI, which the Arduino website suggests. Again, without success.
The test program I used is a  test program on the Arduino website for SD cards (the program in the end of the post, changes marked in bold). Is the problem in the program code or is it a hardware problem? If it is a software problem, could you send me a test program that is designed for Arduino Due?
I have invested several hours and read tens of forums but found nothing comparable. Also, the proposed solutions never worked.
/*
  SD card test

 This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.

 The circuit:
  * SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
        Pin 4 used here for consistency with other Arduino examples

 created  28 Mar 2011
by Limor Fried
 modified 9 Apr 2012
by Tom Igoe
*/
// include the SD library:
#include <SD.h>
**#include <SPI.h>**

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = **10**;

void setup() {
// Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(**chipSelect**, OUTPUT);     // change this to 53 on a mega
  **SPI.begin(chipSelect); //habe ich eingeführt, da es in einigen Foren erwähnt wird, funktioniert jedoch mit und ohne nicht. //I made this, becaus it’s mentioned in severals forums, but it didn’t workt wiht it and whitout it**     // change this to 53 on a mega

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }
  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
  volumesize *= volume.clusterCount(); // we'll have a lot of clusters
  volumesize *= 512; // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
}

That board should have 2 CS pins. One for the display and one for the SD. I can't find any pinouts for that module. Try using a multimeter and test where all the pins of the SD-holder go to (especially the middle one).

Thanks very much,
I just controlled the connections from the SD-Card to the pins on the lcd-display, and they work. Also the wiring from the display to the arduino is okay.Do you know, if there are special needs to initialise SPI on the due?

Thank you very much. I solved part of the problem. I tried it whit a new SD Card. When I use pin 52, I am able to read the card information with the program above. But only if I use SPI.
Pin 10 doesn't work at all and Pin 4 a bit. If I work with Pin 4, it accepts the card, but it can't find out what format the SD card has. This is kind of weird, I think, because Arduino say alls three pins should work (http://arduino.cc/en/Reference/SPI). Does anybody knows something about this?

I use SD card with Arduino UNO. I connected SD card to the Arduino and I saw the Arduino don’t detect the SD card. Then  I see this tutorial and Arduino detect the SD card now.
Don't connect the SD card breakout board to Arduino and use non-inverting hex buffer(4050).


text:
Problems with substring loop
Hey folks … I was hoping some of you might cast your eye over my code.
It splits up a string read from EEprom into an array of separate strings. Based on String length information stored in a separate array. (tempArray[])
It reads fine … and also seems to process fine (ie. it does turn one long string into separate array items)      for some reason it stops working no the 8th array item?
The splitting code (problem) starts on line 80 and i have included the output above it in comments.
http://pastebin.com/Ax4R6t6J   << Full code also available here.
void reJigFromMemory(){

  Serial.print("Eeprom read 1 :");
  Serial.println(eepromReadOne);
  Serial.print("EEprom read 2 :");
  Serial.println(eepromReadTwo);
  String tempArray[10];

  int charLength=eepromReadOne.length()+1;
  char charBuff[charLength];
  eepromReadOne.toCharArray(charBuff, charLength);

  //// GET MEMORY LOCATIONS
  /*
converts long string of numbers:
   13161717171717252533
   into separate strings:
   13
   16
   17
   17
   17
   17
   17
   25
   25
   33

   And stores them in an array.
   */
  for (int i = 0; i <10 ; i++){
    tempArray[i]+=charBuff[i*2];
    tempArray[i]+=charBuff[(i*2)+1];
    Serial.print("I just translated :");
    Serial.println(tempArray[i]);
  }
  /// GET THE STRINGS USING THE ABOVE ARRAYS
  /*
converts long list of data ie:
   |0|Bingo#999#|1|Retest2#9222#|2|Retest3#92299#|3|Retest4#99339#|4|Retest5#95599#|5|Retest6#96699#|6|Retest7#99119#|7|User Defined eighth#0#|8|User Defined ninth #0#|9|User Defined tenth (last) .#0#

   into individual array strings:

   From Number = :0
   To number : 13
   Record 0 :          |0|Bingo#999#
   From Number = :13
   To number : 29
   Record 1 :          |1|Retest2#9222#
   From Number = :29
   To number : 46
   Record 2 :          |2|Retest3#92299#
   From Number = :46
   To number : 63
   Record 3:           |3|Retest4#99339#
   From Number = :63
   To number : 80
   Record 4:           |4|Retest5#95599#
   From Number = :80
   To number : 97
   Record 5:           |5|Retest6#96699#
   From Number = :97
   To number : 114
   Record 6 :          |6|Retest7#99119#
   From Number = :114
   To number : 139
   Record 7 :               <<<<<< THIS ONE IS MISSING ? WHY?
   From Number = :139
   To number : 164
   Record 8 :               <<<<<< THIS ONE IS MISSING ? WHY?
   From Number = :164
   To number : 197
   Record 9 :               <<<<<< THIS ONE IS MISSING ? WHY?

   */
  String tempArray2[10];
  int fromLocation = 0;
  int toLocation=0;

  for (int i = 0; i <10 ; i++){                 /////// LINE 80

    toLocation += tempArray[i].toInt();

    fromLocation += tempArray[i-1].toInt();
    tempArray2[i]=eepromReadTwo.substring(fromLocation,toLocation);
    Serial.print("From Number = :");
    Serial.println(fromLocation);
    Serial.print("To number : ");
    Serial.println(toLocation);
    Serial.print("I just translated :");
    Serial.println(tempArray2[i]);

  }
}

please post code that is complete, i.e. it compiles and can be uploaded to an Arduino. Posting only some parts of your code may not be helpful.

Full Code Link in serial monitor type 1 to write data to the eeprom then 2 to read the eeprom to variables and then type 5 to process it and see the failure. Thank you!

The first issue I can see in your contrived code is fromLocation += tempArray[i-1].toInt(); where i=0: behavior there is undefined (may crash immediately or override memory used later...)

Thanks for advise, I will try and alter that part.  I'm a beginner and i appreciate all input :)

Your 2nd for loop should look something like this:
int fromLocation = 0;
int toLocation=0;

for (int i = 0; i <10 ; i++)
{                 /////// LINE 80

    toLocation += tempArray[i].toInt();

    tempArray2[i]=eepromReadTwo.substring(fromLocation,toLocation);
    Serial.print("From Number = :");
    Serial.println(fromLocation);
    Serial.print("To number : ");
    Serial.println(toLocation);
    Serial.print("I just translated :");
    Serial.println(tempArray2[i]);
    fromLocation += tempArray[i].toInt();
  }
}

On the first pass through the loop, fromLocation is 0. toLocation starts at 0 and gets the value in tempArray2[0] added to it.
After extracting a string, you add the current array value to fromLocation to advance the pointer to the beginning of the next string.
Note that String objects are very inefficient way to save 2 digit numbers. It would be better use an array of ints, and write code that extracts 2 characters at a time into int values.
With only 20 String objects it's not a huge deal, but bear in mind that String objects take a lot of memory overhead on a memory-starved platform like an Arduino. Better to learn how to use C strings.

Great thank you so much.    Strangely using the code about gave me all entries EXCEPT number 7.    However once I changed the Search locations from char to int everything started working :D
Final Function Code - PasteBin


text:
Arduino Leonardo Upload issue with ubuntu 14.04
I got a bare conductive board ( which is based on arduino leonardo ) . I was trying to upload a blink sketch using arduion 1.5.7. But its always failing and here is the log. I never work a leonardo before. Any ideas what is happing with this ?
Build options changed, rebuilding all

/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /tmp/build5447563659949358969.tmp/Blink.cpp -o /tmp/build5447563659949358969.tmp/Blink.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_analog.c -o /tmp/build5447563659949358969.tmp/wiring_analog.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_digital.c -o /tmp/build5447563659949358969.tmp/wiring_digital.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_shift.c -o /tmp/build5447563659949358969.tmp/wiring_shift.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WInterrupts.c -o /tmp/build5447563659949358969.tmp/WInterrupts.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/hooks.c -o /tmp/build5447563659949358969.tmp/hooks.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_pulse.c -o /tmp/build5447563659949358969.tmp/wiring_pulse.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring.c -o /tmp/build5447563659949358969.tmp/wiring.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial3.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial3.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Tone.cpp -o /tmp/build5447563659949358969.tmp/Tone.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial1.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial1.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial2.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial2.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Print.cpp -o /tmp/build5447563659949358969.tmp/Print.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HID.cpp -o /tmp/build5447563659949358969.tmp/HID.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/USBCore.cpp -o /tmp/build5447563659949358969.tmp/USBCore.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/IPAddress.cpp -o /tmp/build5447563659949358969.tmp/IPAddress.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WMath.cpp -o /tmp/build5447563659949358969.tmp/WMath.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WString.cpp -o /tmp/build5447563659949358969.tmp/WString.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/main.cpp -o /tmp/build5447563659949358969.tmp/main.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial0.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial0.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/new.cpp -o /tmp/build5447563659949358969.tmp/new.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Stream.cpp -o /tmp/build5447563659949358969.tmp/Stream.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/CDC.cpp -o /tmp/build5447563659949358969.tmp/CDC.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_analog.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_digital.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_shift.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WInterrupts.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/hooks.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_pulse.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial3.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Tone.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial1.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial2.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Print.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HID.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/USBCore.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/IPAddress.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WMath.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WString.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/main.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial0.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/new.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Stream.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/CDC.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega32u4 -o /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.o /tmp/build5447563659949358969.tmp/core.a -L/tmp/build5447563659949358969.tmp -lm
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.eep
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.hex

Sketch uses 4,798 bytes (16%) of program storage space. Maximum is 28,672 bytes.
Global variables use 157 bytes (6%) of dynamic memory, leaving 2,403 bytes for local variables. Maximum is 2,560 bytes.
Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, } / {} => {}
PORTS {} / {} => {}
PORTS {} / {/dev/ttyACM0, } => {/dev/ttyACM0, }
Found upload port: /dev/ttyACM0
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avrdude -C/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/tmp/build5447563659949358969.tmp/Blink.cpp.hex:i

avrdude: Version 6.0.1, compiled on Apr  3 2014 at 21:52:43
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega32U4
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : butterfly
         Description     : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .avrdude: Send: . [1b]
avrdude: Send: S [53]
avrdude: Recv: C [43]

avrdude: ser_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding

And My dmesg output is
[ 3616.984079] usb 4-2: new full-speed USB device number 11 using uhci_hcd
[ 3617.155216] usb 4-2: New USB device found, idVendor=2a6e, idProduct=8003
[ 3617.155224] usb 4-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3617.155229] usb 4-2: Product: Touch Board
[ 3617.155234] usb 4-2: Manufacturer: Bare Conductive
[ 3617.158323] cdc_acm 4-2:1.0: This device cannot do calls on its own. It is not a modem.
[ 3617.158359] cdc_acm 4-2:1.0: ttyACM0: USB ACM device
[ 3617.166427] input: Bare Conductive Touch Board as /devices/pci0000:00/0000:00:1a.1/usb4/4-2/4-2:1.2/input/input22
[ 3617.166675] hid-generic 0003:2A6E:8003.0007: input,hidraw1: USB HID v1.01 Mouse [Bare Conductive Touch Board] on usb-0000:00:1a.1-2/input2

And My lsusb output
Bus 002 Device 002: ID 04f2:b179 Chicony Electronics Co., Ltd
Bus 002 Device 004: ID 18d1:4ee2 Google Inc. Nexus 4 (debug)
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 002: ID 03f0:171d Hewlett-Packard Bluetooth 2.0 Interface [Broadcom BCM2045]
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 011: ID 2a6e:8003
Bus 004 Device 002: ID 1d57:0008 Xenta
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Try the arduino.cc forums. Post your logs, and you MIGHT get an answer that'll work. The guys who developed the Leonardo got it to work with Ubuntu 10.04 without a special device driver. I use Ubuntu like you but not the magic 10.04 version and was forced to give up on the Leonardo despite heroic effort.
The problem is that 32u4 chip the Leonardo (and Micro) use. Instead of having a separate FTDI chip like a good ol' UNO, it handles USB on its own. With a bootloader on a Leonardo that enables only USB to be used (besides ICSP) Windows needs a funny .inf file to make it work. But Linux? In this case, Windows of a given version is Windows is Windows. Linux boxes are more like people in that each has its own personality, given the zillion distributions and versions thereof.
I'm convinced that the Leonardo developers merely got lucky with Ubuntu 10.04.

This is not an answer.


text:
PWM generation using Registers
I'm using the Registers of the Arduino micro to get a signal for Electronic Speed Controllers (ESC) for brushless motors.
As far as I read, ESCs interpret everything they can, while just ignoring too fast update rates. If somebody knows better, this would be a great time to yell.
The goal is to get a digital signal, where a timespan between 1 and 2 ms is HIGH and the rest low. Ideally I want this at 50-400Hz, since 488Hz is the fastest possible frequency, and 50 Hz the standard Servo frequency.
I try to use Phase Correct Mode to count up and down continuously. As the value in the counter reaches my set OCRnx on the way up, it sets the output pin LOW, as it reaches the same value on the way down, after reaching TOP(value), it sets the output HIGH. In ATmega documentation terms, this is NON-inverted Phase-Correct-PWM.
So I set the Registers DDR (to set the pin as output), TCCR1A and TCCR1B and ICR1 (TOPvalue = between 20000 and 2500).
Now using OCR1A = 1000 should give me a pulse width of 1000ms. This is the expected or target behaviour.
My testing code is:
// using a 16-bit timer to generate PWM signals for ESCs

// Phase Correct Mode counts from Bottom to Top and back to Bottom
// with a prescaler of 8
// motor signal (OCRnx) uses values of 1000 (idle) - 2000 (max)
// which directly corresponds to microseconds HIGH-time
// setting the range to (BOTTOM) 0 - TOPvalue sets the frequency

// two important formulas are:
// frequency(PWM) = F_CPU / (2*Prescalar*TOPvalue)
//
// PulseWidth [s] = High-tick-count / (F_CPU/Prescalar)
// High-tick-count = 2 * OCR-value

// n = number of timer (1,3)
// x = A,B,C

#include "Arduino.h"
// #include <Arduino.h>
// #define DEBUG
// #include <Moto.h>

#define PRESCALAR 8
#define PWM_FREQUENCY 50
#define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY)

uint16_t dutytime = 1000; // this gives idle throttle signal

void setup(void) {
  Serial.begin(115200);
  // moto.setup();

  // TIMER 1
  // TIMSK1 = 0; // disable Interrupts for timer1
  DDRB |= (1<<DDB5); // D9 Output
  DDRC |= (1<<DDC6); // D5 Output

  // set 1000ms to start motors in idle mode
  OCR1A = 1000L;
  OCR3A = 1000L;

  // bits 7,5,3 PWM Output on pins A,B,C respectively
  // bits 1,0 WGM_1,0: phase correction mode
  // TCCR1A |= B10000010; // in hex: 0xAA for all 3 = B 1010 1010
  TCCR1A |= (1<<COM1A1)|(1<<WGM11);
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  // TCCR1B |= B00010010; // in hex: 0x12; B 0001 0010
  TCCR1B |= (1<<WGM13)|(1<<CS11);
  ICR1 = TOP_VALUE;

  // TIMER 3
  // TIMSK3 = 0; // disable Interrupts for timer3
  // bit 7 PWM Output on pin A
  // bits 1,0 WGM_1,0: phase correction mode
  TCCR3A |= B10000010; // in hex: 0x82; // B 1000 0010
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  TCCR3B |= B00010010; // in hex: 0x12; B 0001 0010
  ICR3 = TOP_VALUE; // TOPvalue = 2048

}//setup

void loop(void) {

  // Serial.println(TOP_VALUE);
  // delay(500);
  while (dutytime < 2000) {
    dutytime += 150;
    OCR1A = dutytime;
    OCR3A = dutytime;
    Serial.println(dutytime);
    delay(1500);
  }
  while (dutytime > 1000) {
    dutytime -= 150;
    OCR1A = dutytime;
    OCR3A = dutytime;
    Serial.println(dutytime);
    delay(1500);
  }

}//loop

I repeated the settings for timer3 to get something to compare to. Both do give the same: if i delete the loop and just write loop{} nothing happens. The pins are high and seem to stay so. With the while loops activated, my multimeter gives me 1Hz (which are the changes of course) and between 99.9% duty cycle and 96%.
An led, which i connected to it blinks every second a very short time.
What am I doing wrong?

I don't understand what you want to achieve. Pulse width of 1000ms at a sample rate of 488.28Hz that seems contradictory, as the maximum pulse width can only be 2ms at 488Hz.

2048 to be exact for this case. Why is that contradictory, if I want to have pulses between 1 and 2 ms (something around 48% and 97% duty cycle)?

That doesn't really make it any clearer. Seems I can't help you then.

I'm not 100% familiar with Arduino timers, but here is how I did PWM on an MSP430 with timers: http://imgur.com/2aOnW2g Essentially, you count up, and reset. When the timer hits the set value, it does the rising edge pulse, and when it hits the max count, it resets both the pulse and the timer. The alternative of this is to do the opposite: set the pulse high until the timer hits the threshold value, etc.

Thanks. What you suggest is in Atmels Documentation called fast PWM, where the counters just count until overflow. I however use phase-corrected PWM, where it counts up and down. This gives a more symmetrical output (and according to them) is prefered over fast PWM.

What I did wrong was using |= instead of = . Apparently Arduino set some of these Bits on start, which didn't change.
Now it works like a charm and I added a frequency choice, which works for at least 50,200,400,488 Hz. Everything in between should work aswell!
Working testcode for timer1 with serial input of HIGH-time:
#define PRESCALAR 8
#define PWM_FREQUENCY 50
#define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY)

uint16_t dutytime = 1000; // this gives idle throttle signal

void setup(void) {
  Serial.begin(115200);

  // TIMER 1
  DDRB |= (1<<DDB5); // D9 Output

  // set 1000ms to start motors in idle mode
  OCR1A = 1000L;

  // bits 7,5,3 PWM Output on pins A,B,C respectively (COMnx1)
  // bits 1,0 WGM1(1,0): phase correction mode
  TCCR1A = B10000010; // in hex: 0xAA for all 3 = B 1010 1010
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  TCCR1B = B00010010; // in hex: 0x12; B 0001 0010
  ICR1 = TOP_VALUE;
}//setup

void loop(void) {
  // Serial.println(TOP_VALUE);
  dutytime = serial_input();
  if (dutytime) {
    OCR1A = dutytime;
  }
  delay(500);
}//loop

float serial_input() {
  double num = 0;
  while(Serial.available()) {
    delay(2);
    char ser = Serial.read();
    if(isDigit(ser)) {
      num = (num*10)+(ser-48);
    }else{ break; }
  }
  if (num) {Serial.println(num);}
  return num;
}


text:
While using Arduino Ethernet shield, do we need to explicitly select/Deselect SD and W5100 in our code?
It has been mentioned here http://arduino.cc/en/Main/ArduinoEthernetShield that corresponding libraries take care of chip select between SD and W5100 in Arduino Ethernet shield. Does it take care properly all the time? What happens if the Chipselect is not properly managed by libraries? Does that cause blocking of code?

Without the Chip Select the SPI device will just ignore all date on the SPI lines. I think you can trust most libraries to properly handle the CS pins.

Here we have a nice example of a single Shield requiring TWO libraries. The Ethernet.h and SD.h where the later appears as an after thought and is not demonstrated by the Example. As it is done so in the SD examples. However, their styles are slightly different.
The Ethernet libary as mentioned (provided within) the IDE is hardcoded to implement the Chip Select for the W5100 on corresponding pin. When using the typical purchased Ethernet Shield, there is no need to configure it. Unlike the SD library, which requires the pin to configured using the SD.begin(4) member function.
if (!SD.begin(4)) {
  Serial.println("initialization failed!");
  return;
}

Where again on the typical Ethernet shield the SD card is at pin D4.
Note being hardcode that the Ethernet library selects the matching pin to corresponding shield.
private:
#if defined(ARDUINO_ARCH_AVR)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };
#elif defined(__AVR_ATmega32U4__)
  inline static void initSS()    { DDRB  |=  _BV(6); };
  inline static void setSS()     { PORTB &= ~_BV(6); };
  inline static void resetSS()   { PORTB |=  _BV(6); };
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); };
#else
  inline static void initSS()    { DDRB  |=  _BV(2); };
  inline static void setSS()     { PORTB &= ~_BV(2); };
  inline static void resetSS()   { PORTB |=  _BV(2); };
#endif
#endif // ARDUINO_ARCH_AVR

And in the case of the UNO (or the else case) Port B Bit 2 is D10.

worth noting that SD library has an alternate method of initializing and using the SD card
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
  Serial.println("initialization failed. Things to check:");

where chipSelect would be D10 in this case.


text:
Problem uploading to Arduino Yun
I have an Arduino Yun. I am trying to upload the code in Arduino but after I click on Upload, I get the error message shown in the image.
At first it showed the Arduino Yun under the port tab, after this message no Arduino is showing in port tab.

The portion of the error visible in the image:

Couldn't find a Board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload.

It's very hard to read that error, perhaps you could crop it a bit? It's also useful to include the message as text so that it's searchable for anyone else with the same problem in the future.

In the Arduino IDE, click on Tools (on the menu bar). Then, open the submenu Board and make sure "YUN" is selected.

Seems like you havent chose the appropriate serial port.
Under tools, you'll also find serial port - make sure the appropiate one is selected.


text:
Arduino can't create file in sd card
I need to write and read some data from SD card. I link SD card(LC STUDIO) to Arduino (UNO). I use this link for create my project. In first day I don't have any problem and data correctly save to file. But now my circuit isn't work nicely. When Arduino is running the sketch I don't saw any error message.But when I link the SD card to my laptop, I don't saw any file on card!!
The code is here:
#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

File file;

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
  }
  Serial.println("card initialized.");
  //creating file
  file = SD.open("test.txt",FILE_WRITE);
  file.close();
  //write data to file
  file = SD.open("test.txt",FILE_WRITE);
  if(file){
    file.println("OK!!");
    file.println("1");
    file.println("2");
    file.println("3");
    file.println("OK!!");
    file.close();
  }
}
void loop()
{
}

Welcome to Arduino SE! Can you please add more information to your post? We can't help you much here. What have you tried? Has anything changed?

Try using one of the SD library examples unchanged (at least beyond making sure chip select, etc are correct) to verify the hardware before you modify it in other ways.

First, are you running the board off of USB power from your computer? If so, can you open the serial monitor to see if things are running correctly? If you aren't, the SD card can be picky if your board is running on battery, if the power drops, your SD card can no longer be written or read from.

Seems that last time I had this issue, simply replacing the battery on my datalogger board fixed the issue

Thank you all...
I found solution for my problem.
The circuit and the sketch isn't any problem. But I saw this and I think problem is because of LC Studio's SD card. In previous circuit I connect 5v pin of SD card to 5v pin on arduino. But now I disconnect that and connect 3v3 pin on card to 3v3 on arduino.
Now it's work very nice. And I don't know "why?" . Any idea?

There is no "5v pin" on an SD card!!!

@ChrisStratton There is a 5v pin on my sdcard module

Then the problem would be with some circuutry on the module which you have failed to.mention

If there is no file on the card, you must first create the "test.txt" file and put it in the main directory of your SD card. Your code doesn't create a file and I don't think you can even do that with the SD library. If you want to create a file, you are going to have to use the SDfat library. Also take out this part of your code :
    file.close();
file = SD.open("test.txt",FILE_WRITE);
You are just opening, then closing, and then reopening.

Note that the poster's code isn't far from the SD library examples, so for example "Your code doesn't create a file and I don't think you can even do that with the SD library." is probably untrue.

"If the file is opened for writing, it will be created if it doesn't already exist" — documentation for SD.open


text:
Debugger for Code::Blocks + Arduino
I am not very experienced in this, but I was wondering if Code::Blocks has a way of getting a debugger that runs for Arduino chips, specifically. I understand there is Arduino IDE for but does it allow debugging specific to those microcontrollers (Amtel and such)?

This is for Mac between.

The arduino IDE does not support debugging on chip, and it will take additional hardware to do it (like a JTAG). I don't know if Code::Blocks has any support for this kind on chip debugging though.

If you are interested in on-board debugging or off-board debugging, you will need a programmer/debugger. I would recommend the Atmel AVR Dragon. Atmel AVR Dragon uses the Atmel Studio 6.2, which is a great IDE.

Answer: Code blocks does not currently have an Arduino debugger. The Arduino IDE does not have a debugger.
There is an Arduino debugger in Atmel Studio using the Visual Micro plugin.
That said, you have to use Ms Windows to use Atmel Studio which might not be available to you.
The Visual Micro debugger is simple and uses usb so does not require additional hardware but as your experience grows you might also like to progress to fully blown hardware debug using the native Atmel Studio Tools
Visual Micro debug in Atmel Studio
Atmel Studio Download

Can you suggest a hardware debugger to go with C::B?

I already answered that question so I am not sure what you are trying to achieve by asking it again. Two of us have tried to help you but you seem to want to ignore the answer?


text:
Arduino NRF24L01+ arduino to netmf transmit issue
I want to communicate between Arduino Mini Pro (china import) and a stm32f4 running netmf runtime. At the moment I'm able to communicate between SPI1 and SPI2 on the stm32 board.
After that I switched on the Arduino. I'm using the RF24 library and modified the GettingStarted sample to simply open pipes and send the same byte array again and again to the stm32.
It works for the first transmit but after that I did not receive any interrupts on the receiver side.
Both NRF24L01+ are power supplied by a breadboard power supply module which supplies 500ma (max USB bus). The Arduino is connected and power supplied by a CP2102 USB/Serial adapter.
NETMF Address: 0F0F0F0F0F
Arduino Address: 0F0F0F0F0E
As arduino uses little endian, I reverse the bytes on stm32 side before writing the address into the pipe. But I'm already unsure if I need that step (adding the Arduino address on netmf side).
Here's my Arduino code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

RF24 radio(9,10);

const int payload_size = 4;
const char payload[] = "PING";

void setup(void)
{

    Serial.begin(57600);
    printf_begin();
    radio.begin();
    radio.enableDynamicPayloads();
    radio.setChannel(77);
    radio.setAutoAck(true);
    radio.setRetries(15,15);
    radio.setDataRate(RF24_2MBPS);
    radio.openWritingPipe((uint64_t)0x0F0F0F0F0FLL);
    radio.openReadingPipe(1,(uint64_t)0x0F0F0F0F0ELL);
    radio.stopListening();
    radio.printDetails();
}

void loop(void)
{
    unsigned long time = millis();
    bool ok = radio.write( payload, payload_size );

    if (ok)
        printf("SUCCESS %lu...\n",time);
    else
        printf("fail %lu...\n",time);

    // Try again 1s later
    delay(1000);

}

Here's my NETmf code
NRF24L01Plus _module = new NRF24L01Plus();

public override void Init()
{
    _module.Initialize(SPI_Devices.SPI2, Pins.GPIO_PIN_D_8, Pins.GPIO_PIN_D_10, Pins.GPIO_PIN_B_12);
    _module.Configure(new byte[] { 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }, 77, NRFDataRate.DR2Mbps);

    // both handlers are never executed
    _module.OnDataReceived += this.OnReceive;
    _module.OnInterrupt += _module2_OnInterrupt;

    _module.Enable();

}

Need to see your code. From my experience with RF24 library GettingStarted example, is its not asynchronous. Meaning, one must be listening and the other should be sending.

I've added the code sample

I am not familiar with the NRF24L01Plus library or NETmf. Does NETmf support c? I think the RF24 Library needs to be on both devices. I am not 100% sure.

I have a couple of projects that use the NRF24L01+ and the RF24 Library.
As I mentioned in my comment, the examples provided is not asynchronous. I am not sure if the library supports asynchronous operations. Nevertheless, in your example, one radio should be in transmit mode and the other receive. If you look at the examples, the author uses modes (role_ping_out and role_ping_back). Basicly, the author wrote the code so you can both send and receive. But you can't do send and receive at the same time.
If you look at the example cope in the library, you can see where you need to stop receiving and start sending:
radio.stopListening();

// Send the final one back.
printf("Sent response.\n\r");
radio.write( &got_time, sizeof(unsigned long) );

// Now, resume listening so we catch the next packets.
radio.startListening();

And on the other radio stop sending and start receiving:
radio.startListening();

// Wait here until we get a response, or timeout (250ms)
unsigned long started_waiting_at = __millis();
bool timeout = false;
while ( ! radio.available() && ! timeout ) {
__msleep(30); //add a small delay to let radio.available to check payload
  if (__millis() - started_waiting_at > 200 )
    timeout = true;
}

// Describe the results
if ( timeout )
{
  printf("Failed, response timed out.\n\r");
}
else
{
  // Grab the response, compare, and send to debugging spew
  unsigned long got_time;
  radio.read( &got_time, sizeof(unsigned long) );

  // Spew it
  printf("Got response %lu, round-trip delay: %lu\n\r",got_time,__millis()-got_time);
}

If this is a bit confusing, I would suggest you load the Getting Started example on both your radios. Once you get that working, you can get a better idea on how it works.
Good Luck

Thanks for your answer. As I mentioned, the first transmit works. On STM32 side (NET Micro Framework) the interrupthandler gets raised and I receive the data I sent from Arduino. But after the first receive the interrupthandler never gets called again.

Hard to tell because you only posted half your code. Where the code on the receiver side?

I've added the netmf code

Keep in mind that in most cases you just need to send back Ack for feedback. The library automatically does that, so don't build your own Ack protocol.


text:
How to use output from Arduino in C++ code?
I am a complete novice in Arduino and moderately experienced with the language C++. What if I want to use the output from the serial monitor in C++ code in real time?
Also how can I write to the serial monitor. Which libraries are available for this? Also please give me links to sites where I can learn more about this topic. I am using Arduino Uno.

Which Operating System are you using?

@PeterR.Bloomfield Windows 7 32 bit

This question appears to be off-topic because it is mainly about C++, not Arduino.

@TheGuywithTheHat - unfortunately on any other SO site the question would likely be instantly flushed here without a read for merely mentioning "Arduino".  I would agree that the question pertains to embedded systems in general, but the poster may not know that - part of what answers may need to do is explain what the Arduino Serial Monitor is doing and that the solution is likely not to claim data from that, but rather get data from the same source it does.

@ChrisStratton I would love to learn more about what you are saying. The problem with the internet is there it's too much information and funding something useful is difficult unless you know what you ate looking for... So if you can suggest things I can read to increase my knowledge about arduino or embedded systems in general please do so. Also I would like to learn more about the hardware side of things (For instance what it means to connect a device serially to the computer) and a little more about how it works. Please suggest good sources if possible.

Also please keep in mind my knowledge about arduino or embedded systems in general is practically null. All I have done so far is tweaked the example codes.

Check the modified code in my answer

Unfortunately, C++ doesn't have native support for serial I/O.
You could use the Windows API directly if you're feeling adventurous. It can be a little complicated to get to grips with, but not insurmountable. You can get basic information about it here. There's an example of using it with Arduino here.
As an alternative, you could use a 3rd party library. This one looks good, although I haven't actually used it myself.

#include <windows.h>
#include <string>
#include <stdio.h>
#define ARDUINO_WAIT_TIME 2000
using namespace std;

string portNumber;
HANDLE hSerial;
bool connected;
COMSTAT status;

bool connectPrinter(char *portName){

    //Connects to the port.
    hSerial = CreateFileA(portName,
    GENERIC_READ | GENERIC_WRITE,
    0,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL);

    if(hSerial==INVALID_HANDLE_VALUE)
    {
        if(GetLastError()==ERROR_FILE_NOT_FOUND){
            printf("ERROR: Handle was not attached. Reason: %s not available.\n", portName);
            return false;
        }
        else
        {
            //If port is in use by another program or did not closed previous process.
            printf("ERROR!!! \n");
            CloseHandle(hSerial);
            return false;
        }
    }
    else
    {

        DCB dcbSerialParams = {0};

        if (!GetCommState(hSerial, &dcbSerialParams))
        {
            printf("failed to get current serial parameters!");
            return false;
        }
        else
        {
            // Set Serial Port specifications.
            dcbSerialParams.BaudRate=CBR_115200;
            dcbSerialParams.ByteSize=8;
            dcbSerialParams.StopBits=ONESTOPBIT;
            dcbSerialParams.Parity=NOPARITY;

             if(!SetCommState(hSerial, &dcbSerialParams))
             {
                printf("ALERT: Could not set Serial Port parameters");
                return false;
             }
             else
             {
                 connected = true;
                 printf("Connection Successful for :%s !!! \n" ,portName);
                 //Wait 2s as the arduino board will be reseting
                 return true;
                 Sleep(ARDUINO_WAIT_TIME);
             }
        }
    }

}

int readData(char *buffer,unsigned int nbChar){

    DWORD bytesRead;
    DWORD dwCommModemStatus;

        //Set the type of data to be caught.(RXCHAR -> Data available on RX pin.)
        SetCommMask (hSerial, EV_RXCHAR );

        while (hSerial != INVALID_HANDLE_VALUE)
        {
          // Wait for an event to occur for the port.
          WaitCommEvent (hSerial, &dwCommModemStatus, 0);

          if (dwCommModemStatus & EV_RXCHAR )
          {
                //unsigned int toRead;
                //ClearCommError(this->hSerial, &this->errors, &this->status);
                do
                {
                  // Read the data from the serial port.
                    ReadFile (hSerial, buffer, 1, &bytesRead, 0);
                  // Display the data read.
                      printf ("%s" ,buffer);

                } while (bytesRead > 0);
          }
        }
    //}
    //If nothing has been read, or that an error was detected return -1
    return -1;
}

    int main()
    {

        char* buffer = new char[32768];
        int nbChar= 32768;
        string str="COMx"; // Use your port number to connect

        char * writable = new char[str.size() + 1];
        std::copy(str.begin(), str.end(), writable);
        writable[str.size()] = '\0';

        connectPrinter(writable);
        delete []writable;
        readData(buffer,nbChar);
        return 0;
    }

try this one, it should work. Comment below if it does not work. You might reset Arduino to read data in method void setup() in Arduino code. I recommend you to use C#, Java or Python for efficiency.

What about writing data... Also please upload arduino sketch if possible! Your answer is really good , sorry i cant upvote as it requires 15 rep!

@Peter has already posted library links.
I recommend that you use Node.js (node-serialport) or Python (serial), which have excellent native serial support.
Both of these use C++ internally to communicate over Serial (Serial.h).
Try going through the code Node.js uses internally, and if you are willing to write that much, by all means use the library.


text:
Extract .hex from ATtiny45 using Arduino
As it is possible to program a ATtiny45 using Arduino as ISP Programmer, is there a way to backup an ATtiny45 program to a .hex file using Arduino?

You'll have to use the commandline for that. Inside the arduino program folder there is another executable called avrdude. You need to call something like avrdude -pattiny45 -cstk500v1 -Uflash:r:filename.hex:i

Assuming the lock bits on the device haven't been set, sure. Simply prepare the Arduino for ArduinoISP, hook up the ATtiny45, and perform a read using AVRDUDE instead of a write (-U flash:r:foo.hex:i).

Sorry, totally missed your mention of that.


text:
Using IMU for a small Arduino and bluetooth support
I'm gonna start a project with an IMU with a bluetooth support inside a small board (mini or lillypad) and send datas to the mobile phone. But I'm quite new to those kind of technologies.
I'm going to choose a module for handling both operate voltage restriction and memory capacity for both library (IMU and bluetooth).
Any advice obj which arduino / IMU breakout / bluetooth module / battery to use? Or some similar projects?

A tiny quadcopter board will have the intertial sensors and you can add a bluetooth module.  Or you can use an arduino-with-bluetooth type board and add an intertial module.  Beware that cheap micromachined IMUs (or for that matter just about any you can buy) aren't very good - they are fine for detecting or damping acceleration and rotation, but not for integrating to determine position or even velocity.

can you advice one or two good breakout board?

If you're new to Arduino I'd suggest avoiding the Mini and the BULLSH-fun that external programmers bring.
Something like the Pro Micro is much easier, almost as small, and less likely to bite.
Often the best way to pick hardware is to look for a tutorial (like This one) before deciding what to buy. While I personally haven't used IMUs it looks like the "6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345" from SparkFun would be (relatively) easy to use.
I've used the RN-41/2 Bluetooth modems (the same as are found in BlueSMiRF modules) and usually gotten on OK with them. There are plenty of tutorials available with a bit of Googleing.
Adafruit do a good line of Lipo batteries and chargers. They also have wireless charging modules if you're looking for extra brag-factor.
Hope this helps.


text:
Use Arduino Mega to program Arduino Duemilanove
I hava an Arduino Duemilanove but I think that its FTDI chip is crashed.
I have an Arduino Mega too, so can I use it to program my Duemilanove?

Yes, this is not an uncommon activity.  This is called using an Arduino as an In-System Programmer (ISP)
This page has the information and Arduino program you need.  You'll need to adjust for the Arduino Mega pin differences, but that's fairly easy.
http://arduino.cc/en/Tutorial/ArduinoISP
Where the ArduinoISP page references pin 13, on the Mega it's pin 52.
Where the ArduinoISP page references pin 12, on the Mega it's pin 50.
Where the ArduinoISP page references pin 11, on the Mega it's pin 51.
Where the ArduinoISP page references pin 10, on the Mega it's pin 53.
Otherwise you should be able to connect the Mega to the patient in the same way as described, load the ArduinoISP sketch into the Mega, preferably from the GitHub repository linked in the article (https://github.com/rsbohn/arduinoisp).