text:
TinkerCAD switch seems to be not working (always closed)
I am using TinkerCAD to simulate the functionality of a slide switch. Please comment if you think this question is off-topic.
/*
  LiquidCrystal Library - Hello World

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */
#include <LiquidCrystal.h>

const byte pin8 = 8;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);      // open the serial port at 9600 bps:
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Welcome.");
}

void loop() {
  byte val = digitalRead(pin8);
  Serial.println(val);
  if(val == HIGH)
  {
    lcd.setCursor(0, 1);
    lcd.print("Switch on right.");
  }
  else
  {
    lcd.setCursor(0, 1);
    lcd.print("Switch on left.");
  }
}

The serial monitor and the output of the LCD screen are showing the slide switch to always be on the right side (not creating an open circuit when the switch is on the left side).

As seen in the picture, the switch is on the left. And the code, I think, is correct. So it should display, "Switch on left." This is because pin8 is low (not connected to 3.3V).
So I'm very confused. The switch appears to be shorting all three rails to which it's connected. When the switch is removed, that part becomes open; pin8 is low.

General idea not to leave your pin floating.
If I were you I would use a pull-down resistor (10K) from pin8 to GND.

Is there a way to make your circuit and code public? so we can try it?

As  Sener said, "use a pull-down resistor (10K) from pin8 to GND."

And in case anyone notices, yes, I'm aware of clear().

TinkerCAD must be assuming a floating input reads high instead of an intrinsically floating ground. The most simple solution is adding pinMode(pin8, INPUT_PULLUP); to the setup() function. Then, tie the opposite (than with a resistor) side of the switch to ground: Modified circuit TinkerCAD simulation.

Yes, it is also way to do but then you have to invert the switch function. Means, instead of going 3.3V it should be GND this time.


text:
ESP8266: Multiple analog inputs using software
Is there a way to get at least three analog inputs to the esp8266 (without a multiplexer)?
Each digital or analog pin on an Arduino can be configured as digital or "analog" (e.g., PWM software).
Here is a way to squeeze one additional analog input pin: hackaday.io/project/8435-2-analog-inputs-for-esp8266-without-multiplexer
Any ideas or software?

it depends on what you're feeding it. if it can be crude, you might be able to use mosfets.

1) nope it's not possible "in a straightforward way". you should use analog muxes.
2) the statement "Each digital or analog pin on an Arduino can be configured as digital or "analog" (e.g., PWM software)." means for PWM or the so called "analog output". not intended the ADC unit.
3) the link provided uses software tricks to measure 2 signals in a muxed fashion. it's up to purpose.
workarounds :
1) use CD4066 CMOS bilateral switch. it works with analog signals.
2) use GPIOs to supply voltage to measurement units. like the link you provided. it works for passives like photoresistors and for devices like LM35 temp sensor. but can't be used for devices like 3 channels analog-out accelerometers.

Um, for (2), I put it in quotes for that very reason.

source: Stack Exchange

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

sort: votes


text:
Is an ESP32 HTTP web server limited to a certain number of Base64 images?
This sketch only displays about nine images (when there are more). Does this mean the ESP32 is limited amount of Base64 images able to be displayed?
#include <WiFi.h>
#include <WebServer.h>

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

IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);

// Used for determining the selected pattern and HTML to display:
int pattern = 0;
int selectedPattern = 0;

String circleString = "<img src=\"data:image/png;base64,[encoded data, 6912 characters]\" alt=\"NAME\" style=\"width:100%\">\n";

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

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);

  server.on("/", handle_OnConnect);
  server.onNotFound(handle_NotFound);

  server.begin();
  Serial.println("HTTP server started");
}
void loop()
{
  server.handleClient();

}

void handle_OnConnect() {

  server.send(200, "text/html", SendHTML(selectedPattern));
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(int pattern)
{
    String ptr = "<!DOCTYPE html> \n";
    // Instance of class String (not a pointer)

    ptr += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
    // <meta> viewport element makes the web page responsive in any web browser
    // https://www.w3schools.com/css/css_rwd_viewport.asp

    ptr += "\n";

    ptr +="\n";
    ptr +="\n";

      /*  */
      ptr += "
\n"; // 1
        ptr += circleString;
      ptr += "
\n";

      ptr +="1\n";

      ptr += "
\n"; // 2
        ptr += circleString;
      ptr += "
\n";

      ptr +="2\n";

      ptr += "
\n"; // 3
        ptr += circleString;
      ptr += "
\n";

      ptr +="3\n";

      ptr += "
\n"; // 4
        ptr += circleString;
      ptr += "
\n";

      ptr +="4\n";

      ptr += "
\n"; // 5
        ptr += circleString;
      ptr += "
\n";

      ptr +="5\n";

      ptr += "
\n"; // 6
        ptr += circleString;
      ptr += "
\n";

      ptr +="6\n";

      ptr += "
\n"; // 7
        ptr += circleString;
      ptr += "
\n";

      ptr +="7\n";

      ptr += "
\n"; // 8
        ptr += circleString;
      ptr += "
\n";

      ptr +="8\n";

      ptr += "
\n"; // 9
        ptr += circleString;
      ptr += "
\n";

      ptr +="9\n";

      ptr += "
\n"; // 10
        ptr += circleString;
      ptr += "
\n";

      ptr += "
\n"; // 11
        ptr += circleString;
      ptr += "
\n";

      ptr += "
\n"; // 12
        ptr += circleString;
      ptr += "
\n";

      ptr += "
\n"; // 13
        ptr += circleString;
      ptr += "
\n";

    ptr +="\n";
    ptr +="\n";

    return ptr;

}

Sketch uses 726230 bytes (55%) of program storage space. Maximum is 1310720 bytes.
Global variables use 39384 bytes (12%) of dynamic memory, leaving 288296 bytes for local variables. Maximum is 327680 bytes.

You are including the image raw data several times in the returned string. That could blow up the memory indeed. Why don't you just include a reference to the image in the html and supply the image separately?

Because I do not know how to do that. Also, I am not sure if it matters, but this minimal program uses one image, but the actual program uses all different images.

I would need to read the docs, too. You would need to convert the image back to binary and serve it directly. And then do something like server.on("/myimage.png", ServeImage(myimage.png)).

did you check the html source in the browser? I guess it is cut, because the esp fails to allocate more memory for the large String

You build up the HTML website by concatting strings together by hand in the code. I know this is done in many code throughout the internet, but this is only really practical, if you need to change the website content with every request. Normally it is better to use SPIFFS (or now LittleFS) to store the files and let a fitting webserver library serve them as static files. Additionally you are making Swiss cheese out of your heap memory when you concat String variables this often and you might run out of RAM.
I'm not used to LittleFS, so I will write this answer using SPIFFS. But I'm sure you can use LittleFS in a very similar way. I will leave it to you to determine how it fits in with code for SPIFFS.
Have a look at the ESPAsyncWebServer library and its simple server example. I've used this library for my projects. Try the examples, read the documentation and get an idea how this library is working.
Then have a look at the documentation where it says "Serving static files". I think you want to serve your static files from a directory. That way the library will look for requested files in that complete directory inside of the SPIFFS. Inside that directory you will have your HTML website (named as index.html) and all the images as binary data in a format, that a webbrowser can read (like jpg, png, ...). In your HTML website you reference the images with their path. Since in this scenario they all lie in the root directory the path is only the filename (+ the files extension).
When the webbrowser requests the index.html from the ESP, the library will serve it from SPIFFS. The webbrowser interprets the site and sees the references to the images. It than tries to load these images, meaning it sends requests to the ESP with the path of the images. The library will search for these files in SPIFFS, will find them and serve them to the webbrowser, who will then display them on the website.
Something like this:
#include "ESPAsyncWebServer.h"
#include "SPIFFS.h"

AsyncWebServer server(80);

void setup(){
  Serial.begin(115200);
  while(!SPIFFS.begin()){
    Serial.println("Could not mount SPIFFS");
    delay(500);
  }
  server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
  server.begin();
}

void loop(){
}

Note:

I've left out all Wifi related stuff. You need to add that yourself.
I've not tested this code, just put it together from one of my working bigger programs.
You still need to upload the actual files to the ESP SPIFFS. There are many tutorials on how to do that. Just place your files in the root directory of SPIFFS.

LittleFS vs SPIFFS docs are at https://github.com/esp8266/Arduino/blob/master/doc/filesystem.rst

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


text:
Trying to connect FT sensor to Arduino Mega using RX TX
I am trying to interface this sensor, https://www.robotous.com/forcetorquesensor (RTF60-HA01-C), with the Arduino Mega. The sensor has an input voltage of 5Vs and communicates using CAN/RS232/RS422. I am using the RS232 and have connected wires properly and have tried to establish Serial Communication using the below code.
#include<String.h>
# define BuffSize 32

byte buff[BuffSize];
unsigned char data_field[16];
byte comm[11]  = {0x55, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA};
// SOP == 0x55, EOP == 0xAA, Checksum == summation of each data in data_field
void setup() {

  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial2.begin(115200);
  for (int i = 0; i < BuffSize; i++) {
    buff[i] = 13; //Number to initialise buffer
  }

}

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

     Serial2.write(comm, 11);
    //Serial.println(Serial2.available());
    if (Serial2.available() > 0) {
      //int read = Serial2.readBytes(buff, BuffSize);
        String output = "";
        for(int i=0;i<BuffSize;i++){
        buff[i]=Serial2.read();
        output = output + buff[i] + "|";
     }
  //Serial.println(read);
    Serial.flush();

    Serial.println(output);
    Serial.println();

    }
  }

The output I receive is just 0s and the occasional 10. Like below
0|0|0|0|0|0|0|0|10|0|0|0|0|0|0|0|0|10|0|0|0|0|0|0|0|0|10|255|255|255|255|255|

I am new to this and hope this is not a stupid question.
Let

It seems I am posting this link on every other question at the moment: https://majenko.co.uk/blog/reading-serial-arduino I don't know where people are getting such bad code from for working with serial.

The Serial RX and TX pins of an Arduino are not RS-232 compatible without using some type of circuit to give you the proper voltage levels.
**RS-232 logic and voltage levels**
0 (space)   Asserted    +3 to +15 V
1 (mark)    Deasserted  −15 to −3 V

Connecting the RX/TX pins of an Arduino directly to an RS-232 device may fry your Arduino in addition to just not working for communication.  This circuit given below is an example what you'll need.  There are pre-made adapter boards available for a few dollars.

You obviously haven't understood the way this device communicates over serial. You don't just throw an "11" at it to get it going - you have to craft a proper command packet and send that, and the device then starts responding with response packets that you must parse properly.
A command packet starts with 0x55, then has the command and data (8 bytes in total), then a checksum and EOP byte (0xAA).
For example:
0x55, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0xAA

When reading you do not look for "at least one byte" then try and read 32 bytes. That's just never going to work.  You need to wait for 0x55 to arrive, then wait for each of the 16 following command+data bytes to arrive, one at a time (they do NOT arrive all at once!), and store them - then calculate the checksum for those command and data bytes, and read the next byte and make sure it matches the checksum. Finally, confirm you have a proper packet by reading the EOP byte of 0xAA.
Ideally, you want to implement a sliding window algorithm whereby you have an array of 19 bytes and incoming bytes filter down from one end of the array to the other. When the first byte is 0x55 and the last byte is 0xAA, and the penultimate byte equals the (truncated) total of bytes 2 to 17 inclusive, do you have an actual packet and can act on the data.


text:
How to flash an ATMEGA2560 using a WIZnet 5500?
I am wondering if anyone has ever flashed a ATMEGA2560 utilizing a WIZnet 5500? I have looked at this bootloader package but it only supports the 5100. I may have to do it myself but am a little worried as there doesn't seem to be any support/documentation online and I am not the best programmer. Any help would be greatly appreciated.

The latest Ariadne bootloader from 'codebender' is in his 'personal' GitHub repository. It has W5500 support. Per created his fork with better documentation and a hardware package earlier. The loathingKernel's repo still lacks good documentation.
I installed Per's Ariadne package over Board Manager and then I replaced the files in Per's package with files from loathingKernel's repo. The I flashed the bootloader to Mega without problems and the Ariadne bootloader worked for me over W5500.
I configured the upload from IDE too.

i trying to do same, but use arduino nano + wiznet5500 board. Default configuration with tftp server on 192.168.1.128 is started, but not responing for my tftp client. And I suspect 7KB of memory for the Ariadne bootloader and 26KB for the main firmware will overflow flash-memory microcontroller memory, since there is only 30KB. I'll try Mega, like you

@hwak, did you reset to bootloader. for Mega there is a better library now https://github.com/jandrassy/ArduinoOTA

thank you. It’s a pity that Mega is very large. I would like something smaller so that it fits into standard electrical sealed boxes 100х100 millimeters

@hwak, Nano Every is good, but it has no OTA solution yet. I plan to try to make one over SD card and SD bootloader. but I have too many Arduino plans and not enough free time for it.


text:
Calculating the time between the signal when its ON and when it gets OFF
class Channel
{
    private:
        uint8_t _pin;
        uint8_t _state;
        uint32_t _rise;
        uint32_t _fall;
        uint8_t _count;
        uint8_t _channel;

        static uint8_t channelCount;

        void display()
        {
            uint32_t diff = (_fall - _rise) / 1000;
            uint32_t secs = diff % 60;
            uint32_t mins = diff / 60;
          //  Serial.print(",");
            Serial.print(_channel);
            Serial.print(",");
            Serial.print(mins);
            Serial.print(",");
            Serial.print(secs-4);
            Serial.print(",");
            Serial.println(_count);
        }

    public:
        Channel(int pin) : _pin(pin), _count(0)
        {
            _pin = pin;
            _count = 0;
            _channel = channelCount;
            channelCount++;
        }
        void process()
          {
            int s = digitalRead(_pin);
            if (s != _state)
              {
                _state = s;
                if (s == LOW)  // Fell
                  {
                    _fall = millis();
                    _count++;
                    display();
                  }
                else
                  {
                    _rise = millis();
                  }
                }
            }
        void begin()
        {
            pinMode(_pin, INPUT);
        }
};

uint8_t Channel::channelCount = 0;

Channel channels[] = { 3,5 };
#define NUM_CHANNELS (sizeof(channels) / sizeof(channels[0]))

void setup()
{
    Serial.begin(115200);
    Serial.println("Channel,Minutes,Seconds,Count");
    for (unsigned int i = 0; i < NUM_CHANNELS; i++)
      {
        channels[i].begin();
      }
}

void loop()
{
    for (unsigned int i = 0; i < NUM_CHANNELS; i++)
      {
        channels[i].process();
      }
}

This code works normally in some cases, (i.e.) It provides the exact time between the signal when it's ON and when it gets OFF in seconds.
In some cases, it spits out a 10 digit number. The correct value follows the unknown number in the screenshot attached below

bro that 10 digit is the 0xFFFFFFFF maximum value that an unsigned 32 bit integer can attain.

@Vaibhav: No, the maximum value is 4294967295. The value he is seeing is −4. C.f. Reezy's answer.

You have not yet explained why you have put the bug in there. I mean the "secs-4" instead of "secs".

The values which I get in seconds is four seconds more than the actual value. So I used "sec-4" instead of seconds

I suspect secs is 0 sometimes, because of _rise being 0? In that case unsigned int subtraction causes this: secs(0) - 4 = -4 % 2^32, resulting in your 4294967292

Oh, but there will be at least one second for which the signal will last. (I'm getting 4294967292 three to four times for a single ON and OFF transition). Is there any other possibility that might cause this to appear?

I suggest tracer bullets, i.e. print out all the variables in the Display method.

Yeah but still seconds cant be zero in my case there will be atleast 4 to 5 seconds, so even if I remove that "-4", still I would be getting this number right?


text:
NodeMCU V3 + SD Card with Arduino IDE Not working
I am trying to connect CATALEX MicroSD Card adaptor to new NodeMCU V3 and PIN configuration are as below,
NodeMCU  ---------> SD Card
GPIO13 (D7) ------> MOSI
GPIO12 (D6) ------> MISO
GPIO14 (D5) ------> SCK
GPIO15 (D8) ------> CS
VCC (3.3V) -------> VCC
GND --------------> GND

Tested above setup with QuickStart program from SdFat library in Arduino IDE. But it gives error output as below,
SPI pins:
MISO: 12
MOSI: 13
SCK:  14
SS:   15

SD chip select is the key hardware option.
Common values are:
Arduino Ethernet shield, pin 4
Sparkfun SD shield, pin 8
Adafruit SD shields and modules, pin 10

Enter the chip select pin number: 15

Disabling SPI device on pin 10
Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X20,0XFF

SD initialization failed.
Do not reformat the card!
Is the card correctly inserted?
Is chipSelect set to the correct value?
Does another SPI device need to be disabled?
Is there a wiring/soldering problem?

errorCode: 0x20, errorData: 0xff

chipSelect is 15.

Also, I am using SanDisk 16GB Micro SDHC class 4 Memory Card.
I have tried googling with the error but did not find solution. Please help me.

use the SD library. the esp8266 version. it is a part of the esp8266 arduino package. you can find the examples in IDE Examples menu

Tried CardInfo program with SD library as well and it gives initialization failed error.

the adapter has a 5 V to 3.3 V conversion? like this one? https://www.arduitronics.com/product/210/microsd-card-adapter-catalex

@Juraj: The NodeMCU's SPI pins are 3.3V-ish.

@yeti, I know and if the SD adapter is 5 V then there is the problem

@Juraj, Adapter does have 5 V to 3.3 V conversion. I am using same adapter as https://www.arduitronics.com/product/210/microsd-card-adapter-catalex.

could you provide your code?? @Akshay

SD cards work on 3.3 V, so the adapter has 5 V to 3.3 conversion for power and signal, to connect SD card reader to a 5 V MCU. You can't connect this SD card  adapter to an 3.3 V MCU like the esp8266.

but I would connect the adapter to 5V pin for a test

NodeMCU has VIN pin which shows voltage around 4.25 V, can this be connected to VCC of the SD card? Or should I use external 5 V power supply?

I work with Wemos and there is a 5 V pin.  I thought NodeMcu has it too. I don't know it the Vin of NodeMcu can be used to power devices.

Thank you, it worked with VU pin of nodemcu which provide 5V supply

This is brilliant, works as a charm surely. I have just tried it out was facing a similar challenge, though for my case the output voltage on VIN is 4.75V

If you are giving power to nodemcu through USB cable. SD card VCC can be connected to the VIN pin of nodemcu ESP8266. I faced the same problem
NodeMCU V3 + SD Card with Arduino IDE Not working
but after connecting VCC of SD Card to VIN pin of nodemcu. it worked.
Thanks for the helping me Mr. Juraj


text:
NodeMCU capable of key injection?
Short version: Is the NodeMCU capable of key injection in the same way that an Arduino Teensy can be programmed with Duckuino script to function as a HID?
Long version: Recently, my 7+ year old iMac suddenly stopped working and now I am unable to boot into the Mac which is a right pain. Even more of a pain is that due to the fact that the iMac has a wireless keyboard as opposed to a USB meaning that I am unable to boot into Single User mode, recovery mode, safe boot etc. This is a pain as I am currently stuck with an iMac in an unsuccessful boot loop. I understand that the best option would be to buy a USB keyboard and use this separately; however, it turns out that one of my friends has a spare NodeMCU and said he's willing to lend it to me as he is pretty sure that the Duckuino script will work on it meaning that I could use the NodeMCU as a sort of impromptu keyboard to hold down the shift key on boot, effectively removing the need for me to buy and wait for a new USB keyboard.
I had found this video here on YouTube which explains the process of turning an Arduino into a "USB Rubber Ducky" but there is no mention of this working with a NodeMCU. Assuming that I have the ESP8266 addon for the Arduino IDE and was able to put the Duckuino script onto the NodeMCU, would the NodeMCU function as intended with the Duckuino script or is the NodeMCU hardware such that this would be impossible?
Thank you for any assistance,
Kind regards,
John
P.s. This is what my NodeMCU looks like:

No, you can't. You need a USB capable MCU. The ESP8266 is not.

@Majenko Thank you for your response; so I would need something like the Teensy etc?

Yes, or an Arduino Micro, or other ATMega32U4 based Arduino. Or one of the direct-USB connected chipKIT boards, like a Fubarino Mini, etc.

lend an USB keyboard :-)

@Majenko Thank you for your help. For now I think I'll just have to settle with getting a USB keyboard but might look further into Duckuino etc. in the future. :)

if you live near a goodwill or salvation army, you can get a (used) usb kb for about $2...

A bit late, but yes you can. Though it seems to be a pain: https://hackaday.com/2016/09/03/software-usb-on-the-esp8266/

For those who are still looking for ESP8266 Software USB, have a look at this GH repo (cnlohr/espusb)

No, you can't use a NodeMCU for this.
To emulate a USB keyboard you have to have a device with a main MCU on it which is directly connected to USB. The ESP8266 on the NodeMCU is not a USB-capable MCU, and so it uses a USB to UART bridge chip to connect the ESP8266 to the USB of your computer.
You can't program that bridge chip, so you can't make it anything other than a serial port.
Common devices that are directly USB connected and can emulate a keyboard include:

Arduino Micro
Teensy 3.X
Fubarino Mini / SD
Arduino Leonardo
chipKIT Lenny

And there are many more.
For 8-bit Arduino boards you need to look at the MCU it uses. If it's an ATMega32U4 as the main MCU then you can program it to be a keyboard.

Addendum: There are ways of making non-USB boards work as a keyboard. For ATMega328P based Arduinos and similar that use an ATMega16U2 chip as the USB to UART bridge, that bridge chip can be reprogrammed to appear as a keyboard.  For other MCUs there may be software "bit-banged" USB implementations available (such as V-USB), though YMMV with those implementations, and they require building extra hardware to interface the chip to the USB port.

Thank you very much for your answer! It's a shame that the NodeMCU cannot be used for this purpose. I see that you have mentioned there are ways of making non-USB boards work as keyboards but I can't see any mention of the NodeMCU specifically; is this because it is impossible to do for this board? If not, would you be able to point me in the right direction of how to do this? Thank you once again!

yes, it's impossible to make the ch340 or cp2102 into a usb hid like you can the megaxUxs...


text:
Difference between these two NodeMCU boards?
I recently received a NodeMCU (identical to the one shown in the first picture below) and originally, I was unable to connect it to my computer which eventually turned out to be driver issues; however, during my initial panic, I found that there seems to be two variations of the NodeMCU board.
As you can see from the pictures below, at first glance there seems to be no difference to the boards, however, some of the more noticeable differences are that the first one has only one "orange" chip whereas the second one has two. Moreover, the first one has a large square chip towards the USB port wheareas the second seems to have a rectangular one.
First one:

Second one:

I would really appreciate if someone could enlighten me to what these small differences are between the two boards are and also what are the implications of these differences (if there are any).
Thank you in advance for any help,
Kind regards,
John

the one on top is better: narrower, better 5v (vin), faster serial, etc

Marcel Stör wrote an excellent comparison of the different NodeMCU development boards: https://frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/

The top one is a real NodeMCU version 1 board (ESP-12E module).
The bottom one is a knock-off copy - looks like the same module on it.
The biggest difference is the USB interface. The real one uses a CP2102 USB to UART bridge. The copy uses a CH340G chip.  The CH340G is notoriously unstable and liable to die at a moments notice.  The CP2102 is far more reliable.  I recently accidentally nuked a Wemos D1 Mini pro which has the same CP2102 on it with 12V.  It took out the voltage regulator. It took out the ESP8266 chip.  I replaced both those, and the CP2102 was proved to still be working fine. More than could be said for a CH340G - glance at one of those wrong and they die.

Thank you for your answer! I wasn't aware that there were knock-off clones of the NodeMCU out there and I'm so glad that the one I have is not one of them! I'll be sure to look out for the differences in the future; other than that, my NodeMCU seems to be functioning perfectly. Quick point; I came across this article: frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/ where the picture they use of the board does seem to have the  CP2102 chip but also seems to have an extra orange chip compared to the first picture above; why is this? Thanks once again :)

That's just a tantalum capacitor. They come in different colours from different manufacturers. Black and yellow are the most common colours.

Having China clone your device is a sign of success :)

Perfect, thank you so much for your help! Hahaha I guess that's true :)

@Majenko: Regarding the CH340G, have you had that happen to you? Under which circumstances?
Most of my 3D-printer control boards use the CH340, and they've always been reliable.

I have 5 Arduinos with CH340G, all flashed few hundreds times, and none died.

I was wondering thy they would use the CH340G if the CP2102 is so much better, but then I looked up unit prices and saw how super expensive the CP2102 is.
actually somewhat odd how little progress there is in the USB to serial market.
actually at this point it might even be a good option to program a microcontroller to emulate/simulate a USB to serial chip, since adding a extra microcontroller for that purpose would actually be cheaper than a CP2102 in general.
also allowing more protocols, would only need to be (pre) programmed with a external chip once and then it works.

I have several of the second version and they all have the CP2102 USB to UART bridge. So I wouldn't say it's a copy or a clone. These are now made by several manufacturers, mine came from DOITING not AI Thinker, so the components can vary and come in different colours ! AND, Chinese is Good !


text:
Password.h and keypad.h change pass sketch for Arduino
I have a fixed password. If letter "D" is pressed on the keyboard and the correct password is entered, the fixed password will be then changed. This newly entered password is now the correct password, until the user decides again to change password. It is not working. How to fix it?
#include <Keypad.h>
#include <Password.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

const char keys[ROWS][COLS] = {
    {'1','2','3','A'},
    {'4','5','6','B'},
    {'7','8','9','C'},
    {'*','0','#','D'}
  };
const byte rowPins[ROWS] = {9,8,7,6};
const byte colPins[COLS] = {5,4,3,2};

Keypad    keypad { makeKeymap(keys), rowPins, colPins, ROWS, COLS };
Password passwd = Password("123A4");
char passwd2;

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

void loop() {

  char key = keypad.getKey();
   if (key != NO_KEY){
      delay(60);
      switch (key){
      case 'D': changepasswd(); break;
      case '*': checkpasswd(); break;
      case '#': passwd.reset(); break;
     default: passwd.append(key);
      }
   }
}

void checkpasswd() {

  Serial.print(passwd2);

   if (passwd.evaluate()){
      Serial.println(" OK.");
   } else {
      Serial.println(" Wrong password!");
   }
   passwd.reset();
}

void changepasswd() {
  char key = keypad.getKey();
      delay(60);
      Serial.print(key);
      passwd2 += key;
      passwd.set(passwd2);

   Serial.print("Password changed to ");
   Serial.println(passwd2);

}

It is not working is not a useful description  of what happens ... please provide a description of what actually happens

You don't have and kind of loop in changepasswd() to get more than one character into the password. Also you are just using the value from geKey() without first checking, if there was really a valid key pressed after the change was initiated. Work out the logic of your functions.

@jsotola The password is not changing. That is the description. The part of entering the default "123A4" is working and the OK message is appearing. If you enter an invalid code, it says "Wrong password". So far so good. But when it comes to changing the password via keyboard, it says "Passord changed to " and show nothing. If you enter the new password, it says "Wrong password"... if you enter the default password, it says "Wrong password".

@chrisl I have been working on this the whole week. I cannot work out the logic of my functions by myself at this point. This code is the best I could do and that's why I am asking for help to fix it, because I can no longer go further.

@LuizVaughan, if you enter the default password, it says "Wrong password" .... so, why do you say that the password is not changing? .... from what you said, it is changing .... you just do not know what it changes to ..... i suggest that  you spend time finding out what the new password is, and change your code so that it saves the actual password that you want

per1234; VE7JRO, sempaiscuba, MatsK and gre_gor. Sorry, but only you guys think this post was unclear. Problem was well understood and, by the way, solved many hours before you all "put on hold".

The logic of your function is garbled:

Function checkpasswd(): Most of the function is ok, but you don't need to send passwd2 through Serial, since it doesn't have anything to do with this function. You only use the variable for setting a new password. You can ditch this print statement.
Function changepasswd(): Here lies the problem. Most likely getKey() returns NO_KEY here, which is defined as the null character. So, when outputting it to Serial, you don't see anything there (The null character marks the end of a string in C/C++). You set the password to be the null character, which cannot every be inputted by the user. Also there lies another pitfall: The Arduino Playground Site for the Password library states for the set() function:

Warning: The new password should be a global variable (not a local
  function variable) as this function copies a pointer to the new
  password into the library, not a copy of the password.

Since the key variable is only local, after the function the Password library has it's internal pointer pointing to a now freed memory space. At some other point in the program this space might be written again, effectively changing to password to something else.
And lastly the function does not contain any loop, so only 1 character will be inputted and the newly set password can only be 1 character long. The buffer variable passwd2 is of type char, so also only 1 character. What you really need there is a char [] (character array).
Here is a bit of code (not tested), that should implement this correctly:
char passwd2[6]=""; //global buffer for new password
                    // 6 bytes, because a C string has to end with the null character

void changepasswd(){
    for(byte i=0;i<5;i++){
        char key = NO_KEY;
        while(key == NO_KEY || key=='*' || key=='#' || key=='D') key = keypad.getKey();
        passwd2[i] = key;
        delay(60);
    }
    passwd2[5] = '\0'; //ensure correct string ending
    passwd.set(passwd2);
}

Note the following points:

This implementation blocks the programs execution, until a full valid password has been typed. It will ignore all invalid characters, that you use for other purposes (#, * and D).
The passwd.set(passwd2) is actually only necessary the first time, we change the password, to let the Password object have a pointer to our buffer. After that we technically can change the password directly in the buffer, without calling the set() function. I included it here for readability and making the code a bit more fail prove (against wrong futher coding).
This is hardcoded to accept only 5-digit passwords. If you want passwords with arbitrary length, you can start programming from this basis.
Debouncing buttons with a simple delay() may be not enough at some point. But as I understand the source code of the Keypad library, it also includes code for debouncing, by only checking every 10ms for a changed button and returning NO_KEY everytime else.

Thank you a lot for your time to make corrections and for your detailed explanations. Your suggestion has been tested and is fully working. Kind regards!


text:
Minimal example of Task Scheduler Blink?
Scheduler_example00_Blink is ~300 lines. For just an Arduino Uno, what is a minimal example?
It's hard to know what belongs and what doesn't. This example has six different approaches, and I'm just trying to extract one of them.

what about the scheduler template?

the main GitHub page for the library has a link to an awesome web based Arduino emulator .... https://wokwi.com/playground/task-scheduler ... try deleting sections of code until you are left with minimum

i don't see it as being personal ... i am glad that you were able to work through it ... learning experience ... please don't forget to accept your own answer

#include <TaskScheduler.h>

// Scheduler
Scheduler ts;

/*
   Approach 1: LED is driven by the boolean variable; false = OFF, true = ON
*/
#define PERIOD1 500
#define DURATION 10000
void blink1CB(); // <-------------------------------------------|
Task tBlink1 ( PERIOD1 * TASK_MILLISECOND, DURATION / PERIOD1, &blink1CB, &ts        , true );
//           (     500 * 1UL (ms)        , 100000 ms/ 500    , function , just put it,  ?   )

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  ts.execute();
}

inline void LEDOn() {
  digitalWrite( LED_BUILTIN, HIGH );
}

inline void LEDOff() {
  digitalWrite( LED_BUILTIN, LOW );
}

// === 1 =======================================
bool LED_state = false;
void blink1CB()
{
  if ( LED_state )
  {
    LEDOff();
    LED_state = false;
  }
  else
  {
    LEDOn();
    LED_state = true;
  }
}


text:
Why do COM port numbers between Arduino and Processing not match?
I have a Processing program that reads data sent to the serial port by an Arduino. When I go to device manager it shows that the Arduino is plugged into COM 4, however in order to get Processing to read the data the number I need for the COM in the following line is 2:
String portName = Serial.list()[2]

Why do the numbers not match?
Thanks!

what numbers are you talking about?

Serial.list()[2] can easily refer to COM4 as well.

If you print out portName it should be COM4 it seems you must have 3 COM ports on your machine otherwise you would use index 0; Serial.List() appears to return an array or list which you are taking the third item located at index 2.

Indeed. The numbers do match. But you are trying to match a number with a name, and those do not match. Or are you Number 6?


text:
Time-bound LED program
I am trying to program a sketch such that an LED will light up for as long as a push button is pressed down. I have tested the components and electronics configuration before with a simpler program, and it all works, but there seems to be a problem in the code. I wanted to know how my sketch may be altered so the code will work:
const int ledPin = 12;
const int switchPin = 2;
const int Time = 100;
int buttonState = 0;
int count = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
}

void loop() {
buttonState = digitalRead(switchPin);
while (buttonState == HIGH) {
    count++;
    delay(100);
  }
  count=count*10;

  if (count>1) {
    digitalWrite(ledPin, HIGH);
    delay((count*10));
    digitalWrite(ledPin, LOW);
  }

}

And how exactly this doesn't work?

@gre_gor there is no response from the LED at all, regardless of how long, or much I press the button. When I use a simpler button-light up sketch, it works perfectly, but not with this code

Why do you increase the count value? Should the led be longer on each time the button is pressed. If so, please add that to your question. Hint: nothing stops the while.

Are you also trying to see how long the button was pressed down for?

while (buttonState == HIGH) {
    count++;
    delay(100);
}

this will never exit when the button is ever high. You should also reset count after the if.
Instead you want to either do buttonState = digitalRead(switchPin); inside the loop or rejig the function to be a state machine using timestamps like blink without delay.

Try installing a 1-10k resistor to ground connected to the input pin switchPin, assuming that the pushbutton is connecting 5V to switchPin.  This will force a true logic 0 when the button is not pressed.


text:
How to convert char array to String in arduino?
I want to convert const char array in PROGMEM to String. How do I do this?
const char charArray[] PROGMEM = "Some text";

If you mean a C++ style string, I think you just need to do this - https://stackoverflow.com/questions/8960087/how-to-convert-a-char-array-to-a-string

No, I want to convert this in Arduino-IDE. That is not work correctly!

I just saw the answer and I had no idea that was even possible. I think that is your answer.

Unfortunately that is not work. Thank you, however.

what does this mean? that is not work  ....   that statement provides no useful information ....  describing the actual error would help

you can use a cast to __FlashStringHelper to invoke the right constructor of the String class. It is the constructor which copies the char array from PROGMEM. __FlashStringHelper is intended as return type for the F() macro.
const char charArray[] PROGMEM = "Some text";

void setup() {

  Serial.begin(115200);

  String s((const __FlashStringHelper*) charArray);

  Serial.println(s);
}

void loop() {
}

That is right, but how do this in loop or another functions?

PROGMEM is always global. and setup() is a function like every other so same way

Absolutely, but when I write this code in loop, the compiler will generate this error:
conflicting declaration 'String s'

Thanks so much. The compiler error was due to another part of my sketch.


text:
Relay Module for water pump
I want to switch on/off my water pump by using arduino nano, I have 2 channel relay module. Is this module safe for controlling pump?
Specifications pump:
power = 746 watt (1HP) single phase,
voltage = 220V
Specifications relay:
5VDC
10A 250 VAC,
15A 125 VAC
this model actually (  tongling jqc-3ff-s-z )

Also, what will happen if we draw large current on relay than it can bear?

746 W / 230 V = 3.25 A. why would it draw more than the relay can bear?

@Juraj some motors have a higher current during startup.

I know, but there is 200% reserve to 10 A. And the relay will not be destroyed  at 10 A. I am sure it has a tolerance for short spike over 10 A.

Well you'll need to know the true maximum current for the pump. It may say 1HP (746 watts), which you'd like to think came out to a simple 3.5 amps. But there are a few other factors to consider, such as motor efficiency and power factor to name a few. You can see where if the efficiency were only 50%, you'd need to consume 2X the power to get that 1HP. Also, if the power factor were 60%, it would mean the 746 watts become 1243 VA (volt-amps), which would put you above 5 amps, and that's before efficiency concerns. Then there is the initial surge... how much current is drawn for the short interval during startup.
So what you need to do is really examine the name plate data on that pump. I've actually just done something like this (controlling a water pump for a pool), and I looked at some of those relay modules too. I personally like to see relay contacts that are at least 3X the expected run-time current when controlling a motor. And in the end those modules just did not offer enough extra safety margin for me. But you can make your own analysis.
What I ended up using were some low cost OMRON LY4F-DC12 relays. They have 4 10 amp contacts, and I had a conversation with an OMRON engineer about using the contacts in parallel to create one 40 amp relay, and he confirmed it was a workable solution. Here's one at Mouser Electronics, shown  with a mounting socket. You can safely drive this relay forever with a cheap 2N2222 transistor and a 12V supply, provided you put a revers blocking diode across the relay coil. then, put about a 1K resistor between the 1000 the arduino pin and the transistor's BASE pin. You need the transistor (or a MOSFET) because the relay needs about 100mA to operate, and because the coil needs 12V. I know you didn't count one a separate supply, but you can only push the arduino's 5V supply so far. And 12V switching supplied, good to 300mA, are small and can be had for a couple of bucks. Those supplies can also be powered with anything from about 90VAC to about 250VAC, with no mods.
Here's a piece of a schematic from my own project. It's ugly, but you get the idea. The bottom line is that with my motor, which i expected draw a maximum of 12 amps (mine is 125VAC), I can sleep easy knowing this relay will probably outlast the motor!

what about using a 30 A relay http://wiki.seeedstudio.com/Grove-SPDT_Relay_30A/

well whatever person gave a -1 to my answer is certainly a true asshole, and just the kind of person new stackexchange rules are trying to weed out.

@Juraj -- Note the 2X higher current needed compared to the OMRON relay I suggested. Also, there are some advantages (one of which is cost) working with1 12V relays, and you'll need a power supply eiether way.

I have two of this 30 A relays in my project which moved from Uno to Wemos D1 and then to M0. The relays are powered from 5 V pin (on-board regulator of the board) with no problems even if both hold the coil. I gave you -1 for overcomplicated solution.

@Juraj -- I know the arduino spec says they are good for 500mA, but I've found my NANO boards run a bit too hot for my comfort level. Also, the arduino's spec says no more than 40mA per pin, so I'm not sure how you're powering a 180mA relay coil. But in any case, most of my answer was in response to the question about safely controlling a pump, with a 10 amp/contact relay. And now the question was put on hold, and someone deducted points from me, so If the answer is useful copy it, because I may just delete the whole thing..

the coil is hold by the 5 V from 5 V pin. the digital pin gives only the signal to the circuit on the relay module (3.3 V in case of 3.3 V boards). the regulator heats up if the input voltage is high.

@Juraj and what voltage is powering the arduino VIn pin?

for 5 V boards, ideal is not to use the regulator but supply nice 5 V like the USB. If regulator, then better close to lower limit of the regulator. I use 9 V supply, because I could not find a 7 V one, which would have the right size.  And none of the regulators on the boards I used heated up. Project runs 24/7.

Randy, try to not take a down-vote personally. I've got quite a few in my time, and I know it is enraging. :)  However Stack Exchange gives people the ability to vote up and down, and the occasional down-vote is part of the process. Serial down-voting (ie. when someone stalks you and down-votes every post) is different and will be dealt with in an appropriate manner.

@Juraj I misunderstood. I usually consider Arduino projects to eventually be "stand alone" with no USB power.  So I usually just supply external power to VIN, as you did. I used the 12V switching supply because I had a 12V relay to drive. But if you want a lower voltage, here's an interesting find. Its a small 5VAC transformer, no-load 7VAC, good to 500mA. The filtered DC would be 10V no load (minus diode drops, should be 9V). At full load, 7VDC (about 6 with the diode drops). Looks pretty ideal, and very CHEAP for a xfmr!
http://www.goldmine-elec-products.com/prodinfo.asp?number=G22643

12 V is upper limit for regulator on Nano. no wonder it was heatingup. I didn"t mean to use USB connection for power. but you can connect a "good" 5 V power source to 5 V pin of Uno, Nano, Mega and other 5V Arduinos. then the regulator is bypassed and no heat is generated by powering circuit

@Juraj
people get away with it, but the official stance on supplying power directly to the 5V pin on the Arduino Uno is thus:
"5V. This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it."
reference: https://store.arduino.cc/usa/arduino-uno-rev3

but it is the same as supplying 5 V over USB connector with an USB power adapter

I suspect the reason it is not recommended its that you lose the isolation offered by the schlocky diodes.


text:
Correct wiring?
I'm doing some Home automation and am currently trying to automate my intercom system. My overall aim is to be able to detect when someone has pressed the buzzer and then to be able to open the door if I so wish. Below is the diagram of what I intend to do:

For reference, the buzzer board above is the is the Tegui 1378/1. The documentation can be found (in Spanish) here. I have been able to conclude the following so far about the pins:
1E: Buzzer
2: Common (12V dc)
3: Door lock
4: Microphone
5: Speaker
However, I have been unable to find any GND on this board. As a result, my diagram above makes use of the GND supplied on the NodeMCU instead; is this okay?
Whilst digging around, I found box in my main fuse box called a Tegui E-30. I believe that this takes in mains and drops it down to 12V for the intercom system. It has two pin outs simply labelled "9" & "10". Now, I am fairly sure that one of these is positive and the other negative; in which case, this would explain where the ground has been but I am unsure. It would be handy to know if it is the case that they are positive and negative respectively as it would be more convenient powering the NodeMCU from the 12V (after dropping it to 5V) rather than getting a massive USB cable from the other room.
I would really appreciate any more information people could give me. Both in terms of whether the above diagram would work but also whether someone can have more luck than me finding out exactly what the "9" & "10" pins on the E-30 are.
Thank you in advance for any help!
Kind regards, Rocco

are you sure it is 12 V  DC? door bells traditionally use 12 V AC to buzzzz

from the manual "Características: 12 Vac. y 880 mA." see "ac"

Thanks for your response! I hadn't seen that before; I'd simply done a "Find All" for 12 and had seen a few 12 Vdc but no 12 Vac leading me to assume it was DC but I appear to be incorrect. I've just seen that on the E-30 box, it reads PRIM 230V ~ 50/60Hz 20VA SEC 12V ~ 1A, I assume the ~ refers to AC, am I correct?

yes ~ is for AC. I am sure you can find and buy 12 VAC to USB power (5 VDC) adapter to power the NodeMCU.

I would use a relay to activate the lock and a current sensor or optocoupler to detect current to buzzer. this eliminates the need of common ground

Thanks for the advice! So would something like this be okay to power the NodeMCU from 12Vac (VIN)? I haven't heard of a current sensor before but that sounds like a great solution, would you be able to recommend a cheap one which would work for this use (I live in the UK)? Also, to confirm, are the "9" & "10" pins on the E-30 positive and negative or both positive? Thanks once again for all your help so far!

@Juraj For the current sensor, am I correct in saying that it would need to simply give out a Digital output but that the output would have to be 3.3v as the NodeMCU does not accept 5v logic? Also, the current sensors I have seen online have no reference to voltage (that they are detecting) and just refer to AMPS. Why is this and what would I need for this application? Thanks

current sensor would be analog input. NodeMcu has voltage divider on esp8266 1 V A0 to read to 3.3 V. the optocoupler is simpler. warning, I am not an electronics expert. with AC there is no positive or negative. only 'common' to close the circuit.

the power supply in the link is for DC input

Your diagram doesn’t work. You need a GND connection. Looking at the Dutch manual I think 1E isn’t really the buzzer, but the line selector. Each phone unit has a spectate line for 1E but all phones share lines 2-5. My guess is that 1E becomes GND when the number for you phone is pressed at the door. Which explains why you can’t buzz someone in without them ringing the bell first. So I think the relay needs to be between 1E and 3. But I think you just need to get a multimeter and measure the voltages between screw terminals a different states (beep; phone of hook; buzz door; idle).

found this .... http://www.intercomsrus.com/handset%20pdf/Tegui%20T-71E%20%20Audio%20handset%20Data%20Sheet.pdf


text:
Flashing an ATtiny85 with a NodeMCU?
I recently purchased a Digispark for some of my smaller electronics projects. After it initially being a great little board, I soon found myself unable to flash the board in the same way I had done before i.e. according to the method described here. I am still unsure as to why the previous flashing method stopped working but have been unable to overcome the issue, nor have I found many other accounts of similar problems online.
After a period of frustration, unable to even find a way to reset the board, it dawned upon me that I may be able to use an Arduino to flash the board as seen here. However, the issue is that all the tutorials I could find online assumed that an Arduino Uno could be easily accessed, which is not the case for me. Despite this, I do have a few NodeMCUs hanging around and would love it if I could use them to flash the Digispark.
My question is: how exactly would I flash the Digispark using a NodeMCU (if it is even possible)?
P.S. Whilst I am aware that the Digispark board has a number of other components aside from the ATtiny85 chip, the pinouts (not the USB) of the board allow for direct interfacing with the chip.
Thank you in advance for any help,
Kind regards,
Rocco

Possible duplicate of using esp8266 feather to burn bootloader on redboard

@Juraj I agree that my question is similar to the one linked. However, I would still like someone to confirm that this is the case for my specific situation. I.e. for an ATtiny85 chip as opposed to an 'Arduino redbird'. If so, is this due to the nature of the NodeMCUs or is it a specific issue with the two components in question?

IIRC the NodeMCU is a 3.3V device and the ATtiny is 5V so that could cause problems.

It can be done. Your Digispark has SPI pins, which are ISP pins. For the esp8266 there is an ESP8266AVRISP library for OTA upload to AVR. You can use the example of the library.
You must wire the SPI pins and ground together. Wire reset pin of Digispark to io 5 (D1) of NodeMcu. You should use level conversion, but esp8266 tolerates 5 V TTL (not recommended for long term). Do not wire the SS pin.

Thank you for your reply. I still have a few questions; what is the 'Bluno' you are referring to? Would you be able to give a more step-by-step set of instructions of how to do this as I am unclear as to what exactly you mean. If possible, please could you include a wiring diagram for the digispark and NodeMCU? Thanks once again

@Rocco, sorry Bluno is a very similar small board. I fix it in the answer

Thanks for your answer, I'll give that a go when I next get the opportunity. Just two quastions: would I only need to use level conversion between the Digispark Reset and D5 or would I need it between all connections or what? Also, I can't find clear instructions for how to download avrdude tool online, is there a simple git clone or something?

Also, you mean wire the SPI pins of the NodeMCU and digispark together and then the ground of each board together as opposed to wiring the SPI pins to ground? I would also assume the digispark shouldn't need to be plugged in? Finally, would you be able to include a diagram showing exactly which wires are meant to go where for clarity if possible as I am not familiar with SPI? Thank you once again

reset and MISO are candidates for level conversion. the instructions are on the link to library in the answer

Still a few things I'm not quite sure about: As for the level shifting, is that FROM 3v to 5V or the other way round? I.E. does the digispark need external powering? It would be really great if you could include a full wiring diagram in your answer as it would answer all my remaining questions. Best

level conversion should protect the esp8266 from 5 V. I connected many times 5 V logic to esp8266. It is not like there is some real current. It is only pullup for logic level. You can power the Digispark from 5 V pin of NodeMcu. https://raw.githubusercontent.com/wiki/jandrassy/arduino-firmware-wifilink/images/wemos-nano-spi.jpg

the truth is, you should use level conversion for the 3.3 lines too, because AVR datasheet has that 5 V AVR needs at least 3.7 V as HIGH. but somehow 3.3 V is in tolerance. and the breadboard wiring of SPI with level conversion is spaghetti https://raw.githubusercontent.com/wiki/jandrassy/arduino-firmware-wifilink/images/wemos-nano-ls-spi.jpg

Ah I see, thank you for your reply and your detailed photos. To clarify, in your photo, thr D1 Mini represents the digispark or the other way round? Thanks once again for all your help!

D1 is esp8266 and Nano is AVR. on photos is SPI wiring not only for ISP, but for a networking firmware where AVR is master and esp8266 is slave. but the Nano can be flashed over esp8266. additionally to ISP  wiring there is CS pin, both resets and one more signal connection for the firmware


text:
Securing ESP8266 connections
In my setup, I've got a number of ESP8266 devices around my home controlling various devices like my boiler and some lights.
They're all controlled by a central smart hub on a Raspberry Pi with a static's IP address.
This works great, but I'm increasingly concerned of the security implications of this. Communication between the Pi and the various ESP8266s is currently done over HTTP, with all the commands simply in the URL the Pi requests from the web servers.
As such, anyone on my network could theoretically control these smart devices using a simple curl request.
Whilst I have a strong Wi-Fi password, and am using WPA2 encryption, I would feel much more comfortable if communication with the ESP8266s was controlled in some way. E.g. in the same sort of way you can only connect to an SSH server using public key encryption if you have the right private key.
Is something like this possible to implement on an ESP8266? I've done some searching and only found articles about HTTPS which doesn't seem like it would solve my problem.
Thanks in advance,
Rocco

You could have a shared password. Then have the sender hash that password concatenated with the time and data, and perhaps some random nonce. Send the time, nonce, data and hash to the ESP. The ESP can then do the same at it's end and validate that the hashes are the same. The ESP can validate the sender has the same password, and that the message hasn't been altered. Data however is still send in the clear, but in this case, I don't think it matters. The time is there to prevent replay attacks. Either have the ESP know the time through NTP, or have it store the timestamp of the last message.

@Gerben Thanks, that's a great idea! I feel your solution may be more relevant as it takes far less compute time on the ESP. I'm not quite sure how properly solve the problem of the ESP getting the time. Getting from the NTP would be off by a few milliseconds or seconds, and I'm not quite sure what you mean about the time stamping.

you don't need accurate time. The time is just there to prevent replay attacks. You store the last time stamp of the last message, and then only accept messages with newer timestamps. To prevent replay attacks after the ESP is reset, you could use NTP and make sure the message isn't older than a few seconds or so. PS just to reiterate; the sender sends the timestamp, along with the data, to the ESP.

The simplest method is to encrypt your communication channel using some secret key.  You could use the built-in AES encryption functionality, which would mean that only people that know the key could encrypt a request in such a way that the device at the other end could decrypt it.
You would think that SSL (HTTPS) would do the job, but that only provides interception security, not authentication. Of course for even more security you can combine both HTTPS and AES encryption.  One for overall encryption, and the other for encryption-based authentication.

Thanks for your answer. So you suggest encrypting the instruction on the hub, sending it to the ESP8266, then decrypting it with some key and executing it on the ESP8266? Wouldn't it also be wise to implement HTTPS in this case to prevent replay attacks?

Sure, you can also use HTTPS. More is always better :)


text:
Using WifiUdp.h on Arduino Mega and ESP8266?
I was trying to run this library on Arduino Mega, using ESP8266 as replacement of Wifi Shield, as suggested on my older thread.
The problem is, I got error in compiling, after with this code :
#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <WiFiEspUdp.h>

#include "AppleMidi.h"
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, appleMIDI1);
....

exit status 1
'WiFiUDP' was not declared in this scope

if I modified the code into this :
#include <WiFiEsp.h>
#include <WiFiUdp.h>

#include "AppleMidi.h"
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, appleMIDI1);
....

I got this error instead

C:\Program Files
  (x86)\Arduino\libraries\WiFi\src\utility\server_drv.cpp:313:40: error:
  'WARN' was not declared in this scope
WARN("error waitResponse isDataSent");

                                    ^

exit status 1

Full code here at pastebin.
I was pretty much stuck now. Please help! :(
Thanks :D

WiFiUdp.h is part of the WiFi library for the Arduino WiFi Shield. you can't use it

the WiFiEsp class for UDP is WiFiEspUDP
#include <WiFiEsp.h>
#include <WiFiEspUdp.h>
#include "AppleMidi.h"

APPLEMIDI_CREATE_INSTANCE(WiFiEspUDP, AppleMIDI);

So I would just need to change WiFiUDP to WiFiEspUDP and I'm good to go?

yes, the macro creates an object with template type AppleMidi_Class<WiFiEspUDP> AppleMIDI;

gonna test this tonight. if this works, gonna accept it as answer. thanks for helping me once again :D

I used #include "WiFiEsp.h" and #include "WiFiEspUdp.h" instead and it compiled. thanks!


text:
Sending data over two independently powered arduinos
I have multiple arduinos that are each powered by a 12v battery through a 5v regulator.  All arduinos share a common ground.  Can I simply connect the digital output from one arduino into the digital input of another?  I'm worried the (small) voltage differences between each regulator could cause a problem.

Can you tell more? Add the extra information to your question. How many is multiple? 3 or 3000? Please explain the distances and what else is going on. Do you use SoftwareSerial for the communication? Are there powerful motor or other things nearby? Is the digital signal in a wire next to other wires with current peaks? You could add a protection resistor of 1k at the input, but you can also try wireless or with a optocoupler.

Small differences in power supply will have no effect. Very long distances could have an effect though. How far apart are the Arduinos?

According to the datasheet, the input voltage on an input pin should be between -0.5V to VCC+0.5V. You you have 0.5V of margin. For added safety you could add a 1-10k resistor in between the two.

It's ok if the distance between the two devices are not too big. (couple meters)
Since the valid logic level (voltage) ranges are pretty wide a small difference won't affect the operation of the devices. Arduino uses TTL (5V) logic so let's see the level diagrams:

If you see the output level ranges (on the right) are more strict than on the input side (on left) so the logic value remains valid even if a small voltage drop or noise occurs on the wire.
Make sure you won't connect two outputs directly since it can damage the microcontrollers. Connecting two inputs are totally safe.
EDIT: If you want to cover longer distances you need to use a balanced line  e.g. differential I/O-s, RS-485 or CAN. These are not default Arduino features so you'll need additional electronic to use them.

Well "totally ok" is a stretch. Not all 0V is equal and if the common 0V is noisy, long or current carrying you could have false level shifts. An RS485 link would be better with its high CM range. This probably will work but universally ? No


text:
How can i split an incoming data in arduino?
So  for my arduino project I need to split this line of servos data
180 0 0 0 90 90 0

Which would be parsed as:
servo position1 servo positin2 servo positin3 ...servo position 6

in to separate servo values, but i am new at arduino and c typе languges so a little bit help will be very good. So my question is how can I split these values up?

You can use parseInt() function as well. It looks for next valid integer after one delimiter.
https://www.arduino.cc/en/Tutorial/ReadASCIIString

Scanning string formatted data can be done with sscanf (docs). It takes format strings just like printf() does, but instead of printing formatted data, it parses formatted data into the given variables.
For example,
String input = "180 0 0 0 90 90 0";
//parse input (6 integers)
int servoPositions[6];
int numScanned = sscanf (input.c_str(),"%d %d %d %d %d %d",
    &servoPositions[0], &servoPositions[1],&servoPositions[2],
    &servoPositions[3], &servoPositions[4],&servoPositions[5]);

//print positions again
Serial.println("Parsed servo positions:");

for(int i=0; i < 6; i++) {
    Serial.print("position ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(servoPositions[i]);
}

Outputs
Parsed servo positions:
position 0: 180
position 1: 0
position 2: 0
position 3: 0
position 4: 90
position 5: 90


text:
How to detect when intercom is ringing?
For my apartment, I need to check when intercom is ringing and call an API in that case. I was thinking about using an AC input / DC output relay, since the buzzer signal is an AC signal. Is there an equivalent pre-built component similar to this?

As it sounds like you do not own the buzzer (it is part of the appartment), someone may not like you directly connecting to it.
If this is a classic buzzer with an electromagnet, consider using a Hall Effect Sensor.  The magnetic field generated by the buzzer may be able to activate the Hall Effect Sensor and inform the Arduino the buzzer has been activated.  This article talks about Hall Effect sensors and an Arduino.
Image of Arduino and Hall Effect Sensor from linked to article:

Further, this is a much safer way connect to a buzzer.  As a classic buzzer can generate very high voltages that can damage processors and other sensitive electronic devices when directly connected.

Can you please share a wiring diagram?

There is a diagram from the article linked to in the answer.  I'll add the same image to the answer.

Most Arduino solutions / answers will use an Arduino Uno.  An ESP8266 is a very complex chip and through the efforts of a few has been added to the list of chips which can be supported using the Arduino Integrated Development Environment (IDE).  The problem with the specific board you have chosen, the eps01 board, is that it brings out very few of the ESP8266's pins to the user.  Further, the ESP8266 is very different from the usual ATmega328P processor used on most Arduino boards. Making it even more difficult to look for examples of exact solutions to your situation.

Your solution is nice but requires the circuit to be close to the buzzer. What about using a rectifier and a 12V relay to close the arduino 3.3V / input loop?

The question hinted at using an EP01 device which contains a WiFi radio.  If so, this small "IoT" device could be, as long as power was available, right next to the buzzer.  As it could communicate the state of the buzzer to any other WiFi device wirelessly.  You could use a relay.  But are you sure of the type of signal used by the installed buzzer?  You assumed AC (recommending a rectifier) but it could be DC.  And it may not be 12 volts.


text:
How to avoid electromagnetic interference on ESP32 input
I've realized a simple circuit like the following, in order to implement a rain gauge that I can access via HTTP:

With the following sketch:
#include <WebServer.h>
#include <WiFi.h>
#include <WiFiClient.h>

/**
 * This constant is calculated with the following procedure:
 * - Area of pluviometer is 55 cm^2
 * - Volume of test water is 100 cm^2
 * Resulting height of water is 1.82 cm. Using this water quantity, generates 40 ticks of the pluviometer. So every tick is 0.455 mm of rain.
 */
const double millimetersPerTick = 0.455;
const char* ssid = "*********";
const char* password = "*********";

WebServer server(80);

/* LED pin */
byte ledPin = 2;
/* pin that is attached to interrupt */
byte interruptPin = 14;
/* hold the state of LED when toggling */
volatile byte state = LOW;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;

void IRAM_ATTR handleInterrupt() {
  portENTER_CRITICAL_ISR(&mux);
  interruptCounter++;
  portEXIT_CRITICAL_ISR(&mux);
}

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

  // WIFI initialization
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  pinMode(ledPin, OUTPUT);
  /* set the interrupt pin as input pullup*/
  pinMode(interruptPin, INPUT_PULLUP);
  /* attach interrupt to the pin
  function blink will be invoked when interrupt occurs
  interrupt occurs whenever the pin change value */

   // Notify wifi connection
  digitalWrite(ledPin, HIGH);
  delay(2000);
  digitalWrite(ledPin, LOW);

  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, RISING);

  server.on("/", []() {
    server.send(200, "text/plain", String(millimetersPerTick * numberOfInterrupts));
    numberOfInterrupts = 0;
  });

  server.onNotFound([]() {
    server.send(404, "text/plain", "Not found");
  });

  server.begin();
}

void loop() {
  server.handleClient();

  if(interruptCounter>0) {
    portENTER_CRITICAL(&mux);
    interruptCounter--;
    portEXIT_CRITICAL(&mux);

    numberOfInterrupts++;
    Serial.print("An interrupt has occurred. Total: ");
    Serial.println(numberOfInterrupts);
    state = !state;
    digitalWrite(ledPin, state);
    delay(100);
    state = !state;
    digitalWrite(ledPin, state);
  }
}

The main issue of this circuit is that if I connect the AC plug it suffers from interferences from the household electricity. For example if I turn on the light, the interrupt is called. I tried also to buy an EMI filter like this but it doesn't reduce the problem. What can I do to avoid this?

I think it is moment you should try another interrupt pin(s).

I have to check better, but it seems that other have this issue with reed switches that in some configuration act like antennas and receive interferences (see here and here).

i would try two cheap/simple fixes: 1. a ferrite bead or two on the ac input and the dc output. 2. a smoothing capacitor across the vout of your hilink (100-2200u).

I tried with a battery pack and it happens. I suspect the problem is the long wire for reed switch that is working like an antenna.

@dandavis I have similar issue but I'm using DC-DC converter to power up ESP32. Could you please suggest where I can connect smoothing capacitors?

I researched the power supply shown in your photo and found this comment:

esp8266 hilink


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:
How to pass non-static class member to callback?
I am using the arduinoWebSockets library in my own Arduino library. I'm having trouble with trying to assign a class member as the websocket library onEvent callback function.
MyClass.cpp:
#include <WebSocketsClient.h>
#include "Arduino.h"
#include "MyClass.h"

void MyClass::connect(String host, int port) {
  webSocket.begin(host, port, "/");
  webSocket.setReconnectInterval(5000);

  // tried all these variations
  // webSocket.onEvent(incomingEventHandler);
  // webSocket.onEvent(MyClass::incomingEventHandler);
  webSocket.onEvent(this->incomingEventHandler);
}

void MyClass::loop() {
  webSocket.loop();
}

void MyClass::incomingEventHandler(WStype_t type, uint8_t *payload, size_t length) {
  // do stuff with incoming data
  // need to access other member functions and class variables
}

MyClass.h:
#ifndef MyClass_h
#define MyClass_h

#include <WebSocketsClient.h>
#include "Arduino.h"

class MyClass {
  public:
    void connect(String host, int port);
    void loop();
    void incomingEventHandler(WStype_t type, uint8_t *payload, size_t length);
  private:
    WebSocketsClient webSocket;
};

#endif

The error returned is:

sketch/MyClass.cpp: In member function 'void MyClass::connect(String,
  int)': MyClass.cpp:14:47: error: no matching function for call to
  'WebSocketsClient::onEvent()'
  webSocket.onEvent(this->incomingEventHandler);

From what I understand it seems like I need to create a pointer to the class member, I have tried a few different ways, this one seemed the most promising, but still failed:
typedef void (MyClass::*MyClassMemFn)(WStype_t type, uint8_t *payload, size_t length);

void MyClass::connect(String host, int port) {
  webSocket.begin(host, port, "/");
  webSocket.setReconnectInterval(5000);

  MyClassMemFn onEventCallback = &MyClass::incomingEventHandler;
  webSocket.onEvent(MyClassMemFn onEventCallback);
}

The above returns this error:

sketch/MyClass.cpp: In member function 'void MyClass::connect(String,
  int)': MyClass.cpp:15:34: error: expected primary-expression before
  'onEventCallback'    webSocket.onEvent(MyClassMemFn onEventCallback);

I have also tried to use std::bind:
void MyClass::connect(String host, int port) {
  webSocket.begin(host, port, "/");
  webSocket.setReconnectInterval(5000);

  webSocket.onEvent(std::bind(&MyClass::incomingEventHandler, this));
}

Error:

sketch/MyClass.cpp: In member function 'void MyClass::connect(String,
  int)': MyClass.cpp:12:47: error: no matching function for call to
  'WebSocketsClient::onEvent()'
  webSocket.onEvent(this->incomingEventHandler);

If I move the incomingEventHandler function outside the class definition, it works as expected, however then I can't call other class members or access class properties in the same scope.
In arduino c++ how can I pass non-static class member properties as a callback? Is there a better way to approach this?

@asked This is actually a question about how C++ works. The magic is in the handling of this. Member functions have a "hidden" parameter. This is necessary to allow access to the member data and virtual function table. The short answer to your question is therefore - a callback cannot be a member function.

Yes, a callback can be a member function. The error in your std::bind call is that while you do bind the first hidden this paramater to an object instance, in this case this object, you must also use placeholders for all your other function parameters.
Since you declared
void incomingEventHandler(WStype_t type, uint8_t *payload, size_t length)

You must bind as
webSocket.onEvent(std::bind(&MyClass::incomingEventHandler, this,  std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

Note that this webSocket.onEvent call only works if you are on a non-AVR platform, because the library defines
void WebSocketsClient::onEvent(WebSocketClientEvent cbEvent) {
    _cbEvent = cbEvent;
}

with
#ifdef __AVR__
        typedef void (*WebSocketClientEvent)(WStype_t type, uint8_t * payload, size_t length);
#else
        typedef std::function<void (WStype_t type, uint8_t * payload, size_t length)> WebSocketClientEvent;
#endif

i.e., it is a raw function pointer in __AVR__ but a std::function on non-AVR platforms -- std::bind will give you a std::function. Since you're on an ESP8266, this should work fine.
Refer to https://en.cppreference.com/w/cpp/utility/functional/bind (and maybe my old question)