text:
Ethernet Shield - Multiple simultaneous connections cause TCP reset
I have a very inconvenient problem with a web server I'm writing for a Arduino Mega 2560 with a W5100 Ethernet Shield (with the "official" Ethernet lib). I wrote the server code and it works like a charm, BUT there is a condition, when the server won't accept all the TCP handshakes and resets the TCP connections:
When I load a big webpage, the browser (Firefox and Chrome too) asks for the .htm first, then collects the links in the file and request them all simultaneously and that's when I got the problem:
The server gets multiple TCP connections but it only accepts the first, then dumps all the others (by TCP reset). After that the client sends them again and the problem starts again: the server accepts the first and drops the others. And so on, for example if the browser needs 3 files, it will take ~9 seconds, because of the retransmission delay. (3 + 6 seconds) Eventually the webpage will load, but a 10 second delay is not acceptable.
Is there any way to cache the requests on the Ethernet Shield or to tell the browser to wait a bit between requests or any other way, to wait a bit for the Arduino to finish the previous request?
Snippet for the server, Wireshark and Chrome network data: https://gist.github.com/anonymous/181f359b70d69e4470931204c4ec175c
Thanks for the help!
G.

I am also having this on a Portenta H7. However, the requests are not being retried. Some assets are just never loading. Did you ever find a solution?

I have received a request from the OP to move this to Network Engineering because it got no answers. I'm going to decline this for the moment because I doubt they will be familiar with the Arduino Ethernet shields.

The low-cost shields have a known limit on the number of connections they can handle simultaneously (no doubt limited by available RAM). From the page Arduino Ethernet Shield 2 we learn:

It supports up to eight simultaneous socket connections.

You don't seem to be getting that, which makes me wonder if it is a code issue. It might help to post your code. If you make code that "blocks" while handling the first connection you may not accept the other ones in a timely way, leading to a reset.
Please post a Minimal, Complete, and Verifiable example.
I did a post about a tiny web server for the Arduino which uses a state machine to handle incoming data without blocking.

You may also be able to help yourself by using the HTTP header that requests that the connection be kept open, eg.
Connection: keep-alive

That might stop the client opening new connections in quick succession.

Thank you for your answer, I'll write a working example of my server tomorrow, I'll leave a comment then.
Your web server solution might be applicable for my problem, but I'd have to modify it and my server code heavily to make it queue requests, so it's kind of a last resort solution.
The "keep-alive" header unfortunately did not solve the problem.

I asked for the move of my question because I was hoping I could get some networking (like TCP/IP or HTTP or client-side) tip to solve the problem without heavily modifying my server code and also because I had no answer, but that changed recently. :)

@NickGammon what do you mean you server is non-blocking? It only handles one client (one HTTP connection) at a time as far as I can tell from your code. I don't see how this solves the problem.

@Marcel In the main loop, it gets a character at a time from the client and passes that to the "state machine" in the server code. It doesn't block. Until a request reaches a reasonable processing point it just keeps accepting new characters. A reasonable point might be when a GET parameter has been received, upon which it calls processGetArgument. Now since it doesn't block, you could have multiple instances of the server object, and feed multiple HTTP connections to them (one to each one).

@NickGammon Oh I see. Thanks for clarifying. The implementation seems a little involved though. Any plans to add something like this to the library?


text:
Buffering output stream
I'm looking to toggle a pin on and off in a fast and timing-sensitive manner, and I'm wondering if the Arduino Uno has any built in "buffers" that would be able to hold a set of values and send them sequentially to the output pin at high speed, separately from the rest of the loop. I could then refill the buffer with the next set to be outputted, and so on.
Is this even possible? If anyone has any documentation on what's involved, I'd really appreciate some links (or tips!) :) thanks

The closest thing to what you describe is DMA (Direct Memory Access). The Arduino doesn't have DMA. More powerful microcontrollers often do, but not little 8 bit ones.
The closest you could do is to use a timer interrupt to run a small function periodically which reads the next value from an array and sets the pin to that state.
The TimerOne or TimerThree libraries can be of help to you here.

For most Arduino devices, using the USART in SPI mode is about the most effective way to generate a hardware-timed stream of bits out of one pin.  For background, see §21, “USART in SPI Mode”, in the ATmega328 data sheet.  For some example code and exposition, see ATmega Arduino USART in SPI Master Mode MSPIM,
Posted on February 17, 2015 by feilipu.
Ordinary SPI output on most Arduinos is single-buffered, hence subject to occasional delay if other interrupts get in the way of the SPIF-SPIE-SPDR interrupt handler.  However, the USART-in-SPI-mode method double-buffers output as well as input, allowing continuous data output.  That is, one can generate a continuous stream of bits clocked out at whatever rate one selects.
The Arduino Due is based on the Atmel SAM3X8E ARM Cortex-M3 CPU, a 32-bit ARM core microcontroller.  It supports DMA (direct memory access) and one can find webpages, eg arduino.cc topic 219291, describing waveform generation using DMA and the 12-bit DAC (digital to analog converter) on the Due.  More notably, the Arduino software compatible Teensy 3 series uses Cortex-M4 and M4F chips on boards running at 48, 72, 120, and 180 MHz, probably more suitable for elaborate waveform generation than are the Due or Zero.

source: Stack Exchange

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

sort: votes


text:
Using PROGMEM in constructor
Is it safe to use PROGMEM variable like dynamically allocated memory (a pointer to PROGMEM variable which is out of scope).
I need this so I can generate a variable size (before compilation), constant values, lookup array stored in flash.
Working example:
class Ex_class {
  public:
    Ex_class(int table_size, int value_range) {
      int flash_table[table_size + 1] PROGMEM;
      _ex_table = flash_table;
      for (int i = 0; i <= table_size; i++) {
        _ex_table[i] = random(value_range);
      }
    }

    int get_value(int index) const { return _ex_table[index]; }

  private:
    int* _ex_table;
};

void setup() {
  randomSeed(analogRead(0));
  Serial.begin(9600);
  Ex_class ex_object(5, 50);
  for (int i = 0; i <= 5; i++) {
    Serial.print(i); Serial.print(": "); Serial.println(ex_object.get_value(i));
  }
}

void loop() {}

I am amazed this even compiles... You cannot assign a value to a PROGMEM variable, the only thing you can do with PROGMEM is store compile-time constants. And you cannot dereference a pointer to PROGMEM with * nor [], you need one of the pgm_read_*() macros.

The compiler cannot run "Ex_class ex_object(5, 50);" at compile time.

I am surprised too, but it actually works.

It's probably getting the data from RAM that was allocated (and deallocated) in the stack.

You are right, it stored a new variable in the same address.

The closest I could get to what you are trying to do is this:
template <size_t table_size> struct Ex_class {
  int get_value(int index) const {
    return pgm_read_word(&_ex_table[index]);
  }
  int _ex_table[table_size];
};

void setup() {
  Serial.begin(9600);
  static PROGMEM const Ex_class<5> ex_object = {1, 2, 3, 4, 5};
  for (int i = 0; i < 5; i++) {
    Serial.print(i);
    Serial.print(": ");
    Serial.println(ex_object.get_value(i));
  }
}

void loop() {}

avr-nm and avr-objdump confirmed that the object lives indeed in the
text section of the program. Please note that:

The object is PROGMEM const. It would make no sense to try to put in
PROGMEM anything that is not constant.
The object is allocated statically. It can be either a global or a
static local, but not an automatic local like in your example.
I am using aggregate initialization here. I know no other way to
statically initialize an array of variable length. If you have an
idea, I would be interested to know though.

Thanks. The only thing I can think of is initializing the flash variables separately (because they need to be calculated) and then putting the pointers to them in an array. It shouldn't be a problem since the flash is read-only.

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


text:
Unable to connect Arduino Uno to Ubuntu 16.04
I've received an Arduino Uno today only. I have zero experience prior to Arduino boards or any other micro controller. I followed every step very carefully from the setting up guide for Linux based OS, but I still can't connect the board with my Ubuntu 16.04 PC. After googling the problem I found that the device must show up as ttyACM* but I don't see any such device in /dev. Its also not listed under the command lsusb but the LED's on the board are working properly. The ON LED is turned on when I connect it with my PC and the inbuilt LED starts to blink.
This is what the IDE displays:

Have you tried a different cable?

yes I have two cables

@Majenko can you help me please

In a terminal, run dmesg -w. Then plug in the Arduino. Post the additional lines that should appear into your question.

Some things that may help you: https://hackingmajenkoblog.wordpress.com/2016/08/24/diagnosing-arduino-problems-in-linux/

@Majenko I tried dmesg -w but no new lines show up when i connect the board

Is it a genuine Arduino or a Chinese clone?

@Majenko its a clone

Ah well, there you go then. Maybe it's just dead. Maybe you were sold a lemon.

@Majenko but it can't be dead the LEDs are working just fine

There are two parts: the main MCU, which is working, and the USB interface which, on clones, often dies. Does it have a square or a rectangular chip next to the USB socket?

@Majenko A rectangular one

CH340G - notoriously bad.

Did you select the port in the Tools menu? Check that it shows up there and is selected.

You may have to add yourself to the dialout group in Ubuntu so that your user account can access the serial ports.
Then, in the Arduino IDE, the Tools->Port menu should show you options. Right now, the screenshot you gave shows that it's set for COM1, which is a Windows-style serial port naming and definitely won't work on Ubuntu.

I've already done that and the Port menu is grayed out.

Did you log out and log back in after adding yourself to the dialout group?

yes I did.
I even tried rebooting but nothing works


text:
Sending values from Matlab to arduino using serial communication
I want to send numeric value from matlab to arduino but code is not working.
Matlab code is as:
doi = 3 ;
arduino=serial('COM5','BaudRate',9600); % create serial communication object
fopen(arduino); % initiate arduino communication
fprintf(arduino, '%s', char(doi)); % send answer variable content to arduino
fclose(arduino);

Arduino code is as:
  int solenoidPin = 13; //This is the output pin on the Arduino
int doi;

void setup()
{
  Serial.begin(9600);
  //pinMode(13, OUTPUT);
  pinMode(solenoidPin, OUTPUT); //Sets that pin as an output
}
void loop()
{

  if(Serial.available()>0)
  {

    doi = Serial.read();
    //Serial.println(doi);
    //Serial.println("\n");
    //doi = doi - 48;
   if (doi == 1)
   {
    //Serial.println(1);
    digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
    delay(1000); //Wait .15 Second
     digitalWrite(solenoidPin, LOW);
    }
  else if (doi == 2)
    {
     //Serial.println(2);
    digitalWrite(solenoidPin, HIGH); //Switch Solenoid OFF
    delay(2000); //Wait .165 Second
    digitalWrite(solenoidPin, LOW);
    }
  else
    {
      //Serial.println(3);
      digitalWrite(solenoidPin, HIGH); //Switch Solenoid OFF
      delay(3000); //Wait .180 Second
      digitalWrite(solenoidPin, LOW);
    }

  }
}

I used str2num(doi) also instead of fprintf(arduino, '%s', char(doi)) but no output.
Please give suggestion to correct this.
Thanks.

You need to learn how serial communication works. https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/

fopen(arduino); takes some time to initialize the serial connection so you should use pause(2); after fopen(arduino); and in fprintf() send doi as interger i.e. fprintf(arduino, '%i', doi);. Suppose the doi is 1 then code would be as
doi = 1;
arduino=serial('COM5','BaudRate',9600); % create serial communication object
fopen(arduino); % initiate arduino communication
pause(2);
fprintf(arduino, '%i', doi); % send answer variable content to arduino
fclose(arduino);

Another modification required in arduino program as
doi = doi - 48;

Uncomment this line inside if(Serial.available()>0) block.

I presumed that you are retrieving the value of doi from some other function then using pause(2) will make your program significantly slow. to avoid this problem you can split your program into three part first part will contain upto fopen() which will be executed when the main program initialized, fprintf() will be executed during runtime and at the end fclose() will be executed to terminate the serial communication.

You send a string of ASCII characters representing a number in human readable format.
You then read one of those characters that represents a single digit and then try and use it as if it were a number.
Instead you need to read the whole string of numbers (which means having some way of knowing where the end of the numbers are in the stream of characters that arrive) and then interpret it back into a number again.

Hello Thanks for your reply but as I am beginner so I can not understand the solution what you suggest completely. Can you please suggest me modification in my above code so that I can solve this problem. Thanks.


text:
Carry out two consecutive tasks when a button is pressed
I'm building a project that has 2 motors. What I want to do is:
When button is pressed (hold down through RF controller) then:

Run motor A on pwm at 50 for 1 second
Run motor B on pwm at 255 for 1 second

After that first second

Run motor A on pwm at 255 until button is released
Stop motor B.

And when I hit the button again the whole thing repeats. Here is my rough code but it doesn't work that way. What it does is if I pressed the button in the first second since start up off the Arduino it does the first task. If I press it again it does the second task.
I have looked and tried through a lot of examples of blink without delay and multitasking. But I still can't get it working.
Here is my code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <elapsedMillis.h>

// Motor 1
int dir1PinA = 4;
int dir2PinA = 5;
int speedPinA = 3; // Needs to be a PWM pin to be able to control motor speed

// Motor 2
int dir1PinB = 7;
int dir2PinB = 8;
int speedPinB = 6; // Needs to be a PWM pin to be able to control motor speed

int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

unsigned long previousMillis = 0;
long OnTime1 = 500;
long OnTime2 = 10000;

void setup(){
 Serial.begin(9600);
 radio.begin();
 radio.openReadingPipe(1,pipe);
 radio.startListening();

 pinMode(dir1PinA,OUTPUT);
 pinMode(dir2PinA,OUTPUT);
 pinMode(speedPinA,OUTPUT);

 pinMode(dir1PinB,OUTPUT);
 pinMode(dir2PinB,OUTPUT);
 pinMode(speedPinB,OUTPUT);

 }
 void CandPush()
 {
          analogWrite(speedPinA, 50);//Sets speed variable via PWM
          digitalWrite(dir1PinA, HIGH);
          digitalWrite(dir2PinA, LOW);
          analogWrite(speedPinB, 255);//Sets speed variable via PWM
          digitalWrite(dir1PinB, LOW);
          digitalWrite(dir2PinB, HIGH);

 }
 void CandStop()
 {
          analogWrite(speedPinA, 255);//Sets speed variable via PWM
          digitalWrite(dir1PinA, HIGH);
          digitalWrite(dir2PinA, LOW);
          analogWrite(speedPinB, 0);//Sets speed variable via PWM
          digitalWrite(dir1PinB, LOW);
          digitalWrite(dir2PinB, LOW);

 }
 void Home()
 {
          analogWrite(speedPinA, 0);//Sets speed variable via PWM
          digitalWrite(dir1PinA, LOW);
          digitalWrite(dir2PinA, LOW);
          analogWrite(speedPinB, 255);//Sets speed variable via PWM
          digitalWrite(dir1PinB, HIGH);
          digitalWrite(dir2PinB, LOW);

 }
 void loop(){

 if (radio.available()){
    bool done = false;
    while (!done){
    done = radio.read(msg, 1);
    Serial.println(msg[0]);
    if (msg[0] == 111)
    {
      unsigned long currentMillis = millis();
      CandPush();
      if(currentMillis - previousMillis >= OnTime1)
      {
        CandStop();
        previousMillis = currentMillis;
      }

    }
 }
 }

 else
 {
  Home();
  Serial.println("Nothing");
 }
 }

I assume pressing the button results in msg[0] == 111 every time you do the radio.read (i.e. it will continue sending that while the button is held).  If so, the first issue I see is that after 500ms has elapsed, you will call CandStop(), and then it will loop back and immediately call CandPush(), essentially cancelling the second state.
I think you should create a state variable and state machine, so for example it does a different operation when/while the button is pressed depending on whether it is in the 'home', 'push', or 'stop' state.  In the first ('home') state it is waiting for the button to be pressed, in the second ('push') state it is waiting for the time to elapse, and in the third ('stop') state it is only waiting for the button to be released.  It would also allow you to avoid repeatedly calling CandPush() and Home() when it only needs to be called once (when the button is pressed).
EDIT:
I am adding the code below.  This hasn't been tested so there may be some bugs but it should give an idea of what I mean.  It could probably also be optimized somewhat, but I tried to make it do what I think you wanted it to do based on the code you attached.
There are parts in there that I doubt work as you wanted, aside from the button handling, for example how Home() is called whenever there is no radio available and how nothing appears to happen when the button is released.
Should the Home() call really set B to full output?  I added a call to StopAll which I assumed you would use to stop A and B when the button is released.
Also radio.read doesn't return anything, so done = radio.read(...) is pointless.
// State machine states
enum {
    STATE_INIT,
    STATE_HOME,
    STATE_PUSH,
    STATE_STOP
};

unsigned long previousMillis;
bool buttonPressed = false;
bool radioAvailable = false;
int state = STATE_INIT;

void loop()
{
    //Check for new radio input every cycle
    if (radio.available()) {
        radio.read(msg, 1);
        buttonPressed = (bool) (msg[0] == 111);
        radioAvailable = true;
    } else {
        radioAvailable = false;
    }

    //State machine
    switch (state) {
    case STATE_INIT:
        //first cycle after boot-up, add any desired initialization
        //wait here until the first time the radio is available
        if (radioAvailable) {
            state = STATE_HOME;
        }
        break;

    case STATE_HOME:        //Wait for button to be pressed
        if (radioAvailable) {
            if (buttonPressed) {
                //button was pressed, reset timer and move to PUSH state
                previousMillis = millis();
                CandPush();
                Serial.println("STATE_PUSH");
                state = STATE_PUSH;
            }
        } else {
            //no radio input, go to HOME state
            Home();
            Serial.println("STATE_HOME");
            state = STATE_HOME;
        }
        break;

    case STATE_PUSH:        //Wait for timer to elapse
        if (millis() - previousMillis >= OnTime1) {
            //OnTime1 has elapsed, move to STOP state
            CandStop();
            Serial.println("STATE_STOP");
            state = STATE_STOP;
        }
        break;

    case STATE_STOP:        //Wait for button to be released
        if (radioAvailable) {
            if (!buttonPressed) {
                //button was released, stop all motors?
                StopAll();
                state = STATE_HOME;
            }   //else still waiting for button to be released
        } else {
            //no radio input, go to HOME state
            Home();
            Serial.println("STATE_HOME");
            state = STATE_HOME;
        }
        break;
    }
}

Can you give me a code example?


text:
Powering ESP8266EX with batteries and a voltage divider
So I recently bought a ESP8266 chip, it requires 3V3 and a large current( around 210mA max which is more than that can be supplied by an arduino uno at least). I managed to connect it to my arduino uno and got it to operate in standby mode, but Wifi mode wouldn't work because it requires more power.
After reading multiple online articles, I've decided to construct my own power supply. I'm planning on hooking 3 AAA batteries in series(4V5) and then use resistors(of small values to decrease power loss) to construct a voltage divide which powers the chip.
My concern is that I have not seen a single person doing this online and this seems like a straight forward thing to do, which makes me worried. Did I miss something? Is my plan feasible?

See items like “5V 3.3V DC-DC Step-Down Power Supply Buck Module AMS1117 LDO” and “Mini MP1584EN DC-DC BUCK Adjustable Step Down Module” on ebay.  Also, two brand new alkaline AA batteries in series,will be adequately close to 3.3 V, or two C cells if available to you, or one 3.7V 18650 LIPO cell by itself

I wrote a whole blog article about why you can't do it: https://hackingmajenkoblog.wordpress.com/2016/08/30/why-you-cant-use-resistors-as-a-voltage-regulator/

if you want to implement jank, a couple inline diodes between +5v and Vin should drop the voltage to within the ESP's limits of 3.8-2.8v without a lot of heat and wasted current. A "buck converter" based on a switch-mode regulator would be far more ideal.

I've run an ESP01 off of 2 fresh AA batteries just fine; (1.6X2=3.2v; and even 2.8 is ok)

There's a good reason why you can't do this.
When you power something like an ESP, the current it consumes will vary over time, as it does different things. For the purposes of current consumption, you could model the device as a resistor  whose resistance varies (greatly) over time. When it's in sleep mode with the radio off, it might be a 10k resistor. When it's active with the radio on full power, maybe a 30ohm resistor.
A potential divider divides voltage according to the ratio of the resistances. You are talking about putting your ESP in parallel with one of the resistors. Putting two resistors in parallel creates a new resistor with a resistance lower than either of the two.
If you want to calculate the resistance of two parallel resistors, it's R = (R1 x R2) / (R1 + R2).
What values would you choose for the resistors in the potential divider?  You'd have to go for values much lower than 15ohm in order for the 'resistance' of the ESP not to greatly affect the behavior of the divider - say 5ohm in total. This would mean your divider alone would draw a current of 1A from a 5v supply.
Fortunately, voltage regulators and buck converters are easily and very cheaply available. I recently bought a pack of five 3.3v regulator modules from China, delivered for less than £2.
Alternatively, you can create a reasonably stable supply from a reference voltage with just a single NPN transistor, but I don't know offhand whether it would be good enough for this application.

An esp presents 16-65 ohms (4X) under normal conditions, but the allowed input swing is only 0.3X...

no, the swing relative from 3.3 to 3.8v and 2.8v (1v/3.3v); the official range of the ESP

i was just adding numbers to detail why a voltage divider won't work because the highly variable current draw would force a static divider to provide volts outside the acceptable range. If the ESP always used, say, 85-110ma, one could likely get away with a naive divider (heat excepted)

if means that the divider could only swing 30% of it's pre-programmed 3.3 voltage without issue; but how can one accomplish that when the resistance varies 400%? (one can't)

or, put another way, ~15% from the midpoint for a total range of 30% of the target. you can go 15% down or 15% up, but no more. 0.99v is the spread from 3.8 to 2.8... let me rewrite my comments to clarify, can you delete your responses and i'll follow suite with a to-the-point comment? ( i hate to gunk up a good answer)

Ok I see what you mean. You can do it, by putting the ESP in parallel with one of the resistors in the divider, but you have to use such low value resistors that you're drawing many watts.


text:
Connecting a sensor to the 5V pin shorts Arduino Nano
I bought an ultrasonic distance sensor seen here: http://arduinobasics.blogspot.co.uk/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html?m=1. As per the wiring diagram I connect it to the ground and 5V pins on my Arduino Nano which is powered via USB.
As soon as I connect the 5V to the sensor it shorts and the lights on the Arduino go out and my laptop says 'usb surge too much power being drawn'. Do I need to add a resistor to the circuit? It all works fine and I get a result when the sensor is connected to the 3V3 pin but it does not ping properly.
I have tried using an external power supply via a breakout board as well as usb mains plug but both still short. Any help would be much appreciated!

Perhaps the sensor has an internal short, or you're accidentally shorting wires? I just plugged my unit in exactly the way the referenced link shows, and using their code also on that side, I have no issues (with USB power or external PSU).

I tried both sensors and neither one works. I think i must be shorting wires somehow.

Can you show a pic of how you're doing things?


text:
Vin and Ground pins shorting only under specific conditions
So I have an Arduino Nano that I think might have gone bad. The Vin and ground pins are shorting (I'm checking continuity with a multimeter). But it only shorts when:

The Arduino has power
The red lead of the multimeter is on ground and the black is on Vin (not the other way around)

I've tried checking with the leads both ways (red to ground as well as red to vin) while both on and off, and with two different multimeters, one of which is brand new. Completely at a loss for words because this isn't really how physics is supposed to work (continuity shouldn't depend on lead orientation from the multimeter or whether the circuit is powered, right?). Any insight would be appreciated. Do I have a bad board?

Sounds normal to me. You shouldn't measure continuity when power is applied. As to point two. For the multimeter to measure resistance, it has to apply a small voltage. The Arduino however is using this voltage and tries to run on it. This in turn will drop the voltage making the multimeter confused. Measuring components that are in circuit can be hard or even impossible in certain situations.

if a circuit has DC continuity in one polarity and not the other, there is a diode across the circuit. you describe a "reverse input polarity protection" diode doing it's job.

But it only shorts when: The Arduino has power

You must not use a continuity checker or ohm meter on a powered circuit.
Not only will it not work, you risk damaging the meter.
It's also not necessarily safe to use such a meter on an unpowered active electronic circuit like an IC or eval board, as the meter must apply a small amount of power to the circuit to make a measurement - how much power varies between meters and settings, and how much a circuit can tolerate in an unintended way depends on things like polarity and the state of other parts of the circuit.  However, it is common practice to do so - especially for example when there's a fear that the device might already be damaged.

It is not clear from your question what you are measuring with the multimeter (volts, ohms, amps etc.) but if you are using the ohms scale when your Nano device is not connected to the power, your multimeter charging capacitors on the board and reversing the leads will then cause a discharge through the multimeter, maybe giving a reading which leads you to believe there is a short circuit.

I'm checking continuity (whether or not there is a closed circuit).

Also if you have this setup and set it to measure Amp, then it will effectively shortcut the leads with as small resistace as mutltimeter can.
Also check, if those connectors (usually crocodiles) cannot touch something they should not (each other mainly)


text:
Driving two stepper motors using one stepper motor driver
Using an Arduino Mega, I currently control two stepper motors that never operate at the same time and never will. I am using two EasyDriver stepper control boards with two separate power sources. I was wondering if I could go down to just one stepper control board, one power source but somehow switch the 4 input wires from one motor to another when I need to turn a specific motor. Is there a switch I can control with Arduino where I can plug in 8 wires and say "ok, use the 4 left most wires" or "switch to the right most 4 wires". Does that exist or is that more complicated than what I currently have?

If we call the motor leads A1, A2, B1, B2 on each motor and control, you could tie the two motor A1's to A1 on the control, and motor B1's to B1 on control.  Then wire a DPDT relay as below.  (Coil not shown.)  Note, DPDT relays are about $4 on ebay, with labels like “DR21A01 DC 5V DPDT Relay Module Polarity reversal switch Board for Arduino UNO”.

simulate this circuit – Schematic created using CircuitLab
Since you have equipment in place and working, it might not be worthwhile to change your setup.  However, even without adding a relay, you probably can power both motor controls and motors with a single power supply, ie could use one instead of two power supplies.  The current draw when a stepper motor is idle is a small fraction (eg 10-20%) of the high current drawn when the motor steps.  If you don't have power attached to a stepper motor, there is only its cogging resistance to keep it from turning; it does not take a large torque to turn an unpowered stepper motor.  If that's a concern, the DPDT relay approach might be unsuitable.


text:
When is it necessary to use "float" instead of "int"?
I'm very new to Arduino and I am making a code for a pedometer.  I have a lot of variables and I have used "int" multiple times, but I just came across a code with "float".
Now because my coding background is next to none, I don't really understand the concept of a float and when it's appropriate to use one.
Could someone please give me an explanation.
Thanks!

use them for intermediate division in places map() won't work

An integer is a whole or natural number.  Computers use integers for counting and comparisons.  Computers can count precisely using integers and comparisons of two integers can be absolutely true or false.
To make a float or floating-point number, a computer uses two integer numbers.  It uses one integer as the mantissa and the other as the exponent.  Computers use floats for calculations involving very large, very small or fractional values.  In other words the set of real numbers.  Computers can not count very well using floats.  Computer can not even compare two floats very well. That is to say, you may get different results from different computers when testing if two different floats are the same or not. This is due to rounding error.
Consider that the set of real numbers between 0 and 1 to be infinite.  However, intuitively, we know computers can not keep track of an infinite number of unique values between 0 and 1.  After all, computers use a float to do this and a float has a finite number of bits in it's mantissa and exponent.  The difference, if any, between the actual real number from, say, a calculation and the next possible float value is commonly referred to as the roundoff error.  In a program, a difference, for example, in the order of operation is enough to cause different roundoff errors to occur resulting in two slightly different float value results.
Rounding errors are what we end up with for allowing float values to grow very large or very small or to contain factional amounts.  Fortunately, floats are exactly what we need when computers are asked to calculate very large, very small or fractional numbers.
In embedded programming we rarely use floats.  They take up more of our limited RAM space than integers.  And it is rare that we need to calculate very large or very small numbers.  Usually, in embedded programming, we are counting events or measuring sensors.  Usually integers are preferred or are sufficient for our purposes.
Addressing your specific application (pedometer):
It is anticipated you would prefer to track distances in miles.  And it is practical to assume a good pedometer displays factional miles.  You can use floats to calculate this value.  A rigorous programmer would cast their integers as floats when mixing them in equations to make it clear to the compiler what is desired.

Computer can not even compare two floats very well. This is very wrong. Computers can easily compare two floats. You just have to know exactly why (on a particular CPU) float x=1.1; bool ok=x==1.1; results in not ok. Mandatory reference is What Every Computer Scientist Should Know About Floating-Point Arithmetic.

I appreciate the rigorousness of your comment.  I will reword my answer.

@st2000: You wrote: “[floats] always have a certain amount of imprecision”. This is incorrect, floats are exact numbers. Only the operations done on them may incur rounding error. @Ruslan: You wrote: “float x=1.1; bool ok=x==1.1; results in not ok”. On most Arduinos (the AVR-based ones) it results in ok.

@EdgarBonet OK, I was right to note "particular CPU". Your comment is quite interesting though. AFAIR, AVRs don't have FPU, so float should be "emulated" in software. Based on your comment though, it seems that this emulation makes float and double identical. What is your compiler?

@Ruslan: It's gcc, which is the standard for Arduino. You are absolutely right. AVR floats are implemented in soft, and double is implemented the same as float.

Hi @EdgarBonet, I see your point.  I will attempt to reword the answer.  I appreciate the comment.  This is stackexchange and normally answers are much shorter than "white papers" and usually shorter than wikipedia entries.  I am trying to stay in that format yet provide enough detail for informed decisions.  Let me know if you have any further concerns.

For a pedometer program I would expect number of steps to be an int. I would then have step size in cm or mm also as an int. Internal calculations of distance would then be made purely using ints (or long ints if you need numbers larger than an int can handle). Only when calculating the value to display would you convert to a float and scale into miles or km as needed. That way rounding errors never accumulate, all the internal calculations are exact because they use ints.

"int" means integer. It's either one whole number (forgive me, mathematicians, for the sloppy definition!) or the next or previous.
A "float" is a floating-point number - that is, a number and part of a number.
3 is an int
3.14 is a float
If you need to store/represent a value that can be between integers, you could use a float.
Floats use more RAM than integers, and there is a limit to the precision they can represent. Don't use a float unless you have a need.

"Floats use more RAM than integers" This isn't necessarily always true, some floats are 32 bit and many integers are 32 or even 64 bits.

There are much more details on both data types, but to keep it easy, just a rough explanation:
integer data types only allow a range from -2,147,483,648 to 2,147,483,647 with 4 Bytes of memory per variable.
If your results exceed that numbers, an over- or underflow will occur. If you don't take care, bad things can happen.
And you can only use whole numbers, there is no decimal point.
float instead allows you to do your calculations directly typing decimal values (like 1.25, 3.14, ...), just like you do on paper.
Plus: You usually don't have to care for range checks, because that data type covers a huge value range (-3.4028235E+38 to 3.4028235E+38 with also only 4 Bytes of memory per variable!
So why not use float by default?
One big drawback is that handling this number format requires a special piece of hardware ("Floating Point Unit", FPU) to be efficient.
If your microcontroller doesn't have an FPU (and the small Arduinos don't have one), every calculation using float operands requires to call certain functions which use some rules to convert your float operands into integer data types, do the calculation on integer basis and convert the result back to float.
This consumes some memory and a lot of CPU cycles, which can slow down calculation speed to about 1/10 compared to using an FPU.
There are some other issues which make working with float a little bit tricky, so if your calculation can be done using integer, use this instead.

"And what if i need decimal numbers?"
You can't type 3.14 in integer, but you can multiply it to a value big enough to consider enough decimal places for your application. You just have to define the factor and  imagine the decimal point.
For instance, multiply your values by 1000, then 3.14 * 1.256 = 3.94384 becomes 3140 * 1256 = 3943840 internally.

When is it necessary to use “float” instead of “int”?

IMHO in Arduino world it is never necessary to use float ; well unless you want to do something very fancy like building a space ship route calculation with Arduino. In which case you will have someone on your team who understands the problem in full detail who can decide it is better to use float for some calculations.

How do I deal with behind the comma numbers?

As integers does not allow you to work behind the coma and you won't use float you may wonder how to work with pi (3.1415..radians). In most cases you will only work with a specific number of digits behind the comma. Lets say you want 3 digits behind the comma. In this case you simply work with milli radians instead of radians ( 3145 milli radians=3.145 radians; For the Americans it might be time to look at the metric system for a better understanding)
Because of this change in "base value", no more floats are needed to calculate.  There are 3 drawbacks:

when out-putting information formatting may be needed/desired to
convert to a user "base value".
when in-putting information formatting may be needed/desired to
convert to a user "base value".
When using methods that use float conversions are needed
In and output are normally very small in arduino. The Serial.print() is probably the biggest thing.
If you need to use a method like cos() you do as follows:
long result=DECIMALDIGITS*cos((float)corner/DECIMALDIGITS);
Where DECIMALDIGITS= (float)10^numdigits;

As type I advice to use long on a 8 bitter as int (-32,768 to 32,767) is very likely to get out of range.
More background behind the dirty details of float
It is pretty obvious that float supports behind the comma values, but what are the disadvantage of float?

float is CPU/RAM intensive
float introduces a rounding problem.
multiple types int/float can cause casting issues

Lets go through the disadvantages one by one:
float is CPU/RAM intensive
IMHO In many Arduino projects there is plenty of CPU/RAM left so I don't think this is a real issue.
To prove this point look at how many Arduino projects contain a delay(x00) in the loop; so if things go to slow simply decrease this number to release some CPU cycles ;-).
float introduces a rounding problem.
*When using floats A * B / A does not guarantee to be equal to B!!!* It will be close but ...
This is my main argument to avoid floats. Sooner or later this will hit you and you'll have a hard time finding out why. (I speak from experience here)
Basically 0.1 can not be represented 100% exactly in float. So in float 0.1+0.2 is not equal to 0.3!!!
multiple types int/float can cause casting issues
In C/C++ it is pretty hard to predict the casting that will happen in a formula like:
float z;
byte r;
uint32 t;
...
int a=z*r/t*1.5;

I consider myself very experienced in C/C++ and I always convert code like this into something like
float z;
byte r;
uint32 t;
...
byte rfloat=r;
uint32 tfloat=t;
int a=(int)(z*rfloat/tfloat*1.5);

I prefer not to explain this to a newbie Arduino user :-s.
More in depth details can be found at floating-point-gui.de

While in principle I agree with you, it should be noted that the alternative, namely fixed point arithmetic, is hard, especially for the novice: you have to figure out the proper scaling to apply to your numbers at every step of every calculation. With floats, in contrast, the optimum scaling is automatically computed at run time.

In Arduino world I would disagree. The answer is: Take long. int goest to +-32.700 so is probably to small for cents and for sure to small for millis.
Long still has a huge cpu and memory gain compared to float.

And do not forget. In Arduino world the biggest input is 1023 from the analog read. I challenge you to give a example where long is not long enough for a "normal" arduino project. So no space travelling

No, long is not the universal answer. Sometimes the cost of writing a fixed-point code is just not worth the trouble if you have enough time to do it with floats. You could certainly compute a cos() using only integers (I did it), but you cannot expect a novice to do that.

I do not advice to write your own cos only using integere. I'll mod the answer.

I edited the answer.

I'm very new to Arduino and I am making a code for a pedometer.

others have answered the difference between float and int.
but your project offers an interesting challenge in that it covers a wide range: the pedometer likely counts in miles and have to keep track of total steps, which the increments are done in single steps - much shorter than miles.
what you could do instead of using floats is to use multi-byte types. for example, a 32-bit/4-byte type can support 2 million miles; you can add additional msb to it to create a proprietary data type. a 5-byte type for example would support 5 million miles, and a 128 billion miles for a 6-byte type.
you will need to create your own math routines -> not difficult at all.
the point is that float is a simple solution to simple problems only.

There are tons of scientific computations done with floats. And no, not only simple problems.

int stands for Integer
and float stands for floating point number.
For more reference check this out https://www.arduino.cc/reference/en/language/variables/data-types/float/

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


text:
Arduino Uno-Spider Robot Plan
I have been doing a lot of researching ever since Christmas when I got the Arduino Uno. Anyways, I want to build a 4 leg spider robot using 2 Arduino's. I had a lot of problems on coming up with how to do it, and I think I got it. What I want to be answered is this question, is my circuit good to go and will not fry anything? Anyways, I needed 12 servos. Only 6 pins on 1 Arduino has PWM. So I thought to use 2 Arduino's to communicate through the HC-06 blue-tooth. Power was another problem. I discovered that double AA batteries have an impressive 7 amps on my multi-meter. However, to much for the Arduino. That is why it is only supplying servos and not going directly to the Arduino. A 9v will do that. Anyways, I can't give you guys the schematic as it is to big of a file. However, I will explain the circuit in words. One Arduino is master and the other is slave. These steps go to both master and slave unless stated.

6 servos on master and 6 on slave. Power is going to 4 double AA batteries in series. This supply is not connected to the board except the ground wire. This is a battery holder with switch already on it. All PWM pin's are in use for servos.
9 volt battery going to the Vin pin. I will incorporate a switch.
Fan with positive and negative only. Positive goes to the 9 volt battery. Ground goes to ground pin on Arduino.
Bluetooth module with VCC going to 3.3v pin. Ground to ground pin. TXD going to the RX pin. RXD going to TX pin.
For master Uno only. Distance sensor with Trig going to A5 pin and echo to A4 pin. Ground going to ground pin. VCC going to 5v pin.
2 led's in circuit with 220 ohm resistor. I will use pin 4 and 2. Ground goes to ground pin.

That is the setup. I am in college where soldering is banned. So I am including a fan, like you saw, to cool down the breadboard. Let me know if you think that will work. I could not find a good schematic online for this robot, so I made one. Please let me know if you have any questions. Anyways, please tell me if there are any flaws and thank you so much for your time and effort.
Edit 1:
@gilhad
I did not know about I2C, if that is easier than blue-tooth, then I will get that. Thanks for that input. This way I don't have to use 2 blue-tooth modules. Most of the robot is running in series, not parrel.
Also, I said 4 AA batteries and not 2. If I had 2 in series, then that is 3v only, so that is why I am going for 4 in series for a total of 6v, with amps being the same as with one battery. This will supply 7 Amps. I tested it with my multi-meter. The servo motors are going to need 1 amp of power at max. I have 7. I will probably be using 4 servos at one time. So that is 4 amps. It will run for about an hour. That is fine by me.  This 4 AA battery is not connected to the arduino. There are 2 power sources per arduino. The other one is a single 9v battery, that one is going directly to the arduino, the Vin pin to be clear. If it is going to reset, could I do something in the programming to account for that like a time delay that is short?
I do not want to mess with my breadboards, that is why I am using a fan to cool them. Will that work?
The power source will not be moving all the servos at once, sorry that I did not include that.
Edit 2:
@killer rabbit
I guess I did not want to get a mega because I have 3 Uno's already, but I see they're pretty cheap online. I will ponder this idea of yours. I looked at my schematic and determine this would eliminate the 2 blue-tooth modules, 1 power source, 1 fan, and 2 leds along with their resistor. I think it would also eliminate an extra switch. Programming would be easier to because I don't have to worry about blue-tooth communication. I had no idea what to do for that one. So maybe I will get a Arduino mega.
The reason I am not using RC battery is because they're kinda heavy and SG90 servos are kinda small. I was worried about torque.  Li-ion is not to heavy, but I was worried about power. The ones you gave me though, look like that might work. There is 2 problems though. First, I can't use 2 of these batteries in series because that is 7.4 volts when the servos I am using is at max 7.2 volts. I would have to reduce voltage somehow, I have no idea how to wire that into the circuit. Problem 2 is that if I wire is parrel, that is 6 amps, which is fine, but only 3.7 volts. The motors can run on that, but that is on the low end. Will torque be less?
About the third paragraph, there is limits on the amount of current an Arduino can take. I looked them up. It is about 2 amps for the Vin pin I think or that might be the DC jack, one of the two.
I am using 2 Arduino, so that is why the blue-tooth was necessary. However, if I go with the mega, it will eliminate both of them. I forgot to mention for the distance sensor, I am using ultra sonic one. That is my fault for not mentioning that.
The reason I need 12 servos is because I am using 4 servos at the base, one for each leg to control direction of leg for steering. Then I have 4 legs, each using 2 servo motors to make the leg kick out and in. So 4 + 2(4)=12.
Yes, I would be using, if 2 Arduino, wireless communications, that is why the blue-tooth module. About the schematics, the picture is too big, so that is why I can't upload it. So sorry about that. I did try, believe me.

There are multiple points where you should reconsider your plans:
First of all, do not use multiple Arduino Unos, it's just a pain in the arse to make them work synchronously, instead use (for example) a single Arduino Mega 2560 which has 14 PWM outputs and still cheap as dirt.
I'm not sure about the life length of the AA batteries, I might consider using Li-Po (something from an RC shop, or something) or Li-ion (18650 is very popular and cheap) batteries. The Arduinos can take basically anything from 9 to 6 volts (and 5 from the USB), so you have a bit of freedom there.
A bit of electrical stuff: High available current is not a problem for the Arduino, it takes as much as it needs, so as long as you are in the voltage range of the board, you won't have any problems. Less amperage however is a problem, so be sure your battery can provide enough current!
You probably won't need cooling, there are no devices in your spider that would require more than a heatsink, if at all. But soldering is very recommended, I urge you to reconsider about that.
The Bluetooth module becomes unnecessary by going with a single Arduino.
For distance sensor I recommend an ultrasound one, those are really (ridiculously) cheap and simple to use. (HC-SR04 is very popular for example and there are tons of tutorials for it)
LED's are okay, most people don't think about the resistors, but those are important!
A question: Why do you need 12 servos?
That's all I got in the first round, feel free to share more info and I'll try to help you with your planing. I highly recommend you to share the schematics with us so we can help you to improve it!
Edit: I almost forgot: do you intend to use some kind of connection to the spider, like Bluetooth or Wi-Fi?

As far as batteries go, I'd recommend at least 6 volts, so you can use the Arduino's barrel connector. You may use 2 serial Li-ion batteries and a buck converter, but I believe you'll do fine without it, your servos will handle the extra 0.2 volts.
About the current limits: Your Arduino can supply around maximum 500 mA from all it's pins, and 40mA from a single pin, BUT it won't be a problem, because you do not connect the servos' VCC (+) and GND (-) pins to the Arduino, instead you hook them up to the battery directly. You only connect the SIGNAL pins to your Arduino which draw less then 10 mA.
For the communication with the spider I'd recommend a Wi-Fi module and UDP, as the protocol for the communication.
G.

I commented to your answer at edit number 2.

Got it, I'll edit my answer accordingly.

I can't tell if you edited or not? If you edited, can you just add some like edit 1, so I know? Thanks.

I finished it now, you'll see a line in my answer.

I saw the edit. Let us assume I am going to use the Arduino mega for now. I ordered one as it was only $13 with free shipping. If I put the Li-ion batteries in series, it will have 3 amps, I might need 4 amps at a time though. This concerns me. What can I do about that part? I won't need communication anymore because of the using Mega. Power is still a concern. In series, 3 amp is low, minimum of about 4 amp at a time will be used. In parrel, will 3.7 Volt decrease torque because it is on the low end for voltage supplied to the servo? I think I am close to a finish design now.

By the way, these are the batteries if I use Li-ion.                                                                                https://www.amazon.com/gp/product/B0129F9BXK/ref=ox_sc_sfl_title_1?ie=UTF8&psc=1&smid=A3P4UZIS42PRQV

I got an idea, since I don't want to lose torque or speed. I will get the 4 li-ion batteries. I will wire 2 in parrel and then add 1 more battery but put that battery is series with the 2 in parrel. That will give me 6 amps at 7.4 Volts. You said the extra .2 won't be bad. They are the same, so won't be mixing anything. What do you think?

3 batteries NOT OK! 4 batteries, 2 in paralel, then 2 in serial is OK http://lh6.ggpht.com/_hYIZmJ5Igu4/StP-AYEZBqI/AAAAAAAAAVY/YGNFsNjOG9U/2s2p-2p2s.jpg

Well power is still an issue then. So if 2 in paralel, that is 6 amps, then 2 in series for 7.4 volts. Then do I connect these 2 packs in paralel? Cause in series, it is to much voltage. But in parrel, it would be overkill amps, but it draws from it, so no such thing as to much amps in this circuit. So is this set up correct?

Also, what about the breadboard? I know you said it won't be a problem, but it takes max of 1 amp when we are dealing with a lot more. I can't solder cause it is banned. So will adding a fan to cool just the breadboard work?

I believe you will do fine with the 7,4 volt 2 paralel 2 series pack.

The breadboard won't be a problem, because transferring current does not generate much heat. Your servos and battery might become a bit warm, but I don't expect high temperatures.

Ok, thank you. I think I know what to do now.

For connecting 2 Arduinos use some wires - I2C works good for me, but Serial is also good. Anyway you probabely will came to problem with interrupts and many tasks running in paralel, or the spider be slow - you choose not so easy target (but reacheble).
As for bateries - Arduino need constant power, than it takes as much current as it needs (if it is aviable), so no problem in 2 AA for Arduino.
You would need a lot of servos - they are, what takes energy - even if 2AA can give a lot for short time, this will not last long. Also giving high current means voltage drops (as for cable and mainly internal batery resistence), so if you feed arduino from the same source, it can reset every time, when too much servos try to move/stang agains gravity.
Different source for Arduino is good idea, as the CPU will last longer, then those actuators and could shutdown properly (not let move just one leg or so). Also the electrical interference from servos would be much less this way. (There are other ways, more complicated to do that).
Breadbourd can be stripped the bottom plastic and have it exchange for more thinner double-size tape, then be put on large alluminium (or other heat-conducting) plate for better cooling too.
Arduino cannot move all those servos from its source, think about alimitation currrent per pin and per arduino itself - you may need some other IC/transistors to power it properly on each servo and the servo power should go direct from bateries, not via Arduino. Connect just grounds.

I commented at your answer at edit number 1.


text:
Arduino Nano not visible in Serial Ports (Mac OS)
I have used by Arduino countless times over the past few years and only after installing an update to Mac OS Sierra did the device stop showing up under the Serial Ports. Now only tty-bluetooth shows up no others. I have looked a countless threads where people suggest installing drivers or uninstalling drivers or rebooting. I have tried everything but still no device shows up.
I switched to my Windows partition using Bootcamp and lo and behold it works perfectly there but not in Mac OS. I would still like to use Mac OS to programme my Arduino. If anyone has any suggestions I would be very grateful!

You've already done exactly the right thing to isolate the problem - trying a different operating system on the same hardware, and the result is that this is a Mac question, not an Arduino one. (My standard advice when people have Mac problems is to remind them that "it just works", but strangely this doesn't often help.)

@MarkSmith Hahaha yes it is unfortunate that in this situation 'it just works' until it doesn't.

Thank you @Adrian Mihalko for the detailed solution. I am running on Sierra latest release, i tried all the options you mentioned in the order. But, the serial port doesn't still show up on my Arduino IDE when I connect my Wemos D1 mini chip (which uses CH340G chipset). Please help!

Im trying to make that machine works and my Macbook pro 2016 with osx high sierra
does see the usb serial but not UGP https://www.amazon.com/MYSWEETY-Control-Engraving-16x10x4-5cm-110V-240V/dp/B01NBVXO0V/ref=sr_1_4?ie=UTF8&qid=1512003731&sr=8-4&keywords=cnc

Is it an original Nano or a clone?
The original Nano uses FTDI's FT232 ship, whereas clones use the CG340 USB-to-TTL chip. The former works fine straight away Mac OS Sierra, whereas the latter needs a driver.
The CG340 driver doesn't work under Mac OS Sierra. Fortunately, someone patched the driver and made it available at GitHub. There you'll also find some troubleshooting instructions that can help (hopefully).
From Adrian Mihalko's repository at GitHub:

ch340g-ch34g-ch34x-mac-os-x-driver
Latest macOS Sierra-compatible driver for devices using the CH340G, CH34G or CH34X chipset. This chipset is used in several Arduino-clones.
Introduction
Version 1.3 (2016-09-27) of the OEM driver for the CH34x chipset currently causes a kernel panic (a.k.a. crash) when installed on macOS Sierra. To resolve this issue, please download and install the driver in this repo.
Installation

Remove the old driver by issuing one of the following commands (depending on your installation):

sudo rm -rf /System/Library/Extensions/usb.kext
sudo rm -rf /Library/Extensions/usbserial.kext

Restart your Mac.
Double-click on the CH34x_Install_V1.3.pkg file.
Restart your Mac.
Plug in your device. It should now be listed under the /dev directory. Examples:

/dev/cu.wchusbserial1410
/dev/cu.wchusbserial1420

Troubleshooting
If, and only if, the device is not recognized after the installation (or you cannot install the driver), please disable System Integrity Protection:

Reboot your Mac into Recovery Mode by restarting your computer and holding down Command+R until the Apple logo appears on screen.
Open the Terminal (Applications > Utilities > Terminal).
In the Terminal window, type in csrutil enable --without kext (or to fully disable: csrutil disable) and press Enter.
Restart your Mac.

Please share this page!
Regards,
Adrian Mihalko

Thank you for your help. It is an original Arduino Nano not a clone as far as I know.

Where did you bought it? Was it packaged inside a box, as original Arduino products are? Did you have to install any driver when you used it for the first time?

I'm also using Mas OS Sierra and an Arduino Pro Mini (from Sparkfun) with a breakout USB-to-UART board that uses an FTDI FT232 chip. I'm using the default Apple FTDI drivers (the ones that are bundled with Sierra) and I'm having no problems whatsoever. Some people have reported problems using the manufacturer drivers after upgrading to Sierra. Some of them solved it by uninstalling the conflicting drivers and  relying on the default Apple FTDI drivers instead. It's worth a try.

This works for me. I had Clone Nano. Thanks brah.


text:
Can I port a project built on Arduino Uno to a standalone ATmega328 using the exact same code?
I'm building an IoT power usage monitor in which the data is logged using a RTC and an SD card module and a web app hosted on an ESP8266 gives access to this data. My question is can I use the exact same code (with libraries like "ESP8266.h") on a standalone ATmega programmed using Arduino as ISP?

Yes you can.  There shouldn't be any difference.

most code should run the same. try it and work through the compiler errors.

Almost all of my projects are roll-your-own-duinos with Atmega 328p chips, with code generated for an "Arduino/Genuino Uno" board. Many of them use an ESP8266-01 board as a WiFi interface. I either run the entire board at 3.3v or use a daughter-board that interfaces the ESP to a 5v environment.
If you're porting code from an actual Arduino Uno, there is nothing to do except to make sure your pinouts are the same between the Arduino and the RYO-duino. Otherwise, make all your pin definitions constants and group them together in such a way (e.g. with #ifdef / #else / #endif) that you can easily enable one or the other group just before you compile.
Update:

There's a bit more required, for example, the clock rate needs to
  match or the timing will be off ...

I did gloss over the power & clock since the question hadn't asked about departures from the Uno's design. But yes, a RYO will need a compatible power supply and a matching clock rate, to be able to assume an arbitrary sketch could be run on it successfully. To make the RYO look like an UNO, it will need 5v power and a 16 MHz crystal, just as the Uno design provides.
If a RYO is designed be other than like an Uno, considering power source, clock rate, fuse options, DIP instead of an SMT, then there is nothing to support the supposition that a port from an Uno could succeed without modifying the code for those differences.

There's a bit more required, for example, the clock rate needs to match or the timing will be off, and the clock source and supply voltage need to match or the fuses may make the system unbootable or unstable.

You can run any code on an ATMEGA328P that you can run on an Arduino Uno. For maximum compatibility, you would configure the ATMEGA328P with a 16Mhz crystal/resonator.
There are instructions for using an Arduino Uno as an ISP for programming other devices, many of which require a Uno with a DIP version of the ATMEGA chip which can be removed.
What you cannot do is directly run code for an ESP8266 on an ATMEGA328P.

fun fact: shorting reset to ground does the same thing as removing the DIP...

An Arduino with the processor removed or held in reset is not likely to be helpful for ISP operations, rather it could be borrowed as a serial interface for bootloader or test ones.  BEWARE that an ATmega with its reset grounded is susceptible to corruption (loosing the bootloader, etc) if it sees ISP-like traffic on the SPI pins.

Yes, it might work. But as a minimum you should check that the following is mapped between the two in a compatible way:

Pinout and configuration of pins. ESP8266 allows INPUT_PULLDOWN in some pins, whereas ATmega328 doesn't.
Use of timers and interrupts. ESP8266 accepts "true" interrupts on all I/O pins, whereas ATmega328 only accepts them in 2 pins (although you can use Pin Change Interrupts (PCIx), which are far less powerful than "true" External Interrupts (INTx)). Also, ESP8266 accepts HIGH level interrupts, whereas ATmega328 doesn't (even on INT-capable pins).
Use of specific ESP8266 libraries which won't work at all on an ATmega328

The Arduino library ports for ESP8266 may work as expected out of the box, it may require minor tweaks, or it may require a major revamp of key code fragments. It's difficult to say without seeing the code.

he's not switching to an ESP, he's switching to a bare chip and still wants to connect the ESP as a module. (not sure why; the ESP is faster, cheaper, etc...)


text:
How to use to two different programs into one stkech
I am currently using relay module, but I am facing a problem that, when Arduino pins are LOW then all relay are going HIGH, so I want to use this code so that when arduino starts all pins are getting HIGH, and also can be control with char data/switch(data)/case break;/,
Here is my code:

setup() {
  if(conditionIsTrue) {
    aGroup::setup();
  } else {
    bGroup::setup();
  }
}

loop() {
  if(conditionIsTrue) {
    aGroup::loop();
  } else {
    bGroup::loop();
  }
}

namespace aGroup {
setup() {

    pinMode(ledPinA, OUTPUT);
    pinMode(ledPinB, OUTPUT);
    pinMode(ledPinC, OUTPUT);
    pinMode(ledPinD, OUTPUT);
    pinMode(ledPinE, OUTPUT);
    pinMode(ledPinF, OUTPUT);
    pinMode(ledPinG, OUTPUT);
    pinMode(ledPinH, OUTPUT);
    pinMode(ledPinI, OUTPUT);
    pinMode(ledPinJ, OUTPUT);
    pinMode(ledPinK, OUTPUT);
    pinMode(ledPinL, OUTPUT);

}

loop() {

  digitalWrite(ledPinA, HIGH);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinE, HIGH);
  digitalWrite(ledPinF, HIGH);
  digitalWrite(ledPinG, HIGH);
  digitalWrite(ledPinH, HIGH);
  digitalWrite(ledPinI, HIGH);
  digitalWrite(ledPinJ, HIGH);
  digitalWrite(ledPinK, HIGH);
  digitalWrite(ledPinL, HIGH);

}
}

namespace bGroup {
setup() {
  Serial.begin(9600);
    pinMode(ledPinA, OUTPUT);
    pinMode(ledPinB, OUTPUT);
    pinMode(ledPinC, OUTPUT);
    pinMode(ledPinD, OUTPUT);
    pinMode(ledPinE, OUTPUT);
    pinMode(ledPinF, OUTPUT);
    pinMode(ledPinG, OUTPUT);
    pinMode(ledPinH, OUTPUT);
    pinMode(ledPinI, OUTPUT);
    pinMode(ledPinJ, OUTPUT);
    pinMode(ledPinK, OUTPUT);
    pinMode(ledPinL, OUTPUT);

}

loop() {

  char data = Serial.read();
    switch(data)
    {
        case 'A': digitalWrite(ledPinA, HIGH);break;
        case 'B': digitalWrite(ledPinA, LOW);break;

        case 'C': digitalWrite(ledPinB, HIGH);break;
        case 'D': digitalWrite(ledPinB, LOW);break;

        case 'E': digitalWrite(ledPinC, HIGH);break;
        case 'F': digitalWrite(ledPinC, LOW);break;

        case 'G': digitalWrite(ledPinD, HIGH);break;
        case 'H': digitalWrite(ledPinD, LOW);break;

        case 'I': digitalWrite(ledPinE, HIGH);break;
        case 'J': digitalWrite(ledPinE, LOW);break;

        case 'K': digitalWrite(ledPinF, HIGH);break;
        case 'L': digitalWrite(ledPinF, LOW);break;

        case 'M': digitalWrite(ledPinG, HIGH);break;
        case 'N': digitalWrite(ledPinG, LOW);break;

        case 'O': digitalWrite(ledPinH, HIGH);break;
        case 'P': digitalWrite(ledPinH, LOW);break;

        case 'Q': digitalWrite(ledPinI, HIGH);break;
        case 'R': digitalWrite(ledPinI, LOW);break;

        case 'S': digitalWrite(ledPinJ, HIGH);break;
        case 'T': digitalWrite(ledPinJ, LOW);break;

        case 'U': digitalWrite(ledPinK, HIGH);break;
        case 'V': digitalWrite(ledPinK, LOW);break;

        case 'W': digitalWrite(ledPinL, HIGH);break;
        case 'X': digitalWrite(ledPinL, LOW);break;

    }

}
}

But this isn't work, Please help me.

The title seems to bear absolutely no relation to the question. Could you edit one or the other so that they match, please?

In first place, you have to declare the functions setup and loop as void setup() and void loop().
If you want your output pins to be high when Arduino starts then you should do that in your setup function, instead of doing it in the loop:
void setup() {

  Serial.begin(9600);

  // Step 1: configure pins as outputs
  pinMode(ledPinA, OUTPUT);
  pinMode(ledPinB, OUTPUT);
  pinMode(ledPinC, OUTPUT);
  pinMode(ledPinD, OUTPUT);
  pinMode(ledPinE, OUTPUT);
  pinMode(ledPinF, OUTPUT);
  pinMode(ledPinG, OUTPUT);
  pinMode(ledPinH, OUTPUT);
  pinMode(ledPinI, OUTPUT);
  pinMode(ledPinJ, OUTPUT);
  pinMode(ledPinK, OUTPUT);
  pinMode(ledPinL, OUTPUT);

  // Step 2: initialize pins to output HIGH
  digitalWrite(ledPinA, HIGH);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinE, HIGH);
  digitalWrite(ledPinF, HIGH);
  digitalWrite(ledPinG, HIGH);
  digitalWrite(ledPinH, HIGH);
  digitalWrite(ledPinI, HIGH);
  digitalWrite(ledPinJ, HIGH);
  digitalWrite(ledPinK, HIGH);
  digitalWrite(ledPinL, HIGH);
}

Also, you can't declare a variable and assign to it the value of a function other than an object constructor. Furthermore, you should check if there's data available before trying to read it. So you have replace the following sentence:
char data = Serial.read();

With something like this:
char data = 0;
if (Serial.available() > 0) {
    data = Serial.read();
    // do your stuff
}

This should do the trick.
Last but not least: I don't know why you're using two namespaces. The aGroup looks useless to me. On top of that, I fail to see where in your code do you declare, initialise and update the conditionIsTrue variable. The same goes for all those ledPinX variables. Is there more code that you're not showing here? Is your code failing at runtime, or doesn't even compile?

YES SIR, it is working very good........ Thanks a lot.......


text:
Motor shields in arduino
what is a servo motor shield in arduino? what is the key purpose for using it? I'm newbie in arduino and I've seen some briefings in websites which I couldn't understand, can somebody elaborate it to me?

Servos require power and PWM. Servo shields come in two main forms:

Simple distribution
Active control

The first kind just provides convenient 3-pin headers to the Ardino's PWM pins, and sometimes a dedicated power supply for powering the servos. They're simple and cheap, but can only provide as many servo ports as the Arduino has PWM pins.
The second kind, more expensive, has a PWM chip on it to provide many more PWM pins than the Arduino can natively provide. Again there is sometimes a power supply as well, along with the convenient 3-pin headers. You usually interface with this kind using either I2C or SPI.  These are the ones people usually mean when they talk about a servo shield - a shield designed for powering and controlling many more servos than an Arduino by itself can manage.
Servo Motor Shields should not be confused with Motor Shields, which provide a number of H-Bridge drivers for powering and controlling (both the speed and direction) of a brushed DC motor.

The dumb ones are basically distributors of power for the servo motors.
There are more clever boards that offer the control of multiple servos (usually 10+) by communicating with the Arduino via some higher-than-PWM-level control (Like I2C) thus taking less pins from the Arduino than a dumb servo shield.
Both kinds usually require a power supply to power the servos.
G.

He said "servo motor shield", not a DC motor driving shield. Very different thing.

do you mean that using motor shields provides external power to servo?

@Majenko How does my answer suggest I am talking about a DC motor shield? Would you please elaborate?

"So, you need something that takes the signal from these pins and translate them into high current controls." - that is what a DC motor shield does. It's not what a servo motor shield does. You have perfectly described a H-bridge shield.

@Dharanendiran Almost. A motor shield provides power to the servo/stepper motor but that power has to tome from somewhere, so to make a motor shield work you'll need a power supply to power the shield itself and you may need another power supply to power your Arduino.

@Majenko It is what ALL motor shields do, that's why you need them: to be able to handle high currents. (higher than what the Arduino pins can handle) What you hook up to the other end of the shield is not specified in that sentence, it can be a stepper motor or a servo motor or a DC motor.

@KillerRabbitofCaerbannog Do you actually know how a servo motor works, and what signals it requires?

Yes I do, and let me Google it: http://www.jameco.com/jameco/workshop/howitworks/how-servo-motors-work.html
Sorry, sent it a bit early, I'll elaborate

Ok, so if you know how a servo motor works - tell me: what signal(s) would you possibly want to amplify using a H-bridge?

I see why you think I was talking about DC motors. Most servos contain their electronics, so you only need high current DC supply for them and a signal with PWM. A servo shield gives it power and takes the incoming signal and sends it to the motor. (or even buffers it but that's another topic) I made a mistake with the amplifying thing as I did not state explicitly that you only amplify (or more like translate) signals with stepper motors.

You need a motor shield for stepper or DC motors. Not for servo motors. You can directly drive as many servo motors direct from an Arduino as there are PWM pins (and more if you implement software PWM). There is no need for any amplification or buffering unless you are using long runs of cable and need the extra current to get the signal there cleanly. Your answer doesn't mention a single thing that is relevant to servo motors, and the OP didn't ask about DC or stepper motors.

@Majenko You can directly CONTROL as many servo motors direct from an Arduino as there are PWM pins. You still need some kind of power distribution to the servos, and that's what a "servo motor shield" does. Also, as you said, you don't need a motor shield for servo motors. Then the author was maybe talking about "servo motor control". Or he/she did talk about "motor shield". I elaborated the latter extending it to stepper motors. I am sorry if my answer was ambiguous and hope that the author wanted to know about steppers too.

That is what one kind of servo motor shield does. Those are cheap and rare (and often just a part of another bigger shield). The most common kind of servo motor shield also contain a PWM chip (like I linked to in my answer) for generating more PWM signals than the Arduino can create. THAT is what a servo motor shield is for. The power distribution is just a bonus. It's just as easy to use wires to distribute the power.

You should remove all references to H-bridges, amplifying of signals, DC motor / stepper motor driving, etc from your answer as they are nothing to do with the question and are just plain misleading.

@Majenko "and often just a part of another bigger shield" And that's why I wandered into stepper territory. Most motor shields provide stepper, DC and servo control which makes it appropriate to talk about all of these motors hence the "amplifying" stuff in my answer. My error was not stating that, I'll correct my answer later today.

SOME DC motor shields also provide handy servo pins since you often want to use servos and DC motors together (drive & steering). However, a servo motor shield (which is what the OP asked about) NEVER has DC motor driving capability.

I understand how you find my answer misleading and I'll rewrite it to make sure it is not anymore.


text:
Issues using HC-06 Bluetooth module with arduino
I recently ordered an HC-06 Bluetooth module for my Arduino Uno, and after watching this video, and many others, I still have been having many issues figuring out how to get it to work, and some questions for how the code receives and reads serial data from my phone.

I assume this wiring is correct, right?

Rx  > Tx
Tx  > Rx
Gnd > Gnd
Vcc > 3.3V

When I sent a command over the Bluetooth terminal app I have, the serial monitor displays that command over and over, I assume that is correct also?
How do I read the serial input? I've been using
if(Serial.available() > 0)
        phoneInput = (char) Serial.read();

and then displaying the value of phoneInput to the serial monitor, but for some reason I can't seem to have it control anything properly (in this case an LED)
What datatype is the Serial.read() returning to my variable before I cast char on to it?
I get errors uploading the code to the board (avrdude: stk500_recv(): programmer is not responding), until I remove the pin connected to the Rx on the arduino, is there a cleaner solution to uploading the board without unplugging wires?

I had follow this tutorial and problem fixed: Tutorial Configure HC-06 Bluetooth Module using AT Command

I assume this wiring is correct, right?
Rx > Tx
Tx > Rx
Gnd > Gnd
Vcc > 3.3V

Almost. The Arduino's TX should be reduced to 3.3V using a 10k/20k potential divider.

How do I read the serial input? I've been using
if(Serial.available() > 0)
       phoneInput = (char) Serial.read();

You should read and digest this.

What datatype is the Serial.read() returning to my variable before I cast char on to it?

An integer. It holds either 0-255 representing the ASCII code for a character, or -1 if there is nothing in the buffer to read.

I get errors uploading the code to the board (avrdude: stk500_recv(): programmer is not responding), until I remove the pin connected to the Rx on the arduino, is there a cleaner solution to uploading the board without unplugging wires?

That will be because you are using pins 0/1 to communicate with the bluetooth which you can't do because those are used to communicate with the PC.

I'm away from my computer so I can't test your answers, but thanks so much, your answers were super helpful, but I do have one question; If I shouldn't use pins 0 and 1 as Rx and Tx, what pins should I use?

Anything else - I assume you're using SoftwareSerial - that library is designed to use any pin except 0/1. You use Serial for pins 0/1. There seems to be a number of tutorials (videos?) around that show SoftwareSerial being incorrectly used with pins 0/1.


text:
Unable to program Arduino mega2560?
I am using arduino mega for my application .  Board works well for a week , from yesterday it  is not programming at all , it shows me some error like timeout . What could be the problem kindly  help me to solve this.
avrdude: Version 6.3, compiled on Dec 16 2016 at 13:33:19
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM20
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
avrdude: ser_open(): can't open device "\\.\COM20": The system cannot find the file specified.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
avrdude: ser_drain(): read error: The handle is invalid.

avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

avrdude done.  Thank you.

avrdude: ser_open(): can't open device "\\.\COM20": The system cannot find the file specified. -- There's a hint right there...

Com 20 is not configured with your arduino. Go to the arduino program and I think it is on the tools tab or the one next to it. There should be a port label and it says which com port to use. Then go to device manager, then ports. Then go to properties on the port that has arduino and change that to the port the arduino program said. It should work then. This topic has been solved many times.

ya its working fine now...

I am glad to hear that.

But this problem occurs very often why?.... Now also i am getting this error what could be the problem...


text:
Did I fry my DUE by powering it from a external source and USB at the same time? If so, why?
I guess I just fried my second DUE in a week. The first I didn't really see what happened, but I couldn't upload any sketches, even if the computer could recognize it, and the SAM would get really hot.
Now, I had it powered by a 12V External supply, through a regulator bringing it down to 9V, and in the exact moment I plugged the USB, with power still on, I got a lot of smoke, smelling of fried electronics :p. Afterwards, I have the same symptoms as I had in the other boards: Green and orange LEDs on, chip very hot, computer recognizing it as a Arduino DUE but not being able to upload any sketches.
What just happened?

"I got a lot of smoke" -- Yes, it's dead.

Step 1: check the voltages on VIN, 5V and 3.3V pins.

Maybe ground loop - the voltage difference between USB ground and power source ground?

You're doing it wrong. You should have burnt an UNO before this DUE. Now, at least wait for the TRE to be release before smoking anything else. It's good to be in synchrony.

I did check the pins, and I've got 3.3 V on the 5V one, and 2.7V on the 3.3V. Can't remember the other one, but I guess all hope is gone anyway, after the amount of smoke...

If it was the same sketch involved in the destruction of both it may be a good idea to check to make sure the sketch that is involved as well to make sure there are no logical shorts to ground or other pins. Rugged-Circuits has a list of some common ways the Arduino can get shorted. It is showing the Uno but I am sure all similar rules apply with the exception of total power requirements and other differences between the boards.

As Majenko said you should check these voltages.
Arduino DUE uses the LM2734Y DC/DC converter and according to datasheet it works up to 20V so there is no need to use your 9V regulator.
Also on DUE there is comparator which should turns off a USB power supply when external power supply is used. Look for 2 transistors on board (FDN340P) called T1 and T2. There both are turning on/off power from USB source. Also check them. There can be also problem with all components around USB power. For more info check Arduino schematic.


text:
Xbee can send from arduino to XCTU, but not the other way around
I have two arduinos that I would like to use to communicate with two xbees. I programmed both xbees with the xbee explorer breakout boards in XCTU, and got them to communicate on XCTU. They are XB24Cs, with the Zigbee function set, both on the same PAN ID, one as a Coordinator and one as a router, not on API mode. When I put the router on an xbee shield on an arduino, I run a program on the arduino that should allow me to communcate both ways, However I can send something through the serial and have it show up on the XCTU, but anything typed in XCTU will not show up in arduino. The arduino shield is the sainsmart xbee pro shield, and I tried it both with the jumpers in USB and XBee mode, however I can only ever upload first when it is on USB mode. How can I make communication possible from the computer to the arduino?
Here is my arduino code:
#include <SoftwareSerial.h>
SoftwareSerial Xbee(2,3);

void setup() {
  Xbee.begin(9600);
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
 Serial.println("test");
 delay(1000);
  if(Xbee.available()){
    Serial.println(Xbee.read());
  }
  if(Serial.available()){
    Xbee.write(Serial.read());
  }
}


text:
Why won't this code work on an Arduino Mega 2560 (It works on an Arduino Uno)?
The code below was taken online and was written for the Arduino Uno. I know C++ however I am a beginner with Arduino so I don't understand this compatibility issue or how to fix it. I am very thankful for any help. Here is part of the code - the variable declarations: (I can upload the entire code if that would be more helpful).
ISR(PCINT0_vect) {
  current_time = micros();
  //Channel 1=========================================
  if(PINB & B00000001) { //Is input 8 high?
    if(last_channel_1 == 0) { //Input 8 changed from 0 to 1.
      last_channel_1 = 1; //Remember current input state.
      timer_1 = current_time; //Set timer_1 to current_time.
    }
  } else if(last_channel_1 == 1) { //Input 8 is not high and changed from 1 to 0.
    last_channel_1 = 0; //Remember current input state.
    receiver_input[1] = current_time - timer_1; //Channel 1 is current_time - timer_1.
  }
  //Channel 2=========================================
  if(PINB & B00000010 ) { //Is input 9 high?
    if(last_channel_2 == 0) { //Input 9 changed from 0 to 1.
      last_channel_2 = 1; //Remember current input state.
      timer_2 = current_time; //Set timer_2 to current_time.
    }
  } else if(last_channel_2 == 1) { //Input 9 is not high and changed from 1 to 0.
    last_channel_2 = 0; //Remember current input state.
    receiver_input[2] = current_time - timer_2; //Channel 2 is current_time - timer_2.
  }
  //Channel 3=========================================
  if(PINB & B00000100 ) { //Is input 10 high?
    if(last_channel_3 == 0) { //Input 10 changed from 0 to 1.
      last_channel_3 = 1; //Remember current input state.
      timer_3 = current_time; //Set timer_3 to current_time.
    }
  } else if(last_channel_3 == 1) { //Input 10 is not high and changed from 1 to 0.
    last_channel_3 = 0; //Remember current input state.
    receiver_input[3] = current_time - timer_3; //Channel 3 is current_time - timer_3.
  }
  //Channel 4=========================================
  if(PINB & B00001000 ) { //Is input 11 high?
    if(last_channel_4 == 0) { //Input 11 changed from 0 to 1.
      last_channel_4 = 1; //Remember current input state.
      timer_4 = current_time; //Set timer_4 to current_time.
    }
  } else if(last_channel_4 == 1) { //Input 11 is not high and changed from 1 to 0.
    last_channel_4 = 0; //Remember current input state.
    receiver_input[4] = current_time - timer_4; //Channel 4 is current_time - timer_4.
  }
}

void set_gyro_registers() {
  //Set up the MPU-6050
  if(eeprom_data[31] == 1) {
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
    Wire.write(0x6B); //We want to write to the PWR_MGMT_1 register (6B hex)
    Wire.write(0x00); //Set the register bits as 00000000 to activate the gyro
    Wire.endTransmission(); //End the transmission with the gyro.
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
    Wire.write(0x1B); //We want to write to the GYRO_CONFIG register (1B hex)
    Wire.write(0x08); //Set the register bits as 00001000 (500dps full scale)
    Wire.endTransmission(); //End the transmission with the gyro
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
    Wire.write(0x1C); //We want to write to the ACCEL_CONFIG register (1A hex)
    Wire.write(0x10); //Set the register bits as 00010000 (+/- 8g full scale range)
    Wire.endTransmission(); //End the transmission with the gyro
    //Let's perform a random register check to see if the values are written correct
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search
    Wire.write(0x1B); //Start reading @ register 0x1B
    Wire.endTransmission(); //End the transmission
    Wire.requestFrom(gyro_address, 1); //Request 1 bytes from the gyro
    while(Wire.available() < 1); //Wait until the 6 bytes are received
    if(Wire.read() != 0x08) { //Check if the value is 0x08
      digitalWrite(12,HIGH); //Turn on the warning led
      while(1)delay(10); //Stay in this loop for ever
    }
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search
    Wire.write(0x1A); //We want to write to the CONFIG register (1A hex)
    Wire.write(0x03); //Set the register bits as 00000011 (Set Digital Low Pass Filter to ~43Hz)
    Wire.endTransmission(); //End the transmission with the gyro
  }

Please edit your question and define "doesn't work".  I'm sure the code runs just fine on a Mega. Of course, port B maps to different pins on a Mega than an Uno, ie to digital pins 53, 52, 51... instead of to 12, 13, 14... so it won't do at all the same things on the Mega as the Uno. ¶ In general, include a Minimal, Complete, and Verifiable example of code, not just snippets.  Or provide a link to the online code you referred to.

Thank you, this is my first time posting. Here is a link to the code.

https://drive.google.com/file/d/0B5tJTKkHim16VDFhdHhNUDVOcTA/view?usp=sharing

When I upload to the Arduino Mega, it seems like the code just doesn't run, I'm not entirely sure what the issue is. Here is a link to the code that must be run before the above link's code can be uploaded and run.

https://drive.google.com/file/d/0B5tJTKkHim16NFZUenB6elZEbDA/view?usp=sharing

Break the problem down. Put some serial prints in there, see how far it's getting. If it's really just not running at all, make sure a trivial sketch runs on that device, then find how much you need to strip out of your code to make it basically run. Essentially, as @jwpat7 suggests, create a minimal, complete, verifiable example.

As no preview is available at the given links (for YMFC-AL_setup.ino and YMFC-AL_Flight_controller.ino at drive.google.com) and I don't want to download the code to my system, I haven't looked at the whole program; however, from the code included in the question, it's clear that it uses direct IO rather than Arduino API IO.
Direct IO expressions like PINB & B00000001 [see Edit 1, Note 1] affect differently-numbered digital pins on the Mega than on the Uno or Nano.  (Or, more generally, on boards based on ATmega256x vs ATmega328x or 168x vs ATmega32U4 or 16U4.)
On the Arduino Nano and Uno, PB0–PB5 are assigned to Arduino digital pins 8–13.
On the Arduino Micro with 32U4, PB0–PB3 are not assigned to Arduino digital pins; they connect to SS, SCK, MOSI, MISO, while PB4–PB7 are assigned to Arduino digital pins 8–11.
On the Arduino Mega2560 with  ATmega2560,  PB0–PB3 are assigned to Arduino digital pins 53, 52, 51, 50 respectively, and PB4–PB7 are assigned to 10–13.
Summary:  To adapt direct IO code written for an Uno to a Mega, you may need to change ports and pins numbers.  Just moving wires around to corresponding pins may or may not fix problems; if the code uses a mix of direct IO and API IO (with digitalWrite() etc.) the code may need to be changed as well.  For example, in setup() it might use API pin identifiers, and in ISRs might use direct IO, an approach that will malfunction when transferring code to a differently-mapped board.
Note, see numerous excellent pinout diagrams at pighixxx.com.
Edit 1:
Note 1:  In a file called binary.h, the Arduino IDE's programming environment defines a set of 510 constants whose names consist of a B followed by from 1 to 8 zeroes and ones, with values equal to corresponding binary numbers.  The value of the expression PINB & B00000001 is equal to the low-order bit (PB0) of input register PINB.    The value of PINB & B00001000 is 8 (ie, 1<<3) if PB3 is high, and is 0 if PB3 is low.  Typically, these binary constants are used as bit masks for bit operations (AND &, OR |, XOR ^).
Note 2:  When including code in a stackexchange question or answer, first paste the code into the question or answer editing box; then in that editing box, highlight the code and press ctrl-k.  (Alternately, highlight the code and click the {} icon in the toolbar at the top of the editing box.)
Rather large sections of code can be pasted into questions and answers.  Generally, paste in at least enough to be compilable and exhibit the problem.  If any variable or procedure definitions, #include lines, etc., are left out, people may have to play guessing games to answer the question, and that's generally undesirable as it wastes time and does not elicit good answers.

Thank you for your response, I will look at the Pinout diagrams for both micro controllers. I apologize for the lack of a preview and understand why you wouldn't want to download the file, how would I show a preview for future reference? Also what are the numbers such as B00000100, are they addresses?

@ColinMurphy, see edit 1

The sketch uses I2C to communicate with the Gyro / Accelerometer. On a Uno these pins are A4 (SDA) and A5 (SCL). On a Mega these pins are 20 (SDA) and 21 (SCL).


text:
Call function and not came back
Im having a little problem with my code. here i called a function to make a test, if it passed it goes back and continue if it doesn't it goes to main loop.
void loop()
{

    if (call == 1)
    {
        funca();
    }
    print("waiting..");
}
 void funca()
    {
        gsmtest();
        print("calling..")
    }
 void gsmtest()
    {
        if (test==1)
             {
            print("test ok");
             }
        else
              {
                print("error");
                loop();
              }
    }

here is a simple example, if u press call, the code goes to funca which make a call to gsmtest. if test goes ok it print "calling.." if not it print "error" and goes back to loop. for some reasons here if test failed, it print error and than goes to loop after that it print "calling.." (continuing funca which i want to abort it if test goes wrong) .

You're overflowing your stack due to infinite recursion.
By explicitly calling loop() you are breaking the whole call stack system. You effectively have:
loop() ->
  funca() ->
    gsmtest() ->
      loop() ->
        funca() ->
          gsmtest() ->
            etc...

Instead of>
loop() ->
    funca() ->
        gsmtest()
    <-
<-

Instead of calling loop() you should use return; to "return" back to where the function was called from.
For example:
void loop() {
    if (call == 1) {
        funca();
    }
    print("waiting..");
}

void funca() {
    if (!gsmtest()) return;
    print("calling..")
}

bool gsmtest() {
    if (test == 1) {
        print("test ok");
    } else {
        print("error");
        return false;
    }
    return true;
}

but in that case if gsmtest is error it will continue to the next instruction (it will print "calling.." while it doesn't suppose to).

So you have it returning a value that says "this failed" then test for that in the calling function, then return from that too.

yes its my back up plan, but i'm looking for better way, without using variables.

You won't find a better way. This is how it is done. And you don't need variables.  Let me craft an example for you.


text:
Why is D3 not activating?
So I made this circuit + a momentary push button on D2 and GND:
Because I don't use a real arduino, I use the RAW port to act like the +5V port. It all worked with a single LED without the npn transistor. Now, with the transistor, the strip of LED's doesn't turn off anymore when I hit the button. The code:
 #include <SoftwareSerial.h>

  #include <Keyboard.h>

  boolean toggle = false;
  int inPin = 2;
  int outPin = 3;

  int state = HIGH;
  int ledOn;
  int reading;
  int previous = LOW;

  long time = 0;
  long debounce = 200;

  void setup() {
    // make pin 2 an input and turn on the
    // pullup resistor so it goes high unless
    // connected to ground:
    pinMode(inPin, INPUT_PULLUP);
    pinMode(outPin, OUTPUT);
    Keyboard.begin();
  }

  void loop()
  {
    reading = digitalRead(inPin);
    ledOn = digitalRead(outPin);

    // if the input just went from LOW and HIGH and we've waited long enough
    // to ignore any noise on the circuit, toggle the output pin and remember
    // the time
    if ((reading == LOW) and (ledOn == LOW)) {
      state = HIGH;
      Keyboard.press((char) 128);
      Keyboard.press('r');
      delay(50);
      Keyboard.releaseAll();
      delay(200);
    }

    if ((reading == LOW) and (ledOn == HIGH)) {
      state = LOW;
      Keyboard.press((char) 32);
      delay(10);
      Keyboard.releaseAll();
      delay(100);
      Keyboard.press((char) 177);
      delay(10);
      Keyboard.releaseAll();
      delay(200);

      time = millis();
    }

    digitalWrite(outPin, state);

    previous = reading;
  }

Put a resistor in between the D3 output  and the base of the transistor, say 500ohms, and try it again. If it works, I'll post a proper answer explaining why.

Could you just explain it in an answer so I can mark it as solved?

Looks like Eric has beaten me to it with his answer, which is more thorough than mine, but I'll explain why the base resistor works anyway.
Your code relies on reading the level of a pin set to output.  It will only switch off the output if that output is already reading "high".
If you don't have a resistor on the base, then a pretty high current will flow from base to emitter.  This will pull the level of the output down below the threshold for "high", even if it's being driven.  (It also might blow the output, but I guess you have been lucky.)
It's unusual, even if perhaps not "wrong", to read the value of an output.  I'd use a global or static variable to hold the on/off state, rather than reading it.

You need to adjust the value of Rc, the collector current limiting resistor. When replacing the single LED with a strip of N LEDs of the same kind, you have increased N times the current required (that's why you need to use a BJT, because the Arduino I/O pins won't supply that much current). So, you need a new value for that resistor, let's call it Rc', much lower: Rc' = Rc/N. Otherwise, the old value may limit the current far below of what the LEDs need to light up.
But that's not all. You also need to add 2 resistors:

Rb: a current limiting resistor between D3 and the BJT base. Its value should be in the range 330 - 2200 Ohm. The higher the current draw of the LED strip, the lower the value of Rb should be.
Rpd: a pull-down resistor between the BJT base and ground to avoid it floating while D3 is not initialised as OUTPUT. Make it at least 20x the value of Rb.

All this should be enough to make it work.


text:
GSM serial get event or read the whole input?
I am using an Arduino Uno with GSM shield, trying to read some SMS. Here is my code.

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

char incoming_char=0;

void setup()
{
  Serial.begin(19200); // for serial monitor
  SIM900.begin(19200); // for GSM shield
  SIM900power();  // turn on shield
  delay(20000);  // give time to log on to network.

  SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r");

  delay(100);
}

void loop()
{
  // Now we simply display any text that the GSM shield sends out on the serial monitor
  if(SIM900.available() >0)
  {
    incoming_char=SIM900.read(); //Get the character from the cellular serial port.
    Serial.print(incoming_char); //Print the incoming character to the terminal.
  }
}

My issue is: am testing sending this sms to the shield

A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

but somehow am not getting all the info, why?

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