text:
Teensy MIDI Show Control
I'd like to use my Teensy 3.1 to send MIDI Show Control messages using USB MIDI in order to control an ETC Nomad system. These are different from standard NoteOn, NoteOff, ProgramChange, etc. commands, but as far as I can tell they are not supported by the standard library.
Is there any way I can send these messages directly (using lower level commands), as seen here, or does anyone know of a library that supports this? Google has, unusually, not been much help.

Where does USB come into this? The example you linked to shows exactly how to send non-standard MIDI messages.

@JakeC I just linked to that page to differentiate between MSC messages and standard MIDI note messages. I'm not using hardware MIDI, but using the Teensy as a USB MIDI device.

In which case this is more a matter of finding computer software to send those messages if you are just having the Teensy act as a bridge.

Also, Teensy is a rather expensive way of doing this at ~$20 compared to a ~5 USB MIDI cable.

~$5 MIDI cable, a $10+ MIDI interface for my MacBook, and an extra PCB to house the ports and other components, vs a Teensy I already had on my desk

I totally understand the need it now, however, there is still nothing special you would have to do in the Teensy to make it work with MSC if you are just setting it up to relay what it gets from the computer. Any work you need to do is in what software you are using on your computer.

According to the documentation, SysEx messages are sent like any other messages:
array[0] = 0xf0;
array[1] = 0x7f;
array[2] = 0x7f;
array[3] = 0x02;
array[4] = 0x7f;
array[5] = 0x01;
array[6] = 0xf7;
usbMIDI.sendSysEx(7, array);


text:
Using a class instance with Wire.onReceive
Is it possible to register a class instance member function with Arduino's Wire.OnReceive?
I'm trying to make my code object-oriented, and want a specific non-static class function to handle I2C data, but if I'm reading this thread correctly, onReceive is incompatible with classes since it only accepts a function pointer, which won't store context.

A non-static class member function has an implicit ClassName *this parameter inserted as the first parameter in the parameter list.
Because the function prototype required for Wire.onReceive() does not have that parameter specified in its parameter list a non-static member function is not compatible with it.
The same goes for attachInterrupt() and anything else that takes a function pointer.

source: Stack Exchange

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

sort: votes


text:
Making Servo Motor Automatically Move Based on Input
sorry if I sound incompetent, but I know nothing about coding. I have a group project where I must sort various balls into different tracks. The final issue I have is that I must use an arduino for this portion. However, none of us know how to program, and the only experience we have is from doing the lessons from adafruit (copy and paste written code).
What I am attempting to do is attach a paddle to the tip of a high torque servo motor. I will then automatically feed the servo signals, ranging from 0 to 5. Each signal tells which position for the servo to turn to. Could anyone please help guide me in how to write this code? I was thinking of using
this guide for my motor. However it uses a POT. My project must be completely automated. The positons also are all within 180*.
Thank you!

Re “I will then automatically feed the servo signals, ranging from 0 to 5”, where do the numbers come from?  Are the positions equally spaced, or arbitrary angles?

The numbers come from another sensor, which detects which ball is coming. I was not told which type of sensor this is, but I do know that what is given from it is a number corresponding to a different ball.
As far as position, there is only 3 positions I wish for this servo to turn.
90* vertical, 45*, and 315*. So in total It will only need to turn 135* degrees from the farthest two points, 90*-315*

Welcome to Arduino SE.  Be sure to take the tour at https://arduino.stackexchange.com/Tour

So you have a "number" and you want to set the servo to some angle. The logic is very simple:

If number is 0 then set angle to 90
If number is 1 then set angle to 45

etc.
How you "get" the number hasn't been specified, so I will assume you just have an integer with a value between 0 and 5 inclusive.
Setting a servo's angle is as simple as writing that angle to the servo:
servo.write(45); // Set the angle to 45 degrees

So how do you join the two together?  Well, there's three different ways that spring to mind.

A string of if statements
A switch construct
An array

The first one is just like the bullet points above, just written as C:
if (number == 0) servo.write(90);
if (number == 1) servo.write(45);
... etc ...

The second method is very similar but can be more efficient when you know you only ever select one item from a list of options.  Read this to see how: http://hacking.majenko.co.uk/time-to-make-a-switch
The third option, the array, is especially good when you have a lot of options to manage and they are all the same result with a different value:
const int angles[6] = {90, 45, 315, 0, 0, 0};

// ... later ...
servo.write(angles[number]);

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


text:
Communication between two Bluetooth modules of two Arduinos
I am designing a home automation project. I want to control different home appliances through GSM. I am designing it in such a way that each apparatus is connected to an Arduino and bluetooth module. There is a master unit with Arduino, Bluetooth and GSM modules. When the user sends a message, the GSM receives it and communicates via Bluetooth to the corresponding Bluetooth module and Arduino.
Is it possible to communicate between two Bluetooth modules of two Arduinos? Is there a better solution?

Your GSM-connected arduino may need to connect and disconnect its master bluetooth module with the corresponding slave bluetooth devices as needed, but it should definitely be possible.

I'm not sure how many bluetooth devices can be connected to your smartphone. But if you use smartphone, the you can eliminate the master Arduino. But as I said, it still depends on the number of devices you'd like to control. This is supposed to go in the comment section.

How about little smart WiFi boards (such as Red Bear WiFi Micro or something similar), which are connected at your local home network? You can configure your own dyndns service or use a existing and built a web home appliances or web service for your own mobile application. In general please take care of security aspects, so that your home can not be manipulated...

You connect your different sensors or devices to many slave arduinos and each slave arduino has its own bluwtooth module that send the data to Master Arduino that contains the Bluetooth and GSM Module.
And yes you can connect max 7 bluetooth devices to 1 Bluetooth module at a time so in that manner you can connect 7 slave devices to Master Arduino

FYI this system is called Bluetooth Piconet and is not supported in many devices. Most likely needs more expensive bluetooth modules.


text:
multiple connection with ISP Pin at Arduino Micro
Actually I'm not good at English ;-) trying to ask to you. please understand me :)
I needed connect SD card Shield and TFT LCD Screen to Arduino Micro.
successfully finished compile at source code but when i connect MISO together
it doesn't work. only SS pin is connected separate Pin's to Micro
How can i make it work together to Micro..
i've checked each device perfectly work at Micro
Plese Help me!!
Regards and Thanks

So you have determined that they both work properly individually? When it doesn't work, do they both fail to work or only one?

yes. i've perfectly check both work properly.
it doesn't work both.. when i put MISO pin together.

MISO -> MOSI on the other device, as well as the other way around.

Each SPI device must have a separate device/slave select pin. The device must disconnect (high impedance state) when not selected. The SD shield will have a level shifter. It may not correctly disconnect from MISO.
Depending on what libraries you are using you might also need to check that they set the SPI hardware attributes correctly (clock, mode, etc).
For more help please post code and references to the shields and libraries.
Cheers!

i did it. you means do like 'digitalWrite(lcdCS,HIGH)' when i use SD Card Shield right?.. i don't know my code is wrong or not
i wonder is this possible to work at the same time two SPI device in Micro??

That is correct but you also need to check that the SD Card Shield does not drive the SPI MISO pin due to level shifter (such as resistors). The same goes for the LCD. It is possible; here is an example sketch, CosaCanvasBMP that loads a BMP file from SD and displays it on a ST7735.


text:
How to correctly pack an unsigned long from 3 unsigned chars?
I would like to use 652 unsigned long values on an Arduino Uno, but it doesn't look like there's enough memory. I thought about the splitting unsigned long values to 3 unsigned chars to store in PROGMEM which I can letter recall and join as unsigned long as needed.
I'm not super experienced with byte manipulations and I got myself stuck when trying to merge the data. When I try with one variable at a time, I get the expected output. The part I'm confused about is why do I get different values when using a variable as an array index for each value ? How can I fix this ?
Here's my test code so far:
#include <avr/pgmspace.h>
#include "flashData.h"

void setup() {
  Serial.begin(115200);
  unsigned long fromPROGMEM = (onsets1[0] << 16) | (onsets2[0] << 8) | onsets3[0];
  Serial.println(fromPROGMEM);

  unsigned long fromValues = (0x00 << 16) | (0x01 << 8) | 0xF3;
  Serial.println(fromValues);

  byte b1 = 0x00;
  byte b2 = 0x01;
  byte b3 = 0xF3;

  unsigned long fromBytes = (b1 << 16) | (b2 << 8) | b3;

  Serial.println(fromBytes);
  delay(2000);

  unsigned char c1,c2,c3;
  unsigned long value;

  Serial.println("data using same index:");
  for(int i = 0 ; i < 10; i++){
    c1 = onsets1[3];
    c2 = onsets2[3];
    c3 = onsets3[3];
    value = (c1 << 16) | (c2 << 8) | c3;
    Serial.print("index: ");
    Serial.print(i);
    Serial.print("\tvalue:");
    Serial.println (value);
    delay(10);
  }

  Serial.println("data using counter:");
  for(int i = 0 ; i < 10; i++){
    c1 = onsets1[i];
    c2 = onsets2[i];
    c3 = onsets3[i];
    value = (c1 << 16) | (c2 << 8) | c3;
    Serial.print("index: ");
    Serial.print(i);
    Serial.print("\tvalue:");
    Serial.println (value);
    delay(10);
  }
}

void loop() {

}

and flashData.h:
#ifndef _flashData_h_
#define _flashData_h_

static PROGMEM const unsigned char onsets1[652] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03};
static PROGMEM const unsigned char onsets2[652] = {0x01,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x25,0x26,0x28,0x29,0x2A,0x2B,0x2C,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x38,0x39,0x3A,0x3B,0x3C,0x3F,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x48,0x49,0x4A,0x4C,0x4D,0x4E,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x59,0x5A,0x5B,0x5C,0x5E,0x5F,0x61,0x63,0x64,0x65,0x67,0x6A,0x6B,0x6C,0x6D,0x6E,0x70,0x71,0x73,0x75,0x76,0x77,0x79,0x7C,0x7E,0x7F,0x80,0x82,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9E,0x9F,0xA0,0xA1,0xA2,0xA3,0xA4,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xC0,0xC2,0xC4,0xC6,0xC9,0xCB,0xCD,0xCF,0xD2,0xD4,0xD6,0xD8,0xDA,0xDB,0xDD,0xDF,0xE0,0xE2,0xE4,0xE6,0xE7,0xE8,0xE9,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF4,0xF6,0xF7,0xF8,0xF9,0xFA,0xFD,0xFE,0xFF,0x00,0x01,0x02,0x03,0x06,0x07,0x08,0x0A,0x0D,0x0F,0x10,0x11,0x12,0x13,0x14,0x16,0x18,0x19,0x1A,0x1C,0x1D,0x1F,0x21,0x22,0x23,0x25,0x28,0x2A,0x2B,0x2C,0x2E,0x30,0x31,0x33,0x34,0x35,0x38,0x3C,0x3D,0x3E,0x41,0x42,0x44,0x45,0x46,0x47,0x48,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x53,0x54,0x56,0x57,0x58,0x59,0x5B,0x5C,0x5D,0x5E,0x5F,0x60,0x61,0x63,0x65,0x66,0x67,0x69,0x6A,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x75,0x77,0x78,0x79,0x7A,0x7B,0x7D,0x7E,0x7F,0x80,0x82,0x84,0x87,0x89,0x8B,0x8E,0x90,0x92,0x94,0x97,0x99,0x9B,0x9D,0xA0,0xA2,0xA4,0xA5,0xA6,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB9,0xBA,0xBB,0xBD,0xBF,0xC0,0xC2,0xC4,0xC6,0xC7,0xC8,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,0xE2,0xE4,0xE6,0xE8,0xEA,0xEB,0xED,0xEF,0xF1,0xF2,0xF3,0xF5,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFF,0x01,0x03,0x04,0x05,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0F,0x10,0x11,0x12,0x13,0x15,0x16,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x20,0x21,0x23,0x24,0x25,0x27,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x30,0x32,0x33,0x35,0x36,0x37,0x3A,0x3B,0x3C,0x3E,0x40,0x43,0x44,0x45,0x47,0x48,0x49,0x4A,0x4C,0x4D,0x4E,0x50,0x55,0x56,0x57,0x59,0x5A,0x5B,0x5E,0x5F,0x60,0x61,0x62,0x63,0x65,0x66,0x67,0x68,0x69,0x6B,0x6C,0x6F,0x70,0x71,0x72,0x73,0x74,0x76,0x77,0x79,0x7A,0x7B,0x7D,0x7F,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x99,0x9B,0x9D,0x9F,0xA2,0xA4,0xA6,0xA8,0xAB,0xAD,0xAF,0xB1,0xB4,0xB6,0xB7,0xB8,0xBB,0xBD,0xBE,0xBF,0xC0,0xC1,0xC2,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCC,0xCD,0xCE,0xCF,0xD1,0xD3,0xD6,0xD8,0xDA,0xDC,0xDE,0xDF,0xE0,0xE1,0xE3,0xE4,0xE5,0xE7,0xE8,0xE9,0xEA,0xEC,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFE,0x01,0x03,0x04,0x05,0x07,0x09,0x0A,0x0B,0x0C,0x0E,0x10,0x12,0x13,0x14,0x15,0x17,0x18,0x1A,0x1C,0x1E,0x1F,0x20,0x21,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x34,0x35,0x37,0x39,0x3C,0x3E,0x40,0x42,0x43,0x45,0x47,0x49,0x4A,0x4B,0x4C,0x4E,0x50,0x52,0x53,0x54,0x56,0x57,0x58,0x59,0x5B,0x5C,0x5D,0x5F,0x60,0x61,0x62,0x64,0x66,0x68,0x69,0x6B,0x6C,0x6D,0x6E,0x70,0x71,0x72,0x74,0x75,0x76,0x78,0x79,0x7B,0x7C,0x7D,0x7F,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x8A,0x8B,0x8C,0x8D,0x8F,0x90,0x91,0x93,0x94,0x95,0x96,0x97,0x98,0x9B,0x9D,0x9F,0xA1};
static PROGMEM const unsigned char onsets3[652] = {0xF3,0x31,0x59,0x76,0x98,0xBA,0xDD,0xFF,0x43,0x66,0x88,0xAA,0xC7,0xEF,0x0B,0x2D,0x50,0x72,0x8E,0xB1,0xD3,0xF5,0x17,0x3A,0x5C,0x7E,0xA0,0xC8,0xE5,0x0D,0x29,0x6E,0x90,0xAC,0xD5,0xF7,0x13,0x35,0x58,0x7A,0x9C,0xB9,0xE1,0xFD,0x42,0x6A,0x86,0xA8,0xC5,0x0F,0x31,0x54,0x7C,0x92,0xB5,0xCB,0xF9,0x1B,0x43,0x60,0xA4,0xC1,0xE3,0x28,0x4A,0x72,0x8E,0xB1,0xD3,0xF5,0x17,0x34,0x5C,0x78,0xBD,0xDF,0x01,0x46,0x62,0x84,0xCF,0x0D,0x30,0x52,0x7A,0x91,0xD5,0xF7,0x1A,0x5E,0x86,0xA3,0xE7,0x26,0x5F,0x92,0xAF,0xF3,0x1B,0x32,0x5A,0x7C,0x9F,0xBB,0xE3,0x00,0x28,0x4A,0x66,0x89,0xAB,0xC7,0x0C,0x34,0x4A,0x72,0x95,0xB7,0xD9,0xFB,0x1E,0x3A,0x62,0x7F,0x9B,0xC3,0xE0,0x2A,0x52,0x69,0x91,0xB3,0xD5,0xF7,0x1F,0x36,0x58,0x80,0x9D,0xB9,0xE1,0xF8,0x42,0x65,0x81,0xA9,0xCB,0xE8,0x10,0x54,0x93,0xD2,0x16,0x60,0x9F,0xE4,0x28,0x6D,0xAB,0xF0,0x12,0x34,0x79,0xB2,0xDA,0x02,0x46,0x85,0xAD,0xCF,0xF2,0x0E,0x30,0x4D,0x75,0x97,0xB9,0xD0,0xFE,0x1A,0x65,0x87,0xA3,0xC5,0xE2,0x2C,0x4E,0x6B,0x8D,0xAF,0xD7,0xEE,0x38,0x5B,0x77,0xC1,0x00,0x45,0x67,0x89,0xAB,0xCE,0xF0,0x01,0x57,0x7F,0x95,0xDA,0xFC,0x1E,0x5D,0x7F,0x9C,0xE0,0x25,0x6F,0x91,0xAE,0xF2,0x14,0x3C,0x7B,0x98,0xBA,0x04,0x82,0xAF,0xCC,0x16,0x33,0x77,0x94,0xBC,0xD2,0xFA,0x1D,0x3F,0x61,0x7D,0xA6,0xC8,0xE4,0x29,0x51,0x8F,0xAC,0xCE,0xF0,0x13,0x35,0x57,0x79,0x9C,0xBE,0xE0,0x02,0x47,0x69,0x8B,0xCA,0xF2,0x31,0x53,0x75,0x98,0xBA,0xD6,0xF9,0x15,0x5F,0x82,0xA4,0xC6,0xE8,0x05,0x33,0x60,0x7D,0xBC,0xFA,0x3F,0x83,0xC2,0x0C,0x51,0x95,0xD4,0x18,0x5D,0xA1,0xE0,0x25,0x69,0xA8,0xD0,0xE7,0x0F,0x31,0x53,0x75,0x98,0xB4,0xDC,0xF9,0x1B,0x3D,0x5F,0x7C,0xA4,0xC0,0x05,0x21,0x49,0x88,0xD2,0xF4,0x11,0x55,0x94,0xBC,0xDE,0x1D,0x4B,0x62,0x8F,0xAC,0xF0,0x2F,0x57,0x74,0x96,0xB2,0xD5,0xF7,0x1F,0x3B,0x63,0x86,0xAE,0xC4,0xEC,0x09,0x47,0x8C,0xD0,0xF3,0x15,0x54,0x98,0xC0,0xE2,0x05,0x21,0x66,0x88,0xA4,0xD2,0xEF,0x39,0x72,0xBC,0xD9,0xFB,0x23,0x3F,0x62,0x84,0xA0,0xC3,0xF0,0x07,0x2F,0x4C,0x74,0x90,0xCF,0xF7,0x13,0x3B,0x58,0x74,0x9C,0xB9,0xDB,0x03,0x1F,0x6A,0x86,0xA3,0xED,0x0F,0x31,0x4E,0x76,0x92,0xB5,0xF9,0x27,0x38,0x7C,0xA4,0xC1,0x05,0x28,0x4A,0x8E,0xCD,0x11,0x3A,0x50,0x9B,0xBD,0xDF,0x93,0x24,0x40,0x68,0xA7,0x2A,0x58,0x74,0xB9,0xDB,0xF7,0x3C,0x5E,0x80,0xA3,0xC5,0xE7,0x09,0x2C,0x48,0x70,0x8D,0xD1,0xF9,0x38,0x54,0x77,0x9F,0xBB,0xDD,0x00,0x22,0x60,0x83,0x9F,0xE9,0x11,0x2E,0x50,0x72,0x95,0xB7,0xDF,0xFB,0x18,0x40,0x5C,0x7F,0xA1,0xB8,0x08,0x2A,0x46,0x6E,0x8B,0xAD,0xD5,0xFD,0x14,0x58,0x97,0xDC,0x20,0x59,0xA9,0xEE,0x32,0x71,0xB5,0xF4,0x38,0x77,0x99,0xC1,0x06,0x4A,0x6D,0x8F,0xAB,0xCE,0xF0,0x0C,0x34,0x57,0x79,0x95,0xBD,0xDA,0x02,0x1E,0x46,0x5D,0xA7,0xE6,0x25,0x6F,0xAE,0xF2,0x14,0x37,0x5F,0x7B,0xC0,0xE8,0xFE,0x21,0x43,0x6B,0x8D,0xC6,0x10,0x33,0x55,0x77,0x99,0xBC,0xD8,0x00,0x1D,0x45,0x5B,0x83,0xA0,0xE4,0x29,0x67,0x8F,0xAC,0xF0,0x18,0x35,0x63,0x79,0xB8,0xFD,0xC1,0x4D,0x6F,0x86,0xCA,0xF2,0x09,0x4D,0x92,0xBA,0xD6,0xF9,0x15,0x37,0x59,0x82,0xA4,0xBA,0xE8,0x05,0x27,0x49,0x6B,0x8E,0xAA,0xCC,0xEF,0x17,0x33,0x78,0xB6,0x01,0x3F,0x7E,0xC3,0xEB,0x07,0x4C,0x90,0xB2,0xD5,0xFD,0x19,0x5E,0xA2,0xBE,0xE1,0x03,0x25,0x47,0x64,0xAE,0xD6,0xED,0x15,0x31,0x59,0x76,0xB5,0xF9,0x1B,0x3E,0x7C,0xA4,0xC7,0xE9,0x0B,0x33,0x50,0x8E,0xB6,0xD9,0x01,0x11,0x56,0x7E,0x95,0xDF,0x9F,0x13,0x29,0x46,0x68,0x8A,0xAC,0xC9,0xEB,0x0D,0x2A,0x52,0x6E,0xAD,0xCF,0xF7,0x25,0x30,0x64,0x7B,0xA3,0xBF,0x09,0x42,0x8D,0xCB};

#endif

And here's what I see from Serial:
499
499
499
data using same index:
index: 0    value:1654
index: 1    value:1654
index: 2    value:1654
index: 3    value:1654
index: 4    value:1654
index: 5    value:1654
index: 6    value:1654
index: 7    value:1654
index: 8    value:1654
index: 9    value:1654
data using counter:
index: 0    value:4294945024
index: 1    value:4294962688
index: 2    value:12806
index: 3    value:28928
index: 4    value:4294948096
index: 5    value:4294964224
index: 6    value:14337
index: 7    value:30464
index: 8    value:4294940928
index: 9    value:4294951174

I see what I expect for first 3 values and also for data using same index, but no when using a variable as an index for the PROGMEM arrays.
What is going on and how can I fix this ?
Update
Mikael's answer is the solution, but I will post a working snippet here for reference:
#include <avr/pgmspace.h>
#include "flashData.h"

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

  unsigned char c1,c2,c3;
  unsigned long value;

  Serial.println("data using counter:");
  for(int i = 0 ; i < 652; i++){
    c1 = (unsigned char) pgm_read_byte(&onsets1[i]);
    c2 = (unsigned char) pgm_read_byte(&onsets2[i]);
    c3 = (unsigned char) pgm_read_byte(&onsets3[i]);
    value = (((unsigned long) c1) << 16) | ((unsigned long)c2 << 8) | (unsigned long)c3;
    Serial.print("index: ");
    Serial.print(i);
    Serial.print("\tvalue:");
    Serial.println (value);
    delay(10);
  }

}

void loop() {

}

The key is not only explicitly casting the data read, but also correctly reading the the PROGMEM data.

An unsigned long needs 4 unsigned chars.

Can you please expand ? In my case the data won't need a 4th unsigned char. I've tried (0 << 24) | (c1 << 16) | (c2 << 8) | c3 but the result looks the same.

You don't need to store onsets1. The values it holds are simple to generate at runtime. I'd also look at encoding the values in onsets2 differently, probably as a length and an increment. So the first pair would be 1 and 3, because there's one value (1), followed by an increment of 3 to produce 4. The next pair would be 7 and 3, because there are 7 sequential values (4, 5, 6, 7, 8, 9, A) and the next value is 3 more than the end of that sequence. Etc.

You can try (explict unsigned long values):
unsigned long fromValues = (0x00UL << 16) | (0x01 << 8) | 0xF3;
Serial.println(fromValues);

or:
value = (((unsigned long) c1) << 16) | (c2 << 8) | c3;

The issue is that the expression is implicit int and not long (as you are assuming). You need to tell the compiler about this.
An extra bonus comment: There is actually a 24 bit integer definition in AVR GCC according to the wiki, see Extensions, Types.
Cheers!

Thank you(+1) Mikael, explicitly casting to unsigned long makes sense. However I think this might not be the main issue. This part (unsigned long fromValues = (0x00UL << 16) | (0x01 << 8) | 0xF3; Serial.println(fromValues);) works as expected, this part value = (((unsigned long) c1) << 16) | (c2 << 8) | c3;  only works when I access the PROGMEM arrays using a constant value (e.g. c1 = onsets1[3]; works, c1 = onsets1[i]; produces strange results). I haven't used PROGMEM before, so maybe I'm retrieving/addressing data the wrong way ?

You need to add explicit read of PROGMEM: c1 = (unsigned char) pgm_read_byte(&onsets1[i]). Please see avr/pgmspace.h. I have also put together a more advanced example Sketchbook/ProgramMemory.

I got it to work by typecasting firmly and using multiplications:
  Serial.println("data using counter:");
  for (int i = 0 ; i < 10; i++) {
    c1 = onsets1[i];
    c2 = onsets2[i];
    c3 = onsets3[i];
    value = (uint8_t)c3 + (uint16_t)((uint8_t)c2*256)+(uint32_t)(c1*65536);
    Serial.print("index: ");
    Serial.print(i);
    Serial.print("\t");
    Serial.print(c1, HEX);
    Serial.print(", ");
    Serial.print(c2, HEX);
    Serial.print(", ");
    Serial.print(c3, HEX);
    Serial.print(" ");
    Serial.print("\tvalue:");
    Serial.println (value, HEX);
  }

The result:

data using counter:
index: 0    A1, F6, 0   value:A1F600
index: 1    FC, A7, 0   value:FCA700
index: 2    B5, 7A, B8  value:B57AB8
index: 3    EF, DB, 0   value:EFDB00
index: 4    14, F9, 0   value:14F900
index: 5    D7, 7F, 0   value:D77F00
index: 6    F2, 72, 1   value:F27201
index: 7    6F, DB, 0   value:6FDB00
index: 8    5E, 5E, 0   value:5E5E00
index: 9    F0, E7, B8  value:F0E7B8

Thank you (+1). The issue is that these aren't stored values in PROGMEM, so my issue might actually be about retrieving values from PROGMEM. If you look in the flashData.h, you'll see the first values should be 0x00,0x01,0xF3, not 0xA1,0xF6,0x00.


text:
Controlling 2 relays with IR remote, push button and bluetooth - sort of works, need help!
I'm still very new to arduino and coding and having some difficulties trying to figure out what I am doing wrong here.
This program is to have control over 2 relays, using a combination of an      IR receiver and a ir_remotecontrol with pre-programmed buttons (ir_remote buttons 1 = relay 1 toggle, button 2 = relay 2 toggle).
A master momentary hard wired switch to override changes to the relays and toggle their states i.e if both relays are on via ir remote - toggle them off, or if only 1 relay is on toggle it off with
first click of button then toggle both back on after second click of button.
The Bluetooth module and android app is to also control relays the same as the ir_remote via integers sent through the serial port.
It all sort of works at the moment...
If I just work the relays using the ir remote and the momentary switch it all works perfectly.
if I make sure the relays are in the off position using the remote switch and then use the Bluetooth it also works perfectly.
The problem only is when I use a combination of the ir remote or switch and the Bluetooth - things get weird - the Bluetooth commands seem to reverse and the relays start making a buzzing noise and the momentary switch muddles things up so basically it's all bad news! I've stared at this code for hours and tried a few different things but I just can't see what's wrong.
Let me know if I need to give a more detailed example of the errors I am having. Just thinking it is probably obvious for you pro's out there when you see my noob code!.
Any help would be greatly appreciated!
/*This program is to have control over 2 relays, using a cobination of   an IR reciever and remote control with pre programmed buttons    (ir_remote buttons 1 = relay 1 toggle, 2 = relay 2 toggle).
A master momentery hard wired switch to overide changes to the relays and toggle their states i.e if both relays are on via ir remote - toggle them off, or if 1 only relay is on toggle it off with first click of button then toggle both back on after sencond click of button.
Bluetooth module and andoid app to also control relays the same as the ir_remote.
 */
//include libaries, and initialise variables
#include <SoftwareSerial.h>
#include <IRremote.h>
#define irPin 8
#define RxD 7
#define TxD 6
#define relay1 13
#define relay2 12
#define buttonPin 2
SoftwareSerial blueTooth(RxD, TxD);
IRrecv irrecv(irPin);
decode_results results;
int comdata;
const int wait = 30;
int sensorValue = 0;
int sensorOut = 0;
int relay1State = 0;
int relay2State = 0;
int masterState = 0;
int buttonState = 0;
int lastButtonState = 0;
long lastDebounceTime = 0;
long debounceDelay = 50;

void setup()
{
  blueTooth.begin(38400);                     //set bluetooth baud rate
  delay(500);
  irrecv.enableIRIn();                        //enable infrared recieve
  pinMode(relay1, OUTPUT);                    //setting relays 1 & 2 to output
  pinMode(relay2, OUTPUT);
  pinMode(buttonPin, INPUT);                  //setting momentery swith (overide) to inpt
  digitalWrite(relay1, relay1State);          //putting current status of relays into a variable
  digitalWrite(relay2, relay2State);

}

void loop()
{
  if (blueTooth.available())                  //setting a variable for bluetooth recieved serial commands
  comdata = blueTooth.read();

  if(comdata == '1'){

  digitalWrite(relay1, relay1State);          //if bluetooth receivs "1" toggle relay1state -- essentially relay 1 ON
  }
  if(comdata == '0'){
  digitalWrite(relay1, !relay1State);         //if bluetooth receivs "0" toggle relay1state -- essentially relay 1 OFF

  }
  if(comdata == '2'){
  digitalWrite(relay2, relay2State);          //if bluetooth receivs "2" toggle relay2state -- essentially relay 2 ON

  }
  if(comdata == '3'){
  digitalWrite(relay2, !relay2State);         //if bluetooth receivs "3" toggle relay2state -- essentially relay 2 OFF
  }

  if (irrecv.decode(&results)){                     //Start listing for ir commands, if set remote button code is recvived toggle the variable relay1State or relay2state
  switch (results.value){
      case 0xFF30CF:
        relay1State = !relay1State;
        digitalWrite(relay1, relay1State);
        delay(250);
        break;
      case 0xFF18E7:
        relay2State = !relay2State;
        digitalWrite(relay2, relay2State);
        delay(250);
        break;
    }
    irrecv.resume();
    }

  int reading = digitalRead(buttonPin);          //debounce used to help with faulse readings from momentery switch
  if (reading != lastButtonState) {
   lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {

  if (reading != buttonState) {
      buttonState = reading;

  if (buttonState == HIGH) {                      //if the momentery switch is pressed toggle masterstate which is both relay 1 and relay 2 state
     masterState = !masterState;
     relay1State = masterState;
     relay2State = masterState;
      }
      }
    }

  digitalWrite(relay1, relay1State);
  digitalWrite(relay2, relay2State);
  lastButtonState = reading;

}

Do you want the relay pins to always match the relayStates?  If you get a "1" on the bluetooth, what do you intend to have happen?  Maybe write a "toggleRelayState(relayNumber){} and setRelayState(relayNumber,state) functions to handle all the state changes, and then invoke these identical functions from each input method.    Also, maybe add some debugging info with a Serial.print  and delay(1000) until you can diagnose what is going on.

You might also check the debouncing code.    It looks like the bracket after "lastDebounceTime = millis();" should be moved way down below "lastButtonState = reading;"

Hi Dave, thanks for taking a look at this for me. I'm sorry to be a pain, but I can't get my head around what you're asking me to do exactly. I am maybe trying to run before I can walk with all this. But I have to say I am learning quicker by just doing, rather than reading and forgetting! To answer your question - If I press 1 on the bluetooth I want it to turn on relay 1 if it is off or do nothing if it is already on.

Looking at this now I guess the blue tooth receive '2' & '3' are not necessary as I'm just setting an opposite value for their respective 'relayState's'? I've removed them for now and added:
    if(comdata == '1'){

relay1State = !relay1State;
digitalWrite(relay1, relay1State);
but still not working as I'd hoped

" If I press 1 on the bluetooth I want it to turn on relay 1 if it is off or do nothing if it is already on." -- for this I'd say "if(comdata == '1') {relay1State = 1;digitalWrite(relay1, relay1State);}" to remember the desired state in  relay1State and set the output to match.  Otherwise, the 3rd to last statement in the currently posted code will reset the output to zero, since the relayState1 was unchanged by the bluetooth command.

Re: "Looking at this now I guess the blue tooth receive '2' & '3' are not necessary" don't you want to control relay2 with the bluetooth as well?  If so, you do need some processing to control relay2.  Maybe I am being confused by your usage of 'toggle' in your post. From your comment it seems like bluetooth=='1'  implies relay1 = on, while from your post it seems like bluetooth=='1' implies relay1 = ! relay1.

Thanks again Dave, however still not working right after changing the BT statements to what you sugested. It all sort of works but for example if I now turn on relay 1 with the BT and then try to turn it off with the IR remote it just blinks off and then stays back on again.
Sorry to be confusing, I do want to control the second relay as well, What I was meaning by 2 & 3 not being necessary was that instead of having an on and an off button for each relay in the android app I could just have 1 button that would toggle the relay on or off or basically the opposite of what it is currently at.

The end goal for this little project wouuld be to have 2 LED strips controlled through the relays for my kitchen cabinets. Having a fixed button for a quick on/off, then an IR remote to toggle each on/off and bluetooth/wifi too for fun. Weather or not I actually implement that I'm not sure, but i though it a reasonable first arduino project to take, although it seems more complicated than I had initially though...maybe I need to go back to BLINK! :)

Dave my man!!! :D The updated code you posted below with the switch case functions has solved my problems! So is the switch a better method because it doesn't keep writing 1's or 0's flat out, it just does it once? Thanks so much for your help!

No, the switch is merely an alternate to the set of ifs.  Enclosing it within the "if (blueTooth.available()) {...}" statement makes it happen only once per bluetooth character, contrary to the bare if()s in your posted code, which are able to trigger each loop()   Also, since the state variables are updated to explicit 1 or 0 values, it doesn't matter if they get reset/rewritten to the same values.

ah ok, that makes perfect sense. Well then, looking at my box of random bits I wonder what else I can throw in..might try a status LED and maybe a status notification peizoelectric speaker....or... :D this is fun! Thanks again for all your help!!!  I'm sure you'll here from me soon! But I'll try not to bother you again! ;)

Looks like it could be reusing the old comdata values in the first part of loop().  Maybe make the first chunk:
   if (blueTooth.available()) {
      comdata = blueTooth.read();
      switch (comdata) {  // set state variables based on bluetooth
      case  '0':  // if bluetooth receivs "0" clear 1
          relay1State = 0;
          break;
      case  '1':  // if bluetooth receivs "1" set 1
          relay1State = 1;
          break;
      case  '2':  // if bluetooth receivs "2" set 2
          relay2State = 1;
          break;
      case  '3':  // if bluetooth receivs "1" clear2
          relay2State = 0;
          break;

      case  '4':  // if bluetooth receivs "4" toggle 1
          relay1State = !relay1State;
          break;
      case  '5':  // if bluetooth receivs "5" toggle 2
          relay2State = !relay2State;
          break;
      case  '6':  // if bluetooth receivs "6" toggle master/both
          masterState = relay1State = relay2State = !masterState;
          break;
      }  // end of switch
      // apply state variables to outputs
      // (could be left to the end of the loop() code)
      digitalWrite(relay1, relay1State);
      digitalWrite(relay2, relay2State);
   } // end of bluetooth processing

   ... /// IR processing code

   // debounce button and toggle masterstate & set state vars accordingly
   // see http://arduino.stackexchange.com/questions/17443/how-to-simulate-delay-to-debounce-mechanical-button-using-millis
   //

// re-ensure output state matches the state variables.
digitalWrite(relay1, relay1State);
digitalWrite(relay2, relay2State);
}

As it is, the if() statements trigger on the state of the last read comdata, not on the whether a new command was read.
Also, maybe check whether the toggling comments match the code or the code matches the intention properly.

Stmt relay1State = relay1State; has no effect

True.  I'm not sure if the Poster wants the comdata==?? inputs to toggle or actually change the state variables or not.

Thanks for your reply. I tried the changes you suggested but to no avail..
As for my comments - they're probably very wrong as I'm really just getting to grips with arduino and coding, how I think the code works and how it probably works are usually 2 different things, but every day I think  I grasp a little more. And having you guys to guide me when I am stuck really helps too!
Thanks,
Michael

Only the button changes relay1State and relay2State. The IR and BT only change the pin using digitalWrite. But then in the last 3 lines, the pin is changed back to the value of relay1State and relay2State.
I think for the IR and BT you need to change e.g. digitalWrite(relay2, !relay2State); to relay2State=false; etc.
PS It there a pull-up/pull-down resistor on the button pin?

Thanks for the reply! I have tried making the changes you suggested but it didn't help - unless of course I am not doing it correctly (very possible!)
I tried changing the both IR statements to relay2State=false and then also the BT. I also tried changing the BT to True for the on state and false for the off state but that didn't help either?
I have a pull-down resistor on the button pin.
Thanks again.

You need to change all digitalWrites except for the last two, right?

Yeah, tried all except the last 2. I can only turn the relays on but not off.


text:
Error in modification on MPU6050_DMP6
I made modifications on the original code of DMP6 MPU6050 to make it as I want. I took the standard libraries with it and they are helper_3dmath.h, MPU6050.cpp, MPU6050.h, MPU6050_6Axis_MotionApps20.h, I2C.cpp and finally I2c.cpp.
I made a main.ino and get_angles.cpp, which contains the code that has the function that calculates the angles out of the MPU6050. And a header file get_angles.h. I am getting an error that I can't figure out.
My main.ino is:
#include <Wire.h>
#include "get_angles.h"
angles imu ;
MPU6050 mpu;
void setup() {
    Wire.begin();
     TWBR = 24;
     Serial.begin(115200);
     mpu.initialize();
     mpu.setDMPEnabled(true);
     packetSize = mpu.dmpGetFIFOPacketSize();
}

void loop() {
  int yaw,pitch,roll;
  yaw =imu.get_yaw();
  pitch=imu.get_pitch();
  roll=imu.get_roll();
}

get_angles.cpp
#include "get_angles.h"
int angles::get_yaw() {
  MPU6050 mpu;
  mpuIntStatus = mpu.getIntStatus();
  fifoCount = mpu.getFIFOCount();
  // check for overflow (this should never happen unless our code is too inefficient)
  if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
    // reset so we can continue cleanly
    mpu.resetFIFO();
    Serial.println(F("FIFO overflow!"));
    // otherwise, check for DMP data ready interrupt (this should happen frequently)
  } else if (mpuIntStatus & 0x02) {
    // wait for correct available data length, should be a VERY short wait
    while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
    // read a packet from FIFO
    mpu.getFIFOBytes(fifoBuffer, packetSize);
    // track FIFO count here in case there is > 1 packet available
    // (this lets us immediately read more without waiting for an interrupt)
    fifoCount -= packetSize;
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
    int yaw;
    yaw=ypr[0] * 180/M_PI;
    return(yaw);
  }
}

int angles::get_pitch() {
  MPU6050 mpu;
  mpuIntStatus = mpu.getIntStatus();
  fifoCount = mpu.getFIFOCount();
  // check for overflow (this should never happen unless our code is too inefficient)
  if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
    // reset so we can continue cleanly
    mpu.resetFIFO();
    Serial.println(F("FIFO overflow!"));
    // otherwise, check for DMP data ready interrupt (this should happen frequently)
  } else if (mpuIntStatus & 0x02) {
    // wait for correct available data length, should be a VERY short wait
    while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
    // read a packet from FIFO
    mpu.getFIFOBytes(fifoBuffer, packetSize);
    // track FIFO count here in case there is > 1 packet available
    // (this lets us immediately read more without waiting for an interrupt)
    fifoCount -= packetSize;
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
    int pitch;
    pitch=ypr[1] * 180/M_PI;
    return(pitch);
  }
}

int angles::get_roll() {
  MPU6050 mpu;
  mpuIntStatus = mpu.getIntStatus();
  fifoCount = mpu.getFIFOCount();
  // check for overflow (this should never happen unless our code is too inefficient)
  if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
    // reset so we can continue cleanly
    mpu.resetFIFO();
    Serial.println(F("FIFO overflow!"));
    // otherwise, check for DMP data ready interrupt (this should happen frequently)
  } else if (mpuIntStatus & 0x02) {
    // wait for correct available data length, should be a VERY short wait
    while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
    // read a packet from FIFO
    mpu.getFIFOBytes(fifoBuffer, packetSize);
    // track FIFO count here in case there is > 1 packet available
    // (this lets us immediately read more without waiting for an interrupt)
    fifoCount -= packetSize;
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
    int roll;
    roll=ypr[2] * 180/M_PI;
    return(roll);
  }
}

get_angles.h
#ifndef get_angles_H
#define get_angles_H

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
static   uint16_t packetSize;
class angles {
  public:
    int get_yaw();
    int get_pitch();
    int get_roll();
  private:
    uint8_t mpuIntStatus;
    uint16_t fifoCount;     // count of all bytes currently in FIFO
    uint8_t fifoBuffer[64]; // FIFO storage buffer
    Quaternion q;           // [w, x, y, z] quaternion container
    VectorFloat gravity;    // [x, y, z] gravity vector
    float ypr[3];           // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
};
#endif

The error I am facing:
Arduino: 1.6.5 (Windows 8.1), Board: "Arduino/Genuino Uno"

third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpInitialize()'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpPacketAvailable()'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetAccel(long*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetAccel(int*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetAccel(VectorInt16*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetQuaternion(long*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetQuaternion(int*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetQuaternion(Quaternion*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetGyro(long*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetGyro(int*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetGyro(VectorInt16*, unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetLinearAccel(VectorInt16*, VectorInt16*, VectorFloat*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetLinearAccelInWorld(VectorInt16*, VectorInt16*, Quaternion*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetGravity(VectorFloat*, Quaternion*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetEuler(float*, Quaternion*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetYawPitchRoll(float*, Quaternion*, VectorFloat*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpProcessFIFOPacket(unsigned char const*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpReadAndProcessFIFOPacket(unsigned char, unsigned char*)'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
third_iteration.cpp.o: In function `MPU6050::dmpInitialize()':
C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/MPU6050_6Axis_MotionApps20.h:325: multiple definition of `MPU6050::dmpGetFIFOPacketSize()'
get_angles.cpp.o:C:\Users\MOHAME~1\AppData\Local\Temp\build384877420483334776.tmp/helper_3dmath.h:56: first defined here
collect2.exe: error: ld returned 1 exit status
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

The error, if you read it, doesn't relate to any of those files, it relates to MPU6050_6Axis_MotionApps20.h. Maybe you should have included that file too?  Oh, and helper_3dmath.h

yeah i know that but i declare #include "MPU6050_6Axis_MotionApps20.h" in my header and in it the declearation of the other like helper_3dmath and the other libraries as i said before in the main post .... and btw that is the original dmp code so .. if i took this libraries and put besides jeff code it will work prefectly  @Majenko

Well, that i2cdev library code you have to treat with real kid gloves. Mess with it at your peril. The way it's been written breaks all the rules of good coding and the author should be strung up by his danglies. If he'd been in my employ and had written that code I'd have sacked him on the spot. Good luck with messing with it - you're a braver man than I. I'd start by re-writing the whole library suite properly.

i didn't missed with anything i just took his main and put it in cpp and make his decleration in header then called this class i have done in cpp file .... so i didn't miss with anything .... and that why i am really angry ... i didn't do anything to the code just copy and paste and the error is muilti-defination ... anyway thank you @Majenko

And that's all you really need to do to break it, it's written that poorly.  The whole problem can be summed up in four words: "Functions in Header Files"

ok ... i am in my first steps in coding ... if it is not rudeness can you tell me what i can do to take the original code and don't break it ... thanks in advance and of course make it parts as cpp and header  @Majenko

You need to split it all apart properly so that the functions aren't in the header files, but instead are in cpp files where they should be.


text:
Arduino Variable Data Type?
Is there a variable data type available for Arduino? I have a class that should have a member that will differ in data type, in the past I have used the "variable" keyword in c++ but when I tried to use it the compiler yelled at me. I searched online and found a couple of articles that mentioned that if you are using an alternate GUI (I am using eclipse mars) that you can enable the feature but I can not find the correct settings as the examples I had found were for Juno and below.
Here is an example of what I am trying to accomplish
class DisplayItem{

   public:
   variant *displayVar;

   void Display(){
      Serial.println(displayVar);
   }
}

int intDisplay;
String strDisplay;

DisplayItem item();
item.displayVar = &intDisplay;
item.Display();
item.displayVar = &strDisplay;
item.Display();

I realize I could create a overloaded function to display different data types but it would be allot easier if I could simply assign a reference to a variant datatype and reuse the variable.

Edit
So after looking through the answers I think I have this figured out. I needed to keep track of which variable was being set, I put together a quick example in hopes it will help someone else out with the same question.
class DisplayItem{

   private:
   int iVarType;

   union{
      int *i;
      float *f;
   } displayVar;

   public:
   void SetVar(int *var){
      displayVar.i = var;
      iVarType = 0;
   }

   void SetVar(float *var){
      displayVar.f = var;
      iVarType = 1;
   }

   void Display(){
      if (iVarType == 0){
         Serial.println(displayVar.i);
      }else if (iVarType == 1){
         Serial.println(displayVar.f);
      }
   }
}

int intDisplay = 1;
float floatDisplay = 0.123;

DisplayItem item();
item.SetVar(&intDisplay);
item.Display();
item.SetVar(&floatDisplay);
item.Display();

Will Display:
1
0.123

For the situation illustrated in the question – displaying data – polymorphic functions already exist, and might as well be used in this case.  Specifically, use the Streaming.h contributed library.  It adds some “syntactic sugar” to Arduino C.  At compile time it converts C++-like << Serial stream operators to Serial.print statements, without increasing code size.  You can install it via Streaming5.zip from arduiniana.org .
In other cases, a union data structure allows treating an area of memory different ways.  Wikipedia's Union type article explains the general idea.  See eg tutorialspoint.com/cprogramming for union syntax and usage.  For some reason, arduino.cc's Language Reference page hasn't got union on its list of language features.  However, mcgurrin.com has a page called There is Power in a Union that codes a simple Arduino C example two ways (where bearing is an int):
higherByte = compass.read();
lowerByte = compass.read();
bearing = ((higherByte<<8)+lowerByte)/10

-vs-
union Data {
  byte b[2];
  int value;
};
...
union Data data;
data.b[0] = compass.read();
data.b[1] = compass.read();
bearing = data.value/10;

Would you then use sizeof(data.b[0]) to determine if the variable has been used or is there a better way?

sizeof data.b[0] (the parentheses aren't needed if the argument is a variable rather than a type) is a constant, so has no bearing on whether a section of memory has been set to a value.  Use a separate flag variable or some program flow analysis to keep track of whether a cell is occupied.  Note, union is most useful in certain type conversions (eg changing endianness among integer types or getting the exponent field of a float) or when marshalling data for export, eg filling a buffer with a variety of data items before using a write to send the buffer on its way.

No, there is no such thing.  The whole concept of "type" only exists during compilation, not at run-time.
However, you can "emulate" it using "setters" and keeping your own internal state information:
class Thing {
    private:
        String *strvar;
        int intvar;
        int type;

    public:
        void set(int val) {
            intvar = val;
            type = 1;
        }
        void set(String &str) {
            strval = &str;
            type = 2;
        }
        void Display() {
            if (type == 1) {
                Serial.print("Value: ");
                Serial.println(intval);
            } else if (type == 2) {
                Serial.print("String: ");
                Serial.println(strval);
            } else {
                Serial.println("Something went wrong");
            }
        }
};

Thing t;
String s = "This is a string";
int i = 23;
t.set(s);
t.Display();
t.set(i);
t.Display();

The multiple functions named the same but with different parameters are overloaded. The best match is picked at compile time.

I have in my question about using overloaded functions, I was hoping that there was a variable datatype as I have seen it in other c++ platforms. But if this is the only way to accomplish this I guess I don't have much choice.

It's down to the IDE preprocessing your code with its own keywords. The closest is a void * pointer which can point to the memory of any data type, however it doesn't have any concept of what that datatype is - it's just memory.

Actually modern C++ provides run-time type information for classes. See Wiki for some examples. Unfortunately this is often disabled when compiling for small scale embedded systems to reduce memory foot-print. Last, in @Majenko 's example the value could be stored in a union. See Cosa/Types.h univ16_t and univ32_t for examples of universal type.

You mean dynamic_cast? Only useful when you're working with polymorphism.


text:
Trouble with Timer 0
I'm taking my first wobbly steps outside the Arduino IDE and I'm not having much success with timers / interrupts. I can set a pin to output and light an LED with registers fine but I cannot for the life of me get it to blink using a timer. I have tried numerous tutorials and followed the Atmel ATmega328 datasheet very closely.
Using an Arduino Uno R3 & Atmel ICE (ISP.) My dev system is Raspbian (Debian) with the GNU AVR toolchain (avr-gcc, avr-objcopy, avrdude.) Apart from not having a bootloader it's a bog standard board (including fuses.)
Here's my current code:
#include <avr/io.h>
#include <avr/interrupt.h>

ISR(TIMER0_COMPA_vect)
{
    PORTB ^= (1 << PB5); // Toggle Arduino Pin #13
}

int main (void)
{
    DDRB = (1 << DDB5); // Arduino Pin #13 is Output

    cli(); // Clear Interrupts

    OCR0A = (unsigned char)0xFF; // Compare Register A = 255
    TIMSK0 = (1 << OCIE0A); // Enable Interrupt for Comp. Reg. A
    TCCR0A = (1 << WGM01); // CTC Mode

    sei(); // Set Interrupts
    TCCR0B = (1 << CS02) | (1 << CS00); // Divide by 1024 Prescaler (GO!)

    return 0;
}

I don't know if I'm just not seeing something or if I've set registers in the wrong order but it's driving me crazy.

doesn't return 0 reset the device? Try while(1); to make it wait indefinitely.

I am going to scream. Thank you!
(Do you do the Answer Question thing or do I?)

The commenter should convert it into an answer.

return 0 resets the device. Use while(1); instead, to make it wait indefinitely.

Just to clarify, doing a return from main does not reset the device, as I showed in my answer. I mention this in case people read this answer and think that returning from main is an easy way of achieving a device reset.

Returning from main does not reset the device (it would start up again and do it all over in that case). It calls exit which turns interrupts off and loops indefinitely.
00000068 <__ctors_end>:
  68:   11 24           eor r1, r1
  6a:   1f be           out 0x3f, r1    ; 63
  6c:   cf ef           ldi r28, 0xFF   ; 255
  6e:   d8 e0           ldi r29, 0x08   ; 8
  70:   de bf           out 0x3e, r29   ; 62
  72:   cd bf           out 0x3d, r28   ; 61
  74:   0e 94 52 00     call    0xa4    ; 0xa4 <main>
  78:   0c 94 61 00     jmp 0xc2    ; 0xc2 <_exit>

...

000000a4 <main>:
  a4:   80 e2           ldi r24, 0x20   ; 32
  a6:   84 b9           out 0x04, r24   ; 4
  a8:   f8 94           cli
  aa:   8f ef           ldi r24, 0xFF   ; 255
  ac:   87 bd           out 0x27, r24   ; 39
  ae:   82 e0           ldi r24, 0x02   ; 2
  b0:   80 93 6e 00     sts 0x006E, r24
  b4:   84 bd           out 0x24, r24   ; 36
  b6:   78 94           sei
  b8:   85 e0           ldi r24, 0x05   ; 5
  ba:   85 bd           out 0x25, r24   ; 37
  bc:   80 e0           ldi r24, 0x00   ; 0
  be:   90 e0           ldi r25, 0x00   ; 0
  c0:   08 95           ret

000000c2 <_exit>:
  c2:   f8 94           cli

000000c4 <__stop_program>:
  c4:   ff cf           rjmp    .-2         ; 0xc4 <__stop_program>

You can see at address 0x74 it calls main, and then jumps to exit. exit turns off interrupts.
With interrupts off your ISR will not toggle pin 13.


text:
Issue in installing Arduino unit library and running with Firmata test application
I am trying to update the Arduino library via the library manager and I tried to download it from the link given in the firmata_test program:

WARNING: Category '' in library ArduinoUnit is not valid. Setting to
  'Uncategorized'
  C:\Users\SAURAB~1\AppData\Local\Temp\arduino_c8217a5b56c170d64dfe4c80a1a205dc\firmata_test.ino:
  In member function 'virtual void test_beginPrintsVersion::once()':
C:\Users\SAURAB~1\AppData\Local\Temp\arduino_c8217a5b56c170d64dfe4c80a1a205dc\firmata_test.ino:32:3:
  warning: narrowing conversion of '249' from 'int' to 'char' inside { }
  [-Wnarrowing]
};
^
Multiple libraries were found for "Firmata.h"  Used:
  C:\Users\saurabh2836\Documents\Arduino\libraries\Firmata  Not used:
  C:\Program Files (x86)\Arduino\libraries\Firmata

I'm getting this error. I searched but found no conclusive answer. I'm using Windows 8 64bit and Firmata downloaded from http://www.firmata.org/.
Am I doing something wrong?

The compiler is giving a lot of information. The warnings can be ignored but the "multiple libraries" indicates that there is at least two copies of Firmata installed. Check (search) that you have not got several downloads of Firmata. Worst case reinstall to clean up that.
Cheers!

but what about Category '' in library ArduinoUnit error what are the step to replace adruino unit library

That is from the library manager when reading the library.properties file. The category tag is not correct (actually missing) for ArduinoUnit. https://github.com/mmurdoch/arduinounit/blob/master/library.properties. It is a warning and can be ignored.

but i am not able to run the program for test firmata after reinstall it

But does it compile? This issue was about compiling it. Are there still compile warnings and errors? Did the "multiple libraries..." link error disappear? I was assuming that you had an installation problem.

no still the same issue

You have to remove one of the two libraries. Currently there is two copies of the library installed. Both get located and compile (according to the error message from the linker).

Did you still get: "Multiple libraries were found for "Firmata.h" Used: C:\Users\saurabh2836\Documents\Arduino\libraries\Firmata Not used: C:\Program Files (x86)\Arduino\libraries\Firmata". The compiler is telling you where the two libraries are. Remove one of them.

i solved the issue of library loading double but now that firmata test program is not working i am not able to controller high/low from firmata to arduino


text:
Arduino Mega, ST7920 using COSA
I am trying to learn and understand the COSA Library using a 12864ZW (ST7920) 128X64 LCD Display. Right now I am able to use the LCD using the u8glib but also found that COSA has a library for the ST7920 Display, I originally used this tutorial to get things working.
The main problem that I have now is in the ST7920 Documentation there is a schematic that shows how to hook up a ST7920 Compatible LCD. The first tutorial only uses 3 lines from the Mega and the Cosa is using what looks like 6 lines.
Looking at the header file, it looks like it is derived from the HD44780 Class and what I can gather is pins 16 and 4 are hard coded for something? I am not quite clear on how to use the Cosa version of the library. Can someone please give me a explanation and perhaps a explanation on how to get this working using Cosa?

The Cosa ST7920 library uses text mode only (16X4). The ST7920 class is controlled though an adapter. There are several adapters available depending on how you wish to connect to the Arduino. They range from parallel 4-bit to SPI with shift register. The adapters implement the interface HD44780::IO. There are several LCD examples. The CosaLCDbench shows the possible configurations with LCD and Adapters. Please see the file for further details.

I saw that there are many examples but I can not for the life of me get this to compile, I opened another question at http://arduino.stackexchange.com/questions/18358/eclipse-add-library. I see that you are on the GIT for COSA can you give me any advise to get this to compile?


text:
Arduino Not Working as Intended when using barrel jack
I am using an Arduino to control some mechanical components in a project I have. It controls a motor, two servos, a valve, and a compressor. When plugged into the computer, everything works fine and perfectly. However, when I power it through the barrel jack using our power supply, some weird things happen. First of all, our servos, which are powered through the Arduino, stop working. All the other components work except for them. Secondly, at the end of the code we have a 5 second delay. Using the computer it works fine. When powered with our supply the delay doesn't seem to happen at all. Any ideas?

You say the servos  are powered through the Arduino.   How are the  motor/valve/compressor powered?  What voltage do you read on the +5V line in the two different ways of powering the Arduino?  How's the +5V line look on a scope ?  Re the 5 second delay, if you have an LCD you can attach, display millis() before and after the delay() call

The motor, compressor, and valve are powered with our 12v battery, which is what the arduino runs on when not plugged in. I am not near my setup right now, so unfortunately I can't take those measurements until later, but I'll check them for sure.

You should not power servos through an Arduino.  Even if they have to use the same supply they should have their own wiring.  They should not use the Arduino's regulator.

I believe that the problem that you are facing is lack of power. It is likely that your power source cannot supply enough current or voltage to power the equipment AND the arduino. Try to get a power supply that has more amps.

This could be the case, but I doubt it. Our power supply is a large 12v battery. It looks like a car battery. I can try turning the motor off while the servos are running to see if that will fix it, but I have a feeling the battery should be powerful enough.

It could be that the 5V regulator on the Arduino is unable to provide enough power. Many USB ports now can provide many amps, but the 5V regulator is limited to 800mA.  How hot does the regulator get?

This might be the case. The regulator does get warm, so maybe we are reaching our current limit.

If there is a large amount of voltage, but you circuit is still drawing lots of current, then the circuit will remain unpowered.

@solver - that is untrue.  If the circuit is drawing sufficient current that it is "unpowered" then there will not be a large voltage either, rather it will have sagged below the "open circuit" rating of the regulator or supply.

@ChrisStratton I apologize for my lack of knowledge in this field.

i agree with majenko, maybe you know how to fix it but if you do not know here is a site with good information to make you're own  5 volt Regulated source.
http://www.rakeshmondal.info/IC-7805-Voltage-Regulator
sorry for my bad english and good luck. :D

I had a similar problem recently while powering a servo with a Arduino.
It did turn out to be power, our Arduino could only supply about 500ma and with sufficient speed or torque on the servo (a lot of times just the boot sequence) we would it the 500ma at peak, the effect however was baffling at first because when we hit the peak current the Arduino would reboot, this could account for you extra delay at the end.
For us the solution was simple bypass the Arduino when supplying current to the servos, in our case it as a 5v battery, you would probably need to drop the 12v to 6v in your case.


text:
Eclipse add library
I am completely lost here, I have no idea what I am doing wrong. I am using Eclipse Mars using the Eclipse C++ Arduino extension. I am also using the COSA library, this is where the problem comes in. I can use all of the core COSA libraries but I can not figure out how to include the other libraries that are supplied with COSA specifically the ST7920.h file that is located in the libraries folder. Does anyone have any experience with this?
I have tried setting the path using the Project->C/C++ General->Preprocessor include paths and setting it there to no avail.
One thing that I am concerned about is in these separate libraries they are including files that are in other libs using only the header file, for example in the ST7920.hh file it has:
#include "Cosa/LCD.hh"
#include <HD44780.h>

I need to configure things so that the HD44780.h file needs to be found also. That file is located at "../HD44780/HD44780.h". How do I tell the compiler to search the "libraries" folder for files?
Also I tried to simply add the libraries folder as a linked folder in my project, that also did not work.
the only code I have is the #include  and the compiler come back with that it can't find the file.

FWIW I have stopped using Eclipse Arduino plugin and replaced my whole environment with Netbeans 8 (note: I also use Cosa core and several of its libraries). Although it took me quite some time to configure from scratch, now I have a working setup that works just fine.

@jfpoilpret. Love Netbeans. How good is Arduino integration?

Netbeans integration was not straightforward but it worked well once done. I did not use any specific plugin for it.

I would advice to use the arduino eclipse plugin and not use the eclipse C++ arduino extension.
The eclipse C++ arduino extension is still very much in development.
The Arduino eclipse plugin has been around for years and contains far more features.
If you use V3 (that is still the nightly at the time of writing) you can use the boards manager and the cosa json file to import the cosa boards.
Importing a lib is a matter of typing
#include "libname"

and saving.

If you are using Linux I would recommend looking at the makefile based build script for Cosa (See Cosa/build). After configuration building from any IDE is more or less a simple command. No Makefile is required. The script cosa will do all the work.
$ cosa BOARD ACTION

such as
$ cosa uno avanti

which will build a sketch for Arduino Uno, upload and start a serial monitor. This can be used from any IDE. I use GNU Emacs, M-X compile (F2), with the command.
The way the Arduino pre-processor works each referenced library needs to be included in the sketch. For a sketch that uses ST7920:
#include <HD44780.h>
#include <ST7920.h>

I am on Windows not Linux, is there a Windows version of the script? It seems to me that I should be able to simply add the Libraries folder to Eclipse somewhere to point it to the right folder.

You should be able to configure Eclipse to add include paths for the necessary libraries. This is basically what the pre-processing in the Arduino build is doing (i.e. finding and adding include paths for the compiler).

Right that is my point exactly, I just don't know how this is done, everything that I have tried to link the libraries does not work, I have tried importing the entire libraries folder as a linked folder. I tried adding both the libraries folder and the ST7920 folder as include folders, library folders etc.

I tried to install the regular Arduino IDE and installed Cosa through the additional boards manager and the extra libraries were listed in the libraries. I was able to compile it through the Arduino IDE. Can you think of anything that I might be missing with Eclipse? This really sounds like a very good library and really want to get this working as it is perfect for my current project.

authors: Алексей Кладов


text:
SPI Interface between Arduino UNO and EVK1100
I'm using Arduino Uno board as master and AVR32UC3A0512 as slave. I've written code for arduino using SPI.h library, and Atmel Studio 6.2 using spi.h. I'm sending data from arduino to atmel i.e from SPDR register in arduino to RDR register in Atmel, but the data is not getting recieved. Hence, I'm not able to read the data. I've successfully interfaced SPI between two arduino boards and I'm using the same Arduino Master code while interfacing it with slave EVK. I've also set the baud rate same, I'm not sure what the problem might be. Can anyone please help me out?

Please edit your question to include code, preferably compilable/runnable code that is minimal and exhibits the problem.   That may allow someone with comparable boards to help debug the problem. [To format the code here, highlight it then click the code icon above the edit box, or press F4 iirc]  Also show a wiring diagram or table or a photo of setup

As you have not responded to the request to post the problem code, I am going to close this question as "unclear what you are asking". We can't tell you why code - which we cannot see - doesn't work. Particularly without details about the connections. Please read How do I ask a good question?. Feel free to edit the question with new information. Thanks for your understanding and cooperation!


text:
What does the bootloader do?
As far as I understand it checks for a valid serial connection (new program incoming) and then either writes it to flash or starts executing the existing program.
Can't the 32u4 or EDBG fill the role of an ISP and program the MCU instead of the MCU self-programming? I know the EDBG is accessed via OpenOCD to write the bootloader to the SAMD21 on Arduino Zero boards so why is the bootloader even required?

The bootloader is there for convenience.
Yes, you understand what the bootloader does and how it operates.  However, you have missed out one benefit, and that is evident when you're not using the bootloader.  That is, when you're not using the bootloader the same connection can be used for a serial connection to the PC.  If the 32U4 were directly programming the main MCU then it would be talking to the SPI pins not the UART pins, so you would need a second connection, or both a connection to the UART and the SPI pins, and much more complex firmware on the 32U4, in order to get a serial connection to the PC.
So the simplest option is just to have a dumb pass-through interface from the USB to the UART pins and have the main MCU self program with a bootloader.
It also means that you don't need any special programming hardware when making your own board - just something (another arduino maybe) to get the bootloader on there in the first place (or buy the MCU pre-programmed) and then use any TTL serial interface to program it with your main program.

Surely the 32U4 firmware wouldn't be that much more complex to have it switch between SPI and UART depending on the serial connection speed? (iirc it's 1200 baud to program.)

@AshlynBlack But it's complexity that isn't needed, and would mean you need a special programmer to do anything with your own breadboard Arduino. It is far more convenient for most people to use a UART bootloader. Those that don't want a bootloader use a hardware programmer anyway, so it's a non-argument.


text:
Message received with 1 character less
I have the following situation:
One Arduino Uno with a 433mhz transmitter wired to the laptop to have serial communication. Another Arduino Uno with a 9V battery wired with a 433mhz receiver and an LCD screen (16x2, I2C).
I have the following code to transmit:
#include <VirtualWire.h>

void setup() {
  //Force low when enabled
  vw_set_ptt_inverted(true);
  //Set pin 12 for transmitter
  vw_set_tx_pin(12);
  //Setup with speed of the data transfer.
  vw_setup(4000);
  //Set serial communication at 9600 baud
  Serial.begin(9600);//set Serial
  //Set pin 13 to light up when transmitting
  pinMode(13,OUTPUT);
}

void loop() {
  //If message send via serial monitor
  if (Serial.available()) {
    //wait a bit for the entire message to arrive
    delay(100);

    while (Serial.available() > 0) {
      //Read serial into string
      String message = Serial.readString();
      //Initialize char array
      char msg[message.length()];
      //Write string to char array
      message.toCharArray(msg, message.length());
      //send char array as unsigned int (bits)
      vw_send((uint8_t *)msg, strlen(msg));
      //Wait until the complete message has been send
      vw_wait_tx();
      //Turn on light when finished
      digitalWrite(13,HIGH);
      delay(200);
    }
  }else{
    //Turn off light
    digitalWrite(13, LOW);
  }
}

And the following code to receive a message and print on a LCD screen:
#include <LiquidCrystal_I2C.h>
#include <VirtualWire.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

void setup() {
  //start up LCD with 16 chars with 2 lines
  lcd.begin(16,2);
  //Turn on backlight
  lcd.backlight();
  //Write initialising message
  lcd.setCursor(0,0);
  lcd.print("Initialisation..");
  //Force low when enabled
  vw_set_ptt_inverted(true);
  //Set pin 12 to receive
  vw_set_rx_pin(12);
  //Setup with speed of the data transfer.
  vw_setup(4000);
  //set pin 13 for light
  pinMode(13, OUTPUT);
  //Start receiver
  vw_rx_start();

  //Set message on LCD that setup has completed
  lcd.setCursor(0,1);
  lcd.print("Completed!");
}

void loop() {
  //initialize array for message
  uint8_t msg[VW_MAX_MESSAGE_LEN];
  uint8_t msgLength = VW_MAX_MESSAGE_LEN;

  //If message received
  if (vw_get_message(msg, &msgLength)){
    //Turn on light
    digitalWrite(13, HIGH);

    //Print on lcd
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.write(msg, msgLength);
  }else{
    //Else turn of light
    digitalWrite(13, LOW);
  }
}

My problem is that the message that is being transmitted and received by the other arduino always is short 1 character. For example if I send "test", it receives and displays "tes". What am I missing?
(My short solution was to just add a space to the message, then the space got cut off. But I want to understand what is going wrong.)

One thing that immediately jumps out at me is your flawed serial methodology. You should read this: http://hacking.majenko.co.uk/reading-serial-on-the-arduino

I haven't found the source of the problem by reading through the code, and will limit my comments to advice about debugging the problem.
With the code as it stands, there are half a dozen points where the missing character might have dropped out.  With just a final result, the problem location is difficult to narrow down.  Modify your code to display intermediate data.
For example, in the sending code, print the read-in string and its length to Serial.  Eg, if you #include <Streaming.h> you can say:
Serial << message << ' ' << message.length() << endl;
Serial << msg << ' ' << strlen(msg) << endl;
and so forth.
[Note, msg actually occupies strlen(msg)+1 bytes, the last byte being a null-byte terminator, which your code doesn't send or receive.]
In the receiving code, besides the lcd.write of msg, do an lcd.print with msgLength.
You can also do some code clean-up in the sender.  Remove the line
while (Serial.available() > 0) {,
and its corresponding }, because  Serial.readString() already contains a character-wait loop with timeout.

Thank you for the tips. Im not that familiar with serial/arduino, just started. So these comments about the code are nice!


text:
From Arduino to a miniaturized circuit
I have a project made with Arduino, and I want to replace it by a miniaturized circuit with just a microcontroller. Is there any tutorial that can guide me in doing this? Any reference is wellcome. Thank you!

This can be a useful exercise, though unless you need to incorporate other components it may be worth considering a cheap premade miniature Arduino clone PCB rather than a DIY effort.

I found that the Arduino Pro Mini might actually be smaller than a ATMega328P DIP (with external reset button, LED's, power circuit and cyrstal). Look how tiny it is :D https://i.ytimg.com/vi/SV32k9gCvik/maxresdefault.jpg

You can use an Arduino on a breadboard to get you going. From the breadboard, you can then develop a circuit on a pre-made PCB like this:

Then to a custom PCB, if you so desire.

you can also your m328p-less uno as a serial programmer, if you don't use the hardware serial already

The main question is: Which features do you want to have on your board?
You can start off with the design files of the Arduino board you are using: update what you need (and don't need).
Then, for the manufacturing itself, several approaches will work:

veroboard & through hole components. Not very practical, not small, but easy;
DIY manufacturing: toner transfer method, or if you have a CNC, isolation milling;
Boardhouse (e.g. PCB manufacturer) to whom you send your finished design to have it manufactured.

An alternative would be to use a smaller board, like an Arduino nano: it all depends on what your constraints/goals are.


text:
Are INTx pins the only ones eligible for Software Serial?
As opposed to PCINT (Atmel's Pin Change INTerrupt, INTx is arduino-compatible interupt)  In other words, does Software Serial use atmel's pin change or arduino falling interrupt?

SoftwareSerial uses PCINT.  AltSoftSerial uses INT0 or INT1, which has FALLING, RISING, CHANGE or LOW LEVEL options.  See Section 12.2, p. 71 of the Atmel ATmega328 spec, for example.


text:
Converting three-axis magnetometer values to degrees
I have a 9-DOF sensor (MPU-9150) and I want to use its magnetometer to retrieve the rotation angle, from 0 to 359. However, its library returns three values: x, y and z.
I do not know how to transform this into a single value. Is there any way to do this?

It is giving you the vector that runs along the local magnetic field -- ideally it points to magnetic north. The rotation mapping between the measurement and magnetic north should give you your heading.

Reading the datasheet could be very enlightening. Have you tried it?

@Majenko Yes, but nothing really useful.

So, basically, is it even possible to compute a heading (with tilt compensation) with a magnetometer only (no gyrometer or accelerometer)?

The answer given by Dave X, namely
az=90-atan(y/x)*180/pi

is on the right track. However, it cannot work as is for two reasons:

The formula fails badly whenever x = 0,

It gives the same azimuth for x = y = 1 and for x = y = −1. In other
words, it cannot differentiate between north-east and south-west.

The formula could be fixed by replacing atan(y/x) by a function that
returns:

atan(y/x) if x > 0
π/2 if x = 0 and y > 0
−π/2 if x = 0 and y < 0
atan(y/x) + π if x < 0 and y ≥ 0
atan(y/x) − π if x < 0 and y < 0

That would be essentially a two-argument, “quadrant-aware” version of
the arctangent, yielding results in (-π, π] instead of
(−π/2, π/2).
Fortunately, such function already exists. It is a very standard
function of the C library and is called atan2(). Thus, the correct
formula is
az = 90 - atan2(y, x) * 180 / M_PI;

Now, since atan(y/x) = π/2 − atan(x/y), the formula above can be
simplified into
az = atan2(x, y) * 180 / M_PI;

This formula gives the direction of the (x, y) vector counted clockwise
from the y axis. It is likely that the OP wants instead to know the
heading of some kind of vehicle. The correct formula depends then on how
the magnetometer has been mounted relative to the vehicle. If we assume
that the x axis of the magnetometer points forward and the y axis points
to the left, then:

the vehicle is heading north (0° magnetic heading) when the horizontal
component of the magnetic field is along +x
the vehicle is heading east (90° magnetic heading) when the horizontal
component of the magnetic field is along +y

From here, it follows that the vehicle heading is
heading = atan2(y, x) * 180 / M_PI;

Obviously, the magnetic declination has to be added if one is
interested in the true (rather than magnetic) heading.

Edit: All this assumes the XY plane is horizontal. If it is not
(due to the vehicle's pitch and roll), see Tails86's answer for a
way to cope with that.

You first need calibration (either using the device calibration method, or, by rotating it in a complete circle to ascertain the full field strengths).
You can then use the X, Y, and Z readings to compute the location of "north" relative to whichever way you're pointing (keeping in mind that "north" changes as much as 30 degrees depending where on earth you are (called declination - see http://www.magnetic-declination.com/), and that it's not horizontal to the ground either (confusingly, called "inclination" - see https://physics.stackexchange.com/questions/283761/if-you-hold-a-compass-needle-vertical-does-it-point-down-or-up-differently-on-wh/283782 )
If you picture the X, Y, and Z readings as meaning "where on an imaginary circle is the direction of magnetism - where those 3 circles are on 3 different planes, you can compute the logical position of a vector pointing towards magnetic north in 3 dimensions.
The bad news - there's no simple way to do what you want accurately, and definitely not one that's going to work without trig math on all 3 readings (you can't just use X and/or Y alone).
The good news - you probably don't really need to know an actual "heading" - most applications just need some local relative direction as compared with something you already know.
Beware that strong magnets (such as ones in all modern motors) seriously mess with readings from a long way away (10 or more foot even) - grab an app from your phone store that shows your phone magnetometer readings, and wave a magnet around to see this easily!

I wanted to expand upon what Anon is getting at and provide some math as I've just gone through this process for a similar 9-axis device.
First, it's good to know what the magnetic field vector means. I like this source because it provides an image showing where magnetic vectors point as you move up and down earth. It points downward on the northern hemisphere and upward in the southern hemisphere. The text is otherwise not relevant as it more or less just explains how you can approximate laitudinal position from that data - the angle of the horizontal component is all that we need to be concerned with in order to obtain a heading.
The problem with Edgar's answer is that it assumes that your reference plane is flat against earth. As soon as you add any pitch or roll, that answer won't be right. To correct, you need to project the magnetic field vector onto your horizontal plane. Luckily, that sensor also provides you with an accelerometer which provides a way to tell you which way is down due to the force of gravity as long as you're not moving around too quickly.
What I did was project the magnetic field vector onto the acceleration vector then subtracted that from the magnetic field vector to get the horizontal component vector. Then I could retrieve the vector angle on the X/Y plane just as described by others.
First, a partial definition of a vector so I'm not depending on external libraries:
    class Vector3D
    {
    public:
        Vector3D() : mArr{} {}

        Vector3D(double x, double y, double z)
        {
            mArr[0] = x;
            mArr[1] = y;
            mArr[2] = z;
        }

        double dot(const Vector3D& rhs) const
        {
            double out = 0;
            for (int i = 0; i < NUM_DIMENSIONS; ++i)
            {
                out = out + mArr[i] * rhs.mArr[i];
            }
            return out;
        }

        Vector3D operator* (double x) const
        {
            Vector3D out;
            for (int i = 0; i < NUM_DIMENSIONS; ++i)
            {
                out.mArr[i] = mArr[i] * x;
            }
            return out;
        }

        Vector3D operator- (const Vector3D& x) const
        {
            Vector3D out;
            for (int i = 0; i < NUM_DIMENSIONS; ++i)
            {
                out.mArr[i] = mArr[i] - x.mArr[i];
            }
            return out;
        }

        double getX() const {return mArr[0];}
        double getY() const {return mArr[1];}
        double getZ() const {return mArr[2];}

    private:
        static const int NUM_DIMENSIONS = 3;
        double mArr[NUM_DIMENSIONS];
    };

    Vector3D operator* (double x, const Vector3D& y)
    {
        return (y * x);
    }

Here is how the compass angle can be computed:
    // mag: magnetic vector
    // accel: acceleration vector (due to gravity)
    double computeYaw(double mag_x, double mag_y, double mag_z, double accel_x, double accel_y, double accel_z)
    {
        const Vector3D vector_mag(mag_x, mag_y, mag_z);
        const Vector3D vector_down(accel_x, accel_y, accel_z);
        const Vector3D vector_north = vector_mag - ((vector_mag.dot(vector_down) / vector_down.dot(vector_down)) * vector_down);
        return atan2(vector_north.getX(), vector_north.getY()) * 180 / M_PI;
    }

EDIT: I changed the code so needed elements of a Vector are defined here so there is no confusion.
EDIT2: Here is a good resource on this subject if you need a more accurate solution. As stated in this resource, the above is only really useful if you're not moving around too much and your magnetic environment is clean.

tf2/LinearMath/Vector3.h: No such file or directory. Got a link to the library?

Very good point! Note that: 1. If the platform is moving, we can get a better estimate of the vertical by combining the accelerometer data with the gyro data. 2. For better accuracy, atan2() should be fed with the components of the magnetization in the horizontal plane, rather than the platform's XY plane.

Edgar - That is indeed a big issue with this implementation. Any small movements will skew the result. I found that averaging the result over 20 samples was enough to smooth that out for my own needs as I'm dealing with a slow moving device.

Is there any open source lib that implements all the math of the article linked in the second edit?

This is a basic math problem.
az=90-atan(y/x)*180/pi

"atan()" is arctangent and converts from coordinate variables to angle in radians, *180/pi converts from radians to degrees, and 90- converts from degrees math angles (degrees CCW from the x axis) to azimuth (degrees CW from north).
Calibrating the sensor is a trickier problem.

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


text:
Arduino Uno and Raspberry Pi USB Serial Communication
I am trying to get Arduino Uno with Raspberry Pi to communicate with each other. I want the python script to write a message and for my Arduino to read it. This was working before, but I came back a week later and it stopped. Essentially, I want the Raspberry Pi to write '3' and for my Arduino to recognize this 3 and light up some LEDs. Where do you think I am going wrong? The Arduino works when testing it through the IDE and Serial Monitor. There are no errors when running the python script, the LEDS just don't light up, so I assume there is some miscommunication.
Python Code
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
ser.write('3')

Arduino Code
String serialRead;
int val;
void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.setBrightness(25);
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  serialRead = Serial.read();
  if (Serial.available() > 0) {
    val = Serial.read();

    if (val > '0' && val <= '9') {
      Serial.println(val);
      val = val - '0';
      Serial.println(val);

      if (val == 3)
      {
        //strip.setBrightness(100);
        colorWipe(strip.Color(127, 127, 127), 50);
        colorWipe(strip.Color(0, 0, 0), 50);
      }
    }
  }
}

What you can do is remove the rPi from the equation. Run the sketch and send your own serial commands direct via your computer and see if the LEDs change as expected. That will narrow down which end is having the problem: works, it's the rPi send/arduino rcv. doesn't work, it simply your code or the LED setup. Report back and tell us how you go

Just at a glance:
Your loop consumes the byte and stores it in serialRead, so there is probably no available data at the outer if, so it is never entered.
Try deleting this line:
serialRead = Serial.read();

Unfortunately, that did not work. I am able to get it to work through the Arduino IDE using Serial Monitor both ways, but still not with the RPi

I suspect a timing issue; perhaps the rPi sends the '3' before the Arduino is listening?  Have you tried to put a loop w/delay in the Python code?

The first Serial.read(); is a problem for sure – unless the Raspberry Pi sends more than one '3' this line could consume it, and then nothing will happen. I'm suspicious that there are garbage characters that are consumed by that first Serial.read(); when you're testing with Serial Monitor. Why don't you print what your get from it. Also is the pi sending a newline? Could the problem be that there is Serial.read() expects one?

I took out the first Serial.read(); and the problem persisted. I think NVRAM may be right with the timing issue. I was able to get it to work with constantly writing a 3. Unfortunately, I had to give the setup back to my friend so I won't be able to test this issue further. Thanks for the help.


text:
Blink question with breadboard & LED
I tried a basic Blink example and I found a strange case where :
Works

Does not work

Can someone explain me what is happening ?

It is because the rail in the middle breaks the vertical connections.
So the positive leg in the first example is not connected to the negative leg of the LED.
In your second example both the negative leg and the positive leg are connected on the same rail, because of the that the power is not flowing through the LED but directly back to the GND pin of your arduino.
Same for the resistor. Since both legs are connected to the same rail, the resistor has no effect.

Also note that in both cases the resistor will not work. This will damage the led, and possibly the arduino.


text:
MQ135 output on Arduino Uno
I bought an FC-22 (MQ135) gas sensor module which I plugged into my Arduino Uno. I connected it to the A0 analog port. Then created a code that reads the raw data from A0 (code below).
When I run the code on my Arduino Uno in my house I get values of about 30. If I blow over the sensor I get values until about 160. My question is now how I have to read / interpret these values.
According to the MQ135 specifications the sensor has a sesitivity for air quality, measuring benzene, alcohol and smoke.
How can I interpret the values I get? What is a good value and what isn't? Do I have to calculate something out of these values?
My code looks like this:
void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  int sensorValue = analogRead(0);
  Serial.print(sensorValue, DEC);
  delay(100);
  if (sensorValue > 50) {
    digitalWrite(13, HIGH);
  }
  else {
    digitalWrite(13, LOW);
  }
}

any reference for co2 calibration?

@manish As for now the only info I have is from the answer below in the datasheet of the MQ135.

According to the datasheet you have to calibrate it.

Thanks for the link to the datasheet. Yep, at the end of the document indeed it says to calibrate the sensor to either 100ppm NH3 or 50ppm Alcohol. Unfortunately, I haven't got the tools to create an atmosphere with these contents. Furthermore, I'd be more interested in CO2 values, even if I didn't state that in the initial question.

@Socrates Any update on CO2? I'm struggling with it. Could you please help me out?

@AdityaPonkshe I haven't got any update on this yes, sorry. Please post it here, if you get it running.


text:
Extra characters remain in Serial
I have spent the whole day trying to deal with this problem connecting Arduinos together using UART (Serial). But the problem is that it always behaves weirdly. For now the problem is that if previous number (I am sending numbers over serial) stays in the serial port.
Let me describe the problem. I want to send the following sequence of numbers 16 4 100. Numbers are sent with a terminator char after each number, but on the receiver side I get the following result 16 46 100.
As you can see if the previous number is longer (length, has more digits) than the current one, like 16 and 4, 132 and 34, the difference (number of digits) remains in the next result: for 16 and 4 it will be 16 and 46, for 132 and 34 it will be 132 and 342.
I have tried different ways to solve this problem, but unfortunately I cannot find the solution.
Here are my functions used for communication:
void sendCommandToSerial(int command) {
  Serial3.print(command);
  Serial3.print(TERMINATOR_CHAR);
  Serial3.flush();
}

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

int readRawBytes(char *inputBuffer,const int bufferSize) {
  return Serial3.readBytesUntil(TERMINATOR_CHAR, inputBuffer, bufferSize);
}
int readIntFromSerial() {
  if(readRawBytes(inputBuffer,DEFAULT_BUFFER_SIZE) > 0) {
    return atoi(inputBuffer);
  }
  return -1;
}
int readFloatFromSerial() {
  if(readRawBytes(inputBuffer,DEFAULT_BUFFER_SIZE) > 0) {
    return atof(inputBuffer);
  }
  return -1;
}

I have tried both software and hardware serials, still the same.
Please help to find and solve the problem.

The Stream member function readBytesUntil() does not null terminate the string. It returns the number of characters read. You must terminate the string with null(0) before calling atoi() and atof() or fill the string will null(0) before calling readBytesUntil().
For more details see Arduino Stream.cpp.
Cheers!


text:
Arduino IDE fails without sudo
I use Arduino IDE 1.6.6 on Ubuntu 15.10.
Starting the Arduino IDE without using sudo fails for both:

uploading the code to the Arduino Uno
starting the serial monitor

The group I need to add my user to is called dialout:
myuser@mycomputer:~$ ls -l /dev/ttyACM*
crw-rw---- 1 root dialout 166, 0 Dez 12 17:57 /dev/ttyACM0

So I added myuser to dialout:
sudo usermod -a -G dialout myuser

Somewhere I read that I have to add myuser to tty as well, so I did it:
sudo usermod -a -G tty myuser

Though I still fail with the above mentioned when trying to use the IDE with myuser.
What do I have to do to get the IDE working with myuser?

Have you logged out yet?

@IgnacioVazquez-Abrams Oh, that was it. I had to log off and on again, something I rarely do. I feel so stupid now for not having tried that. Thanks for telling me!

There should be a command like 'id' or something similar that will show the groups you are a member of. Run that to check that the new groups have taken effect – you may need to log out and then log back in.
The other thing to check is the group owner of the device itself (in /dev). that will also need to match the group you assigned to yourself. Also make sure that the device permissions allow group access.

This is a very informal "solution", not too useful for beginners.