text:
ESP32 - error when using `LITTLEFS.h` after core updated to 2.0.4
After updating ESP32 to core version 2.0.4 (file in Arduino IDE preferences was replaced  tohttps://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json to upgrade), I get the following error:
/Users/guydvir/Dropbox/Arduino/libraries/LittleFS_esp32/src/LITTLEFS.cpp: In member function 'virtual bool LITTLEFSImpl::exists(const char*)':
/Users/guydvir/Dropbox/Arduino/libraries/LittleFS_esp32/src/LITTLEFS.cpp:44:28: error: no matching function for call to 'LITTLEFSImpl::open(const char*&, const char [2])'
     File f = open(path, "r");
                            ^
In file included from /Users/guydvir/Dropbox/Arduino/libraries/LittleFS_esp32/src/LITTLEFS.cpp:17:
/Users/guydvir/Library/Arduino15/packages/esp32/hardware/esp32/2.0.4/libraries/FS/src/vfs_api.h:38:17: note: candidate: 'virtual fs::FileImplPtr VFSImpl::open(const char*, const char*, bool)'
     FileImplPtr open(const char* path, const char* mode, const bool create) override;
                 ^~~~

I minimized code to headers only ( and empty setup and loop:
#include "FS.h"
//#include "LITTLEFS.h" // <----- commenting out stops the error message
#include <time.h>
#include <WiFi.h>
What may be the error and how to fix it ?

maybe uninstall the library. https://github.com/lorol/LITTLEFS#readme

@Juraj now after downgade back to 1.0.4 (still in new repository) it cant find $PATH for python.....

@Juraj see pic below

you have 2.0.4, not 1.0.4

@Juraj I'm trying to understand what have change between 1.0.4 to 2.0.4

@Juraj Thank you, problem solved

As you experienced, the Lorol's LittleFS_esp32 library was merged into ESP32 core from v1.0.6 and creates compile error to some old codes.
The difference is you have to use #include <LittleFS.h> instead of #include <LITTLEFS.h> for new cores (v1.0.6, v2.0.0+)
Check and modify the following snippet (used widely in my ESP_WiFiManager library ) for your purpose
// Check cores/esp32/esp_arduino_version.h and cores/esp32/core_version.h
//#if ( ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) )  //(ESP_ARDUINO_VERSION_MAJOR >= 2)
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) )
  #if (_WIFIMGR_LOGLEVEL_ > 3)
    #warning Using ESP32 Core 1.0.6 or 2.0.0+
  #endif

  // The library has been merged into esp32 core from release 1.0.6
  #include <LittleFS.h>       // https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS

  FS* filesystem =      &LittleFS;
  #define FileFS        LittleFS
  #define FS_Name       "LittleFS"
#else
  #if (_WIFIMGR_LOGLEVEL_ > 3)
    #warning Using ESP32 Core 1.0.5-. You must install LITTLEFS library
  #endif

  // The library has been merged into esp32 core from release 1.0.6
  #include <LITTLEFS.h>       // https://github.com/lorol/LITTLEFS

  FS* filesystem =      &LITTLEFS;
  #define FileFS        LITTLEFS
  #define FS_Name       "LittleFS"
#endif

As Juraj commented - no need for LittleFS_esp32 library, after upgrade to esp32 Arduino 2.0.4


text:
`time.h` vs `TimeLib.h` on AVR boards
Why do I get wrong result when using time.h library when using AVR boards, such Nano/Uno/Pro Micro (while when using TimeLib.h).
OUTPUT (for given Epoch ):
TimeLib: 2022-04-02 16:11:20
time.h: 0152-03-01 16:11:20
CODE:
#define CASE 1

#if CASE == 1
#include <time.h>
#elif CASE == 2
#include <TimeLib.h>
#endif

time_t bootTime = 1648915880;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("\nStart!");
  delay(1000);

  char clk2[40];

#if CASE == 1
  struct tm *tm = localtime(&bootTime);
  sprintf(clk2, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);

#elif CASE == 2
  sprintf(clk2, "%04d-%02d-%02d %02d:%02d:%02d", year(bootTime), month(bootTime), day(bootTime), hour(bootTime), minute(bootTime), second(bootTime));
#endif
  Serial.println(clk2);
}

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

localtime() requires a timezone to be set. No idea how you set that. Use gmtime() instead to get the UTC (GMT) time which has no timezone.

well for that, I guessed it'll take TZ=0, or any default, no-TZ value.

Never guess anything. The problem with these functions is they grew up on UNIX (or Linux) where the OS provides things like the selected timezone. How avr-libc handles these things I have no clue.

in time.h tm struct the year starts in 1900 and the moths are 0 to 11.

@Juraj, yes- that I know, but year 153 while we are 2022, strikes a bit odd. Also subtracting few seconds bootTime, yielded a non rational change in result.

You are assuming the avr-libc "epoch" is the same as the UNIX "epoch". It isn't. According to the manual:

Though not specified in the standard, it is often expected that time_t is a signed integer representing an offset in seconds from Midnight Jan 1 1970... i.e. 'Unix time'. This implementation uses an unsigned 32 bit integer offset from Midnight Jan 1 2000. The use of this 'epoch' helps to simplify the conversion functions, while the 32 bit value allows time to be properly represented until Tue Feb 7 06:28:15 2136 UTC. The macros UNIX_OFFSET and NTP_OFFSET are defined to assist in converting to and from Unix and NTP time stamps.

So you need to subtract the UNIX_OFFSET from your time value before passing it to any avr-libc functions.
Also you should initialize the time system with set_zone() and similar functions.

source: Stack Exchange

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

sort: votes


text:
PubSub'a - KeepAlive function not as expected
I'm using PubSubClient to pub/sub MQTT messages using ESP8266.
As far as I know "Keep-alive" detects when a client went off-line after a period of time.
I'm using library's example mqtt_ESP8266 with 2 minor adjusments (noted "<----- 1/2"), to use keepAlive.

Timeout was set to 45 sec (client.setKeepAlive(45);), in order to be "far enough" from reboot.
Pressing on-board Reset button.
Although Wifi+MQTT connection establish after 10 sec, and mqtt sends messages as shown loop, a "DEAD" publish is sent to designated topic after roughly 45 seconds from (2) , whuch makes no sense since MQTT was reconnected 35 seconds before.

Appreciate assistance,
Guy
/*
  Basic ESP8266 MQTT example
  This sketch demonstrates the capabilities of the pubsub library in combination
  with the ESP8266 board/library.
  It connects to an MQTT server then:
  - publishes "hello world" to the topic "outTopic" every two seconds
  - subscribes to the topic "inTopic", printing out any messages
    it receives. NB - it assumes the received payloads are strings not binary
  - If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,
    else switch it off
  It will reconnect to the server if the connection is lost using a blocking
  reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
  achieve the same result without blocking the main loop.
  To install the ESP8266 board, (using Arduino 1.6.4+):
  - Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":
       http://arduino.esp8266.com/stable/package_esp8266com_index.json
  - Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
  - Select your ESP8266 in "Tools -> Board"
*/

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.

const char* ssid = "Wifi";
const char* password = "Password";
const char* mqtt_server = "192.168.2.100";

WiFiClient espClient;
PubSubClient client(espClient);
unsigned long lastMsg = 0;
#define MSG_BUFFER_SIZE (50)
char msg[MSG_BUFFER_SIZE];
int value = 0;

void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

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

  randomSeed(micros());

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

  // Switch on the LED if an 1 was received as first character
  if ((char)payload[0] == '1') {
    digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
    // but actually the LED is on; this is because
    // it is active low on the ESP-01)
  } else {
    digitalWrite(BUILTIN_LED, HIGH);  // Turn the LED off by making the voltage HIGH
  }

}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
    client.setKeepAlive(45);  \\ <--------- Line 1
    if (client.connect(clientId.c_str(), "guy", "kupelu9e", "myHome/log", 0, true, \\ < "DEAD")) { \\ <---- Line 2
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish("outTopic", "hello world");
      // ... and resubscribe
      client.subscribe("inTopic");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void setup() {
  pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}

void loop() {

  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  unsigned long now = millis();
  if (now - lastMsg > 2000) {
    lastMsg = now;
    ++value;
    snprintf (msg, MSG_BUFFER_SIZE, "hello world #%ld", value);
    Serial.print("Publish message: ");
    Serial.println(msg);
    client.publish("myHome/debug", msg);
  }
}

This is the correct behavior.
The “last will” message is sent by the broker when it detects that the client has gone away.
When you reset the ESP8266, the original connection to the broker is destroyed. When it restarts, it creates a new, second connection, it does not resume the original connection. So the broker correctly transmits the last will message when the original connection times out.

even it connects in same client ID ? so what's the point?

The point is to notify other clients when a client terminates without disconnecting. The client ID is irrelevant unless you use a session with MQTT 5. Both the client and broker must support MQTT 5 for that to work; in that case, if the client reconnects before the “last will delay”, the will won’t be sent. pubsubclient does not support MQTT 5.

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


text:
ESP32- Sporadic slow receive of MQTT messages
Problem description: Every ~20+ published messages (using terminal), MCU receives that message in a very noticeable delay (mostly ~10 sec, few time it got up to 1 min). Upon receive (printed in Serial monitor), MCU is working as expected.
Hardware: ESP32 DEVKIT MCU, PubSubClient.h for MQTT and WiFi.h for WiFi.
Important remark: Code is same for ESP8266 and ESP32.This behavior happens only on ESP32.
Question: Does ESP32 has a know issue regarding receiving MQTT messages? is there a workaround? or perhaps- bug in code?
What did I do to try isolating the problem:

Tried on 3 different ESP32s (2 DEVkit MCU, and 1 with relays on board) - same behavior - it is not an specific MCU hardware problem.

Used another PC to publish MQTT messages (via terminal. MAC and Linux, and a 3rd party MQTT App)- no change. It has nothing to do with publishing platform.

To rule out it may be a MQTT broker's fault (Local RPI3 connected using LAN cable)- Subscribing to that topic in order to see if the delay repeats . MQTT server receive pubs on time. Broker responds on time (while waiting to see when publish is received in Serial monitor).

adding a flashing LED every 200ms in loop(), to verify that MCU is not get stuck in a process. loop() is looping as expected (see in code below).

Spitting heap free memory to Serial monitor, in order to see if there is some memory issue, degradation. Nothing suspicious.

Code simplification- used code segments from ESP32 wifi and MQTT pubsub's example, while disabling every functionality of original code(with and without). Delay still happens sporadically.

OUTPUT1- sending "0" and "1" almost simultaneously,  almost 15 sec delay
13:31:21.516 -> Message arrived [myHome/test] 0 <--- right after this, "1" was sent
13:31:22.510 -> 278616 <---- free heap size (send every 1000 ms. non-blocking)
13:31:23.570 -> 278616
13:31:24.630 -> 278616
13:31:25.657 -> 278616
13:31:26.718 -> 278616
13:31:27.778 -> 278616
13:31:28.805 -> 278616
13:31:29.866 -> 278616
13:31:30.926 -> 278616
13:31:31.954 -> 278616
13:31:33.014 -> 278616
13:31:34.075 -> 278616
13:31:35.102 -> 278616
13:31:35.964 -> Message arrived [myHome/test] 1 <--- received 15 sec later

OUTPUT-2: Code
#include <WiFi.h>
#include <PubSubClient.h>

WiFiClient espClient;
PubSubClient client(espClient);

const char *mqtt_server = "192.168.2.100";

void setup_wifi()
{

        delay(10);
        // We start by connecting to a WiFi network
        Serial.println();
        Serial.print("Connecting to ");
        // Serial.println(ssid);

        WiFi.mode(WIFI_STA);
        WiFi.begin("iot", "GdS");

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

        Serial.println("");
        Serial.println("WiFi connected");
        Serial.println("IP address: ");
        Serial.println(WiFi.localIP());
}

void callback(char *topic, byte *payload, unsigned int length)
{
        Serial.print("Message arrived [");
        Serial.print(topic);
        Serial.print("] ");
        for (int i = 0; i < length; i++)
        {
                Serial.print((char)payload[i]);
        }
        Serial.println();

        // Switch on the LED if an 1 was received as first character
}

void reconnect()
{
        // Loop until we're reconnected
        while (!client.connected())
        {
                Serial.print("Attempting MQTT connection...");
                // Create a random client ID
                String clientId = "ESP8266Client-";
                clientId += String(random(0xffff), HEX);
                // Attempt to connect
                if (client.connect(clientId.c_str()),"guy","kupelu9e")
                {
                        Serial.println("connected");
                        // Once connected, publish an announcement...
                        client.publish("myHome/log", "hello world");
                        // ... and resubscribe
                        client.subscribe("myHome/test");
                }
                else
                {
                        Serial.print("failed, rc=");
                        Serial.print(client.state());
                        Serial.println(" try again in 5 seconds");
                        // Wait 5 seconds before retrying
                        delay(5000);
                }
        }
}

void setup()
{
        Serial.begin(115200);
        setup_wifi();
        client.setServer(mqtt_server, 1883);
        client.setCallback(callback);
        reconnect();
}
void loop()
{
        loop_buttons();
        if (!client.connected())
        {
                reconnect();
        }
        client.loop();
        static unsigned long lastentry = 0;
        static unsigned long lastentry2 = 0;
        if (millis() - lastentry > 200)
        {
                pinMode(2, OUTPUT);
                digitalWrite(2, !digitalRead(2));
                lastentry = millis();
        }
        delay(50);
        if (millis() - lastentry2 > 1000)
        {
                Serial.println(ESP.getFreeHeap());
                lastentry2 = millis();
        }
}

The code you posted does not compile as there is no loop_buttons().

@StarCat You are right. It is a left over. Please comment it out.

guyd, did the answer help?

I have a very similar problem - but I use ESP8266 (observe it on different types - NodeMCU, ESP-01S etc).  I cleaned up  MQTT callback - no use of Serial there (tried to follow what was suggested by Accomation below) - no success.

In case somebody finds this when faced with the same issue:
I had a similar problem on a Pico W. Turned out that the Serial.println()s in the MQTT callback clobbered the MQTT+WiFi stack. Something did not multitask nicely. Not accessing the Arduino Serial port in the MQTT callback fixed it.


text:
`ConfigTime` daylight saving update
I'm using an ESP8266 to get clock NTP sync in this manner:
void myIOT2::_startNTP(const int gmtOffset_sec, const int daylightOffset_sec, const char *ntpServer)
{
    configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); //configuring time offset and an NTP server
    while (now() < 1627735850)                                /* while in 2021 */
    {
        delay(20);
    }
    delay(100);
}

But now, when daylight saving ended on 31/10/2021, what "flags" code that now daylight saving has ended, and 3600 sec have to reduced (or add) ?
in my case gmtOffset_sec=2*3600 and daylightOffset_sec=1*3600 ntpServer="pool.ntp.org"

the SDK adjusts automatically. I use only configTime(TZ_Europe_Bratislava, "pool.ntp.org"); TZ constants are in TZ.h  in esp8266 core

@Juraj I guess that ‘TZ_Europe_Bratislava’ encapsulates similar constants as mine. But still my time sync hasn’t updated

the DST info is not from the NTP server. my esp8266 clock changed time at 3 AM to 2 AM, but it syncs with NTP only once a day

@Juraj I used my TZ constant, and it worked as you said. Can you please explain why my method did not work as needed?

@Juraj What should I do in ESP32 ?

@Juraj NTP was not shifted as needed

@Juraj TNX, and that relates to my question about ESP32 ( since TZ.h belongs to ESP8266.h)

the esp32 has the configTzTime function for timezone. it is missing the TZ.h file. you can copy the TZ.h file or only the string with zone definition for your time zone.

For reference: https://github.com/esp8266/Arduino/blob/14c3798d4ff959254599f2904579412acba3f175/cores/esp8266/TZ.h#L338

Summing @juraj's comments

instead of defining UTC+x and Daylight offset, using NTZ instead.

While ESP8266 has `TZ.h as part of its core I used relevant TZ as shown.

for ESP32: a) replace to configTzTime as shown. b) Copy relevant TZ from TZ.h for current lib and use as follows.

for ESP8266:
configTime(TZ_Asia_Jerusalem, ntpServer);
for ESP32:
configTzTime(TZ_Asia_Jerusalem, ntpServer); // Tz value was copied to code


text:
Timers, PWM pins and digital outputs on Arduino Mega
I'm using an Arduino Mega to control motors via PWM and Adafruit DRV8871 motor drivers.  I also use TIMER1 for a timed interrupt.  After adding the TIMER1 interrupt I discovered I had problems with motor control, which I finally tracked down to using pins 11 & 12 for PWM simultaneously with using TIMER1 for timed interrupts.
My initial thought was to change the timer used for the ISR to avoid the pin 11/12 conflict, but now I'm uncertain as to what the restrictions are for using pins associated with timers.  I now realize that pins associated with a timer interrupt can't be used for PWM using analogWrite(int val), but can they be used as general purpose digital outputs?
For instance, if I change from TIMER1 to TIMER0 for my timer interrupt, that appears to change the pin dependency from 11/12 to 4/13.  I don't use pin 13, but I do use pin 4 as a digital output.  Will using pin 4 as a digital output still work properly?
TIA,
Frank

Are you sure you are using an Arduino Mega? pins 11 and 12 aren't PWM pins on the mega. Only on the UNO. The Mega has like 6 timers, so you'd have plenty to choose from, to avoid conflicts.

You can use them for any purpose other than PWM.  You can even use them for PWM as long as the settings for the timer allow you to produce the waveform you want.
The reason PWM broke was that you had changed the settings for the timer.  The timer is what controls the PWM.  When you changed those settings you either turned the PWM function off or set some setting where it wouldn't work.  Then the pins associated with that timer didn't get PWM anymore.  You can do anything else you want that doesn't involve the timer including use the pin for input or output or any other special function it has not related to the timer.
If you change the timer interrupt to TIMER0, then you run the risk of delay, millis, and micros stop working right.  They depend on the TIMER0 overflow interrupt running at a set interval to count time.  It depends on how you set the timer up.
I would suggest you do some reading on how these timers work.  The Datasheet for the ATMega328P chip is a great place to start.


text:
Why am I getting an 'invalid conversion' error on compile?
I have one of these NodeMCU ESP8266 OLED Arduino Wifi Modules which I am trying to load with SpaceHuhn's deauther software from Github
I am trying to compile the source code using Arduino IDE with the display enabled and have followed the instructions to do so from github repository here.
I initially downloaded the latest software but as I didn't know which display option to enable before compiling, I went for an earlier version, v1.6, which has a video on how you are supposed to install it on YouTube.
After uncommenting line 18 from:
//#define USE_DISPLAY /* <-- uncomment that if you want to use the display */
so that it reads:
#define USE_DISPLAY /* <-- uncomment that if you want to use the display */
and then trying to compile, I get this error:
D:\Documents\Innovateking-EU Nodemcu ESP8266\Deauther\esp8266_deauther-v.1.6\esp8266_deauther\esp8266_deauther.ino: In function 'void setup()':

esp8266_deauther:592:32: error: invalid conversion from 'const char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

   display.setFont(Roboto_Mono_8);

In file included from D:\Documents\Arduino\libraries\esp8266-oled-ssd1306-master\src/SSD1306Wire.h:34:0,

                 from D:\Documents\Arduino\libraries\esp8266-oled-ssd1306-master\src/SSD1306.h:33,

                 from D:\Documents\Innovateking-EU Nodemcu ESP8266\Deauther\esp8266_deauther-v.1.6\esp8266_deauther\esp8266_deauther.ino:28:

    D:\Documents\Arduino\libraries\esp8266-oled-ssd1306-master\src/OLEDDisplay.h:243:10: error:   initializing argument 1 of 'void OLEDDisplay::setFont(const uint8_t*)' [-fpermissive]

     void setFont(const uint8_t *fontData);

Multiple libraries were found for "SSD1306.h"
 Used: D:\Documents\Arduino\libraries\esp8266-oled-ssd1306-master
 Not used: C:\Users\cos\AppData\Local\Arduino15\packages\deauther\hardware\esp8266\2.0.0-deauther\libraries\esp8266-oled-ssd1306-4.0.0
exit status 1
invalid conversion from 'const char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

The youtube video shows the process working, assuming nothing was edited out....  As far as I can see I have done everything the same.
Has anyone had any experience of loading this on to these boards?  Or know what the problem is?

It looks like the font data being used in that code (I haven't found where that is yet) isn't the right data type.  Probably a conflict between old code and new libraries.  You want to get the newest code working with the newest libraries.

esp8266 core in 2.5.1 changed char to unsigned as default, so it looks like you use some older version of the core

So what is the best course to fix this?  Use an earlier version of esp8266-oled-ssd1306-master. I cannot use a later version of deauther as there doesn't appear to be an option for a oled display...I can compile it but the display does not work!!

go in the data.h TAB
find : const char Roboto_Mono_8[] PROGMEM = {
and replace with : const uint8_t Roboto_Mono_8[] PROGMEM = {
Voilà


text:
Where is tcp.c?
This question is related to my other question, which I already answered.
I want to add modify tcp.c to include my own code. The problem is I can't find tcp.c. The first thing I tried was looking in the same directory as tcp.h (C:\Users\Me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip2\include\lwip\tcp.h) but there is no tcp.c file there. So then I tried every tcp.h file on my c: drive.
c:\>dir *tcp.c /s
c:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\wifishield\wifiHD\src
c:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\wifishield\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\LWIP\lwip-1.3.2\src\core
c:\Program Files (x86)\Arduino\libraries\WiFi\extras\wifiHD\src
c:\Program Files (x86)\Arduino\libraries\WiFi\extras\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\LWIP\lwip-1.3.2\src\core
c:\Users\Me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip\src\app
c:\Users\Me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip\src\core
c:\Users\Me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip2\builder\glue-lwip

and it's none of those. I assume this because I deleted everything in those files and my program still runs and builds. Now I don't know what to do. Am I right in assuming the file would be called tcp.c? If so why doesn't it seem to be any of the tcp.c files on my computer?

most of the LWIP library versions in esp8266 package are provided as already compiled  .a (esp8266/hardware/esp8266/2.5.2/tools/sdk/lib/liblwip2-1460.a) and without source code. source code esp8266/2.5.2/tools/sdk/lwip/src

Thanks. How did you know that? What can I do if I want to modify and rebuild the source?

the lwip folders contain make files


text:
Where is tcp.h?
This is for an esp8266 project that uses EasyAsyncTCP. In EasyAsyncTCP.cpp they   #include "lwip/tcp.h". But I can't figure out where that file is. I've found a tcp.h in the following directories on my c drive:

c:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\wifishield\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\LWIP\lwip-1.3.2\src\include\lwip
c:\Program Files (x86)\Arduino\libraries\WiFi\extras\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\LWIP\lwip-1.3.2\src\include\lwip
c:\Users\me\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\tools\sdk\include\lwip\lwip
c:\Users\me\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\tools\sdk\include\lwip\lwip\prot
c:\Users\me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip\include\lwip
c:\Users\me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip2\include\lwip
c:\Users\me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip2\include\lwip\prot

but so far I've only tested the first two. I've tested them by either straight up deleting the directory and using the #error got here directive. No matter what I do my project builds. So I think I must either have the wrong file or it doesn't rebuild the entire thing.
How can I determine which tcp.h my program is including?

do you see the esp8266 folders. one of them it is. LWIP version is selected in Tools menu

yes! thank you.

While this isn't the right way of doing it I'm sharing the way that I figured it out.
Step1:
cd c:\
dir tcp.h /s
c:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\wifishield\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\LWIP\lwip-1.3.2\src\include\lwip
c:\Program Files (x86)\Arduino\libraries\WiFi\extras\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\LWIP\lwip-1.3.2\src\include\lwip
c:\c:\Users\Me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip2\include\lwip\protUsers\Me\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\tools\sdk\include\lwip\lwip
c:\Users\Me\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\tools\sdk\include\lwip\lwip\prot
c:\Users\Me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip\include\lwip
c:\Users\Me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip2\include\lwip
Step2:
I went through and tested each one. It was... C:\Users\Me\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\tools\sdk\lwip2\include\lwip\tcp.h


text:
Can you program an ESP32 with an Arduino?
I've done it with an ESP-8266 but can't find any articles on how to do it with an ESP-32. I'm working with an ESP-32 on my own PCB, not a dev board. I exposed:

3V3
GND
EN
TX
RX
IO0

I'm pretty sure I can use a standalone programmer but I was expecting to be able to do it with an Arduino. Is that possible? ...if it's super difficult to do like setting up a toolchain and all that I'd rather just spend $10 and get a programmer.

it is the same as with esp8266. there is no programmer.


text:
ESPAsyncWebServer how do you escape the % character?
% characters are used for template processing but I want it to just send the % through. How do you tell it to do that?

Can you please add some more context. Thanks.

You'd use %% to get a single % as output.
From the source code: double percent sign encountered, this is single percent sign escaped.

Thank you. Biyaaaaaa!


text:
How can I upload a sketch remotely from a distant location onto an arduino that is power by a battery
Of course after developing a success full embedded product the next step would be making upgrades to compete favorably with new products in the market. Well making upgrades would require making adjustments in the sketch and Uploading it onto already made prototypes to cub the costs involved in by the hardware of a remotely located prototype. How can one upload a sketch from his location on to the prototype without going there psychically to upload through the port?

Battery powered devices need a system where the device checks over Internet connection (WiFi, mobile) if a new firmware bin file is available on a specific location on a server. If the bin file is available the device can download it and apply.
One option how to apply the new bin is to use SD card and SD bootloader (Zevero avr_boot) The sketch saves the downloaded file on SD card and resets the MCU. The SD bootloader then loads the binary from the SD card to flash.
Other option if enough free flash memory is available is to use the InternalStorage object from ArduinoOTA library. It uses the upper half of the flash memory to store the uploaded bin and then activates a modified Optiboot to copy the bin to run location and reset the MCU.

I  have options i think all i have to do is do some reading and seek out examples then i could do what ever i want to do. Thanks once again Im grateful for the information let me look out for the examples then I am sure I will be good to go then

First you have to establish communication between Arduino and your computer. This communication could be wire (ex. LAN) or wireless.
Like Juraj said, you could use ArduinoOTA with an additional WiFi or Ethernet module on your Arduino, as long as arduino is connected to the network and you know its address. I haven't tried it yet, so I don't know its reliability. Even so, it helps your problem

so why do you write an answer if you didn't test it?

I do not really know but its as if a few people or none have tried it. I really cannot afford wasting my money on unneccessary hardware if its not really worth a try. I wish i could get a clear highlight or possibility on how it would be done

@Sigma, the library has 38 stars  on GitHub in 1 year of existence even it is downloadable from Library Manager so most users don't have to go to GitHub. there are a few arduino forum threads where people ask for assistance to make it work and all were successful. right now here https://forum.arduino.cc/index.php?topic=629780.msg4421977#msg4421977

@Juraj This is helpful I am going to give it a shot


text:
Is there some hardware that can be used to upload sketch source code via USB flash disk (Automatically By plugging it in)
Well am asking this basically to know if it is possible to create a bootable flash drive that automatically uploads any source code onto the arduino just like creating a bootable flash drive when installing windows operating system on a computer. I will be happy to get some cool responses that would be helpful thanks.

There is a solution with SD card and SD bootloader. You put a bin file on SD card, insert it into the SD adapter and power up the Arduino. The bootloader loads the bin file to flash memory.
I use 'avr_boot' SD bootloader by Zevero. It reads a file named firmware.bin from SD card if present and loads it into flash.
To generate a bin file for Arduino AVR boards add to platform.txt
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" -O binary {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"

I use this with the ArduinoOTA library which uploads the bin file from IDE to the SD card over network and then resets the MCU for the bootloader to apply the bin.
btw: the ArduinoOTA library can use the upper half of the flash memory too to store the uploaded bin and then activate a modified Optiboot to copy the bin to run location and reset the MCU.
UPDATE 2022: new advanced example for my ArduinoOTA library: load hex from SD card

Could you please provide a link were i could get more information about how it can be done with ease or if possible please

@Sigma, sorry, I forgot to link the Zevero bootloader. fixed. the link is in answer.

There is no specific piece of hardware that does what you ask.
There are various options though:

Write a new bootloader that uses the USB Host Shield to load data from a USB MSD device then flash it to the internal flash of the MCU (hard to do if you don't know low-level programming)
Use an embedded Linux computer (Raspberry Pi, etc) to run avrdude and flash your Arduino like it's a connected to a computer
Use an Arduino that has a Linux portion to it (such as the venerable Arduino Yun) or a shield that provides a similar function (Dragino Yun Shield) to flash the AVR chip from Linux
Don't use an Arduino at all, but use an embedded Linux computer for everything.

Thanks for the comment though it really seems tough to me its like I have a lot of reading and practice that I have to do. Isn't there any easier way that can by pass Linux some how?

Not without writing lots of software and learning how the USB host shield works, how flashing the chip works, and other such low-level functionality.


text:
Can connect to esp8266 AP which is connected to Arduino UNO but no response
I am new to arduino and am trying to connect the esp8266 to arduino UNO and send commands to the arduino using an android phone.
I have double, triple checked the connections and I am sure they are 100% correct. I have connected esp GND to arduino GND, esp VCC to arduino 5V, esp TX to arduino SoftwareSerial RX and esp RX to arduino SerialSoftware TX and CH_PD to 5V. I can connect to esp using my phone but I can't send commands to it. I am using TCP/UDP Terminal on android to test the connection. Phone is connected to the AP but in the app it is not. I configured the app with 192.168.4.1 IP and 333 Port and I know that app works correctly because I have tested its integrity several times before.
I have searched so much and tried so many but non worked.
My code:
#include <SoftwareSerial.h>
SoftwareSerial ESP8266(2,3);

boolean FAIL_8266 = false;

#define BUFFER_SIZE 128
char buffer[BUFFER_SIZE];

void setup() {

  Serial.begin(9600);
  ESP8266.begin(115200);  // change this value to your wifi module (esp8266) baud rate

  do{
  ESP8266.println("AT");
    delay(1000);
    if(ESP8266.find((char*)"OK"))
    {
      Serial.println("Module is ready");
      delay(1000);

      //configure ESP as AP
      Serial.println("AT+CWMODE=2");
      delay(1000);

      //Set multi connections
      Serial.println("AT+CIPMUX=1");
      delay(1000);

      Serial.println("Server setup finish");
      delay(1000);

      FAIL_8266 = false;

    }
    else{
      Serial.println("Module have no response.");
      delay(500);
      FAIL_8266 = true;
    }
  }while(FAIL_8266);

  ESP8266.setTimeout(100);

}

void loop() {

  if(ESP8266.available()){
    String msg = ESP8266.readString();
    Serial.println("MSG: "+msg);
  }
}

Could anyone please tell me what is wrong?

You can't use SoftwareSerial reliably at 115200 baud. The Arduino just can't keep up with the speed to the data coming in. That said, you should write a simple serial echo program to allow you to communicate with the esp8266 manually via the Arduino to test that communication is actually happening.

@Majenko Thanks about the answer, I did a little research about what you said on the internet and it looks correct. I have read about changing the esp8266 baudrate to a lower amount but I didn't do it because many have reported that doing it have bricked their esp8266. Now, do you have anything in mind to fix the problem?

You really want to reduce the ESP8266 baud rate. You should get yourself set up for reflashing the ESP8266 first though. It's something you should get into anyway - it's far more efficient writing software to run directly on the ESP8266 rather than struggling with a ropey AT command set.

@Majenko I flashed my esp8266 and now it is working. Thanks for the Assist.

it's virtually impossible to brick an esp; all you need to do is put it in flash mode and reflash.


text:
How to set PC (Program Counter) register to another function (for scheduler)
I am trying to implement a scheduler for Arduino Mega 2560. I think I lack understanding of how to set the PC register to another instruction.
Here is my simple approach so far:
void dummy(){
    digitalWrite(LED_BUILTIN, HIGH);
 }

in a naked ISR method:
SP = (uint16_t)(&dummy)
__asm volatile(
"reti     \n\t"
)

However it is not working. How should the PC register be set to a certain function or to where it was in a previous process for a scheduler approach?

This:
SP = (uint16_t)(&dummy)

is changing the stack pointer. Not what you want. You want to instead
push the destination address to the stack. However, rather than
simulating a function return, it should be simpler to perform an
indirect jump:
asm volatile("ijmp" :: "z"(dummy));

Don't forget that your naked ISR has to save all the call-used
registers, as well as SREG, r0 and r1, in its custom prologue. And
restore them in its epilogue. Check the AVR calling
conventions.

Thanks for you fast answer, I am saving all registsers r0, ..,r31 and SREG to the stack, however I am not sure how I can save the PC into the stack and reload it.

@MustafaOtbah: The PC was already saved by the interrupt. You normally restore it with reti. Maybe you should expand your question and explain in more detail how you intend to manage saving and restoring task context, what you have done so far, and what is not working.


text:
Can I use only Ruby or Crystal Lang with an Arduino?
I am new to Arduino. I have used other SBCs before and ran some ruby script to automate many tasks.
I know Ruby and Crystal programming languages.
Can I use Ruby or Crystal solely on Arduino for creating basic robot?

Short answer: No

Long answer: Noooooooooooooo.

You could bridging via Firmata: https://playground.arduino.cc/Interfacing/Ruby/
Another resource is https://code.tutsplus.com/articles/using-ruby-to-program-arduino--cms-21893
You will need to Flash your Arduino with Firmata and then program in Ruby.
I'm not sure if that would work with Crystal.

No. You cannot. It is not possible. And some more filler to make the answer long enough.


text:
Sending Integer > 1 Byte from Android to Arduino over Serial
I´m using
public abstract void write(int b) throws IOException;

from class OutputStream on Android Studio to sent Integer (degrees from 0 to 360) to the Serial Port of my Arduino over HC06 Bluetooth module.
Degrees from 0 to 256 are read well by using
 int angle = Serial.read();

Values over 256 (1 Byte) are received as 0 are something weird.
I tried using
 Serial.parseInt();

as it should return an long int but all I get is one digit mostly 0.
I also tried using
Serial.readBytes(threeDigitsInt, 3);
angle = (threeDigitsInt[0] * 100) + (threeDigitsInt[1] * 10) + threeDigitsInt[2];

but I cannot tell what ends up in the array. Definitly not the correct single digit. I tried char[] and byte[] but I´m not able to reconstruct my send Integer value.
Summary: I want to send 360 as Integer from Android and have it as Integer on Arduino.
Appreciate your help!

You are only sending one byte from 0 to 255. Read the manual. https://developer.android.com/reference/java/io/OutputStream.html#write(int)

Ok. I see you´re right!
Can you help me parse that int angle into an byte b [ ] so I can use the
   public void write(byte b[]) throws IOException {
        write(b, 0, b.length);
    }

You can't just throw data randomly at a serial connection. You need to have some kind of format so the receiver knows what byte is what.

Hm. I mean the format is recognized well on Serial.read()

First off, you are only sending one byte from Android:

public abstract void write (int b)
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

OutputStream.write(byte) can never write more than one byte.
Also it's clear you have no clue about what format the data is sent in if you are trying to then read 3 bytes and use Binary Coded Decimal to reconstruct it.
Instead I suggest you work in a purely ASCII format. Forget bytes. Bytes are not what you want, unless you feel like spending some extra time defining, and then implementing, your own protocol.
Start by formatting your data into an ASCII printable string.  If Android Java is anything like normal Java I'd start by turning your integer into a string with proper line endings.  Something like:
String val = String.format("%d\n", angle);

Then get the bytes that represent that formatted string:
byte[] valBytes = val.getBytes();

Now you have a valid byte array containing your textual representation of the data that you can send with OutputStream.write(byte[]).
Now your task is to read that data on the Arduino.  That means reading each byte that arrives in turn storing it away in some form until you receive the \n line ending.  At that point you can take each byte as a string and convert them into an integer again.
It's possible to do that on the fly:
static int angle = 0;

if (Serial.available()) {
    char c = Serial.read();
    if (c == '\n') {
        Serial.print("I got: ");
        Serial.println(angle);
        angle = 0;
    } else if ((c >= '0') && (c <= '9')) {
        angle *= 10;
        angle += (c - '0');
    }
}

Basically, have a variable that stores the incoming angle. For each character that arrives on the serial port - if it's a line ending \n then do whatever with the angle value. If it's a character between 0 and 9 then multiply your angle by 10 (decimal shift left), convert your character to the equivalent integer by subtracting character '0', and add it to your angle.

Angle does not receive any value?

Maybe Android is sending things differently. You should first confirm exactly what is being sent by Android.

Also test the Arduino separate from Android. If it works using the serial monitor by typing in numbers then the Arduino code is fine.

Alright thanks a lot. I´ll take my time and try it today!


text:
How can I measure if a battery is there?
With my arduino I want to measure if one / two AAA batteries are in their single / double battery holder.
When the Arduino is running, connected to some other power supply and the batteries are in place everything is fine: I get my measurements of around 1.5V / 3V on the analog pin the battery is connected to (- of battery and Arduino GND are connected as well of course).
Problems arise when I either
a) pull the batteries out: The analog pin is left floating. Not good. Can I put the pin into INPUT_PULLUP mode? Is the internal resistor big enough? Or will the then connected 5V damage my batteries when they are back in the battery holder?
b) dissconect the Arduino from its external power supply: Because the Arduino is then "powered" by the 3V through the analog pin my blinking LED keeps blinking (at less brightness, but still...). I neither want the batteries to get drained nor damage my Arduino with it. So I would like to avoid this.
Actually I don't care about the actual battery voltage - I just want to know if the batteries are in their holder or not. And I want to leave the batteries there even though the Arduino is not powered. I would even consider something like "a button is held down when a battery is in its holder" or any other (simple) creative ideas.
Is this possible? How?

do you want to use batteries as a [backup] power source or not ? if not (and you didn't connect the + of batteries to arduino supply line), why the arduino is powered by them when you disconnect the main power source in section b of your question?

@Tirdad Sadri Nejad That is a parasitic current through the input pin. Not good for the microcontroller.

I see 1 main problem: Keeping the batteries isolated, so that no current flows between them and the Arduino (especially no parasitic current into the input pin of a turned off Arduino), while still reading a voltage level (HIGH or LOW).
I would suggest using a fitting N-Channel MOSFET. Connect the minus pin of the batteries to ground and the plus pin to the gate of the MOSFET. Then source and drain of MOSFET to ground and a digital arduino pin respectively. Enable the internal pullup resistor. Add a pulldown resistor between gate and ground.
Now, without the batteries, the gate is at ground level, so the MOSFET is not conducting. The level at the input pin will be high. If the batteries are in, their voltage will activate the MOSFET, which pulls the Arduinos input pin to ground, thus LOW level. Since the MOSFET is somewhat like a capacitor between gate and the rest, almost no current will flow here (only enough to load the small capacitance). Though I'm not sure, I think that no current will flow either in the case of the Arduino being unpowered.
The task now would be to find a fitting MOSFET, which goes in saturation for 1.5V.
Of course you can also use a microswitch, that gets pushed down by the batteries. That is electronically easier, but maybe mechanically challenging.

Sounds reasonable, thanks! I tried to draw a schematic off your instructions: https://i.ibb.co/pW7n4D6/sch.png Is that what you thought of?
Now I go find a MOSFET and try it :-)

Almost. I intended to connect to a digital pin instead of an analog one, since you only need information, if there are batteries or not. Doing this electrically also means, that empty batteries are like no batteries.

I built this circuit with a "ZVN3310A", a 560k Pulldown and internal pullup. Seems to work :-)
For the one-battery-version I had to measure the analog value though, because the transistor I got has a VGS(th) of 0.8 to 2.4V and the 1.5V of a single battery were just not enough to make the transistor fully conductive (I had no other transistor available). But it conducted enough to get the analog value from about 1000 (no battery) to about 700 (1.5V battery).
All LEDs stay off even with a 3V battery when no power is connected, so I guess there is no (significant) parasitic current.

Yes, I assumed a transistor, that would be already fully conductive for 1.5V, but if you don't have a better transistor, using analog input is also fine.

You could add a pulldown to the analog pin. If the ADC reads a value below e.f. 10, you could consider this the state when there are no batteries.
From the signal perspective a pullup would be better, because without batteries you would read 5V which is unambigous as it can not be provided by the batteries themselves. But in general I don't think that applying higher voltage to the batteries is good practice, even though you could limit the current with a reasonably high resistor.


text:
pulseIn only returning 0
I'm new to arduino and I've searched through a lot of posts but can't find anything to fix the issue.
I'm trying to send a signal through some medium (water in this example) using a pizoelectric transducer and measure the time it takes for the signal to go from transducer to the other.
Attached is an image of the setup. Below is the code.
const int trigPin = 1;
const int echoPin = 0;
float duration;

void setup() {
  pinMode (trigPin, OUTPUT);
  pinMode (echoPin, INPUT);
  Serial.begin (9600);
}

void loop() {
  // set transmitting pin to low
  digitalWrite (trigPin, LOW);
  delayMicroseconds (2);

  // send the signal
  digitalWrite(trigPin, HIGH);
  digitalWrite (trigPin, LOW);

  // read in the signal on receiving pin, print duration to the Monitor
  duration = pulseIn (echoPin, HIGH);
  Serial.print("duration: ");
  Serial.print(duration);
  Serial.print("\n");
}

The issue is "duration" variable has been 0 in all of my tests. I've tried using various values for the timeout parameter in pulsIn to no avail. Any advice is appreciated.

There are a few issues here.
The most obvious is that you are using the wrong pins. On the Arduino
Uno, digital 0 is the serial RX pin, and digital 1 is TX. Thus, if you
use Serial in your sketch, you cannot use these pins for anything
else.
At a more fundamental level, it looks from your picture that you have
connected your Arduino to a couple of bare piezo transducers. Your code,
on the other hand, assumes the Arduino is connected to a digital sonar
module, like the very common HC-SR04. You have to keep in mind that
a piezo transducer is an analog device. The sonar module, on the other
hand contains quite a few electronic parts that take care of
conditioning the analog signals and providing an easy to use digital
interface, where you just have to call pulseIn() to get the
measurement.
If you want to use the bare piezo transducers, the first thing you have
to do is read their datasheet. This is really essential. Once you have
read (and understood) that document, you can figure out whether or not
you need some interface electronics between the piezos and your Arduino.
Maybe you can get away with exciting the transmitter with PWM and
reading the receiver with the on-board ADC. Or maybe not. First read the
datasheet, then design your circuit, then test using a scope to look at
your signals.


text:
Nodemcu single server with 2 clients
I am trying to connect my nodemcu server with 2 nodemcu clients. One client is connected and it works perfectly. I am unable to configure what to do for the other client to be connected and share data through server.
Server Code
/*
Geekstips.com
IoT project - Communication between two ESP8266 - Talk with Each Other
ESP8266 Arduino code example
*/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// IoT platform Credentials
String apiKey = "PBD5LAJC4BSV3OKC";
const char* logServer = "api.thingspeak.com";

// Internet router credentials
const char* ssid = "Dhamaal";
const char* password = "03334204224";

ESP8266WebServer server(80);
WiFiClient client;
char * ssid_ap = "ESP_AP";
char * password_ap = "123456789";

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_AP);
  setupAccessPoint();
}
// Handling the / root web page from my server
void handle_index() {
  server.send(200, "text/plain", "Get the f**k out from my server!");
}

// Handling the /feed page from my server
void handle_feed() {
  String t = server.arg("temp");
  String h = server.arg("hum");
  String s = server.arg("moi");

  server.send(200, "text/plain", "This is response to client");
  setupStMode(t, h, s);
}

void setupAccessPoint(){
  Serial.println("** SETUP ACCESS POINT **");
  Serial.println("- disconnect from any other modes");
  WiFi.disconnect();
  Serial.println("- start ap with SID: "+ String(ssid));
  WiFi.softAP(ssid_ap, password_ap);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("- AP IP address is :");
  Serial.print(myIP);
  setupServer();
}

void setupServer(){
  Serial.println("** SETUP SERVER **");
  Serial.println("- starting server :");
  server.on("/", handle_index);
  server.on("/feed", handle_feed);
  server.begin();
};

void setupStMode(String t, String v, String m){
  Serial.println("** SETUP STATION MODE **");
  Serial.println("- disconnect from any other modes");
  WiFi.disconnect();
  Serial.println();
  Serial.println("- connecting to Home Router SID: **********");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("- succesfully connected");
  Serial.println("- starting client");

  WiFiClient client;

  Serial.println("- connecting to Database server: " + String(logServer));
  if (client.connect(logServer, 80)) {
    Serial.println("- succesfully connected");
    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(t);
    postStr += "&field2=";
    postStr += String(v);
    postStr += "&field3=";
    postStr += String(m);
    postStr += "\r\n\r\n";
    Serial.println("- sending data...");
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
  }
  client.stop();
  //Serial.println("- stopping the client");
  /// If your ESP does not respond you can just
  // reset after each request sending
  //Serial.println("- trying reset");
  //ESP.reset();

}

void loop() {
  server.handleClient();
}

and my client code is
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#define DHTPIN 0

// AP Wi-Fi credentials
const char* ssid = "ESP_AP";
const char* password = "123456789";

// Local ESP web-server address
String serverHost = "http://192.168.4.1/feed";
String data;
// DEEP_SLEEP Timeout interval
int sleepInterval = 1;
// DEEP_SLEEP Timeout interval when connecting to AP fails
int failConnectRetryInterval = 2;
int counter = 0;
float s;
float h;
float t;
// Static network configuration
IPAddress ip(192, 168, 4, 4);
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);

DHT dht(DHTPIN, DHT11);
WiFiClient client;

void setup() {
  ESP.eraseConfig();
  WiFi.persistent(false);
  Serial.begin(115200);
  Serial.setTimeout(2000);
  Serial.println();
  Serial.println("**************************");
  Serial.println("**************************");
  Serial.println("******** BEGIN ***********");
  Serial.println("- start sensors");
  dht.begin();
  delay(500);
  Serial.println("- set ESP STA mode");
  WiFi.mode(WIFI_STA);
  Serial.println("- connecting to wifi");
  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, password);
  Serial.println("");
  while (WiFi.status() != WL_CONNECTED) {
    if(counter > 20){
       Serial.println("- can't connect, going to sleep");
       //hibernate(failConnectRetryInterval);
    }
    delay(500);
    Serial.print(".");
    counter++;
  }

  Serial.println("- wifi connected");
  Serial.println("- read DHT sensor");
  readDHTSensor();
  Serial.println("- build DATA stream string");
  buildDataStream();
  Serial.println("- send GET request");
  sendHttpRequest();
  Serial.println();
  Serial.println("- got back to sleep");
  Serial.println("**************************");
  Serial.println("**************************");
  hibernate(sleepInterval);
}

void sendHttpRequest() {
  HTTPClient http;
  http.begin(serverHost);
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  http.POST(data);
  http.writeToStream(&Serial);
  http.end();
}

void readDHTSensor() {
  delay(200);
   s = analogRead(A0);
  h = dht.readHumidity();
  t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    t = 0.00;
    h = 0.00;
  }
  Serial.println("- temperature read : "+String(t));
  Serial.println("- humidity read : "+String(h));
  Serial.println("- moisture read : "+String(s));
}

void buildDataStream() {
  data = "temp=";
  data += String(t);
  data += "&hum=";
  data += String(h);
  data += "&moi=";
  data += String(s);
  Serial.println("- data stream: "+data);
}

 void hibernate(int pInterval) {
  WiFi.disconnect();
  ESP.deepSleep(120e6);
  delay(100);
}

void loop() {

}

Kindly help me to change my code so it can be connected with server.

and where is the problem? set a different IP for the other client and that is all

I am confused for that how server will understand that data coming from which ip? i want to send data of both clients on different thingspeak channel.

send some id as parameter

and what changes must be reflected on server?

read the additional parameter


text:
How to get a hex file for Samd21 from .ino file
Can you generate a .hex file from an .ino file for the Atsamd21-zero?
I can generate a .bin file but not a .hex file.

what do you want to do with a hex file?

I want to combine the bootloader which is in .hex with the Samd21 file which is in .elf or .bin format.

and then what? bin is uploaded

in platform.txt build.preferred_out_format=bin

You can also manually do it with a arm-none-eabi-objcopy call (this tool is somewhere in your arduino IDE tool folder for the SAMD21 platform) if you do arm-none-eabi-objcopy -O ihex input.bin output.hex


text:
Is there way to wirelessly connect a arduino drone‘s camera?
Is there way to wirelessly connect a arduino drone‘s camera and stream to a set device from 10 km away?

Welcome to Arduino.SE. Questions starting with "Is there a way" are usually very broad and sometimes difficult to answer. You may receive more and better answers if you expand your question by describing, what you have tried already and how you (not) succeeded.

You could try using the most common solution for streaming low latency drone video, called FPV. You basically connect an AV video output from a camera to a transmitter and use a receiver on the ground to receive the AV video. After this you can connect it to any AV display (or a usb AV decoder if you want to use a computer) and you'll get an almost real time video feed of what is happening on your drone. To get long range you would need to buy a powerful transmitter, good receiver and decent antennas for bout of them. You can find different configurations for different ranges online.

Most (commonly available) RF links' communication distance is more limited than that (10 Km). If your flying locations are within a cell service area, a cell radio aboard the drone will probably give you the most universally available connection. Note that your streaming rate may vary with the location and cell congestion at that particular time, and may sometimes be limited, especially for video.


text:
Can Chirp Waves be sent using JSN-SR04T?
So i have project for underwater rangefinding using JSN-SR04T. I've read on the datasheet that the module sends square waves. Is it possible to program it so that it sends Chirp waves instead ? (Help with the coding is very appreciated)
Thanks in advance

Does the data sheet say the module can send chirp waves?

no, it says it sends square waves

Well surely that was your answer?

This question is not about Arduino, this question can be better solved by contacting the supplier, this question shows no/little effort of the asker and is too broad (also asks help for "coding"). Please read https://arduino.meta.stackexchange.com/questions/2523/how-to-ask-a-good-question-for-arduino-stack-exchange I'm voting to close, but please feel free to adjust your question accordingly.

As I googled the sensor, I found various sites stating, that a JSN-SR04T behaves exactly like the HC-SR04. The difference is mainly the water prooving.
So the answer is: No, you can't do this. The square wave, which drives the ultrasonic transducers, is generated by a hardware circuit and is not meant to be changed. To output a chirp wave you would need to rebuild the signal generation and measurement hardware (leaving only the transducers unchanged). At that point you may just buy the pure ultrasonic transducers and build the rest yourself.

Ok thank for the help

Ok, i also want to translate the distance data into a 3D image, how do you propose i do that ?

That depends on how you want to represent the image and how exactly you are measuring. Are you moving the sensor over a surface, or are you turning the sensor ro look in different directions?


text:
Is volatile qualifier needed if shared variable cannot be changed externally during complete function call?
Consider the following example:
int i { 0 };

void incInt() {
    ++i;
}

int readInt() {
    return i;
}

setup() {
    Serial.begin(9600);
    attachInterrupt(digitalPinToInterrupt(D1), incInt, CHANGE);
}

loop() {
    noInterrupts();
    int currI = readInt();
    interrupts();

    Serial.println(currI);
}

By wrapping the call to readInt() with noInterrupts() and interrupts() it is ensured that i cannot be changed externally during the execution of readInt(). i also cannot be changed externally during the execution of incInt(), as long as it is only called as ISR (interrupt service routine). Do I still need to declare i as volatile?
Does the situation change if i is accessed directly in the main loop:
loop() {
    noInterrupts();
    int currI = i;
    interrupts();

    Serial.println(currI);
}

In other words: What is the context in which the compiler expects a variable to not be changed externally if it is not declared volatile?

Declaring a variable as volatile tells the compiler, that it always has to read the real variable and that it cannot use a cached value. Also the compiler cannot optimize this variable, since it is unknown, when the variable will change. For this it is irrelevant, how you actually read the variable in the main sketch, it only matters, that it get's read. Also this has nothing directly to do with doing the read atomically (with noInterrupts()) (though you only garantee correct values, when doing it)
So yes, you need to declare it volatile, or the compiler might think, that the value doesn't change and optimize it out in some way.

What is the context in which the compiler expects a variable to not be changed externally if it is not declared volatile?

Externally here means outside of the main routine. This covers variables, that get changed in ISRs and also registers, that are changed by hardware (so the register definition in the used core are also volatile). The compiler cannot know, when these changes happen, because they are triggered by the hardware, not by the code. It will try to optimize your sketch (which is a rather complex procedure), and might see, that your variable is never changing in the code (the ISR does not get called from the main sketch, thus the compiler does not see it getting called) and will try to optimize it. To ensure, that your sketch works properly, it is your task to tell the compiler, that this variable can change at any time (so that it does not think the other way). You are doing this by declaring it as volatile

Let's forget about atomicity for a moment, which is a separate issue, and
assume i is an atomic type (maybe byte or something equivalent).
Consider the following code:
void loop()
{
    Serial.println(i);
}

Not so long ago I would have expected this to work just fine on Arduino,
as there aren't many ways to compile this function… on its own! However,
since version 1.6.10, the IDE enables link-time optimization.
This means that the compiler (or rather, the optimizer working within
the linker), can see the whole program and notice that setup() and
loop() are called from only one function which belongs to the Arduino
core:
int main()  // slightly simplified
{
    init();      // Arduino core initialization
    setup();     // User's initialization
    for (;;)
        loop();  // User's loop
}

This makes them perfect candidates for inlining:
int main()
{
    init();      // will likely be inlined too

    // Inlined setup():
    Serial.begin(9600);
    attachInterrupt(digitalPinToInterrupt(D1), incInt, CHANGE);

    for (;;) {
        // Inlined loop():
        Serial.println(i);
    }
}

Now it should become clearer that repeatedly reading i from memory
looks like a waste of time, which can be optimized-out. The for loop then
becomes:
register uint8_t cached_i = i;  // save `i' in an internal CPU register
for (;;) {
    // Inlined loop():
    Serial.println(cached_i);
}

And now the program only prints zeros. That's why you need volatile to
prevent that optimization.


text:
random characters
I am using arduino mega with LCD 4X20 character to measure weight by 40 kg load cell and pt 100 to measure the temp. I have 4 output to 4 relay module. all are powered from 12vdc /3 amp Power supply..
the problem is.. the display started normally showing every thing perfectly.. but when the output comes out and the loads runs.. random characters appear
is the power supply is not enough? or another problem..
Please advice.

Please show you circuit and your code

start with a simple sketch that displays 0123456789abcdefghij on every line ... then wiggle wires

Do you know what character generator ROM is built into that HD44780 4X20 display? What signals have you wired from your Arduino? Have you tied the R/W line to GND?

Please read How to ask a good question for Arduino Stack Exchange

@Ashraf Nassar There could be a number of reasons for this, from connection issues to bad libraries

Does this answer your question? Why does my LCD display random characters?

I'd suspect that it is a software error. Did you check your circuit if it induces desync between the Arduino and the LCD, or did you just use the wrong drivers?


text:
RtcUtility.h: No such file or directory
I have a problem with remaining headers. Can't seem to find the first header "RtcUtility.h". Anyone how to fix? I've provided a picture for you to see.

Error Messages:

Arduino: 1.8.10 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
sample_time:6:24: error: RtcUtility.h: No such file or directory
Multiple libraries were found for "ArduinoOTA.h"
   #include
Used: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ArduinoOTA
                          ^
Multiple libraries were found for "Wire.h"
  compilation terminated.
Used: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\Wire
  Multiple libraries were found for "ESP8266WiFi.h"
   Used: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi
  Multiple libraries were found for "ESP8266mDNS.h"
   Used: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266mDNS
  exit status 1
  RtcUtility.h: No such file or directory
This report would have more information with
  "Show verbose output during compilation"
  option enabled in File -> Preferences.

Please add the RTC library in the Arduino as below.
Open the Library Manager and search for "Rtc by Makuna" and install.
You can also checkout the Github page for that particular library at
https://github.com/Makuna/Rtc


text:
NodeMCU current consumption in all modes
I am using NodeMCU for my project.I wanted to know how much current it takes in its all modes like sleep mode,deep sleep mode and also in its wifi modes like station and access point mode.
Thanks in advance...

have you checked the datasheet?

count the consumption of the USB chip too


text:
Temperature varations using ADS1115 and voltage divider to read 12v
I have an issue with reading battery voltages of three 12 volt batteries using an ESP-01 and an ADS1115.  I have been graphing the measurements and the all of the graphs have a temperature component to the readings.  As the outside temperature increases, so does the reading from the ADS1115.  I have verified that battery voltages do not change with the temperature.  I have also recreated the problem by heating up my project case and seeing a great increase in the readings.  Both of my voltage divider resistors are made of the same material, so I would have thought that the changes in resistance would affect both components and not change the reading much.  I have replaced the LD1117 with a 3.3v buck converter and the problem still exists.
Details of my project are located here: https://hackaday.io/project/167291-rv-battery-monitor
ThingSpeak data graphs: https://thingspeak.com/channels/870224
Any ideas where the temperature component error is originating?

Your resistor values are way too high. The ADS1115 can have (depending on the settings) an input resistance as low as 3MΩ. Your resistors (battery output impedance) needs to be no more than 10% of that. For the impedance of a voltage divider calculate the parallel resistance of the two resistors involved (909kΩ currently).

consider reading the 3.3v at the same time, then using any derivation from 3.3v to calibrate the 12v readings. That said, the ADS should not fluctuate very much from temp, so maybe your resistors are getting hot.

I finally received my resistors in the mail and was able to replace them with smaller values.  I decided on using 100k and 10k for the voltage divider and the temperature error component is mush less, .07 volt difference in readings between 30F and 95F.  This is sufficient for my needs.  Thanks for the recommendation Majenko!


text:
Control 5V from ESP8266 Wemos D1 mini
I am making a simple heater with the help of ESP8266 wemos d1 mini. Heaters will use 12V DC power suply and ESP8266 must turn the heater on and off with the help of 5V DC relax. I want to avoid the use of anything else then ESP8366 and relay. I will need 2 such relays. So the question is, can i control 5V output on ESP8266 ? Or do i need to find a 3V DC relay and use that ? If the latter is the case, can i get some ebay link to 3V DC relay ?

is it a relay or a relay module with separate power input and signal input? some of the relay modules work wit a 3.3 V signal and you can power them from 5 V pin of Wemos

I was thinking of simply using standalone relay, basicly square thingy with tiny legs. I already have 2 of them that is why i am asking. I would like my project to be as simple as possible.

ditch the relay and use a logic-level mosfet, like the irlz44n; cheaper, longer-lasting, faster switching, higher current, lower resistance, smaller footprint, negligible power consumption. The only downside it that they don't galvinically isolate or handle AC, but you don't care about that.

Voltage is only part of what a relay uses.  Check the current requirements for the relay coil/input as well.
For example the common result for "3V relay arduino" will produce results for relay MODULEs that contain something akin to a SRD-03VDC-SL-C relay (labeled on the relay itself).  Spec for the RELAY (separate search by relay part no) yields a data sheet that says the coil resistance is 25 ohms for a 3V and would use 120 mA at that voltage (25 Ohm * .120A = 3).  Note if the same coil were run on 5V it would draw 200 mA (25 Ohm * .200A = 5V).
120 mA is bloody high to be coming from a logic pin which is why the MODULE has more than just the relay.  What the MODULE likely contains is an additional gate device that takes less current that then supplies the relay (with 120mA) from another port.
You might also be looking at a solid state relay that uses less input current but generally has some slight leakage when "Off"

Do NOT try to drive a simple relay from an MMU like a ESP8266, Arduino, or Pi. That would likely destroy the digital pin on the MMU, and might destroy the whole processor.
You want a "digital relay module" which has a driver circuit to control the relay, plus some form of isolation to protect the digital pins.
A relay like this would be perfect: https://www.amazon.com/Icstation-3-3V-Optocoupler-Trigger-Development/dp/B01300ZY5M
Note that those come in 1, 2, 4, and 8 channel modules. Such a relay needs an external power supply, and your ESP8266 may or may not be able to provide enough current for the relay from its voltage regulator. Check the current requirements on the relay and the output specs on the ESP8266's voltage regulator.


text:
how can i split string data in arduino?
im sending string data via serial with following format ex. :45:60 or such as ":120:57".i got the data shown in Serial.println (secondValue) Serial.println (thirdValue); but i cant convert it to int
String myString;
char c;
int Index1,Index2,Index3, azi;
String secondValue, thirdValue;
void setup(){
Serial.begin(9600);}
void loop(){
while (Serial.available()>0)
{
delay(10);
c = Serial.read();
 myString += c;
}
 if (myString.length()>0)
{
Index1 = myString.indexOf(':');
Index2 = myString.indexOf(':', Index1+1);
Index3 = myString.indexOf(':', Index2+1);

secondValue = myString.substring(Index1+1, Index2);
thirdValue = myString.substring(Index2+1, Index3);

Serial.println(secondValue);
Serial.println(thirdValue);

myString="";
}
delay(1000);
}

Hint: Try String.toInt(), https://www.arduino.cc/en/Tutorial.StringToIntExample

https://majenko.co.uk/blog/evils-arduino-strings

https://majenko.co.uk/blog/splitting-text-c

https://majenko.co.uk/blog/reading-serial-arduino

All numbers are integers?
If yes, you can use toInt() function.
int secondValueInt, thirdValueInt;

secondValueInt = secondValueInt.toInt();
thirdValueInt = thirdValue.toInt();

thx a lot bro, you are a life saver (Y)


text:
Converting of 32 bit signed hex value to dec
Using Seed studio CAN shield to read and convert CAN data to dec value.
Example of expected result:
Full CAN message is 70 3B F1 FF 00 00 00 00 , using little endian first 4 bytes gives: FFF13B70 , which should be equal to converted dec value of -0.967824 (using factor of 0.000001).
Here is code to extract the text value I am using.
CAN.readMsgBuf(&len, buf);
unsigned char len = 0;
unsigned char buf[8];
    {
           String reg0 = String (buf[0], HEX);
           String reg1 = String (buf[1], HEX);
           String reg2 = String (buf[2], HEX);
           String reg3 = String (buf[3], HEX);
           Serial.print(reg3);
           Serial.print("\t");
           Serial.print(reg2);
           Serial.print("\t");
           Serial.print(reg1);
           Serial.print("\t");
           Serial.print(reg0);
           Serial.print("\t");
           String regsumm = (reg3 + reg2 + reg1 + reg0);

           Serial.println(regsumm);
        }

As result I got only text string which couldn't be converted into dec. Any other ways how do it?

You have taken completely the wrong tack. You don't want to convert your data into text and then convert it back into data again - it's already data.
You can combine your first four buffer bytes into a single 32-bit signed integer with just:
int32_t val = ((int32_t)buf[3] << 24) | ((int32_t)buf[2] << 16) |
              ((int32_t)buf[1] << 8) | (int32_t)buf[0];

That gives you the value -967824, which is 0xFFF13B70 in hex notation, or 11111111 11110001 00111011 0111000 in binary.  All of them are the same thing and are just a number.
You can then multiply that result by your "factor" into a float variable:
float dec = val * 0.000001;

Chances are it won't give you -0.967824 due to the nature of floating point values, so you may be better off keeping it as -967824 and working in "micro-units" instead of "units".

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

Since the bytes you received in the buffer are in little endian order,
and your Uno is itself little endian, you don't even need to move bytes
around: you can just reinterpret the bytes you already have as an
int32_t:
union {
    uint8_t bytes[8];
    int32_t numbers[2];
} buffer;
unsigned char len = 0;

CAN.readMsgBuf(&len, buffer.bytes);
Serial.println(buffer.numbers[0] * 1e-6, 6);

This prints -0.967824 to the serial port.
Note that this code will not work as expected on a big endian platform.
If you want something portable, the usual solution is to build the
result using bit shifts, as in Majenko's answer.


text:
Connecting Logitech F310 gamepad to Arduino Uno and Arduino USB Shield
I am trying to connect Logitech F310 gamepad to Arduino Uno with ARDUINO USB HOST SHIELD https://store.arduino.cc/arduino-usb-host-shield using http://github.com/felis/USB_Host_Shield_2.0 library.
The closest is https://github.com/felis/USB_Host_Shield_2.0/tree/master/examples/HID/USBHIDJoystick example
After compiling there is no print output in serial window after "Start".
Tried keyboard sketch on same board - it worked.
There is "Mode" button on joystick - by pressing green led is switched ON and OFF.
Behind the joystick there is switch between "X" and "D" .
On "D" green led is working, on "X" - not.
Is this joystick even compatible with HID library? Is there other way how to configure it to USB shield?
Joystick is working on different other devices.

I found it here : https://github.com/AlanFord/Logitech_F310_and_Arduino
So there is a glitch in library and driver customization was necessary

It's OK to accept your own answer as the solution to the problem. I think you get 15 rep for it.


text:
My alterate flashing LED program is not working
I am trying to program my Arduino UNO ATMega 328p in assembler to implement a ﬂashing pattern with two LEDs. When one LED is oﬀ, the other must be on. I have made a program but it is showing errors and I don't know how to fix it. I have done it Atmel Studio 7. Please help if you can.
Here is my program:
main:

sbi 0x04, 5
sbi 0x04, 4

start:

sbi 0x05, 5
ldi r16,1000
rcall delay
cbi 0x05, 5

sbi 0x05, 4
ldi r16,1000
rcall delay
cbi 0x05, 4

rjmp start

delay:

dec r8
brne delay
dec r9
brne delay
dec r16
brne delay
ret

Please show the errors you received.

When I run this I get 2 errors: Operand(s) out of range in 'ldi r16,0x3e8' Operand(s) out of range in 'ldi r16,0x3e8'

I think I found the problem now, thanks anyways :)

@user58745 Then please write an answer to your question, so that others can learn from this.


text:
What are the environmental requirements of an Arduino?
I'd like to use an Arduino Yún in a somewhat outdoor environment (in a metal box on a truck).  I think I've seen that the temperature requirements of the Uno are -40 °C to +85 °C, but I can't find that information about the Yún.  It would be nice to know where to find information about the temperature and humidity safe working requirements for every Arduino model.

The AtMega32u4 (the chip that drives the Arduino Yun) has an operating requirement of -40 to +85, so if you go outside that range, you will definitely void warranty (which is not to say it will break, of course!). See datasheet at http://www.atmel.com/devices/atmega32u4.aspx
A datasheet for the AR9331 seems to say that it only works down to 0°C ( http://www.eeboard.com/wp-content/uploads/downloads/2013/08/AR9331.pdf page 305, "Commercial Case Temperature") - this seems awfully high for a minimum temperature.
While that does not mean that, inside that range, you are safe, I would GUESS that you probably are - I would guess that the AtMega32u4 or AR9331 is going to be the most delicate part in there.
Of course, to get a definitive answer, you (or someone) would have to check the specs on each part.

+1 Useful albeit incomplete aswer. You are unlikely to void warranty on temperature excursion alone. I do not know why anyone would downvote this.

That's only for the chip itself. Since the chip might have a different expansion coefficients as the PCB, the soldered connection might tear/crack over time. Same goes for all the other components on the Yun's board.

@Gerben. Indeed - but if one component is specified at  eg -40 to +85 and another at eg 0 -125 you can be confident [tm] that the overall figures is not outside 0 - 85 - unless extra work and specific design renders it otherwise. .

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


text:
Where can I find beginner tutorials for the Arduino?
I am new to all of this so anything is helpful.

There are hundreds of Arduino tutorials on the web (more than we could list here). A search engine should help you find them, and the official Arduino website is always a good place to start.

As above - PLUS load the Arduino IDE (you don'y have to own one) and on menu click Help then Reference. Each instruction is included with example code and explanations. Also in Help is "Getting Started" and "Frequently asked questions". Then in menu item File open "Examples" and you'll find many subfolders with working example code covering most areas.

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


text:
verification error, first mismatch at byte 0x3895 0xdf != 0x44?
I bought a SainSmart Arduino Mega 2560. I uploaded a small sketch to it, and it uploaded fine. When I upload a larger sketch though, I get this error:
verification error, first mismatch at byte 0x3895
         0xdf != 0x44

So obviously there's nothing wrong with my bootloader because I can upload smaller files. Why is this happening?

I added some serial output to my program and it seems to work correctly though... What?

It seems like it was a bad upload for some odd reason. Retry uploading the sketch that gave you that error and see if it persists.

@AnnonomusPenguin I have, multiple times. It still persists.

Sounds like a possibility of a defective board...

Is the error address always the same or does it change? Try uploading a different larger sketch, maybe one of the examples that pulls in a library or two. Does the reported error occur at the same address? That could mean a defect in the chip's flash memory. You might also try deliberately generating code containing either of the problem cases @NickGammon mentions and see if either of those causes the same error. That would suggest your larger sketch contains one of them.

If your sketch contains !!! in it, that can cause some versions of the bootloader to drop into interactive mode, eg.
Serial.println ("Rocket firing!!!");

Also there can be problems with 0xFF bytes in your code causing the bootloader to incorrectly assume that that page of memory was erased, when it was not.
I have a bootloader-uploader sketch at: Atmega bootloader programmer
You need a second board to use it (eg. a Uno) - the bootloader for the Mega2560 is a reasonably up-to-date one. I haven't actually tested it with the Sainsmart version of the Mega, but I presume that internally that part is the same.

I believe I have finally understood this error today, and would like someone to verify or refute.
In "avrdude.conf" there is defined for each processor and for each memory type a minimum duration and a maximum duration that the programmer will repeat trying to write each byte. These have values of "min_write_delay = 4500" and "max_write_delay = 4500" (no idea what the units are).
After increasing the max_write_delay to "max_write_delay = 16000" (arbitrary increase but keeping it less than a 16 bit signed integer to avoid buffer overflow risks), for all memory types (but I would presume that only "flash" memory needs the parameter to be altered) my Arduino takes an extra 30 seconds to program, but no more verification errors.

authors: Сергей Новиченко


text:
Will the 3.3V regulator on an Arduino Leonardo work when powered from USB?
Will the 3.3V regulator produce 3.3v when the Arduino is powered from the USB port?

Will the 3.3V regulator on an Arduino Leonardo work when powered from USB?

Yes, provided that

it is an "official" Leonardo or a competent clone and
as long as you do not load the power supply excessively with external loads.

Official circuit diagram here
The USB supply feeds the 3V3 regulator via MOSFET T1 at the bottom of the sheet and U3, an LP2985 LDO regulator. If your board has the same circuitry as this it should provide 3V3 from USB.

The 3.3V regulator is fed by the 5V, whatever that comes from. If you don't use a separate power supply like a wall-wart, the 5V switches automatically to the USB's 5V. That feeds the regulator for the 3.3V.
So yes, it will produce 3.3V.


text:
Connect to ch340 on MacOS Mojave
I recently upgraded my MacBook Pro to Mojave. Now I'm not able to connect to my Arduino board with ch340g usb-to-serial chip. It is a Arduino board with AtMega 328 and ESP8266 integrated. I downloaded the drivers from the Chinese website for the ch340 and also removed old installations, like some tutorials tell me. I just can't get a /dev/cu.* port (besides the /dev/cu.Bluetooth-Incoming-Port.
I do have an external FTDI usb to serial board. I didn't get to it to try to connect it.
Does someone know how to get the ch340 to work on MacOS Mojave, or as a last resort: use the FTDI to program/monitor the Arduino board?

Ok, this is the solution for me:
remove all old drivers:
sudo rm -rf /Library/Extensions/usbserial.kext
sudo rm -rf /System/Library/Extensions/usb.kext

Now reboot the computer.
And then (very important, because it took me 10 cables to find the right one) use a fully connected cable ;-)
Now I have these ports:
/dev/cu.wchusbserial1410
/dev/cu.usbserial-1410

Sven's answer is 100% correct the fully connected cable is what hung me up for a few hours. Took 6 cables to find the right one.

What do you mean with "fully connected cable"? Is this a specific kind o USB cable or what?

It is a USB cable with also the data lines connected. Most cables you get with phones and devices just have the +5 and GND connected so they don't pass data.

this my problem too.
i found these solutions

mac-usb-serial app
a topic in arduino forum

make sure delete old usb driver in these path
/Library/Extensions/usbserial.kext
and
 /System/Library/Extensions/usb.kext

then install it again download link

When I experienced this problem, installing the latest driver still failed, but when I removed the old drivers and did not install anything new, it worked fine.


text:
Uploading new sketch to Leonardo-type boards when you've changed the HID mode
I have Sparkfun Pro Micro (Leonardo compatible board). I got it because I plan to build my own array of controls for use in flight/racing sims.
My starting point is LeoJoy, and I didn't have any trouble getting this up and running. Installed just fine, and I have a programmable HID joystick available in windows. It seems to work by modifying the RAWHID code in the default libraries to spoof being a HID joystick. However, my board was now stuck in joystick mode, with no available COM ports for uploading new sketches.
Resetting the board (by grounding the RST pin), enables the COM port, but very, very briefly. Not enough time to send new sketches.
After about an hour of trying different timing, I finally did upload an empty sketch to the board before it went into Joystick mode. So I'm good for now, but I'm a bit worried that I'm going to have to repeat this every time I want to make a change to my program.
Am I doing something completely noobish here? Is this the correct way to program a board that has been forced to act as a joystick? Is there a better way?
Perhaps there's some code I can put into my sketch that will delay the change of USB behavior for a few seconds. That way, it will allow me to recompile and submit my sketches after a reset without having to rush the timing.

From Sparkfun's page Pro Micro Hook-upGuide
When a Pro Micro is externally reset (by pulling the RST pin low), it’ll only briefly (<750ms) start the bootloader before continuing on to the sketch. If you need the bootloader to run longer, resetting twice quickly will get the Pro Micro to enter bootloader mode for eight seconds.
Hope that helps! If not there are some other procedures you might want to look into.

Hmm.. I thought I had read something like that, so I had tried resetting it twice quickly. But I couldn't get it to work. I don't have a switch wired to that pin, so I was using a little piece of wire, so it's entirely possible that I wasn't able to get the second "click" in quick enough.

I am interested in learning about the "other procedures" you mentioned though. Any additional information would be great.

Oh snap, the link didn't make it through, updated:
https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide#faq-change-pid

Also, I wasn't able to correlate enough of the details from your question to their documents. If you still need assistance after looking, can you elaborate on modifications to the raw HID update, if you yourself made any? Or can you shed some light on whether or not you made VID/PID changes?

Thank you so much for your help. I didn't make any changes myself. The changes were made by the LeoJoy! program. The leonardo boards by default show up as a USB composite device consisting of a Mouse, Keyboard, and a Serial device for uploading new sketches. Installing LeoJoy appears to modify the serial device code to spoof itself as a Joystick, disabling the serial functions in the process. Don't really know enough about it to know if that's something that's entirely necessary, but your advice has got me to the point where I can compile and upload new sketches consistently, so I'm happy.


text:
float precision in arduino
I am reading a string which i have to convert into a float with a maximum of precision.I didn't want to use toFloat() function since it make a truncation so i made my own code.
My problem is that the final result is also approximated.
I need a precision of 4 digits after the float.I read the documentation about float in the arduino website.They say it should be maximum 7 digits of precision but i don't get it.When i test my code on the value of '23,459' ,all i get is 23,46.
Any suggestions?
void setup() {

 Serial.begin(9600);

}
int longu=0;
char data='2';
  String data2="23,459";
  float val=0;
  int posVir=0;
  int t=0;
  float postVir=0;
  float preVir=0;
  int lonPostVir=0;
  int lonPreVir=0;
  float posvir2=0;
  void loop()
{

   lonPostVir=(data2.substring(posVir+1)).length();
   lonPreVir=(data2.substring(0,posVir)).length();

   longu=data2.length();
   posVir=data2.indexOf(",");
   preVir=(data2.substring(0,posVir)).toFloat();
   postVir=(data2.substring(posVir+1)).toFloat();
   posvir2=postVir*pow(10,-lonPostVir);
   val=preVir+postVir*pow(10,-lonPostVir);

  Serial.println(val);

    }

Serial.print only gives two decimal points. (Otherwise it would return 23.4589996337890625 as that is the closest float value that exists.)

Are you sure about that sir?

Sure about which of the two statements?

I confirm that 23.4589996337890625 (i.e. 12299272/2^19) is the float32 nearest to 23.459.

The simplest way to get more decimal places to print is this:
Serial.println(val,NUMBER_OF_DECMIAL_PLACES);

This will print out any number of digits after the decimal place. Regular print without the number of digits specified will default to 2 decimal places. for example, here is some code and the result that gets printed:
float val = 23.459;
Serial.println(val);
Serial.println(val, 4);
Serial.println(val, 10);

23.46
23.4590
23.4589996337

You may notice that with 10 decimal places printed you can start to see how much the actual value of 23.459 needs to be approximated to fit within a floating point number. This is similar to how 1/3 can not be represented 100% accurately in a finite number of decimal digits; 459/1000 cannot be represented 100% accurately in a finite number of binary bits, so it is approximated.
Also, note that for non-floating point numbers the optional second argument to print and println is the base it should be printed in (dec, hex, oct, ...) and has nothing to do with precision.

Just write the amount of numbers you want to get float here Serial.println(val); after the val.
example:
Serial.println(val, 5);
It will give 5 digits after the decimal point


text:
What is the size of the buffer in serial communication with arduino uno?
as it is in the question, i need to know what is the size of the biggest string that i can send using the serial port to the arduino.
Thank you

You may check the sources shipped with the Arduino IDE.

The size of the buffer and the size of the biggest string you can send are not necessarily related (if they are, that's really lazy programming on someone's part)

That would be 64 bytes, providing the buffer is fully empty. See https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial.h#L42-L43


text:
What are the connectors used in the arduino mega?
I am trying to build a shield for an arduino mega.For that i need to know the type of the female connectors that are soldered in the pins of the arduino mega in order to choose the correct male connectors.

What kind of shield are you trying to build? Have you looked at the Arduino documentation...? Take a look! Mega link

Those are standard 0.1inch female/male headers.

I looke for sure but couldn't find anything about mechanical design

Look for male pin header strip, with 0.1 inch (2.54mm) pitch.
In single and dual row form.
Specifically they are:

8x1 ADCL
8x1 ADCH
8x1 PWML
8x1 PWMH
8x1 Communication
6x1 Power
18x2   digital IO (on the side)

Source: Schematics


text:
arduino webserver serves single web page to WAN/Internet very very slowly
I have an arduino web server running from a mega 2560 and a wiznet ethernet shield.
It serves the single page just fine (and very fast) to the LAN (192.168.1.50), but serves the same page very, very, slowly when accessed from the  WAN/Internet.
I have port forwarding set-up on the modem router so that the Arduino web page  can be accessed from the outside world, and it does work, I can see the page from anywhere, but it's page serve rate is impractically slow. The page takes 30 - 45 seconds to load up.
(I have the RaspPi with Apache set-up, also in the house, using the exact same port forwarding settings - with a different port - and it serves pages to the WAN/Internet very fast).
Has anyone any ideas what might be wrong ?
Thank you

I haven't used the ethernet library for a while, but I remember that it served up tiny packets - basically each write call went in its own TCP packet. It sounds like you may have latency issues across the WAN.
You could try using your Apache instance to proxy the Arduino pages. Details are at http://httpd.apache.org/docs/current/mod/mod_proxy.html I have this running but all my pages are small so I'm not sure how it would behave on larger pages.

The answer is :
I combined all my
client.println("Some text here
");

html statements into much longer statements eg
client.println("Some text here
All On   All Off
Socket 1 On   Socket 1 Off
");

This reduced the number of client.println("  ");  statements by about one third, which resolved the issue.

This would be a good place to get out tcpdump or WireShark (or any other tool that will let you observe network traffic). If you watch the traffic while you're making the a request that goes to the Arduino (perhaps use a phone to make the request so that it comes from outside) you will be able to observe the TCP/IP transactions and see where the delays are.