text:
Sending serial commands to yourself
Is it possible to "send" a serial command to the device itself to see the response?
I have written a little routine based on a couple of serial sends and receives and want to see if that works out like I want.
EDIT:
I have a device (an AVR with arduino boot loader) and as part of my program, the device exchanges phrases with peripheral devices over a serial connection. Since I have right now just the arduino itself and can't really test, if at least the logic behind the serial part of works out, I would like to get serial commands from somewhere and trigger 'continuous talking', so I want to monitor the response behavior of my module, if it gets a certain command (stability reasons). Instead of waiting for a second device, is it possible to "link the TX/RX line to itself" internally or externally to test my program with itself?

No idea what you are asking there, sorry.  Please flesh out your question with an actual example - your current description is impossible to interpret.

Welcome to Arduino SE! I've edited your extra content into the main question.

It sounds like you may be thinking of a serial "loopback" test.  On the hardware side, it can be as simple as shunting the transmit pin to the receive pin - just make sure nothing else is hooked up to that transmit pin.  Coming up with something useful on the software side may be more interesting; there is also the question of how you are going to monitor it.

But if I recall, there is a resistor between the USB-serial output and the ATmega input on the basic Arduino series, so if you jumper D1 and D0 the ATmega will hear its own transmissions, and a connected PC will passibly see all of it.  Just remove the jumper before you try to talk or program with the PC.

Yes, you can do that by cross-connecting the transmit and receive pins on the Arduino. But then your devices sits there silently murmuring to itself (or not...) and you can't really tell what it's saying, or if it's doing anything unless you can observe some other hardware - LEDs, a 'scope, f/ex.
But why not hand-type or script some messages to it on your PC? If the Arduino sketch would make some brief, coherent replies you could confirm what it's doing and debug it if necessary.
I've done just this in your situation: Two of us defined a serial protocol - the ASCII (for human readability!) commands and replies that either end could make or expect. Then each of us wrote the communication code for one of the two devices and proved that it met the protocol. Once both of us had finished and were confident in our respected communication code, we plugged the two devices together, and - they played! Nicely! :)  And if they hadn't we could have eavesdropped on the serial line and printed their attempted conversation to discover where it went wrong.

That's a good idea!


text:
Analog pins all reading same value
I'm trying to read 5 analog inputs, but all the pins are reading the same as pin A0, plus or minus a couple points. I tried using pulldown resistors on all 5 pins and it made no difference. The board is a Leonardo. Thanks for any ideas/help!
void setup() {
    Serial.begin(115200);
    analogReference(EXTERNAL);
}

void loop() {
    int A0, A1,A2,A3,A4;
    delay(200);
    A0= analogRead(A0);
    A1= analogRead(A1);
    A2= analogRead(A2);
    A3= analogRead(A3);
    A4= analogRead(A4);

    Serial.print(A0);
    Serial.print(" ");
    Serial.print(A1);
    Serial.print(" ");
    Serial.print(A2);
    Serial.print(" ");
    Serial.print(A3);
    Serial.print(" ");
    Serial.print(A4);
    Serial.print("\n");
}

int A0, A1,A2,A3,A4;
delay(200);
A0= analogRead(A0);
A1= analogRead(A1);
A2= analogRead(A2);
A3= analogRead(A3);
A4= analogRead(A4);

Your local variables (A0 through A4) are shadowing the global variables for the pins (A0 through A4). Give your local variables different names.

Thank you! I knew it must be something stupid I'd overlooked.

source: Stack Exchange

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

sort: votes


text:
Arduino Due and Vin, 3.3V and 5V power inputs
I just want to confirm something before I wire up my first ever Arduino project and fry all the stuff I just spent money on.
It is my understanding that the Vin power input will tolerate a 9V battery and use voltage regulators to pare it down to either 3.3V or 5V (as different parts of the board require). So it is then my assumption that if I have a 9V battery running to Vin, that I could then connect a power wire to the 3.3V connector, and reliably get a 3.3V signal (and ditto for 5V), yes?
Or, is it that they are input jacks expecting either 3.3V or 5V signals? I guess I'm confused over this:

Will Vin then power the 3.3V and 5V inputs, giving me access to voltage at that level; or
Do I have to choose between 3.3V, 5V or Vin, and only use one of those to power my board (with the appropriate voltage level)

Have you checked the schematic yet?

If you can provide a schematic I'll check it out and maybe it answers my question, but I'm so new to electronics, I may not even be able to make sense of it.

All Arduino product pages link to a schematic for the board.

Then I would assume this is what you mean, in which case, I cannot at this exact moment make sense of it. And although I think I can guess your next argument, which is probably "Well then you need to learn how to read schematics, otherwise get out of electronics", I would counter-argue that Arduino is from the ground-up aimed at complete electronics newbies like myself. And that this is a basic usage question that should be answer-able without a moderate understanding of EE/ECE.

And yes, in time, I will learn this stuff, but I shouldn't have to be able to read that diagram and fully comprehend it to understand how to connect my board to a battery.

The power subsections are on the bottom right of the page. Unmarked, of course, because that's how Arduino rolls.

DC Jack is connected, through a diode, to Vin.
Vin is stepped down to 5V on-board.
5V is stepped down to 3V3 on board.
Thus you can do any one of the following numbered items.

Connect a 7-12V supply to the DC Jack; thus:

use Vin as a supply @ DC - 0.7V for off-board peripherals, and
use 5V as a supply for off-board peripherals, and
use 3V3 as a supply for off-board peripherals.

Connect a 6-12V supply to Vin; thus:

use 5V as a supply for off-board peripherals, and
use 3V3 as a supply for off-board peripherals.

Connect 5V supply to the 5V; thus:

use 3V3 as a supply for off-board peripherals.

The above is only guaranteed for boards that follow the reference schematic, as plenty of clone/compatible boards do. If you buy a cheap Chinarduino and something doesn't work, or the thing breaks, after following anything above then that's your tough luck.

Yes your assumption is correct you can power 3.3v and 5v items from those pins as long as you don't take more current than the onboard regulator(s) can supply

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


text:
Arduino Due Pinout with Explanations?
I am trying to understand what each pin on my Arduino Due is and what it is used for, and so I have been searching for things like "Arduino Due pinout", "Arduino Due pin mapping" and similar.
The best I could find was this table, however it doesn't help you out at all if you are completely new to electronics and have no idea what TX2, SDA or NPCSO mean, etc.
Does anybody know of Arduino/Due documentation that explains what each I/O pin is?

Yes, it's called the datasheet for the chip on the board. TX2 is UART 2 Transmit. SDA is I2C Serial DAta.  NPSC0 is Chip Select 0 for SPI  (the N is "Not", or "Active Low").

Thanks @Majenko - is this what you're talking about?

That is a start - you can use it in conjunction with this: http://www.atmel.com/images/doc11057s.pdf

Check out:
http://www.robgray.com/temp/Due-pinout.svg
OR http://www.robgray.com/temp/Due-pinout.pdf
Search 'Due Pinout'!

The Arduino Due is backed by an Atmel SAM3X8E ARM Cortex-M3 microprocessor and most of the pins on the Due are connected directly to this chip. Therefore, you can refer directly to the chip's datasheet for descriptions of these hardware features.
Atmel SAM3X8E ARM Cortex-M3 datasheet

I'm shocked that something as mainstream as Arduino hasn't incorporated this into their end user docs. But thanks!


text:
How to increment and decrement an output voltage by using two buttons?

I'm trying to create a code using an Arduino Uno board to increment and decrement the output voltage of the Arduino Uno which is 5 volts and I need to step it up to 10 volts which I have done below.
The things that are missing on the schematic are two buttons. I want to be able to increment 0.5 volts with each press of Button-A until the Arduino is at 5 volts. With Button-B I want to be able to lower the voltage by 0.5 volts with each press of the button till value is 0.
I can do the calculations and the circuit design but I'm not much of a programmer. I just want to know if anyone can point me in a good direction of where I can get the right code. I have already looked at all the tutorials on the Arduino Website. I do know I have to work with the PWM functions as well as attachinterrupt() and Debounce() functions. Also, how do I set the increments so that I don't go over, say it takes 10 presses to get to 5 volts on the 11th press have it not do anything so I don't break anything. So can anyone please help me with any suggestions?
I have a low pass filter on the circuit for noise handling and like I said I need to add in the buttons to my schematic.

simulate this circuit – Schematic created using CircuitLab
Here is my code I have made. I'm using an LED to test the Vout aspect. So far I can only get my LED to flicker from 2 to 4 volts and my buttons A and B don't work. Can someone look over my code and see how bad I made this?
int PWMPin = 6; // output pin supporting PWM
int buttonApin = 9; // buttonA to pin 9 PWM
int buttonBpin = 10; // buttonB to pin 10 PWM
float value = 0; // read the value at 0
int fadeValue = value;

void setup()
{
  Serial.begin(9600); //initialize serial communication at 9600 baud
  pinMode(buttonApin, INPUT_PULLUP);
  pinMode(buttonBpin, INPUT_PULLUP);
  pinMode(PWMPin, OUTPUT);
}
void loop()
{
  {
    int port = analogRead(0);
    port = map(port, 0, 10, 0, 255);
    analogWrite(6, port);
  }

  {
  if (digitalRead(buttonApin) == LOW, fadeValue)
  {
  // fade from min to max in increments of 25.5 points: basically (0.5 volts)
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=25.5)

    digitalWrite(PWMPin, fadeValue);

    // sets the value (range from 0 to 255):
   Serial.println(PWMPin);
   analogWrite(PWMPin, fadeValue);
  }
  }

  {
    if (digitalRead(buttonBpin) == LOW, fadeValue)
  {
  // fade from max to min in increments of 25.5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=25.5)

    digitalWrite(PWMPin, fadeValue);

  // sets the value (range from 0 to 255): basically (0.5 volts)
  analogWrite(PWMPin, fadeValue);
  }
  }
}

I think you need to add a pull-down resistor to the + side of the opamp. Since the input of the opamp is high impedance, the voltage on the + is always 5v even at a low pwm duty cycle.

I suggest you to use debounce to detect if a pin has been definitely pressed. You could also test using interrupts (hint: interrupts can happen multiple times even if you "only" pressed once). So either use Arduino's example of debounce or take a look at the Bounce2 library found on their website.
Now that you can check whether or not either button A or B has been pressed, how do you keep track of the voltage to be output? You should use a counter variable that will be incremented when button A is pressed and decremented when button B is pressed. Here is a pseudocode:
if(ButtonA == pressed)
  counter++;
else if(ButtonB == pressed)
  counter--;

This counter variable can be used to control the output voltage. Remember that the argument for analogWrite() function on the Arduino Uno is the duty cycle which takes in values from 0 to 255. So analogWrite(0) ≣ 0 Volt and analogWrite(255) ≣ 5 Volt. So at the moment, you couldn't just do analogWrite(counter) because you would need to press 255 times button A!
Instead, you would need a way to convert your counter to reflect the increment you need. You mentioned that it should require 10 presses to reach 5 Volt at the Arduino output, and the easiest way to accomplish this is to use Arduino's Map function. The pseudocode would look like this:
Output = map(counter, 0, 10, 0, 255);
analogWrite(Output);

Now there is one last step! The map function will limit the output voltage from 0 to 5 Volt so everything will be safe; however, the counter is not limited to 0 to 10. This means that even if the counter is at 15 (because you pressed button A too many times) the voltage will be 5 Volt and you would need to press button B at least 6 times to see the voltage go down! So to limit the counter you could easily implement your own function:
if(counter >= 10)
  counter = 10;
else if (counter<= 0)
  counter = 0;

You could also use Arduino's constrain() function which more information can be found on their website.
Hopefully this points you in the right direction.

If all you have to do is to read those 2 buttons, you could just forgo the interrupts and simply poll in the main loop.
The Bounce2 library does basically the same.
Also, about the PWM, why not an R-2R?
10V/0.5V + 1 => 21 steps < 32 => 5 bits => 6 resistors.
But it could be more precise, as you would not depend on the oscillator, rather on the precision of the resistors.

Agreed with Igor. Resistor ladders are much more accurate and noise resistant. I would go for an I2C potentiometer such as AD5248.


text:
how to make an led turn on when something gets close to an ultrasonic sensor
Hey I just started using arduino and so far can't get any help with how to write a code for an led to turn on when someone gets in range of a three pin ultrasonic sensor, and off when they are out of a specific range.
Any help?

What have you tried so far? Have you tried lighting an LED? Have you tried getting the distance from the ultrasonic sensor?

i have already done all of that

Then you just need to do some comparisons.  Learn about the "if" command.

Try with this and check that at least you can reproduce the desired effect:
http://www.arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor
Then you can refer to this for the part related to driving the LED:
http://www.arduino.cc/en/Tutorial/Blink?from=Tutorial.BlinkingLED
Since the ultra sound demo already calculates the distance, you can do the test on that to decide when to turn ON/OFF the LED.


text:
Can Bus Shield Not Receiving Data
I am trying to connect my Arduino Uno board with SeeedStudio Can Bus Shield to my 2006 325i BMW. After compiling and uploading the example program by SeeedStudio, the serial monitor returns "Can Bus Shield Init ok!"
// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13

#include <SPI.h>
#include "mcp_can.h"

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN); // Set CS pin

void setup() {
  Serial.begin(115200);
START_INIT:
  if(CAN_OK == CAN.begin(CAN_500KBPS)) {
  // init can bus : baudrate = 500k
    Serial.println("CAN BUS Shield init ok!");
  } else {
    Serial.println("CAN BUS Shield init fail");
    Serial.println("Init CAN BUS Shield again");
    delay(100);
    goto START_INIT;
  }
}

void loop(){
  unsigned char len = 0;
  unsigned char buf[8];
  if(CAN_MSGAVAIL == CAN.checkReceive()) {
    // check if data coming
    CAN.readMsgBuf(&len, buf);
    // read data,  len: data length, buf: data buf
    unsigned char canId = CAN.getCanId();
    Serial.println("-----------------------------");
    Serial.println("get data from ID: ");
    Serial.println(canId);
    for(int i = 0; i<len; i++) {
      // print the data
      Serial.print(buf[i]);
      Serial.print("\t");
    }
    Serial.println();
  }
}

So I get the initialize statement returned but I'm not receiving any data. It seems like the if(CAN_MSGAVAIL == CAN.checkReceive()) statement isn't executed. I found my vehicle's Can high and Can low wires and inserted them into my Can Bus Shield. So I'm not sure if it's a code problem or if the wires aren't transmitting the data to the shield. Any help would be great.

I'm having a similar problem, I can see the light flashing with different operations of the vehicle but no data is spit out to the serial monitor. Are you seeing the led flashing as data being received?

No :/ only the power light

How are you connecting to the can bus shield. I stripped two wires and stuck them into can high and can low

I'm hooked in to the screw terminals as well. I'm using a single wire system and a ground.  I've tried a variety of different sketches, tried modifying the can library file but still no luck

Any progress on this?

Not yet. Im going to order a different canbus shield from spark and see if that works :/

You made the key on and press gas pedal while Arduino UNO and CAN-BUS Shield are connected to your car?

Yes. Connected Can-Bus Shield to Arduino and also connected to Can High and Can Low. Then turned car on

@DailenSpencer - Does the module return "CAN BUS Shield init ok!" without being connected to the car? Mine is saying "CAN BUS Shield init fail" but I'm not sure if it's my connection to the module or the module's connection to the car. Thanks.

@Bort Yes. When connected to can wires, Arduino output returns "Can BUS Shield init ok!"

@DailenSpencer - I'm sorry, but "Yes" doesn't match the rest of your answer. So, it DOESN'T say "init ok" UNLESS you connect to the car? If I get any further, I'll post how I get it to work!

Any progress guys? I am facing the same problem. Mine says "Init OK" even when not connected to the car. (I am using a clone http://www.elecfreaks.com/estore/can-bus-shield.html)
I only connect CAN-H and CAN-L. You mentioned also GND... Should I wire that too?

UPDATE: So yes, for me it was the GND. Also when connecting to an in-car bus make sure to break the P1 trace, or at least consider it and read-up about it why you might need to do it.

It may be a dumb question, but are you sure your car CAN bus is 500kbps?
Have a look at this:
pdfLink
Maybe try different speeds? 100kbps maybe?
Also, look at the schematics of your shield? Is the bus termination resistor soldered on the board?

Make sure to cut the P1 trace (see the link below) and also to connect GND from the OBD-2 to the shield/Arduino. There are two ground pins on the OBD-2 port, Signal and Chassis Ground. I went with Signal GND, but allegedly they are linked anyways.
This guide helped me a lot.


text:
PYM-1 PIR sensor current concerns
I am busy toying with some PIR sensors to detect movement etc for a nightlight for my kids. One of the sensors I ordered is the PYM-1 PIR sensor.
The data sheet states the following:

Operating Voltage: 4,5~5V.
Standby current: 65 micro-amps (65uA)
Operating Current: 40mA (40 milli-amps)

The limit for current on the arduino pins is 40mA. According to documentation at the arduino site 40mA is the upper limit per pin and the site clearly states: Absolute Maximum Ratings - the point where damage will start to happen I would rather avoid sinking the current directly on the Arduino.
So my question is will sinking 40mA on a pin cause damage? I have not been visited by the blue smoke genie yet and would rather avoid it at this point.
I suspect it might be safer to run this via a transistor and external power than directly on the arduino?

This is completely acceptable for your intended purpose.
By itself it will act as a light on/off trigger as others have noted.
An Arduino could be added if you wish to add extra features when the PIR is triggered. In it's most basic light-switching form using an Arduino is overkill.
By itself it will act as a light on/off trigger as others have noted.
An Arduino could be added if you wish to add extra features when the PIR is triggered. In it's most basic light-switching form adding an Arduino is overkill.
When it comes to playing overkill can be good :-)

To use it to provide input to an Arduino and NOT to a mains level light:
NB relay contacts may only be connected to mains for light switching OR to the Arduino. NEVER to both at the same time.
Connect it's DC supply input to your Arduino (or other) power supply.
As long as the supply can provide 40 mA when needed it will work OK.
40 mA is a power supply rating This is unrelated to the Arduino pin loading.
Connect the output to an Arduino digital pin configured as an input.

The output is a relay, activated when an object is sensed.
When inactive the centre pin is probably connected to the right pin - Check with Ohm meter.
When activated the left pin in connected to the centre pin (see their diagram)
Connect ground to right pin.
Connect Arduino digital input to centre pin.
Connect a "high" level to left hand pin.
OR as Majenko suggests, just set the pin to have pullups enabled.
If connecting to V+ as shown then V+ can be Vcc  (=5V for a 5V Arduino, 3v3 for a 3V3 Arduino)
DO NOT set V+ to higher than Arduino's Vcc.
You can connect a say 1k to 10k resistor from V+ to the voltage source bur still do not set V+ above Vcc.
OK - just have pullups enabled:-)
eg (untested)

int ADCMode = 0;
   int PIRPin = 6;                 // PIR connected to digital pin 6
   void setup()
   {
     pinMode(PIRPin, INPUT_PULLUP); // set PIRpin as input with pullup
   }
   void loop()
   {
    ...
     ADCMode  = digitalRead(PIRpin);   // $Read PIR status
   ...
   }

When the circuit activates digitalRead() will return a high.
When the circuit is not activated digitalRead() will return a low.

See here re Arduino pin modes

Thanks for the information but could you clarify the following: DO NOT set V+ to higher than Arduino's Vcc. The sensor has no adjustable setting except for distance and time which are both related to the functioning of the IR motion detection. Do you mean when using an external power source do NOT go over the VCC of the arduino?

That is not a good way to wire the relay to the Arduino.  Forget the V+ connection and just wire the middle terminal to the Arduino's IO pin and the Ground terminal to the Arduino.  Enable the internal pullup resistor on that IO pin of the Arduino.  Connect the Arduino's 5V and GND pins to the power (red and black wires respectively) pins of the board.  Wiring the relay like that will result in a dead zone between switching HIGH and LOW where the input is floating, which is not nice.  The bounce effect would be 1,000,000,000x worse that way.

@Majenko For some values of "not" :-)  / And but, or add a resistor externally or polish its doorknobs etc. My main aim was to try to provide a clearly understandable counter to the statements that the module was not suitable. Descent into pullups etc may be good if needed but may drive OP back into "it doesn't work" camp. | Aside: I wonder if the leakage current of an O/C input pin driving input capacitance of IC + PCB + ... has a time constant < to << the relay changeover time as you imply. It may BUT I (strongly) suspect that  if bounce is an issue in the application then

@Majenko formal debouncing is likely to be needed. Which is simple indeed in this application. All this I know you know. .

@RussellMcMahon That is all very well, but you have to remember - these are Arduino users.  They a) have very little knowledge, and b) what they do know is generally wrong thanks to Arduino teaching them the wrong things.  It is my quest to undo that bad teaching, and getting them away from switching like this is one of those steps.

@Majenko We have the same aim, but both of our suggestions have pros and cons. Yours aimed at electronic purity (albeit close to pedantry :-) ) and mine at having a clear "the relay does this!!!" physical picture. Bot of us have the ame aim. Neither answer is 100% right. Which is best is moot - but I have altered my answer to incorporate pullups if desired.

@Namphibian When I mention V+ I meant the connection I show on the photo I have posted. Yes. I mean do not connect it to more than the Arduinos Vcc. As Majenko notes, you can leave the line i have shown to V+ disconnected and instead set the pin to INPUT_PULLUP mode as now covered in my answer.

Thanks guys both your input is appreciated. It would help if the manual that came with the device is not in engrish.. they mention the time delay relay for suction of people in there. I was originally planning to power the device via the black and red wires(power supply terminal) and then have the relay connect to a IO pin and ground. What I did not realize is that the 40mA was power supply not the output at the relay which is a completely different case.

When I look at the PYM-1 seen here:
http://www.ebay.com/itm/Infrared-PIR-Human-Sensor-NEW-Arrival-Pyroelectric-DIY-Kit-PYM-1-for-Arduino-/271677900953
I don't see any need for an external microprocessor such as an Arduino.  It seems that one just applies 5V as input and it switches on/off up to 300W of power.  Where would one use an Arduino GPIO?

I would like to use the sensor with other sensors so when there is movement and sound for example. I do understand that this unit is probably more than I need however it does have the photoresistor which will allow me to trigger at certain light levels i.e. when it is dark when it lighter etc. This is part of a larger system in other words.

I get the impression that this module is a stand-alone device ... a PIR that detects movement and closes a circuit ... and that's it.  If you want to build a circuit that can detect movement, sound, light level changes etc etc ... you probably don't want to start with the PYM-1 but instead get parts such as an HC-SR501 and use THAT with the Arduino.

Also starting to get that impression. Love how they mark things as Arduino  on the site though. I have another one the HC-SR501 as well. Ordered two just in case the one is wrong. I will power the PYM-1 separately and play with it a bit more. I could probably just use it to close the circuit on one of the arduino pins and thus sending a signal.

I understand ... I too have bought parts before understanding what they were ... and its a lesson I learned well.  Now I study parts before purchase (unless they are so cheap it is unimportant).  I imagine I have it in front of me and set myself the puzzle of "how would I wire it?".  I then use Fritzing to build a circuit and if all still holds in theory, then I purchase.

Indeed I normally do that however this one was on special on DX.com and tried as I may I could not get a manual. Today I did get a manual however it is some of the worst english I have read. Might as well be no manual as it not worth the paper it is written on. I do however have another use for this sensor.... scary halloween puppet coming up.


text:
ESP8266 and Arduino Interfacing
I have connected Arduino with ESP8266 with
Arduino pin 2 connected to ESP's Tx Arduino pin 3 connected to ESP's Rx via Voltage Divider Arduino GND connected to ESP's GND Arduino 3v3 connected to ESP's CH_PD
I have powered ESP8266 using 1117 Voltage regulator
When I initially bought ESP8266 it was working properly(I could even set up a server) but now when I connect it to Arduino an endless stream of garbage values is seen on the Serial Monitor...
The arduino is programmed with the following code
#include <SoftwareSerial.h>

SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
                             // This means that you need to connect the TX line from the esp to the Arduino's pin 2
                             // and the RX line from the esp to the Arduino's pin 3
void setup()
{
  Serial.begin(9600);
  esp8266.begin(9600); // your esp's baud rate might be different
}

void loop()
{
  if(esp8266.available()) // check if the esp is sending a message
  {
    while(esp8266.available())
    {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      Serial.write(c);
    }
  }

  if(Serial.available())
  {
    // the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
    // In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
    // but we want to send everything at the same time.
    delay(1000);

    String command="";

    while(Serial.available()) // read the command character by character
    {
        // read one character
      command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}

Maybe it helps if you tell us what happened between "initially" and "now"?

Lose the Arduino and program the ESP directly. You can do it with the same language as Arduino.  https://github.com/esp8266/Arduino - also supported in UECIDE - all you need is a USB -> UART dongle.

If the stream of garbage values comes in response to things you send to the ESP8266, then the problem is most likely the baud rate.  For the ESP8266-01 modules that I have used, the default baud rate is 115200.

I had already changed the Baud Rate of the Module to 9600 using AT+BAUD command..

There is a new command for the ESP8266 in AT version:0.50.0.0 - SDK version:1.4.0 that lets you explicitly set the full UART configuration:
AT+UART_CUR – set the current UART configuration
This command sets the current UART configuration; it does not write to the flash. Hence there is no change in the default baud rate.
For example:
AT+UART_CUR=9600,8,1,0,0


text:
Rf receiver, change timer
I need some help. I use function rx_setup()  оf library VirtualWire.h which is used to transmit information wirelessly. The function use timer аnd there is  conflict with any of the other libraries. Does anyone know how I can change the timer, which uses function?
This is the function:
void vw_setup(uint16_t speed)
{
    uint16_t nticks; // number of prescaled ticks needed
    uint8_t prescaler; // Bit values for CS0[2:0]

#ifdef __AVR_ATtiny85__
    // figure out prescaler value and counter match value
    prescaler = _timer_calc(speed, (uint8_t)-1, &nticks);
    if (!prescaler)
    {
        return; // fault
    }

    TCCR0A = 0;
    TCCR0A = _BV(WGM01); // Turn on CTC mode / Output Compare pins disconnected

    // convert prescaler index to TCCRnB prescaler bits CS00, CS01, CS02
    TCCR0B = 0;
    TCCR0B = prescaler; // set CS00, CS01, CS02 (other bits not needed)

    // Number of ticks to count before firing interrupt
    OCR0A = uint8_t(nticks);

    // Set mask to fire interrupt when OCF0A bit is set in TIFR0
    TIMSK |= _BV(OCIE0A);

#elif defined(__arm__) && defined(CORE_TEENSY)
    // on Teensy 3.0 (32 bit ARM), use an interval timer
    IntervalTimer *t = new IntervalTimer();
    t->begin(TIMER1_COMPA_vect, 125000.0 / (float)(speed));

#else // ARDUINO
    // This is the path for most Arduinos
    // figure out prescaler value and counter match value
    prescaler = _timer_calc(speed, (uint16_t)-1, &nticks);
    if (!prescaler)
    {
        return; // fault
    }

    TCCR1A = 0; // Output Compare pins disconnected
    TCCR1B = _BV(WGM12); // Turn on CTC mode

    // convert prescaler index to TCCRnB prescaler bits CS10, CS11, CS12
    TCCR1B |= prescaler;

    // Caution: special procedures for setting 16 bit regs
    // is handled by the compiler
    OCR1A = nticks;
    // Enable interrupt
#ifdef TIMSK1
    // atmega168
    TIMSK1 |= _BV(OCIE1A);
#else
    // others
    TIMSK |= _BV(OCIE1A);
#endif // TIMSK1

#endif // __AVR_ATtiny85__

    // Set up digital IO pins
    pinMode(vw_tx_pin, OUTPUT);
    pinMode(vw_rx_pin, INPUT);
    pinMode(vw_ptt_pin, OUTPUT);
    digitalWrite(vw_ptt_pin, vw_ptt_inverted);
}

#endif // ARDUINO

// Start the transmitter, call when the tx buffer is ready to go and vw_tx_len is
// set to the total number of symbols to send


text:
GPS logging on the intel edison breakout board
I'm working on my project car, and I have decided I would like to have a GPS and log some sensors too. I'm just at a bottle neck here, the sensors I have brought pull about 7v each where I can't pull that much from the breakout board that I have, and I can't seam to get the GPS to work.
I've tried using ths code but software serial isn't supported on the edison:
// GPS Setup
#define rxGPS 0
#define txGPS 1
SoftwareSerial serialGPS = SoftwareSerial(rxGPS, txGPS);
String stringGPS = "";

void setup() {
  pinMode(rxGPS, INPUT);
  pinMode(txGPS, OUTPUT);

  Serial.begin(9600);
  Serial.println("Started");

  // GPS Setup
  serialGPS.begin(4800);
  digitalWrite(txGPS,HIGH);

  // Cut first gibberish
  while(serialGPS.available())
    if (serialGPS.read() == '\r')
      break;
}

void loop()
{
  String s = checkGPS();
  if(s && s.substring(0, 6) == "$GPGGA")
  {
    Serial.println(s);
  }
}

// Check GPS and returns string if full line recorded, else false
String checkGPS()
{
  if (serialGPS.available())
  {
    char c = serialGPS.read();
    if (c != '\n' && c != '\r')
    {
      stringGPS  = c;
    }
    else
    {
      if (stringGPS != "")
      {
        String tmp = stringGPS;
        stringGPS = "";
        return tmp;
      }
    }
  }
  return false;
}

Any ideas or help would be much appreciated

"Sensors pull 7V"? Hmm? Do they pull 7A? Or they need to be powered from 7V?

stringGPS += c;

checkGPS() returns String and you have "return false" at the end

Try this:
String GPSLine;

bool checkGPS()
{
  while(serialGPS.available())
  {
    char c = serialGPS.read();
    if(c == '\n') return true;
    if(c == '\r') continue;

    GPSLine += c;
  }
  return false;
}

void loop()
{
  if(checkGPS())
  {
    Serial.println(GPSLine);
    GPSLine = "";
  }
}

requiring any libraries?

Okay well to break up what I'm doing

1 I have the Intel Edison one breakout board  it has a micro SD card slot and I want to take the gps and log everything that it sends to a SD card  and the second part is to read and display sensors onto a screen. But for now I just want to get the gps working

You might try my NeoGPS library.  It has a diagostic program and some good information in the Troubleshooting section.  And NeoGPS doesn't use the String class, although you can safely waste lots of RAM on the Edison.  :P
For an Edison build, you may have to change the PACKED_DATA configuration item, described here.
(This is an Arduino product, right?)


text:
How do you call to a previous function?
I'm using an Arduino to control a reverse osmosis machine, I would like after a certain number low pressure events to return to the testing routine. Can you call to previous functions?

You need to get your head around the Finite State Machine (FSM).
It is a programming method which allows your program ("Machine") to be in any of a certain number ("Finite") of states ("State").  One state would be reading pressure. Another state would be "testing", or whatever.
I wrote a tutorial ages ago about it: http://hacking.majenko.co.uk/finite-state-machine

What do you mean by "previous"? In the call stack or in the code?
Either way, you can call any (public|member|static) function you want at any time, even call the very same function you're already in (recursion, but not recommended on Arduino or any other embedded system).

fsm does seem like a good way to handle it. your tutorial is very easy to follow

by previous, I mean  I had a void testing routine that once voltage reading in met it goes to  void main run I was trying to get it to  read a  high/low signal and after 2 cycles of reading low i wanted it to go back to void testing.

Ok, I see. To me it sounds like you should read up on the basics of programming, before posting questions here.


text:
Cannot access SD card on Yun
I have a brand new 8GB micro SD card freshly formatted as FAT in my Yun.
When I run df -h, I don't see the card's capacity included.
When I enter cd /mnt/sda1, it says can't cd to /mnt/sda1.
When I SSH into the Yun with ssh root@arduino.local and run dmesg, I see confirmation that the SD card is recognized:
[   11.510000] sd 0:0:0:0: [sda] 15431680 512-byte logical blocks: (7.90 GB/7.35 GiB)
[   11.510000] sd 0:0:0:0: [sda] Write Protect is off
[   11.510000] sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00
[   11.510000] sd 0:0:0:0: [sda] No Caching mode page present
[   11.510000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   11.520000] sd 0:0:0:0: [sda] No Caching mode page present
[   11.520000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   11.530000]  sda: sda1
[   11.530000] sd 0:0:0:0: [sda] No Caching mode page present
[   11.530000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   11.540000] sd 0:0:0:0: [sda] Attached SCSI removable disk

How can I access my SD card and include it in the Yun's recognized storage space?

I take it you've mounted the SD card, with mkdir -p /mnt/sda1 and then mount  /dev/sda1 /mnt/sda1 ...?

I ended up resetting my Yun and following the Arduino tutorial to expand disk space. But, thank you for that comment - as funny as it sounds, I didn't know to do that!


text:
Adafruit_GFX setRotation not working when called from within a class
Using an ILI9341. I'm trying to set the rotation from within a class, but it's not working.  The code is very straight forward.
If I rotate in the class, the setRotation code does not work but the text is still printed. The pointer is set properly and the text is still printed, it just doesn't get rotated.
Outside of the class, the rotation works fine.
Any help would be greatly appreciated!
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define TFT_DC 5
#define TFT_CS 3

Adafruit_ILI9341 *tft;
uint8_t newRotationAngle = 0;

void drawStuff() {
    tft->setTextColor(map(rand(), 0, RAND_MAX, 0, 0xffff));
    tft->fillRect(0, 0, tft->width(), tft->height(), ILI9341_BLACK);
    tft->setCursor(0, 0);

    tft->print(F("01234567890"));
    delay(250);
}

class test {
public:
    void init(Adafruit_GFX *_p) { ptrTft = _p; };

    void inClassRotation(int newRotation) {
        ptrTft->setRotation(newRotation);
        drawStuffInClass();
    };

    void drawStuffInClass() {
        ptrTft->setTextColor(map(rand(), 0, RAND_MAX, 0, 0xffff));
        ptrTft->fillRect(0, 0, ptrTft->width(), ptrTft->height(), ILI9341_BLACK);
        ptrTft->setCursor(0, 0);

        ptrTft->print(F("01234567890"));
        delay(250);
    }

    Adafruit_GFX *ptrTft;
};

test instance;

void setup() {
    tft = new Adafruit_ILI9341(TFT_CS, TFT_DC);

    tft->begin();
    tft->setTextSize(2);

    instance.init(tft);
}

void outsideClassRotation(Adafruit_GFX *passed) {
    passed->setRotation(newRotationAngle);
    drawStuff();
}

void loop(void) {
    newRotationAngle++;

    // This works. No problems.
//    outsideClassRotation(tft);

    // This does NOT rotate but still prints the text fine.
    instance.inClassRotation(newRotationAngle);

}

I would actually be quite surprised if outsideClassRotation() actually
worked. My guess is that it does not work as is. Maybe it did work at
some point, but then you made some subtle changes to your code and did
not check that it is still working.
Here is the deal: there are two setRotation() methods:

Adafruit_GFX::setRotation(unsigned char) does very little besides
storing the rotation angle... which is not used anyway.
Adafruit_ILI9341::setRotation(unsigned char) actually sends commands
to the LCD asking it to apply the rotation; this is the method you
want.

The problem is that these methods are not virtual, which means that
when you call them through a pointer, as in
some_pointer->setRotation(the_angle);, you get the method
corresponding to the type of the pointer, not the type of the actual
object. For example:
tft->setRotation(the_angle);     // calls Adafruit_ILI9341::setRotation()
ptrTft->setRotation(the_angle);  // calls Adafruit_GFX::setRotation()
passed->setRotation(the_angle);  // calls Adafruit_GFX::setRotation()

I checked this by uncommenting your call to outsideClassRotation() and
disassembling the compiled binary: both times you are calling
Adafruit_GFX::setRotation().
Solution: change your Adafruit_GFX * pointers to be of
type Adafruit_ILI9341 *, or patch Adafruit_GFX.h to make
setRotation() virtual.

Actually, outsideClassRotation() works regardless, but you solved my mystery. I knew it was something simple.  I can only unlock bounty after 18 hours. Thanks!!!


text:
Spilt string and convert to float to compare
I'm transmitting: Temperature: 28.22C
and on the receiving end I'm receiving the whole tranmission as a string. I'm trying to spilt Temperature to leave it as a string and 28.22 as a float to compare, how do I do that ?
TX end hardware: (Arduino Uno board with Xbee S1)  to computer
RX end hardware: (Arduino Uno board with Xbee S2)  to computer

Is the "receiving end" an Arduino or a computer? If it's a computer, you should tell which language you use and probably ask your question on stackoverflow.

Hi, the receiving end is an Arduino Uno board which is hooked up to the computer. The transmitting end is also hooked up to an Arduino Uno board. Both communication goes through Xbee S1 card

Okk very simple approach :-
Suppose this is your string variable inStr = "Temperature: 28.22C"
String inStr = "Temperature: 28.22C";
int indexOfSpace = inStr.indexOf(' ');
//this stores the address of the space character in the string.
int indexOfC = inStr.indexOf('C');

String Temp = inStr.substring(indexOfScace+1,indexOfC);
//as the parameter for the function is supposed to be the starting point of the string to
 be extracted and one more than its ending point.

//Now to convert to float

float TempFlo = Temp.toFloat();

@user10566     if this answer worked please consider marking it as accepted so that the SE system does not bump it up as an unanswered question.

I suppose your communication is working... In order to retrieve a floating number from a string you might use toFloat() function. You can watch the reference page here to understand how does it work.


text:
esp8266 esp-01 crashing, restarting over and over
I flashed my ESP-01 with the nodemcu firmware 512k version, and everything was working fine.  I testing some lua scripting on init.lua and it was working.  Then, after writing a bunch of code and uploading, the module restarted.  And it restarted.  And it's still restarting, over and over again, and prints to serial
CÀbc0°ýbcü¨HøNodeMcu 0.9.4 build 20141230  powered by Lua 5.1.4
ö,3bþÈH

It was always printing the garbage in there before, so I'm not worried about that.  However, I can't send anything to the device--I can't send serial commands, or reflash the device.  I'm thinking I overloaded the memory or something.  Anyone have any ideas for recovering this brick?

This is really not the right website for this question.  If you were running a port of the Arduino framework to the ESP8266, that might barely be a fit (though still much better supported on an ESP8266 site), but here your question concerns neither Arduino-type hardware nor software.

Turns out I was pulling up on the GPIO0 pin, instead of down.  Ensure you have the correct pin-out when flashing.
ESP-01 VCC - 3.3v Serial Adapter
ESP-01 GND - Ground or Minus Serial Adapter
ESP-01 RX - Connect to TX on Serial Adapter
ESP-01 TX - Connect to RX on Serial Adapter
ESP-01 CH_PD - 3.3v Serial Adapter
ESP-01 GPIO0 - Pull low by connecting to ground / minus
There also seems to be a problem with NodeMCU not clearing variables in the Ram, so Ram fills up as you run, and this causes the module to crash upon restarting, over and over.  That is also what was happening.  There is some problem with wifi.sta.getap() that exacerbates this.


text:
Fading the brightness of LEDs using MAX7219 and PWM
I am doing a project with bi-color led matrix 8x8 and MAX7219 as the LED driver. I want to implement a fading effect on the LEDs, like mixing the two colors by varying the individual duty cycles.
My idea is the use of the Iset parameter; I would connect the PWM pin from Arduino through the Rset resistor and feed that into the Iset of the MAX7129 instead of 5V supply. Please suggest whether or not this is possible, if not what can be the alternative approach?

This is possible in two ways:

The MAX72xx has its own internal intensity control register. From the datasheet:

Digital control of display brightness is provided by an internal pulse-width modulator [...]. The modulator scales the average segment current in 16 steps from a maximum of 31/32 down to 1/32 of the peak current set by RSET [...].

This of course requires no extra components or effort, but you are limited slightly by only a 4-bit intensity resolution. Also, there is no 'off' so you'd have to either manually blank the displays or put the ICs into shutdown mode.

Your suggested way is possible. However, the low frequency of the Arduino's PWM may lead to flickering if the MAX7219's internal segment current reference driver needs a steady voltage. You'll have to consider smoothing the PWM output through a low pass filter - the TL072/TL082 has two op-amps so you can use one for colour A and the other for colour B. I'd choose an op-amp over passive filtering because the current drawn from the Arduino will be negligible and the stability of the current into the MAX7219 will be improved.


text:
Simple LED circuit is not working
This is my first circuit ever (!) and so I'm hoping that I'm just making an easy-to-spot rookie mistake. I am trying to power an Arduino Due with a 9V battery and then have the Due in turn power a red LED. No blinking. No sketchpad/C program flashed to the chip. Just straight up electricity:

When I connect the battery, several things happen:

There is a green power LED on the Due that lights up; and
Right next to it is an orange LED (on the Due itself) that blinks every few seconds (not sure what this LED is or what the blinking means, but providing that detail for good measure); and
The red LED on the breadboarrd does not light up

This is a 2V/15mA LED, and as you can see I'm powering it from the 5V power jack on the Due. So a 220 ohm resistor should be perfect for it (R = (Vs - V) / I = (5V-2V) / .015A ~= 220 ohms).
So, for the first time ever, I busted out my multimeter, set it to the voltage setting, and started testing the circuit. First I tested Vin and GND on the Due (that is, the connection between the battery and the Due), and the multimeter lit up and hovered (correctly) around 5V. So far so good. Next I tested the power and ground connections on the breadboard power rails (indicated in green above). Again, the multimeter reported a roughly 5V power supply. Then I tested the connection from the power rail to the row (purple in pic above) feeding power to the resistor, and to my surprise, the multimeter reports no power at those two purple locations.
My understanding was that the power rail will power the entire column its connected to (in my case, the left-most column), and then any rows connecting to a power rail/column will also be powered. So I'm not understanding why there's voltage on my power rail/column, but not on the wire connecting my power rail to the resistor. Any ideas?

Update:
Here is my corrected circuit per initial feedback. Please note this is still not working, but I think I'm getting close:

The LED is shorted out - both leads are connected together - as shown here

LED is connected directly to the 9V battery. It's not under Arduino control. No blinking here.

What connects the resistor to the LED?

Absolutely nothing.
It's hard to work out which holes the LED is plugged into, but I think your current circuit looks something like this:

You need to connect that resistor and LED together.
For your edit:
Now your circuit looks like this:

Behind the 5 pins in that column with the ground wire there is a big chunk of metal connecting them all together.  It's no different to if you'd taken the LED and twisted the pins together into one.  There's no way the power can get up one and down the other when they are connected together like that.  You need to separate them into different columns.
And this is how the (black) connections inside are laid out, and how your (red) electricity is flowing:

And here is how the circuit should look, using a program called Fritzing.  It's a pretty basic design tool, but great for showing wiring.

You can see how the green highlighting shows the columns that are connected.

Thanks @Majenko (+1) - please see my update a new pic. I did my best to follow your advice but the LED is still not lighting up. I think I'm closer but I'm still missing something. In that 2nd picture, you'll notice that I've placed the LED and the wire going back to the GND rail on the same row as the resistor's "cathode" end. Any ideas where I'm going awry now? Thanks again!

I have edited my answer to cover your edit.

I totally get it now, makes perfect sense! Thanks again!

Glad you have it :)  I've added another picture and comment to my answer. You might like to check out the software "Fritzing" (free) which I used to draw it. It can be a big help when learning.

Oh,and your next exersize... move the +5V connection wire from the +5V pin on the Arduino and connect it to pin 13 instead - you'll then see the LED blinking at the same time as the one on the Arduino.

I can see I should have put my "The LED is shorted" comment 1st and then edited the picture :)

@RussellMcMahon Heh :)

It looks like you've got confused between columns and rows.
You are correct that the power rails run the length of the breadboard -- these are seen as the top and bottom pairs of rows in the diagram below (ignore the middle row). However, the rest of the board is connected up as separate columns. Each column is independent of its adjacent columns.

This means your red wire going from the power rail to the resistor is connected correctly. However, the other end of your resistor is currently going nowhere. It needs to be in the same column as the anode of your LED.

Thanks @Peter R. Bloomfield (+1) - so I don't think it's that I'm misunderstanding how the breadboard is organized (as columns and rows), perhaps I'm so new to electricity that I'm just misunderstanding the very flow of power itself! Let's call the two rows that the resistor is "living on" the resistor anode row and resistor cathode row, respectively (although I understand resistors have no polarity). So you're saying that I have the resistor anode row wired correctly, meaning I am correctly powering the resistor from the power rail...

However, you are then saying that the resistor cathode row is "going nowhere". I would have expected the voltage/power coming into the resistor (via the anode row) to provide power to the resistor cathode row. Is this not the case?!? In any respect, how should I be wiring the resistor and the LED so that the circuit is correct? Perhaps once I see how it should look, everything will make sense to me. Thanks again!

Also @Peter R. Bloomfield please see my update and my comment underneath Majenko's answer - I have the same question for you!

@smeeb The line which your resistor anode is on is not connected to the line the resistor cathode is on (except by the resistor itself). That's vital because the power has to flow into a component and then out. If they were connected by the breadboard itself then virtually no power would go through the resistor (electricity always takes the path of least resistance).

@smeeb In your updated image, that's exactly the problem. Your LED anode and cathode are on the same column, so they're directly connected to each other by the breadboard. That means the electricity won't flow through your LED at all. The LED's anode and cathode need to be on different rows.

@smeeb Here's an example of a similar circuit which may help you: http://apps.usd.edu/coglab/psyc770/images/bboard-circuit-653x425.jpg


text:
How do I know when the connections is ready between Arduino and QSerialPort
I am trying to send data from QSerialPort to Arduino Mega 2560. The proccess always takes some time to establish the connection.
How do I know with QSerialPort is the connections is ready to send data?
I don't know how much time do I have to wait for that and it happens every time when I run the application.
The configuration of my QSerialPort instance is:
mSerialPort = new QSerialPort();
mSerialPort->setPortName("COM3");
mSerialPort->setBaudRate(QSerialPort::Baud9600);
mSerialPort->setDataBits(QSerialPort::Data8);
mSerialPort->setParity(QSerialPort::NoParity);
mSerialPort->setStopBits(QSerialPort::OneStop);
mSerialPort->setFlowControl(QSerialPort::NoFlowControl);
mSerialPort->open(QIODevice::ReadWrite);

I check the device configuration of COM port:

I also changed and play the Arduino delay but nothing changed.
I am sending to Arduino little piece of data. Example:
X100.10,Y10.23, H9999, ...others

And these data work when I am debugging the functions of my application. Everything is writting and work. So I am lost.
I hope all this information be usefull to give me an answer or at less some tips.

I am guessing that what you are seeing is not the port taking some time to open, but the Arduino resetting as soon as you open the serial port.  That means there is a short time while it's in the bootloader looking for an "I am here" signal from avrdude.  The timeout of that signal is configured in the bootloader, and is usually something like 1 second.
The simplest thing you can do is, as one of the first commands in your program, send an "I am ready to receive" signal to the computer (maybe just the word "OK" or something like that), which you then wait for before sending your data.

I just send a command from my Application with QSerialPort but it take a little time. I wait the answer from Arduino and after a 40 seconds I get the answer? I don't know why and I don't understand this behaviour

40 seconds is unusual.  It could be that you are sending the message too soon and the Arduino isn't receiving it.  Add a delay of 2 seconds between opening the serial port and sending the message, see if that helps.

I put an sleep of 2 seconds but nothing... it takes a long time to get an answer.


text:
How do I print the reading serial data sending from Arduino
I am sending data to Arduino using QtSerialPort. When I read the data the ouput has several not printer characters. I am using a QTexEdit (in left hand) to insert the data to send and other (in right hand) to insert  the data to read.

You can see the receive data has some no printer character.
Workflow of sending and receiving data between QtSerialPort and Arduino
Sending Data with QtSerialPort
void MainWindow::sendData(){

    QString m_allData = m_sendEdit->toPlainText();
    int i = 0;
    int size = m_allData.size();

    QString line = "";
    int c = 0;
    while(i < size){
        line.append(m_allData[i]);
        if(c == 24){
            int sended = m_serialPort->write(line.toUtf8(), 24);
            m_serialPort->flush();
            line.clear();
            c = 0;
        }
        i++;
        c++;
    }
    if(c > 0){
        m_serialPort->write(line.toUtf8(), c);
    }
    m_serialPort->flush();
}

I want to send the data with a buffer size of 24 bytes.
Reading and Sending Data with Arduino
 void setup() {
    Serial.begin(9600);
 }

 void loop() {

    delay(1000);

    if (Serial.available() > 0){
        short i = 0;
        int size = Serial.available();
        String data = Serial.readString();
        Serial.print(data);
    }
 }

The Arduino code is simple.
Receiving Data with QtSerialPort
void MainWindow::readData(){
    int c = 0;
    char * dataBuffer;
    int size = m_serialPort->bytesAvailable();
    dataBuffer = new char[size];
    c = m_serialPort->read(dataBuffer, size);
    m_receiveEdit->setText(m_receiveEdit->toPlainText() + QString::fromUtf8(dataBuffer));
        delete dataBuffer;
}

I am trying to read the same data that I send to Arduino. What kind of convertion do I have to do?

There is no point in splitting your writes into 12-byte chunks. The serial port is slow, and your Qt code is fast, thus the first byte of the second chunk will come right after the last byte of the first chunk.

You have no warranty that Qt will receive the whole message in a single
chunk. It may receive "no se" as the first chunk, and then "q pasa" as
the second chunk. Since dataBuffer is dynamically allocated, it
initially contains garbage, and you are printing the part of this
garbage that you did not overwrite.
An easy fix would be to simply NULL-terminate the buffer:
dataBuffer = new char[size + 1];            // + 1 byte for '\0'
c = m_serialPort->read(dataBuffer, size);
dataBuffer[c] = '\0';                       // terminate the string

Ok, that was the problem. with dataBuffer['c'] = '\0' the output data is clean. Thank you @Edgar Bonet


text:
How do I receive more that 64 bytes with Arduino
I am using QtSerialPort to send and receive data from Arduino. I am sending more than 64 bytes (125, 220, more), I receive the data with Arduino, and trying to sending back the same data, but Arduino sending only 64 bytes in its response. Then I am thinking that the problem is with Arduino buffer. I am trying to clear the data but without result.
Here is my Arduino code:
void loop() {
    if (Serial.available() > 0) {
        int i = 0;
        delay(500);
        int size = Serial.available();
        while (i < size)
            buffer[i++] = Serial.read();

        Serial.print(buffer);
        //delay(500);
        int j = 0;
        while (j < size)
            buffer[j++] = '\0';
        //while (Serial.available()) Serial.read(); I tried it
        //Serial.flush();   Also tried it, but nothing.
    }
}

You are probably also sending the zeros back, hard to guess how that will confuse QT.  It will.  Just no point to using a buffer, just read one byte and send it back with Serial.write().

Remove the delay(500): during this delay, you are letting the internal buffer of Serial overflow. Instead of just wasting 500 ms, you should be copying the incoming data into your own buffer array as it comes.

Instead of blocking the loop for 500 ms, you should be actively
reading the data as it comes. Otherwise the internal buffer of the
Serial object will overflow after only 64 bytes are received.
Here is an example that copies the incoming bytes into a larger buffer
(256 bytes) and, upon receiving an end-of-line character, echoes
back the whole line.
void loop() {
    static char buffer[256];
    static size_t pos;              // position of next write

    while (Serial.available() && pos < sizeof buffer - 1) {

        // Read incoming byte.
        char c = Serial.read();
        buffer[pos++] = c;

        // Echo received message.
        if (c == '\n') {            // \n means "end of message"
            buffer[pos] = '\0';     // terminate the buffer
            Serial.print(buffer);   // send echo
            pos = 0;                // reset to start of buffer
        }
    }
}

after every read action the buffer consume one character and the buffer size is menor? So if I constantly send data to  Arduino and constantly read from buffer, the buffer never going to be on overloaded?

Did not really understand your question. There are two buffers: the one from the Serial object (64 bytes), and your application's buffer. Which one are you talking about? At 9600 bps, each byte takes about one millisecond, which is plenty. As long as loop() runs often enough (with no delay()), the Serial buffer is not going to overflow.

The final result was receive each byte one by one and removed any delay in the code. Thank you @Edgar Bonet


text:
Reading values from the register of a slave
I am trying to interface MPU6050 with arduino. Found a simple code online, but having a bit of trouble in interpreting it.
// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B);  // PWR_MGMT_1 register
Wire.write(0);     // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C     (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for   temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(3330);
}

Now there are a few things i want to ask regarding this code:
1. Here we have specified that the data from 3B register of the slave should be the first one and master will receive in total 14 bytes. In this case the 14 registers are continuous (see datasheet here) .Now how should i go about reading the values if i am interested in registers which are not continuous ,let us say alternative?
2.AcX=Wire.read()<<8|Wire.read();
This line is taking the first 8 bits and last 8 bits and forming a 16 bit number . But why do we need to shift the first 8-bits byte 8 places to left.Please explain how exactly this line works?

This code you found is very bad. Do not rely on it for your own developments. Specifically, there is no way to know which read() will be evaluated first in Wire.read()<<8|Wire.read().

So can you please tell me how should i go about doing the same in a better way?

Take a look at FreeIMU - it has all the code you could ever want.

For reading non-consecutive bytes, the “normal” way would be to do a
one-byte request and a one-byte read for each byte you want. However, if
the bytes you want are close enough (e.g. you want every other byte), it
would be faster to do a contiguous read and just ignore the bytes you do
not want. E.g.:
byte data1 = Wire.read();  // read first byte
Wire.read();               // read and ignore second byte
byte data3 = Wire.read();  // read third byte

For your question regarding the meaning of
Wire.read()<<8|Wire.read();:

Wire.read() return a 16-bit integer, where the 8 most significant
bits are zero and the 8 least-significant bits contain the actual
data. In binary, it's something like 00000000xxxxxxxx, where x
are the data bits.
<<8 means “shift left by eight positions”, where the missing bits
are replaced by zeros. Thus Wire.read()<<8 is xxxxxxxx00000000
in binary.
The second call to Wire.read() return another 16-bit integer in the
form 00000000yyyyyyyy.
The vertical bar | is the bitwise-or operator: each bit of the left
operand is or-ed with the corresponding bit of the right operand to
give one bit of the result: x or 0 is x, 0 or y is y.
Then, the whole expression gives xxxxxxxxyyyyyyyy, where xxxxxxxx
comes from the first Wire.read() and yyyyyyyy from the second.

The problem here is that the “first” and “second” Wire.read() in the
sentence above refer to the position of the call in the line, not to the
actual order in which the calls are performed. Thus you may be lucky and
get the the correct byte order... or not. You should instead do a single
read per statement if you want to control the byte order. For MSB first:
AcX = Wire.read() << 8;  // read most significant byte first
AcX |= Wire.read();      // then least significant byte

And for LSB first:
AcX = Wire.read();        // read least significant byte first
AcX |= Wire.read() << 8;  // then most significant byte


text:
Arduino Uno coding problem voltage varying
I was wondering whether anyone could help me... I am using an Arduino Uno and I am writing my code in the Arduino IDE. I am trying to implement the code so that the output voltage can be varied from 0 - 5 volts using 2 pushbuttons. I want to be able to increment the voltage by +0.5 volts from 0-5 volts every time I push Button A. Also I want to decrement the voltage by -0.5 volts from 5-0V every time I push Button B.
Example: (push Button A): output voltage 0.5: (push Button A): output voltage 1.0 etc.
So far when I upload my code the LED as my test for output just flickers between 2 - 4 volts. Can anyone tell me what I am doing wrong? I am not that good at coding so any help would be awesome.
Here is my code.
int PWMPin = 6; // output pin supporting PWM
int buttonApin = 8; // buttonA to pin 9 PWM
int buttonBpin = 10; // buttonB to pin 10 PWM
float value = 0; // read the value at 0
float fadeValue = value;
float counter = 0;

void setup() {
  pinMode(buttonApin, INPUT);
  pinMode(buttonBpin, INPUT);
  pinMode(PWMPin, OUTPUT);
}
void loop() {
  int port = analogRead(0);
  port = map(port, 0, 10, 0, 255);
  analogWrite(6, port);
  if (digitalRead(buttonApin) == LOW, fadeValue) {
    if (counter >= 10) {
      counter = 10;
    }
    // fade from min to max in increments of 25.5 points: basically (0.5 volts)
    for(fadeValue = 0 ; fadeValue <= 255; fadeValue +=25.5) {
      counter = fadeValue;
      // sets the value (range from 0 to 255):
      analogWrite(PWMPin, fadeValue);
      delay(100);
    }
  }
  if (digitalRead(buttonBpin) == LOW, fadeValue) {
    if (counter <= 0) {
      counter = 0;
    }
    // fade from max to min in increments of 25.5 points: basically (0.5 volts)
    for(fadeValue = 255 ; fadeValue >= 0; fadeValue -=25.5) {
      counter = fadeValue;
      // sets the value (range from 0 to 255):
      analogWrite(PWMPin, fadeValue);
      delay(100);
    }
  }
}

Why would you use a LED to test your output instead of, say, a DMM?

Because it would be the same thing when I connect it to a different source I will still be able to vary voltage IF i can get this running.

Varying the voltage on a LED does almost nothing.

okay so what would use for an output?

Something that gives you an actual number.

obviously if I get the Light to turn on I get light I can dim the light an brighten the light according to how often I push the button to the max 5v i think I'll be fine but what about my code? how bad is it?

"obviously if I get the Light to turn on I get light I can dim the light an brighten the light according to how often I push the button..." No. You can't. This is a LED.

@IgnacioVazquez-Abrams - that is not true - it's not an LED by itself, it's an LED in series with a resistance (external or internal).  And that means that the current which flows, and hence brightness, is a function of overall voltage.  Of course, most LED dimmers work with a fixed, optimal voltage and varying duty cycle.  It's an open question here if the Arduino's PWM output should be considered smoothed, or pulsed - that depends on the frame rate, and capacitance in comparison to load.

@ChrisStratton: The 25ohm resistance of the output is going to be unnoticeable at best.

On the contrary, the resistance whatever it is is going to be extremely noticeable - either the LED fails, or if it doesn't, that effective resistance is what is setting the operating current and preventing it from doing so.  Given the maximum current rating I expect it's a bit higher than 25 ohms effective when operating in excess of rated current.

The statement if (digitalRead(buttonApin) == LOW, fadeValue) is equivalent to if (digitalRead(fadeValue). I guess that's not what you wanted to do. See https://en.wikipedia.org/wiki/Comma_operator

There's a number of very basic things wrong with your code - things that aren't doing what you think, or you just telling it completely the wrong things.
Start by formatting your code properly (INDENTS!) and match up all your brackets.  You'll soon see what I see as far as what is wrong.
I'll give you some clues:

{
if (digitalRead(buttonApin) == LOW, counter)

Where to I start with that one...?

for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=25.5)
  counter = fadeValue;
  digitalWrite(PWMPin, fadeValue);

C is not Python!

digitalWrite(PWMPin, fadeValue);

Writing an analog value to a digital pin?!

Serial.println(PWMPin);

Printing the pin number - now what is the point of that?

... fadeValue += 25.5 ...

Adding a float to an integer - bad practice (and ultimately pointless) - pick one, float or integer, and stick to it.

And then there is the whole logic of your program. I can't work out what it's supposed to be achieving.  It looks like you've tried to get it to do all sorts of parts of different things and not got it to do anything at all.  Strip it right out and get it to do ONE thing - provide a specific, STATIC, voltage.  Then add in some way of changing that voltage afterwards.

I dont get it? what brackets should I take out

You have brackets where you shouldn't have, and you're lacking brackets where you should have them.

And that's just a start...

That's no help at all.  Please edit the code in your original question so I can see it in context

Yes I was going to put it in this comment and It was too long my bad I'm editing it now

uploaded new code now

Your program is still complete gibberish I am sorry to say. It looks like you have copied and pasted bits of other code without first understanding how that code works, and then interspersed it with some random bits that you think look like C but aren't. Go back to basics and get an LED to light at a specific brightness.

You forgot to add. It's useless to scale an analog output by a loop without delays!

Arduino IDE has autoformat function, it does most of the job itself that way.


text:
How far can i go just with this starter kit?
I want to buy this kit: http://www.banggood.com/UNO-Basic-Starter-Learning-Kit-Upgrade-Version-For-Arduino-p-970714.html
However, as shipping stuff from China takes like 3 months to arrive, i need to be certain i won't have much else to buy.
How far can i go just with this kit, and what would you recommend me buying together with it?
Thanks in advance.

As far as your imagination can take you. That's a decently comprehensive kit.

Without knowing your goals, that is unanswerable.  I'd be quite tempted to get a few basics like the board itself from a faster supplier, and then when this arrives you will have a second.  Are you looking at such slow sources dues to cost, or because all sources are slow to ship to wherever you are?

Yeah that is a massive starter kit so for beginning and learning it will be great. You have the basics there that will open up a much larger world. I did a laser spirograph and laser night light for my kids but those parts I could not source from an Arduino supplier. So depends on your projects and ideas.

That kit is quite good and/but, if you are prepared to source some of the basics in addition, I'd recommend at least considering something like this kit . I've NOT bought this but always thought this looked like a superb idea for experimenting. | I find these people low cost & prompt and I have found their products good. Worth a look. I have no involvement except as a customer

I bought a basic original starter kit from Arduino comes with book. Gave it to my son 9 years and me both working and learning. Its very good to understand the basics and complete all chapters. If your foundation is solid then you would be able to go higher projects. Try to combine different projects and after short period of time you will be able to work on advanced projects using Arduino forums and other tons of information in net.

@RussellMcMahon. About half of the sensors are already present in the kit Igor was asking about. Though without the nice breakout board and headers. Other than that, a nice suggestion.

To answer some of your questions, shipping from China is the best option because anywhere outside Brazil takes ~3 months to arrive, and buying here is like 10x more expensive.
I do not have any experience with electronics overall, but i can read some books about it and tutorials and stuff. Basically, i'm willing to learn, haha.


text:
Problems uploading sketch to Arduino Due
Windows 7 here. I just bought an Arduino Due and downloaded the Arduino IDE. I wrote a simple "blink LED" program (see below) and am trying to flash it to the Due.
When I connected the Due to my laptop (via micro USB cable), I got a warning on my laptop that it could not find the correct device driver. So I followed the instructions discussed on this excellent video tutorial and went into Control Panel >> System >> Device Manager >> Arduino and pointed it to load the appropriate device driver from C:\Program Files (x86)\Arduino\drivers. This got rid of the warning. Hooray!
I then Verified & Compiled my program:
int led = 13;

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

void loop() {
    digitalWrite(led, HIGH);
    delay(5000);
    digitalWrite(led, LOW);
    delay(5000);
}

Great success! Now it was time for me to upload the program to my Due. The first time I tried to upload it, I got the following error:
Arduino: 1.6.4 (Windows 7), Board: "Arduino Uno"
Sketch uses 1,068 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2,037 bytes for local variables. Maximum is 2,048 bytes.
avrdude: ser_open(): can't open device "\\.\COM1": The system cannot find the file specified.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

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

So then in the IDE I went to Tools >> Port and changed the selection from Serial to COM3 (again, sort of explained in that video tutorial). I tried to upload again:
Arduino: 1.6.4 (Windows 7), Board: "Arduino Uno"
Sketch uses 1,068 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2,037 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x09
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x09

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

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

I thought it was interesting that the IDE thinks this is an Arduino Uno. So then I went to Tools >> Board and changed the selection from Uno to Duemilanove, hoping that Due and Duemilanove are compatible for the programmer/flasher tool. This time the error was the same as last, except the first line reads:
Arduino: 1.6.4 (Windows 7), Board: "Arduino Duemilanove or Diecimila, ATmega328"

So at least the IDE is switching board correctly. :-) I should note that my Tools >> Board menu does not have an "Arduino Due" option. And when I go to Tools >> Board >> Board Manager, searching for Due does not turn up anything either.
I also tried running the upload with verbose output, but that really didn't tell me anything more. I'm happy to post the exact verbose output but figured I could omit it here for brevity. I also did peruse the troubleshooting link that the error output recommends, but it looks like I've already exhausted all of those recommendations as well.
I'm stuck and frustrated, any suggestions?
What do I need to do to get the IDE programming my Due?

... hoping that Due and Duemilanove are compatible for the programmer/flasher tool.

Not even close. You will need to go into the Boards Manager and download and install the SAM support files, select the Due from the list, and then upload the sketch.

Thanks @Ignacio Vazquez-Abrams (+1) - you got me half-way there. After installiing the Arduino SAM Boards, the Tools >> Board menu gives me two Arduino Due options: Arduino Due (Programming Port) and Arduino Due (Native USB Port). What are these, what's the difference between them, and which one do I want? Thanks again!

I'm not entirely certain, except that they use different physical ports on the board itself.

Programming Port it is! Thanks again!

Yes, I just had this problem myself..
Unless you use the Boards Manager Menu and install the Arduino SAM Boards (32Bits ARM cortex M3) board info you will not be able to upload your sketch.
After installing in the Boards Manager you will see the Arduio Due programming port and Arduino Native port as an extra options at the bottom or the TOOLS>BOARD menu.
That should fix the problem.(Check which you are connected to and which COM port)
If you still have trouble, disconnect and reconnect the DUE and restart the IDE and if required restart you computer.
This seems to be a common problem when people switch from the Uno or MEGA to the Due. I'm surprised this is not installed as standard in the IDE. I am using 1.6.5r2.
Thanks also to Ignacio Vazquez-Abrams.


text:
Arduino Serial Queue
So I am programming an LED Music Visualizer that uses a combination of Processing and Arduino. I have it all working as I want to but there is a small problem. If I were to stop the music, then the Arduino will keep displaying the visualization for a few seconds. I believe that this issue would be caused by it "catching up" on new serial data from Processing like a queue. So my question is: When arduino uses the Serial.read() function, is it using the most recent value or is it using the next value received after the last one that it used, like a queue of values.
Example: Processing sends the values 1,2,3,4,5,6,7,8,9 over serial in 10 millisecond intervals. Arduino only performs Serial.read at 20 millisecond intervals. Would the arduino read the values 1,3,5,7,9 in or would it read the values 1-9 but in twice the time?
Sorry for the confusing question, hopefully somebody could shed some light. At the core, it is a question on how serial works, you can ignore the part about the music visualizer.

It sounds like you figured most of your question out already.
(Someone correct me here if I'm wrong). The Atmega 328p uC, I believe, has an 8 byte hardware buffer for RX serial data. In software, the Arduino core code defines a maximum ring buffer of 64 bytes that acts as a FIFO queue.
So, what does his mean? Let's just focus on the hardware buffer since it's fairly easy. Say you send your data 1,2,...,10 at 10ms intervals, and you read your data at 100ms intervals (for illustration purposes). The problem is that you send 10 bytes of data but only have room for 8 bytes. So, your first two values (1,2) are pushed out of the buffer and lost. This idea also illustrates a FIFO queue, first in first out.
The same idea can be extended to a ring buffer.
Anyway, like you said, this could explain your problem. If you have 64 bytes, which will obviously be full since your inevitably losing data (20ms read with a 10ms write), you'll be seeing the effects for 64 * 20ms = 1.28s. There's probably some processing delay too which will extend this delay, but it's more than likely minimal if it's efficient code.

The hardware buffer is only 2 bytes according to the datasheet: “The receive buffer consists of a two level FIFO.”

Actually, the last bytes received are dropped when the input ring buffer is full.

Arduino only performs Serial.read at 20 millisecond intervals.

It sounds like you're using delay to pace the reads.  But why?  You'll start to lose data after reading just 3 or 4 characters (60ms to 80ms).  Serial at 9600 can send 1 character per millisecond, 20 times faster than you are reading them.
If you edit your post to include your code, we might be able to make a suggestion to eliminate that delay.


text:
Help understanding how to drive Step motors with Arduino
I am building a 2-Axis gantry system to dispense some thermal paste on boards. I was given two stepper motors in order to do so along with a gantry already built that will arrive in two weeks. So basically I just need to figure out how to drive them on the software side. However the boss demands testable code to be finished by EOB tomorrow, despite the hardware not being here yet. So I drafted some quick code that should drive a stepper motor, it's an easy open loop system, but I'm struggling. The operator will home the gantry after each cycle so it's just a matter of getting the motors moving.
My method was as follows:
#include <Stepper.h>
*declaring the stepper and all that goes here*
void loop(){ etc.
   basic logic flow stuff
   stepper.step(20); // to move forward twenty steps
   stepper.step(-20) // to move back twenty steps

However my boss says this is incorrect as I need to be giving the steppers both step and direction.
After some tenuous google searching he recommended I use the AccelStepper library to fix this problem. After looking through this library I'm unsure how this will give me anything I need (distances are so small acceleration is useless) and how I am not giving it both step and direction in my original example code, I give it steps (20) and a direction with my negative/positive coefficient.
Am I correct in my thinking? Is there a better solution neither of us have found? I'd love to understand not just that I'm wrong, but why I am.

Does your boss not realize that the polarity of the number is the direction?

@IgnacioVazquez-Abrams thats what I responded with. He just seemed confused and said something  about direct driving. I am not one to question him, he's been in the CNC business longer then I've been alive. I'll suggest this during our standup tomorrow morning.

You should read this: http://www.cncroutersource.com/cnc-control.html
"First lets review how the computer or the stand alone user interface communicates to the controller. Most systems today operate on a step and direction format of command signals. Some higher end machines use a proprietary analog or digital signal, but it is usually a variation of the step and direction format."
Probably your boss wanted to tell you that the protocol from the PC to Arduino (or standard CNC protocol) differs from the way the stepper library works

Also, I'm guessing stepper motors have a rather tricky way of working, they use combinations of pins for rotating, in which forward differs from backward. Your boss might be talking about this, while you're using the arduino library which covers up all the direct hardware interfacing.
You should tell him, or even better, show him with an image that you're using the arduino as a controller, which has software instructions that will drive the stepper.

Sorry for all the commotion on your thread.
It comes down to this: Your boss (probably) wants you to implement the driving off the stepper motors yourself, withouth using the arduino library. You should check some tutorials on stepper motors. And ask him if he wants you to drive the coil pairs 'manually' rather than using a library. He's most likely to say yes (as this is how the pro's do it? :D or how you should learn it.).

Show him the source code of the Stepper library. The first three statements of Stepper::step(int) convert the signed number of steps to a positive number of steps (steps_left = abs(steps_to_move)) and a direction flag (this->direction).

I think there is some mis-communication between you and your boss. I do not think your boss is stupid, but I do think he's talking on a different level as you do. You're using arduino which covers up a lot of hardware-interfacing, especially with steppers.
I suggest you check out this video: https://www.youtube.com/watch?v=bngx2dKl5jU
(I haven't watched it, but It will help you get more into the ideas of your boss)
Now you understand your boss's view, you can try to show him your view. When talking about steppers/arduino and how you can put in negative steps, he might think you're talking trash, as steppers require different pairs of coils to be active depending on the direction. (which is all handled by arduino)
The best way is to provide him a visual guidance, so that he can see the relation with his (hardware-view) on the issue and your software/arduino solution.
You could make something like the image below.
I'm not sure if this is what you're trying to tell him.
I guess you should mention/add that the software on the arduino takes integer values, with negative values being clockwise or such. And that the arduino will convert this to the right coil pairs or direction and step.
P.S:with direct driving, I think he meant toggling the right pins at the right moments so that the stepper will rotate, basically what the stepper library does for you. Maybe he wants you to implement something like the stepper library (is it an internship? so that you can learn?) I suggest you check some tutorials on how stepper motors work, and how you can drive them 'directly' withouth the use of libraries.


text:
How to copy files from local computer to Yun with scp?
I need to transfer files from my local machine to my Arduino Yun.
I have tried:
scp /Users/SSCirrus/Documents/index.html root@arduino.local:/root
scp ~/Users/SSCirrus/Documents/index.html root@arduino.local:/root
# No such file or directory (referring to my desktop)

I have confirmed that the filepath is accurate. What's wrong here?

Try ~/Documents/index.html

Try ~/Documents/index.html
The ~ represents the current user's home directory, so ~/Documents is the Documents folder for the current user.  It means you don't have to make sure you have spelled the user's home directory exactly right.
Other options are:

$HOME/Documents/index.html
Documents/index.html (if you are in your home directory)
cd ~/Documents then just use index.html

... the list goes on ...


text:
Running multiple tasks at once
For a school project we're working on a wearable device to track people's movement and heart rate. We use an Arduino Pro Mini with a heartbeat sensor and an accelerometer. The wearable device uses Bluetooth to send data, but only once or twice a day to save battery.
The problem we currently face is having the Arduino keep track of the accelerometer data while also reading the heartbeat sensor on a select interval. See the pseudo-code underneath. In what way (preferably without implementing too many libraries) could we merge these two loops so the accelerometer is read non-stop while keeping an interval (of about 30 minutes) between the heart beat readings? Any input would be greatly appreciated and if needed I can provide additional information.
void loop() {
// Heartbeat sensor loop
  while (array is not full) {
    delay(30 minutes);
    heartbeatArray[index++] = readHeartbeat();
  }
  sendData_Bluetooth(heartbeatArray);
  emptyArray();
// End of heartbeat sensor loop

// Accelerometer loop
  while (true)
    if (readAccelerometerData > limit)
      sendAlert();
// End of accelerometer loop
}

How long does readHeartbeat() take to execute? What is the accelerometer sampling rate and must it stay consistent?

Reading the heartbeat takes about 10 seconds but may take longer as we plan to read multiple samples to check for inconsistent data (the sensor sometimes doesn't work or gives odd data). The accelerometer samples every 100 ms and should continue like that, preferably also while reading the heartbeat.

What you want to do is rather easy task, you just need to forget about delay() function. When writing some more complex programs using it is generally a bad idea, as it blocks code execution, so you won't get any sensor readings, communication, anything. Instead try something like this:
unsigned long delay1 = 100;
unsigned long delay2 = 1800000; //30 minutes in miliseconds
unsigned long t1, t2;

void setup() {
  t1 = t2 = millis();
}

void loop() {
  if(millis() - t1 > delay1) { //this will be executed every delay1 ms
    // do one part of code
    t1 = millis();
  }

  if(millis() - t2 > delay2) { //this will be executed every delay2 ms
    // do another part of code
    t2 = millis();
  }

  // here insert the code that should be executed as frequently as possible
  // (every loop passage)
}

There is also a nice Arduino library called TaskScheduler, that basically does the same thing: periodically executes different functions with different time intervals.

I figured delay() wouldn't be a good idea as I was aware of it blocking execution; I just put it in to indicate the wait before the next reading. Thanks for the millis() suggestion though, think I'll give that a try. Will it however block the accelerometer reading if the heartbeat sensor reading takes a few seconds?

@OlivierV accelerometer can be read every time main loop executes. So if you are stuck at some inner loop of reading heartbeat, other sensors won't be checked. Try to divide this long process to smaller pieces. Perform the first piece, read accelerometers, perform the second etc. State machines concept can come useful here.

millis() is your great friend here.
millis() is function that returns the value of a 32 bit counter that is incremented once per millisecond. By adding the current value returned by millis() to a value representing the number of milliseconds that you want to 'delay' for you get a value that can be compared with the ongoing value returned by millis() to see if the time period has elapsed.
You can have as many variables as you wish which hold future timeout values for millis(0 - you perform the related action when millis() returns >= the saved value and reinitialise the value to some new future time.
Variables used to hold values from millis() MUST be type unsigned long.
The millis() timer rolls over every 49.7 days.
( = 2^32/1000 ms/s / 3600 s/hr / 24 h/day)

If your system may run for longer than that without being reset or powered down then handling millis()'s timer rollover must be known about.
It's MUCH easier than many people realise but best not dealt with here EXCEPT to know that if you add a constant to millis() and the value exceeds 2^32 and is truncated the comparisons with and subtractions wrt millis() still work correctly if the variable is type unsigned long. ("Why" is for elsewhere)

micros() is like unto millis() but returns the time since reset in microseconds. Depending on the processor used micros() may have a granularity of 4 uS rather than one uS. ie it steps by 4 counts every 4 uS rather than 1 count per uS.
micros() rolls over every 1.19 hours
( = 2^32 / 10^6/3600s/h)

// Example - not tested:
unsigned long DoitNow;

void setup(){
  DoitNow = millis() + 1800000; // Add half an hour of milliseconds
 }
void loop(){
   if(millis() > DoitNow)
   { Do heartbeat stuff;
      DoitNow = millis() + 1800000; // Add another half hour of ms
   }
 Do accelerometer stuff;
}

Your test millis() > DoitNow does not work if the computation of DoitNow = millis() + 1800000 has rolled over. You should never compare timestamps like you have done here, it does not make sense. Comparing delays (as in mactro's answer), on the other hand, is rollover-safe.

I just finished a tutorial on the millis() rollover covering precisely this issue. You may want to take a look.

To keep the 10Hz accelerometer sample rate consistent, you'll need an 10Hz interrupt routine to do the sampling, and probably queue them somewhere, as they will accumulate while you're off measuring the heart rate.
Your main loop can collect any accelerometer samples out of the queue periodically, and at appropriate intervals, read the heart beat. This organization will keep the accelerometer sample rate stead whether your main loop has anything else to do or not.
Make the queue more than long enough to hold all the samples that could collect during a heartbeat measurement, which you should probably make one at a time, even though you might do it in rapid succession, so the main loop gets to drain the accelerometer queue as often as possible.
Otherwise you'll need a queue as large as (10 Hz * 10 sec * maxPossibleConsecutiveHeartBeatMeasurements * factorOfSafety * sizeof(oneSample) bytes; and you don't have a whole lot of memory to play with in an Atmega 328.
Where will you be storing the measurements between Bluetooth connects? If it's an SD card, you'll need some space for its write-buffer, and the main loop will have to manage the card writing.

See https://electronics.stackexchange.com/a/67091/10371 (Since this is another stack exchange site, I won't copy the info)
The short answer is to use timers that trigger interrupts.  Examples are shown in the link.


text:
How to read code from Arduino Uno to Arduino IDE?
we can upload a code into Arduino UNO from our computers, but how about reading code? Can we read and get C codes from compiled codes from Arduino hardwares? My second question is that will we read these compiled codes on Arduino ZERO's debug port, which will be a new product for us as developers?

Can we read and get C codes from compiled codes from Arduino hardwares?

While it is possible, even trivial, to disassemble machine code, it is very difficult to convert the assembly code into a higher-level language, and essentially impossible to turn it back into an exact copy of the source code it came from. There simply isn't enough information in the machine code to do so.

My second question is that will we read these compiled codes on Arduino ZERO's debug port, which will be a new product for us as developers?

The debug port will work in tandem with appropriate software that will already have access to the source code, so this is not a method for conversion either.

You wont be able to get the code in readable C. It would be in Machine code.


text:
EB - 4x4 Soft Keypad Driver Diagram from Makerstudio needed
I have found this interesting device wile looking for a cheap Arduino.

It's a "driver" that converts a 4x4 Keyboard 8-PIN (8-IO)
to a 4-Pin (2-IO) Device
I would like to know if is Achieved by a shift register ,One Wire Keypad or some other magic. If you have a diagram/tutorial/video please share (I know the "One Wire Keypad" uses Only 3-PINS (1-Analog-IO))Naturally ordered one to have a look but its gonna take some time to get here and i am way to exited.

If you can identify the chip that's on it that should give you all the information you need.  Chances are it's an I2C interface.

The chip is a tm1650. But I don't know how it is being used on makerstudio.cc their is a lib to use it.But i have not had time to use it yet .

Have you thought to ask Google then?  5 seconds, and I have Arduino library: http://playground.arduino.cc/Main/TM1650 and datasheet: http://www.datasheetspdf.com/datasheet/download.php?id=840047 which though in Chinese has certain words like "SDA" and "SCL" in English. Like I guessed, it's an I2C interface.


text:
Powering a 6-12V motor using a lead acid 6V battery with 6Amps of current?
Hi I'm using a adafruit motor shield v2 and I need to power a DC motor 6-12V but I'm not sure if my battery will be okay for the shield. Will it burn the shield? I'm going to be using 6V so it should draw less current?

The 6Amps is the maximum current the battery can supply. It will only supply what it needed. You only need to look at the voltage, and 6v is fine for both the shield and the motors.

On the shield it says 1.2A/motor (3A max)

"1.2A per motor", so the battery doesn't really matter here, only the motors. What is the current rating of the motors at 6v?

Here's the link to the motor specs:  http://www.jaycar.com.au/Electromechanical-Components/Mechatronics/Motors-%26-Gearboxes/12V-DC-Reversible-Gearhead-Motors---55RPM/p/YG2738

14A full load (at 12 volt). 0.45A at no load (at 12V). So it depends on what is attached to it. You could try measuring the current by connecting the motor directly to the battery and see how much current it uses at 6v when attaching the maximum load.

Ohkay that sounds good but its just for an RC car project like move the wood car, do u think it will be a problem?

If you take the "full load" to be the "stall current", then you can work out the resistance of the winding.
R=V/I = 12/14 = 0.857Ω
From that you can then work out the stall current at 6V:
I=VR = 6×0.857 = 5.143A
That, being the stall current, is the maximum the motor will draw - the current drawn when it is trying to move an impossible amount of load and the rotor cannot move.  At that current you will melt the motor drivers (or they will go into thermal shutdown).
Of course, with a geared motor, that becomes a (comparatively) massive load and would be quite hard to achieve.  You have a 50:1 gear ratio, so the stall load is effectively 50x greater.
So there is going to be a limit to the load that you can drive with the motor before it becomes a problem for the driver.  There are ways of calculating it from the given torque, gear ratio, load/noload current ratings, etc, but I don't have all that at my fingertips right now.
So you can either "play it safe" and invest in a driver that can cope with the stall current, or experiment and measure what current is drawn by the motor with different loads and see if it stays below the 1.2A limit of the shield.