# Question
Title: Arduino Motor Shield and Adafruit CC3000 WiFi Shield Compatibility
My question is similar to this one: Motor shield and wireless transceiver compete for same pins But not exactly the same!

I would like to know if the solution is as practical, though.

I have an Arduino Mega 2560 R3, with an Arduino Motor shield plugged into it. Now I want to use the Adafruit CC3000 WiFi shield. It plugs in fine, but when reading the specifications, it wants to use pins 13, 12, 11 which are also used by the Motor shield. I also want to use pin 10 as a servo is plugged into it. This is all on a robot so I don't have space to wire the shield separately through a breadboard or similar.

It should perhaps also be noted that I have the motor shield on top of the wifi shield so that the wifi shield can use the ICSP ports which the motor shield doesn't have, therefore any redirecting of pins on the CC3000 will mean that the motor shield pins will also be affected unless I redirect them too, and at that point I feel like it would be all a bit of a mess.

The solution to the other question was indeed to redirect the relevant pins to other free pins on the micro-controller board. However, I noticed that the Adafruit shield has a second row of connector holes next to the main pin holes. In the shield documentation I found, I didn't find any specific reference to these parts and in what situations they could be used, but maybe this is one of them.

My concern with using these is that (as you can see in the second image below, ignoring the coin!), the ports are wired together in the board. Does this mean that it won't make any difference which I use; if I connect a second row of pins/connectors to these points will it simply transmit the same data down both sides? I don't know enough about how electronics work at that level to understand the consequences.

So really my question is: can I use the outside row of ports for my motor shield and the inside row for the wifi shield?

**EDIT:**

So I've spent until now on the Adafruit forums trying to get some help with this and I still am not all the way there... maybe at this point someone here can cast fresh eyes over my problem.

The Adafruit CC3000 uses both the dedicated ICSP pins and pins 3, 11-13 to transmit the same data. The reason for this is to do with compatibility between different Arduino boards and their versions. E.g. apparently the Uno uses those pins whilst the mega uses some of the pins in the 50s range. I'm not sure what to make of this as the Uno and most of the boards seem to have the ICSP pins, so if they're not used for this purpose then what's the point of connecting to them? Anyway.

As it was explained to me, even if the board can use the ICSP pins to communicate with the microcontroller, it is still sending data via the other pins. So the main pins are essentially useless at this point. To make them useful again, the idea is that you sever the wires that are sending the data through them (often referred to as trace wires). This means that only the ISCP ones will be active for what they are needed, and the main pins will be free for other uses. This is what I ended up doing to my board for pins 11-13, and then for pin 3 I cut the trace wire and wired up the connection to pin 2 as these can both be used for an IRQ (interrupt request) on the Mega and I need pin 3 for the motor shield. The lighting on these pictures isn't the best, but you can see what I've done (the lower part of the second image shows where I made the cuts and the top image shows the wire connection):

After doing that I have been testing the shield connected to both my Mega and my Uno and they both produce the same results. This is using the Adafruit-created library called `Adafruit_CC3000_Library`. It starts the initialisation, then whilst it's trying to run the code it gets stuck. I traced the problem to a while(1) loop of which you can only exit by meeting a condition which is never met in my case: `if (*pucReceivedData == HCI_TYPE_EVNT)`. This may be because `pucReceivedData` is not initialised properly, but I don't know why and whether it has to do with my modifications. This happens in the `hci_event_handler` method of `evnt_handler.cpp`. This is through the main file and `wlan.cpp` so I won't write it here as it is simple enough to follow.

It should also be noted that this shield doesn't work properly with the later versions of the arduino IDE (1.5+) so I had to reinstall 1.0.6. To be honest, I got the same problem on both versions so who knows.

I realise that this is a very specific problem, but I figure that this may leave someone with a lot fewer issues in the future. If anyone has any bright ideas, even if just for testing then I would be grateful.

# Answer
It works!

First I'll say thanks to the moderators/support staff from Adafruit. One dude in particular has tried to help me constantly for the past couple of days or so.

So, following on from my edit, Adafruit told me that the ICSP pins are connected to the control part of the board via the main pins. I should have seen it actually, but I obviously didn't examine and understand it properly. This means that although I severed the connection between the main pins and the centre, the ICSP and 11,12,13 were still connected together. What I actually needed was for the ICSP pins to be connected to the controls to receive the data, and the main pins to be detached from them. So I de-soldered the solder jumpers that I had originally put on the connector plates on the underside of the board (which connect the ISCPs to the main pins), then soldered wire from the ICSP side to the associated breakout holes which are the ones on the inside of the cuts that I made on the board. Here is a picture:

If anyone tries to do this, beware of where you are wiring to! I was very careful to make sure I matched the connecting wires to the correct pins. I have tested it several times (using the example test file that comes with the library) and it works as it should. It works on my Uno R3 and my Mega 2560 R3, which is great, as now pins 11-13 are free to use for my motor shield, or potentially any other shield which may need those pins.

I hope this helps someone else in the future. There doesn't seem to be any information on this particular combination of shields, but as these projects are becoming more popular this may prove to be useful.
> 0 votes

---
Tags: shields, wifi, arduino-motor-shield, adafruit
---


# Question
Title: What's the simplest way to get arduino functionality?
I want to control a servo with the least amount of components. But generally, what is the simplest way to do this without actually using a fullblown arduino board?

# Answer
If you what you're looking for is the cheapest option with the fewer components possible, then you can use a regular ATMega328p chip, with a few passive components attached to it.

You just need to program it with an Arduino Bootloader once, in order to be able to program it easily, but you can use any existing Arduino to do that. After doing this once, you can program it with any FTDI-type USB to Serial converter.

Here's an Instructable that explains the whole process.
> 2 votes

# Answer
Please, take a look at this guide by Nick Gammon, which explains in detail how to build a breadboard Arduino.

You'll need also an Arduino board without the chip (a good UNO will do the job) because you need to program it some way. It is needed absolutely in the case that you buy an ATMEGA328 that hasn't the bootloader, as you'll have to write it on the blank chip.

To speak directly via serial with the standalone Arduino (and to program it), I suggest you to buy a FT232RL board (just be careful to buy a real one, as there are fakes that FTDI blocked and bricked with drivers)

Then, for the servo you just have to plug it correctly: two cables for power, one for the control.
> 0 votes

# Answer
This is useful if you don't need all the I/O of the Atmega.

If you want a simple board just to run a servo or two and still have some I/O you could use a ATTiny85 chip and use this software servo library that works with the attiny. It also works best with the High-Low tech cores.

I used this with a project and it works flawlessly without stalling.

This would give you small setup as you can use the internal clock 8MHz and minimal external components, i.e. regulator and Capacitors.
> 0 votes

---
Tags: atmega328
---


title: Switching a dual h bridge in parallel

text:
# Question
Title: Switching a dual h bridge in parallel
I'm using a dual h bridge to control two dc motors on an inverted pendulum (cart-pole system). At the moment, I have to send two different pulse width modulated signals to the two enable pins to control the two motor speeds and four digital write commands to control the directions.

Ideally, I want to switch the two motors simultaneously in the same direction and with the same speed. So, I'd like to be able to control both motors' speeds with only one pulse width modulation signal and control both motor directions with only two digital write commands.

Is there a way I can do with with Arduino? Can one PWM signal from a single arduino pin be sent to two enable pins at the same time? Can the same be done for a single digital output pin? If so, how can I accomplish this?

# Answer
You can connect a single output to as many input loads as you like, provided the current is sufficient to hold the output voltage within the input thresholds. See the datasheet for the H bridge to find out what the input load and thresholds are, and compare them with the output from the Arduino.
> 2 votes

---
Tags: arduino-uno, motor, pwm, digital, h-bridge
---


title: Don't pee there! Device

text:
# Question
Title: Don't pee there! Device
I want to make a device with a sensor I can attach to the places my dog likes to mark. When sensor becomes wet I want a buzzer to make a loud noise to scare the animal and notify me I need to encourage the dog to go outside. Any suggestions on what sensor to use.

# Answer
You probably will want a moisture sensor like this one (there are many variations of this).

This will return one signal when dry, and another when wet.

You will need a Buzzer to make a sound as well (Or a piezo speaker if you feel like getting more advanced) in order to make a sound.

Your sketch should have, in its `loop`, an `if` statement checking if the moisture sensor has returned the wet signal (The signal will depend on the sensor you get) and, in the block that executes if there is a signal, a statement driving the buzzer and a delay before turning it off.

Bear in mind that you want to keep the Arduino itself away from the moisture sensor, as your Arduino probably won't survive the dog's doings.
> 2 votes

---
Tags: arduino-uno, sensors, hardware
---


title: pcDuino 3B Wire library errors

text:
# Question
Title: pcDuino 3B Wire library errors
I recently purchased a pcDuino 3B and I am very pleased with the Board so far. I can use the preinstalled arduino IDE to program the board from the board and run programs.

However, when I came to use I2C, it generated a load of errors with the built-in libraries when I tried to compile. I don't know why it did this, it does it when trying to compile any program using I2C. Here is the error list (Yes, I am using an Adafruit display library that works fine with exactly the same sketch on my laptop):

```
In file included from /usr/share/arduino/hardware/arduino/pcduino/cores/arduino/Stream.h:26:0,
                 from /usr/share/arduino/hardware/arduino/pcduino/libraries/Wire/Wire.h:9,
                 from Stopwatch_new.ino:1:
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/Print.h:47:23: error: ‘byte’ has not been declared
In file included from Stopwatch_new.ino:1:0:
/usr/share/arduino/hardware/arduino/pcduino/libraries/Wire/Wire.h:41:23: error: ‘byte’ has not been declared
Stopwatch_new.ino:5:51: error: cannot allocate an object of abstract type ‘Adafruit_RGBLCDShield’
/home/ubuntu/Arduino/libraries/AdafruitLCD/Adafruit_RGBLCDShield.h:68:7: note:   because the following virtual functions are pure within ‘Adafruit_RGBLCDShield’:
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/Print.h:47:17: note:  virtual int Print::write(int)
Stopwatch_new.ino:5:23: error: cannot declare variable ‘lcd’ to be of abstract type ‘Adafruit_RGBLCDShield’
/home/ubuntu/Arduino/libraries/AdafruitLCD/Adafruit_RGBLCDShield.h:68:7: note:   since type ‘Adafruit_RGBLCDShield’ has pure virtual functions
Stopwatch_new.ino: In function ‘void updateScreen()’:
Stopwatch_new.ino:125:27: error: call of overloaded ‘String(float&, int)’ is ambiguous
Stopwatch_new.ino:125:27: note: candidates are:
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/WString.h:44:14: note: String::String(unsigned int, unsigned char)
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/WString.h:43:14: note: String::String(int, unsigned char)
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/WString.h:42:14: note: String::String(unsigned char, unsigned char)

```

It seems that no one else is having this issue.

Just to clarify, the issue is not with my code or the library, it compiles fine on my other computer running WINDOWS but same Arduino version (1.5.3), same sketch code and same library code.

Help much appreciated, thanks!

# Answer
It turns out that the libraries for compiling were incomplete. Having copied the libraries for the official IDE, it worked fine.
> 1 votes

---
Tags: i2c, library, wire-library
---


# Question
Title: Can Ultimate GPS module use arduino micro instead of UNO?
i am doing a Ultimate GPS module like this:

it works when i use arduino UNO board, but when I use arduino micro board it doesn't work, so could anyone tell me how to fix it?.By the way I use the example code in GPS library.

UNO: the data looks like messy code

Micro: didn't give me any time, date or fix

# Answer
Your photo shows the GPS connected to pins 0 and 1 (RX and TX) on the UNO. But you don't show the sketch you are running. Do you have it set that way in the sketch?

It turns out the micro and UNO are different in the way those pins work. From http://arduino.cc/en/Main/arduinoBoardMicro

> Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data using the ATmega32U4 hardware serial capability. Note that on the Micro, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class.

This suggests to me that you'd need to change the code to read pins 0 and 1.

Easier is probably to wire it up to pins 2 and 3 and use the defaults in the sketch

```
// If using software serial, keep this line enabled
// (you can change the pin numbers to match your wiring):
SoftwareSerial mySerial(3, 2);

```
> 1 votes

# Answer
The Arduino Uno and Micro, in practice, work almost exactly the same. Just make sure that your wiring is correct (In this photo, the wires go from TX to TX and RX to RX, they should go between TX on one board and RX on the other, and vice versa.

Your code should work on a micro exactly as it does on an Uno. That is one of the best features of Arduino; the ability to port code to another board without much (if any) modification.
> 0 votes

---
Tags: arduino-uno, arduino-micro, gps
---


title: Send \r or \n via phone serial monitor

text:
# Question
Title: Send \r or \n via phone serial monitor
I have a bluetooth adapter connected to uno, and using a serial monitor on phone.

In the arduino code im debugging there is this line waiting for new line signal in the serial stream:

```
char c = SerialBT.read();

if (c == '\r' || c == '\n'){

```

no matter what i try sending to via my phone i cant get this to evaluate as true...

if i send \n , i believe it is sending it as 2 chars \ and n , not as a single char.

is this a problem with the phone app or what ?

# Answer
It turns out it was a problem with the android terminal program i was using, by switching to another that specifically has support and options for \n \r things it works now.
> 1 votes

---
Tags: serial, bluetooth
---


title: Adding a steering servo

text:
# Question
Title: Adding a steering servo
I got a Sparkfun Redbot Kit a while back. I ended up building it vanilla and it was a good introduction to the board (the board is basically Uno and a motor shield in one) and the toys that came with it. I figured if could scavenge an RC car, I'd get a more robust redbot. I found an old RC Rock Crawler, it has a basic suspension, two motors, and a steering servo.
Unfortunately, I encountered a problem. The steering servo only has two wires. I loaded the *Servo* -\> *Sweep* example that is default in the Arduino IDE to see if I could make it work regardless. I tried all the different all the different wire/header combinations on the servo headers:

1. When I attach the wires to gnd and # I get a buzzing noise.
2. When I attach the wires to gnd and pow the servo turns left or, if I swap the wires, it turns right.
3. When I attach the wires to pow and # nothing happens.

I currently can't take advantage of the servo headers on the board (or at least I don't know how to). I was hoping that I could that there might be a work around, I just don't know what it is.
The obvious answer is that I could run both motors off of only one of the headers and use the other to control the steering (thats how the original board from the car was wired), but I can get a faster car if each motor has its own header, and I'm all about the vroom vroom...

I'm running the whole thing off the default 6v (4 AA) battery pack. I might be able to wire in the extra 2 AA's for the extra 3v but I don't want mess with the wiring on the pack unless I know it's going to work.

I have an accelerometer connected to the A4 A5 header block and the motors connected too (I checked w/o them connected but there was no difference).

*Image courtesy of https://learn.sparkfun.com/tutorials/getting-started-with-the-redbot*
More info on the redbot board https://www.sparkfun.com/products/12097

# Answer
If the motor you are using has only two wires, and as you described it's response to the direct connection to the power, it can't be a servo. The motor is a normal dc motor. If you want to control the amount of the turns on your rc car you should try to play with the pwm signal, I don't know if it will work or not but at least you will have tried. And remember not to connect the motor directly on the micro's pin if there no motor pins on your red board.
> 0 votes

---
Tags: arduino-uno, motor, pins, servo, wires
---


title: How to use an 8x8 LED Matrix?

text:
# Question
Title: How to use an 8x8 LED Matrix?
I have a LED Matrix just like this one

but couldn't find the data sheet for it (1855AS) I asked around in my country and one guy told me to try attaching one side to 5v and the other to GND. Some LEDs worked fine and others didn't light up at all. In the end one if not more got burned.

So I'm here asking if anyone can tell me a way to figure out how it works. I would appreciate the help!

# Answer
As you are testing the correct functionality of LEDs on matrix board, which means the LEDs are multiplexed together. The fastest way to check the pinout is to use a multimeter in continuity test mode and then connect the positive or signal wire ( the red one ) to an fixed pin (usually start with one ) and the with negative or gnd wire ( the black one ) connect it one by one to the all the remaining pins. When you have finished move the signal wire to the next pin and rescan all the pins, repeat all the steps for every pins on the matrix board. I don't recommend you to use directly 5v because it can be dangerous and you can damage the LEDs of the matrix display as there isn't a current limiting resistor.
> 1 votes

# Answer
You could check from where you have bought it. Maybe they have datasheet. I found one similar, but before you must check if everything is the same and then do testing with power. LuckyLight
> 1 votes

---
Tags: arduino-uno, led
---


# Question
Title: difference between output pin high and 5v pin
So this might be a total noob question (which admittedly I am) I have a Motor, if I connect it to GND and the 5V output it runs. Ok so far. But if I connect it to GND and a pin set to OUTPUT and HIGH nothing happens. My multimeter reads 5V for both setups, so if 5V come to the motor one way or the other why does one work and one not?

# Answer
That's probably caused by the motor's current consumption. The 5V pin can deliver much more current than the output pin in high state. If you want to switch the motor on/off by software, you need a "hardware driver" for the motor, in the simplest case a power transistor.
> 1 votes

---
Tags: motor, voltage-level, electricity
---


# Question
Title: interrupt and/or other ressources used by Time functions micros() and delayMicroseconds()
I want to use Arduino Uno (Rev. 3) resp. Arduino Nano for time critical ignition control of a combustion engine. Software is developed under arduino rev. 1.6.2.

The only Arduino system functions i use are micros() and delayMicroseconds(). I suppose they are implemented by a timer interrupt, which may fire within time critical port polling regions of the program.

What's the maximum runtime for the ISR i have to expect? As long it stays within the range of a few microseconds, say 10 or like, it would be tolerable.

Are there other time ressources used in the background by the arduino system i have to cope with?

# Answer
> 1 votes
Here is the The ISR code.

Here is the obj-dump:

```
000008f6 <__vector_16>:
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ISR(TIM0_OVF_vect)
#else
ISR(TIMER0_OVF_vect)
#endif
{
 8f6:   1f 92           push    r1
 8f8:   0f 92           push    r0
 8fa:   0f b6           in  r0, 0x3f    ; 63
 8fc:   0f 92           push    r0
 8fe:   11 24           eor r1, r1
 900:   2f 93           push    r18
 902:   3f 93           push    r19
 904:   8f 93           push    r24
 906:   9f 93           push    r25
 908:   af 93           push    r26
 90a:   bf 93           push    r27
    // copy these to local variables so they can be stored in registers
    // (volatile variables must be read from memory on every access)
    unsigned long m = timer0_millis;
 90c:   80 91 a0 01     lds r24, 0x01A0
 910:   90 91 a1 01     lds r25, 0x01A1
 914:   a0 91 a2 01     lds r26, 0x01A2
 918:   b0 91 a3 01     lds r27, 0x01A3
    unsigned char f = timer0_fract;
 91c:   30 91 9f 01     lds r19, 0x019F

    m += MILLIS_INC;
    f += FRACT_INC;
 920:   20 e3           ldi r18, 0x30   ; 48
 922:   23 0f           add r18, r19
    if (f >= FRACT_MAX) {
 924:   2d 37           cpi r18, 0x7D   ; 125
 926:   20 f4           brcc    .+8         ; 0x930 <__stack+0x31>
    // copy these to local variables so they can be stored in registers
    // (volatile variables must be read from memory on every access)
    unsigned long m = timer0_millis;
    unsigned char f = timer0_fract;

    m += MILLIS_INC;
 928:   40 96           adiw    r24, 0x10   ; 16
 92a:   a1 1d           adc r26, r1
 92c:   b1 1d           adc r27, r1
 92e:   05 c0           rjmp    .+10        ; 0x93a <__stack+0x3b>
    f += FRACT_INC;
    if (f >= FRACT_MAX) {
        f -= FRACT_MAX;
 930:   23 eb           ldi r18, 0xB3   ; 179
 932:   23 0f           add r18, r19
        m += 1;
 934:   41 96           adiw    r24, 0x11   ; 17
 936:   a1 1d           adc r26, r1
 938:   b1 1d           adc r27, r1
    }

    timer0_fract = f;
 93a:   20 93 9f 01     sts 0x019F, r18
    timer0_millis = m;
 93e:   80 93 a0 01     sts 0x01A0, r24
 942:   90 93 a1 01     sts 0x01A1, r25
 946:   a0 93 a2 01     sts 0x01A2, r26
 94a:   b0 93 a3 01     sts 0x01A3, r27
    timer0_overflow_count++;
 94e:   80 91 a4 01     lds r24, 0x01A4
 952:   90 91 a5 01     lds r25, 0x01A5
 956:   a0 91 a6 01     lds r26, 0x01A6
 95a:   b0 91 a7 01     lds r27, 0x01A7
 95e:   01 96           adiw    r24, 0x01   ; 1
 960:   a1 1d           adc r26, r1
 962:   b1 1d           adc r27, r1
 964:   80 93 a4 01     sts 0x01A4, r24
 968:   90 93 a5 01     sts 0x01A5, r25
 96c:   a0 93 a6 01     sts 0x01A6, r26
 970:   b0 93 a7 01     sts 0x01A7, r27
}
 974:   bf 91           pop r27
 976:   af 91           pop r26
 978:   9f 91           pop r25
 97a:   8f 91           pop r24
 97c:   3f 91           pop r19
 97e:   2f 91           pop r18
 980:   0f 90           pop r0
 982:   0f be           out 0x3f, r0    ; 63
 984:   0f 90           pop r0
 986:   1f 90           pop r1
 988:   18 95           reti

```

I'll let you calculate how many clock cycles that is. My guess is that it's less that 160 clock cycles (i.e. 10S).

But I'm unsure if the accuracy of `micros` is good enough in your application.

---
Tags: interrupt, arduino-nano, timers, time, core-libraries
---


title: IR trouble with raw buffer

text:
# Question
Title: IR trouble with raw buffer
I am attempting to send a RAW IR code using the IRremote.h library. The process for capturing IR pulses is easy to find on the web, but the process for sending them again is not. After a few days, i pieced the following code together:

```
#include <IRremote.h>
 IRsend irsend;

void setup() {

}

void loop() {

  int IRsignal[] = {

// ON, OFF (in 10's of microseconds)

    90, 86,

    174, 88,

    86, 88,

    86, 88,

    86, 88,

    86, 88,

    86, 88,

    86, 88,

    86, 174,

    88, 86,

    174, 88,

    86, 2340,

    88, 86,

    174, 88,

    86, 88,

    86, 88,

    86, 88,

    86, 88,

    86, 88,

    86, 88,

    86, 174,

    88, 86,

    174, 88,

    86, 0};

      irsend.sendRaw(IRsignal, 10, 38);

      delay(1000);

}

```

When I run it, i get the following error:

> ir\_test.ino: In function 'void loop()': ir\_test.ino:65:38: error: invalid conversion from 'int\*' to 'unsigned int\*' \[-fpermissive\] In file included from ir\_test.ino:3:0: /Applications/Arduino.app/Contents/Resources/Java/libraries/RobotIRremote/src/IRremote.h:143:8: error: initializing argument 1 of 'void IRsend::sendRaw(unsigned int\*, int, int)' \[-fpermissive\] void sendRaw(unsigned int buf\[\], int len, int hz); ^ Error compiling.

I am not sure what I did wrong, or how to convert the data types. Any tips or ideas?

# Answer
Use `unsigned int IRsignal[]` instead.

Also, your array is 48 items long, not 10. So `irsend.sendRaw(IRsignal, 48, 38);`
> 2 votes

---
Tags: ir, data-type
---


# Question
Title: Problem with declaring 2D vector in Arduino
I have included the STL library in Arduino and i can run a program with 1D vector. But i am getting error while declaring a 2D vector.

```
#include <StandardCplusplus.h>
#include <serstream>
#include<vector>
#include<iterator>

using namespace std;

vector <vector<int> > grid;
vector<int> col(5,3);
grid.push_back(col);

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

void loop()
{
  for(int i = 0; i < 5; i++)
  {
    Serial.println(grid[[0][i]);
  }
}

```

And the error is

```
'grid' does not name a type.

```

Do i need to add another header file?

# Answer
> 4 votes
The error is coming from

```
 grid.push_back(col);

```

You cannot have this line at the top-most level outside a function / main. Move it inside `setup` or `loop`.

---
Tags: c++
---


title: Home-made Arduino not receiving data

text:
# Question
Title: Home-made Arduino not receiving data
Me and my friend recently built a Breadboard Arduino. It switches on fine, and the LED changes a bit. I have added a 5V FTDI cable, but it wouldn't upload, trying to fix this, I used my friends 5V FTDI Basic USB-To-Serial converter chip, thinking this would upload fine, as it was new, but it still wouldn't upload, giving the very long error:

```
Arduino: 1.5.8 (Windows XP), Board: "Arduino Duemilanove or Diecimila, ATmega328"

Build options changed, rebuilding all

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\sketch_jan31a.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\sketch_jan31a.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\hooks.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\hooks.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\WInterrupts.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WInterrupts.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_analog.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_analog.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_digital.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_digital.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_pulse.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_pulse.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_shift.c -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_shift.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\abi.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\abi.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\CDC.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\CDC.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial0.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial0.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial1.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial1.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial2.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial2.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial3.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial3.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HID.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HID.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\IPAddress.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\IPAddress.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\main.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\main.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\new.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\new.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\Print.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Print.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\Stream.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Stream.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\Tone.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Tone.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\USBCore.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\WMath.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WMath.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=158 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\WString.cpp -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WString.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\hooks.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WInterrupts.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_analog.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_digital.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_pulse.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\wiring_shift.c.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\abi.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\CDC.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial0.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial1.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial2.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HardwareSerial3.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\HID.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\IPAddress.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\main.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\new.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Print.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Stream.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\Tone.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\USBCore.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WMath.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\WString.cpp.o

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega328p -o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.elf C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp\sketch_jan31a.cpp.o C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/core.a -LC:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp -lm

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.elf C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.eep

C:\Program Files\Arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.elf C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.hex

Sketch uses 450 bytes (1%) of program storage space. Maximum is 30,720 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables. Maximum is 2,048 bytes.

C:\Program Files\Arduino/hardware/tools/avr/bin/avrdude -CC:\Program Files\Arduino/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -PCOM8 -b57600 -D -Uflash:w:C:\DOCUME~1\George\LOCALS~1\Temp\build7021919583125132986.tmp/sketch_jan31a.cpp.hex:i

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

         System wide configuration file is "C:\Program Files\Arduino/hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : COM8
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x01
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x01

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

```

The light on the USB-To-Serial board lights once for each failed upload, but the sketch won't upload. I am trying to upload the blink sketch. The chip I am using is an Atmel AtMega328P-PU. All answers greatly appreciated.

# Answer
I would upload a blink sketch using the method Stephan suggested then plug it back into your breadboard. If it runs the blink sketch then the problem is in your programming method, but it is more likely there is something wrong in the setup. Problems could be using the wrong crystal for your setup, mis-wired or loose connection, or having your chip turned around (happens more often than you think). If it does run I would make sure that you are using all USB-to-Serial converter with all the wires used and having a resister on the reset pin.
> 1 votes

# Answer
I solved this by using an empty Uno-Board as a 'bridge' between the PC and the Bareduino (empty means with no controller chip). Just connect this guy via USB to the PC and then connect RX/TX, Ground, and Reset to your Bareduino. Just works fine for me.
> 0 votes

# Answer
The likely causes of failure are

* Wrong baud rate: you're already using 57600, the most common one.
* Rx and Tx cross connected: try connecting them the other way round.
* Wrong clock clock frequency in the chip: The tools usually assume an AtMega328 runs at 16MHz.
* Chip is not in bootloader/programming state, in the very first seconds after releasing the reset button or powering the arduino, the bootloader is listening for instructions to start reprogramming the chip via serial communication, if there is none it will continue running the program on it. Hold reset -\> Hold upload -\> Release upload -\> Release reset.

The above assumes, of course, that you have a working board. If that isn't certain, follow @Nathan's advice to plug in a chip pre-programmed with a Blinky sketch to confirm it. I use a combined Blinky and HelloWorld sketch to prove both the basic functioning and the serial I/O in one test.

A couple of these are handy to keep around, too, for proving there is power or a logic HIGH where you expect it:

```
       LED with current-limiting resistor on the cathode

```
> 0 votes

---
Tags: uploading, ftdi
---


title: Calculating time between Serial events

text:
# Question
Title: Calculating time between Serial events
I am trying to calculate time between two serial events. Using Arduino UNO R3 with 16MHz default clock source. I am using timer 1 with pre-scale of 64 to get time per one count = 4000ns. This i am choosing at random without any specific reason. Sending character 'o' to start the timer and character 'k' to stop it and hence calculate the time in between. The ISR routine calculates how much times the timer overflows. The code is:

```
    unsigned int t;
unsigned int c;
char r;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;

  TIMSK1 = (1<<TOIE1);//enable timer overflow interrupt
  sei();
  //SREG = (1<<8);//enable global inteerupt
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()>0)
  {
    r=Serial.read();
  if(r=='o')
  {
    TCNT1=0;
    TCCR1B |= (1<<CS11)|(1<<CS10);//64 pre-scale & start
    Serial.println(TCNT1);
  }
  else if(r=='k')
  {
    Serial.println(TCNT1);
    TCCR1B = 0;//stop timer
    t=TCNT1+(c*65536);
    t=t*(4*10^(-9));
    Serial.print("overflows = ");
    Serial.println(c);
    Serial.print("time = ");
    Serial.println(t);
    c=0;
    t=0;
  }
  }
}//loop

ISR(TIMER1_OVF_vect)
{
  c++;
}//isr

```

But, on serial monitor only the block of if(Serial.read()=='o').... is executing. The flow does not enter the second else if block.

What is wrong with this code? How long does the Serial buffer hold its vale ?

**EDIT:** I got the code working for checking for 'k'. But the timer value it calculates is very less than compared to what it should be. Is anything wrong with the timer settings. Setting CS10=CS11=1 gets the pre-scaler value to 64.

Hence, the time for 1 count should be = 1/(16MHz/64) .

Is anything wrong with this?

# Answer
> 0 votes
I'd read the result of `Serial.read()` to a variable and check this variable, because otherwise the first `Serial.read()` will have already read the 'k'. I reckon you can remove the `Serial.available()` check.

```
void loop() {
    int chr = Serial.read();
    if(chr=='o')
    {
        TCNT1=0;
        TCCR1B |= (1<<CS11)|(1<<CS10);//64 pre-scale & start
    }
    else if(chr=='k')
    {
        t=TCNT1;
        TCCR1B = 0;//stop timer
        t=t+(c*65536);
        c=0;
        Serial.println(t);
        t=0;
    }
}//loop

```

---
Tags: arduino-uno, serial, timers
---


# Question
Title: What is the size of the buffer in serial communication with arduino uno?
as it is in the question, i need to know what is the size of the biggest string that i can send using the serial port to the arduino.
Thank you

# Answer
That would be 64 bytes, providing the buffer is fully empty. See https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial.h#L42-L43
> 1 votes

---
Tags: serial
---


title: Using Arduino Micro With 12V Buzzer

text:
# Question
Title: Using Arduino Micro With 12V Buzzer
I have an interesting situation. I wonder if anyone can help?

I have:

* 4x Arduino Micros loaded with the basic Blink sketch
* 5x 12 volt buzzers
* A desk full of completely fresh Duracell AA and 9v batteries

If I connect (using VIN and GND) any of the Arduino Micros to either a 9v battery, or a 12v network of 8 AA batteries, then they run the blink sketch, and the appropriate LED flashes on the Arduino as expected.

If I connect any of the buzzers to either a 9v battery, or a 12v network of 8 AA batteries, then they buzz as expected.

If I connect both a buzzer and an Arduino in parallel to either a 9v battery, or a 12v network of 8 AA batteries, then the Arduino works fine, **but the buzzer makes barely an inaudible whimper**.

If I connect only a buzzer to the Arduino and battery, it works fine. If whilst the buzzer is buzzing I connect the Arduino, then on every ON or OFF of the blink sketch LED, the buzzer gets quieter and quieter until it can barely be heard.

These buzzers are rated to work at 25mA, so it really astounds me that they can't be run off a battery together with an Arduino.

Any help would be appreciated!

Thanks

Dave

# Answer
> 4 votes
Attach your voltmeter across the battery, and measure the available voltage when different things are attached; or attach it in series, and measure current draws. You probably will find that a 9V battery's voltage is under 8 volts when a mix of multiple Arduinos and buzzers is attached. That voltage may be too low to activate the buzzer.

A powerstream.com web page called *9V Alkaline tests* shows how rapidly a 9V battery's voltage drops when heavy currents (more than a few dozen milliamps) are drawn from it, and a batteriesinaflash.com web page includes the following diagram that shows battery voltage quickly falling below 8.5 V in its first minutes of life when 27 mA is drawn from it.

For some models of Arduino, eg the Uno R3, various posts on the web list currents from 25 mA up to 45 mA, depending on LED and sleep settings. Currents for the Duemilanove from 10 mA up are reported. The Arduino Micros in your tests probably use a little more current than Pro Mini boards (which have no USB), and although it's unlikely they will use as much or more current than the buzzers, they still may drag the voltage down to a level where the buzzers won't work.

If your system needs to be battery powered, consider using separate batteries for different devices, to avoid problems like you saw. Alternatively, use heavier-duty batteries, eg good-sized lithium-polymer units. Also review posts about decreasing Arduino power usage via sleep, disconnecting the power LED, and using large capacitors to buffer power surges.

*Edit:* Given that voltage measurements show enough voltage being available, the suggested use of capacitors or inductors to isolate circuits may be a good idea.

When adding a capacitor, locate it physically close to the power-using board or component. For electrolytic capacitors, attach the capacitor's + terminal to the high side, eg to the +5, +9, or +12 side, and attach its - terminal to ground.

When adding ferrite beads, wrap the supply wire through the bead several times, if there's room. The picture below illustrates the idea.

An electrolytic capacitor across a circuit acts as a voltage reservoir. It also gives high-frequency signals an easy path to ground, reducing interference. A ferrite bead or other inductor impedes high frequency signals, again reducing interference.

---
Tags: current, arduino-micro
---


# Question
Title: How to prevent file overwriting in processing?
i am working on this arduino project using processing. There are some sensor values which should be logged, but unfortunately my processing code rewrites the file after each cycle so that i get the last sensor value only. How do i prevent this from happening? I am using the ordinary method by the way. PrintWriter command followed by createWriter

# Answer
> 1 votes
`PrintWriter pw = new PrintWriter(new FileOutputStream(
 new File("persons.txt"),
 true /* append = true */));`

The `true` is the append mode flag. Also check if you're using

`pw.append(p.toString());
 pw.append("sdf");`

https://stackoverflow.com/questions/8210616/printwriter-append-method-not-appending

---
Tags: arduino-duemilanove, processing-lang
---


title: Problem importing a library in .h file

text:
# Question
Title: Problem importing a library in .h file
I have following code:

**MyApp.ino**:

```
#include "DfRobotLcdShield.h"

void setup() {
}

void loop() {
}

```

**DfRobotLcdShield.h**:

```
#include <LiquidCrystal.h>

```

When I try to compile, I'm getting the error:

```
In file included from MyApp.ino:1:0:
c:\temp\build5856181074637812172.tmp\DfRobotLcdShield.h:4:27: fatal error: LiquidCrystal.h: No such file or directory
 #include <LiquidCrystal.h>
                           ^
compilation terminated.
Error compiling.

```

When I add

```
#include <LiquidCrystal.h>

```

directly to the .ino file, it works. I'm using the latest Arduino-IDE 1.6.3.

# Answer
This seems to be a general problem of the Arduino IDE: It only recognizes libraries that are included in the (primary) `.ino` file.

If you look at the invocation of the compiler, the path to any given library is only added if this library's header file is included in the `.ino` file.

I tested this with the EEPROM library. If this library is included in the `.ino` file, the compiler is called with

```
avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/eightanaloginputs -I/usr/share/arduino/libraries/EEPROM /tmp/build2678545434708654378.tmp/test.cpp -o/tmp/build2678545434708654378.tmp/test.cpp.o

```

where the important part is the `-I/usr/share/arduino/libraries/EEPROM`.

If I now remove `#include <EEPROM.h>` (but still have it in another header file which in turn is included in the `.ino` as in your case), the compiler call changes to

```
avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/eightanaloginputs /tmp/build2678545434708654378.tmp/test.cpp -o/tmp/build2678545434708654378.tmp/test.cpp.o

```

where now the include path to the library is missing.

## TL;DR

If you need to use a library, just (also) add an include to the `.ino` file. It doesn't cost you anything and will solve your problem ;)

---

### `#include <file>` vs. `#include "file"`

From the gcc documentation:

* *#include \<file\>* is used for system header files. It searches for a file named file in a standard list of system directories. \[...\]
* *#include "file"* is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for \<file\>. \[...\]
> 4 votes

# Answer
Try `#include "LiquidCrystal.h"`

Or where is the library located? Be sure the include specifies the location.

You might have to add the library location to your environment variables.
> -1 votes

---
Tags: library, c
---


title: Convert uint8_t array to uint32_t array

text:
# Question
Title: Convert uint8_t array to uint32_t array
I have this array of bytes, that I need to convert to an array of unsigned ints. Also the function (`btea`) that needs it, seems to need a pointer.

I'm currently using `reinterpret_cast` which seems to work, but I'd like to know how/why. I'm pretty new to `C`. It also seems kind of dirty. I could use a for loop, and bitshift everything into a separate int array variable, but that seems wasteful.

```
uint8_t data[] = {1,2,3,4,5,6,7,8};//can be any multiple of 4 bytes

btea(reinterpret_cast<uint32_t*>(data), sizeof(data)/4, encryption_key);

radio.write(data, sizeof(data));

...

void btea(uint32_t *v, int n)
{
  ...
}

```

Any pointers (pun intended) are much appreciated.

# Answer
> 3 votes
@mpflaga's answer gives a great alternative, but I thought I'd explain why your code works (grossly simplified).

All the reinterpret cast does is let the compiler know how wide of a variable it assumes is in each element of the array. When you access `data[1]`, it uses one byte at an offset of one byte from `data[0]`. When you cast to uint32\_t and access `data[1]`, it uses 4 bytes at an offset of 4 bytes.

If your memory looks like this (each square is one byte)...

...before the cast you are interpreting it as the top layout, after the cast you interpret it as the bottom layout. It's still exactly the same in memory, you're just telling the compiler to use it differently. The reason that using a union is better is that it is safer. Your code would read garbage after the end of the array if its length *wasn't* divisible by 4.

One other quick note, be careful with the sizeof() operator on arrays - it always gives the length in bytes regardless of the element size.

# Answer
> 3 votes
I prefer to use unions. example:

```
union fourbyte {
  uint32_t dword;
  uint16_t word[2];
  uint8_t  byte[4];
};

union fourbyte val;

val.dword = 0x03020100;

Serial.println(val.byte[0], HEX);
Serial.println(val.byte[1], HEX);
Serial.println(val.byte[2], HEX);
Serial.println(val.byte[3], HEX);

Serial.println(val.word[0], HEX);
Serial.println(val.word[1], HEX);

Serial.println(val.dword, HEX);

```

---
Tags: atmega328, c, data-type
---


title: Day-night powered Arduino

text:
# Question
Title: Day-night powered Arduino
What should I do to have an Arduino Pro Mini 5V (clone) powered by a 5V solar panel during the day and by battery during night which will be charged during the day by the solar panels.

* is there any guide out there?
* is it possible with the 5V version of Arduino Pro Mini or will I have to buy the 3.3V
* I prefer to make the circuits by myself rather than buying them (for example: the charging circuit.)

# Answer
This would be better answered on Stack Exchange Electrical Engineering.

Also see this question and answers. This is not quite the same and the answers there are OK but less than complete or correct, but it adds to the resource available.

You need a battery charging controller, a PV (solar) panel capable of producing somewhat more than maximum battery voltage and enough energy to operate your circuit and a battery with enough voltage to operate the device and enough capacity to store the energy.

Current drain will vary with total circuit. You can measure this will a milliammeter. I'll assume that 50 mA continuous will be enough. Less or much less may suffice. I have a pro mini clone operating at 20 mA on 5V at present and with due care you may be able to operate one with less or much less current depending on application and what your circuit needs are.

Looking at solar current needs at present, the average solar current needed is about Icircuit x 24/SSH mA where SSH = average sunshine hours per day. eg if you had 4 hours of sunshine per day but want to run the circuit for 24 hours a day the sun must provide (24 hours per day)/(4 hours of sun) = 6 x as much current as the circuit needs on average. So if your circuit needs 50 mA continuous the PV panel must provide 6 x 50 mA = 300 mA for 4 hours per day. You will see below that this is not a trivial amount.

Sunshine hours per day may be found for sites worldwide using the excellent www.gaisma.com The **average sunshine hours per day for Iráklion** may be found at that link and other locations in Greece can be found **here** but will probably be similar.
For Iráklion the SSH may be found in the 1st line of the 4th chart.
Average hours/day of equivalent full sunshine = kWh/m^2/day = a peak of 8.53 hours in June and a low of 2.08 hours in December.
Wow! I think that is about as sunny a place in Summer as anywhere on earth not in the polar regions. In Winter it gets about the same SSH as in my city. You can calculate PV sizing for peak summer - but if you want year round operation you should use the worst case winter month and add a bit for bad days.
For Iraklion us say 2 SSH per day so the panels needs to provide 24/2 = 12 x winter average load. So per 10 mA of load yo need 120 mA of panel and if the mean load is 50 mA you need 12 x 50 = 300 mA panel output.

Battery voltage needs to be \> 5V at all times.
An easy cheap available starting solution is to use a 6B lead acid battery. These are easyish to charge and provide a relatively stable operating voltage.
Vmax\_charge is **about** 7V so an 8V or 9V PV panel is "about right". 9V is a common voltage for hobby applications. An alternative is to use a 12V panel. this is probably more suitable as they are widely available and cost per energy out is often lower. This wastes MOST of the panel output but still MAY be the cheapest option in many cases. (A 12V x 600 mA panel is rated at about 18V x 0.6A ~= 10 Watts. Actual Arduino load = 50 mA x 5V x 12:1 = 3 Watts)

At 50 mA load you need 24/2 x 50 mA = 600 mA PV output in full sun.
PV panel sizing is not as may be expected. It is easiest to get a panel that makes at least enough voltage and enough current. This is because panel RATED voltages are usually higher than the voltages they are used at. eg 12V system PV panels are usually rated at 18V max power voltage- so an 18W panel provide 18V at 1 A BUT if attached directly to a 12V battery the input to the battery = 12V x 1A = 12 Watts. There are ways around this but at first, just concentrate on panel mA.

So, you "need" a 600 mA panel for a 50 mA load.
Or a 60 mA panel for a 5 mA load.
Or a 6 mA panel for a 0.5 mA load.
Obviously, reducing load current is going to help panel sizing.
So knowing what your application really needs is essential.

Batery is easier.
If you use 6V lead acid then for one day you need.
Hours x load = mAh.
Here load=24 hours. mA = 50 in this example.
mAh = 24 x 50 mA = 1200 mAh = 1.2 Ah. This is the capacity of about the smallest LA battery commonly available. In practice you want to discharge your battery by only a small % of its actual capacity so use a 2.4 Ah or 3.5 Ah or larger. 7Ah is not vastly dearer and will last far longer and will have several days of reserve capacity for bad weather.

Charging can now be discussed - but I'll stop here and see what is said about the above. We can add charging and other detail if it seems useful to do so.

An easy battery to use is 2 x LiIon or LiPo cells in series.
> 9 votes

---
Tags: battery, solar
---


# Question
Title: What's the smallest (cheap) USB Host solution for Arduino?
I'm building a project that will connect to users' phones (Android at first, but iPhone too, if there's enough interest) via USB. Of course, this means that I need a USB host in the project. The total size of the device has to be about the size of the phone, so answers that seriously suggest shields aren't going to be helpful - they'd put me over my size budget by at least a factor of 3.

I'd also rather not require an adapter to go from the USB Mini B connector type to the Micro B connector type.

Gravitech has a USB Host board for the Nano 3 that has a USB Type A connector, and the combination of a Nano and Gravitech Host is about the right size (maybe a little thick, once the whole thing is soldered to my own board), but the USB host is $25. I can get the Nano for about $4 each and would like to keep the USB host in the neighborhood of $8 each. Are the solder fumes getting to me, or is there such a specimen out there and I'm just not finding it?

# Answer
> 2 votes
The Arduino Due and Arduino Mega ADK can both serve as a USB Host. You can also use the chip that the Mega uses yourself

# Answer
> 0 votes
Cypress makes very small usb chips capable of host mode. Does this board meet your size requirements? http://www.mouser.com/ProductDetail/Cypress-Semiconductor/CY8CKIT-049-41XX/?qs=FSHIiqjonm0YmFbmBQfo1A%3D%3D&kpid=1159933375&gclid=CPjl6KOm4cQCFYGUfgodJh4A\_g

You may also consider ditching the arduino and running everything on the cypress

---
Tags: usb
---


# Question
Title: What is the fastest and easiest way to transmit arduino's sensor data to a PC wirelessly
I have a specific problem :

1. I'm working on a testing platform. It has to be absolutely isolated, so I cannot wire it back to my PC. I again reiterate it. There is no way to wire it to my PC. IT HAS TO BE ABSOLUTELY ISOLATED
2. It has about 10 different sensors on it and I need to read sensor's data simultaneously at 100Hz. It is currently working fine with 16Hz, but I need to improve it further, so I think maybe in future sampling rates higher than 100 is beneficial. 7 Hz is the lowest possible value that doesn't botch the whole things up.
3. I have a laptop on the platform which reads the sensor data via RS232, then it processes them in a fraction of a second and produce a control signal and send it to the actuators. It has to happen at real-time. Control algorithm is not heavy, it is several PIDs.
4. It has 6 actuators with the fastest possible reaction time of 0.005 second.
5. The main sensor currently is Microstrain 3DM-GX1. It is a very good sensors.
6. I want to add a GY-80 sensor in parallel to 3DM-GX1. I want to test various filtering algorithms on the GY-80's output and compare them to 3DM-GX1.
7. Platform has 6 degrees of freedom so I think laser transmission is not practical.
8. Distance between the computer and the platform is at most 3 meters.

For some reasons I am not able to use the laptop anymore. I want to read the sensor's data with an Arduino, preferably Arduino Mega 2560. My problem is that I don't want to load the control algorithm to the Arduino.

IMHO the perfect solution is going to be a Wireless link between the Sensors via Arduino to my PC. This way my PC logs data and also the Control Algorithm can promptly calculate the feedback signal and send it to Arduino which will send them to the actuators. This immensely makes things easier for me.

I think I need a RS232 shield for the 3DM-GX1 & Arduino, + some wireless solution for sending data from both sensors to my computer. Then I need to send back the control signal back to the actuators wirelessly.

Now what is the fast and easy way to transmit the data between PC and Arduino in real-time?

Thank you in advance!

# Answer
> 1 votes
The fastest way would be to use a laser link!! Yeah lasers. You could go with wifi or some other custom wireless but lasers will guarantee the highest energy density and therefor best bandwidth. This guy claims near 10 MB/s with his setup:

http://www.instructables.com/id/Laser-Transceiver/

---
Tags: sensors, wifi
---


# Question
Title: Set the timeout - Ethernet Shield library
Does anyone know if you can set the time for the timeout Ethernet Shield library? Let me explain:

I created a very simple function (below) that attempts to connect to an address if it is not accessible returns 0 if it is available returns 1. Problem is that when the site is not available, the microcontroller is waiting for an answer for a long time, wanted to reduce it.

```
uint8_t ping(const char* address)
{
    EthernetClient http;

    if(http.connect(address, 80)) {
        http.stop();
        return 1;
    }
    else
        return 0;
}

```

# Answer
> 0 votes
In the stream class there is a setTimeout(ms) function. e.g.

```
String str;
Serial.setTimeout(5000) ;
str = Serial.readStringUntil('\r');

```

Where this does timeout the initial connection attempt in http.connect(). Whereas I found it also important to timeout each line, as a web page may not disconnect at the end or not send anything.

```
int httpGetHeaders() {
  String request, response;
  int result = 0;
  long startOfHttpResponseTime;

  client.setTimeout(1000) ;
  response = "";
  inHeaders = true;
  startOfHttpResponseTime = millis();
  while((client.connected()) && inHeaders && ((long)(millis() - startOfHttpResponseTime) < HTTP_RESPONSE_TIMEOUT)) {
    String header = client.readStringUntil('\n');
    header.trim(); // trim off white spaces including CR and LF at end.
    Serial.print(F("head["));
    Serial.print(header.length());
    Serial.print(F("]:\""));
    Serial.print(header);
    Serial.println(F("\""));
    if (!header.length()) { // first blank line indicates end of headers
      inHeaders = false;
      Serial.println(F("No longer in Headers"));
    }
    else {
      if (header.startsWith("HTTP")) {
        Serial.println(F("HTTP Found"));
        int firstspace = header.indexOf(" ");
        result = header.substring(firstspace + 1, header.indexOf(" ", firstspace + 1)).toInt();
        Serial.print(F("result = "));
        Serial.println(result);
      }
    }
  }

  Serial.print(F("Result code = "));
  Serial.println(result);
  return result;
}

```

You may want to review the whole code at https://github.com/lansing-makers-network/StatusBotArduino/blob/master/StatusBotArduino.ino I have reduced the connection to a sequence of commands that can be used consectutively in the desired order to meet different needs. The above is just to read a headers response.

---
Tags: ethernet
---


title: How to interrupt a code after delay

text:
# Question
Title: How to interrupt a code after delay
I have a functionality on my mega 2560 to connect with other devices. Sometimes, devices can't answer. I don't want to wait for a longwhile. So, how can I interrupt the chunk of program after the specific amount of time?

My code for receiving messages is:

```
while (!(UCSR1A & (1<<RXC1)));

```

so, `millis` can't solve my problem because I haven't ability to check for conditional loops like that

```
if(currentMillis - previousMillis > interval) {

```

# Answer
OMG, I was stupid. I can just place millis in this `while` condition.
> 1 votes

---
Tags: serial, arduino-mega, softwareserial
---


title: Delay versus polling power consumption?

text:
# Question
Title: Delay versus polling power consumption?
Does using the delay function use any less power than spinning in a polling loop on a timer?

# Answer
> 3 votes
That depends very much on how delay() was written (and how it will be written in the future!). There are "sleep modes", which will reduce the power consumption of the arduino - these are one of the best way to reduce power consumption. Delay() may or may not activate these. If not, there could be a replacement Delay() function that could do this.

If you want to reduce power, check out http://www.gammon.com.au/power \- this is an excellent step-by-step tutorial on how to reduce power consumption from 50mA down to 288 µA

# Answer
> 1 votes
The answer is probably "they are equal" because what the CPU is doing is less than 1% of power draw. In order to save power while waiting you can put the chip to sleep. Assuming you have an Arduino uno, this post contains sample code about sleeping and current consumption. http://forum.arduino.cc/index.php?topic=78430.0

Maybe explain what you are doing (what size battery you have) and we can add some advice about ways to save power

---
Tags: power, timers
---


# Question
Title: Is is possible to hook up an SD card and a GSM/GSRM module?
Is it possible to hook up a GSM/GSRM module *AND* an SD card at the same time to an Arduino Uno, or any Arduino?

I want to build a cellphone to read off the buttons that are being dialed into it for a poor guy who has no hope of using a regular cellphone, and I figure I need to include wav files for the buttons (and any other functions) on an external source.

I'm a good programmer, so if I can hobble the parts together I can make them talk to each other. But, I'm not so sure the different schemes for this all use the same pins, so I was wondering if someone would be so kind as to enlighten me..

# Answer
> -1 votes
Yes.

---

But let me try to talk you through it.

**Step 1 - Analysis/Requirements:** Get your requirements right, what should your system do, what functionality. So, GSM functionalities and SD card savings (in short). One of the requirements would be that's it on an Arduino (atmega 328P). Any other hardware requirements?

**Step 2 - Design:** Check the possibilities with the Arduino, 1 hardware serial and multiple software serial connections. One hardware SPI/I2C I believe. SD cards often use SPI connection and GSM units most likely use serial. So this works great. Check some tutorials on SPI and (arduino) serial.

**Step 3 - Wiring up** Wire everything up, as defined in the datasheet of the devices. Cross the Rx and Tx lines. Put MISO to MISO and MOSI to MOSI accordingly. Be sure everything has enough power (GSM modules typically draw a lot of current when sending/connecting). Usually, if you find out that two devices are attached to the same pin, there might be something wrong (unless you can declare how they're seperated or why this is the case).

**Step 4 - Implement** Well, you stated you're good at programming, so I'll leave this open for you. But mind that it's only one of the three steps, so you should look at some tutorials, it'll learn a lot faster than asking everything. Try to get a bit comfortable with your thoughts, base them on things you have learned.

> So this shouldn't be an issue? Those pins aren't shared? - user1833028

Things like this can be found in the device's datasheet and if you follow some tutorials you'll see that they're different and why.

Also, what helps for me often, is to try to seperate this 'big' project into two smaller projects. Try to get the GSM working and after that you go for the SD card reader.

---
Tags: arduino-uno, gsm, sd-card
---


# Question
Title: Can I charge a 4.2 V battery with a 5 V adapter?
Can I charge a 4.2 V battery with a 5 V adapter without damaging the battery?

# Answer
This question would be a better match to the Stack Exchange Electrical Engineering group.

A 4.2V battery is very likely a LiIon or LiPo battery. I'll call it LiPO below as it's easier to type.

Most cellphones and many small electronic device use a single LiPo battery and use a 5V input to charge them. To do this they have internal control circuitry that ensures the battery's specifications are met. You can obtain suitable control electronics (in many cases as a single IC requiring maybe a few external resistors to configure it) and it makes great sense to use such a control circuit.

In an emergency you can use a 5V source to charge a 4.2V battery **IF** you know what you are doing and are able to ensure the battery specifications are adhered to. Failing to stay "in spec" may lead to the traditional LiPo "vent with flame" response, and even if there is no apparent damage the battery life can be greatly or very greatly reduced by out of spec treatment.

Key requirements are:

* NEVER exceed 4.2V at battery terminals.
* NEVER exceed Ichg\_max = manufacturers max charging current.
This is usually the same value in mA as the battery capacity in mAh.
ie 1000 mA for a 1000 mAh battery
3300 mA for a 3300 mAh battery etc
* When charging, EITHER stop charging when battery potential reaches 4.2V OR if you are able to hold the battery AT 4.2V, then stop charging when Ichg falls (under battery control) to say Ichgmax/4.
* If Vbattery is under 3.0 V (which it NEVER should be) charge at no more than C/10 (eg for a 1000 mAh cell) until Vbattery rises to \>= 3.0V. If the battery will not rise to 3.0V under C/10 charge it is dead.

IF you can satisfy ALL these requirements at all times you can charge a LiPo or LiIon battery from 5V without a special charger.
> 2 votes

# Answer
No. You must use a charger properly designed for the battery; attempting to connect a Li-ion battery directly to a USB charger will damage the battery, possibly catastrophically.
> 1 votes

---
Tags: gsm, usb, battery
---


# Question
Title: Connecting an AB phase encoder motor to arduino
i'm trying to understand how to connect this motor:

"Mitsumi 334P/R AB"

Link to the motor i bought

connections are:

GND - Obvious.

5v - Obvious.

rest of the connections are a bit confusing to me and i do not want to fry my arduino trying.

* do i need a driver or this looks like a built in one?
* do i need to add any electrical components like resistors and capacitors ect?

# Answer
It's just a regular motor, with a (optical) rotary encoder inside. So the first two `motor` pins are to run the motor. So connect to VCC and GND, or GND and VCC, if you want to run it in reverse. (VCC doesn't have to be 5v; it can be 3v to 30v).

Connect A and B to a digital input pin. You can see what kind of signal you can expect in the screenshot of the oscilloscope, attached to the ebay-listing. So you can measure the speed, and relative position of the motor-shaft.
> 1 votes

---
Tags: motor
---


# Question
Title: Why does the ADC overflow when using an external Aref?
I'm using an LM35 temperature sensor, and it outputs 190 mV (which agrees with 19°C). I'm using an external reference voltage which I measure as 417mV. (This is set by the pin "aRefCntrl"). So I should have a reading around 467, but I get 1023, i.e. the ADC overflows. When I use the internal 1.1V reference I get a correct reading. Any ideas?

This is my code (Arduino waits for a request from the PC to send the data):

```
#define lm35 A0
#define aRefCtrl 10

void setup() {
  pinMode(aRefCtrl, OUTPUT);
  digitalWrite(aRefCtrl, 0);
  analogReference(EXTERNAL);
  analogRead(lm35); // dummy read
  Serial.begin(9600);
}

void loop() {
  if ( Serial.available() ) {
    Serial.read(); // PC's request is a single byte
    int temperature = analogRead(lm35);
    Serial.println(temperature);
  }
}

```

**follow-up** on Ignacio's comment: would a decoupling capacitor do? (I can't test for the moment, I have to order some)

# Answer
The minimum reference voltage is 1.0 V according to the atmega328 datasheet. See table 29-15. ADC Characteristics.
> 4 votes

---
Tags: arduino-uno, analogread
---


title: Differential steering drive equation

text:
# Question
Title: Differential steering drive equation
I'm trying to control an Arduino-powered motorized toy with a differential drive. However, I want to code it the motor movements with a direction vector.

e.g.

```
(1,0) = forward
(-1,0) = backward
(0,1) = turn left, pivoting on center axis
(0,-1) = turn right, pivoting on center axis
(1,1) = forward-left, pivoting on left wheel
(1,-1) = forward-left, pivoting on right wheel

```

I thought the equation to convert these to the literal motor signals was:

```
float mag = sqrt(dirX*dirX + dirY*dirY);
float left = dirX - dirY;
float right = dirX + dirY;

```

This seems to work for the first 4 cases, but fails for the last two, where it results in an un-normalized vector.

One potential fix would be to simple wrap `left` and `right` in min() to stop it from going over 1.0, but that feels like a hack, and would possibly lose resolution. Is there a more elegant fix?

# Answer
> 2 votes
If you want to take it to to the extreme, I always use an algorithm called Diamond Coordinates. It is described in this PDF. It performs perfectly, and I keep a C# and Java implementation handy. I'll probably be doing a Python one soon :)

# Answer
> 0 votes
Part of the problem is that "direction vector" is a bit vague in this context. Here are two popular ways of doing this:

**(x = right speed, y = left speed)**

This is like "tank drive", where two joystick's up/down axis are used to drive; you don't really need to do any math to get motor outputs.

**(m = output magnitude, d = left/right balance)**

I've heard this called "arcade drive", where one joystick's up/down is m and left/right is d.

Your equations are correct; the bounds check is unavoidable. Linear vector spaces just are not going to arbitrarily bound themselves at 1 for you. you could make it so "full speed ahead" doesn't actually max out the motor speeds; then when you turn it could still speed up one side a bit, but that is obviously still suboptimal.

You could try normalizing left and right, then multiplying by "m" again. The magnitude would be constant so you wouldn't have to do any bounds checking, but you would lose the pivoting on the center behavior you want, and full forward would be slower. You could also try making "d" an angle, and then choosing left and right with sine and cosine, probably shifted 45 degrees. That has the same problems.

I like to try driving it a bunch of different ways and see what handles best.

---
Tags: motor
---


# Question
Title: Install Bluetooth inside a home theater, How?
I have a 5.1 home theater(old one), I would like to transform it into a audio streaming system. I have a Arduino UNO and HC-05 Bluetooth Module, and I don't know how to install it in my home theater(if it does). solution please...

# Answer
> 0 votes
I don't think this will be feasible. There are two main issues:

**1.** I don't think there's a sensible way to get the HC-05 module to work with A2DP. It's great for a simple serial connection, but Bluetooth-enabled media devices generally won't connect to it if they're looking for audio streaming systems (as far as I know).

**2.** The Uno probably isn't powerful enough. Even if you could get the audio data into it, I don't think it will be able to decode the information to an analog audio signal in real-time.

Something like a Raspberry Pi with a suitable Bluetooth module might be a better choice for this.

---
Tags: arduino-uno, bluetooth
---


# Question
Title: How do I turn on or off an array of LEDs based on the value of a variable?
I've created a function whereby an int ('cleanCount') automatically goes up or down (0-1000) based on the situation. The value changes every few milliseconds.

Based on the value, I would like to turn on or off LEDs. Let's say for every increment of '100' another LED goes on. So if the value is 359 there are 3 leds on, if It would been 899 there would've been 8 LEDs on.

I could simply write

```
if (cleanCount <= 100) { // turn on NO LEDs
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    ...
}

...

else if (cleanCount <= 500) { // turn on 4 LEDs
    ...
    digitalwrite(led3, HIGH);
    digitalwrite(led4, HIGH);
    digitalwrite(led5, LOW);
    digitalwrite(led6, LOW);
    ...
}

```

but that would be a big pile of code which could be way more efficient. Perhaps.. my code isn't even correct.

So how could this be more efficient or perhaps actually working?

---

*The whole code, here below.*

```
int cleanCount = 1000;
int softpotPin = A0; //analog pin 0

void setup () {
    Serial.begin(9600);
    digitalWrite(softpotPin, HIGH); //enable pullup resistor
}

void loop() {
    int softpotReading = analogRead(softpotPin);
    if (softpotReading < 980) { // IF AANGERAAKT
        digitalWrite(werktIeLED, HIGH);
        ++cleanCount;
        Serial.println(cleanCount);
        delay(16); // 5x zo snel als leeglopen
    }
    else if (softpotReading > 980) { // IF NIET AANGERAAKT
        digitalWrite(werktIeLED, LOW);
        --cleanCount;
        Serial.println(cleanCount);
        delay(64); // 1000 / 60 seconden
    }
    else {      // Als er een fout optreed..
        Serial.println("Fout!");
        digitalWrite(werktIeLED, HIGH);
        delay(250);
        digitalWrite(werktIeLED, LOW);
        delay(250);
    }

}

```

# Answer
Here is a suggestion with the led pins in an array that you loop over.

I suggest making the array global, so put it outside any functions (usually at the top):

```
byte led_pins[] = {pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8};

```

Then put this in your loop (assumes that you have a `int` called cleanCount that is in scope:

```
const int increment = 100;

for (int i = 0; i < sizeof(led_pins) / sizeof(led_pins[0]); i++) {
  boolean onOrOff = cleanCount > (i+1) * increment;
  digitalWrite(led_pins[i], onOrOff);
}

```
> 2 votes

# Answer
You can use the barGraph example from the Arduino code examples. This gives a bar-type graph and not point. I will give rough explination why it will work and the need not to re-invent the wheel.

```
    int sensorReading = analogRead(analogPin);
  // map the result to a range from 0 to the number of LEDs:
  int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);

  // loop over the LED array:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    // if the array element's index is less than ledLevel,
    // turn the pin for this element on:
    if (thisLed < ledLevel) {
      digitalWrite(ledPins[thisLed], HIGH);
    }
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], LOW);
    }
  }

```

`int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);`

This will give you the point in the array, 0-10, for 0-1000, if you replace `1023` with `1000`

Simplified `map()` function:

`int point = sensorReading*10/1000` this gives you a range of 0-10, the int keeps it from having decimal points.

As you can see from the for loop it turns on all the LEDs that are in the array to the end and then turns off those not needed.
> 2 votes

# Answer
Instead of repeating several calls to `digitalwrite` you should consider changing the pins directly as described here.

This now depends on which port your LEDs are connected to. Assuming port D you would use `DDRD` to define the pins as output (usually in `setup()`) and `PORTD` to set their values (in `loop`), e.g.

```
DDRD = B11111110; // define pins 1..7 as outputs, pin 0 as input

```

and

```
PORTD = B11110000; // switch on first 4 LEDs

```

Now all you need to do is to write a function to map your number range to suitable bit strings.

The function could look like this:

```
int convert(int n) {

  int res = 0;   // start with all pins off (zero)
  while (n > 100) {
    res <<= 1;   // shift pattern 1 bit (i.e. pin) to the left
    res |= 1;    // "switch on" lowest pin
    n -= 100;    // defines step size (1 LED for every  100)
  }
  return res;

}

```

It takes your value and returns an `int` that you can assign to the port. I.e. for 0..100 it returns `0`, for 101..200 it returns `1`, for 201..300 it returns `3` = `B11`, for 301..400 it returns `7` = `B111` and so on. (Note that it does not do any sanity checks on the input / output but that's certainly easy for you to add if needed.)

(In response to comment: Note that the bit pattern I use as example for `DDRD` above is an example: It sets bit / pin 0 as input. If you use `convert` you would, of course, set the lowest bit of `DDRD` to 1 to make it an output.)
> 0 votes

---
Tags: led, variables
---