message:
Getting the contacts/ storing contacts to SIM card

I have the [GSM shield][1] and is there any ways to get the stored contacts on the SIM card? It seems that [the GSM library][2] does not support writing data onto/ reading data from the SIM card?

My aim is to store the SIM card's phone number and some variables onto the SIM card itself, such, I would not need to change the program from time to time.

All I need to do is enter all the variables in the SIM card via any mobile phone (perhaps by storing the variables as contacts, as phone book function should be very common on phones).

  [1]: http://arduino.cc/en/Main/ArduinoGSMShield
  [2]: http://arduino.cc/en/Reference/GSM

body:
What have you researched so far? Following the link you have given for the shield, about the third line of the description is a reference to the [AT Command Set][1] used by the chip.

I just did a couple of quick searches through it and found:

>`2.2.4  ATD><n>` Originate phone call to number in memory
>
>`3.2.26 AT+CPBF` Find phone book entries
>
>`3.2.27 AT+CPBR` Read current phone book entries
>
>`3.2.28 AT+CPBS` Select phone book memory storage

probably a good place to start.

  [1]: http://arduino.cc/en/uploads/Main/Quectel_M10_AT_commands.pdf


sender: user

sender: assistant

body:
Thanks to @Madivad for the AT command inspiration. I am not very familiar with GSM and Arduino. But anyway, the below worked for me.

Credits to @Madivad and [people from the arduino forum.][1]

    #include <GSM.h>
    GSM gsmAccess(true);
    int sizer = 200;
    char myNumber[200];
    int timeout = 5000; // in milli seconds

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

      boolean notConnected = true;

      Serial.println("Connecting to the GSM network");

      while(notConnected){
        if(gsmAccess.begin() == GSM_READY) // Note: I do not require PIN #
          notConnected = false;
        else {
          Serial.println("Not connected, trying again");
          delay(1000);
        }
      }

      Serial.println("Connected");

      theGSM3ShieldV1ModemCore.println("AT+CPBS=\"SM\"");
      int start1 = millis();
      while((millis() - start1) < timeout){
        Serial.print(theGSM3ShieldV1ModemCore.theBuffer().read());
      }
      Serial.print("Set to look at SIM card storage");

      // search for contact name "test"
      theGSM3ShieldV1ModemCore.println("AT+CPBF=\"test\"");
      start1 = 0;
      start1 = millis();
      while((millis() - start1) < timeout && !theGSM3ShieldV1ModemCore.theBuffer().extractSubstring(",\"", "\",", myNumber, sizer)){
        Serial.print(theGSM3ShieldV1ModemCore.theBuffer().read());
      }
      Serial.print("Got contact number");

     // print out the phone of "test"
     Serial.println(myNumber);

    }

    void loop()
    {

    }

  [1]: http://forum.arduino.cc/index.php?topic=163155.0


message:
IR controlled light dimmer

I am doing a project on Arduino controlled light dimmer circuit...

I have a separate circuit for zero crossing detector and IR receiver but when I am combining both of them in arduino then my IR receiver stops working and zero crossing interrupt is not detected...

Here is my code:

    #include <IRremote.h>
    int RECEIVE_PIN = 8;
    int AC_LOAD = 3;
    int dimming;

    IRrecv irrecv(RECEIVE_PIN);
    decode_results results;

    void setup()
    {
        Serial.begin(9600);
        irrecv.enableIRIn();
        pinMode(AC_LOAD, OUTPUT);
        attachInterrupt(0, zero_crosss_int, RISING);
    }

    void zero_crosss_int()
    {
        int dimtime = 75*dimming;
        delayMicroseconds(dimtime);    // Off cycle
        digitalWrite(AC_LOAD, HIGH);   // triac firing
        delayMicroseconds(10);         // triac On propogation delay
        digitalWrite(AC_LOAD, LOW);    // triac Off
    }

    void loop()
    {
        if (irrecv.decode(&results))
        {
            Serial.print("0x");
            Serial.println(
            results.value, HEX);
            delay(50);

            if(results.value==0xE13DDA28)
                dimming = 120;

            if(results.value==0xAD586662)
                dimming = 80;

            if(results.value==0x273009C4)
                dimming = 20;

            irrecv.resume();
        }
    }

Can anyone help me with this????

body:
What you've described (without source code and/or a circuit diagram) sounds like you'll probably be using interrupts at least for the zero crossing detection. And probably the IR receiver too. The IR receiver is going to be your problem since the zero crossing is a very quick flag set and you're out of the interrupt.

On the other hand, the IR detection is going to take time, and if you're doing THAT in an interrupt you're going to be missing dozens of crossings.

To mix the two you can leave the zero crossing in it's own interrupt, but you're probably better off handling the IR in the loop via a state machine.

Since you say that neither are working, I'm going to hazard a guess and you're using the same interrupt or badly implemented them (possibly a timer and interrupt clash) and until you post some code people here aren't going to be able to help you any more than that.


body:
One important problem in your code is concurrent access to `dimming` variable. That may not be the only problem you have though.

Indeed, `deeming` is accessed for writing in your `loop()`, but it can be simultaneously read by `zero_crosss_int()` function which is executed in interruption mode because it was registered as such with `attachInterrupt()`.

Since `deeeming` is an `int` (2 bytes on AVR MCU), it cannot be read or written in just one clock-cycle (AVR is an 8-bit technology). Hence it is perfectly possible that `loop()` gets interrupted by `zero_crosss_int()` just in the middle of writing `dimming`, eg in:

    dimming = 120;

Note that, in theory, concurrent acces in your case should not be an issue as long as `dimming` is never greater than 255.

## How do you protect access to `dimming` variable?
You can do the following:

    int dimming() {
        cli();
        int temp = dimming;
        sei();
    }

    void dimming(int value) {
        cli();
        dimming = value;
        sei();
    }

And replace any direct access to the `dimming` variable in your code with a call to one of these functions above.

## Will that fix your problem?
Maybe not unfortunately, as it is probable that mixing IRremote.h with your code brings other conflicts.

But at least, this will solve a dormant bug in your code, a complex bug that may catch you some day.


body:
It seems that the jaydeep might have been building my circuit and  used the provided code: http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/step4/Arduino-controlled-light-dimmer-The-software/
so obviously this problem has my interest.
With regard to the 'dimming' variable, that will not go beyond 128 so I might as well have used 'byte'  to define it.
The IR remote library is I presume that of Ken Shirrif and that one uses the Timer2 interrupt. In principle, combining those two interrupts shouldnt necessarily cause a problem as I have done so as well (in using the timer interrupt rather than 'delay to trigger the TRIAC).
But in that case the entire timer interrupt was handled within the period of  the mains wavelength (100 or 83 ms depending on frequency).

I don’t think the access to the 'dimming' variable -as jfpoilpret mentions- is the problem (though he makes some sound remarks), as that will just remain as is for a specific  light level.

The problem -as  is also suggested above- might well be in the fact that the IR receive takes too long.

So... disregarding interrupt priority for a moment, if the code is hanging around in the timer interrupt routine and there is a zerocrossing, that won't be detected, or, if the code is just doing a zero crossing detection, the timer is  screwed up.

In comes interrupt priority: The external interrupt has the highest priority (other than reset). So.. when  the IR receive routine is busy in the Timer service routine and a zerocrossing arrives, it will be taken out of that routine, zerocrossing will be handled and ideally, it should continue with the timer routine again.
However, your remote has no idea what is going on in the Arduino and some of the code sent will be missed.

all of this shouldn’t need to be a problem if the external interrupt was fast, but as most of the waiting is actually done within this interrupt, it could take up to almost 10mS/8.3mS (when 'dimming' approaches 128).

Solution?
Well, I can't say much about the Timer2 interrupts in Ken's library, But on 'my side' of the software, what could be done is to shorten the external interrupt by removing the delays and use (yet another) timer interrupt.
Ken uses Timer2, so this would have to be timer1.
So, whenever there is a zerocross, there is no waiting in a delay, but it will be handled by timer1
An example is given in [Step 6 of my instructable][1]. There is no guarantee this will work but there is a good chance

Let me just point out that the basic  program I supplied was just given as an example, It uses much computer time in waiting and therefore isn’t the best to combine with other actions of the processor.

  [1]: http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/step6/Arduino-controlled-light-dimmer-The-software-III/


message:
How to write makefile-compatible sketches?

I'd like to write my sketches so that I can either build/upload them using the Arduino IDE, or optionally using GCC and a makefile.

I know about including the function declarations at the top, but is there anything else to do in order for my sketch to be considered valid C++ by my compiler?

### Update 1

Understanding what the Arduino IDE does to .ino and .pde files is fine, but extraneous to my question, so this is not a duplicate. What I want to know is "how do I write a program such that it is considered valid both by the Arduino IDE **and** g++.

The official(?) makefile [available here](http://playground.arduino.cc/Learning/CommandLine) explains what to do if using the makefile *instead* of the IDE:

    # The Arduino environment does preliminary processing on a sketch before
    # compiling it.  If you're using this makefile instead, you'll need to do
    # a few things differently:
    #
    #   - Give your program's file a .cpp extension (e.g. foo.cpp).
    #
    #   - Put this line at top of your code: #include <WProgram.h>
    #
    #   - Write prototypes for all your functions (or define them before you
    #     call them).  A prototype declares the types of parameters a
    #     function will take and what type of value it will return.  This
    #     means that you can have a call to a function before the definition
    #     of the function.  A function prototype looks like the first line of
    #     the function, with a semi-colon at the end.  For example:
    #     int digitalRead(int pin);

...but this doesn't explain how use *both* the IDE and a makefile.

### Update 2
I recently found [PlatformIO](platformio.org) which doesn't answer this question directly, but does automate a lot of the process (generates Scons files for you) and so far I prefer the workflow over both the Arduino IDE and the source+makefile approach.  Good support from the authors as well.

body:
By gcc/g++ I think you're referring specifically to avr-gcc/avr-g++.  Your arduino code probably won't be considered valid C/C++ code because gcc will try to compile with your PC as the target system. Many of the Macros in "WProgram.h" will refer to inaccessible memory on your target system.

Providing you include the header file "WProgram.h" and you build your code with the Arduino Makefile above (which uses avr-g++ not g++), your cpp files should compile and link correctly.  Likewise, you will be able to open your Arduino code within the IDE and Verify your code there.  The IDE puts in the "WProgram.h" file for you, so technically it would be included twice.  However, the include guards will prevent any duplicate code from being compiled.


body:
Generally you'll need to state the `setup()` and `loop()` functions, they are just wrappers of the IDE:

    void setup() {}
    void loop() {}

    int main() {
      setup();
      while (1)
        loop();

      return 0; // never reached
    }

This works both in the IDE and on the command line.
As you specify the Board and SerialPort in the IDE,
you'll need also to specify both in the Makefile.
So you'll end up with two configurations.

Many people leave the IDE because they prefer use different
editors or have more configuration options by setting
the compiler and linker switches.

To make it really easy, you can use [Arduino Makefile][1]. Today
starred with 347.

Here an example Makefile:

    # try: make help
    #
    include /usr/share/arduino/Arduino.mk
    ARDUINO_DIR = /usr/share/arduino
    # list boards with: make show_boards
    BOARD_TAG = promicro16
    ARDUINO_LIBS = EEPROM
    # MONITOR_CMD = picocom -b 9600
    MONITOR_CMD = moni -config ACM0-9600.cfg
    ARDUINO_PORT = /dev/serial/by-id/usb-Arduino_LLC_Arduino_Leonardo-if00
    # ARDUINO_PORT = /dev/ttyACM0
    # ARDUINO_PORT = /dev/ttyUSB0
    OPTIMIZATION_FLAGS = -Os -fexpensive-optimizations -fstrength-reduce
    #

The '*.ino' files don't need to be changed and the `Makefile` file is to be placed in the same directory.

Meanwhile I prefer the `Makefile` way, but I still use the IDE for small projects.

[1]: https://github.com/sudar/Arduino-Makefile


body:
> What I want to know is "how do I write a program such that it is considered valid both by the Arduino IDE and g++.

See: [How to avoid the quirks of the IDE sketch file pre-preprocessing](http://www.gammon.com.au/forum/?id=12625).

Disregarding for the moment what the Makefile will look like, the simple answer to your question, as discussed in the above link, is to put everything into .cpp and .h tabs in the IDE, and leave the main "sketch" (.ino file) blank. That will still compile under the IDE, and will also therefore be normal C++.

Make sure you start your .cpp files with:

    #include <Arduino.h>

If you use libraries (eg, SPI) you must include them in the main sketch file, which triggers the IDE to copy them into the temporary project build file. The Makefile won't care about that, as you will make sure your Makefile includes all the necessary library files.

Also see my answer here: https://arduino.stackexchange.com/questions/13178/classes-and-objects-how-many-and-which-file-types-i-actually-need-to-use-them/13182#13182


message:
Sketches not uploading to Micro from Ubuntu 14.04

I recently bought an Arduino Micro to see what all the fuss was about and I figured I'd use it with Ubuntu on an older Dell Latitude. I was able to install all of the files using some tutorials but I have this problem uploading sketches. After plugging in the board, the green top LED is consistently flashing so it seems to be working, but when I try to upload a sketch I get the following error

    Connecting to programmer: .avrdude: Send: . [1b]
    avrdude: Send: S [53]
    avrdude: ser_recv(): programmer is not responding
    avrdude: butterfly_recv(): programmer is not responding

Any ideas how to fix this? I tried pressing reset during the send as some forums have suggested but it doesnt seem to be working.

body:
The only way I have been able to fix this is revert back to Ubuntu 12.04.

There is something about 14.04 that does not play nice with the Micro.

I've tried running avrdude on the command line as well with no luck. The Arduino IDE code jumps through some hoops to detect the proper USB port, so timing is probably critical. I don't know the secret sauce for 14.04 though. The micro is tricky since USB is disconnected and reconnected during programming.

If anybody has better luck with this please update.


body:
I have a Micro and Ubuntu 14.04. I have successfully uploaded sketches to the Micro using IDE 1.0.6. Thus that combination should work.

I suggest you get the sketch compiling OK. Then hold down the Reset button on the Micro, start an upload with your other hand, and release Reset when it says "Uploading".

---

Try typing

```lsusb | grep Arduino
```

I found with a sketch uploaded which opens the Serial port:

```Bus 003 Device 087: ID 2341:8037 Arduino SA ```

If you hit Reset and wait a second, then do the lsusb again you see a different device:

```Bus 003 Device 086: ID 2341:0036 Arduino SA ```

That one (the 0036 one) is the one it will upload to. You might get 0037 rather than 0036 because I reflashed the bootloader to be the Leonardo one, but the concept is the same.


message:
Simple Script controlled by Raspberry not working

I can't figure out why the next script is not working. I have attached the Arduino to one USB port of the raspberry pi, in which I've installed pyserial. I just want to turn off/on a led depending of the number I write on the Raspi console (1-> on, 2-> off).

        int led=13;

    void setup(){
      Serial.begin(115200);
      pinMode(led,OUTPUT);
    }
    void loop(){
      if(Serial.available()){
         mode(Serial.read() - '0');
      }
    }
    void  mode(int n){

        if (n== 1){
             digitalWrite(led,HIGH);
        }
        if (n== 2){
            digitalWrite(led,LOW);
        }
      }

PS: I double checked and the baudrate is configured also at 115200 at the raspi side.
In addition, if I place digitalWrite(led,HIGH) just before  the line  "mode(Serial.read() - '0');" the led turn on when I send some information from the raspi shell (so, works well).

body: Finally I've found the error, it was the serial communication baud rate: 115200. It seems that at higher speeds it not works properly, lowering it to 9600 do the trick.


message:
Reverse turning of Stepper motor

I have a stepper motor connected to my Arduino like this using the ULN2003A Darlington Array:

![Circuit Diagram][1]
![Image][2]
(Ignore the potentiometer)

And I have programmed it with the following code:

    #include <Stepper.h>

    int in1Pin = 22;
    int in2Pin = 23;
    int in3Pin = 24;
    int in4Pin = 25;

    Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);

    void setup()
    {
        pinMode(in1Pin, OUTPUT);
        pinMode(in2Pin, OUTPUT);
        pinMode(in3Pin, OUTPUT);
        pinMode(in4Pin, OUTPUT);

        motor.setSpeed(25);
    }

    void loop()
    {
        int steps = 360;

        motor.step(steps);
        delay(500);
    }

At the moment the motor rotates clockwise, how could I have it so it rotates in the opposite direction?

My code was copied and edited from [here](http://learn.adafruit.com/adafruit-arduino-lesson-16-stepper-motors/arduino-code).

----------------

The problem was that I had the two middle wires the wrong way round as said here: http://forum.arduino.cc/index.php?PHPSESSID=kvi8dt2b5en5hhk02dlmjrotl5&topic=143276.msg

[1]: https://arduino.cc/en/uploads/Reference/unipolar_stepper_four_pins.jpg
[2]: https://static.flickr.com/32/54357295_756c131217.jpg

body:
The answer is simple. Just pass a negative number of steps as an argument to `motor.step();`.

Another note: You forgot a semicolon on your second to last line. IIRC this doesn't matter in C, but **it's just bad practice to do this.** If you add a line of code below that, then it won't work.

Example code:

    #include <Stepper.h>

    int in1Pin = 22;
    int in2Pin = 23;
    int in3Pin = 24;
    int in4Pin = 25;

    Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);

    void setup()
    {
        pinMode(in1Pin, OUTPUT);
        pinMode(in2Pin, OUTPUT);
        pinMode(in3Pin, OUTPUT);
        pinMode(in4Pin, OUTPUT);

        motor.setSpeed(25);
    }

    void loop()
    {
        int steps = 360;
        motor.step(steps);
        delay(100);

        steps = -360;
        motor.step(steps);
        delay(500); //Semicolon added
    }


message:
Adding devices makes I2C read 0

I'm using an Arduino Due with a logic level converter to interface with two different 5v sensors via I2C. Being of poor quality, these sensors have no data sheet.

When either one of these sensors is plugged in, I am able to read from it without issue. The moment I plug the other one in as well, the I2C stops working, and I just get 0. I know that it's not an address collision issue, because they have different addresses.

I tried adding an additional set of pull-up resistors (such that they are in parallel with the built-in ones) in order to counteract potentially increased bus capacitance, but no dice.

What could be causing this issue? I apologise for asking such a noob question.

body:
Your problem is probably from the level converter. Which one did you use?
Most level converters are uni-directional, and don't work for I2C.
See the App note and device from NXP:
http://www.adafruit.com/datasheets/an97055.pdf


message:
Arduino 1 can somehow support 32-bit audio?

I wanted to take the audio from a device such as the PC, insert it through different ADC in arduino, processing them with DSP and DAC REnter all through to the other speakers, reading here and there on the internet but some people were put in difficulty because Arduino has a data bus to 10 bits. What problems can cause this? I can not send the same 10 bits at a time, until you arrive at 32?

body:
First of all,*what is the point of this?* [I'm afraid this is a XY question](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). You won't get that good of quality with Arduino. If you're hoping to create some sort of an amp, learn electronics and do that directly. Maybe you should just send data via serial.

Anyway, that aside, here's a chart I drew:

![][1]
(Excuse my poor image alignment, PowerPoint was being a little mean today)

The bottom is all the "channels" the PC can send. The top is all the "channels" the Arduino can recieve. As you can see, there's a *huge* degradation in quality. Not to mention, I made this that 1 bit = 1 "channel," yet it's very much more than that.

A standard Arduino (Uno, Leonardo, etc.) has a 10 bit ADC that can read values 0-1023. The computer can output 0-4294967295! (It' exponentially grows due to permutations). You can see why I very much simplified my chart! :P

DSP won't really work well, unless you are trying to do some weird alien sounding modifications or a cheesy echo to. You probably will want to add an external 32 bit ADC. I would recommend, additionally, adding a Due or Galileo that can process 32 bit integers without emulating a bigger chip, thus greatly reducing performance and giving you a low framerate.

tl;dr: It'll work fine, but it'll have horrible sound quality. You can't send the same 10 bits until 32, since the computer changes that 32 bits into a voltage (sent to Arduino), and the Arduino translates that voltage into 10 bits.

  [1]: https://i.stack.imgur.com/L8BAr.png


message:
Processing Input

How to make an input from computer using processing (like a password form) and trigger pin in arduino?
If you let some link to read more that would be very helpful.

body:
You need to have a look at the Serial commands: http://arduino.cc/en/Serial/read

http://arduino.cc/en/Tutorial/ReadASCIIString


body:
On the processing side you need to communicate with the arduino using the Serial class. To set up use something like the following. It is a bit of guess work
to find which of the serial ports to use

    Serial myPort;
    void setup() {
      // List all the available serial ports:
      println(Serial.list());

      // Open the port you are using at the rate you want:
      myPort = new Serial(this, Serial.list()[6], 9600);
      myPort.buffer(2); // sets the size of the buffer, I send two bytes at a time
    }

You can read a write using the Serial.read() and Serial.write() see https://processing.org/reference/libraries/serial/index.html for the processing serial references.


message:
Debugging my Stepper Motor Driver circuit

I'm using the [Pololu DRV8825 Stepper Motor Driver](http://www.pololu.com/product/2132) to control a [NEMA 17 Steppermotor](http://www.ebay.co.uk/itm/Nema-17-1-7A-2-55V-Motor-ACT-17HS4417-Rep-rap-Nema17-Bipolar-/281122696759) with an Arduino Uno.  According to the Pololu website, the circuit should be wired as follows:

![enter image description here][1]

I did, however, deviate from this exact sketch a little bit:

 1. The Arduino (microcontroller) is powered by a USB cable connected to the computer
 2. I connected the 5V pin on the arduino to the + rail on a breadboard.  I then connected two wires on this rail to the **RESET** and **SLEEP** pins on the driver.
 3. I'm using a 9V battery to power the motor.
 4. I've connected the **DIR** and **STEP** pins to Arduino Uno pins 12 & 13, respectively.

Consequently, I coded and uploaded the following sketch:

    int stp = 13;  //connect pin 13 to step
    int dir = 12;  // connect pin 12 to dir
    int a = 0;     //  gen counter

    void setup()
    {
      pinMode(stp, OUTPUT);
      pinMode(dir, OUTPUT);
    }

    void loop()
    {
      if (a <  200)  //sweep 200 step in dir 1
       {
        a++;
        digitalWrite(stp, HIGH);
        delay(10);
        digitalWrite(stp, LOW);
        delay(10);
       }
      else
       {
        digitalWrite(dir, HIGH);
        a++;
        digitalWrite(stp, HIGH);
        delay(10);
        digitalWrite(stp, LOW);
        delay(10);

        if (a>400)    //sweep 200 in dir 2
         {
          a = 0;
          digitalWrite(dir, LOW);
         }
        }
    }

**RESULT**
The stepper motor does not turn.  Instead, it just hisses at a high pitch.  After a short while, the driver gets very hot.

**THINGS I'VE TRIED**

 1. I double checked to make sure that connected stepper wires pairs are properly connected to the "A" pins and "B" pins on the driver.
 2. I tried reversing the A1-A2 pair and B1-B2 pair in all possible combinations.  All combinations produce the same result as above.
 3. I tried increasing the motor power supply to 12V (8 alkaline AA batteries).  The same result occurs.
 4. I double checked to make sure the 100microF radial electrolytic capacitor is connected with the long end to the positive motor supply and short end to the negative motor supply (on a different breadboard rail than the logic power supply, of course).
 5. I tried using the 3.3V pin instead of the 5V pin to connect to SLEEP and RESET on the driver.  Again, the same result occurs.

I'm not really sure what to try next to debug my circuit.

**My Hunch:**

I do, however, have one suspicion based on a little warning box on the pololu website which reads:

> **Caution:** Installing the header pins so that the silkscreen side is up
> and the components are down can limit the range of motion of the
> trimpot used to set the current limit. If you plan on installing the
> header pins in this orientation, please set the current limit before
> soldering in the pins.

The way I soldered the headers onto the driver looks like the bottom left corner of the picture below:

![enter image description here][2]

**My Question:**
Given that my stepper motor requires 1.7A current, is there anything I can do to improve this circuit to make it work?  Did I make any mistakes?  Is there anything else I should try or check?  Did I solder the header in the wrong way?

  [1]: https://i.stack.imgur.com/x76EK.png
  [2]: https://i.stack.imgur.com/I4p4R.jpg

body:
**A couple things I noticed first:** This is one of the best formatted questions I've ever seen... :) Anyway, your circuit looks fine to me except for a few things:

> **Warning:** This carrier board uses low-ESR ceramic capacitors, which makes it susceptible to destructive LC voltage spikes, especially when using power leads longer than a few inches. Under the right conditions, these spikes can exceed the 45 V maximum voltage rating for the DRV8825 and permanently damage the board, even when the motor supply voltage is as low as 12 V. One way to protect the driver from such spikes is to put a large **(at least 47 µF) *electrolytic* capacitor across motor power (VMOT) and ground** somewhere close to the board.

*(Added some italic/bold myself, quote from product page.)*

Capacitors are cheap ($1.50 on eBay from US), and although new drivers are too, it's generally a good idea to build it right. There's nothing more annoying than waiting for shipping on something you shouldn't have had to fix.

Additionally, battery power (especially AAs) can be bulky if not done right, and may not provide enough current. Note that in a series configuration that **it will provide the voltage of 8 AAs, but only the current of one.** You can't run a 1.7 A motor off of a single AA's current. Stab in the dark guess: you'll need ~80-100 AAs to provide enough current and voltage. I'm too lazy to measure the internal resistance and actually calculate it.

**Suggested solution:** There are a million things that could go wrong. Without being there, I'm betting that your delay function is too short. What this will do is not provide enough time for the motor to move, thus it staying still. This would still use a lot of current (50% of the time it's full current to motor coils), therefore it would make the driver hot. (**Note on heat:** *...to supply more than approximately 1.5 A per coil, a heat sink or other cooling method is required...* -Product page: you'll need a heatsink to cool your chip down.) Also note that some heat is normal; a general rule of thumb is if it's too hot to hold your thumb on it for a few seconds, you need more cooling. Remember that the more it's used, the hotter it'll get, so keep this in mind when deciding if you want to add a heatsink.

**tl;dr:** You need to increase the delay time and provide more current than you have currently.


body:
I don't think your batteries were too low in current capacity, your delay time is not too short, at 10 +10 ms per clock pulse, you are only talking about 50 steps per second, that's not all that fast. I've written programs where I have had to go to microseconds to get enough rpm out of my stepper.

First, take everything out of your loop except the digitalwrite high, delay digitalwrite low and delay lines. Then the program "should" just spin the motor continuously in one direction. That way you are sure you don't have a logic issue.
Second, did you check to see if you didn't hook up pin 12 and 13 backwards, such that you are telling the driver to change direction every 10 ms instead of stepping? The sound it makes would be more like a buzz or vibration, usually a soft, staticy hiss is when the motor is enabled, but not getting a step pulse.

Finally, this post is about 18 months old, it is considerate and helpful to others to explain how you solved the problem (assuming you figured it out).


body:
The one thing that helped me was NOT to connect GND to stepper board from microcontroller (bottom black line from schematic posted in first post).

If it was connected, driver would draw 12V@3A immediately and gets freaky hot. Also motor didn´t turn at all.


body:
I had this same issue when setting up this circuit with this code and driver on an Arduino Uno. All else was fine, but the current for the motor was set WAY too high on the driver from the factory. The VREF was 1.7 volts, and it needed to be around .5 for the motor I was using. As I set the VREF to the appropriate voltage, the motor started to spin as it should and stopped hissing.

I know this post is old, but I hope that this helps someone else. Pololu has a great video (and documentation in general) for setting the appropriate voltage on most of their drivers on the product page here: [DRV8825 Stepper Motor Driver Carrier, High Current][1].

  [1]: https://www.pololu.com/product/2133


message:
how does serial port communication work under the hood?

im just looking for how to send/ write date to pc over serial port from arduino..vice versa.

I have few Question to ask after taking so much time and couldn't figure it out myself. I hope you guys can guid me please.

First, i found i can use Serial.println() function to send some data then, on the pc side, it just checks and reads the port (/dev/tty..). But, how does this process actually work under the hood? So, if you use serial.println() it knows about where to write?

Second i also found it's something to do with UART communication.. But, inside Hardware.cpp file, i couldn't find any function call to the one for UART.

Third there is the code like extern HardwareSerial Serial; Then where is the definition of this Serial?

Fourth There seem to have ring buffer for serial buffer. So, when data is being sent then, what and who fill the data into this buffer inside Hardware.cpp?

please, forgive my silly question.. i'm just so curious about this..

body:
Serial.println knows where to write because Serial is an object. On boards with more than one port there will also be a Serial1,Serial2,etc. Each object corresponds to a port.

The ring buffers are filled from interrupts. When a new byte comes in, it triggers an interrupt that puts the byte in the buffer. When a byte is finished sending it triggers another interrupt that reads the next byte from the buffer and sends it.

Somewhere there is a source file that sets up the UART. It's full of writing special values to registers and low level things like that. I'm not sure what files things are defined in, but if you use the search feature on github there is tons of interesting stuff.


body:
The first question already got a perfectly good answer. I am answering the other ones.

> i couldn't find any function call to the one for UART.

There are no "UART functions" in the MCU. The UART is controlled by reading and writing into special registers. These come by names like `UCSR0A`, `UCSR0B`, `UCSR0C` (USART 0 Control and Status Registers A, B and C), `UBRR0L`, `UBRR0H` (Low and High bytes of the USART 0 Baud Rate Register) and `UDR0` (USART 0 Data Register). These registers are all referenced in HardwareSerial.cpp. You can check the datasheet for their meaning.

> where is the definition of this Serial?

In HardwareSerial.cpp, by the end of the file, right after the comment "Preinstantiate Objects".

> There seem to have ring buffer for serial buffer. So, when data is being sent then, what and who fill the data into this buffer inside Hardware.cpp?

There are actually _two_ ring buffers: the receive buffer (`_rx_buffer`) is filled by an interrupt service routine and is emptied by you calling `Serial.read()`. The transmit buffer (`_tx_buffer`) is filled by you calling `Serial.write()`, `Serial.print()` or `Serial.println()` (the line `_tx_buffer->buffer[_tx_buffer->head] = c;` in `HardwareSerial::write()`), and is emptied by an interrupt service routine.

These interrupt service routines are defined in HardwareSerial.cpp. They start with lines like `ISR(SOMETHING_vect)`. They are triggered by the hardware UART. The transmit ISR is triggered when the UART is ready to accept a new byte to transmit (when it is done transmitting byte _n_, it starts transmitting byte _n_+1 and is ready to accept byte _n_+2 in its TX buffer). The receive ISR is triggered when a new byte has been received.

> when does it get initialised?

When you call `Serial.begin()`.


message:
Arduino shield stacking

I have an Arduino GSM Shield mounted on an Arduino Uno. Can I stack this [GPS shield][1] above Arduino GSM shield? Will there be any pin configuration problem?

In GSM Shield hardware pin’s configuraton are as below:

    0 - Not connected
    1 - Not connected
    2 - GSM Rx
    3 - GSM Tx
    7 - Modem reset

If there is any problem, how can it be solved? I would be happy if there are any alternatives for the GPS shield.

----

### Addendum

The [schematic of the Arduino GSM shield][2]:
![schematic of the Arduino GSM shield][3]

The [schematic of the SparkFun GPS shield][4]:
![schematic of the SparkFun GPS shield][5]

  [1]: https://www.sparkfun.com/products/10709#comment-5366048bce395fa40e8b4567
  [2]: http://arduino.cc/en/uploads/Main/arduino-gsm-shield-schematic.pdf
  [3]: https://i.stack.imgur.com/7ttFF.png
  [4]: https://cdn.sparkfun.com/datasheets/Dev/Arduino/Shields/GPSShield-v16.pdf
  [5]: https://i.stack.imgur.com/zZUxI.png

body:
From [the shield description][1], the TX and RX of the GPS are mapped on pins 2 & 3, like your GSM, so you'll have to change that.

I'm using Adafruit GPS + flash card shield, which is a bit cheaper (and uses pins 7&8).

  [1]: https://www.sparkfun.com/products/10710


body:
![enter image description here][1]
<sup>*Photo by [John Boxall](http://tronixstuff.com/)*</sup>

Which pins do they use?
-----------------------

To determine if two shields are compatible, you have to read the specifications of both shields.

The best source for this information is the data sheets supplied with the shields. However there is also this [Shield List](http://shieldlist.org/)

Can you reassign pins?
----------------------

Some shields provide a means to alter which pins are used for communications. This can take the form of a switch or a jumper - either pull-off or solder-bridge type. (the GPS shield in the question has jumpers).

Where the shields do not support pin-reassignment or provides insufficient flexibility, to work-around incompatibilities you can use an in-between shield designed for the purpose.

[here](https://www.sparkfun.com/products/11002) is one example:

> You hear it all the time in the Arduino community, “will this shield work with my other shield?.” I think we’ve all been disappointed to find that two of our favorite shields compete for control of a digital pin here or a serial pin there. While there are sometimes some clever workarounds from elegant code modifications to aggressive ‘greenwiring,’ Mayhew Labs may have come up with the simplest solution thus far: The Go-Between Shield.

Are any alternatives for the foo shield
----

I notice that Arduino.cc now point people to the list referenced above. They used to have their [own list](http://playground.arduino.cc/Main/SimilarBoards#goShie).

Product recommendations are off-topic here but, obviously, you can [search](https://www.google.com/search?q=gps+shield)

  [1]: https://i.stack.imgur.com/I7hXM.jpg


body:
This answer does not directly address the pin conflict issue, but rather skirts around it.

I have been looking into this same issue for over a month now and have come to the conclusion that the best option is to either [purchase][1], for around $30:

![SIM908 Shield][2]

 or [make][3], for around $20 (+$60 for the modules)

![Modular SIM908/900 shield][4]

 a shield that uses the [SIM908][5]. The SIM908 comes with both GPRS/GSM functionality, and GPS functionality, whereas the SIM900 only has GPRS/GSM. Now, there is no longer an issue with pin conflicts, as instead of two separate shields, only one is required.

The only disadvantage is that if you already have a GPRS/GSM shield, then that purchase will become redundant.

As an aside there is an alternative of a *3G* (**WCDMA** and **HSPA**) and GPS, using both assisted-mobile (A-GPS) and mobile-based (S-GPS) modes, combined shield, from [Cooking Hacks][6]. A bit more pricey though, at $160.

  [1]: http://www.ebay.com/itm/GSM-Phone-Module-GSM-GSM-GPRS-Arduino-Shield-Based-on-Quad-band-SIM908-Module-/251665851830
  [2]: https://i.stack.imgur.com/1yOw5.jpg
  [3]: http://www.open-electronics.org/gsm-gps-shield-for-arduino/
  [4]: https://i.stack.imgur.com/sEc4n.jpg
  [5]: http://wm.sim.com/producten.aspx?id=1024
  [6]: http://www.cooking-hacks.com/documentation/tutorials/arduino-3g-gprs-gsm-gps


message:
client.connect() fails except the first time

I am communicating with the Web server's database via Arduino GSM shield + GPRS connectivity

    void loop()
    {
      if (client.connect(server, port))
         {
           .......
          }
      else
         {
          Serial.println("Server not found");
          }
      delay(1000);
    }

The first time when the loop() runs in the serial port, the code works perfectly and stores in my server's db. The second time when the loop() runs after some delay, It is unable to connect to the server and results "server not found" . I don't know what is the problem.

Please let me know if there is a way to connect continuously. Thank you

body:
You have to disconnect before being able to connect again otherwise the controller will crash due to memory starvation. Every connect you do takes some memory to register state information. Not sure of the exact commands involved, but it'd look a bit like this:

       if (client.connect(server, port))
         {
           .......
           client.disconnect( .... );
          }
      else
    ........

Alternatively you can check if you are already connected, and only do a reconnect when necessary, but I don't know which library you are using, let alone if there is a proper check available in it.


body:
    void loop()
    {
     if (client.connect(server, port))
     {
       .......

       client.stop();
      }

     else
     {
      Serial.println("Server not found");
      }
     delay(1000);
     }


body:
If possible, do a check, if it's still connected with the server. Close the connection when work is done. You might also keep using the open connection, just try whatever works best for you.

But avoid opening a second connection, when you still have an open one. As an example:

    void loop()
    {
        if(!client.connected())
        {
            if (client.connect(server, port))
            {
                ...
                client.disconnect();
            }
            else
                Serial.println("Server not found");
        }
        else
            client.disconnect();
        delay(1000);
    }


message:
Playing audio files with sine wave from arduino

So, when searching for a way to play audio files through the Arduino, I came across this site: [How to play WAV audio files with Arduino Uno and MicroSD card][1]

This seems like a really good library (although I haven't had the time to really play around with it yet). Has anyone used this before, and, if so, is it a good library to use, or do you know of better ones out there which you would recommend?

  [1]: http://maxoffsky.com/maxoffsky-blog/how-to-play-wav-audio-files-with-arduino-uno-and-microsd-card/

body:
I used some time ago the TMRPCM library that the tutorial you linked used and I was very satisfied.

It doesn't take too much space and it has some really unique and neat features like the possibility to use two speakers instead of one to reproduce stereo audio (Unfortunately you need a more powerful AVR IC, surely not an UNO board/328 IC for this feature if you don't want to occur in bad reproduction)

From [GitHub's wiki][1]:

> All 328 based boards: Arduino Uno, Nano, Duemilanove, etc
>
> Mega Types: 1280, 2560, etc
>
> No Due support currently.

You can only have WAV files on the SD but they can be very large (other libraries limit you to a specific maximum size/duration) and you need to connect the SD to the arduino via SPI (as far as I know it is the only way to communicate directly with an SD card).

Also, you will need to convert the files to 8 bit WAV (so it's faster and easier for the arduino to reproduce the sound) with sample rate from 8 to 32khz, mono audio.

Be careful just because you'll need to power the SD with 3.3 volts otherwise you'll fry the entire card.

> Most of the extra features require more memory, more program space, and in some cases, more processing power for playback Some of them are still being fine tuned. Please keep this in mind when enabling these features.

If you want to take a look, [go to this page][2] for more informations on the advanced features

A last thing that I have to say is that the functions are really straightforward:

    TMRpcm audio;
    audio.play("filename");    plays a file
    audio.play("filename",30); plays a file starting at 30 seconds into the track
    audio.speakerPin = 11;     set to 5,6,11 or 46 for Mega, 9 for Uno, Nano, etc.
    audio.disable();           disables the timer on output pin and stops the music
    audio.stopPlayback();      stops the music, but leaves the timer running
    audio.isPlaying();         returns 1 if music playing, 0 if not
    audio.pause();             pauses/unpauses playback
    audio.quality(1);          Set 1 for 2x oversampling
    audio.volume(0);           1(up) or 0(down) to control volume
    audio.setVolume(0);        0 to 7. Set volume level
    audio.loop(1);             0 or 1. Can be changed during playback for full control of looping.

  [1]: https://github.com/TMRh20/TMRpcm/wiki
  [2]: https://github.com/TMRh20/TMRpcm/wiki/Advanced-Features


message:
arduino 16u2 stk500v2_command(): command failed

I'm trying to fix arduino uno r3 that was burned-out.
I changed m16u2 chip on it. and now I need burn in:  `Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex`
I'm using stk500v2 and connecting it to isp of arduino. Output log file of avrdude:

    C:\>avrdude -c stk500v2 -P COM4 -p m16u2 -U flash:w:1.hex -vvvv

    avrdude: Version 6.1, compiled on Mar 13 2014 at 00:09:49
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2014 Joerg Wunsch

             System wide configuration file is "C:\WinAVR-20100110\bin\avrdude.conf"

             Using Port                    : COM4
             Using Programmer              : stk500v2
    avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]
    avrdude: Recv: . [1b]
    avrdude: Recv: . [01]
    avrdude: Recv: . [00]
    avrdude: Recv: . [0b]
    avrdude: Recv: . [0e]
    avrdude: Recv: . [01]
    avrdude: Recv: . [00]
    avrdude: Recv: . [08]
    avrdude: Recv: A [41]
    avrdude: Recv: V [56]
    avrdude: Recv: R [52]
    avrdude: Recv: I [49]
    avrdude: Recv: S [53]
    avrdude: Recv: P [50]
    avrdude: Recv: _ [5f]
    avrdude: Recv: 2 [32]
    avrdude: Recv: t [74]
    avrdude: stk500v2_getsync(): found AVRISP programmer
             AVR Part                      : ATmega16U2
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PC6
             RESET disposition             : possible i/o
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max
    W   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
    -- ---------
               eeprom        65    20     4    0 no        512    4    128  9000  90
    00 0x00 0x00
                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max
    W   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
    -- ---------
               flash         65     6   128    0 yes     16384  128    128  4500  45
    00 0x00 0x00
                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max
    W   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
    -- ---------
               lfuse          0     0     0    0 no          1    0      0  9000  90
    00 0x00 0x00
                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max
    W   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
    -- ---------
               hfuse          0     0     0    0 no          1    0      0  9000  90
    00 0x00 0x00
                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max
    W   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
    -- ---------
               efuse          0     0     0    0 no          1    0      0  9000  90
    00 0x00 0x00
                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max
    W   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
    -- ---------
               lock           0     0     0    0 no          1    0      0  9000  90
    00 0x00 0x00
                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max
    W   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
    -- ---------
               calibration    0     0     0    0 no          1    0      0     0
     0 0x00 0x00
                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max
    W   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
    -- ---------
               signature      0     0     0    0 no          3    0      0     0
     0 0x00 0x00

             Programmer Type : STK500V2
             Description     : Atmel STK500 Version 2.x firmware
             Programmer Model: AVRISP
    avrdude: Send: . [1b] . [02] . [00] . [02] . [0e] . [03] . [90] . [86]
    avrdude: Recv: . [1b]
    avrdude: Recv: . [02]
    avrdude: Recv: . [00]
    avrdude: Recv: . [03]
    avrdude: Recv: . [0e]
    avrdude: Recv: . [03]
    avrdude: Recv: . [00]
    avrdude: Recv: . [02]
    avrdude: Recv: . [15]
    avrdude: Send: . [1b] . [03] . [00] . [02] . [0e] . [03] . [91] . [86]
    avrdude: Recv: . [1b]
    avrdude: Recv: . [03]
    avrdude: Recv: . [00]
    avrdude: Recv: . [03]
    avrdude: Recv: . [0e]
    avrdude: Recv: . [03]
    avrdude: Recv: . [00]
    avrdude: Recv: . [02]
    avrdude: Recv: . [14]
    avrdude: Send: . [1b] . [04] . [00] . [02] . [0e] . [03] . [92] . [82]
    avrdude: Recv: . [1b]
    avrdude: Recv: . [04]
    avrdude: Recv: . [00]
    avrdude: Recv: . [03]
    avrdude: Recv: . [0e]
    avrdude: Recv: . [03]
    avrdude: Recv: . [00]
    avrdude: Recv: . [0a]
    avrdude: Recv: . [1b]
             Hardware Version: 2
             Firmware Version Master : 2.10
    avrdude: Send: . [1b] . [05] . [00] . [02] . [0e] . [03] . [94] . [85]
    avrdude: Recv: . [1b]
    avrdude: Recv: . [05]
    avrdude: Recv: . [00]
    avrdude: Recv: . [03]
    avrdude: Recv: . [0e]
    avrdude: Recv: . [03]
    avrdude: Recv: . [00]
    avrdude: Recv: U [55]
    avrdude: Recv: E [45]
             Vtarget         : 8.5 V
             SCK period      : 0.1 us

    avrdude: Send: . [1b] . [06] . [00] . [0c] . [0e] . [10] . [c8] d [64] . [19]
    [20] . [00] S [53] . [03] . [ac] S [53] . [00] . [00] 5 [35]
    avrdude: Recv: . [1b]
    avrdude: Recv: . [06]
    avrdude: Recv: . [00]
    avrdude: Recv: . [02]
    avrdude: Recv: . [0e]
    avrdude: Recv: . [10]
    avrdude: Recv: . [c0]
    avrdude: Recv: . [c1]
    avrdude: stk500v2_command(): command failed
    avrdude: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.

        avrdude: Send: . [1b] . [07] . [00] . [03] . [0e] . [11] . [01] . [01] . [00]
        avrdude: Recv: . [1b]
        avrdude: Recv: . [07]
        avrdude: Recv: . [00]
        avrdude: Recv: . [02]
        avrdude: Recv: . [0e]
        avrdude: Recv: . [11]
        avrdude: Recv: . [00]
        avrdude: Recv: . [01]

        avrdude done.  Thank you.

My question is what block with error does? can it be I shorted due soldering? or maybe burned chip? any issues? how I can check?

ps. programmer works perfect. checked!

body:
Here’s a decoding of the crucial pair of messages exchanged here. Protocol is documented [on Atmel’s site](http://www.atmel.com/Images/doc2591.pdf).

Your machine sends:

    [1b]                              Beginning of message
    [06]                              Message sequence number
    [00] [0c]                         Message body length (big endian)
    [0e]                              Beginning of message body
    [10]                              Command: CMD_ENTER_PROGMODE_ISP
    [c8] [64] [19] [20] [00]          Various programming parameters
    [53]                              Response value to look for
    [03]                              Response index
    [ac] [53] [00] [00]               Enter programming mode command
    [35]                              Checksum

This causes the programmer to send the 4 bytes `0xAC 0x53 0x00 0x00` to the MCU, and look for the value `0x53` in the third of the 4 response bytes, as specified on page 260 of the [data sheet](http://www.atmel.ch/Images/doc7799.pdf). However, the programmer answers:

    [1b]                              Beginning of message
    [06]                              Sequence number (matches message previously sent)
    [00] [02]                         Response body length
    [0e]                              Beginning of response body
    [10]                              Command: CMD_ENTER_PROGMODE_ISP (Matches message)
    [c0]                              STATUS_CMD_FAILED (This is the error message)
    [c1]                              Checksum

That means that tyne very first command sent to the microcontroller “failed” (most likely by not returning the expected answer byte).


message:
Using 3.3V XBee with Arduino Pro Mini 5V Version

The Xbee requires a 3.3V power input and the Arduino Pro Mini (5V version) only provides a regulated 5V.

**Question:** What will be the simplest way to provide a 3.3V rail to the XBee from the Arduino Pro Mini?

If we use a voltage divider consisting of 2 resistors, the ratio should be 66/100, but how do we choose the resistor values?

If we choose a 3.3V voltage regulator, will the [STMicroelectronics L78L33ACZ][1] be suitable?

![enter image description here][2]

Between the voltage divider and voltage regulator, which is the preferred method? Is there a better alternative?

  [1]: http://www.st.com/web/en/resource/technical/document/datasheet/CD00000446.pdf
  [2]: https://i.stack.imgur.com/3nr5L.png

body:
This is part of a Fritzing circuit I used to control the x'mas tree lights (the relays and sensors have been snipped out) with an XBee. This circuit uses a 3.3v LDO you may have to change the capacitor values depending on your regulator specs. I chose to use a separate 5V regulator (not shown) but it will work off the Pro Mini's +5V power rail.

There are two FETs that do the actual level shifting, the bonus transistor allows you to reset the Arduino and thus gives you the ability to program it over the air via the XBee (beyond the scope of the question, but if you want to go wireless, go wireless all the way - do the Google for wireless programming over XBee if needed). Note the 0.1uF across the XBee power pins, I recommend this capacitor be placed as close to the XBee as possible to minimize noise (I solder it across the back of the XBee interface board).

![enter image description here][1]

  [1]: https://i.stack.imgur.com/PzjWI.jpg


body:
You can use a voltage regulator to get the supply voltage down to 3.3v.

For the Serial Lines, the best way forward is to use a good level convertor like https://www.sparkfun.com/products/11978 from sparkfun.

If you don't want to buy it, you can also make it using a couple of Mosfet's and resistors. Here's the [schematic](http://dlnmh9ip6v2uc.cloudfront.net/datasheets/BreakoutBoards/Logic_Level_Converter.pdf) from Sparkfun.


body:
**The simplest way**, as you ask, is probably a resitor-based [voltage divider][1]; its main drawback is the waste of energy in the resistors.

![enter image description here][2]

To calculate the "best" resistor values, you'll need to know the amount of **current** needed by the XBee module.

So you have:

- `Vin` = **5V**
- `Vout` = **3.3V**
- `Iout` = to be determined (check XBee spec sheet for that)

Then you have to resolve the following equations to calculate the resistor values you shall use:

    R1 = R2 x (Vin - Vout) / Vout
    Iout = (Vin - Vout) / R1 - Vout / R2

These equations simply come from applying Ohm's law and Kirchhoff's circuit laws.

This [site calculates the ideal resistor values][3] for you.

For `Iout` = **100mA**, it gives the following values:

- `R1 = 17 Ohm`
- `R2 = 33 Ohm`

Another **simple way** is to use a **3.3V zener diode** if you have one on hand. You can google for good circuit examples.

  [1]: http://en.wikipedia.org/wiki/Voltage_divider
  [2]: https://i.stack.imgur.com/gWyVW.png
  [3]: http://www.power-io.com/library/appnotes/voltage-divider.htm


message:
Figuring out some numbers for a mini pump

I'm just now getting into electronics (I don't know why I waited so long) and I'm just figuring out some stuff.  I picked up an Arduino kit from [Vilros.com][1] and a few other parts for my project.

I'm currently trying to work on a project that is basically a humidor keeper.  Living in So.California, it's extremely dry here and I would like a perfectly controlled environment for my humidor.  I purchased a few things like some humidity sensors (as an input obviously), a humidifier (basically a water canister with a sponge and tubes) some tube splitters and twist valves and most importantly, a small air pump.

The small air pump is what I'm having problems with at the moment.  [This is the pump][2]. Obviously it's a 3v pump.  I will be using the supplied 9v battery cable when the project is ready, so I understand I'll have to use resistors to bring the voltage down so I don't burn out the pump.  As I said, I'm new to this, so I'm trying to figure out ohms law to find out what kind of resistor(s) I will need.  The problem is, I don't know the amperage.  Where would I find this?

I looked at the details for the pump and what looks like amps (or milliamps) is really just the product number.  Can anyone help me out?

Right now, I have my equation as r=6v / ?i  But where do I find the current?

  [1]: http://www.vilros.com/arduino/uno-rev-3/ultimate-starter-kit.html
  [2]: http://www.amazon.com/dp/B00FHABXE0/ref=pe_385040_30332200_TE_item#productDetails

body:
Unlike voltage, which depends on the source, the current depends on the motor itself. To find the current, you need to run the motor and measure it with a multimeter:

                  +------------+
        +---------+ Multimeter |
        |         +--------+---+
    +---+---+              |
    | Motor |              |
    +---+---+  +--------+  |
        |      | Power  +--+
        +------+ source |
               +--------+

Note that when the motor is actually pumping, it will draw more current.


body:
There are two serious problems with your approach, which you will need to change in order to end up with a sound solution.

- If by "9v battery cable" you mean that you intend to use a 9v battery, this is highly unsuitable for motor applications given its low power storage capacity and high internal impedance - without extreme care to use sleep modes, it probably can't even run the Arduino alone for a week.  It would be much more appropriate to use a larger capacity lower voltage source - 4 or 5 C or D cells for example.  A power supply could be another option, though given the water involved, be very careful to pick an isolated one and use a ground fault protected outlet.

- Resistors are a poor way of reducing the supply voltage to a motor, as they are not only wasteful, but the applied power will depend too much on the load.  A professional solution would use pulse with modulation to apply the supply voltage at a reduced duty cycle - something you can try with one the various motor shield, but you will need to be careful not to overheat the motor by using too high a duty cycle.

Probably your best bet would be to buy a pump with a 6 or 7v motor (as is showing up in the associated products at the bottom of that page), or even replace the standard-form-factor motor in that pump with a higher voltage one.  A 7v or so supply voltage can then be a compromise solution for running both the motor and the arduino.


message:
If I put a shield on an Arduino, can I use the Arduino for anything else?

I did some basic Arduino examples in the recent past, but I have never actually seen a shield for Arduino firsthand.

So I wonder: If I put a shield on an Arduino (for example, the Adafruit Motor Shield), does it "block" the entire Arduino, including all input and output pins?

Is it possible to use a shield, and still connect additional components that would usually connect directly to the Arduino (say, a potentiometer, or anything similar)? Does this depend on the type of Arduino, or on the type of the shield, or is it not possible at all?

body: As long as the shield uses stackable headers (or provides alternate headers) it doesn't block *any* (broken out) pins, either input or output. It is possible to add more shields or components, but the circuit must still be "valid" (all inputs must be either be connected to an output or have the pullup enabled, no more than one push-pull output connected together, etc.), otherwise components may be damaged.


body:
Normally, yes, you may plug other components to your setup after you plug your shield, but it depends on the shield exposing the unused Arduino pins through additional female headers.

Some shields even provide a little protoboard or perfboard to make it convenient for plugging or soldering additional components. Below are some examples:

![Example of an Arduino protoboard shield][1]
![Example of an Arduino perfoboard shield][2]

Arduino shields are normally designed to be stackable, so you can plug one on top of the other. See [more on Arduino shields](http://en.wikipedia.org/wiki/Arduino#Shields) from this WikiPedia article. See below one example of stacked shields, shamefully stolen from [this great answer by RedGrittyBrick](https://arduino.stackexchange.com/a/1399/46).

![Example of many Arduino shields stacked together][3]
<sup>*Photo by [John Boxall](http://tronixstuff.com/)*</sup>

But note that **you need to study carefully what pins each of the shields use to avoid conflicts between the boards**. Such conflicts may lead to damages.

  [1]: https://i.stack.imgur.com/mHAiC.jpg
  [2]: https://i.stack.imgur.com/VbYmJ.jpg
  [3]: https://i.stack.imgur.com/I7hXM.jpg


body:
There are several distinct concerns to consider:

- **Physical interference:** are headers provided to make it possible to stack the two shields on top of one another?  Do any protruding components block stacking?  Do any components have metal shield cans (for example the USB connector on the Uno itself) which can short out an adjacent PCB?

- **Pin assignments:** generally you cannot use the same pin for two different purposes.  Many shield provide a way to alter the pins used in order to avoid those used by another shield.  Sometimes you can share a pin, for example two SPI devices can usually share their clock and data lines provided they have separate selects, and you may be able to even use those signals for other purposes while the SPI select is de-asserted.  Sometimes you can move a part from an unavailable hardware peripheral to a software emulated one, for example using software serial, bitbang SPI, or interrupt based PWM.

- **MCU resources:** Not specifically the shields themselves, but driver libraries may end up consuming large amounts of program memory or RAM, using up timer channels, needing interrupts frequently services with low latency, etc, so combinations may not be possible or may require alterations to library code.


body:
Yes, but sometimes it interferes with the output and the input pin, and most shields use up the
CS, MOSI, MISO, SCK pin. Even through on some shields like wireless SD shield you can switch from USB to MICRO, this is going to interfere with your program. Say, when you want to access
the info on your SD card to run your Motor Shield.


message:
How to receive data from my server database to a variable in my Arduino?

I am learning to work with the client - server communication. I am able to communicate with my server and able to store values in the table. But I want to receive one of the specific data from the database.

Here I want to get the 'abc' value from the 'Current' column to store in a variable in my Arduino.

Below is the code that I have done until now. I would be really happy if you could solve the problem.

Here is my database structure

    ---------------------------------------------------
    | Device |  Previous |  Next |  Distance |  Current|
    ---------------------------------------------------
    |katup123| xyz       | abc   | 2.600     | abc     |
    ---------------------------------------------------

Here is my PHP code:

locator.php

    <?php
    $con=mysqli_connect("your_domain.com","peter","abc123","locate");
    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysqli_query($con,"SELECT Current FROM locate WHERE Device='katup123'");

    while($row = mysqli_fetch_array($result)) {
      echo $row['Current'];
      echo "<br>";
    }
    ?>

Here is my Arduino code:

    // Include the GSM library
    #include <GSM.h>
    #define PINNUMBER ""
    // APN data
    #define GPRS_APN       "GPRS_APN" // replace your GPRS APNgpsll
    #define GPRS_LOGIN     "login"    // replace with your GPRS login
    #define GPRS_PASSWORD  "password" // replace with your GPRS password
    // initialize the library instance
    GSM gsmAccess;
    GSMClient client;
    GPRS gprs;
    // URL, path & port (for example: arduino.cc)
    char server[] = "your_domain.com";
    char path[] = "/locater.php";
    int port = 80; // port 80 is the default for HTTP

    void setup() {
      Serial.begin(9600);
      Serial.println("Starting Arduino web client.");
      // connection state
      boolean notConnected = true;
      // Start GSM shield
      // If your SIM has PIN, pass it as a parameter of begin() in quotes
      while(notConnected) {
        if((gsmAccess.begin(PINNUMBER)==GSM_READY) & (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
          notConnected = false;
        else {
          Serial.println("Not connected");
          delay(1000);
        }
      }
      Serial.println("GSM initialized");
      Serial.println("connecting...");
    }

    void loop() {
      char result [20];
      Serial.print(" Connecting to server Database ");
      if (client.connect(server, port)) {
        client.print("GET /locator.php?");
        Serial.print("GET /locator.php?");
        client.println(" HTTP/1.1");
        Serial.println(" HTTP/1.1");
        client.println("Host: www.your_domain.com");
        Serial.println("Host: www.your_domain.com");
        client.println("User-Agent: Arduino");
        Serial.println("User-Agent: Arduino");
        client.println("Accept: text/html");
        Serial.println("Accept: text/html");
        client.println("Connection: close");
        Serial.println("Connection: close");
        client.println();
        Serial.println();
        Serial.println("\nCOMPLETE!\n");
        client.stop();
      } else {
        Serial.println("connection failed");
        Serial.println("\n FAILED!\n");
      }
      delay(5000);
    }

Here I want to store the 'abc' value to my 'result' variable. I don't know how to do it.

body:
If you have your Arduino on tcp/ip your answer can be found in O'Reilly's Arduino Cookbook: [Recipe 15-4][1].  As Sourcery mentioned you need to make a new page on the PHP side that spits out just the data you are looking for and then use a web client on the Arduino side to download that data.

If you don't have your Arduino on the network then you have to stick the data over the serial line.  One way would be to bake it into your source and recompile/reburn the Arduino.  A smaller hammer would be to build-in something to your Arduino sketch that can deal with getting the data via USB serial and have a shim on the computer side to pull the data from PHP and send it to the Arduino.  [Serial communication with Arduino and Processing][2] shows something similar where he is running Processing on the computer which is passing data to the Arduino.

  [1]: https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-15/recipe-15-4 "Recipe 15-4"
  [2]: http://www.varesano.net/blog/fabio/serial-communication-arduino-and-processing-simple-examples-and-arduino-based-gamepad-int


body:
After you send the GET request, you read the response to fill the `char result [20]` variable you declared:

    int i=0;
    ...
    if (client.connect(server, port))
    {
      client.print("GET /locator.php?");
      ...
      Serial.println("\nCOMPLETE!\n");

      // Read response from server
      i=0;
      while (client.available())
      {
        result[i] = client.read();
        Serial.print(result[i]);
        i++;
      }

      client.stop(); // disconnect
    }

This is an example, `result` will contain the text output by locator.php. You will need to tweak this code to apply to your case. The above code has no error checking of any kind. Also, you should perform a check and only make the web call one time.

In locator.php you should replace `echo "<br/>";` with `echo "\n";`. And for good measure, make sure there is no white space before `<?`, and remove the trailing `?>`.


message:
Can I speed up the Leonardo bootloader?

Inspired by an example question before beta, can I make the Leonardo bootloader take less that 8 seconds to run? It is very slow and I want to speed it up somehow.

body:
Detailed instructions on how to shorten the bootloader time of Leonardo etc. are explained [[here]][1] (as stated by @Chris Stratton).

The crux of the matter was to redefine the timeout period

    /* ./arduino/hardware/arduino/bootloaders/caterina/Caterina.c */
    #define TIMEOUT_PERIOD 8000

to a lower value.

However I do not have such issues with Leonardo it boots very fast.
So this issue depends on your environment.

There is also **OptiBoot**, an alternative bootloader that really boots faster [link][2]:

[1]: http://www.leonardomiliani.com/en/2013/accorciamo-i-tempi-del-bootloader-della-leonardomicroesplora/
[2]: https://code.google.com/p/optiboot/


message:
How to map PID output to actuator control?

I'm building a control system for the heating of a house. A sensor reads the temperature inside and is then used as the input in the PID control. The temperature is then controlled by a servo which opens and closes a shunt were water runs to the radiators. I understand all the inner workings of the PID library for Arduino and PID in general, but **the thing I don't understand is what I'm exactly supposed to do with the output signal I receive. In what way should the output signal correspond to how open or closed the shunt is?**

I understand I can simply map the output signal to the servo signal, but is this the correct way? And with what angle coefficient should I map it with, cause that is basically set with the P parameter, isn't it? Is there some standard way to map the output signal to the actuator "signal", so that that tuning parameters are somewhat "standard".

Hope someone understands anything of what I tried to explain :)

body:
I don't think you would need to use a PID library (or any control loop for that matter) to control a radiator. You could use a simple threshold code, like this:

**Pseudocode:**

    Check temperature
    If radiator is off and temperature > (ideal temp - threshold)
      turn radiator on
    If radiator is on and temperature > (ideal temp + threshold)
      turn radiator off


body:
If you can't find some actual info regarding applying PID to a water-based radiator system, then I'd suggest the following principles.

First, I assume that the output of the PID algorithm appears as an An Arduino PWM output at some rate. This could be a fast rate, like in the hundreds of Hz (if the load is DC), or fractions of Hz, or even 10 sec or more cycle time.

Next, I assume that the PID algorithm is likely designed to expect that a linear change in output has a linear effect on the heating output. That is to say, as though it's controlling an electric heater, where, for example, 25% ON-time produces 25% of full heat output.

If these are true, then you need to determine how that relates to what you can control on your shunt valve.

Is it acceptable for the valve to be turned full on/off on a proportion-of-10-seconds basis? Probably not.

Can the valve be set to an intermittent position if fed with a 10 Hz or 100 Hz PWM signal, perhaps so.

If the latter, then a further question is how does the PWM range of values correspond to actual angle of the valve, and more to the point, how does it correspond to flow rate, and ultimately to heat delivery. Perhaps a 33% PWM signal is required to deliver 25% of the full-range heat, for example.

(At a guess, I'd assume that heat delivery is proportional to flow, but as I think you anticipate, flow is not proportional to valve angle.)

You might just mock up your system, program the Arduino to output particular PWM values to the valve, and measure the resulting flow, and if possible, heat delivery. Then, interpose in the PID library the inverse function, perhaps as a lookup table.

So when the PID library wants to command 25%, that number gets looked up in the table, which (continuing my example) translates it to a 33% PWM signal, and your program sends that value to the PWM output.

Hope that provides some ideas.


message:
Is the Sparkfun RedBoard pre-loaded with a blink sketch?

As soon as I plugged my brand new RedBoard (Sparkfun's Uno) into my computer, I saw the onboard LED (for pin 13) blink on and off every 1 second. This was before I even sent the first demo sketch to blink the LED. After I uploaded a sketch to change the blink time, the LED's blink cycle changed as I expected.

But why was the LED blinking *before* I sent my very first sketch? Is the RedBoard pre-loaded with a sketch?

body: Yes, the RedBoard is preloaded with the blink sketch (or at least the two that I've purchased have been).


message:
Arduino sizeof Servo array objects is.. wrong?

After searching *for a quite long while* over the internet, I have no choice but to try asking someone if they can explain me this apparently strange situation.

I'm doing some tests using some servo motors, trying to move them almost together using `millis()` and `Servo` object.

It is, of course, working either for single Servos and multiple servos.

The case, more detailed, is about this:

 1. Move one, two or more servo motors together.
 2. Force them to take ALMOST the same time to accomplish any action.
 3. Have a dynamic number of servos.

About the first two points I had no problems to solve them, I was easily able to make a function and then make a library to accomplish such a job.

However, since I'm NOT that used to C++ and I was wondering if it actually was possible to create an array of Servo objects, like you can actually do, on arduino, with strings:

    String stringArray[] = {"string1", "string2", "and so on, I love it."};

So, after wondering a while, I've tried this:

    Servo servObject;
    Servo servObject_2;
    Servo servObject_3;

    Servo servos[] = {servObject, servObject_2, servObject_3};

And you know what's cool? my function is actually working correctly by forcing the amount of elements of the servos array.

What I mean by that is that if I force my function to know that it is going to have 3 elements into the array it will, of course, work; However, for some reason, if I use `sizeof(servos);` the value returned, surprisingly, is `2`....
Moreover, if I only push two servo objects instead of three into the servo array, its `sizeof` returns `6`.

By googling, I've found out a couple of discussions about the fact that, for some reasons, in some cases, sizeof returns an incorrect value (if I'm not wrong it was the correct value -1), but in my case it apparently is not following any logic at all.

The board I'm using is an Arduino nano w/ ATMEGA 328.

Any idea of why it is not returning the correct value? Am I actually going totally wrong because I shouldn't make an array of servo objects?

ps: I didn't post the whole code because it would've been useless, since the sizeof is the first function called in the `loop()`

Regards,

briosheje

body:
What you describe seems to be a common issue that many C or C++ developers can get (or have got) with `sizeof`.

Take a look at the following code:

    char a[3];

    int size(char b[]) {
        return sizeof b;
    }

    void setup() {
        int size1 = sizeof a;
        int size2 = size(a);
    }

In that code, `size1` will be evaluated, by the compiler, to `3` which is the real size of `a` variable, whereas `size2` will be `2`.

## Why so?

This is just because `sizeof a` is evaluated by the compiler, and the compiler *knows* that `a` is an array of 3 `char`; but when `a` is passed as an argument to function `size()`, it is converted to a pointer (to the first element of the array), hence its size is the **size of a pointer**, which is `2` bytes on AVR ATmega MCU.

This subtlety of `sizeof` may explain strange values as you describe.

## How to fix the issue?

Most C functions that take an array as argument will require another argument that tells the size of the array; that's the way (the only one I think) to deal with this problem.

Here is a sample code:

    Servo allServos[] = {...};
    #define NUM_SERVOS (sizeof(allServos) / sizeof(Servo))
    ...
    void handleServos(Servo *servos, int numServos) {
        for (int i = 0; i < numServos; i++) {
            servos[i].write(...);
            ...
        }
    }

    void loop() {
        handleServos(allServos, NUM_SERVOS);
    }

It is common practice in C to **declare an array** and immediately after, **define its size** as above.


message:
How to read a Text file from server and store to a separate variable?

I am working on reading a text file from the server, using http://arduino.cc/en/Reference/GSMClientConnected. It gives me this code:

    char path[]="/asciilogo.txt"

I want to store only the contents that are inside the text file to a variable (String). But `client.read();` only reads a single character at a time. Also, it takes all the HTTP, GET, TIME parameters together.

How to store only the contents that are present in the text file to a string variable?

body:
Here is what I found:

You need to have a special character like  "*" (a delimiter), from which important data will flow through.

    char z = '*';
    int s=0;

    void setup()
    {
      // usual initialization
    }

    void loop()
    {
      if (client.available())
      {
        char c = client.read();
        // Serial.print(c);
        if (z == c)
        {
          s=1;
        }

      if(s == 1)
      {
        int i=0;
        k[i] = c;
        i=i+1;
        // Serial.print(k);
      }

      place +=k;

      Serial.print(place);

      }

    .......
    }


message:
What is the advantage of using a motor shield if I want to use a stepper motor?

I know that it is possible to connect a stepper motor directly to an arduino ([as displayed here][1]). I know that another option is to use a motor shield (for example the [Arduino Motor Shield][2] or the [Adafruit Motor Shield][3]).

What I would like to know: What are the actual advantages of using a motor shield?

Is it just a question of convenience? Or does a motor shield do something that could not easily performed without a shield? Does it allow me to connect more motors than I could connect directly without a shield (power supply comes to mind)?

  [1]: http://arduino.cc/en/Tutorial/StepperUnipolar
  [2]: http://arduino.cc/de/Main/ArduinoMotorShieldR3
  [3]: http://www.adafruit.com/product/1438

body:
The example you linked to isn't actually connecting the Arduino *directly* to a stepper motor. It's going via a ULN2003A driver. That's a very common Darlington transistor array, which basically just lets you use a small current to switch a larger load.

That's necessary because the Arduino pins can't safely source enough current to drive the stepper motor directly. It might work for a while, but it would damage your Arduino sooner or later.

Motor shields usually have a similar driver in them, but can also provide additional functionality which you might find useful. For example, the Adafruit shield you linked to is controlled by the I2C bus, and has its own on-board PWM. That means you can control several motors without needing any extra output pins on your Arduino.

In short, motor shields aren't necessary. They can be helpful though, especially if you aren't familiar with the underlying electronics, or you don't want to build it yourself.


body: Mechanical stability of the whole thing is probably the main advantage. I'd personally opt for a generic module or loose components. The main disadvantage of shields is pin conflicts when using more than one shield.


body:
I'm using a adafruit motorshield v2 for my solar tracker project with two stepper motors atm.
i'm quite a new to arduino and coding and i think the shield made it a lot easier for me to get a hang of it - easy to code and nicely stack able on the ardiuno (little soldering to assemble but not too difficult).


message:
GSM and GPS shield pin conflict

I have an [Arduino GSM shield][1] and I plan to purchase an [Adafruit GPS shield][2]. The GPS module uses Pin 7 & 8 for Rx and Tx, but the GSM shield uses Pin 7 for Modem Reset.

Will the overlap on pin 7 affect it in any way? If it does cause issues, how can the problem be avoided?

  [1]: http://arduino.cc/en/Main/ArduinoGSMShield
  [2]: http://www.adafruit.com/products/1272

body:
Looking at the [PDF for the Adafruit GPS shield][1], pin 7 is indeed hard wired to `Rx` and pin 8 is hard wired to `Tx`.

![Adafruit GPS shield PCB][2]

These can not be changed.

Looking at the [guide for the Arduino GSM shield][3] pin 7 is indeed reserved for modem reset:

> Digital pins 2, 3 and 7 are reserved for communication between the
> Arduino and modem and cannot be used by your sketches. Communication
> between the moden and Arduino is handled by the Software Serial
> library on pins 2 and 3. Pin 7 is used for the modem reset.

As this is the case, should you stack the two shields together, without modification, then the *overlap of the `Rx` pin on the GPS shield will cause resets to the modem on the GSM shield*.

So, it seems that your best option is to use the solution provided by RedGrittyBrick, to your previous question [Arduino shield stacking][4], the Go-Between Shield

> You hear it all the time in the Arduino community, “will this shield
> work with my other shield?.” I think we’ve all been disappointed to
> find that two of our favorite shields compete for control of a digital
> pin here or a serial pin there. While there are sometimes some clever
> workarounds from elegant code modifications to aggressive
> ‘greenwiring,’ Mayhew Labs may have come up with the simplest solution
> thus far: The Go-Between Shield.

Once you have used the Go-Between shield to reassign the `Rx` pin to something that the GSM shield does not use, (as 2, 3 and 7 are already used, let's say you use pin 6), then in the **File -> Examples -> Adafruit_GPS -> Parsing** sketch, you will need to change the line

    SoftwareSerial mySerial(3,2);

to

    SoftwareSerial mySerial(8,6);

instead of

    SoftwareSerial mySerial(8,7);

which is recommended in the PDF.

I hope that this answers your question(s). Let us know how you get on.

----

### Addenum

The [schematic of the Arduino GSM shield][5]:
![enter image description here][6]

The [schematic of the Adafruit GPS shield][7]:
![schematic of the Adafruit GPS shield][8]

  [1]: http://learn.adafruit.com/downloads/pdf/adafruit-ultimate-gps-logger-shield.pdf
  [2]: https://i.stack.imgur.com/hSuip.png
  [3]: http://arduino.cc/en/Guide/ArduinoGSMShield
  [4]: http://Arduino shield stacking
  [5]: http://arduino.cc/en/uploads/Main/arduino-gsm-shield-schematic.pdf
  [6]: https://i.stack.imgur.com/7ttFF.png
  [7]: http://learn.adafruit.com/downloads/pdf/adafruit-ultimate-gps-logger-shield.pdf
  [8]: https://i.stack.imgur.com/AyYlo.png


message:
How Do I Properly Ground my Arduino Leonardo using Capacitive Sensor?

Hi we are using Arduino Leonardo with some electric paint and [Capacitive Sensor Libraries][1]. We have a lot of variance in our Serial output from our sensors, we believe if we grounded the Arduino we would have more concrete values.

On the Capacitive Sensor doc, it reveals to use a small capacitor to put on one of the pins. More details!
Another guide somewhere says to wrap the Arduino in plastic and tin foil. These are vague, and we have not landed success when we tried.

Has anyone had success grounding Arduino Leo? Thank you.

  [1]: http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense

body: The simplest way to ground an Arduino is to attach the ground pin, found on the power header, to a grounded surface, like a metal pipe. As for the capacitor you mentioned, that is called a smoothing capacitor. It is a small capacitor, about 1microfarad, and goes between the supply of the sensor and the ground line.


body:
The documentation for that library is recommending that you place a 100 pF capacitor between the sense pin and ground.

However, I personally suspect you will get the best results when the user's presence affects at small mutual capacitance between a sense surface and a ground surface.

One idea could be to have a large ground plane, and on it a smaller insulated "sense" plate.

Another could be to run two parallel traces in a spiral filling a large area

Do take care to secure you wires - they are part of your sensor too, and if they move relative to each other they will alter the baseline.  Any other mobile cables in the vicinity can have the same effect, especially if they contain a ground that can exhibit capacitance to the sense node.

  [1]: http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense


message:
Receive SMS example gives me a garbage values

When I run my [Receive SMS][1] example code, By default every time I get the same thing.I am trying to send sms to my sim card present in the Arduino GSM shield. I don't want this message. How to solve this problem ?

![enter image description here][2]

I

  [1]: http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS
  [2]: https://i.stack.imgur.com/gGZKX.png

body:
Most Telecom operators agree for sending advertisements and promotions to their customers for certain business and some money. You can stop these promotion for your mobile by making (Do Not Disturb)DND active. In India, just do the following for DND Activation

     ( Fully Blocked Category )

     Send SMS at START 0 to 1909 or Call at 1909

     Partial Blocked Category

    Send SMS at START 1 to 1909 to block Banking – Insurance – Financial Products – Credit Cards
    Send SMS at START 2 to 1909 to block Real Estate
    Send SMS at START 3 to 1909 to block Education
    Send SMS at START 4 to 1909 to block Health
    Send SMS at START 5 to 1909 to block Consumer Goods & Automobiles
    Send SMS at START 6 to 1909 to block Communication – Broadcasting – Entertainment – IT
    Send SMS at START 7 to 1909 to block Tourism

- See more at: http://www.techsiren.com/how-to-activate-do-not-disturb-india-registration/#sthash.F87Pfj5V.dpuf


message:
What's the deal with Uno's pin 13 LED?

(I have a Sparkfun RedBoard, but this question seems to apply to R3 Unos and Uno-compatible boards.) As I was building the first circuit in my SIK guidebook (add a resistor, LED, hook it up and make it blink from code), I noticed a blue LED on the board itself did everything that the circuit's LED did - blinking according to the programming.

Why is this LED here? What use cases is it for?

What kind of circuits will I have to adjust to account for this LED?

Is pin 13 traditionally a debug or a troubleshooting pin? Where did this convention come from?

body:
The LED on pin 13 is used by the **optiboot** loader (the one used on **UNO**):

- at Arduino **boot time** (the LED blinks a few times)
- when **uploading a sketch** to Arduino

I haven't checked other bootloaders, they may provide the same behavior as the optiboot.

For optiboot, there are optional defines (at compile time) to modify this behavior:

- `LED_START_FLASHES` defines the number of flashes of pin 13 LED at boot time (can be set to `0`)
- `LED_DATA_FLASH` will use pin 13 LED during sketch upload if **defined** at compile-time

These defines are explained in `hardware/arduino/bootloaders/optiboot/optiboot.c` from within your Arduino IDE install directory.

If you want to change these, you will have to recompile the optiboot loader first and then burn it to your Arduino through an **ISP programmer**.

I guess one other reason for the LED on pin 13 was to simplify the demonstration of the "*Hello World*" sketch for Arduino, namely the `Blink` sketch, without the need for any extra component.


body:
Yes, pin 13 is traditionally an output pin that drives an LED. But the blue LED should not be blinking as it is the "power on" indicator - do you have a grunty power supply to your board?

You can experiment with PWM to the pin13 LED, which will control its apparent brightness. There are plenty of example sketches on the web.


body:
> What kind of circuits will I have to adjust to account for this LED?

You'll need to take it into account if you're using that pin as a digital input.

> NOTE: Digital pin 13 is harder to use as a digital input than the
> other digital pins because it has an LED and resistor attached to it
> that's soldered to the board on most boards. If you enable its
> internal 20k pull-up resistor, it will hang at around 1.7V instead of
> the expected 5V because the onboard LED and series resistor pull the
> voltage level down, meaning it always returns LOW. If you must use pin
> 13 as a digital input, set its pinMode() to INPUT and use an external
> pull down resistor. <sub>[Arduino - DigitalPins][1]</sub>

  [1]: http://arduino.cc/en/Tutorial/DigitalPins


body:
What everyone else said, plus: if you find the digital-13 LED gives you a problem, you can always remove it from the circuit, either by removing the LED, or the series resistor.

This might be useful if you are running out of digital I/Os, or you want several contiguous I/O bits and don't want one of them to behave differently from the others.


message:
Can I turn off a device using the 5V and analog pins?

Could I connect a device that requires minimum 5V 1A from the 5V Pin to the Ground and somehow turn it off inside  a sketch?

edit: I'm using a Due based boad, the digix http://digistump.com/wiki/digix/tutorials/basics

body:
*Short answer: NO*. It would fry your Arduino.

*Long answer:*

The current of Arduino pins is very limited (40mA max on UNO).

If you need to draw 1A, then you need a *transistor* between the Arduino pin and your device.

In such case, what you would normally do is:

- connect any Arduino logical pin to the transistor base (through a resistor),
- plug your device between a 5V supply (capable of 1A current providing) and the transistor collector,
- connect the transistor emitter to the Arduino GND pin (and connect that pin also to the 5V-1A supply)

Note that **you don't need to use an analog pin** for that, a logical pin is enough if you just want to switch the device on or off.

Now notice that I specified **a 5V 1A supply**, that should normally be **distinct** from the 5V pin of the Arduino.

So the next question is: **can you draw 1A out of the Arduino 5V pin?**

The [Arduino UNO page][1] does not specify the current limitation on that pin. However it mentions the following:

> 5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V).

So the max current on this pin depends on 2 factors:

- what is the power supply for the board: it is either USB, or an external power supply, which can be connected to the power plug or to the Vin pin.
- the specs of the 5V regulator voltage on the Arduino board

If you use USB as power supply, then you are limited to **500mA** as stated in the Arduino UNO page:

> The Arduino Uno has a resettable polyfuse that protects your computer's USB ports from shorts and overcurrent. Although most computers provide their own internal protection, the fuse provides an extra layer of protection. If more than 500 mA is applied to the USB port, the fuse will automatically break the connection until the short or overload is removed.

If you use an external power supply that provides at least 1A, then we have to find out the max current by ourselves.

If we take a look at [Arduino UNO schematics][2], then we see that this regulator is referenced as "**NCP1117ST50T3G**" (this is "**U1**" on the top-right corner).

The [spec sheet for this regulator][3] mentions that it can supply **1.0A**.

So in theory, that should work, however, you also have to consider that this regulator **also** supplies current to the Arduino borard itself and all its pins.

If you love your Arduino and don't want to fry it, you should probably stay away from using its 5V pin for your purposes.

Now if you're open to experiment, you may try it :-)

  [1]: http://arduino.cc/en/Main/ArduinoBoardUno
  [2]: http://arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf
  [3]: http://www.onsemi.com/pub_link/Collateral/NCP1117-D.PDF


body:
You would use a transistor. Something like this would work.

In this case the Arduino controls a transistor to drive a brushless motor.

Source: Arduino Cookbook: (https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-8/figure-8-9)

Update:
For the sake of clarity I should point out that the TIP102 is the device to use for the 1A required (not the 2N2222). And as pointed out by others the 5V supply of most Arduino boards would not be sufficient to supply 1A, so an external supply would be advised.

![enter image description here][1]

  [1]: https://i.stack.imgur.com/JqfF7.png


body:
The simpler solution is to power Arduino from some external supply, then fork that power through a relay to controlled device.

Then you can switch the device by controlling that relay through your digital pin.