text:
Clearing EEPROM
I'm trying to clear my EEPROM and am using this code:
#include <EEPROM.h>
void setup()
{
// write a 0 to all 4096 bytes of the EEPROM
for (int i = 0; i < 4096; i++)
EEPROM.write(i, 0);

delay(9999999);
}

void loop()
{
}

I don't see a problem with it but it is ineffective.  Am I missing something?

from memory, you need EEPROM.commit(); or maybe EEPROM.end(); after writing

Aaaaaah! Of course! Thank you.  Stupid stuff like this drives me crazy.

Although, that MAY just be on the ESP8266 judging from the sample sketches

What do you mean "ineffective"? The EEPROM is not cleared? Or only some is? If so, how do you know? Which Arduino do you have?

Ineffective in thwt the eeprom was not erased.  Nothing changed after I ran this sketch.  I saved "TEST01" to eeprom and it was still there after I tried to erase it.

Note that empty EEPROM is all 1s, not all 0s. Write -1 instead.

I am nitpicking but... when you EEPROM.write(), you are actually erasing an EEPROM cell, then writing a new value into it. This takes 3.4 ms, irrespective of the value written. You could do an erase-only operation, which takes only 1.8 ms. It looks, though, like this cannot be done with the Arduino EEPROM library, and not even with <avr/eeprom.h> from avr-libc. You would have to access the EEPROM address and control registers directly, as documented in the datasheet of the MCU.

Thankyou for this sketch , It works perfectly for me. I added a two lines to turn on LED after the sketch completed.

The tutorial here is very clear about how to clear the contents of the Atmel's EEPROM.  I only see 2 major difference.  The tutorial finds the size of the EEPROM through a function call.  Probably much safer.  And there is no call to a delay() function.
The tutorial does include lighting up an LED when finished.  And @Edgar Bonet is correct that erasing an EEPROM (altering each floating gate with in the chip) does take time.  And you have no way to known when the EEPROM clearing is finished in your code.
It is possible you are forcing your code to stop before it is finished.  In which case it would appear the EEPROM is not completely cleared.

Thank you all for helping me out.  This is what I ended up using (ESP8266 1.0 12E with Arduino IDE):
#include <EEPROM.h>
#include <ESP8266WiFi.h>

void setup()
{
  Serial.begin(115200);
  EEPROM.begin(512);
  delay(5000);
  Serial.println("clearing EEPROM...");
  // write a 0 to first 1000 bytes of the EEPROM
  for (int i = 0; i < 1000; ++i) {
    EEPROM.write(i, -1);
 }
  EEPROM.commit();
  delay(5000);
  Serial.println("Reading EEPROM ssid");
  String esid;
  for (int i = 0; i < 64; ++i)
  {
    esid += char(EEPROM.read(i));
  }
  Serial.print("SSID: ");
  Serial.println(esid);
  Serial.println("Reading EEPROM pass");
  String epass = "";
  for (int i = 64; i < 128; ++i)
  {
    epass += char(EEPROM.read(i));
  }
  Serial.print("PASS: ");
  Serial.println(epass);
}

void loop()
{
}

It's probably longer than it has to be but I pulled stuff from other sketches I've worked on and prioritize function over form.  This writes a "-1" to the first 1000 bytes and then prints the first 128 bytes.  Since I am only concerned about the first 50 bytes or so this was sufficient for my needs.


text:
What does "+=" mean?
I'm working with an esp8266 and want to have it default to an access point when it cannot connect to a wifi network.  I'm using chriscook8's example from github here.
chriscook8 uses "+=" in several places and I can't find an explanation of what that means.
Here is an example from setup():
void setup() {
  Serial.begin(115200);
  EEPROM.begin(512);
  delay(10);
  Serial.println();
  Serial.println();
  Serial.println("Startup");
  // read eeprom for ssid and pass
  Serial.println("Reading EEPROM ssid");
  String esid;
  for (int i = 0; i < 32; ++i)
  {
    esid += char(EEPROM.read(i));  //<- here
  }

What does += do?

This belongs on stackoverflow.com, not here. Stackoverflow is the site for programming questions, as this asks about C++'s syntax.

Google for C++ operators

It adds the value or variable on the right to the variable on the left and assigns the result to the variable on the left.
A += B

is the same as:
A = A + B

It's short-hand.
In the case of a String it concatenates the right hand item on to the end of the left hand item.

Thank you.  Is it considered better form to use +=?

It makes no real difference. It's just quicker to type. Also it's a historical thing - when storage space was at a premium saving bytes here and there could make a difference. I recall at University I had a maximum storage space of 4MB for all my work on the servers. Saving space like that was good.

I'm not sure it's correct to say that it "assigns the result to the value on the left. A "value" is the result of evaluation; you cannot assign anything to a value. The right word would be variable, or maybe location.

The computer will not function differently with A += 1 or A = A + 1, but the code is simply easier to read.  If your variables are more descriptive, say AmountOfDaysWorked, then AmountOfDaysWorked += 1 is easier to read than AmountOfDaysWorked = AmountOfDaysWorked + 1.  It gets worse if you have to add a variable to another variable.

@Sahuagin: You're right that value is not precisely correct. But neither is variable: I can assign to str->field, but this is not a variable; it is a (compound) expression. The term you are looking for is lvalue ("ell-value"), which is merely "something that can appear on the left-hand side of an assignment expression." (Circular? Perhaps. But that is the term.)

@wchargin I forgot about the word "lvalue". Its name suggests that I may have been wrong to say that "value" was incorrect, though I think "value" alone generally means "rvalue". "Variable" is correct in this specific case, though isn't the broadest possible term.

@sahuagin agreed!

+= is a common programming shortcut. An example: (pseudo-code)
num1 = 7
num2 = 15
#these two lines are exactly the same
num1 += num2
num1 = num1 + num2

+= is extremely useful for increasing the value of a variable by another variable. It also works similarly with -=, *=, and /=

The assignment versions of binary operators include the arithmetic, bitwise logical, and shift operators: *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, and |=. Expr1 = Expr2 is equivalent to Expr1 = Expr1  Expr2, except that Expr1 will only be evaluated once (important if Expr1 has side effects).

In the earliest days of the C language (I'm talking late 60's here), the compilers did not do much (if any) optimization, and a lot of the constructs in C were put in so that a programmer could get a more optimized program by using hints like +=.  So, in those days, A = A + 5 generated three PDP11 instructions, while A += 5 was only a single PDP11 instruction.  That meant that most programmers learned to write it that way.  But because it was more concise and to many also more readable, the C constructs with <op>= have made it into most modern languages.

But as other comments have said, general programming questions have their own StackExchange sites...actually several of them...

source: Stack Exchange

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

sort: votes


text:
TFT screen to change sketches
I have an Uno + WiFi 101 thermometer and I'd like to be able to take it places and easily change WiFi network SSIDs and passwords.  Can I use a TFT screen to make these changes to a sktech or am I stuck using a PC and IDE for this kind of thing?
Can someone provide a sample sketch of what this might look like?  I want to know it's something that's possible before I spend the money on a TFT.
It's possible (let's face it, LIKELY) that I fundamentally misunderstand the capabilities and limitations of the TFT screen.  Sorry for the noobish question.

The screen is just a screen. You can do whatever you like with it.

So...you can use it to modify sketches and not just view output?

If that's how you've written your sketch.

That is encouraging.  I hope that someone can provide more detail.  My research continues.

All the TFT does is display things -- it's just a screen.  What Ignacio is saying is that if you have written your sketch to be able to modify itself, then you can use the screen to display a user interface.  The screen can't modify your sketch.  Your sketch technically can modify itself, but it is very difficult to do so and would require a custom bootloader.  It would be a lot easier to store the data that can be modified in EEPROM.

If you post that as the answer I'll close this out.

A TFT screen is just a screen. You can't modify SSIDs and passwords with it, any more than you can by poking your PC monitor (unless perhaps you have a touch-screen*). To modify things you would need:

An input device (eg. a keypad)
A method of displaying what you are entering (this is where the screen would be handy)
A method of storing the new information. You could store things like passwords in EEPROM.
Code to make all that work.

* Some distributors sell touch-screen interfaces designed to go on top of screens - this might conceivably be what you are thinking of. However you still need the touch-screen, and code to make the touch-screen, and the TFT screen, work.

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


text:
EEPROM - Storing Static Data
I'm trying to store four items to EEPROM.  I can do one item no problem, I just don't know how to make the jump to multiple items.
My code:
#include <EEPROM.h>
char sgrpID[31] = "acpilot's arduino";
char addrID[51] = "123 any street rd";
char zpcdID[11] = "12345";
char gwayID[31] = "what a cool toy!";

void setup()
{
  Serial.begin(9600);
  for (int i = 0; i < 6; i++) {
    EEPROM.write(i, sgrpID[i]);
    EEPROM.write(i, addrID[i]);
    EEPROM.write(i, zpcdID[i]);
    EEPROM.write(i, gwayID[i]);
  }
}

void loop() {
  Serial.println(sgrpID);
  Serial.println(addrID);
  Serial.println(zpcdID);
  Serial.println(gwayID);
  delay(99999);
}

I want to be able to call on these in a sketch and post them to a db along with dynamic data of some flavor (TBD).
Am  on the right path?  Any help, corrections, or general guidance is appreciated.  I've moved beyond the "novice" stage of basic Arduino programming but an completely new to EEPROM.  If in doubt, SLOWER AND LOUDER is by far the best way to communicate key EEPROM concepts to me.
I have reviewed the Arduino EEPROM library but I was reading Greek.  I keep reading it and I'm sure at somepoint I'll recognize a pattrn and start to "get it."

Some things I noticed in your code:

You are writing everything to the same address (is that intentional?)
You are only writing the first 6 six bytes of your arrays (I am pretty sure that is intentional)
You are declaring these arrays to be bigger than what you are putting in them (this is again probably intentional, but I am just guessing)

So here is an example of how I would handle the eeprom:
#include <EEPROM.h>

char sgrpID[31] = "acpilot's arduino";
char addrID[51] = "123 any street rd";
char zpcdID[11] = "12345";
char gwayID[31] = "what a cool toy!";

//These are the definitions of what goes where in memory
//You do not want everything to have the same number
const size_t SGRP_ID_EE_START = (0);  //Zero is good address to start
//To get the next address we merely add the size of the first item
//With the address of the first item
const size_t ADDR_ID_EE_START = (sizeof(sgrpID) + SGRP_ID_EE_START);
//And so on and so forth
const size_t ZPCD_ID_EE_START = (sizeof(addrID) + ADDR_ID_EE_START);
const size_t GWAY_ID_EE_START = (sizeof(zpcdID) + ZPCD_ID_EE_START);

//Use this function to write a char array to the EEPROM at
//The address "address" (and the size of "len")
void WriteEepromArray(size_t address,char* arr,size_t len){
  for (size_t x = 0; x < len; x++){
    EEPROM.write(address+x,arr[x]);
  }
}
//Use this function to load your char array with values from
//The EEPROM
void LoadFromEeprom(size_t address,char* arr,size_t len){  //Be aware that this function modifys the data pointed to by "arr"
  for (size_t x = 0; x < len; x++){
    arr[x] = EEPROM.read(address+x);
  }
}

void setup()
{
  Serial.begin(9600);
  //Some sample writes
  //               starting address----array-----size of the array
  WriteEepromArray(SGRP_ID_EE_START   ,sgrpID   ,sizeof(sgrpID));
  WriteEepromArray(ADDR_ID_EE_START   ,addrID   ,sizeof(addrID));
  WriteEepromArray(ZPCD_ID_EE_START   ,zpcdID   ,sizeof(zpcdID));
  WriteEepromArray(GWAY_ID_EE_START   ,gwayID   ,sizeof(gwayID));
  //Use the following to load:
  LoadFromEeprom(SGRP_ID_EE_START,sgrpID,sizeof(sgrpID));
  Serial.println(sgrpID);   //Now it should be loaded

}

The comments I hope help....otherwise comment below with what I left out.

Answers to your bullets: no; that's an error, should be the length of the string, not just 6 bytes; yes, I'm allowing for longer names than what I'm using.
I follow the flow but some of the commands are new.  I don't know what this means, for example:
for (size_t x = 0; x < len; x++){
arr[x] = EEPROM.read(address+x);.
If I need to recall the "sgrpID", for example, and use it in a sketch do I simply use:
for (size_t x = 0; x < len; x++){
arr[x] = EEPROM.read(sgrpID+x);?

I've spent many hrs trying to get a Serial.println() out of this and i haven't a clue as to what I'm doing wrong.  Can you dumb it down more than you already have?  I'm doing something like "WriteEepromArray(size_t GWAY_ID_EE_START,char* gwayID,size_t len)"...with no luck.  I understand for the most part what's going on (or supposed to happen), I just can't make it spit a string back out.

@acpilot To read the eeprom do LoadFromEeprom(SGRP_ID_EE_START   ,sgrpID   ,sizeof(sgrpID));.  This will then cause the sgrpID array to be loaded with whatever was in the eeprom.  Try that.....if that doesn't work let me know......

@acpilot PS: If you were wondering what the size_t was all about.....that is just a type (like int or char) whose max value is the maximum size of an array.....so it makes sense to use that in a loop.....but in order to have a simpler view of it just imagine that it says int there.

Serial.println(LoadFromEeprom(GWAY_ID_EE_START,gwayID, sizeof(gwayID))); // generates "invalid use of void expression."  Evidently this means that the void, as I've written it, will not return a value.  Do you see an error?  I've been trying different things for a few hours...I promise that I'm not just fishing for a spoon fed answer.  I see where you're going and am trying to wrap my head around it.  Also tried defining "#define MemLoadGway = LoadFromEeprom(GWAY_ID_EE_START,gwayID, sizeof(gwayID));" and see a similar error: "in expansion of macro 'MemLoadGway' invalid use of void expression."

I also tried as a String(MemLoadGway); and String(LoadFromEeprom(GWAY_ID_EE_START,gwayID, sizeof(gwayID))); without success.

@acpilot Added an example of reading....hope that helps

I see.  I was going about it all wrong.  It works perfectly.  The new problem is the quantity of data being sent over WiFi causes and incomplete post to the db, but that's a topic for another post.  Thank you DarthRubik.  You condensed what would have taken me weeks into mere days.

@acpilot Glad I could help


text:
Digital Pin State - Some 1, Some 0
I'm running a sketch that looks for inputs to digital pins 3, 4, 5, 6, and 7.  The gist of the sketch is that it's a digitalRead() from 3-7 with a Serial.println() to the monitor. The odd thing is that without any pins connected I'm seeing "0" on some and "1" on others.  I there a reason some will be "0" while other are "1" without anything connected?  I imagine that all pins should read "0" until voltage is detected.
Based on my limited experience I draw the conclusion that a pull-up resistor will likely resolve my problem.  Thoughts?

Yep, in fact I would configure them as INPUT_PULLUP (which uses a built-in resistor), unless you are actually wiring pull up resistors of your own to them.
Also the Digital pins Tutorial has a bit more info on the modes possible.

The effect you are seeing is the result of floating pins.
Because the inputs are not at any defined voltage level and will 'follow' the voltage applied. So leaving them unconnected with no defined state will make it look as if its picking up stray signals.
Adding a pull-up resistor, or a pull-down resistor will give you a known  state, the value can be anything from 4.7kohms to 100kohms. So your conclusion to use a resistor is correct.


text:
Square LED vs Round LED
I'm trying to choose between square or round LEDs.  I would like to select an LED that will "project" light and I cannot find any information comparing the two types.
Which style of LED will project light better?
Projection, for the purposes of this question, means casting light "in-line" with the LED.  For example, an LED right out of the box with straight leads plugged into a breadboard on a flat table will stand vertically.  In this case, I would like to project as much light onto the ceiling as possible.  I hope this makes sense.
If it matters, I'd like to use water clear blue LEDs.

Go with the round ones. The curved top acts like a lens, making it shine light in a bundle.

Many of the square or rectangular LEDs with leads  – that is, not surface mount devices (SMD)  –  that I've seen are intended for use as panel indicator lights, so are not very bright.   On the other hand, among SMD devices square, rectangular, and round lights run the whole gamut of brightness.  Of course many white LEDs, square or round, are extremely bright because of being intended for illumination.
For projecting a beam against a ceiling, adding optics to the LED may be the best approach.  For example, buy some 99¢ flashlights like “Waterproof 3500LM Pocket LED Flashlight Zoomable LED Torch Mini Penlight Light” on ebay, and either add a blue filter in front of the lens or replace the LED with an ultrabright blue LED, using the zoomed-out flashlight lens to concentrate the light.  Also, search for 10° or 15° “PMMA LED lens” on ebay, Amazon, aliexpress, etc.
Note, for determining if any given LED will project a tight bright beam, look at the angles of its beam pattern.    This diagram (from Led Buying tips at sunriseled.us) contrasts the intensity of a 30°-beam LED with that of a 70°-beam LED.  The diagram at left below (from dimmable-gu10.com) is typical of intensity-vs-angle diagrams, which usually are shown on a polar plot like that, with a narrower oval corresponding to a tighter beam.  The diagram at right below shows the same information, in a perhaps more easily comprehended form.


text:
Open WiFi Configuration Automatically
Is it possible to have an Arduino Uno + WiFi 101 recognize when the USB cable has been connected and prompt a user to enter a network name and password?
Can this be stored on the Arduino itself or does it need to be something run locally on the user's PC?

Prompt the user where? The serial monitor? What do you want to be stored on the Arduino?

Good questions. I'd like a window with a few text fields to open. The user will input the network name and network password and press a submit button. The submission will amend the sketch and replace the old name/pass with the new. The file that opens the window would be stored on the Arduino (or is that unwise/not possible?).  A clean-ish ui would be better than the terminal but the terminal would work I suppose.  A user should not have to download and install the IDE.  Think parents and non-tech friends

To render a UI, you need a PC program. It would handle presenting an interface as well as communicating the user's input to the Arduino over UART. I would recommend writing your own program as it would give you a lot of freedom in the UI design. Processing and Python are good options. To avoid using the IDE, you'll need a USB-TTL adapter cable. If you use the default USB connection, you need the drivers which only ship with the installer AFAIK. To detect the COM port, you can either have the user check the Device Manager or make your program auto-detect it, though this isnt very reliable. This link shows some Python code on detecting the Arduino's port or at least, displaying a list of open ports and allowing the user to choose. You can set the baud rate and other stuff permanently in your code; the COM port is the only variable. Also all handshaking b/w the Arduino and PC can be done without the knowledge of the user.
That said, there are already existing programs (for most common OSes) that can provide minimal functionality. If you dont need a fancy GUI, then putty (on Windows) can serve to read input from a user and pass it on to the listening Arduino. You can use putty's default baud rate (9600) in your Arduino sketch so that the user doesnt have to set this. Again, the COM port must be known. Device Manager is the only real option.
With this second approach, you could make a user enter some string (or even a char) in putty to prompt the Arduino to ask for the SSID and password. Once the Arduino is powered, it does nothing but wait for that input string and once it receives it, it sends something like: Enter SSID: , the user complies (and presses the Return key to terminate) and this is repeated for the password. The Arduino sketch would look like this:
#define MAX_LEN 20  //max length of name or password

char PROMPT[] = "ready\r"  //the initial string input from a user
char SSID[MAX_LEN];  // buffers for the ssid and pwd
char PWD[MAX_LEN];

init_done = 0;  // this var is set when an ssid and pwd have been received

void setup(){
  Serial.begin(9600);
  //anything else
}

void loop(){
  if (!init_done)
    continue;
  //  your other code
}

void get_data(){
  Serial.print("Enter Network SSID: \r\n");
  while (Serial.available() == 0);  // wait for input

  // no timeouts used here; wait till user presses return key
  int i = 0;
  char c;
  while (i < MAX_LEN - 1){  // read chars till the buffer is almost full
    c = Serial.read();
    if (c == '\r') // means end of input
      break;
    SSID[i++] = c;
    while (Serial.available() == 0);  // wait for next char
  }
  SSID[i] = 0;  // null terminate
  while (Serial.read() != -1);  // flush serial buffer

  Serial.print("Enter password: \r\n");  //same as before
  while (Serial.available() == 0);

  i = 0;
  while (i < MAX_LEN - 1){
    c = Serial.read();
    if (c == '\r') // end of input
      break;
    PWD[i++] = c;
    while (Serial.available());
  }
  PWD[i] = 0;
  while (Serial.read() != -1);

  //Serial.print("Done.");
  init_done = 1;
}

void serialEvent(){
  if (!init_done){
    while (Serial.peek() != PROMPT[0]) // read off any garbage
      Serial.read();
    int i = 0;
    while (1){
      if (Serial.peek() == PROMPT[i++]) // compare received chars to PROMPT
        Serial.read();
      else
        return

      if (i == sizeof(PROMPT)){ // read enough chars
        while (Serial.read() != -1);  // flush the buffer
        get_data();  // get ssid and so on
      }
    }
  }


text:
FCC Certification
I noticed that both the Uno and Wifi101 are FCC certified.  Does this mean that these components can actually be used in commercial applications?  This never really occured to me before I noticed the markings.
I'm sure there is more to a commercial product than just FCC certification but I know that the certification process isn't cheap!

FCC certification is not transfered just because components are certified. You can have a non-certified transmitter that is shielded so that the product becomes FCC certified. Anyway, please improve your question as it is relevant for anybody considering using Arduino as a starting point for a product.

Recommend changes.  I do not know what you mean by "improve your question."

@acpilot
in my opinion, your scenario makes the product compliant for commercial use as i beleive arduino guys got all required certificates before bringing products to the public Jake C
I am unable to comment due to less reputation points. thanks alot for your detailed answer.can i borrow your advise for this:if we are making an IoT product that contains this arduino mkr and couple of sensors like DHT11 etc, what kind of certifications needed apart from FCC?and do we need certifications for sensors that are collecting data only (temp sensor, smoke sensor, fire sensor etc)

These products are not certified, they merely have been verified and issued a Declaration of Conformity. The WiFi module on the WiFi shield itself has been certified, as indicated by the FCC ID on its label.
To explain what that means, I am going to give a simplified explanation. If you are looking to make a commercial product and you are not sure what you need to do to be compliant, hire out a professional to help you through the process.
In the eyes of the FCC, devices fall into one of two categories, devices that are intentional transmitters, and devices that are not. Devices that are intentional transmitters need to be certified. Certification is a process of making sure that it is only transmitting on the frequency band it specified, that it is maintaining certain power limits, and that it will not cause interference with other devices. This is a very expensive testing procedure.
Devices that are not intentional transmitters, only need to get a verification. What this means is that the devices is not designed to transmit anything and is test to makes sure that it indeed does not. If you pass the verification you are issued a Declaration of Conformity basically stating that the device is not unintentionally transmitting any frequencies. This is usually a lot less expensive than than certification (but still in the few thousand USD range).

So taking the WiFi shield as an example, the module shown above circled in red is an intentional transmitter, i.e. it is designed to transmit on a particular frequency band (in this case 2.4 GHz ISM band). The device is certified to make sure that its emissions are within FCC specifications and it is issued an FCC ID.
Now at this point only the module is certified and is good to be used in a product, however, now that it is on a shield with extra circuitry added to it, the extra circuitry could be unintentionally transmitting. So now the whole shield is tested to make sure that the added circuitry does not have any emissions exceeding the FCC specifications and is issued a Declaration of Conformity.
So now fast forward to making your own thing, the module is certified, the WiFi shield and the Uno are verified, you add your own additional circuity around those components that may emit electromagnetic fields. You now may have to get your product verified to ensure that the added components to the system have not caused it to unintentionally emit radio frequencies.
The whole process, conditions, and requirements are a lot more nuanced than my description above. So this should in no way be used as the basis for product development or legal advice.
(Image borrowed from https://www.arduino.cc/en/Main/ArduinoWiFiShield101)

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


text:
WiFi.setOutputPower();
I'm trying to cut my esp8266 range down to about a meter to save power.  I know that I can adjust output power but I don't know enough to understand what a given setting will actually yield.
I can set zero to kill it or 20.5 to set max range, but what setting is appropriate for a meter or so?  Is there a rule of thumb?

The actual WiFi range is highly dependent on many more factors than just the TX power:

The antenna gain, directionality, and orientation of the receiver
The antenna gain, directionality, and orientation of the transmitter
The proximity of radio-reflective objects nearby (metal)
The proximity of radio absorbing objects nearby (humans)
RF Black Magic

In practice, test your situation by running a series of tests at lower and lower power settings until you get an unreliable connection, then bump it up a couple of notches from there.
Do not rely on transmitter power for security, however. You cannot stop someone from pointing a high-gain antenna at your device and communicating with it from a distance farther than 1 meter. TX power reduction should primarily be for energy conservation.

Thank you.  Am I correct in assuming that .01 would be extremely short range and 20.5 would be max range?

The lowest power output is 0;

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


text:
NodeMCU 12E V2 Power Saving
I'm powering a NodeMCU with 4 x AA batteries (6v, ~9,600mAh).  I am running  ESP.deepSleep([milliseconds]) to minimize power consumption.  Even with deepSleep I am seeing a precipitous drop off in battery voltage.  I've gone from 6.00v to 5.62 in 28 hours.  Does this make sense?  I was expecting the board to consume SIGNIFICANTLY less power and I'm at a loss.
I have the reset/wakeup pins (D0, D3, and D4) set connected to 3.3v with resistors and I've jumped the reset pin to D0 to make the wakeup call.  Nothing else is connected!  Does this power draw make any sense??
As far as the operation goes, it's waking up and posting data just fine.
I've researched various power saving techniques and the best description I've found is here.  I really don't want to start hacking up ESPs though.  That is time consuming and presents a real opportunity (ahem...guarantee) for me to destroy a lot of boards!
My questions:
1.) Are there other SW-based methods for improving power use on the NodeMCU 12E?
2.) Where do I probe a 12E to read current draw with a multimeter
3.) Are there "dumber" ESP8266 modules that have a reset pin, a few? GIPOs and a VIN capable of handling a 6v input with either a 5v and/or 3.3v output?  Product recommendation...I know...I'm hard up though and need some guidance.
I'll make these separate questions if necessary.
I am going to by an in-line current reader.  I need to stick with a multimeter for now.

have you seen this? ... https://www.losant.com/blog/making-the-esp8266-low-powered-with-deep-sleep

I've not but a cursory read of the demo seems to be exactly what I've done...except that the entire thing seems to run in setup().  I'll re-read the summary tomorrow after some sleep and with some coffee.  Thank you!!

perhaps it's the voltage regulator and the USB interface and all the other circuitry on the nodemcu board that still consumes power, despite the ESP module being in deep sleep - searching nodemcu power consumption deep sleep in your search engine of choice will show many documented examples of this behaviour

That's what I'm thinking based on all of the other stuff I've read.

If you can't do anything about the hardware you're using (lower powered USB interface, etc) then the top thing you can do is run the wifi radio as little as possible. The radio uses a lot of power, so the less time it's on for and the less network traffic you send, the less power you'll use.
When the board comes out of deep sleep and reconnects on wifi again, it performs a DHCP exchange to find out its IP address. Configuring a static IP address, network mask and router address will avoid this and let the radio stay on for less time.
The ESP8266 SDK also automatically saves wifi credentials to flash every time you call WiFi.begin(). This is probably not what you want. Disabling this will also help save power.
The new wifi connect code would look something like this:
IPAddress ip( 192, 168, 0, 1 );
IPAddress gateway( 192, 168, 0, 254 );
IPAddress subnet( 255, 255, 255, 0 );

WiFi.forceSleepWake();
delay( 1 );
WiFi.persistent( false );
WiFi.mode( WIFI_STA );
WiFi.config( ip, gateway, subnet );
WiFi.begin( WLAN_SSID, WLAN_PASSWD );

You'd need to replace the specific IP address, gateway (router) address and subnet mask with ones that work for your network. And you'll need to allocate a static IP address either from a range that your router sets aside, or you'll need to configure your router to permanently allocate the address - how you do this totally depends on the router you're using.
The other way to save wifi-related power is to use as lightweight a protocol as possible and do as little work while wifi is on as possible.
For instance, suppose you need to compute a complicated piece of data that you're transmitting over wifi. Maybe it's a chunk of XML or a JSON string. Or you need to read a slow sensor. Do all that work before you enable wifi, and have the data ready to transmit.
Or if you're receiving data, if at all possible, finish receiving the data and turn off wifi before you do any work with the data.
If you have any choice in the matter, use as simple a protocol to transmit the data as possible. UDP is ideal - you can transmit a single packet (but you won't know if it's been received). TCP requires several packets of handshake at connection startup and shutdown. If you use a secure (SSL) connection over TCP that's even more data and computation.
If your very top priority is battery life, UDP is ideal though it's not reliable and not secure.
There's a great series of articles on power saving at
https://www.bakke.online/index.php/2017/05/21/reducing-wifi-power-consumption-on-esp8266-part-1/
https://www.bakke.online/index.php/2017/05/21/reducing-wifi-power-consumption-on-esp8266-part-2/
https://www.bakke.online/index.php/2017/05/22/reducing-wifi-power-consumption-on-esp8266-part-3/
Part 1 is about measuring power use; part 2 is about switching the wifi radio on and off and part 3 gets partly into the stuff I talked about above.

HW is the issue (as Jaromanda X pointed out as well).  This is good advice and I'll have to find ways to optimize.  Bummer, but doable.  Do you know of other ESP HW that has integrated WiFi or is the 12E pretty much it?

@acpilot All ESP8266s have integrated Wifi. It's part of the CPU - it's not an ESP8266 without it. There are quite a few ESP8266 boards without USB ports, or just using USB for power, not data (like the Sparkfun Thing). ESP8266 boards that can be programmed with just a regular USB cable have an integrated USB adapter; boards that need an FTDI cable to program them don't and may avoid the USB/serial adapter power drain. (FTDI is a USB to serial converter that's commonly used with ESP8266s and Arduinos)


text:
How to connect a card reader (extracted from printer) to arduino uno
I'v got this USB/SD card/CompactFlash reader from an old DELL AIO 926 printer, it's a double sided PCB board and that's all i know about it.
I tried to google it but couldn't find anything relevent, how can i tell what voltage it takes and what each wire does and how to interface it with arduino?

It seems to me that it has two sets of 4 wires (red/orange - black - yellow - white) and an extra blue wire, i'm guessing that the black is for GND, red/orange for VCC, yellow/white for SDA/XDA I2C serial bus data transfer, but no clue what the blue wire does, i could've tested this with arduino but i don't want to risk frying the board by using a wrong voltage. any help would be greately appreciated. thanks.

If the end is a USB that presumably can work when plugged in to computer, why dont you try it with Raspberry Pi?

I can pretty much categorically say you won't get it working.
I have a similar board here with the same SMSC (now owned by Microchip) chip on it.
The interface is USB plus some other signals.  I have managed to identify the USB portion of the interface on mine, but not the other signals.
The SMSC chip has the option of using an external ROM chip to store its program, and Dell love to do that.  So, it has a custom firmware which means it doesn't get recognized by my computer without Dell's specific drivers installed.  So it's useless.
There's a very very slim chance you may get it working with a USB Host Shield, but unlikely - and at the end of the day, what's the point?  It's just an SD card reader.  Wire an SD card socket direct to the Arduino and save yourself both the headaches of trying to work it out and also the massive pointless expense in buying the hardware you'll need to do the interfacing.

Well it would've been nice to use it as usb host and sd card reader, but what i really want is to learn how to hack such boards. Do you know what voltage should i use as VCC? and do you have a datasheet link to the smsc chip?

Vcc would be 5V as it's USB.  My board actually has a slightly different SMSC chip looking at it - similar thing, but a little newer (and that one is obsolete too).  Getting a datasheet for that very old one would be hard.  I'll see what I can do.

Looks like a no-go.  I could beg the guys at Microchip to head down to the archive room and see if they can dig out an old datasheet in their files, but it won't help you to get it going on an Arduino.  The SMSC chips are pretty much all 8051 based internally, so if there is an external ROM you could wire that up and read off the program from it and disassemble it to see how it works, but that'd be a huge job with no real reward at the end of it (other than a knowledge of old 8051 assembly).  I'd just strip the useful components off it to use elsewhere. Maybe try and rescue the sockets, etc.

It does sounds like a huge job for a hobbiest like me, i would probably strip it from its coponents and throw it in the bin soon, thanks for your help.

Actually, it looks like someone may have already had the ROM chip off it...


text:
Importance of resistor
I'm new to Arduino and also new to electronics. I'm following the tutorial here. I'm not understanding the importance of the resistor in this schematic diagram. Can someone please help me on this?

Maybe the author meant removing the resistor, not replacing it with a wire?

That resistor, where positioned, is called a pull-down resistor, and if replaced by a straight wire, that circuit would short out when the switch was closed.
The purpose of this is that when a digital input pin is not connected, it floats, and if the switch were open that pin could see upwards of 2v floating value from external and internal noise. With Digital circuitry, any value in this float range can be invalid and return invalid results.
A pull down resistor will generally have a very high ohmic value >5kohm, as to allow as little current pass as possible. Here, you are shorting the pin to ground through the resistor so it will not have a LOW value when the switch is open, instead of possibly invalid.
When the switch is closed, you will have 5v passing through switch into the pin, to be read as a HIGH value, also sending 5v across a 10k or so resistor to ground, consuming only .5mA of current.
It you want to see what I mean by a floating value, debug the output of any analog pin with a wire going nowhere, and watch as the value changes. Try touching the wire, now add a pull down to ground, or try pulling it up to 5v and observe the behavior.
Happy Arduinoing!

In the above circuit there are several other resistances that are being ignored for simplicity and because most of them are extremely tiny. However, one of the resistances is significant, and that it the internal resistance of the power supply.
Without the resistor shown in the schematic, the internal resistance of the battery becomes the most significant resistance in the circuit and the voltage measure at D2 would remain near zero when the switch is closed and very near zero when the switch is opened.
If the resistor shown were several thousand ohms or greater, the voltage at D2 would measure close to 5 volts when the switch is closed and zero when the switch is open (however D2 will be subject to picking up any nearby static electricity or strong electromagnetic fields when the switch is open).
To prevent D2 from being subject to spurious noise, resistors are often used between signal points and ground to dampen any such undesired noise. To better imagine how this works, imagine a 100 megohm resistor connected to D2 with the other end hanging out into the air. The unconnected end of the large resistor is acting like an antenna picking up any possible noise in the vicinity. Because the resistor shown in the diagram is so much smaller then the imaginary resistor, the noise will seem to be shorted out to ground in comparison.
In a very real sense, this schematic is telling you to add in a known resistor to ground or suffer from the effects of all the resistors not show; some being very very high resistance and some being nearly non-existent.

Why the down vote... +1 to rectify

Ohnose! That was supposed to be an up... And now it is locked in. Make a quick edit and I can up it ;D

Vote fixed. (and more letters)

Without the resistor, closing the switch would connect the positive supply directly to the negative supply. This would cause the voltage across all digital components in the circuit to drop close to 0V, crashing the whole thing.

so,it's what we call short circuit if i'm not wrong?

It would cause a short circuit across the power supply, yes.

Check out the internal pull-up resistor (disconnected by default) for Arduino as well. Save yourself wiring up an extra resistor.
pinMode(5, INPUT_PULLUP); // Enable internal pull-up resistor on pin 5

From SparkFun: Pull-up Resistors


text:
GSM shield SIM card troubles
So I'm trying to use the GSM shield to communicate with my smart phone. The SIM card that came with the shield only works with other devices on that network, and it's an obscure latin network that I don't have so I cant use that one, and I bought another t-mobile SIM card activation kit, but I can't figure out how to activate it without having an actual T-mobile number. Somebody please help me! Either help me figure out a way to get the T-mobile SIM card to work or tell me what other SIM to use! If you used the GSM shield with a different SIM card, could you give me a link to where you bought it? Thanks!

How do you propose to use the GSM shield to communicate with your smart phone? SMS?

Yeah, I was going to use SMS.


text:
20x4 LCD shows alternating blank lines
I just acquired a Arduino learning kit, which includes a 20x4 LCD display. I was going to test it, so I grabbed an example "hello world" program from the Arduino docs, connected the display appropriately, and then "Voila! ... Oh, it didn't work.".
The display lights up both its backlight and characters, however not in any desirable pattern. The first and third lines are full white (display is white-on-blue), while lines 2 and 4 are full blue. See picture:

The below schematic is exactly how I've connected the display, which should be correct.

simulate this circuit – Schematic created using CircuitLab
I triple-checked all wiring for any shorts, adjusted the potentiometer to a good value and quadruple-checked the connections, and wasn't able to find any errors.
The dead-simple example program is following:
#include <LiquidCrystal.h>

// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup() {
    // Print a message to the LCD.
    lcd.begin(20, 4);
    lcd.print("hello, world!");
}

void loop() {
}

Where is the decoupling for the LCD?

@IgnacioVazquez-Abrams Sorry? I was following this tutorial (in Portuguese) for the connections, it doesn't mention that... http://blog.filipeflop.com/display/controlando-um-lcd-16x2.html

After a quick search, I see that you mean a decoupling capacitor, right? Apparently, the kit I've bought doesn't have a capacitor that I could use for that purpose.

Just putting the jumper wires in the plated holes, doesn't always give a good connection. Try applying some lateral force, to make sure all of them have proper contact. Wiring looks otherwise fine.

@Gerben Indeed, after pushing the screen in the direction of the Arduino (as per Q image) and rebooting it, it worked correctly. Would you mind turning this into an answer, and if possible, suggest a better way to connect the display?

Great. Glad you got it working.

I have a similar but different problem. My lcd also hows up as same as in your picture. But I can setCursor on 1 ad 3 lines when printing. But if I print starting from the beginning, it will use the alternate lines only. Got any idea what's causing this? BTW I have the wires soldered.

Just putting the jumper wires in the plated holes, doesn't always give a good connection. Try applying some lateral force, to make sure all of them have proper contact. Wiring looks otherwise fine.
A more permanent solution would be to solder some male headers to the display, so you can properly seat it into the breadboard.

Had the same issue recently, only after soldering my cables to the LCD I was able to avoid tilting them to make effective contact. It's definitely a problem of bad contact. In my LCD the holes turned out to be too big.

I had similar problem and I found that I had wrong contrast/brightness. Communication was working but just the characters were invisible. I spent much time, changed the LCD and in the last minute before went to rubish I got it.

I did check the potentiometer values, and it is on a ok contrast. It's really the characters

It's definitely not the contrast. It hasn't even initialized properly.

First, and third lines is all white, second and fourth lines are all blank. So contrast has been set correctly.

Even though contrast may not be the case in this particular scenario, I can confirm that, for some screens, a poor contrast setting gives these exact symptoms.


text:
DHT11 and DHT22 unused pin
The DHT11 and DHT22 is a 4 pin temperature and humidity sensor, where one of the pins is labelled as NC (not connected).
I'm curious what the unused pin is used for.
Factory calibration?

I have wondered the same, however I think that is just is not connected.

On the DHT11 it's connected to pin 6 of the SOIC14 inside. So it's at least connected to something. But who knows what it's for.
It has a (internal) pull-up resistor to VCC of around 100kOhm on this pin.
I connected my logic analyzer to it, there is no signal, even while reading the sensor. Also connecting the arduino's signal wire to this (incorrect) pin does nothing.
Factory calibration or testing would be my guess too, but who knows.

in this datasheet both 3. and 4. pins are marked GND :
https://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf

Only on the DHT22.


text:
Stack arduino, motor shield and lcd shield
I made arduino-stack which consists of arduino r3, robotdf motor shild and robotdf lcd shield. But motor shield and lcd use same pins 4 and 5, so we have a conflict of pins. Can i use other pins?

Nope. Welcome to shields.

Technically you can rewire the shield. But this is a physical change, and different combinations of shields will require different rewiring. In the end you may be better off just using breakout boards instead.

@IgnacioVazquez-Abrams this variant is ok for me, thanks

Stack one shield on top of the Arduino itself and connect the other shield using wires. This way you can pick your own pin assignment for the 'external' shield.
Be careful when using a specific library though, sometimes the used pins are hard-coded in the library itself. Modifying the .h and .cpp files for the library is possible, so you could (hard code) assign your own used pins.


text:
Uploading Temperature data (DHT22) to Thingspeak with an ENC28J60
So, I've gotten my module working pretty well. It logs data from the DHT22 and sends it to a 192 address on my LAN. However, I'd like to log and graph the data.
I figured thingspeak is a decent platform for that. However, I have no experience doing so, and I'm not sure where to start. All the examples use the "official" arduino shield. I've only found ONE example bit of code, but it uses the Dallas One Wire temp module. Link
I'm in over my head, and have no idea how to switch from the One wire to the DHT22. Thanks for the help!
I'm using a clone arduino pro mini, 5V 16mhz, 328.
If there's a better platform than thingspeak, I'm open. All I want to do is graph and visualize the DHT22 sensor readings.

Try this:
/*
| Post temp. values from a DS18B20 to ThingSpeak using the Ethercard interface based on the
| ENC28J60 chip.
| Based on the Ethercard example from www.jeelabs.org
| Phil Grant Jan 2014
*/
#include <EtherCard.h>
// change these settings to match your own setup
#define APIKEY  "xxxxxxxxxxxxxxxx"

//DHT Setup
#include "DHT.h"
#define DHTPIN 2     // what pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);

// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0xXX,0xXX,0xXX,0xXX,0xXX,0xXX };

char website[] PROGMEM = "api.thingspeak.com";

byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;

void setup () {
  Serial.begin(57600);
    dht.begin(); //Initializate DHT
  Serial.println("\n[webClient]");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");

  ether.printIp("SRV: ", ether.hisip);
}

void loop () {
  ether.packetLoop(ether.packetReceive());

  if (millis() > timer) {
    timer = millis() + 60000; //Transmit every minute
    delay(2000);  // Wait a few seconds between measurements.
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity(); // Read temperature as Celsius (the default)
  char h_buffer[10];
  String Hstring = dtostrf(h,0,5,h_buffer); //Convert Humidity value to String

  float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true)
  //float f = dht.readTemperature(true);
  char t_buffer[10];
  String Tstring = dtostrf(t,0,5,t_buffer); //Convert Temperature value to String

    byte sd = stash.create();
    stash.print("field1=");
    stash.println(Hstring);
    stash.print("&field2=");
    stash.println(Tstring);
    stash.save();

    // generate the header with payload - note that the stash size is used,
    // and that a "stash descriptor" is passed in as argument using "$H"
    Stash::prepare(PSTR("POST /update HTTP/1.1" "\r\n"
                        "Host: $F" "\r\n"
                        "Connection: close" "\r\n"
                        "X-THINGSPEAKAPIKEY: $F" "\r\n"
                        "Content-Type: application/x-www-form-urlencoded" "\r\n"
                        "Content-Length: $D" "\r\n"
                        "\r\n"
                        "$H"),
            website, PSTR(APIKEY), stash.size(), sd);

    // send the packet - this also releases all stash buffers once done
    ether.tcpSend();
  }
}


text:
W5100 module hookup help - Not a shield
I recently purchased a W5100 based ethernet shield for my arduino Uno, and looks like this. I had been following the guide here, and connected the pins accordingly - 5V to 5V, GND to GND, MOSI to 11, MOSO to 12, SCK to 13, and SS to ten.
I booted up a default sketch (webServer, under Ethernet), and plugged in and ethernet cable. - PWR, LINK, SPD,and FDX all lit up, with Rx blinking for first 10 or so seconds. I then go to the IP specified on the arduino sketch, and nada. Also, my router doesn't show the shield under the attached devices.
Therefore, I figure it's a problem with my connections. Can anyone help me? Googling has only brought my lots of info about shields, and little info on these modules.

Just to sanity check - can you post the IP address of your router (or your PC) and the IP address you used in the sketch?

Router's address is 192.1681.1.1 - a default. The IP used in the sketch, for the Ethernet's 192.168.1.177

First, if you cannot connect to arduino by ethernet, use Serial Monitor and add some Serial.println to your code to log what is going - what part of program Arduino is executing.
W5100 module has no automatic reset module as opposed to Ethernet shield.
So try to connect W5100 RST pin to for example D8 and reset module in setup.
Here you are example from my (working) project:
const int W5100_RESET_PIN = 8;

void setup() {
  Serial.begin(SERIAL_SPEED);
  Serial.println();
  Serial.println(F("node starting..."));
  pinMode(W5100_RESET_PIN, OUTPUT);
  digitalWrite(W5100_RESET_PIN, LOW);
  delay(100);
  digitalWrite(W5100_RESET_PIN, HIGH);
  // give the Ethernet shield a second to initialize:
  delay(3000);
#ifdef USE_DHCP
  Serial.println(F("DHCP..."));
  while (Ethernet.begin(mac) == 0) {
    Serial.println(F("DHCP failed."));
    delay(10000);
  }
#else
  Serial.print(F("static IP..."));
  Ethernet.begin(mac, IPAddress(MY_IP));
#endif
  Serial.print(F("local IP:"));
  Serial.println(Ethernet.localIP());
  Serial.println(F("node started."));
}

Also after setup if your arduino lost ethernet connection and cannot get it again, you can try to reset w5100 and initialize Ethernet again.


text:
Installing Arduino IDE on Linux
I downloaded arduino-1.8.4-linux32.tar.xz and ran install.sh as outlined (the very sketchy instructions) in https://www.arduino.cc/en/Guide/Linux
This seemed to work OK, so I removed 354M of what I thought was the installer, only to discover that I had deleted arduino.
The so-called install.sh on closer inspection seemed only to create links into the uncompressed download in my home directory.
The whole process seems very un-Linux like; I had assumed that it would be installed in /usr/share/ like most Linux programs.
I realise I could extract into /usr/share/ and set permissions for other users, but surely there must be others who have wanted to do the same. The macOS version seems to have a proper installer; does one exist for Linux?

There is a .deb package that properly installs everything. Alas, it's for the ancient Arduino 1.0.5.

I mentioned here about the flatpak versions (cross-distro)

I ran the following to Install the latest Arduino IDE on my Raspberry Pi3.
This should work all Pi models. This release enables you to run the Arduino Software (IDE) on many of the mini PC boards based on ARM6+ processors currently on the market, including Raspberry Pi
# Installing Arduino IDE
cd /usr/share/
sudo tar xf /home/pi/arduino-1.8.9-linuxarm.tar.xz
sudo chown root:root -R /usr/share/arduino-1.8.9/

# Adding desktop shortcut, menu item and file associations for Arduino IDE
# Each user needs to repeate this
cd
/usr/share/arduino-1.8.9/install.sh

There is a similar instruction in MagPi61 except they suggest installation in /opt

The problem here is that there are multiple flavours of linux each with their own installation and package management systems - Aptitude, Yum, EMerge, etc.
It is not easy for Arduino to keep up with creating packages for each and every system, so instead they create a single tarball that can be used on any of the systems.
At one point Arduino (or someone, anyway) used to create Debian packages for the IDE and upload them to the main Debian repository - however this has not been done for many years now and the packages in the Debian repositories are very much out of date (1.0.5 IIRC).
If you, as a system manager, choose to deploy the IDE system wide then it is your task to decide how best to do that.
One option is to just copy the contents of the archive to /usr/share/arduino and then run ./install.sh from within that directory.

There is some work being done for packaging a newer Arduino, but it seems there are some non trivial issues in the way: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=780706

I wrote an installation instruction for the Arduino 2.0.x IDE over at AskUbuntu.
I chose to install the files in the /opt directory, but opinions differ on that topic. The instruction also elaborates on adding desktop links and an icon for Ubuntu flavors.


text:
Stacking Arduino Shield (Motor Shield, LCD Keypad, LED Sensor)
I'm building a line follower with arduino, here some part that I'm going to use

Arduino Uno
Motor Shield 2A http://www.dfrobot.com/index.php?route=product/product&product_id=69
LCD Keypad
4 Channel Line Tracking Sensor http://www.aliexpress.com/item/4Channel-Infraed-Line-Tracking-Sensor-Module-w-Connector-Line/2021343637.html

I'm using LiPo Batteries 3 Cell 11.1v for power source.
I'm new in here so I didn't know how to stack that shield, if I recall I can stack up Arduino and the LCD Keypad, and Arduino and the Motor Shield, but didnt know how to stack those 2 together and adding another sensor like that line tracking sensor. May I know how to resolve that? thanks.

What LCD Keypad are you using?

this is LCD Keypad that I'm using http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_%28SKU:_DFR0009%29

The Motor Shield 2A plugs in on top of the Arduino Uno, and the LCD Keypad plugs in on top of the motor shield. [But see Edit 1 below]
There is better information about the  4 Channel Line Tracking Sensor at uctronics.com where you can see that its main board (with the LM339 chip) connects to the Arduino via six lines: Vcc, Gnd, Out1, Out2, Out3, Out4.  That main sensor board does not mount on the stack, but instead can be located whereever is convenient and leaves its four comparator-level pots accessible for adjustment.
Mount the four small boards for the tracking module as convenient and necessary for line following.
For connecting the six lines from the sensor main board to the Uno, you probably will need to solder two headers (rows of pins) to a board in the stack.  Using right-angle headers (see below) will allow the pins to come out of the side of the stack without interfering with other layers of the stack.  One of the headers should let you connect sensor Out1...Out4 digital outputs to four otherwise unused analog or digital pins, and the other header should let you connect Vcc and Gnd.

Edit 1: In the LCD shield page, section 2 (Diagram) shows Vcc, Gnd, and D0-D3 available at the top right corner (the angled corner).  Those six pins probably are a reasonable place to add a six-pin angled header for the sensor board.
Given that the LCD KeyPad Shield is a DFRobot.com model, the summary pinout at shieldlist.org shows that its use of D4,5,6,7 will conflict with use of those same lines by the DFRobot 2A Motor Shield.  There are several ways to handle a conflict like this:  1, use two Uno's, one per shield; 2, make one shield or the other use different lines; 3, share the lines.
Method 2 could work as follows:  Stack the LCD shield directly on the Uno (or any other compatible Arduino).  Besides a header for the sensor board, add a header for a cable to the motor board, and drive the motor board's D4-7 inputs with some other lines from the Uno, eg A4-7.  [Alternately  one could remove the D4-7 pins on the LCD shield and jumper from A4-7 to the D4-7 lines on the LCD shield.  This would leave the boards in a single stack but would make some serious changes to the LCD board.]
Method 3 would work as follows:  The LCD shield only pays attention to D4-7 (which from the DFRobot schematic drive DB4-DB7 on an LCD TC1602 chip) when the TC1602's E line is strobed.  See pages 7 and 8 of Adafruit.com's copy of TC1602 specs, where timing diagrams show about half-microsecond times for writing to or reading from the TC1602.
You would need to run tests with your motors and see if they work ok in spite of the four inputs to the motor shield being random during the occasional half-microseconds that data is being written to the LCD.  You might have to add more diodes or capacitors to  suppress electrical noise due to rapid switching.
DFRobot's motor shield page has links to that board's schematic and to its L298 chip data sheet.  Page 7 of the datasheet says

An external bridge of diodes are required when inductive loads are driven and when the inputs of the IC are chopped; Shottky diodes would be preferred.

The motor shield schematic shows diodes; although not drawn using Schottky diode symbols they might be Schottky anyway (which would give better noise suppression, less heating, etc).  The schematic also shows that JP1, a 16-pin dual row header, has jumpers that control ENA and ENB on the L298.  In a "proper solution" for sharing D4-7 between the LCD and motor shields, you'd drive ENA and ENB low when using D4-7 for LCD i/o, which would allow the attached motors to briefly free run, as opposed to being suddenly commanded to stop or reverse.

Note, I didn't verify whether any of the LCD shield lines conflict with any of the motor shield lines.  As asked earlier, what LCD Keypad are you using?

LCD Keypad just like in DFRobot in here http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_%28SKU:_DFR0009%29 I didn't know how to attach the additional header pin because the top of stack is LCD Keypad and didnt know where to use it

kripton, see edit

based on your method, can I use ardu nano or mini? cause I only have 1 uno at a time. or maybe can I use shiftout just like in this tutorial? http://arduino.cc/en/tutorial/ShiftOut thanks anyway

Neither shield can directly plug into a Nano or Pro Mini (which are about 1/3 as wide as an Uno) but would instead need cables or an adapter shield.  In that case you might as well use a cable from Uno to motor shield.  The Uno has enough lines to do it all.  See edit about "Method 2".

The most elegant approach would probably be to use shields controlled by the I2C bus. I've found LCD+keypad and motor shield offered by Adafruit for example.
The I2C bus is shared by all slaves connected to it, and you should find microswitches on each shield to set its I2C address.
Regular shields should not interfere with I2C lines, so as last resort you can put one shield controlled "traditional way".

By in case of trouble finding do you mean when you need to do some trouble shooting or if you encounter any problems?

@Greenonline sorry for imprecise language, I meant "trouble finding I2C controlled shield for your purpose" and I have edited my answer.


text:
Plug/socket between thermocouple wires and the amplifier
I am building a temperature monitoring system that has 24 thermocouples. Managing all the wires is a hassle, and I'd like to connect all 48 wires to a few plug and socket connectors. Maybe 6 of these lead wire harnesses from eBay (see below).
The point of this would be to allow me to quickly disconnect all the thermocouples from their amplifiers when I need reposition the arduino, and then reconnect them afterwards without tracking each individual cable.
I don't know if this will have a negative impact on the function of the thermocouples. Is it ok to have a 'joint' (i.e., the socket) in the thermocouple cables, or do they need to remain intact from the end all the way to the amplifier?
Alternatively, would having a few inches of regular copper wire inserted between the thermocouple wires and the amplifier be ok? That is, having two copper wires attached to the amplifier, joining 8 of these wires together in a socket, and attaching the plug to the actual thermocouple (alumel/chromel) wires? The thermocouple wires are several feet long.

I do not know the accuracy that you will require in your temperature measurements.
Your idea of using copper wire and connector sockets is reasonably ok as long as you are aware of the following :
Where you make a connection from thermocouple wire to copper, that creates another thermocouple in itself. This isn't a great problem since the temperature of the "undesired" thermocouple is likely to be at room temperature (constant?)
No matter what you do, you always end up with undesired thermocouples (example when you connect your thermocouple directly to your circuit board copper, darn it.)
Thermocouple Selection and use is a page you can go to for more information.  Especially the Cold junction compensation (CJC) section.
EDIT added : You should twist your extention leads together to reduce electrical noise from the environment. Twist each pair, do not twist the bundle all together.

Thanks Marla! The whole setup is in a greenhouse, and the temperature of the thermocouples (desired and undesired) will fluctuate from 0C (hopefully not lower, but it is -20C outside tonight) to +35C. I'll study the page you linked, it looks like exactly the info I needed.

On the linked page, the author uses words like "must use", strong language encouraging to use thermocouple wire for extensions.  But that merely reduces the number of unintended thermocouples.

I'd put the sockets upstream of the amplifiers, ie arduino---sockets---amps---TCs


text:
RF Remote Clone using NRF905
I have come across the various blogs which talks about cloning RF remote using cheap 434 MHz Tx/Rx and RCSwitch library.
I tried using RF 434 MHz ASK (https://www.sparkfun.com/products/10532) module with arduino, but the range I get it very less , just around 5-6 centimeters. Seems these RF 434 MHz modules are not stable. So I am planning to use now another RF Module which uses NRF905.
Link -
http://www.ebay.com/itm/2pcs-NRF905-wireless-module-PTR8000-wireless-transmission-433-486-915MHz-/270963407796
My query is can I use NFR905 based RF modules which is also 434 Mhz to clone any existing remote working on 434 MHz. Please help

can I use NFR905 based RF modules which is also 434 Mhz to clone any
  existing remote working on 434 MHz.

The answer is, inevitably, no, you cannot. Each such remote controlled device might have a different digital modulation scheme. Best if you could focus on one specific product and adjust your design to fit it.
Note that the two products you are referring to are both 433Mhz but differ by many other parameters, such as:

Supply voltage (5v vs 1.9v-3.6v)
Interface (single digital output vs SPI)
Capabilities (receiver vs  transceiver),
Presence of a crystal
Power consumption
Price

This might affect your final design as well, and should be taken into consideration.
For example, from my experience, if you will shrink your project into a ATtiny85 at some stage, you might not have enough I/O pins to satisfy the NRF905, but enough for the Sparkfun's product (or a similar one).

but the range I get it very less , just around 5-6 centimeters.

The maximum range I got with the Sparkfun's module using a half-wave antenna (34cm) was ~40 meters inside a building and about 80 meters in open air. My testings with quarter-wave length was about ~30 meters inside a building.

You can connect an external antenna to pin 8 on that module. Just use a piece of wire that is 17.3cm long. But since the range is that bad to start with, probably means it isn't tuned very well. I'd return it, or try fiddling with the pot at the back. Not sure why Sparkfun has these crap transceivers for sale. Transceivers without a crystal are very inaccurate in their frequency.
If you only need to transmit, I'd suggest this products: https://www.sparkfun.com/products/10534
 . Those worked great for me, and are currently switching on the power sockets for my lights when it gets dark enough.

Thanks Gerben for your inputs and response. I will try out with a pot added at the back. Also, trying out with nRF905. This uses FSK instead of ASK. Is this module (nRF905) good for using in home automation or should I use ASK based RF modules only.

I really don't know the nRF905. It will probably work for home automation, but I'm not sure if it's the easiest to work with. E.g. the nRF24L01 I'm using for my home automation takes care of a lot of stuff, like addressing, data integrity, auto-ACK etc.. Using a raw data module like the module in the link I posted above, you'd have to implement all of that yourself. Glancing through the datasheet it look like the nRF905 does some of that too. The lower frequency may also help in getting a better range that the 2.4Ghz products out there.

Thanks Gerban for your inputs and views, really appreciate. I am getting my nRF905 in couple of days. Will post the feedback once I use this.

+1 for the external antenna suggestion and the comment about the crystal (nowadays I always use 434Mhz with crystal). NRF24L01 is 2.4Ghz and will probably not suite for cloning an existing 434 RF remote. Also, the Sparkfun's product is a receiver, not a transceiver.


text:
MMA7361 readings deviate a lot
This is what I get using a MMA7361 breakout board (just the IC, no resistors or capacitors). The IC is powered using arduino nano's 3v3 pin.
The x, y, z values are read from analog pins A0, A1, A2. The readings are subtracted with 338.
x   y   z
-4 -26 44
44 -27 -5
-57 -11 27
-29 -23 22
28 -21 9
-44 3 20
-26 -14 39
26 -32 -8
-17 -12 19
-30 -15 35
4 -26 14
24 -43 49
-58 -19 0
16 -29 24
9 -48 13
-58 -42 12
12 -47 14
-24 -31 9
-46 -31 10
16 -52 1
-43 -21 8
-31 -25 16
37 -18 11
-45 -10 20
-22 -36 16
27 -19 20
-5 -9 1
-59 -10 10
37 -18 30
-53 -18 16
-30 -8 10
54 -19 17
-27 -29 15
-40 -23 -14
-1 -18 19
34 -22 2
-35 -24 41
13 -17 7
-14 -17 21
-39 -14 35
-19 -31 6
62 -9 34
-63 -16 16
-12 -6 23
60 -33 36
-45 -2 34
-18 -15 9

As you can see the x value, when the whole thing is not moving, can range from -59 to +44. This looks very unusual as other people's reading seems to have just +-3 deviations. What might be wrong with my setup?

(just the IC, no resistors or capacitors)
What might be wrong with my setup?

That's easy: You miss the capacitors ;-)
Check figure 5 of the datasheet and try again.

I'm still getting +-20 of deviation with capacitors on.
Could it be wire length? Or I'm worried that I might have damaged the IC when soldering it with a torch (literally).

Wire length can be an issue. You mentioned "other people"... ask them for their schematics. Maybe they have higher capacitance for their capacitors. This will make the signals smoother, but also slower.


text:
Powering an Arduino Pro Mini directly from a LiPo
I've recently purchased an Arduino Pro Mini, 3.3V version. I've planned to use it in a diy remote: I've empty a ps2 remote, just left the buttons, and the board will be inside. The remote will be wireless: I use an xbee, which also fit inside the ps2 controller. To power it, I use a one cell Lipo, which will empower the Arduino and the XBee, here comes my issue: As you've seen, there will be many things an a single ps2 controller, so I try to minimize connections and external components. But, the XBee will take more than the maximum 150mA provided by internal regulator of the Arduino. So, either I use an external regulator, or I directly plug the lipo in the VCC pin if the Arduino. Can the board survive? If the voltage is greater than 3.3V, will it damage the board?

also, is that XBEE 3V3 or 5V? You should be ok just connecting the lipo directly to 3.3V+.

I removed the 3v3 regulator on my pro mini by accidentally connecting a lipo directly to the Vcc pin, which roasted the regulator enough to desolder itself! Luckily, no other damage.

The only thing about the 3.3V Pro Mini that is actually 3.3V is the 3.3V regulator.  The main chip (pretty much the only other component) is good for anything from 1.8V up to 5.5V.
Running direct from a 3.7V LiPo or Li-Ion will be perfectly fine.  You might want to disconnect or otherwise disable the regulator though to reduce current consumption - the latest Minis have a solder jumper SJ1 for doing just that, but older versions you may want to actually cut the 3.3V OUT pin of the regulator or de-solder it entirely.


text:
Schematic interpretation, where to put resister?
I'm new to schematics, trying to figure out where to put a resistor (no  instructions other than the schematic)
I'm told I need:
10K variable Resistor x 1, 4.7K Resistor x 1, 100 Resistor x 1
But I only see where to put the 10k resistor (I added a blue circle around the 10k). Can someone show me (describe, illustrate) where to put the others?
And where there's the triangles for +5V or AGND, do I put something there (purple circles)??
Thanks!
Here is a link from the project I'm trying to build
https://bestengineeringprojects.com/arduino-weighing-machine-using-hx711/

The 4.7kOhm resistor is shown in the second image (They simply didn't want to scramble the big image). It shows, that the pin between the resistor and the button has to be connected to pin D10 of the Arduino:

The 100 Ohm resistor isn't shown in the image, too. But in the text it says:

Note: Cathode and Anode pin of LCD (pin 15 and pin 16) is not shown in
  circuit diagram. Connect +5 volt to pin 15 with current limiting
  resistor (generally 100-ohm) and pin 16 of LCD to ground.

Pins 15 and 16 are not shown in the diagram, but the text gives all necessary information. Connect pin 15 of LCD to the 100 Ohm resistor and this resistor to 5V power source. And then connect pin 16 of LCD to ground.

The two other symbols, that you circled, are used as indicator of the power source. Normally all pins, which are marked with +5V (triangle) are connected together to the 5V power source. The triangle consisting of 3 horizontal lines marks ground. Normally all grounds are connected together to the ground pin of the power source.
So these symbols are used, so that you don't have to draw all the lines for connecting the power lines together.

Neither are shown in that schematic, as described in the text.

Calibration Circuit: The weight calibration circuit is shown in figure 2. [...]
[A schematic that includes a 4.7kohm resistor]

...

Note: Cathode and Anode pin of LCD (pin 15 and pin 16) is not shown in circuit diagram. Connect +5 volt to pin 15 with current limiting resistor (generally 100-ohm) and pin 16 of LCD to ground.


text:
hx711 and load cell read out 0 for calibration
I'm using this tutorial from Sparkfun
https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide
And using THEIR code. The only difference is I added a delay so it wouldn't write a reading 10x a second.
QUESTION:
How do I get nonzeros?
#include "HX711.h"
#define DOUT  3
#define CLK  2
HX711 scale(DOUT, CLK);
float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
void setup() {
  Serial.begin(9600);
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);
}
void loop() {
  scale.set_scale(calibration_factor); //Adjust to this calibration factor
  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 20);
  Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
  Serial.print(" calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();
  if(Serial.available())
  {
    char temp = Serial.read();
    if(temp == '+' || temp == 'a')
      calibration_factor += 10;
    else if(temp == '-' || temp == 'z')
      calibration_factor -= 10;
  }
  delay(2000);
}

NOTE: I did not yet solder anything because I don't want to mess up the soldering and have to buy new cells and wait a week for shipping. So I placed pinheads in the amplifier and connected with m/f jumpers, and used alligator clips to connect to the loose wires.

what does this mean? ... How do I get nonzeros?

picture #1 shows the type of loadcell .... why did you include the other two pictures? ... they show nothing useful

@jsotola thank you so much for your insight, but just because YOU don't know something, it's not nice to say my images are useless. What they show is that I did not have the VDD connected to 5v, and that was actually the problem. And a "nonzero" is something other than 0.

they show is that I did not have the VDD connected to 5v ... actually, they do not show that .... the pictures are not a clear view of the wire routing

i thought about your comment .... it's not nice to say my images are useless  and but just because YOU don't know something  .... you are correct, i have no idea how everything is connected ... you are the only one that knows how it is connected .... your pictures do not show the connections in a clear way, therefore they are useless .... it has nothing to do with being nice or not nice, but it has to do with the quality of the information that you presented

@jsotola, well the SparkFun folks were able to tell from the exact same pictures, so clearly you are not qualified to make such an assessment.

Only VCC was connected to 5v. Had to add a breadboard to connect VDD as well.
(The kind folks at Sparkfun were able to help me out)


text:
Emulating 1-wire device(s)
What I want to do is make a ATTiny IC become a slave on the 1-wire bus, with its own S/N and command list for its specific functions.
What I want to know is if I can use the one wire library from the arduino site to send data as a slave.
For example, you can have a slave in one room with multiple types of sensors which would report to the master on requested information, or the master can tell it to control something like blinds.
Question
Would I have to monitor the bus line and respond to a request from the master and also take into consideration the way a normal sensor would send data? What frequency should I run the slave at to get the best functionality?
I won't use parasitic power, as a note.

http://forum.arduino.cc/index.php?PHPSESSID=trj6v208snqfutqhrfltnu0364&topic=65706.0

@Gerben - I had found that before on a search. Skimmed through it. But I was concerned because there were some errors, though solved, I don't know the reliability. Also search foe designs using custom slaves didn't seem like a common thing, hence question above.

It seems to say the library supports it. Here is a library specifically for it I think. Speed seems to be around 15kbps. I think CPU speed doesn't really matter, but that depends on the library. If it's not battery powered, just run it at 8mhz or 16mhz, and it should be fine.

@Gerben I will test out the library to see how it runs. One thing I still don't get is why it is so uncommon for some things not to use the one wire slave?

@RSM You should check this library https://github.com/MarkusLange/OneWireSlave

@Ryu_hayabusa you should put that as an answer

As far as I know, the 1-wire library you linked in your question allows only to act as a master, not a slave.
I've just released a library to turn an Arduino board into a 1-wire slave, here: https://github.com/neuoy/OneWireArduinoSlave (edit: moved here https://gitea.youb.fr/youen/OneWireArduinoSlave). I use it in my custom home automation system, and it works flawlessly in my setup (the 1-wire master, a DS9490R, is connected to a laptop via USB, and also provides power to the Arduino, which is an Arduino Uno). The library handles low level details: match rom, byte send and receive (which is actually quite hard to get right, mostly impossible without a logic analyzer). The rest is up to you.
It's entirely implemented with interrupts, all communications are performed in background, you can execute other code as usual, in parallel, and are notified by callbacks when bytes are received etc. Sending bytes to the master is also asynchronous.
I also know at least one other library exists, https://github.com/MarkusLange/OneWireSlave, as commented above by Ryu_hayabusa. It didn't work for me (don't know if it's because of my hardware setup or for another reason), but it definitely work for others, so also worth a try. It seems this library is not implemented with interrupts, so your program is blocked while waiting for master activity (which is perfectly acceptable in a lot of scenarios).

The repository seems to have moved to https://gitea.youb.fr/youen/OneWireArduinoSlave

@JonasBerlin Indeed, I've moved the repository (just edited the answer to reflect that). I leave the old link as a backup just in case, and as a reference to find other people forks on GitHub.

Should the issues be copied perhaps?


text:
Can I have backup power for an Arduino device?
I have an arduino project that will work while plugged into a generic outlet. But I want to connect a battery in case the power goes out. I know there are various power sources (coin cell, polymer lithium, 9V, etc.). But if I code my project to use the backup power if the main power goes down, would that mean the backup always has to be running? How would I go about this?
Thanks for the help! Every time you help me you save a kitten!!

You could set up a relay to work in reverse with the mains power.
Have your backup battery connected to the gate contacts of the relay, and then use the mains power running your project to open the relay and keep it open as long as there is power. If the mains turns off, then the relay closes and the battery is connected.
You might want to put something in line with the power to the Arduino to make sure you don't get any spikes when things switch.
I hope this helps as I love kittens

Thanks! I have to look into the code, but this sounds like a great possibility!

I doubt if a relay would work. It would cause a drop-out in power as it switched from mains to battery.

This needs a big capacitor, to survive the time it takes for the relay to throw.

@Jasmine what farad value would you recommend OP?

The cap would slowly eat the battery charge :/

@user400344 - not enough information. You need to know the time to flip the relay - some are really fast, some are slower. You also need to know the maximum draw of any connected devices. Then you pick a cap twice as big as you need to deliver that current draw over the time it takes to throw the switch.

I have been looking into this myself.  After getting some advice online I have come up with this circuit :

http://everycircuit.com/circuit/5059191601364992
The top left power source is the mains supply and the bottom  left is the battery.
A voltage divider is connected to both that then feeds into an OPAMP comparator.  For illustrative purposes there is a switch at the top left you can toggle to see the circuit in action.
When the mains power gets cut off the op amp comparator sends a logic level signal through the diode and into the mosfet which enables the battery circuit.   the capacitor is there to keep power while the comparator makes the switch.
The link on every circuit is interactive, so feel free to have a play about with it.  The LED represents your Arduino.  The OpAmp is powered by the Positive and negative rails of thi diagram (impossible to draw on EveryCircuit)
Be sure to attach a voltage regulator to this circuit (at the input of the Arduino) so that the voltage doesn't change to your Arduino.
Here's where I researched about comparator OPAMPS ... Setting up a comparator OpAmp circuit
The LM358 is a good very cheap OPAMP for this circuit.   All parts well sourced will cost you about £1 (or less).
Or if your battery is rechargeable you can try this circuit :

http://everycircuit.com/circuit/5232232327282688
Again this is just for illustrative purposes.   You will need a 5V step-up converter to get 5v from a 3.7v battery.  Also the battery I am using has a builtin protection circuit, if yours doesn't it's important you include it in your schematic.
Here's a video of it working for me with a 3.7V Li-Polymer Battery:
https://www.youtube.com/watch?v=Sv2rjVqQg3U

Three problems: First, what powers the op-amp?  Not that it can't be resolved, but you haven't specified.  Next, you appear to back-drive the mains supply when it is unpowered - that may or may not work, for example, it may load the battery supply.  Finally, you appear to be supplying either 5v or 9v, but the typical arduino does not have any power input which can accept both of those values and function as intended.

It's highly simplified due to a lack of components on Every Circuit.   I would probably attach a voltage regulator in there.   The OpAmp gets powered by the battery, the mains or the capacitor depending on the situation (ie its power is from the negative and positive rails on the diagram).
I'm new to electronics, but I based this circuit off examples and advise from around the internet.

The point is that this can't be used without changes.

Feel free to draw up a circuit diagram for my benefit and for those reading this post.

I suggest this "Battery boost" circuit from AdaFruit. It's designed to do exactly what you describe. An Arduino needs a smooth, steady 5 V supply with no "blips". The AdaFruit unit does just that, and charges the battery while on Mains supply.

You can use https://www.regaldreamtech.com/micro-ups/ for the backup 5V power supply to Arduino in absence of main power. It has 5000mAh battery and 5V 2A output. It will handle the switching on its on between main and battery power.
Disclosure: We manufacture this product.

You could solve this very simply with some diodes or get creative with a bridge rectifier.  Connect both positive sources to the ac input one on each leg.  then the positive side of the bridge rectifier would be your positive source.  the grounds need to be all tied together


text:
Wrong documentation for Mega2560 SPI Pins?
This page https://store.arduino.cc/usa/mega-2560-r3 contains an image under the Documentation section which shows digital pins 10 to 13 with labels SS, MOSI, MISO, and SCK.
EDIT: The documentation page has since been updated with the correct pin assignment as discussed below. The image has been removed to stop it from showing up in "mega SPI pinout" searches and continuing to spread wrong information.
However, this page says that those are at pins 50 to 53 https://www.arduino.cc/en/reference/SPI.

Which page is correct?

check the schematic ... the top picture is incorrect ... PB4 to PB7 are not SPI pins  ... ATmega2560 datasheet confirms that PB0 to PB3 are SPI pins ... these are pins 50 to 53 on the Arduino board

https://store.arduino.cc/store-support

I have asked Arduino store tech support to check on it - "        Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us."

Got reply from Arduino Store as well. " it is being taken care"

The image is incorrect, unfortunately.
The SPI pins are below:
PB0 - #SS
PB1 - SCK
PB2 - MOSI
PB3 - MISO


text:
Feather M0 RFM69 serial over radio IP over serial works for UDP packets but fails for TCP sessions
I'm trying to build a serial over radio transmitter module using two Feather M0 boards with RFM69HCW chips on board. As a test I'm trying to run a slip IP over serial session. This seems to work consistantly for UDP sessions (in my case ICMP ping requests) but fails for TCP sessions (in my case a simple HTTP request).
Here is the code:
#include <RFM69.h>
#include <RFM69_ATC.h>
#include <SPI.h>
#include <string>
// a simple off the shelf CRC8 implementation
#include <crc.h>

// defined for one of the two boards
// #define B

#ifdef B
#define NODEID 1
#define RECEIVER 2
#endif
#ifndef B
#define NODEID 2
#define RECEIVER 1
#endif

#define MAX_BYTES 56

#define NETWORKID 100
#define FREQUENCY RF69_433MHZ
#define IS_RFM69HW_HCW

RFM69_ATC radio(8, 3, true);

char buf[512];

void setup()
{
  // initialize random using receiver address
  // this guarantees that both nodes have different initial random values
  randomSeed(RECEIVER);

  Serial.begin(115200);

  radio.initialize(FREQUENCY, NODEID, NETWORKID);
  radio.setPowerLevel(0);
  radio.setFrequency(446000000);
}

int8_t receiver_last_id = -1;

bool read_packet(bool override = false)
{
  if (radio.receiveDone() || override)
  {
    int cnt = radio.DATALEN - 2;
    int crc = radio.DATA[0];
    int8_t packet_id = radio.DATA[1];

    memcpy(buf, radio.DATA + 2, cnt);

    uint8_t crc_data = crc8(0, (uint8_t*)buf, cnt);

    if (radio.ACKRequested())
    {
      if (crc == crc_data)
      {
        radio.sendACK();

        // sometimes duplicates seem to occure
        // in case this happens just ignore the packet
        if (packet_id != receiver_last_id)
        {
          Serial.write(buf, cnt);
          receiver_last_id = packet_id;
          return true;
        }
        return false;
      }
      else
      {
        radio.ACK_REQUESTED = 0;
        return false;
      }
    }

    return false;
  }
  return false;
}

int8_t sender_packet_id = 0;

bool send_packet()
{
  int serial_cnt = Serial.available();

  if (serial_cnt > 0 && radio.canSend())
  {
    // packet structure:
    // 1. byte: CRC8 of DATA
    // 2. byte: ID of packet (to prevent duplicates)
    // variable length: DATA

    int payload_size = min(MAX_BYTES, serial_cnt);
    int total_size = payload_size + 2;

    Serial.readBytes((char *)buf + 2, payload_size);
    buf[0] = crc8(0, (uint8_t*)(buf + 2), payload_size);
    buf[1] = sender_packet_id++;

    while (!radio.sendWithRetry(RECEIVER, buf, total_size, 1, 5U))
    {
      // radio.receiveDone() switches the
      // radio into receive mode
      if (radio.receiveDone())
      {
        // if receive is done instantly
        // process the packet and move on
        read_packet(true);
        continue;
      }

      // wait random time in case
      // a collision happened
      delay(random(5, 30));

      read_packet();

      // wait for radio to be ready to send
      while (!radio.canSend()) ;
    }

    return true;
  }

  return false;
}

void loop()
{
  read_packet();

  send_packet();
}

I also have a network capture of both sides.
Here is the capture for the Client: https://ufile.io/v945jl8i
Here is the capture for the Server: https://ufile.io/yn36rjw4
I've figured out that it happens somewhere in the while (!radio.sendWithRetry(RECEIVER, buf, total_size, 1, 5U)) loop but I can't figure out what exactly goes wrong and how I can fix it.
Any help would be greatly appreciated!
Edit: I'm running a simple python HTTP server (python 3 -m http.server 8080). And as client i'm using curl (curl <server address>:8080)
Here are the Commands I use for starting slip:
modprobe slip
slattach -vL -s 115200 -p slip /dev/ttyACM0
ifconfig sl0 192.168.2.1 pointtopoint 192.168.2.2 up

I switched the two IP addresses for the other side.
Also interestingly it sometimes seems to randomly work for one or two requests, so i'm guessing some kind of race condition.
I also made sure that i'm connecting to the correct serial ports.
PS: i'm kind of new to C++ so any recommendations on best practices are also appreciated

Are you running an actual server on the receiver?

edited the question to add the info. TLDR: yes, I have a server running