text:
using esp8266 to fetch specific data from firebase
I want to fetch specific data from firebase using Node Mcu ESP 8266. I can fetch the num value, but I failed to fetch the id value. The serial monitor kept displaying 0 when I try to fetch the id value. Any method to fetch the newest insert id value( Id value automatically update every time I submit the form at my web application). Thank you.
below is my coding
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

// Set these to run example.
#define FIREBASE_HOST "inserted"
#define FIREBASE_AUTH "inserted"
#define WIFI_SSID "Pro_4258"
#define WIFI_PASSWORD "1234567890"

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

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
int a;

void loop() {

  a=Firebase.getInt("id");

  if (Firebase.failed())
  {
    Serial.println(Firebase.error());
    }else
    {
      Serial.println(a);
      }
delay(500);
}


text:
ESP8266 Deep Sleep Wake Up
I am testing esp8266's deep sleep mode. And i have some questions about that.
1- I want to wakeup esp via timer. I did it. I implemented GPIO16-RST connection and this version done.
2- I want to ake up esp with external button too. It means, I will use timer and button to wake up esp8266 same time.
Is it possible and how can i connect  button to RST pin that while GPIO16 has already connected to RST?

The reset pin of the ESP8266 has internal pull-up. Connecting the pin to ground activates the reset of the ESP.
To create a reset button, wire a momentary push button between reset pin and ground. Pushing the button will connect reset to ground, causing a reset of the esp8266.
The io 16 pin is connected internally to RTC, which in deep sleep counts down the time and then sets the pin LOW. If io 16 is wired to reset pin, this resets the ESP8266 to end the deep sleep.
The only way to end the deep sleep of the esp8266 is a reset. There is no conflict between RTC io 16 and a reset button, both wired to reset pin. Both can activate the reset to end the deep sleep.

source: Stack Exchange

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

sort: votes


text:
Arduino DDS IOT ESP8266 controlling AD9834
first post, having probs with uploading sketches on win10, blink sketch loads but when I try either of 2 sketches which have been specifically coded for this duino I get the following error: redefinition of 'const byte dds_data'
I have it on good faith that it works on other operating systems. I would also appreciate any advice about how to make a similar one using shields joined together, afaics I just need to join 2 boards readily available on ebay with the 8366 controlling the DDS Ad9834, many thanks in advance, for some reason the com port is grayed out in tools menu, https://sites.google.com/site/addsontheinternetofthings/home code below...
Arduino: 1.8.5 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, nodemcu, 26 MHz, 40MHz, QIO, 512K (no SPIFFS), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

...some code removed so it will fit on this post...

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFi.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiAP.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiGeneric.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiMulti.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\ESP8266WiFiScan.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiClient.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiClientSecureAxTLS.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiServer.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiServerSecureAxTLS.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiServerSecureBearSSL.cpp" -o "nul"
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src\WiFiUdp.cpp" -o "nul"
Generating function prototypes...
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\sketch\ESP_WiFi_VFO.ino.cpp" -o "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/lwip2/include" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\Ewan\AppData\Local\Temp\arduino_build_458317/core" -c -w  -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_GENERIC" -DLED_BUILTIN=2  -DESP8266 "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\variants\generic" "-IC:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi\src" "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\sketch\ESP_WiFi_VFO.ino.cpp" -o "C:\Users\Ewan\AppData\Local\Temp\arduino_build_458317\sketch\ESP_WiFi_VFO.ino.cpp.o"
AD9834_Test:20: error: redefinition of 'const byte DDS_data'

 const byte DDS_data = 13;

            ^

ESP_WiFi_VFO:25: error: 'const byte DDS_data' previously defined here

 const byte DDS_data=13;

            ^

AD9834_Test:21: error: redefinition of 'const byte DDS_clck'

 const byte DDS_clck = 14;

            ^

ESP_WiFi_VFO:26: error: 'const byte DDS_clck' previously defined here

 const byte DDS_clck=14;

            ^

AD9834_Test:22: error: redefinition of 'const byte DDS_fsync'

 const byte DDS_fsync = 16;

            ^

ESP_WiFi_VFO:27: error: 'const byte DDS_fsync' previously defined here

 const byte DDS_fsync=16;

            ^

AD9834_Test:26: error: redefinition of 'long unsigned int m'

 unsigned long m;

               ^

ESP_WiFi_VFO:30: error: 'long unsigned int m' previously declared here

 unsigned long m;

               ^

AD9834_Test:27: error: redefinition of 'unsigned int m1a'

 unsigned int m1a, m2, m3;

              ^

ESP_WiFi_VFO:31: error: 'unsigned int m1a' previously declared here

 unsigned int m1a,m2,m3;

              ^

AD9834_Test:27: error: redefinition of 'unsigned int m2'

 unsigned int m1a, m2, m3;

                   ^

ESP_WiFi_VFO:31: error: 'unsigned int m2' previously declared here

 unsigned int m1a,m2,m3;

                  ^

AD9834_Test:27: error: redefinition of 'unsigned int m3'

 unsigned int m1a, m2, m3;

                       ^

ESP_WiFi_VFO:31: error: 'unsigned int m3' previously declared here

 unsigned int m1a,m2,m3;

                     ^

AD9834_Test:29: error: redefinition of 'const long unsigned int M_Clk'

 const unsigned long M_Clk = 60000000L;

                     ^

ESP_WiFi_VFO:33: error: 'const long unsigned int M_Clk' previously defined here

 const unsigned long M_Clk = 60000000L;

                     ^

AD9834_Test:30: error: redefinition of 'const long unsigned int TwoE28'

 const unsigned long TwoE28 = 268435456L;

                     ^

ESP_WiFi_VFO:34: error: 'const long unsigned int TwoE28' previously defined here

 const unsigned long TwoE28 = 268435456L;

                     ^

C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void setup()':

AD9834_Test:36: error: redefinition of 'void setup()'

 void setup() {

      ^

ESP_WiFi_VFO:50: error: 'void setup()' previously defined here

 void setup()

      ^

C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void loop()':

AD9834_Test:42: error: redefinition of 'void loop()'

 void loop() {

      ^

ESP_WiFi_VFO:60: error: 'void loop()' previously defined here

 void loop()

      ^

C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void sendFrequency(double)':

AD9834_Test:49: error: redefinition of 'void sendFrequency(double)'

 void sendFrequency(double frequency) {

      ^

ESP_WiFi_VFO:224: error: 'void sendFrequency(double)' previously defined here

 void sendFrequency(double frequency) {

      ^

C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void setFreq(double)':

AD9834_Test:55: error: redefinition of 'void setFreq(double)'

 void setFreq(double(f)) {

      ^

ESP_WiFi_VFO:231: error: 'void setFreq(double)' previously defined here

 void setFreq(double(f)){

      ^

C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void setFreqFloat(float)':

AD9834_Test:66: error: redefinition of 'void setFreqFloat(float)'

 void setFreqFloat(float f) {

      ^

ESP_WiFi_VFO:242: error: 'void setFreqFloat(float)' previously defined here

 void setFreqFloat(float f){

      ^

C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino: In function 'void writeFreq()':

AD9834_Test:77: error: redefinition of 'void writeFreq()'

 void writeFreq() {

      ^

ESP_WiFi_VFO:253: error: 'void writeFreq()' previously defined here

 void writeFreq(){

      ^

Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Ewan\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi
exit status 1
redefinition of 'const byte DDS_data'

You have two sketches in the project folder ESP_WiFi_VFO.  First is ESP_WiFi_VFO.ino and second is AD9834_Test.ino. Booth sketches have defined same functions, constants and variables so the final program can't be build.
Delete AD9834_Test.ino from the sketch folder ESP_WiFi_VFO (Delete C:\Users\Ewan\Downloads\ESP_WiFi_VFO\AD9834_Test.ino)

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


text:
Push button control of multiple relays
I'm new to arduinos and have not been able to find/create a working bit of code for my project. I'd like to control several different relays (standard 5v optical relays) with push buttons. I want one pushbutton1 to turn on/off relay1, pushbutton2 to turn on/off relay 2, etc.
I ran into troubles using delay statements as debouncers because I guess it locked out the remainder of the code while it ran? I then tried to use a flagging approach covered here:
https://github.com/VRomanov89/EEEnthusiast/blob/master/03.%20Arduino%20Tutorials/01.%20Advanced%20Button%20Control/ButtonSketch/ButtonSketch.ino
const int numOfInputs = 2;
const int inputPins[numOfInputs] = {2,3};
const int outputPin = 10;

int LEDState = 0;
int inputState[numOfInputs];
int lastInputState[numOfInputs] = {LOW,LOW};
bool inputFlags[numOfInputs] = {LOW,LOW};
int inputCounters[numOfInputs];

long lastDebounceTime[numOfInputs] = {0,0};
long debounceDelay = 50;

void setup() {
  for(int i = 0; i < numOfInputs; i++) {
    pinMode(inputPins[i], INPUT);
    digitalWrite(inputPins[i], HIGH); // pull-up 20k
  }
  Serial.begin(9600);
  pinMode(outputPin, OUTPUT);
}

void loop() {
  setInputFlags();
  resolveInputFlags();
  resolveOutputs();
}

void setInputFlags() {
  for(int i = 0; i < numOfInputs; i++) {
    int reading = digitalRead(inputPins[i]);
    if (reading != lastInputState[i]) {
      lastDebounceTime[i] = millis();
    }
    if ((millis() - lastDebounceTime[i]) > debounceDelay) {
      if (reading != inputState[i]) {
        inputState[i] = reading;
        if (inputState[i] == HIGH) {
          inputFlags[i] = HIGH;
        }
      }
    }
    lastInputState[i] = reading;
  }
}

void resolveInputFlags() {
  for(int i = 0; i < numOfInputs; i++) {
    if(inputFlags[i] == HIGH) {
      // Input Toggle Logic
      inputCounters[i]++;
      updateLEDState(i);
      printString(i);
      inputFlags[i] = LOW;
    }
  }
}

void printString(int output) {
      Serial.print("Input ");
      Serial.print(output);
      Serial.print(" was pressed ");
      Serial.print(inputCounters[output]);
      Serial.println(" times.");
}

void updateLEDState(int input) {
  // input 0 = State 0 and 1
  if(input == 0) {
    if(LEDState == 0) {
      LEDState = 1;
    }else{
      LEDState = 0;
    }
  // input 1 = State 2 to 6
  }else if(input == 1) { // 2,3,4,5,6,2,3,4,5,6,2,
    if(LEDState == 0 || LEDState == 1 || LEDState > 5) {
      LEDState = 2;
    }else{
      LEDState++;
    }
  }
}

void resolveOutputs() {
  switch (LEDState) {
    case 0:
      digitalWrite(outputPin, LOW);
      break;
    case 1:
      digitalWrite(outputPin, HIGH);
      break;
    case 2:
      analogWrite(outputPin, 30);
      break;
    case 3:
      analogWrite(outputPin, 70);
      break;
    case 4:
      analogWrite(outputPin, 100);
      break;
    case 5:
      analogWrite(outputPin, 155);
      break;
    case 6:
      analogWrite(outputPin, 255);
      break;
    default:
    break;
  }
}

But was unable to alter the code to get it to work... could someone help me write a bit of code which will allow me to do what I want it to do? I'd rather not buy a matrix-style shield to accomplish this, but I will if I have to.
What I want to do:

Turn on relay1 by pressing momentary pushbutton1
Turn off relay1 by pressing momentary pushbutton1
Turn on relay2 by pressing momentary pushbutton2
Turn off relay2 by pressing momentary pushbutton2
etc.
etc.

Thank you in advance!

To use this sketch, you will need the Bounce2 Library, and two N.O. switches connected between GND and the Arduino Digital Pins specified. I'm not sure if there is a limit to the number of Bounce2 objects you can create. Have a look at the Bounce2.h and Bounce2.cpp files.
#include <Bounce2.h>
byte buttonOneState = 0;
byte buttonTwoState = 0;
const byte buttonPin1 = 4;
const byte buttonPin2 = 5;
const byte debouncerInterval = 50;

// Instantiate ONE OR MORE Bounce2 object(s).
Bounce debouncer = Bounce();
Bounce debouncer2 = Bounce();

void setup(){
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  debouncer.attach(buttonPin1);
  debouncer.interval(debouncerInterval);
  debouncer2.attach(buttonPin2);
  debouncer2.interval(debouncerInterval);
}

void loop(){

  // Button 1
  if(debouncer.update()){
    if(debouncer.read() == 0){
      if(buttonOneState == 0){
        Serial.println("Turn Relay 1 ON");
        buttonOneState = 1;
      }
      else{
        Serial.println("Turn Relay 1 OFF");
        buttonOneState = 0;
      }
    }
  }

  // Button 2
  if(debouncer2.update()){
    if(debouncer2.read() == 0){
      if(buttonTwoState == 0){
        Serial.println("Turn Relay 2 ON");
        buttonTwoState = 1;
      }
      else{
        Serial.println("Turn Relay 2 OFF");
        buttonTwoState = 0;
      }
    }
  }

}

Forgive my ignorance: which line does it specify the output pin for me to connect to the relay? Thank you so much for your help - this is much more concise than my attempts!

The sketch doesn't specify the relay pin numbers. I left that up to you to decide which ones to use. You can control the ON/OFF commands for the relays where the "Serial.println..." statements are located in the sketch. Keep in mind that some optical relay modules require a LOW signal to turn them ON, and a HIGH signal to turn them OFF. It's important to ensure you are getting the desired output first, and the print statements are an easy way to do this.

Okay beautiful, thank you very much! Good point on the relays; I'll have to check the datasheets. I'll post what I have once I have it working.

You can use this Button library from JChristensen (in GitHub)
You only need to read the brieve (altough usefull) documentation and you can control, no only the state of many buttons, you also can read the time that the buttons are pressed.
Hope you can solve your little problem :D
TIP: Try with 50ms of delay when you instantiate the button object

Here is the final solution I've implemented:
/*  Thanks to VE7JRO for giving me this solution to my problem.
 *  Thread found at https://arduino.stackexchange.com/questions/55540/push- button-control-of-multiple-relays
 */

#include <Bounce2.h>
byte buttonOneState = 0;
byte buttonTwoState = 0;
byte buttonThreeState = 0;
byte buttonFourState = 0;
const byte buttonPin1 = 2;
const byte buttonPin2 = 3;
const byte buttonPin3 = 4;
const byte buttonPin4 = 5;
const byte relayPin1 = 9; //Relay pin 1
const byte relayPin2 = 10; //Relay pin 2
const byte relayPin3 = 11; //Relay pin 3
const byte relayPin4 = 12; //Relay pin 4
const byte debouncerInterval = 50;

// Instantiate ONE OR MORE Bounce2 object(s).
Bounce debouncer = Bounce();
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce();
Bounce debouncer4 = Bounce();

void setup(){
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  pinMode(buttonPin4, INPUT_PULLUP);
  debouncer.attach(buttonPin1);
  debouncer.interval(debouncerInterval);
  debouncer2.attach(buttonPin2);
  debouncer2.interval(debouncerInterval);
  debouncer3.attach(buttonPin3);
  debouncer3.interval(debouncerInterval);
  debouncer4.attach(buttonPin4);
  debouncer4.interval(debouncerInterval);
  pinMode(relayPin1, OUTPUT); //Define pin as output
  pinMode(relayPin2, OUTPUT); //Define pin as output
  pinMode(relayPin3, OUTPUT); //Define pin as output
  pinMode(relayPin4, OUTPUT); //Define pin as output
}

void loop(){

  // Button 1
  if(debouncer.update()){
    if(debouncer.read() == 0){
      if(buttonOneState == 0){
        Serial.println("Turn Relay 1 ON");
        digitalWrite(relayPin1, HIGH);
        buttonOneState = 1;
      }
      else{
        Serial.println("Turn Relay 1 OFF");
        digitalWrite(relayPin1, LOW);
        buttonOneState = 0;
      }
    }
  }

  // Button 2
  if(debouncer2.update()){
    if(debouncer2.read() == 0){
      if(buttonTwoState == 0){
        Serial.println("Turn Relay 2 ON");
        digitalWrite(relayPin2, HIGH);
        buttonTwoState = 1;
      }
      else{
        Serial.println("Turn Relay 2 OFF");
        digitalWrite(relayPin2, LOW);
        buttonTwoState = 0;
      }
    }
  }

  // Button 3
  if(debouncer3.update()){
    if(debouncer3.read() == 0){
      if(buttonThreeState == 0){
        Serial.println("Turn Relay 3 ON");
        digitalWrite(relayPin3, HIGH);
        buttonThreeState = 1;
      }
      else{
        Serial.println("Turn Relay 3 OFF");
        digitalWrite(relayPin3, LOW);
        buttonThreeState = 0;
      }
    }
  }
  // Button 4
  if(debouncer4.update()){
    if(debouncer4.read() == 0){
      if(buttonFourState == 0){
        Serial.println("Turn Relay 4 ON");
        digitalWrite(relayPin4, HIGH);
        buttonFourState = 1;
      }
      else{
        Serial.println("Turn Relay 4 OFF");
        digitalWrite(relayPin4, LOW);
        buttonFourState = 0;
      }
    }
  }

}


text:
No Response from ESP8266 WIFI
I am getting no response back from an ESP8266 WIFI with Arduino Mega using library ITEADLIB_Arduino_WeeESP8266.
//serial monitor response

setup begin

FW Version:

to station + softap ok

Join AP success

IP:

single ok

setup end

create tcp ok

release tcp ok

create tcp ok

Arduino Mega Code
#include "ESP8266.h"
#include <SoftwareSerial.h>

#define SSID        "atmel"
#define PASSWORD    "bets12345"
#define HOST_NAME   "www.google.com"
#define HOST_PORT   (80)

SoftwareSerial mySerial(10, 11); /* RX:D3, TX:D2 */ ESP8266 wifi(mySerial);

void setup(void) {
  Serial.begin(9600);
  Serial.print("setup begin\r\n");
  Serial.print("FW Version:");
  Serial.println(wifi.getVersion().c_str());
  if (wifi.setOprToStationSoftAP()) {
    Serial.print("to station + softap ok\r\n");
  } else {
    Serial.print("to station + softap err\r\n");
  }
  if (wifi.joinAP(SSID, PASSWORD)) {
    Serial.print("Join AP success\r\n");
    Serial.print("IP:");
    Serial.println( wifi.getLocalIP().c_str());
  } else {
    Serial.print("Join AP failure\r\n");
  }
  if (wifi.disableMUX()) {
    Serial.print("single ok\r\n");
  } else {
    Serial.print("single err\r\n");
  }
  Serial.print("setup end\r\n");
}

void loop(void) {
  uint8_t buffer[128] = {0};
  if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
    Serial.print("create tcp ok\r\n");
  } else {
    Serial.print("create tcp err\r\n");
  }
  char *hello = "Hello, this is client!";
  wifi.send((const uint8_t*)hello, strlen(hello));
  uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
  if (len > 0) {
    Serial.print("Received:[");
    for(uint32_t i = 0; i < len; i++) {
      Serial.print((char)buffer[i]);
    }
    Serial.print("]\r\n");
  }
  if (wifi.releaseTCP()) {
    Serial.print("release tcp ok\r\n");
  } else {
    Serial.print("release tcp err\r\n");
  }
  delay(5000);
}

Have you tried a hard reset?

Rx and Tx properly crossed - SwSerial Rx to ESP Tx and SwSerial Tx to ESP Rx? And the connections are sound? It wouldn't be the first time "someone" thought he'd killed an ESP, only to find a missing connection from its transmitter (not that I'd know anything about that ..... ;)

Have you remembered to logic shift the ESP8266 from 3.3v to 5v?
Any by no response, do you mean no response from your web server or the board itself?

ya 3.3 V is ok,AT command work fine,using library ITEADLIB_Arduino_WeeESP8266,no response print back in serial monitor.as describe above.

just like we want to get version of it.Serial.println(wifi.getVersion().c_str());,no response printed.

If you send it "AT+GMR", does it respond then?

If you look in the source code for the library, wifi.getVersion() sends AT+GMR and returns it. I think the GMR command was added in a firmware update, which could mean you are running an old firmware which does not support AT+GMR

If you are using an ESP-01 board (which is an ESP8266 based board)
You should try running the ESP8266 from an independent 3.3V power supply.
The Arduino Mega 3.3V pin only supplies up to 50mA, wheres as the ESP8266 requires up to 200mA.
Also, make sure the CH_PD and RESET pins are held high (connected to the 3.3V).
Because you're using an Arduino Mega, you might find it beneficial to use pins 16 and 17, and Serial2 instead of software serial.
Internet sources indicate that they are sometimes set up with a baud rate of either 9600, 57600 or 115200. I managed to get mine working with 115200, but software serial is limited to a baud rate of 19200.

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


text:
SPP-C and HC-05 are they the same thing or something else?
I was actually thinking to buy a cheap HC-05 module while I was searching I found a similar (think so) module It say it is a replace for HC modules.
Is it compatible with Arduino Nano and will it work same as the HC-05 module ????

In theory they are the same and have the same capabilities. Practically they are not. With SPP-C you get twice the headache for half the price as for HC-05. In had to find it out the hard way Sending data using Bluetooth SPP-C Module without a Breakout-Board. I tried both SPP-C and HC-05 with and without breakout boards finding the same issues. So if you are willing to spend time, risk your project and save some money then use SPP-C. Otherwise use the well known HC-05.

What about using with a breakout board will it be easy ???

As I wrote, I tried both. But yes. They are supposed to work as a drop in replacement.

Yes, both the SPP-C and HC-05 are compatible with the Arduino range, and they do work in pretty much the same manner!

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


text:
Programming other Atmel chips(excluding Atmega 328 and 168)
How can we program any other chips of Atmel using Arduino Nano as a Arduino ISP ? Excluding the Atmega 328 and 168.

Most AVRs can be programmed using the ISP protocol. Your Nano can do the job: just follow the Arduino ISP tutorial.

For AVR's and perhaps a few others you can use avrdude with various chip-specific parameters.  Going beyond those, the question gets too broad.

Since you say:

Excluding the Atmega 328 and 168.

I'm going to assume that you already understand the general process for using your Nano as an ISP.
The Arduino IDE includes the Arduino AVR Boards hardware package which provides hardware definitions for specific configurations of:

ATmega328P
ATmega168
ATmega2560
ATmega1280
ATmega32U4
ATmega8

If your hardware matches the configuration of one of the Arduino AVR Boards then you only need to select that board from the Tools > Board menu.
It is also possible to program many other Atmel microcontrollers or alternative configurations of the microcontrollers included with the Arduino AVR Boards hardware package with your Nano but you will first need to install the 3rd party hardware package that contains the definitions for the part you want to program. You can find a fairly comprehensive list of these hardware packages here:
https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls
Once you have found the hardware package that contains the necessary definitions you will need to install it. For this you have two options:
Boards Manager
The easiest installation option Boards Manager. Most Arduino hardware packages allow this type of installation (and certainly all of them on the above list):

Copy the Boards Manager package index URL.
File > Preferences > Additional Boards Manager URLs > paste URL > OK
Tools > Board > Boards Manager
Wait for downloads to complete.
Scroll down until you see the entry for the hardware package you want to install. Click on it.
Click "Install".
Wait for installation to finish.
Click "Close"

Manual Installation
Another option is to manually install the hardware package. For a simple package this would involve:

Download the hardware package
Copy the contents of the downloaded file to {sketchbook folder}/hardware. You can find the location of your sketchbook folder at File > Preferences > Sketchbook location.
Restart the Arduino IDE if it's running

After installation you will only need to select the correct board from the Tools > Boards menu. In some cases selecting a board may also add custom menu items to the Tools menu that can be used to adjust the configuration of the board (part, clock, BOD, etc.).

using Arduino Nano as a Arduino ISP

Note that the correct term is Arduino as ISP. There is a programmer named ArduinoISP that is completely different from the Arduino as ISP. The confusion is increased by the sketch used on the Arduino as ISP being named ArduinoISP.


text:
'setup' does not name a type?
Was trying to work some code that I found online to suit my needs and it continues to show the same error 'setup' does not name a type. I have tried setting it to void, Void as well as rewriting the code but still the same issue arises and I was wondering how to fix this issue.
This program will at some point compile data from 3 different sensors and do its various calculations within these separate loops and print to serial in a table that can then be saved or exported. The only sensor attached at the moment is a ultrasonic sensor that measures the distance it is from a surface. (last 2 groups of code have a basic print function just so the loop is occupied)
Here is the code:
#include <CapacitiveSensor.h>

long timeCounter; // milliseconds counter
long timePassed; // The actual milliseconds time
int trigPin = 2;
int echoPin = 3;

long delay1 = 10;    // ms for cycle of event 1
long delay2 = 5;     // ms for cycle of event 2
long delay3 = 25;    // ms for cycle of event 3
long delay4 = 10;

// Counters for the number of triggered events before the
// corresponding event starts
int countEvent1, countEvent2, countEvent3, countEvent4;

int TRIGGER = 5; // ms to trigger the milliseconds timer

int MAX1 = 2; // Number or triggered milliseconds to start event1
int MAX2 = 1; // Number or triggered milliseconds to start event2
int MAX3 = 5; // Number or triggered milliseconds to start event3
int MAX4 = 2;

// Initialisation
setup {
     timeCounter = millis(); // read the actual internal time
     timePassed = 0; // we start with no time passed

     countEvent1 = 0;
     countEvent2 = 0;
     countEvent3 = 0;
     countEvent4 = 0;
}

// Infinite cycle
loop() {

     // Read the actual time
     timePassed = millis() - timeCounter;
     // The smallest unit of time that should trigger an event is for event 2 (5 ms)
     // so our trigger should count this smaller unit

     // Check if the time passed after last reading is the trigger time
     if(timePassed >= TRIGGER) {
          if(++countEvent1 == MAX1){
               // Reset the trigger and start the event
               event1();
               countEvent1 = 0;
          } // Event 1

          // It's time to manage the events
          if(++countEvent2 == MAX2){
               // Reset the trigger and start the event
               event2();
               countEvent2 = 0;
          } // Event2

          // It's time to manage the events
          if(++countEvent3 == MAX3){
               // Reset the trigger and start the event
               event3();
               countEvent3 = 0;
          } // Event3

          if(++countEvent4 == MAX4){
               // Reset the trigger and start the event
               event4();
               countEvent4 = 0;
          } // Event4

     } // Trigger

} // LOOP

// ============ Event functions ==============

event1() {
  long duration, distance;
  digitalWrite(trigPin,HIGH);
  delay(100);
  digitalWrite(trigPin, LOW);
  duration=pulseIn(echoPin, HIGH);
  distance =(duration/2)/29.1;
}

event2() {
Serial.print("work")
}

event3() {
Serial.print("work")
}

I am very new to coding so there will be stupid mistakes hidden amongst this I can guarantee it.

You're just forgetting the smooth brackets after void setup. It should be void setup () {

You should learn the basics of a language's syntax before writing programs in it...

All your functions (including setup and loop) need a type as part of the declaration. This for example:
event2() {
Serial.print("work")
}

Should be:
void event2() {
  Serial.print("work");
  }

Note also the semicolon after the Serial.print function call.
I have a page that explains the basics.
On that page is a diagram that breaks down what a function declaration looks like:

You have a problem with function definition. Let me explain with an example.
int kPinLed = 8; // LED - Pin 8

void setup()
{
  pinMode(kPinLed, OUTPUT); // LED as output
}

void loop()
{
  ledFun(); //Create LED Function
}

//Now write function's code with type, here "void"

void ledFun()
{
  digitalWrite(kPinLed, HIGH); //LED ON
  delay(1000);
  digitalWrite(kPinLed, LOW);  //LED OFF
  delay(1000);
}

Same things you have to do with your code. Just write properly function's type. I hope this will help you.

Yeah you never defined setup or loop which need the void before them.
void setup(){

}

void loop(){

}

Function declarations start with a type:
void setup() {

}

void loop() {

}

void means the function doesn't return a value.

error 'setup' does not name a type. I have tried setting it to void

the correct typing of it is this:
void setup(void) {
...
}

void loop(void) {
...
}


text:
iterate through 8 thermocouple sensors (MAX31856)
I have 8xMAX31856 and I am trying to use the Adafruit library. Instead of writing all 8 thermocouple channels each time in code (and wasting memory), I want to store the objects in an array and loop through them periodically.
Here is my code:
Adafruit_MAX31856 TCouple1 = Adafruit_MAX31856(2,11,12,13);
Adafruit_MAX31856 TCouple2 = Adafruit_MAX31856(3,11,12,13);
Adafruit_MAX31856 TCouple3 = Adafruit_MAX31856(4,11,12,13);
Adafruit_MAX31856 TCouple4 = Adafruit_MAX31856(5,11,12,13);
Adafruit_MAX31856 TCouple5 = Adafruit_MAX31856(6,11,12,13);
Adafruit_MAX31856 TCouple6 = Adafruit_MAX31856(7,11,12,13);
Adafruit_MAX31856 TCouple7 = Adafruit_MAX31856(8,11,12,13);
Adafruit_MAX31856 TCouple8 = Adafruit_MAX31856(9,11,12,13);

char* thermocouples[] = {TCouple1, TCouple2, TCouple3, TCouple4, TCouple5, TCouple6, TCouple7, TCouple8};

however, I am met with this error on compile:
cannot convert 'Adafruit_MAX31856' to 'char*' in initialization

Why can I not store these variables in an array and call on them later? Is there another way to do this? They work on SPI logic...

You CAN store them in an array, but NOT in an array of pointers to characters. That is just the wrong type. Try
Adafruit_MAX31856 thermocouples[] = {TCouple1, ...}

or even ditch the first declarations and use
Adafruit_MAX31856 thermocouples[] = {
    Adafruit_MAX31856(2,11,12,13),
    Adafruit_MAX31856(3,11,12,13),
    Adafruit_MAX31856(4,11,12,13),
    ...
};

I don't have that library installed, but I tried compiling this pattern with the Bounce2 library and it works. That looks like this:
Bounce buttons[] = {
    Bounce(),
    Bounce(),
    Bounce()
};

Alright! I have tried that and it compiles past it... but how do I loop through this array? I tried for(int i = 0; i<8; i++){thermocouples[i].setThermocoupleType(MAX31856_TCTYPE_T);} and it says it is void

nevermind... sorted out issue. Thanks for the guidance!


text:
Float array to comma separated string
I have a loop command reading temperature sensor data from 8 thermistors and are storing them as floats into an array. Instead of printing to Serial on each iteration, I would like to create a comma separated string of these values and send to serial (in one instance, versus 8). What would be the best way to do this? I have tried sprintf commands to no avail.
Thanks in advance!
Edit: I would like to also write this string of comma separated values to a MicroSD card slot so I am under the assumption that creating the string once and printing to Serial AND saving to MicroSD card is more efficient than 8 separate iterations

It sounds like you're expecting serial communication to be like a bag of candy. All there in one place at the same time. In reality serial communication is more like this: https://www.youtube.com/watch?v=jv9qaPAlK_g

Unless the thermistor actually delivers floating point results, your code can do less work by storing the fixed-point data and converting that. The array will be smaller, and you would be able to use any of the printf()-family of functions to format your output if that would be helpful, including generating the ASCII data into memory once, and then sending it to both devices (regardless of whether you handle 1 or all 8 results at a time).

@JRobert - would be able to provide a printf() example? I think for cleanliness this would be ideal. And I do get float values from thermistors

I'd be happy to, except for the fact that the Arduino library printf() functions exclude the floating point conversions. If you don't need any decimal places, then we could do it. Even if you did want a couple of decimal places - but then it starts to get messy because you'll need to extract the whole number of degrees and the fractional remainder rounded to n-places, and convert them separately. It's doable but you lose some of the directness and simplicity of expression that printf() is meant to offer.

... In this situation I use dtostrf() to convert the float to ASCII in one buffer, then format any remaining output using printf() - or sprintf() - using the ASCII string versions of the floats, to a serial device or another buffer, respectively. It's workable but the code doesn't look as nice as if the printf() functions would all the work at once.

Darn, my idea for, what I thought, was clear logic, is probably a lot harder and more memory hogging than expected. I might as well print to serial and microSD card on each loop of each thermistor reading. seems cleaner. Thanks for the explanation(s)

Basic Arduinos have no support for floating point in sprintf and related functions.
Instead you have to use dtostrf() to build up a string block by block.
However there is no benefit to building a string then outputting to serial "in one instance" compared to outputting the data a bit at a time.  Serial is slow. Very slow. When you "output" data to serial you aren't outputting data. You're merely putting the data into a buffer to be sent when it's possible.
In effect, by using multiple Serial.print() calls, you're building up the string to send in the Arduino's internal serial TX buffer.
By building the string first all you're doing is creating a buffer to copy data into a buffer to send it through serial. It's redundant, wasteful, and utterly pointless.

Thanks for the response and description @Majenko. I should have also mentioned this too but I was planning to also write the string of comma separated values to a microSD card. I thought it would be better to log the data once versus 8 times each void loop() - hence why creating the string might be optimal

Same thoughts apply for writing to SD. (file.print only writes to a buffer) You should consider calling flush or close/open less often than after every print, anyway.

Thanks @DataFiddler. I will try avoiding the building of strings and just submit to Serial/SD writing as data is ingested.

Here's a sample program using sprintf() to convert some float data to ASCII in a buffer, format an output string containing that data into another buffer and print the result on the terminal. It's not quite as neat as
   "sprintf(buffer, "i=%2d, T=%f\n", i, Temp);

It takes three lines and two buffers but it gets the job done:
#include <Arduino.h>

float getTemp(void);

void setup()
{
   char tempBuf[10+1], outputBuf[50+1];

   // Open console
   Serial.begin(115200);

   // Print 20 successive temperatures to the terminal
   for( uint8_t i = 1;  i <= 20;  ++i){
      float Temp;

      Temp = getTemp();                 // get the next value
      dtostrf(Temp, 6, 2, tempBuf);     // Convert float to ASCII
      sprintf(outputBuf, "i=%2d, T=%s\n", i, tempBuf); // format the value for printing
      Serial.print(outputBuf);          // print the line to the terminal

      delay(1000L);
   }

}

// Function to return temperatures.
// STUB: The data is made-up.
float getTemp(void){
   static uint8_t n = 0;        // count of results returned

   return( (float)n++ * 1.7 );  // index 'n' times an arbitrary multiplier
}

void loop(void)
{
   ;
}


text:
2 SPI Slaves with 2 different SPI modes on one Arduino Mega
I am working on a project where I read 8 MAX31856 thermocouple sensors using the Adafruit Library. This works just fine and prints the read outs to serial.
I want to also save the readings to a microSD card. And this is where I hit a snag.
I am trying to use the SdFat.h library. I can loop through my MAX31856 thermocouples, and write once to my SD card, but after that it hangs the SPI bus.
the MAX31856 works on SPI_MODE1 (as per Adafruit Library) and the microSD card works on SPI_MODE0, I believe. I am trying to switch SPI bus modes before and after writing to the SD card but I think there is something wrong after first successful write to the SD card. After the first loop iteration, it seems like all data is basically noise on the SPI bus.
I am using the Adafruit ADA254 microSD breakout Board, which has a card detect pin, so I first check to see if an SD card is inserted, and then write to the file.
Question: Is there another or better way to switch SPI_MODES on each loop? is there anything more I need to consider so I end up back to SPI_MODE1 appropriately for the MAX31856 thermocouples?
Below is the pertinent code for what I have going on...
void setup(){
   int sdCard = 36;
   char filename[10] = "test.txt";
}

void loop(){
....code to read thermocouples ...

///THEN THIS

  //lets confirm SD card is still in socket before writing
  CardDetect = digitalRead(37);
  if(CardDetect == HIGH){

     SPI.setDataMode(SPI_MODE0);
     SPI.setClockDivider(SPI_CLOCK_DIV4);
     SPI.setBitOrder(LSBFIRST);
     digitalWrite(sdCard, LOW);
     sd.begin(sdCard, SD_SCK_MHZ(1));
    //LETS START SAVING DATA
          myFile.open(filename, O_WRONLY | O_CREAT | O_EXCL);
          myFile.write(now.unixtime());
          myFile.write(",");
            for(int i = 0; i<8; i++){
              myFile.print(TEMP[i]);
              myFile.write(",");
            }
          myFile.println();
          myFile.close();
          digitalWrite(sdCard, HIGH);
          SPI.setDataMode(SPI_MODE1);
          SPI.setClockDivider(SPI_CLOCK_DIV16);
          SPI.setBitOrder(MSBFIRST);
          delay(200);
    }

}

what is your question?

if your question is how do I debug the code?, then remove all sensor code and see if file is written without crashing

@jsotola - the file is writing no problem on first iteration. However, after the first loop of the code, the SPI bus 'glitches' and I does not read sensors correctly

This is more likely the SD card or level translator itself interfering with the SPI bus. I never share an SPI bus with an SD card - always have it on its own dedicated bus.

@Majenko I feared this... I needed all the digital pins, hence why the project is built around the arduino Mega - any way to add a second SPI bus (software maybe)?
Wait - are you the author of: https://github.com/MajenkoLibraries/SoftSPI ?

I might be. Been so long I have no idea how well it works. I've become so used to working with chips with 6 SPI busses built in I've had no cause to use it for a number of years...

the Adafruit's library has built in software SPI. use the constructor with pin numbers Instantiate MAX31856 object and use software SPI pins

@Juraj I have done that, each MAX31856 thermocouple object is built by their software SPI pins, eg: Adafruit_MAX31856(22,50,51,52)
Again - my code works fine until I get to the SD card logic. If I remove the SD card logic, code works too. It has something to do with the SPI bus after I read/write to SD card

In case you are using a 'cheap' SD reader, the SPI bus cannot be shared. I had more luck with a SD data logger card. It is related to thri-stating.

@Michel im using the Adafruit breakout board... not cheap. I believe it has something to do with different SPI_MODES between my spi devices

@NRav ok then it's probably not the issue I had long time ago.

don't use the hardware SPI pins for software SPI

@Juraj I was under the impression that declaring the pins was just redundant... or am I misinterpreting that? In which case, any 3 digital pins can be SPI bus pins?

those are the pins which software SPI will use. by using this constructor you activate software SPI on selected pins

For anyone who has a similar issue with the SPI Bus, SdFat library has a Software SPI option built in (example here).
You need to modify your SdFat/SdFatConfig.h file, but that is minimal. Once you have the microSD card module on a separate bus, it will not corrupt the main SPI Bus.
Switching the SD Card module to it's own bus rectified the issue. Keep in mind that Software SPI comes with a speed penalty.


text:
How can I switch from ArduinoOTA to ESPhome safely?
I have an ESP8266 (ESP-12F), which I flashed with ElegantOTA, a variation of ArduinoOTA with just a different interface. I never managed to flash anything else, so it's a bare OTA I flashed using a dedicated programmer. The device has not even pins for further flashing.
The ESP is already in a device that I would like to avoid opening, and I would like to avoid soldering pins and flashing locally the ESPhome firmware (which is also configured for future OTA).
I'm not sure the bootloader or whatever is used to self-flash the chip is compatible. How can I do it?
Or should I just open the ArduinoOTA webpage, upload a ESPhome firmware and go on?

if you can load a new firmware, load a new firmware. make sure it works before hand, but an image is an image.

I thought that different bootloaders use different techniques for replacing the running one. For example, one may write the new one in the second half of the flash and run it from there, but they could also write the firmware file in the second half, then copy it back to the first "already running" area. But ok, if it's compatible, I'll do it.

well i've definitely used different firmwares with different OTAs and not had a problem. It feels dirty, i'll give you that. I suppose it's possible to fail and I just got lucky, and i'm just some guy on the internet not guaranteeing your money back, but afaik, you don't really need to worry about boot-loaders on ESP8266s.

@dandavis at the end I compiled a minimal ESPhome firmware, with only OTA and wifi captive portal, and I tried to upload it (300 KB, more or less). "Space is not enough". I also tried to compile a minimal BasicOTA from the Arduino suite, and I got a binary of the same size and the same error message. I have to flash using the pins.

I compiled a minimal ESPhome firmware, with only OTA and wifi captive portal, and I tried to upload it (300 KB, more or less).
Initially I got the error "Space is not enough", but then after rebooting the ESP8266 and trying again, it worked.
So as said by dandavis, different firmwares are compatible in regard to OTA capabilities and it's possible to cross-flash.

I've found that when a flash fails with a space error, I've usually specified the wrong flash size option in Arduino (under Tools->Flash Size).  Depending on the version of Arduino you're using, try picking the one with "No SPIFFS" or FS:none that matches the size of your flash memory.  Once you make that change, recompile and reupload.


text:
Can I get the current connection speed with ESP8266?
Using an ESP8266 I can get the RSSI of the Wifi network using Wifi.getNetworkInfo() or Wifi.RSSI(). But is there a way to know the actual connection speed in Mbps, after joining successfully a WiFi network?

isn't it always 54?

@dandavis Are your phone or laptop always connecting at 350 Mbps on 2.4 GHz or 867 Mbps on 5 GHz? of course not, it depends on the signal strength. That's the MAX connection speed with strong WiFi signals.

no, the ESP can't even talk on 5Ghz. My asus RT-AC68U claims ~54Mbps. Not sure what figure you're actually looking for, since you're never going to get more than a few dozen KB/s throughput.

@dandavis I know that 5 GHz are not supported and that 54 Mbps are the maximum. Still, try to move the ESP far from the station, about the maximum distance that allows you to get a connection, and check in your router if the connection is still 54 Mbps. It shouldn't be, since in the datasheet it's stated that 22 Mbps have a better S/N and allow weaker signals. There will be a distance where 54 Mbps are not physically possible anymore and the connection will be established at 22 Mbps. My router doesn't show me the connection speed, please do this test :)

Wifi modules decide on link speed based on signal strength. So you can estimate the link speed with signal strength, which you can get with WiFi.RSSI(network).
The datasheet of ESP8266 contains a table mapping RSSI to link speed under "Sensitivity":

-98 dBm: 1 Mbps
-93 dBm: 6 Mbps
-91 dBm: 11 Mbps
-75 dBm: 54Mbps
-71 dBm: 65Mbps, 72.2Mbps

Whenever these values are "minimum", "maximum" or "typical" remains unclear. These dBm limits are also quite low, which means the link speed will probably be capped by the other communication peer (your router). Here's the same table for a random D-link router, DI-624.


text:
Use a PIR Sensor to detect the movements of a paper
I need to detect when a paper comes out from a laser printer and count the number of printed papers. For that I hope to use a PIR sensor to detect the movement of the paper from the printer. Is it possible to detect the movement of a paper using a PIR sensor? Please be kind enough to help me.

If the paper is hot when it comes out of the printer, possibly.  Could be unreliable though.
Better would be to place a photo-interrupter (or IR LED and IR Photodiode) in the path of the paper to detect a break in an infra-red beam.

The solution from the OP with the photo-interruptor is probably the most standard one.
However it might be worth checking if you can get away with a light sensor: assuming that the paper is mostly of different colour than the background, the paper should change the current passing through the photodiode.
Alternatively, you could use a proximity sensor, aimed at a location on the path of the paper, where there is typically nothing.
These 2 solutions are trying to avoid having to place something on both sides of the paper. If that doesn't bother you, then I'd recommend the OP's solution.

A "light sensor" that relies on ambient light may be rather subject to changes in external conditions.  If using anything open to the environment it's really best to provide your own light source that is modulated and look for that pattern in the receiver, at least with an op-amp filter, and possibly with something as discriminating as a lock-in amplifier (which is fairly easy in software - it ends up a lot like a single point fourier transform)


text:
Outlet switcher using servo motor
I am building a small-scale watering system to water my plants, controlled by Arduino. I have designed most of the project except for how to switch water between multiple pipes.
A little more background:
I want to be able to use a servo motor to control the amount of water that is sent to each plant (based on pot size and plant type). The motor needs to be able to switch input (a 1/2 inch pipe carrying water) to a set of outputs (similarly sized pipes all going to different plants). I am not able to find something off the shelf that does this. So, I am about to 3D print something. Is there something available that I can use instead?

A typical hobby servo may not have enough torque. Try searching for 'miniature rotary valve' or 'miniature solenoid valve'.

Pressure tight valving is tricky.  If you can locate your selector above the targets, you might be able to make gravity feed, open-to-atmosphere system following a single pressure value where some sort of rotary diverter channel would direct the stream of water into the end of any one of a number of open-ended hoses (maybe with little funnels?) placed around the perimeter and leading from there to the various plants.  Hopefully you are doing this over a concrete floor with a drain..

As JRobert mentioned in a comment, you could use a solenoid valve, some of which you can get for about $5.
If you want to water one line at a time, get Normally Closed, one per line. Naturally, since most of them are 12v DC, you can't directly power them from your Arduino. You'll need some power transistors or some relays, and a 12v supply capable of steadily powering the solenoid.

To me it would seem simpler to use a faucet for each line, each faucet controlled by a motor.
Then you can even water the plants in parallel.
Even better, why not using submersion pumps, like those used in water tanks? Here too, you can control them in parallel.
The amount of time you keep a motor running is proportional tothe amount of water delivered.

Yes, this is simpler but also not very cost effective and does not scale well. Since, I have to buy one faucet motor (a solenoid valve) per plant and separate wiring for it in my circuit board. This is why I was looking at a servo motor to switch between multiple output lines for water.

Ok, then there is a solution that is even simpler and definitely cheaper: just connect all the pipes together and, for each pipe, on the ending for the vase, apply a sort of cork with a hole of custom size.
Of course it's not exactly programmable, but you can easily swap corks.
It scales indefinitely and you need 1 single master actuator/tap.


text:
Can I use the NodeMCU ESP12 5v pin and control it with a relay?
This question might be a little esoteric, but I cannot find any answer for it.
Situation:
I want to have more than 8 Analog sensors on a NodeMCU ESP32. Unfortunately due to SPECTACULARLY poor design choices you cannot do this and have WiFi active at the same time. This is a non-starter for my project so I need a workaround.
Thought:
What if I share the available pins I can use, by turning power on and off to the sensors in question? Easy enough using the digital GPIO's and just turning them on and off. The issue is that the sensors are at the end of long wires and so I need 5v power to ensure good readings. So what if I just use a relay, powered off the 5v pin on the ESP32, and switch them on and off?
My question is - can you even do this? Most of what I have seen would indicate I need a separate power supply for the relay itself, and the source being switched on and off, but I would like to avoid having another power supply, and build it as in the circuit diagram below.
A couple of notes:

ignore the V1/1 V label in the picture - the circuit tool is very nice, but freezes a lot and I forgot to change that to VIN/5V before the screenshot
I have also omitted the data connections from sensors and to the relays to switch them on and off - I know they need to exist, but they aren't the issue.
I am running this project plugged in to the wall so source power is not an issue - I am not worried about drain or having a full 5V from the VIN pin

Before I fry parts, I thought it would be good to ask if anyone has tried this or if it is even possible?

your setup could work as described. sharing power isn't the issue. the main concern would be the 3.3v HIGH being high enough to actuate the relay module.

You dont really need relays, you could switch power on/off using a transistor, use the same power supply, there would be no issue.  However, you would need to find out if having two sensors connected to the same input would skew the results even if one is not powered. You are still introducing an "unknown" circuit and it could mean that your output changes or even damages the other circuit, as you are now apply a voltage to an output of another device.  You could use diodes to ensure current is only flowing out of the device and not into the other device, but again this will effect the voltage

dandavis the 3.3 should work to activate it (I can get a 3.3 model as well so that's an option too)
@ChadG - I had thought of the diodes to protect the data lines from the sensors, but the voltage drop could be an issue. Given the length of wire involved between sensor and MCU, we are talking about pretty small amounts (sub 3 volt most likely although not tested with a multi yet). Would the diode be that much of a drop in that case?

voltage drop over a diode is pretty fixed, so it actually becomes a much higher percentage with lower voltages. The exact amount changes based on the diode, but 0.7V is common.

Yeah dropping almost a full 1v is probably a no go for the readings from the sensor since they are analog and thus voltage dependent. Oh well, guess I am stuck then.

oh, @ChadG, thanks for the idea on the transistor instead of the relay. Probably a much more efficient design for the PCB, given it has to fit in roughly 70 x 70 MM!

Now you could use double throw relays between the output lines of sensors and the input on the uC.  This way only one was connected to it at a time, and the two sensor outputs would not be connected this way.

Another option, and probably the cleanest, is to use adc IC's.  The ones I link are only a single channel, but they communicator over I2C so you can use a number of them off the same bus, now you actually have as many inputs as you need   https://www.mouser.com/ProductDetail/Analog-Devices/5962-9475501MPA?qs=sGAEpiMZZMvTvDTV69d2QgYdPJm2vkaBTxTWToXHJa8%3D

Just get an additional power supply that is capable of providing enough current. The relay-approach is much too complicate and will be more expensive than an ordinary PSU...

@SimSon the relays were not being considered because of power draw, but so that the sensors could be multiplexed to the inputs.(have one set on at a time)

@ChadG Doesn't the esp32 have enough pins that are multiplexed to the ADC internally? And if the OP really needs more pins than available then using an analog multiplexer IC would be the way to go in my opinion...

I am liking the ADC IC idea. It would eliminate both the power and " not enough pins" issue. I think it will fit in the confines of the PCB - just need to see. I have several on the bench, but it never occurred to me to go that route. DUH.


text:
How to create TCP server on Arduino UNO WiFi?
I'm currently trying to make my Arduino UNO WiFi work as a TCP host, so I can send him a TCP message and it sends a response.
I had no problem doing this on the Arduino Galileo Gen 2 using the EthernetServer, but since this one is using WiFi, EthernetServer isn't an option.
I can, however, run a web server, but that's not what I want.
So how do I make the Arduino receive, handle and respond to sent TCP/IP messages?

Ethernet and wifi are basically the same thing but only joinig Ethernet is codewise different than joining a wifi address and thus these two need 100% different code because wifi and Ethernet are a different thing.
See, compare codes in below links, and you see the difference is on making up the level 1 connection, and tcp and ip on 2 and 3 do not change.
https://github.com/evothings/evothings-examples/blob/master/examples/arduino-led-onoff-tcp/arduinoethernet/arduinoethernet/arduinoethernet.ino
https://github.com/evothings/evothings-examples/blob/master/examples/arduino-led-onoff-tcp/arduinowifi/arduinowifi/arduinowifi.ino

Thank you, however I'm still getting the "WiFi shield is not present". May I ask you how I can fix that issue? I've tried a lot of things but I still get that error. And is it still neccesary to give the SSID and password if the Arduino Uno WiFi is already connected to the wifi?

To initialize the used connection object, I suppose yes.

Okay thanks. Now I'll try to fix the "WiFi shield is not present" message

For Arduino UNO Wifi, you have to use library "UnoWiFi-Developer-Edition-Lib". You can directly download and install it through library manager or can get it offline through the following link "https://github.com/arduino-libraries/UnoWiFi-Developer-Edition-Lib".
Hope this can help you.

this 'late' answer is ok, only there is now a better option then the slow UnoWiFi-Developer-Edition-Lib. the new library for Uno WiFi is UnoWiFiDevEdSerial1 library


text:
Using 2 serial ports on NodeMCU
I am using a NodeMCU ESP 12E board which will be programmed using the Arduino IDE. I intend to use it to send GPS data to the Blynk app server. I also want to interface a Bluetooth module HC-05 to the board along with the GPS module. I am also interfacing a L239D motor driver IC to the NodeMCU in order to control two DC motors. I am also using a metal detector module with analog output which is connected to the A0 pin of the board. Motor driver inputs are given using D0,D1,D2 and D3 pins set as digital out.
I need the NodeMCU to receive data from the GPS module and also send and receive data through the Bluetooth module. So I need 2 UART serial ports. I understand that the UART0 port can be used as the Serial port using Serial.begin(BAUD-RATE). UART1 can be used only for transmission. UART2 can be configured on GPIO13 and GPIO15 as Rx and Tx using Serial.swap(). But this cannot be used along side the UART0 port.
So is there a way I can implement Software serial in the Arduino IDE in order to set 2 ports, one for receiving only and other for both sending and receiving serial data ?

the Arduino esp8266 boards package has a SoftwareSerial library. a new one in the 2.5.0 version

Consider upgrading to the ESP32. It has bluetooth built in, and far more GPIO and analog facilities. Not to mention much much much more power in general.


text:
Reading bytes from a file on SD Card - Understanding Buffer
I have the following piece of code which opens a Bitmap from the SD card and outputs the width to the serial monitor.
#include <SPI.h>
#include <SD.h>

File bitmap;

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

  Serial.println("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  bitmap = SD.open("/TEST2.BMP");

  int width[0]; // why can't I just write "int width;"
  bitmap.seek(18);
  bitmap.read(width, 4);
  Serial.println(width[0]); // and "Serial.println(width);"
}

void loop() {

}

It works perfectly fine but I don't understand why I have to declare the buffer for the width as int width[0];. I tried int width; but then the output is just 0.

You don't have to, it's just one way of doing it.
Basically the read function needs a pointer to a buffer to store the data in.  By using an array with one entry you get a pointer to a buffer that is big enough for one (32-bit) integer. And you then get an "easy" way of accessing that one integer within that buffer.
Another way would be to just use a simple integer and pass a pointer to that integer to read:
uint32_t width; // Use a fixed size integer for portability
bitmap.seek(18);
bitmap.read(&width, sizeof(width)); // Use sizeof for portability
Serial.println(width);

I think I have a bit of insight:
An array is a pointer. Thus,
int arr[0];
is equivalent of
int * simple;
So. read(arr...  or read(&simple...


text:
Multiple Push buttons to one input
So I am trying to use one input to control an LCD display. The goal being that once one of the buttons is pressed it delivers a message. I have watched quite a few tutorials and can get the program to work sometimes. Yet, it is still pretty buggy and I am wondering why that is. To get this make this project work somewhat used this code.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonPin = A0;     //Button and LED pin numbers
    void setup()
{
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  //lcd.print("hello, world!");
  Serial.begin(9600);           //Serial monitor used to determine limit values

 }

void loop()
{
  int temp = analogRead(buttonPin);   //Read the analogue input
  Serial.println(temp);               //Display the read value in the Serial monitor
  if (temp = 340)                     //Lower limit for first button - if below this limit then no button is pushed and LEDs are turned off
  {
  lcd.print("No Button Pushed \n");
  }
  else if (temp = 867)                //First button limit - if below this limit but above previous limit then the first button is pressed
  {
    lcd.print("Button 1 Pushed");
  }
  else if (temp = 156 )                //Second button limit
  {
    lcd.print("Button 2 Pushed");
  }

  else                                //If none of the previous buttons are pressed, then the third button must be pressed
  {
    lcd.print("Button 3 Pushed");
  }
  delay(100);                         //Delay for stability
}

The output sometimes is correct other times it is off. I think it has something to do with the circuit. Yet, I am scratching my head to find out what.

Michel Keijzers pointed out the issues you have in your code. But then
there is also an issue with your circuit: if you press any of the push
buttons, the analog input pin gets connected to one of the nodes of the
resistor ladder, and you get a well defined voltage reading. Good.
However, if none of the buttons is pressed, the input is not connected
to anything: it is floating. In this case the reading you get is
unpredictable, as it depends on parasitic influences of stray
capacitances, environmental noise, etc. You should modify your circuit
to make sure that the input voltage is well defined even when no button
is pressed.
Then, regarding the program, I recommend you remove everything after
Serial.println(temp);. Just make it work like this, and take note of
the readings you get in each case. Make sure they are consistent. Once
you know the values you expect, you can decide on the threshold to
apply, which should be about halfway between the typical readings. E.g.
if the two lowest values you get are 0 and 240, you would set a
threshold at 120.

Ok so if I wanted to get a well-defined voltage reading then I would tie the rightmost button to 5v Correct?

Good point, I stopped looking after I saw the problem in the code. Guess a combination of your and my solution is needed (doing your solution first).

So I am going to add in another picture which is the reason for my confusion

I understand now if I tie it low then I can get nice increasing values. Thanks for the help it really helped a bunch

You made a few mistakes with the three lines, first one being:
if (temp = 340)

First, the single '=' is an assignment operator instead of a comparing operator.  You want to use '=='.
However, you need to check if it is within a range, so you need to use <= (to see if it is smaller or equal). Also you need to put them in the correct order, so you get something like:
if (temp <= 156)
{
   // Process value if temp is smaller or equal than 156
}
else if (temp <= 340)
{
   // Process value if temp is smaller or equal than 340 (and higher than 156)
}
else if (temp <= 860)
{
   // Process value if temp is smaller or equal than 860(and higher than 340)
}
else
{
   // Process value if temp is higher than 860
}

Ok so that fixes some issues but the buttons are not giving nice values like that. When no buttons are pushed A0 is reading in 340 and the first button gives a value of 860. This makes me question the circuit itself.

Yes,  you first need to fix the problem that is solved by Edgar, then using my solution once you know the correct value ranges.


text:
Send numbers to arduino via serial port using python
I have a file with numbers called fginputs.txt. For example it could be something like this:
4958
4154
4154
4154
4154
4154
4154
4154
4154
4154
4154
4154
4154
4154
4154
4154
4154
4958

I want python to send each number to arduino via serial port. After each number is received, arduino should print back an acknowledgment number, indicating that it got a valid number, and then store that number in a dynamic array, because I could create larger files. When there are no more numbers left, send a '-1' to finish transmission.
Here's my arduino code:
// save some unsigned ints
uint16_t SIZE, *inputList, cont = 0;
boolean inputsReady = false;

void setup()
{
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);

 //free dynamic array memory
 free(inputList);
 //counter for how many numbers I've received starts at 0
 cont = 0;
 //This is true when there are no more numbers to receive, meanwhile false
 inputsReady = false;
 setupInputList();
 }

/* If there's not enough space, resize the array by one unit and store the number
   */
void growAndInsert(int currentSize, int newInt){
    if(currentSize > SIZE)
        inputList = (uint16_t *)realloc(inputList, (currentSize + 1)*sizeof(uint16_t));
    inputList[currentSize] = newInt;
}
/**
  init inputList with 100 blocks
 */
void setupInputList(){
  SIZE = 10;
  inputList = (uint16_t *)malloc(sizeof(uint16_t) * SIZE);
}

void clearBuffer(){
while(Serial.available() > 0)
    Serial.read();
}

/**
Listens in serial port for an integer that represents a new input and returns it.
If it doesn't get anything useful from serial, return 0
*/
  int getNewInputFromSerial(){
   if (Serial.available() > 0) {
    delay(100);
    // look for the next word
    int cmd = Serial.parseInt();
    clearBuffer();

    if(cmd == 4958)
        Serial.write("4");
    else if(cmd == 4154)
        Serial.write("5");
    else
        Serial.write("0");
    return cmd;
   }
  return 0;

}

void loop()
{
     if(!inputsReady){
        int newInput = getNewInputFromSerial();
        if(newInput == 0)
            return;
        if(newInput != -1)
            growAndInsert(cont++, newInput);
        else{
            inputsReady = true;
            //initTimer();
        }
    }

}

and the python script:
global arduino
PORT = '/dev/ttyACM0'
FILENAME = "fginputs.txt"
#Read file with inputs
with open(FILENAME) as f:
        content = f.readlines()
#init serial port
arduino = serial.Serial(PORT, 9600, timeout=1);
time.sleep(2);

#write
for input in content:
    arduino.flush()
    arduino.write(input)
    time.sleep(.1);
    resp = arduino.read();
    print "i got " + resp

#Finish transmission with -1
arduino.flush()
arduino.write("-1")
#done
arduino.close();

The fist time I execute the script I get this:
i got 4
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 5
i got 4

Which is great. But if I run it a second time I get this:
i got 0
i got 4
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0
i got 0

Which is terribly wrong because the file hasn't changed. I don't know what is going on here. If I unplug and plug back in the USB cable, transmission works flawlessly again.

// save some unsigned ints
uint16_t SIZE, *inputList, cont = 0;
boolean inputsReady = false;

void setup()
{
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);

 //free dynamic array memory
 free(inputList);

You are freeing a NULL pointer which is an undefined operation not necessary here, since it was never allocated.

  if (Serial.available() > 0) {
    delay(100);
    // look for the next word
    int cmd = Serial.parseInt();
    clearBuffer();

This is going to just throw data away, I'm not surprised stuff goes missing.
Read this: How to process incoming serial data without blocking - you need to get rid of the delay, and the clearBuffer() for a start.

Example code for reading from Serial without blocking and without using delay:
// how much serial data we expect before a newline
const unsigned int MAX_INPUT = 50;

void setup ()
  {
  Serial.begin (115200);
  } // end of setup

// here to process incoming serial data after a terminator received
void process_data (const char * data)
  {
  // for now just display it
  // (but you could compare it to some value, convert to an integer, etc.)
  Serial.println (data);
  }  // end of process_data

void processIncomingByte (const byte inByte)
  {
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;

  switch (inByte)
    {

    case '\n':   // end of text
      input_line [input_pos] = 0;  // terminating null byte

      // terminator reached! process input_line here ...
      process_data (input_line);

      // reset buffer for next time
      input_pos = 0;
      break;

    case '\r':   // discard carriage return
      break;

    default:
      // keep adding if not full ... allow for terminating null byte
      if (input_pos < (MAX_INPUT - 1))
        input_line [input_pos++] = inByte;
      break;

    }  // end of switch

  } // end of processIncomingByte

void loop()
  {
  // if serial data available, process it
  while (Serial.available () > 0)
    processIncomingByte (Serial.read ());

  // do other stuff here like testing digital input (button presses) ...

  }  // end of loop

In process_data in my example is where you would call atoi to convert the incoming string into an int (or atol if it is going to be longer).

free(NULL) is ok; per man malloc re  void free(void *ptr),  “If ptr is NULL, no operation is performed.”

Ach, you are right. Still, a pointless thing to do in setup. Post amended.

You could have a look at this.
It's a python program which does record/playback of key-presses, through an UNO.
It already implements:

serial communication with error checking
ACK: each message has its own ID, so you can keep track of what was lost, should anything bad happen
synchronization, in case your Arduino is powered up after the python program is started


text:
ESP32 HTTP Server request interrupts Telnet session
I have an ESP32 application that uses a web server as a user interface. For auditing and debugging during development I use Serial; however, that is impractical in the installed system. So, I decided to use Telnet (TCP/IP) to monitor what is happening when Serial is impractical.
The issue is that once a TCP/IP session has been established, when a HTTP request is received, the TCP/IP session is aborted.
I have reproduced the issue in a minimal sketch here:
#include "Arduino.h"
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>

WiFiClient telnetClient;
WebServer server(80);
WiFiServer telnetServer(23);

void telnetPrint(const char* text)
{
  if (telnetClient)
  {
    telnetClient.print(text);
  }
}

void telnetPrintln(const char *text)
{
  telnetPrint(text);
  telnetPrint("\r\n");
}

void _print(const char* text)
{
  Serial.print(text);
  telnetPrint(text);
}

void _println(const char* text)
{
  Serial.println(text);
  telnetPrintln(text);
}

void _println(IPAddress myIP)
{
  char rgIPTxt[32];
  sprintf(rgIPTxt,"%u.%u.%u.%u",myIP[0],myIP[1],myIP[2],myIP[3]);
  _println(rgIPTxt);
}

const char *rootFmt="\
\
  \
    <title>Test</title>\
  \
  \

Test
\

\

Heap size=%d

\

\
  \
\
";

char rootMessage[1024];

void updateRootMessage()
{
  _println("updateRoot");
  snprintf(rootMessage, sizeof(rootMessage), rootFmt,
           heap_caps_get_free_size(MALLOC_CAP_8BIT)
           );
}

void handleRoot()
{
  _println("Entered handleRoot");
  updateRootMessage();
  server.send(200, "text/html", rootMessage);
  _println("Leaving handleRoot");
}

void wifiSTASetup(const char*ssid, const char*password)
{
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(ssid, password);
  telnetServer.begin();
  telnetClient=telnetServer.available();
  _println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    _print(".");
  }
  _println("");
  _print("Connected to ");
  _println(ssid);
  _print("IP address: ");
  _println(WiFi.localIP());
  server.on("/", handleRoot);
  server.begin();
}

#define BAND    915E6

void setup()
{
  Serial.begin(115200);
  wifiSTASetup("your ssid", "your password");
}

void loop()
{
  server.handleClient();
  if (!telnetClient)
  {
    telnetClient=telnetServer.available();
    if (telnetClient)
    {
      _println("telnetClient obtained");
    }
  }

}

create an issue https://github.com/espressif/arduino-esp32/issues

https://github.com/espressif/arduino-esp32/issues/4399


text:
LoRa Ra-02 Module begin and beginPacket not working in Arduino Nano
Here there, recently I am testing Lora Ra-02 module I saw many videos and it is easy to set up, according to this schematic:

LoRa SX1278 Module-----Arduino Nano Board
3.3V-------
Gnd---------Gnd
En/Nss------D10
G0/DIO0------D2
SCK---------D13
MISO----------D12
MOSI----------D11
RST-------------D9

I am using a very common library called sandeepmistry. and I tried this code:
#include <SPI.h>
#include <LoRa.h>

int counter = 1;

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("LoRa Sender");
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);
  // send packet
  LoRa.beginPacket();
  LoRa.print("hello ");
  LoRa.print(counter);
  LoRa.endPacket();
  counter++;
  delay(500);
}

When I run it, it just sticks in this line {Serial.println("Starting LoRa failed!");}
Then I updated the code and tried to reduce the SPI Frequency because I am using Arduino Nano  now the code is this:
#include <SPI.h>
#include <LoRa.h>

int counter = 1;
int frequency = 8E6; // Set the desired frequency here

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("LoRa Sender");
  LoRa.setSPIFrequency(frequency); // Add the missing semicolon here
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);
  // send packet
  LoRa.beginPacket();
  LoRa.print("hello ");
  LoRa.print(counter);
  LoRa.endPacket();
  counter++;
  delay(500);
}

This code passes the line Starting LoRa failed! but it again stuck in here

LoRa Sender
Sending packet: 1

So why won't it do LoRa.beginPacket(); and loop the code? Why does it stop here?

Have you set the pins properly? Try doing:
  LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin

There is a problem with the way your SX1276 is connected to the board, which is why .begin() returns false.

By saying csPin - do you mean SS pin?? and irq - DIO0 pin?

From my experience, I was facing exact same error!!
After reviewing lot of forums and troubleshooting session, I've identified the root cause - I was connecting the Arduino Uno / Nano board to my laptop which was receiving a 5V supply. As Arduino boards (when connected to higher current source), always supplies 5V power from the 3.3V pin, in my case the LoRa module was receiving 5V power supply!! As the LoRa module can't handle the 5V power, it was throwing error.
After using a Level Shifter and connecting to Arduino Nano board, I was able to fix the error!!
Hoping my response would be helpful for someone facing similar issue!!

you have a board which has 5 V on pin labeled as 3.3 V pin? that is very wrong.

@Juraj - I've an official arduino board, can't say the incorrect pin issue.
However, It was mentioned in the Official Arduino forums that 3.3V pin emits 5V if connected to higher current - please follow this link - https://forum.arduino.cc/t/using-lora-with-arduino-nano/1266604

you misunderstood one or more things there. 1) io pins are 5 V. 2) 3.3 V pin can't supply enough current

FYI - https://forum.arduino.cc/t/using-lora-with-arduino-nano/1266604/15

@Juraj Could you please elaborate ?? if either 5V or 3.3V can't supply enough current, then why are we connecting 3.3V arduino pin with 3.3V pin LoRa ??

3.3V pin is the pin labeled 3.3, not any other pin. it is intended to power 3.3 V sensors but has limited power not suitable to power wireless transmitters

Tha main issue of LoRa is 1. Connection and 2. Powering.

@Juraj As you mentioned "3.3V pin is intended to power 3.3V sensor" - Agree on it..
You also mentioned - it is not suitable to power wireless transmitters - here do you mean it is not suitable to power LORA module ? If yes, this is exactly what I mean in my post..
And I want to understand the "reason" why you say it is not suitable to power wireless transmitter ? Is it because the 3.3V pin of Arduino supplies less power to wireless transmitters ? Or high power ?

you write "supplies 5V power from the 3.3V pin"