text:
ATTiny 85 analog input pin number problem
I am using AT Tiny 85 to read voltage from lead acid battery charger while charging.  Basically the setup has two 7-segment displays driven by two SIPO shift registers(74ls164n). And used tiny 85's pin 4 (physical pin3) to read voltage.
I tested the code using arduino and finally burned it to AT Tiny 85,   it didn't worked, i debugged it for hours, and pulled hair out of my head, tested it on bread board, eventually i changed the port to "A2" from "4" and surprisingly, everything runs as expected.
My question is why this happens? why analogRead(A2) works while analogRead(4) don't. ?
I am using Arduino IDE 1.6.5 with https://github.com/damellis/attiny  (1.0.1 installed from the board manager) .

Full Code:
//// Arduino Uno Pins
//const int data = 8 ; //Tiny pin 3 (Physical 2)
//const int clock = 9 ;//Tiny pin 2 (physical 7)
//const int battery_Sensor = A0; //Tiny pin 4 (physical 3)
//const int charger_ctrl = 5;   //Tinypin 1 (physical 6)

// ATTiny 85 Pins
const int data = 3 ;
const int clock = 2 ;
const int battery_Sensor = 4;
const int charger_ctrl = 1;

int outputValue = 0;
int sensorValue = 0;
int voltage_reading = 0;
int msb = 0;
int lsb = 0 ;

// Qo -> 1
// Q1 -> 2
// Q2 -> 4
// Q3 -> 5
// Q4 -> 6
// Q5 -> 7
// Q6 -> 9
// Q7 -> 10

char c_array[10] = { '0', '1', '2',  '3',  '4',  '5', '6',  '7', '8', '9'} ;

int measure_voltage(){
 sensorValue = analogRead(battery_Sensor);
 return map(sensorValue, 0, 1023, 0, 50);
}

byte seven_segment(char input, bool period){
  byte output_byte;
  switch (input) {
      case '0':
        output_byte = B11101110;
        break;
      case '1':
        output_byte = B10000010;
        break;
      case '2':
        output_byte = B11001101;
        break;
      case '3':
        output_byte = B01101101;
        break;
      case '4':
        output_byte = B00101011;
        break;
      case '5':
        output_byte = B01100111;
        break;
      case '6':
        output_byte = B11100111;
        break;
      case '7':
        output_byte = B00101100;
        break;
      case '8':
        output_byte = B11101111;
        break;
      case '9':
        output_byte = B00101111;
        break;
      default:
        output_byte = B00000001;
      break;
    }
  if(period == 1){
    output_byte = output_byte ^ B00010000;
  }
  return output_byte;
}

void setup()
{
  pinMode(clock, OUTPUT); // make the clock pin an output
  pinMode(data , OUTPUT); // make the data pin an output
  pinMode(charger_ctrl, OUTPUT);
  pinMode(battery_Sensor, INPUT);

}

void loop() {
    voltage_reading = measure_voltage() ; // voltage x 10
    msb = voltage_reading/10;
    lsb = voltage_reading%10;

    shiftOut(data, clock, LSBFIRST, seven_segment(c_array[lsb], 0));// send this binary value to the shift register
    shiftOut(data, clock, LSBFIRST, seven_segment(c_array[msb], 1));
    delay(1000);
}

See the analogPinToChannel function.
static const uint8_t A0 = 6;
static const uint8_t A1 = 7;
static const uint8_t A2 = 8;
static const uint8_t A3 = 9;

...

#define analogPinToChannel(p)   ( (p) < 6 ? (p) : (p) - 6 )

Using A2, which is 8, will return 2 (8-6) from the analogPinToChannel function.
Using 4 will give 4. There is no (useful) analog channel 4.


text:
Connect Antenna to GPS Module ET314AC
How can I connect antenna to GPS Module ET314AC?(it is not on a breakout board). I have an antenna like this one GPS Active Antenna and Here is the datasheet of ET314ACET314AC Datasheet.I want to connect it manually without any connectors or other things in fact I want to cutoff the connector from antenna.

Just solder the center wire to the ANT pin, and the outer shielding to the GND pin.

What about power supply? How can I connect battery to that antenna as it is an active antenna?

Have you actually read the datasheet? It's plainly there in black and white.

Read the datasheet!

V_ANT_IN
This pin is reserved an external DC power supply for active antenna.
  If using 2.85V active antenna, pin 19 has to be connected to pin 20.
  If the bias voltage of active isn’t 2.85V,you can input bias voltage of you need to this pin.

So just wire the antenna to the RF_IN pin and GND, and connect pin 19 to +3.3V (since your antenna is 3.3V not 2.85V).

i got the point :)

source: Stack Exchange

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

sort: votes


text:
Communication between two arduinos over wifi esp8266
I have two arduinos one is Arduino Mega while other is Arduino UNO and I want to send data from UNO to Mega and vice versa over wifi using two ESP8266 wifi modules without use of any router in between, so what is the simplest procedure I can use to do this? Moreover how can I do this with a router in between?

The simplest solution is to turn on Access Point Mode on one of Wifi modules. and the other one has to be set to Station Mode in order to connect to the first one.
In case you want to add a router, just set both ESP8266 modules to Station Mode and connect them to the router.
Also, I would recommend replacing the Original Firware (AT firmware) of ESP8266 with NodeMCU Firmware. It uses lua language to write programs directly to ESP8266 which means that you can even make 2 ESP8266 modules talk with each other without even using Arduino.

can i use Arduino to Flash NodeMCU to ESP8266 or I have to buy usb to ttl adapter like thing?

No you don't need a USB to TTL. Use your arduino, just connect RX pins together and TX pins together (RX<------>RX and TX<------->TX).

You first need to upload a blink sketch to ensure that Serial interface isn't used by Arduino. then you can flash NodeMCU.

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


text:
How to connect Arduino and Beaglebone
I am newbie, I am afraid of doing harm and getting a burned-out Beagle Bone Black. I have soldered this SparkFun Logic Level Converter - Bi-Directional.
I have several questions:

How can I check if my converter works correctly without connecting it to any board or at least only to an Arduino?
How should I connect all my schematic from bbb to converter and then to an Arduino. I have a bi-directional converter, BTW. Can someone draw a simple picture of how to connect?

I would be grateful for any help.

The simplest method of connection is just to plug the Arduino into the BBB's USB socket.  That way there's no level conversion or anything needed - you can just open the serial port and communicate through that - what could be simpler?
You can even install avrdude on the BBB itself and upload code (HEX files) direct from the BBB, and the BBB supplies all the power.

In addition to the other methods listed, which will both work, you could also use an Arduino that uses 3.3V logic and connect the serial/UART.
The Trinket: https://www.adafruit.com/products/1500?gclid=COGOxqq-z8kCFcYRHwodpL8P2A
Pro 328: https://www.sparkfun.com/products/10914

Your main concern for frying something would be when sending data from the Arduino(which uses 5V) to the Beagle (Which uses 3.3).
The Arduino receiving data on the Arduino RX line wouldn't be anything to worry about since you would be sending data at 3.3V from the Beagle to 5V on the Arduino( Remember that unlike RS-232, TTL serial has no carrier voltage, so current only travels over the lines when data is actually sent )
You could always hook up the Arduino side (HV/5V), program the Arduino to do
Serial.println("HELLO WORLD");

inside void loop()
and look for voltage being send over the RX pin on the LV side. You would still have to connect 3.3V to LV and GND to GND.


text:
Not sure if logic analyzer shows an error or perhaps just a 'relay bounce'
I have an Arduino controlling a relay. I was taking a look at the timings using a logic analyzer and at the onset of the relay switching, it quickly switches again.
This seems to be occurring randomly and I thought it could be highlighting a problem with my code but I wondered if it might just be a 'relay bounce' due to the speed of the switch. I've attached an image below. Any feedback is greatly appreciated. Thanks.

It's probably just bounce.

Increase the sample rate and you may get a clearer idea.

you would probably get a better answer in http://electronics.stackexchange.com/ although usually as soon as they see the word "arduino" they usually bump things over here lol. Do you have the relay connected directly to the arduino pin or are you switching through a transistor and if so, on which side are you measuring it. That will give you a much better idea. For all intents and purposes, it does just look like bounce.

Thanks for the replies guys. Madivad: it is connected directly, however it's one of the module boards (https://tinyurl.com/ph5pozj) so there may be a transistor it's going through there. I just thought of using a solid state relay so that may shed some more light on whats going on. Thanks again for your help

If you can, attach the LA to both sides of the relay so that you can watch the signal controlling the relay as well as the relay output. That should make it much easier to tell what is happening.

According to your plot, the pulse length is 50 microseconds. Typical mechanical relay switching time is 10 milliseconds, which is 200 times longer. It's next to impossible that the pulse is due to your software powering the relay back on for a moment, since the relay simply could not react to such a short input pulse.
So yeah, it's just a bounce. You can safely ignore it in most cases, unless you're counting events or doing something similar. In the latter case, there are both hardware and software debouncing techniques, which share the basic idea of a low-pass filter.


text:
Connect Digital monitor to Arduino?
I need a small display with ~ 5 digits.
The display needs to show number of visits to my site in real-time.
(Every time someone visits it needs to increase by one).
I thought to create an app, that fetches server stats every 10 seconds, and checks new number of visitors.
Do you think it is better to do with Arduino or Raspberry Pi?
Do you know of a digits monitor that can be connected to it?

A 7 segment display (they come from tiny to huge) or SPI Character or Graphic display fits with an Arduino.  But once you add networking a pi is a better conceptual fit though has a lot of practical complications.  A simple Android tablet may be considered, too.

For the complexity of the pulling of the data from a specific API, I would suggest to use i2c screen from adafruit and a python script running on raspberry pi.
this will save you time on coding eth interface and just mostly copy and  paste some simple code to communicate to the display

@max246 I came in to write pretty much the same thing, so you should post that s an answer

Trivial edits to a question that isn't specific enough for the site and has been abandoned by its asker are not going to redeem it - they just undeservedly bump it back to the top of the queue.  If the poster won't nail down their requirement, this should be closed.

It all depends on how used to you are with using pi or arduino. What you want can be done in both ways.
The displaying of count is common for both. It can be done using a 16X1 LCD display, 5 different 7 segment LED connected via decoders or a graphic display module. Interfacing all these with Arduino will be relatively simpler than Pi.
For the fetching of data and sending it to your device for displaying it. You can use ESP8266 Wi-Fi module with arduino and pull the data. Which is not as simple as it sounds but it is not impossible too.
For pi, (like @max246 said) you can run a python script and use another api to get the data.

For the complexity of the pulling of the data from a specific API, I would suggest to use i2c screen from adafruit and a python script running on raspberry pi. this will save you time on coding eth interface and just mostly copy and paste some simple code to communicate to the display
This is one module that I used and it is simple to use: https://www.adafruit.com/products/1270

authors: Вкотором Тио


text:
On the Uno, why does VIN require 7-12 volts and the USB only 5 volts?
I'm just wondering why the VIN would require 7-12 volts when the USB port itself only requires 5 volts? What happens if you power an Uno on VIN with 5 volts?

Feel free to supply 5 volts to the 5V pin on the Uno.

Possible duplicate of Powering an Arduino UNO through 5V

USB's Vcc pin is assumed to be a stable, 5v supply, and is directly connected to the 5v bus on the Arduino board with no further regulation. Vin is assumed to be an unknown and unregulated voltage in the range of 7-12 volts.
The 7v minimum is a requirement of the design of the on-board voltage regulator which needs the 2v "head room" to maintain its output at 5v. A 5v power supply could be designed with a larger input range, even including voltages less than 5v, but the simple design used on the board covers a range of sources at a lower cost than a higher-performance power supply.

The UNO takes your input power supply (7-12 volts) and then regulates the voltage down to 5 volts. This way, the UNO operates at a constant voltage regardless if your input power supply wanders about from 7 to 12 volts.
The USB port,  BY DEFINITION and International Standards, needs to operate at 5 volts.
If you apply 5 volts power supply, the UNO won't be able to regulate to 5 volts. The voltage regulator itself will have a voltage drop, and the UNO will operate at less than 5 volts.  The UNO may or may not operate properly. The USB will likely suffer from more problems than the UNO if you apply 5 volts.
Good news is that the UNO will not likely suffer permanent damage.

What does this mean "The USB will likely suffer from more problems than the UNO if you apply 5 volts. "

Items connected to the USB port can become disfunctional if operated from less than 5 volts.


text:
Powering an Arduino UNO through 5V
I have a bench supply which I can use to power a breadboard at 5 V. Is it a bad idea to power the the Arduino by going directly to the 5 V pin? It sounds like both this method, and the USB are unregulated, so there would be no difference. Is it safe? Are there any caveats to this?

5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it.

They say they "don't advise it", but why?

Possible duplicate of On the Uno, why does VIN require 7-12 volts and the USB only 5 volts?

They wouldn't advise it because they provide on board regulation. By feeding it directly you're circumventing their own protection. If however, you're providing your own regulated supply there is no reason why you can't supply it directly.
In a perfect environment, USB should already be regulated. However given the cheap imported USB hubs and plug packs that are available on the market, I would certainly argue that a good bench power supply is no problems in this regards.

How precise does the regulation needs to be? What can I figure out the tolerance?


text:
Interrupt on Analog Port - ESP8266 w/ Arduino
I'm trying to implement interrupts in my program. It essentially is constantly reading a photo-resistor and if it exceeds a certain threshold, we should send an update to our database. I'm struggling to understand how to do interrupts on a analog pin. I've tried reading this but honestly, it doesn't make much sense. Could anyone give me some advice? Here's out code.
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Initally send out false state
  sendState("18:FE:34:F4:D0:AF", false, false);
}

void loop() {

  if(analogRead(A0) < 20) {
    sendState("18:FE:34:F4:D0:AF", false, true);
    lastState = true;
    Serial.println("Waiting....");
    delay(15000);
  } else if(lastState == true){
    sendState("18:FE:34:F4:D0:AF", false, false);
    lastState = false;
  }

}

void sendState(String address, boolean lights, boolean occupied) {

  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  String lightsStr = (lights) ? "true" : "false";
  String occupiedStr = (occupied) ? "true" : "false";
  String json = "{\"MACAddress\":\"" + address + "\", \"occupied\":" + occupiedStr + "}";

  String postData;
  postData += "POST /sensor HTTP/1.0 \r\n";
  postData += "X-Parse-REST-API-Key: " + API_KEY + "\r\n";
  postData += "Content-Type: application/json \r\n";
  postData += "Host: " + String(host) + " \r\n";
  postData += "Content-Length: " + String(json.length()) + "\r\n\r\n";
  postData += json;

  // Send the postdata to the server.
  client.print(postData);

  delay(1000);

  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }

  Serial.println();
  Serial.println("Closing connection!");
}

Interrupts are a tricky concept to get, you have to be mindful of so many things (in bigger projects).
Have a quick look on youtube for some tutorials, there are a heap out there.
Having said all that, your code above isn't using interrupts at all. And you have these big delays, does the code work as published?
I would suggest you rework the code into more of a state machine and have a single loop. ditch all the delays (except for your setup, that's fine) and go along the lines of:
setup
set a variable for current timer value and have a constant defined for your update interval
loop

read sensor (consider constantly reading, or reading it more often than the information is sent, and average it out)
anything on the serial port?

go read it

check timer against old timer and interval
interval exceeded

send averaged value

using interrupts
You could use interrupts but the thing to consider is that they can be run AT ANY TIME. your code must be interrupt-able which whilst isn't too hard, needs special consideration in relation to delays, reading 16bit values, not having delays in the interrupt, status register changes, a whole host of others.
There are two types of interrupt, those that are driven by a change in input and those that are time based. You don't really want the change in state on this one because you would normally want to monitor it constantly anyway, but it is certainly doable.
In both time based and external input, you would have the interrupt set a flag that gets acted upon in your main loop.
sorry for not providing more info at this time, screaming kids :(

You can use the inbuilt analog comparator to generate an interrupt when a certain threshold is reached. Example circuit (reference voltage on D7, voltage under test on D6):

Example code for the Uno:
volatile boolean triggered;

ISR (ANALOG_COMP_vect)
  {
  triggered = true;
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Started.");
  ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
  ACSR =  bit (ACI)     // (Clear) Analog Comparator Interrupt Flag
        | bit (ACIE)    // Analog Comparator Interrupt Enable
        | bit (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
   }  // end of setup

void loop ()
  {
  if (triggered)
    {
    Serial.println ("Triggered!");
    triggered = false;
    }

  }  // end of loop

The incoming voltage is on the AIN0 (positive) pin which is pin 12 on the actual chip, and D6 on the Arduino board. The reference voltage (negative) pin is pin 13 on the chip, and D7 on the Arduino.
My example does not address the issue of transmitting the results, but that is the easy bit. You might need to build in a test so that you don't transmit the information thousands of times a second.

I need wifi capabilitiy is this available for any esp microcontroller?

@LucaZiegler - this is not relevant to this question. I suggest you ask your own question, preferably after searching to see if it has already been answered here.

But the title is 'Interrupt on Analog Port - ESP8266 w/ Arduino'

@LucaZiegler The abbreviation "w/" means "with" not "wifi". The basic question was "I'm struggling to understand how to do interrupts on a analog pin.". Not "how to do WiFi".
Look, comments on questions are for clarifying the question. Asking about WiFi capability on ESP microcontrollers is a new topic, and I suggest you make your own question about it. That is, IF that has not already been answered.

I believe the reason for Luca's comment is that the question refers to the ESP8266 but your code example is for the Uno; the comment as I understand it is "I need WiFi capability, will this code also work on an ESP microcontroller?".

*shrug* - my code is for the Uno, and it does not have WiFi in it (the code). Asking about WiFi on the ESP controller seems to be quite a leap. In fact, one that really requires a new question.

As far as I understand, the question is not asking about WiFi - the asker is simply stating that they are using an ESP microcontroller due to the WiFi capability of said microcontroller.
As such the question is as simple as "Will this work on an ESP microcontroller?" to which the answer is "no", as the registers you have used are not present on an ESP8266/ESP32.

"I need wifi capabilitiy is this available ..." - perhaps, but I took "this" to mean WiFi not "the code above for interrupts".

The joys of ambiguity when using written communication!


text:
Suggest me some good seller for Arduino UNO
I want to start a new project with arduino uno and want to make some amazing mini projects, but i am confused that from where should i buy. So please suggest me some affordable robotic stores.

I'm sorry, this is an opinion-based question. Your question is very likely to be deleted. But as stated below, you can always check aliexpress.com.

I recently bought some arduino nano V3 on Aliexpress. It cost me €1.75,- so I immediately bought 4 :P arrived within 10 days. Also the arduino uno R3 (non-official) is only €3,-. Worth the try? I would say definitely, because if you need it for a project you want to leave it in not take it out because you have another idea. Hope this helps.

Thanx weaverworm for this suggestion.

I would comment, but my rep is not high enough so consider this a comment:
Welcome to StackExchange. You should maybe take a look at some guidelines on how to ask good questions.
First of all: mind your tune! ASAP in capitals is very impolite and implies a request we MUST fulfil - no we don't. Try to use please and thank you and everyone will be happy.
Second: this is a Q&A Site to help people now and in the future, so most of the time questions like: where can I buy this or what book is good are not what this is made for because they won't be valid for very long and have been asked many times before (but answers lost their validity as mentioned above).
and last but not least: Google it. Ebay, Aliexpress, Amazon... whatever you fancy. There are many Arduino clones for low prices around. I bought a few UNOs for like 6€ each. They work fine.
With that in mind: welcome again. I hope you find many useful answers around.

ok i understand, this is a first and last mistake.


text:
How can I see the mySerial.print( ) through the serialmonitor on IDE?
I made an object named "mySerial" like this.
SoftwareSerial mySerial(2,3) //pin 2 = RX, pin 3 = TX

also I made pin 13 periodically(0.5 seconds) blink(HIGH/LOW),
then the signal from pin 13 goes directly to pin 2 and pin 0(basic RX pin of UNO). I connected pin 0,2,13 directly with jumper wire.
and in the setup(), I wrote
Serial.begin(9600);

mySerial.begin(9600);

and in the loop(), I wrote
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);

if(mySerial.available()){
    mySerial.println("mySerial!");
}
if(Serial.available()){
    Serial.println("Serial!");
}

when I compile this code and operate arduino,
I can only see the "Serial!" on the serialmonitor.
I think this means that the pin 0 can recognize the signal but the pin 2 cant'
How can I solve this problem?
I can't find what I've missed. Please help me guys!

And what exactly is it you hope to achieve with that setup? It makes absolutely no sense to me whatsoever, and from my initial understanding "Serial!" on the serial monitor is all you can expect to get.

I connected pin 0,2,13 directly with jumper wire. - why? You've lost me here.

Not the most scientific of approaches, and fundamentally flawed at any rate.
You've toggled the input twice over the period of one second, hardly an emulation of any serial port transmission and so one is letting you know there's been a change of state, the other is letting you know that it hasn't received any valid data.
In any case, when you attempt to read the port both will/should correctly give you nothing as a result because there was never anything there to begin with, nor is there anything coming in at the time.
If you want to test serial port comms like this, you are going to have to make a sketch for each scenario and use a real device to test it (like your actual serial port thru the Arduino IDE). Run some test, print the results and upload your second sketch and do it again.
You could even get a bit fancy and have a bit of fun with this and send a command to the arduino to turn off one serial port and turn the other one on, but that's got nothing to do with what you asked, so I won't be writing the code for that here ;)


text:
PWM help (input changing duty cycle)
Is there a way to adjust the duty cycle (PWM) based upon input gained by a sensor. For example, if the sensor picks up a really high value, it would increase the duty cycle for an LED making it brighter. Can we also do this task without a potentiometer? Can all of this be done "hands-free" by the Arduino?

Yes, yes, and yes. Totally possible.

The example at the bottom of this Arduino reference page does exactly that. If you want to change the way the value varies, you can just modify the variables in a loop or in whatever approach you prefer instead of analogread'ing it.
https://www.arduino.cc/en/Reference/AnalogWrite

There is a simple project that can be done with a photo-resistor for an analog input, a light levels sensor circuit, and an LED for an output.
The software requirement is to have a loop with a delay that reads from the analog pin the photo-resistor is attached and use that value to set the Duty Cycle for the PWM output pin driving the LED illumination level.
You can then test by shading the photo-resistor from the ambient light (I used a sheet of paper rolled up into a tube and placed over the photo-resistor on the breadboard), putting it into darkness, and by using a flashlight to provide more light than ambient in order to test the range and watch the LED dim and brighten.
I have done this project with a Raspberry Pi, which required an MCP3008 Analog to Digital Converter to interface to the photo-resistor circuit since the Pi has only digital pins. Arduino has analog pins so the ADC is not necessary.
The project that I did with my Raspberry Pi is at URL: https://github.com/RichardChambers/raspberrypi/tree/master/project08 with C source code and a link to the manufacturer of the experiment kit I am using which has the details for the actual circuit. What I did was to make the LED illumination level track to the inverse of the value reported by the photo-resistor circuit. So when the light level was low as reported by the photo-resistor then I made the LED brighter.


text:
Arduino : distance measurement between fixed points
I am creating a moving robot which needs to know its exact position on the map(known before, start point also known). My ideas were :

GPS : this is not accurate enough for me, does not work indoors
Acc + GYRO + Compass(Magnetometer): MPU-9150 : from that values I could compute the position but as small errors are continuously added after a while it becomes very inaccurate

Finally my idea is to put some fixed points into the area and robot can periodically check where they are and compute its position accurate.
Although I did some googlin' I could not find any appropriate sensor pair to do this. My idea is:

one(more if no other option) sensor on robot covering 360 degrees
few fixed points which sends a signal; each different one - let's say : I am the point one. I am the point two etc.
sensor on a robot is receiving those signals and give me some meaningful value e.g. time from which I can compute the distance from each of the fixed point.
10+ meters maximum range is fine for me
must be cheap (less than 30$ for all)

Questions:

Do you have any idea of such sensor pair ?
Or other solution which would fit to my needs?

Bonus:
* The best would be if the fixed points were passive and just reflected the signal sends from robot - but I have no clue if such a thing exist :-)
Thanks in advance for any answers/comments.

Could you place some black and white pattern on the floor? If so, some photo-reflective sensors on the bottom of the robot could be used to detect where in the no-repeating pattern it is positioned. It could even detect rough orientation.

Seems to me you are looking for some kinda of SLAM thing. Depending on your knowledge in control theory and your precision goals you can go from simple rotary encoders on wheels to multiple sensor fusion like Extended Kalman filters (example videos). Probably the most precise thing you can have is sensor fusion with LIDAR (can be achieved precisions like 1cm), however the price range is way to far from described.
I would start with a small approach and go from there depending on the results I'd get:

rotary encoders (easy to calibrate and can be precise enough as a starting point)
9DOF IMU (use a Extended Kalman filter or similar to make an AHRS correction). And in this part I have many advices. You have suggested MPU-9150. I'm not familiar with it but looking at datasheet it seems very good, specially because gyro comes factory calibrated. In past I've used razor IMU / GY-85 (adlx345 + ITG3200 + HMC5883L) and gyro was very precise and low noise. Hope Invesense used the same sensor in MPU . First in hardware: Acc are easy to calibrate just use gravity. Gyros are easy to calibrate but hard to do. Why, because it may be hard to get something that spins at constant RPM and know that value. But as I've said, according to datasheet, MPU comes factory calibrated. Magnetometers calibration can be a bit tricky. Bottom line is you get readings from various points of your robot  in 3D space. you plot all and you will get an ellipsoid. Then you find a transformation equation that maps the ellipsoid into a perfect sphere take a look this article. Your concerns about Angle random walk can be minimized with kalman filter and similar. This page provides much great information and examples in how to make a good AHRS. Mr. Madgwick wrote a really nice algorithm that implements the IMU  filter and have it also written in C (nice for Arduino).

After integrate all things with Kalman and see the results, if things are not good enough, you can add more sensor and provide a better estimation for example: sonars, rangefinders, landmarks with image processing and as suggested also, RSSI and triangulation.
These links might help you in finding your way:

Introduction to Kalman Filters and SLAM
Indoor Location Tracking using Received Signal Strength Indicator

I've been working on this also, and have not found a 100% satisfactory solution. Some ideas I've been throwing around include:

Using an optical mouse to measure ground distance more accurately. This also subject to cumulative errors.
Some sort of radio transmitters
A pulse from a magnet, with a compass - these can be highly directional, and could possibly be strength-based, too.
I read about one robot competition which had a fixed, overhead camera, picking up infrared LEDs; this is processed by a computer, which would then send the data back (e.g. for bluetooth) to the robot.
The same infrared camera trick, but reversed: a camera pointing up, looking for fixed constelation of infrared LEDs on the ceiling - I would expect this to require more processing than an Arduino has, possibly a raspberry pi could do the trick?


text:
Using Arduino for simultaneous lighting effects
I am building a computer for my son (me).  I'm trying to spark his interest in computer technology, so my idea is to drive multiple case lighting effects with a microprocessor or controller.  I went with the arduino over the pi because of simplicity of the system.
There are several lighting effects I want to drive, simultaneously, and that's where I'm wondering if the arduino is well suited, because the effects need to make use of delay(), and with it being single threaded I'm struggling to figure out how to make each output operate independently.
To give you an idea of what the microcontroller needs to drive simultaneously:

Flicker pattern using random delay values for outer case lighting
Heartbeat pattern for CPU cooling block
Blacklight / UV LED lighting for coolant lines.
Strobing LEDs aimed at the fans to make them look stationary.

Trying to run all these effects in a linear loop with delay() operators just doesn't seem to be feasible.
Do I need to get an UNO for each effect?  Or is there a way of making these outputs operate independently?

Avoid delay() and use specific times of next actions and compare them to millis().  For a random time, set something like:
now=millis();
...
if(nextFlicker < now) {
   toggleFlicker();
   nextFlicker=now+random(10000);
}
if(nextPulse < now) {
   nextPulse=now+ isPulseOn? 100 : 1000 ;
   togglePulse();
}

...

If you are running more than the 50 day roll-over time of millis(), you may need some care to handle the overflows.  See http://playground.arduino.cc/Code/TimingRollover
For the strobing leds, investigate the timer-controlled outputs outputs.

Base the pattern on time, instead of using delays. E.g. if the current time in seconds if odd, the led should be on. If it's even it should be off. This creates a blinking led effect without using any delay.
Some example code:
long seconds = millis()/1000;
if( (seconds % 2)==0 )// even
  digitalWrite(led, HIGH);
else // odd
  digitalWrite(led, LOW);

E.g. to have it blink faster, change 1000 to a lower value.
E.g. to make the led be on shorter than of change %2 to e.g. %4 (i.e. 1 second on, 3 seconds off)
etc.


text:
How do I set a constant in setup() that I can use in loop()?
I am new with coding, and I was wondering how I could run something once and define it as a constant. Here is my code:
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
int g0 = 9.81*9.8;
int h1 = 48;
int R = 287.06;
int a = -0.0065;

void setup() {
    Serial.begin(9600);
    int p1 = (1.09512*sensorValue2-22.105)*133.3225;
    int t1 = (-0.08126*sensorValue1+65.6597)*274.15;
}

void loop() {
    String t = "Temperature:    ";
    String tt = " Celsius";
    String p = "Preassure:    ";
    String pp = " Pascal";
    float celsius = -0.08126*sensorValue1+65.6597;
    float kelvin = celsius*274.15;
    float pascal = (1.09512*sensorValue2-22.105)*133.3225;
    float height = (t1/a)*((pascal/p1)^((a*R)/g0))-1)+h1;
    Serial.println(t+celsius+tt);
    Serial.println(p+pascal+pp);
    Serial.println(kelvin);
    Serial.println( );
    Serial.println(height);
    delay(1000);
}

What do you need to run something once? Put in inside "setup" method (it gets executed once the Arduino powers up or gets reset)

You can't, and there's other things wrong with your code.
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);

Calling functions from the global scope is an incredibly bad idea.  Those are run before the board has been properly initialized, and the results you may get from it are not guaranteed in any way, shape, or form.  Instead you must call functions like analogRead() from within another function, like setup(), or loop().
As for const - a const is just that - a constant value that can never change.  You can only assign a value to it at the moment of creation.
And that means that you can only use it within the scope it was defined within.  As you can't do that in the global scope (see above) then you cannot use a constant.
So just use a normal global variable.  It will only change when you tell it to change.  Using a const only makes sense when you have a numeric literal that you want to refer to by name. Using const doesn't protect the variable from being changed at run-time by memory leaks, etc, it just protects it from attempts to modify it at compile time - and if possible replace it with the numeric literal that it refers to.
So in summary just use:
int sensorValue1;
int sensorValue2;
int p1;
int t1;

void setup() {
    sensorValue1 = analogRead(A0);
    sensorValue2 = analogRead(A1);
    p1 = (1.09512*sensorValue2-22.105)*133.3225;
    t1 = (-0.08126*sensorValue1+65.6597)*274.15;
}
... etc ...

HOWEVER: Your program methodology is also completely flawed.  You read the analog values once, and do calculations with them once, then repeatedly display the same values over and over again.
You must perform a new analogRead() of your sensors every iteration of loop() in order to update the values in your variables.

You can define Constants using the "const" keyword. Ex:
    const float pi = 3.14;
    const int foo = 12;

https://www.arduino.cc/en/Reference/Const

However scope rules mean that variables declared in setup() won't be visible in loop() – to make them visible declare them outside of any function.


text:
Convert INT to Array of Strings
My sensor outputs an int. I would like this to be an array of strings so I can send it with my 433MHz transmitter.
Converting an int to a string to an array of strings seems to be extremely complicated. I've tried multiple approaches.
The error is always:

array must be initialized with a brace-enclosed initializer

#include <VirtualWire.h>

const int led_pin = 11;
const int transmit_pin = 12;
const int receive_pin = 2;
const int transmit_en_pin = 3;
int mostureSensor = 0;

void setup()
{
  // Initialise the IO and ISR
  vw_set_tx_pin(transmit_pin);
  vw_set_rx_pin(receive_pin);
  vw_set_ptt_pin(transmit_en_pin);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(1000);   // Bits per sec
}

byte count = 1;

void loop()
{
  // read the input on analog pin 0:
  String sensorValue = String(analogRead(mostureSensor));

  char charBuf[7];
  char msg[7] = sensorValue.toCharArray(charBuf, 7);

  //char msg[7] = {'h','a','l','l','o',' ','#'};
  Serial.println("sending");
  msg[6] = count;
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msg, 7);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  delay(1000);
  count = count + 1;
}

toCharArray is a method. It will copy the value from SensorValur to charBuff, it won't return the char array.
Line:
 char msg[7] = sensorValue.toCharArray(charBuf, 7);

Should be:
 sensorValue.toCharArray(charBuf, 7);

charBuf will already have the sensorValue copied.
Check more about "toCharArray" method :
https://www.arduino.cc/en/Reference/StringToCharArray


text:
Arduino sketch does not repeat
I have a Problem with my code.
My Goal is to receive a Ethernet message via UDP and send the message back via CAN.
It works fine but only with the first packet I send. When I send the same packet again there is no Response as you can see in the screenshot.
I´m using the Arduino Due with a Transceiver. The Programm which sends and reads the Messages is Vector Canoe
#include "variant.h"
#include "due_can.h"
#include "Arduino.h"

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

EthernetUDP Udp;

void setup() {

Can0.init(250000);
Serial.begin(9600);

Ethernet.begin(mac, ip);
Udp.begin(localPort);

}

void loop() {

    int packetSize = Udp.parsePacket();
    Udp.read(packetBuffer,packetSize);

   if (packetSize)
  {

    int Canframestosend= packetSize/8;    //Divides the Ethernet packet by 8 to match with CAN packet
    int count =0;
    int Rest=packetSize%8;                //Needed if the Ethernet packetsize isn´t a multiple of 8

    for(int j=0;j<=Canframestosend;j++){

    CAN_FRAME NewFrame;                   //CAN frames which are sent
    NewFrame.id=0xFA;                     //ID of the frames
    NewFrame.length=8;                    //Maximum of bytes a Can frame can have

    for (int i=0;i<8;i++){

       NewFrame.data.byte[i] = packetBuffer[count]; //Write the Ethernet info byte by byte on the CAN frames
       count++;
       }
    if(packetSize<count){
      NewFrame.length=Rest;                         //Shortens the last frame to avoid unnessecary zeros
      }
       Can0.sendFrame(NewFrame);

      }

   }
   delay(10);
}

Maybe there is an endless Loop but I don´t know which and why.
Hope anybody can help me with that!

I'd guess it's in the if(packetsize) logic -- if you get a packetsize of zero, you still try to read into a zero-size buffer and who knows what would happen.  Move the read inside the if(){...}
See https://www.arduino.cc/en/Reference/EthernetUDPRead
Also, you want to limit the reading to the UDP_TX_PACKET_MAX_SIZE size of the buffer, not to the size of the packet.
Update: The UDP_TX_PACKET_MAX_SIZE is only used in the user code, and nowhere else within the Ethernet Library.  You could use a larger buffer if you need to by defining and allocating a larger buffer and specifying its size in  EthernetUDP.read()  (see https://www.arduino.cc/en/Reference/EthernetUDPRead).

Thanks for your Response, the mistake was that i limited the buffer in PacketSize and not in UDP_TX_PACKET_MAX_SIZE. But what if my packets are bigger than UDP_TX_PACKET_MAX_SIZE? I wanted to be more flexible by limiting it to the packetSize i get from parsePacket.

If the packets are bigger than your buffer, you still do not want to read them into the smaller buffer. If it does write outside its allocated space, it could damage other variables.

Okay so is there an Limitation for my UDP_TX_PACKET_MAX_SIZE? I can change the value in the Code of the library and Wikipedia says a UDP packet can contain up to 65.535 Bytes

Looks like you can: http://forum.arduino.cc/index.php?topic=103502.0  Still, move your read inside the if(){} so you don't attempt to read if there is nothing to read.

Don't limit your receive buffer to the TX packet size, make it bigger than any expected received packet: BUFFERSIZE=2048; char packetBuffer[BUFFERSIZE]; ... Udp.read(packetBuffer,BUFFERSIZE);


text:
Including Class with .h and .cpp files
I am trying to use a class in .ino file. The code is:
  .ino file
#include <LED.h>

int Pin1 = 13;
int Pin2 = 12;
int Pin3 = 11;
LED led;
void setup() {
  pinMode(Pin1,OUTPUT);
  pinMode(Pin2,OUTPUT);
  pinMode(Pin3,OUTPUT);
  digitalWrite(Pin1,LOW);
  digitalWrite(Pin2,LOW);
  digitalWrite(Pin3,LOW);
}

void loop() {
  led.on(Pin1);
  delay(2);
  led.on(Pin2);
  delay(2);
  led.on(Pin3);
  delay(2);
}

.h file
#ifndef LED_h
#define LED_h

class LED{
public:
    void on(int);
    void off(int);
};

#endif

.cpp file
#include <stdio.h>
#include <Arduino.h>
#include "LED.h"

void LED::on(int PIN){
    digitalWrite(PIN,HIGH);
}

void LED::off(int PIN){
    digitalWrite(PIN,LOW);
}

Arduino compiler picks the object declaration error:
LEDC:6: error: 'LED' does not name a type
LEDC.ino: In function 'void loop()':
LEDC:17: error: 'led' was not declared in this scope
How should I declare objects in Arduino then?
The way that I am putting the files in folders is like the attached image:

There is nothing syntactically wrong with your program - it compiles perfectly in UECIDE. My guess is it's something to do with the Arduino IDE.  Which version of the IDE are you using? I know that recently they have made some changes to how the compilation works (or maybe doesn't work).

It is Arduino 1.5.6

Your LED.cpp and LED.h files are in an LEDD subfolder. In your LEDC.ino file you should use #include "LEDD/LED.h"

That version of the IDE (it seems to change from version to version) differentiates between includes with <...> and includes with "...".
If you use <...> it only looks in the system and library areas.  If you use "..." it also looks inside your sketch.
So in your main INO file change the LED include from:
#include <LED.h>

To:
#include "LED.h"

and it should compile.

Still does not compile. Maybe the way that I am putting the files in folders is not right? See the image in main question.

I did it by adding two new tabs - LED.cpp and LED.h and pasting your code into them.

All you need to do is this in the (.ino)
#include <LED.h>

int Pin1 = 13;
int Pin2 = 12;
int Pin3 = 11;
LED led1;
LED led2;
LED led3;
void setup() {
  pinMode(Pin1,OUTPUT);
  pinMode(Pin2,OUTPUT);
  pinMode(Pin3,OUTPUT);
  digitalWrite(Pin1,LOW);
  digitalWrite(Pin2,LOW);
  digitalWrite(Pin3,LOW);
}

void loop() {
  led1.on(Pin1);
  delay(2);
  led2.on(Pin2);
  delay(2);
  led3.on(Pin3);
  delay(2);
}

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


text:
How to make data sent by Python (via serial connection) wait for Arduino to finish current task?
I am trying to make my Arduino micro-controller and my Mac talk together, and I have created a functional serial connection. My computer is sending data to my Arduino, and my Arduino is sending a 1 when it is ready to receive a new piece of data.
I have created an if-else statement (Python script below), which is either sending a new line of data to the Arduino or waiting for the Arduino to be ready for receiving a new line of data.
The problem is that ser.read() in the first part of the Python script always returns 1, which means that the script is sending the individual data lines faster than the Arduino connected stepper motors can possible react.
In the Arduino script you can see that I am sending the state-status in the first line of the serialEvent() function, which in my world should let the Arduino finish its job, before a new "task" is coming. However, it is for some reason not working. Can anybody help me out here?
Python script
import os
import time
import serial

# Name of csv file with drawing coordinates
csvFile = "scaled_coordinates.csv"

# Create serial connection
ser = serial.Serial(port='/dev/tty.usbserial-A9005bDh', baudrate=9600)

wd = os.getcwd()
myFile = open(wd + "/coordinates/" + csvFile)

state = '1'

while True: # Exits when there is no more lines to read
    print "test"

    if state == '0': # Wait for Arduino to be ready
        state = ser.read()

    elif state == '1': # Send one more line to Arduino
        line = myFile.readline()
        if not line:
            break
        print line
        ser.write(line)
        state = '0' # Wait for Arduino before reading next line

ser.close
myFile.close

Arduino loop function
void loop() {
  serialEvent(); // Call the serial function
  if (coord_complete) {
    // Steps to move from currrent to new point
    target1 = steps(x_current, y_current, x_new, y_new, 1);
    target2 = steps(x_current, y_current, x_new, y_new, 2);

    // Start moving
    stepper1.move(target1);
    stepper2.move(target2);

    // Update current position
    x_current = x_new;
    y_current = y_new;

    // Reset variables
    x_complete = false;
    y_complete = false;
    coord_complete = false;
  }

  // Stay in while loop until steppermotors is done
  while ((stepper1.distanceToGo() != 0) && (stepper2.distanceToGo() != 0)) {
    stepper1.run();
    stepper2.run();
  }
}

Arduino serialEvent function
void serialEvent() {
  // EDIT : PUT SERIAL.WRITE INSIDE IF STATEMENT //
  if((stepper1.distanceToGo() == 0) && (stepper2.distanceToGo() == 0)){
    Serial.write('1'); // Tell Python that Arduino is ready for one more line
  }

  while (Serial.available() && coord_complete == false) {
    char ch = Serial.read(); // Get new character
    // EDIT : REMOVE THIS LINE //
    Serial.print(ch);

    // If digit; add it to coord_string
    if (isDigit(ch)) {
      coord_string[index++] = ch;

    // Else if ch is ","; then rename to x_new
    } else if (ch == ',') {
      coord_string[index++] = NULL;  // Finish coord_string
      x_new = atoi(coord_string);    // Convert to integer
      x_complete = true;             // Change x_complete to true
      index = 0;                     // Reset index
      memset(coord_string, 0, sizeof(coord_string));  // Reset coord_string
    // Else if ch is a new line; then rename as y_new
    } else if (ch == ';') {
      //Serial.write('0');
      coord_string[index++] = NULL;
      y_new = atoi(coord_string);
      y_complete = true;
      index = 0;
      memset(coord_string, 0, sizeof(coord_string));
    }

    // Ends while-loop when true
    coord_complete = x_complete * y_complete;
  }
}

Edit
I have changed a bit in the first few lines of the serialEvent function (See comments).
Here is a sample of the text file I am reading from:
239,275;
1100,275;
300,400;
200,400;
200,300;

I'm voting to close this question as off-topic because you have cross posted it to stack overflow and answered it there. http://stackoverflow.com/questions/33805986/how-to-make-data-sent-by-python-via-serial-connection-wait-for-arduino-to-fini/33853784

If I'm getting things right, your program fails in the above:
when you send the first message in python, you set state = 0. In
  arduino you enter the serialEvent function and while is triggered. You
  get the first char and send it through Serial.print (but this char
  will be send to python!!!). For the sake of example let's say the
  first char you get from cvs is '2'. At this point let's hold on a
  sec and look what happens in python. State was '0' but as you have
  used in arduino Serial.print(ch); now state will be updated with
  '2'. This will cause no more triggers of the if-else statements in
  python.
edit:
By now, and also as a debug, add this lines at your code:
if state == '0': # Wait for Arduino to be ready
    state = ser.read()
    if state != '1':
        print "state: " + state
        state = '0'

However if csv file contains '1's values this will also cause a
  problem. Do you really need that Serial.print(ch) in arduino?

EDIT The new version since comments
Basically if you are trying to do things before new coordinates, you have to do things in a sequential way. You only ask for info after making all the moves. This is the code I've used to test.
Note: I had to adapt your code because was missing the complete arduino code to test it. So I kinda simulated the motor moving etc with delays. Please adapt to your original code
#include <string.h>

bool coord_complete = false;
byte stepper1_disToGo = 0, stepper2_disToGo = 0;
// debug things
int led = 13;
bool led_state = true, x_complete, y_complete;
char coord_string[256];
int index = 0, x_new = 0, y_new = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  memset(&coord_string, 0, sizeof(coord_string));
}

void loop() {

  serialData(); //ask and process more data

  /*
    // Steps to move from currrent to new point
    target1 = steps(x_current, y_current, x_new, y_new, 1);
    target2 = steps(x_current, y_current, x_new, y_new, 2);

    // Start moving
    stepper1.move(target1);
    stepper2.move(target2);

    // Update current position
    x_current = x_new;
    y_current = y_new;

    // Reset variables
    x_complete = false;
    y_complete = false;
  */
  delay(2000); //replace to simulate actions
  stepper1_disToGo = 10;
  stepper2_disToGo = 10;
  coord_complete = false;

  // replaced to simulate
  /*
    // Stay in while loop until steppermotors is done
    while ((stepper1.distanceToGo() != 0) && (stepper2.distanceToGo() != 0)) {
    stepper1.run();
    stepper2.run();
    }
  */
  while ((stepper1_disToGo != 0) || (stepper2_disToGo != 0)) {
    stepper1_disToGo --;
    stepper2_disToGo --;
    digitalWrite(led, led_state); // is moving!!!!
    delay(100);
    led_state = !led_state;
  }
}

/*
   you try to use the serialEvent  but the structure of
   your code and the verifications make it act like sequential.
   If you only want to make things after all steps are done there
   is no need for the serialEvent function
*/
void serialData() {
  /*
     This will never be false because you are stuck in the while

    // EDIT : PUT SERIAL.WRITE INSIDE IF STATEMENT //
    if((stepper1.distanceToGo() == 0) && (stepper2.distanceToGo() == 0)){
    Serial.write('1'); // Tell Python that Arduino is ready for one more line
    }
  */
  //EDIT: wait for info
  while (Serial.available() < 1) {
    Serial.write('1'); /// Tell Python that Arduino is ready for one more line
    delay(500);// ask for info sometimes
  }
  while (Serial.available()) {
    char ch = Serial.read(); // Get new character

    // If digit; add it to coord_string
    if (isDigit(ch)) {
      coord_string[index++] = ch;

      // Else if ch is ","; then rename to x_new
    } else if (ch == ',') {
      coord_string[index++] = NULL;                   // Finish coord_string
      x_new = atoi(coord_string);                     // Convert to integer
      x_complete = true;                              // Change x_complete to true
      index = 0;                                      // Reset index
      memset(coord_string, 0, sizeof(coord_string));  // Reset coord_string

      // Else if ch is a new line; then rename as y_new
    } else if (ch == ';') {
      coord_string[index++] = NULL;
      y_new = atoi(coord_string);
      y_complete = true;
      index = 0;
      memset(coord_string, 0, sizeof(coord_string));
    }
    //EDIT: change to AND verification
    // Ends while-loop when true
    coord_complete = x_complete && y_complete;
  }
}

The structure of your loop should be:

ask for data and wait for it
Read data and parse it
Calculate steps needed
move servos till new positions
repeat

this should be your new code more or less if no mistakes were made because can't really test this version (is missing the variables declarations setup, includes etc...)
void loop() {

  serialData(); //ask and process more data
  // Steps to move from currrent to new point
  target1 = steps(x_current, y_current, x_new, y_new, 1);
  target2 = steps(x_current, y_current, x_new, y_new, 2);

  // Start moving
  stepper1.move(target1);
  stepper2.move(target2);

  // Update current position
  x_current = x_new;
  y_current = y_new;

  // Reset variables
  x_complete = false;
  y_complete = false;
  coord_complete = false;

  // Stay in while loop until steppermotors is done
  while ((stepper1.distanceToGo() != 0) && (stepper2.distanceToGo() != 0)) {
    stepper1.run();
    stepper2.run();
  }
}

void serialData() {

  //EDIT: wait for info
  while (Serial.available() < 1) {
    Serial.write('1'); /// Tell Python that Arduino is ready for one more line
    delay(500);// ask for info sometimes
  }
  // we got info!!!
  while (Serial.available()) {
    char ch = Serial.read(); // Get new character

    // If digit; add it to coord_string
    if (isDigit(ch)) {
      coord_string[index++] = ch;

      // Else if ch is ","; then rename to x_new
    } else if (ch == ',') {
      coord_string[index++] = NULL;                   // Finish coord_string
      x_new = atoi(coord_string);                     // Convert to integer
      x_complete = true;                              // Change x_complete to true
      index = 0;                                      // Reset index
      memset(coord_string, 0, sizeof(coord_string));  // Reset coord_string

      // Else if ch is a new line; then rename as y_new
    } else if (ch == ';') {
      coord_string[index++] = NULL;
      y_new = atoi(coord_string);
      y_complete = true;
      index = 0;
      memset(coord_string, 0, sizeof(coord_string));
    }
    //EDIT: change to AND verification
    // Ends while-loop when true
    coord_complete = x_complete && y_complete;
  }
}

It makes sense to delete the Serial.print(ch) but it is still not working for me. I guess I have to clear the serial buffer or something. I can see that the my python code somehow is getting stucked in the if-statement.

@Christoffer can you edit your post and had a few lines of your csv file for testing? thanks.

sure. I have changed the post now.

@Christoffer Hope it helps now to achieve your goals. If it still doesn't work, supply the complete arduino code. However, i'd like to suggest you to parse the csv in python and send coordinates to arduino by using two strings or using a binary data. The easiest away should be using strings and Serial.parseInt() in arduino for each string.

I figured out that the solution was to clear the serial buffer and implement a minor delay. The solution is here: http://stackoverflow.com/questions/33805986/how-to-make-data-sent-by-python-via-serial-connection-wait-for-arduino-to-fini/33853784#33853784

@Christoffer OK, glad you make it work :)


text:
How to flash the "atmega328" with AVRDUDE?
I have an external device using an ATmega328, not a ATmega328-P as used by the Arduino Uno.
Now I want to use AVRDUDE and an Arduino Uno to flash a hex file on this chip. Therefore I removed the ATmega that came with the Arduino and popped in the one without the "-P".
With the Arduino IDE, it doesn't work, so I tried AVRDUDE:
avrdude -c arduino -P com3 -p ATMEGA328 -b 19200 -U flash:r:sdint.hex:r

However, I'm doing something wrong here, because it does not work:

avrdude: stk500_recv(): programmer is not responding
  avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
  avrdude: stk500_recv(): programmer is not responding
  avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
  ...

What commandline should I use to flash an Arduino Uno with an ATmega328?

Does it give any error messages?

I'm sorry I didn't provide them. I would have to get my whole setup here and disassemble the other device again. But I get different error messages with different command lines I tried. And I tried a lot of them.

When posting an issue on SE, if there is an error message, include it in the post - the error message usually says exactly what's wrong, if you can decode it. I think you are unlikely to get an answer if you don't post the error message.

I will update it then. Give me just a few minutes.

I have updated it with the error message.

I always had troubles getting these to work :(

do you know if the atmega328 has the bootloader in it?

It's probably a blank atmega328, so without a bootloader, right? Try uploading the sketch using Arduino as ISP

I don't know if it has a bootloader. Could be that it doesn't. Uploading a sketch using the Arduino IDE doesn't work. So how do I burn a bootloader (without modifying its functionality)?

This seems to be quite a common problem, and there are a number of problems, each with their own solution.

Make sure you have selected the right chip
Make sure you have selected the right serial port (when you unplug your board, it should disappear).
Make sure you do not have anything plugged in to the tx & rx pins (usually 0 and 1).
Make sure your Atmega chip has a bootloader on it
Try another cable
There may be a problem with your computer - try another computer
If using another helps, try reinstalling the USB serial driver
Try unplugging the Arduino board, holding down the reset switch, then plugging it in (still holding down reset); continue to hold down reset for about 5 seconds.
make sure nothing else is trying to use your serial port
Does your chip have a bootloader? Chips bought as part of an Arduino will, otherwise, it almost certainly doesn't, unless it specifically says (in the description of what you bought).

If it does not have a bootloader (or may not have a bootloader) you will need to set this up. You can either use the instructions here: https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard (which I never got working) or you can use an ICSP like the http://www.freetronics.com.au/products/usbasp-icsp-programmer-for-avr-arduino#.VlIY_2xifXs (which is what I use) - works great. They can be had for a few dollars from China.

I'm not even using the Arduino IDE, have you read my question? And... another cable........

I am sorry for offending you by mentioning the IDE, I have corrected it. As mentioned in my post, this error is a common error, and to save others from having to post another question, I have given as many possible answers as I could think of. Also note the answer at the bottom, which I have just added

Most likely I don't have a bootloader. The chip I'm using didn't come with an Arduino. It was part of a DIY circuit board. Can I burn a bootloader using an Arduino, without buying additional hardware?

Yes - using the first of the two links at the bottom - you'll need a working Arduino (with a bootlloader - you don't mention why you bought the new chip, so this may not be possible), and the separate chip (without the bootloader). Your mileage may vary, and if you have problems, I recommend getting the ICSP, which is cheap, and I've never had a problem with.


text:
Building an adjustable low frequency PWM controller with Arduino
I am looking for a way to create an adjustable PWM controller capable of modulation frequency from 0-100 (more preferably 0-1000) Hz, duty cycle from 0-100%, and able to accept a voltage range of 5-30V DC. I have looked through Sparkfun and Adafruit for product or PWM shields capable of this and I have yet to find one. Some servo shields can be programmed down to 50Hz and arduino itself can be slowed to like 30Hz using timer0 and timer1 changes. However none of these options make it easy to vary frequency and none of them can accept much more than 6V.
I have searched far and wide and found a few interesting things:
1) http://www.instructables.com/id/The-ultimate-PWM-driver-for-many-applications/
 This instructable shows an analog un-sensored PWM driver. It would get the job done here however, I need a way to read my Frequency and Duty Cycle

2) https://www.electronicsblog.net/arduino-frequency-counterduty-cycle-meter/

Here there is a way using pulsein() and other arduino functions to read both frequency and duty cycle as seen above. But then this is also assuming you're PWM voltage is 5V. So maybe you use a 5V regulator on the signal into the arduino? Would something that simple work or would it skew the signal and prevent accurate measurements?
Obviously, if anyone has a better idea I'm open to it. I've been searching for a solution for some time. The trouble really seems to be the low frequency PWM request.

The ATmega328 in the Arduino Uno has a 16-bit timer (Timer/Counter 1) which can do PWM. It has a prescaler that can divide by 1024.  The lowest frequency that it can generate is about 0.12 Hz:
16MHz / 1024 / 65535 / 2 = 0.1192 Hz

We change the PWM frequency by changing the "top" value. For higher frequencies, lower the top value, and/or pick a smaller prescaler.
(And, really, what does 0 Hz PWM even mean?!? :-)
The duty cycle can vary from 0-100%, with the resolution changing with the specific frequency you generate.
As for the high-voltage... use a motor driver, or darlington, or hexfet, or whatever...
I'm confused as to why you're reading the frequency. With the 16MHz crystal, you set it and you get what you asked for (within the crystal tolerances, temperature, etc.)
At least, that's how I think it works.
Good luck!

So for 440Hz at 25% on pins 9&10, you might choose a fast PWM with Wave Generation Mode 14, 16e6 /1/440 = 36363 TOP with /1 prescaling, so: ICR1=36363 ; TCCR1A=0b10100010; TCCR1B=0b00011001; TCCR1C=0; OCR1A=36363/4

The PWM Waveform Generation Modes with a settable TOP value (e.g. set with the OCR1A or ICR1) are the ones that can achieve these low, adjustable frequencies. Set the Waveform Generation Mode mode and prescaler with the TCCR1* registers and then the duty cycles would be modified by adjusting OCR?B. For frequencies below the threshhold the timers can handle, one could switch over to toggling based on elapsed millis() and handle frequencies down to 1 cycle per 50 days.

@Mike I appreciate the help. However I truly intend on the PWM frequency to be variable. And yes 0Hz is improper but my point is to make it very low. Using prescale factor like shown in this link you can only reach 30Hz using prescale factors. If you also modulate your TOP values I suppose you get any 16-bit value from 1-65535 in resolution. The 2 indicate difference between the two outputs?? link

@Mike  Either way this looks like I'll be able to modulate frequency easy enough...Now just the high voltage. I'll have to think more about that. But I definitely think you solved my frequency problem.

Your question is so close to my own project, for a second I thought it was something I posted awhile back, go figure.   I don't expect you to gain from my answer, me coming along to find your question some 2 years, 5 months later. It may be of help to others who pass by this way in the future. I am currently working on the exact same variable duty cycle controller and will offer up my findings.
The following programming code is the result of apx. 5 months of study into the Arduino programming as well as a long failing attempt at getting control through a series of 555 timer chip builds. I shit canned the 555 timer chip & Darlington transistor method. I thought it was too crude, and all 'engineering' schematics never allowed me to have anything more than a 50% duty cycle control. I wanted control over all PWM variables. Today I will be purchasing a metal case, or making one that can hold apx. 5-6 potentiometers allowing me to adjust every possible variable within the PWM domain of parameters (there are more variables than what I have in this code below). I will give you some details in the code first, that will give you some idea of the obsessively precise control I'm demanding from my PWM project:
Getting into the heart of the variable HIGH/LOW control. Be sure to read everything you can to understand fully why these functions are needed. Also, know that with 10 bits the 1023 value allows a resolution of .0043 volt increments (really nice):
void loop()
{
Potentiometer1 = analogRead(PotHzHIGH);
Potentiometer1 = map(Potentiometer1, 0, 1023, 1023, 0);
Potentiometer1 = constrain(Potentiometer1, 500, 1023);

Potentiometer2 = analogRead(PotHzLOW);
Potentiometer2 = map(Potentiometer2, 0, 1023, 1023, 0);
Potentiometer2 = constrain(Potentiometer2, 500, 1023);

Potentiometer3 = analogRead(Pot5Volts);
Potentiometer3 = map(Potentiometer3, 0, 1023, 1023, 1023); //Hold at 12Volts
Potentiometer3 = constrain(Potentiometer3, 0, 1023);
//Potentiometer3 can either be locked at 12volts with the map function, or
//you can use a Potentiometer to varry the voltage. I illistrate the
//constant at 12 volts with the map function - low/high both set to
//1023 & 1023

digitalWrite(PotHzHIGH, HIGH);
//turn it ON delayMicroseconds(PotHzHIGH);
//Keep ON for Potentiometer1=PotHzHIGH Microseconds
//1000 microseconds = 1millisecond; 1000ms = 1second

digitalWrite(PotHzLOW, LOW);
//turn it OFF delayMicroseconds(PotHzLOW); //Keep OFF for
Potentiometer2=PotHzLOW Microseconds
//1000 microseconds = 1millisecond; 1000ms = 1second;
//Largest value within the delayMicroseconds function: 16383microseconds
//Largest value when converted to milliseconds is 16.383ms, or axp. 1/20th of
//...a second

}
//other things to understand about the above program. It is possible to
//have the LOW written with: delayMicroseconds(PotHzLOW+100);
//or delayMicroseconds(PotHzLOW*1.1);
//You can add an additional potentiometer to be the multiplier of the LOW.
//these added controls prevent the LOW from ever being less than the high.
//this can come in handy if you wish to work within duty cycles that are
//between 1% & 50%. It is of interest to me because I am dealing with
//high frequencies.

timkasey1@gmail.com


text:
Arduino and WS2812 RGB LED Strip "freezing"
I have been working on a project as a gift for my girlfriend for Christmas which involves some a bunch of standard "white" LEDs controlled by shift registers and darlington arrays, and also some RGB LED strips (WS2812B strip, 29 LEDs on strip). Everything is going fine with the white LEDs, but not so much with the RGB ones.
If I leave the RGB leds running for a while all of the LEDs on the strip turn red, except for the first one, which continues to change color. I am not sure how long "a while" is because in "short term" testing, approximately running continuously for an hour, it works fine and all of the LEDs change appropriately, but if I leave it running overnight I wake up with the issue of all red and one single RGB "working". I then have to reset to get it working again. These RGB LEDSs need to be run for long periods (24 hours) of time without "freezing". The rest of the program (with the normal LEDs) continues to work fine despite the RGB ones not.
Let me explain how I am controlling them. V_rgb is 5V (5V - 8A power supply), which it is also grounded to. Then the data line, C, is connected to an Arduino Uno, on pin 12, which is a PWM pin.
In software, I am using a Adafruit Neopixel Library to control the RGB LEDs and write their respective colors, based off the examples given in their git repo and the tutorial here.
I have pasted my code below in case that may help, but honestly I am not sure if it is software or hardware related. (unrelated code has been removed)
#include <Adafruit_NeoPixel.h>
#define rgbPin 11
#define numRGBleds 29

Adafruit_NeoPixel strip = Adafruit_NeoPixel(numRGBleds, rgbPin, NEO_GRB + NEO_KHZ800);
int colorStep = 0;
int rgbIndex = 0;

void shiftColor() {
  int i = 0;
  for (i = 0; i < numRGBleds; i++) {
    int idx = (rgbIndex + i) % numRGBleds;
    int colorVal = round(i * colorStep);
    strip.setPixelColor(idx, Wheel(colorVal & 255));
  }
  strip.show();
  rgbIndex++;
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

void setup()
{
  strip.begin();
  strip.show();
  rgbIndex = 0;
  colorStep = 255 / (numRGBleds - 1);
}

void loop()
{
  shiftColor();
  delay(1000); // Redo every second
}

My thoughts of what it could be are the following, let me know if any make any sense or are known issues:

Having issues with micros() value rollover
Overheating
Noisy power supply
Defective LED strip
black magic?

Thanks in advance for any help.
UPDATE
My current solution to the problem is to just reset the board using the watchdog functionality. It reboots in a few milliseconds and sometimes flashes in the process, but I would like to figure out the real problem.
UPDATE #2
So with the reset solution, I left it running overnight and it did not freeze which leads me to think it is definitely a software, not hardware, issue. I have changed some of the wiring and coding to make sure the watchdog reset is not noticeable. It resets every half hour or so. This will make sure all of the memory is cleaned, except stuff I store in the EEPROM (which I do use to make the reset less noticeable). This reset delays processing by a few milliseconds, but time is not critical, so it is not a big deal.
I still however, would like to know a more elegant way of doing this. The software reset is a bit "hacky"

Do the Arduino and LED strip share a common ground? You'd expect to connect more than just the signal line to the Arduino.

@TomvanderZanden They do. Everything is connected to the same ground line through the power supply.

Is everything connected to the same power supply? Chances are the power supply is galvanically isolated so nothing is connected to anything through it.

@TomvanderZanden yes, all is wired through one 5V - 8A power supply. The arduino is powered through the 5V pin, which is wired in parallel to LED strip. Note that a reset does fix the problem, without disconnecting power.This is my power supply

Try changing delay(1000) to delay(1). That way the problem might pop up a lot faster. Also, try changing rgbIndex++; to rgbIndex=(rgbIndex+1)%numRGBleds;. I thing the problem is the int rgbIndex rollover, which occurs after about 9 hours.

@Gerben That is actually a fantastic point, I was not considering the rollover of rgbIndex. and since it is an int, it will flip to a negative on rollover, which is an invalid address on the LED strip. I was also under the impression until now that ints were 32-bit. Such a naive assumption, clearly I don't program for Arduino frequently

@Gerben That seemed to fix the problem. I will still let it run overnight, but it has been running now for over 3 hours , with the update rate being 5 times as fast as it was previously (it is now delay(200)) and it is has not frozen yet, so that would be equivalent to 15 hours previously, which definitely would have seen it freeze. Thanks for the help, if you want, post the same thing in an answer and I will accept it.

Try changing rgbIndex++; to rgbIndex=(rgbIndex+1)%numRGBleds;. I thing the problem is the int rgbIndex rollover, which occurs after about 9 hours.
Also try changing delay(1000) to delay(1). That way the problem might pop up a lot faster.

Thanks a lot for your help! I left it overnight and it is working perfectly now. Sometimes you can stare at your code for hours on end, and then someone else looks at it for 2 minutes and immediately sees the problem.

Well, to be honest, there was nothing wrong with you code, except for the fact that computers only allocate a limited number of bit to represent a number. Anyways, glad to be of help.

valid point, if only arduino int was 32 bit, it would not have been an issue for 68 years, which is well beyond what I expect to actually get out of the project. And that is assuming it never loses power, which if for sure will at some point.


text:
Yun availability
I am starting a project that may need a lot of Arduino Yuns in the future, but today I found that they are not available on the official Arduino store.
What's the story on the Yun? Is it being replaced by something newer? Also, how can I evaluate the longer-term availability of this board?
In case it's helpful, I need the dual-processor setup, wifi capability, and extra storage of the Yun.

If you need a lot of them, the Yun, or frankly anything branded Arduino, is probably not the best choice.  For anything production oriented, define the specific characteristics you actually need, and then look at the range of platforms providing them.  There are lots of wifi/IoT type boards on the market, of both embedded linux and bare metal varieties.  You will be most secure if you can distinguish the generic parts of your system from the layers needed to tailor it to a particular board, as that gives you the future option of changing out the board based on market conditions.

In short: Who knows?!
With all the in-fighting between the two Arduino factions (Arduino.cc and Arduino.org) it's anyone's guess what boards are going to be available this time next year, and of those that are available which of the two factions will be producing and distributing them.


text:
Identifying Arduino-compatible board signatures in code
I am developing libraries for compatibility across a number of Arduino/compatible boards. I know that Arduino boards can be identified by the test "#if defined (AVR_ATmega328P)" and compatibles as well: #if defined(TM4C123GH6PM).   There are a few lists of these IDs on the web but are all outdated. I have searched various cores and library code and do not see where these defines are actually defined.
Nick Gammon's Sketch to detect Atmega chip types identifies the chip type. What I'm looking for the board type to define pin configurations, etc.
Where and in what format are board signatures stored? Is there c++ code that can find the board signature? Does anyone know of a site where these signatures are stored and updated by the Arduino community?

In the boards.txt file each board has a board type definition, such as:
uno.build.board=AVR_UNO

When you compile your sketch that is adapted into a "board" define by prepending -DARDUINO_ to it and adding it to the compilation command line - so that one becomes the same as #define ARDUINO_AVR_UNO.  You can, of course, test for it with:
#ifdef ARDUINO_AVR_UNO
....
#endif

The location of the boards.txt file varies with different versions of the IDE, but every installed core will have one.  Look around in your Arduino program folder in the hardware subdirectory.

Thanks, Majenko. That one has been bugging me for months.


text:
Why does an LED sometimes flash when increasing brightness?
This is admittedly a cross-post from LED fade malfunction (random flash)  but I can't get an answer on the Arduino forum.
I was mucking around with some very basic code and I noticed that when repeatedly holding an LED at 0 brightness for 1 second and then fading in to full brightness, a small flash would occasionally happen at the beginning of each fade (seemingly random).
int led = 11;
int brightness = 0;

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

void loop()
{
  if(brightness >= 256) //checks if brightness has passed 255, resets to 0
  {
    analogWrite(led, 255);
    brightness = 0;
  }
  analogWrite(led, brightness);
  if(brightness == 0)
    {
      delay(1000); //LED off for 1 second
    }

  brightness+=1; //increment brightness
  delay(20);
}

So, the thing that has me completely perplexed is that I can use a different piece of code (below) and the flash goes away!
int i = 0;
int led = 11;

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

void loop()
{
analogWrite(led, i);
delay(6);
if(i%256 == 0)
{
  i = 0 ;
  delay(1000);
}
i++;
}

Has anyone got any clue as to why this would happen? Both programs have basically the same code, except for that i is reset to 0 in the first program whereas in the second, i keeps incrementing past 255 so that analogWrite 'overflows.' I think it must be a firmware, (or maybe a software?) problem.
There is a video on youtube of it happening here, Arduino - fading LED problem.

Try removing analogWrite(led, 255); as it's quite useless, given that two lines below it, it is set back to 0. Can't see anything really wrong with the code (other that a bit of a weird order).

In your second code, change delay(6) to delay(20) - does the flash appear? You've got the second code rolling round three times faster than the first code (ignoring the 1-second delay, of course), so the random flash is probably undetectable. As for why there's a flash at all... no idea.

@Gerben That is true... :) Will do

@CharlieHanson I have tried increasing the delay and it doesn't have any effect. I can still detect the flash with the 6 second delay. I have now got a good answer/explanation as to why it happens on the Arduino forum.

Oops, I meant 6 millisecond delay.

According to the links you provide from the arduino.cc forum the question is more or less answered. If not that important, just avoid analogWrite(led,0) and make it analogWrite(led,1)
if you still want that analogWrite(led,0), I've tested your code with the advice and it seems to work OK when changing the register manually:
#include "wiring_private.h"

int led = 11;
int brightness = 0;

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

void loop()
{
  if (brightness >= 256) //checks if brightness has passed 255, resets to 0
  {
    brightness = 0;
    sbi(TCCR2A, COM2A1);
    OCR2A = 0; // set pwm duty
  }

  analogWrite(led, brightness);
  if (brightness == 0)
  {
    delay(1000); //LED off for 1 second
  }

  brightness += 1; //increment brightness
  delay(20);
}

Edit: to explain what those "strange codes" are
I'm not very expert in this field to explain how exactly this works but basically sbi is function defined in a macro by Atmel (?), it stands for "set bit in" and is used to change registers of ATmega chips. So basically what I did was change register defined by the macro TCCR2A (why? because it is the register that controls PWM in pin 11) and pass the bitmask COM2A1 (this is a mode of compare defined in datasheet) and OCR2A is a register used to store the compare value that defines duty cycle. Imagine a counter that every time it receives a tick from a signal clock it compares the value of the counter with the value stored in OCR2A and it sets the pin high or low if that value as been passed or not (more or less like this, depending on the mode stored on TCCR2A).
But in fact I've not done some black magic. I just looked into the code of analogWrite() and that is the way they use to set a value of PWM in pin 11:
void analogWrite(uint8_t pin, int val)
{
    // We need to make sure the PWM output is enabled for those pins
    // that support it, as we turn it off when digitally reading or
    // writing with them.  Also, make sure the pin is in output mode
    // for consistenty with Wiring, which doesn't require a pinMode
    // call for the analog output pins.
    pinMode(pin, OUTPUT);
    if (val == 0)
    {
        digitalWrite(pin, LOW);
    }
    else if (val == 255)
    {
        digitalWrite(pin, HIGH);
    }
    else
    {
        switch(digitalPinToTimer(pin))
        {

...

          #if defined(TCCR2A) && defined(COM2A1)
            case TIMER2A:
                // connect pwm to pin on timer 2, channel A
                sbi(TCCR2A, COM2A1);
                OCR2A = val; // set pwm duty
                break;
          #endif
...

}

So basically I just used that info to set the register to zero, as suggested from the arduino.cc forum link that you have.
If you want to know more about PWM in Arduino, this site has a lot of info and explains a lot of the modes of registers also.

Thanks @Personagem, I will test it, but could you please explain the use of sbi, TCCR2A, COM2A1, and OCR2A. Also, considering that wiring_private.h is of the included header files in the Arduino directory, is it necessary to include it?

Also, how do you learn how to use these libraries in the first place??

@Adrian I've edit to explain a bit of those codes and arduino IDE complains if I do not made that include. I'm not really an expert but if you want to dig in, the datasheet of atmega is your friend. This should be used in kinda of advanced way. What arduino.cc team did ( and that is the real beauty that change a bit everyone's world) was create simple functions that don't need typical user to dig into datasheets and some registers settings. They kinda made simple what could be hard for not so experienced people. However if you really need you can look at all code in github of arduino

Thanks a lot for the help, explanation and for the link. I can basically see how to do it now. I think you can also find all of the code in \hardware\arduino\avr\cores\arduino.

Wouldn't analogWrite(led,1) accomplice a similar effect to sbi(TCCR2A, COM2A1);OCR2A = 0;? I.e, setting the duty cycle to a very low value, just before setting the output to LOW. That would make it a lot more readable.

yes it does, I've suggested that in first sentence. But in case he really wanted for any reason or just curiosity this should be the way. In fact the problem relies on how analogWrite function handles values of 0 and 255 without changing the registers


text:
Newbie - What is the Difference Between Power Supply's GND and Arduino's GND?
I am new to electronics and Arduino.
What is the difference between power supply ground and Arduino's ground. If I connect my LED cathode to power ground, it doesn't work. But if I connect it to Arduino ground, it works. Aren't all ground the same?
Please see picture below.

Could the power supply / ground bus on your breadboard be split? One difference that I see is that the LED ground to the power supply is more than half way down the breadboard. I've got some that are split in the middle.

dlu, you are right! The breadboard was split in half. Silly me.

I'll bet it never fools you again! You're certainly not the first person to wonder about this…

I had long forgotten about the split in the breadboard power rails. Even when @dlu mentioned it, I thought, that couldn't be it. But then when memory serves, my breadboard have little connectors between the two rails top and bottom. I kinda see the benefit of it, but I would expect the power rail indicator lines to be split (I noticed my boards are). ie, the blue and red lines on the outer edge of the breadboard, are they continuous from one end to the other (as in your diagrams above) or are they themselves broken in the middle? As is mentioned, that won't trip you up again :)

I would expect there to be no difference between the grounds in your circuit, and after looking over the schematic for the board, it appears that all of the grounds are common.
I think the most likely explanation for what you're seeing is a quirk in the breadboard. It may be that the side busses are split at the middle of the board, or perhaps there was just a bad connection somewhere on the ground bus on that side of the board.
One way you could troubleshoot it further would be by jumping the ground side of the LED to the power supply ground. Start with the ground on the regulator and then work out until you find the spot where you loose continuity.

I agree with the other answers.  On rare occasions, TO-xxx packages have bizarre pinouts, but the 78xx series does, in fact, have ground on the middle terminal.  This is surely a split power supply in your breadboard power busses, or else a bad breadboard.  Many breadboards have splits in the power rails halfway down.  I've also seen some with splits more often than that, perhaps as much as disconnects every 5 (or 5 pairs of) contacts.  I have a breadboard, for example, which allows for 6 different voltages, all in a single line, from various connections to a battery pack.  I'd recommend buzzing the breadboard before starting to use it.
I've also had breadboards whose contacts fail after using larger AWG wires in particular holes (or forcing odd connections, such as machined contacts on IC's or sockets, or larger stamped rectangular pins on a TO package such as this) into breadboard holes. The last thing you want to worry about when building a prototype of a new design is whether or not the wiring under the breadboard works.
Many multimeters have a continuity test capability for diagnosing problems such as these, BUT make sure no power is connected (or you could damage the meter on this setting).


text:
Library to correct time for DST
I am using a Uno as a data logger with a DS1307 RTC and the following libraries Time.h DS1307RTC.h
The DS1307 does not have any support for DST and neither library includes Time Zone.
Are there any libraries which adjust for DST?

I used the Timezone module to correct my times for DST.
It took a little time to sort it out, so I though I would post the steps I followed.
Customise WriteRules for my Timezone.
I copied rule from WorldClock.
NOTE also need to modify Timezone in setup(void)
Run WriteRules.pde to write rules to EEPROM address 100
Run TimeRTCSet.pde to set RTC time to UTC.
Start Serial Monitor.
In Terminal send time to Arduino
date -u +T%s > /dev/tty.usbmodemFA131

Run HardwareRTC.pde to demonstrate time display in UTC & local
I modified my sketch by including the following code:-
#include <Timezone.h>    //https://github.com/JChristensen/Timezone
⋯
Timezone myTZ(100);       //assumes rules stored at EEPROM address 100
TimeChangeRule *tcr;        //pointer to the time change rule, use to get TZ abbrev
time_t utc, local;
⋯
utc = now();
local = myTZ.toLocal(utc, &tcr);

Do you have any idea how huge the DST database is? Work in UTC, and perform the conversion on a bigger machine.

@IgnacioVazquez-Abrams I am logging to FAT, and want to store file times in the usual format.

You could use the Timezone library.

The HardwareRTC appears to be what I am looking for. I will use WriteRules to store my time zone in EEPROM.


text:
Why can't I include a library in another one?
I am trying to create a new library that uses another existing library.
The original library declares a way to create an object called Multiserial that can be created in the main file and the program is correctly compiled.
However, when I include this library in a second one and I try to build the program, then the IDE returns an error that says:

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:27:0,
                   from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26,
                   from MultiSerial.h:17,
                   from maqMODBUSmst.h:5,
                   from maqMODBUSmst.c:1:
  C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Printable.h:25:1: error: unknown type name 'class'
   class Print;

Even if the library only contains the include of the first one.

I am absolutely stupid. The fail was that ai was trying to use classes in a .c instead creating a .cpp

Nested includes lead to these convoluted error messages and are in general, a PITA for the next reader to follow & understand. It is better practice for the dependent library to test, at compile time, for the existence of its required libraries and for each one found missing, issue:
#error DepLibe.h: Missing required include file ReqLibe.h

Most .h files guard against multiple-inclusion by
#ifndef _REQLIBE_H_
#define _REQLIBE_H_
// library definitions here

or some variant of it. DepLibe.h can test for these guard symbols. DepLibe.h should document the dependencies in prominent comments.


text:
Arduino graphic interface
I succeeded in programming a system of thermoregulation using Arduino.  This system holds the temperature of a plate at 37°C. I used a PID corrector to realize this.
What I want to do now is make a graphic interface that can communicate with the Arduino, allowing me to see a graph of the temperature.
I would like an explanation of how to send temperature data to a graphic interface using Arduino Uno.

There are two main possibilities.
The first one is to make a GUI on the Arduino itself. Add a TFT screen, touchscreen if you want the user to interact, or a non-touchscreen (cheaper) if you just want to display. Then, within your Arduino code, you can display the temperature data, and if you go the touchscreen route, interact with the user.
I own a couple of Arduino Esplora devices, and they would be near perfect for this, as they have a non-touch TFT screen, a joystick, buttons and a pot. All the equipment you need to display the temperature. Oh, and it has temperature and light sensors onboard.

The second way would be to make a GUI on your desktop/laptop machine. In your Arduino code, you could send your temperature data through USB (Serial), Bluetooth (SoftwareSerial), WiFi, Ethernet, nRF, etc etc etc. If you don't mind having the Arduino tethered to your computer by a cable, USB<-->Serial is the easiest solution. The software on the computer listens on a serial socket and when it receives temperature data, it displays it within its GUI.
HTH

It all depends on what graphical interface.  There's many ways of doing it.  You have TFT screens that the Arduino controls directly (take a look at UTFT for example), or serially connected displays (such as the ones offered by 4D Systems).
First you need to decide what kind of display device you want to use - and that is deciding:

What your budget is
How many Arduino resources you can dedicate to the interface
What IO you have available on your Arduino

And more.

@zakaria That's even more vague than before. Is this a program you already have (if so WHAT program?!), or do you want to write your own PC program? (We don't know how, ask on a PC programming website).

no I don't have the program before and i want to write my own PC program. but anyway I want to understand how can arduino send the data to another program, by using sockets?

@zakaria Now you throw sockets into the mix as well...!  What you ask is not trivial. I think you need to go back to basics and work out exactly what you want and how to articulate that into words and then google the different aspects of it.

Does your Arduino mount an Ethernet shield? If not, the only chance is to send data to your PC via the "serial" interface trough the USB port. Hence, the PC need to be kept close/connected to Arduino, and turned on. Then, on the PC, there are plenty of option to fetch such data and do whatever you want with them (graphing including).


text:
Arduino due dying after connection, gets hot
I have an Arduino Due (made in Italy) which suddenly (after working nicely for some time) started a new behavior: If I connect it to my computer via USB it is recognized and connects. The "On"-led is turned on but gets darker within seconds until it's off and the connection breaks. This happens with both USB ports. The area around the usb ports gets hot and especially the "504L" next to the reset buttons. (I just have my finger to measure the temperature, so it could also be something else in this corner).
What could have happened to the board? And is there anything I can try to revive it?
Update:
@GuitarPicker: It's the object labelled "0105" in your image, so it's probably the F1 fuse. If I connect the top USB, F1 gets hot, if I use the lower usb, F2 is activated.

There is nothing connected to the board. Before that, I used it to send SPI commands where I might have connected some of the SPI pins in the 6 pin group.
The board is placed on wood, so there should be no external connection
No smoke or visible damage.

I'm having trouble locating your "504L" part.  One sheet says it's a tiny resistor about 1mm x 0.5mm  Perhaps it's a different revision.  Near the reset button, I see a resettable fuse (F1), and a pair of capacitors (C25, C27).  Please check the layout below and see which part number corresponds to the hot one.  I suspect it may be the fuse.
Links: Layout, Schematic,
Photo

The board is using too much current. This will trip the polyfuse, which will gradually increase resistance. Which explains the power led fading out. Is there anything connected to the board?

The "504L" is a 500mA polyfuse.  If more than 500mA is attempted to be drawn through the USB port it will get hot which causes the fuse to "trip".  When it cools down again it will "reset".
Why is too much current being drawn through the USB port?  Well, that's what needs answering to know just why your board is misbehaving:

Do you have lots of things plugged into the board - like LED strips, motors, etc?
Is the board sat on something metal causing a short circuit? (I did that by having some loose change on my desk once).
Have you physically damaged the board and caused some pins of one of the chips to short together?
Has the Magic Smoke™ escaped from one of the chips rendering your board broken?