text:
Flash an ESC Through Serial USB without Arduino Interrupting the Signal
So I have four Electronic Speed Controllers (ESC's), each connected to a motor. I am building a drone with an Arduino UNO board as my flight controller. For convenience, I have soldered the signal wires on each of the four ESC's onto the bottom of the Arduino where the Arduino's pin headers are soldered on. The serial ground pins on the ESC's are soldered to the ground pins on the Arduino.
The ESC's I am using can be found here.
In order to change settings on my ESC's, I am trying to use this Turnigy USB linker to connected to the BLHeli software on my computer.
The linker has a signal and a ground wire for Serial Communication, as well as a positive wire (I think this is just to fit the connector on ESC's with a BEC, but mine are OPTO, and have none). To connect the USB Linker to an ESC, I should be able to plug it into appropriate female pin headers on the Arduino using some breadboard-type jumper cables.
At least that's what I thought...
Whenever I try to connect to an ESC with the BLHeli software, I get a message:
Please Connect ESC and power up or cycle power.
Earlier, I was able to make the connection and change the settings on my ESC's when they weren't connected to the Arduino board, but now that they are soldered and hot-glued on there, they won't work. So the question is: What is the Arduino doing to the Serial connection, and how can I fix it without desoldering my ESC's whenever I need to change some settings?
Now before you ask:

Yes, the ESC is powered up and connected to a motor. It gives me a happy beeping sound.
Yes, I definitely have the signal and ground wires connected correctly. I have been trying to figure this out for days, and have even tried switching them.
The Arduino is turned off when I try to connect an ESC to the USB Linker.
Only one ESC is powered on at a time.

Maybe the Arduino has some kind of protection circuit for the IC that is messing up the signal, or maybe the ESC's have something similar that's messing it up too, because some of the ground wires are connected together. I'm going to have a very difficult time figuring this out myself, so hopefully someone out there has an idea of what's going on.
Thanks for any help you have to offer.
-- Ember

Hey,
Russell, already gave some good advice. I just want to add that, as far as I understand you are able to control the ESC from your Arduino, so why make your life more complicated with this programmer thing. I got some of ESC's from Robbe and didn't want to buy a programmer.
You can quickly write a program that allows you to program the ESC with your Arduino. For example a short program with severals commands you write serially. That gives you also much more control over your thing, what can be useful when testing.

That would be nice, but I couldn't find any information on what type of commands to send the esc through serial. I might be able to write a program that mimics programming the esc through the transmitter, but that seems like a lot of work. I think what I'll do is order some jst xh 2-pin connectors and solder those to the arduino and the esc. That way I can take it all apart and program the esc's whenever I need to.

It's really not look here: https://hobbyking.com/media/file/708075066X189350X31.pdf
Go to "program example" there is exactly written how it's done. You only need commands for top and bottom position, I guess you have that already, otherwise how would you drive drone ;) But it's on you..good luck what ever you try :D

As far as I can tell, it is not possible to program a Turnigy Multistar ESC while it is connected in parallel to any pins on an Arduino. Whether the Arduino is off, or the pins are set to input, output, HIGH, or LOW, the signal is disrupted somehow.
Solution: Don't do what I did and solder the ESC's to your Arduino unless you want to de-solder them to change settings. Sticking some wires into the Arduino's pin headers will not make a strong connection, so I would recommend soldering some sort of strong JST connectors to the pins on the Arduino.
Hope this all helped, and good luck,
-- Ember

I can offer general advice without reference to specific implementations.
By driving the Arduino pins when it is powered off you are potentially exceeding it's maximum rated specifications for voltage on any ping, and possibly for current into a pin, and you risk damaging it.
When the Arduino is powered down its Vdd pin and power supply rail will be at about 0.0 volts and will be loaded to ground by power supply capacitors and various other items connected to Vdd - including the OUTPUT of the Vdd voltage regulator in many cases.
Each Arduino pin is connected to the Vdd rail by a body / protection diode. To drive the pin high you must also raise Vdd to high-1 diode drop and must drive the Vdd rail load from your signal line via the body diode.
If your programmer has the ability to do this there is a reasonable chance that you may damage the body diode. For extra points, a very capable signal input MIGHT damage the Arduino's voltage regulator and possibly other on board devices - but I'd think that to be unlikely.
The technically best solution is to disconnect the Arduino's relevant pins when programming. As you obviously would rather not do that, then ...
Probable solution: If you power on the Arduino and run a program which ensures that the relevant pins are set to input mode then it should work as required. IF the Arduino default program sets the relevant pins to inputs then just powering it on should suffice, but odds are that the serial port pins are not both configured as inputs.
If the Arduino has a USB to serial port IC or other devices connected to the pins in question then you will need to also ensure that they do not load the pin excessively and that they will not be damaged by programming signals. eg if you were trying to drive the Arduinos serial RX_in pin which was connected to the TX_out pin of a USB-Serial IC then the programmer would be attempting to drive the USB-serial output pin and this must be dealt with in some way.
Checklist:

Is there something else connected to this pin.

If so

What state is it in during ESC programming
Will it be damaged by programming
Will it affect programming.
What action is thus needed.

Thanks for the reply! I uploaded code to my arduino that did nothing except set the esc pins to inputs. This seemed to do something, because I got some weird beeping coming from the esc when I tried to connect. The esc still can't connect though...


text:
MPU6050: Setting Gyro Output Range Throws of Positional Reading
I am using the MPU6050 in conjunction with an Arduino and Jeff Rowberg's i2cdev library, and my project requires that the gyro rate outputs be more precise than the default setting, which is 1/16.4 of a degree (+/-2000 deg/sec range). The gyro outputs can be changed with mpu.setFullScaleGyroRange(uint8_t range) for which I passed in MPU6050_GYO_FS_500 for range to get a higher precision
In this project, I also need the YPR position, which I obtain through mpu.dmpGetQuaternion(&q, fifoBuffer) and mpu.dmpGetGravity(&gravity, &q) and mpu.dmpGetYawPitchRoll(ypr, &q, &gravity).
The problem is with the new gyro output range, the YPR position changes drastically when the MPU is being rotated and slowly catches up again once the MPU is held still. I think there is an error in the filter that combines the gyro and accel data that is making the gyro to sensitive. Maybe the DMP is dividing the GYRO rate data by the default sensitivity factor (16.4) when it should be dividing by the new one (131)?
How can I get accurate YPR readings without delay?
Here is a screenshot of the data. The axis aren't labeled, but the x-axis represents about 16 seconds of time. The blue line is the gyro rate data, and the pink line is the roll position of the MPU. The graph shows two rotations of the MPU.

Had the same problem, it appears that MPU6050 DMP code works like that once you change accelerometer and gyro scales.
Works better once you use +-2000 deg/sec and +-2g scaling settings.
    mpu.setFullScaleGyroRange(MPU6050_GYRO_FS_2000);
    mpu.setFullScaleAccelRange(MPU6050_ACCEL_FS_2);

The issue lies in the way "DMP" inner logic fuses data, i suppose it has "constants" that are tuned for these settings only.
In case you need both "changed settings" and "yaw\pitch\roll" data, you might want to implement sensor data fusion by yourself or use existing libs.
The easiest i may suggest would be implementing Complementary Filter.
More complex, yet accurate would be using Kalman Filter, all depends on time and patience you have to research those topics :)

source: Stack Exchange

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

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

sort: votes


text:
How can an Arduino-Quadcopter be stabilized?
I have built an arduino quad-copter and I am using an MPU6050 to read the rotational position and velocity of the aircraft. The problem is that I cannot get the thing to stabilize. Watch this video here to get an idea of what I mean.
So as you can see from the footage (and you did watch it, right?), I'm not even getting steady oscillations, it's just random. What I don't understand is how people get their quad-copters to oscillate very quickly (maybe 10 times per second) and then trim up their PID gains to smooth it out, whereas if I raise my p-gain high enough for it to adjust that quickly, the quad-copter just goes berserk and tries to kill me.
And, speaking of p-gains, here's the PID I wrote:
float KrP = 0.002000;
float KrI = 0.000001;
float KrD = 0.200000;

void adjustRoll(float currentRoll, int newRoll) {
  if (thrust <= 1200){
    inAutoRoll = false;
    NWPower = thrust;
    NEPower = thrust;        //PID not ready to turn on yet? Just set motor powers
    SWPower = thrust;        //equal to the throttle.
    SEPower = thrust;

    I_roll = 0;              // Reset the integral.
    return;                  // Don't do anything else
  }

  float newRate = 2 * (newRoll - currentRoll); // How fast should the drone try to
                                                                       // adjust, based on the error.

  if (newRate > 50)newRate = 50;        // Don't adjust too fast!
  else if (newRate < -50)newRate = -50;

  float offset = newRate - rollRate;

  I_roll += KrI * offset;

  if(!inAutoRoll) {        // Is the PID just now turning on? (Throttle requirement met).
    lastRollRateOffset = offset;  //Smooth transition.
    inAutoRoll = true;
  }

  float adjust = (KrP * offset) + (KrI * I_roll) + (KrD * (offset - lastRollRateOffset));

  NWPower += adjust;
  NEPower -= adjust;
  SWPower += adjust;
  SEPower -= adjust;

  if (NWPower > maxOut) NWPower = maxOut;
   else if (NWPower < minOut) NWPower = minOut;

  if (NEPower > maxOut) NEPower = maxOut;
   else if (NEPower < minOut) NEPower = minOut;

  if (SWPower > maxOut) SWPower = maxOut;
   else if (SWPower < minOut) SWPower = minOut;

  if (SEPower > maxOut) SEPower = maxOut;
   else if (SEPower < minOut) SEPower = minOut;

  lastRollRateOffset = offset;
}

And in case you were wondering... yes, I do know about integral windup. The reason I have not dealt with that in my code is because the quadcopter is no where near stable, so I'm not worrying about perfection just yet. Also, I have my I-gain set to 0.000001, so it doesn't matter. The reason I have done this is because (as far as I know) a quadcopter can fly with only P and D, and with the way mine is behaving, I think a larger I-gain would only make things worse.
More detail about my PID: The PID corrects for the rotational velocity of the quad-copter, which, as I understand it, is the best way to control a quadcopter. The correction-rotation-rate is determined by multiplying the error (in degrees) by two. Why two? I dunno. I experimented with some other multipliers and two seems to be okay. Its also a prime number, so, yeah...
So anyways! What do I need to do to make the quad-copter stable? I have seen amazingly perfect quad-copters using the same arduino and the same MPU6050, but mine just tilts all over the place.
Some possible problems off the top of my head:

Bad algorithm for calculating the needed rotational velocity based on error.
Bad PID algorithm.
Bad PID gains.
I didn't balance my props, but seriously, would a couple of pieces of electrical tape stuck to the props really fix this? It doesn't seem like it would.

Thanks for any help you have to offer!

Have you run some subsystem testing sketches?  Eg did you specifically test whether the MPU6050 is working correctly, motor drivers ok, etc?

The MPU seems fine. When I tilt it it gives me reasonable values for yaw pitch roll, as well as for rotational velocity. The drivers work fine too. I have the quadcopter plugged into my computer so I have all the data I could possibly want on my screen while it's running.

Re 4: The cool thing about quadcopters is that all the control trimming and balancing /can/ be done in math, rather than physically.

This is far, far, far beyond the scope of this site.  If you want to build something that flies, spend some time studying existing solutions and the control algorithms they use, and read the replacement firmware threads at rcgroups; also don't use an actual arduino - pretty much every project that started there has long since moved on to better choices.

Can you post more code? Where is the PID updated?

random behavior is a big problem with Drone.
Did you solve this problem ?
My drone has got the same random behavior.
infrare4ever

To help solve this problem, I wrote a program in Processing that graphs all the data from the quadcopter, including roll rate, roll angle, thrust, etc... After doing so I realized that the problem was not in the PID, but in how I handled the data coming out of MPU6050. You can read all about it in this question I posted here before I had discovered the full solution.
The quadcopter is now capable of taking off, though sadly it is not very stable. This could be from bad PID gains, but I suspect it is from vibration in the roll-rate values from the MPU6050. The reason I think this is because I don't see steady oscillations, but rather random movement. Anyway, If I find a more complete solution I will update this answer.

For stability and tuning you need to make the adjustment cycle time compatible with the physical system.  How fast does this adjustment code get called relative to how fast the physical system oscillates?  Without that under control, tuning the gains will be difficult, particularly for krI and krD.
For instance, if you are updating every millisecond, and it takes a 1/10th of a second to physically flop over from -90 to 0 at the current roll_thrust setting, there's only enough kP to adjust the roll_thrust kP*(RollDelta/2)*DT/dt=0.002*(90/2)*0.1/0.001=9  Is that a sane adjustment for a thrust/motorPower of 1200+?  If you sample fast enough to make it capable of a full-throttle (+/-800?) adjustment with this particular kP, you might need to sample 88x faster (1ms/(800/9)=0.01125ms).  From the other direction, I'd figure out how fast you can sample, then choose a krP that could get you a full-bias adjustment in reasonable time.
Maybe think of adjust as roll_thrust state variable measured in units of ESC_microseconds, and krP is the conversion factor from whatever error you are measuring.  Is it roll angle error? roll rate error? Absolute roll rate error?  It looks like this bit:
float newRate = 2 * (newRoll - currentRoll); // How fast should the drone try to
if (newRoll - currentRoll < 0) {             // adjust, based on the error.
   newRate = 0 - newRate;
}

is essentially:
float newRate = 2 * abs(newRoll - currentRoll);

which might make control discontinuous.  If currentRoll is a positional roll angle setpoint, it won't be able to tell if it is on one side or the other.
If you want a roll angle of -90deg to make full throttle one way and 90deg to full throttle the other, then krP should be on the order of 900us/90deg=10us/degree.   And krI=krD=0 to start with.
I'd code up separate PIDs for thrust, roll_thrust, pitch_thrust, yaw_thrust control variables and then sum them together to get the  {NE,NW,SE,SW}Power outputs.  Then you could monitor and control in {thrust,roll_angle,pitch_angle,yaw_rate} space and the coding will be more straightforward and interpretable.

Thanks for your feedback! I have some things to clarify though: 1) I think you may have misread my code, because there shouldn't be any accumulation in the P adjust, which has no lasting memory between individual loops in the PID. 2) My throttle increments between 1100us and 1900us, so there is an 800 range, not 2500 (ESC's accept a ppm signal of 1000 - 2000us).

Also, how can I write a positional PID to control the speed PID that I already have, and still have the slightest clue as to which of the now SIX pid gains I would have to adjust? I tried it, but I don't know how to look at my quadcopter's behavior and deduce which of the six gains I need to change. That's why I just stuck with the [2* error] to make it simple.

You are right. I missed that the thrusts were initialized in the loop--it is a plain old positional form of PID--I'm striking the velocity form bit.  The krP, krI and krD, are just scaling factors from the various forms of error to the output variable.  I think I'm still confused about what the measured inputs are.

Actually, it is a velocity form PID, let me explain: "thrust" is the 1100-1900ppm signal from the thrust stick on my transmitter. Each motor is assigned that thrust in the beginning, then the PID adjusts that thrust to each motor to try to get the quad-copter to move at the desired rotational velocity(determined by 2* error in degrees from the desired angle). So to answere your question: The measured inputs are 1) the current angle of the quad-copter, and 2) the current rotational rate of the quad-copter. Also, the if(newroll-current roll<0) thing is an error on my part. I took it out.

Are you sure that driving rotational_velocity(deg/sec) towards the 2*error_deg value is the right control scheme?   This is beyond anything Arduino, but I think you'd want to work towards stability in degree-space.  Maybe not tracking the planned velocity curve at higher gains is what is causing your instability.

I'm not sure what you mean by "stability in degree-space" or by "tracking the planned velocity curve at higher gains". Do you mean that I should focus more on position rather than velocity? Anyways, right now I'm working on writing a program that will graph the data for me as I fly the quadcopter. That way I will be able to get a much better idea about where the problem is.

Yes, focus on controlling roll position instead of roll velocity.   On the second, I mean the stability problem you see at high gains might be because the desired velocity (newRate = 2 * (newRoll - currentRoll) might not be an appropriate goal for the physical system.

To be sure the receiver gets the right signal from the emitter it is mandatory to scrutinize the signal on the receiver for a while.
Once the signal on the receiver is checked good it is possible to go ahead step by step.
The first step is to drive the 4 ESC/motors with the same signal coming from the throttle.
Once the behavior of the 4 motors complies with changes on the throttle coming from the emitter it is time to go to the next step.
The next step stems from a mix with pitch/roll/yaw coming from the emitter.
The mix is added/removed to/from the throttle addressing each motor.
The behavior of the 4 motors must show exactly the mix that comes from the emitter.
An "acceptable" mix is something like (in the same unit, degres or microseconds):
Something like this:
int throttle_gaz;
int roll_length, pitch_length, yaw_length;

throttle_gaz=pulse_duration[throttle_chanel];
if ( abs(throttle_gaz-1500) <= 50 )
{
 throttle_gaz=1500;
}
roll_length=pulse_duration[roll_chanel]-1500;            //ROLL
if (abs (roll_length) <=100 )
{
roll_length=0;
}
roll_length/=3;

pitch_length=pulse_duration[pitch_chanel]-1500;           //PITCH
if (abs (pitch_length) <= 100 )
{
  pitch_length=0;
}
pitch_length/=3;

yaw_length=pulse_duration[yaw_chanel]-1500;             //YAW
if (abs (yaw_length) <=100 )
{
  yaw_length=0;
}
yaw_length/=3;

//add/soustract from THROTTLE (pulse_duration[throttle_chanel])
//change the sign (+ / -) acc
pulse_length_esc1=throttle_gaz + roll_length + pitch_length - yaw_length;
pulse_length_esc2=throttle_gaz - roll_length +  pitch_length +  yaw_length;
pulse_length_esc3=throttle_gaz + roll_length - pitch_length  + yaw_length;
pulse_length_esc4=throttle_gaz - roll_length -  pitch_length  -  yaw_length;

The question is about how to automatically stabilize the craft using data from an inertial measurement unit. Your answer does not address this question.

as a beginner in making a ,flight controller I am looking for a tutorial depicting all the steps to fullfil such a purpose.

authors: Корней Чуйковский

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


text:
Control time without delay() Arduino
For the last couple of day I've been trying and failed many times just to not use the delay() funtion in Arduino. I have to admitted that my coding skill are extremely bad.
What i trying to do is:
If button is pressed:
Motor A and B move for 1 second at slow speed == > Motor A keep moving but at fast speed and motor B stop.
else:
Motor A and B both stop.
I managed to wrote the code by using delay function for that 1 second. However i got no idea how to do it WITHOUT DELAY() there will be sensor reading as well at the same time, i cant afford that 1 second delay of sensor reading).
Here is my code:
int dir1PinA = 2;
int dir2PinA = 3;
int speedPinA = 9; // Needs to be a PWM pin to be able to control motor speed

// Motor 2
int dir1PinB = 4;
int dir2PinB = 5;
int speedPinB = 10; // Needs to be a PWM pin to be able to control motor speed

int button = 6;

void setup() {  // Setup runs once per reset
// initialize serial communication @ 9600 baud:
Serial.begin(9600);

//Define L298N Dual H-Bridge Motor Controller Pins

pinMode(dir1PinA,OUTPUT);
pinMode(dir2PinA,OUTPUT);
pinMode(speedPinA,OUTPUT);
pinMode(dir1PinB,OUTPUT);
pinMode(dir2PinB,OUTPUT);
pinMode(speedPinB,OUTPUT);

// Define button pin
pinMode(button,INPUT);

}

void loop() {
  if( button == LOW){           // if button is pressed
    // Motor A (move slow) and B  moving
    analogWrite(speedPinA, 100);//Sets speed variable via PWM
    digitalWrite(dir1PinA, LOW);
    digitalWrite(dir2PinA, HIGH);
    analogWrite(speedPinB, 255);
    digitalWrite(dir1PinB, LOW);
    digitalWrite(dir2PinB, HIGH);
    delay(1000);

    // After 1 second Motr A (move fast)and B stop every time button pressed
    analogWrite(speedPinA, 255);//Sets speed variable via PWM
    digitalWrite(dir1PinA, LOW);
    digitalWrite(dir2PinA, HIGH);
    analogWrite(speedPinB, 0);
    digitalWrite(dir1PinB, LOW);
    digitalWrite(dir2PinB, LOW);
  }
  else
  {
    // Both motor not moving
    analogWrite(speedPinA, 0);//Sets speed variable via PWM
    digitalWrite(dir1PinA, LOW);
    digitalWrite(dir2PinA, LOW);
    analogWrite(speedPinB, 0);
    digitalWrite(dir1PinB, LOW);
    digitalWrite(dir2PinB, LOW);
  }
}

Please point me out the direction or give me an example of code. And I have already try the Blinkwithoutdelay Arduino example but it does not work for this case.
Very much appreciated.

Did... you... just misspell else as esle!?

This has been asked many times, both here and on the Arduino Forum. For one treatment (by me) see this.

Thanks for the link. Ill have a look and will try my best. Ha:)

Also posted on Arduino Forum

you need a state machine with two states (unpressed, pressing). You also save a timestamp each time the state changes. You can compare the last change's timestamp with the system time to determine if it's time to move to the next state. "unpressed" changes to "pressing" upon a button press (if state is unpressed). "pressing" changes to "unpressed" if it's been 1000ms since the last change AND the button is not pressed.

Just got the whole thing working with if statement. Its very messy but its works like a charm.
I did try to approach thet FSMachine method. But i think my brain just not good enough for it, LOL

If button is pressed: Motor A and B move for 1 second at slow speed == > Motor A keep moving but at fast speed and motor B stop. else: Motor A and B both stop.

I would do a quick state machine:

STATE / button released: do nothing;
      STATE / button pressed: run motors a+b;
      STATE / run motor a+b: run motor a+b; if 1 second has passed, advance to just run motor a;
      STATE / run motor a: run motor a at fast speed and stop motor b.

fairly easy to code as well.

Assuming the button isn't held down for 50 days straight, you can use the millis() function and basically set a marker of the current time when the user pushes the button down. To do this, you need to detect when the user switches from off to on, not when while the button is pushed or you'll be resetting the marker every time.
Then you record the time every loop while the button is pushed down. If the current time is more than one second after the time recorded by the marker, you switch motor B off and make motor A as fast speed like you said. When the button is off, like you said set both motors to off.

The 49.71-day  millis() rollover is relevant only if button presses longer than that are allowed.   For any shorter interval, unsigned long arithmetic works ok, even if a rollover occurs during the interval.

Well i said that just incase he's pressing the button down for 50 days straight ^.^

I got the thing working. So thanks.
The things is gonna run 3650 day. But the button only pressed for maximum 1 min. So it should be fine i guess. Anyway thanks for the advise guys

You might want to use a timer. There are some libraries available for Arduino that precisely do that.
You can either use a library that implements a software timer (something similar to comparing millis(), but with powerful additional built-in features such as button debouncing, timed pulses, etc.) or use a library that deals with the hardware interrupts of the MCU.
As an example take a look at this particular library: Timer. I think you'll love it!

Thank youn I got the code working. Using millis() and a bunch of if. But i definitely have a look at the timer library.


text:
Serial not working with I2C
I have been working on a hydroponic garden that is controlled with Arduinos. I have everything working except for the user interface. What I would like to do is have an LCD screen paired with a rotary encoder for use on the garden, and an ESP8266 WiFi module set as a server working with a custom Android app that I am writing.
I have been working on writing the app and the code that will allow the Arduino and the app to talk to each other, but I have been running into a problem. Sometimes the serial data between the ESP266 and the Arduino is not being picked up by the Arduino. I have verified that the data coming out of the WiFi module is correct, but the Arduino seems to be missing characters. This seems to happen almost at random. Sometimes it will work, and other times it will simply get stuck. I used a SoftwareSerial library to add an extra serial port and printed what the Arduino was receiving from the WiFi module, and it just seems to be missing random characters.
Up until now I have had the WiFi module connected and the LCD screen. I was using the LCD screen to display debugging messages. I took the LCD screen off and deleted all the LCD code and now everything seems to work just fine.
The LCD screen uses I2C.
Why does disconnecting the LCD screen solve the issue? Is there a way to make both run at the same time? The LCD uses I2C. I am unaware of anything that would prevent this from working.
Thanks.

Without seeing your code, and preferably a schematic, a reply would be guesswork.

I'll guess it's the incompatible voltage levels because ESP8266 is a 3.3V device that'll output 3.3V logic high. Try converting the ESP8266's TX 3.3V to 5V serial and Arduino's TX 5V to 3.3V serial

Please add some info on the memory statistics with and without the LCD code. And the obvious question; are you using String?

Explanation
The SoftwareSerial library requires continually polling the serial ports over short periods of time therefore it presents a problem of having to parse received data into something usable, which is going to be nearly impossible as your program is going to be too busy trying to keep up with all the incoming NMEA characters to assemble it all into something meaningful.
So in your situation the data from the ESP8266 module is probably fine as you say, but parsing it and sending it to the lcd over I2C is a lot of work and sometimes it will "lose" data it simply doesn't have time to process. This explains why the data loss is hit and miss, and gets resolved when you reduce the processing workload of your program by removing the lcd component.
Solution
What you need here is to use an interrupt-driven SoftwareSerial library instead, which works by filling a buffer in the background with received data and allows a little breathing room to process the serial data. A great example is the NewSoftwareSerial library. This link will show you how to use the library , also expand into the details my answer to give you a deeper understanding.

I am using the native serial pins on the Arduino to receive information from the WiFi module.  The SoftwareSerial library was only used to print to the computer to see what the Arduino was receiving from the module.  Would the same problem happen with the native serial pins?

Old thread, but this answer contains incorrect information.  From arduiniana: "NewSoftSerial is in the core!  Starting with Arduino 1.0 (December, 2011), NewSoftSerial has replaced the old SoftwareSerial library as the officially supported software serial library."  So that library still blocks.  I would suggest my library, NeoSWSerial.  It does not block on receive and can transmit and receive at the same time. See also this answer regarding "native serial pins", aka HardwareSerial.

@slash-dev My answer does point to the NewSoftwareSerial library, what exactly is incorrect?. If you have a custom library you think would suit the OP's needs please add a full answer above as a useful reference for anyone with a similar issue.

I agree that the polling approach is causing problems, but but he is already using that library.  NewSoftwareSerial is the current SoftwareSerial.  Although the start of each character causes an interrupt, SoftwareSerial polls for the remaining 9 bits, with interrupts disabled.   :P  I was reluctant to add a complete new answer, because your analysis is correct, but the library suggestion is not.  Alternatives are listed in my other answer, here.  SoftwareSerial is last choice for many reasons, including the OP's problem.


text:
Can't connect to my Arduino via W5100 Ethernet shield
I recently bought a W5100 Ethernet shield and I'm trying to run this simple example, which is a little improvement of the basic WebServer sketch provided by Arduino.cc
#include <SPI.h>
#include <Ethernet.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress DnsServer (192, 168, 1, 6);
IPAddress GateWay (192, 168, 1, 1);
IPAddress SubNetMask(255, 255, 255, 0);
IPAddress ip(192, 168, 1, 20); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80

String HTTP_req; // stores the HTTP request
boolean LED_status = 0; // state of LED, off by default

void setup() {
  Ethernet.begin(mac, ip, DnsServer, GateWay, SubNetMask); // initialize Ethernet device
  server.begin(); // start to listen for clients
  Serial.begin(9600); // for diagnostics
  pinMode(2, OUTPUT); // LED on pin 2
}

void loop() {
  EthernetClient client = server.available(); // try to get client
  if (client) { // got client?
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) { // client data available to read
        char c = client.read(); // read 1 byte (character) from client
        HTTP_req += c; // save the HTTP request 1 char at a time
 // last line of client request is blank and ends with \n
 // respond to client only after last line received
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          // send web page
          client.println("<!DOCTYPE html>");
          client.println("");
          client.println("");
          client.println("<title>Arduino LED Control</title>");
          client.println("");
          client.println("");
          client.println("
LED
");
          client.println("
Click to switch LED on and off.
");
          client.println("<form method=\"get\">");
          ProcessCheckbox(client);
          client.println("</form>");
          client.println("");
          client.println("");
          Serial.print(HTTP_req);
          HTTP_req = ""; // finished with request, empty string
          break;
        }
 // every line of text received from the client ends with \r\n
        if (c == '\n') {
 // last character on line of received text
 // starting new line with next character read
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // a text character was received from client
          currentLineIsBlank = false;
        }
      } // end if (client.available())
    } // end while (client.connected())
    delay(1); // give the web browser time to receive the data
    client.stop(); // close the connection
  } // end if (client)
}

// switch LED and send back HTML for LED checkbox
void ProcessCheckbox(EthernetClient cl) {
  if (HTTP_req.indexOf("LED2=2") > -1) {
    // see if checkbox was clicked
 // the checkbox was clicked, toggle the LED
    if (LED_status) {
      LED_status = 0;
    } else {
      LED_status = 1;
    }
  }

  if (LED_status) { // switch LED on
    digitalWrite(2, HIGH);
    // checkbox is checked
    cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\" checked>LED2");
  } else { // switch LED off
    digitalWrite(2, LOW);
    // checkbox is unchecked
    cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
        onclick=\"submit();\">LED2");
  }
}

So I proceed with connecting my shield via a LAN cable to my router (Gateway 192.168.1.1), but if I ping 192.168.1.20 (my Arduino) it says "Host Unreachable", my router use DHCP which always worked and still works fine, I'm sure that there aren't any MAC address or IP conflict. I googled around a lot but nothing seems to work.
My DNS server is 192.168.1.6 because I'm running PI-Hole (it's an ad blocker) on a Raspberry, and I don't think this is the problem because all devices connected to it are working fine.
Please any help? Do I have to assume that my shield is faulty?
I tried also using DHCP connection in order to get an IP from the router by doing a:
Ethernet.begin(mac);

But no good as well.

Genuine Arduino shield, or Chinese knock-off? Those Chinese knock-offs often need a few resets to get them to actually communicate.

@Majenko it's a Chinese one, what do you mean by few resets? Clicking the reset button few times?

That usually worked for me, yes.

Oh, and you might like to wrap all your string literals in F("...") to move them out of precious RAM.

@Majenko alright, I'll try when I get back from work ;)

Does your Arduino support ping?  Looking at your code I can't see where you open the socket and monitor it for incoming ping requests.

@Matt I suppose yes, as long as the WebServer is up and running...

@FabioEnne - Do you mean the webserver on the Arduino?  I wouldn't expect that to make a difference to the ping service.  Maybe I'm wrong but I don't think an Arduino responds to ping unless you have put some code on there to do it.  Basically I think your system is working.

@Matt Probably you are right..anyway my Router doesn't see him as a connected device, so also via Browser I got no response from the Arduino IP.. very strange...probably is a faulty Ethernet shield..

Yes given that information I would get a new shield.

"...Please any help? Do I have to assume that my shield is faulty?..."
Before trashing the shield, I'd run through a sligtly more comprehensive troubleshooting approach, from the lowest level of the network stack (the physical layer) up to the ICMP/IP layer. Let me expand over this process:

Physical layer: I bet your router has some LEDs whose purpose is to show IF some ethernet device is connected to related physical router port... or not. So, as a very first step, supposing you connect your ethernet shield to PORT-1 of your router, you should check that once you connect the cable and turn on the Arduino.... the "port 1" LED on the router should turn on.
If it turns on... let's proceed to next step. Otherwise... let's launch a different question (or expand accordingly your OP);
Ethernet layer: once the LED is on, we can be sure that the physical layer is OK. So let's go up at Ethernet layer. In order to communicate on an Ethernet network, every device need to have a MAC address. Also, even if not strictly necessarily, we can bet that every ethernet device (including your shield) implement the ARP resolution protocol. This is needed in order, for other ethernet devices, to obtain the MAC address of your shield, in order to include such a MAC address in all the ethernet datagrams to be sent over the network (to communicate with your shield).
So, if you configured your shield with MAC DE:AD:BE:EF:FE:ED and IP 192.168.1.6 I would:

connect my Linux box to your router (BTW: sorry! I can't help with other operating systems, as I switched to a linux-only notebook lots of years ago!);
configure my Linux ethernet interface (eth0) with an IP like 192.168.1.99;
run an arping -I eth0 192.168.1.6 (where arping is this tool)

If everything is working correctly, you should receive something like:
root@iMac-Chiara:~# arping -I eth0 10.20.20.2
ARPING 10.20.20.2 from 10.20.20.1 eth0
Unicast reply from 10.20.20.2 [A4:BA:DB:98:FC:A4]  0.736ms
Unicast reply from 10.20.20.2 [A4:BA:DB:98:FC:A4]  0.729ms
Unicast reply from 10.20.20.2 [A4:BA:DB:98:FC:A4]  0.720ms
[...]

where you see that my notebook (10.20.20.1) is getting ARP-replyies from 10.20.20.2, who has the A4:BA:DB:98:FC:A4 MAC address.
If you don't see replyies... we have an Ethernet problem (but not a physical one) and... chances are high that you have a faulty shield (BTW: the message "Host unreachable" you mentioned in your OP, let me think that this is your problem);
Viceversa, if you obtain replyies, than the Ethernet level is OK and problems are located on upper layers. Let's focus on this last particular case

IP layer: once the physical layer and the ethernet layer are OK, you should be able to properly PING your target (I'm excluding the case where you have some firewall that, somewhere along the path from the two hosts, could "cut" some traffic. I'm also supposing that IP addresses and netmask are properly configured [from an IP point of view]). I'm not getting deeper with such a case, as you should be already familiar with PING (BTW: from your POST, it's not clear from where you were PINGing your Arduino. Directly from the "router"? or from you PC?)

Having said all the above, let me conclude by saying that several further checks could be putted in place but... it's much better to previously run above checks :-)
Hope this help!

I read with a lot of interest, but yesterday I passed in front of a shop in Milan who was selling an original Arduino Ethernet Shield 2 for 22€ so I couldn't resist and I've bought one, connect and everything worked fine in less than 3secs..I suppose that the oder CHine clone for 4€ was a waste of money ;) Thanks everybody by the way


text:
Getting a reset error on a WEMOS D1
As a learning effort, I am trying some sample code on my WEMOS D1, which is basically an Arduino compatible board with a built-in ESP8266 (Wi-Fi module).
This is the output of my Serial Monitor:
1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
Initializing Wifi...
Start printMacAddress
 ets Jan  8 2013,rst cause:4, boot mode:(1,4)

wdt reset

It stops there and I see no more messages. Below is the code I am trying (from https://www.arduino.cc/en/Guide/ArduinoWiFiShield):
#include <SPI.h>
#include <WiFi.h>

void setup() {
  // initialize serial and wait for the port to open:
  Serial.begin(115200);
  // attempt to connect using WEP encryption:
  while(!Serial) ;
    Serial.println("Initializing Wifi...");
    printMacAddress();
    // scan for existing networks:
    Serial.println("Scanning available networks...");
    listNetworks();
}

void loop() {
  delay(10000);
  // scan for existing networks:
  Serial.println("Scanning available networks...");
  listNetworks();
}

void printMacAddress() {
  Serial.print("Start printMacAddress");
  // the MAC address of your Wifi shield
  byte mac[6];
  // print your MAC address:
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);
}

void listNetworks() {
  // scan for nearby networks:
  Serial.println("** Scan Networks **");
  byte numSsid = WiFi.scanNetworks();
  // print the list of networks seen:
  Serial.print("number of available networks:");
  Serial.println(numSsid);
  // print the network number and name for each network found:
  for (int thisNet = 0; thisNet<numSsid; thisNet++) {
    Serial.print(thisNet);
    Serial.print(") ");
    Serial.print(WiFi.SSID(thisNet));
    Serial.print("\tSignal: ");
    Serial.print(WiFi.RSSI(thisNet));
    Serial.print(" dBm");
    Serial.print("\tEncryption: ");
    Serial.println(WiFi.encryptionType(thisNet));
  }
}

I am not a hundred percent sure, but I think this started happening when I connected D8 (Digital Pin 8) to a relay.  I later read that it has a specific use (to flash firmware I think). The error message appears to point to something called a "WatchDog Timer", but I am not even sure what to eat that with. :-)
There are no error messages in the IDE and it even uploads fine. So why is this happening and how do I fix it?
TIA!

Can you disable the code for setting the relay pin as an output? I once got watchdog reset for setting reserved pins as an output. Which prins are reserved, can differ per board.

There is no such code in the above.  This happened in another program and I thought I may have munged the board.

Ah okay, I was unsure if you left out that piece of code, since it was described in the text, but not in the code. Given that it still uploads, I think it's unlikely you broke something, since, I assume, the uploading should break if you break the bootloader pins.

WEMOS D1 is not an Arduino board. It's a NodeMCU clone.

@dda You're right, I meant an Arduino "compatible" WEMOS D1.  Turns out it is not even a WEMOS but a clone made by Qunqi. :-)

If Watchdog timer is the cause of reset that means there is at least one place in your code that runs too long without allowing subsystems to do the background tasks. It might be possible the part of your code causing the problem is:
while(!Serial) ;

Instead that loop use:
while(!Serial)
  delay(100);

so the background tasks will get the chance to be exectuted during the while loop.
EDIT:
In fact you can completely remove that while loop as it is not necessary. There is a possibility !Serial is always true so the loop never ends. And I suggest you using 74880 instead of 115200 so you can see the debug messages sent automatically by ESP8266.
END OF EDIT
However, if that is not the part of the code that causes the problem (and I think it is not) then the problem might be for loop where you list networks. You can check if that is the problem by adding a small delay inside the loop as follows:
for (int thisNet = 0; thisNet<numSsid; thisNet++) {
  delay(1);
  Serial.print(thisNet);
  Serial.print(") ");
  Serial.print(WiFi.SSID(thisNet));
  Serial.print("\tSignal: ");
  Serial.print(WiFi.RSSI(thisNet));
  Serial.print(" dBm");
  Serial.print("\tEncryption: ");
  Serial.println(WiFi.encryptionType(thisNet));
}

If the problem will still exist then you can add a few more delay(1); statements through the code.
Instead of delay you may use yield(); which is the same as delay(0);.

Thanx @Chupo_cro but none of those worked.  So, I started commenting out stuff and apparently the problem is at two places (the program works without these two).  The first is the line: WiFi.macAddress(mac); and after that this line: byte numSsid = WiFi.scanNetworks();  Which pretty much makes this program a zero....


text:
Does a graphical driver chip exist for this project?
I need some expert advice. I'm using an Arduino Leonardo, which I have got working with a Nokia 3310 monochrome screen. I wrote some code to draw any graphics to the screen.
What I want to know is, can I buy a chip from somewhere that will offload most of the CPU usage (for graphics from the Leonardo) that draws numbers and letters to the screen and basic graphics (different types of polygons and lines)? So I'm looking for a chip designed to do the graphical work and a data sheet reference for the chip.

Just get a second arduino. e.g. a pro-mini.

I have no idea if there is a chip or not, but I doubt it.
But then, why do you need one?
You already know how to communicate with the screen, so why not off-load those functions on to another Arduino (make your own small ATMega328P based board to do it) and then communicate with that through whatever means you like from your Leonardo?
You don't need a dedicated chip to do what you can quite easily program an Arduino to do.


text:
How to connect Flora 2 and nRF8001 BLE Breakout
I'm trying to get the nRF8001 BLE Breakout polling properly on Flora but Adafruit's tutorial and everything I've read and hunted around but I'm new to Arduino and not really sure how the Adafruit_BLE_UART library is handling I/O on the various pins. I'd appreciate it if anyone knows the proper pin configuration to get this working. I'm not in a position where I can easily change out to a better BLE device for my Flora.
So it's clear I have

SCK connected to SCK.
MISO to MISO, I've also tried it in D12 with the same outcome.
MOSI in MOSI, there's no D11 on this board so I couldn't try that.
REQ in D10.
RDY in SDA, which is supposed to correspond to D2 (besides SCL I don't think there are any other interrupt pins).
RST in D9, also tried it in the Reset SPI, doesn't seem to make any difference.

In short I'm using all the appropriate SPI pins and two of the data pins mentioned in the BLE tutorial, and I've tried a couple other configurations without much success.
And it appears to be powered properly.
using echoDemo, getState always returns the disconnected opcode. Polling apparently does nothing, setDeviceName does not set a name. I think either MISO or MOSI or both are the problem here. I can blink the LED, and other peripherals are working okay. (Crossposted to Adafruit forums.)
Some code:
#include <SPI.h>
#include "Adafruit_BLE_UART.h"

// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 2
#define ADAFRUITBLE_RST 9

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

void setup(void) {
  Serial.begin(9600);
  while(!Serial); // Leonardo/Micro should wait for serial init
  Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Print echo demo"));
  BTLEserial.setDeviceName("NEWNAME"); /* 7 characters max! */
  BTLEserial.begin();
}
aci_evt_opcode_t laststatus = {5};

void loop() {
  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();
  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();
  Serial.println(laststatus);
  Serial.println(status);
  Serial.println(ACI_EVT_DEVICE_STARTED);
  Serial.println(ACI_EVT_CONNECTED);
  Serial.println(ACI_EVT_DISCONNECTED);
  delay(1000);
  // If the status changed....
  if (status != laststatus) {
    // print it out!
    if (status == ACI_EVT_DEVICE_STARTED) {
        Serial.println(F("* Advertising started"));
    }
    if (status == ACI_EVT_CONNECTED) {
        Serial.println(F("* Connected!"));
    }
    if (status == ACI_EVT_DISCONNECTED) {
        Serial.println(F("* Disconnected or advertising timed out"));
    }
    // OK set the last status change to this one
    laststatus = status;
  }
}

The SPI bus can be accessed using a 6 pin header located next to the embedded processor.  Look at the embedded image below. Locate the 6 pin header just to the right of the processor.  Note the white dot indicating pin1 of the header.  Now look at the bottom of the embedded image to see the definitions of the 6 pins.  MISO, MOSI and several other SPI signals are listed.

I'm not sure what you're trying to get at. I mentioned in the post that I'm using the SPI bus pins, do you mean to say that I should be modifying the BLE library to (somewhere) reference different pin numbers for MISO, MOSI, SCK? On the SPI bus the datasheet marks them 1, 4, and 3, but I don't see anything else indicating a pin number. The image you talked about doesn't seem to be in your reply, so I can't really tell what document you're referencing.

The image is embedded in the stackexchange answer.  In your question you associated MISO with D12 and MOSI with D11.  On this page Adafruit says the SPI is on the 6 pin header on pin 1 (MISO) and 4 (MOSI).  I do not think you should modify the library.

I do see that I did not read the flora key correctly off the embedded image.  I will remove the pin suggestions from the answer.  Adafruit might have done a better job at documenting their product as it does not appear Adafruit consistently used Arduino Uno pin names on the Flora.

The image thing turned out just to be in my browser, I can see it just fine using a different one. I'll see what I can do using this sheet for reference.


text:
Read signal from co-ax cable with ADC
I have an Arduino Uno and I'd like to read a signal from a co-ax cable with it. The cable carries 12VDC (power for other components) along with a signal (of about 1 Ghz frequency). How do I go about recording this signal with my Uno? I'm new to this field so I don't know the full capabilities of the ADC. Also, the Uno can't handle >5 VDC, so what should I do to make the signal readable?

a signal (of about 1 Ghz frequency). How do I go about recording this signal with my Uno? ... umm ... maybe with somthing that runs about 1,000 x faster than an Uno? You have zero chance of doing it.

It's not possible. To sample a 1GHz signal you need to sample at least 2 billion times per second (a sample rate of 2Gsps). You can maybe get a couple of hundred KILO samples (thousand) per second on an Arduino.
Also the 1GHz signal itself is of no interest to you. What is of interest is what is modulated on the 1GHz signal.
What is normally done is:

Down-mix (filter) the carrier signal to an IF (Intermediate Frequency) usually in the order of a few kilohertz
Demodulate the signal using whatever modulation scheme was used to encode it.
Extract the encoded information from the demodulated signal.

To do that you'd need

the precise carrier frequency (1GHz is not the same as 1.029GHz)
the modulation scheme used (there's loads to choose from)
knowledge about any data formats and encodings used in the signal

As well as the hardware to do all that.
So no, you're never going to come even anywhere close with an Uno. You need specialised RF hardware just to prepare the signal for working with.


text:
Reading pulse train with DC offset
One of the analog inputs to Arduino is a pulse train with DC something like 1.5V to 3.9V pulse. This of course changes by time and Im only interested in the difference voltage (peak-to-valley). Like I want Arduino to measure (3.9V-1.5V) in the loop. I can use two analog inputs if there's no other way.
How to code this kind of measurement?
Does anybody have experience with this?
duty cycle is 50% freq 3.3kHz.

Please edit your question (click the edit button) to include some waveform and performance specs  – how long the voltage stays high or low; required accuracy; what you want to measure.  A solution that works if the input is audio frequency might not be adequate to handle RF inputs.  Regarding what you want to measure, do you want to know the frequency, or risetimes, or pulse lengths, or voltages, or what?

just an incoming pulse train to ADC with  duty cycle is 50% freq 3.3kHz. with dc offset. i even gave an example in my question about what i need. i want to roughly measure peak to valley voltage of this type of pulse.

The proper method to use depends in part on what the data is for, and on what other processing your loop needs to do.  The following example assumes there is nothing to do except compute the difference between the highest and lowest readings from among the most recent 8.
enum { nReads = 8 }; // # of readings = 2**3
enum { rMask = 7 };  // index-mask of 3 bits
enum { aIn = A3 };   // analog input pin #
int reads[nReads];
byte rindex=0;

void loop() {
  int vhi, vlo, vdiff, r;
  r = reads[rindex] = analogRead(aIn); // Analog read takes about .1 ms
  vhi=0; vlo=1024;
  for (byte i=0; i<nReads; ++i) {
    if (r > vhi) vhi = r;
    if (r < vlo) vlo = r;
  }
  rindex = (rindex+1) & rMask;
  vdiff = vhi - vlo;
  //
  // In this section, scale or use or report vdiff
  //   ...
}

An analog read takes about 104 μs.  That, plus any time taken to scale, use, or report vdiff, will be the major determinant of how rapidly loop() runs, because the for loop that calculates vhi and vlo should take less than 10 or 15 μs.
For example, if loop() takes 125 μs per pass, the code will get about one reading per half cycle of input.  (3.3 KHz is 303 μs per full cycle.)  This will produce a steady precession of where the analog readings are taken within the input waveform's cycle.  If that phenomenon is undesirable, you may need to use interrupt-triggered ADC reads.
If you don't need new differences as frequently as the above code produces them, you could instead on demand take several readings in a row and produce a result.  For example:
int getDiff() {
  enum { nReads = 6 };
  enum { aIn = A3 };   // analog input pin #
  int vhi=0, vlo=1024, r;
  for (byte i=0; i<nReads; ++i) {
    r = analogRead(aIn); // Analog read takes about .1 ms
    if (r > vhi) vhi = r;
    if (r < vlo) vlo = r;
  }
  return vhi - vlo;
}

void loop() {
  int vdiff;
  if (readingIsNeededNow) {
    vdiff = getDiff();
    // do stuff with voltage difference
  }
  // etc
}


text:
How to explain the need/advantage for volatile in terms of microcontroller instruction flow
I know there are already many questions why volatile is used when it comes to interrupts.
But explanations like this doesn't help to picture what really happens:

Specifically, it directs the compiler to load the variable from RAM
  and not from a storage register, which is a temporary memory location
  where program variables are stored and manipulated. Under certain
  conditions, the value for a variable stored in registers can be
  inaccurate.

Above is from the official Arduino website:
And below is the basic Atmega328 architecture:

Is it possible to explain the use/advantage of volatile by comparing it to the usual declaration way considering the above architecture?
I mean such way: If volatile int x is used, the CPU fetches this from this  by this way ect. And if instead int x is used the instruction flow works like this so forth and so on.
Unfortunately I have difficulty to understand from plain two sentence explanations.
As you see my question is about after the compilation what do we observe as a benefit inside the hardware during the instruction flow.

Let's say you are running the code x++; x++; the compiled code will have to load variable x from the predefined memory location; place the value in a register; call the increment instruction; and write the register back to the memory location; and then the same steps for the next x++. The compiler will be smart and notices you write the register to memory, and the read it back from memory directly after, and will just remove these two steps entirely, to increase performance. It is however assuming the memory location doesn't change in between statements.

Are general purpose registers used for fetching volatile variables from SRAM?

The ALU can only work on registers, so you have to load the variable from SRAM to do anything with it. Sometimes local variable aren't even placed in SRAM, but only a register is used for them (for example the i variable in a for( i... loop)

The compiler can't see whenever an interrupt is being called. So may basically make a constant out of a value that you wanted to change in the interrupt. You can draw your normale program loop, with an interrupt completely loose from that. Tell that the hardware calls this function, thus the compiler doesn't know if and when it's called. Show some example code and ask what a compiler could do with or without interrupts.

Short answer: no, volatile cannot be explained in terms of the
figure you show in your question.
Longer answer: there is no direct link between the meaning of volatile
and the architecture depicted in the figure. If you insist in linking
them together, it is possible to find a very weak and indirect link
as follows:

Volatile is all about preventing the compiler from doing some
optimizations when translating your program to assembly. Looking at the
generated assembly can help understanding the effect of volatile.
When learning the assembly language, the figure you show is helpful
in understanding the assembly instructions themselves.

As you see, the link is indirect, mostly because we are talking about
different abstraction levels. Also, the link is weak because the figure
describes specifically the AVR architecture, whereas volatile applies
to any architectures for which there is a C compiler.
To illustrate the first point above, here is an example program which
shows the effect of volatile:
volatile bool volatile_flag;
bool plain_flag;

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

void loop()
{
    Serial.print("Waiting for volatile flag... ");
    while (!volatile_flag) ; /* wait */
    Serial.println("done.");

    Serial.print("Waiting for plain flag... ");
    while (!plain_flag) ; /* wait */
    Serial.println("done.");
}

As such, the program is not very interesting, it will just hang on the
first loop. But you can imagine there being some ISR that can set the
flags when some external event happens. Then the wait loops would start
to make sense, as they wait for the external event.
Here is the disassembly of the loop() function:
    Serial.print("Waiting for volatile flag... ");
  ce:   60 e0           ldi r22, 0x00   ; 0
  d0:   71 e0           ldi r23, 0x01   ; 1
  d2:   82 e5           ldi r24, 0x52   ; 82
  d4:   91 e0           ldi r25, 0x01   ; 1
  d6:   0e 94 b3 02     call    0x566   ; 0x566 <Print::print(char const*)>
    while (!volatile_flag) ; /* wait */
  da:   80 91 51 01     lds r24, 0x0151
  de:   88 23           and r24, r24
  e0:   e1 f3           breq    .-8         ; 0xda <loop+0xc>
    Serial.println("done.");
  e2:   6e e1           ldi r22, 0x1E   ; 30
  e4:   71 e0           ldi r23, 0x01   ; 1
  e6:   82 e5           ldi r24, 0x52   ; 82
  e8:   91 e0           ldi r25, 0x01   ; 1
  ea:   0e 94 d0 02     call    0x5a0   ; 0x5a0 <Print::println(char const*)>
    Serial.print("Waiting for plain flag... ");
  ee:   64 e2           ldi r22, 0x24   ; 36
  f0:   71 e0           ldi r23, 0x01   ; 1
  f2:   82 e5           ldi r24, 0x52   ; 82
  f4:   91 e0           ldi r25, 0x01   ; 1
  f6:   0e 94 b3 02     call    0x566   ; 0x566 <Print::print(char const*)>
    while (!plain_flag) ; /* wait */
  fa:   80 91 50 01     lds r24, 0x0150
  fe:   81 11           cpse    r24, r1
 100:   01 c0           rjmp    .+2         ; 0x104 <loop+0x36>
 102:   ff cf           rjmp    .-2         ; 0x102 <loop+0x34>
    Serial.println("done.");
 104:   6e e1           ldi r22, 0x1E   ; 30
 106:   71 e0           ldi r23, 0x01   ; 1
 108:   82 e5           ldi r24, 0x52   ; 82
 10a:   91 e0           ldi r25, 0x01   ; 1
 10c:   0c 94 d0 02     jmp 0x5a0   ; 0x5a0 <Print::println(char const*)>

The important thing to notice is how the compiler implemented the
waiting loops. The first one is essentially
0:  lds r24, volatile_flag  ; load the flag from RAM
    tst r24                 ; test it
    breq 0b                 ; if zero, loop back

whereas the second loop is:
    lds r24, plain_flag     ; load the flag from RAM
    cpse r24, r1            ; if zero, skip the following jump
    rjmp 1f                 ; jump over the next loop
0:  rjmp 0b                 ; infinite loop
1:

You may appreciate the first loop has been translated to assembly in a
very literal way, whereas in the second loop the compiler optimized away
all but the first read of the variable. That could be translated back to
C as
if (!plain_flag) {
    for (;;) ;  // hang in an infinite loop
}

The compiler assumed the flag cannot be changed by some external event,
so there is no point in reading it repeatedly. The volatile keyword
prevents the compiler from making such assumption.
And how is all this related to your figure you may ask? Well, if you
happened to not understand the assembly code above, you could check the
AVR Instruction Set Manual to see what each instruction does,
and that's when the figure becomes helpful.

I believe the back translation to C you provided is going to be the clearest explanation of volatile you can provide: any further simplification is not going to have any value.

@RobertoLoGiacco: Agree, but reading the generated assembly is the only (contrived) way I found to link volatile with the figure, and the OP kind of insisted on finding such a link. I reworded the answer to make this clearer.

Let me explain it like this. Modern compilers optimize. They do this to make things run faster. People would complain if they didn't, or switch to another compile that does optimize.
Here's an analogy. Let's say you are wondering how many cats your brother has. You call him up on the phone, and he says "two".
A week later your friend asks how many cats your brother has. You say "I'll call him up and ask him.".
Your friend says "Didn't you do that last week? How many did he have then?"
You reply, "Yeah, that's right. He must still have two cats, right? I've just saved the expense of a phone call!"
Not making the phone call is an optimization - you save time and money by not doing it. However what if your brother now has another cat? Or he gave one away? The information about the number of cats is out of date.
If your brother is a cat dealer, or frequently changes his cat configuration you might say "the number of cats my brother has is volatile - I'll have to call him up again to make sure of the number."
So, if something happens behind your back (like in your brother's house - or in a computer program in an ISR) then you need to check again each time. However if you are sure that things haven't changed (eg. in your house you would know if you got a new cat) then you can optimize by not checking each time.
I agree with Gerben's comment on this page. This is nothing to do with the compiler architecture - any more than the number of cats you have depends on the way the house is built.

volatile varaibles are used in Shared variables, because the flow can change whit compiler otimizations.
It's important to when you use timer's interrupt in sample.

Im looking for a pictorial explanation using illustrated flow chart I provided. How the variable is stored and fetched and processed in both volatile and other cases.

volatile variables are the same as variables, the diference is in the code otimization. A volatile variable is ever consistent.

Im not asking what you write about.

Volatile is a compiler only thing. It not part of the micro controller, so it doesn't exist in the diagram.

The mocrocontroles use a non-volatile program memory.
The Atmel328 has a Harvard architecture, so have a memory block for instrutions and one block for data, both are non-volatile.
If what you will is persist data betwhen a shutdown, you need use the EEPROM memory.

@rodrigo: You are mixing two very different meanings of the word “volatile”.

That's what I mean, volatile can be interpreted in two ways.

physically: Computers. of or relating to storage that does not retain data when electrical power is turned off or fails.
Logicaly: Compiler otimization rules


text:
Absolute encoder vs Accelerometer for calculating angles
I've been toying with this idea for a while and after some thorough research I'm more than happy that the project is realistic. However I'm in need of some direction in terms of the sensors I should be using.
There will be 3 arms all connected together (Like a poor mans Microscribe). I want to read the angle between each arm and use that info to calculate the final X and Y coordinates of the final end point on the arm.
I've looked closely into forward kinematics in robot arms and understand the principles are very much the same.
I've narrowed it down to Absolute encoders or accelerometers. Unfortunately I just can't find enough documentation about how to use the encoder with Arduino. There's plenty on using an accelerometer but I can't imagine the accuracy would be as good as the encoder.
I'm hoping to get the X and Y coordinate accuracy within +/- 0.5mm. Is this accuracy feasible?
The diagram attached shows the basic principle and formula I will use.

------EDIT-----
Thanks for the info everyone! Seems like this is going to be a little trickier than I originally thought. I've found a project achieving something very similar, however there's no mention of it's accuracy. http://fablab.ruc.dk/diy-digitizer/
Any ideas as to what sort of accuracy he could be achieving? I understand the length of the arms are considerably shorter than mine which must help a huge deal.

If your angle range is suitably limited using simple potentiometers is probably the easiest option.

Just a comment: why do you need a sensor? Can't you use stepper motors (which will provide better torque, AFAIK) and so avoid the need for knowing the position (you just need to zero the arm every time you boot it)

@frarugi87 stepper motors rarely have more than 200 steps per resolution. Microstepping can increase this by a factor of 16 at the cost of lower torque. That gives 0.11 degrees per step, his target accuracy would require him to gear the motor down by at least a factor of 6 to give the required accuracy. Also he would need a motor with an encoder attached in order to detect slips, if you care about absolute accuracy you can't assume a stepper did exactly what you requested.

I'm hoping to get the X and Y coordinate accuracy within +/- 0.5mm. Is this accuracy feasible?

I'm only going to consider the A1 in your diagram since the accuracy of that will have the greatest impact in the final position. For the other angles any errors will have a smaller impact on the final position accuracy.
Take the most simple case, the arm is in a straight line almost completely in the X direction.
You want a Y reading of +/- 0.5 mm with an arm length of 1400 mm. That will require an angular accuracy of +/- 0.02 degrees.
Assuming you have a maximum travel of 90 degrees and you scale things such that your full ADC range is used linearly over that range then you require log(90/0.02)/log(2) = 12.1 bits resolution on your readings. So after allowing for the noise in all sensor outputs you're looking at a minimum of a 14 bit data required to give that level of resolution.
It's been suggested you use a pot connected to the internal 10 bit ADC.
Assuming you used your full ADC range over 90 degrees and the 10 bit ADC reading had no noise on it you would be looking at around 2 mm accuracy. In the real world I'd be impressed if such a system could reach 5 mm accuracy.
Assuming you are working vertically accelerators could work, they typically have at least 16 bit resolution on the output but are noisy, you'd need to average for a long time in a very stable environment to get the levels of accuracy needed. Probably a non-starter.
A very quick google didn't find any easily available encoders with the required accuracy. I'm sure they exist but they are probably going to be expensive. You could possibly use gearing to improve the sensitivity of a more standard part but that's adding mechanical complexity.
In other words the accuracy you're aiming for isn't easy to achieve. You may want to look at relaxing your requirements a little.

Hi Andrew, thanks for taking a look. how did you go about calculating the angular accuracy? I think I could compromise on accuracy if it'd help reduce the cost of the project and make it more realistic!

The angle of a 0.5 mm error on a 1400 mm arm is asin(0.5/1400)

Is this accuracy feasible?

possible with high accuracy encoders but unlikely with accelerometers - they also drift too much.
Also, cos(x+y) can be decomposed into cos/sin(x) and (y), making a recursive calculation possible. that can be handy if you are using a lut to calculate sin/cos.

An accelerometer is not a suitable sensor for this, unless you are working in a vertical orientation (drawing on a wall), in which case you can use the pull of gravity.
It would, though, be overly complex for what is actually a very simple requirement.
Absolute encoders in the traditional (digital) sense are also not good since they don't give great resolution without an overly complex (large number of bits) interface.
The simplest option is to use simple potentiometers. They give around 270° of rotation, which should be more than enough for most uses, and are incredibly simple to interface. They give the resolution of the ADC (10 bit) and are very very simple to read (just use analogRead()).
They are also very cheap.


text:
VirtualWire `vw_get_message`: docs and examples on the PJRC site
I'm looking at he following page, that describes functions from VirtualWire library and provides some examples.
https://www.pjrc.com/teensy/td_libs_VirtualWire.html
Some basic questions I have after reading it:

The description of vw_get_message function states.

Read the last received message. This should be called only when a message is known to be received with any of the 3 functions above.

"3 functions above" refers to vw_have_message, vw_wait_rx and vw_wait_rx_max functions.
However, in the example on that very same page vw_get_message function is called from receiver's loop() without making any attempts to call any of those 3 functions first.
Why? Is it legal to use vw_get_message by itself? And how does it work in this case, i.e. what is the semantics of the return value?
The function is explicitly described as non-blocking, apparently implying that if this usage is legal, there's no way to tell "corrupted message" situation from "no message" situation.
Does the library preserve the granularity/separation of messages? I.e if the TX side sends 1-byte messages, does it guarantee that each call to vw_get_message on RX side will return 1-byte messages? It seems to be implied by the description of the protocol, but I'd like to ask just in case.
If the answer to the second question is "yes", then does this API preserve zero-length messages? Or are they discarded immediately?

http://www.airspayce.com/mikem/arduino/VirtualWire/

The example with only vw_get_message is the common usage of the VirtualWire library. It returns true if something was received and the checksum was okay.
Yes, each message is seperated from the other messages. Each message gets extra bits (intro bits) and extra bytes (checksum and length).
I don't know, I have never tested that. Looking at the source code, there is no problem with zero length messages.

The VirtualWire library is outdated, although it is still used with Arduino boards with little memory (Arduino Uno, Nano, Leonardo, Pro Mini, and so on).
The RadioHead library (www.airspayce.com/mikem/arduino/RadioHead) has included the VirtualWire protocol with the RH_ASK mode. The examples for the RH_ASK mode shows that the usage is almost the same. The RadioHead library should be used when there is more memory (Arduino MKR, Zero, Due, and so on).

That makes sense, thank you. BTW, someone mentioned in the comments (now deleted), that this usage will probably lead to vw_get_message reading the same message (and returning true) again and again from every call, until a new message is received to replace the previous one.  Do you know if this is the case?

No, that is not the case. The received message is used just once. If you look at the source code, a flag vw_rx_done is used for that. The flag is set true when data has been received, and the vw_get_message sets it to false to indicate that the new data has been read.

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


text:
Multiple timed functions (timing off)
Desired program:
I have 3 momentary push buttons and a 4-channel relay board with my Arduino Uno. The relays are connected to 2 sinks, a shower, and a pump. Each push button should turn the pump and its respective fixture on for 10 seconds. I used a time buffer to debounce the push buttons.
Problem:
The time in which the function stays on is inconsistent. Sometimes 10 seconds, sometimes 3 seconds. Additionally all the relays turn off at the same time even if they were started at different times. they should all be individually timed and the pump should stay on as long as any of the three other relays are on.
Wiring Diagram:

Code:
//initialize and declare variables
// Pins 10,11,12,13 will be connected to their respected relays
const int pump = 13;
const int relay2 = 12;
const int relay3 = 11;
const int relay4 = 10;

//initialize pins 2,3,4 to be connected to the momentary push buttons
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;

//these variables track the state of the buttons, low if not pressed, high if pressed
int buttonState1 = LOW;
int buttonState2 = LOW;
int buttonState3 = LOW;

//Initialize pin states for valve check
int relay2State;
int relay3State;
int relay4State;

long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 100; // the debounce time; increase if the output flickers
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
unsigned long runTime = 10000;

void setup() {
  //set pins connected to the relays as outputs.
  pinMode(pump, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);

  //set push buttons as inputs
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);

  //initialize the starting state of the relay pins
  digitalWrite(pump, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
} // close void setup

void loop() {
  unsigned long currentMillis = millis();
  unsigned long currentMillis2 = millis();
  unsigned long currentMillis3 = millis();
  //sample the state of the buttons
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  //check to see if any valves are open
  relay2State = digitalRead(relay2);
  relay3State = digitalRead(relay3);
  relay4State = digitalRead(relay4);
  //filter out any noise by setting a time buffer
  if ((millis() - lastDebounceTime) > debounceDelay) {
    //sample the state of the buttons
    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);
    buttonState3 = digitalRead(buttonPin3);
    //check to see if any valves are open
    relay2State = digitalRead(relay2);
    relay3State = digitalRead(relay3);
    relay4State = digitalRead(relay4);
  }

  // if button1 has been pressed, let's toggle the pump and relay2 from off
  //to on for 10 seconds
  if (buttonState1 == HIGH) {
    digitalWrite(relay2, LOW); // turn relay2
    lastDebounceTime = millis(); // set the current time
  }
  if (currentMillis - previousMillis > runTime) {
    digitalWrite(relay2, HIGH); // turn relay2
    previousMillis = currentMillis;
  }
  //if button2 has been pressed, lets toggle the pump and relay3 from off
  //to on for 10 seconds
  if (buttonState2 == HIGH) {
    digitalWrite(relay3, LOW); // turn relay3 on
  }
  if (currentMillis2 - previousMillis2 > runTime) {
    previousMillis2 = currentMillis2;
    digitalWrite(relay3, HIGH); // turn relay3 off
  }
  // if button3 has been pressed, lets toggle the pump and relay4 from off to
  //on for 10 seconds
  if (buttonState3 == HIGH) {
    digitalWrite(relay4, LOW); // turn relay4 on
    lastDebounceTime = millis(); // set the current time
  }
  if (currentMillis3 - previousMillis3 > runTime) {
    previousMillis3 = currentMillis3;
    digitalWrite(relay4, HIGH); // turn relay4 off
  }
  // if any valve is open, turn the pump on
  if(relay2State == LOW || relay3State == LOW || relay4State == LOW) {
    digitalWrite(pump, LOW);
  } else {
    digitalWrite(pump, HIGH);
  }
} // close void loop

Any help would be greatly appreciated. I think I'm stuck in the time buffer for the debounce and my time checks aren't updating right.

In a program like this it rapidly becomes quite confusing with the variable names all being so similar. Because of this, this is a good candidate for creating a class to do the job for you. This is because you have sets of functionality and variables that are duplicated to do the same job with different settings (IO pins).
It would be a trivial matter to create a class that turns on an output for a specified amount of time:
class TimedOutput {
    private:
        uint8_t _pin;
        uint32_t _started;
        uint32_t _runtime;
        bool _running;

    public:
        TimedOutput(uint8_t pin, uint32_t runtime) {
            _pin = pin;
            _runtime = runtime;
            _started = 0;
            _running = false;
        }

        void begin() {
            pinMode(_pin, OUTPUT);
            digitalWrite(_pin, LOW);
        }

        void start() {
            digitalWrite(_pin, HIGH);
            _running = true;
            _started = millis();
        }

        void run() {
            if (!_running) return;
            if (millis() - _started >= _runtime) {
                digitalWrite(_pin, LOW);
                _running = false;
            }
        }
};

// Create the object
TimedOutput shower(10, 10000); // Output on pin 10 for 10 seconds
TimedOutput sink(11, 3000);    // Output on pin 11 for 3 seconds

void setup() {
    // Configure the pin
    shower.begin();
    sink.begin();
    pinMode(2, INPUT_PULLUP); // Button
    pinMode(3, INPUT_PULLUP); // Button
}

void loop() {
    // Start it if the button is pressed:
    if (digitalRead(2) == LOW) {
        shower.start();
    }

    if (digitalRead(3) == LOW) {
        sink.start();
    }

    // Do the checking for if it needs to stop:
    shower.run();
    sink.run();
}

is there no need to debounce the button in this case?

No, not really. Once the output is on its on regardless of what the button does.

the relays start out energized. What would i need to change to have them start deenergized? this would be my last question as this code has helped a ton!

Swap the highs and lows in the digitalWrites in the class.

@NathanH. I see your buttons are pull down. You should change INPUT_PULLUP to INPUT and check if the input is HIGH not LOW.

Take a modular approach to it.
For example, break the functionality intwo two pieces.
Readbutton1() returns 1 if and only if button 1 has been pressed and it passed debouncing. There are tons of ways to do that.
Energizerelay1() is called to energize relay number 1 for 10 seconds. Again, there are tons of ways to do that.
Then you can integrate them all together in your loop.
Fairly easy. The key to any programming is to break down a task into individual modules and then reintegrate those modules together to perform the desired the task.
Coding those individual modules is often simple.


text:
How to embed a 5V-range Arduino-based controller in a 12V-range DC circuit?
We have an installation that provides:

a common line (C), which divides into two wires;
an input line (I), which carries the signal from a button (between I and C there's normally 0V, and 12V when the button is pressed);
an output line (O), which carries a signal to a bell (between O and C there's always 12V).

simulate this circuit – Schematic created using CircuitLab
A controller is to close the OC circuit every time a given temporal pattern shows in I (say, a concrete Morse-like -short/long- sequence of pulses), so the bell will ring if the concrete word is recognized at the input. Such a controller has been implemented in C++ and uploaded to an Arduino Nano, and it works fine on a protoboard, with a button as input and led as output, all in the same electrical range.
Since both the IC and the OC are 12V circuits, and the controller is in the 5V range, what is the minimal circuit to embed the controller between the IC and the OC circuits?

You may wish to look at: https://electronics.stackexchange.com/questions/43498/how-can-i-use-a-12-v-input-on-a-digital-arduino-pin and https://electronics.stackexchange.com/questions/167411/how-to-mosfet-to-drive-12v-relay-from-microcontroller-logic-high-is-3-3v-using

easy:
1) use a transistor's b-c junction;
2) use a mosfet;
3) use a relay, solid state or mechanical;
4) find a chip with 12-compliant pins;
...

Just use a transistor that can handle 12V with the base connected to the Arduino and that's it...
Maybe I didn't get what you were trying to say, but anyway, I think that's what you are looking for.

I think you can use "mosfet" control 12v with 5v voltage also if you think this is insufficient you can add the relay, control relay with mosfet without how much voltage as you want.
I made disco lights with rgb strip led and when I run the circuit different time and different type of led turn on and turn off I used 3 mosfets and 3 arduino outputs the strip led work with 12v.


text:
3 AC current sensors using one Arduino Uno board measuring at 200Hz
I'm new to electronics and need some help please.
I'm planning to measure current of a 3-phase output using one sensor for each phase (thus 3 sensors would be required). The frequency of data recording should be 200 Hz.
Performance/data transfer wise: Is one Arduino Uno board enough to plug in the three sensors and get the data transferred using the USB cable onto a PC? Or should I get one board for each sensor?
I appreciate your help.
Cheers.
lorena

what is the voltage ? If it is less than 5 volt you can use the internal interupts, the uno board have 3 such interupts

See Arduino Stackexchange https://arduino.stackexchange.com/questions/699/how-do-i-know-the-sampling-frequency

You also asked the question with the EmonLib: https://arduino.stackexchange.com/questions/45353/setting-reading-frequency-sct013-current-sensor-code-using-arduino-uno Please explain what you want to achieve and why you need 200 samples per second for a 50Hz or 60Hz signal.

Is the sampling speed enough?

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.
Ref.: https://www.arduino.cc/en/Reference/AnalogRead

Is the USB port fast enough?

The serial speed over USB is maximum 2Mbps and a fast calculation (200 samples/s x 3 sensors x 10 bit) 18kbps, so 2Mbps should be enough.


text:
Programing a Mini 05 without a USB-to-serial converter
I have an Arduino Mini 05 clone Wattuino, an Elegoo Mega, a Powerboost 1000c, but not access to a USB-to-serial converter. Is there any way to program the Arduino Mini with these devices?
I tried to search it but they only mention using an Arduino uno as the chip can be put out of the board. Discusion

You can use the Mega. The only reason for "removing the chip from the board" is to disable it so it doesn't respond to the serial data - you can also disable it by just connecting the RESET pin to GND.


text:
433Mhz receiver only get values of 0, 1, 2
I have two Arduino Uno and a few sets of transmitters and receivers. I followed some guide on the internet to make them work and that's what I did so far but I still get random values of 0 or 1 or 2, no matter what signals I am trasmitting.
I connected the receiver's VCC to 5v on Arduino; the receiver's data to A0 on the Arduino; the receiver's GND to the Arduino's GND.
I connected the transmitter's VCC to 5v on Arduino; the transmitter's data to  on Arduino; the transmitter's GND to the Arduino's GND.
This is the transmitter code:
#define dataout 12
#define ledPin 13
unsigned int temp = 0;

void setup() {
  pinMode(dataout, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {

  digitalWrite(dataout, HIGH);
  digitalWrite(ledPin, HIGH);
  delay(5000);
  digitalWrite(dataout,LOW);
  digitalWrite(ledPin, LOW);
  delay(5000);
}

This is the recriver code:
const int datain=A0;
#define ledPin 13

int temp = 0;
const unsigned int upperThreshold = 500;
const unsigned int lowerThreshold = 100;

void setup() {
  pinMode(datain, INPUT);
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  temp=analogRead(datain);
  Serial.println(temp);
  delay(300);
  if(temp<lowerThreshold) {
    digitalWrite(ledPin, HIGH);
  }

  if(temp>upperThreshold) {
    digitalWrite(ledPin, LOW);
  }
}

I tried to change the transmitter and receivers. I tried to change Arduino boards. I tried to change analog to digital, nothing worked...
Suggestions?
Update:
Here are some pictures of my gear:

This is the output of the receiver when both Arduinos work near each other, there no sync between the signals transmitting and receiving.

0 1 0 0 0 0 1 1 0 2 1 2 1 0 1 362 0 1 1 1 1 1 0 2 0 314 2 2 1 0 0 2 1
  0 1 2 1 1 2 0 1 1 0 1 1 2 1 0 0 0 0 2 1 0 1 0 0 1 0 1 0 1 1 1 2 2 1 1
  2 1 1 1 1 1 0 211 2 0 2 0 0 1 2 0 0 759 1 2 1 1 2 1 2 0 1 16 0 0 1 1 0
  0 2 1 1 0 1 2 1 2 0 2 1 0 2 0 1 2 1 1 2 2 1 2 0 0 1 0 1 1 2

This is the output when I tried to disconnect the GND and VCC from the receiver:

433 426 431 422 379 367 362 394 405 412 406 394 399 388 356 258 193
  438 507 507 499 486 478 473 449 442 431 428 427 424 425 423 422 419
  417 414 413 413 409 410

I thought the typical 433 device used a modulation of the carrier signal to transmit the data.  You end up using it like a Morse code system.  Your code needs to be a lot more complex than that, or use a library.  Of course I might be wrong, because I don't know what gear you are using (post a picture/part number/data sheet).

The receivers probably don't receive a DC voltage, only a stream of bits. You probably need a library and digital pins and interrupts. Please tell which transmitter and receivers you have, and give a link to that guide,

I updated my post,
Code Gorilla - how can i use a library? i tried to use virtual wire but failed...
Jot - the receiver do receive DC voltage as you can see in the outputs i got

Those cheap 433 MHz RF modules require a (good) library to work. The VirtualWire/RadioHead library is the best.
The VirtualWire library it outdated, but still used.
The RadioHead library has a few bugs fixed, but uses more memory.
Use it in RH_ASK mode, see the included 'ask' examples.
[Update: better quality]
Most cheap 433 MHz ASK transmitters work with 3.5 to 12V. They have the longest range at 12V. About 20 meters is no problem with 5V, but if longer range is needed then transmitters that are only made for 5V are better.
The cheap 433 MHz receivers use a coil to tune the frequency. They are very sensitive and they do work well. However, when such a module is placed near metal or close to the Arduino, the frequency might change. Modules that use a crystal for the frequency are better. Sometimes a sensitivity is mentioned (for example -112dBm) but I don't know how reliable that is. When an antenna of 16 cm does not work well, try an antenna of more than a meter.
The transceivers are better for wireless data transfer, but that depends on the use.
Sparkfun has Wireless Buying Guide.
RadioHead has a list of supported transceivers.
The nRF24L01+ are very cheap. I read that every one of them on Ebay or Aliexpress is counterfeit, but the counterfeit chips do work. They work at 3.3V, and are 5V tolerant.
The CC1101, CC2500 and so on are good, but not often used with an Arduino. The same for Si4432, Si4436 and so on. If you know a good library, they are very good transceiver chips.
Adafruit is using the RFM69 a lot. For example the Feather Packet Radio board.
Last but not least: don't forget Wifi and Bluetooth.

can you please recommend me on some good transmitters and recievers?

@user35399, I have added a "Update: better quality" section.


text:
firebase arduino uno + esp8266
I am trying to make a project that can read data from usbsheild connected to arduino uno board then send them to firebase through esp8266.
But the libraries of firebase and esp8266wifi that i found are not for arduino uno but for the esp8266 board can anyone help me in this problem ?

The best way you can do is connect it to a web and then use firebase-php library

https://github.com/ktamas77/firebase-php/blob/master/README.md

insert this
Follow this as your guide

https://stilllot2learn.wordpress.com/2017/11/18/arduino_gps_gsm/comment-page-1/#comment-47

Don't forget to create your FIREBASE ACCOUNT

look for database secret as your TOKEN under User and Permissions
  TAB


text:
ATmega 32A and 2560 R3 register to pin mapping?
I've been doing research for the last few hours trying to determine the mapping of physical pins to memory-mapped I/O registers for the Arduino Mega board (which is an ATmega 2560 R3).

My code is on GitHub in a pull request, but hasn't been merged yet because I'm not finished yet.
This is the upstream example I'm working from, which was written for an ATmega 32A.
Here is Arduino's 2560 pin mapping which doesn't tell which registers are mapped to which pins.
Here is avr/iomxx0_1.h which defines the ports with simple numbers that I can't make heads or tails of.
Here is a collection of links relevant to my research.
I broke down and cross-referenced all of the uses of memory-mapped I/O registers in the upstream example.

Some of the registers used include CS11, DDB4, DDRA, DDRB, GICR, INT0, INT1, ISC00, ISC10, MCUCR, PA0, PB5, PB7, PD2, PD3, PIND, PORTA, PORTD, SPCR, SPDR, SPIF, SPSR, TCCR1B, and TCNT1. I can't figure out which pins these are and/or what they do.
Here is a diagram provided by the upstream example:

Unfortunately, I'm not very good at reading these diagrams so I'm doing my best.
How can I determine the mapping of these registers to physical ports on both the ATmega 32A, which is the board the example was originally written for, and the ATmega 2560 R3, which is the board I'm currently working with?

Here is an alternative GPIO mapping: https://github.com/mikaelpatel/Arduino-GPIO/blob/master/src/Hardware/AVR/Board.h#L225, Please note the Register and Pin bit mapping, names, etc.

What is ATmega2560 R3? There is ATmega2560 MCU or Arduino Mega R3. do you want the mapping of pins of Arduino Mega or the pins of the ATmega2560 MCU.
The mapping of pins of the ATmega 2560 chip is in the datasheet.
The mapping of the Arduino Mega pins to ATmega2560 pins and registers is in the schema of the board or in the Arduino AVR boards package variants mega folder.
The link "Arduino's 2560 pin mapping" in your question shows the mapping too. Registers are PA, PB,... and every register covers to 8 pins with the 8 bits of the register. For example PB3 is pin 50 of the board.

This is the exact board that I bought, and I'm looking for a reference on which pins on the board correspond with which registers exposed in the avr C library. The schema doesn't seem to list things like PORTA and so on that are referenced in the code I'm working from.

it is an Arduino Mega clone. the link to schema is in answer.

Because I'm porting code that I did not write. I need to understand what the code is actually doing before I can start porting it to my board.

but the schema clearly shows the register to board pin mapping. and that is what you asked. and the link "Arduino's 2560 pin mapping" in your question shows it too

I added something to the answer

@NaftuliKay, did it help?

Atmega32A is a 44 pin TQFP part with 4 8-bit IO ports.
It is kind of a crippled Atmega1284P. You may have an easier time just switching to a 1284P chip (also 44 pin TQFP) to take advantage of its 16K byte SRAM and 128K byte flash. There's an easy to use add-in to the Arduino IDE to use it.
https://github.com/MCUdude/MightyCore
I do a lot of 1284P designs and use it all the time.
Atmega2560 is 100 pin TQFP part with 10 8-bit and one 6-bit IO ports.
As your schematic only uses a few IO pins, the electrical connections will be simple - SPI for bootloading or downloading code
- 2 pins for serial
- 2 pins for other IO
If you look at the Arduino Mega2560 schematic, you can pick those out pretty readily.  The rest you will have to tweak up in your code.

he has a Mega. nothing special

I'm hoping to start with the board that I have (mega 2550) and then use conditional compilation to support other boards. I'm having a hard time with the schematic, as it doesn't seem to list which registers map to which pins, e.g. what is PORTA and what is it mapped to in avr's C library and what does it do? Is there a reference I can look at to determine this?

The IDE already does that mapping. For example, on  '328P board, Port D is D7-D0, PORT B is D13 to D8 (upper two bits not used as IO), Port C 9 is D19 to D14. (upper two bit not used as IO).  Used to be that you could look at pins_arduino.h (I think that's the name) in the IDE folders for a particular board and read the mapping from PINx/PORTx to the IO pins.  I can't access arduino.cc from here to provide links to the specific boards, and I don't have them on this computer.