text:
Should all unused analog input ports be tied to ground for accurate A2D measurements?
I am using the A0 port on my Arduino Uno to read the voltage output from an LM35 temperature sensor.  I observed that the reading fluctuates a lot if I leave the remaining analog input ports A1 to A5 floating. Would floating analog inputs affect the accuracy of readings on input ports connected to some signals.

Any floating pin will act as an antenna, and may interfere with values around it, this is one of the major disadvantages of using analog.
To get the most accurate readings with minimal amount of interference, you can pull all unused inputs to ground.
The accuracy will not change, as the accuracy is determined by the sensor itself. However it will reduce the amount of noise / interference, which will give you more accurate readings.
These pull to grounds can be accomplished by configuring the unused analog pins as digital outputs, and setting them low.
pinMode(A1, OUTPUT);
digitalWrite(A1, LOW);

Not sure if it is a lucky guess, but driving an output pin (including An) low is the most energy effective way too. Driving high or enabling the pull-up consumes more energy from the power source.

@jippie - If you don't have any board leakage, they're likely to take about the same power. If you do have leakage, it depends on whether it's to power or ground.

@FakeName No they don't. I read an article one on the very issue. Driving the pin low takes approximately as much current as leaving it high impedance. Driving high or pull-up draws more current. I'll try to find the article later today.

I haven't read the article, but can confirm that driving all pins high pulls marginally more current than all low.

@jippie - Huh, that's weird. I'd expect totem-pole outputs to be symmetrical. Go figure!

Even if setting the unused pins to OUTPUT/LOW consumes a little bit less power than INPUT with PULLUP enabled, i guess the second option is more save.
To quote somebody else:

If you accidentally touch a hot wire to an output set low you short-circuit your processor and frie it. If you accidentally touch a ground wire to an output set high you short-circuit your processor and frie it. If you accidentally touch either wire to an input with pull-up you won't even notice.

source: Stack Exchange

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

sort: votes


text:
Using more than one Ping Ultrasonic Range Finder
I have done various applications with the Ultrasonic example project but it is always using one pinger. I'd like to make a scanner resting on a servo sweep but to reduce sweep time use more than one censor.
the documentation is rather basic ping sonic that states the signal 40khz is used.
Down to the question now. Is there a means to tell one pinger to use 40Khz and another say  45Khz.
This would allow me to scan two areas (different directions) per cycle, reducing the time frame to complete area scan by half.

@NickAlexeev, there actually may not be an answer, the pinger hardware is the key not the Arduino itself - the 40Khz cycle may indeed be fixed by it's hardware.  I will leave it sit a day and then take your suggestion, thank you.

The question might also work on EE.SE, but consider leaving out the Arduino tag if it's not essential.

By the way.  With a single sensor, how long does the scan take?  How many increments?  How much time does the servo adjustment take?  How much time does the actual ping take?

I am sweeping 180 degrees, its about 30 seconds all told, I am guessing from memory I did not time it. But I'd like to reduce the time.

You may want to clarify the question a bit. These ping sensors work on a "pulse driven" method. The Arduino sends the activation pulse, and detects the difference in time from the return (echo). Using two (or more) sensors on separate I/O pins means each sensor is activated (pulsed) separately, their ultrasonic signals do NOT interfere with each other as they will not fire off at the same time.

This question was migrated from Stack Overflow, but it doesn't seem to be about Arduino at all. As per one of the original comments, I'm inclined to migrate it to EE.SE.

There is no way to change the frequency, however there are other ways of doing what you want to accomplish. I think the best thing to do is stagger the timing of the pings so they don't happen at the same time.
Example code, modified by me:
#include <Servo.h>
Servo servo; // create servo object to control a servo

int pingPins[] = {7,8}; //The pins for the two sensors
char *pingString[] = {"Ping1", "Ping2"};

void setup()
{
  servo.attach(10); // attaches a servo to pin 10
  Serial.begin(9600);
}

void loop()
{
  unsigned long ultrasoundValue;
  for(int i = 0; i < ultraSoundSignalPins.length; i++)
  {
    ultrasoundValue = ping(i);
    Serial.print(pingString[i]);
    Serial.print(": ");
    Serial.print(ultrasoundValue);
    Serial.print("in, ");
    delay(50);
  }
  Serial.println();
  delay(50);
 }

//Ping function
unsigned long ping(int i)
{
  unsigned long echo;

  pinMode(pingPins[i], OUTPUT);         // Switch signalpin to output
  digitalWrite(pingPins[i], LOW);       // Send low pulse
  delayMicroseconds(2);                 // Wait for 2 microseconds
  digitalWrite(pingPins[i], HIGH);      // Send high pulse
  delayMicroseconds(5);                 // Wait for 5 microseconds
  digitalWrite(pingPins[i], LOW);       // Holdoff
  pinMode(pingPins[i], INPUT);          // Switch signalpin to input
  digitalWrite(pingPins[i], HIGH);      // Turn on pullup resistor
  echo = pulseIn(pingPins[i], HIGH);    //Listen for echo
  return (echo / 58.138) * .39;         //convert to CM then to inches
}

Sources:

https://stackoverflow.com/questions/20273971/arduino-multiple-ultrasonic-sensors-interference
http://forum.arduino.cc/index.php?topic=17898.0

The Ping))) sensor uses a crystal for timing.
Some of the cheap knock-offs actually use a MAX3232 chip (which is an RS232 serial port/usart) to detect the return pulse, just for the carrier detection. If the parallax is similar, these have a fairly wide range of frequencies they work at, since you never know the baud rate to expect, from 9600 up to 1mhz, although they are deliberately not very fussy about accidentally picking up nearby frequencies.
Since there's probably some other logic on the other chips, and everything is probably run off the one crystal, I'd recommend going to lower frequencies, otherwise you're overclocking.
Also, make sure to send a longer trigger pulse because all the logic will be slower.
From the picture, it looks like a 16MHz crystal, which must be divided down to the 40KHz.
So solder in a 14MHz, and an 11MHz, lengthen the 5 uS trigger pulse accordingly, and you should be good to go.
As an aside, you might also consider scanning further apart. If it's taking you 30 seconds, you're probably checking every degree; maybe try every 15 or 30 degrees (just make sure to give the servo time to move)

I don't think it would be very easy to change the frequency unless Parallax decides to release the firmware for the Ping. It is possible to use two, as long as you use a different data pin for each, but the ultrasonic signals may interfere.

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


text:
How do I manipulate a large number of moving platforms?
I am trying to build a device that will allow me to control at least a couple hundred raising platforms. The goal of this is to create a real time editor for board games (Dungeons and Dragons).
Ideally:

All the platforms would move simultaneously
The platforms would be transparent to allow us to place LEDs inside them to color the platform so we can make colors like blue for water and brown for dirt.

In our current setup, we use some acrylic prisms that are 1 inch x 1 inch x 6 inch (width, length, height). We wanted to use a CNC motor like system to move something around and move a platform. Obviously, this can only raise/lower one item at a time. We calculated (on paper) quite a long update time (calculated approximately 1 sec per platform) to raise/lower a platform. A CNC linear drive type system is the only solution we found that had a reasonable cost/quality (a CNC motor for every platform also raised the power consumption very high). After a few weeks of looking around, planning and throwing stupid ideas away, we found this.
Clearly, it's way better then our idea but I have no idea how they did this. They have 900 platforms and they all work simultaneously. We also don't need real time interaction. Loading from computer and staying static until we change it is good (though water movement would be really nice).
What would you guys recommend to raise simultaneously a thousand small platforms?

After looking at this document that the devs made, and doing a bit more research I found that the device they used to move the platforms cost approxomently $30; I don't think I need to say this, but I don't have $27,000.
Key difference between their implementation and our goal:

No real-time interaction with the table. Controlled by an Arduino is fine.
Size of the platforms will be closer to 1 inch^2
All sides of the platform should be light up, but I believe this is mostly a question of choosing the right material

What do you plan to use to control the setup?

If possible an arduino as maybe we would want water to be consistently moving. If not a desktop is also a possibility (thx for the edit :)

It would be great if you could find a proper image (not the gif that you have linked) to allow others to visualize what it is you are talking about. It took me a long time to even understand what you were describing :)

I found the video MIT made

Are you sure the pricing is right?

@TheDoctor, more or less, they have 900 platforms and the device they use (revealed in the paper) seems to cost around $30 on various site I found. That's excluding the material, table, lights etc etc
@ annon, thx, i did :)

How many defined states (positions) is each platform supposed to have?

@KlausWarzecha, anythign between max and min

Do you really need 1,000 platforms? That seems like a pretty big game board, but I've never played that game.

@AnnonomusPerson, do you really need 500gb of extra space in your hard drive? :P Not reaaallly but its there in case you do have a situation where the map you wish to describe is actually really big. But I could say that most maps WE play on would fit in 20x20 (400). But the map size depends on a few factor. Maybe my group can play on a 20x20 but another group needs a 50x50 because there are 4 time as many players

In terms of cost, perhaps it would be best to build a 4x4 prototype.
My first thought was to use inexpensive servos with a flexible rod inside a sheath, perhaps a wire, like a bicycle brake/gear.  The amount of movement could then be governed by the size of the armature on an inexpensive servo.
Servos will position themselves after being given the command, so there's no need to wait and do them one-by-one.  Fire off the command, then use some sort of multiplexed output like multiple 74HC595 shift registers to connect to the next one.
If the tiles were spring loaded, such that they returned to the topmost position by themselves, only a simple pull-string is needed to adjust the tile height.  Even a very light filament (like fishing line) would be strong enough for the pull.  This would allow the servos to be positioned even some metres away from the table.


text:
Is my Arduino destroyed or are the pins destroyed?
I made a working model of Bluetooth light control with arduino and Bluetooth. Everything worked fine and then after some time I connected the circuit again it didn't work and the pins 7,10,11,12 aren't working . I was using a Bluetooth shield but I tried the simple LED flash program and even that's not working .
Please suggest any good way of making it working again or at least explain what happened with it.

If a blink sketch on those pins no longer works, it’s likely that they are destroyed.

Do sketches download to the board OK or do you get an error message? If they download OK, does blink work on other pins? If so, which ones does it work on/which ones does it not work on?

Which bluetooth shield were you using?

Try running the blink LED, on a different terminals.
If the LED is working properly, then most likely the pins are destroyed.
Why are they destroyed?
Most likely, you've withdrawn more current than the pins can actually provide.
According to the datasheet of the Arduino uno, the IO pins can handle up to 40mA.

The only possible way to solve this problem is to change the IC (Atmega328) by another one. It's not guranteed that it will work, but the microcontroller is reletively cheap.
The definite answer can not be determined unless you showed us a schematic of your connection.

Note that a plain ATmega328 will not have a bootloader and would need ISP programming.

But it's also easy to find ATmega328 with Arduino UNO bootloader flashed in already; then the unit price may increase a little bit though (~$1)


text:
Arduino Not Responding During Program
I got an Arduino Uno to play around with, and started to actually dive in. During a program that I am writing for a friend, it suddenly stopped outputting to the serial monitor. When I comment out the part I added (the for loop for changing the names), it still doesn't respond.
#include <TrueRandom.h>
#include <EEPROM.h>
#define numPokemon 151
String nameArray[] = {"MISSINGNO","Bulbasaur","Ivysaur","Venusaur","Charmander","Charmeleon","Charizard","Squirtle",
"Wartortle","Blastoise","Caterpie","Metapod","Butterfree","Weedle","Kakuna","Beedrill","Pidgey","Pidgeotto",
"Pidgeot","Rattata","Raticate","Spearow","Fearow","Ekans","Arbok","Pikachu","Raichu","Sandshrew","Sandslash",
"Nidoran♀","Nidorina","Nidoqueen","Nidoran♂","Nidorino","Nidoking","Clefairy","Clefable","Vulpix","Ninetales","Jigglypuff",
"Wigglytuff","Zubat","Golbat","Oddish","Gloom","Vileplume","Paras","Parasect","Venonat","Venomoth","Diglett","Dugtrio","Meowth",
"Persian","Psyduck","Golduck","Mankey","Primeape","Growlithe","Arcanine","Poliwag","Poliwhirl","Poliwrath","Abra","Kadabra","Alakazam",
"Machop","Machoke","Machamp","Bellsprout","Weepinbell","Victreebel","Tentacool","Tentacruel","Geodude","Graveler","Golem","Ponyta","Rapidash",
"Slowpoke","Slowbro","Magnemite","Magneton","Farfetch`d","Doduo","Dodrio","Seel","Dewgong","Grimer","Muk","Shellder","Cloyster","Gastly","Haunter",
"Gengar","Onix","Drowzee","Hypno","Krabby","Kingler","Voltorb","Electrode","Exeggcute","Exeggutor","Cubone","Marowak","Hitmonlee","Hitmonchan","Lickitung",
"Koffing","Weezing","Rhyhorn","Rhydon","Chansey","Tangela","Kangaskhan","Horsea","Seadra","Goldeen","Seaking","Staryu","Starmie","Mr. Mime","Scyther","Jynx",
"Electabuzz","Magmar","Pinsir","Tauros","Magikarp","Gyarados","Lapras","Ditto","Eevee","Vaporeon","Jolteon","Flareon","Porygon","Omanyte","Omastar","Kabuto","Kabutops",
"Aerodactyl","Snorlax","Articuno","Zapdos","Moltres","Dratini","Dragonair","Dragonite","Mewtwo","Mew",
};
int a = 0;
int b = 0;
int value;
String pokemonName;
int currentID = TrueRandom.random(1,numPokemon+1);
// a = CurrentID
void setup(){
  Serial.begin(9600);
  if (EEPROM.read(a)!=0){
    currentID = EEPROM.read(a);
    Serial.print("The Stored ID is ");
    Serial.println(EEPROM.read(a));
    Serial.println("Stored = true");
  }else{
    value = EEPROM.read(a);
    Serial.println(value);
    EEPROM.write(a,currentID);
    value = EEPROM.read(a);
    Serial.println(value);
    Serial.println("Stored = false");
  }
  for (int i = 0 ; i < 152 ; i++){
      if (currentID = i){
        pokemonName = nameArray[i];
        Serial.print(pokemonName);
        break;
      }
   }
  //nameChange(currentID);
  //Serial.println(pokemonName);
}
void loop(){

}
void nameChange(int currentID){
   for (int i = 0 ; i < 152 ; i++){
      if (currentID = i){
        pokemonName = nameArray[i];
        break;
      }
   }
}

What is the problem with this code?

Some of the problems include (as mentioned elsewhere) some simple bugs like using the assignment versus equality operator, and treating an Arduino Uno like a full-blown computer with gobs of memory. Funny thing is, had you done this with an Arduino Mega 2560, it would probably have worked for a longer period of time.

The primary reason that this isn't working is that you are using more RAM than the ATmega328 has (2Kbytes).
The array nameArray is huge. Each one of those characters is 1 byte, it's ~1.1k in itself. Add in Serial, TrueRandom and String, and you are over the limit. It could be you are right on the bounds and calling a single function pushes the stack over it's limit.
To save size, you can place the strings in flash. There is functionality to do this in Arduino, namely PROGMEM directive from underlying AVR-GCC and F() from Arduino. Making arrays of string is quite painful though, and using the Flash library helps here.
Personally I would avoid String for anything like this. The insides of String use dynamic memory allocation and when you are near the limits of RAM, it really isn't helpful. You lose a lot of ease of use by moving to arrays of char though.
You are also using assignment instead of comparison in your code:
if (currentID = i){
   pokemonName = nameArray[i];
   Serial.print(pokemonName);
   break;
}

This needs to be currentID == i.
I'm not confident what you are doing here though. If you want to get the i th element from the array, then just do
pokemonName = nameArray[currentID]

You also have an odd conditional at the beginning where you check for an EEPROM value being non zero, and then the else reads out the EEPROM value which by definition must be zero.
Also, you have a define for numPokemon but you aren't using it for the bounds on your for loops.

You have mixed up your comparison and assignment operators in two instances:
First is towards the end of setup.
  for (int i = 0 ; i < 152 ; i++){
      //if (currentID = i){ //This is assignment, not comparison
      //This is a comparison operation
        if (currentID == i){
        pokemonName = nameArray[i];
        Serial.print(pokemonName);
        break;
      }
   }

Second, is in the function definition of nameChange.
void nameChange(int currentID){
   for (int i = 0 ; i < 152 ; i++){
      //if (currentID = i){ //This is an assignment operation, not comparison.
      //This is a comparison operation
        if (currentID == i){
        pokemonName = nameArray[i];
        break;
      }
   }

Also, you have defined a constant numPokemon but are not using it at any point.

the string array is too big for ram, place it in flash with the fucntion F()
Serial.println(F("This string will be stored in flash memory"));

also a detailed example with array with explanation cn be found here


text:
What's the difference/relationship between Arduino and AVR?
I'd always thought Arduino was a microcontroller platform but the actual microcontroller is an AVR chip made by Atmel, or something like that made by someone else, based on a RISC ISA, and Arduino is usually used to refer to the whole circuit board powered by this AVR chip. Is my understanding correct?
What's the difference/relationship between Arduino and AVR?

Arduino is a prototyping board, and the term "Arduino" is also used to refer to the IDE and library on the PC side, and the whole ecosystem.
AVR is the architecture (developed by Atmel) of the microcontroller chip used in all official 8-bit boards, and almost all clones.
Arduino UNO and 2009, the most used boards, use the AtMega328P chip.
Many times, Arduino is used to quickly test some idea, sensor, and circuitry, then a stand-alone board is built around the AtMega chip, as it cost 1/10 of the Arduino board, soldered circuit on a stripboard or on a custom PCB are more reitable, and can be optimized on some aspect, like power usage, space occupied, high current/voltage, and so on.
Newest and advanced Arduino board use a different chip with a very different architecture; the Arduino Yun uses a SAM plus a classic AVR, the Due uses an ARM (same architecture used by many smartphones), the Galileo use an x86 (like a classic single-core cpu).

Arduino is a set of open-sourced hardware- and software specifications, originally conceived as a students' platform. I would add that the specifications, though openly available, are distributed under various public licenses.
There are "official" Arduino boards made by an Italian company of the same name, but as the board designs are open-sourced, there are lots of good (and a few "less good") variants from other sources.
AVR refers to the line of MCUs manufactured by Atmel and used in the original designs. Atmel was acquired in 2016 by Microchip Technology, who continue to manufacture the AVR devices.
Some of the more recent Arduino designs use more capable processors from other chip manufacturers, but many still use the Atmel/Microchip AVR processors. The smaller AVRs' relative simplicity (ATtiny & ATmega, f/ex) make them ideal for quickly designing/building boards and software for less demanding applications and for learning about programming and digital controls.

The Arduino is an AVR processor running special code that lets you use the Arduino environment.
AVR's can be used by themselves with some additional supporting components.
Arduino is a combination of both AVR(chip) and breadboard.
AVR is a single chip, and would require a breadboard.

For the record, you can use the Arduino environment for many AVR chips without any special code. The only extra thing you need is an AVR programmer which could be a $40, official Atmel one, or a $5 USPASP programmer, or even another Arduino running the ArduinoISP sketch.

Arduino is really a common set of code that makes using the dev boards they sell accessible to wide range of user base.
Arduino is basically an IDE that uses the C/C++ language and a set of classes that are adaptable to common set of hardware, predominantly Atmel and mostly AVR although as people have mentioned already the Arduino boards are becoming increasingly more powerful. But is amazing how much you can do with the ATmega328p.
You don't have to use the Arduino IDE to program your board and in fact, I tend to use Atmel Studio myself or Notepad++. You can get a plug-in for Atmel Studio 6.2 and above that allows you to create sketches and upload them to most Arduino boards.

The Arduino tools and ecosystem supports processors other than just Atmel AVR chips.  For instance the Arduino Due uses an ARM Cortex-M3 processor.

Although the previous answers are technically correct, I think there is currently a shift in the meaning of "Arduino".
When the original Arduino boards were released they were head and shoulders better than the competition, especially when looking at the cost vs performance tradeoff.
But this is no longer the case. Boards based around the ESP8266 and ESP32 chips are cheaper and far more powerful than the Atmel chips. Also, the AVR IDE environment has been extended to support these chips. And to further confuse the issue this "Arduinio" forum has almost 2000 questions tagged ESP8266 and around 850 tagged ESP32.
So expect changes. They are already happening. Will "Arduino" come to mean any chip supported by the IDE? Will this forum move to a more generic name like IOT? I really don't know.

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


text:
Passing variable in url
Working on a arduino script where I am right now entering manually the value with the URL, but wondering how to do it with a int in a loop.
This is the url and how it works now:
student.cs.hioa.no/~s180343/updatedb.php?verdi=25

Code:
#include <Process.h>

void setup() {
  // Initialize Bridge
  Bridge.begin();

  // Initialize Serial
  Serial.begin(9600);

  // Wait until a Serial Monitor is connected.
  while (!Serial);
  Serial.println("Ready");

  // run various example processes

}

void loop() {
   runCurl();
   delay(10000);
}

void runCurl() {
  // Launch "curl" command and get Arduino ascii art logo from the network
  // curl is command line program for transferring data using different internet protocols
  Process p;        // Create a process and call it "p"
  p.begin("curl");  // Process that launch the "curl" command
  p.addParameter("student.cs.hioa.no/~s180343/updatedb.php?verdi=25"); // Add the URL parameter to "curl"
  p.run();      // Run the process and wait for its termination

  // A process output can be read with the stream methods
  while (p.available()>0) {
    char c = p.read();
    Serial.print(c);
  }
  // Ensure the last bit of data is sent.
  Serial.flush();
}


text:
Communication with two XBee's and Arduinos over serial
I have two XBee's connected to two Arduino Uno boards (one for each XBee). I connected each XBee to the X-CTU software, and have set the following:
XBee 1
Pan ID = 4270
DL = 10
MY = 20
XBee 2
Pan ID = 4270
DL = 20
MY = 10
Both
DD = 10000
IC = FF
IR = 32
Therefore, they should be on the same network and see each other as the 'other person' each is talking to. I'm using the TX and RX pins of the arduino and the XBee to communicate over the serial port.
When testing if each can hear the other, I loaded one arduino with this code:
#include <SPI.h>

void setup() {
// put your setup code here, to run once:
  Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
  Serial.print('x');
  delay(1000);
}

Then another with this:
#include <SPI.h>

void setup() {
// put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(7,OUTPUT);
  digitalWrite(7,LOW);
}
void loop() {
// put your main code here, to run repeatedly:
  if(Serial.available())
  {
    char getData = Serial.read();
    if(getData == 'x')
    {
      digitalWrite(7,HIGH);
      delay(500);
      digitalWrite(7,LOW);
      delay(500);
    }
  Serial.print(getData);
  getData = ' ';
  }
}

This works perfectly. One LED will light up on the correct arduino in half second intervals. However, when I try to make them both communicate at the same time to each other, nothing happens. Neither LED will light up. The code for both arduino's is:
#include <SPI.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(7,OUTPUT);
  digitalWrite(7,LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print('x');
  delay(1000);
  if(Serial.available())
  {
      char getData = Serial.read();
      if(getData == 'y')
      {
        digitalWrite(7,HIGH);
        delay(500);
        digitalWrite(7,LOW);
        delay(500);
      }
      Serial.print(getData);
      getData = ' ';
    }
}

But for one arduino I change the code to Serial.print('y') and if(getData == 'x') to listen for the other one. I also have tried delaying one arduino in the setup by one second to offset the sending and recieving, but that also doesn't help.
I need them to be able to listen and talk to each other, maybe even at the same time like this example. I'm trying to create a proximity sensor in, lets say the 'back', area communicate with the 'front' area, and an accelerometer and two switches from the 'front' communicate with the 'back'.
Is there any settings I can change in X-CTU, such as the baud rate or the amount of packets re-sent, to overcome this problem? Or is this merely a code issue?
I do have the power connected to the 3.3V pin of the arduino, and I'm using 470/220 Ohm resistors as voltage dividers for the output pins from the arduino to the XBee, so I don't think voltage is an issue here.
Also, I have disconnected the arduino from the computer. I'm powering it via the USB-A to USB-B cord -> 13000 mAh 5V DC rechargeable battery, so there should be no interference with the serial data lines. Pin 2 (RX) of the XBee is connected to pin D0 (RX) of the arduino, and pin 3 (TX) of the XBee is connected to pin D1 (TX) of the arduino.
Thanks for your help.

I've seen a few posts that include the SoftwareSerial library. Could this help?

Have you tested the modules with X-CTU's terminal to see if you can send something from one module to the other? That would help determining if you have ahardware problem, a configuration problem or a software problem.

Did you set one of your modules into coordinator mode?
Every xBee network needs a coordinator. Therefore, you need to put one of your Xbee modules into coordinator mode using the "Function Set" dropdown box in X-CTU. The coordinator has the fixed address 0, so you need to set DL and HL address parts of the other module to 0. On your coordinator, you can set DL to FFFF and HL to 0, which is the broadcast address.
Softserial won't help you. It's just a way to use some of the pins as an additional serial port. Don't use that if you can use a hardware serial port.

I removed the wrong information abou routers.

Yeah I did try that, I ended up just resetting the firmware back to factory settings and only changed the pan ID. For some reason that worked so I guess that's all I had to do.. Thanks for the reply though.


text:
Arduino Serial Communication
I'm trying to communicate with the Arduino through the serial port to fade the LED.
There's the code running on my Arduino:
#include <aJSON.h>
aJsonStream serial_stream(&Serial);

const int localID = 1;
int intensity = 100;        // fadeTo value(0% - 100%)
int currentIntensity = 0;   // how bright the LED actually is (0-100%)
int time = 0;               // milliseconds
int color[] = {0, 255, 0};

int pinRed = 11;
int pinGreen = 10;
int pinBlue = 9;
int pinPower = 8;

void fadeTo() {
  if(intensity != currentIntensity) {
    if(intensity > currentIntensity)
      currentIntensity+=1;
    else
      currentIntensity-=1;

    analogWrite(pinRed,255-currentIntensity);
    analogWrite(pinGreen,255-currentIntensity);
    analogWrite(pinBlue,255-currentIntensity);
  }
}

aJsonObject *createMsg()
{
    aJsonObject *orbData, *colorData;

    orbData = aJson.createObject();
    aJson.addNumberToObject(orbData, "id", (int)localID);

    aJson.addNumberToObject(orbData, "currentIntensity", (int)currentIntensity);

    //aJson.addNumberToObject(orbData, "time", (int)time);

    colorData = aJson.createIntArray(color, 3);
    aJson.addItemToObject(orbData, "color", colorData);

    return orbData;
}

// echo {\"id\":1, \"intensity\":150, \"time\":10} >> /dev/ttyACM0 in terminal
// {"id":1, "intensity":150, "time":10} in Serial Monitor
void processMsg(aJsonObject *msg)
{
    //Serial.println("Data succefully received.");
    Serial.println("received message: ");
    aJson.print(msg, &serial_stream);

    aJsonObject *idData = aJson.getObjectItem(msg, "id");
    if(idData != NULL)
    {
        Serial.println("ID data succefully received.");
        if(localID == (idData->valueint)) {

            aJsonObject *intensityData = aJson.getObjectItem(msg, "intensity");
            if(intensityData != NULL) {
                if(intensityData->type != aJson_Int) {
                    Serial.println("Invalid data type for Intensity");
                    return;
                }

                if(intensityData->valueint == currentIntensity) {
                    Serial.println("The received intensity value is already the current LED intensity");
                    return;
                }

                else {
                    Serial.println("Intensity data succefully received");
                    intensity = intensityData->valueint;
                }
            }
            else {
                Serial.println("No intensity value received.");
                return;
            }

            aJsonObject *timeData = aJson.getObjectItem(msg, "time");
            if(timeData != NULL) {
                if(timeData->type != aJson_Int) {
                    Serial.println("Invalid data type for time");
                    return;
                }
                else {
                    Serial.println("Time data succefully received");
                    time = (timeData->valueint);
                }
            }
        }

        else {
          Serial.println("The received ID is not mine.");
          return;
        }
    }

    else {
      Serial.println("No ID data received.");
      return;
    }

    Serial.println("received message: ");
    aJson.print(msg, &serial_stream);
}

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

    pinMode(pinRed,OUTPUT);
    pinMode(pinGreen,OUTPUT);
    pinMode(pinBlue,OUTPUT);
    pinMode(pinPower,OUTPUT);

    digitalWrite(pinPower,HIGH);
    digitalWrite(pinRed,HIGH);
    digitalWrite(pinGreen,HIGH);
    digitalWrite(pinBlue,HIGH);
}

void loop()
{
    aJsonObject *orbData = createMsg();

    Serial.println("current status: ");
    aJson.print(orbData, &serial_stream);

    Serial.println();

    aJson.deleteItem(orbData);
    delay(100);

    fadeTo();

}

void serialEvent()
{
    if(serial_stream.available())
    {
        // first, skip any accidental whitespace like newlines
        serial_stream.skip();
    }

    if(serial_stream.available())
    {
        aJsonObject *msg = aJson.parse(&serial_stream);

        processMsg(msg);

        aJson.deleteItem(msg);
    }
}

The problem is, I can open my Serial Monitor in the Arduino IDE and send json data to the Arduino and I see live the changes through the output and the LED on the board. I can also send data through terminal to /dev/ttyACM0 while running Serial Monitor in the IDE and it works fine too. But as soon as I close the Serial Monitor and send data to the device through terminal, it breaks down. I can then open Serial Monitor and every time I get the ERROR from json parser --> ("No ID data received.").
Has anyone any idea why this is happening?

My first thought would be that the port speed and settings change back to defaults when you close the IDEs Serial monitor?

This really should go back to stackoverflow, as the problem is with not using the desktop serial configuration APIs.  Basically, you need to set a variety of serial port settings in a compatible way - when you (somewhat dangerously) "share" the port you inherit those set by the serial monitor, until it sets them back on exit.  You may be able to use a command line stty program to discover how the serial monitor is setting the port.

How are you opening the serial port when you communicate "through terminal" ?  It's application dependant whether the serial port settings are restored to their original state when the port is closed.  From your result it seems like the Arduino IDE is restoring them (which is best practise).

I had a similar problem trying to use the commands such as :

echo 1 > /dev/ttyACM0

and found that I needed privileges to perform serial communication in this way like:

sudo echo 1 > /dev/ttyACM0

You could also try setting the baud rate you are communicating at :

sudo echo 1 > /dev/ttyACM0 9600

GOOD LUCK!


text:
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

You can't change the pins.
ArduinoISP uses the SPI interface on pins 10-13 which is provided by the underlying AVR hardware.

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.


text:
Problems with using example code for Wi-Fi shield (arduino)
I have problems with the Wi-Fi shield example code.
#include <SPI.h>
#include <WiFi.h>

char ssid[] = "*****";          //  your network SSID (name)
char pass[] = "*****";   // your network password

int status = WL_IDLE_STATUS;
char servername[]="google.com";  // remote server we will connect to

WiFiClient client;

void setup() {
    Serial.begin(9600);
    //disable SD SPI
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);

    Serial.println("Attempting to connect to WPA network...");
    Serial.print("SSID: ");
    Serial.println(ssid);

    status = WiFi.begin(ssid, pass);
    if ( status != WL_CONNECTED) {
        Serial.println("Couldn't get a wifi connection");
        // don't do anything else:
        while(true);
        }
     else {
     Serial.println("Connected to wifi");
     Serial.println("\nStarting connection...");
     // if you get a connection, report back via serial:
     if (client.connect(servername, 80)) {
         Serial.println("connected");
         // Make a HTTP request:
         client.println("GET /search?q=arduino HTTP/1.0");
         client.println();
      }
    }
}

 void loop() {

}

The Wi-Fi Shield has connected with the internet Wi-Fi, but the last printing was "Starting connection..." I can't get to connect to (google.com), why?

insert a Serial.println(status); and which WL_status is returned? Did it actually connect (WL_CONNECTED) or is it some other result?

Have you upgraded the firmware in your wifi shield? If not, it will have problems connecting. Compile and upload this sketch. If it shows the firmware version as 1.0.0, then you need to upgrade the firmware. If it shows 1.1.0, then it is current as of today.
#include <SPI.h>
#include <WiFi.h>

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while(true);
  }

  Serial.print("Firmware version: ");
  Serial.println(WiFi.firmwareVersion());
}

void loop() {}

Please Note: The chips are numbered differently but run the same Wi-Fi firmware. You can upgrade the firmware without any worries.

I had this problem aswell. The problem was a bug with the official editor of arduino. I fixed this by downgrading the editor to version 1.0.3. (from 1.0.5) You can find a download link for it at the Arduino website.
Hope this helped!
-Kad

#include <WiServer.h>

#define WIRELESS_MODE_INFRA 1
//#define WIRELESS_MODE_ADHOC   2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {146, 227, 174, 29};      // Indirizzo IP
unsigned char gateway_ip[] = {146, 227, 175, 254};      // Indirizzo gateway IP
unsigned char subnet_mask[] = {255, 255, 248, 0};   // Subnet Mask
const prog_char ssid[] PROGMEM = {"enduroam"};      // SSID access point

unsigned char security_type = 3;    // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"EAP-MSCHAP V2"};  // max 64 characters
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {

    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("Hello World!");
        WiServer.print("</html>");

        // URL was recognized
        return true;
    }
    // URL not found
    return false;
}

void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);

  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
}

void loop(){

  // Run WiServer
  WiServer.server_task();

  delay(10);
}

Please add information about your code: what does it do? how does it work?


text:
How to make XBee module interrupt/wake arduino
What I am trying to do is, to have arduino in low power mode and waking up only when a packet is received and is available to be read from the buffer.
A scenario : Zigbee XBee module is not receiving anything, arduino is asleep. Once this particular module receives any data from any other module, it makes the arduino wake up and process this packet.
I've looked almost everywhere possible about this, and people say they do not have a 100% working solution.
Does the XBee module produce a particular output on a specific pin when it receives data? If so, can I connect that pin to the interrupt enabled pin on arduino and with that interrupt arduino or wake it up?
do I need arduino mega for that or is the uno a good enough option?

The pin number 9 and 13 on the Xbee are DTR/RTS used for hardware handshaking. You can connect it to the interrupt pins on the Arduino and program the arduino to wake when the pulse changes. Enable the DTR/RTS feature from X-CTU and it should work. Check this for more information.


text:
error: no '' member function declared in class 'SonarSRF08'
Hi, I am a pretty novice coder and I am getting this error consistently with a library I have installed. Here is the code I am trying to run:
#include <Wire.h>
#include <SonarSRF02.h>
#include <SonarSRF08.h>

#define leftAddress ( 0xF2 >> 1)
#define rightAddress ( 0xE0 >> 1)
#define mainAddress ( 0xF8 >> 1)
SonarSRF02 LeftSonar;
SonarSRF02 RightSonar;
SonarSRF08 MainSonar;

char unit = 'c'; // 'i' for inches, 'c' for centimeters, 'm' for micro-seconds

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

    LeftSonar.connect(leftAddress);
    Serial.println("Left SRF02 US-Sensor ");
    Serial.println(LeftSonar.getSoft());

    RightSonar.connect(rightAddress);
    Serial.println("Right SRF02 US-Sensor ");
    Serial.println(RightSonar.getSoft());

    MainSonar.connect(mainAddress);
    Serial.println("Main SRF08 US-Sensor ");
    Serial.println(MainSonar.getSoft());
}

void loop() {
    float sensorReading = 0;

    sensorReading = LeftSonar.getRange(unit);
    // print out distance
    Serial.print("Distance from left: ");
    Serial.print(sensorReading);
    Serial.print(" ");
    Serial.print(unit);
    Serial.println();

    sensorReading = RightSonar.getRange(unit);
    // print out distance
    Serial.print("Distance from right: ");
    Serial.print(sensorReading);
    Serial.print(" ");
    Serial.print(unit);
    Serial.println();

    sensorReading = MainSonar.getRange(unit);
    // print out distance
    Serial.print("Distance from main: ");
    Serial.print(sensorReading);
    Serial.print(" ");
    Serial.print(unit);
    Serial.println();
}

My project is using an SRF08 sensor with an Arduino Mega 2560

Please note that I did not try to run your code on my Mega because I don't have SRFs
However, here is what I tried to recreate your error:

I went to the arduino homepage and downloaded the 1.0.5 version.

I downloaded the zipped library from this page SRF08 Ultra Sonic Range Finder

I imported the library into the arduino IDE. For this, I had to unpack the .zip and rename the folder of the library because arduino complained about non-ascii characters. I just called the enclosing folder "arduinoSRFmaster" without dashes. After that it let me import the library the usual way:

After that I copied your code into a new sketch and hit Ctrl + R to compile and verify. It compiled just fine:

(Picture updated for compiling against MEGA)
Please provide more information, like yor OS, Arduino Version, where you got the SRF Library from etc. if that didn't help.

It seems you have compiled for UNO, maybe the problem is specific to Mega?

There should not be anything specific to the UNO in the code, therefore that should not be any issue. I updated my answer anyway.

Sometimes OS might be a problem. When I used BLE library from Redbearlabs. And compile it I got an error message on Ubuntu. But when I did the same procedure with windows I was able to compile my sketch.

I'll try it on Ubuntu and Mac and update my answer


text:
Parallel shift registers
I'm having trouble with using parallel shift registers, I've studied example codes and I've come up with this function to set the pins to on or off. The problem is the first time the function runs all the output pins are set to HIGH regardless of the values in the array.
    void updateRegister(int ClockPin,int DataPin,int LatchPin){
      int pinState;//Holds the state of the data pin
      pinMode(ClockPin, OUTPUT);//Sets the pinmode of the pins
      pinMode(DataPin, OUTPUT);//Sets the pinmode of the pins
      pinMode(LatchPin, OUTPUT);
      digitalWrite(LatchPin, 0);//Turns latch off to prevent bleedover while shifting

      digitalWrite(DataPin, 0);//clear everything
      digitalWrite(ClockPin, 0);//clear everything

      for (int i=1; i<=16; i++){//Repeats 16 times with i increment from 1 to 16
          if (Qout[i]){pinState= 1;}//Checks the array for the value and if it is true sets the pinstate to 1, HIGH
          else{pinState= 1;}//If it equals false set it to 0, LOW

          digitalWrite(DataPin, pinState);//Sets the data pin depening on the pinstate
          digitalWrite(ClockPin, 1);
          digitalWrite(DataPin, 0);
          digitalWrite(ClockPin, 0);
        }
      digitalWrite(LatchPin, 1);//Turns latch pin back on
    }

I'm storing the boolean values of the each pin in an array called Qout which is defined and all set to false like this
    boolean Qout [17];//Holds the state for each pin
    for (int i = 1; i < 17; i++ ) {Qout[i]=false;}//Sets all output to off

I know I should start at Qout[0] but it just makes it way more confusing.
Can someone help me fix my function so that it actually works.
This is what I based it on ShftOut23

Try bringing ClockPin down before bringing DataPin down and also add some delay before clearing ClockPin(say 1us).

Why not directly use standard Arduino API shiftOut()?

First of all, fix the following part of your code:
if (Qout[i]){pinState= 1;}//Checks the array for the value and if it is true sets the pinstate to 1, HIGH
else{pinState= 1;}//If it equals false set it to 0, LOW

into:
if (Qout[i])
{
    //Checks the array for the value and if it is true sets the pinstate to 1, HIGH
    pinState = 1;
}
else
{
    //If it equals false set it to 0, LOW
    pinState = 0;
}

Of course, if you always set pinState to 0, it won't work as you expect :-)
Note that you should rather use HIGH and LOW constants (more readable) instead of 1 and 0.
Finally, you could make the code much simpler this way:
pinState = (Qout[i] ? HIGH : LOW);


text:
util/delay.h from arduino _delay_ms not delaying in accurate time with my hardware configuration
I have configured my arduino as a flash programmer and i'm sending data to an atmega328P. It is actually working and the data is send to my atmega328. But what is strange that the _delay_ms from  from the Arduino library is not delaying in accurate seconds.
_delay_ms(1000) who should wait from 1s, is actually more 8 seconds from my atmega328P hardware point of view.
My question is what could possibly turn the program wrong. I'm strongly assuming that this a misconfigured clock cycle from my Atmega, but this is my newbie guess,  it can be something else, that's why I'm posting my question here. Can someone can hint me what's wrong with my configuration?
Here's the sample code, a dumb toggle pin on / off:
#include <util/delay.h> // from arduino library

/*
*/

 DDRB |= 0b0000001;

  while (1) {
    PORTB = 0b00000001;
    _delay_ms(1000); // it should be 1 second, but on my hardware it is more ~8 seconds

    PORTB = 0b00000000;
    _delay_ms(1000);
  }

And my configuration is (from arduino IDE)
Arduino Pro / pro Mini (3,3v 8 Mhz) / Atmega 328
I have tried with
Arduino Pro / pro Mini (5v 16 Mhz) / Atmega 328
expecting that more power will affect speed, but the result is actually the same.

It's likely to be the CKDIV8 fuse is set because it's the default, although I'm not sure how you change the fuse settings when using an Arduino as a programmer.

At a 30000 ft. level, it's because the defined F_CPU value doesn't match your hardware. This can happen because the incorrect device is chosen in the IDE or because the device is misconfigured in boards.txt, or because the hardware is somehow different from what is expected.
Given that you are using a bare ATmega328P, assuming that you've selected the correct crystal, and that the apparent time scale is 8x, it is likely that the CKDIV8 fuse is set. This means that the chip is running at 1/8 the crystal speed. You will need to unprogram (set to 1) bit 7 of the low fuse byte in order to reset it. Use AVRdude from the command line to read the low fuse byte (-U lfuse:r:-:h), set the bit (lfuse | 0x80), and then write it back (-U lfuse:w:0xnn:m).

Hi Ignacio. Yes it is exactly what happened. The clock speed was 1/8 speed because of that. I have resolved my problem with using avr-gcc and avrDude from command line. Setting the clock speed at 8000000 (F_CPU) resolved my problem, i think arduino IDE was using 1Mh instead. I have also tried your solution from arduino IDE and it worked like a charm too.


text:
How to create delays in AVR assembly language
Hi i'm new to AVR assembly language so i was trying to get delay function to create 1 ms , 100us, and 1us  delays to do that i need to figure out what to replace nop's with below here (mainboard arduino uno r3 ATmega328
Thank you.
"delay_ms%=:    nop                 ; code to replace  nop  \n"
"delay_100us%=: nop                 ; code to replace  nop  \n"
"delay_1us%=:   nop                 ; code to replace nop  \n"
"               sbiw r30,1          ; decrement ms count (r31:r30)\n"
"               brne delay_ms%=     ; loop to delay_ms while > 0  \n"
"               ret                 ; return from subroutine      \n"

The rest is below.
word millisecs;
Serial.begin(9600);
}
void setup() asm volatile(
"          ldi r16,0x3F    ; r16 = 00111111\n"
"          out 4,r16       ; set pins 8-13 as outputs in DDRB\n"
::: "r16");
millisecs = 1000;            // 1s blink delay
Serial.begin(9600);
}
void loop()
{
long starttime = millis();        // make a note of the start time

asm volatile(
// jump to "blink" - ie jump around the delay_ms subroutine
"            rjmp  blink%=        ; relative jump to 'blink' \n"
"          ldi r16,0x3F    ; r16 = 00111111\n"
"          out 4,r16       ; set pins 8-13 as outputs in DDRB\n"
::: "r16");

registers used:
r31 - millisecond count (lo byte)
r30 - millisecond count (hi byte)
r17 - 100 microsecond count
r16 - 1 microsecond count
Overall delay (ms) = r30:r31 * r17 * r16
---------------------------------------------------------------------*/
"delay_ms%=:    nop                 ; code to replace  nop  \n"
"delay_100us%=: nop                 ; code to replace  nop  \n"
"delay_1us%=:   nop                 ; code to replace nop  \n"
"               sbiw r30,1          ; decrement ms count (r31:r30)\n"
"               brne delay_ms%=     ; loop to delay_ms while > 0  \n"
"               ret                 ; return from subroutine      \n"

This is a pure programming question and probably should have remained on stackoverflow, rather than been migrated here.

its atmega328 so 16mhz but how many clock cycles would that be 16000 for 1 millisecond?

AVR LibC already has macros that do this, provided F_CPU is set correctly.
// Note: The Arduino IDE gets the value for F_CPU from boards.txt
#define F_CPU xxxxxxxxxx

#include <util/delay.h>

 ...

_delay_ms(1);
_delay_us(100);
_delay_us(1);


text:
How does the Arduino handle serial buffer overflow?
How does the Arduino handle serial buffer overflow?  Does it throw away the newest incoming data or the oldest?  How many bytes can the buffer hold?

For hardware serial ports you can see in HardwareSerial.cpp that the buffer size varies depending on the amount of RAM available on the particular AVR:
#if (RAMEND < 1000)
    #define SERIAL_BUFFER_SIZE 16
#else
    #define SERIAL_BUFFER_SIZE 64
#endif

For a software serial port in SoftwareSerial.h the receiver buffer size _SS_MAX_RX_BUFF is defined as 64 bytes. In both cases it stops attempting to insert received data into the queue when it is full, so you could get a mix to old and new data depending on how you're retrieving data from the queue.
Ideally it would be best to ensure the buffer always gets emptied in a prompt manner to avoid the buffer filling. Maybe take a look at timers and implementing a simple state machine if your problem is related to other code blocking the main loop.

I get the impression that if I transmit data to the Arduino and don't have an active "puller" of data on the Arduino side then if more data arrives than can fit in the buffer, it will be discarded.  Can you confirm that?  I had naively assumed that the transmitter would block until space available to hold the data became available.

I just looked through all that code (under /usr/share/arduino/hardware/arduino/core/arduino/HardwareSerial.cpp) and can confirm what you wrote here. The only thing I would add is that since the SRAM is 2K (RAMEND>1000) then that if statement will always use 64 rather than 16 on a Nano or an Uno. So if one would want to expand the size of the ring buffer that would be the place to change it

Receiving
You can see from the source of HardwareSerial that if an incoming byte finds the ring buffer full it is discarded:
inline void store_char(unsigned char c, ring_buffer *buffer)
{
  int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;

  // if we should be storing the received character into the location
  // just before the tail (meaning that the head would advance to the
  // current location of the tail), we're about to overflow the buffer
  // and so we don't write the character or advance the head.
  if (i != buffer->tail) {
    buffer->buffer[buffer->head] = c;
    buffer->head = i;
  }
}

I get the impression that if I transmit data to the Arduino and don't have an active "puller" of data on the Arduino side then if more data arrives than can fit in the buffer, it will be discarded. Can you confirm that?

Yes it will be discarded. There is no software or hardware flow control, unless you implement your own.
However with a 64-byte buffer, and receiving data at (say) 9600 baud, you get one byte every 1.04 ms, and thus it takes 66.6 ms to fill up the buffer. On a 16 MHz processor you should be able to check the buffer often enough that it doesn't fill up. All you really have to do is move the data from the HardwareSerial buffer to your own, if you don't want to process it right now.
You can see from the #if (RAMEND < 1000) check that the processors with 1000+ bytes of RAM get the 64-byte buffer, the ones will less RAM get the 16-byte buffer.

Sending
Data that you write is placed in a same-sized buffer (16 or 64 bytes). In the case of sending if the buffer fills up the code "blocks" waiting for an interrupt to send the next byte out the serial port.
If interrupts are turned off this will never happen, thus you do not do Serial prints inside an Interrupt Service Routine.

I believe you're off by an order of magnitude: at 9600 baud, you get a byte every ~0.1 ms, so it only takes 6.6 ms to fill up the buffer.

At 9600 baud you get 9600 bits per second. Since each byte is 10 bits (8 data + 1 start bit + 1 stop bit) then you get 960 bytes per second. 1/960 = 0.001042 s - that is one byte every 1.04 ms.

Ahh of course, bits not bytes! Thanks for the correction.

So Nick, please answer this for me:  If I have a Pi running Python sitting at a ser.readline() waiting for input as a data logger, and it is fed via serial by Arduino taking readings then sending them as a batch with tab delimeters, then using delay(120000) so the batches come in every two minutes, the Python innards probably immediately read in each character until it encounter a newline, at which point it releases the whole line as a return value.  So I don't have to worry about the Arduino buffer size even if I am sending 80 characters total, eh?  Would that be a good assumption?

Yes, the sending buffer size won't matter in this scenario. A small buffer would slow down the sending (slightly) but if you are doing a lengthy delay anyway you won't care.


text:
LED Cube lighting wrong LEDs randomly
So I built my First LED Cube and the thing turns ON!!! Pretty happy about that but here is my problem.
When I try and get the Cube to display say a basic "outline" (a wire form of a cube only the outer most LEDs are on)
The shift registers, that I have daisy chained together, give the correct display 80% of the time, but the other 20% give completely wrong LEDs lighting up.
I have used 4 74HC595 shift registers linked together so I am only using 3 of my Arduino ports to control the 5*5*5 Cube.
The basic shape is there but the ones that are not meant to be lighting up cause a lot of flickering (or ghosting?) in the center of the cube.
I have thought about using pull up or pull down resistors but I find that, when I run my program at a slower rate, the LEDs that are lighting wrongly are lighting up controlled so I think it has to be something with my code or setup.
Has anyone got any experience with LED cubes doing this?
Also I am only using the output enable and disable to make use the wrong this is not displayed when I am shifting the data out, should I be using the clear?
One last thing, does anyone have recommendations for the delay time to let each layer shine for?
My code is below
int clockPin = 8;
int dataPin = 7;
int set = 6;

void setup()
{
  //set pins to output so you can control the shift register
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(set,OUTPUT);
}

void loop()
{
      digitalWrite(set,HIGH); // DISABLES OUTPUT
  // level 1 ( top )
      shiftOut(dataPin, clockPin, MSBFIRST, B00000011);//from left 3rd to the 7th = levels 5-1,, The right first LED
      shiftOut(dataPin, clockPin, MSBFIRST, B11111000);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B11000110);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B00111111);// Makes the " wire cube "
      digitalWrite(set,LOW);  // enables output
      delay(2);

       digitalWrite(set,HIGH); // DISABLES OUTPUT
 // level 2
      shiftOut(dataPin, clockPin, MSBFIRST, B00000101);//from left 3rd to the 7th = levels 5-1,, The right first LED
      shiftOut(dataPin, clockPin, MSBFIRST, B00010000);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B00000000);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B00010001);// Makes the " wire cube "
      digitalWrite(set,LOW);  // enables output
      delay(2);

      digitalWrite(set,HIGH); // DISABLES OUTPUT
 // level 3
      shiftOut(dataPin, clockPin, MSBFIRST, B00001001);//from left 3rd to the 7th = levels 5-1,, The right first LED
      shiftOut(dataPin, clockPin, MSBFIRST, B00010000);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B00000000);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B00010001);// Makes the " wire cube "
      digitalWrite(set,LOW);   // enables output
      delay(2);

      digitalWrite(set,HIGH); // DISABLES OUTPUT
 // level 4
      shiftOut(dataPin, clockPin, MSBFIRST, B00010001);//from left 3rd to the 7th = levels 5-1,, The right first LED
      shiftOut(dataPin, clockPin, MSBFIRST, B00010000);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B00000000);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B00010001);// Makes the " wire cube "
      digitalWrite(set,LOW);   // enables output
      delay(2);

      digitalWrite(set,HIGH); // DISABLES OUTPUT
 // level 5 ( bottom )
      shiftOut(dataPin, clockPin, MSBFIRST, B00100001);//from left 3rd to the 7th = levels 5-1,, The right first LED
      shiftOut(dataPin, clockPin, MSBFIRST, B11111000);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B11000110);// Makes the " wire cube "
      shiftOut(dataPin, clockPin, MSBFIRST, B00111111);// Makes the " wire cube "
      digitalWrite(set,LOW);   // enables output
      delay(2);
}

Any help would be appreciated
Thanks

add circuit scheme , for the times it depends on many things (mainly fps) but the usual is 1-10ms look here for similar problem http://stackoverflow.com/a/20468992/2521214

A simple way to test for short between LEDs is to write a loop that lights one of them at a time, one right after the other, for 50ms or so. It's relatively easy to notice two LEDs lighting together (a short) or a missing blink in the sequence (an open), assuming you can see all the LEDs at once.
Update (6 years later, but hey - I since people still read this question):
I use a sketch that does exactly this to help find shorts and opens when I'm building up a new board. I'd previously implied that you need all of the LEDs attached, but you need at most 2.
On a newly soldered cpu with power & ground (and reset jumpered to ground), holding an LED on each of two adjacent pins will show a shorted pair, while a single LED on one pin will display an open or a short to ground (or to +5, if you orient your LED+resistor that way). I keep a few LEDs with a resistor soldered to the cathode, or ground, leg to use as digital probes.

I have had a similar issues when building this instructable, a 8x8x8 LED cube. Lighting up some of the LEDs caused wrong LEDs to light up simultaneously, even though according to the circuit diagram they where not suppose to. The wrong LEDs that lighted up seemed to be random, though it was reproducible.
The root cause was, after some debugging using a Multimeter's continuity test, that some of the LEDs legs where touching in places they shouldn't, and so the current was flowing where it was not supposed to flow. I strongly recommend to investigate that direction, verifying that Ground paths and Vcc paths are properly isolated from each other. This should be easier to do with a 5x5x5 cube.
About the delay - I suggest you'll take a look at the Arduino code in that instructable - it seems that between the different layers, the code does not use any delay, only between effects. The final result seems to works great.

I have a similar circuit (running a 7-segment display); I don't use reset, and for something like this (since the only state it keeps is reset on sending of new data, which is every frame).
For debugging, I would suggest seeing if there are any patterns. For example, if it doesn't happen on LEDs controlled by the first shift register, then it's likely to be due to the connection between them.
You might try seeing if a pulldown resister (try >10kOhm) between the data pin and ground has an effect, too.
If you get really desperate, it might be worth getting an oscilloscope - see what is actually happening on the wire.


text:
Operating HB100 backpack with Arduino Due
I need to connect a speed sensor module with an Arduino Due and calculate the speed of an approaching object.
the sensor is:
http://www.limpkin.fr/index.php?post/2013/08/09/Making-the-electronics-for-a-%247-USD-doppler-motion-sensor
The sensor already output a signal that its' frequency represents the speed of the object.
I would really appreciate any help understating how can it be connected and operated by the Arduino without burning it, and how can I sample its output?
If more details are needed I'll be happy to supply.
Thanks.

This looks useful: http://tushev.org/articles/arduino/item/51-measuring-frequency-with-arduino

The articles and tutorials I've read on the subject say that the HB100 module produces a very weak signal which needs to be amplified before your Arduino can read it. They recommend building an op amp. This post on the Arduino forums, for example: http://forum.arduino.cc/index.php?topic=61989.0
BUT looking at your picture and linked article, I find that your device already includes the signal amplification and filtering you need in the backpack board. I found the store page for this module, which has a more noob-friendly explanation. From what I gather:

VCC: provide the module with a 5v supply.
VOUT: analog reading of the amount of return signal being received. My guess is you could use this with analogRead() to get a rough estimate of the size or distance of the object being read. If you want only the speed reading, you don't need this pin.
FOUT: digital output of the speed that the sensor is reading. Thanks to @sachleen's link, you can use either pulseIn() or FreqCounter library to measure the frequency and then convert it to a MPH or KPH speed.
GND - ground, aka common, aka -.

So connect VCC to 5v, GND to ground, and FOUT to an input pin on your Arduino. If you use pulseIn(), frequency f = 1 / t, t being the return value from pulseIn(). If you use the FreqCounter library, it no doubt has documentation on its usage.


text:
How to program arduino for ethernet with only usb cable
I have arduino UNO r3 ATMEGA 328P board and this kind of a cable. But I want to make and test a program that need to get the data through ethernet port. Can I do only with them. I want to know whether they are enough to that (there are any converter or virtual devices) or should I buy anything.

You can do the programming of the Arduino through the USB cable, but in order to test and operate the program, you'll need an Ethernet shield and a cable to connect that to the LAN.


text:
Arduino Ethernet Shield connection to PC
is it possible to connect Arduino Ethernet Shield direct to PC and send a String variable? How can I read it later on the PC?
Will this code work?
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; // Shield MAC

byte pc[] = "192.168.0.13"; // pc IP
EthernetClient client;

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

  Serial.println("connecting...");

  delay(5000);
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("Sample String");
    client.println();
  } else {
    Serial.println("connection failed");
  }

}

void loop()
{

}

No, you seem to be off on a tangent. There at least two problems:

The Ethernet library is designed to run on an Arduino board. If you set the IP address to the same as the PC IP address, the network will get confused and nothing will work reliably.
Are you asking how one can publish data from an Arduino board and read the results on a PC? This is easier. Just set up the web server example on the Arduino, and access it from a browser on your PC.


text:
Did I burn my Arduino UNO?
I've recenly bought my first Arduino uno and I was messing with DC motors. I put on the prototype shield on arduino with a mini breadboard on it. I was using L293D bridge. I've connected everything and then put in my 6V battery pack and it BURNED. I don't know what happened. I didn't upload the code, I just connected batteries. I put negative to GND and positive to pin 8. Arduino is responding, but I'n not sure whether all pins are working, how do you check this?

There is not enough information here to tell if you damaged the board or ATmega, you can check by writing a simple sketch to toggle the state of each IO and test them with a multimeter/logic probe/LED and resistor.

@Dan Nixon. The arduino has internal PULLUP resistors and a led on the board which makes it possible to test the pins without external tools except a jumper wire.

To make sure all pins are responding you could put all your pins as input with internal pull-up except pin 13 which must be set as output. The on board led is connected to pin 13, so when you put pin13 high it will turn the led on. Connect every other pin 1 by 1 to the GND to see if the led is toggling once you've connected a pin to the GND.
Try to use this code.
void setup(){
for(int p = 0; p <= 12; p++){  // Define pin0 until pin12 to INPUT with internal pull-up resistor
pinMode(p, INPUT_PULLUP);
}
pinMode(A0, INPUT_PULLUP);  // Define pinA0 as INPUT with internal pull-up resistor
pinMode(A1, INPUT_PULLUP);  // Define pinA1 as INPUT with internal pull-up resistor
pinMode(A2, INPUT_PULLUP);  // Define pinA2 as INPUT with internal pull-up resistor
pinMode(A3, INPUT_PULLUP);  // Define pinA3 as INPUT with internal pull-up resistor
pinMode(A4, INPUT_PULLUP);  // Define pinA4 as INPUT with internal pull-up resistor
pinMode(A5, INPUT_PULLUP);  // Define pinA5 as INPUT with internal pull-up resistor
pinMode(13, OUTPUT);        // Define pin13 as OUTPUT (INTERNAL LED);
}

void loop(){
if(digitalRead(0, LOW)){   // If pin0 is connected to GND turn led on
digitalWrite(13, HIGH);
}
if(digitalRead(1, LOW)){   // If pin1 is connected to GND turn led off
digitalWrite(13, LOW);
}
if(digitalRead(2, LOW)){   // If pin2 is connected to GND turn led on
digitalWrite(13, HIGH);
}
if(digitalRead(3, LOW)){   // If pin3 is connected to GND turn led off
digitalWrite(13, LOW);
}
if(digitalRead(4, LOW)){   // if pin4 is connected to GND turn led on
digitalWrite(13, HIGH);
}
 if(digitalRead(5, LOW)){  // If pin5 is connected to GND turn led off
digitalWrite(13, LOW);
}
 if(digitalRead(6, LOW)){  // If pin6 is connected to GND turn led on
digitalWrite(13, HIGH);
}
if(digitalRead(7, LOW)){   // If pin7 is connected to GND turn led off
digitalWrite(13, LOW);
}
if(digitalRead(8, LOW)){   // If pin8 is connected to GND turn led on
digitalWrite(13, HIGH);
}
if(digitalRead(9, LOW)){   // If pin9 is connected to GND turn led off
digitalWrite(13, LOW);
}
if(digitalRead(10, LOW)){  // If pin10 is connected to GND turn led on
digitalWrite(13, HIGH);
}
if(digitalRead(11, LOW)){  // If pin11 is connected to GND turn led off
digitalWrite(13, LOW);
}
if(digitalRead(12, LOW)){  // If pin12 is connected to GND turn led on
digitalWrite(13, HIGH);
}
if(digitalRead(A0, LOW)){  // If pinA0 is connected to GND turn led off
digitalWrite(13, LOW);
}
if(digitalRead(A1, LOW)){  // If pinA1 is connected to GND turn led on
digitalWrite(13, HIGH);
}
if(digitalRead(A2, LOW)){  // If pinA2 is connected to GND turn led off
digitalWrite(13, LOW);
}
if(digitalRead(A3, LOW)){  // If pinA3 is connected to GND turn led on
digitalWrite(13, HIGH);
}
if(digitalRead(A4, LOW)){  // If pinA4 is connected to GND turn led off
digitalWrite(13, LOW);
}
if(digitalRead(A5, LOW)){  // If pinA5 is connected to GND turn led on
digitalWrite(13, HIGH);
}
}


text:
Cannot upload program to Arduino Duemilanove w/ Atmega328

This is the error I receive while trying to upload to the Arduino.
I have installed FTDI drivers for mac. (http://www.ftdichip.com/Drivers/VCP/MacOSX/FTDIUSBSerialDriver_v2_2_18.dmg)
The board is part of a quadcopter: https://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=50460
The processor is an Atmel 328P. Do I have the correct drivers?
What else could be the issue?

You shouldn't need to load any drivers for your Mac; it should (mine does) recognize your FTDI USB device the moment you plug it in.

You may have wrong port:  /dev/tty.usbserial-A9007LXq works with Duemilanove on my Mac.

You can check this by opening a terminal and typing in ls/dev/tty. and then hitting tab. It should tell you all the open ports


text:
Error building Arduino WiShield Flash example: 'dflash' was not declared in this scope
I'm using WiShield library from: https://github.com/jcmuller/WiShield
What is wrong with this library?
The code:
/*
 * Web Server using Flash
 *
 * A simple web server example using the WiShield 2.0
 * that reads the manufacturing ID from the Flash and
 * displays it on a webpage.
 */

#include <WiShield.h>
#include <dataflash.h>

#define WIRELESS_MODE_INFRA    1
#define WIRELESS_MODE_ADHOC    2

#define FLASH_SLAVE_SELECT 7
#define WIFI_SLAVE_SELECT  10

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};   // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};  // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes

unsigned char security_type = 0;    // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};   // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {   0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,     0x09, 0x0a, 0x0b, 0x0c, 0x0d,   // Key 0
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 1
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 2
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00    // Key 3
                            };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

unsigned char mfg_id[4];

void setup()
{
  initShield();
}

// This is the webpage that is served up by the webserver
const prog_char webpage[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type:     text/html\r\n\r\n"
                                ""
                                ""
                                "
Flash Mfg ID: 000 000 000
"
                                "<form method=post action=\"/upload\" enctype=\"multipart/form-data\">"
                                "FS Image Upload"
                                "
"
                                "<input type=file name=i size=40>   <input type=submit value=\"Upload\">"
                                "</form>"
                                ""
                                "";

void loop()
{
  dflash.read_id(mfg_id);

  WiFi.run();
}

void initShield()
{
  // there is some contention on the SPI between the flash and wifi chip,
  // so disable both devices at the beginning until they are properly
  // initialized by their respective libraries
  pinMode(FLASH_SLAVE_SELECT, OUTPUT);
  digitalWrite(FLASH_SLAVE_SELECT, HIGH);
  pinMode(WIFI_SLAVE_SELECT, OUTPUT);
  digitalWrite(WIFI_SLAVE_SELECT, HIGH);

  // now init dataflash
  dflash.init(FLASH_SLAVE_SELECT);

  // now init wifi
  WiFi.init();
}

Try putting Dataflash dflash; along with your other variables.

error: 'Dataflash' does not name a type

I doubt anything is wrong with the library, but in your initShield and loop methods you refer to a variable called 'dflash' which does not seem to be defined anywhere.

This is the example that comes with the library. No changes.
https://github.com/jcmuller/WiShield/blob/master/examples/Flash/Flash.pde

Interesting; looks like there is no dataflash.h in the repo.  Post an issue; the file might not have been committed correctly.

Never mind; you need this library too: https://github.com/asynclabs/dataflash


text:
Efficient periodic wake up for sensor reads
I've been tasked to do an initial design for an Arduino setup that needs to run very infrequently.
Basically, I'd like the system to wake up daily to take some sensor readings and report them back to a central site (the mesh network for this will be my next stage).
Since these things are going to be run on battery, I need it to be as insanely efficient as possible, with minimal power drain when not reading the sensor.
What facilities does Arduino have to do this?

Also relevant: http://arduino.stackexchange.com/questions/1096/extend-battery-life-with-a-power-controlling-microcontroller

Please refer to http://playground.arduino.cc/Learning/ArduinoSleepCode
it explains the details of a the sleep command and interrupts to re-a-wake. Where the power savings is from putting the resources individually into low power mode.
In your solution, you may want to put everything in low power, except power_timer1_disable(). Where timer1 would be configured to provide an overflow interrupt, say every 1 minute or longer and then go back to powering all off and return to sleep.
Note the article also mentions that the UNO's power supply is a linear regulator, which is very in-efficient. You may want to use your own. You can also get away with just running directly off of 2-3 AA's, if your other circuitry does not care. If this, then I would also suggest enabling the brown out detection, to ensure low battery does not get funny.


text:
Error uploading on Arduino Mega 2560
I'm completely new to Arduino, I bought a Rampos 1.4 and an Arduino Mega 2560 to build a Prusa Mendel 3D printer.
But when I connect the Arduino via USB to my computer, open the software and click to upload the blink example, it does anything and says Uploading to i/o board.
This happens when I use Arduino 0022 and then when I use Arduino 1.0.5 r2 that is the problem:
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

I don't know what is happening, and I don't know what to do.

you need to read the extremely comprehensive getting started documentation on the Arduino website. this is off-topic here as it is way to broad to teach the basics and fundamentals of working with an Arduino. this is about specific solvable questions, not help teach me I don't want to read type questions.

I searched on Google during 2 hours until make that post, I'm not of that people you say. Now I'm searching that getting started that you said.

And @JarrodRoberson, I'm not english and I had several mistakes to write and I to read. Is that what I have to read? http://arduino.cc/en/Guide/Windows

I've done all the getting started, and it happened another time. I don't know what to do, now the port changed from COM12 to COM3, but it's still not working.

You need to select the proper board and port.

@TOMATO I've done it.

This question fits the subject scope of SuperUser better than that of StackOverflow.

Sorry I do not have the reputation to comment. I think your problem can be because you selected the wrong settings for your board. Check in Tools option, and make sure Board, Processor and Port is correct.


text:
Arduino uno + XBee Shield Not transmitting when under battery power?
I have a few Arduino's along with XBee Shields communicating with one another.
The problem I'm having is that, when all the Arduinos+XBee Shields are powered via USB(PC) they seem to work fine and all transmissions get through to one another. But, when I use them with 9Volt batteries(fairly new batteries) the whole thing crashes and I never receive responses back from the battery powered ones.
I'm wondering if this is really a power issue? wouldn't a 9volt be enough to power a single arduino(uno)+xbee shield?

Using a multimeter you can confirm your theory by looking for a voltage drop on the power connections to the XBee and into the UNO.
9V batteries don't store much charge, nominally 563mAh according to wikipedia. It is possible that the fairly new batteries are not that new after all.
Depending on the XBee, power consumption varies. 40mA for a normal XBee (ZigBee), 200mA for pro, and 309mA when transmitting for the new XBee WiFi. If the battery is low, the high current draw plus internal battery resistance may drop the 9V output to below the 7V needed for the UNO's voltage regulator to function correctly.

The usb port on your computer can supply about 500mA of current. If geometrikal is correct about the 563mAh and you are using an XBee pro or a higher current draw radio, you could easily be hitting the current limit of the battery. Another aspect of this is the internal resistance of the battery. I'll let you read about it, but it is another current limiting factor. All of this boils down to once you are drawing more current than the battery can provide the voltage drops. Once it gets down to below what the Arduino board can regulate the microcontroller will reset.

Is space an issue? Have you considered using 6 AA batteries? From what I've read basically the current provided by a battery is determined by it's size so C is bigger than AA which is bigger than AAA.
The 9volt battery is from what I understand made up of 6 AAAA cells and therefore has a much lower maximum current. about 563mAh rather than about 1500mAh depending upon the type you choose.

Current is measured in A (amps) or mA (milli-amps). mAh stands for milli-amp hours. This refers to how much current can be drawn for a single hour. For example with a 500mAh rated battery you could draw 500mA for 1 hour or 250mA for 2 hours. mAh says nothing about maximum current draw, except for how fast the battery will be drained (if you know the current draw).

I know i was over simplifying things but does not the fact of a higher mAh not indicate that the potential current is higher? I guess i need to do more reading

It is solely an indicator of capacity. For example if the ESR (http://en.wikipedia.org/wiki/Equivalent_series_resistance) is low enough you could draw 1000mA from a 500mAh battery for 30 minutes.


text:
MakeyMakey + Arduino
I am trying to use the MakeyMakey with the Arduino (not as an Arduino) and then use a USB to TTL module to send the keys pressed to the Arduino. Is this possible? Do I have to reprogram?

No you can't the makeymakey and the usb-to-serial adapter are both usb clients. You need one host and one clients for usb. You could alter the firmware to send serial info using D0 and D1 on the header on the backside, but that's not that easy.

Why not have the MakeyMakey communicate using its USART intead?

Possibility, but the USB host shield worked for me!

one possibility is to use HOST SHIELD
http://www.circuitsathome.com/products-page/arduino-shields
Arduino is now as host
Makey is keyboard


text:
Can I use notepad++ for writing sketches?
Before I install the Arduino IDE, I was just wondering whether I could just use notepad++ to write the files and move them into correct location. I assume notepad++ doesn't support Arduino code, but I suspect there will be a mod for it, even though sketches are a low-end version of C++, which is supported.

You can easily use notepad++ or any text editor to edit arduino code files (.pde or .ino). I use the sublime text editor for all my arduino coding.
As you noted, the arduino syntax is c++, so setting the syntax highlighting mode to c++ is all that you need to do; no mod should be necessary.
Arduino includes a "Use external editor" option in the preferences menu that will make it reload the file every time you compile or upload. It also disables editing in the editor window. In this mode, just save your file in any editor, change to the arduino window, and hit upload.
Since 1.5, arduino has had command line support. most editors allow making the "build" button execute arbitrary commands in the current directory. by setting build to run "arduino --verify" or "arduino --upload" you can code in any editor you want even without having an arduino window open.

You can use any editor to write Arduino code. @BrettM has already detailed it.
Instead of the external editor option, you can do away with the Arduino IDE completely using Makefile and build and upload your code yourself.

Arduino IDE sucks. Ok, I admit it’s nice for beginners and for the
  click-and-forget kind of programmers, but it needs the full Java stack
  and hides to the user the fundamental steps involved in compiling and
  uploading programs to the arduino board.
I (like many other software developers) prefer to understand what I’m
  doing and running a Makefile from the command line is the way to see
  the individual steps and choose which to run and when. Finally, I’m
  not going to drop my favourite editor just to write arduino programs.

Here's how to do it.

The Arduino files are just text files with the *.ino extension, so it is OK to edit them with a text editor.
The Arduino IDE is needed to compile them (easily) however. To make an Arduino project without the IDE, create a directory e.g. MyProject, and create a file inside it called MyProject.ino. They have to have the same name. Adding extra *.ino files inside the directory will result in extra tabs in the Arduino IDE for those files when you open MyProject.ino.

The Arduino IDE isn't needed to compile them. It's just calling the avr-g++ compiler then avrdude to upload. (Ok, so it does some pre-processing too, but it's probably worthwhile to just write valid c++ anyway)

@RubberDuck The Arduino build script adds all the headers in to the *.ino files. Personally I use netbeans with avr-g++ and a library of all the Arduino code. Works really well once it is setup.

Its fine,  you have to start asking questions somewhere right? You could use notepad++ to write your files and move them to a correct location, but it would be pointless, because you would need a mod to compile and upload it to your Arduino. I would recommend just using the native Arduino IDE, because it does all the work for you, all you have to do is write your code, upload it, and sit back and watch.


text:
How do I attach 4 input pots to arduino?
I am making an arduino game and the requirement is that my arduino reads 4 analog values from the pots. I dont know whether I should use an external battery supply or the 5V from the duino' itself. I dont want my ICs to get fried or nothing happening at all.

It doesn't really matter as long as the the voltage across your pots doesn't exceed the ARef or IORef voltage, which is usually equal to Vcc (3.3V or 5V) for the Arduino boards. It's best to use the 5V from your board. The ADC inputs are relatively high impedance so very little current flows through. Don't use very large value pots or you might not get the correct values from your analog inputs.

Set up 4 pins as inputs. Wire the pots as voltage dividers (center wired to the input through a small-value resistor. One of the ends of the pot wired to +5V from your Arduino, and the other end wired to ground.)


text:
Arduino Uno R3 Bluetooth Shield is not discovering in any of the device
I have a problem regarding Seeedstudio Bluetooth shield http://www.seeedstudio.com/depot/Bluetooth-Shield-p-866.html
I can't detect its presence by any other devices.
The code I uploaded to Arduino is a standard example for slave device from the library:
#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 6
#define TxD 7

#define DEBUG_ENABLED  1

SoftwareSerial blueToothSerial(RxD,TxD);

void setup()
{
    Serial.begin(9600);
    pinMode(RxD, INPUT);
    pinMode(TxD, OUTPUT);
    setupBlueToothConnection();
}

void loop()
{
    char recvChar;
    while(1)
    {
        if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
            recvChar = blueToothSerial.read();
            Serial.print(recvChar);
        }
        if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
            recvChar  = Serial.read();
            blueToothSerial.print(recvChar);
        }
    }
}

void setupBlueToothConnection()
{
    blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
    blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
    blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
    blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
    blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
    delay(2000); // This delay is required.
    blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
    Serial.println("The slave bluetooth is inquirable!");
    delay(2000); // This delay is required.
    blueToothSerial.flush();
}

I've uploaded it to Arduino UNO, connected the shield.
LED marked as D1 is blinking green, and D2 is switched off. The device is not detected by none of the  devices I've tried
Please Help Me

Have you checked if you set the jumpers correctly?

As per this site: http://www.rjanick.com/2012/11/26/seeed-studio-bluetooth-shield/
Try switching the #define rxd and #define txd pin numbers in the code, inversely corresponding to the ones that the jumpers are connected to on the board.
For instance: my pins are jumped from the BT_TX line to digital 6 (and BT_RX to pin 7), so in the code I write #define TxD 7, and RxD 6. This made the board's LEDs blink differently (red blinks on D2 until connection).


text:
Computer not detecting my Arduino MEGA 2560 R3
I've tried different USB cables, computers, ports and none of them can detect my possibly bricked Mega 2560 R3. Nothing shows up at all in the Device Manager, not even "Unknown Device".
When the board is plugged in via USB, the "L" LED is constantly lit as well as the "ON" LED next the reset button.
I came up on this article here and I gave it a try, which I believe is putting it in DFU mode. However I'm not having any luck with this. http://www.wayneandlayne.com/blog/2011/02/16/fixing-linux-firmware-issues-on-arduino-mega-2560/
Any one have any ideas on where to go from here? I'm very new with Arduino.

Have you tried a different computer and cord? When did it stop working (and what did you do differently)?

I recently purchased a clone Mega 2560, and could not get the USB port to work. Check the USB chip marking. If its a CH340G, it is not compatible with the Arduino drivers for PC USB ports. You need to find a file called ch341ser.zip, and install this on the PC, not the Arduino.

I have the same issue with an Arduino Mega ADK (same as Mega 2560 but with additional USB Host port) and only get gibberish as serial output

If your Mega has an ICSP header for the USB chip (circled below) then you can test that chip.

You can use another Arduino (eg. a Uno) to detect the signature on that chip, as per my sketch on Sketch to detect Atmega chip types.
All you need is 6 hookup wires to connect your testing board (the known good one with the sketch on it) to the ICSP header on the Mega. Note the pin orientation. I have circled the correct header pins, and pointed to pin 1. On the board pin 1, has a small white dot.
Below are the ICSP pin names, seen from above (component side).

Wire the Uno to the chip being tested as follows:
Arduino Uno      Target chip

D10 (SS)            /RESET
D11 (MOSI)          MOSI
D12 (MISO)          MISO
D13 (SCK)           SCK

Gnd                 GND
+5V                 VCC

Check your wiring! If you wire things around the wrong way you can turn a good chip into a bad one.

Important! Only attempt this process if you can see that you have an ATmega8U2 or ATmega16U2 chip on your board (see below). If you have something totally different this will not work. In that case you probably have a cheap clone board.

Using the Serial Monitor on your Uno, you should then see something like this:
Atmega chip detector.
Written by Nick Gammon.
Version 1.17
Compiled on Jul  7 2015 at 10:47:47 with Arduino IDE 106.
Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x93 0x89
Processor = ATmega8U2
Flash memory size = 8192 bytes.
LFuse = 0xEF
HFuse = 0xD9
EFuse = 0xF4
Lock byte = 0xFF
Clock calibration = 0xAB
Bootloader in use: No
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 4096 bytes starting at 1000

Bootloader:

1000: 0x4B 0xC0 0x00 0x00 0x64 0xC0 0x00 0x00 0x62 0xC0 0x00 0x00 0x60 0xC0 0x00 0x00
1010: 0x5E 0xC0 0x00 0x00 0x5C 0xC0 0x00 0x00 0x5A 0xC0 0x00 0x00 0x58 0xC0 0x00 0x00
1020: 0x56 0xC0 0x00 0x00 0x54 0xC0 0x00 0x00 0x52 0xC0 0x00 0x00 0xCB 0xC4 0x00 0x00
1030: 0x4E 0xC0 0x00 0x00 0x4C 0xC0 0x00 0x00 0x4A 0xC0 0x00 0x00 0x48 0xC0 0x00 0x00
...

My board had a ATmega8U2 on it, yours might have a ATmega16U2. However the concept is the same. If you see something like that, the chip is (probably) good. At least it responds to programming commands.

If you see something like
Atmega chip detector.
Written by Nick Gammon.
Version 1.17
Compiled on Jul  7 2015 at 10:47:47 with Arduino IDE 106.
Attempting to enter ICSP programming mode ......................................................
Failed to enter programming mode. Double-check wiring!
Programming mode off.

Then either you made a wiring error, or the chip is bad.

I have had the same symptom with a Arduino Decimilia.
In that case had the USB to Serial chip failed. I used a USB to Serial device to verify the problem

It sounds like the USB to serial chip has failed. You could test this by using another arduino or a programmer like the AVRISP mkII to load a program that way and see if it's your whole board or just the serial chip.
If the board and main chip are still good, you could just get used to uploading with this new method, or you could try to reprogram the other chip used for serial. I know it I'd possible but ever time I've burned one this hadn't help so YMMV.

Check the Chips for any solder mistake, I found that my serial chip had two pins soldered together, probably cause i bought it for cheap :D


text:
OBD Connector to Arduino
I bought an OBD connector from Sparkfun to try to connect to my vehicle via arduino.
I'm just beginning and am not sure if I can just connect the connector pics to the arduino directly, or if there is some other required hardware?
Does anyone know if I can connect directly and why or why not?

I briefly read up on this subject and I found out this:
It seems like there's a protocol called J1850. There's no native support on the Arduino for that, but you might be able to do something bit-banging if you can find the specifications for this protocol. If you do this, I'd advise accessing the registers directly and skipping the digitalRead() command.
There are a few protocols in use, so it is hard to know without knowing the car you drive to even tell what the car will send.
More on this topic...
Anyway, it seems like you need a chip to use with this. Sparkfun also sells a breakout board for the STN1110 OBD-II to UART chip (tutorial). I couldn't really find anything else besides this.
Anyway, you probably need another chip to do this work. The Arduino isn't meant to do all of these protocols, and the OBD isn't UART-compatible.

Thanks for the help!   I also found an pdf here https://www.google.com/url?sa=t&source=web&rct=j&ei=uvPxU-vjLo27oQTW2YDgCA&url=https://www.cs.purdue.edu/homes/millerrv/Ryan_Miller/Projects/Entries/2010/12/21_Arduino_OBD-II_Interface_files/CS497_presentation_miller.pdf&cd=1&ved=0CBwQFjAA&usg=AFQjCNEguP_tgEU-i6_6MbNqOoXj9er37A&sig2=1teeC0hht_QSnBZAc9JrBQ

@mECH interesting! It looks like they used the MC33290 and bit banging to do this. I don't have time now to look into it more now, but a library with hardware timers would be helpful...


text:
Using Arduino Nano as USB Host
I'm pretty new to microcontrollers and Arduino and since I can't find any satisfying information on my problem, I hope that you might answer them:
My project is actually quite simple: I just want to write out data over a serial connection via USB, the problem: My Arduino Nano has to run as USB Host. That's because the other device is a vacuum cleaner: Neato XV-25 with a mini usb jack. I was already able to 'talk' to it using a Raspberry Pi.
Since I don't have much knowledge about USB communication, I would like to know the following, before I start digging deeper:

I found out, that I would not be able to use the 'usual' usb port of the nano. But I've read a few things about that 'V-USB' library, but did not understand very much. Would it be possible to create a USB Host with this library, that can communicate via a virtual serial connection?
I stumbled across the USBHost for Android Nano. It's a shield, but I'm not sure if it would fit my needs. Is it able to handle serial communication? And is there somewhere a store where I can get it cheap? I think more than 20$ for a shield is a bit too much...

I'm sorry, I just saw another post and realized, that hardware questions are not tolerated, but i still think, that at least my first question counts as a software-based question...

Realistically, by the time you put a USB host shield on an Arduino you might as well just get a raspberry pi model A.  Or you can look at various other embedded boards with USB host capability - STM32F4 discovery - but you may have to learn more to write the software for it.  It would also be useful to check what driver is being used on the pi, as if it is one for a stand alone chip, that suggests you could modify the target to get at a logic-level UART behind the USB-serial chip.  Conversely something like CDC/ACM suggests you may be talking to a USB-device port on the main micro.

V-USB is a software-only implementation of a low-speed USB device for Atmel’s AVR® microcontrollers

No host support here, sorry.
The USB host shield handles the hardware bit and simplifies the software bit. It is up to the firmware to support the various USB profiles. Version 2.0 of the library supports CDC with a few devices; check to see if they would be correct for your purpose.