text:
Multiple definition error when linking firmware.elf
I just can't wrap my head around on how to properly work with multiple files. My code has been getting quite big so I decided to split all the classes into one file each. So I'm left with 6 files:
dataHandler.cpp
fileHandler.cpp
header.cpp
main.cpp
request.cpp
sensorData.cpp

header.cpp includes all the header files, and main.cpp the setup() and loop() functions.
Visual Studio Code shows me no errors while compiling. The includeguards have the name convention: CLASSNAME_INCG
So in my main.cpp for example I have something like:
#ifndef HEADER_INCG
#include "header.cpp"
#define HEADER_INCG
#endif

#ifndef SENSORDATA_INCG
    #include "SensorData.cpp"
    #define SENSORDATA_INCG
#endif

#ifndef DATAHANDLER_INCG
    #include "DataHandler.cpp"
    #define DATAHANDLER_INCG
#endif

setup()
{
    ...
}

...

When going into a class-file I have it defined in the following way (fileHandler.cpp):
#ifndef HEADER_INCG
#include "header.cpp"
#define HEADER_INCG
#endif

#ifndef FILEHANDLER_INCG
#define FILEHANDLER_INCG

class FileHandler{
    ...
}

#endif

So in summary I include the headerfile into every file, with includeguards arround. If I wouldn't include it I would get errors that crucial libaries like Serial etc. are missing. But when including the header into every file compiliing works just fine, but when it comes to linking the files togehter I get an error of multiple definitions.
So how can I define the headerfile just once for all files albeit I need it in every file?

you use the guards wrong. see some library for correct use and use .h files

Rule #1:
Header file extension is ".h". Files with ".cpp" are ususally compiled as separate compilation units into the object file. If you have any function definition (= declaration + implementation) or any global variable in more object files, it'll fail to link.
Rule #2:
No definitions in headers - variables and functions will cause this error if you include .h file into more .cpp files. If you need super global variable, you have to use declaration with extern modifier and you have to define it in one of the .cpp files. But only one! Also there can be only function prototypes (declarations) in header file. Implementation have to be only once in one of the ".cpp" files.

It's usually in the first chapter of books about learning C/C++.
Really short example:
// myLib.h
#ifndef _myLib_h_guard_
#define _myLib_h_guard_

void myFunction(); // function prototype (declaration)

extern int mySuperGlobalVariable;  // variable declared as extern, there must be definition somewhere

class MyClass {
public:
  int someMethod(); // method declaration

  int anotherMethod() { return 1; }  // definition inside of class works, but sometimes is less readable
};

#endif

// myLib.cpp
#include "myLib.h"

void myFunction() { // function implementation (definition)
  // do something...
}

int mySuperGlobalVariable; // definition

int MyClass::someMethod() { return 2; } // method definition

// main.cpp
#include <myLib.h>

int main() {

  mySuperGlobalVariable = 10;

  myFunction();

  MyClass instance;
  int first = instance.someMethod();
  int second = instance.anotherMethod();
}

Could you maybe give me an example on how to do this properly? I'm sure this sounds trivial to you but I hardly understand what you've said.

Thanks a lot :) I tried to declare and initialize it in myLib.cpp and forgot the extern-keyword in myLib.h.

you can use #pragma once instead of the old fashioned #ifndef _myLib_h_guard_ :p


text:
Arduino Nano Midi to cv convertor interesting issue
I created the circuit in this schematic on protoboard,

and the code,
https://github.com/elkayem/midi2cv
I use a dual opamp and a single dac, because i only need note and velocity.
The opto i use is, H11L1
It works but has a strange issue that i can not figure out.
The author says the code supports midi notes from 21 to 108.
When I send midi notes to test the device,
(Arduino powered with +12, TL082 Opamp powered with +15 to GND )
The notes <= 36 gives +15V in the output of the opamp.
The note 37 gives +3.43V
The note 38 gives +1.7V
.
.
.then it increments as expected until note 108 which gives +7.52 V
Also to add I have +1.5V DC offset on the both outputs of the opamp.
(This, i can live with but i would love it not to happen. )
I would be very happy if you help me on this, thank you.

Find out what voltages are output by the DAC, and what voltages the opamp can handle.

I changed the opamp to LM358 and all problems solved it works perfectly!
If you have enough motivation and time please explain me why, but i will research and learn anyway.

source: Stack Exchange

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

sort: votes


text:
74HC595 shift register not working
I got my Arduino kit a few days ago and I've been going through some of the tutorials.
I got to the 8 LEDs with a shift register tutorial, where I got stuck. Nothing would light up after I plugged everything in and uploaded the sketch.

This is the circuit I've attempted to recreate using Fritzing, and the following is the code I used, from the tutorial :

int tDelay = 100;
int latchPin = 11;      // (11) ST_CP [RCK] on 74HC595
int clockPin = 9;      // (9) SH_CP [SCK] on 74HC595
int dataPin = 12;     // (12) DS [S1] on 74HC595

byte leds = 0;

void updateShiftRegister()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, leds);
  digitalWrite(latchPin, HIGH);
}

void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

void loop()
{
  leds = 0;
  updateShiftRegister();
  delay(tDelay);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(tDelay);
  }
}

I have also attempted to use an 8-segment digit display using the same shift register, also failing.
Is there something wrong that I am doing or could it be that the little chip is broken?
I accidentally discovered that when I swap the ground from pin 8 on the 595 to 5V, all the LEDs will light up.
Update : I got the same circuit in Tinkercad, some kind of Arduino simulator.
After dropping in the code and running the simulation, after it lights up the 5th LED, I get this warning :

However, when I change the 220 ohm resistors to something like 500 ohm resistors, that pop-up is gone. Could this be another reason of why my chip could be possible broken at the moment?

LEDs light up because of protection diodes on the inputs/outputs. You've got negative voltage on the outputs, so current flows.
I'd worry about OE input, as it's hardwired to the ground. Protection diodes are for the small currents only so i'd expect burning protection diode and after that /OE might get destroyed.

BTW: code + schematics is working.

Okay... thanks for confirming that. Guess I'll have to buy a new shift register... the issue is I have no idea where in the town I can get electronics like that. Thank you, anyway!

And check if connections in breadboard aren't too loose. I've got one dead "pixel" because of it.

I tried the config in different places on the breadboard and with different wires... same result.

the power and ground rails on breadboards are sometimes interrupted int the middle of the breadboard

A few thoughts
Connecting 5v to pin 8 (=gnd) is not a good idea.  It may not cause any damage if pin 16(=vcc) is also connected to 5v but i would not rely on that. Generally reverse voltage will kill all electronics unless they are specifically protected against it.
For the LEDs I would use 1k to 10k ohm resistors.  This is giving still enough current to see them light up. Using 330ohms just takes more current and makes the leds extremely bright (3mA is enough).
For testing whether something simple is working, like a shiftregister, flipflop, or logic gate, I would not use a microcontroller at all. You can just use a couple of switches attached to the CLK and LATCH pins, with a slide switch attached to the DATA pin to select 1 or 0 input bit. This eliminates one point where stuff can go wrong.
Whether or not you put in a bypass cap will not make a difference if your supply is sufficiently capable and stable. I use the charger of my broken laptop that can deliver 5v at up to 2.5amps. In this setup I don't need any bypassing, although it's still best practise to include it.
Adding LEDs to the serial IN, latch, and shift clock, and serial output may also help nail down the problem.
Also make sure you don't have dodgy cables. If any of the wires is broken or has microscopic internal breaks this can lead to misbehaviour and is very difficult to find.
One thing I did when I tried if my chips worked was to first use a known good chip from a colleague to confirm the circuit was ok.
Depending on where you take your power from, adding a power LED is usually a good idea as well. If you power everything from a powerbank you may find that some of them just shutoff the outputs if there is less than a certain threshold current flowing out.  This can leads to effects like "the circuit worked for 30 seconds and then died. After disconnecting and waiting a couple of seconds and repluging the power it works again..."  For this reason I include a power LED in just about every project of mine.

Your answer seems to be getting some down votes. Perhaps if you took the trouble to properly construct English sentences that would help? Sentences start with a capital letter, and the word "I" is capitalized. This isn't a mobile phone message.

Really? That seems unduly harsh to down vote an answer because it is not punctuated and does not start sentences with capitals correctly. I also could not see that as a reason in the help center https://arduino.stackexchange.com/help/privileges/vote-down . Now if it were the English literature SO community, I would tend to agree. It is a shame that people are not required to give a reason for the down vote... I to have received several on the arduino site and often have no clue why.

This is a good discussion on troubleshooting best practice (especially e.g. the point about testing with switches instead of microcontroller code).  I've made the grammatical edits, and removed some of the unnecessarily provocative phrases ("stupid idea", etc.)

The only way i found to make this circuit to work
is by putting  8 pullup resistors (1k) from vcc
to each of the output pins of the 74hc595 whithout
them no leds light up ever.

One omission I see is that you don't have a bypass capacitor across Vcc and Gnd of the 74HC595. Without it you would have inconsistent operation.
But if you had the power reversed on the chip then that will be the major problem and I'm sure the chip is damaged.
What I would do is put leds on the clock, data, and latch lines. And then make your delay very long, 1 second, so that you can see what the lines are doing. Just to confirm that you are getting the output that you expect. But first put a bypass cap across the chip.
Also double check that your leds are in the right way.

I'm quite a newb in the electronics field, may I ask what am I supposed to do, in a step-by-step fashion? I followed the guide I got with the kit and it didn't have any capacitors involved. The LEDs are the right way, I tried each one of them out before and they all light up.

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


text:
Newbe needing help with fixed string length
im trying to build a bit of test equipment that will talk to some software and it needs to send a fix string. when the voltage changes the string length does as well. i need to cap the results to 4 in length. (sorry for not knowing the correct terminology. this is the output i need -

Where,
X = Flag CP Value
_ = Space
P = Polarity
C = CP Received value
Y = Flag Field Gradient
F = Field Gradient Received value
Z = Flag Contact CP
T = Contact CP Received value

There is also a line feed and carriage return present at the end of each string.
The polarity indicator will only display a minus sign ‘-‘ if the received value is
negative otherwise no assignation will be transmitted. Although the overall string
length is constant the values for each measurement are right justified and hence a
space will be present should the value of the measurement not necessitate the
utilisation of all allocated character spaces.
Sample Outputs
< X -89 Y -1989 Z -1096 >
< X 1039 Y 8 Z 78 >

this is my code so far
#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads1(0x48);     // Use this for the 16-bit version
Adafruit_ADS1115 ads2(0x49);

void setup(void) {

  Serial.begin(9600);

  ads1.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 2mV
  ads2.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 2mV

  ads1.begin();
  ads2.begin();
}

void loop(void) {

  int16_t results01,results02,results03;

  results01 = ads1.readADC_Differential_0_1();
  results02 = ads1.readADC_Differential_2_3();
  results03 = ads2.readADC_Differential_0_1();

  Serial.print("X ");
  Serial.print(round(results01 * multiplier));

  Serial.print(" Y ");
  Serial.print(round(results02 * multiplier));

  Serial.print(" Z ");
  Serial.print(round(results03 * multiplier));

  Serial.println();              // send a cr/lf
  delay(500);
}

Any help pointing me in the right direction would be Amazing.
Thanks in advance
Joe

What is it that your trying to "cap to 4 in length"? I'm assuming you have no control over how the device sends its string, and that you want to format the device's results for the terminal? Can you show a sample of what you want the end-result to look like?

< X      -89 Y -1989 Z -1096 >

each of the reading im getting need to be 4 in length . im reading -2000 to +2000 but say when the voltage is -89 it shortens the string.

So you want to print, e.g. "15" as "0015"? How about "-1500"? How can that take fewer than 5 printing characters?

sorry i mean 5 characters.  "___15" or " __-15"  or "-1500" or "_1500"  like i said im very new to this and im amazed i have got this far without asking for help . :)

The printf() family of functions comes handy when you need
this kind of control over the formatted output:
/*
 * Format a number as 5 characters.
 * Returns the string in a statically allocated buffer.
 */
char * format5(int x)
{
    static char buffer[6];  // 5 chars + terminating NUL
    snprintf(buffer, sizeof buffer, "%5d", x);
    return buffer;
}

void setup() {
    Serial.begin(9600);
    Serial.println(format5(15));
    Serial.println(format5(-15));
    Serial.println(format5(-1500));
    Serial.println(format5(1500));
}

void loop(){}

output:
   15
  -15
-1500
 1500

thanks for this. as been very new to this I have tried and cant  get this working...


text:
Cannot get esp8266 - 12 wifi module to always read analogRead incoming voltage accurately
So I have and arduino uno that is firing an output on pin 8. This code is not in this file just to be clear. From there Im taking that output and using it to fire pin 0 on the wifi module. Im using pin 0 because from what I understand all other pins have a pullup or pulldown resistor. When pin 0 is hot I want to print that value. Sometimes it works when I do it other times the analog values reads very low. I am using the 3.3v from the arduino uno and I plan to get a voltage regulator for the wifi module but would this cause this kind of issue? I am very very new to arduino so if anyone has any ideas I would appreciate a very dumbed down explanation. Thanks a lot. Also the reason why I have the delay turned down so low is because it seemed to make the analog signal pick up more often. Im not sure why this would matter but at a delay of 3000 it would almost never change analog value but when I turned the delay down to one the value came through much more consistently. Currently the code just outputs low analog numbers and occasionally pops up 1023 when voltage is applied but not consistently. And sometimes it just stops altogether until I keep trying for a while. I am getting voltage to the pin however so I know I have a complete circuit and power.
include
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

const char* ssid = "ENDOWED Underwear";
const char* password = "endowwear";

HTTPClient http;

static const uint8_t D0   = 16;
static const uint8_t D1   = 5;
static const uint8_t D2   = 4;
static const uint8_t D3   = 0;
static const uint8_t D4   = 2;
static const uint8_t D5   = 14;
static const uint8_t D6   = 12;
static const uint8_t D7   = 13;
static const uint8_t D8   = 15;
static const uint8_t D9   = 3;
static const uint8_t D10  = 1;

int featherPin = D3;

void setup() {
  Serial.begin(115200);
  pinMode(featherPin, INPUT);

  WiFi.begin(ssid, password);

  while(WiFi.status() != WL_CONNECTED) {
    delay(10);
    Serial.println("Waiting for connection");
  }
}

void loop() {
  int sensorValue = analogRead(featherPin);

  if (WiFi.status() == WL_CONNECTED) {
        Serial.println("yay connect");

        http.begin("http://10.150.40.121:3000/");
        http.addHeader("Content-Type", "text/plain");

        int httpCode = http.POST("Message from ESP8266");
        String payload = http.getString();
//        Serial.println(payload);
        http.end();

    } else {
        Serial.println("Error in Wifi connection");
    }

    if (sensorValue > 850) {

      http.begin("http://10.150.40.121:3000/home");
      http.addHeader("Content-Type", "text/plain");

      int httpCode = http.POST("Message from ESP8266");
      String payload = http.getString();
      Serial.println(payload);
      Serial.print("hi");
      http.end();
      } else if (sensorValue < 850) {
        Serial.print(sensorValue);
//        Serial.println("I am not hot");
      }

//  digitalWrite(trigPin, LOW);
//  delayMicroseconds(1);
//  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(2);
//  digitalWrite(trigPin, LOW);
//
//  pinMode(echoPin, INPUT);
//  duration = pulseIn(echoPin, HIGH);
//
//  inches = (duration / 2) / 74;
//  Serial.println(inches);
//
//  spaceIntruded = inches;
//
//  if (spaceIntruded <= 50 || spaceIntruded >= 900){
//      digitalWrite(ledPin, HIGH);
//      digitalWrite(hornPin, HIGH);
//      Serial.println("Intruder Detected!");
//      Serial.println("Sending text Notification...");
//      delay(500);
//      Serial.println("Armed...");
//  }
//
//  else{
//    digitalWrite(hornPin, LOW);
//    digitalWrite(ledPin, LOW);
//  }
    delay(1);

}

When pin 0 is hot I want to print that value...? What value? What do you mean by "hot"?

When pin 0 on the Arduino uno is hot meaning it has 3.3v applied to it I want to analogRead the change in value. If no voltage is applied it should read as a lot number and when voltage is applied it should read as a high number and sometimes it does but it in no way consistent. Im not sure if its because Im taking the 3.3v from the arduino uno but i also tried taking it from the 5v on the arduino uno and steeping it down with a voltage regulator and Im getting the same issue. However it was adjustable voltage regulator. Im going to get one that is specifically for 3.3v.

Do you have the pin connected to the analog input pin as well as pin 0?  You do know that the ESP8266 has only one analog input, and that is a special pin and not one of the normal Dx pins, yes?

No I didnt and I not to clear on what you mean by DX pin and I have pins soldered for each pin and im am maunally touching the output from the arduino uno to the 0 pin and no consistent change occurs. As of right now its working at all but at times it does. But the pin is not connected to an analog pin its just a pin. All the pins are soldered on and im only using pin 0 cause it doesnt have a pullup pulldown internal resistor. When tried using the other pins I couldnt get the value to change at all. Only when I chnaged to 0 did it read the change sometimes.

https://www.microcenter.com/product/460313/feather-huzzah-with-esp8266-wifi
This is the wifi module I am using

The pin labelled ADC is the only one that can be used with analogRead. And unless that board includes a divider it can't read more than 1V.

Do you think I could step down the voltage to one volt and work with it that way. I'm only keeping track of one value or how would ypu go about it. I have two files one for arduino uno and one for the feather. I just want to read and chnage the state of one pin. I set of a sensor in the arduino program that fires an input and makes kne pin on the Wi-Fi module that I can read the change from low to high. I also dont know much about rx TX but ive read I can talk to the module or should I use a different Wi-Fi module. Thanks again for your help.

Yes. Yes you can. Google knows how.

I understand Google knows how. Ive googled my way up to this point. I'm just seeking some direction from someone with experience becuase I just started learning two days ago so certain things I'm confused on. Ive read dozens of articles so if you could guide me in a direction or maybe explain it from your point of virw I would greatly appreciate it. Thanks a lot for your help.

The key word, which I have already mentioned, is "divider". Specifically voltage divider. A basic principle of electronics that you need to learn. The board may already have it though, so check the manual or schematic.

This is cool. Thank you. I need this. My last question is the pin labeled adc can I treat this pin like a regular analog read as far as the code goes and do you know why I cant do a digital read. Is it because its floating until its not. I'm mainly curious now. Thanks again. This is helpful.

why do you want to use troubled ADC of the esp8266 if you have an Uno with 5 good analog inputs in project setup?

The ADC pin can only be used with analogRead(). No other pin can, and nothing else can be done with the ADC pin. It is directly connected to the ADC internal to the chip and nothing else. You can't use digitalRead(), digitalWrite(), pinMode() or analogWrite(). It doesn't even have a pin number to use with those functions.

Majenko is right that the only pin you can use with analogRead is pin A0. I would add that I think you are making a mistake in assuming that any of those other pins can be used. I'm also new to this but I have two NodeMCU ESP8266 units and only a few pins are actually useful as input or output. Many of the pins are dedicated to other uses like serial RX/TX, storage, and RST. Pin D3, in particular, is reserved for FLASH. Some info here.

I would also add that analogWrite does NOT just set some voltage level on a pin. The pins can only go to 0 or 3.3 -- i.e., completely on or completely off. In order to emulate some voltage level in between, the ESP8266 will use PWM, which is basically switching the voltage on and off quickly to mimic the intermediate voltage.

Analog to Digital conversion is one aspect1 where the ESP8266 is very poor. It has a single ADC pin which can read a maximum of 1V.
That pin is the only pin you can use with analogRead(). Any attempts to use any other pin just use that pin instead. The parameter (pin number) to analogRead(pin) is ignored and no matter what you do that one single ADC pin is what is being read. Also the pin cannot be used for anything else. None of the digital functions can be used with it since the pin doesn't have a GPIO number associated with it.
Some boards include a simple voltage divider on the ADC pin to allow higher voltages to be read, such as the NodeMCU:

If your board doesn't have such a divider you will have to implement it (or something similar) to be able to read the 3.3V incoming voltage.

1 The ESP8266 is great for WiFi but pretty poor for everything else. It is seriously starved of internal peripherals (it doesn't even have I²C). For a more feature-rich solution you might consider upgrading to the ESP32.


text:
ESP8266 Switching firmware on the fly
Can you help me out to understand if this is possible with ESP8266 / 32 ?
I have a main binary that i upload to the chip, let's call it A - that's done from arduino.
A starts to work, but communicates every couple of minutes with central server polling for a task.
If there is a task - let's call it B
A downloads it and stores it on SPIFFS.
Now what should happen is that A uploads it, reboots and B starts to work.
When B finishes it loads up again A and the circle closes - this process goes on forever.
Questions:
1) Is it possible that a stored on SPIFFS binary file can be uploaded to the chip? Like OTA does via www.
2) Can i somehow store A onto the SPIFFS, so that when B finishes i reupload A ?
Thanks for any input into this

why don't you have a single program that does both A and B?

Look at what ArduinoOTA does.

@Majenko - right, but i would then have to ask for firmware via WWW i don't speak to Web server, i download the binary from a dedicated grid computing system.
So maybe you know if i can i download binary to SPIFFS and upload to chip other way than OTA?

@jsotola because B changes and is sent from a distributed system, has nothing to do with A. Binaries sent from distributed system will be different all the time.

Look at what ArduinoOTA does. I say again. Look at what it does. Don't use it. Just look at what it does.

@Majenko got your point now, thx.

I think i've found an answer to my question here
https://www.esp8266.com/viewtopic.php?f=32&t=11324
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

#include "FS.h"

void setup() {
  Serial.begin(115200);
  Serial.println();
  SPIFFS.begin();
  Dir dir = SPIFFS.openDir("/");

  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, LOW);

  File file = SPIFFS.open("/blinkESP.bin", "r");

  uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
  if (!Update.begin(maxSketchSpace, U_FLASH)) { //start with max available size
    Update.printError(Serial);
    Serial.println("ERROR");
  }

  while (file.available()) {
    uint8_t ibuffer[128];
    file.read((uint8_t *)ibuffer, 128);
    Serial.println((char *)ibuffer);
    Update.write(ibuffer, sizeof(ibuffer));

  }

  Serial.print(Update.end(true));
  digitalWrite(BUILTIN_LED, HIGH);
  file.close();
}

void loop() {

}

Will give it a try and revert back to confirm if it answers my question.

Confirmed,works like a charm. Flashes firmware with a file from SPIFFS.

The esp8266 Arduino package has 3 libraries for firmware update.

ArduinoOTA for upload from Arduino IDE
ESP8266HTTPUpdateServer for upload with web browser
ESP8266httpUpdate library to check a web server for new version of the
firmware


text:
Divide two integers resulting into a float
Suppose I want to divide two integer variables and put the result into a float.
In order to prevent integer division do I have to program like this:
    int i = 6312;
    int j = 258;
    float f;
    f = i;
    f = i/j;

Or can I straightforward program like below and the compiler makes sure it is handled the 'proper' way:
    f = i/j;

why don't you run a test?

Isn't there a typo in your first block of code? Did you mean to write f = f/j;? Otherwise, (a) why bother assigning f = i;? and (b) the last line of the first block is exactly the same as the line in the second block... So the question doesn't make much sense... unless you made a typo...

@Greenonline: you are correct, in the first block of code I should have written f = f/j;

Cast the integers to float before doing the calculation.
float f = float(i) / float(j);

or
float f = (float) i / (float) j;

Always be clear how the calculation should be done, so the compiler will do what you want it to do.

or float f = (float) i / j;

@Juraj, that relies on the compiler to do a float calculation when a float and a int are involved. I prefer to make it clear for someone reading the code and for the compiler what is going on without having to think about it.

As Arduino is C++, you should really use a static cast, to be technically accurate. However, for Arduino code it probably doesn't really matter.
So either
float f = static_cast< float >(i) / static_cast< float >(j);

or
float f = static_cast< float >(i) / j;

Note: Using a static cast on each operand, rather than just one, is  useful to quiet any warnings about the loss of precision with int to float, which typically needs to form a rounded float for large int values.
See C++ int float casting for more info.

Just to add to Jot's answer: Strictly speaking, it should be pointed out that (float) is C, whereas float() is C++.

Also, as you had meant to write in your question:

int i = 6312;
int j = 258;
float f;
f = i;
f = f/j;
Yes, that would work. However, even though it seems quite elegant, it could cause confusion later in time, when someone else examines the code - unless you added a comment explaining why.
it is probably best to keep the code simple and obvious (for debugging purposes) unless you are deliberately intending to obfuscate the code.


text:
Have terminal bash script act as virtual "button" for Leonardo?
I've searched quite a lot for this and tried to piece bits of code together but with no luck so far.
All i'm looking to do is have a command I can run in terminal/bash script on the Mac trigger some code to run on the Arduino (Leonardo)
It doesn't matter what data the Mac sends, I only have one command to run so it doesn't need to look like separate buttons or anything.
So far i've tried
int incomingByte = 0;   // for incoming serial data
void setup() {
Serial.begin(9600);
}

void loop() {

    // send data only when you receive data:
    if (Serial.available() > 0) {
            // read the incoming byte:
            incomingByte = Serial.read();
//run commands
  }
    }

and then from terminal/script both
echo "1" > /dev/tty.usbmodemHIDPC1 9600

and
screen > /dev/tty.usbmodemHIDPC1 9600

I see the Arduino light flash when I run those two commands in terminal which would seem to suggest that its receiving the data, but nothing runs.
I have stripped out my code that is due to be run by the way for simplicity. I've got working keyboard presses ready to go to enter in the "run commands".

how do you know that the code does not run?

stty -F /dev/tty.usbmodemHIDPC1 speed 9600 && echo "1" > /dev/tty.usbmodemHIDPC1

@jsotola it's set to write some letters with the keyboard, but nothing is written. Will try Majenkos edit below.

@Majenko neither of those commands did anything unfortunately, just locked terminal up - the Arduino hasn't even flashed either

Also asked at: http://forum.arduino.cc/index.php?topic=588990 If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information.


text:
Reading Multiple Analog Input Pins
I am having a bit of trouble trying to read multiple Analog Input Pins (A0 and A3, in this instance). I am using a Pololu A-Star 32U4 LV Robot Controller (https://www.pololu.com/product/3116), and am using the Arduino IDE to program the board; it is recognized as a Arduino Leonardo. I am using the Joystick Library (https://github.com/MHeironimus/ArduinoJoystickLibrary/tree/version-2.0) to have the controller be recognized by Windows as a Game Pad (irrelevant to the issue I am seeing, I believe).
I am simulating an Axis by using a potentiometer, with the data line running into the Analog Input, the 5V baseline coming from the board, and the Ground on the opposite of the Analog Input. This does indeed cause the values to change.
The issue that I am specifically running into is when I attempt to get the analog value for each pin that I am monitoring, it appears that the values of the other pins change at the same time. Because I am trying to use the Analog Pin values to drive an X/Y Axis, this issue manifests itself in an X/Y graph that appears linear with some sort of defined slope (with an X change leading to a Y change); rather than the expected X Horizontal only movement and Y Vertical only movement.
Further.. when I remove the second Axis (ie. only using X or only using Y), it appears to track as I expect, with the Pot moving the axis (changing the value of the Analog Input).
Here is where I check the pins in the loop:
  // Read the Analog Pins and update the controller
  for(uint8_t a = 0; a < TOTAL_AXIS_PINS; a++) {
    checkAnalogAxisState(a, axisPins, axisPinVals);
    delay(10);
  }

And here is where I attempt to send the X/Y Axis changes based off of the readings coming from the Analog Pins:
// Checks the Analog Pin for a value to be used as the Axis value. Only updates the state if it
// has been found to have changed. Will update the Joystick Axis based on which pin it is currently
// looking at
void checkAnalogAxisState(uint8_t pinIndex, uint8_t analogPins[], int analogPinVals[]) {
    uint8_t analogPin = analogPins[pinIndex];

    // The trick when using multiple analog sensors is to read them twice, with a small delay after each read (10ms is good)
    // then discard the first reading. This is because the ADC multiplexer needs switching time and the voltage needs
    // time to stabilize after switching.
    int currentState = analogRead(analogPin);
    delay(10);
    currentState = analogRead(analogPin);
    delay(10);

    if(currentState <= analogPinVals[pinIndex] - 5 || currentState >= analogPinVals[pinIndex] + 5) {
        if(analogPin == X_AXIS_PIN) {
            Joystick.setXAxis(currentState - ANALOG_ADJUSTMENT);
        } else if(analogPin == Y_AXIS_PIN) {
            Joystick.setYAxis(currentState - ANALOG_ADJUSTMENT);
        }
        analogPinVals[pinIndex] = currentState;
    }
}

I try to keep the Pin and the Value of that pin in an array, but even when I do this with 2 separate variable and function calls, I still see that the Analog values change at the same time.
Here is the full sketch, I can include the full contents of ControllerDefines.h and ControllerFunctions.h if they will be helpful, but I have pulled the relevant functions from each:
#include <AStar32U4.h>
#include <Joystick.h>
#include "libraries/ControllerDefines.h"
#include "libraries/ControllerFunctions.h"

void setup() {
  // Setup pins for the Axis controls
  for(uint8_t a = 0; a < TOTAL_AXIS_PINS; a++) {
    pinMode(axisPins[a], INPUT);
  }

  // Setup Joystick
  Joystick.begin();
  Joystick.setXAxisRange(-ANALOG_ADJUSTMENT, ANALOG_ADJUSTMENT);
  Joystick.setYAxisRange(-ANALOG_ADJUSTMENT, ANALOG_ADJUSTMENT);

  // Setup Serial Comm
  Serial.begin(9600);
}

void loop() {
  // Read all button states and update the controller
  for(uint8_t b = 0; b < TOTAL_BUTTONS; b++) {
    checkButtonState(b, buttons, buttonStates);
  }

  // Read the Analog Pins and update the controller
  for(uint8_t a = 0; a < TOTAL_AXIS_PINS; a++) {
    checkAnalogAxisState(a, axisPins, axisPinVals);
    delay(10);
  }

  // Delay before polling buttons again
  delay(50);
}

Edit:
I have taken a plot of the 2 Array values over time, as can be seen here. This is with the Pot hooked up to A3, which is axisPinVals[0]:

Moving the Pot to A0 gives the following:

Using the modified code below:
  // Read the Analog Pins and update the controller
  for(uint8_t a = 0; a < TOTAL_AXIS_PINS; a++) {
    checkAnalogAxisState(a, axisPins, axisPinVals);
    delay(10);
  }

  // For the plotter
  Serial.print(axisPinVals[0]);
  Serial.print(",");
  Serial.println(axisPinVals[1]);

As you can see, the two values track together. This same behavior is not present in the buttons presses, and multiple buttons can be held at the same time with no issue.
I would expect each variable (line) to track independently of one another, when the Pot is moved from A0 to A3.

Just to clarify, do you have two pots connected while testing? If not, you are reading "floating" input which will not give valid results.

I think you're on to the issue, will figure out definitively tomorrow

I can't reproduce your problem. Your code is a bit lengthy to say for certain whether or not A0 and A3 clash when read in quick succession. Try this test code and see what results you get:
void setup() {
 Serial.begin (115200);
 while (!Serial) {}  // wait for Serial

 Serial.println ("Starting");
}

void loop() {

int a, b;

  a = analogRead (0);
  b = analogRead (3);

  Serial.print ("A0 = ");
  Serial.println (a);
  Serial.print ("A3 = ");
  Serial.println (b);
  delay (100);
}

I found on my Micro (which has the same processor) that the two inputs were completely independent. For example changing A3:
A0 = 0
A3 = 195
A0 = 0
A3 = 453
A0 = 0
A3 = 680
A0 = 0
A3 = 879

And then changing A0:
A3 = 0
A0 = 64
A3 = 0
A0 = 292
A3 = 0
A0 = 427
A3 = 0
A0 = 474
A3 = 0
A0 = 294
A3 = 0
A0 = 48

This was with two potentiometers connected at all times. If you only had one you might get a "floating" input.
I suggest you try the code above and confirm whether or not you get similar results. If you do, then the problem is not "Reading Multiple Analog Input Pins" but something else entirely, like logic in your code.
Even when I changed the delay in my code to 10, the figures reported were still independent. That is, one pot did not influence the other at all.

This is what I expected to see, I'll give it a shot; could be how I have things setup or a problem with the board itself. Luckily, I have a couple Micros on the way as they better suit my project in the end.

Well, it's definitely the board. Running your code, both numbers still track each other, even when I have a single Pot changing the values. Thanks for the help and the test code. I'll accept this after a bit here.

You need to have a pot in each input at the same time for a valid test.

Your joystick would, of course, do that. Your problem might be that you are testing with a single pot, and such a test is not reproducing the live situation correctly.

Ah yeah I can give that a shot too, that would make too much sense actually. I'll try that out here tomorrow.

That was the issue; I was reading a floating pin.

Try reading each input twice in a row, and use the value from the 2nd read.  The input source may need additional time to charge up the sample & hold cap that is read by the ADC in the uC.


text:
Does UNO and Nano have the same pins?
Do Arduino Nano Atmega328p have the same pins as Arduino/Gizduino Uno Atmega328p?

uno and nano are about the two closest together AVR boards; nano is a small uno.

The '328P uC on the boards is the same die. The 328P in DIP has 4 fewer pins brought out (Vcc, Gnd, A6, A7) compared to the surface mount parts. The boards themselves then bring the pins out to edge connectors in physically different locations.

Gizmoduino Uno has SMD ATmega328 with A6 and A7 brought out


text:
Detect power interruption on NodeMCU
Im using a 5v 1A power supply and connected to VIN pin on the NodeMCU. I also use 18650 battery to keep NodeMCU running in case the power supply shuts off due to power interruption.
I'm planning to use the 5V from power supply, convert it to 3.3V with voltage divider and connect it to the gpio to detect power interruption.
Is it possible? Can the NodeMCU handle the current from the power supply?

try to take a look to this answer: https://electronics.stackexchange.com/questions/372717/how-to-detect-power-failure-and-make-micro-controller-save-data-in-eeprom

Yes, you can.  You need to convert the 5V down to 3.3V with a voltage divider. You also need to consider how you are going to operate the ESP8266 when there is no power.

Can the gpio handle the 1A current?

That question makes no sense.

What about the current of the power supply? I'm worried that it may damage the NodeMCU

What about the current of the power supply? Why do you think that factors into anything?

@Tobot What Majenko is trying to say, in the most condescending way that can be conjured at this time, is that you need to do some reading on the fundamentals of electricity. The GPIO pin determines what current it draws from the power supply, not the other way round. A supply could be rated for 1A or 1000A: if a connected device only needs 1uA, it will only draw 1uA.

I really need to do some reading. Thanks @CharlieHanson


text:
SSD1306 allocation failed when adding a constant
I am trying to get this code working:
#include <Button.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RTClib.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS1307 RTC;

// when I remove this part it works...
int mode = 1;
const String periodicSystem[60] = {
    "H", "He", "Li", "Be", "B", "C", "N", "O",
    "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S",
    "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr",
    "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge",
    "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb",
    "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn",
    "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd"
};
/////////////////////////////////////////////////////////////////////

Button button1(7);

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

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  RTC.begin();
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // This will reflect the time that your sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }

  display.display();
}

void loop() {
  DateTime now = RTC.now();
  if(button1.pressed()) {
      display.clearDisplay();
      display.setTextSize(1); // Draw 2X-scale text
      display.setTextColor(WHITE);
      display.setCursor(10, 0);
      display.print(now.second());
      display.display();
  }
}

Whenever I try to add the constant periodicSystem, I get the error SSD1306 allocation failed over Serial. The error also goes away when I remove the part with button1.pressed(). Basically I am not able to add the constant periodicSystem and read out a digital pin at the same time. To me it seems to be some sort of memory issue (I am only adding the constant, I am not doing anything else with it), but my IDE tells me I am only using 52% of the available storage. What am I doing wrong?
Here is my wiring (in reality I am using a 128x32 display, I didn't have the correct part for Fritzing; my display is labeled SDA, SCK, VCC, GND instead of SDA, SCK, VDD, GND; the RTC Module I am using is a DS1307 AT24C32 RTC Module):

Hint: Consider a more memory efficient storage for the string table. Using Arduino String for this is a very very very bad idea. Use character strings and put the whole table in program memory. Ref. https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

Your display needs 624 bytes of RAM for its internal buffer (128 * ((32 + 7) / 8)). The periodicSystem array needs a massive 360 bytes of RAM just for the objects. That doesn't include the memory used to store the actual string data, which by my reckoning is 168 bytes.
So far we're up to 624+360+168 = 1152 bytes of a maximum of 2048.  Over half way and we haven't touched on the serial buffers or other objects that you're using.
An array (const or otherwise) of String objects is by far the least efficient way possible of storing constant string data on an Arduino. You're using 528 bytes of RAM to store what could be stored in 121 bytes of flash.
Personally I would store the data thus:
const char periodicSystem[] PROGMEM = "H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNd";

Each symbol consists of exactly two bytes, and the PROGMEM forces it to stay in flash and never be copied to RAM.
You can get the two bytes of each symbol with:
char b1 = pgm_read_byte(periodicSystem + (i * 2));
char b2 = pgm_read_byte(periodicSystem + (i * 2) + 1);

Then either print them separately, or combine them into a C string:
char symbol[3] = { b1, b2, 0 };

That will include the space character, of course. So you could remove that if you like:
if (symbol[1] == ' ') symbol[1] = 0;

Theoretically you could also change the spaces in the original data to be character 0 if you like - depending on what you do with it, it shouldn't cause any issues:
const char periodicSystem[] PROGMEM = "H\0HeLiBeB\0C\0N\0O\0F\0NeNaMgAlSiP\0S\0ClArK\0CaScTiV\0CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY\0ZrNbMoTcRuRhPdAgCdInSnSbTeI\0XeCsBaLaCePrNd";


text:
How to upload Arduino C code to mBot?
I am trying to program mBot using Arduino IDE. I am connected to the mBot using USB on COM7, I am able to upload a code created in mBlock 3.4.11 fine, using "Arduino Mode" as the editing mode. I would like to proceed to more complex coding now and for this I want to be able to edit the source code directly. The source code seen in the MBlock application seems to be read only, there is a button which should allow editing the code, called "Edit with Arduino". When I press this button, the Arduino IDE opens and I am able to edit the code. The trouble is I seem to be unable to send the code edited this way into the mBot.
When I use the Arduino IDE Sketch/Upload menu item, the code is compiled, but when sending it, I always get following error:

avrdude: stk500v2_ReceiveMessage(): timeout

Note: I was editing and uploading Arduino code before with both Ardino IDE and VisualStudio visualMicro (now Arduino IDE for Visual Studio) without any issues.
I do not know exactly how is the mBlock application handling the upload, but while doing so a folder with the project is created, which contains the following buildprefs.txt - perhaps this could help to understand what it is doing:
build.arch = AVR
build.board = AVR_UNO
build.core = arduino
build.core.path = X:\Users\UserName\mblockExe\Arduino\hardware\arduino\avr\cores\arduino
build.extra_flags =
build.f_cpu = 16000000L
build.mcu = atmega328p
build.path = X:\Users\UserName\AppData\Local\Temp\build3998294614124133332.tmp
build.project_name = project_followLineAuto0_0.cpp
build.source.path = X:\Users\UserName\AppData\Roaming\com.makeblock.Scratch3.4.11\Local Store\scratchTemp\project_followLineAuto0_0
build.system.path = X:\Users\UserName\mblockExe\Arduino\hardware\arduino\avr\system
build.usb_flags = -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
build.usb_manufacturer = "Unknown"
build.variant = standard
build.variant.path = X:\Users\UserName\mblockExe\Arduino\hardware\arduino\avr\variants\standard
build.verbose = true
build.warn_data_percentage = 75
compiler.S.extra_flags =
compiler.S.flags = -c -g -x assembler-with-cpp
compiler.ar.cmd = avr-ar
compiler.ar.extra_flags =
compiler.ar.flags = rcs
compiler.c.cmd = avr-gcc
compiler.c.elf.cmd = avr-gcc
compiler.c.elf.extra_flags =
compiler.c.elf.flags = {compiler.warning_flags} -Os -Wl,--gc-sections
compiler.c.extra_flags =
compiler.c.flags = -c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD
compiler.cpp.cmd = avr-g++
compiler.cpp.extra_flags =
compiler.cpp.flags = -c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
compiler.elf2hex.cmd = avr-objcopy
compiler.elf2hex.extra_flags =
compiler.elf2hex.flags = -O ihex -R .eeprom
compiler.ldflags =
compiler.objcopy.cmd = avr-objcopy
compiler.objcopy.eep.extra_flags =
compiler.objcopy.eep.flags = -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
compiler.path = {runtime.tools.avr-gcc.path}/bin/
compiler.size.cmd = avr-size
compiler.warning_flags = -w
compiler.warning_flags.all = -Wall -Wextra
compiler.warning_flags.default =
compiler.warning_flags.more = -Wall
compiler.warning_flags.none = -w

Which Arduino IDE do you use? How did you get it? Which operating system? May we see the code (just curious)?

@Jot The Arduino IDE is installed by the mBlock application. The version I have is 1.6.5. I am running Windows 10 x64 Pro.

That is an old version. The newest version is 1.8.8. Here is more information about mBot: https://github.com/Makeblock-official/mBot The schematic is in the "pcb" folder. As far as I can tell the hardware and software of the mBot is okay, they know what they are doing. You could buy a cheap uno clone for 3 dollars to learn more about c++ arduino programming.

"That is an old version. The newest version is 1.8.8". Well, that is a version which is bundled with mBlocks. As it is working fine, I am not sure if it is worth messing with the installation. Regarding the C++ arduino programming, I already have experience with that (I own one Uno and one Mega board). I only had trouble making the C code working with the mBot.

Be sure to select correct board (Arduino UNO) and port.
See this guide for details:
https://www.arduino.cc/en/Guide/ArduinoUno#toc5


text:
Newbie question: Set servo at certain degrees when something happens
I am trying to set my servo at f.e. 90 degrees when the friendlyValue of the soil sensor is < 50%. The servo isn't moving at all, is it because the code is running too fast and the servo doesn't have time to reposition in between? I tried putting in delays but that didn't work, how do I fix this?
I am new to Arduino and would appreciate any help.
#include <Servo.h>
Servo myservo;

int dryValue = 1024; // max
int wetValue = 0; // min

int friendlyDryValue = 0; // %
int friendlyWetValue = 100;

int sensor = A0;
int sensorValue;

void setup() {

  Serial.begin(115200);

  pinMode(A0, INPUT);
  pinMode(D6, OUTPUT);
}

void loop() {

  int rawValue = analogRead(A0); // soil sensor

 Serial.print("Raw: ");
  Serial.print(rawValue);
  Serial.print (" | ");

   int friendlyValue = map(rawValue, dryValue, wetValue,     friendlyDryValue, friendlyWetValue);

  Serial.print("Friendly: ");
  Serial.print(friendlyValue);
  Serial.println("%");

if (friendlyValue <50)
{
  myservo.write(9);
  }
  else
  {
    myservo.write(90);
    }
  }

You should call https://www.arduino.cc/en/Reference/ServoAttach with the pin you have to connected to. Also what is the debug output on the serial monitor? And how is the server connected to the Arduino?

have you tried to run a servo demo sketch?

From your statement pinMode(D6, OUTPUT);, It looks you're using pin6 for the servo - ? If so, you need instead: myservo.attach(6); to prepare a servo object to use that pin to drive a servo. Not having done this is the reason why your servo wasn't moving. There is an example program to drive a servo using the servo library on the Arduino site.
Your code will run very fast, but since soil moisture can't change rapidly, the value being read from the soil sensor shouldn't either - unless there is electrical noise (and there will always be some; it's a question of how much). Your print statements should show you how consistent the readings are.
There are a couple of things you can do about it:

Delay for a second or so at the bottom of the loop() function so the servo updates will come less frequently and the servo will have time to track them. This really doesn't help with a noisy signal though, and you probably don't want it to track noise. Also, I don't usually suggest using delays but in so uncomplicated a program as this one, it is really the most straightforward approach.
Calculate the servo position from an average of a few sensor readings rather than using just one. This will help with noise so the servo should only have to track real data rather than data+noise.
Do both. Update less frequently and average a few readings taken a few 10s of milliseconds apart. This will both reduce noise and keep the servo updates to within its tracking ability.


text:
How to store an array of doubles? As array of doubles, Strings or const char *? Then convert back to use?
This seems like an old, solved problem, but I can't find any simple answers.
I'm reading latitude and longitude data as Strings from a file (about 50 points), but they are really double float numbers.
First, I want to find the min/max ranges.   Then, later, I want to do some calculations on them.  I don't really want to keep reading the file, so I want to put them in an array.  But no matter what kind of array I use (3 examples below), the program crashes with stack errors.
const char *latArray[ptsN];
const char *lngArray[ptsN];
//  or
String      latArray[ptsN];
String      lngArray[ptsN];
//  or
double      latArray[ptsN];
double      lngArray[ptsN];

while( myFile.available() ) {
  lineN++;
  String  latGet = myFile.readStringUntil(',');
  double dLat = StrngToDouble( latGet );
  if( dLat < minLat )  minLat = dLat;
  if( dLat > maxLat )  maxLat = dLat;

  latArray[lineN] = latGet;         //  put in String array
  //  or
  latArray[lineN] = latGet.c_str(); //  put in const char * array
  //  or
  latArray[lineN] = dLat;           //  put in double array

  String  lngGet = myFile.readStringUntil(',');
  double dLng = StrngToDouble( lngGet );
  if( dLng < minLng )  minLng = dLng;
  if( dLng > maxLng )  maxLng = dLng;

  lngArray[lineN] = lngGet;         //  put in String array
  //  or
  lngArray[lineN] = lngGet.c_str(); //  put in const char * array
  //  or
  lngArray[lineN] = dLng;           //  put in double array

  String  tmp = myFile.readStringUntil('\n');
}

where
double StrngToDouble( String dblString ) {
  double temp = strtod( dblString.c_str(), NULL );
  return temp;
}

This can compile and work - EXCEPT for reading the arrays and calculating using the floats, no matter what type of arrays I try using.  It just crashes.  What's the best way to resolve this?
Thanks, Rick

You may be out of memory. What Arduino are you using? How large is lineN? How much RAM is statically allocated (the compiler tells you that)?

I'm actually using a Wemos ESP32.  The compiler says:   Sketch uses 285032 bytes (27%) of program storage space. Maximum is 1044464 bytes.
Global variables use 37092 bytes (45%) of dynamic memory, leaving 44828 bytes for local variables. Maximum is 81920 bytes.

And lineN?...

Simplify your program. Read the data and print out what you get. Don't do anything with arrays yet. Once you have it reading and converting fine you can look at creating the arrays and adding the data to them.  To me it sounds like you may be having a buffer overrun. Too many entries being put into your arrays.

And to back that up - the first thing you do in your loop is lineN++, so you start with slice 1 instead of slice 0. Do you then go to fill slice ptsN? That's one more slice than you have...

About the size of lineN: 20 minutes * 1/sec = 1200 points.  Pretty big.  Maybe I should just keep reading the file.

Thanks, @Majenko, for pointing out that I was starting at 1, instead of 0.

The answer to this question is helpful:  https://arduino.stackexchange.com/questions/48935/put-integer-and-double-into-char-array

If lineN ever gets bigger that ptsN-1 then you will crash.  What is ptsN?


text:
The code is working fine with Arduino Uno but not with NodeMCU
I uploaded program MPU6050_DMP6_Multiple.ino (https://github.com/eadf/MPU6050_DMP6_Multiple/blob/master/MPU6050_DMP6_Multiple.ino) to Arduino Uno and it works fine.
When I upload the very same code to NodeMCU 1.0 board in Arduino IDE I have this message from the compiler :
Errors :
Arduino: 1.8.5 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (3M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 115200"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Pera\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Pera\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Pera\Documents\Arduinogttp\libraries -fqbn=esp8266:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M3M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 -ide-version=10805 -build-path C:\Users\Pera\AppData\Local\Temp\arduino_build_960938 -warnings=none -build-cache C:\Users\Pera\AppData\Local\Temp\arduino_cache_811066 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.xtensa-lx106-elf-gcc.path=C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2 -prefs=runtime.tools.mkspiffs.path=C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\mkspiffs\0.2.0 -prefs=runtime.tools.esptool.path=C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\esptool\0.4.12 -verbose C:\Program Files (x86)\Arduino\examples\14.Experiment\OrigMPU6050\OrigMPU6050.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Pera\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Pera\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Pera\Documents\Arduinogttp\libraries -fqbn=esp8266:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M3M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 -ide-version=10805 -build-path C:\Users\Pera\AppData\Local\Temp\arduino_build_960938 -warnings=none -build-cache C:\Users\Pera\AppData\Local\Temp\arduino_cache_811066 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.xtensa-lx106-elf-gcc.path=C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2 -prefs=runtime.tools.mkspiffs.path=C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\mkspiffs\0.2.0 -prefs=runtime.tools.esptool.path=C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\esptool\0.4.12 -verbose C:\Program Files (x86)\Arduino\examples\14.Experiment\OrigMPU6050\OrigMPU6050.ino
Using board 'nodemcuv2' from platform in folder: C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0
Using core 'esp8266' from platform in folder: C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0
Detecting libraries used...
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\sketch\OrigMPU6050.ino.cpp" -o "nul"
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev" "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\sketch\OrigMPU6050.ino.cpp" -o "nul"
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire" "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\sketch\OrigMPU6050.ino.cpp" -o "nul"
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master" "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\sketch\OrigMPU6050.ino.cpp" -o "nul"
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master" "C:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev\I2Cdev.cpp" -o "nul"
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master" "C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire\Wire.cpp" -o "nul"
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master" "C:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master\MPU6050.cpp" -o "nul"
Generating function prototypes...
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master" "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\sketch\OrigMPU6050.ino.cpp" -o "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/lwip2/include" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Pera\AppData\Local\Temp\arduino_build_960938/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DESP8266 "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\variants\nodemcu" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev" "-IC:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire" "-IC:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master" "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\sketch\OrigMPU6050.ino.cpp" -o "C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\sketch\OrigMPU6050.ino.cpp.o"
In file included from C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/Arduino.h:244:0,

             from C:\Users\Pera\AppData\Local\Temp\arduino_build_960938\sketch\OrigMPU6050.ino.cpp:1:

C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/pgmspace.h:16:51: error: __c causes a section type conflict with __c

#define PSTR(s) (extension({static const char __c[] PROGMEM = (s); &__c[0];}))

                                               ^

C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/WString.h:38:76: note: in definition of macro 'FPSTR'

#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))

                                                                        ^

C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/WString.h:39:34: note: in expansion of macro 'PSTR'

#define F(string_literal) (FPSTR(PSTR(string_literal)))

                              ^

C:\Program Files (x86)\Arduino\examples\14.Experiment\OrigMPU6050\OrigMPU6050.ino:225:20: note: in expansion of macro 'F'

 Serial.println(F("FIFO overflow!"));

                ^

C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/pgmspace.h:16:51: note: '__c' was declared here

#define PSTR(s) (extension({static const char __c[] PROGMEM = (s); &__c[0];}))

                                               ^

C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/WString.h:38:76: note: in definition of macro 'FPSTR'

#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))

                                                                        ^

C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/WString.h:39:34: note: in expansion of macro 'PSTR'

#define F(string_literal) (FPSTR(PSTR(string_literal)))

                              ^

C:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master/DeathTimer.h:45:22: note: in expansion of macro 'F'

     Serial.print(F("S:")); Serial.println(time % 60);

                  ^

Using library I2Cdev in folder: C:\Users\Pera\Documents\Arduinogttp\libraries\I2Cdev (legacy)
Using library Wire at version 1.0 in folder: C:\Users\Pera\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\Wire
Using library MPU6050_DMP6_Multiple-master in folder: C:\Users\Pera\Documents\Arduinogttp\libraries\MPU6050_DMP6_Multiple-master (legacy)
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

I am not so good in programming to understand what I can do to solve the problem !
I'd like to use NodeMCU with two MPU6050 and I need help !

you have not asked a question. ...... what research have you done?

While we wait for a 2nd approval on the edit a kind person did for you on your question, may I ask if you have successfully compiled a simple program for the NodeMCU.  As the Arduino Uno and the NodeMCU used completely different processors, you need to take care that both are setup correctly in your IDE.

jsotola , the question is: can You help me understanding this compiler message : :   "Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/pgmspace.h:16:51: error: __c causes a section type conflict with __c " ?

st2000, about NodeMCU  setup You can see from the first line of compiler message "Arduino: 1.8.5 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (3M SPIFFS), v2 Prebuilt (MSS=536)"

It is an issue in esp8266 Arduino core. It is hard to explain, but here is a workaround for you:
In MPU6050_Wrapper.h change word __FlashStringHelper to char for function halt to be void halt(const char* errMessage = NULL).
In DeathTimer.h remove #include <Arduino.h>.
In sketch add before includes #define F(s) s to hide the F macro.

Juraj, MY HAT OFF !!! Thanks for your guidance.It works now like a charm ! I think there is no many people with knowledge like yours !


text:
Is it okay to short IN and GND pins of relay module with controller ground?
I have this relay module that is attached to an ESP8266 (Wemos D1 Mini). Currently, I operate the relay by shorting the IN and GND pins to ground (relay module uses low state to energize) with a transistor hooked to my D1 pin. Relay 5V comes from an external power supply
The circuit diagram can be found here.
The module works fine and all but I am wondering: is it okay to operate it like this ?

the schematic is messy, but it looks ok ..... put a 1k ohm resistor between pin D1 and the base of the transistor for current limiting on pin D1 ..... put a bypass diode on the relay coil to prevent voltage kickback when the relay is de-energized .... the kickback may destroy the transistor

It is not okay. The base-emitter of an NPN transistor acts as a diode. That means pin D1 is shorted to GND via a "diode". You need a resistor to the base of the transistor.
The relay module has already a transistor to drive the relay and also a flyback diode. The control signal that is needed depends on the relay module. The explanation "5VDC to 12VDC (some boards may work with 3.3)" on the page of the relay does not sound reliable.
The relay module on that page is not the module that you have. You have a different module that is activated with a low signal.
Nevertheless, I think that a transistor can be used when the IN and GND of the relay module are connected to the collector of the transistor.
Could you please not try to make the schematic as small as possible. A schematic should explain how everything is connected.
Could try to connect the collector only the IN pin? As in the schematic below.

In your circuit diagram, the mains "neutral" is connected to an earth ground symbol. I hope you are not going to connect a mains wire to ground.

When the IN and GND are connected, then the resistor to the transistor needs to be lower. The ESP8266 can output 12 mA. Let's use 10 mA for safety: (3.3V - 0.5V)/10mA = 280 Ω. I suggest using a resistor of 330 Ω or more.

The relay in the schematic is barebone as I couldn't manage to find the actual module to add to it. I just found the relay that is used on the module as a reference. The relay needs 5v and my microcontroller can only deliver 3v. That's why I'm using my own transistor. As with the schematic, it's my first one ever, first project ever. Thanks for the advice. As with the mains neutral, indeed I'm not connecting it to ground, I messed up the symbol and didn't care after. Again, it was just for reference.

@TermoZour which transistor do you really use? I have added a calculation (below the horizontal line) to my answer. I think 330Ω or 470Ω are good and safe values for the resistor.

I use a BC548B with a 510 ohm resistor on it's input signal

The sdrd-05vdc-sl-c relay is 5v 70mA. The bc548b is maximum 100mA. I'm not happy with that, but it might work. Does the relay work with a 510 ohm resistor to the base? When the transistor is on, you could measure the voltage of the collector. If it is about 0.1v then the transistor is fully turned on and it is okay.

You mean that you pull your Arduino relay control pin LOW, causing it to ground the pin? Yes, that sounds correct. (And you would set it HIGH to not energize the relay.) You might need a low value resistor between the relay's logic pin and the Arduino output if the relay is sinking too much current through the Arduino logic pin. A 100 ohm resistor would prevent sinking too much current through the Arduino logic pin. Try it and see if the relay still energizes.
EDIT:
When I posted my answer the image wasn't loading, so I had to guess as to what you were describing. My guess was wrong, and thus my answer was wrong too.
Since you're driving the gate of a transistor you will need a current limiting resistor or you will overload the logic pin on your microcontroller. (As Jot says in their answer.)
There are 3.3v versions of these logic-driven relay modules readily available, and some even include optical isolation, so why not use one of those?
Take this one for example: https://www.adafruit.com/product/3191
(I don’t think that one has optical isolation.)


text:
strcat char concatenation trouble
Still don't understand about char concatenation.
void setup() {

  testCounter(3);

}

void loop() {
  // put your main code here, to run repeatedly:
}

char testCounter(int countx){
  char a[10];
  strcpy(a, "COUNTER: ");
  strcat(a, printDigits(countx));
  return a;
}

char printDigits(int digits){
  char a[3];
  if(digits < 10) {
    strcpy(a, "0");
    sprintf(a,"%d",digits);
  } else {
    sprintf(a,"%d",digits);
  }
  return a;
}

Error:  invalid conversion from 'char' to 'const char' [-fpermissive]* in testCounter line:
strcat(a, printDigits(countx));

Don't understand this part of error.
printDigits function return char, so... strcat should be work. But why still error?
Please help...

char printDigits(int digits){

You are telling the compiler you will return one character.
 char a[3];

a is three characters. Thus the declaration doesn't match.

You could change the declaration to:
char * printDigits(int digits){

But even that would be bad because a would go out of scope after the function returns.

 char a[3];

That's a little short for putting an integer into. An integer might be 5 characters, plus possibly a minus sign, and you need a trailing "null" at the end. Seven bytes would be safer.

The simplest way of doing what you seem to be wanting is:
void setup() {
  Serial.begin (115200);
  testCounter(3);
}

void loop() {
}

char testCounter(int countx){
  char a[15];
  sprintf (a, "COUNTER: %02d", countx);
  Serial.println (a);
}

Also, here:
  if(digits < 10) {
    strcpy(a, "0");
    sprintf(a,"%d",digits);
  } else {

That won't work because you are putting "0" into a and then overwriting it with sprintf.

printDigits function return char, so... strcat should be work. But why still error?

Look at the prototype for strcat:
http://www.cplusplus.com/reference/cstring/strcat/
It expects char * not char. They are different things. One is a pointer, one isn't.


text:
Analog vs Digital Accelerometers - pro's and con's?
For my project i need to measure accelerations up to 16g. My options are either digital accelerometers such as the MPU6050 or MPU9250 or an analog accelerometer such as the ADXL326.
What are any major pro's and con's of each. number of wires would be almost equal. the digital accelerometer is less pins on the board but i could easily use analog to digital convertors to bypass that. sampling rate is lower at 550Hz for the analog vs 4000Hz for the MPU9250. However i believe 550Hz would be more than adequate. And the biggest difference for me. £2 for an MPU9250 and £12 for the ADXL326!
Does anyone have any general advice on the main differences when choosing between analog and digital? I am measuring suspension motion on a motorcycle and need 5 of these accelerometers.

Is the motorcycle supposed to be driving while you take your measurements? I suspect you would only capture vibrations rather than the (relatively slow) movement of the suspension components relative to each other. Hall sensors with a mechanical linkage are traditionally used to measure suspension movements on cars.
IR distance sensor may also be an option.

Very interesting point. I successfully recorded suspension motion of a motorcycle moving over a specially designed obstacle and compared to a numerical simulation and the answers were relatively close. I've never heard of hall sensors being used. Would you mind sharing a link to an example of such a system or device? I've only seen linear potentiometers used.

It's mostly used in finished products, but both my BMW E39 and MB W211 use hall based sensors for regulation the air suspension (and automatic headlight adjustment) functions. Have a look for "W211 Höhenstandgeber" to see an example, I'm not sure about the licences on those pictures.

Thanks, i had a look at the sensor, and it seems that it uses a linkage system with a hall sensor on a rotary shaft or similar? The type of system i was looking at was more similar to a suspension potentiometer. However i might start a new thread for people to comment on alternatives, but i will still test the accelerometer method as it is an interesting proposal in my mind if the small accelerations from vibration could be filtered out.

The biggest difference is where the measurement (the conversion to digital) is done.  On the digital accelerometer, it is done in the accelerometer itself. On the analog one it is done at the MCU.
For simple arrangements where the accelerometer is near the MCU that makes no difference. However the analog one is more susceptible to noise. With longer wires / traces between the accelerometer and the MCU you can get less accurate results with an analog one since it picks up noise which you are then sampling and including in your results.
The digital one is more immune to that kind of interference - instead it is susceptible to digital noise - corruption of the data as it traverses long wires. But that is less of a problem since it takes far more induced voltage to corrupt a digital signal than an analog one.
One other main difference is that you are limited to the ADC that is in the digital accelerometer. If you want a different resolution you have to use a different accelerometer. With analog, since it has no inherent resolution, you sample at the resolution of your MCU's ADC.
Digital is also easier to interface in modern systems.  Many SoCs don't have analog inputs. So adding an analog accelerometer would mean adding an ADC chip as well - and you don't really want to do that in something like a mobile phone.
So in summary:

Digital is the most convenient, reliable and suitable for current basic uses
Analog is more of a niche product that is rarely used in consumer electronics

The ADXL326 is only an accelerometer.
When you have one, you can measure the output of the sensor with a oscilloscope. For the final project a digital sensor is preferred as @Majenko has explained in his answer.
The MPU-9250 is an accelerometer, gyro and magnetometer. That makes it possible to use sensor fusion (combining the sensors with software calculations for a much improved result).
Are there vibrations involved? An accelerometer is sensitive for vibrations. I doubt if an accelerometer can be used to measure the suspension motion.
By the way, I'm ignoring the MPU-6050 and so should you. The MPU-9250 is less noisy.


text:
Debugging a Nordic MCU (feather NRF52) using Segger J-Link
I have an Afafruit NRF52 board with SD 132 and 5.1 dual fw bootloader.
I implemented RTT logging and controlling (input) and the code is compiled using arduinoBuilder with RTT and debug level 3.
The device uses to control DALI lights but sometimes it hangs, I can see that it does not responses to input and light level never changes.
I want to debug it, maybe getting a stacktrace to see where it hangs, hoping it's a software issue.
Any leads on how to do that ?
Tutorial maybe ?

OpenOCD appears to support both the nRF51 and the JLink.

I haven't tried this, but OpenOCD supports both the nRF52 and the JLink.  Something like (on Linux):
openocd -f /usr/share/openocd/scripts/interface/jlink.cfg -f /usr/share/openocd/scripts/target/nrf52.cfg

might start OpenOCD.
You can then connect with (nRF52 flavour of) gdb (arm-none-eabi-gdb).
You can find information about using gdb with OpenOCD here and here.

i was told i can use it with openocd and eclipse mcu plugin which is nice, but j-link supposed to be much more with his ozone debugger. i just didn't figure out yet how to debug the code with it or how to use the jlinkexe CLI tool to get a stacktrace, or even how to point it to the debug symbols, and of course i compiled with arduino ide so i have no clue where the debug symbols are, i assumenot in the *.bin*.hex files....

and it's feather nrf52 no nrf51 the 51 tag is because i had to put a tag and  there is not nrf52...

Just change 51 to 52 then. OpenOCD supports both.

according to openocd it doesn't support non stop mode. i want to debug a running target, i'll explain. the atget seems to be "stack" doesn't responds, however if i use jlink commander and use halt then go presumably i didn't do much, stopped the cpu then resumed it, however it does causes restart and then i don't know what happen. i need to get a stacktrace or get the PC to be sure the cpu indeed doesn't stop...

Then it sounds like you will be using proprietary Nordic Semiconductor tools to do the job, and we can't help you with that.

bummer :-( maybe i'll go for gdbserver method, for that iu need to see how to convert the project from aduino to eclipse mcu or Segger's "Ozeone"


text:
Leonardo - always on power, status remains between computer reboots?
I'm looking for two answer here.

Is it possible to power a Leonardo to be always on, separate from the power from the USB host - I've tried with a full size Leonardo and a power adapter but for some reason the code didn't run when I did that. I've bought a battery shield too which will be arriving soon.
I want it be power-able via a switch with batteries so that I do a few things. For a start avoid it's boot up time and have it pressing a key as soon as the booted computer sees it (I'm running it as a keyboard/mouse via USB-HID) and also at one point I have the computer send serial data to have the Arduino run a different part of it's code...at this point the host computer reboots. Obviously that means the Arduino will see it's USB host disappear then come back online, will that automatically reset it and thus start it from the beginning again, or can I set it so that with always on power it will carry on doing what it is, irregardless of it's connecting to the host?

Do I need to change code, or libraries to achieve any of this?
With the theory intact answered, here is some of my actual code, i've stripped most of it out as it's just a bunch of keyboard presses
#include <Keyboard.h>
#include <Mouse.h>
char returnKey = KEY_RETURN;
char tabKey = KEY_TAB;
void setup() {
Keyboard.begin();
Mouse.begin();
// delay(60000); //Deploy Delay
delay(3000); //Testing Delay
// Keyboard commands
Keyboard.write(returnKey);
delay(14000);
// Welcome Screen
Mouse.click(MOUSE_LEFT);
delay(100);
}

void loop() {
}

Please show us the code and tell us which libraries you use and where they come from (only for libraries that are not standard included with arduino). Beside the arduino keyboard there are other ways to implement a usb keyboard: https://github.com/NicoHood/HID/wiki/Keyboard-API

Have added an example of my code

When do you expect those keyboard and mouse commands to execute?

@Majenko, at the moment 3 seconds after it's connected to the computer. Or instantly ideally. I plug the power barrel in and the ON and L leds light up - but nothing happens when I plug the USB in. I have to remove the power barrel and then it appears to reconnect to the USB and begin operating. It's as if the power barrel is stopping the USB port from doing anything on my device.

Well, they run 3 seconds after the board is powered up. Regardless of what the USB is doing. I am not aware of any way of saying "Run this once the USB is connected" in the current API.

@Majenko good point, I did consider this - however I also had a 60 second delay and plugged it in a few seconds after the power was fed to it and it didn't do anything. I also have another sketch where I trigger a sketch via a serial command in Terminal but when using the power barrel the Mac doesn't even see it until I remove the barrel. Maybe I have a faulty board that is disabling USB when powered from the barrel? (I'm quite happy for it to run code as soon as powered on, if I need a longer delay I could just trigger it with an external button)

put some code into loop()  ..... right now, you cannot tell if the sketch crashed or if it ran all way through

@jsotola but that's not really my problem at the minute. When I plug in with USB the sketch runs, as soon as I connect the barrel jack, it seems to disengage the USB connection. I'm using an official Arduino Leonardo too made in Italy, not a clone.

Is it possible to power a Leonardo to be always on, separate from the power from the USB host

Yes, that is what the barrel jack is for.

I've tried with a full size Leonardo and a power adapter but for some reason the code didn't run when I did that.

Then your code is wrong. Are you using while (!Serial); or something similar near the top of your code?

For a start avoid it's boot up time

The most certain way of doing that is to not use the bootloader. Instead program the board directly with a hardware programmer disabling (or erasing) the bootloader.

Obviously that means the Arduino will see it's USB host disappear then come back online, will that automatically reset it and thus start it from the beginning again, or can I set it so that with always on power it will carry on doing what it is, irregardless of it's connecting to the host?

The Leonardo only reboots if you open the serial port at 1200 baud, or toggle the RESET pin / button.

Do I need to change code, or libraries to achieve any of this?

It sounds like you may need to, yes - since it's not working at the moment when if the code were correct it should work.

IMPORTANT
Most computers will not recognize the Leonardo until the operating system is fully booted. This means you cannot use the Leonardo to interact with the BIOS or boot menu. The Leonardo does not implement the "Boot Protocol" keyboard which is required to interact with the BIOS or other pre-boot environment.

Thanks Majenko - it looks like I can do what I want in theory then. No "while (!serial)" at the top now, but as soon as I used the barrell connector on my full size Leonardo the code stopped running - it powered on and then it just seemed to ignore the USB connection.
Fortunately in my testing the macOS works with the default keyboard and with the BootKeyboard available in the HID-Project library, so I'm covered there too fortunately.

Have added an example of my code

It is possible to tell if the computer has opened or closed the serial port.
The serial port is located on the Arduino board.
By testing if(Serial) you can check if the serial port has been made active by the computer.
You could send keyboard and mouse events after it became active.
The fading in and out of the led at pin 13 is done by the bootloader. You could upload the sketch with a programmer to run without bootloader.
As far as I know, even without bootloader the serial port is still created.
The Teensy boards have a little more control over the USB interface.
To know what is going on and when a computer is connected, a mini linux computer is a lot easier. For example a Raspberry Pi.
The ATmega32u4 of the Arduino Leonardo has the possibilities and the information is available, but as far as I know, there are no libraries functions to use it.


text:
LED turning on late
I am using an Arduino nano and an ESP8266. I have burnt an Arduino, but when I send a request to the Arduino LED, it takes some time to turn ON.
Here is my code:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3); //Pin 2 & 3 of Arduino as RX and TX. Connect TX and RX of ESP8266 respectively.
#define DEBUG true
#define led_pin 11 //LED is connected to Pin 11 of Arduino
#define LED1 6
#define LED2 7
#define LED3 4
#define LED4 5

void setup()
  {
    pinMode(led_pin, OUTPUT);
    digitalWrite(led_pin, LOW);
     pinMode(LED1,OUTPUT);
 pinMode(LED2,OUTPUT);
 pinMode(LED3,OUTPUT);
 pinMode(LED4,OUTPUT);
    Serial.begin(115200);
    esp8266.begin(115200); //Baud rate for communicating with ESP8266. Your's might be different.
    esp8266Serial("AT+RST\r\n", 5000, DEBUG); // Reset the ESP8266
    esp8266Serial("AT+CWMODE=1\r\n", 5000, DEBUG); //Set station mode Operation
    esp8266Serial("AT+CWJAP=\"shubham\",\"shubh@1\"\r\n", 5000, DEBUG);//Enter your WiFi network's SSID and Password.

    //while(!esp8266.find("OK"))
    //{
     //}
    esp8266Serial("AT+CIFSR\r\n", 5000, DEBUG);
     esp8266Serial("AT+CIFSR\r\n", 5000, DEBUG);
      esp8266Serial("AT+CIFSR\r\n", 5000, DEBUG);//You will get the IP Address of the ESP8266 from this command.
    esp8266Serial("AT+CIPMUX=1\r\n", 5000, DEBUG);
    esp8266Serial("AT+CIPSERVER=1,80\r\n", 5000, DEBUG);
  }

void loop()
  {
   String IncomingString="";
 boolean StringReady = false;

 while (esp8266.available()){
   IncomingString=esp8266.readString();
   StringReady= true;
  }

  if (StringReady){
    Serial.println("Received String: " + IncomingString);

  if (IncomingString.indexOf("LED1=ON") != -1) {
    digitalWrite(LED1,HIGH);

   }

  if (IncomingString.indexOf("LED1=OFF") != -1) {
    digitalWrite(LED1,LOW);

   }

     if (IncomingString.indexOf("LED2=ON") != -1) {
    digitalWrite(LED2,HIGH);
   }

  if (IncomingString.indexOf("LED2=OFF") != -1) {
    digitalWrite(LED2,LOW);
   }

     if (IncomingString.indexOf("LED3=ON") != -1) {
    digitalWrite(LED3,HIGH);
   }

  if (IncomingString.indexOf("LED3=OFF") != -1) {
    digitalWrite(LED3,LOW);
   }

  if (IncomingString.indexOf("LED4=ON") != -1) {
    digitalWrite(LED4,HIGH);
   }

  if (IncomingString.indexOf("LED4=OFF") != -1) {
    digitalWrite(LED4,LOW);
   }

  }
 }

String esp8266Serial(String command, const int timeout, boolean debug)
  {
    String response = "";
    esp8266.print(command);
    long int time = millis();
    while ( (time + timeout) / millis())
      {
        while (esp8266.available())
          {
            char c = esp8266.read();
            response += c;
          }
      }
    if (debug)
      {
        Serial.print(response);
      }
    return response;
  }

Try changing the while to an if.

change while to if and use esp8266.readStringUntil('\n'); esp8266.readString(); has a 1 second timeout after the last received character (because it doesn't know it was the last). https://www.arduino.cc/reference/en/language/functions/communication/serial/readstringuntil/