text:
Arduino not recognised by windows after using a lot of the storage
I made a script for my Arduino Pro Micro that was very large (Global variables were 98% of the intended storage). The Arduino was not recognised by Windows after loading the script and I don't know how to fix this issue.

reset it while it attempts to upload, to start the bootloader. try double reset if simple reset doesn't work

Not recognized means, it was not recognized at the corresponding COM port or don't you simply get any communication on the serial port while the sketch is (should be) running?

on Micro the MCU (32u4)  has native USB handled by your sketch (the part from Arduino core), so if the sketch doesn't run, the USB is not handled. the IDE can reset the MCU only if it listens on USB (with 1200 baud connection). if you activate the bootloader with reset, it will handle USB while it is active


text:
arduino yun sysupgrade 'platform_check_image' failed
https://www.arduino.cc/en/Tutorial/YunSysupgrade
when i run the following command. i get this error.
run-sysupgrade /mnt/sda1/openwrt-ar71xx-generic-yun-16M-squashfs-sysupgrade.bin
Image metadata not found
Invalid image type.
Image check 'platform_check_image' failed.

via webinterface its the same problem
i have a freshly unboxed arduino yun rev2
i really don't want to use the go updater since i still have 2 years of warranty.
https://www.arduino.cc/en/Guide/YunUpdater

Hint: The SD card should be inserted with Yun powered off, then once the card is in, power up the Yun.

@MikaelPatel didn't work. same problem.

Check that the SD is mounted ls /mnt/sda1/

@MikaelPatel it is. the bin shows up.

Check the size and contents of the file against the original. How did you download?

source: Stack Exchange

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

sort: votes


text:
Trouble running two NEMA 17's with a joystick
So I'm trying to make a motorized dobsonian telescope using two NEMA 17 motors with Easy Driver boards. I want to control the x and y axis with a joystick. I found a code that ran one with a joystick and I tried to modify it by copying the loop and adding the y-axis. Well only the X-axis moves and it only turns CCW.
Can someone run over this and see if they see the issue that I can't? Thank you
/*This program is designed to control two nema 17 boards with easy driver board with a joystick on a Nano.
My specific use is to control the X and Y axis of a homemade telescope

considered open source, feel free to do whatever with it.
*/

#define step_pinX 3                                                             // Pin 3 connected to Steps pin on EasyDriver       X-AXIS
#define dir_pinX 2                                                              // Pin 2 connected to Direction pin                 X-AXIS
#define MS1X 5                                                                  // Pin 5 connected to MS1 pin                       X-AXIS
#define MS2X 4                                                                  // Pin 4 connected to MS2 pin                       X-AXIS
#define SLEEPX 6                                                                // Pin 6 connected to SLEEP pin                     X-AXIS
#define step_pinY 7                                                             // Pin 7 connected to Steps pin on EasyDriver         Y-AXIS
#define dir_pinY 8                                                              // Pin 8 connected to Direction pin                   Y-AXIS
#define MS1Y 9                                                                  // Pin 9 connected to MS1 pin                         Y-AXIS
#define MS2Y 10                                                                 // Pin 10 connected to MS2 pin                        Y-AXIS
#define SLEEPY 11                                                               // Pin 11 connected to SLEEP pin                      Y-AXIS
#define XPin A0                                                                // Pin A0 connected to joystick x axis              x-AXIS
#define YPin A1                                                                // Pin A1 connected to joystick y axis                Y-AXIS
#define JoySwitch 12                                                            // Pin 12 connected to joystick button
#define Limit01 22                                                              // Pin 22 connected to limit switch
#define Limit02 23                                                              // Pin 23 connected to limit switch

int stepSpeed = 10;                                                            // speed of stepper motor

void setup() {
   pinMode(MS1X, OUTPUT);
   pinMode(MS2X, OUTPUT);
   pinMode(dir_pinX, OUTPUT);
   pinMode(step_pinX, OUTPUT);
   pinMode(SLEEPX, OUTPUT);
   pinMode(MS1Y, OUTPUT);
   pinMode(MS2Y, OUTPUT);
   pinMode(dir_pinY, OUTPUT);
   pinMode(step_pinY, OUTPUT);
   pinMode(SLEEPY, OUTPUT);

   pinMode(Limit01, INPUT);
   pinMode(Limit02, INPUT);

   pinMode(JoySwitch,INPUT_PULLUP);

   digitalWrite(SLEEPX, HIGH);                                                  // Wake up EasyDriver
   delay(5);                                                                    // Wait for EasyDriver wake up
   digitalWrite(SLEEPY, HIGH);                                                  // Wake up EasyDriver
   delay(5);                                                                    // Wait for EasyDriver wake up

/* Configure type of Steps on EasyDriver:
// MS1X MS2X MS1Y MS2Y
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/

   digitalWrite(MS1X, LOW);                                                      // Configures to Full Steps
   digitalWrite(MS2X, LOW);                                                      // Configures to Full Steps
   digitalWrite(MS1Y, LOW);                                                      // Configures to Full Steps
   digitalWrite(MS2Y, LOW);                                                      // Configures to Full Steps

}

void loop() {
  if (!digitalRead(JoySwitch)) {                                                 // Check joystick switch position
  delay(500);                                                                    // delay for debouncing
  switch (stepSpeed) {                                                          // Check current value of step_speed and change it
    case 1:
    stepSpeed=10;                                                               // slow speed
    break;
    case 3:
    stepSpeed=1;                                                                // fast speed
    break;
    case 10:
    stepSpeed=3;                                                                // medium speed
    break;
  }
  }

  if (analogRead(XPin)> 712){                                                     //if joystick is moved left
    if (!digitalRead(Limit01))  {}                                               // check is limit switch is activated

    else {                                                                       // if limit switch is not activated, move motor clockwise
      digitalWrite(dir_pinX, LOW);                                               // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pinX, HIGH);
      delay(stepSpeed);
      digitalWrite(step_pinX, LOW);
      delay(stepSpeed);
    }
  }

if (analogRead(XPin) < 312){                                                     //if joystick is moved left
    if (!digitalRead(Limit02))  {}                                               // check is limit switch is activated

    else {                                                                       // if limit switch is not activated, move motor clockwise
      digitalWrite(dir_pinX, HIGH);                                               // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pinX, HIGH);
      delay(stepSpeed);
      digitalWrite(step_pinX, LOW);
      delay(stepSpeed);

    }
    }
    if (analogRead(YPin)> 712){                                                     //if joystick is moved left
    if (!digitalRead(Limit01))  {}                                               // check is limit switch is activated

    else {                                                                       // if limit switch is not activated, move motor clockwise
      digitalWrite(dir_pinY, LOW);                                               // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pinY, HIGH);
      delay(stepSpeed);
      digitalWrite(step_pinY, LOW);
      delay(stepSpeed);
    }
  }

if (analogRead(YPin) < 312){                                                     //if joystick is moved left
    if (!digitalRead(Limit02))  {}                                               // check is limit switch is activated

    else {                                                                       // if limit switch is not activated, move motor clockwise
      digitalWrite(dir_pinY, HIGH);                                               // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite(step_pinY, HIGH);
      delay(stepSpeed);
      digitalWrite(step_pinY, LOW);
      delay(stepSpeed);

    }
    }

}

how many limit switches do you have? ... you are reading the same switch with X and Y code

you code has unnecessary convolution .... if(!digitalRead(Limit02))  {}   else { .... } is same as if(digitalRead(Limit02))  { .... }

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


text:
ESP8266 exception if sending TLS-POST-request for a couple of iterations
Problem
I send sensor measurements from an Arduino to -> AWS APIGateway -> Lambda -> CloudWatch, which works but only for a couple of minutes, then a stack-trace is shown and the program stops.
Request
I search for solutions, which ..

avoides the stack trace
recovers from the stack trace and starts over
speed up sending data (as close to once every second as possible!)
still collect data points during sending/receiving data (if I add the uncommented part during receiving the response nothing is happening) -> Parallel execution?

Tried so far
I so far observed that it may be a time issue, as with more "delay" it takes longer to receive the error. I really just want to write the data and therefore uncomment my code part which reads the APIGateway response, this way the error comes sooner. I already looked up the related issue on Github, but nothing solved my problem.
Specs

NodeMCU v2 including ESP8266
LM393 noise sensor
MacBook for development

The bare output:
...
Request: { "id": "S3", "noise": 41 , "ip": "192.168.178.20" }

Exception (29):
epc1=0x4020c612 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000

ctx: cont
sp: 3fff0010 end: 3fff0530 offset: 01a0

>>>stack>>>
3fff01b0:  00820000 00000082 3fff57cc 40219652
3fff01c0:  3ffef4b0 3fff5f44 3fff57cc 4021984c
3fff01d0:  3fffba7c 00000208 3fffba7c 40100670
3fff01e0:  00000104 0000b018 00001603 00000042
3fff01f0:  00000040 00000082 3fff7dd4 40219b65
3fff0200:  00800000 00000080 00000000 00000041
3fff0210:  00000040 0000003f 3fff6164 00000041
3fff0220:  3fffb664 3fff7dd4 3fff6164 3fff6f34
3fff0230:  3fffbb78 ffffffff 3fff5f44 40204c04
3fff0240:  00000040 3fff5f44 3fff7dd4 3fff5f44
3fff0250:  00000040 3fff5f44 3fff7dd4 4021a69f
3fff0260:  3fff67b4 0000003f a5c6bfaf 00000001
3fff0270:  3fff5f44 3fff6a04 3fff7dd4 00000001
3fff0280:  00000010 3fff5f44 0000000f 4021a8f4
3fff0290:  3fff6164 3fff9b1c 0000000f 00000001
3fff02a0:  00000001 3fff68bc 3fff3872 402196f8
3fff02b0:  00000100 3fff96fc 3fff3847 00000000
3fff02c0:  00000100 3fff96fc 3fff3847 4021ba7d
3fff02d0:  3fff0300 00000000 000000d0 00000030
3fff02e0:  b9a842ca 3fff68c8 3fff6170 00000004
3fff02f0:  3fff3841 3fffa794 3fff3841 40216778
3fff0300:  eb090303 4fed87e4 8f9aa767 9126663e
3fff0310:  ea791a25 f4e54d08 e2cb4f3b da7af472
3fff0320:  3d042744 7d12ab50 1cecee1e 42cab262
3fff0330:  3fff3841 00000004 3fffa794 40216c0d
3fff0340:  fa036a52 f16613d1 c13f331a 40213cd0
3fff0350:  f6658dd1 3fffc6fc 3ffef510 4020f835
3fff0360:  00000000 00000004 00000004 40203688
3fff0370:  00000012 00001192 00000064 40204bc4
3fff0380:  00000050 00000000 00000032 00000004
3fff0390:  3fff3841 00000004 3fffa794 00000004
3fff03a0:  3fff3841 00000004 3fffa794 40216580
3fff03b0:  d7c44818 00000131 00000131 0000002d
3fff03c0:  00000062 3fff3841 3fffa794 4021695c
3fff03d0:  00000016 3fff3874 3fffa794 401004d8
3fff03e0:  3fff0438 0000000e 00000010 3fff3044
3fff03f0:  4020343c 3fffa794 3fff0430 01000000
3fff0400:  3fff0438 00029c3d 3fffa794 402166e8
3fff0410:  3fffa794 3fff13ec 3fff14ec 3fff3044
3fff0420:  3fff241c 00029c3d 3fff14ec 40203e25
3fff0430:  3fffa794 3fff13ec 40204b4c 3ffef510
3fff0440:  00003a98 00003a98 00003a98 4020136f
3fff0450:  3ffef248 00000000 3fff241c 00000029
3fff0460:  000001bb 3ffe8a09 3ffef248 40204073
3fff0470:  000001bb 3ffef248 3ffe8a09 00000029
3fff0480:  000001bb 3ffef248 3ffe8a09 40204119
3fff0490:  40107158 ce653134 40107158 ce653134
3fff04a0:  3ffe8a09 3ffef248 3ffef240 402022d4
3fff04b0:  40244290 00000004 00000000 4023d5cd
3fff04c0:  4023d631 60000a00 00000000 3fffdad0
3fff04d0:  004b004b 004b004b 004b004b 004b004b
3fff04e0:  00000000 00000026 40238168 3ffef4f4
3fff04f0:  402013fa 0000001c 00000000 3ffef4fc
3fff0500:  3fffdad0 3ffef244 3ffef240 4020245c
3fff0510:  3fffdad0 00000000 3ffef4f4 40204b98
3fff0520:  feefeffe feefeffe 3ffef510 40100710
<<<stack<<<
⸮⸮؁⸮

The decoded stack trace:
Decoding 36 results
0x40219652: more_comps at crypto/bigint.c line 672
0x4021984c: alloc at crypto/bigint.c line 672
0x40100670: _umm_realloc at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/umm_malloc/umm_malloc.c line 1641
:  (inlined by) realloc at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/umm_malloc/umm_malloc.c line 1715
0x40219b65: regular_multiply at crypto/bigint.c line 672
0x40204c04: optimistic_yield at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/core_esp8266_main.cpp line 57
0x4021a69f: bi_barrett at crypto/bigint.c line 1289
0x4021a8f4: bi_mod_power at crypto/bigint.c line 1414
0x402196f8: trim at crypto/bigint.c line 672
0x4021ba7d: RSA_public at crypto/rsa.c line 254
:  (inlined by) RSA_encrypt at crypto/rsa.c line 288
0x40216778: send_client_key_xchg at ssl/tls1_clnt.c line 409
0x40216c0d: do_clnt_handshake at ssl/tls1_clnt.c line 123
0x40213cd0: mem_free at /local/users/gauchard/arduino/arduino_esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/mem.c line 152
0x4020f835: pbuf_free_LWIP2 at /local/users/gauchard/arduino/arduino_esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/pbuf.c line 1306
0x40203688: ClientContext::_consume(unsigned int) at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 310 (discriminator 1)
:  (inlined by) ClientContext::read(char*, unsigned int) at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/libraries/ESP8266WiFi/src/include/ClientContext.h line 253 (discriminator 1)
0x40204bc4: __yield at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/core_esp8266_main.cpp line 57
0x40216580: do_handshake at ssl/tls1.c line 2007
:  (inlined by) basic_read at ssl/tls1.c line 1483
0x4021695c: do_client_connect at ssl/tls1_clnt.c line 168
0x401004d8: malloc at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/umm_malloc/umm_malloc.c line 1668
0x4020343c: SSLContext::_delete_shared_SSL(SSL_*) at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 310 (discriminator 1)
0x402166e8: ssl_read at ssl/tls1.c line 2007
0x40203e25: SSLContext::connect(ClientContext*, char const*, unsigned int) at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 310 (discriminator 1)
0x40204b4c: esp_yield at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/core_esp8266_main.cpp line 57
0x4020136f: delay at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/core_esp8266_wiring.c line 51
0x40204073: WiFiClientSecure::_connectSSL(char const*) at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 310 (discriminator 1)
0x40204119: WiFiClientSecure::connect(char const*, unsigned short) at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 310 (discriminator 1)
0x40107158: sntp_get_current_timestamp at ?? line ?
0x40107158: sntp_get_current_timestamp at ?? line ?
0x402022d4: loop_send_post(int) at /var/folders/ld/dws59xv93p15208nvrw7tt9w0000gn/T/arduino_modified_sketch_158237/HTTPSRequest.ino line 86
0x40244290: pm_wakeup_init at ?? line ?
0x4023d5cd: test_tout at ?? line ?
0x4023d631: test_tout at ?? line ?
0x40238168: system_adc_read at ?? line ?
0x402013fa: __analogRead at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/core_esp8266_wiring_analog.c line 33
0x4020245c: loop at /var/folders/ld/dws59xv93p15208nvrw7tt9w0000gn/T/arduino_modified_sketch_158237/HTTPSRequest.ino line 52
0x40204b98: loop_wrapper at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/core_esp8266_main.cpp line 57
0x40100710: cont_norm at /Users/lony/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/cont.S line 109

The sketch/code I use:
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

static const String         SYSTEM_NAME = "S3";

static const char*          WIFI_SSID = "SSID...";
static const char*          WIFI_PASSWORD = "PW...";
static String               local_ip;

static const char*          TARGET_HOST = "host.com";
static const int            TARGET_PORT = 443;
static const String         TARGET_URL = "/v1/noise-data-receiver";
static const char*          TARGET_SSL_SHA1_FINGERPRINT = "8D ....2"; // To retrieve use web browser

static const int            BAUD_RATE = 9600;
static const int            PIN_SENSOR = A0;
static const int            PIN_LED = LED_BUILTIN;

static WiFiClientSecure     client;

static const int            THRESHOLD_NOISE = 100;
static int                  level = 0;

static const unsigned long  REFRESH_INTERVAL = 1000; // ms
static unsigned long        lastRefreshTime = 0;

void setup() {

  pinMode(PIN_LED, OUTPUT);
  Serial.begin(BAUD_RATE);
  setup_wifi();
}

void loop() {

  // Fetch noise level
  digitalWrite(PIN_LED, LOW);
  level = analogRead(PIN_SENSOR);
  digitalWrite(PIN_LED, HIGH);

  // Send HTTP POST request (every s)
  if(millis() - lastRefreshTime >= REFRESH_INTERVAL) {
    // Send request
    loop_send_post(level);

    lastRefreshTime += REFRESH_INTERVAL;
  }
}

/*
 * LIBS
 */

void setup_wifi() {

  Serial.println();
  Serial.println();
  Serial.print("Connecting system [" + SYSTEM_NAME + "] to WIFI ");
  Serial.print(WIFI_SSID);

  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

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

  local_ip = WiFi.localIP().toString();
  Serial.print("IP address: ");
  Serial.print(local_ip);
  Serial.println();
}

void loop_send_post(int level) {

  // Connect
  if (!client.connect(TARGET_HOST, TARGET_PORT)) {
    Serial.println("connection failed");
    return;
  }

  // Speed up sending
  client.setNoDelay(true);

  // Verify TLS
  if (!client.verify(TARGET_SSL_SHA1_FINGERPRINT, TARGET_HOST)) {
    Serial.println("certificate doesn't match");
    return;
  }

  // Send
  String body_json = "{ \"id\": \"" + SYSTEM_NAME + "\", \"noise\": " + String(level) + " , \"ip\": \"" + local_ip + "\" }";
  client.print("POST " + TARGET_URL + " HTTP/1.1\r\n" +
               "Host: " + TARGET_HOST + "\r\n" +
               "Connection: close\r\n" +
               "User-Agent: ESP8266\r\n" +
               "x-api-key: GEeGwazU1Ia2h6rZH6e0y4jwlxhjVurT9OWbOed4\r\n" +
               "Cache-Control: no-cache\r\n" +
               "Content-Type: application/json\r\n" +
               "Content-Length: " + body_json.length() + "\r\n" +
               "\r\n" +
               body_json);
  Serial.println();
  Serial.println();
  Serial.println("Request: " + body_json);

//  // Wait for response
//  unsigned long timeout = millis();
//  while (client.available() == 0) {
//
//    if (millis() - timeout > 5000) {
//      Serial.println(">>> Client Timeout !");
//      client.stop();
//      return;
//    }
//  }
//
//  Serial.println("Response: ");
//  while(client.available()){
//    String line = client.readStringUntil('\r');
//    Serial.print(line);
//  }
}

Can you please move the declarion of your WiFiClientSecure client in your loop_send_post function to force the destruction of that object at the end of the function? Sounds like your client leaks memory because the session is never closed properly.. Maybe try calling client.stop() after sending your request, too?

It is already running more stable thank you. Still there are delays in the execution. Do you know if there is a tool to analyse memory leaks more detailed?

1 second to do a TLS handshake with huge RSA certs is kinda hard on your ESP8266, so I would not expect new sessions to be established that fast. If you want less delay you should .connect() in your setup once and use Connection: keep-alive to POST as many times as possble before re-establishing the connection (and handshake). Regarding memleaks: You can print the amount of available heap memory anytime by using the ESP.getFreeHeap() function.

If you can fully solve this problem you should post an answer yourself afterwards to close the question

Will do but so far I only succeeded running the job consistently by moving the client into the function. Everything else needs another week.

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


text:
Can i send sensor data from arduino to cloud without sending it via PC
I am trying to build a GPS tracker. I need to send the data from GPS sensor on the arduino uno board to cloud directly i.e. without sending it via PC or mobile.
Is it possible and if yes, HOW?

GSM module...? Or does that equate to "mobile" for you?

use an esp8266 and a router.

The best way of sending data straight to a cloud will be by laser.:)  You can use any method of networking that is applicable to your situation, ESP8266 is probably the best as @dandavis says, but also there is Ethernet.  If you allow yourself a receiving stations then blue tooth, IR and RF are also possibilities.

Another option is an Arduino board that has built-in wifi hosting, e.g. Arduino MKR1000 https://store.arduino.cc/arduino-mkr1000

Arduino UNO is a micro controller without any internet communication. In order to send data to the cloud, you need to have an internet connection (meaning TCP/IP stack).
In regards with your project, there are 2 major solutions:

Store all data locally on EEPROM (if not too much data because there is only 1KB on the Arduino Uno) or an external flash memory (there are some modules and libraries for this). When the Arduino is connected, you send over all the data to the cloud.
Send the data while data are collected.

In both case, you need an internet connection that could be managed by a wifi module or a GPRS module depending on your needs.
For the wifi module, the ESP8266 is a popular and cheap choice. You will find a lot of documentation on Google.
For the GSM/GPRS module, I suggest the SIM800L which is cheap and easy to use (there is a HTTP/S stack embedded on the module).

btw AI Thinkers - the creators of the esp8266, have developed a gsm board too, that might be worth taking a look at - https://www.iot-experiments.com/ai-thinker-a9-module-with-custom-firmware/

To connect to the cloud directly while the tracker is on the move, you'll need to use GSM & GPRS technology, ie. a SIM card to make a 3G/4G connection to the Internet. GSM gets you connected, GPRS does the Internet traffic. Using WiFi to connect to a router won't work since you'll soon get too far from the router.
I suggest initially investigating the SIM908 and SIM800L (there are others).
Here are 2 projects which both use the SIM908 (GSM, GPRS AND GPS):
Geolocation Tracker (GPRS + GPS) with SIM908 over Arduino and Raspberry Pi
Where is my car? Realtime GPS+GPRS Tracking of Vehicles Using Arduino
The cheaper SIM800 is also popular GPRS/GSM module (no GPS capability, but you already have that?):
QUICKSTART SIM800 (SIM800L) WITH ARDUINO
This technology is moving quickly, so you may find better options, for instance see:
Difference between SIM908 vs SIM808 modules
Hope this helps,
Regards, Geoff

Not with a UNO alone, the UNO obviously needs internet connection either via a LAN shield, a Wi-Fi unit (ESP8266) or a GSM unit.
Since you are GPS tracking then a GSM unit is most suited.
Particle Electron GPS receiver (Location plotted on Google Map)
https://www.brianmoreau.com/projects/particle-electron-gps-receiver/particle-electron-gps-receiver.php

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


text:
DHT22 need pull down/up ESP8266
I have the strange pb.
My esp8266 was working fine with my DHT22 and then failed every time.
I loaded an example sketch in a other ESP8266 and I have the same pb.... until I shut down -> up the DHT22 when the ESP8266 is working.
To check more, I added this at the setup before dht.begin() :
      digitalWrite(0, LOW); // turn the LED on (HIGH is the voltage level)
  delay(1000); // wait for a second
  digitalWrite(0, HIGH);

And it works. But I don't know why I need to do this "pull up".
PS : I already tried with or without the 10K resistor, same pb.
PS2 : I already tried with 3.3v or 5V for DHT22. Same pb.
Any idea ?

how is the DHT22 wired and what esp8266 module you use?

I use a nodeMCU (Bangood, Geekcreit). The DHT22 is wired like this : https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity/arduino-wiring?fbclid=IwAR0cLuSXA4HMeCTtD-YC03FJ9pqGUj37HY_hyMXhz5dp4z-I-HkIzA1Or0Y

to which pin of NodeMcu is the DHT data pin 2 connected? to D2 (io 0)?

I connected it to pin D4. But the pb is I can see the data AFTER the pullUp trick. So why ?

sorry D2 is not io 0, it is io 4

Can you use a i2c humidity and temperature sensor? The dht sensors are not accurate and they cause many problems. The esp8266 is sensitive for this bug: https://github.com/adafruit/DHT-sensor-library/issues/48 The data signal has a shortcut since that library was written. The issue is from 2015 and adafruit has not fixed it yet, so they probably never will. Please use a i2c humidity and temperature sensor.

No, I haven't an other one. As the DHT11 and 22 seams to be used frequently, I thought it was good. I will check the issue. Does it work if we modify the lib code ?

Cocorico, when you use @Jot in your answer, I will get notified. There are also timing issues with the esp8266 and the dht11 / dht22 sensors, and library incompatibilities. That was already a problem, but since this year many have issues. So please use a i2c humidity and temperature sensor.

I answer my own question in case someone has the same issue.
The ADAFRUIT_DHT lib DOESN'T WORK WITH ESP8266. It keep saying Failed to read from DHT sensor! until you unplug/plug the VCC on the DHT.
But the DHTesp (link) works very well at first try !
Thx @Juraj and @Jot for their support.


text:
Can someone help me with my arduino and relay and switch?
This is my code. What i want to do is activate the relay when switchInNcPin is activate. I am using a switch (micro switch). It has COM NC and NO pins. Can you tell me what is wrong with my code?
PROBLEM:
The relay keeps clicking ON and OFF even though it is meant to wait 5000ms, activate, wait 3000ms, deactivate only once. Can you look at my code and help me?

connect the switch like a button https://www.arduino.cc/en/Tutorial/InputPullupSerial

please don't post pictures of code, copy the code into your question and use the proper format. This way people can copy all or part of your code, make changes and use that in their answer.

Maybe it's not the only problem, but at least:
int val = ...

and
if (val == "FLUSH")

do not match.
I assume you mean a digit here (0 or 9 to flush)?
Also, you should put your circuit in your question. A reason because of the 'flipping' is that your switch is not pulled down, and it results in undefined behavior.
Another thing you could add is debouncing, when a switch is clicked, it results in multiple 0/1 and 1/0 transitions (although your delay might help too).


text:
Septic tank project
We are to make a project.We have to connect MQ7, buzzers and lights to Arduino. And one buzzer will make sound when gas reaches high level and another buzzer will beep when gas level is very low.. High gas amount will lead to red light glow and very low gas will lit green light.. HOW TO EXECUTE ??

Your question is too broad. This site works best with specific, rather narrow questions. What exactly is preventing you from making the project? Have you googled, how to control the components with an Arduino? There are plenty tutorials out there.

It's a good idea to plan your code by first ignoring any details about the Arduino or the sensors and make a rough list of steps you would need the Arduino to take. When you have done that, then look at each step and do the same thing again - plan that broad step into finer detail. Try doing that first, then if you feel stuck at some point, then say what you did or tried, and what part you don't understand or failed to work the way you expected it to. We're much better able to help with that kind of a question.

I suggest you take a 1 or 2 liter tupperware (i used an empty ice cream container) to test.  leave a little cup of poop and you will get all the gas you need real soon.  For your final project, though, I would have 2 sensorsper nbnoard and at least 2 boards.  PEOPLE DIE IN SEPTIC TANKS.  be safe.  UPVOTED

Easy, this is one of the simple projects used as an introduction to Arduino programming.  You will find many versions of free code out there.  below is an example and a total newbie step-by-step.

Download Arduino IDE.  Buy an MQ7, an Arduino or NodeMCU, a breadboard, a LED and some jumper wires and you are in business.  Use the sketch below or google "MQ7 arduino sketch".
/* MQ-7 Carbon Monoxide Sensor Circuit with Arduino */

const int AOUTpin=0;//the AOUT pin of the CO sensor goes into analog pin A0 of the arduino
const int DOUTpin=8;//the DOUT pin of the CO sensor goes into digital pin D8 of the arduino
const int ledPin=13;//the anode of the LED connects to digital pin D13 of the arduino

int limit;
int value;

void setup() {
  Serial.begin(115200);//sets the baud rate
  pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
  pinMode(ledPin, OUTPUT);//sets the pin as an output of the arduino
}

void loop() {
  value= analogRead(AOUTpin);//reads the analaog value from the CO sensor's AOUT pin
  limit= digitalRead(DOUTpin);//reads the digital value from the CO sensor's DOUT pin
  Serial.print("CO value: ");
  Serial.println(value);//prints the CO value
  Serial.print("Limit: ");
  Serial.print(limit);//prints the limit reached as either LOW or HIGH (above or underneath)
  delay(100);
  if (limit == HIGH){
    digitalWrite(ledPin, HIGH);//if limit has been reached, LED turns on as status indicator
  } else {
    digitalWrite(ledPin, LOW);//if threshold not reached, LED remains off
  }
}

original sketch published by Learning About Electronics

Answers should be complete and do not link important data (like the scetch) but contain it. In some time the website you linked will be dead any your answer useless.

i uploadded the file as directed by stackexchange.  i did not link it to an external site.  SE linked it to imgur

I meant the "Use this sketch" link. If the target site goes down then the whole answer is missing most important part. https://stackoverflow.com/help/how-to-answer "Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline."

that is precisely why i wrote or google "MQ7 arduino sketch" @FilipFranik  ;)


text:
How to read high voltage (40-65v) from a Solar Battery bank
I would like to monitor the battery voltage of a 48v solar battery system. The expected voltage range is 40-65v.
I have tried creating a voltage divider with 2 resistors but with all values I have tried one resistor almost melts as soon as you connect to battery.
Also, using a voltage divider creates a (small) drain which I would like to avoid.
Can anyone suggest a way of reading high DC voltage (40-65v) with and Arduino (really I'm using an ESP8266)?
If Voltage Divider
please suggest resistor types (e.g. 1/4watt or 1-2% etc, I'm new here but know there are many types) and values that I could read with A0 (analog pin, max 5v)
Can I use a MOSFET to connect the voltage divider just before reading the voltage? How?
or another way
like a circuit (from AliExpress) or using some other component that would be greatly appreciated.
So far this article has been helpful, it talks about a voltage divider with a opamp to get more accuracy, but I need a bit more advice from someone that knows more than myself.
https://openenergymonitor.org/forum-archive/node/11011.html
Thanks in advance for any help.

Is this what you are trying to do? https://electronics.stackexchange.com/questions/42710/how-to-read-high-voltages-on-microcontroller

the resistance of your voltage divider (the sum of both resistors) needs to be that high so that the current is rather small, milliamps or less (to prevent the melting of the resistors and the discharge of the battery). Note that the proportions of both resistors define the voltage level for the analog in while the sum of both resistors are relevant for the current. So higher is better but unfortunately you also need 2) that resistance to be low compared to the input impedance of the analog input. This is where the OPAMP might come into play. Both are adressed in the link posted by VE7JRO.

You need a voltage divider with resistors that have large values.

...but with all values I have tried one resistor almost melts as soon as you connect to battery.

This suggests that you have been using values that are too low.
So lets go through the calculations to select good resistor values.
1/4 Watt resistors are common and easily available so I will base my calculations on that. These calculations will also be suitable for 1/2 Watt and 1 Watt resistors.
I am also going to add some margin above the 65V max that the solar panel can output (plus it makes the math easier)
Max Voltage = 100V

The voltage Divider:

Let's simplify. Almost all of the current will be going from your source, through the resistors (R1 & R2) to ground. Let's simplify by initially calculating the resistance required if R1 & R2 were combined into a single resistor:
From V = I x R
And P= V x I
Minimum resistor = V^2 / P
R = 75^2 / 0.25
R = 22500 Ω minimum
I would go further and say double that because I never like operating a resistor right on its maximum power rating. ie  the minimum that R1 + R2 should equal is 50kΩ.
Lets play it safe and say that R1 + R2 is 100kΩ. The ESP8266 ADC pin input voltage range is 0 to 1V. Input is 0-100 V (which covers the required 40-65V range). Now all we have to do is calculate for R1.
Note: Most ESP8266 development boards come with an internal voltage divider. For these boards the input range is 0 to 3.3V.
Edit: The OP tells me that they get a max analog reading at 3.0V not 3.3V. Adjust the below calculations for an input voltage of 3.0V not 1V.
The formula to calculate the output voltage is:

Vout / Vin = R2 / (R1 + R2)
1 / 100 = R2 / 100kΩ
0.01 = R2 / 100k
Therefore R2 = 1k Ω
R1 = 100k - R2 = 99kΩ
I would up R1 to 100kOmega; as it will only result in a 1% error.
So R1 = 100kΩ and R2 = 1kΩ

Values of R1 = 49.5kΩ and R2 = 500Ω would also work.
In this case R1 could be made up of 2-3 resistors in series:
47KΩ
2.2KΩ
300Ω or 330Ω (optional)

The raw ADC input on the ESP8266 chip is 0-1V with a high input impedance (~20M). This means an op-amp buffer is not needed.
However, if you are interested, a op-amp circuit can be built from a 741 IC (among others) and is configured like this:

Thank you very much for putting your time into that answer. I tested a few ESP8266 dev boards I had and to get 1024 on the Analog pin it only requires 3v on all my boards, specs do say 3.3 but all voltages higher than 3 just = 1024 so I will factor this in to my calculations, thank you again!

It sounds as if you have tried using far too small a value resistors. For example, if you used resistors totaling , say, 1,000 ohms across a 50V supply then they would dissipate V^2/R watts = 2.5W. Standard 1/4 watt resistors are going to melt when overloaded 10 times.
So it boils down to picking a pair of resistors that
1) Are working within their wattage rating.
2) Give a convenient scaling factor.
3) Draw an insignificant amount of current relative to the ratings of the solar panels.
The design of any voltage divider also depends on the input impedance or load imposed by the ESP8266. Referring to the ESP8266 Community Forum the analog input imposes a 50nA load, but they also state that the maximum input voltage is only 1V (equivalent to 20 M ohm impedance). The Adafruit forum also suggests that 1V is the maximum. Maybe the board you have has different built in scaling.
For the sake of argument, let us assume the following
Voltage range to be measured = 40 - 65V
Maximum input voltage of pin A0 = 1V
Pin A0 can draw 50nA and this should not effect the measurement by more than 1 in 2048 (half the least significant bit of the ADC).
The current through the voltage divider should therefore be at least 2000 * 50nA = 0.1 mA. This almost certainly meets the requirement of not significantly loading the battery.
So based on the low end of the voltage range the divider chain should total in the region of 45V / 0.1mA = 450K ohms. The two resistors need to be in the ratio 64:1 in order to drop a 65V input to 1V. Referring to standard resistor values, 360K and 5K6 in series will be very close to 64:1 (64.28:1). They will draw a maximum of 65V/(360K + 5K6) = 0.18mA and the 360K resistor will dissipate about 10mW.
So standard quarter watt E24 series 1% resistors should be suitable.

Wow thank you so much for a great explanation.
I have a few ESP8266 devices, all analog pins can take up to 5v but I think in reality the A0 (ADC) should be max of 3.3v (see Wemos
Any chance you could let me know the values to go from 60V to 3.3v?

Your Vin is 60V and Vout is 3.3V , Assume R1 and R2 have same value, then calculate the values of R1 and R2 using above formula i.e. Vout = (R2/(R1+R2))*Vin;

I have not use your particular ESP8266 board, but it may be that 3.3V is the maximum voltage you can apply to the A0 input without causing damage. The input voltage that will generate the full scale 10 bit encoding (1024) may well be different. You need to do a bit more research, either by finding a more detailed data sheet or testing it on the bench with a low voltage source, a meter and a program that loops reporting the ADC output.

Hi @PeterJennings , I have tested the boards I have, they read max input (1024) at 3v (not 3.3 like the specs say) so I'll adjust accordingly, thanks.


text:
Can´t load a program into my ESP01 using an ArduinoUno
This is my problem,  I´ve been trying to load a program(any program) into mi ESP01 and because I do not have the usb adapter, I decided to use my Arduino Uno to do the work.
This is my first time working with this board (ESP01), and in my search I found that it is important to have GIO0 LOW ,GIO2, RST and in HIGH to upload a program; besides I already have this board into the list that Arduino´s IDE have and I used 3.3v for VCC.  Yet, when I try to upload a program, the IDE wont let me because of this error: esptool.FatalError: Failed to connect to ESP8266: Invalid head of packet (0xF0
The program that I want to try is the HelloServer example.

Thanks for your help!!

what is your question?

the sketch in Uno should not have Serial.begin(). make it simpler by pulling down io 0 all the time why you try flash the esp (remove the switch)

I would not trust breadboard connections for RX voltage divider. you can test it by wiring RX without voltage divider. esp8266 can tolerate 5 V on pull-up current levels used with TTL Serial.


text:
20x4 LCD Error. 8 black boxes to the left on row 3 and 4
20x4 I2C conected LCD. 8 black boxes to the left on row 3 and 4.
What could the problem be?

Add the (relevant) code

What Arduino? Due or Mega? My guess is that your i2c wires are too long and/or there is a timing issue. Is this the code? https://github.com/johnrickman/LiquidCrystal_I2C/blob/master/examples/HelloWorld/HelloWorld.pde

the picture does not show black boxes ... they look white or light blue to me

@MikaelPatel. im running on a Mega 2560. Yes it is that code. but i have tried diffrent code. same everytime. I dont have shorter Wires, but i have tested extended them to over 100 cm. No diffrence at all to my 20 cm cables. So mayby the length of the cables are not the issue? Mayby its just a bad lcd?

Ok so it is not the wire length. It is the first 8 characters per line and these do not map to the sketch. Or have you changed the sketch? Please add the sketch you are running.

@MiaelPatel  ok my latest code has the same problem as the LiquidCrystal_I2C example code. i wrote to the lcd is a simple calculator. Here is that code. (Im sorry the coments are in swedish. https://create.arduino.cc/editor/halt1/a2917809-ce6d-4dc7-8962-28e274b8fe9b/preview


text:
How can I make FastLED set every 2 LEDs to the same color?
I'm controlling an WS2812 LED strip in which every 2 leds is controlled together - they are setup as "eyes" in a prop.  I'm looking to control hundreds of these, so in an effort to save RAM I'd like to have each byte in the LED color array represent 2 LEDs.  That is to say that when the FastLED library writes to the data lin I want it to duplicate every byte going out.
I've dug into FastLED code but get lost around the timings deep down in the code.
Any ideas?

use an ESP, they have plenty of RAM. modifying the code to save ram will be a lot of work and probably limit features/updates.

@dandavis I’m trying to use up a pile of atmega328 chips that I have. Saving the 400 or so bytes would be perfect without reworking the board. However, o have a bunch of old atmega1284 chips too. Going that route.

The FastLED community appears to live at this reddit.com site. Consider asking your question there.
It is unknown if the following will exceed the current limitations of the Arduino platform you are using.  But, consider sending the same data to two different strings of LEDs simultaneously.  Briefly, each LED strips off the 1st packet of data and sends the balance of data through to the next LED.  Two different strips should behave the same if given the same data.  Thereby creating the effect you described (pairs of LEDs behaving the same).

I'm dealing with premade strips of eyes, so the two strip idea isn't feasible at this time. Thanks for pointing me to the subreddit. I've posted there.

A quick look at the FastLED repository and it looks like it is very complex and possibly created for multiple Arduino platforms (that is, different processors).  As such you need to specify exactly what hardware you are using.  Something you didn't list here.  And something that is specifically asked for over at the reddit.com site.  More to the point, the transfer rate to feed the LEDs can be very high and direct memory transfer for some of the higher end processors is a possibility.  In such a case it may be difficult to save much on memory.


text:
Unable to upload to Arduino Uno From Raspberry Pi
I am trying to upload code to my Arduino Uno from my Raspberry Pi 3B+ and have been following this guide.
After following the instructions and trying to upload, I received this error message.
pi@Positron-Pi:~/sketchbook $ make upload
-------------------------
Arduino.mk Configuration:
- [AUTODETECTED]       CURRENT_OS = LINUX
- [USER]               ARDUINO_DIR = /usr/share/arduino
- [COMPUTED]           ARDMK_DIR = /usr/share/arduino (relative to Common.mk)
- [AUTODETECTED]       ARDUINO_VERSION = 105
- [DEFAULT]            ARCHITECTURE =
- [DEFAULT]            ARDMK_VENDOR = arduino
- [DEFAULT]            ARDUINO_SKETCHBOOK = /home/pi/sketchbook
- [BUNDLED]            AVR_TOOLS_DIR = /usr/share/arduino/hardware/tools/avr (in Arduino distribution)
- [COMPUTED]           ARDUINO_LIB_PATH = /usr/share/arduino/libraries (from ARDUINO_DIR)
- [COMPUTED]           ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino//variants (from ARDUINO_DIR)
- [COMPUTED]           BOARDS_TXT = /usr/share/arduino/hardware/arduino//boards.txt (from ARDUINO_DIR)
- [USER]               USER_LIB_PATH = /home/pi/sketchbook/libraries
- [DEFAULT]            PRE_BUILD_HOOK = pre-build-hook.sh
- [USER]               BOARD_TAG = uno
- [COMPUTED]           CORE = arduino (from build.core)
- [COMPUTED]           VARIANT = standard (from build.variant)
- [COMPUTED]           OBJDIR = build-uno (from BOARD_TAG)
- [COMPUTED]           ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino//cores/arduino (from ARDUINO_DIR, BOARD_TAG and boards.txt)
- [DETECTED]           MONITOR_BAUDRATE = 9600  (in sketch)
- [DEFAULT]            OPTIMIZATION_LEVEL = s
- [DEFAULT]            MCU_FLAG_NAME = mmcu
- [DEFAULT]            CFLAGS_STD = -std=gnu11 -flto -fno-fat-lto-objects
- [DEFAULT]            CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics -flto
- [COMPUTED]           DEVICE_PATH = /dev/tty* (from MONITOR_PORT)
- [DEFAULT]            FORCE_MONITOR_PORT =
- [AUTODETECTED]       Size utility: AVR-aware for enhanced output
- [COMPUTED]           BOOTLOADER_PARENT = /usr/share/arduino/hardware/arduino//bootloaders (from ARDUINO_DIR)
- [COMPUTED]           ARDMK_VERSION = 1.5
- [COMPUTED]           CC_VERSION = 5.4.0 (avr-gcc)
-------------------------
mkdir -p build-uno
make reset
make[1]: Entering directory '/home/pi/sketchbook'
/usr/bin/ard-reset-arduino  /dev/tty36
Traceback (most recent call last):
  File "/usr/bin/ard-reset-arduino", line 45, in <module>
    ser = serial.Serial(args.port[0], 115200)
  File "/home/pi/.local/lib/python2.7/site-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/home/pi/.local/lib/python2.7/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 13] could not open port /dev/tty36: [Errno 13] Permission denied: '/dev/tty36'
/usr/share/arduino/Arduino.mk:1478: recipe for target 'reset' failed
make[1]: *** [reset] Error 1
make[1]: Leaving directory '/home/pi/sketchbook'
/usr/share/arduino/Arduino.mk:1454: recipe for target 'upload' failed
make: *** [upload] Error 2

After this I ran the command with root privileges and got this.
pi@Positron-Pi:~/sketchbook $ sudo make upload
-------------------------
Arduino.mk Configuration:
- [AUTODETECTED]       CURRENT_OS = LINUX
- [USER]               ARDUINO_DIR = /usr/share/arduino
- [COMPUTED]           ARDMK_DIR = /usr/share/arduino (relative to Common.mk)
- [AUTODETECTED]       ARDUINO_VERSION = 105
- [DEFAULT]            ARCHITECTURE =
- [DEFAULT]            ARDMK_VENDOR = arduino
- [DEFAULT]            ARDUINO_SKETCHBOOK =
- [BUNDLED]            AVR_TOOLS_DIR = /usr/share/arduino/hardware/tools/avr (in Arduino distribution)
- [COMPUTED]           ARDUINO_LIB_PATH = /usr/share/arduino/libraries (from ARDUINO_DIR)
- [COMPUTED]           ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino//variants (from ARDUINO_DIR)
- [COMPUTED]           BOARDS_TXT = /usr/share/arduino/hardware/arduino//boards.txt (from ARDUINO_DIR)
- [USER]               USER_LIB_PATH = /home/pi/sketchbook/libraries
- [DEFAULT]            PRE_BUILD_HOOK = pre-build-hook.sh
- [USER]               BOARD_TAG = uno
- [COMPUTED]           CORE = arduino (from build.core)
- [COMPUTED]           VARIANT = standard (from build.variant)
- [COMPUTED]           OBJDIR = build-uno (from BOARD_TAG)
- [COMPUTED]           ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino//cores/arduino (from ARDUINO_DIR, BOARD_TAG and boards.txt)
- [DETECTED]           MONITOR_BAUDRATE = 9600  (in sketch)
- [DEFAULT]            OPTIMIZATION_LEVEL = s
- [DEFAULT]            MCU_FLAG_NAME = mmcu
- [DEFAULT]            CFLAGS_STD = -std=gnu11 -flto -fno-fat-lto-objects
- [DEFAULT]            CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics -flto
- [COMPUTED]           DEVICE_PATH = /dev/tty* (from MONITOR_PORT)
- [DEFAULT]            FORCE_MONITOR_PORT =
- [AUTODETECTED]       Size utility: AVR-aware for enhanced output
- [COMPUTED]           BOOTLOADER_PARENT = /usr/share/arduino/hardware/arduino//bootloaders (from ARDUINO_DIR)
- [COMPUTED]           ARDMK_VERSION = 1.5
- [COMPUTED]           CC_VERSION = 5.4.0 (avr-gcc)
-------------------------
mkdir -p build-uno
make reset
make[1]: Entering directory '/home/pi/sketchbook'
/usr/bin/ard-reset-arduino  /dev/tty36
Traceback (most recent call last):
  File "/usr/bin/ard-reset-arduino", line 46, in <module>
    ser.setDTR(False)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 581, in setDTR
    self.dtr = value
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 453, in dtr
    self._update_dtr_state()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 614, in _update_dtr_state
    fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_DTR_str)
IOError: [Errno 22] Invalid argument
/usr/share/arduino/Arduino.mk:1478: recipe for target 'reset' failed
make[1]: *** [reset] Error 1
make[1]: Leaving directory '/home/pi/sketchbook'
/usr/share/arduino/Arduino.mk:1454: recipe for target 'upload' failed
make: *** [upload] Error 2

Any help would be greatly appreciated.

Seems, that you use the wrong serial port. Is your Arduino really connected to /dev/tty36? If yes, then you don't have the correct permission to access it. Check, which group the device has and be sure, that your user is part of this group

How would I check which group I am in, as well as the permissions I possess?

The command id will show the groups of the current user. with ls -l /dev/tty36 you can check the permissions and the group of the device.

/dev/tty36 is a root directory and the current user is in the group "27(sudo)"


text:
What is the difference between Tools > Board settings in Arduino IDE? ex: ESP32-Dev v. Huzzah32
I had a recent memory issue where the resolution was to change the Tools > Partition setting.  However this setting wasn't available in the Arduino IDE for the boards I was using (Huzzah32 and NodeMCU-32s).  I changed the board setting to ESP32-Dev Module, and the addition menu items under Tools appeared.  My project compiles and works fine now.
However it never occurred to me to set the Board to the "wrong" type.  What's the purpose of a vendor specific board setting when the more generic one appears to work fine?  What settings should you use and under what circumstance?
My guess is that the vendor specific board settings are more about the peripheral hardware on the boards (USB ports, LEDs, etc) and that the more of those you are using the more likely you'll need to use a board specific setting.   In my case, since my project uses just the WiFi and Bluetooth built into the ESP32 chip itself, that I'm ok, but if I was using a bunch of GPIO and other things I'd need to use the actual Huzzah32.  Is that right?

board-specific flavors take some of the guesswork out of burning the first image and save clicks when switching

For ESP32 boards the differences are very minor. In general an ESP32 is an ESP32. The only changes are name to pin mappings, and how to upload code.
There are a couple of different ESP32 modules, but in general all the boards use the same (cheapest) module.
If you look at the pins_arduino.h file for a variant you see that it is pretty much all in the format:
static const uint8_t SDA = 21;
static const uint8_t SCL = 22;

Just mapping names to pins. Note that some are special, like SDA and SCL above, which are used as defaults for the Wire library.
The biggest differences are in the boards.txt portion for the board. This is where any differences in the module will be defined.
In general though all the "specific" boards are just the "ESP32-Dev Module" with some options removed, and a new name give to it.  So you can usually use ESP32-Dev Module for any board as long as you select the right mode for things like flash.
One big benefit of using the correct board, though, is that a #define macro is provided identifying the board. If you want the same code to run differently on different boards (such as using different pins on different boards) you can use that macro to direct the flow of your code.


text:
Powering a MKR with regulated 3.3v
I've a low power consumption regulator to get 3.3V from two 1.5V batteries.
I'm going to use it for powering an arduino MKR (MKRFOX1200), so my question is where I should connect it, to the battery connector or directly to VCC.
Looking at schematics it's not clear to me which is the best option in terms of power saving, as VCC seems better but I don't know if it's ok to use that pin to give power

You don't really need your regulator. That board has a connection (X1) intended for directly connecting two AA batteries (according to the schematic).
However, if you want to keep it regulated at 3.3V for other reasons (the MCU will happily run from as low as about 1.62V) then sure - use your regulator.  But just treat it like batteries regardless. Connect the output of your 3.3V regulator to the battery connector, which goes via the power switching and control circuitry to the 3.3V rail of the board.

Yes I want to keep it regulated to 3.3V as sensors as DS18B20 are not happy under 3V, and for some others I need a more accurate potential and less drift than the discharging batteries. I actually have tested both modes, through X1 battery connector and through VCC, and the consumption is identical for the resolution of my multimeter (and under my specs), so I'm going to proceed with X1 battery connector. Thanks!

@avelo The only difference between connecting to VCC and to X1 is that X1 is protected against reverse powering (which could damage your batteries) when the board is connected to USB.


text:
How to rotate a servo motor on a specific angle?
I am trying to rotate a top on a specific angle after every 1 second. For example: 1 degree/second. I have two question:

Can I achieve this with servo motors?
If not, what motor should I use?

I know this question has very little description. I am mainly a programming guy. I don't much about arduino stuff. It's actually a hobby project for me.
Thanks in advance.

The kind people who have written the Arduino libraries include software drivers for servo control.  These drivers abstract the hardware from the programmer of the sketch software (the sketch is application software you write in C or C++).  It is unnecessary to understand the driver in detail.  However the servo driver software (likely written in C++) can been examined here.
To move a normal servo to a particular position, make a call to the Arduino Servo Driver using the function write(angle) passing an angle value from 0 to 180.  The value is an approximation of degrees and the value type is of type integer.
In the above links you will find this example of sweeping the servo motor across its range:
/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Proceed to that page for more details including a schmatic (diagram) of how the servo is connected to an Arduino Uno board.

One more question: can I use small arduino's like nano instead of mega/uno?

The deal w/using different platforms can generally be boiled down to 2 issues.  One, to make sure the HW is there to deal with the application.  In this case the Arduino servo libraries use the PWM HW inside the processor.  And both the Uno and Nano use the ATmega328P processor.  So that should work.  Two, the library has been ported to the different processor and board.  In this case the processor is the same.  So it is likely you can use a Nano instead of the Uno.

If not clear, @PotatoMan is correct.  Normal servos have a limited rotation (less than one complete revolution).  As you said, your end-goal is not clear.  So we can not help in picking out an alternative motor.

thanks man. I will work on it and find out more. I have got my starting point. Thanks for clearing things up. Have a nice day :)

You can rotate the servo motor per degree, but it has it's limitations, it only has 0-180 degrees of movement. If you need to rotate beyond that, I would recommend using Stepper motors, they can be very precise, but they don't have a potentiometer, like a servo does, so, after resetting the system, the motor won't comeback to the starting position.

Thanks man. However, @st2000 gave a far more detailed example.


text:
Windows 10 does not recognize Arduino Leonardo
Using Arduino Leonardo, IDE 1.8.9, Windows 10.
For a short time, when I first got the Leonardo, Windows 10 would recognize the board; I could see it in devices, Windows 10 would make a sound when plugged in, it would show listed in the ports of the IDE, and I could upload my code to the board (confirmed with blinking light sketch). It no longer does.
The error I get in the IDE avrdude: butterfly_recv(): programmer is not responding.
I believe the main issues stems from I had selected Arduino UNO (I have a couple of those as well) in the IDE and Uploaded my sketch.
Ever since I did this, Windows 10 no longer recognizes the board when plugged in. It doesn't even show in "other devices" under device manager.
I have tried the following:

The on-board reset trick that seems to be most of what other users experience and solves their issue. All variations. Holding the reset button, uploading, releasing, etc.
Swapping cables. Confirmed with another device it was a data cable and working.
Uninstalling and reinstalling the IDE
Restarting numerous times
Burning boot loader - since Windows 10 won't recognize the device, this fails immediately can't even communicate to the board.

I have seen similar questions about this, but none of them seem to specifically cover what I am encountering.

did you try a double reset?

the bootloader can be burned only with a programmer so it is not relevant if the board shows up as a port

I believe so yes. reset.. click upload... reset again when IDE says uploading?

no reset and reset. then select port and upload

yes tried that as well. waiting for it to appear in the ports menu. never does

Sounds like you've bricked it.  Your broken sketch (wrong MCU selected) means that it's not presenting a CDC/ACM port.
Your best bet is to use a hardware programmer (eg USBASP or another Arduino) to erase the chip and reload the bootloader.

Thanks for the info. Can you point me to a tutorial for this?

@static_cast It's the same as burning any Arduino bootloader. There's millions of tutorials online about how to do it. TBH I'd buy a USBASP. They're dirt cheap from China.


text:
Converting human readable date to a unix timestamp
Can anyone provide a sample code that would convert a human readable date like 2019-10-27 22:10:35 to a unix timestamp like 1572214235?
I found many topics about it, but they eider refer to out of date libraries, or they seem to address more complex time functions, I find it hard to extract this functionality from them.

If you have a fixed format you can use strtok() to slice the string into individual segments, then convert those segments to integers. They can then be used with TimeLib.h with the setTime() function.  You can then query TimeLib for the unix timestamp with now().
Edit: using PaulStoffregen's TimeLib, this code sets current time and returns current unix timestamp.
#include <TimeLib.h>

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

  // hour, min, sec, day, month, year
  setTime(22, 30, 11, 29, 3, 2019);

  // 1553898611
  Serial.println(now());
}
void loop() {}

Edit 2: And to convert any given date to a unix timestamp (without setting current time):
#include "TimeLib.h"

tmElements_t my_time;  // time elements structure
time_t unix_timestamp; // a timestamp

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

  // convert a date and time into unix time, offset 1970
  my_time.Second = 0;
  my_time.Hour = 23;
  my_time.Minute = 0;
  my_time.Day = 25;
  my_time.Month = 3 - 1;      // months start from 0, so deduct 1
  my_time.Year = 2017 - 1970; // years since 1970, so deduct 1970

  unix_timestamp =  makeTime(my_time);
  Serial.println(unix_timestamp);
}

void loop() {}

I already have them into separate values like year, month, etc, I just have no clue on how the code should look when using the time library. I am new to Arduino.

Pass the values to setTime() - I forget the order, but I think it's setTime(hours, minutes, seconds, year, month, day) - though check the documentation or source to be sure.  Then you get the time since the unix epoch with now().

Thanks, I was able to do that and added a full sample code in your answer, I still need a way to convert any given date (not just current time).

I hope you don't mind, I altered a code once more so I am able to select your answer as the correct one :D

After parsing the time into numbers, you can use the standard C time library time.h. More specifically, use the mktime function to convert a struct tm into a time_t, and use difftime to get the seconds since the start of the Unix expoch:
#include <time.h>

void loop() {
    struct tm ltm = {0};
    ltm.tm_year = 2019 - 1900;
    ltm.tm_mon  = 11 - 1;
    ltm.tm_mday = 5;

    int32_t epoch_seconds = difftime(mktime(&ltm), (time_t)0);
    Serial.print("Remember, remember, ");
    Serial.print(epoch_seconds);
}

Note that in struct tm, the year starts at 1900 and the month starts at 0.
EDIT: In avr-libc, difftime returns an int32_t, not a double.

So I replace 2019 with my year and I leave/append the  -1900 part, same for month, then where do I specify the hour, minute and second ?

@adrianTNT Yes, you can use tm_hour, tm_min and tm_sec to specify hours, minutes and seconds, respectively. The available fields of struct tm are linked in the reference. Cf. https://en.cppreference.com/w/c/chrono/tm

I tried the code, seems close but I get a timestamp like 626227200.00 which (without .00) is around 1989, I am lost.

Serial.print might have some trouble printing double-precision floats. Does it work when you change it to Serial.print((float)epoch_seconds, 0);? This should also cut off the '.00' decimal places at the end.

Do I have to set current time first ? If I just set year to 0 and no month or day, it prints a timestamp since 2006-02-07 (1139293696). In another answer I was able to set current time and print current timestamp, but converting any date with mktime would be nice.

The order of setting variables should not matter. It's odd that it prints unrelated times. I did experience something similar before I added the = {0} part. It's either an initialization error (you could check by printing a non-set member of ltm, e.g. Serial.print(ltm.yday) and see if this is always 0); or it might be a problem with Serial.print itself (did you convert it to float? Or try using char buf[20]; sprintf(buf, "%.10g", epoch_seconds); Serial.print(buf) instead).

That timestamp seems to be a default or an offset, I found web results when searching for arduino 1139293696. I think different time components inside the library might use different defaults/offsets. I will do some more tests.

Note that: 1. mktime() interprets the time as being in the local time zone, which on AVR is UTC until you change it with set_zone()/set_dst(). 2. avr-libc uses the epoch 2000-01-01. If you want a Unix timestamp, you should use mktime(&ltm) + UNIX_OFFSET.

"2038". When using int32, it means only 31 valid bits for real numbers, the final bit (MSb) is the negative sign. So we can only get a number of 2'147'483'647, and that arrives at the year 2038. If someone needs to increase this, perhaps the simplest thing would be to use a base year to subtract, and avoid overflow. Maybe that's why the year 2000 is used as a base, and maybe it's interesting to use 2020. Try this yourself: https://timestampgenerator.com/date-from-timestamp/2147483647/+00:00


text:
EEPROM.get returns bad data
I am using the attached code.
What I am trying to do is:
Test if there is a personalized "board serial number" written in the EEPROM (by previous code run)
If data found was not 7 characters (e.g SN-XXXX), then generate a serial number and save it to EEPROM
Problem is: it generates a serial correctly, it even stores and reads it a few times, but when I disconnect the USB cable and reconnect to test again, it returns some bad data from the EEPROM, like: ⸮^R⸮y⸮| which seems to pass my 7 characters test and it doesn't generate a new one.
What am I doing wrong ?

#include <EEPROM.h>

// board SERIAL number
char serial_characters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"};
// will be filled as SN-A2KH
String serial_number;

void setup() {

  Serial.begin(9600);

  // Get the float data from the EEPROM at position 0
  EEPROM.get(0, serial_number);

  // serial from EEPROM valid
  if (serial_number.length() == 7) {
    Serial.println("Found valid serial in EEPROM");
    Serial.println(serial_number);
  }

  // serial from EEPROM not valid (e.g not: SN-XYZ5)
  if (serial_number.length() != 7) {

    Serial.println("Serial from eeprom is NOT 7 chars, generating a random serial");
    Serial.println(serial_number);

    // if analog input pin 0 is not connected, use noise from it in order to generate a random seed, otherwise random is not so random
    randomSeed(analogRead(0));

    // serial might be empty now, set a "SN-" prefix
    serial_number = "SN-";
    for (int i = 1; i <= 4 ; i++) {
      serial_number = serial_number + serial_characters[random(0, 35)];
    }
    Serial.println("Generated serial now: " + serial_number);

    // save to eeprom if format is valid
    if (serial_number.length() == 7) {
      EEPROM.put(0, serial_number);
      Serial.println("Written serial to EEPROM");
    }

  } // <<< serial from eeprom not correct, generated one

}

void loop() {}

You are saving a String object in EEPROM, which is useless. A string
object does not store the contents of your string. Instead, it just
stores:

the memory address where the actual contents (the characters) is
stored
the amount of memory allocated for this contents
the number of characters that actually make the string

This is what you are storing to, and retrieving from EEPROM. So you get
the correct number of characters (third item in the list above), but the
memory address now points to uninitialized RAM.
I suggest instead storing in the EEPROM a raw C string, i.e. an array of
8 chars (7 printable chars plus the terminating NUL). You could achieve
this by just changing the declaration of serial_number:
char serial_number[8];

For checking the validity, I would just check that it starts with "SN-"
and the last char is a NUL:
if (memcmp(serial_number, "SN-", 3) == 0 && serial_number[7] == '\0') {
    ...
}

You could do a more stringent validation though, and check that the
other 4 chars are within the valid set.
Edit: to build serial_number with random chars:
strcpy(serial_number, "SN-");
for (int i = 3; i < 7; i++)
  serial_number[i] = serial_characters[random(0, 36)];
serial_number[7] = '\0'; // terminating NUL

Just to have the full working code, I ended up with this:
#include <EEPROM.h>

char serial_characters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"};
// 7 chars for serial and one for string end '\0'
char serial_number[8];

void setup() {

  Serial.begin(115200);

  EEPROM.get(0, serial_number);

  // check found format
  if (serial_number[0] == 'S' && serial_number[1] == 'N'  && serial_number[2] == '-' && serial_number[7] == '\0') {

    Serial.println("serial from eeprom is valid");
    Serial.println((char*)serial_number);

  } else {

    Serial.println("no valid serial found in eeprom, generating new serial");

    // if analog input pin 0 is unconnected, use noise from it in order to generate a random seed, otherwise random is not so random
    randomSeed(analogRead(0));

    // generate a new serial
    serial_number[0] = 'S';
    serial_number[1] = 'N';
    serial_number[2] = '-';

    // overwrite ending chars of serial with random values
    serial_number[3] = serial_characters[random(0, 35)];
    serial_number[4] = serial_characters[random(0, 35)];
    serial_number[5] = serial_characters[random(0, 35)];
    serial_number[6] = serial_characters[random(0, 35)];

    // end string with null as raw C strings ?!
    serial_number[7] = '\0';

    Serial.println((char*)serial_number);

    // write new serial to eeprom
    EEPROM.put(0, serial_number);

  }

}

void loop() {

}


text:
How to merge two GPS coordinates without losing decimals
I want to take the GPS coordinates like 42.1234 per 22.1234 and merge them as a string, with a separator character:
42.1234 x 22.1234
But using this code:
gps_string = (String)gps.location.lat()+' x '+(String)gps.location.lng();
I lose the last decimals and I get:
42.12 x 22.12
The only way I could see full coordinates is by specifying an extra parameter to println, like this:
Serial.println(gps.location.lat(), 6);
How can I create a string containing both two coordinates without losing decimals ? e.g 42.1234 x 22.1234

your question has nothing to do with GPS ... it is a question about converting a floating point number to string without losing precision

one thing to note, the GPS module probably outputs text, not floating point numbers

What GPS module have you got? What GPS library are you using?

@Dougie I can check when I get back on computer but like jsotola said, it is a float number conversion issue, not really speciffic to this GPS, but to Arduino.

Try using dtostrf(val, 4, 6, buff); rather than casting the value to a String.

the CStringBuilder from my StreamLib allows to build a C string (char array terminated by 0) with the same functions you use on Serial

@jsotola: The GPS module probably outputs text in the NMEA format, with degrees, minutes, and minute decimals. So you'll need to convert that anyway.

If you want 4 decimal places, you may try something like this:
gps_string = String(gps.location.lat(), 4)
           + " x "
           + String(gps.location.lng(), 4);

https://forum.arduino.cc/index.php?topic=243660.0 suggests avoiding Strings and String() functions. Use dtostrf(val, 4, 6, buff);

This one works very nice (simple). If I can simplify the code a bit, I will post an answer using the dtostrf. I understand the dtostrf method is for memory/performance considerations.


text:
Why isn't this EEPROM.get() working?
I am trying to save a string/char to EEPROM with EEPROM.put() and then get the value, but it doesn't work and I get a blank value when I do a EEPROM.get().
I remember this is how it worked on arduino nano, but now I am trying with an ESP32 board, do they work different ?
#include <EEPROM.h>

char my_string[8];

void setup() {

  Serial.begin(115200);

// I am writing by this code, then comment it out to try to read from EEPROM
/*
    my_string[0] = 'S';
    my_string[1] = 'N';
    my_string[2] = '-';
    my_string[3] = 'A';
    my_string[4] = 'B';
    my_string[5] = 'C';
    my_string[6] = 'D';

  EEPROM.put(0, my_string);
*/

  EEPROM.get(0, my_string);

  Serial.println("data is: ");
  Serial.println((char*)my_string);
}

void loop() { }

EEPROM can't store string. It stores numbers.  put() takes a type and stores that type as numbers.
The char[] isn't a string - it's a number. More specifically it's a memory address for where the string data is stored.
All you're doing is storing that memory address, not the data itself.
Instead you need to iterate over your string. You should also store the length of the string if it's going to be variable.
For example:

void storeString(const char *str) {
    EEPROM.write(0, strlen(str)); // Store the string length
    for (int i = 0; i < strlen(str); i++) {
        EEPROM.write(i + 1, str[i]);
    }
}

void getString(char *str) {
    int len = EEPROM.read(0);
    for (int i = 0; i < len; i++) {
        str[i] = EEPROM.read(i + 1);
    }
}


text:
Arduino library or code for ESP32 to scan for Bluetooth devices?
Is there some code or library that would allow me to scan for nearby Bluetooth devices using a common ESP32 board ?
I only found similar code for actual Arduino boards.

a web search reveals some

Well.. now this question is answer #4 in a web search and 2 of the answers above are for BLE only and the other one leads to another unanswered question. It is not that easy to find good example because the Arduino-ESP32 framework added advanced Bluetooth support just recently - and its not that easy to use the receent versions.

@IanH Almost two years later, there is an actual solution to this. See gbafamily's answer below.

https://github.com/esp32beans/ESP32-BT-exp is a Bluetooth Dual
Mode (classic and BLE) scanner. ESP32-BT-exp works on the original ESP32. No other ESP32 supports BT classic mode.

Worked as promised! How unfortunate that it is *only * ESP32, and not ESP32S2/S3 or ESP32C2/C3. (Cue rant on Espressif's naming conventions...)

The ESP32 Arduino boards support package includes libraries for ESP32 Bluetooth and BLE. Both libraries have examples which you can find in Arduino IDE Examples menu.

I looked trough the examples but I didn't see one that lists nearby devices, just various example on how to pair with specific device.


text:
variable name standards, e.g best method to send motion_detect=true
I am working with some sensors and sending data to a public web server via http, I was thinking this server can be possibly used by more people to send their data and server displays a chart.
I was wondering if there is a IOT industry standard when sending certain type of data, so that in future I don't need to rename this or change documentation to be more compatible or more intuitive.
For example when sending a "motion detected" ping, do I go with pir=true, pir=1, motion_detect=true ?
Then for example when sending temperature, it would be much better temp_celsius=30 then just temp=30.
It should also make developers job much easier if there is a certain standard. Is there one ?

Yes, there are systems designed to continuously receive such data and the data exchange is standardized, even some Units are standardized.
OPC DA
An example is OPC Data Access for real time values. It seems you want to build a graph, so OPC Historical Data Access is more what you're looking for.
One would set up the data points on the server side once, i.e. configure the type and unit that you're gonna receive on that "channel" or "port" or whatever you call it.
Unfortunately, OPC DA and OPC HDA use XML and building XML is not trivial. It's not very suitable for IoT devices.
Lessons learned: configure the unit on server side and let the client send data only. Do not use XML for data transfer.
OPC UA
Then there is OPC Unified Architecture. They also learned their lesson and removed XML and added security. They now use a binary protocol. The specification is more than 1000 pages, so understanding it will be difficult and is in fact so difficult that even OPC UA implementations of different companies do not work together well.
OPC UA defines 25 data types and ways of defining other data types.
The address space in OPC UA is hierarchical - and probably a device can exist in multiple hierarchies, e.g. physical topology like floors and rooms or logical topology that fits into the structure of the machine.
Lessons learned: make the protocol simple and think about security, i.e. if you want to do URL encoding (GET), then use HTTPS at least. AFAIK, devices ESP32 support encryption, so it's no longer a problem for tiny devices. People will use very strange data types, like 18 bit integers. Also, do not only provide a flat list of devices, but let them arrange stuff as needed.
MQTT and NodeRed
Now these were quite heavy protocols and models driven by companies. Of course there are also protocols better suited for IoT, like MQTT. MQTT is widely known and uses the also well known Node Red software for handling it. You can define workflows how the data should be handled, converted, stored and whether alarms shall be triggered above or below thresholds.
They already think of connection loss, reconnect and how to send all the data that was already recorded but could not be sent.
Lessons learned: People want more than just data storage and a graphics.
Units
openHAB tries to come up with a List of units. I am a radio amateur. I am measuring electromagnetic fields. I am still missing

SWR (standing wave ratio)
dBu (dB µW)
dBc (dB relative to the strongest signal)
dBV, dBmV (dB for Volts instead of Watts)

Personal experience
I was working for a company that made software for industry. There are devices that send a measurement value every 100 ms. Let's say this is a simple temperature value of just 1 byte, that's still 315'000'000 records per year.
How do you display such data? On a Full HD screen you would still need to combine 150'000 measurement values on a single column of pixels.
Lessons learned: you need sophisticated data crunching skills to generate the graphics. The users probably want some control over the time span they are viewing. They want zooming and panning.
Conclusion

I was thinking this server can be possibly used by more people to send their data and server displays a chart.

IMHO, sorry, it's hardly needed. People do not want to send their data to a random HTTP server. Some want to set it up at home only, so that no data ever reaches the Internet. Some people want to do more than just displaying a grpahics (especially alarms). MQTT and Node Red runs locally, on a Raspberry, on a server and even in the cloud, whatever you want.
You do not only need pir=true, pir=1, motion_detect=true, you also need

an ID for the device,
a timestamp when the data was recorded
potentially a way to send bulk data after the server was offline for an hour of maintenance
a system for units
encryption

That's quite an effort. Node Red has > 4000 commits.

No, there is no "industry standard". You are free to choose what you like.
If you want to be completely generic you could choose to do something like:
p1name=Temperature&p1units=celcius&p1value=23.4&p2name=Humidity&p2units=%25&p2value=43.8

(%25 is a % when URL encoded)
Or you could use:
p1=Temperature/Celcius/23.4&p2=Humidity/%25/43.8

That's just two examples. There is no end to how you could do it.

I don't think there is. It also kind of depends on how you are going to store the data.
I'd go with motion=true instead of pir=true, as it describes what you are detecting, instead of what sensor type you used. What if you decide to change the PIR sensor to a radar-based sensor. Now the variable name doesn't make sense.
Secondly, what happens if you add a second motion sensor somewhere else? I'd add something unique to the request. Something like a node-id. That way, you can differentiate between the two. Something like ?nodeid=1&motion=1. You can that also add additional info like the battery voltage for that node; ?nodeid=1&motion=1&voltage=3.1.
I don't think differentiating between C and F makes a lot of sense. But if it does you'd store this somewhere on the server, as it should never really change. Something like; the temperature value coming from nodeid 6, is the temperature in the "livingroom", and is specified in "C", and should be shown on a graph with Y-axis of "10 C" to "30 C".

Regarding nodeid I made it automatically generate a random serial number that is saved to EEPROM so each new node will send an unique ID.

For motion, to cover both situations (adding / replacing sensors and types) I might go with pir[1], pir2, radar[1], radar2 and user can associate friendly names on server.

On my own system I had every arduino have a nodeid. The each sensor has an id (unique for that node). Every sensor value was just a number. This made the packet data really compact (send via NRF24). The other upside was that I could just store this data directly to the database, without any preprocessing, as it does have to have idea what the data is. New nodes and/or sensors could be added with zero server changes. The web application showing the data did the heavy lifting, in turning the raw numbers to the real word data. This worked pretty okay for me. Maybe some part of it is useful to you

yes, that helps a lot, it is mostly how I do it now. And the NRF24 is nice, the one with external antenna goes 1 KM


text:
How to count the number of rising edges on DS3231 rtc?
I am using a DS3231 rtc and I would like to get millisecond accuracy from it so I decided to use the 32kHz generated clock from it. I wrote a code that would count the rising edges or falling edges using an interrupt with (RISING or FALLING parameters) but I get only zeros on my Serial board for the count.
Here is the code I am using :
#include <DS3231.h>
#include <RTClib.h>
#include <Wire.h>
#include "rtc.h"
#define InterruptPin 3

volatile long lcnt = 0;

RTC_DS3231 rtc;

void setup() {
  Wire.begin();
  Serial.begin(74880); // init serial port
  pinMode(InterruptPin, INPUT_PULLUP);
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
  attachInterrupt(digitalPinToInterrupt(InterruptPin), fcnt, FALLING);
}
void loop() {
  unsigned long a=millis();
  if (a<1000){
  Serial.println(lcnt);
  }
}

void fcnt(){
  lcnt+=1;
}

I just want to check how many rising edges I have in 1s. What is strange is that this code used to work and now it doesn't ^^'... I don't know if I changed something by mistake or deleted something useful.
Can somebody help me to resolve this little problem ?
Thanks a lot for your time !

try disabling the pullup resistor on the input pin

I'm not sure why you're getting 0 as such, but your interrupt and variable methodology leaves a lot to be desired (probably the cause of the "tutorials" you followed).
My primary concern is that you are using a 32-bit "long" variable in an interrupt, and referencing that directly outside the interrupt.  The Arduino is an 8-bit system, which means that all accesses to that variable take many instructions to arrange (splitting it down into 4 8-bit values, manipulating it, recombining it, etc).  Because of this no operations on that variable are "atomic".
You need to make them atomic.  If you don't then it's perfectly possible for the interrupt to trigger and modify the value in the middle of you doing something with that value.
The simplest way of making it atomic is to disable interrupts, then copy the value to another variable and/or modify it, and enable interrupts again.
Here's an example that I would consider stable:
#include <DS3231.h>
#include <RTClib.h>
#include <Wire.h>
#include "rtc.h"
#define InterruptPin 3

volatile uint32_t lcnt = 0;

RTC_DS3231 rtc;

void setup() {
  Wire.begin();
  Serial.begin(74880); // init serial port
  pinMode(InterruptPin, INPUT_PULLUP);
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
  attachInterrupt(digitalPinToInterrupt(InterruptPin), fcnt, FALLING);
}

void loop() {
  static uint32_t ts = millis();
  uint32_t a = millis();
  if (a - ts >= 1000) {
    ts = a;
    noInterrupts();
    uint32_t currentCount = icnt;
    icnt = 0;
    interrupts();
    Serial.println(currentCount);
  }
}

void fcnt(){
  lcnt+=1;
}

That should print the number of pulses over successive 1 second periods.

Thank you for your answer, I uploaded your code and I still get only zeros each second on my screen...

@JamesONeil Then you should triple check your wiring.

I already use one interrupt from the ds3231 for the alarm on the pin SQW to wake up my arduino and it works fine so the problem can come only from the pin of the 32kHz clock. I double checked my wiring and nothing wrong there...

I used the same code as yours and simply changed the datatype from uint32_t to unsigned long and it started working. May be you can try the same.


text:
USing arrays, binary data and bitRead
This is my first manually typed code. I'm sure there may be some glaring "schoolboy errors" in it, so wondered if people could give it the 'once over' In particular, I have never used C++ arrays, storing binary data within, and then trying to read them bit by bit. In perl, much easier; you would simply use a multi-dimensional something like this:
@code1=('10101010', '01010101');
$bit=$code1[0][0] (..through to..) code1[0][7]
$bit=$code1[1][0] ... code1[1][7]

So this is my Arduino code. Welcome to suggestions.
int pinArray[]={2,3,4,5,6,7,8,9};
int code1[]={B10101010, B01010101,B10101010, B01010101,B10101010, B01010101};
int count=0;
int split=0;    // Counter for the bit loop
int led;    // Store bit data
byte x;     // Used to store the binary data in code1

void setup(){
    for (count=0; count<8; count++){
    pinMode(pinArray[count],OUTPUT); // Sets pinMode as output on pinArray pins
    ]
}

void loop(){
    for (count=0; count<6; count++){
    x=code1[count];
    ledDisplay(x);
    }
}

void ledDisplay(){
    for (split=7; split>=0; split--){
    led=bitRead(x,split);
        if (led == 1){
        digitalWrite(split+2,HIGH);
        }
        else{
        digitalWrite(split+2,LOW);
        }
    }
}

Have just modified split as realised bit7 is the leftmost digit. In split, I am adding 2 to the value.  Does this need to be enclosed in brackets,ie (split+2) ?

Your indents are confusing. Press Ctrl+T

When I write my code in text editor, I use the tab key to indent code, so that the "for" opening / closing brackets etc are in the same column, (which seems to view correctly in my desktop browser - maybe perhaps incorrect on phone - so will use CRTL+t in future when posting. (I know CODE1 doesn't follow the same convention, but then I try to keep open/close on same  line so it doesn't 'run into' the next array, bearing in mind I will have 14 such arrays) This isn't meant to be 'nasty' to you as I do appreciate your taking the time to be helpful, just showing my personal 'naming convention'

Ctrl-T is just a quick way to get the code correctly indented in whatever is the IDE's default style. You don't have to use it though. You can use whatever indentation style you like if you handle it manually. Alternatively, you can configure the IDE for your favorite style. Just make sure to adopt one indent style and apply it consistently.

There are only two errors I can spot in your program:

A block of code should be delimited by curly braces:
for (count=0; count<8; count++){
    pinMode(pinArray[count],OUTPUT);
}  // ← ‘}’ instead of ‘]’

If a function expects to be passed arguments, these should be
declared as parameters in the function prototype:
void ledDisplay(byte x){  // ← mind the “byte x”
    // ...
}

Other than that, here a few suggestions to make the code look nicer, and
hopefully more maintainable:

indent consistently
use const to qualify constants
use named constants instead of magic numbers
keep variables local if possible
note that an int that is either 0 or 1 is equivalent to a boolean
use pinArray[] for accessing the pins

Applying those suggestions, I get the following:
const int PIN_COUNT = 8;
const int pinArray[PIN_COUNT] = { 2, 3, 4, 5, 6, 7, 8, 9 };
const int CODE_COUNT = 6;
const int code1[CODE_COUNT] = {
    B10101010, B01010101, B10101010, B01010101, B10101010, B01010101
};

void setup() {
    for (int count = 0; count < PIN_COUNT; count++) {
        pinMode(pinArray[count], OUTPUT);
    }
}

void loop() {
    for (int count = 0; count < CODE_COUNT; count++) {
        ledDisplay(code1[count]);
    }
}

void ledDisplay(byte x) {
    for (int split = 7; split >= 0; split--) {
        if (bitRead(x, split)) {
            digitalWrite(pinArray[split], HIGH);
        } else {
            digitalWrite(pinArray[split], LOW);
        }
    }
}

For once, I honestly wish I had the ability to upvote a reply. You have given me very constructive advice, rather than just a pointer here and there. (The "]" was just a typo,but thanks for pointing it out) I like too the boolean comment,which will save an extra few bytes. I shall now research "const" to see what that does exactly ...  Again, I honestly am very grateful for your indepth feedback


text:
Compiled sketch vs text file size
OK,so this is my first program written via the Tinkercad utility. I have saved the program as a text file, and it equates to about 22K.
My simple question is, when uploaded / compiled to the actual board, is the size increased or decreased? I plan to use the Nano (32K) If it shrinks or stays roughly the same, I should be OK. However,if it 'bloats' due to extra C code ...
** As someone used to working with sub routines, arrays and variables, found it a bit of a hassle that everything has to be in one loop, only conditional statement breaking the flow - leastin TinkerCAD. And when you want to control 8 LED outputs, having to switch each one on and off via a digital write line. For example, the four output lines below:
11001100
01100110
00110011
10011001

... needs 32 digital write commands !! (And whilst the above is 4 lines, there are nearer 150 similar lines in final code, hence it's size)
The way I wrote it using ths above utility was something like:
for(counter=0; counter<4; counter){
if (counter==0){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
  }
if (counter==1){
    digitalWrite(2, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
  }
//etc
}

Though I don't know if this works in Tinkercad, but you can use direct port manipulations to do this. Then you are able to write a complete port (8 outputs) in one statement (actually 1 atomic operation). Have you tried this?

and why do you use TinkerCAD if you can code? use Eclipse with Sloeber plugin. or at least the Arduino IDE

"direct port" ... "1 atomic operation".Sorry, only been coding for four days,so that's gone right overmy head ! WHy use Tinkercad if you can code? Well, I know PERL,HTMLand Javascript ... but Arduino is  all a new game for me

The size of the text file and the size of your compiled code are impossible to relate. The compiled size purely depends on what your code consists of, not the size.
To find out how much room your code will take on the chip you need to compile it. The IDE will then tell you how much flash and RAM it takes.
For example:
Sketch uses 3730 bytes (13%) of program storage space. Maximum is 28672 bytes.
Global variables use 157 bytes (6%) of dynamic memory, leaving 2403 bytes for local variables. Maximum is 2560 bytes.

You can compile the code without even having the board. So you could even compare different boards, before buying. (Though it shouldn't be that different between the nano and the uno)

Thanks for the feedback Majenko. You've sort of said what I thought might happen, that there are certain 'housekeeping' codes that also have to go into the storage space in order to be able to 'read' the text (or ino?) file. The only way to know for sure will be to run it through the IDE,but not save it to board, (if that's even poss: Still very much a noob!)

@Cristofayre In the IDE you can compile the code (called "verify" in the IDE IIRC) which creates a file that can be installed into a board or a later date. Or you can compile and upload in one go. You can just hit the compile (or is it verify?) button and it will convert the C code into machine language for running on the board (the board does not run C) and it tells you how big the result is.

Thanks Majenko. I will look into that. I've also just signed up for an online (FREE) course, so we'll see what I can learn from their coding. (Sorry, I can't 'upvote' your answer at this stage)

Does counter increase somewhere?  As written, it would always be 0, yes?
I would use
for(counter=0; counter<4; counter = counter +1){ // or counter++

You could store your 8 bits in an array
byte ledArray[] = {
0b11001100, // or hex format, 0xCC
0b01100110, // 0x66
0b00110011, // 0x33
0b10011001, // 0x99
};

Then use a function call (subroutine by another name) to manipulate the outputs.

Apologies. You're right, I missed the "counter ++" off the end of the loop. I think what you suggest of "byte ledArray" enters the realm of manual coding, (which, now I know it can be done, might look further) But Tinkercad uses Codeblocks,so the code they build is 'basic'. (And if you switch to manually editing code...you lose all the previous blocks set up!)

What I like about TinkerCad is that it shows the Arduino PCB, and you can add virtual resistors and LED's etc to it, and then you get a visual indication of what the code blocks will do. (But even to add a library, you have to edit manually; no blocks to help.That will be OK once I start to know more of whatI'm doing !)

Not sure of the correct way to do this on the forum, but I have "devised" a possible solution. Since this is my first atttempt at manual coding - jumping in at the deep end - I have posted it as another question, and wondered if those more knowledgable to give it the once over ... especially as it involves arrays, binary 'strings', and reading individual bits !


text:
esp32 and the esp32-cam (agoal)
Is it considered possible to use the esp32 code on an esp32 cam board? Do they use the same hardware? I am having difficulty using this sketch https://gist.github.com/wybiral/2a96c1d1605af7efa11b690586c4b13e on my esp32 cam and I think it is because it was designed for an esp32 board.
Thanks,
Dave

what difficulty?

are you implying they should be compatible? @Juraj I am having difficulty with the board locking up and not being able to program it anymore. That is another issue I am still dealing with. I am new to arduino and cant understand it. I explain that issue here: https://arduino.stackexchange.com/questions/66402/stuck-with-bad-sketch

StackExchange is not for troubleshooting. stop asking the same question again and again and discussing in comments. https://arduino.stackexchange.com/tour


text:
Is it possible to put priorities between external interrupts?
My question is quite simple. I am using one external interrupt on the Mega2560 to wake it up with an alarm from the rtc DS3231 and record data from sensors for about 30 seconds and I would like also to use the other external interrupt to wake it up in case of shock detection to measure the signal.
The thing is that I know external interrupts have priority on internal interrupt but is it possible to put, in my case, the shock detection prior to the alarm ? In case the shock occurs during the alarm recording I would prefer to record the shock signal.
Thank you for your help !

Is it really important to catch the case, that both interrupts fire at the same time? That's seems to be a rather rare case. Maybe it would be sufficient to check the shock interrupt flag at the start of the alarm ISR.

Hi ! Ok so it is not possible to have priorities between external interrupts ? I agree that it would be bad luck if the shock occurs at that moment but I wanted a rather robust system. Your idea of checking the flag at the moment of the alarm will just tell me if a shock occured but I wouldn't get the intensity of it... I guess I will have to make a compromise. Thank you !

Interrupts are not the right place to handle priorities. The interrupt
handlers should be as short as possible. Then the likeliness of two of
them happening at the same time is very low. And even if it happens, the
lowest-priority interrupt will only be delayed by a handful of
microseconds, which should not be a big deal.
In this case, the sensible approach is to have the interrupt handlers
set a global flag and do nothing else. Then the main program will
check the flags and do the real work, handling the priorities as needed.
Conceptually, the code could be something along these rough lines:
// Global flags.
volatile bool alarmDetected;
volatile bool shockDetected;

// Interrupt handlers.
void onAlarmInterrupt() { alarmDetected = true; }
void onShockInterrupt() { shockDetected = true; }

void loop() {
    if (shockDetected) {  // check this first!
        measureShockData();
        if (gotEnoughShockData()) {
            shockDetected = false;
            alarmDetected = false;  // ignore the alarm
            goToSleep();
        }
    } else if (alarmDetected) {
        recordSensorData();
        if (gotEnoughSensorData()) {
            alarmDetected = false;
            goToSleep();
        }
    }
}

Note that you can remove the line that ignores the alarm in case of
shock. If you do so, the alarm will be handled after all relevant
shock data has been recorded.

Hi ! Thank you for your solution I think I will go with it !


text:
Why do we need this resistor?
What is the purpose of it and on what bases its value is calcuated in ohms ?

use INPUT_PULLUP mode for a simpler wireup