text:
Attiny84 and 2-Axis Joystick
I have a Parallax 27800 2-Axis Joystick wired up to a AVR 14 Pin 20MHz 8K 12A/D - ATtiny84. The joy stick sends out a x y analog signal. I have programmed the Attiny84 to read the signals and set one of the attiny84 pins (high or low) depending on the direction of the joystick. In this example, each pin is wired up to a LED. The problem I am having is there is about a 1 second delay for the LED to light. The Attiny84 has a built in 8MHz clock. Would connecting an external 20MHz crystal fix this issue?
int UD = 0;
int LR = 0;

int DWN = 0;
int UP = 1;
int LEFT = 4;
int RT = 5;

int LRMID = 0;
int UPMID = 0;
void setup(){

  pinMode(DWN, OUTPUT);
  pinMode(UP, OUTPUT);
  pinMode(LEFT, OUTPUT);
  pinMode(RT, OUTPUT);

  digitalWrite(DWN, LOW);
  digitalWrite(UP, LOW);
  digitalWrite(LEFT, LOW);
  digitalWrite(RT, LOW);

  //calabrate center
  LRMID = analogRead(3);
  UPMID = analogRead(2);
}

void loop(){

  UD = analogRead(2);
  LR = analogRead(3);
  // UP-DOWN
  if(UD < UPMID - 5){
   digitalWrite(DWN, HIGH);
  }else{
   digitalWrite(DWN, LOW);
  }

  if(UD > UPMID + 5){
   digitalWrite(UP, HIGH);
  }else{
   digitalWrite(UP, LOW);
  }
  // LEFT-RIGHT
  if(LR < LRMID-5){
   digitalWrite(LEFT, HIGH);
  }else{
   digitalWrite(LEFT, LOW);
  }

  if(LR > LRMID +5){
   digitalWrite(RT, HIGH);
  }else{
   digitalWrite(RT, LOW);
  }

  delay(100);

}

Have you tried removing the delay?

Do you have capacities somewhere in your circuit?

Thee delay(100) is only 1/10th of a second, and its there to give the code time to respond. And there are no caps in the circuit. Its pretty straight forward design.

While @alexan_e’s suggestion fixed your practical problem, I would argue that it did not address your root cause, which is that whatever board setting you’re working from in boards.txt assumes a clock rate of 8MHz, while in reality your fuses are set to boot the microcontroller at 1MHz. This caused your delay(100) to take 800ms, and was the entire reason for the slowdown.
Instead of fixing this at runtime, as aleman_e suggested, it seems more natural to me to bring your fuse settings into alignment with your compiler settings, using the “burn boot loader” Arduino command (which on Attinys generally does NOT burn a boot loader, but only sets the fuses to be in sync with the compiler settings).
If your application is not going to become much more complex, running at 1MHz might be a more efficient choice than running at 8MHz.

Thank you. I will give it a try. I thought I ran the "burn boot loader" at 8Mhz. I'll try again.

Fair point, although I originally suggested the runtime function so that he could check if that was indeed the problem, when we were not sure that this was the actual cause. In my reply I explained both methods to change the prescaler and just repeated the same suggestion I made in the comments because he asked me to post it as an answer, but it didn't occur to me to make a suggestion about changing the fuse.

@alexan_e I did not mean to disparage your runtime function (It did, after all, help diagnose the issue correctly), I was merely arguing that it was not necessarily the best solution for a permanent fix.

Running the boot loader did indeed fix the issue.

Several AVR devices including ATtiny 84, have a clock prescaler that can be used to lower the core frequency.
The divider can be controlled two ways.
The first way is the CKDIV8 fuse that controls the default loaded value to CLKPR (Clock prescale register) to either

fuse disabled:  Clock Division Factor 1 (clk/1)
fuse enabled: Clock Division Factor 8 (clk/8)

The fuse is enabled by default and applies the clk/8 setting, it can be changed with a programmer.
The second way is by changing the prescaler value during runtime. All you need to do is to include the following header
#include <avr/power.h>

and call one of following functions with the appropriate value you want to use
   clock_prescale_set(clock_div_1);    // Clock Division Factor 1
   clock_prescale_set(clock_div_2);    // Clock Division Factor 2
   clock_prescale_set(clock_div_4);    // Clock Division Factor 4
   clock_prescale_set(clock_div_8);    // Clock Division Factor 8
   clock_prescale_set(clock_div_16);   // Clock Division Factor 16
   clock_prescale_set(clock_div_32);   // Clock Division Factor 32
   clock_prescale_set(clock_div_64);   // Clock Division Factor 64
   clock_prescale_set(lock_div_128);   // Clock Division Factor 128
   clock_prescale_set(clock_div_256);  // Clock Division Factor 256

power.h manual
Note that the above functions can be applied at any part of the program, for example you can lower the cpu frequency to reserve battery and then set it higher again for intensive tasks. Just be aware that all peripheral will work with the divided clock too so PWM, timers, SPI, UART etc will all be affected.
If the problem you are facing is caused by the clock divider being in the /8 setting then you can change it at runtime.
Add the header at the start of the sketch
#include <avr/power.h>

And then set the prescaler value to 1 at the start of setup()
void setup() {
               clock_prescale_set(clock_div_1);  // set the clock prescaler to /1
}

Also note that changing the prescaler will affect delay() and millis(), since they assume a (predetermined) fixed clock frequency.

@IgnacioVazquez-Abrams The mentioned functions are based on the use of timers, and I mentioned that they get affected. In any case it's worth pointing for users that are not aware of that.

Are you absolutely sure your AVR is running at 8MHz, because default I believe it is scaling the 8MHz internal RC-oscillator down to 1MHz system clock. Change your F_CPU macro to 1MHz to see what happens.

..the internal 16MHz clock What are you referring to? The only available internal clocks for the mentioned device are 125KHz and 8MHz

I'm probably confused with ATtiny85 which does. @alexan_e

@PhilVallone If the problem is caused by the clock divider (CKDIV8 fuse) then you can set the divider to 1 in run time by including power.h #include <avr/power.h> and using clock_prescale_set(clock_div_1); in setup(). Although if this was related to the clock divider I would have expected problems during programing too, caused by the low UART BAUD rate.

@jippie - once the code is was uploaded I burned the bootloader at 8Mhz. Would I be doing harm to the chip if I try the bootloader again?

@alexan_e - I'll try your suggestions and report back

@PhilVallone Did you write the bootloader using the Arduino IDE? If so then the IDE writes the fuses too, so I doubt that the CKDIV8 fuse is still in the default set state. In any case rewriting the bootloaded doesn't damage the device in any way.

@alexan_e setting the clock_prescale_set(clock_div_1); did the trick. Response time is almost instant. If you put it as answer, I'll make as correct.


text:
Bootup on lower power not functioning
I have a custom Arduino ATMega328 board that generally runs at 5V @ 8MHz (using the Arduino Pro 3.3V 8MHz profile and bootloader). The main reason I'm using this setup is so that I can put the board to sleep when main power is disconnected and it starts being run off of battery power (3V from a coin cell). The 5V and 3V sources are diode OR'ed together and the 5V input is tied to INT0. In code, when it detects that INT0 has fallen low, it initializes sleep mode and everything powers down with the exception of the watchdog timer that keeps a 1Hz cycle to keep an internal count and check it the chip should be woken back up. This works beautifully when 5V power is applied first, then the battery is inserted, then 5V is disconnected. It goes to sleep and when 5V is brought back it wakes up and I can see it hasn't lost count.
However, the problem comes when 3V is applied first. I'm honestly not sure if it's even booting. But what it is supposed to do is boot, check if INT0 (Digital 2) is low and, if so, go right to sleep. By watching the current draw I see that it powers up to a few mA for a couple seconds, then drops to about 0.3mA (still higher than it should be in sleep mode). But when I re-apply 5V, nothing. The power draw goes back up but it is unresponsive (over FTDI serial).
Is there maybe something I'm missing that it can't be booted on 3V... in theory it should run just fine.
Update: I dropped an LED onto D13 and tried the blink sketch. Works fine when starting from 3V or 5V. However, when I run my firmware and start it from 3V, the LED just starts flashing wildly. I have no idea what's causing it since I never even setup D13 as anything in my code. But it makes me thing it's something to do with the bootloader...

What is the BOD set to, and what is the current draw on startup?

It's set to 2.7V. Current draw while at 3V is about 4mA for the first few seconds, then drops and the LED goes crazy.

Have you tried without the bootloader, i.e. via ISP?

No, I haven't tried that yet. What's weird is it's fine when just running the blink sketch

ISTR that the bootloader causes D13 to have a weird pulse pattern which flickers the LED that's normally there, but since I don't actually have an Arduino (yeah I said it), I'm not certain of the timing/pattern.

I'm used to D13 flickering, but only when uploading the firmware.

Can you add a diagram to show "exactly" how your wiring is connected, including any and every sensor or load on the battery. What kind of coin cell are you using, is it a Lithium Ion (rechargeable) or alkaline?

If Blink is working, then it's more likely your code and not the bootloader. You probably will need to post your code and a schematic to get an answer. Also, have you tried disabling the BOD?

How are you measuring current?  Is it possible the burden voltage of your meter could be dropping the supply too low for reliable startup?

So... turned out what was happening was all in code. Turns out that I was initializing an interrupt on INT0, when it was low, at the very beginning of my code. Problem was that when it started up on 3V backup power, INT0 was always low because INT0 is tied to the 5V line (it's how it knows to go to sleep). Because INT0 was low and the interrupt was triggering on low it was causing a constant interrupt to occur, never giving the rest of the program any time to run. Switched to enabling that interrupt only once I've entered full waking mode and it works fine now.

Exactly what is happening and why cannot be determined based on the amount of info provided. However, I see at least one potential problem which would at least partially explain the symptoms described.
You said that you are using diodes to select the voltage supply, and one supply is a 3V battery. If you are using standard diodes that drop ~0.6V then the supply voltage to the MCU is only ~2.4V. If you are using Schottky diodes with a voltage drop between 0.15-0.45, the supply voltage is potentially as low as 2.5V. You have the BOD voltage set to 2.7 volts, so in theory the MCU will never boot with the battery.
As for why you can start it at 5v, drop to 3v, and bring it back up again- I'm not sure. You could be disabling the BOD in code...maybe… Not sure why it works, but it's likely not guaranteed to work.
I setup a diode switch circuit with 5v and 3.3v to see what it looks like on my oscilloscope when the voltages switch. When at 3.3v switching up to 5v, the voltage oscillates quite a bit initially. This may potentially cause some problems when the MCU tries to come out of sleep. Putting a cap between VCC and GND smoothed the signal very nicely. When switching from 5v to 3.3v, there really wasn't any oscillating, just a clean drop.
From this information, it seems that you should lower the BOD threshold or turn off the BOD, and put a decoupling cap between VCC and GND. You probably also should make sure you have a pull-down resistor on INT0, and read the MCU datasheet sections explaining the various sleep modes all the considerations for sleeping and waking – it’s pretty involved. Cheers

I think the problem is with your bootloader, but not in the way you think.
When an Arduino starts up, a bootloader profiting several tasks, such as looking for a serial host or loading program data from flash is going to take a lot more energy than a sleeping Arduino.
I think the reason why your Arduino will not start is because the bootloader requires an accurate clock source, but applying 3v to it will mess up that clock and it will perhaps crash or wait for 3.3v to be applied for a stable source.
Looking at the datasheet:

We see that current draw while waking up (running the bootloader) is probably going to be around 2mA, while sleeping current is about 0.8 microamps. This could certainly lead to a blackout on startup without the proper current.
Perhaps you should only turn it on with 5v power, or maybe you need a higher current, higher voltage battery.

Wouldn't this mean that Blink wouldn't work either? Also, I'm running more than a few Arduino's from coin cells with no issues. They can provide a lot of current for a short time.

source: Stack Exchange

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

sort: votes


text:
How to implement multiple LED modes in a sketch with potentiometers?
My hardware is 4 potentiometers connected to Arduino Analog 0-3, the output is an RGB led driver connected to Digital outputs 9,10,11. The output channels provide access to PWM control of those pins. So idea is the color and intensity can be controlled by the Arduino. I wrote a simple Sketch that reads the potentiometers and then outputs PWM to the RGB driver circuitry. This works great! So the hardware is working! Now comes the last potentiometer...
I want to make the last potentiometer a "mode select" control. It would function like this: If the last potentiometer (Pot4) is turned down all the way, then all lights are off. If the level is turned up a little, the Arduino then controls the RGB channels via Pots 1, 2 & 3. If Pot4 is turned up to just past halfway, the sketch enters a "strobe flash pattern" pulsing all channels on and off. And if the mode control Pot4 is turned up all the way, Arduino turns on all RGB channels.
How do I implement? Mode selection via a potentiometer?

Have you looked at how analogRead() works yet?

It seems you already have code for the 3 first pots to drive the RGB LED; it would be good to show it here so that answers can better show where to modify the current code.

Since you already know how to hook up a pot and read it's value, it's quite simple. You already have it hooked up in a voltage divider configuration and are getting a 10 bit (0-1023) value using analogRead(), you just need to decide what to do with it.
Assume potVal has the value of the pot.;
if (potVal < 256) {
    // Pot is one quarter turn or less
} else if (potVal < 512) {
    // Pot is between 256 and 512, so its more than quarter but less than half
} else if (potVal < 768) {
    // Pot is between half and 3/4ths of the way there
} else {
    // Pot is greater than 3/4 of it's full range
}

So I have broken it down into four quadrants for you, but you can do it however you like.

There should be at least a little calibration involved (for instance, if the pot being read involved is a logarithmic audio pot), but these threshold values are the best starting point.

It would be relatively simple to do a threshold test on analogRead() to switch modes (e.g. if the value is above 512 (analogRead() gives values between 0-1023) then you switch modes (probably with a boolean variable that you can then use to decide whether to strobe the LEDs).

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


text:
How has Arduino been used in the classroom?
I remember seeing Primo, this robot that is based on Arduino and serves to teach kids to program. My interest in the platform comes from there, but it is always nice to learn about other cool applications.
What other applications are there that utilise Arduino for K-12 education?

This is very broad. What age range? What type of education?

Edited to mean only k-12. Is that still too broad?

There's linkbot http://www.barobo.com/

I've used Sparki from Arcbotics as a robotics platform. It's uses Arduino Sketch to program and a modified Arduino IDE.
Sensors for line following , edge detection, distance and light level sensing are built in. Also the creators are focused on education so the material and projects are teaching oriented.
The Community seems pretty active and engaged too so the material should build over time.

We have been using Arduino's to teach basic microcontroller concepts in classes focused on environmental monitoring & instrumentation, rather than just electronics:
An Arduino UNO based Datalogger for the Classroom
The IDE abstracts away enough of the low level details that you can get students into programming quickly, while still exposing them to enough of hardware side of things. I am not sure what other platform would let us take true beginners so far, so quickly.


text:
Digital RGB LED animation
I've been trying to get colours fade into each other for a project I'm working on.
I have achieved this with the rainbow effect that some from Adafruit's example code, however I want to be able to choose the colours (eg. dark blue into light blue).
I've got the colours changing and fading, however the fade turns off all the LEDs and starts to increase the brightness of the new colour. I need the colours to blend rather than fade out and increase in brightness.
Is anyone able to point me in the right direction?
#include "LPD8806.h"
#include "SPI.h"
#define stripSize 64

int nLEDs = 160;

int dataPin  = 2;
int clockPin = 3;

// First parameter is the number of LEDs in the strand.  The LED strips
// are 32 LEDs per meter but you can extend or cut the strip.  Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(64, dataPin, clockPin);

// You can optionally use hardware SPI for faster writes, just leave out
// the data and clock pin parameters.  But this does limit use to very
// specific pins on the Arduino.  For "classic" Arduinos (Uno, Duemilanove,
// etc.), data = pin 11, clock = pin 13.  For Arduino Mega, data = pin 51,
// clock = pin 52.  For 32u4 Breakout Board+ and Teensy, data = pin B2,
// clock = pin B1.  For Leonardo, this can ONLY be done on the ICSP pins.
//LPD8806 strip = LPD8806(nLEDs);

void setup() {
  // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}

void loop() {
  //turnAllOn(strip.Color(30,30,30),4000);
  fade(0, 127, 0, 100); //red, green, blue, delay - fade up all pixels one color
  //turnAllOn(strip.Color(30,100,30),4000);
  fade(50, 127, 02,100); //red, green, blue, delay - fade up all pixels one color
  //turnAllOn(strip.Color(100,30,100),4000);
  fade(50, 127, 50, 100); //red, green, blue, delay - fade up all pixels one color
}

void fade(uint32_t r, uint32_t g, uint32_t b, uint32_t wait) {
  int i, j;
  for (j=0; j < 384; j++) {
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color((r*j)/1000,(g*j)/1000,(b*j)/1000));
    }
  strip.show();
  }
  delay(wait);
}

void turnAllOn(uint32_t c, uint32_t wait) {
  int i;
  for (i=0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);  // turn all pixels on
  }
  strip.show();   // write all the pixels out
  delay(wait);
}

uint32_t Wheel(uint16_t WheelPos)
{
  byte r, g, b;
  switch(WheelPos / 128)
  {
    case 0:
      r = 127 - WheelPos % 128;   //Red down
      g = WheelPos % 128;      // Green up
      b = 0;                  //blue off
      break;
    case 1:
      g = 127 - WheelPos % 128;  //green down
      b = WheelPos % 128;      //blue up
      r = 0;                  //red off
      break;
    case 2:
      b = 127 - WheelPos % 128;  //blue down
      r = WheelPos % 128;      //red up
      g = 0;                  //green off
      break;
  }
  return(strip.Color(r,g,b));
}

Currently, your fade function is starting at 0 and effectively interpolating up to the desired colour. To fade between colours, you would need the sketch to remember the previous colour it used, and start fading from that instead of from 0.
The approach I'd use is to start by calculating how much each component needs to change by on each step. For example, if you want to fade from 100 to 200 across 50 steps, then it needs to change by +2 on every step. If you wanted to do the same in reverse (200 to 100) then it would have to change by -2.
One of the problems is that each component will probably be changing by a different amount (red might go from 0 to 200, but blue might only go from 50 to 70). If you're using integers all the time then it could result in some uneven transitions, so I'd recommend using floating point instead. It's technically slower (less efficient), but probably not enough to worry about.
This is how I'd probably write it:
void fade(uint8_t oldR, uint8_t oldG, uint8_t oldB, uint8_t newR, uint8_t newG, uint8_t newB, uint32_t numSteps, uint32_t waitPerStep)
{
    // Guard against division by zero
    if (numSteps == 0) numSteps = 1;

    // Calculate how how much each colour needs to change on each step
    const float
        stepR = (newR - oldR) / (float)numSteps,
        stepG = (newG - oldG) / (float)numSteps,
        stepB = (newB - oldB) / (float)numSteps;

    // These values will store our colours on the way along
    float r = oldR, g = oldG, b = oldB;
    uint8_t byteR = oldR, byteG = oldG, byteB = oldB;

    // Go through each fade step
    const uint16_t numPixels = strip.numPixels();
    for (uint32_t step = 0; step < numSteps; ++step) {
        // Move one step towards the target colour
        r += stepR;
        g += stepG;
        b += stepB;

        // Round the colours to integers here so we don't have to do it repeatedly in the loop below
        byteR = (uint8_t)(r + 0.5f);
        byteG = (uint8_t)(g + 0.5f);
        byteB = (uint8_t)(b + 0.5f);

        // Apply the colour to each pixel
        for (uint16_t pixel = 0; pixel < numPixels; ++pixel) {
            strip.setPixelColor(pixel, byteR, byteG, byteB);
        }

        strip.show();
        delay(waitPerStep);
    }
}

As you can see, you pass it the old colour (which you're fading from) and the new colour (which you're fading to). As I mentioned above, this means your sketch has to remember which colour it previously used, as I don't think the library provides a way to read the current colour back.
I've included some optimisations in there to make it run faster. There's more you could do to optimise it even further, if necessary.
To use this, you'd do something like this:
// Fade from black to red and pause briefly
fade(0, 0, 0,  255, 0, 0,  100, 10);
delay(500);

// Fade from red to purple and pause briefly
fade(255, 0, 0,   255, 0, 255,  100, 10);
delay(500);

// Fade from purple to green and pause briefly
fade(255, 0, 255,  0, 255, 0,  100, 10);
delay(500);

I've made a couple of other changes compared to your own fade function function. First of all, I've made it so that you can set the number of steps to fade over. This can be quite useful because bigger colour changes will need more steps to look smooth.
I've also modified the wait parameter. In your code, you put the delay after the entire fade was complete, which seems like an odd approach. It makes more sense to allow a small delay between each step of the fade, so you can control how fast it goes.
In my example above, you can see the 100, 10 parameters at the end of each call to fade(). That means it will divide the colour change into 100 steps, with a delay of 10ms between each step. The result is that each fade will take roughly 1 second (not counting the time taken to actually update the LED strip).

Very well answered. Kudos for all code details, optimizations and explanations. Maybe a small bug: the from color never appears as you start your loop with the first step increment. You should add one more iteration and increment only at the end of the loop.

@jfpoilpret Thanks. Missing out the first step is actually deliberate. Based on the question, I'm assuming the LEDs are already showing the 'old' colour before fade() is called. You're absolutely right though. In other circumstances you may indeed want that extra step.

This is really great. Thanks so much for the detailed write up!


text:
Arduino program only works when run as root
Uploading simple sketches seems to work when I run the Arduino program as root (sudo). I would like to run it as a regular user. Has anyone faced the same problem before and fixed it?
Here is what I obtained from lsusb:
$ lsusb
Bus 002 Device 022: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)

And the Arduino program identifies it as /dev/ttyACM0. Here are its permissions:
$ ls -l /dev/ttyACM0
crw-rw---T 1 root dialout 166, 0 Mar 14 22:03 /dev/ttyACM0

Here is the output from id
groups=1000(abhiram),20(dialout),24(cdrom),25(floppy),29(audio),
30(dip),44(video),46(plugdev),105(scanner),110(bluetooth),112(netdev)

When I upload an sketch from the examples, as a regular user, I encounter this error:
avrdude:stk500_recv(): programmer not responding

Any suggestions are welcome.

See if this helps, section "SET THE PERMISSION"

And +1 for not accepting the situation to run the IDE as root, but trying to figure out how to properly solve the issue.

What is the exact error you get when you try to run the IDE under a non-privileged user? You may need to enable verbose output in the Preferences menu.

Ensure you are connecting to the correct device, by unplugging, then wait for a few seconds, then replug, then check the output of dmesg for the device file that is registered.

Checked that, the device is discovered properly as /dev/ttyACM0: USB ACM device. So, it doesn't seem like problem to me.
On the other hand, the logs from compiling and uploading( had to enable them in Preferences), seem promising. I just can't seem to copy them from the arduino program :(. (may be they are writing to a file somewhere?)

What happens when you avrdude -p atmega328 -carduino -P /dev/ttyACM0 -b 57600 -D -Uflash:r:/tmp/project.hex:i ? Double check the device and baudrate.

I see what you mean, I had to change the command a little bit. Here is what it looks like /usr/share/arduino/hardware/tools/avrdude -C/usr/share/arduino/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/build6432672958845434451.tmp/Blink.cpp.hex:i And it works when I run it as a regular user :). Not sure why it borks with the arduino tool though.

The baudrate is odd, I'd expect 57600, at least that is what I use to connect to an Arduino. Did you find that baudrate in the Arduino logging? I am using another board though, that may explain the difference.

The easiest solution is to add yourself to the dialout group.
First make a note of the output from id. Save it in file (not in /tmp as that gets cleaned out on a reboot). If you look at the output, you'll notice that your user is signed up for several groups and those groups represent extra privileges on the system. By default your Arduino is assigned to the group dialout because it registers as a serial interface and in the old days these were often used to ... dial out, using a modem.
To add yourself to the dialout group, issue the following command:
sudo usermod -a -G dialout $USER

Don't forget the -a flag (for appending groups rather than replacing) or you will have entirely different problems. This is the reason for making a copy of the id output to a file, so in case you do mess up at least you know what your user was configured like before.
Then log out and log in and it should work from that point.
Optionally you can double check the output for id against the output you saved before.

thanks @jippie, for the thoughtful answer. I have added myself to the dialout group, but the problem still seems to persist. I have modified my question with the output from the id command.

My impression from your update is that the exact cause of the problem has shifted to the next issue. You are on your way to solve it. What happens when you cat /dev/ttyACM0? Does it throw an error?

No, the device file seems to empty, when I cat it.

Empty is OK, as long as you don't get an error message.

The oft-repeated advice to "just do sudo usermod -aG dialout <username> never worked for me, and I finally figured out why. On my machine, /dev/ttyUSB0 is of the group serial and not dialout, so adding my username to dialout did nothing.
# ls -l
# crw-rw---- 1 root serial 188, 0 Mar 31 20:52 /dev/ttyUSB0
                    ^^^^^^ (group-name)

Finally: sudo usermod -aG <group-name> <username> fixed it for me.
Embarrassingly, this is also explicitly mentioned here under "SET THE PERMISSION". Sigh.

Yes, it's worth checking the actual owning group.  Also the device file can be either a ttyUSB# or a ttyACM# (or theoretically anything) depending on the board type, kernel driver, and ultimately configuration of udev or whatever creates the nodes.

It's also mentioned at https://www.arduino.cc/en/Guide/Linux#toc6

This happens to me.
In my case, I had upgraded the version of arduino and seems the preferences file was causing the problem.
Just delete ~/.arduino/preferences.txt file (with Arduino IDE closed).
Steps:

Close Arduino IDE
execute this:
rm ~/.arduino/preferences.txt
Launch Arduino IDE

This worked for me, hope it works for someone else.
I am using Linux Mint 17 and I upgraded from Arduino 1.05 to Arduino 1.06 by extracting the Arduino IDE, I am not using the one in the repo.
(Of course, after adding your user to the corresponding group as mentioned by others, but if that wont help you try this)

Possibly related to this, one side effect of running tools as root is that you can end up leaving behind temporary, config, or project files which your ordinay account cannot modify or clean up.

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


text:
Arduino error message that I don't understand
I downloaded Arduino code from this: https://github.com/BabyWrassler/MissionControl/ Github, and got the  error message below.
It is designed to work with a Raspberry Pi, and I installed the two Adafruit libraries.  I also have not hooked it up to either the Pi, or the two Adafruit devices, but that is partly because I cannot get it to run without the error message.
Update:
Here is what was highlighted:
Adafruit_LEDBackpack matrixA = Adafruit_LEDBackpack();
The orange bar says:
    Variable or field ‘matrixOff‘ declared void
I cannot tell what of the following was from before, but here is the entire console log:
    mcDesk.ino:2:53: error: Adafruit_LEDBackpack.h: No such file or directory
    mcDesk.ino:3:45: error: Adafruit_GFX.h: No such file or directory
    mcDesk:11: error: variable or field 'matrixOff' declared void
    mcDesk:11: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:11: error: expected primary-expression before 'buffer'
    mcDesk:12: error: variable or field 'ledOn' declared void
    mcDesk:12: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:12: error: expected primary-expression before 'buffer'
    mcDesk:12: error: expected primary-expression before 'cat'
    mcDesk:12: error: expected primary-expression before 'an'
    mcDesk:13: error: variable or field 'ledOff' declared void
    mcDesk:13: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:13: error: expected primary-expression before 'buffer'
    mcDesk:13: error: expected primary-expression before 'cat'
    mcDesk:13: error: expected primary-expression before 'an'
    mcDesk:14: error: variable or field 'dispMat' declared void
    mcDesk:14: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:14: error: expected primary-expression before 'buffer'
    mcDesk:17: error: variable or field 'threeDigitDisp' declared void
    mcDesk:17: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:17: error: expected primary-expression before 'buffer'
    mcDesk:17: error: expected primary-expression before 'cats'
    mcDesk:17: error: expected primary-expression before 'ans'
    mcDesk:17: error: expected primary-expression before 'number'
    mcDesk:18: error: variable or field 'digitDisp' declared void
    mcDesk:18: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:18: error: expected primary-expression before 'buffer'
    mcDesk:18: error: expected primary-expression before 'pos'
    mcDesk:18: error: expected primary-expression before 'cat'
    mcDesk:18: error: expected primary-expression before 'an'
    mcDesk:18: error: expected primary-expression before 'num'
    mcDesk:23: error: variable or field 'switchBars' declared void
    mcDesk:23: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:23: error: expected primary-expression before 'buffer'
    mcDesk:23: error: expected primary-expression before 'grphCats'
    mcDesk:23: error: expected primary-expression before 'grphAns'
    mcDesk:23: error: expected primary-expression before 'cmnd'
    mcDesk:23: error: expected primary-expression before 'offset'
    mcDesk:24: error: variable or field 'barDisp' declared void
    mcDesk:24: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:24: error: expected primary-expression before 'buffer'
    mcDesk:24: error: expected primary-expression before 'grphCats'
    mcDesk:24: error: expected primary-expression before 'grphAns'
    mcDesk:24: error: expected primary-expression before 'pos'
    mcDesk:24: error: expected primary-expression before 'offset'
    mcDesk:25: error: variable or field 'cBarDisp' declared void
    mcDesk:25: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:25: error: expected primary-expression before 'buffer'
    mcDesk:25: error: expected primary-expression before 'grphCats'
    mcDesk:25: error: expected primary-expression before 'grphAns'
    mcDesk:25: error: expected primary-expression before 'pos'
    mcDesk:25: error: expected primary-expression before 'offset'
    mcDesk:11: error: 'Adafruit_LEDBackpack' does not name a type
    mcDesk:12: error: 'Adafruit_LEDBackpack' does not name a type
    mcDesk:13: error: 'Adafruit_LEDBackpack' does not name a type
    mcDesk:14: error: 'Adafruit_LEDBackpack' does not name a type
    mcDesk:15: error: 'Adafruit_LEDBackpack' does not name a type
    mcDesk.ino: In function 'void decodeCommand()':
    mcDesk:193: error: 'matrixE' was not declared in this scope
    mcDesk:193: error: 'ledOn' was not declared in this scope
    mcDesk:199: error: 'matrixE' was not declared in this scope
    mcDesk:199: error: 'ledOff' was not declared in this scope
    mcDesk:204: error: 'matrixC' was not declared in this scope
    mcDesk:204: error: 'cBarDisp' was not declared in this scope
    mcDesk.ino: In function 'void allMatrixOff()':
    mcDesk:213: error: 'matrixA' was not declared in this scope
    mcDesk:213: error: 'matrixOff' was not declared in this scope
    mcDesk:214: error: 'matrixB' was not declared in this scope
    mcDesk:215: error: 'matrixC' was not declared in this scope
    mcDesk:216: error: 'matrixD' was not declared in this scope
    mcDesk:217: error: 'matrixE' was not declared in this scope
    mcDesk.ino: At global scope:
    mcDesk:220: error: variable or field 'matrixOff' declared void
    mcDesk:220: error: 'Adafruit_LEDBackpack' was not declared in this scope
    mcDesk:220: error: expected primary-expression before 'buffer'

"Adafruit_LEDBackpack not declared" tells me maybe the library wasn't installed? Can you run one of the examples in that library? (File > Examples)

@sachleen which one?  Does it matter?

Printscreen is far clearer than taking a picture of the screen. Also put all of your code up on pastebin.

@cybergibbons sorry, I was using my iPad to make the post.  My Arduino computer doesn't have wifi on it.

Copy and paste the messages from the text below the code window, as well as the code section that has the error in it (the highlighted section). Try not to post images of code or error messages, when it is in plain text.

Don't use images to explain your problem. Nobody is ever going to find this question through a search engine because the text cannot be indexed and it uses much more resources than necessary. What is wrong with a regular copy and paste of the text?

It's hard because I don't have my Arduino computer connected to the internet.

Ok I figured out how to copy and paste it.   Adding all the spaces before each line took FOREVER but it is all on there now.

Those error messages are exactly the ones I get when the libraries aren't there and they go when the library is there.

The first 2 lines clearly show that you have not properly installed the 2 required adafruit libraries.

It seems to me that those Adafruit libraries were not correctly installed on your PC or your sketch.
In addition to downloading and installing the library onto the Arduino library directory (on Windows, that's normally C:\Users\UserName\Documents\Arduino\libraries), when you want to use that library with Arduino IDE, you must add the library for your sketch with the menu command "Sketch -> Import Library..."
Important note: it seems just adding #include "library.h" does not work with Arduino IDE, you absolutely need to use the menu.

I don't think I've ever used the menu to include a library - it definitely works just typing it in here.

@Cybergibbons I faced that problem a couple of times in the past (I almost never use Arduino IDE anymore though, except for quick qnd dirty proofs of concept), that's why I mentioned it here.

Interesting. The more I use the Arduino IDE, the more I dislike it.

I tried that, but still got the exact same error message. @cybergibbons + jfproilpret

I agree with Cybergibbons, you don't have to use the menu...

Installing external libraries can be a mess, I suggest trying biicode (docs) that downloads and configures them for you. Your required libraries are here:  adafruit and the firmware is here mission control you can try with bii open babywrassler/missioncontrol to download it along with adafruit requirements


text:
Reading multiple bytes from *software* serial
I have Arduino Leonardo board operating lots of AC relays in quite noisy environment. USB works unstable, which sometimes causes the board to hang, so I decided to use secondary serial connection as "debug console":
  Serial1.begin(115200);
  .....
  .....
  if (Serial1.available()) {
    char ch = Serial1.read();
    if ( isalnum(ch) ) {
      switch (ch) {
        case 'M': {
          turnOn_pin_Motor();
          break;
        }
        case 'm': {
          turnOff_pin_Motor();
          break;
        }
        .......

My problem is that noise affects Serial1 the same way it messes USB (but at least it doesn't cause it to freeze). I'd like to use some sort of error checking to prevent Leonardo from acting on "phantom" commands. I could, for example, prefix each keyboard command my Arduino should receive with special symbol, maybe "!".
So I must be reading one char, checking if it is "!" and reading second character.
Unfortunately, I can't modify my code so it would use 2-character buffer and shift its contents as characters arrive, without locking the main loop while waiting for the next char. Any hints on what should I do in this case?

Serial1 on a Leonardo is not “Software Serial”, it’s arguably more “hardware” than Serial.
How does the noise on your serial port manifest? Are the characters injected truly random?

Yes, they are totally random: here is tiny example from my debug log (notice the garbage as the 'Inlet' valve turns off and the current inducted by AC coil messes with power supply): [3819448        void turnOff_pin_Inlet()]                                                 WкК•╧╠•я² [3819570        void checkTempSensors()]        DS18B20 on Door failed!

I've replaced today the wire connected to Serial1 (I've used piece of Ethernet Cat5 twisted pair patch cord) with Bluetooth dongle - it didn't help, I still see garbage in log and Arduino still acts weird - it receives "phantom" keypresses from "debug" console.

Providing a schematic of your circuit would help. The best way to solve your problem is to first try to reduce the noise, this has to be done electronically.

As @jfpoilpret mentions, investigate the cause of the noise. It is usually easier to fix the cause than to remedy the data corruption.

Noise bad enough to cause Serial to corrupt is likely to cause other problems on I/O. Fixing the commands won't fix other issues, and it's likely you system would fail in another way.

I've added decoupling caps everywhere I could, it reduced the problems but didn't fix them entirely. Probably I will have to physically separate relays and Arduino to two different boxes, and will add separate AC-DC power supply unit for relays. I'll also order relays with optocoupling instead of existing relay board.

Just to be sure, you also used flyback diodes on relays right? How do you command your relays: directly from Arduino pins, through a transistor, a Darlington, a MOSFET?

I have dedicated relay board - http://dx.com/p/202361 - it has flyback diodes. By mistake I've ordered 12V board, not 5V - so I am powering it from Vin pin of my Arduino - so it gets unregulated power supply. Relay board is not a problem - it is probably the 220VAC power lines being close to Arduino's 5VDC lines. Will need to spread them farther, as I wrote above. I'll need to figure out how to insulate 5V lines though - I believed using wires in twisted Ethernet cable would be fine, but it looks like I need to switch to some shielded cable.

Serial1 on the Arduino Leonardo is hardware serial, not software.
There are several ways to read in multiple bytes from Serial.
Instead of detecting Serial.available() (i.e. non-zero), change it to Serial.available() >= 2
if (Serial.available() >= 2) {
  for (int i=0; i<2; i++) {
    buffer[i] = Serial.read();
  }
}

Or you can leave it as it is, and read into the buffer one at a time.
static int bufferIndex;

if (Serial.available())
{
    buffer[bufferIndex++] = Serial.read()
}

You'll need to detect the contents of the buffer in another if statement, and also deal with the bounds of the index.
Honestly though, noise is your issue here - this is an example of an XY problem. There's nothing inherent in using a microcontroller with relays that should mean that serial won't work.


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 Pro Mini (3.3V version) input voltage range / tolerance
I have a few Arduino Pro Mini clones (cheap Chinese stuff) and would like to power them with 12V power supply (same as fan voltage). According to the Arduino Pro Mini spec the RAW pin can take 3.35-12V (3.3V model). In practice this means a 12V PSU cannot be used as they are almost always over 12V with low load. I read that the voltage regulator in this board is capable up to 16V input. I tried plugging in a cheap 12V power adapter that read 15.1V with no load but a component on the arduino clone board actually exploded instantly. The board seems to work still when powered from usb programmer. Component that burned out is just above VCC, RST and GND pins.
Why did this happen? What did I just damage and most importantly what is a safe voltage level to use? I already have a few 12V switching power supplies it would be a shame if I could not use them.
Solution:
In the end it seems to have been a faulty arduino clone, faulty or poor quality power adapter or the fact that I powered the power supply before plugging it to the board's RAW input pin. The cheap 12V switching power supplies work just fine even though my multimeter registers a voltage spike as high as 30V during power up.

There doesn't seem to be any Pro Micro board on the official site. I can only find it on Sparkfun. Could you verify which board do you have?

My mistake, it's actually Pro Mini (corrected now).

The genuine Pro Mini's use a MIC5205 regulator which should accept up to 16V at it's input normally, with an absolute maximum of 20V. It's unlikely that the regulator would be damaged by 15.1V.
However, the component you have indicated that has blown is a capacitor. SMD capacitors are available in different voltage ratings, typically 4V, 6.3V, 10V, 16V, 25V, 35V and 50V (and above, but let's ignore them for this). It's rare to see any intermediate values.
SMD capacitors are very intolerant of being used at a higher voltage than specified. This is especially true of electrolytic and tantalum capacitors. The blown capacitor on the genuine Pro Mini's is polarised (the grey band not he package and the schematic indicates this), so we can infer it is either electrolytic or tantalum. A 10µF SMD electrolytic is unlikely to be in this package, so it is almost certainly a tantalum.
Sparkfun sell 10µF tantalums, and they are rated at 16V. It's quite likely these are the same ones used on the Pro Mini. 15.1V is very close to 16V - in fact, if this is a poorly smoothed power supply, the meter might show 15.1V but the peaks could well be 16V or even 20V. It is recommended that you de-rate the voltage ratings on tantalums by 50% at least.
It's really important to realise that most low-cost DC power supplies are not regulated and produce a very bumpy output voltage with no regulation:

Tantalums also have no tolerance for reverse voltage, so if you did apply reverse voltage, it would pop.
So it is quite likely that you over-volted the cap and blew it. You could replace them with higher rated capacitors - I would go for 35V ones if you want to supply 15.1V. Desoldering and desoldering a single capacitor is relatively easy as long as the pads haven't been damaged. Realistically, you could use a normal leaded 10uF electrolytic between RAW and GND instead of the SMD one.
EDIT: However, looking at the data sheet for the regulator, it shouldn't really matter if that 10uF is there or not:

A 1μF capacitor should be placed from IN to GND if there is more than
  10 inches of wire between the input and the ac filter capacitor or if
  a battery is used as the input.

Some regulators absolutely require an input capacitor, with others it is just advisable. This looks like it is just advisable. So if it isn't working on external power now, you may have blown the regulator as well.
Even if the clone board uses a different SMD regulator, their characteristics are all very similar. As stated, some do need a capacitor on the input to work, so replacing it might fix it.
There is a further consideration that dropping from 15.1V to 3.3V on a SMD regulator is not a great idea. You will need to burn off a lot of power.
The MC5205 can dissipate 455mW with a minimal PCB footprint (which the Pro Mini has) with a 25°C ambient:

So, we know the maximum power we can dissipate, and we know the voltage drop - we can then calculate the current:
P = (Vin - Vout) * I
0.455 / (15.1 - 3.3) = I
I = 38.5mA
This isn't very much at all. You might want to consider regulating off the board, and probably with a switching regulator rather than linear regulator.
I also note your PS:

the ground of the 12V PSU is shared with Arduino ground pin, not sure
  if this might be the cause.

If they weren't shared, there would be no way that this could work. They need to be shared otherwise the Vcc from the power supply is not referenced to anything and may as well not be there.

Fantastically detailed answer! The psu I used could well have higher peak voltage. Could a switching supply have this problem too? The damaged capacitor has "a104C" written on it and "3A052" below that. Not sure what that means. The pads seem fine as I only contacted the RAW pin for less than half a sec. I will attempt to solder a normal 35V capacitor when my soldering iron arrives. I assume larger cap is ok?

A blown tantalum would likely result in more damage than just a blown capacitor (like, say, a scorched PCB).

I only see damage to the capacitor, no marks on the PCB at all. Top of cap has a hole and some exposed metal inside also some black burn mark on the side but that's all. I only touched the contacts for a very short time so maybe that's why.

I've definitely taken out tantalums and the damage has been limited to the cap and minor scorching.

@Cybergibbons I had the power adapter plugged in before connecting the arduino, does that rule out that the startup voltage was the cause? I have switching supplies but not sure if they are prone to higher voltages than rated or not..?

Always remove power before connecting anything. Most small unregulated PSUs slowly ramp up rather than spike. Switch mode PSUs can spike when turned on.

Also, for the replacement, try to stick to ~10µF, certainly no smaller than 1µF, no bigger than 20µF

@Cybergibbons indeed the dc adapter I used does ramp up to 15.1V in 1-2 seconds. Will see how switching psu behaves when I get my soldering iron. Would I notice a start up spike on the multimeter? Don't want to damage another arduino, how would you test/make sure it will not be damaged before trying with another psu? I'd rather not use voltage dividers or other components if I don't have to.

The component that exploded during your test is a capacitor.
According to the position on the board you mentioned, it is one of the 2 electrolytic capacitors used on both sides of the 3.3V regulator (I would say that's probably the upstream capcitor).
There are a few reasons why a capacitor may explode:

apply an inverted voltage to it (polarized capacitors only)
apply a voltage above its rating
apply a current above its rating

Your situation is probably the 2nd one: too high voltage applied.
According to Sparkfun original schematics, this capacitor must be polarized with 10uF capacity. Unfortunately the schematics do not mention the maximum voltage.
According to the specification for the original board, the maximum voltage for this cap should be at least 12V, but there is no guarantee that it is anthing above than 12V. Hence, you have to consider 12V is the maximum voltage applicable to your board (on the RAW pin).
In addition, you have mentioned you are using a cheap chinese clone, it is perfectly possible (although not expected, as it would make the board operate differently than the original specs) that this one uses a lower voltage cap (eg 10V) which would be a bit cheaper.
If you do want to reuse your 12V PSU, you will have to ensure that its output voltage never exceeds 12V, for this you are left with a few options:

use a voltage divider made of 2 resistors: you must first know the max voltage output of your PSU and then calculate resistance values to get 12V based on that max voltage. That's easy but it can waste a lot of energy
use a 12V Zener diode outside your PSU
use a 12V voltage regulator circuit after your PSU: that one is the safest, but also the most expensive solution

Edit:
Of course, if you have already done it and are equipped for it, you can find replacements for the capacitor that has exploded and buy a higher-voltage one, then replace it on your boards; that will reauire good soldering/desoldering equipement usable for surface-mounted components.

Or replace the low-voltage parts with higher-rated ones.

Yes of course but that involves SMC desoldering which is not something everyone can do.

@Ignacio-Vazquez-Abrams I have edited my answer to include your suggestion, thanks.

I do have a few capacitors, just waiting for my hakko soldering iron to rrive as my el cheapo broke... Can I use any non smd capacitor with voltage rating of let's say 35V?

Higher voltage caps is OK, as long as capacitance is the same as the original. You can go and remove the SMD cap (only one is needed to be replaced) and solder a "normal" cap instead, but beware of shorts as leads are much bigger!

Any idea what the capacitance of this cap is? I cant seems to find any info on it based on what's written on it. a104C 3A052.

According to the board schematic it is 10uF

For the replacement you can solder it onto the pins on the board rather than the pads.

Although this thread is old, people has to be aware that some clone boards uses 4B2X regulator and they support maximum 10v (https://epstik.com/p744820729-xc6204b332mr-4b2x-stabilizator.html , https://www.mcucity.com/product/3240/xc6204b332mr-g-3-3v-4b2x-4b2y-positive-voltage-regulator). Theses clones are extremely common on ebay and another marketplaces.


text:
Is there a way to detect if Arduino, Stino or another IDE/toolchain is in use?
I've noticed some irritating differences between the Arduino IDE and Stino (mainly around including certain header files). These are likely bugs that need following up with one or both of the parties, but in the meantime, I would like my code to compile with both of them without editing. This is because I do not want to lock any users out of using my code.
Are there any macros or similar that are readily available (as in, require no modification of the toolchain or IDE) that would allow me to detect which is in use?
For example, in many libraries, there is this snippet:
#if ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif

However both Stino and Arduino define this.

I've poked around in the Stino toolchain a fair bit, and submitted a pull request or two. It should be pretty easy to get something like #define STINO_COMPILER added to the compilation-time defines. The guy who manages the repo is quite open to sensible pull-requests like that, and once it's properly in the mainline repo, it wouldn't require changes for any of the end-users.

Thanks Fake Name - yes, I think that sounds like a good plan. I think I only need support for Stino really. I've not seen Eclipse used often enough to care.

This isn't a real solution but you could also add two versions of the code or somehow have a comment: Uncomment the following lines and delete the other lines for Stino. | @Fake Would that be a problem when using that code with the Arduino IDE?

To further Anonymous Penguin's comment, you could have a pound define per compiler.  And then the default version of the code has an error and will not run unless the user comments a line to specify which compiler they are using.  Something like this #if !defined(STINO_COMPILER) #error please uncomment one of the compiler lines #endif

As Stino claims to use the installed Arduino IDE you already have, which means you can not differentiate at compile time.


text:
What alternatives are there to the Optiboot bootloader?
Nearly all modern Arduino boards use the Optiboot bootloader. Compared to the ATmegaboot used before, this is smaller in flash terms (by about 1.5KB) and faster in upload speed (115.2k vs 57.6k) and starts your sketch quicker (the delay whilst waiting after reset is shorter).
Are there any alternatives to the Optiboot bootloader? Specifically, are there any smaller (in flash terms) boot loaders? What differences do they have?

Optiboot is about the smallest bootloader available.
But, there is a much more powerful (with inbuilt console for hardware testing, RAM and Flash contents checking, etc) bootloader with a more developed and robust stk500v2 communications protocol between avrdude and the AVR bootloader.
I've used it on the ATmega2560 and on the ATmega1284p. It works for both 3 byte and 2 byte program counter MCU.
I have a STK500v2 Bootloader version on Sourceforge.
This bootloader is based the Peter Fleury STK500v2 bootloader, updated by Mark Sproul. I've made edits to have it supporting with the Goldilocks (an ATmega1284p) board.
The key feature is to use the STK500v2 protocol for uploading the Flash image to the Arduino. This protocol is more robust and gives better error capabilities than the avr109 protocol. As an aside the avr109 protocol is called "Arduino" in the Arduino world, because it toggles DTR (to reset the board and automatically enter the bootloader), and the STK500v2 protocol is called "Wiring" in the Arduino world, because of the same reason.
The Fleury/Sproul STK500v2 bootloader is designed to work with the ATmega2560 which has a 3 byte program register, because of the larger Flash size. But, it also supports normal 2 byte boards (everything else really).
For boards with plenty of Flash (like Goldilocks 1284p), there is a hardware monitor that can be used to query Flash, SRAM and hardware; you can check connections without additional code, and check the actual contents of Flash and EEPROM. Because the 1284p supports 2 USART, I added the ability to have debugging on USART1, so that the upload process via USART0 isn't disturbed.

This seems to be part of FreeRTOS, is that bootloader totally independent from FreeRTOS?

It is totally independent. The bootloader is used to write flash with anything. FreeRTOS comes later after main() is started. I just keep it in the same repository. I didn't write it, just modified for my purposes.

This seems interesting; it would be useful if you could sum up important features of your bootloader in your answer: size in Flash, upload max speed, Arduino boars it can work with, and some more details about hardware testing).

It is (based on) the Peter Fleury STK500v2 bootloader, updated by Mark Sproul. I've made edits to have it supporting with the Goldilocks (an ATmega1284p) board. The key feature is to use the STK500v2 protocol for uploading the flash image to the Arduino. This protocol is more robust and gives better error capabilities than the avr109 protocol. As an aside the avr109 protocol is called "Arduino" in the Arduino world, because it toggles DTR (to reset the board and automatically enter the bootloader), and the STK500v2 protocol is called "Wiring" in the Arduino world, because of the same reason.

The Fleury/Sproul STK500v2 bootloader is designed to work with the ATmega2560 which has a 3 byte programme register, because of the large flash size. But, it also supports normal 2 byte boards (everything else really). For boards with plenty of flash (like Goldilocks 1284p) there is a hardware monitor that can be used to query flash, RAM, and hardware. You can check connections without additional code, and check the actual contents of flash and eeprom. Because the 1284p supports 2 USART, I added the ability to have debugging on USART1, so that the upload process via USART0 isn't disturbed.

Thanks for the info, I have updated your post as I think this information should directly be part of your answer. Feel free to add more information if you see fit!

One more question: you mention the Goldilocks 1284p a lot, but all features that work for it also work for the Arduino Mega, right?

Yes, absolutely. It was designed for 3 byte program counter devices, such as the Atmega2560/2561, the Arduino Mega.

TinySafeBoot is an alternative for ATtiny and ATmega devices.

Compatible to plenty of ATtinys and ATmegas (see below)
Read/Write access to Flash and EEPROM.
All IOs available for serial communication
One-wire, also with multiple AVRs on a single line
Autobauding, rugged protocol.
Activated by Reset + Password (optional)
Password and Timeout user changeable anytime.
"Emergency Erase" to overcome lost Password - kills all data but leaves bootloader intact.
ATtinys: ~ 550 bytes,
ATmegas: < 512 bytes (!)
TSB for ATtiny can update itself.
The Sourcecode is free Software (GPL)

anyone know how TSB compares to Optiboot? Last update seems at least 2 years ago...

Are there any alternatives to the Optiboot bootloader?

Err... not really. There's actually a [unofficial] modification to Optiboot to make it faster when uploading.

To install the high baud rate variations…

Ensure the Arduino IDE is not running
Download the 7-Zip archive using the link above
Extract the three files to the following directory: {Arduino Installation Root}\hardware\arduino\bootloaders\optiboot\
Open the boards.txt file located in the following directory: {Arduino Installation Root}\hardware\arduino\

Find This section inside it:
uno.name=Arduino Uno
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.path=optiboot
uno.bootloader.file=optiboot_atmega328.hex
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino
uno.build.variant=standard

Add the following section…
uno_uf.name=Arduino Uno / Upload Fast
uno_uf.upload.protocol=arduino
uno_uf.upload.maximum_size=32256
uno_uf.upload.speed=250000
uno_uf.bootloader.low_fuses=0xff
uno_uf.bootloader.high_fuses=0xde
uno_uf.bootloader.extended_fuses=0x05
uno_uf.bootloader.path=optiboot
uno_uf.bootloader.file=optiboot_atmega328_250000.hex
uno_uf.bootloader.unlock_bits=0x3F
uno_uf.bootloader.lock_bits=0x0F
uno_uf.build.mcu=atmega328p
uno_uf.build.f_cpu=16000000L
uno_uf.build.core=arduino
uno_uf.build.variant=standard

Change the two highlighted values to the baud rate you plan to use:    250000, 500000, or 1000000 Save and close the boards.txt file
Using your favourite ISP programmer, install the new bootloader. Don’t forget to: Ensure the Arduino Uno / Upload Fast board is selected (Tools / Board), If appropriate, ensure the Serial Port of
  your programmer is selected (Tools / Serial Port), Ensure the
  programmer is selected (Tools / Programmer), After installing the
  bootloader, change the Serial Port to the serial port of your Arduino
  Uno.

Above text slightly modified for compatibility with site. Original post

Besides that, and the ATmegaboot bootloader, you can't really find any alternative. I would imagine that if Arduino loads it on all the Unos ever produced, it's pretty optimized. The above hack speeds up upload time, but it doesn't reduce the size of the bootloader. You can also remove the wait time on the bootloader so it has a faster startup.
If you're that concerned about maximising flash see: How to really shrink a sketch and this answer [on on What can I do if I run out of Flash memory or SRAM?].


text:
Most power efficient way to constantly save 2 kilobytes of data per second
I would like to constantly save data coming from sensors (for an activity tracker) while consuming as less battery as possible (I'd like to have a 4/5 days autonomy on a 3000 mAh battery) but I can't find the best way to save about 2 kBytes/s on a memory large enough to contain several days of data.
Sensors would be read at a rate of 20 times per second and produce about 100 bytes each time.
What options do I have in order to:

store such an amount of data (hardware)?
ensure the system can work properly with required autonomy?

What options have you explored? Also, 2KB/s is a lot of data. Are you sure all of it is essential and there are no redundancies?

You need to clarify your needs further: what Arduino board do you use, what kinds of sensors are there, WHERETO do you need to save these 2KB/s? It is important to understand that no Arduino alone will have enough memory to store 2KB/s during days.

@jfp You could use a SD card...

Yes I know, that was actually the idea of my comment to ask that question! But is this an acceptable option for the OP, or would he want direct (e.g. wireless) transmission of data to some other device, e.g. a PC?

@AsheeshR Well, I calculated that all the data coming 20 times per second would be about that (2KB/s), well yes, it is, because since It will be some pretty hard to do activity recognition, the Arduino probably won't have such computation power, so I need to do that later, on a computer.

@jfpoilpret Right now I don't know exactly, because I need enough power to constantly read the data coming from the sensors at an high rate but I would to have a very low power consumption. Yes I know, that why I am asking your help... ;)

@AnnonomusPerson I thought to this option but I am wondering if the write speed will be high enough and we told me that it takes a lot of power.

An important question is related to your sensors, about which you mentioned nothing interesting so far: do they provide these 2KB/s in a continuous way of they act only once per second and produce 2KB everytime (or something in between)? That aspect is highly important in order to find out: the consumption of your circuit, the possibilities to use a low-power mode of the Arduino...

SD card is probably a good option (the only one?) for your storage needs; however, current consumption during write operations is totally dependent on each brand and model.

SD cards are all over the place with current consumption. 5mA whilst writing is the lowest I have seen, 100mA the highest, but the spec allows for 200mA. Typical is maybe 30-50mA. They use quite a lot of power when using the SPI interface.

I think it's critical to answer the question hinted at by jfpoilpret, which is:
What is the data you're storing? Is there any way to consume just the minimum amount of compute cycles on the Arduino in order to pack this data a bit more compactly. 2kB/s is a fair amount of data for a microcontroller to collect and send to storage.
And yes, for data logging, SD cards are pretty much the best option, if only for the fact that the card can be physically moved off to a computer for proper data analysis.

There are two constraints here, and I think it might back you into a corner. Size and then power.
2Kbyte/s is 2*60*60*24/1024 = 168.75Mbyte/day. This is a lot. The only readily available technology that can be used with a small microprocessor that can store this volume of data is an SD card. There are no serial EEPROM or flash chips this large, and the Arduino, as far as I know, can't deal with the NAND flash used in USB sticks and SD cards.
However, SD cards can be relatively power hungry. They draw between 5mA and 100mA when writing, typically around 30-50mA. The SD spec says the maximum is 200mA. Writing is also quite lengthy as they operate on blocks of data rather than individual cells. I've never done a full analysis of how much power they use, but it is not insignificant and much, much more than serial EEPROM or flash.
So your only choice, if you have to store that much, is to go with SD cards.
I would investigate compressing the data. Even very basic schemes can make a huge difference.

Thank you for your answer ! What do you think about saving the data on a small low power flash memory (like this one : http://www.adafruit.com/products/1564) and then, when this memory is full, saving it on the SD card ? Wouldn't it save power ?

Yes, there is potential to save power. It is much better to write to the SD card in large blocks because even if you change a single byte, it has to update the whole block. How big that block is, I don't recall.

Actually, I think that an Arduino probably can deal with a bare NAND flash (at least if few of the pins are already used, or one is willing to add an external latch for as a demultiplexer), but one would have to consult data sheets to see if the power consumption would be lower than a carefully selected SD card.

This would be possible with a standard SD card.
Capacity
Using some simple calculations, I was able to find that writing at 2kB/s for 5 days would only consume 0.8GB. You could probably get by with a 1 or 2 GB card.
Speed
I found this benchmark, which says it is possible to write SD card data from an Arduino at 192 kB/s, which should be more than enough for your needs.
There are a lot of great tutorials and examples out there for using an SD card with an Arduino. The official documentation is always a good place to start.


text:
3.3V, 5V and 9V pins on Arduino
On my Arduino Uno R3 and Arduino Mega R3, there are 5V and 3.3V pins.
However on this page Introduction to the Arduino Board, there is a 5V and 9V pin but no 3.3V pin. The page at Arduino: What Adapter? also mentions a 9V pin.
Why is there a discrepency?

You've just made the argument that the Arduino team needs to put a brightly colored disclaimer at the top of these older reference pages that refer people to the current revision of the hardware. This version of the Arduino is really, really old by Internet standards.

The link you provide looks rather old and I don't think it applies to UNO Revision 3 as it has more pins than on the diagram you show.
I suggest you rather take a look at this Arduino UNO link which contains uptodate information about the UNO; in there you will see that for R3, the "power rail" has been extended and has the following pins, left to right:

1 unlabeled pin (can't remember what it is)
1 IOREF pin (used by shields to know if they should operate as 3.3V or 5V devices)
3.3V regulated output
5V regulated output
2 GND pins
Vin pin: this pin can be used in 2 different ways:

either as a voltage supply input (instead of using the power plug or the USB); the input voltage should be in 7-12V range and will be regulated internally (by the board circuits) to 5V
or an output supply voltage (if you plugged voltage supply through the power plug or the USB plug) that is a "copy" of the voltage input through the power plug or USB plug (not regulated yet)

There are three power supply pins on the Arduino Uno and on the Mega:

5V - Labelled as 5V. Can be used to power other 5V devices.
3.3V - Labelled as 3.3V. Can be used to power other 3.3V devices.
Vin - This also referred to as the 9V pin that is shown in the schematic. This is used to power the Arduino board itself, usually using a 9V battery.

Note that the Vin is whatever the board gets, so it can be more or less than 9V as well, depending on how the board is hooked up itself. Also the 5V pin can be less than 5V if you underpower the Arduino board itself.


text:
I'm using too much RAM. How can this be measured?
I would like to know how much RAM I am using in my project, as far as I can tell, there's no way to actually work that out (other than going through and calculating it myself). I have got to a stage in a rather large project where I have determined that I am running out of RAM.
I have determined this because I can add a section and then all hell breaks loose somewhere else in my code for no apparent reason. If I #ifndef something else out, it works again. There is nothing programatically wrong with the new code.
I suspected for a while that I was getting to the end of available RAM. I don't think I'm using too much stack (although it's possible), what is the best way to determine how much RAM I am actually using?
Going through and trying to work it out, I have problems when I get to enums and structs; how much memory do they cost?
first edit: ALSO, I have edited my sketch so much since starting, these are not the actual results I initially got, but they are what I am getting now.
  text     data     bss     dec     hex filename
 17554      844     449   18847    499f HA15_20140317w.cpp.elf
 16316      694     409   17419    440b HA15_20140317w.cpp.elf
 17346      790     426   18562    4882 HA15_20140317w.cpp.elf

The first line (with text 17554) was not working, after much editing, the second line (with text 16316) is working as it should.
edit: the third line has everything working, serial reading, my new functions, etc. I essentially removed some global variables and duplicate code. I mention this because (as suspected) it's not about this code per sae, it has to be about the RAM usage. Which brings me back to the original question, "how to best measure it" I'm still checking out some answers, thanks.
How do I actually interpret the above information?
So far my understanding is:
`TEXT` is program instruction memory
`DATA` is variables (unitialised?) in program memory
`BSS`  is variables occupying RAM

since BSS is considerably less than 1024 bytes, why does the second work, but the first doesn't? If it's DATA+BSS then both occupy more than 1024.
re-edit: I edited the question to include the code, but now I've removed it because it really had nothing to do with the problem (other than maybe poor coding practices, variable declarations and the like). You can review the code by looking back through the edits if you really want to see it. I wanted to get back to the question at hand, which was more based around: How to measure RAM usage.

I thought I would add, I have added various new sections of code over the last few weeks, then optomised it until it works, but now I have only added half a doz byte vars and I'm done... :(

Do you use String type in your programs? This is known to perform frequent dynamic memory allocations and releases, which may fragment the heap to the point where you may no memroy left.

@jfpoilpret I stay away from Strings because of the overhead. I'm happy working with char arrays, that said, I almost always define all my char arrays with a fixed size (at the moment, I have ONE byte array that isn't purely because I change the content length for different recompiles.

Posting your code here (or to pastebin if it's too big) may hekp find out what problems you encounter with memory.

@jfpoilpret I can't really post the code, it's huge and unfortunately very bloated, spread over 16 files. It was a project that I was allowing to grow well beyond what was required (it is several projects merged together). I'm starting now to break it apart which I'm sure will help to fix the problem. Although there are some parts of it I need people to look at (or guide me on), I'll post those later.

maybe you could just post the section you've removed with #ifndef, that could guve us hints; another point: you've not mentioned what Arduino you use. A list of the libraries you use could be helpful as well. Finally, the output given by avrdude generally (works on Windows) includes the size of static data, that could help a lot.

While your question seems related to runtime memory consumption, you'd like to consider using 1.5.x series of the Arduino IDE: it reports the amount of "static" RAM used by the sketch (variable declarations), right after compilation. It won't be precise if your code uses malloc, but it's a start.

Yeah, ok, I'll edit shortly to include some code. I have made so many chops and changes since last night, removing and tweaking things and looking at avr-size and avr-objdump outputs. I'll put up the code that broke the camels back

I just thought I would add, I don't think there is anything intrinsically wrong with the code above, in fact, if I remove other segments of code, the above works as expected. In fact, that code itself ALWAYS works as expected. It BREAKS elsewhere in code (essentially it breaks serial communication being received).

Regarding your point about bss and data: data is initialized global data that initially resides in Flash and gets copied to SRAM at program start; bss is uninitialized global data that exists only in SRAM. Hence both are using SRAM altogether. What's left in SRAM is for the stack and the heap.

So does that mean used SRAM once underway, would equate to at least .bss PLUS .data? or is there some overlap?

That's a PLUS, there's no overlap (fortunately, would I add!)

You can use the functions provided AVRGCC: Monitoring Stack Usage
The function was intended to check the stack usage but what it reports is the actual RAM that has never been used (during execution). It does so by "painting" (filling) the RAM with a known value (0xC5), and then checking the RAM area counting how many bytes have still the same initial value.
The report will show the RAM that has not been used (minimum free RAM) and therefor you can calculate the max RAM that has been used (Total RAM - reported RAM).
There are two functions:

StackPaint is executed automatically during initialization and "paints" the RAM with the value 0xC5 (can be changed if needed).
StackCount can be called at any point to count the RAM that hasn't been used.

Here is an example of usage. Doesn't do much but is intended to show how to use the functions.
// -----------------------------------------------------------------------------
extern uint8_t _end;
extern uint8_t __stack;

void StackPaint(void) __attribute__ ((naked)) __attribute__ ((section (".init1")));

void StackPaint(void)
{
#if 0
    uint8_t *p = &_end;

    while(p <= &__stack)
    {
        *p = 0xc5;
        p++;
    }
#else
    __asm volatile ("    ldi r30,lo8(_end)\n"
                    "    ldi r31,hi8(_end)\n"
                    "    ldi r24,lo8(0xc5)\n" /* STACK_CANARY = 0xc5 */
                    "    ldi r25,hi8(__stack)\n"
                    "    rjmp .cmp\n"
                    ".loop:\n"
                    "    st Z+,r24\n"
                    ".cmp:\n"
                    "    cpi r30,lo8(__stack)\n"
                    "    cpc r31,r25\n"
                    "    brlo .loop\n"
                    "    breq .loop"::);
#endif
}

uint16_t StackCount(void)
{
    const uint8_t *p = &_end;
    uint16_t       c = 0;

    while(*p == 0xc5 && p <= &__stack)
    {
        p++;
        c++;
    }

    return c;
}

// -----------------------------------------------------------------------------

void setup() {

Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println(StackCount(), DEC);  // calls StackCount() to report the unused RAM
delay(1000);
}

interesting piece of code, thanks. I did use it, and it suggests there's 600+ bytes available, but when I bury that in the deeper subs it does reduce, but doesn't wipe out. So MAYBE my problem is elsewhere.

@Madivad Note that this 600+ bytes represents the minimum  available amount of RAM up to the point when you called the StackCount. It doesn't really make a difference how deep you place the call, if the majority of the code and nested calls have been executed before calling StackCount then the outcome will be correct. So for example you can leave your board working for a while (as long as it takes to get enough code coverage or ideally until you get the misbehavior you describe) and then push a button to get the reported RAM. If there is enough then it's not the cause of problem.

Thanks @alexan_e, I have created an area on my display that reports this now, so as I progress over the next few days I'll watch this number with interest, especially when it fails! Thanks again

@Madivad Please note that the given function will not report correct results if malloc() is used in the code

thanks for that, I am aware, it has been mentioned. As far as I'm aware, I'm not using it (I know that there may be a library using it, I haven't checked fully yet).

The main issues you can have with memory usage at runtime are:

no available memory in the heap for dynamic allocations (malloc or new)
no room left on the stack when calling a function

Both are actually the same as the AVR SRAM (2K on Arduino) is used for both (in addition to static data which size never changes during program execution).
Generally, dynamic memory allocation is seldom used on MCUs, only a few libraries typically use it (one of them is String class, which you mentioned you don't use, and that's a good point).
The stack and the heap can be seen in the picture below (courtesy of Adafruit):

Hence, the most expected issue comes from stack overflow (i.e. when the stack grows towards the heap and overflows on it, and then -if the heap was not used at all- overflows on the static data zone of the SRAM. At that time, you have a high risk of either:

data corruption (i.e. the stack ovewrites heap or static data), giving you ununderstandable behavior
stack corruption (i.e. the heap or static data overwrites stack content), generally leading to a crash

In order to know the amount of memory that's left between the top of the heap and the top of the stack (actually, we might call it the bottom if we represent both the heap and the stack on the same image as depicted below), you can use the following function:
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

In the code above, __brkval points to the top of the heap but is 0 when the heap has not been used, in which case we use &__heap_start which points to __heap_start, the first variable that marks the bottom of the heap; &v points of course to the top of the stack (this is the last variable pushed on the stack), hence the formula above returns the amount of memory available for the stack (or the heap if you use it) to grow.
You can use this function in various locations of your code to try and find out where this size is getting dramatically reduced.
Of course, if ever you see this function return a negative number then it is too late: you have already overflown the stack!

To moderators: sorry for putting this post to community wiki, I must have made somthing wrong while typing, in the middle of the post. Please put it back here as this action was unintentional. Thanks.

thanks for this answer, I literally only JUST found that piece of code barely an hour ago (at the bottom of http://playground.arduino.cc/Code/AvailableMemory#.UycOrueSxfg ). I haven't included it yet (but I will) since I have quite a large area for debugging on my display. I think I've been confused about dynamically assigning stuff. Is malloc and new the only way I can do that? If so, then I have nothing dynamic. Also, I've just learned the UNO has 2K of SRAM. I thought it was 1K. Taking these into consideration, I'm not running out of RAM! I need to look elsewhere.

In addition, there is also calloc. But you may be using 3rd party libs that use dynamic allocation without you knowing (you'd have to check source code of all your dependencies to be sure about it)

Interesting. The only "problem" is that it reports the free RAM at the point where it's called, so unless it's placed in the right part you may not notice a stack overrun. The function I have provided seems to have an advantage in that area since it report the min free RAM up to that point, once a RAM address has been used, it's not reported free any longer (on the down side there may be some occupied RAM bytes that match the "paint" value and are reported as free). Apart from that maybe one way suits better than the other depending on what a user wants.

Good point! I had not noticed this specific point in your answer (and for me that looked like a bug in fact), now I see the point of "painting" the free zone upfront. Maybe you could make this point more explicit in your answer?

I wonder if the Serial.print() functions would still work after your 'freeRam()' function because it might not be too late.  Maybe you could have an ISR call freeRam() and if it is negative write a message out to the Serial monitor. What I don't know is whether you could also report on the sizes of the heap or stack.

It is not advised to use Serial from an ISR. The issue when freeRam() returns a negative value, is that the stack has already overflown over the heap (or the opposite), meaning that some data has been modified unexpectedly. if this is the heap overflowing the stack, it is likely to become an imminent crash. In the opposite, you may not have a crash but some potentially important data would have been destroyed.

When you figure out how to locate the generated .elf file in your temporary directory, you can execute the command below to dump a SRAM usage, where project.elf is to be replaced with the generated .elf file. The advantage of this output is the ability to inspect how your SRAM is used. Do all the variables need to be global, are they really all required?
avr-objdump -S -j .bss project.elf

project.elf:     file format elf32-avr

Disassembly of section .bss:

00800060 <__bss_start>:
        ...

00800070 <measurementReady>:
        ...

00800071 <cycles>:
        ...

00800073 <measurement>:
  800073:       00 00 00 00                                         ....

00800077 <measurementStart>:
  800077:       00 00 00 00                                         ....

0080007b <timerOverflows>:
  80007b:       00 00 00 00

Notice that this doesn't show stack or dynamic memory use as Ignacio Vazquez-Abrams noted in the comments below.
Additionally a avr-objdump -S -j .data project.elf can be checked, but none of my programs output anything with that so I can't tell for sure if it is useful. It supposed to list 'initialized (non-zero) data'.

Or you could just use avr-size. But that won't show you dynamic allocations or stack usage.

@IgnacioVazquez-Abrams about the dynamics, same for my solution. Edited my answer.

Ok, this is the most interesting answer so far. I've experimented with avr-objdump and avr-size and I'll edit my post above shortly. Thanks for this.

I suspected for a while that I was getting to the end of available RAM. I don't think I'm using too much stack (although it's possible), what is the best way to determine how much RAM I am actually using?

It would be best to use a combination of manual estimation and by using the sizeof operator. If all your declarations are static, then this should give you an accurate picture.
If you are using dynamic allocations, then you may run into a problem once you start deallocating the memory. This is due to memory fragmentation on the heap.

Going through and trying to work it out, I have problems when I get to enums and structs; how much memory do they cost?

An enum takes as much space as an int. So, if you have a set of 10 elements in a enum declaration, that would be 10*sizeof(int). Also, every variable that uses an enumeration is simply an int.
For structures, it would be easiest to use sizeof to find out. Structures occupy a (minimum) space equal to sum of its members. If the compiler does structure alignment, then it may be more, however this is unlikely in the case of avr-gcc.

I do statically assign everything as far as I can. I never thought of using sizeof for this purpose. At the moment, I have almost 400 bytes already accounted for (globally). Now I'll go through and calculate the enums (manually) and the structs (of which I have a few—and I'll use sizeof), and report back.

Not sure you really need sizeof to know the size of your static data as this gets printed by avrdude IIRC.

@jfpoilpret That is version dependent, I think. Not all versions and platforms provide that. Mine (Linux, multiple versions) don't show memory use for one, while Mac versions do.

I have searched the verbose output, I thought it should be there, it isn't

@AsheeshR I was not aware of that, mine works fine on Windows.

There is a program called Arduino Builder that provides a neat visualization of the amount of flash, SRAM and EEPROM your program is using.

The Arduino builder makes up part of the CodeBlocks Arduino IDE solution. It can be used as either a standalone program or through the CodeBlocks Arduino IDE.
Unfortunately Arduino Builder is a little old but it should work for most programs and most Arduinos, such as the Uno.


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:
Unrecognizable Message From PROGMEM char*
I'm using a PROGMEM char* to store a massive array. When I try to print a certain part of the array, the message comes out mangled. How do I fix this?
The output should be "Poliwag", but it comes out as "arow".
#include <TrueRandom.h>
#include <EEPROM.h>
#define numPokemon 151
PROGMEM char* 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 = "Missingno";
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");
  }
  pokemonName = nameArray[currentID];
  Serial.println(pokemonName);
}
void loop(){

}

The way you've written in, the pointer is stored in flash, but the strings are stored in SRAM. Read the appropriate documentation (also found in the Arduino reference) more closely, and do as it says.
char nmPokemon0[] PROGMEM = "MISSINGNO";
char nmPokemon1[] PROGMEM = "Bulbasaur";
 ...

PGM_P nameArray[] PROGMEM =
{
  nmPokemon0, nmPokemon1, ...
};

And don't forget to copy the string to SRAM as shown further down before outputting it, since Serial.println() can't work directly with flash.

http://arduino.cc/en/Reference/PROGMEM has all of this info.


text:
PROGMEM char* mangled text
I wrote a program using PROGMEM for massive string arrays. One of the arrays worked, but when I added the second one, the serial output only puts out "th".
Pastebin Code: http://pastebin.com/9U7QZQKn

Perhaps the PROGMEM tag should be removed? The problem seems to be unrelated to PROGMEM.

Also, the essential parts of the code ought to be included here, e.g., in a reduced form (MRE). A similar comment.

Your declaration of char buffers is done like so:
char* move1 = "N/A";

This will only allocate 3 characters with an additional one for null termination i.e. not long enough to hold the name.
You need to do:
char buffer[16];

Where the length is long enough to hold your string.

According to C++ reference on string literals (and C is the same in this topic), "N/A" will allocate 4 characters, the last one being 0: http://en.cppreference.com/w/cpp/language/string_literal

Yes, forgot the termination. For the purposes of the problem though, there are still only 3 characters that you can use, and the code not working is still going to be cause be the same thing.

Ok, I see your point now, granted. Maybe you should copy the line with strcpy to better show where the problem resides, that would make youranswer clearer at first read.

Agree will edit at PC later;

I see one major flaw in your code, related to index usage on arrays.
Arrays in C and C++ are using a 0-based index, meaning that, for an array containing N elements:

the first element is accessible with index 0
the last element is accessible with index (N-1)

However, your code uses TrueRandom.random(1,numPokemon+1); which means you'll get an index between 1 and numPokemon (included), if you get the numPokemon value for your index, then you'll get garbage as it will try access some other part of memory.
Maybe that is not the only problem in your code, but this one is a major bug.