text:
Adafruit gps breakout module help
I am intending to show the initial, searching for signal..., screen until the location is updated and then show the location on the lcd. However, even after the led on the gps indicates a satellite fix, the screen never leaves the searching for signal screen. Any help would be greatly appreciated-- very new to microcontroller programming. Sorry for the poorly formatted code block as well, I am in a rush.
Thanks in advance.
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <TinyGPS++.h>

#define RXPin 2
#define TXPin 3
#define GPSBaud 4800

SoftwareSerial ss(RXPin, TXPin);
TinyGPSPlus gps;
LiquidCrystal lcd(12, 11, 10, 7, 6, 5, 4);

double latt;
double lon;
int screen;

void setup(void);
void loop(void);
void readGPS(void);
void update(void);
void render(void);

void setup() {
     //variable initialization
     latt = 0.0;
     lon = 0.0;
     screen = 0;

     //lcd initial setup
     pinMode(9, OUTPUT);
     analogWrite(9, 100);
     pinMode(13, OUTPUT);
     digitalWrite(13, HIGH);

     //display intial screen
     lcd.begin(16,2);
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("Searching for");
     lcd.setCursor(6,2);
     lcd.print("Signal ...");
     ss.begin(GPSBaud);
}

void loop() {
    readGPS();
    update();
}

/** Receives data from the gps if available */
void readGPS() {
    while (ss.available() > 0) {
        gps.encode(ss.read());
    }
}

/** Processes the data read by readGPS() */
void update() {
    if (gps.location.isUpdated()) {
        latt = gps.location.lat();
        lon = gps.location.lng();
        render();
    }
}

/** Displays the current screen on the lcd */
void render() {
    if (screen == 0) {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Lat:");
        lcd.print(latt);
        lcd.print(" Lng:");
        lcd.print(lon);
        lcd.setCursor(0,1);
        lcd.print("Sats:");
        lcd.print(gps.satellites.value());
    }
}

Does this also happen when the Arduino is NOT connected to the computer? I've had problems with LCD displays when I leave the Arduino connected. I have to disconnect from the PC and then the display comes to life.

Have you tried this outside? A GPS can get a partial lock (I frequently get time/date signals without location signals) which would cause the lock light to turn on, but you wouldn't be receiving latitude and longitude yet. If you can I would output the GPS string to Serial as well and keep an eye on it to see if you are getting lat/long data or if that part is missing.

Adafruit GPS breakout has their own library setup.
Below is the code I use for my telemetry. Notice I'm using HardwareSerial though.
You can just change that into SoftwareSerial.
#include <SoftwareSerial.h>
#include <Adafruit_GPS.h>
#define GPSECHO false // Disables GPS breakout debug

boolean usingInterrupt = false;

HardwareSerial gpsSerial = Serial1;
Adafruit_GPS GPS(&Serial1);

SoftwareSerial XBee(2, 3); // For wireless

unsigned int REFRESH = 20;

double lat_deg, lon_deg, lat_min, lon_min;
char lat, lon;

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

  GPS.begin(115200);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ); // Either 1HZ or 5HZ
  GPS.sendCommand(PMTK_API_SET_FIX_CTL_5HZ);
  GPS.sendCommand(PGCMD_ANTENNA);

  useInterrupt(true);
}

SIGNAL(TIMER0_COMPA_vect)
{
  char c = GPS.read();
#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;
#endif
}

void useInterrupt(boolean v)
{
  if(v)
  {
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  }
  else
  {
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

void loop()
{
  if(GPS.newNMEAreceived())
  {
    if(!GPS.parse(GPS.lastNMEA()))
    {
      writeData(1, true);
      Serial.print(GPS.hour, DEC); Serial.print(F(","));
      Serial.print(GPS.minute, DEC); Serial.print(F(","));
      Serial.print(GPS.seconds, DEC); Serial.print(F(","));
      Serial.print((int)GPS.fix); Serial.print(F(","));
      Serial.print((int)GPS.fixquality); Serial.print(F(","));
      Serial.print(F("-999")); Serial.print(F(","));
      Serial.print(F("-999")); Serial.print(F(","));
      Serial.print(F("-999")); Serial.print(F(","));
      Serial.print(F("-999")); Serial.print(F(","));
      Serial.print(F("-999")); Serial.print(F(","));
      Serial.print(F("-999"));
    }
    else if(GPS.fix)
    {
      writeData(1, true);
      parseGPS(GPS.latitude, GPS.longitude);
      Serial.print(GPS.hour, DEC); Serial.print(F(","));
      Serial.print(GPS.minute, DEC); Serial.print(F(","));
      Serial.print(GPS.seconds, DEC); Serial.print(F(","));
      Serial.print((int)GPS.fix); Serial.print(F(","));
      Serial.print((int)GPS.fixquality); Serial.print(F(","));
      Serial.print(lat_dd, 8); Serial.print(F(","));
      Serial.print(lon_dd, 8); Serial.print(F(","));
      Serial.print(GPS.speed); Serial.print(F(","));
      Serial.print(GPS.angle); Serial.print(F(","));
      Serial.print(GPS.altitude); Serial.print(F(","));
      Serial.print(GPS.satellites);
    }
  }
  delay(REFRESH);
}

void parseGPS(float _latitude, float _longitude)
{
  lat_deg = (int) (_latitude / 100);
  lon_deg = (int) (_longitude / 100);

  lat_min = _latitude - (lat_deg * 100);
  lon_min = _longitude - (lon_deg * 100);

  lat_dd = (double) lat_deg + ((double) lat_min / 60);
  lon_dd = (double) lon_deg + ((double) lon_min / 60);

  lat = GPS.lat; lon = GPS.lon;

  if (lat == 'S') lat_dd = -lat_dd;
  if (lon == 'W') lon_dd = -lon_dd;
}

void writeData(float data, boolean next)
{
  Serial.print(data);
  if (next) Serial.print(F(","));
}


text:
How to prepare data structures and classes?
How can I port these structures to arduino ide, I also get error when I define pointers
// pointer to classes example
#include <iostream>
using namespace std;

class Rectangle {
  int width, height;
public:
  Rectangle(int x, int y) : width(x), height(y) {}
  int area(void) { return width * height; }
};

int main() {
  Rectangle obj (3, 4);
  Rectangle * foo, * bar, * baz;
  foo = &obj;
  bar = new Rectangle (5, 6);
  baz = new Rectangle[2] { {2,5}, {3,6} };
  cout << "obj's area: " << obj.area() << '\n';
  cout << "*foo's area: " << foo->area() << '\n';
  cout << "*bar's area: " << bar->area() << '\n';
  cout << "baz[0]'s area:" << baz[0].area() << '\n';
  cout << "baz[1]'s area:" << baz[1].area() << '\n';
  delete bar;
  delete[] baz;
  return 0;
}

In CPP shell it works
I try to put it like this
class Rectangle {
  int width, height;
public:
  Rectangle(int x, int y) : width(x), height(y) {}
  int area(void) { return width * height; }
};

  Rectangle obj (3, 4);
  Rectangle * foo, * bar, * baz;
  foo = &obj;
  bar = new Rectangle (5, 6);
  baz = new Rectangle[2] { {2,5}, {3,6} };

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

I get an error
sketch_nov27a.ino:10:3: error: 'foo' does not name a type
sketch_nov27a.ino:11:3: error: 'bar' does not name a type
sketch_nov27a.ino:12:3: error: 'baz' does not name a type
Error compiling.

Should I lough or cry?

The problem is that the lines saying foo = ... etc. are assignment operations. C++ lets you declare and immediately initialise variables at global scope, but after that you can only assign to them inside a function. In your original program, all your declarations/assignments were inside main(), which is why it worked there.
For your Arduino program, you could change the assignments to initialisations instead (in global scope):
Rectangle obj (3, 4);
Rectangle * foo = &obj;
Rectangle * bar = new Rectangle (5, 6);
Rectangle * baz = new Rectangle[2] { {2,5}, {3,6} };

Alternatively, you could leave the declarations in global scope and move the assignments into setup():
Rectangle obj (3, 4);
Rectangle * foo, * bar, * baz;

void setup() {
    foo = &obj;
    bar = new Rectangle (5, 6);
    baz = new Rectangle[2] { {2,5}, {3,6} };
}

You put a bunch of code in a place where you can't have it. Move the assignments into a function body.

source: Stack Exchange

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

sort: votes


text:
Linking one circuit to two Arduinos
I don't actually have to achieve this, it's more of an attempt to see what the best way to do this is. I'm sure the answer also differs depending on what circuitry you're trying to connect.
In this case, I plan on an Arduino (probably a Pro Mini or similar) that will control some RGB LEDs (via the WS2811 chip). If I wanted to add a second Arduino that would drive the LEDs if the first one failed (obviously very unlikely), I was wondering how I would do it. The WS2811 chip takes 5V, GND and data in.
My best attempt at a solution is using 3 relays which are SPDT. Connect the LEDs to the main Arduino via the normally open, which is controlled by that particular Arduino, and connect the LEDs to the backup Arduino via the normally closed, which is held open by the main Arduino. In the event of a failure, the main Arduino would lose connection to the LEDs while the backup would make a connection.
This probably isn't a very safe way of doing it (especially if the relay failed for example). Is there a way to do this?
The two Arduinos will be powered from two separate laptops.

You are also assuming that the Arduino pin will go LOW if it fails. Also, what if it fails because of a faulty power supply. Then after the power supply takes down the first arduino, it would then take out the second. I'd rather invest time in making the setup and software more robust. E.g. enabling the WatchDog-timer inside the Arduino.

And is there a particular reason you think the relay will be more reliable than the Arduino? You still have a single point of failure, and now it's a device with moving parts.

You first need to make a communication between both Arduinos and then you can control RGB led from any Arduino.
For the connection between both the Arduinos, you can make a serial port interface for doing this, you just need softwareserial.h library. Then you just need to connect the RGB LED to one Arduino. Then when you send a command from another Arduino to that one, the Arduino (Connected to RGB LED) can operate the LED according to the command.

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


text:
Intercept Data being sent to XBee Module via UNO
An XBee Pro S1 module sits on a DIP socket on-board a Personal Weather Station (PWS) to transmit data.
Instead of letting the station transmit data wirelessly via the XBee, I would like to read that data off the socket pins on which it sits, via an Arduino UNO.
Is this possible? If so, what should I look into?
I am new to wireless communication with a µC, so any help would be appreciated.

If i am getting you right, try connecting the tx pin of Xbee with the rx of UNO and then read the data coming in to the serial UART.

@AnumSheraz: thanks for that. I tried but Arduino did not pick up any data off pins 2 & 3 of the XBee socket (Tx & Rx pins). I'm guessing the settings (baud rate, parity, etc.) need to be known first before any meaningful data can be captured.


text:
Hardware Interrupt Triggered Randomly
So there is this pretty generic part of my project that involves triggering an ISR that will flip a boolean value. I have set up the software side like so:
void setup() {
  attachInterrupt(digitalPinToInterrupt(2), displayConvergence, FALLING);
}

void loop() {
  if(flashConvergence) {
    //Do stuff that takes several seconds
    delay(3000);
    flashConvergence = false;
  }
}

void displayConvergence() {
  if (!flashConvergence) {
    flashConvergence = true;
  }
}

The schematic is as follows:

simulate this circuit – Schematic created using CircuitLab
But the behavior of my circuit surprised me as the pin interrupt would get triggered randomly at a frequency at (guessing here) 3 times a second.
Weird, I thought. I fiddled around and found that when the boost converter's 180V is not connected to any load, the interrupt service triggers as expected, as in it starts working correctly. So I thought perhaps the issue was some noise introduced by the boost converter.
I modified the circuit by adding a capacitor across the switch:

simulate this circuit
I tried 1 uF at first, but that didn't help and neither did 10 uF. However, when I tried 100 uF (I thought decoupling capacitors are usually 0.1uF to 1 uF, is the value I am using too big?), things seem to be working as expected with the exception that when I hold the switch in the closed position for a long time, then let it go back in the open position, the interrupt service can be triggered randomly for a short period right after I let go of the switch.
Is my initial assumption that the ISR is triggering randomly due to EMI from the boost converter correct? Perhaps there are other causes I am not looking at? Is there a way to make this work 100% (as in solve the issue right after the switch is put in the open position)?
Thanks for the help!

You could try; lowering the pull-up resistor. Moving the button away from the boost converter and it's wires. Move the pull-up nearer  to pin 2. Use a pull-down system (by swapping R1 and SW1), instead of pull-up. PS the capacitor isn't used for decoupling here, but as a low-pass-filter.

Why would a pull-down system have more noise immunity than a pull-up system?

I'm not sure if it would, but might be worth a try.

Buck-Boost converters are pretty noisy. If the interrupt is triggered randomly without you even touching the switch, that means some noise is definitely causing the issue. If you have an oscilloscope you can hook it up to D2 to see what is happening. Try adding a 100uF and a 0.1uF cap on the 5V before it connects to the Arduino circuit.

I think if you only want to flip a value of a Boolean try using this only in the ISR "flashConvergence = !flashConvergence;" it will save a ton of space and is less complicated.

It has come to my attention I never posted a followup to this but I was actually able to solve this problem by shielding the wire going from the switch to the arduino. The switch's wire was about 2 to 3 inches long and I wrapped aluminum foil around it, which shielded the signal from what I suspected was EMI induced by the switching converters.

If you don't have any bulk capacitance (100uF or so) on your logic supply you will have noise problems.  You should also use some smaller (1uF and 0.1uF) to provide bypass for higher frequency noise in the power supply system.
Glenn

An alternative approach is to detach the interrupt handler and use the internal pullup instead of external resistor (and capacitor).
const int BUTTON = 2;
volatile bool flashConverage = false;

void setup()
{
  setmode(BUTTON, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(BUTTON), displayConvergence, FALLING);
}

void loop()
{
  if (!flashConvergence) return;

  // Do stuff that takes several seconds
  delay(3000);
  flashConvergence = false;
  attachInterrupt(digitalPinToInterrupt(BUTTON), displayConvergence, FALLING);
}

void displayConvergence()
{
  detachInterrupt(digitalPinToInterrupt(BUTTON));
  flashConvergence = true;
}

The processing ("stuff that takes several seconds") will debounce the button (or at least ignore it :).
Cheers!

The problem isn't (only) switch bounce. It's false triggers. This code won't help with that.

Well we have provided a few solutions to test. I do agree that the noise from the Converter might be the issue. Moving the 100 uF capacitor to filter noise on the power (5V) might also help.

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


text:
SIM300cz AT command returns -1
I connected SIM300cz module's GSM board with Arduino Mega. The GSM board has the pins VCC, GND, RXD, TXD, GND, RI, DTR, STATUS, PWKEY and GND. I connected the GNDs with Arduino's GND, VCC to Arduinos 5V (took power from Arduino), RXD to pin 5, TXD to pin 6 (because of using software serial) and PWKEY to pin 53. My code is as follows:
#include<SoftwareSerial.h>
SoftwareSerial GPRS(5, 6);

int inputPinTempSensor = 0;
float tempCelsius = 0 ;
float thresholdTemp = 45;

void setup()
{
  GPRS.begin(9600);               // the GPRS baud rate
  Serial.begin(9600);  // the Serial port of Arduino baud rate.
  pinMode(53, OUTPUT);
  digitalWrite(53, HIGH);
  delay(100);
}

void loop() {
  GPRS.print("AT+CREG/r");
  Serial.print(GPRS.read());
  delay(2000);
}

The AT command response should be something like "ok" but it's returning -1 for every loop waiting 2 seconds. Why and what could be the solution?
Edit:
Sorry for the mistakes. I was trying different ways with carriage return and new line characters to make it work. Now the code is:
#include<SoftwareSerial.h>
SoftwareSerial GPRS(5, 6);

void setup()
{
  GPRS.begin(9600);               // the GPRS baud rate
  Serial.begin(9600);  // the Serial port of Arduino baud rate.
  pinMode(53, OUTPUT);
  digitalWrite(53, HIGH);
  delay(2000);
  GPRS.println("AT+CREG");
}

void loop() {
  while(GPRS.available()){
    Serial.print(GPRS.read());
  }
}

Now it gives no responses at all. Actually after buying the module I was trying with these examples and they were not working either. So, I thought to test if the AT commands were working properly. I could be a problem with my wiring too.

Did you wire DTR to GND?

Yes, I tried with both keeping it opened and by adding to GND.

BTW, pin 53 is to pull up PWKEY. It's connected to PWKEY.

The correct AT command is AT+CREG?\r. A delay of at least 500ms is also advised after every command, though a timeout loop would be better. Since you didn't send any other commands, the modem will have no further responses for you and the Arduino will return -1 to any Serial.read()s, indicating there's nothing to be read.

I think there are 2 mistakes in your code:
First, you should ensure that the 3AT3 commands are termintaed by a new line character:
GPRS.print("AT+CREG/r");

should be changed into:
GPRS.println("AT+CREG/r");

or:
GPRS.print("AT+CREG/r\n");

Nite that I am not sure why you added /r at the end of the AT command, is that supposed to be part of the command? If your intention was to force a new line, then you meant \r not /r, which is not really a new line character but a carriage return (that might be interpreted the same by yur GSM module, but not necessarily).
The the second mistake in your code, is directly calling GPRS.read() without first waiting for a character to be available; in this situation, GPRS.read() will always return -1 as a specific value meaning "no available character to read".
So you should change your code to something like:
// 1st wait for a character to be available
while (!GPRS.available()) {
}
// Then read all available characters and log them to Serial
while (GPRS.available()) {
    Serial.print(GPRS.read());
}

Thanks a lot for your answer. I edited my question. I still have problems.

Note that GPRS.read() will return  -1  if the input buffer is empty.


text:
Controlling image display on LED matrix by buttons
Building a 9x9 LED matrix and facing following 2 problems in Arduino code,
The current code displays 2 images (using byte arrays and then using bitRead) one by one, each for a certain duration of seconds. Persistence of vision is obtained by a delay of 300ms. There is a subroutine called upon in the main loop function with arguments of desired byte array and duration. I want to control the images by using 2 push buttons (push button1 and it displays 1st image until button2 is pressed, push button2 and second image is displayed until button1 is pressed). But the scanning algorithm exits the scan routine upon completion of the given input duration and restarts the routine with new argument (byte array of image2). I WANT THE IMAGE TO BE RETAINED ON THE MATRIX UNTIL BUTTON IS PRESSED. Can't figure out how to accomplish this.
If i nest the routine in a DO WHILE loop, then my problem is that how will the buttons be read from the main loop? Because I believe as long as the subroutine is being executed, main loop will be halted. (or I am totally wrong in this assumption?)
Reference code which I intend to manipulate. (Here its for an 8x8 Matrix. Thats not an issue)
byte bigHeart[] = {
    B01100110,
    B11111111,
    B11111111,
    B11111111,
    B01111110,
    B00111100,
    B00011000,
    B00000000};

byte smallHeart[] = {
    B00000000,
    B00000000,
    B00010100,
    B00111110,
    B00111110,
    B00011100,
    B00001000,
    B00000000};

const int columnPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};
const int rowPins[] = { 10,11,12,15,16,17,18,19};

void setup() {
    for (int i = 0; i < 8; i++)
    {
        pinMode(rowPins[i], OUTPUT); // make all the LED pins outputs
        pinMode(columnPins[i], OUTPUT);
        digitalWrite(columnPins[i], HIGH); // disconnect column pins from Ground
    }
}

void loop() {
    int pulseDelay = 800 ; // milliseconds to wait between beats
    show(smallHeart, 80); // show the small heart image for 100 ms
    show(bigHeart, 160); // followed by the big heart for 200ms
    delay(pulseDelay); // show nothing between beats
}

// routine to show a frame of an image stored in the array pointed to by the
// image parameter.
// the frame is repeated for the given duration in milliseconds
void show( byte * image, unsigned long duration)
{
    unsigned long start = millis(); // begin timing the animation
    while (start + duration > millis()) // loop until the duration period has passed
    {
        for(int row = 0; row < 8; row++)
        {
            digitalWrite(rowPins[row], HIGH); // connect row to +5 volts
            for(int column = 0; column < 8; column++)
            {
                boolean pixel = bitRead(image[row],column);
                if(pixel == 1)
                {
                    digitalWrite(columnPins[column], LOW); // connect column to Gnd
                }
                delayMicroseconds(300); // a small delay for each LED
                digitalWrite(columnPins[column], HIGH); // disconnect column from Gnd
            }

            digitalWrite(rowPins[row], LOW); // disconnect LEDs
        }
    }
}

Why don't you show the code rather than trying to explain it? That would make it easier for others to help you!

Place the button tests inside the Do...WHILE Loops

Code added @jfpoilpret

@RussellMcMahon I am using a push button. And i dont want to keep the button pressed to display its associated image. Just one time push and leave.

OK. Figured out a solution which is working for me. Upon reading a forum on Arduino.cc. That stated a nice analogy to handle this issue.
You have something to heat up on stove while also waiting for an important email which you have to respond to immediately. (You only have a PC in the farthest corner of house at which you have to monitor your outlook :D) How will you do both tasks simultaneously? Run the stove for 10seconds, go to PC to check email, return to stove, run it again for 10 seconds, then again go to PC to check email. Do this until you get the email or your food gets hot enough.
To implement this in our program. I read the states of 2 buttons at start of the main loop. Store their values in 2 variables. Then check the values to check if some button is pressed. if value A is 1 and B is 0, call function A, if A is 0 and B is 1 call function B. The called function comprises of the scan routine. So when called, it performs 1 scan and comes back to the main loop. If no button was pressed meanwhile, the variables have same values, so the same function is called again and it performs the 2nd scan. if a button was pressed meanwhile, then 2nd function is called instead of the 1st one. The speed of all this is enough so that the user does not experience any delays, neither Arduino misses a button pressed while executing the scan.
The LEDs started to flicker when I implemented this code. So I further reduced the delay in the scan routine (time for which each LED is lit before turning it off and lighting the next one) from 300 microsecond to 100 and all went fine. My matrix of 64 LEDs is working fine however I assume that if matrix goes beyond some 100 LEDs then problems like delay or flickering or reduced brightness may arise.
Here is the complete code
byte img1[] = {
    B01100110,
    B11111111,
    B11111111,
    B11111111,
    B01111110,
    B00111100,
    B00011000,
    B00000000
};

byte img2[] = {
    B00000000,
    B01100110,
    B01100110,
    B00000000,
    B00011000,
    B10000001,
    B01000010,
    B00111100
};

const int rowPins[] = {13,12,11,10,9,8,7,6};
const int columnPins[] = {5,4,3,2,14,15,16,17};

const int but1 = 18;
const int but2 = 19;

int but1State = 0;
int but2State = 0;
int but1Now;
int but2Now;

int value1;
int value2;

void setup() {

    for (int i = 0; i<8; i++){
        pinMode(rowPins[i], OUTPUT);
        pinMode(columnPins[i], OUTPUT);
        digitalWrite(columnPins[i], HIGH);
    }

    pinMode(but1, INPUT);
    pinMode(but2, INPUT);

    but1State = digitalRead(but1);
    but2State = digitalRead(but2);
}

void loop() {

    but1Now = digitalRead(but1);
    delay(5);
    int but1Now1 = digitalRead(but1);

    if(but1Now == but1Now1)
    {
        if(but1Now != but1State)
        {
            value1 = 1;
            value2 = 0;
            //show(img2);
        }

        but1State = but1Now;
    }

    but2Now = digitalRead(but2);
    delay(5);
    int but2Now1 = digitalRead(but2);

    if(but2Now == but2Now1)
    {
        if(but2Now != but2State)
        {
            value1 = 0;
            value2 = 1;
            //show(img2);
        }

        but2State = but2Now;
    }

    if(value1 == 1)
    {
        show(img1);
    }

    if(value2 == 1)
    {
        show(img2);
    }
}

void show(byte*image) {

    for(int row = 0; row<8; row++)
    {
        digitalWrite(rowPins[row], HIGH);

        for(int col=0; col<8; col++)
        {
            boolean pixel = bitRead(image[row],col);

            if(pixel == 1)
            {
                digitalWrite(columnPins[col], LOW);
            }

            delayMicroseconds(150);
            digitalWrite(columnPins[col], HIGH);
        }

        digitalWrite(rowPins[row], LOW);
    }
}

Please, PLEASE format your code.

But that's not what you actually do, is it? You turn on the audio notificaiton so you don't have to constantly check if the email is there, you get notified when it is. Same with the stove. You set a timer and you let it work until the timer goes off. See what I'm getting at?


text:
Arduino on ubuntu 14.4 gives "Broken pipe" and "Input/output error"
Im using arduino (R2) uno board and my pc is running 64bit ubuntu 14.4.
I was previously using arduino on ubuntu 10.04 for a long time and got no error. I recently moved to 14.4 from 10.4.
I installed arduino using this command
$ sudo apt-get update && sudo apt-get install arduino arduino-core

later arduino appeared, but was not working. According to this link, i was able to launch the IDE on mouse click. I then tried to upload servo examples, i get following errors.
Binary sketch size: 1,056 bytes (of a 32,256 byte maximum)
ioctl("TIOCMSET"): Broken pipe
ioctl("TIOCMGET"): Input/output error

I get the same error for even an Led blinking program too.
Update 1: (after Edgar's comment)
on terminal i get
~$ /usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/Servo /tmp/build4933543797518254688.tmp/Sweep.cpp -o /tmp/build4933543797518254688.tmp/Sweep.cpp.o
avr-g++: error: /tmp/build4933543797518254688.tmp/Sweep.cpp: No such file or directory
avr-g++: fatal error: no input files
compilation terminated.

But on the IDE, after enabling verbos i get
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/Servo /tmp/build4933543797518254688.tmp/Sweep.cpp -o /tmp/build4933543797518254688.tmp/Sweep.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/Servo -I/usr/share/arduino/libraries/Servo/utility /usr/share/arduino/libraries/Servo/Servo.cpp -o /tmp/build4933543797518254688.tmp/Servo/Servo.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/wiring_analog.c -o /tmp/build4933543797518254688.tmp/wiring_analog.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/avr-libc/malloc.c -o /tmp/build4933543797518254688.tmp/malloc.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/avr-libc/realloc.c -o /tmp/build4933543797518254688.tmp/realloc.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/wiring_digital.c -o /tmp/build4933543797518254688.tmp/wiring_digital.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/wiring_pulse.c -o /tmp/build4933543797518254688.tmp/wiring_pulse.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/wiring.c -o /tmp/build4933543797518254688.tmp/wiring.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/wiring_shift.c -o /tmp/build4933543797518254688.tmp/wiring_shift.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/WInterrupts.c -o /tmp/build4933543797518254688.tmp/WInterrupts.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/Stream.cpp -o /tmp/build4933543797518254688.tmp/Stream.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/HID.cpp -o /tmp/build4933543797518254688.tmp/HID.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/Print.cpp -o /tmp/build4933543797518254688.tmp/Print.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/WMath.cpp -o /tmp/build4933543797518254688.tmp/WMath.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/CDC.cpp -o /tmp/build4933543797518254688.tmp/CDC.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/new.cpp -o /tmp/build4933543797518254688.tmp/new.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp -o /tmp/build4933543797518254688.tmp/HardwareSerial.cpp.o
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp: In function ‘void store_char(unsigned char, ring_buffer*)’:
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:100:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i != buffer->tail) {
                    ^
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp: In function ‘void __vector_18()’:
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:129:21: warning: unused variable ‘c’ [-Wunused-variable]
       unsigned char c = UDR0;
                     ^
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp: In member function ‘void HardwareSerial::begin(long unsigned int, byte)’:
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:370:11: warning: unused variable ‘current_config’ [-Wunused-variable]
   uint8_t current_config;
           ^
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp: In member function ‘virtual size_t HardwareSerial::write(uint8_t)’:
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp:469:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (i == _tx_buffer->tail)
                           ^
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/main.cpp -o /tmp/build4933543797518254688.tmp/main.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/Tone.cpp -o /tmp/build4933543797518254688.tmp/Tone.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/IPAddress.cpp -o /tmp/build4933543797518254688.tmp/IPAddress.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/USBCore.cpp -o /tmp/build4933543797518254688.tmp/USBCore.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /usr/share/arduino/hardware/arduino/cores/arduino/WString.cpp -o /tmp/build4933543797518254688.tmp/WString.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/wiring_analog.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/malloc.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/realloc.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/wiring_digital.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/wiring_pulse.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/wiring.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/wiring_shift.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/WInterrupts.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/Stream.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/HID.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/Print.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/WMath.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/CDC.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/new.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/HardwareSerial.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/main.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/Tone.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/IPAddress.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/USBCore.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4933543797518254688.tmp/core.a /tmp/build4933543797518254688.tmp/WString.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -Os -Wl,--gc-sections -mmcu=atmega328p -o /tmp/build4933543797518254688.tmp/Sweep.cpp.elf /tmp/build4933543797518254688.tmp/Sweep.cpp.o /tmp/build4933543797518254688.tmp/Servo/Servo.cpp.o /tmp/build4933543797518254688.tmp/core.a -L/tmp/build4933543797518254688.tmp -lm
/usr/share/arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/build4933543797518254688.tmp/Sweep.cpp.elf /tmp/build4933543797518254688.tmp/Sweep.cpp.eep
/usr/share/arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom /tmp/build4933543797518254688.tmp/Sweep.cpp.elf /tmp/build4933543797518254688.tmp/Sweep.cpp.hex
Binary sketch size: 2,554 bytes (of a 32,256 byte maximum)
/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/build4933543797518254688.tmp/Sweep.cpp.hex:i

avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/share/arduino/hardware/tools/avrdude.conf"
         User configuration file is "/home/username/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: ser_open(): can't open device "/dev/ttyACM0": No such file or directory
ioctl("TIOCMGET"): Inappropriate ioctl for device

avrdude done.  Thank you.

Update 2: (tried again, this time i get "broken pipe". Led 13 blinks like crazy and my servo sounds different, no movement but continues sound)
.
.
.
avrdude: avr_read(): skipping page 253: no interesting data
avrdude: avr_read(): skipping page 254: no interesting data
avrdude: avr_read(): skipping page 255: no interesting data
avrdude: verifying ...
avrdude: 2554 bytes of flash verified
avrdude: Send: Q [51]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]

avrdude done.  Thank you.

/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/Servo /tmp/build4258280580047414287.tmp/Sweep.cpp -o /tmp/build4258280580047414287.tmp/Sweep.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/Servo/Servo.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/wiring_analog.c.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/malloc.c.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/realloc.c.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/wiring_digital.c.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/wiring_pulse.c.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/wiring.c.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/wiring_shift.c.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/WInterrupts.c.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/Stream.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/HID.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/Print.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/WMath.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/CDC.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/new.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/HardwareSerial.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/main.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/Tone.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/IPAddress.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/USBCore.cpp.o
  Using previously compiled: /tmp/build4258280580047414287.tmp/WString.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/wiring_analog.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/malloc.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/realloc.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/wiring_digital.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/wiring_pulse.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/wiring.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/wiring_shift.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/WInterrupts.c.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/Stream.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/HID.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/Print.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/WMath.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/CDC.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/new.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/HardwareSerial.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/main.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/Tone.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/IPAddress.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/USBCore.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-ar rcs /tmp/build4258280580047414287.tmp/core.a /tmp/build4258280580047414287.tmp/WString.cpp.o
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc -Os -Wl,--gc-sections -mmcu=atmega328p -o /tmp/build4258280580047414287.tmp/Sweep.cpp.elf /tmp/build4258280580047414287.tmp/Sweep.cpp.o /tmp/build4258280580047414287.tmp/Servo/Servo.cpp.o /tmp/build4258280580047414287.tmp/core.a -L/tmp/build4258280580047414287.tmp -lm
/usr/share/arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/build4258280580047414287.tmp/Sweep.cpp.elf /tmp/build4258280580047414287.tmp/Sweep.cpp.eep
/usr/share/arduino/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom /tmp/build4258280580047414287.tmp/Sweep.cpp.elf /tmp/build4258280580047414287.tmp/Sweep.cpp.hex
Binary sketch size: 2,554 bytes (of a 32,256 byte maximum)
/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/build4258280580047414287.tmp/Sweep.cpp.hex:i

avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/share/arduino/hardware/tools/avrdude.conf"
         User configuration file is "/home/username/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
ioctl("TIOCMSET"): Broken pipe
ioctl("TIOCMGET"): Input/output error

Check File → Preferences → Show verbose output during upload, 2. try again, 3. copy and paste the avrdude command line in a terminal and hit Enter, 4. post here all the output.

You have a communication problem.  The recommendation to try compilation commands from the terminal is not helping you, but merely showing that the files in /tmp are emphemeral.  Look into things like a flaky USB cable (or possibly an OS USB stack incompatible with quirks of your motherboard) which may be causing your board to "jump" to a different virtual port.  Check dmesg right after the failure.

@ChrisStratton - I uploaded example code form arduino IDE. And regarding brltty i removed it using sudo apt-get remove brltty. or is there any other steps involved with brltty

@ChrisStratton - I think your point is correct, about changing the cable worked. But that too worked only for certain uploads. During some upload i get the very same Broken pipe and Input/output error. Dose this issue has to do anything with improper installation. Because, when i get that error, my Icon never works on clicking unless i restart whole system, or i have to remove the cable and kill the avrdude process through sudo top command and then initiate IDE by sudo arduino from terminal. only then i get serial port active and displayed

Does the file /dev/ttyACM0 appear when you plug the Arduino and disappear when you unplug it?

@EdgarBonet - yes it dose. But while uploading the code, if i get the broken pipe error, it never appears until i restart the system or the arduino with some pkill or top command

You should never be running arduino (or any other IDE) under sudo.  If you think you need to do so, it is either because you have not given your account membership in the group which owns serial devices, or you have left behind files by running it as root in the past, which now only root can cleanup/replace.

If your /dev/ttyACM0 has failed for some reason while in use, a reconnection would probably show as /dev/ttyACM1 and so on, incrementing number.

@ChrisStratton - I tried sudo chmod a+rw /dev/ttyACM0 and then sudo gpasswd -a _username_ dialout also tried sudo usermod -a -G dialout _username_ as suggested from various tutorials. All i can start the IDE is only using the sudo command. Are those the right way to add account membership ?
and about the ttyACM0 and ttyACM1 i do get those some times and i understood that part, thanks.

Please try using the last IDE version released here: http://arduino.cc/en/Main/Software The version 1.6.1 has many improvements about serial devices detection and sketches upload.

What the right group is depends on your installation.  "All i can start the IDE is only using the sudo command" has nothing to do with port permissions (you would only have a problem trying to download or open the serial monitor), but only with a broken install, possibly as a result of having made a mess by improperly running it as root in the past.

@lcipriani - I downloaded v1.6.1. It worked fine without any error. But after downloading im only able to open it from the directory where it resides. can you please help on how to open it from anywhere..?

@arvindh it would be nice if you can upvote my comment if it really helped you.

@lcipriani - i Know, I tried, and im sorry that i dont have enough reputation points to upvote your comment. Please write up the solution as an answer, i will remove my answer and mark yours as accepted,.. Im glad to do that instead of taking credit of others effort. Please feel free to write an answer.

Please use the last IDE version released here: arduino.cc/en/Main/Software The version 1.6.1 has many improvements about serial devices detection and sketches upload. It will solve your issues about older Arduino UNO version and Arduino Yun.


text:
Path relater errors on compilation in Arduino IDE 1.8.5 under Windows XP
For the XP under the Russian locale I'm getting the strange output when trying to compile Marlin project for Anycoubic 3d printer according to instruction https://3dtoday.ru/blogs/trialon/marlin119-for-anycubic-kossel-linear-plus
avr-g++: error: C:\DOCUME~1\ИЖИ: No such file or directory
avr-g++: error: Ь~1\LOCALS~1\Temp\arduino_build_153827\sketch\Marlin.ino.cpp: No such file or directory
avr-g++: error: Ь~1\LOCALS~1\Temp\arduino_build_153827\preproc\ctags_target_for_gcc_minus_e.cpp: No such file or directory
avr-g++: warning: '-x c++' after last input file has no effect
avr-g++: fatal error: no input files
compilation terminated.
exit status 1
Ошибка компиляции для платы Arduino/Genuino Mega or Mega 2560.

I have realized that the root cause was the windows user with the Cyrillic name. So creating a new user wiht base Latin name and running Arduino IDE from it helped

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


text:
Cannot find Arduino under /dev Directory
I have the Arduino board connected to a USB port of my machine. But I cannot find it under /dev/ directory in my Ubuntu. Does anyone know how to deal with this issue? By the way, "lsusb"'s output proves that it has been recognized. Here is the output of this command:
Bus 002 Device 002: ID 8087:8000 Intel Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:8008 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 007: ID 413c:2105 Dell Computer Corp. Model L100 Keyboard
Bus 003 Device 013: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Here is the output of ls -l /dev/ttyACM*
ls: cannot access /dev/ttyACM*: No such file or directory

and the dmesg output when disconnect and reconnect the device:
[1653809.002715] usb 3-11: USB disconnect, device number 13
[1653832.188835] usb 3-11: new full-speed USB device number 14 using xhci_hcd
[1653832.211392] usb 3-11: New USB device found, idVendor=2341, idProduct=0043
[1653832.218400] usb 3-11: New USB device strings: Mfr=1, Product=2, SerialNumber=220
[1653832.226003] usb 3-11: Manufacturer: Arduino (www.arduino.cc)
[1653832.231859] usb 3-11: SerialNumber: 85235353137351708191
[1653832.237468] usb 3-11: ep 0x82 - rounding interval to 1024 microframes, ep desc says 2040 microframes

Please edit the output of ls -l /dev/ttyACM* into your question. Also, see if dmesg says anything upon connection.

Just did it. Please see the question revised.

Plase rerum dmseg after a while after plug in. Seems Luke enumeration is failing. Dmesg should tell you eitch tty gas ben assigned to the device.

The output of dmesg is the same as what has been shown in question.

Note that lsusb does not guarantee the drives are loaded (See https://superuser.com/questions/165733/will-lsusb-and-lspci-list-devices-for-which-the-system-has-no-drivers)
Per the https://stackoverflow.com/a/14586884/1653571 answer, try an 'lsmod' and see whether you have a 'cdc_acm' module loaded.


text:
What will use less memory, an array or if ... else?
I'm trying to make my sketch smaller. Right now I use an array for the AM/PM part of my time display. My thinking is this makes it easy to change the formatting:
char* ampms[]= {"am", "pm"};

void loop() // run over and over again
{     //get time from RTC
     getDateDs1307(&second, &minute, &hour);

      //change to 12 hour format.
      if (hour>12) { hr = hour - 12; ampm=1; } else { hr = hour; }

      //add leading 0 for hours
      if (hr<10) { lcd.print("0"); }

      //print hour in 12 hour format.
      lcd.print(hr, DEC);

      lcd.print(":");

      //add leading 0 for minutes
      if (minute<10) { lcd.print("0");}

      //print minutes
      lcd.print(minute, DEC);

      //print am or pm using array.
      dataFile.print(ampms[ampm]);
}

I could do this instead:
void loop() // run over and over again
{     //get time from RTC
     getDateDs1307(&second, &minute, &hour);

      //change to 12 hour format.
      if (hour>12) { hr = hour - 12; } else { hr = hour; }

      //add leading 0 for hours
      if (hr<10) { lcd.print("0"); }

      //print hour in 12 hour format.
      lcd.print(hr, DEC);

      lcd.print(":");

      //add leading 0 for minutes
      if (minute<10) { lcd.print("0");}

      //print minutes
      lcd.print(minute, DEC);

      //print am or pm using array.
      if (hour>12) { lcd.print("am");} else {lcd.print("pm"); }
}

No more am/pm array. But, I have to add an if... is one better than the other for memory? Why?

avr-size says what?

Sketch uses 25,588 bytes 79% Max is 32,256 Global variables use 1,938 bytes 94%

And the other way?

I appears to be the same.

Then neither is the solution you're looking for. Try putting the constants into flash.

Try looking into PROGMEM. See the 'Arrays of strings' section on the arduino website for example.

As Ignacio says, if the compiled size is the same both ways, look for something else.  (But note that having the constants in flash memory (program memory) may still use about the same amount of RAM, and typically will take more program space.)
When I compile the code you showed (together with minor additions like declaration of variables) I show the array method using 4 bytes less code and 5 bytes more RAM than the if method, so there are tradeoffs.
You can replace the clunky if statement and its two lcd.prints  with the following:
      lcd.print(hour>12? "am" : "pm");

Note that that line retains the two bugs that your if statement has, but it produces them more compactly. :) [One error is that your if statement prints pm for hours 0 through 12 and am for hours 13 through 23.  Another error is that it prints zeroes instead of twelves for the hours after midnight and noon.  More properly, a program should print like 12:xx am during hour 0 of the day, and like 12:xx pm, 1:xx pm, ... 11:xx pm during hours 12 through 23.]
Also note that as Gerben mentions, moving the "am" and "pm" strings into program memory via
lcd.print(hour>12? F("am") : F("pm"));

saves 6 bytes of RAM.  However, that improvement in RAM usage is offset by 74 additional bytes of program space! The following saves 6 bytes of RAM while increasing program size by only 12 bytes so may be preferable:
lcd.print(hour>12? 'p' : 'a');
lcd.print('m');

The following lines of C can replace much of the code you showed.  However, the printf library uses about 1300 bytes of program space, so the following compact-source-code approach cannot be recommended unless you are already loading some printf functions.  It replaces the lines from if (hour>12) { hr = hour - 12; } ... to the end with
enum { bufsize=8 };
char buf[bufsize];
snprintf (buf, bufsize, "%02:02%cm", hour%12, minute, hour>12? 'p' : 'a');
lcd.print(buf);

lcd.print(hour>12? F("am") : F("pm")); will safe 6 more bytes.

@Gerben, but program size increases 74 bytes.  Printing characters (see edited answer) saves the 6 bytes of RAM but increases program size only 12 bytes

didn't thing of checking that. That's very interesting. Having an almost empty sketch with only that line, will make it increase by only 26 bytes on my system.


text:
Stepper motor doesn't start immediately when i pressed the button
When I release my hand from the button on pin 2, the stepper motor takes at least few seconds to stop, but I want it stop immediately. here's my codes:
 #include <Stepper.h>

    const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
    // for your motor

    // initialize the stepper library on pins 8 through 11:
    Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

    bool dir = false;
    bool power = true;

    void dir_pin() {
      if (!digitalRead(3)) {
        dir = !dir;
      }
    }//when the switch is being pressed
    //it condition would be different from last time

    void setup() {
      // set the speed at 60 rpm:
      myStepper.setSpeed(60);
      // initialize the serial port:
      Serial.begin(9600);
      pinMode(2, INPUT_PULLUP);//it is a easier way to using INPUT-PULLUP
      //cause you dont have to use a real resistor
      pinMode(3, INPUT_PULLUP);//why choose those two pins
      //cause for uno, the interrupt pin are pin 2 and pin 3
      attachInterrupt(digitalPinToInterrupt(3), dir_pin, FALLING);
      pinMode(A0, INPUT);
    }

    void loop() {
      int pwr = analogRead(A0) / 100;
      Serial.print("power:");
      Serial.print(power);
      Serial.print("  pwr:");
      Serial.print(pwr);
      Serial.print("  dir:");
      Serial.println(dir);
      while (digitalRead(2) == 0)
      {
        if (pwr) {
          myStepper.setSpeed(pwr);
          int pwr = analogRead(A0) / 100;

          if (dir) {
            //Serial.println("clockwise");
            myStepper.step(stepsPerRevolution);
            //delay(500);
          }
          // step one revolution in the other direction:
          else if (!dir) {
            //Serial.println("counterclockwise");
            myStepper.step(-stepsPerRevolution);
            //delay(500);
          }
        }
        else
        {
          myStepper.step(0);
        }
      }
      while (digitalRead(2) == 1)
      {
        pwr = 0;
        myStepper.step(0);
      }
      delay(10);
    }

Doesn't start immediately? (as in the title?) or Doesn't stop immediately? (as in the body?)

You tell it to move whole 200-step revolutions, so once it begins a revolution, it must continue.  At 60 RPM, that should be up to 1 full second after you open pin 2.   Depending on the analogRead(A0)/100, a full revolution could take much longer than 1 second -- maybe 5.86s to 6000s
If you want it to stop immediately, disregarding full revolutions, you could:
      stepsPerButtonpress = 1;

      ...

      if (dir) {
        //Serial.println("clockwise");
        myStepper.step(stepsPerButtonpress);
        //delay(500);
      }
      // step one revolution in the other direction:
      else if (!dir) {
        //Serial.println("counterclockwise");
        myStepper.step(-stepsPerButtonpress);
        //delay(500);
      }

Or you could reduce stepsPerRevolution to the fraction of steps you want to treat as a unit, and increase rpm proportionally.


text:
Interfacing Digital clock with Uno
I want to take input from a clock for a specific time and respond to it.
I am taking alarm as input because it will send some signal to a buzzer and I want to decode it through Arduino.
I am using Arduino Uno.
The program I used is as follows:
int b = 0;

void setup() {
    pinMode(8, INPUT);
    Serial.begin(9600);
}

void loop() {
    b=digitalRead(8);
    Serial.println(b);
    if(digitalRead(8) != 0)
    {
        Serial.println("input in 8");
    }
    else
        Serial.println("not");

    delay(500);
}

I have removed the buzzer from the clock and connected the terminals to Arduino pin 8 and GND.
But the output is always random (i.e. 0 & 1), no matter if my alarm is on or off.
I cannot find if my program has a flaw or if my approach is just wrong.

It is likely that the alarm clock does not provide any voltage level (I mean GND) to the  buzzer when it does not have to ring, the circuit is just left "open" then; it will provide a voltage level (depending on your clock power supply) only when the alarm has to ring.
On the other side, your Arduino pin 8 must have a voltage level that can be mapped to a 0 (anything between GND and 5V/3) or a 1 (anything between 2x5V/3 and 5V).
However, in the absence of alarm, the input is left "dangling" (no voltage level at all). In CMOS technology, leaving an input pin dangling will make it randomly take 0 and 1 levels as you described.
Fortunately, the solution to this problem should be easy: you just have to force a 0 level to pin 8, by connecting it to GND through a resistor. I generally use 10K or 15K for that resistor. This is called a "pulldown" resistor:

when the alarm does not provide any voltage, the input pin level will be "pulled down" to GND, ie 0.
when the alarm provides a 5V (see important remark below) to the input pin, then it will be seen as 1.

IMPORTANT: you have to make sure that your alarm clock, when ringing, provides a voltage that is not higher than 5V (it would grill your UNO, or more precisely the ATmega328 of your UNO) and is at least ~3V to be "recognized" as 1.
NOTE: it is likely that solving this first issue will not be enough to make your complete program work, because your alarm clock probably does not send a continuous voltage to your buzzer but and alternate one to make it ring, hence you will get successive 1 and 0 at high speed (between 100Hz and 100Hz I would say) in your program. If that is the case please open another question as the solution for that specific issue is disconnected from the current one (random 1 and 0).

A 10k pull-down resistor should also help to stabilize the signal.

A capacitor could help smooth the 100 Hz (or whatever) signal when the alarm is on.

If you have access to an oscilloscope, it would be beneficial to take a reading of what output the clock makes when the alarm is on. (ie whether it is AC or DC and what voltage it is).


text:
where to syphon off voltage from a 25 pin serial?
I have a mircocontroller that's looking to be powered by a 5v source.
I am trying to 'cypher off' some of this power from a 25 pin serial port, which is being powered by a constant power source.
Are there any pins that could give me that sort of voltage, or enough to power the board?

Please note, I'm not an electrical person at all, and so hope this is actually possible (otherwise my 3 months + program's work doesn't really add to anything).
I've tried a 9v battery, but it didn't seem to hold its charge?
I'm reading these labels going "what the ..." so you can probably tell coding the board wasn't the easiest, either.
Edit History

I would like to clarify this is an existing serial lead
I understand this may be deemed verging off topic, but due to the need to 'power' a microcontroller, I thought this could be answered here
If this isn't possible, (as an alternative, possibly) would a 9V/battery be able to power this board reliably for around 2-3 weeks?

Pins 11/18 might be NC so you could add your own adapter on the other side to send power through unused lines. If not, the only real thing I can see is using pin 9 and a regulator. I'm not sure how much that pin is rated for, though. I probably won't damage anything with 100 mA though....

@AnnonomusPenguin: Sorry if this is a stupid question, but what'd you mean by a 'regulator'. Like, i know what it means in English, but physically what?

I meant using the onboard linear regulator. When you connect a power supply to VIN or the black power jack that's over ~7.5V the Arduino converts that to a 5V for it to use. In this case, you might be able to connect pin 9 on the serial wire to the VIN pin on the Arduino and the ground wire on the cable to the GND pin on the Arduino and it would convert it to 5V for it to use.

You need 5 volts; A serial port uses higher voltages (usually 12v but apparently there is some latitude). A voltage regulator is a circuit that provides a stable 5 volts (in this case) from a higher and not necessarily constant voltage. (For completeness, there are also regulators that provide a higher voltage than their source, but that isn't what you need here).

It is unclear from your question whether you are trying to get power from an existing serial port, or merely use it for transport. The diagram you posted MAY have been relevant 40 years ago, but NO  current microcomputer equipment would support this - indeed this is why most equipment uses a 9 pin connector, and even these are rare. One thing that is clear is that you do not understand the interface. Even in the good old days you COULD NOT derive power from serial. Equipment no longer supports the voltages in the standard, which was meant to operate over 1000m.

@Milliways - no, the person who does not understand the interface is you.  Drawing small amounts of power from serial interfaces was quite normal.  It's a moot point though, as this question is not on topic for the Arduino site.

@ChrisStratton: It's in that grey area of topicality, since it's about powering the board from serial. So, i personally would agree there is an iffy point. But I hope this could be solved?

This is off topic because it is not asked about an Arduino, and because nothing sold as an "arduino" would be particularly suitable for this use.  Your question belongs on EESE.

You should be able to use pin 7 for negative, 9 as positive, this gives you 12 volts.
YOU MUST NOT HOOK THIS UP DIRECTLY to the arduino, connect it to a plug for the power jack (right of the USB connection).
If you are using a USB -> serial adapter, then the voltage may be 5v, but don't count on it.
Of course, USB is always going to be better!
PS - if you draw more power than the serial port is rated for, you will probably destroy the card. In most cases, this will be the motherboard. You are unlikely to be able to find out what it is rated for (look for Amps or A, or milliAmps  mA, or microAmps uA). The Arduino (with NO inputs or outputs, and idle) running from a 9v battery will draw about 50 milliAmps.

No.  You are quite unlike to "destroy the card" by drawing more power, as the port drivers simply can't supply much power to begin with, and I/O drivers are typically designed to be robust, because people do silly things like wire up mistaken cables, using straight cables where they should use null modems, or null modems where they should use straight cables.  The 1488 data sheet says "current limited" and the MAX232 says output short circuit duration unlimited.

That makes a lot of sense :) I thought it better to err on the side of caution. It also encourages checking specs, which is a good habit to get into.

@AMADANONInc.: I can't seem to 'get' a voltage from pin 9... I'm guessing the 'other end' either doesn't connect to anything, or doesn't carry a voltage?

A 25 pin serial cable doesn't have to be connected to anything standard.  I often used 25 pin serial cables that only had 3 wired pins (2, 3, and 7).  That is sufficient for software flowcontrol serial communications.  If the equipment on the other end doesn't wire up pin 9, then you can't use it.

In a lot of further research, I have discovered that 'It doesn't really matter' what the serial port diagram says, since in 25 pin serials (and 9 pin D-subs), it all depends on the circuit at the other end, showing which wires are actually 'connected', or 'used'.

I managed to get some current from +pin 6 -pin 5 in which allowed me to draw some current, but have chosen to go with a (PP3?) 9v battery instead due to its reliability.

So, in conclusion to this question, there isn't a specific answer, since it all depends on how the serial at the other end is wired.
It seems to me that in my case, there were minimal wires actually connected, so I was forced to look for other means of connecting to a 'reliable' power source.


text:
Sending data from processing to arduino
I have problem to send data from processing to arduino mega.
Processing Code :
import processing.serial.*;

Serial myPort;

void setup()
{
println(Serial.list());
String arduinoPort = Serial.list()[0];
myPort = new Serial(this, arduinoPort, 9600)
}

void draw()
{
byte a= 3;
myPort.write(char(a));
}

Arduino Code :
#include <Servo.h>
#include <Wire.h>

Servo myservo1;
Servo myservo2;

void setup()
{
Serial.begin(9600);
myservo1.attach(9);
myservo2.attach(10);
myservo1.write(90);
myservo2.write(90);

}

void loop()
{

if(Serial.available()>0){
myservo1.write(70);
myservo2.write(70);

}

}

Code is really simple, processing send a value to trigger arduino mega turning 2 servo
motors.
But it doesn't response at all..
Please help if anyone has any clue.
Thanks :))

Some things to try: 1) Send the output from Processing to a terminal to check that Processing does what you think it should do. 2) Send the "correct" text to the Arduino from a terminal to check whether correct text will cause the proper response. 3) Put one or more LEDs on your board and light them when significant things happen such as receiving any text, attempting to control the motors, etc. 4) Keep on testing smaller and smaller parts of the system until you identify something that behaves differently than you intended it to. Fix that and try again.

Thanks a lot Robert! Finally I realized its because I didnt add delay after every time sending data to arduino..


text:
How can I communicate from Arduino to MATLAB
I want to use sensors on an Arduino to control values in a MATLAB program. What are my options for communicating?
I've used Processing to receive data sent via the serial cable, and that strategy has worked pretty well. Is there something similar I can do using MATLAB? I'm somewhat new to MATLAB, so gentle guidance would be great.
I'm not really looking for something like the ArduinoIO package -- I want to have separate computation executing on the Arduino and occasionally informing my MATLAB program (which will occasionally poll the serial line, I suppose).

Do you need help writing the code for the Arduino, or help writing MATLAB code to read data input from the serial stream?

This question appears to be off-topic because it is about programming in Matlab.

The serial port is your best bet.  I would define a simple message format bases on your needs.  If you only are doing simple stuff like valve on/off: I would define a start byte followed by a fixed number of data bytes.  If you want to get more complicated send a length byte first, followed by that many data bytes.  Please remember: don't send serial bytes nonstop, always have a few breaks (sleep cycles) in the data which allows the serial chips to clock recover.

MATLAB Support Package for Arduino (aka ArduinoIO Package) allows you to do it fairly easily.

Sample usage:
%-- connect to the board
a = arduino('COM9')
%-- specify pin mode
a.pinMode(4,'input');
a.pinMode(13,'output');
%-- digital i/o
a.digitalRead(4) % read pin 4
a.digitalWrite(13,0) % write 0 to pin 13
%-- analog i/o
a.analogRead(5) % read analog pin 5
a.analogWrite(9, 155) % write 155 to analog pin 9

If I understand ArduinoIO correctly, all the computation is initiated on the Matlab side and the Arduino just becomes a sensor extension.  That isn't what I want.  I want to have a program on the Arduino (doing it's own computation) that occasionally communicates with Matlab.

The MATLAB side simply provides you with the functions to communicate with the Arduino. It's up to you how/when you want the two to communicate. The Arduino can write to the serial port and this allows you to read from it.

I don't know a whole lot about MATLAB, but I found some tutorials about reading and writing from the serial port:
s = serial('COM1');
fopen(s)
fprintf(s, 'Your serial data goes here')
out = fscanf(s)

out is now your received data, and you can do whatever you want with it.
To close:
fclose(s)
delete(s)
clear s

It is from Writing and Reading Data (MATLAB/ Data and File Management/ Serial Port Devices).
From your question I assume you know about the Arduino side of things (using Serial).

I've established a connection, sending numbers. By just changing Serial.write to Serial.print and fread to fscanf you can send/receive clear ASCII text instead of binary data.
Both matlab and arduino code can be found at this question:
https://stackoverflow.com/questions/24368670/matlab-plot-serial-data-continously

clc
clear all
global value
global value1
global val5
global val6
global val7
global val8
global val9
a=arduino('COM4');
   value = zeros();
   value1 = zeros();
   val5 = zeros();
   val6 = zeros();
   val7 = zeros();
  val8 = zeros();
  val9 = zeros();
for i=1:1000
val1(i)=analogRead(a,0)/2; %incomming
val2(i)=analogRead(a,1)/2; %heater
val3(i)=analogRead(a,2)/2;   %heat sink
val4(i)=analogRead(a,5)/2; %atmsphr
val8(i)=analogRead(a,6)/2; %pressure
val9(i)=analogRead(a,7)/2; %pressure
val(i)=analogRead(a,0)/2;
value(i)= (val1(i)+val4(i)+val3(i))/3;
value1(i) =(val8(i)-val9(i)); %pressure
val5(i)=analogRead(a,0)/2 %incoming
val6(i)=analogRead(a,4)/2 %outgoing
val7(i) = value(i)-val6(i)
    plot(value, 'r');
    title('heat sink temprature');
hold on

plot(val5, 'k');

title('incoming air temprature');
plot(val6, 'g');

title('outgoing air temprature');

 plot(val4, 'k');
 title('atmospheric temperature');

plot(val7,  'c');
title('change in temprature');

pause(6)

figure
plot(value1,  'r');
title('change in pressure');

pause(6)

end

Providing a code-answer without an explanation on what it does it's not a valid answer here on StackExchange. Can you edit your post providing some informations?


text:
What are ideal delay times between commands for RF24 lib
Am working on a WiFi based irrigation system that utilises the RF24 lib for comms.
Have got prototype of remote sensor up and running which has a standby current of 0.036mA and transmits data every hour using around a peak of 12mA.
While running the prototype I see various retry attempts which seem to vary with every transmission – despite the setup being under the same conditions all the time. I have coded a retry loop to limit this to 10 tries connecting to the master – don’t want the sensor to continuously be sending without getting a confirmation from the master
What I am trying to find is the ideal delay required between various RF24 commands to limit transmit times as much as possible to conserve power usage.
Any ideas??
(code snippets attached)
   pinMode(mostureSensorVCC, OUTPUT);
   digitalWrite (mostureSensorVCC, HIGH); //VCC to sensor
   pinMode(mostureSensor1, INPUT);      //moisture sensor on
   delay(10);
   int sensorValue1 = analogRead(mostureSensor1); // read the input on analog pin
   Serial.print("Current Value Sensor 1 is : "); // debugging
   Serial.println(sensorValue1); // print out the value you read:
   msg[0] = sensorValue1;
    digitalWrite(mostureSensor1, LOW);
    digitalWrite(mostureSensorVCC, LOW);
      while (message != sensorValue1)
        {

          Serial.print("sensorValue in while loop is "); // debugging
          Serial.println(sensorValue1);                   // debugging
          Serial.print("Message One is ");                // debugging
          Serial.println(message);                        // debugging
          radio.powerUp();
          delay(70);

          radio.stopListening();
          delay(50);
          radio.write(msg, 2);
          delay(40);
          radio.startListening();
          delay(50);

         Serial.println(d);               // debugging

          if (radio.available())
            {
             Serial.println("Radio available");     // debugging
              radio.read(msg, sizeof(msg));
              message = msg[0];
              Serial.print("Check Message received from master ");// debugging
              Serial.println(message);

            }
            if(d>=10)
            {
              Serial.println("Unable to send to master");
              break;
            }
       d++;
  }

delay(1000);
radio.powerDown();
message = 0;
msg[0] = 0;

Do you eventually get confirmation after a number of tries? What state (power saving and all) is the master in when the node is starting to transmit? And what makes you think delay (or lack therof) is the cause? Did you try to adjust transmit power and data rate instead?

Don't use delays, totally unnecessary 2. Look at the examples, PingPair etc.

Hi, Thanks for the great responses Get confirmation after different numbers of replies – ranges from 2 to 8 or 9 attempts to the master. Have seen on the master that it occasionally receives upto 3 messages which it seems to respond to.
Will include relevant code clip from master below

I have configured a specific channel outside of most used in my area, and have used recommended settings for remote sensor transmits
    //.....start radio and pipes.....

Serial.println("Start radio...");  // debugging
radio.begin();
delay(30);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS); //Fast enough.. Better range
radio.setChannel(108); //2.508 Ghz Above most Wifi Channels
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);

Remove all delays except the one after startListening.
You could replace it with a "wait for radio.available to be true OR 50ms to have passed" piece of code. There is no need to wait for 50ms if the message was already received after e.g. 10ms.
Even better would be to use the ACK-package feature of the NRF. With this feature the master already prepares a package for the slave. Then when the slave sends it's message (every hour), the prepared package is included in the ACK (acknowledgement) packet.
As to optimizing it even further. It would be better to optimize the sleep code, then the send code. The sleep part will still use more power in an hour than the sending code, even if it takes 10 second to do so.
As to the lost packages. Try using a different channel. You also might want to get an NRF module with an real antenna, and maybe even an amplifier, for the master.
PS You can remove the serial.print in the deployed version.

Hi, Thanks for the response. Not sure how to configure ACK package feature – pretty new to this radio stuff. Have ( I feel) got the sleep code pretty well configured – drawing around 0.035mA while sleeping which works for me
All of the Serial.Print statements are just for debugging and I do remove them from the deployed code.

Also check out this battery calculator to see how much runtime you get.


text:
Low Power library messing up serial text
I noticed something unusual using the Low Power library today.
When printing text in the loop and using LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); to sleep for one second, all the text in the loop gets messed up in the Serial Monitor as if you chose the wrong baud rate.
Example code:
#include "LowPower.h"

void setup() {
  Serial.begin(9600);
  Serial.println(F("HELLO"));
  Serial.println(F("HELLO"));
}

void loop() {
  Serial.println(F("HELLO"));
  LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
}

This code just prints
����11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=

even when using different baud rates. (I used the same baud rate on both the arduino and the monitor).
Replacing the low power command with delay(1000); works fine

The problem is most likely that the system is going to sleep while it's still sending the serial data.
Forcing all the serial data to be sent before you go to sleep should fix the problem (serial data is sent in the background using an interrupt so as to keep sketch slowdown to a minimum):
Serial.flush();
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);

Thank you very much for this fast answer. Would this affect the power saving of the library? I assume not but better be sure :)

It will cause a slight delay before it goes to sleep while the serial data is sent out.  It won't affect the actual sleeping though, no.  It just means the "on" time will be slightly longer - long enough to finish what it's doing.

I didn't know of that method. Thanks. @qwertz using a higher baudrate than 9600 will decrease the transmit time, so reduce power usage.

@Gerben In pre-1.0.0 Serial.flush wiped the transmit buffer.  In 1.0.0 and onwards it blocks until the transmit buffer is empty and the UART hardware has transmitted the last bit.

Let us know if this doesn't totally solve it. There may be other issues as well like the serial line stopping being driven high.


text:
Bluetooth not transmitting refreshed sensor values
I have a 9 DOF sensor attached to a BLE chip and Arduino Uno. I want to send the position measurements (i.e. x, y and z coordinates) from the sensor to my iPhone app (Bluefruit LE). The code below starts off well and I am able to see the coordinates on the iPhone. But after showing 6 sets of x-y-z coordinates on the phone all it prints are the x-coordinates. The y and z coordinates do not get shown on the phone at all. I have put the code below (likely not the most efficient code). Any suggestions on how to fix it will be very helpful. thanks in advance.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <SPI.h>
#include "Adafruit_BLE_UART.h"

/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)

#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 2
#define ADAFRUITBLE_RST 9

Adafruit_BNO055 bno = Adafruit_BNO055(55);
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ,     ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

void displaySensorDetails(void)
{
sensor_t sensor;
bno.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print  ("Sensor:       "); Serial.println(sensor.name);
Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
Serial.print  ("Max Value:    "); Serial.print(sensor.max_value);
Serial.print  ("Min Value:    "); Serial.print(sensor.min_value);
Serial.print  ("Resolution:   "); Serial.print(sensor.resolution);
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}

/*
Arduino setup function (automatically called at startup)
*/

int x = 0;
int row = 0;
void setup(void)
{
Serial.begin(9600);
Serial.println("Orientation Sensor Test"); Serial.println("");
Serial.println("CLEARDATA");
Serial.println("LABEL,x,y,z");

/* Initialise the sensor */
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}

delay(1000);

/* Display some basic information on this sensor */
displaySensorDetails();
bno.setExtCrystalUse(true);

BTLEserial.begin();

}

aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop(void)
{

BTLEserial.pollACI();

/* Get a new sensor event */
sensors_event_t event;
bno.getEvent(&event);

/* Display the floating point data */

Serial.print("X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
Serial.println("");

/* This is the code that sends x, y and z coordinates to BLE */
  uint8_t sendbuffernew_x[20];
  char buff_x[20] = "";
  String xorient = "";
  dtostrf(event.orientation.x, 4, 1, buff_x);  //4 is mininum width, 6 is precision
  xorient += buff_x;

  xorient.getBytes(sendbuffernew_x, 20);
  char sendbuffersizenew_x = min(20, xorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_x, sendbuffersizenew_x);
  memset(sendbuffernew_x, 0, sizeof(sendbuffernew_x));

  uint8_t sendbuffernew_y[20];
  char buff_y[20]= "";
  String yorient = "";
  dtostrf(event.orientation.y, 4, 1, buff_y);  //4 is mininum width, 6 is precision
  yorient += buff_y;

  yorient.getBytes(sendbuffernew_y, 20);
  char sendbuffersizenew_y = min(20, yorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_y, sendbuffersizenew_y);
  memset(sendbuffernew_y, 0, sizeof(sendbuffernew_y));

  uint8_t sendbuffernew_z[20];
  char buff_z[20]="";
  String zorient = "";
  dtostrf(event.orientation.z, 4, 1, buff_z);  //4 is mininum width, 6 is precision
  zorient += buff_z;

  zorient.getBytes(sendbuffernew_z, 20);
  char sendbuffersizenew_z = min(20, zorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_z, sendbuffersizenew_z);
  memset(sendbuffernew_z, 0, sizeof(sendbuffernew_z));

delay(1000);

delay(BNO055_SAMPLERATE_DELAY_MS);
}

Voting to close as this has sat for over a year without any effort on your part to clarify or work the issue.  The problem could be so many things; if you find yourself wanting to solve it, it would be good to obtain a distinct USB-serial converter and connect the transmit data line from the Arduino to the BTLE to the receive line of that, as well as connect the grounds (do not connect the other serial line).  Then you can use a terminal or the serial monitor to see what the Arduino is actually sending, and so determine if this is an Arduino problem, a BTLE problem, or maybe even an iOS one.

That's an incredibly complex way of outputting a floating point number as a string. You may possibly be fragmenting RAM with your use of String, and those String additions. Try replacing:
  uint8_t sendbuffernew_x[20];
  char buff_x[20] = "";
  String xorient = "";
  dtostrf(event.orientation.x, 4, 1, buff_x);  //4 is mininum width, 6 is precision
  xorient += buff_x;

  xorient.getBytes(sendbuffernew_x, 20);
  char sendbuffersizenew_x = min(20, xorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_x, sendbuffersizenew_x);
  memset(sendbuffernew_x, 0, sizeof(sendbuffernew_x));

  uint8_t sendbuffernew_y[20];
  char buff_y[20]= "";
  String yorient = "";
  dtostrf(event.orientation.y, 4, 1, buff_y);  //4 is mininum width, 6 is precision
  yorient += buff_y;

  yorient.getBytes(sendbuffernew_y, 20);
  char sendbuffersizenew_y = min(20, yorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_y, sendbuffersizenew_y);
  memset(sendbuffernew_y, 0, sizeof(sendbuffernew_y));

  uint8_t sendbuffernew_z[20];
  char buff_z[20]="";
  String zorient = "";
  dtostrf(event.orientation.z, 4, 1, buff_z);  //4 is mininum width, 6 is precision
  zorient += buff_z;

  zorient.getBytes(sendbuffernew_z, 20);
  char sendbuffersizenew_z = min(20, zorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_z, sendbuffersizenew_z);
  memset(sendbuffernew_z, 0, sizeof(sendbuffernew_z));

by:
  char buff[10];

  dtostrf(event.orientation.x, 4, 1, buff);
  BTLEserial.write(buff, strlen (buff));
  dtostrf(event.orientation.y, 4, 1, buff);
  BTLEserial.write(buff, strlen (buff));
  dtostrf(event.orientation.z, 4, 1, buff);
  BTLEserial.write(buff, strlen (buff));


text:
Problem fetching data from MPU6050
I am new to Arduino. I have an arduino mega board, which I need to interface with MPU6050 accelerometer-gyroscope module.
My connections are
Arduino_SCL->MPU6050_SCL;
Arduino_SDA->MPU6050_SDA;
Arduino_GND->MPU6050_GND;
Arduino_5 V->MPU6050_Vcc;
Arduino_Pin 2->MPU6050_INT;
I have uploaded the following code to the arduino mega.
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"

MPU6050 accelgyro;

int16_t ax, ay, az, gx, gy, gz;
double  time;
int i;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  accelgyro.initialize();
  time = millis();
  i = 1;
}

void loop()
{
  // collect readings
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  // print result
  Serial.print(i);   Serial.print("\n");
  Serial.print(ax);   Serial.print("\t");
  Serial.print(ay);   Serial.print("\t");
  Serial.print(az);   Serial.print("\t\n");
  Serial.print(gx);   Serial.print("\t");
  Serial.print(gy);   Serial.print("\t");
  Serial.print(gz);   Serial.print("\t\n");

  i = i + 1;
  delay(1000);
}

My problem is when I observe the reading on serial monitor, it shows every reading as zero. Does this mean my sensor is damaged or there's some problem with my connection? Or is my code for fetching the data incorrect?
Thanks

Have you put pullup rsistors on SDA and SCL wires? I2C expects these wires to be pulled up. Some dvices include pullup resistors, but not all. For MPU6050 I don't know, but probably not.

@jfpoilpret, most MPU6050 breakouts have pull-up resistors. I did some research before buying mine and most of them have pull-up resistors.

If you are using the MPU6050 library from jrowberg/i2cdevlib, the library does not have any kind of error handling, so it is unfortunately not easy to guess what went wrong, or even if something went wrong. If the getMotion6 function fails, it will simply copy corrupt data into your return values and it is not possible after the invocation to tell if the function succeeded and you got a valid reading, or if the function failed and you only got garbage back.
One possible problem is that the MPU6050 can be configured to use one of two I²C addresses (0x68 or 0x69) and you are using the default address, as implemented in the MPU6050 library (0x68). It might be worth to try the other address, in case your module is configured that way:
MPU6050 accelgyro(0x69);

To change the module's adress, set A0 to HIGH.


text:
Light only half of the LEDs
How can I only let half of the LEDs light up,
for example, LED 1 on, LED 2 off, LED 3 on...and so on.
I did it this way
(this example fades also all LEDs on and off)
   int x = 1;
   for (int i = 0; i > -1; i = i + x){
      leds[0] = CRGB(i,0,0);
      leds[1] = CRGB(0,i,0);
      leds[2] = CRGB(i,0,0);
      leds[3] = CRGB(0,i,0);
      Serial.println(i);
      FastLED.show();
      if (i >= 55) x = -1;             // switch direction at peak
      delay(10);
   }

but that is not so nice if you have 100 LEDs or so.

Change int x = 1; to int x = 2;.

I don't know much about neopixel but as a general coding practice if you want to do something for every other object, you use the modulus operator like so
if(i % 2 == 0)
{
  //i is even
  //off
}
else
{
  //i is odd
  //on
}

So just wrap your current for loop in another one and to the above with the iterating variable.

This is, for the most part, exactly what others have said. However, nobody has managed to actually use a for loop properly; they've carried forward your inefficiencies for some unknown reason.
The whole point of a for loop is to execute a block of code a predetermined number of times. In your code, you create a loop that loops for a ridiculous length (65,536 times) but each time checks how many loops there have been.
Once the for loop has been constructed properly there are two approaches:
int NUMBER_LEDS = 100;      // you only ever have to change this
                            // if the number of LEDs change - and it's really
                            // easy to find if you put it at the start of
                            // your code.

for (int x = 0; x < NUMBER_LEDS; x++)
{
    if (x % 2 == 0)
        leds[x] = CRGB(x,0,0);
    else
        leds[x] = CRGB(0,x,0);
    Serial.println(x);
    FastLED.show();
    delay(10);
}

The above code is fine if you just want two LED subsets. If you want more than two, you can use a switch/case statement:
int NUMBER_LEDS = 100;      // you only ever have to change this
                            // if the number of LEDs change - and it's really
                            // easy to find if you put it at the start of
                            // your code.
int NUMBER_SETS = 4;        // this will give four groups.

for (int x = 0; x < NUMBER_LEDS; x++)
{
    switch (x % NUMBER_SETS)
    {
        case (0):
        {
            leds[x] = CRGB(0,0,0);
            break;
        }
        case (1):
        {
            leds[x] = CRGB(x,0,0);
            break;
        }
        case (2):
        {
            leds[x] = CRGB(0,x,0);
            break;
        }
        case (3):
        {
            leds[x] = CRGB(0,0,x);
            break;
        }
    }
    Serial.println(x);
    FastLED.show();
    delay(10);
}

You don't have to write a case block for every outcome of x%2; you might want a certain group of LEDs to stay on for two iterations, for example. More information on switch/case can be found here, towards the bottom of the page.
I recommend you read this article on Operators in C++, starting from "Compound Assignement". It helps make code more readable and can considerably decrease the amount of typing you have to do - i = i + 1 neatly becomes i++.