text:
Autoranging ohmmeter
Note: Before i explain my issue i would like to note that I am a beginner in electronics. Please pay attention to that when providing solutions and explanations. Thank you.
I have succeeded at making an auto ranging Ohmmeter it is still ofcours experimental there for I would like to get some opinions and perhaps solutions to some of the issues I’m facing
How it works:
It is based on a simple voltage divider. After experimenting it seems that a voltage drop across the unknown resistor in a certain range (this case [3.135V, 0.99V] with a voltage source equal to 3.3V) gives the most precise results compared to other values.
This Ohmmeter has a very useful feature and that is auto ranging, it changes the range automatically when the voltage drop values are not in the previously mentioned interval ([3.135V, 0.99V]).
The accompanied image shows how the device works.
If the value of Rx is too small compared to (R1+R2+R3) the Arduino switches the analog reading from A0 to A1 if the problem still accurse the Arduino will change again to A2 meaning it is now measuring not the value of Rx but (Rx+R1+R2) in series after that the Arduino is programmed to do the subtraction accordingly.
This device presents some noticeable inconvenients  that need to be eliminated:

It depends on experimental values, so it is not certain if it’ll
function properly in different conditions.
For accurate (still not exact) measurements the value of Rx has to be greater than R1
It provides acceptable measurements compared to the actual value with an error that is not too big (less than 1% relative error) the precision was obtained by the use of some of the arduino functions (such as voltage reference) also I have chosen the voltage source to be 3.3V instead of 5V to reduce noise, now if one wishes to use a different microcontroller other than arduino will it still be possible to obtain the same precision.

I would like to know your professional opinion regarding these inconvenients and if you may solutions for them, I have accompanied the code for better understanding.
Thank you
#include <ResponsiveAnalogRead.h>
ResponsiveAnalogRead analogPin0(A0, true);
ResponsiveAnalogRead analogPin1(A1, true);
ResponsiveAnalogRead analogPin2(A2, true);

int raw1= 0,raw2=0,raw3=0;
int Vin= 3.3;
float Vout1= 0,Vout2=0,Vout3=0;

float R1= 10000,R2=100000,R3=1000000;
float Rx= 0;
float buffer= 0;

void setup()
{
  analogReference(EXTERNAL);

Serial.begin(9600);
}

void loop()
{
  analogPin0.update();
  analogPin1.update();
  analogPin2.update();
raw1=analogPin0.getValue();
buffer= raw1 * Vin;
Vout1= (buffer)/1024.0;
if(Vout1<=3.135&&Vout1>=0.99) //firstif
{

buffer= (Vin/Vout1) -1;
Rx= (R1+R2+R3) * buffer;
Serial.print("Vout1: ");
Serial.println(Vout1);
Serial.print("Rx: ");
Serial.println(Rx);
delay(1000);
}
   else //else1 of first if
   {

   raw2=analogPin1.getValue();
   buffer= raw2 * Vin;
   Vout2= (buffer)/1024.0;
      if(Vout2<=3.135&&Vout2>=0.99) //second if of first else
      {
      buffer= (Vin/Vout2) -1;
      Rx= (R2+R3) * buffer;
      Rx=Rx-R1;
      Serial.print("Vout2: ");
      Serial.println(Vout2);
      Serial.print("Rx: ");
      Serial.println(Rx);
      delay(1000);
      }
      else
      {
      raw3=analogPin2.getValue();
      buffer= raw3 * Vin;
      Vout3= (buffer)/1024.0;
          if(Vout3<=3.135&&Vout3>=0.99)
          {
          buffer= (Vin/Vout3) -1;
          Rx= R3 * buffer;
          Rx=Rx-(R1+R2);
          Serial.print("Vout3: ");
          Serial.println(Vout3);
          Serial.print("Rx: ");
          Serial.println(Rx);
          delay(1000);
          }
       }
   }
}

======================================================

to jot here are the results as i have previously explained the ohmmeter worked pretty well at the beginning but when i turned it off Then back on the value measured changed, the error got much bigger i tried changing the caliber aka R1 from 220 to 100 but the results were the same, the error was still big
thank you

Make the variable Vin a float.
The range is limited by the number of analog inputs and the resistors are in series. It will be hard to adapt the circuit to measure a resistor of 10 ohm. It is possible to use digital pins to power resistors or not and use a single analog input.

The answer by @EdgarBonet seems to be a very nice solution for the lowered output voltage of a pin, when a low resistor value is used.
A arduino uno pin can output 20mA without problem, even up to 40mA if needed. So a safe value to measure low resistor values is 220 ohm, which could result in a maximum of 23mA.
Analog input A1 is used both as digital output to power the circuit and also as a analog input to measure how much the voltage has dropped.
This is a quick test:
// Using the idea in the answer by Edgar Bonet
//
// Allow that the voltage of a digital output is
// lowered by the low resistor value,
// to calculate the unknown resistor.
//
// With two resistors in series.
// A1 - 220 ohm - A0 - 10 ohm - GND
//
// The circuit is a voltage divider.
// A1 powers the voltage divider.
// A0 measures the output.

#define R1 220
#define N_SAMPLES 10

void setup() {
  Serial.begin(9600);
  pinMode(A1,OUTPUT);
  digitalWrite(A1, HIGH);
}

void loop() {

  // Pin A1 is already set as a digital output and set HIGH.
  // Using analogRead(A1) is to measure the real output
  // voltage. There is a voltage drop, because of the current.
  float Vin = averageRead(A1);
  Serial.print("Vin=");
  Serial.print(Vin);

  float Vout = averageRead(A0);
  Serial.print(" Vout=");
  Serial.print(Vout);

  if(Vin > 0.0 && Vout < Vin) {
    float Vt = Vout / Vin;
    float Rx = (Vt * R1) / (1 - Vt);
    Serial.print(" Rx=");
    Serial.println(Rx);
  }

  delay(500);
}

float averageRead(int analogPin) {
  int total = 0;
  for(int i=0; i<N_SAMPLES; i++) {
    total += analogRead(analogPin);
  }
  return float(total) / N_SAMPLES;
}

That is very nice. It is no problem when the unknown resistor is 10 ohm.
Because of the low resistor values, I did not add delays. With high resistor values, some delay is needed before measuring the analog values.
The next step is to find the best value by finding the value that is the most in the middle, as Edgar Bonet has explained in his answer.
// Autoranging by finding the value that is most in the middle.
// Using the answer by Edgar Bonet

#define N_SAMPLES 10          // the number of samples to average, maximum 30

// Four resistors to power the circuit (one at a time).
// A1 has a resistor of 220 ohm, A2 has 3k3, A3 47k, and A4 750k
// The other leg of the resistors are all connected to A0.
// The unknown resistor Rx is at pin A0 and GND.
const float R[4] = {220.0, 3300.0, 47000.0, 750000.0};
const int pinR[4] = {A1, A2, A3, A4};
const unsigned long wait[4] = {1, 2, 4, 10};  // delay, values guessed.
const int pinMeasure = A0;

void setup() {
  Serial.begin(9600);
  Serial.println("Autoranging");
}

void loop() {
  float Vin[4];    // Vin is the pin that powers the circuit
  float Vout[4];   // Vout is the voltage over the unknown resistor

  for(int i=0; i<4; i++) {
    // Power the circuit with this resistor
    pinMode(pinR[i], OUTPUT);
    digitalWrite(pinR[i], HIGH);

    // Vin is the pin that powers the circuit.
    // This is always low impedance, no need to wait.
    Vin[i]  = averageRead(pinR[i]);

    // Extra delay to wait for the voltage to become steady,
    // before reading the analog data.
    // Might be needed for the higest resistor values
    // Perhaps there is a cable to the unknown resistor
    // that has capacitance.
    delay(wait[i]);

    // The first 'analogread()' sets the multiplexer.
    // For a high impedance circuit, the first
    // 'analogread()' might be less acurate.
    // Read it a few times, and throw it away.
    averageRead(pinMeasure);

    // Everything is settled by now.
    // Read the analog input for real.
    Vout[i] = averageRead(pinMeasure);

    pinMode(pinR[i], INPUT);  // Make this pin high impedance
  }

  // Find the value for Vout that is the most in the middle.
  // For an Arduino Uno, the middle ADC value is 512.
  float diff = 2000.0; // set to value higher than possible as default
  int best = 0;        // index of the best resistor

  for(int i=0; i<4; i++) {
    float d = fabs(512.0 - Vout[i]); // difference for this resistor
    if(d < diff) {                   // closer to the middle?
      diff = d;                      // remember new difference
      best = i;                      // remember index best resistor
    }
  }

  if(Vin[best] <= 0.0) {
    Serial.println("Something wrong with the circuit");
  }
  else if(Vout[best] >= Vin[best]) {
    Serial.println("Rx not connected");
  }
  else {
    float Vt = Vout[best] / Vin[best];     // temporary precalculation
    float Rx = (Vt * R[best]) / (1 - Vt);  // calculate unknown resistor

    Serial.print(" Rx=");
    Serial.print(Rx);
    Serial.print(" ohm (with resistor ");
    Serial.print(R[best]);
    Serial.print(")");
    Serial.println();
  }

  delay(250);
}

float averageRead(int analogPin) {
  int total = 0;
  for(int i=0; i<N_SAMPLES; i++) {
    total += analogRead(analogPin);
  }
  total += N_SAMPLES / 2;  // see www.gammon.com.au/adc
  return(float(total) / float(N_SAMPLES));
}

I would like to add a capacitor from A0 to GND (parallel with the unknown resistor) to reduce noise. This capacitor should be 1nF or less. The delay in the code is large enough to wait for the voltage to settle with 1nF.
The increase of the resistors by 15 times is a large step. That makes it less accurate, but the arduino uno has only 6 analog inputs. By using 5 resistors with an increase of 6 times is better.
4 resistors 15x : 220, 3k3, 47k, 750k
5 resistors 6x  : 220, 1k2, 8k2, 47k, 270k
There are a few ways to do more:

When two resistors result in a output that is close to the middle, it is possible to average the results.
When the 5 resistors are used, it is for example possible to lower the value of the 8k2 resistor. When all higher values are turned on, the resulting resistor value becomes 6k8 instead of 8k2.
For high resistor values, the output voltage of a pin is not lowered, and digital outputs can be used as well.

An protection resistor for A0 might be needed. I think that a value of 470 ohm or 1k should be fine.
Many thanks to @EdgarBonet, I used his answer and added the average and the delay.

Update November 2018
@RekaiaDraoui
When using a breadboard, there can be contacts which are not perfect. That can cause a lot of troubles.
Are you using a circuit as this:

Wow this is pretty impressive i see what you did right there one small issue that still worries me, EdgarBonet previously mentioned "the pins have an output resistance that is about 25 Ω, which ends up being in series with the corresponding reference resistors. You can account for that by adjusting, in your code, the values of those references." i wonder why you didn't take this detail in consideration when you wrote this code?, thank you

I did! Not the 25 ohm, but I measure the actual voltage drop. Edgar Bonet wrote "That's why I suggest to use analog instead of digital pins" (to be able to measure the voltage drop of a pin). I measure the voltage of the pin that powers the circuit and the voltage over the unknown resistor. The analogRead of pin a1 could be 840 (instead of 1023) and the a0 could be 37. The actual voltage does not matter. With the two resistors, everything is relative. Because it is a voltage divider, the unknown resistor is measured relative to the 220 ohm resistor. The calculation is just two lines.

OH! true i missread both of your answers well thank you big time! i will improve it and post it here as an answer once im done if anybody was interested, thank you again

i have another question, i've tried ur circuit in a simulator bcz my pc decided to stop all of a sudden, anyway when i chose a high value reference resistor(say 100k) vin was equal to 1024 so 5v unlike a low value reference resistor(say 220)where vin was about 824  can you please explain to me why is that ?

Because of the output resistance of 25 ohm, that Edgar Bonet was talking about. The atmega328 can output 20mA (even up to 40mA), but with such high currents the pin is no longer Vcc (5.0v), but lower. With very small current, it has no problem to set a pin to Vcc (5.0v). That is what my sketch is for. To test the accuracy by actually measuring the output pin with a analog pin. Since the arduino uno has a digital pin and a analog pin combined for all analog inputs, it is possible to use that single pin. Did you choose reference resistors? You can set them apart by 15 times: 220, 3k3, 47k, 750k.

i have, that's what i've been saying and when i used high values like 100k or 1M vin would be vrey high (1024).you're saying that is bcz the current is very low ?

Yes. In the datasheet ( http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf ) at page 391, Figure 33-24 you can see that the output drops when it has to supply current. For example, it drops to 4.5V at 20mA.

You are welcome, and nice job! For high resistor values, I suggest that instead of delaying, you read Vin, then take many readings of Vout that you throw away, then the Vout readings that you want to keep. The reason is that you want the ADC input capacitor within the sample and hold circuit to get charged to the appropriate Vout voltage. AFAIK, this capacitor only has a chance to charge during a short time at the start of each ADC conversion, meaning that the first readings you take after switching the multiplexer from Vin could be corrupted by the cap not having completely settled.

@EdgarBonet Thanks. I want to keep the possibility to add a small capacitor (1nF or less) at A0, parallel with the unknown resistor, to reduce noise. I have rearranged the delay and do a dummy read before finally reading the analog input. I have also added 0.5 bit to the average function. The 10 samples for the average is a low amount, perhaps 50 can make it a little better, but then the 'total' must be a long.

@Jot was hoping you could help me more, i have tested your program and circuit it worked very well at the beginning but after some time the values changed completly and the error got much bigger i was hoping you could explain to me why and if possible tell me how yo fix. I have posted 2 images showing the different values measured i edited this information into my question  please check it out, thank you

@RekaiaDraoui, I have added an update to my answer.

@Jot i have removed the breadboard now it's measuring 12 ohms instead of 14ohms but the error is still big(ps: Rx=10ohms)

@RekaiaDraoui, the Arduino Uno can supply 20mA (40mA shortcut current), that limits the maximum current, and that is why the lowest resistor to A1 is 220 ohm. With this circuit it is not possible to measure 10 ohms accurate. To measure 10 ohms accurate, perhaps a opamp has to be added. EdgarBonet wrote about the limits, but I thought it did not have to be very accurate for low or high resistor values.

@Jot i chenged the breadbord now im getting acceptable readings(10.66/10.75....ohms)but im still concerned cuz i got good results using the first breadbord at first then you know what happened, anyway thank you so much for your help, i was wondering if you had a blog or a quora account if you welcome questions, thank you again

@RekaiaDraoui no, no blog or quora. For 10 ohms you might need soldered connections, but it is the limit, it will not be accurate.

As you probably already know, the standard setup for measuring a
resistance with an Arduino is to put the unknown resistor in series with
a known one between 5V and GND, and measure the voltage at the point
in-between them:
     5V
     │
     R₁
 A0 ─┤
     R
     │
    GND

where R is the unknown resistor and R1 is the known
reference. The resistance is then computed as:
const float R1 = ...;  // reference resistance

int reading = analogRead(A0);
float R = (float) reading / (1024 - reading) * R1;

First, it is worth noting that the reference voltage does not appear in
this calculation. You could, of course, do the calculation in terms of
voltage, but you should then notice that the reference voltage can be
simplified away. This is not surprising if you realize than the ADC of
the Arduino does not actually measure a voltage: it rather measures a
voltage ratio: the ratio of the input voltage to the reference
voltage. This ratio can then be easily related to the resistance ratio
R/R1. What all this implies is that you should not expect to
get better accuracy by using a 3.3 V reference rather than
5 V. Any inaccuracy in the voltage reference is irrelevant to the
measurement of the resistance.
Next, when measuring a physical quantity, you are almost always
interested in the relative rather than the absolute accuracy. From
the equation above, it can be easily shown that you get the best
relative resolution when the reading is near the middle of the ADC
range:
raw reading    │   64 │  128 │  256 │  512 │  768 │  896 │  960
───────────────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
resolution (%) │ 1.67 │ 0.89 │ 0.52 │ 0.39 │ 0.52 │ 0.89 │ 1.67

This is consistent with your observations, and it means that the
reference resistor should ideally have a value that is of the same order
as the unknown resistor.
Now, for the autoranging, I would advise you against putting all your
reference resistors in series. With this setup, you always have the same
voltage across the unknown resistor, irrespective of what range you
choose. Reading a different input does not help. You may find out that
the voltage between R1 and R2 gives a better
reading (closer to mid-range), and you get a better accuracy on the
measurement of R+R1. However, when you subtract R1
you are immediately degrade the relative accuracy of the result. In
the end you cannot really improve the accuracy this way.
What I suggest is to put the reference resistors in parallel instead of
in series, and power each one from an analog pin:
     A1  A2  A3
     │   │   │
     R₁  R₂  R₃
 A0 ─┼───┴───┴── ...
     R
     │
    GND

You then use these analog pins in digital mode: all of then in INPUT
mode, except one which is set to OUTPUT HIGH. You can try all of
them in turn and select whichever gives a result closer to mid-range. Or
you can implement a smarter algorithm that finds the optimal one without
trying them all.
There is something to be aware of with this setup: the pins have an
output resistance that is about 25 Ω, which ends up being in series
with the corresponding reference resistors. You can account for that by
adjusting, in your code, the values of those references. But then that
output resistance is not very well known, and can vary with temperature.
This should only be an issue when you are in the low ranges though. You
can mitigate this problem by measuring the voltage at the pin that is
currently pulling up, and replacing 1024 in the equation for R by that
reading. That's why I suggest to use analog instead of digital pins.
Finally, there are a couple of limitations that you should be aware of
when measuring resistances with the Arduino ADC. At the low end of the
resistance range, you cannot use a reference resistor with a very low
value, because you have to make sure you do not pull more than about
20 mA from the pin that pulls up. Your smallest reference may then
end up being somewhere around 220 Ω, and you will loose significant
accuracy when you try to measure anything below 50 Ω. At the upper
end of the range, you should be aware that the ADC is meant to measure
voltage sources with an output resistance no larger than 10 kΩ,
otherwise you risk cross-talk between the ADC channels. Then your higher
reference should probably be 10 kΩ, and any measurement above
50 kΩ will give poor accuracy. Going past these limitations would
require extra electronics, like a good-quality op-amp to “condition” the
signal into something that the ADC can reliably measure.

The 50kΩ upper limit is on the safe side. I have no problem with 1M. That requires the average of a number of samples and sometimes an extra delay or a capacitor to gnd (to keep the voltage the same when the adc eats some charge). When for example only 5% accuracy is required for the very low and very high resistor values, then a lot is possible.

thank you for your answer it has served me alot, as a last question i have felt after reading your answer that my project doesn't seem to be well made and that is of course due to my lack of knowledge in this field now, do you think it is worth fixing or should i jump to another way? it doesn't metter how it works as long as it is eventually an autoranging ohmmeter, thank you @EdgarBonet

@RekaiaDraoui Your circuit has too many limitations. Use this circuit with turning on a resistor one at a time. Find in the sketch which value is the most in the middle and use that to calculate the unknown resistor.

I don't quite get your last question. Can you easily change the circuit, or is it something you have soldered?

@EdgarBonet yes i can easily change the circuit

@Jot thank you for orienting me, that's what i'm planning to do.

@EdgarBonet can you please tell me where did you get the values of the table from?

@RekaiaDraoui: I computed them. For example, for a reading of 256, R/R₁ = 256/(1024-256) = 0.33333. One ADC step above, at 257, it's R/R₁ = 257/(1024-257) = 0.33507. The difference between these two numbers is 0.52%.

@EdgarBonet actually it's 0.174%, if by difference you mean (0.33507-0.33333)*100

@RekaiaDraoui: No. When a difference is given in percent, it is always understood that it is a relative difference.

@EdgarBonet your results make much more sense now. Thank you very much for your help.


text:
Storing an array of objects
I followed the instructions of this post: Storing an array of function pointers.
To show my problem I shorted my code extremely but the problem is still there.
My classes are defined as followes:

class MyBaseClass
{
public:
  MyBaseClass(String functionName);
  String functionName();
private:
  String _functionName;
};

class MyDerivedClassA : public MyBaseClass
{
public:
  MyDerivedClassA(String functionName);
};

class MyDerivedClassB : public MyBaseClass
{
public:
  MyDerivedClassB(String functionName);
};

MyBaseClass::MyBaseClass(String functionName) {
  _functionName = functionName;
}

String MyBaseClass::functionName(){
  return _functionName;
}

MyDerivedClassA::MyDerivedClassA(String functionName) : MyBaseClass(functionName) {}

MyDerivedClassB::MyDerivedClassB(String functionName) : MyBaseClass(functionName) {}

The test method is this:
void test(){
  MyBaseClass *_elements[1000];
  int _elementCount = 0;

  for (int i = 0; i < 2; i++){
    if (i == 0){
      MyDerivedClassA tmp("MyDerivedClassA");

      _elements[_elementCount] = (MyBaseClass *)&tmp;
      Serial.println( _elements[_elementCount]->functionName() );

    } else if (i == 1){
      MyDerivedClassB tmp("MyDerivedClassB");

      _elements[_elementCount] = (MyBaseClass *)&tmp;
      Serial.println( _elements[_elementCount]->functionName() );

    }

    Serial.println( _elements[_elementCount]->functionName() );

    _elementCount++;
  }

  Serial.println("count: " + String(_elementCount));
  for (int i = 0; i < _elementCount; i++) {
    Serial.println("loop: " + String(i));
    Serial.println( _elements[i]->functionName() );
  }
}

When the code is running I get the following at the serial monitor:
MyDerivedClassA

MyDerivedClassB

count: 2
loop: 0

loop: 1

I dont understand, why the first call of "_elements[_elementCount]->functionName()" inside the first loop returns the correct value and the second only an empty string. Inside the second loop it again returns an empty string. I think it's the same problem like inside the first loop.
And there is the problem, that my NodeMCU crashes if the code is executed.
This is the output while it carshes:
Soft WDT reset

ctx: cont
sp: 3ffffd20 end: 3fffffd0 offset: 01b0

>>>stack>>>
...
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,7)

 ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset

Where is my problem?

You allocate 1000 pointers, aka 1000*4 Bytes on the stack. That kills the thread. (MyBaseClass *_elements[1000];)

ok, this was a really stupid mistake... Setting "MyBaseClass *_elements[10];" solved the crash problem. But the output at the serial monitor is still the same...

Your  tmp variable doesn't survive the { } it is placed in. It is de-allocated when it exits the }. Move the temp variables to an outer, greater scope or new and delete them.

source: Stack Exchange

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

sort: votes


text:
FastLED - How to Control specific LEDs
I am fearly new to Arduino and FastLED. I found a nice Sketch which fits almost perfectly to my needs.
Just one Problem:
I dont want the Sketch to effect ALL LEDs in one color.
I want some LEDs in Red (ex. LEDs 0-4) Some in green and others in blue.
They could all have the same effect and timing, but it would be really neat if I could make them out of sync a little bit.
But having the possibility to make different LEDs different colored would be great. Here is the "Pulse" or "Breath" Sketch I want to use.
    #include <FastLED.h>

    #define NUM_LEDS 37
    #define DATA_PIN 11
    #define CLK_PIN 13

    CRGB leds[NUM_LEDS];

    int fadeAmount = 5;  // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255.
    int brightness = 0;

    void setup()
    {
      FastLED.addLeds<APA102, DATA_PIN, CLK_PIN, BGR>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
      FastLED.setBrightness(50);
    }

    void loop()
    {
       for(int i = 0; i < NUM_LEDS; i++ )
       {
       leds[i].setRGB(0,255,250);  // Set Color HERE!!!
       leds[i].fadeLightBy(brightness);
      }
      FastLED.show();
      brightness = brightness + fadeAmount;
      // reverse the direction of the fading at the ends of the fade:
      if(brightness == 0 || brightness == 255)
      {
        fadeAmount = -fadeAmount ;
      }
      delay(80);  // This delay sets speed of the fade. I usually do from 5-75 but you can always go higher.
    }

The colors of the LEDs in your sketch are set in this loop:
for(int i = 0; i < NUM_LEDS; i++ )
{
    leds[i].setRGB(0,255,250);  // Set Color HERE!!!
    leds[i].fadeLightBy(brightness);
}

You loop over all LEDs and set them to a specific color and brightness. The changes will be send to the LEDs, when you call FastLED.show() afterwards. There is nobody, that prevents you from setting a different color for each LED or to only chnage the value for some of the LEDs.
For example, to light the first 5 LEDs in red, the next 10 in green and leaving the rest as they were before, you can use this code (Just exchange it with your for loop):
for(int i=0;i<5;i++){
    leds[i].setRGB(255,0,0);
    leds[i].fadeLightBy(brightness);
}
for(int i=5;i<15;i++){
    leds[i].setRGB(0,255,0);
    leds[i].fadeLightBy(brightness);
}
FastLED.show();

The principle is, that you have an array with color values. Each value consists of 3 smaller values for red, green and blue (RGB)(The color results from the distribution between red, green and blue; the brightness results from the overall level of red, green and blue). And each value of the array is bound to an LED (First value to first LED, second value to second LED,...). You can change the color values in the array as you like. And when you want the LEDs to show the current values in the array, you send them out by using FastLED.show(). This means you have to call this function everytime, that you want LEDs to change. You don't have to change every value in the array for this to work.
If you would like to build an asynchronous change of colors, you can ditch the delay(80) and use non-blocking code like in the BlinkWithoutDelay example of the Arduino IDE. There you use the millis() function as a clock (it returns the milliseconds since the Arduinos startup). You take a timestamp at the beginning and compare the difference between it and the current time:
unsigned long timestamp=0;
unsigned long interval=80; //interval of 80 milliseconds

void loop(){
    unsigned long current_time=millis();
    if(current_time - timestamp > interval){
        // do something here, like setting LED colors
        timestamp = current_time;
        // don't forget FastLED.show(), to output the colors
    }
}

You can use multiple of these timestamps with if-statements, one for each segment you want to change in a different frequency.

Hi, wow!
I am absolutely amazed how good you explained and showed all this to me!
This is great!
I will absolutely try this when i am at home from work and give feedback.
Thank you very much !

WOW this worked perfect!!
Again: Thank you very much!!!

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


text:
Output set to 'low' when new variable in buffer
I would like to turn on and off the output of two pins on my arduino independently from each other. However, so far all my attempts have failed.
My current idea is to save the status (which I chose to be 0 as 'low' and 'high' as 1) of each of the pins in an integer array and then change the status of the pin depending of the entry in the variable. However, the entries in the variable are always set back to 0 and I do not know why this is happening.
This is my arduino code
const byte numChars = 32;
byte receivedChars[numChars];
boolean newData = false;
const int num_of_pins=2;
int output_pins[num_of_pins]={22,26};
int status_pins[num_of_pins]={0,0};

void setup() {
    int ii=0;
    Serial.begin(9600);
    for(ii=0; ii<num_of_pins; ii++){
        pinMode(output_pins[ii],OUTPUT);
    }

}

void loop() {
    recvWithStartEndMarkers();
    chooseFunction();
}

void chooseFunction(){
  if (receivedChars[0]==0){
    shutter();
    }
}

void shutter(){
        // get number of pin
        int pin_number_rcvd;
        int ii;
        int pin_status_rcvd;
        pin_number_rcvd=receivedChars[1];
        pin_status_rcvd=receivedChars[2];
        //check all status of pins and turn on and off
        for (ii=0; ii<num_of_pins; ii++){
          if (pin_number_rcvd==output_pins[ii]){
            status_pins[ii]=pin_status_rcvd;
          }
          if (status_pins[ii]==0){
            digitalWrite(output_pins[ii],LOW);
          }
          if (status_pins[ii]==1){
            digitalWrite(output_pins[ii],HIGH);
          }
        }
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    byte startMarker = 8;
    byte endMarker = 9;
    byte rc;

    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

I use pyserial to send the input data to the arduino. my python code:
import serial
import time, struct, sys
ser=serial.Serial('COM17', 9600, timeout=10)
time.sleep(2)
ser.reset_input_buffer()
ser.reset_output_buffer()
pin_number= int(sys.argv[1])
high_or_low=int(sys.argv[2])

ser.write(struct.pack('>5B',8,1,pin_number,high_or_low,9))

I am using an ArduinoDue together with the arduino IDE.

Maybe it isn't it, but you are expecting:  receivedChars[0]==0  but  ser.write(struct.pack('>5B',8,1,pin_number,high_or_low,9)) is sent (eg it's 1, not 0)

thanks for your answer. Unfortunately, it does not change anything

you left  our some information .... the following description does not explain why python script is involved .... I would like to turn on and off the output of two pins on my arduino independently from each other.

Thats true. Sorry for that. I want to switch the output on the board on and off using python, e.g. I want to send data to the arduino with pyserial telling the arduino to switch on or off the output on a certain pin.

I think I figured iut the problem, but I still do not know how to solve it. The problem is that whenever I want to switch the output on or off, I restart the python script which completely resets the arduino and therefore the output on all the other channels is switched off

Your problem is in one tricky option for arduino's com connection. When you reopen COM port where arduino is connected your arduino resets automatically.
Here's workaround from arduino.cc:

DisablingAutoResetOnSerialConnection
The simple way that doesn't require
  any permanent modifying of your hardware or software configuration
  changes:
Stick a 120 ohm resistor in the headers between 5v and reset (you can
  find these on the isp connector too). 120 is hard to find so just
  combine resistors. Don't go below 110 ohms or above 124 ohms, and
  don't do this with an isp programmer attached. You can just pull out
  the resistor when you want auto-reset back.

http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection
Or you can just modify you script to be able to start over without reopening it.
For example use a loop there and some exit command to end that loop:
try:
    while True:
        do_something()
except KeyboardInterrupt:
    pass

https://stackoverflow.com/questions/13180941/how-to-kill-a-while-loop-with-a-keystroke
Replace do_something() with this part of your code:
ser.reset_input_buffer()
ser.reset_output_buffer()
pin_number= int(sys.argv[1])
high_or_low=int(sys.argv[2])

ser.write(struct.pack('>5B',8,1,pin_number,high_or_low,9))

I hope I was clear enough.


text:
NodeMCU ESP8266 button wiring problem
Hello guys, this is my code and I am basically doing if-else statement.
int led = D2;
int but = D1;

void setup() {
  pinMode(led, OUTPUT);
  pinMode(but, INPUT);

}

void loop() {
  if (digitalRead(but) == HIGH){
    digitalWrite(led, HIGH);
  }else{
    digitalWrite(led, LOW);
  }

}

I have also attached the photo so that you can diagnose the situation.
The led show only glow if the button is pressed. But the led keeps glowing for longer time and I don't know why.
I think there is current leak somewhere in the circuit or the internal processing is slow.
Please help me guys.

The circuit seems like it's wrong.
When a button is pressed it wil fluctuate some before it going to be stable.
Try this:
"
bool state=digitalRead(but)
digitalWrite(led, state);
"
also similar problem: https://arduino.stackexchange.com/questions/3425/unstable-reading-from-pushbutton-on-digital-pin

Your button and pull-up configuration is not correct, so when the button is not being pressed, the pin D1 is floating, being pulled neither HIGH nor LOW.
Instead, use a pull-up resistor as shown. When the button is not pressed, D1 is connected to GND through a resistor. When the button is pressed, the 3.3V source has a direct path to D1.

simulate this circuit – Schematic created using CircuitLab

why pull-down? it is simpler to use the internal pullup

Because the asker has coded for a pull-up. Yes, it’s trivial to change.


text:
How to prevent interference between dc motor and arduino?
It may be already asked question in somewhere but I am struggling!
I have a four wheel robot which I want to drive it to perform 90-degree left/right turn, I am using the MPU6050 3dof to get angles, however everything is ok when the DC motors are off and the readings from the MPU6050 are pretty good.
But when the DC motors are on, the readings start to be increase randomly. I tried to use a different power supply to the DC motors and the Arduino, but with no solution. At the end when I reset the Arduino everything was back to be normal even if the DC motors are on!

Any help will be appreciated and I am open for any suggestion.

You said " I tried to use different power supply to dc motors" -- please provide details. Your diagram shows a 9V battery, which can hardly supply enough current to operate two motors and an Arduino. Be sure that you include all relevant details in your question.

@josecanuc , thank you for your reply and I'm sorry I wasn't accurate in my question, however, for now, I am using an 11.3v battery for the dc motors and 7.3v for the Arduino , the rest of the image is the connections for my setup as well as I connected the GND of the motor with the GND of the Arduino

There are two basic things you need to do:

Use proper pullup resistors on your I2C lines (2.2kΩ) instead of relying on the (terrible) internal pullups of the ATMega
Add capacitors to the motors.

For point 2 you need two or three small ceramic capacitors (10nF to 100nF) per motor.

Connect one from each terminal to the motor's body
Optionally connect a third between the two terminals of the motor

This will reduce the EMI produced by the motor, and the improved pullups should reject EMI easier.
(Even if this doesn't entirely fix your underlying issue, it's certainly something that you should do regardless.)

well, thank you for the suggestions, is it ok if I do both points?

Yes. You should do both points.

I have a question if you could answer it, why when I press the reset button on the Arduino everything is normal and the readings from MPU6050 back to be normal?

No idea. EMI causes strange things.

it didn't work!
i added the capacitors as you said and pullup resistors but nothing changed!
the problem still only with first power when reset the arduino from the RESET button everything back to be normal

You can just change ground port for your MPU6050 or for your motors(experiment with different choices). You have another ground port near pin13. As far as I know some of them are for analog devices and some of them are for digital (to avoid interference).
Adding capacitors may not help.
If none of the methods will help, try to add an inductor to your circuit.
Please, try that and write here if these were helpful or not.
Update: As per this site the problem is caused by data cables.

Thank you a lot !
Didn't have to change frequency. I just eliminated SDA and SCL wires
  and plugged a chip with MPU-6050 directly into Arduino and it works
  without any problems. Thanks to you this issue is solved :)

In addition, I would like to mention that Arduino standard pin cables are very noisy, so all connected modules which use high data rates or which are very sensitive to data errors (for example, nRF24L01+) will have strange behavior.
Temporary and harsh workaround: You could reset your Arduino after first initialization process (at the end of setup) then, save a flag("1") to EEPROM so it will not reset each time you start Arduino (warning: EEPROM cells can be rewritten only 10000 times).
if(EEPROM.read(0))
{
  EEPROM.write(0,1);
  //put your reset code here
}

if(EEPROM.read(1))
{
  EEPROM.write(0,0); //make it back "0" for next start
}

Comments are not for extended discussion; this conversation has been moved to chat.


text:
Interfacing AD7606 with Arduino Due. How to data-log?
I have an 16 bit ADC7606. It is in parallel mode. I have a working sketch that allows me to read  8 channels, convert the 16 bit integer to decimal and then serial prints to monitor. I would like to increase the frequency of the sampling rate. The serial monitor can not keep up with a sampling rate faster than 40millis. The Due is connected via USB on COM3.
How do I log the data to a file on my laptop/computer?
All and any help greatly appreciated.
Code below,
#include <EnableInterrupt.h>

#define BUSY 3
#define RD 4  //RD+CS tied together
#define RESET 5
#define CONVST 6 //CONVSTA+CONVSTB soldered together on the board
#define RANGE 7

#define DB0 38
#define DB1 39
#define DB2 40
#define DB3 41
#define DB4 42
#define DB5 43
#define DB6 44
#define DB7 45
#define DB8 46
#define DB9 47
#define DB10 48
#define DB11 49
#define DB12 50
#define DB13 51
#define DB14 52
#define DB15 53

// declare rawData as an array of 16 integers
int rawData[16];

void setup() {

  enableInterrupt(BUSY, ISR_, FALLING);

  pinMode(RESET, OUTPUT);
  pinMode(CONVST, OUTPUT);
  pinMode(RD, OUTPUT);
  pinMode(RANGE, OUTPUT);
  pinMode(BUSY, INPUT);

  Serial.begin(9600);

  //reset ADC to begin conversion
  digitalWrite(RESET, HIGH);
  delayMicroseconds(10);
  digitalWrite(RESET, LOW);

  digitalWrite(CONVST, LOW);
  digitalWrite(RD, HIGH);
  digitalWrite(RANGE, HIGH);
  digitalWrite(BUSY, LOW);

  delayMicroseconds(1000);

}

void loop() {

  disableInterrupt(BUSY);

  delayMicroseconds(40000);
  digitalWrite(CONVST, LOW);
  delayMicroseconds(10);
  digitalWrite(CONVST, HIGH);
  enableInterrupt(BUSY, ISR_, FALLING);

}

void ISR_ ()  {

  //Serial.print(millis());
  //Serial.print(",");

  delayMicroseconds(1);
  digitalWrite(RD, LOW);
  delayMicroseconds(1);
  readDBpins(); // do read
  digitalWrite(RD, HIGH);
  Serial.print(",");

  delayMicroseconds(1);
  digitalWrite(RD, LOW);
  delayMicroseconds(1);
  readDBpins(); // do read
  digitalWrite(RD, HIGH);
  Serial.print(",");

  delayMicroseconds(1);
  digitalWrite(RD, LOW);
  delayMicroseconds(1);
  readDBpins(); // do read
  digitalWrite(RD, HIGH);
  Serial.print(",");

  delayMicroseconds(1);
  digitalWrite(RD, LOW);
  delayMicroseconds(1);
  readDBpins(); // do read
  digitalWrite(RD, HIGH);
  Serial.print(",");

  delayMicroseconds(1);
  digitalWrite(RD, LOW);
  delayMicroseconds(1);
  readDBpins(); // do read
  digitalWrite(RD, HIGH);
  Serial.print(",");

  delayMicroseconds(1);
  digitalWrite(RD, LOW);
  delayMicroseconds(1);
  readDBpins(); // do read
  digitalWrite(RD, HIGH);
  Serial.print(",");

  delayMicroseconds(1);
  digitalWrite(RD, LOW);
  delayMicroseconds(1);
  readDBpins(); // do read
  digitalWrite(RD, HIGH);
  Serial.print(",");

  delayMicroseconds(1);
  digitalWrite(RD, LOW);
  delayMicroseconds(1);
  readDBpins(); // do read
  digitalWrite(RD, HIGH);

  Serial.println(" ");

}

void readDBpins()
{
  rawData[0] = digitalRead(DB15);
  //Serial.print (rawData[0]);
  if (rawData[0] > 0) {rawData[0] = 32768;}
  rawData[1] = digitalRead(DB14);
  //Serial.print (rawData[1]);
  if (rawData[1] > 0) {rawData[1] = 16384;}
  rawData[2] = digitalRead(DB13);
  //Serial.print (rawData[2]);
  if (rawData[2] > 0) {rawData[2] = 8192;}
  rawData[3] = digitalRead(DB12);
  //Serial.print (rawData[3]);
  if (rawData[3] > 0) {rawData[3] = 4096;}
  rawData[4] = digitalRead(DB11);
  //Serial.print (rawData[4]);
  if (rawData[4] > 0) {rawData[4] = 2048;}
  rawData[5] = digitalRead(DB10);
  //Serial.print (rawData[5]);
  if (rawData[5] > 0) {rawData[5] = 1024;}
  rawData[6] = digitalRead(DB9);
  //Serial.print (rawData[6]);
  if (rawData[6] > 0) {rawData[6] = 512;}
  rawData[7] = digitalRead(DB8);
  //Serial.print (rawData[7]);
  if (rawData[7] > 0) {rawData[7] = 256;}
  rawData[8] = digitalRead(DB7);
  //Serial.print (rawData[8]);
  if (rawData[8] > 0) {rawData[8] = 128;}
  rawData[9] = digitalRead(DB6);
  //Serial.print (rawData[9]);
  if (rawData[9] > 0) {rawData[9] = 64;}
  rawData[10] = digitalRead(DB5);
  //Serial.print (rawData[10]);
  if (rawData[10] > 0) {rawData[10] = 32;}
  rawData[11] = digitalRead(DB4);
  //Serial.print (rawData[11]);
  if (rawData[11] > 0) {rawData[11] = 16;}
  rawData[12] = digitalRead(DB3);
  //Serial.print (rawData[12]);
  if (rawData[12] > 0) {rawData[12] = 8;}
  rawData[13] = digitalRead(DB2);
  //Serial.print (rawData[13]);
  if (rawData[13] > 0) {rawData[13] = 4;}
  rawData[14] = digitalRead(DB1);
  //Serial.print (rawData[14]);
  if (rawData[14] > 0) {rawData[14] = 2;}
  rawData[15] = digitalRead(DB0);
  // Serial.print (rawData[15]);
  if (rawData[15] > 0) {rawData[15] = 1;}

  Serial.print (rawData[0]+rawData[1]+rawData[2]+rawData[3]+rawData[4]+rawData[5]+rawData[6]+rawData[7]+rawData[8]+rawData[9]+rawData[10]+rawData[11]+rawData[12]+rawData[13]+rawData[14]+rawData[15]);
}

Its name is a AD7606 (without the C)? http://www.analog.com/en/products/ad7606.html

why 9600 baud?  try 921600 baud

Other Serial terminal programs may have a function to save the received data to a file. Try some of them. And - since the Serial interface doesn't keep up - as Juraj wrote increase the baudrate, so that the data transfer is done with higher speed.

Thanks peeps. I read that anything over 115200 baud is not effective. 115200 is the usual rate I use. Serial Monitor cannot display the readings with anything faster than a 40millis sampling rate so I cannot do what I usually do and copy and paste to file as there is nothing there to copy.

@Juraj and chrisl 921600 baud and anything above 250000 prints gibberish. i now have a pyserial log script but it still bottlenecks, although now at 1.5millis, which is good but not good enough. I now know I messed up the 2's complement conversion in my arduino sketch but even with that commented out it still bottlenecks.

You can use python on the command line to log your serial monitor output. This is described here. The script below has a baud rate of 250000 but can be set according to how you program your arduino.
from time import sleep
import serial

# Change port and baud rate to match your setup
ser = serial.Serial('/dev/ttyACM0', 250000) # Establish the connection on a specific port

counter = 32 # Below 32 everything in ASCII is gibberish

while True:
     counter +=1
     ser.write(str(chr(counter))) # Convert the decimal number to ASCII then send it to the Arduino
     print(ser.readline()) # Read the newest output from the Arduino
     sleep(.1) # Delay for one tenth of a second
     if counter == 255:
         counter = 32

Script from here. You must put in your appropriate port and baud rate. This Mathworks link describes how to find your port number.

In windows look in Device Manager under USB Serial Port.
In linux or OSX open a terminal and search with ls /dev/* or ls /dev/tty*. You can | grep <search> on the same line to search usb or ACM

This is a discussion about maximum baud rate. I have gone up to 250000 on the Due's programming port but you can go faster using the native port. You may also be limited by your computer usb though unlikely. 480 Mbit/s max for USB 2.0.

The Arduino Due has two USB ports available. The Native USB port (which supports CDC serial communication using the SerialUSB object)
  is connected directly to the SAM3X MCU. The other USB port is the
  Programming port. It is connected to an ATMEL 16U2 which acts as a
  USB-to-Serial converter. This Programming port is the default for
  uploading sketches and communicating with the Arduino.
The USB-to-serial converter of the Programming port is connected to
  the first UART of the SAM3X. It's possible to communicate over this
  port using the "Serial" object in the Arduino programming language.
The USB connector of the Native port is directly connected to the USB
  host pins of the SAM3X. Using the Native port enables you to use the
  Due as a client USB peripheral (acting as a mouse or a keyboard
  connected to the computer) or as a USB host device so that devices can
  be connected to the Due (like a mouse, keyboard, or an Android phone).
  This port can also be used as a virtual serial port using the
  "SerialUSB" object in the Arduino programming language.

From the Arduino Due guide you can switch Serial.print to SerialUSB.print, same with other serial functions like println. Then if you plug your usb into the Native port you can read off that port at a higher baud rate. You must also initialize the SerialUSB,
SerialUSB.begin(2000000);    // Initialize Native USB port
while(!SerialUSB);           // Wait until connection is established

It shouldn't matter what you set the baud rate at on the native port, it will run at the maximum bus speed but from what I know it has to be set regardless.
When running on the command line you can use > to send the output to a log file.
For example,
python serial_log.py > out.txt

Thanks for the detailed answer. I've now got a basic sketch output being read by python and displayed in a command prompt python window. I can data log now thanks to the path you set me on, using a different serial logger script I found here https://github.com/diegoherranz/serial-logger

I could not get the serial_log.py that you suggested to work.  I still have the same problem though, logging 8 columns of 16bit integers at a faster rate than 40millis. Do you think your suggestion will be able to log any faster?

I believe the code provided only works with python2. If you got something else similar to work thats just as well. Raising your baud rate will increase your transmission speed, notes on baud rate. The python script may enable baud rates that the arduino ide does not support. If your problem is in fact with the speed of an arduino function you may look into an alternative, this is an example for the analogRead function.

Update: with 250000 baud I can increase the sampling rate to 2 millis, which is good but I need a minimum of 1 millis and ideally I'd hit 0.5 millis. I know there is 500k and 1M baud rates available but anything above 250k baud returns gibberish. There's got to be a way of reading 16 digital pins 8 times in a row and logging the result every 0.5ms.....

Use the native port and increase the baud rate further. Replace Serial.print with SerialUSB.print, see the updated response.

Implemented! The Due can't make up its mind whether it is connected to port 5 or port 6. I can upload the sketch but pyserial logger can't access the port and neither can serial monitor. It's nearing midnight for me so I think I'll have to leave this for tomorrow, if I can sleep that is, I feel like I'm on the edge of a breakthrough! Cheers

Make sure you are only accessing the serial from one location. If you have the Arduino ide accessing the monitor then you may not be able to use a script to access it, or if you have two terminal windows open. Also I would still probably program via the programming port, then switch over to the native port for reading. Hope it helps!

You nailed it! program in the programming port run the pyserial logger in the native USB port and I'm golden! After playing about with my sketch I am now reading at 1millis average. I believe I will be able to claw back some processing time by fine tuning my sketch and finding a more streamlined way of reading 16dig pins, converting to dec, then printing. BUT the problem of fast data logging to file on my computer/laptop has been cracked, the question thoroughly answered. I am very grateful of your time and your help. Thank you!


text:
Connecting multiple topics- MQTT
I'm configuring an ESP8266 using Arduino Uno.
I have several MQTT topics I wish it to subscribe, and I do not want to repeat code 3 or 4 times ( in Python I would have created a list - and make a for loop to subscribe all )
These are my topics:
//MQTT topic
const char* deviceName = "Sonoff1";
const char* deviceTopic = "HomePi/Switches/Sonoff1";
const char* msgTopic = "HomePi/Messages";
const char* groupTopic = "HomePi/All";

This is the function registering a single topic:
void reconnect() {
        // Loop until we're reconnected
        while (!client.connected()) {
                Serial.print("Attempting MQTT connection...");
                // Attempt to connect
                if (client.connect(deviceName,user, passw)) {
                        Serial.println("connected");
                        pub_msg("Power On");
                        client.subscribe(deviceTopic);
                } else {
                        Serial.print("failed, rc=");
                        Serial.print(client.state());
                        Serial.println(" try again in 5 seconds");
                        // Wait 5 seconds before retrying
                        delay(5000);
                }
        }
}

Appriciate you kind help,
Guy

make an array and use a for loop

just for a closure:
added an array (thank to Juraj):const char* topicsArry[]={deviceTopic, msgTopic, groupTopic, "HomePi/Dvir/Clock", "HomePi/Dvir/Alerts"};
a for loop to over this that loop, and using sizeof ( which was not trivial for me ), led to :
void reconnect() {
        // Loop until we're reconnected
        while (!client.connected()) {
                Serial.print("Attempting MQTT connection...");
                // Attempt to connect
                if (client.connect(deviceName,user, passw)) {
                        Serial.println("connected");
                        pub_msg("Power On");
                        for (int i=0; i<=sizeof(topicsArry)/sizeof(char *); i++){
                          client.subscribe(topicsArry[i]);
                          char msg[50];
                          sprintf(msg, "Subscribed to %s",topicsArry[i]);
                          pub_msg(msg);
                        }
                } else {
                        Serial.print("failed, rc=");
                        Serial.print(client.state());
                        Serial.println(" try again in 5 seconds");
                        // Wait 5 seconds before retrying
                        delay(5000);
                }
        }
}

You can make life easier if you arrange your topic names hierarchically.
As an example suppose we have a multimedia controller that accepts various commmands:

mediaserver/set/volume
mediaserver/set/pause
mediaserver/set/audio/source
mediaserver/set/video/subtitles
etc...

You can then subscribe to "mediaserver/set/#"
For looping over the array of topics, you can take advantage of modern C++'s range-based for loop:

https://en.cppreference.com/w/cpp/language/range-for

Example code:
const char *topicArry[] = {
    deviceTopic, msgTopic, groupTopic,
    "HomePi/Dvir/Clock", "HomePi/Dvir/Alerts"
};
void reconnect() {
    // Loop until we're reconnected
    while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
        // Attempt to connect
        if (client.connect(deviceName,user, passw)) {
            Serial.println("connected");
            pub_msg("Power On");
            for (const char *topic : topicsArry) {
                client.subscribe(topic);
                char msg[50];
                sprintf(msg, "Subscribed to %s",topic);
                pub_msg(msg);
            }
        } else {
            Serial.print("failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            delay(5000);
        }
    }
}


text:
what the benefit uploading hex file merely to arduino board?
What the benefit of uploading merely hex file to avr based board like arduino uno Since the arduino ide it self will send intel hex file to the board after compile .ino file to hex file by the avrdude compiler (https://github.com/arduino/Arduino/wiki/Build-Process)?

The data is send to the bootloader, and the bootloader writes it to flash memory. Can you explain your question? What else would you want to upload to the arduino board?

i just wondering if there is sketch speed execution difference betwen uploading .ino file and uploading pure hex file whether via usb or isp

If you want to upload the same sketch to many  Arduinos compiling it again and again would take much longer. Or if you create a firmware ànd don't want to disclose the source code, you can distribute it in compiled form.

In some languages an accent can be used to emphasize a word, but the other accent is used (á). What is ànd?

@Jot, I don't know. I wrote it on an Android phone with on screen keyboard which has only English characters

i just want to know if there is significant speed difference in user program excecution between .ino file and hex file

ino file is not executable. it is a source code. an input for the compiler

@juraj i do agree with you reffer to link i attached with my question. but when you googling "send hex file to avr board" and some short of that  you will find alot talking around that concept. what dou you think

The page describes what happens when you push the Upload button in IDE. The "send hex file to avr board" is about sending a ready hex file. It is the last chapter of the "build process". What is unclear?

if the arduino ide via uart connection send hex file extracted from .ino file to arduino board after upload button pressed why so many avr anthusiast talking about send hex file to avr board like http://www.hobbytronics.co.uk

because AVR was here long before Arduino. and the multiuploads

so you are saying coding with .ino or send hex file to arduino board will result the same in term of program speed execution

the hex created from that ino will be always the same. if you write in assembler language or low level C, the hex will be different and the program possible faster.

thank you bro its clear now that asm c and ino created different hex file. again thank you.


text:
Arduino sketch for NodeMCU v1.0 (ESP8266-12E) has no error of compiling but does not run on NodeMCU v1.0 (ESP8266-12E) Board
i compiled a Arduino Sketch for NodeMCU v1.0 (ESP8266-12E) which have no error while i test with verifiy button in Arduino IDE 1.8.6 but i don't know what is the problem when i upload and test it . it [ NodeMCU v1.0 (ESP8266-12E) ] is not showing an static IP address while there is turned ON WiFi hotspot from my android phone.
I'm sharing two codes (code 1, code 2) here. Code 2 connect to the WiFi Hotspot but i make changes in code 2 to make code 1 for desired output which is not working.
Need help for making proper code.
code 1
#include <ESP8266WiFi.h>

int pin1 = 2; // GPIO 14 (D5)
int pin2 = 3; // GPIO 5 (D1)
int pin3 = 6; // GPIO 5 (D2)

  const char* ssid = "wifi";
   const char* password = "12345678";

  WiFiServer server(80);

void setup()
{

  Serial.begin(115200);
  delay(10);

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(6, OUTPUT);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

// Start the server
  server.begin();
  Serial.println("Server started");

// Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
  return;
}

// Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
  delay(1);
}

// Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
// Match the request
  int value = LOW;
  if (request.indexOf("/pin1=ON") != -1) {
  digitalWrite(2, HIGH);
  value = HIGH;

}
  if (request.indexOf("/pin1=OFF") != -1) {
  digitalWrite(2, LOW);
  value = LOW;

}

  if (request.indexOf("/pin2=ON") != -1) {
  digitalWrite(3, HIGH);
  value = HIGH;

}
  if (request.indexOf("/pin2=OFF") != -1) {
  digitalWrite(3, LOW);
  value = LOW;

}

  if (request.indexOf("/pin3=ON") != -1) {
  digitalWrite(6, HIGH);
  value = HIGH;

}
  if (request.indexOf("/pin3=OFF") != -1) {
  digitalWrite(6, LOW);
  value = LOW;

}

// Set ledPin according to the request
//digitalWrite(ledPin, value);
// Return the response
// Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("");
  client.println("");
  client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
  client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
  client.println("");
  client.println("");
  client.println("

");
  client.println("
Wifi Based Project
");
  client.println("");
  client.println("

");
  client.println("");
  client.println("<button>Data </button>
");
  client.println("");
  client.println("

");
  client.println("");
  client.println("Load 1");
  client.println("<button>Turn On </button>");
  client.println("<button>Turn Off </button>
");
  client.println("");
  client.println("

");
  client.println("");
  client.println("Load 2");
  client.println("<button>Turn On </button>");
  client.println("<button>Turn Off </button>
");
  client.println("");
  client.println("

");
  client.println("");
  client.println("Load 3");
  client.println("<button>Turn On </button>");
  client.println("<button>Turn Off </button>
");
  client.println("");
  client.println("

");
  client.println("");
  client.println("

");
  client.println("");
  client.println("
");
  client.println("

");
  client.println("
");

  if(digitalRead(pin1)){client.print("Load 1 is ON	");}
  else{client.print("Load 1 is OFF	");}

  if(digitalRead(pin2)){client.print("Load 2 is ON	");}
  else{client.print("Load 2 is OFF	");}

  if(digitalRead(pin3)){client.print("Load 3 is ON	");}
  else{client.print("Load 3 is OFF	");}

  client.println("
");
  client.println("
");
  client.println("");
  client.println("");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

}

if you will upload this code in your NodeMCU v1.0 (ESP8266-12E) , this will connect with your Android phone. You can consider it, code 2 and above code 1.
code 2
#include <ESP8266WiFi.h>

int pin1 = 14; // GPIO 14 (D5)
int pin2 = 5; // GPIO 5 (D1)
int pin3 = 4; // GPIO 5 (D2)

const char* ssid = "wifi";
const char* password = "12345678";

WiFiServer server(80);

void setup()
{

Serial.begin(115200);
delay(10);

pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");

}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}

// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

if (request.indexOf("/l1on") > 0)  {
digitalWrite(pin1, HIGH);

}
if (request.indexOf("/l1off") >0)  {
digitalWrite(pin1, LOW);

}

if (request.indexOf("/l2on") > 0)  {
digitalWrite(pin2, HIGH);

}
if (request.indexOf("/l2off") >0)  {
digitalWrite(pin2, LOW);

}
if (request.indexOf("/l3on") >0)  {
digitalWrite(pin3, HIGH);

}
if (request.indexOf("/l3off") > 0)  {
digitalWrite(pin3, LOW);

}

// Set ledPin according to the request
//digitalWrite(ledPin, value);

// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); //  do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("");
client.println("");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("");
client.println("");
client.println("

");
client.println("
Wifi Based Project
");
client.println("");
client.println("

");
client.println("");
client.println("<button>Data </button>
");
client.println("");
client.println("

");
client.println("");
client.println("Load 1");
client.println("<button>Turn On </button>");
client.println("<button>Turn Off </button>
");
client.println("");
client.println("

");
client.println("");
client.println("Load 2");
client.println("<button>Turn On </button>");
client.println("<button>Turn Off </button>
");
client.println("");
client.println("

");
client.println("");
client.println("Load 3");
client.println("<button>Turn On </button>");
client.println("<button>Turn Off </button>
");
client.println("");
client.println("

");
client.println("");
client.println("

");
client.println("");
client.println("
");
client.println("

");
client.println("
");

if(digitalRead(pin1)){client.print("Load 1 is ON	");}
else{client.print("Load 1 is OFF	");}

if(digitalRead(pin2)){client.print("Load 2 is ON	");}
else{client.print("Load 2 is OFF	");}

if(digitalRead(pin3)){client.print("Load 3 is ON	");}
else{client.print("Load 3 is OFF	");}

client.println("
");
client.println("
");
client.println("");
client.println("");
delay(1);
Serial.println("Client disonnected");
Serial.println("");

}

Also asked at: https://stackoverflow.com/q/52342641 and http://forum.arduino.cc/index.php?topic=568674 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.

You can't use io 6. IO 6 is for internal use to connect the flash memory to esp8266. IO 6 has no Dx pin on the board. And io 3 is Serial RX connected to USB.
Use Dx constants and the corresponding 'D' labeled pins of the NodeMcu. (and remove conflicting comments)
const int pin1 = D2;
const int pin2 = D3;
const int pin3 = D6;

pin D3 is io 0 used to put the board into flashing mode. do not connect there something that pulls the pin LOW at reset or power-up

Actually, I am newbie in arduino and programming . i take this code in demo form, so i have no idea of conflicting comments. But i share both codes (Demo+modified) to understand for everyone to get desired code.

and did the answer help?


text:
"exit status 1" error when invoking "useInterrupt" method
for context to this post you can catch up on this post
I am working with an Arduino Leonardo and Adafruit Music Maker shield.
I am trying to use the startPlayingFile method via the interrupt pin but I am getting a exit status 1 error when instantiating the interrupt pin. I have pin pointed the error down this one statement. If I comment this statement out, the sketch compiles.
if (! musicPlayer1.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
    Serial.println(F("DREQ pin is not an interrupt pin"));

The frustrating thing is that this is also the case with the example sketch "player_interrupts" provided by Adafruit.
Does anyone have a clue as to what is causing this compile error?

Here's my code which is a slightly simplified version of the example sketch
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)

// These are the pins used for the music maker shield
//SHIELD 1
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)
#define DREQ          3       // VS1053 Data request, ideally an Interrupt pin

// SHIELD 2
#define SHIELD_CS_2     5      // VS1053 chip select pin (output)
#define SHIELD_DCS_2    2      // VS1053 Data/command select pin (output)
#define DREQ_2          0       // VS1053 Data request, ideally an Interrupt pin

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt

  Adafruit_VS1053_FilePlayer musicPlayer1 = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
  Adafruit_VS1053_FilePlayer musicPlayer2 = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS_2, SHIELD_DCS_2, DREQ_2, CARDCS);
//  Adafruit_VS1053_FilePlayer musicPlayer3 = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS_3, SHIELD_DCS_3, DREQ_3, CARDCS);

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

  if (! musicPlayer1.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053_1, do you have the right pins defined?"));
     while (1);
  }

  Serial.println(F("VS1053 found"));

  musicPlayer1.sineTest(0x44, 500);    // Make a tone to indicate VS1053 is working
  musicPlayer2.sineTest(0x44, 500);

  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }
  Serial.println("SD OK!");

  // list files
  printDirectory(SD.open("/"), 0);

  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer1.setVolume(20,20);
  musicPlayer2.setVolume(20,20);

  /***** Two interrupt options! *******/
  // This option uses timer0, this means timer1 & t2 are not required
  // (so you can use 'em for Servos, etc) BUT millis() can lose time
  // since we're hitchhiking on top of the millis() tracker
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT);

  // This option uses a pin interrupt. No timers required! But DREQ
  // must be on an interrupt pin. For Uno/Duemilanove/Diecimilla
  // that's Digital #2 or #3
  // See http://arduino.cc/en/Reference/attachInterrupt for other pins
  // *** This method is preferred
  if (! musicPlayer1.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
    Serial.println(F("DREQ pin is not an interrupt pin"));

//     if (! musicPlayer2.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
//    Serial.println(F("DREQ pin is not an interrupt pin"));
}

void loop() {
  // Alternately, we can just play an entire file at once
  // This doesn't happen in the background, instead, the entire
  // file is played and the program will continue when it's done!
//  musicPlayer1.playFullFile("track001.mp3");

  // INTERRUPT
  // StartS playing a file, then we can do stuff while waiting for it to finish
  musicPlayer1.startPlayingFile("track002.mp3");
//  musicPlayer2.startPlayingFile("track002.mp3");

}

/// File listing helper
void printDirectory(File dir, int numTabs) {
   while(true) {

     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

This is the output of the compiler which seems to show the error happening at "Linking everything together..."
Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Board: "Arduino Leonardo"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\edwar\Documents\Arduino\libraries -fqbn=arduino:avr:leonardo -ide-version=10807 -build-path C:\Users\edwar\AppData\Local\Temp\arduino_build_927460 -warnings=none -build-cache C:\Users\edwar\AppData\Local\Temp\arduino_cache_535084 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose C:\Users\edwar\Documents\Arduino\Test_simul_play\Test_simul_play.ino
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\edwar\Documents\Arduino\libraries -fqbn=arduino:avr:leonardo -ide-version=10807 -build-path C:\Users\edwar\AppData\Local\Temp\arduino_build_927460 -warnings=none -build-cache C:\Users\edwar\AppData\Local\Temp\arduino_cache_535084 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose C:\Users\edwar\Documents\Arduino\Test_simul_play\Test_simul_play.ino
Using board 'leonardo' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr
Detecting libraries used...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\leonardo" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\sketch\\Test_simul_play.ino.cpp" -o nul
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\leonardo" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SPI\\src" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\sketch\\Test_simul_play.ino.cpp" -o nul
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\leonardo" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SPI\\src" "-IC:\\Users\\edwar\\Documents\\Arduino\\libraries\\Adafruit_VS1053" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\sketch\\Test_simul_play.ino.cpp" -o nul
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\leonardo" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SPI\\src" "-IC:\\Users\\edwar\\Documents\\Arduino\\libraries\\Adafruit_VS1053" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\libraries\\SD\\src" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\sketch\\Test_simul_play.ino.cpp" -o nul
Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SPI\src\SPI.cpp
Using cached library dependencies for file: C:\Users\edwar\Documents\Arduino\libraries\Adafruit_VS1053\Adafruit_VS1053.cpp
Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries\SD\src\File.cpp
Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries\SD\src\SD.cpp
Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries\SD\src\utility\Sd2Card.cpp
Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries\SD\src\utility\SdFile.cpp
Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries\SD\src\utility\SdVolume.cpp
Generating function prototypes...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\leonardo" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SPI\\src" "-IC:\\Users\\edwar\\Documents\\Arduino\\libraries\\Adafruit_VS1053" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\libraries\\SD\\src" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\sketch\\Test_simul_play.ino.cpp" -o "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 "-DUSB_MANUFACTURER=\"Unknown\"" "-DUSB_PRODUCT=\"Arduino Leonardo\"" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\leonardo" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SPI\\src" "-IC:\\Users\\edwar\\Documents\\Arduino\\libraries\\Adafruit_VS1053" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\libraries\\SD\\src" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\sketch\\Test_simul_play.ino.cpp" -o "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\sketch\\Test_simul_play.ino.cpp.o"
Compiling libraries...
Compiling library "SPI"
Using previously compiled file: C:\Users\edwar\AppData\Local\Temp\arduino_build_927460\libraries\SPI\SPI.cpp.o
Compiling library "Adafruit_VS1053"
Using previously compiled file: C:\Users\edwar\AppData\Local\Temp\arduino_build_927460\libraries\Adafruit_VS1053\Adafruit_VS1053.cpp.o
Compiling library "SD"
Using previously compiled file: C:\Users\edwar\AppData\Local\Temp\arduino_build_927460\libraries\SD\File.cpp.o
Using previously compiled file: C:\Users\edwar\AppData\Local\Temp\arduino_build_927460\libraries\SD\SD.cpp.o
Using previously compiled file: C:\Users\edwar\AppData\Local\Temp\arduino_build_927460\libraries\SD\utility\Sd2Card.cpp.o
Using previously compiled file: C:\Users\edwar\AppData\Local\Temp\arduino_build_927460\libraries\SD\utility\SdVolume.cpp.o
Using previously compiled file: C:\Users\edwar\AppData\Local\Temp\arduino_build_927460\libraries\SD\utility\SdFile.cpp.o
Compiling core...
Using precompiled core: C:\Users\edwar\AppData\Local\Temp\arduino_cache_535084\core\core_arduino_avr_leonardo_83dd9225a3a2a4e5654b35f3e742d65a.a
Linking everything together...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega32u4 -o "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460/Test_simul_play.ino.elf" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\sketch\\Test_simul_play.ino.cpp.o" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\libraries\\SPI\\SPI.cpp.o" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\libraries\\Adafruit_VS1053\\Adafruit_VS1053.cpp.o" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\libraries\\SD\\File.cpp.o" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\libraries\\SD\\SD.cpp.o" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\libraries\\SD\\utility\\Sd2Card.cpp.o" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\libraries\\SD\\utility\\SdFile.cpp.o" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460\\libraries\\SD\\utility\\SdVolume.cpp.o" "C:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460/..\\arduino_cache_535084\\core\\core_arduino_avr_leonardo_83dd9225a3a2a4e5654b35f3e742d65a.a" "-LC:\\Users\\edwar\\AppData\\Local\\Temp\\arduino_build_927460" -lm
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SPI\src\SPI.cpp: In function 'begin':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SPI\src\SPI.cpp:64:1: internal compiler error: Segmentation fault

 }

 ^

Please submit a full bug report,

with preprocessed source if appropriate.

See <http://gcc.gnu.org/bugs.html> for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.15.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

Using library SPI at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SPI
Using library Adafruit_VS1053 at version 1.0.5 in folder: C:\Users\edwar\Documents\Arduino\libraries\Adafruit_VS1053
Using library SD at version 1.2.2 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\libraries\SD
exit status 1
Error compiling for board Arduino Leonardo.

The code is OK. It compiles in IDE 1.8.6. You have some strange version of IDE and the compiler crashes with "internal compiler error: Segmentation fault"

Looks like the windows app store version. Buggy as hell, don't touch it. Same as all things Windows really...


text:
Sending a digital signal from one Arduino to another to trigger an event
I am wanting to send a digital signal from one Arduino to another. The goal is for one Arduino send a HIGH signal to a pin on the receiving Arduino. While the pin is HIGH, do function
I initially successfully tested this by blinking the LED on pin 13 but then I tried to add the functionality I needed but I couldn't get the state to change of pin 12 to change.
The circuit is simple
GND <--> GND
pin 10 --> pin 12
I saw there is already a post with a similar title but it didn't help me.
Any ideas?

Host Arduino
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

//DIGITAL SIGNAL PIN
int pin = 10;

void setup() {

 Serial.begin(9600);

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));

   if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }

  // list files
  printDirectory(SD.open("/"), 0);

  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int

    pinMode(pin, OUTPUT);}

void loop() {

  digitalWrite(pin,LOW);
  Serial.print(digitalRead(pin));

  // Play one file, don't return until complete
  Serial.println(F("Playing track 001"));
  musicPlayer.playFullFile("track001.mp3");
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing track 002"));
  musicPlayer.startPlayingFile("track002.mp3");

  delay(100);
}

/// File listing helper
void printDirectory(File dir, int numTabs) {
   while(true) {

     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

Slave Arduino
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

//DIGITAL SIGNAL PIN
int inPin =  12 ;
int state;

void setup() {

  Serial.begin(9600);

 if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));

   if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }

  // list files
  printDirectory(SD.open("/"), 0);

  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int

  pinMode(inPin, INPUT);
}

void loop() {

  state = digitalRead(inPin);
  Serial.println(digitalRead(state));

  if(state == HIGH){
    musicPlayer.playFullFile("track001.mp3");
    Serial.println(F("Playing track 001"));
    }
}

/// File listing helper
void printDirectory(File dir, int numTabs) {
   while(true) {

     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

please post the actual question .... you either have a problem with changing the state of pin 12 or changing the state of pin 10 .... which one is it? ..... it is unclear which one is the output

What has changed between the LED test working, and the actual functionality not working? For the LED experiment to have worked, the input pin of the receiving Arduino must have followed the output from the sender. Did any wiring change? Pinmode? If not, then the problem is in the new coding.

One method is to use interrupts with a state machine.  Here is a minimal example:
Master
#define pin 10 // connect to slave digital input pin
void setup(){
  pinMode(pin,OUTPUT);
  digitalWrite(pin,LOW);
}

void loop(){
if( // insert your condition to trigger the slave Arduino ){
 digitalWrite(pin,HIGH);
 delay(10); // short delay
 digitalWrite(pin,LOW);
 }
}

Slave
#define pin 2 // connect to master digital output "pin"
unsigned int state;
void setup(){
  pinMode(pin,INPUT);
  state=0;
  attachInterrupt(digitalPinToInterrupt(pin),isr,RISING) // trigger ISR on rising edge of master voltage signal
}

void loop(){
if(state==1){
  // your code here
  state=0;  // reset when done
 }
}

void isr() {
 state=1;
}

Digital interrupts can be done on the Arduino UNO with pins 2,3.  Don't forget to also connect a common electrical ground between Arduinos.

If you use SPI, you can't use pin 12 as GPIO. Pin 12 is SPI MISO.


text:
Using Waveshare Raspberry Pi TFT LCD with Arduino Uno
I have a 3.5 inch Waveshare Raspberry Pi TFT LCD which uses the XPT2046 Touch Controller. I want to use this LCD screen with my Arduino Uno.
I originally believed something like this was impossible, but then I found out that the XPT2046 Touch Controller is compatible with the Arduino, and a large number of libraries for the same exist. However, I'm not really very sure whether I can use this with my Arduino; the design of the screen I have is slightly different from the ones I've found online, which are supposed to be compatible with an Arduino Uno.
Is it possible for me to use this screen with my Arduino Uno? If so, what would the wiring schematics look like, and would I be able to use libraries like URTouch?

Possibly.
The XPT2046 chip is only for the touch screen, not the LCD.  That will be easy to get going on the Arduino since many many Arduino LCD screens use the same chip.
However, you will need to find out what driver chip the LCD display uses (maybe ILI9488 or HX8357 or something similar), and what pins on the Pi header relate to what function on the display (note: it is probably a 16 bit parallel interface, so uses a lot of pins).
Also note that this only applies to displays that connect only to the big 40 pin header. If it uses the FPC display connector you will have no luck trying to use it with an Arduino.

it is SPI https://www.waveshare.com/product/3.5inch-RPi-LCD-A.htm

That will be very slow over SPI at that resolution...

Is there a website where I could find which driver chip the LCD uses? The LCD connects only to the 40 pin header on the RPi, and does not use the FPC display connector. It is a parallel interface of 16 pins each side, you're right.

I've found some docs (scroll down to the Interface section) which underlines what each pin on the display does. I probably now can build a circuit, but I have no idea on how to program each pin. Is there any guide which you know of?

as I write in the first comment, it is SPI. try SPI libraries for displays. and lookup Arduino SPI wiring