message:
What are the main differences between the Arduino Tre and the Intel Galileo?

I'm looking to find a suitable board for a robot I'm developing (it'll involve computer vision, else I'd be using my Arduino Micro) and I've come across two possibilities: [The Intel Galileo][1] and the [Arduino Tre][2].

Now as I understand it, the Intel Galileo has a 400MHz Quark processor, whilst the Arduino Tre has 2 processors, an onboard 16MHz standard ATmega32u4 with the Arduino bootloader and then another 1GHz TI processor with Linux installed on it.

However, I'm not sure of the differences between both products, as price estimates appear to place them at approximately the same price (around $70) and the Intel Galileo doesn't appear to have any real advantage over the Arduino Tre (except for a full x86 instruction set).

Does anyone have any information on comparison of the two boards so I can make a better informed decision?

  [1]: http://store.arduino.cc/index.php?main_page=product_info&products_id=522
  [2]: http://arduino.cc/en/Main/ArduinoBoardTre

body:
## Biggest difference IMHO: Tre hasn't been released yet!
Besides that, there are a few different things that you should compare. Not much is available about the Tre as of now, but I'll update this post when it's released.

****
## *Basic Specs:* [First sub-bullet is TRE, second Galileo; better spec in bold]
 - Microcontroller:
  - Texas Instrument Sitara AM3359AZCZ100 (ARM Cortex-A8) (**1 GHz,** 32 bit), Atmel ATmega32u4 (16 MHz, Secondary, found on Leonardo)
  - Intel® Quark SoC X1000 (400 MHz, 32 bit)
 - RAM:
  - 512 MB SRAM (2.5 KB ATmega32u4)
  - 512 MB SRAM
 - Pins
  - **14 Digital 5V, 7 of which are PWM, 6 analog 5V (additional 6 multiplexed) (32u4); 12 Digital 3.3V, 4 of those are PWM (Sitara)**
  - 14 5V digital, 6 of those are PWM, 6 analog 5V
 - Networking:
  - Ethernet 10/100
  - Ethernet 10/100
 - USB port:
  - 1 USB as slave, 4 USB host ports
  - Up to 128 devices as host, 1 USB slave
 - Video
  - **HDMI (1920x1080), LCD header**
  - None that I can find
 - Audio
  - HDMI, stereo analog audio input and output
  - None that I can find
 - MicroSD card
  - Yes
  - Yes
 - PCIe Slot
  - No
  - **Yes**

Sources (I combined a bunch of data for this): [Galileo](https://arduino.cc/en/ArduinoCertified/IntelGalileo) & [Tre](https://arduino.cc/en/Main/ArduinoBoardTre)
****
**Conclusion:** If you need a board before the Tre comes out, which seems to be soon (Spring 2014), Galileo is your only option. Other than that, the Tre seems to be better all around in most aspects, minus the PCIe slot. I can't comment on power, but it seems like the Tre will be able to supply 4x the power per pin than the Galileo. The Galileo is getting older, and it doesn't seem like the Galileo can provide full Linux support like the Tre will.

Personally, I'd wait for the Tre. The *only* thing I can think that the Galileo would be better for would be either a.) lower power usage or b.) the PCIe slot for a WiFi adapter that works decently. The second one could be solved by [doing a common WiFi router hack](http://www.instructables.com/id/Cheap-and-Easy-Arduino-Wi-Fi-Hack/0).

If you need a lot of processing power without the need of low latency, you should conciser sending data to a computer to process.

>

[Source](https://arduino.cc/en/uploads/Main/ArduinoTre_LandingPage.jpg)
>

[Source](https://arduino.cc/en/uploads/ArduinoCertified/IntelGalileo_fabD_Front.jpg)


sender: user

message:
Changing pins used in ArduinoISP example

I have built my own ATTiny programmer, but made a bit of a mistake along the way - I didn't align the headers properly, and now instead of them plugging into pins 10, 11, 12 and 13 as per the ArduinoISP example - they now plug into pins 8, 9, 10 and 11.

If I use some jumper cables to wire the pins to match the ArduinoISP example, it all works fine, meaning the wiring on the actual board is OK, however, I want to be able to just plug my board I have made straight in, and thus need to get the bootloader burning and the uploading to work via pins 8, 9, 10 and 11 instead.

I have tried modifying the example myself by replacing the references to RESET, MOSI, MISO and SCK with my own pin numbers, but this doesn't seem to suffice. When I try to burn the bootloader now, I get the following error:

    avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
    avrdude: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.

    avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

If I try to upload a sketch using my version which has the custom pin numbers, I get this error:

    avrdude: stk500_getsync(): not in sync: resp=0x00

The wiring of my programmer is the same as can be found here: http://highlowtech.org/?p=1706 except I want the programmer sketch to work with different pins.

Thanks

sender: assistant

body:
You can't change the pins.

ArduinoISP uses the SPI interface on pins 10-13 which is provided by the underlying AVR hardware.


body:
As a practical matter, you're much better off correcting things so you're using the original pins, which correspond to hardware SPI.

However, it's not terribly hard to implement SPI in software (at a lower performance, of course):

    static uint8_t
    SPITransfer(uint8_t out)
    {
        uint8_t in = 0;
        for (int i=0; i<8; ++i) {
            digitalWrite(MOSI, (out & 0x80) != 0);
            out <<= 1;
            digitalWrite(SCK, HIGH);
            in = (in << 1) | digitalRead(MISO);
            digitalWrite(SCK, LOW);
        }
        return in;
    }

There are several SPI modes, but this implements the one used for ISP.


message:
How do I initialize a servo object in my own library?

I'm trying to make my first library for Arduino and want to use a servo object in my library. How can I do this?

body:
**This is a simple solution.** All you need to do is declare a *global variable* (i.e. make it accessible everywhere in your sketch), and then add some additional code to "share" the servo between the different parts of the code.

## Code you need:

**Your library:**

    Servo servoname;
    void foo() {
      //Some code here!
    }

    void bar() {
      //More code here!
    }

The methods `foo()` and `bar()` are irreverent to the code, you just need to declare it.

**Your library header file (`name.h`):**

    extern Servo servoname;
All you need to do then is import your new library and use `servoname`. You will have to still call `servoname.attach([pin]);` before you can use the servo, but then you just need to use the servo.

*[Source](https://stackoverflow.com/questions/1045501/how-do-i-share-variables-between-different-c-files)*


body:
If your question is about **including library A inside library B and then including library B in your main program**, then you need to be aware of a limitation of Arduino IDE (discussed in [this answer][1] to a similar question).

Arduino IDE (at least 1.0.x, I have not checked with 1.5) for an obscure reason will not include libraries included by other libraries.

The only way to work around this issue is to include ALL libraries (direct **and** indirect) in your main program file (`.ino` file):

    // Needed by library "B"
    #include "A.h"
    // Needed by your program
    #include "B.h"

    void setup() {
        // You can use B stuff here
    }

    void loop() {
        // You can use B stuff here
    }

Another workaround is to trash Arduino IDE and use a better (I mean a real) IDE: many good options have been discussed in [this question][2].

  [1]: https://arduino.stackexchange.com/questions/322/why-do-i-need-to-include-libraries-used-in-other-libraries/328#328
  [2]: https://arduino.stackexchange.com/questions/40/what-are-the-other-ides-for-arduino


body:
This should give you an idea of how to create a custom library which you can use in your project. I actually compiled it with Arduino IDE 1.0.5 on Mac OsX.
I did not run it on an Arduino board, but have similar code in a production project, that works just fine.

Start a new Arduino sketch, name it as you like.

Go to the folder where you saved that file.

Add a new file called MyServoLib.h parallel to your main project file.

In your main file, include the servo library from Arduino and your custom library like so:

    #include <Servo.h>
    #include "MyNewLib.h"

If you close and reopen your project, it the Arduino IDE will automatically load your custom library file as well.

Copy the following simple stub code into your custom library file:

    #ifndef MY_SERVO_LIB_H__
    #define  MY_SERVO_LIB_H__

    #include <Servo.h>
    #include <Arduino.h>

    class MyServoLib
    {
    public:

      MyServoLib()
        : _servoPin(9)
        , _attached(false)
      {}

      void attach()
      {
        if (_attached)
          return;

        _attached = true;
        _servo.attach(_servoPin);
      }

      void detach()
      {
          if (! _attached)
              return;

          _attached = false;
          _servo.detach();
      }

      void setPin(int pin){
        _servoPin = pin;
      }

    private:

      bool _attached;
      Servo _servo;
      int _servoPin;

    };

    #endif

Your main file should look like this:

    #include <Servo.h>
    #include "MyNewLib.h"

    // use your custom lib here
    MyServoLib myServo;
    int MyServoPin = 5;

    void setup(){

      pinMode(MyServoPin, OUTPUT);
      myServo.setPin(MyServoPin);
      myServo.attach();

      // your additional setup code here
    }

    void loop(){

      // your main code here

    }

That's it!

Upload it to an Arduino board and give it a try. The servo won't move, but it should get powered on.


message:
Arduino stopwatch, which board to use?

I am planning on making a simple stopwatch with:

 - A display
 - One or two additional buttons to start the stopwatch and stop the stopwatch and
   maybe reset it.

The problem is that it has to be as small as possible.
With all those different Arduino boards out there, I don't know which one I should buy (mini, micro, nano, ...).

I am not sure how many pins I need for the LCD since I have read that in fact not all pins are mandatory for the LCD. I have done something earlier with an LCD and I found the pot meter for the LCD contrast level a bit of waste of space. Could I just replace it with a certain resistor or something?

How many pins in the end would I need and which board would be fitting for this little project?

body:
**By that [photo](http://arduino.cc/en/uploads/Tutorial/LCD_bb.png) you posted, you pretty much answered a decent part of your question.** You'll need six pins for the LCD, and one or two for the button. That means that you need a *total* of 8 pins. That Uno pictured has 20 (analog can act as digital, too).

As far as the boards, if you feel comfortable with some extra work, I'd recommend an ATtiny. From what I can find, it seems like you can drive a LCD with a 44 or an 84 (similar, but the 84 is more powerful).

>

*[Source for image and how to program chip](http://highlowtech.org/?p=1695)*. I'm not going to go into the details for this method, as the link has the necessary files...
****
That's the smallest way to do this*, however, if you want to use a real Arduino board, then I'd recommend the Micro for a few reasons.

First of all, it has the newer ATMEGA32u4 chip, found on the Leonardo. I do *not* recommend the Mini because, although it's the smallest of the three, it doesn't feature on board USB. You would have to buy another adapter to program it. If you're already using a breadboard, the extra 2cm (or so) is worth not having to spend *more* to buy both of those components. The Nano is the equivalent of the Mini, only with USB. Also, the Nano and the Micro are roughly the same size, one a little bit longer and one a little bit wider.

However, the Nano and Micro are roughly the same as far as processing power, so I'd recommend that, if you can get one significantly cheaper, to go with that. It doesn't really matter that much.

*If you're building this on a breadboard, it won't be smaller. If you're transferring to a PCB, then you should use an ATtiny.
****
As far as the pot goes, I'd recommend getting a *trimmer* with an equivalent value. Some of them are very small, as I have one that fits on the USB connector part of my thumb drive. They need a screwdriver to adjust, but I would recommend it. I've had issues moving it from a dark room to in the sun and not being able to see it clearly. Spend the two cents and the 2 cm2 and have an opportunity to change it if needed.

For the battery, I would recommend any rechargeable battery (under ~3.5V) **if and *only* if** you add a proper chip to not waste energy in the conversion. I talked about this in [this post](https://arduino.stackexchange.com/questions/665/powering-arduino-with-solar-panels/667#667).


message:
Turning a DC motor a set number of Rotations using an encoder

I'm using an arduino UNO, and i want to turn a motor a set number of revolutions, i'm trying to read the clicks of the encoder which has a resolution of 360 clicks/ revolution, my logic is that i count the number of clicks until i get to the desired number which represents the the number of revolutions * the resolution of the encoder:

1 revolution ==> 360 clicks
5 revolutions ==> 360*5 (desired number)

i'm a beginner with arduino so here is my code:

    volatile int counter=0;
    int motor=5;  // motor is connected to pin 5

    void setup(){
      pinMode(motor,OUTPUT);
      attachInterrupt(0, count,RISING); // attaching encoder on interrupt 0
    }

    void loop(){
      while(counter< 360*5){
        analogWrite(motor,255);
      }
    }

    void count(){
      counter++;
    }

This code is not working at all, how can i fix it?

body:
You never tell the motor to stop.

    void loop(){
       while(counter< 360*5){
         analogWrite(motor,255);
       }
       analogWrite(motor, 0); //add something like this or whatever could stop it
       //you may want to disable the counter now too
    }

However, even with that change you are likely a long way from having a working, or at least reliable system - see other issues in my comment on the question.


body:
Since the Encoder resolution is high, the Arduino Uno misses some pulses hence you could not get the accurate reading from it. You could use the hardware quadrature decoder in Arduine Due board which can easily read the encoder values.

Here is a code which can only be executed in arduino Due to Read one quadrature encoder.
https://arduino.stackexchange.com/questions/28268/how-to-configure-2nd-quadrature-decoder-io-pins-in-arduino-ide


message:
Analog average sample wind speed sensor

I have wind speed sensor that can measure max speed upto 30 m/s with analog out put 0-5v. I have simple code calling from the loop. When I put the wind speed average code, the web server is not working and it just hangs. If I comment out web server it's working fine. Let me know What makes my web server hang or not get connected. Is there any way I can change average taking code?

**Working code should like below:**

    if wind speed exceed 30 m/s
       mode =stow
    else
       mode =track

 My code. And how can write average of windload of day to SDcard

    #include"wind.h"
    #include"mode.h"

    float sampleAverage(void)
    {
      float accumulator = 0;
      for (int i = 0; i < SAMPLE_COUNT; i++)
      {
        accumulator += sample[i];
      }
      return accumulator / SAMPLE_COUNT;
    }

    void Wind_calc()
    {

      static unsigned long lastSampleTime = 0;
      unsigned long currentTime = millis();

      // check if time for new reading
      if (currentTime - lastSampleTime >= SAMPLE_RATE)
      {
        lastSampleTime = currentTime;
        int sensorValue = analogRead(SENSOR_PIN);
        float voltage = sensorValue * (5.0 / 1023.0);
        /* Serial.print("voltage: ");
         Serial.println(voltage);*/
        // add the newest reading at the oldest pointer
        sample[sampleIndex] = voltage;
        // advance to next index which is now oldest
        sampleIndex++;
        // check for and handle rollover
        if (sampleIndex == SAMPLE_COUNT)
        {
          sampleIndex = 0;
        }
        // the sample array now contains the last ten readings
        // sampleIndex now points to the oldest reading
        // it will be replaced with the newest next time

        float average = sampleAverage();
        /*Serial.print("average:");
         Serial.println(average);*/
        Wind_Speed = (6 * average);
        Wind_Kmph = 3.6 * Wind_Speed;
        /*    Serial.print("Wind_Speed:");
         Serial.print(Wind_Speed);
         Serial.println("m/s");

         Serial.print("Wind_Exceed_count:");Serial.println(Wind_Exceed_count);Serial.println(".................");
         Serial.print("Wind_Kmph:");
         Serial.print(Wind_Kmph);
         Serial.println("KMPH");
         */
        if((Wind_Speed>4.0)&&(Stow_flag==0))
        {
          Wind_Exceed_count=Wind_Exceed_count+1;

          //Serial.println("Wind_Exceed_count");Serial.print(Wind_Exceed_count);
          if(Wind_Exceed_count<5)
          {
            Stow_flag=0;
          }
          else
          {
            Stow_flag=1;
            MODE=STOW;
          }

        }
        else
        {
          Redo_Wind_calc();
        }

      }

    }

    void Redo_Wind_calc()
    {
      //  Serial.println("Wind_Exceed_count");Serial.print(Wind_Exceed_count);
      if(Wind_Speed>4.0 &&Stow_flag==1)
      {
        Wind_Exceed_count=Wind_Exceed_count+1;
        if(Wind_Exceed_count<=10)
        {
          MODE=STOW;
        }
        else
        {
          MODE=TRACK;
          Wind_Exceed_count=0;
          Stow_flag=0;
        }

      }
    }

    void loop()
    {
     Wind_calc();
    webcontrol();
    }

    void webcontrol()
    {

    //Web control function are defined here

    }

body:
What arduino board is being used? I find that some webserver code takes up a lot of the SRAM and in an UNO this leaves very little space for other code.

To save SRAM use the F macro on all the Serial.print statements that have quoted text. i.e:

    Serial.print("Some text you want output");
This takes up SRAM when running. 1 byte per letter and space.

    Serial.print(F("Some text you want output"));
This takes up no SRAM as it is stored in program space and is makes a big difference.

Search for a `freeRam()` and use that in debugging your sketch to see how much free space you have.

Relevant question: [What can I do if I run out of Flash memory or SRAM?][1]

  [1]: https://arduino.stackexchange.com/questions/221/what-can-i-do-if-i-run-out-of-flash-memory-or-sram


message:
Can the official arduino GSM shield library be changed to work with hardware serial on mega

I have a complex requirement that uses a number of libraries that depend on timing I.e. OneWire. When using the official GSM shield on a mega, it loads a version of software serial to talk to the GSM. I want to make it use a spare hardware serial port on the MEGA for more timing stability. How should I modify the GSM library to (optionally) auto detect a MEGA and then use a nominated serial port. I am happy to jumper the correct pins from the mega serial hardware port to the bent outwards pins 2 and 3 of the GSM shield ( pin 2 is already bent out if you use a MEGA anyway).

body:
Before we start, note that it might not be the right pinout for the GSM shield to use a hardware serial port on the Mega. Beware of some nasty wiring.

Poking around on Github, I found [this is the directory for the GSM library](https://github.com/arduino/Arduino/tree/db8cbf24c99dc930b9ccff1a43d018c81f178535/libraries/GSM). Ladies and gentlemen, it's time to <strike>break something important</strike> get our hands dirty! Draw your  chairs close for a tale of touching code you shouldn't touch!

Click on the `src` folder to open it up. When I first opened this up, I was somewhat scared by the number of files. However, I had a plan:

 1. Find the name of the SoftwareSerial instance. I'm guessing that they would use only one object to do this to prevent redundancy. In addition, I'm going to guess that most serial data is handles though a single file, but I'll have to confirm this.
 2. Remove instances of the SoftwareSerial Object.
 3. Clean up any remaining issues with the "port"

After more poking around, I noticed that the library actually uses [a unique version of the SoftwareSerial library](https://github.com/arduino/Arduino/blob/db8cbf24c99dc930b9ccff1a43d018c81f178535/libraries/GSM/src/GSM3SoftSerial.h), so it will be even *harder* to do this. Yay us! On the upside, we know exactly what code to replace. Fasten your seatbelts, this is about to get pretty nasty.

Okay, take a step back here and figure out *what* we want to modify. First of all, it's a *terrible* idea to modify the libraries directly in the directory that the Arduino IDE uses.

So, if you were to make a copy from the `src` folder for the GSM library into the Arduino "libraries" folder, it wouldn't be enough. The Arduino IDE would get confused when there would be two identical header files to use. You will need to rename the *main header file* and use just that one instead to include into your projects. In addition, most of the files in the library probably reference that file, so make sure to rename any references within the library to that one file. A quick CTRL + SHIFT + F on the Atom text editor will search the entire project I'm working on. I'm not entirely sure if a folder name would mess up the Arduino IDE, but it'd be a good idea to rename the folder to whatever your library is called, at least for readability purposes.

Before we continue, let's make sure that the library still compiles without us playing with the code. Import the new library into a basic GSM example sketch and see if it compiles and works normally.

It compiles? Great. Let's go on!

The file that does serial is the `GSM3SoftSerial.cpp` file. Without actually porting it, I can't give you a ton of advice here. Look through and see when variables are created, used, and modified. If you're not sure, [I'm in chat sometimes: feel free to ask there on minor questions and ping me with @AnnonomusPenguin][1] or leave a comment on this post.

I'd also advise to leave everything in there that you're not sure of, make sure it works with hardware serial, and line by line start removing that variable and see if anything breaks. A great too for this would be to use a tool like Git/Github (or other version control software) to help you revert changes that broke something or to see, overall, what you've changed.

So, after replacing the code inside the functions (finalWrite, the ISRs, and the begin/clear seem like the ones you should touch), compile the code and see if it works!

  [1]: http://chat.stackexchange.com/rooms/8489/pin-13


message:
How to compile code for the Arduino Due?

I have set up Eclipse to compile for the Arduino Due using all the tools shipped with the Arduino IDE 1.5.6-r2. It compiles without errors, but when uploaded, the Arduino does nothing, and isn't recognized on the computer. It then has to be reset manually using the erase and reset buttons.

There is one static library (ArduinoDueCore) consisting of the Arduino library (`core`), and other code (Atmel found in `lib`). The other Eclipse project is the TestProject. It contains one file blinking an LED on pin 13. All the files from the Arduino library are there.

This is the output from Eclipse compiling the library itself: (excerpt of only one of each type of command)

    18:31:36 **** Build of configuration Release for project ArduinoDueCore ****
    make all
    Building file: ../src/lib/variants/arduino_due_x/variant.cpp
    Invoking: ARM Sourcery Linux GCC C++ Compiler
    arm-none-eabi-g++ -DUSB_PRODUCT="Arduino Due" -DARDUINO=156 -DUSB_MANUFACTURER="Unknown" -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE -D__SAM3X8E__ -Dprintf=iprintf -DF_CPU=84000000L -DUSB_VID=0x2341 -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/lib/variants/arduino_due_x/variant.o.lst" -fno-exceptions -fno-rtti -w -c -g -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -MMD -MP -MF"src/lib/variants/arduino_due_x/variant.d" -MT"src/lib/variants/arduino_due_x/variant.d" -mcpu=cortex-m3 -mthumb -o "src/lib/variants/arduino_due_x/variant.o" "../src/lib/variants/arduino_due_x/variant.cpp"
    Finished building: ../src/lib/variants/arduino_due_x/variant.cpp

    Building file: ../src/lib/libsam/source/adc.c
    Invoking: ARM Sourcery Linux GCC C Compiler
    arm-none-eabi-gcc -DARDUINO=156 -DARM_MATH_CM3 -DUSB_MANUFACTURER="Unknown" -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE -D__SAM3X8E__ -Dprintf=iprintf -DF_CPU=84000000L -DUSB_VID=0x2341 -DUSB_PRODUCT="Arduino Due" -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/lib/libsam/source/adc.o.lst" -w -c -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -std=c99 -MMD -MP -MF"src/lib/libsam/source/adc.d" -MT"src/lib/libsam/source/adc.d" -mcpu=cortex-m3 -mthumb -o "src/lib/libsam/source/adc.o" "../src/lib/libsam/source/adc.c"
    Finished building: ../src/lib/libsam/source/adc.c

    Building file: ../src/core/USB/HID.cpp
    Invoking: ARM Sourcery Linux GCC C++ Compiler
    arm-none-eabi-g++ -DUSB_PRODUCT="Arduino Due" -DARDUINO=156 -DUSB_MANUFACTURER="Unknown" -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE -D__SAM3X8E__ -Dprintf=iprintf -DF_CPU=84000000L -DUSB_VID=0x2341 -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/core/USB/HID.o.lst" -fno-exceptions -fno-rtti -w -c -g -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -MMD -MP -MF"src/core/USB/HID.d" -MT"src/core/USB/HID.d" -mcpu=cortex-m3 -mthumb -o "src/core/USB/HID.o" "../src/core/USB/HID.cpp"
    Finished building: ../src/core/USB/HID.cpp

    Building file: ../src/core/cortex_handlers.c
    Invoking: ARM Sourcery Linux GCC C Compiler
    arm-none-eabi-gcc -DARDUINO=156 -DARM_MATH_CM3 -DUSB_MANUFACTURER="Unknown" -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE -D__SAM3X8E__ -Dprintf=iprintf -DF_CPU=84000000L -DUSB_VID=0x2341 -DUSB_PRODUCT="Arduino Due" -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/core/cortex_handlers.o.lst" -w -c -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -std=c99 -MMD -MP -MF"src/core/cortex_handlers.d" -MT"src/core/cortex_handlers.d" -mcpu=cortex-m3 -mthumb -o "src/core/cortex_handlers.o" "../src/core/cortex_handlers.c"
    Finished building: ../src/core/cortex_handlers.c

    18:31:39 Build Finished (took 2s.811ms)

Here is the project itself:

    18:33:42 **** Build of configuration Release for project TestProject ****
    make all
    Building file: ../src/TestProject.cpp
    Invoking: ARM Sourcery Linux GCC C++ Compiler
    arm-none-eabi-g++ -DARDUINO=156 -DUSB_PRODUCT="Arduino Due" -DARDUINO_SAM_DUE -D__SAM3X8E__ -DARDUINO_ARCH_SAM -Dprintf=iprintf -DF_CPU=84000000L -DUSB_MANUFACTURER="Unknown" -DUSB_VID=0x2341 -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/TestProject/src" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -Os -ffunction-sections -fdata-sections -Wall -fno-exceptions -fno-rtti -c -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -g -w -MMD -MP -MF"src/TestProject.d" -MT"src/TestProject.d" -mcpu=cortex-m3 -mthumb -o "src/TestProject.o" "../src/TestProject.cpp"
    Finished building: ../src/TestProject.cpp

    Building target: TestProject.elf
    Invoking: ARM Sourcery Linux GCC C++ Linker
    arm-none-eabi-g++ -T"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x/linker_scripts/gcc/flash.ld" -L"/home/kim/workspace_juno/ArduinoDueCore/Release" -Wl,-Map,TestProject.map -lm -lgcc  -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--gc-sections -mcpu=cortex-m3 -mthumb -o "TestProject.elf" -Wl,--start-group  ./src/TestProject.o   -lArduinoDueCore -Wl,--end-group
    Finished building target: TestProject.elf

    make --no-print-directory post-build
    /home/kim/arduino-1.5.6-r2/hardware/tools/g++_arm_none_eabi/bin/arm-none-eabi-objcopy -O binary TestProject.elf TestProject.bin

    Invoking: ARM Sourcery Linux GNU Create Listing
    arm-none-eabi-objdump -h -S TestProject.elf > "TestProject.lst"
    Finished building: TestProject.lst

    Invoking: ARM Sourcery Linux GNU Print Size
    arm-none-eabi-size  --format=berkeley TestProject.elf
       text    data     bss     dec     hex filename
      10396      24    1188   11608    2d58 TestProject.elf
    Finished building: TestProject.siz

    18:33:43 Build Finished (took 308ms)

Here is the upload command: (removed `readWord`, `go`, `write` and `writeWord` lines)

    -i -d --port=ttyACM0 -U true -e -w -v -b ${project_loc}/Release/${project_name}.bin -R

    Set binary mode
    chipId=0x285e0a60
    Connected at 921600 baud
    Erase flash
    Write 10420 bytes to flash

    [                              ] 0% (0/41 pages)
    [=======                       ] 24% (10/41 pages)
    [==============                ] 48% (20/41 pages)
    [=====================         ] 73% (30/41 pages)
    [============================= ] 97% (40/41 pages)
    [==============================] 100% (41/41 pages)
    Verify 10420 bytes of flash

    [                              ] 0% (0/41 pages)
    [=======                       ] 24% (10/41 pages)
    [==============                ] 48% (20/41 pages)
    [=====================         ] 73% (30/41 pages)
    [============================= ] 97% (40/41 pages)
    [==============================] 100% (41/41 pages)
    Verify successful
    Set boot flash true
    Device       : ATSAM3X8
    Chip ID      : 285e0a60
    version()=v1.1 Dec 15 2010 19:25:04
    Version      : v1.1 Dec 15 2010 19:25:04
    Address      : 524288
    Pages        : 2048
    Page Size    : 256 bytes
    Total Size   : 512KB
    Planes       : 2
    Lock Regions : 32
    Locked       : none
    Security     : false
    Boot Flash   : true
    CPU reset.

TestProject.cpp:

    #include "Arduino.h"

    void setup() {
        pinMode(13, OUTPUT);
    }

    void loop() {
        digitalWrite(13, HIGH);
        delay(50);
        digitalWrite(13, LOW);
        delay(950);
    }

body:
Using 1.5.6-r2 with Eclipse cause the Due to hung in Default_Handler function after entering main and polling a few times for the next SysTick gettin passed.

Some weak symbol declarations are done twice (i.e. the SysTick_Handler function definitions). They appear to overwrite each others weak alias depending on the link time usage of the objects. All declarations (not only the failing SysTick_Hanlder) from cortex_handler.c are getting overwritten by weak symbol redeclaration inside startup_sam3xa.c.

This commit seems to already address a weak symbol definition problem.
https://github.com/arduino/Arduino/commit/65f00a69c74ca0def8d7f1d7597327945a04a33f

For now, to fix it. Just comment out the part in startup_sam3xa.c with the weak symbol declaration regarding the vectors. Lines 53 to 129.

It should also work to just remove the file completely.
The startup handler code and vector map should be provided by gcc arm built-in libraries instead.


message:
CO2 sensor for arduino

I want to add CO2 measuring feature to my room weather station. Can someone please recommend a CO2 sensor easy to integrate with Arduino?

body:
You could try the [K30 CO2 sensor][1]. There is also a guide using it to make an arduino CO2 detector [here][2].

I've also seen people use the MG-811 module, you can buy them from dfrobot.com . There is also good documentation for how to use the MG-811 with arduino [here][3].

  [1]: http://www.co2meter.com/products/k-30-co2-sensor-module
  [2]: http://www.openhomeautomation.net/wireless-co2-sensor-arduino/
  [3]: http://www.spencerpages.com/wiki/index.php?title=MG811_Carbon_Dioxide_(CO2)_Sensor


body:
How about this one? http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=380915024016&ssPageName=STRK:MESE:IT
The MG-811 is highly sensitive to CO2 and less sensitive to alcohol and CO.


body:
This one:
http://sandboxelectronics.com/?product=mg-811-co2-gas-sensor-module

They also got a nice demo code there.
Here is a wiring scheme if you use the demo without modification:

1. Red - 5V
2. Black - GND
3. Yellow - Analog input 0
4. Green - Digital I/O 2

The easeir integration ever


body:
Based on hands-on time with CCS811 CO2 sensors, I would recommend against them. They tend to drift high, sometimes way high, and then come back to their senses and provide reasonable readings when reset.

I've tried two batches of CJMCU-811 sensors, purchased months apart (hoping to get a different manufacturing lot), and they were all rubbish.


body:
This worked well for me on a colour screen. A small delay for the sensor and a long burn (24hrs) required. But easy KIWI

    #include <XTronical_ST7735.h> // Hardware-specific library
    #include <SPI.h>
    #include <Adafruit_GFX.h>    // Core graphics library
    #include <sSense-CCS811.h>
    #include <dht.h>

    #define SERIAL_SPEED  9600

    #define TFT_SCLK 13         // SPI clock
    #define TFT_MOSI 11         // SPI Data
    #define TFT_CS   10         // Display enable (Chip select), if not enabled will not talk on SPI bus
    #define TFT_RST   9         // Display reset pin, you can also connect this to the Arduino reset
                                // in which case, set this #define pin to -1!
    #define TFT_DC     8
    CCS811 ssenseCCS811;
    Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);
    dht DHT;

    #define DHT11_PIN 7

    void setup()
    {
      DebugPort.begin(SERIAL_SPEED);
      delay(5000);
      Serial.println("s-Sense CCS811 I2C sensor.");
      if(!ssenseCCS811.begin(uint8_t(I2C_CCS811_ADDRESS), uint8_t(CCS811_WAKE_PIN), driveMode_1sec))
        DebugPort.println("Initialization failed.");
      tft.init();   // initialize a ST7735S chip,
      tft.setRotation(0);
      tft.fillScreen(ST7735_GREEN);
      tft.setTextColor(ST7735_RED);
      tft.setCursor(0, 30);
      tft.setTextSize(1);
    }

    void loop()
    {
      ssenseCCS811.setEnvironmentalData((float)(21.102), (float)(57.73));  // replace with temperature and humidity values from HDC2010 sensor
      int chk = DHT.read11(DHT11_PIN);
      if (ssenseCCS811.checkDataAndUpdate())
      {

        tft.fillScreen(ST7735_GREEN);
        tft.setCursor(10,10);
        tft.print("CO2 ppm  ");
        tft.print(ssenseCCS811.getCO2());
        tft.setCursor(10,40);
        tft.print("tVOC ppb ");
        tft.print(ssenseCCS811.gettVOC());
        tft.setCursor(10,70);
        tft.print("Temp C   ");
        tft.print(DHT.temperature);
        tft.setCursor(10,100);
        tft.print("Humid %  ");
        tft.print(DHT.humidity);

      }
      else if (ssenseCCS811.checkForError())
      {
        ssenseCCS811.printError();
      }

      delay(2000);
    }


message:
XBEE WiFi S6B RSSI for Smartphone localization

I am building an early prototype, proof of concept, network monitoring tool.  A big part of it uses localization of a Smartphone.  It seems that the best way to do this is using RSSI from multiple points.  I plan to do this using several Arduino Fios with Xbee WiFi (S6B) cards.

My current setup has a network running from my smartphone (it is running DHCP) with a laptop monitoring all the traffic on the network.

What I need is for my Fio Xbees to dump the RSSI of the "access point" (Smartphone) onto the network so my laptop can pull the data.

Thus, to/from is not important as far as the packet is concerned, I just need the data dropped on the "wire" for my laptop to later parse, which is good because Serial.print* sends out a broadcast to 255.255.255.255:fffff.

I can make my devices broadcast any integer, but when I go into AT mode nothing aside from the initial DHCP handshake gets put on the wire.  Any ideas?

<!-- language: c -->

    void setup() {
      Serial.begin(9600);
      Serial.flush();
      delay(1000);//enter AT mode start
      Serial.print("+");//AT
      Serial.print("+");//AT
      Serial.print("+");//AT
      Serial.flush();
      delay(1000);//enter AT mode finish
      while(Serial.available()>0){
        Serial.write(Serial.read());
      }

    }

    void loop(){
      Serial.println("ATDB");

      while(Serial.available()>0){
        Serial.write(Serial.read());
      }
      delay(750);//3/4 a sec
    }

Note, `Serial.println("ATDB");` should cause the xbee to drop the RSSI on the wire; see
[XBee_WiFi_AT_Commands.pdf](http://examples.digi.com/wp-content/uploads/2012/06/XBee_WiFi_AT_Commands.pdf)
at digi.com.

The three "+"s at the start are how you move the device into AT mode; see
[Digi_International_90002124_G.pdf](http://www.mouser.com/pdfdocs/Digi_International_90002124_G.pdf) at mouser.com.

Once again what I am trying to do is get the collected RSSI information dropped onto a wifi connection from multiple xbee WiFi S6B equipped Fios.

body:
Just incase anybody stumbles onto this page googling, I am posting my solution below (I *think* it will work for any xbee radio)

Basically for some reason the RSSI values are getting nulled out before I can read them, both in my API mode tests and AT commands.  I'm not convinced that there is not some way around this in API mode at least, but it is irrelevant for my current purpose.

What I did was wire pin 6 on the xbee to a digital pin on the Arduino (I used 7) then use a pulse detector to find the period of the wireless signal coming in.

    int pin = 7;
    unsigned long period;

    void setup(){
      Serial.begin(9600);
      pinMode(pin, INPUT);
      Serial.println("Getting started");
    }

    void loop(){
      delay(100);
      period = pulseIn(pin, HIGH);
      Serial.println(period);

    }

It is not perfect, but for now it works, might help someone else in the future.


message:
My Servo Won't Sweep Smoothly

So I've tried this a few times and I always get the same issue. When I try to run the sweep example the servo goes round 180 degrees but only in steps. Anyone know a way to fix this?

The servo I'm using is a **Tower Pro Micro Servo 9G SG90**

    // Sweep
    // by BARRAGAN <http://barraganstudio.com>
    // This example code is in the public domain.

    #include <Servo.h>

    Servo myservo;  // create servo object to control a servo
                    // a maximum of eight servo objects can be created

    int pos = 0;    // variable to store the servo position

    void setup()
    {
      myservo.attach(9);  // attaches the servo on pin 9 to the servo object
    }

    void loop()
    {
      for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
      {                                  // in steps of 1 degree
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
      }
      for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
      {
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
      }
    }

Video: http://vidd.me/A40

body:
It looks like your sketch runs in slow motion.

Check if you wrote delay(150) or have an additional delay in your loop.
Check twice and - just to make sure - upload the corrected sketch again.

**Edit:**
If possible, test with another servo and even test with another Arduino board.


body:
In electronics, as usual in situations where a cricuit is misbehaving and we don't understand why, a solution that generally works is to add a **decoupling cap** between `+5V` and `GND`.

In your case, I would put at least **220uF**; that would ensure two things:

- the voltage used to control the servo never drops
- the voltage brought to Arduino by the USB does not drop either (which would have very bad impact on the Arduino, probably resetting it)

Electrolytic caps are a **must-have** for every electronics hobbyist (and professional as well, of course).

You can read more about decoupling capacitors on [Wikipedia][1].

**Edit:**

According to @gwideman comment, it seems that using a decoupling capacitance **above 10uF** in a USB 2.0 device would violate USB specs and ***may damage*** the USB host controller on the computer.

I was not aware of this limitation but I have already used decoupling capacitance up to 100uF in my circuits and never got any issue with my USB computer port.

It might be due to extra electronics on the Arduino board that would "isolate" USB power from Arduino +5V anf d GND pins, I don't know (**that should probably be the topic of a specific question**); or maybe I have just been lucky all this time...

  [1]: http://en.wikipedia.org/wiki/Decoupling_capacitor


body:
I've experienced same behavior with this type of servos. In my case it was easier to spot since Arduino frequently rebooted when servo was approaching the boundaries of the swing - so it was clear it was consuming too much power, and USB port was unable to deliver that.

Cheap dedicated 9V 1A AC/DC converter usually solves the problem. But if you can't wait for one to get delivered, get an iPad USB charger (nowadays everyone has it or has a neighbor/friend who has one). It is rated 10W, and it doesn't suffer from voltage drops even under high loads. Power your setup from it, and if you'd see it moves smoothly, you will have your answer.


body:
give a 9v supply +ve terminal to Vin and -ve ground.
since the arduino board cannot supply enough power to the servo, this will provide
this worked for me and workin just fine


body:
I tested your code, nothing wrong with it.
Maybe it is power supply issue.
1. Don't use USB to power servo, it can make current spike when it move rapidly.
2. Use proper supply for servo. High current and use large capacitor to deal with current spike.


message:
ArduinoUno+LcdKeypad+ArduinoWifi=Pins Problems

Is it possible to connect these two shields to my Arduino Uno? After a research on the internet, I discovered that they use some of the same pins. Even so, is it still possible for me to connect the LcdKeypad and the ArduinoWifi on my Arduino Uno? (the LCD would be on top)

Here are the pic of the shields, and some information:

[LDC KEYPAD][1]

[Arduino WIFI][2]

WiFi shield info:

> The Arduino communicates with the processor WiFi shield with the microSD card by SPI
> (Eurotherm the ICSP bus) that is on pins 11, 12
> and 13 at Uno. The pin 10 is used to select the HDG104 and pin 4 to
> the microSD card(i dont need the pin 4 cause i wont use SD). These pins can not be used
> for input and output. The
> digital pin 7 is used for initialization of the communication protocol
> between the shield and Arduino WiFi and should not be used.

LCD info:

> This shield we will have to use the following sequence to initialize
> the library LiquidCrystal:
> LiquidCrystal lcd (8,9,4,5,6,7);

As you guys have noticed, there is the pin 7 on both shields that I need to use. How would it work? Can I do this? If i can't, is there any solution that I can expand my pins that would not result buying a Mega?

I still have to connect two INFRA-RED sensors and a motor (using pins 0, 1, and 2). I don't know if i can connect on the pins TX and RX (they seem to work).

  [1]: http://www.robotshop.com/media/catalog/product/cache/1/image/325x325/9df78eab33525d08d6e5fb8d27136e95/a/d/adafruit-rgb-lcd-keypad-shield-kit-arduino-i2c.jpg
  [2]: http://ktjjnx9q5vgx99fk.zippykid.netdna-cdn.com/wp-content/uploads/2013/06/arduino-wifi-shield.jpeg

body:
**So here are your needs:**

 - WiFi, which uses pins 4, 10, 11, 12, 13. I know you said that you don't need pin 4 since no SD, but because that pin switches on/off the SD card, if you use it at all. Note: As Connor Wolf points out, it's not really relevant when there's no SD card. If you're facing problems with the Ethernet shield using the LCD additionally, you might have to reroute pin 4.
 - LCD, which uses pins 4, 5, 6, 7, 8, 9. The standard Arduino LCD library can use any pins, but your shield is hard wired to use those. As mentioned before, you can reroute them if you want to. Below is the method for rerouting pins.

****
## Rerouting pin 7 (you need to do this!):

 - Bend pin 7 on the LCD shield and the WiFi shield outward so it doesn't make contact with the header
 - Use `LiquidCrystal lcd(8,9,3,5,6,2);` if you're rerouting pin 4, or `LiquidCrystal lcd (8,9,4,5,6,2);` in your code if you're not rerouting
 - Attach a jumper between the pin 7 on the header of the WiFi shield and the pin 7 on the Arduino Uno
 - Attach a jumper between the pin 2 of the WiFi shield (or the Uno, if that's easier) and the pin 7 of the LCD using the free space of the pin bent above it.

This will isolate pin 7 on the LCD, still send the pin 4 signal to the WiFi shield, and reroute the signal from pin 2 on your Arduino to pin 7 on the LCD shield.
****
## Rerouting pin 4 (optional):

 - Bend pin 4 on the LCD shield and the WiFi shield outward so it doesn't make contact with the header
 - Use `LiquidCrystal lcd(8,9,3,5,6,2);` in your code
 - Attach a jumper between the pin 4 on the header of the WiFi shield and the pin 4 on the Arduino Uno
 - Attach a jumper between the pin 3 of the WiFi shield (or the Uno, if that's easier) and the pin 4 of the LCD using the free space of the pin bent above it.

This will isolate pin 4 on the LCD, still send the pin 4 signal to the WiFi shield, and reroute the signal from pin 3 on your Arduino to pin 4 on the LCD shield.
****
For number of pins, you should be fine. You can use pins 0 and 1 (TX/RX) **as long as you aren't connecting to the computer or any other UART device**  (i.e. using the `Serial()` library). Don't forget you can use the analog pins as digital pins by referencing them as `A0` to `A5`.


message:
Why doesn't the master branch BOSSA work on Arduino Due?

I have downloaded BOSSA for Linux, and have run `bossash->scan`. I have also tried erasing and resetting the board before scanning. It does not work. According to the [Arduino website][1], the native USB port is connected directly to the chip.

Isn't the master branch BOSSA (Arduino IDE uses it's own modified version of BOSSA) working because of a problem with this specific board, or have Arduino modified something inside the chip which alters the behaviour of the native port?

  [1]: http://arduino.cc/en/Main/arduinoBoardDue

body: No Arduino did not alter the chip, custom chips are massively expensive. If they are using their own modified version of BOSSA, then there must be a reason for it, probably the support of Arduino's hardware platform. To find out what the difference is, you have to find the code base used for Due and the original version when the code was forked. Often in such cases a project like Arduino can provide a patch to the BOSSA project, and that patch may or may not be applied to the master tree. Only way to find out is to check the BOSSA project repository / bug  reports and documentation.


message:
A waterproof Chlorine Sensor

Does anyone know where I can find a Chlorine Sensor to use with the Arduino? It would need to be water proof. I've googled, but I couldn't find anything.

**EDIT**
Requirements: relatively inexpensive (under $100us), works with Arduino, waterproof and used to detect chlorine in water.

body:
Your best bet would probably be to interface with a colorimeter.  There is a tutorial for an open source colorimeter here:

http://www.appropedia.org/Open-source_colorimeter

IORodeo also sells a shield:

http://www.iorodeo.com/colorimeter

Vernier sells a colorimeter that may be suitable for your project & Sparkfun sells a shield to interface with Vernier sensors.

If a colorimeter doesn't work you would have to use an electrode, which is pretty expensive and has a shelf life.


body: Maybe measure conductivity instead?  I think, in freshwater pools, one of the active parts of working chlorine is an OCL ion - which I guess is conductive.


message:
Seeed Studio motor shield

My goal is to have my Arduino fire two stepper motors.  They need not be simultaneous. I'm using an Arduino Uno with 2 motor shields - specifically, the [Seeed Studio Motor Shield v1.0][1]. I know this shield uses D8-13.

Question is, how can I get the Arduino to use both shields?  Is there a way to make one of the shields take D0-D7?  If I could do that that'd be great. As far as I can tell, there's no way. The motor shields cannot be physically mounted either.

  [1]: http://www.seeedstudio.com/depot/Motor-Shield-p-913.html?cPath=73

body: Some shields let you use jumpers or something to change the pin assignments, but I don't believe the Seed motor shield does.  What you can use is a [go-between shield](https://www.sparkfun.com/products/11002) between the two shields to remap the pins on the top shield.  Then in your code, you just initialize the second instance using different pins.  You just have to make sure the alternate pins have the features you need, like pwm.


message:
How to catch the Enter key received by Bluetooth?

I got some code to receive characters from Bluetooth and code and print it back to the LCD display.

However, want to detect the *`Enter`* *character* to be the input signal, in other words, not to print nothing to the display until Enter is pressed.

An strange character is shown at display for Enter but I can't *catch it*.

This is my code:

    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>

    LiquidCrystal_I2C lcd(0x20,16,2);

    void setup()
    {
      lcd.init();
      lcd.backlight();
      pinMode(13,OUTPUT);
      Serial.begin(9600);
      Serial1.begin(9600);

    }

    void loop()
    {

      while (Serial1.available())
      {
        char dato= Serial1.read(); //Comprobamos el dato

         lcd.print(dato);

        switch(dato) {
        case '#':
          Serial.println("GATO...");
        break;
        case 'e':  digitalWrite(13,LOW);

        Serial1.println("Led apagado");
        break;
          case 'r':
          digitalWrite(13,HIGH); delay(200);
          digitalWrite(13,LOW); delay(200);

          Serial1.println("Led intermitente");
          break;
      } //fin switch

    }//serial disponible

    }//fin programa

body:
It depends on what the enter key sends. It may be just CR (carriage return), LF (line feed), or both. You can check the [ASCII table][1] for the hex values for those characters.

LF is 0x0A and CR is 0x0D. Those are the characters you're looking for, you can add a `if` for these cases in order to guard the call to `lcd.print(dato)`:

    char dato= Serial1.read(); //Comprobamos el dato
    if (dato != 0x0A && dato != 0x0F)
        lcd.print(dato);

  [1]: http://www.cdrummond.qc.ca/cegep/informat/professeurs/alain/images/ASCII1.GIF


message:
Can I write to Flash Memory using PROGMEM?

On the documentation of Arduino, I quote:

> http://playground.arduino.cc/Learning/Memory
> Note: Flash (PROGMEM) memory can only be populated at program burn time. You can’t change > the values in the flash after the program has started running.

And on the PROGMEM description:
> http://arduino.cc/en/Reference/PROGMEM
> Store data in flash (program) memory instead of SRAM. There's a description of the various types of memory available on an Arduino board.
>
> The PROGMEM keyword is a variable modifier, it should be used only with the datatypes defined in pgmspace.h. It tells the compiler "put this information into flash memory", instead of into SRAM, where it would normally go.

So can we or can't we? Or it's not the same thing?

body:
The short answer is no: PROGMEM data is read-only.

**Flash memory limitations**
The first thing to understand is that Flash memory (where program space lives) is designed for long-term fixed storage. Reading from it is very fast and precise. However, generally speaking, you can't modify it on a byte-by-byte basis (e.g. changing a specific variable). You usually have to erase and re-write it in large blocks. That makes it completely impractical for run-time manipulation, because you'd have to store a lot of redundant information somewhere else while you do the erase and write cycle.

**What PROGMEM actually does**
Any literal data specified in your code (such as strings and numbers) always reside in program space at first (i.e. in Flash). However, when your sketch actually wants to use that data at runtime, it normally has to allocate some space for it in SRAM and copy it over. That means you end up with two copies: the fixed original in Flash, and the temporary copy in SRAM.

When you use the PROGMEM modifier, you're telling it not to make that second copy in SRAM. Instead, your sketch will simply access the original in Flash. That's very useful if you only ever have to *read* the data, as it avoids the allocation and copy operations.

However, copying it to SRAM is essential if you want to modify the data. Aside from the Flash limitations I mentioned above, it's also a question of code safety.

If you're able to modify the **data** stored in program space, then it follows logically that you could also modify the **code** stored in program space. That would mean that a simple mistake (or in theory a malicious attack) could result in your sketch being partially or fully rewritten at run-time. This could have very unpredictable results, ranging from simply ceasing to work, through to damaging/destroying any connected equipment.

**More information**
You can learn more about the low-level PROGMEM stuff from here:

 * http://www.fourwalledcubicle.com/AVRArticles.php

An older version of the same PROGMEM tutorial is available here:

 * http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=243018


message:
Arduino Uno and Leonardo SPI clock can't be measured

I want to measure the SPI clock (pin 13) using the Arduino example code for the SPI library (very simple example). Basically independent from the `loop` function, the clock should be fired continuously.

I deployed the Arduino SPI example code on the board and measured pin 13 on an oscilloscope, but nothing was found, always zero volt.

body:
Please note the SPI clock will only be active while it is shifting data. So simply put the spi.transfer in a hard loop

    #include <SPI.h>

    void setup() {
      SPI.begin();
      while (1) {
        SPI.transfer(0x00);
      }
    }


message:
Interference at digital input (UNO)

I was trying out a basic button tutorial on my new Arduino UNO. But for some reason, the Arduino was detecting the button as on (pressed) even when it was off (unpressed).

After some experimentation, I found that the digital pins were flickering between `HIGH` and `LOW`, even if there was just a loose wire plugged in with nothing at the other end. And the state of the button, etc. wasn't making any difference. I tried this with pins 5,6 and 7, and it's happening with all of them, even when the neighbouring pins are connected to the ground.

**Is this behaviour normal or is there something wrong with my input pins?**

*Since I'm new to Arduino, there might also be something wrong with my testing code. Here's what I used...*

    const unsigned int LED_PIN = 12;
    const unsigned int BUTTON_PIN = 7;
    const unsigned int INDICATOR_PIN = 13;

    void setup() {
      pinMode(LED_PIN, OUTPUT);
      pinMode(LED_PIN, OUTPUT);
      pinMode(BUTTON_PIN, INPUT);
      digitalWrite(LED_PIN, LOW);
    }

    void loop() {
      const int BUTTON_STATE = digitalRead(BUTTON_PIN);

      if (BUTTON_STATE == HIGH) {
        digitalWrite(LED_PIN, HIGH);
        digitalWrite(INDICATOR_PIN, LOW);
      }
      else if (BUTTON_STATE == LOW) {
        digitalWrite(LED_PIN, LOW);
        digitalWrite(INDICATOR_PIN, HIGH);
      }
    }

*This code makes the lights always in opposite states: when one is on, the other is off. When I ran the code, both lights seemed on, which meant they were probably flickering, which meant that there was some interference in the input pin.*

body:
It sounds like you're seeing entirely normal behaviour. If you leave a digital input unconnected (or connected to an open button) then it's 'floating'. That means it can pick up interference from all sorts of things, and may appear to drift between high and low.

The usual way to resolve this problem is using a pull-up or pull-down resistor. This is usually a high-ohm resistor (e.g. 10,000 Ohm or more) which will gently pull the pin HIGH or LOW in the absence of any other signal. When another signal comes in (e.g. from a button being pushed), it should have a much stronger effect than the resistor, so that is what the input will see.

Your Uno has built-in pull-up resistors which you can use for this, although it will require a couple of changes. In your `setup()` function, you can enable the pull-up on your input pin like this:

    pinMode(BUTTON_PIN, INPUT_PULLUP);

That will cause the input to appear HIGH when the button is **not** pushed. That means you'll need to wire the other end of your button to ground (negative) instead of the voltage supply (positive). If you've set it up correctly, the input should appear LOW when the button is pushed.


message:
Control/count rotations of a DC motor

Using an Arduino and an L293D IC, can I control the number of rotations a DC motor makes? Or can I only control the direction and speed of the motor?

I purchased a two-wheeled robot platform to learn Arduino programming and electronics. The platform is here: http://www.robotshop.com/en/dfrobot-2wd-mobile-platform-arduino.html

Each wheel is controlled by a DC motor. I followed Adafruit's tutorial (https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing) to control the motors with the help of an L293D IC.

Now I realize that I can't directly control the rotations of the motor. I can control the direction, voltage, and time of the rotation. For example: turn forward at 50% voltage for 500 milliseconds.

But that's difficult to translate into actual rotations. The speed of the motor varies according to voltage (like if I switch from 2AA batteries to 4AA's) and weight (adding sensors slows the motors down). Every time I change voltage or weight, I have to guess how much voltage/time causes a single rotation.

I think I should just buy stepper motors. Before I do that, I'll ask the community: Is there a way to control DC motors by rotations rather than time?

body:
Stepper would be heavy and battery consuming, as Ignacio says.

Pololu makes an encoder for a wheel: http://www.pololu.com/product/1217, but obviously you can implement this in other ways too.


body: As you've discovered, there are a lot of variables involved, so you need *some* sort of feedback.  A popular way to do this is with an encoder, but depending on your needs, other kinds of sensors can make do.  For example, if your problem is keeping the robot going in a straight line, an electronic compass can help.  For a line following robot, the line sensors are usually enough.  Range sensors can track your distance.  You get the idea.


message:
How to control Keyboard inputs using arduino(serial monitor) and python keyboard libraries?

I am able to control my monitor and most other applications by giving serial input to python through arduino.
Arduino code:

    void setup()
     {

      pinMode(2, INPUT);
      pinMode(3, INPUT);
      pinMode(4, INPUT);
      pinMode(5, INPUT);
      pinMode(6, INPUT);
      pinMode(7, INPUT);
      Serial.begin(9600);

    }

    void loop()
    {
      if(digitalRead(2) == HIGH)
      {
        delay(5);
      }
      else
      {
        Serial.println("up");
      }
      if(digitalRead(3) == HIGH)
      {
        delay(5);
      }
      else
      {
        Serial.println("down");
      }
      if(digitalRead(4) == HIGH)
      {
        delay(5);
      }
      else
      {
        Serial.println("left");
      }
      if(digitalRead(5) == HIGH)
      {
        delay(5);
      }
      else
      {
        Serial.println("right");
      }
      if(digitalRead(6)== HIGH)
      {
        delay(5);
      }
      else
      {
        Serial.println("space");//orange
      }
      if(digitalRead(7)==HIGH)
      {
         delay(5);
      }
      else
      {
        Serial.println("nitro");//brown
      }
     }

Python code:

    import serial
    from pymouse import PyMouse
    from pykeyboard import PyKeyboard

    k = PyKeyboard()

    ser = serial.Serial('COM7', 9600)

    #sp.write("AT\r\n".encode('ascii'))

    while True:
        p=ser.readline()
        print p
        if ('up' in p):
            k = PyKeyboard()

            k.tap_key(k.up_key)

        if ('down' in p):
            k = PyKeyboard()

            k.tap_key(k.down_key)

        if ('right' in p):
            k = PyKeyboard()

            k.tap_key(k.right_key)

        if ('left' in p):
            k = PyKeyboard()

            k.tap_key(k.left_key)

        if ('space' in p):
            k = PyKeyboard()

            k.tap_key(k.space_key)

        if ('nitro' in p):
            k = PyKeyboard()

            k.tap_key(k.enter_key)

My problem is that..I am not able to play games such as NFS and other similar games using these controls..
What should i do??

body:
Your examples of sending input to the Arduino IDE monitor and to Python involve the Arduino sending data via "Serial over USB" convention. However this is not seen by the operating system (Windows, MacOS) as legitimate keyboard/mouse/joystick input.

There are separate USB conventions (device types) for keyboard/mouse/joystick. Only Arduinos where the USB interface is programmable are able to present those conventions, and some more easily than others, and require understanding some USB client libraries.  The link provided by Chris Stratton has some useful background.

A particularly easy way to get into this is with the PJRC Teensy, https://www.pjrc.com/teensy/, which comes with libraries and examples that let you do this out-of-the-box. See the "Teensyduino" section of their website for USB Keyboard, Mouse, Joystick and so on. These pages are useful background even if not using Teensy. It has attracted a small following of users interested in this area. Plus the various Teensies are conveniently small boards that fits nicely in some user-interface device you might want to build.


body: I'm later, but, I think you should redesign your python and arduino code, to make messages like "start up", "end up", and if message is "start *", hold that key, if "end *", release that key. This should work as intended. I will pin python and arduino code later here. (Also sorry for my english, i'm russian)


message:
Pull Chain Switch

I'm a bit new to electronics/Arduino projects, so am looking for some help on some wiring needed for a project involving this Pull Chain: http://proto-pic.co.uk/pull-chain-switch/

The chain works like a fan chain would.

I am using an Arduino UNO

I have wired up the pull chain to a mini breadboard with a light that turns on and off just to test it's working. What I want to do, is get an analog/digital read each time the chain is pulled?

Is this possible? If so, would you be able to help me with how it would be wired up, as I am completely new to the electronics side of Arduino. I simply need to get a reading each time the chain is pulled, I don't need it to switch a light on.

Thanks all!

body: Connect it between ground and an interrupt pin configured as an input with the pullup enabled. Configure the interrupt to trigger on any state change. Check the digital value of the pin in the ISR.


message:
Super slow serial (UART) communication on Arduino

I am using this device for my Arduino that connects to the [OBD-II][1] port of my car to get various information such as speed, rpm, etc. I am using this for a digital [Nixie tube][2] speedometer using the smart Nixie tube from a [Kickstarter][3] project.

I pass the information to the Nixie tubes through serial and get information from the OBD-II through serial as well. I am getting speed updates about every 20 seconds and that is incredibly slow when the device can supposedly update up to 100 times per second.

I originally was using an [Arduino Uno][4] and using software serial for the tubes, but I figured the slowdown was due to interupts interfering with the hardware serial, so I switched to the [Arduino Mega 2560][5] to use a second hardware serial pin to hopefully fix the problem, yet the same issue is occurring.

Here is my code... There must be something I'm doing wrong. Serial2 is for the Nixie tubes.

    #import <Arduino.h>

    #include <OBD.h>

    int ones = 0;
    int tens = 0;

    int kphValue = 0;
    int mphValue = 0;

    int rpmValue = 0;

    String onesString;
    String tensString;
    String payloadString;
    String rpmString;
    COBD obd;

    void setup(){
        Serial2.begin(9600);
        obd.begin();

        //Initiate OBD-II connection until success
        while (!obd.init()){
            Serial2.print("$0,Y,Y,255,255,000,000$0,Y,Y,255,255,000,000!");
            delay(1000);
            Serial2.print("$0,Y,Y,000,000,000,000$0,Y,Y,000,000,000,000!");
            delay(1000);
        }
    }

    void loop(){
        onesString = String(ones);
        tensString = String(tens);
        payloadString;
        rpmString;

        if(obd.read(PID_RPM, rpmValue)){
            if (rpmValue < 3000){
                rpmString =",N,N,255,000,255,000";
            }
            else if (rpmValue >= 5000){
                rpmString = ",N,N,255,255,000,000";
            }
            else if (rpmValue >= 3000){
                rpmString = ",N,N,255,255,030,000";
            }
        }

        if (obd.read(PID_SPEED, kphValue)){
            kphToMPH();
            payloadString = "$" + onesString + rpmString + "$" + tensString + "rpmString" + "!";
            Serial2.print(payloadString);
        }
    }

    void splitDigits(int input_number)
    {
        ones = (input_number);
        tens = ((input_number/10));
    }

    void kphToMPH()
    {
        mphValue = kphValue * 0.621371;
        splitDigits(mphValue);
    }

**EDIT:**
I am using the following library: https://github.com/stanleyhuangyc/ArduinoOBD

  [1]: http://en.wikipedia.org/wiki/On-board_diagnostics#OBD-II
  [2]: http://en.wikipedia.org/wiki/Nixie_tube
  [3]: http://en.wikipedia.org/wiki/Kickstarter
  [4]: http://arduino.cc/en/Main/ArduinoBoardUno
  [5]: http://arduino.cc/en/Main/arduinoBoardMega2560

body:
I think the problem is not so much in the update speed, but in the fact that you loose accuracy in your calculation. The following lines are the culprit:

    int kphValue = 0;  // [-32768:32767]
    int mphValue = 0;
    mphValue = kphValue * 0.621371;

Make sure the calculation will be entirely in integers to prevent calculation errors:

    uint16_t kphValue = 0;  // [0:65535]
    uint16_t mphValue = 0;
    mphValue = ( kphValue * 621 ) / 1000;

This limits kphValue to just over 100, if you want to go higher than that there are two option:

- multiply by 62 and divide by 100;
- use longer integers `int32_t` [-2147483648:2147483647], which comes with enough room for multiplying by 621371 and dividing by 1000000, but will perform slower and with a larger memory footprint. Do you really need that accuracy?


body:
try this:

    #import <Arduino.h>
    #include <OBD.h>

    int kphValue = 0;
    int rpmValue = 0;

    COBD obd;

    //array of character arrays, see http://arduino.cc/en/Reference/string
    const char* rpmStrings[] = {    ",N,N,255,000,255,000",
                                    ",N,N,255,255,030,000",
                                    ",N,N,255,255,000,000" };

    void setup(){
        Serial2.begin(9600);
        obd.begin();

        //Initiate OBD-II connection until success
        while ( !obd.init() ) {
            Serial2.print("$0,Y,Y,255,255,000,000$0,Y,Y,255,255,000,000!");
            delay(1000);
            Serial2.print("$0,Y,Y,000,000,000,000$0,Y,Y,000,000,000,000!");
            delay(1000);
        }
    }

    void loop() {
        if ( obd.read(PID_RPM, rpmValue) && obd.read(PID_SPEED, kphValue) )
        {
            int rpmStringIndex = determineRpmIndex(rpmValue);
            int mphValue = kphToMPH(kphValue);

            //payloadString = "$" + onesString + rpmString + "$" + tensString + "rpmString" + "!";
            //using Arduino String objects is generally not a good idea due to memory constraints
            //it's probably ok, but I'd rather use character arrays and/or print a bit at a time rather than trying to assemble a giant string
            Serial2.print("$");
            Serial2.print(mphValue % 10); //ones
            Serial2.print(rpmStrings[rpmStringIndex]);
            Serial2.print("$");
            Serial2.print(mphValue / 10); //tens - integer division, don't need modulo

            //do you really want to append the string "rpmString!" or did you want the contents of the variabe rmpString+"!" ?
            //I'm pretty sure you meant the latter
            Serial2.print(rpmStrings[rpmStringIndex]);
            Serial2.print("!");
        }
        else
        {
            //obd read error
            //add debugging output here to see if obd failed to respond correctly/on time
        }
    }

    int kphToMph( int kphValue ) {
        //return a value rather than updating a global variable
        return ( int ) ( kphValue * 0.621371 );
    }

    int determineRpmIndex( int rpmValue ) {
        if ( rpmValue >= 5000 )
            return 2;

        if ( rpmValue >= 3000 )
            return 1;

        return 0;
    }


body:
I was found solution with

Serial.setTimeout(100);

Like this (https://www.arduino.cc/en/Serial/SetTimeout) setTimeout was 1000ms default.

the check serial port per 1000ms.

I referenced this https://stackoverflow.com/a/28892086/929740


message:
How can I convert Arduino String to C string type?

I got a `String` which as I understand is an Arduino object, and got some C++ code:

    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    #include <string.h>

    LiquidCrystal_I2C lcd(0x20,16,2);

    boolean borrar = false;
    String IP;

    void setup()
    {
      lcd.init();
      lcd.backlight();
      pinMode(13,OUTPUT);
      Serial.begin(9600);
      Serial1.begin(9600);

    }

    void loop() {

      while (Serial1.available()) {

        char caracter = Serial1.read(); //Comprobamos el caracter

        switch(caracter) {

        default:
                    if (borrar) {
                                  IP = "";
                                  lcd.clear();
                    }

                    lcd.print(caracter);
                    delay(125);
                    borrar = false;

                    IP.concat(caracter);
                    break;

        case '\r':
        case 0x0F:
        case 0x0A:

                    String res = "";
                    borrar = true;
                    int num= atoi(IP.c_str());
                    if (num < 127)
                      res="Clase A";
                    if (num == 127)
                      res="Direccion reservada";
                    if (num > 127 && num < 192)
                      res="Clase B ";
                    if (num >= 192 && num < 224)
                      res="Clase C ";
                    if (num >= 224 && num < 240)
                      res="Clase D ";
                    if (num >= 240 && num < 255)
                      res="Clase E ";
                    break;

      } //fin switch

    }//serial disponible

    }//fin programa

However, this won't compile because of this line:

    int num= atoi(IP.c_str())

As IP is a **`String`** and such method works for **`string`**. How can I make it compatible (convert it)?

body:
Try

    unsigned char z[100];
    IP.getBytes(z, 100);
    z[IP.length()] = 0;
    int n = atoi(z);

To retrieve bytes inside the string. This assumes IP string's length is shorter than 100.


body:
Try updating to the latest version of the Arduino libraries/IDE.

The `c_str()` method was introduced to the Arduino String class quite recently, I believe. That line of code certainly works fine for me on Arduino IDE 1.0.5.


body:
Your code could be improved by removing the use of `IP` string altogether, and directly calculating its numeric value while characters come in through `Serial1`:

    ...
    boolean borrar = false;
    int IP = 0;
    ...

    void loop() {
      while (Serial1.available()) {
        char caracter = Serial1.read(); //Comprobamos el caracter
        switch(caracter) {

        // NOTE it is better to replace default by the list of all digits...
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
                    if (borrar) {
                                  IP = 0;
                                  lcd.clear();
                    }

                    lcd.print(caracter);
                    delay(125);
                    borrar = false;

                    IP *= 10;
                    IP += (int) (caracter - '0');
                    break;

        case '\r':
        case 0x0F:
        case 0x0A:

                    String res = "";
                    borrar = true;
                    int num= IP;
                    if (num < 127)
                      res="Clase A";
                    if (num == 127)
                      res="Direccion reservada";
                    if (num > 127 && num < 192)
                      res="Clase B ";
                    if (num >= 192 && num < 224)
                      res="Clase C ";
                    if (num >= 224 && num < 240)
                      res="Clase D ";
                    if (num >= 240 && num < 255)
                      res="Clase E ";
                    break;

      } //fin switch

    }//serial disponible

    }//fin programa

This way would bring you 2 advantages:

1. a bit faster than working with `String`
2. no dynamic memory allocation/deallocation (`String` does a lot of these) which might lead your program to **[heap fragmentation][1]** and eventually crash.

Note that I have not further refactored your code as I guessed it was just a snippet, not the complete code for your program. Otherwise, I would have performed further refinement like:

- remove `num` variable since it is the same as `IP` now
- replace `res` from `String` to `const char*` (to further reduce heap fragmentation due to `String` usage)

  [1]: https://arduino.stackexchange.com/questions/763/im-using-too-much-ram-how-can-this-be-measured/787#787


message:
Which voltage regulator should I use?

A friend and I are working on building a smartwatch on a budget, so it’s a (very) low power project, but we are currently having a problem with the power supplying.
We already chose this board, because of its size and the BLE chip: [RFduino BLE SMT](http://www.rfduino.com/product/rfd22301-rfduino-ble-smt/)
For now on, we are planning to use this battery [500 mAh LiPo battery](http://www.adafruit.com/products/1578) (approx. 4V at full charge) with this voltage regulator [Micrel MIC5209-3.6YS](http://www.mouser.com/ds/2/495/mic5209-239527.pdf) (the board supports 3.6V max.).

But the problem is that the Voltage Regulator will apparently drain by itself too much energy from the battery (by heating), reducing drastically the autonomy.

So we would like to know if you guys can help us, if you can tell us exactly what (type of) regulator would be the best or if we need to find another battery.

body: IGND which is mentioned on page 4 of the datasheet is apparently proportional to the output current. This accounts for about 2-5% of the total current drawn by the regulator, depending on its load. With the maximum voltage drop of 4 - 3.6 = 400mV, a switching regulator will make no real difference. I think your only option is to find another regulator that has better efficiency.


message:
Simultanous read and read/write on two serial connections

At the moment I'm using two softserials to connect to a GPS and an GSM module.

It seems not possible to have two open software-serials. So I was looking for an solution

After the initial-setup, the GPS module is only needed to be read from; while the GSM module needs to be bidirectional. So:

    GPS > listen only
    GSM > listen and write

Now I came across the [GPS library from Adafruit][1], which uses an interrupt to receive data. Is this _instead_ of a software serial. Or do I again run into the limitation?

An other solution might be to use the D0 and D1 to attach eg the GPS module. But than I won't be able to see the debug messages in my serial monitor. Is that correct?

Sorry in advance for these n00b questions. But I'm frustrated the things dont work as I want :)

**edit**

* [This is the adafruit GPS board][2].
* And the board with whom it is connected: [Gboard][3]
* The Sim900 is connected to D2/D3 and the GPS is connected to A2/A3.
* D0/D1 are connected to a FTDI breakout board, which is plugged into my USB.

  [1]: https://github.com/adafruit/Adafruit-GPS-Library
  [2]: http://www.adafruit.com/products/746
  [3]: http://imall.iteadstudio.com/im120411004.html

body:
[`Adafruit_GPS.h`](https://github.com/adafruit/Adafruit-GPS-Library/blob/master/Adafruit_GPS.h) (line 132-), which is included in [`Adafruit_GPS.cpp`](https://github.com/adafruit/Adafruit-GPS-Library/blob/master/Adafruit_GPS.cpp) (line 13) refers in turn to the SoftwareSerial library on AVR platform and Arduino IDE version > 100.

    #ifdef __AVR__
    #if ARDUINO >= 100
        SoftwareSerial *gpsSwSerial;
    #else
        NewSoftSerial *gpsSwSerial;
    #endif
    #endif

This means it uses software serial on an Uno. It also means if your problem is indeed with Software Serial, that is the library to check for bugs / updates or commit a patch to.


body:
The solution to your problem might be to combine [AltSoftSerial][1] with SoftwareSerial. I haven't done it myself (yet) but I have the same problem as yours.

SoftwareSerial does busy wait for counting time between two bits, so it can't read simultaneously from two ports (some bits could be lost).

AltSoftSerial was created to overcome some of these limitations. It's interrupt-based. Unfortunately, it's harwired for one port (and pins 7 & 8). My understanding is that you can combine it with SoftwareSerial to read from 2 simultaneous ports. Pins 7 & 8 aren't what you need, from the description of the GBoard, but AltSoftSerial is open source, you can change the pin numbers (and possibly some masks) in the source code.

Hope this helps.

  [1]: https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html


body:
So you want three serial ports: upload/debug (hardware serial), GSM (software serial) and GPS (software serial).  Unfortunately, two SoftSerial ports are not going to work at the same time (or even send and receive at the same time on one SoftSerial port).  In your current configuration it's not going to be solvable.

If you can wire the GPS to different pins, there are a couple of options to try.  One would be to disconnect the FTDI when running (reconnect to program) so you can use the hardware serial port for either GSM or GPS (probably the former).  If you need some print statements for debugging, you could use SoftSerial or AltSoftSerial (and connect the FTDI differently).  Reconnecting between upload/debug and run phases would be a pain but it comes with the platform you are choosing and the number of serial ports you need; you might be able to wire up a DPDT switch externally to do the switching rapidly.

The other and perhaps easier approach would be to connect the GPS to pins 8 and 9, and use AltSoftSerial for the GPS; as long as your baud rate to the GSM is high enough that might work.  (SoftSerial for the GSM will turn off interrupts for excessive periods of time at low baud rates).  Using AltSoftSerial makes use of the single 16 bit timer (Timer1), so this won't work if you use any other library which requires Timer1.


body:
I've done exactly this.  The secret sauce for me was the [SoftwareSerial.listen()](http://arduino.cc/en/Reference/SoftwareSerialListen).

Before running your GSM commands you have to make sure the GSM module's SoftwareSerial port is "listening".  Then when you're done you have to `listen()` again to the GPS.

This is, of course, not terribly efficient, while the GSM port is listening any GPS data will be lost, but at least in my case the impact was negligible.

My code is here: [https://github.com/lectroidmarc/gsm-tracker](https://github.com/lectroidmarc/gsm-tracker)

As an aside, I have also considered plugging the GPS into the UART and running debug messages to a SoftwareSerial serial port, to be monitored during testing with another Arduino.  I'm just not sure the benefit would be there.


message:
SeeedDuino/Grove and the story of not being able to upload programs

I am new to the arduino world and wanted to start playing with the micro controllers, I am a .NET developer by trade so not completely new to this kind of world.

I purchased a seeedduino v3 and a Grove started kit (No soldering skills here) and can't even get the basics to work.

I am setting up a simple button to light up the LED program. I have had it run once or twice but it seems really hit or miss on whether or not the Arduino IDE actually gets the program onto the seeedduino.

***Arduino IDE (1.5.6-r2) set-up:***
Followed setup instructions found here: [SeeedDuino v3][1]

 - Board: Arduino Duemilanove or Diecimila
 - Processor: ATmega328
 - Port: COM4 [this is what popped up once device was plugged in]
 - Button is installed on D3
 - LED is installed on D7

***Program:***

    int button = 3;
    int LED = 7;

    void setup()
    {
      pinMode(button, INPUT); //define button on INPUT devices
      pinMode(LED, OUTPUT);   //define LED on OUTPUT device
    }

    void loop()
    {
      int buttonState = digitalRead(button); //read the status of hte button

      if(buttonState == HIGH) //also used (buttonState == 1)
      {
        digitalWrite(LED, HIGH); //also used digitalWrite(LED, 1)
      }
      else
      {
        digitalWrite(LED, LOW); //also used digitalWrite(LED, 0)
      }
    }

Upload Verbose Message:

    avrdude: verifying ...
    avrdude: 1070 bytes of flash verified
    avrdude: Send: Q [51]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [10]

    avrdude done.  Thank you.

I have only had the LED from this program turn on twice, then reloading it ruins it.

***SIDE NOTE***

If I try and run Burn BootLoader I get this message-

    avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

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

             Using Port                    : usb
             Using Programmer              : stk500v2
    avrdude: usbdev_open(): did not find any USB device "usb"

  [1]: http://www.seeedstudio.com/wiki/Seeeduino_v3.0#How_do_I_configure_the_Arduino_IDE.3F

body:
OK mystery solved!

I ended up getting [Visual Micro Debugger][1] plug-in for my Visual Studio 2013 since I am native .NET programmer. I could see that the code was indeed loaded onto the board and when I pressed the button it was indeed getting to the line of code for setting the digital LED to HIGH.

It was a very unfortunate case of trying different components and learning I actually had 3 dead LEDs and one bad cable. After getting functioning ones it's all good. :) unlucky me just had 4 bad parts in my kit.

Output from Visual Studio Debugging:

    Legend:
    line 12 = button state check
    line 16 = button pressed turn on LED
    line 20 = button not pressed turn off LED

    =================OUTPUT====================
    14:01:04.372 SeeedDuinoPlayground.ino, line 12 loop()
    14:01:04.372 SeeedDuinoPlayground.ino, line 16 loop()
    14:01:04.481 SeeedDuinoPlayground.ino, line 10
    14:01:04.481 SeeedDuinoPlayground.ino, line 12 loop()
    14:01:04.592 SeeedDuinoPlayground.ino, line 16 loop()
    14:01:04.592 SeeedDuinoPlayground.ino, line 10
    14:01:04.696 SeeedDuinoPlayground.ino, line 12 loop()
    14:01:04.697 SeeedDuinoPlayground.ino, line 20 loop()
    14:01:04.804 SeeedDuinoPlayground.ino, line 10
    14:01:04.804 SeeedDuinoPlayground.ino, line 12 loop()
    14:01:04.912 SeeedDuinoPlayground.ino, line 20 loop()

  [1]: http://www.visualmicro.com/


message:
Check contents of buffer after serial read

I would like to test the contents of data received over a serial connection. In my loop() I store the data in bffr; and afterwards I would like to test to see if there are some predefined words in it.

    #define BFFSZ 90
    char bffr[BFFSZ];
    char bffridx;

    void loop()
    {
       readline();

       //- Test the bffr
           if(strstr(bffr, "CLOSED")){ //- WORKS
              Serial.println("> conn. closed");
              digitalWrite(A1, HIGH);
           }else if(strstr(bffr, "RING")){ //- WORKS
              Serial.println("> Someone is ringing");
              digitalWrite(A2, HIGH);
           }else if(strstr(bffr, "0,7,j,BLINK")){ //- Doesn't work
              Serial.println("> Blink");
              digitalWrite(A2, HIGH);
              delay(300);
              digitalWrite(A2, LOW);
           }
    }

    void readline()
    {
       memset(bffr,0,sizeof(bffr));
       char c;
       int i =0;
       bffridx = 0; // start at beginning

       long previousMillis = millis();
       while (1) {
         unsigned long currentMillis = millis();
         if(currentMillis - previousMillis > 20000) {
           Serial.println("TIMEOUT");
           return;
         }
         delay(2);

         c=gsm.SimpleRead2();
         //- debug only, to see if there is something received.
         Serial.write(c);

         if (c == -1)
           continue;
         if (c == '\n')
           continue;
         if ((bffridx == BFFSZ-1) || (c == '\r')) {
           bffr[bffridx] = 0;
           return;
         }

         bffr[bffridx++]= c;
         delay(2);
       }
    }

The debug-line makes that I can see the data flowing, eg when I phone the SIM.

But it looks like the buffer isn't tested properly. The first two will work, but the last test fails. It is part of a larger string: `$0,7,j,BLINK,567^` But I thought the `strstr(1,2)` searches for 2 in 1. And as `0,7,j,BLINK,` is within the haystack I assume it wil return true. But apparently not...

The `gsm.SimpleRead2()` comes from [GSMlib][1] and is my altered version of gsm.SimpleRead(). Instead of printing the char, I just return it so we can buffer it in the `readline` function.

    void SIMCOM900::SimpleRead()
    {

     char datain;
     if(_cell.available()>0){
       datain=_cell.read();
       if(datain>0){
         Serial.print(datain);
       }
     }
    }
    char SIMCOM900::SimpleRead2()
    {

     char datain;
     if(_cell.available()>0){
       datain=_cell.read();
       if(datain>0){
         return datain;
       }
     }
    }

Does anyone know the answer to this?

  [1]: http://www.gsmlib.org/download.html

body:
After a `serial.read();`, the data [as far as I can tell] is pretty much destroyed. You have two main options to accomplish this:

 - Store the data in a string when read and then reference this later. I'd do this with a *global variable*, that is declared outside of a method and accessible throughout your whole sketch.
 - I haven't read throughout your whole code, but, if you only need to read one character, you can use [`serial.peek();`](http://arduino.cc/en/Serial/Peek). **This only works if you need the first character of the buffer.**

Most likely, your only option would be the first bullet. I'd implement this by adding a method something like this:

    String buffer_string_serial;

    void setup() { //code here }

    void loop() { //code here }

    int serial_read_buffer() {
      while(serial.avaliable() > 0) {
        buffer_string_serial = buffer_string_serial + serial.peek();
        return serial.read();
      }
    }

Then, just use `serial_read_buffer();`. That will act similar to `serial.read();`. The only difference is it will fill up the `buffer_string_serial` string. You'll have to clear that out after you used all the data so it doesn't get full.


message:
Matching Baud Rates

So I am working on speeding up a nixie tube speedometer, in this question: , but this brought up another question.  Would having matching baud rates for multiple external devices speed up processes.

 In the case of the other question the OBD-II device is running at 38400 where the Nixie Tubes are running at 9600.  Since I'm taking the info from the OBD-II connector and doing a little math and sending it to the Nixie Tubes, would it be beneficial to have the same baud rate for both devices?

Now... before you down-vote this question for making some sort of "duplicate" this also answers a question about having a "master" serial hub and having communication between different "slave" serial devices.

body: It all depends on how often speed is being reported via the OBD-II connection. If the report rate is faster than the update rate of the tubes then yes, increasing the speed of the tube circuit (not necessarily the connection itself) can have an effect (as long as the tubes themselves can keep up, of course). If the speed is being reported slower than the tubes then don't bother unless you have *other* reasons for increasing it, since both bit rates are already so much faster than the human mind can see, much less process.


body:
If you are using different serial ports for each device (eg: using software serial for at least one of them on a Uno, or using separate hardware serial on a Mega2560), then it really doesn't matter whether they use the same baud rate or not.

If you are somehow multiplexing the same serial port (eg: input only from one device, output only to the other; or some external multiplexing hardware) then there might be a slight gain in not needing to change the baud rate when switching between devices, but probably not noticable.

If either or both devices have some option to communicate faster, that might speed up your system - independent of whether they use the SAME rate.


message:
Detect and stream if a chair is occupied

I am planning to build a device able to detect and tell a server via Wi-Fi if a chair is occupied. How would you do it? And how cheap do you think the device could be?

body:
I'm not going to answer this directly, because then you wouldn't learn anything! However, here are a few suggestions:

 - Use a pressure sensor on the seat of the chair or
 - Put a distance sensor (IR or ultrasonic) pointing at the chair.
 - Use the official [Arduino WiFi shield][1].

  [1]: http://arduino.cc/en/Main/ArduinoWiFiShield


body:
For a soft seat you could sense occupancy with an LED and photo-sensor at opposite ends of a short somewhat flexible tube that gets flexed when the cushion compresses, interrupting the light. That or a microswitch would have to be the cheapest means of sensing.

Getting from there to the server depends a little on how much work you're willing to do, from rolling your own micro-controller+WiFi PCB to purchasing off the shelf parts, which may in turn, depend on whether you need to monitor one chair or a whole auditorium.


body:
Oh wow, so many ways you could do this.  To start, get an arduino with a wifi shield to transmit and read data.  Familiarize yourself with how the arduino works with the shield, and how to read it on the other end.  Then it's time to look at sensors you could use.  Here's a couple ideas, I would recommend using more than one and cross-checking:

 1. Force sensor on base of chair: Can tell you how much weight is on a chair (Sparkfun SEN-09376)
 2. IR or sonic sensor on back of chair to detect distance ([example][2])
 3. Vibration/shock sensor to detect if someone has sit down ([example][3])
 4. Load sensor: literally a scale in a sensor. (Sparkfun SEN-10245)

The optimal solution if you had the cash would be to put all of them on the chair and use the arduino to compute all of the sensor values into one boolean.  However, if you only could have one sensor I would recommend the load sensor which would definitely be the most reliable of all the examples I gave.

  [2]: https://www.sparkfun.com/products/242
  [3]: https://www.sparkfun.com/products/9197


body:
You could use [the awesome CapSense-Library][1]. Additionally to the Library you only need a thin piece of conducting material e.g. aluminium foil and two pins on your arduino. The only thing you have to do is experiment with different resistors to reliably distinguish between someone sitting on the chair or not. Advantages of this method are:

 - virtually no costs at all
 - easy to implement
 - not subject to wear and    tear
 - should work with any kind of chair independent of material e.g.
   hard or soft surface
 - consumes next to no power (I assume the whole device runs on battery since it's attached to a movable chair)
 - could even sense a person in the process of seating her-/himself and enable you to start the music faster (my stereo for example takes a second or so to start up)
  [1]: http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense


body:
You could use Electric Field Sensing, it allows you to detect the presence and position of conductive objects even if the sensor is covered by an opaque object. The technology is used in cars to detect if someone is sitting in a seat so the car can beep at you to put your seat-belt on. However, if all you want to do is detect presence then this is no better than using CapSense.

http://web.media.mit.edu/~jrs/efs.html

https://en.wikipedia.org/wiki/Electric_field_proximity_sensing

To communicate with a server over WiFi you could use the Arduino WiFi shield, the Arduino Yun (which has on-board WiFi) or buy a ethernet WiFi adapter and use it with an Arduino board which has ethernet.

http://arduino.cc/en/Main/ArduinoWiFiShield

http://arduino.cc/en/Main/ArduinoBoardYun
(Arduino board with on-board WiFi)

http://arduino.cc/en/Main/ArduinoBoardEthernet


body:
conductive foam as sensor. it chg resistance when compressed.

or use image from camera to determine if seat is occupied. only one source for all data.


message:
How to test the sleep / enable function of Stepper Driver?

I am currently using an Arduino Mega 2560 to run this stepper motor driver (Big Easy Driver, ROB-11876 from sparkfun) https://www.sparkfun.com/products/11876.

I am trying to use the sleep or enable function on this chip to decrease the power consumption when I am not using the motor. I have all the rest of the driver working properly (steps, direction etc.) but when I hook up a wire to either the sleep or enable section and send a respective high or low it doesn't appear to do anything. (Chip works as normal, power consumption stays the same).

I have tested to see that the Arduino is outputting correctly and it seems to be. But other than this I'm kinda at a loss on what might be wrong.

Does anyone have any suggestions on why this might be or other things to test to try to narrow down the problem?

---------------------------
Found my answer from Sparkfun - see below

body:
Just for future reference if anyone needs it I got the following from SparkFun:

On the Big Easy Driver Board, the Step, Dir, Sleep, Reset, and the Microstep pins are all >pulled high with 20kΩ resistors, while Enable is pulled low with the same. So sleep is >disabled (until explicitly enabled) and the stepper is enabled (until explicitly disabled).

For much of the use of this board, there is no real need to adjust these settings, but If you >want to achieve a low-power state you would pull the sleep pin low. This should disable much >of the internal circuitry on the IC. In order to reduce power, Enable should be pulled high >to disable the output FETs.
To test that the sleep function is working on the chip you can just jump it to low (ground). For me it turned out to be an error with the Arduino code rather than the chip. Here is also a good reference about pull-down / pull-up resistors. http://www.bit-101.com/blog/?p=3813