text:
How can I use IRsend with a string or convert a char from serial to uint32_t?
I'm trying to control my arduino with a raspberry pi with python instead of C++ (which I don't know). I've found code to take a string from serial and print it, but instead I'd like to use IRsend to use the code. Unfortunately I'm getting the error invalid conversion from 'char*' to 'uint32_t {aka long unsigned int}' [-fpermissive]. I know this must be an incredibly dumb question but is there a int() function for uint32_t for arduino C++? that I could set blah=uint32_t(buf) and then use my irsend.sendNEC(buf, 32)? If it's not painfully obvious, I don't know C++ and my python isn't great.
#include <IRremote.h>

char buf[80];

int readline(int readch, char *buffer, int len) {
  static int pos = 0;
  int rpos;

  if (readch > 0) {
    switch (readch) {
      case '\r': // Ignore CR
        break;
      case '\n': // Return on new-line
        rpos = pos;
        pos = 0; // Reset position index ready for next time
        return rpos;
      default:
        if (pos < len-1) {
          buffer[pos++] = readch;
          buffer[pos] = 0;
        }
    }
  }
  return 0;
}

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

IRsend irsend;

void loop() {
  if (readline(Serial.read(), buf, 80) > 0) {
    Serial.print("You entered: >");
    Serial.print(buf);
    Serial.println("<");
    irsend.sendNEC(buf, 32);

  }
}

Error:
/home/pi/Desktop/sendIRfromserial2addingir/sendIRfromserial2addingir.ino: 39:27: warning: invalid conversion from 'char*' to 'uint32_t {aka long unsigned int}' [-fpermissive]
             irsend.sendNEC(buf, 32);

                  ^

In file included from
/home/pi/Desktop/sendIRfromserial2addingir/sendIRfromserial2addingir.ino:1:0:
/home/pi/Arduino/libraries/IRremote/src/IRremote.h:444:10: note:   initializing argument 1 of 'void IRsend::sendNEC(uint32_t, uint8_t, bool)'
     void sendNEC(uint32_t data, uint8_t nbits, bool repeat = false);
          ^~~~~~~`

Instead of
irsend.sendNEC(buf, 32);

cast it to an unsigned int32 type:
irsend.sendNEC((uint32_t) buf, 32);

That works! Thank you so much! It's sad how much time I spent looking for an answer. I think it's too simple of a question to have been asked before.

Maybe but it's ok ... Welcome anyway, next time also use ctrl-k to align your code and I advise to read a book about C/C++, it will help you greatly using the Arduino. Good luck with your project.


text:
Arduino.Mk together with MightyCore
There's no end to my frustration trying to figure out how the arduino build system works -- despite my best efforts I just can't seem to grok it. Anyhow, I did this:
ALTERNATE_CORE_PATH=/path/to/MightyCore/avr
BOARD_TAG=324
...

make show_boards shows me several boards available, including 324. Yet whenever I try to build my project, I get this error:
avr-g++: error: missing device or architecture after ‘-mmcu=’

Can someone point me in the right direction?
Thanks.

what is after -mmcu=?

doesn't look like you use Arduino IDE or arduino-cli

I used Arduino.mk. I think I have managed to sort it out, just took a few extra Makefile options:
BOARD_TAG=324
MCU=atmega324a
VARIANT=standard

Resolved with the following Makefile options:
BOARD_TAG=324
MCU=atmega324a
VARIANT=standard

source: Stack Exchange

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

sort: votes


text:
Brushless motor vibration/jitter/noise - arduino uno
I am currently using these motors and driving them off these drivers and an arduino uno, and alternatively trying to make them turn using the setup in step 6 (both with l298n and without) in this instructable. I have 4 motors and all are exhibiting the same behaviour.
Using the drivers, I just sent a constant PWM via PWM pin, and the motor would only spin at high values around 255, but even then only when I touch the motor does it start spinning. This spinning is then not even smooth, it pauses a bit every second or so and results in a sort of jittering. After a bit more, plugging the motors in it now just makes an increasingly louder whining noise, kind of like it's getting ready to take off but doesnt really spin. Code used here is just basic as below:
void setup () {

pinMode(9, OUTPUT);

}

void loop (){

analogWrite(9, 255);

}

Using the instructable setups, I've wired exactly the same way (wiring for l298N version is in step 10, wiring for discrete steps is just directly pwms to the motor), but the motors will not spin like theirs do (same poles and slots, 12n14p). Mine just jitters back and forth in tiny steps and looks like it's just twitching. Code used is exactly as at the end of 'step 6'.
Imgur album of issues

sounds like the power supply is running out of juice

put the analogWrite into setup() ... remove it from loop()

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


text:
use Nodemcu to program Attiny85
I have a dev board for my attiny85.
when connecting it to the computer I get "unknown USB device(device descriptor request failed)"
although I have the needed drivers, so I thought of trying using my nodemcu.
Tried connecting the SPI (to the nodemcu hmiso;hmosi;hcslk;hcs)and upload using "arduino as ISP" and compitable settings(https://www.hackster.io/arjun/programming-attiny85-with-arduino-uno-afb829).
pressing "burn bootloadre" using this way gives me errors:
"avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x03
......
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x03
Error while burning bootloader."
***EDIT:
After changing a line(#define USE_OLD_STYLE_WIRING) in ArduinoISP (from example)
the error code changed a bit and it shows up much faster:
"Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "ATtiny25/45/85, ATtiny85, Internal 8 MHz"
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x04
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x61
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x67
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xc1
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xc4
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xc5
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xa1
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xcc
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe2
Error while burning bootloader."
Any help on how to use nodemcu to program attiny85 will be great
thanks

how did you prevent reset of the NodeMcu? try a different pin then io15 for reset of target

Hi thanks for answering, first thing I tries was GPIO5 with no success :(

how do you prevent auto-reset of the NodeMcu?

you mean by using a capacitor from RST to GND? I did try using a capacitor, although a 22uF one, did not work

Using  a 10 uF also did not work nor trying flashing the bootloader using the cmd

Modifications to the ArduinoISP.ino sketch
I made the following changes to the ArduinoISP.ino file it exists in IDE version 1.8.13, and uploaded it to the NodeMCU board.
In short, I commented out (by way of #if 0) the heartbeat, err, etc LED related stuff.  Not doing this causes the board to reset for reasons that would probably be apparent if I researched it, but I haven't and since I don't plan on using the LEDs and that you may not, I figured I would get this to you sooner.
I changed RESET to be SS which on NodeMCU is D8.
Why LED related code causes resets
... Out of curiosity I just went and looked at the ESP-12F and ESP8266EX datasheets.  GPIO7, GPIO8, GPIO9 all go to the ESP-12F's SPI flash (program storage), so ostensibly monkeying with them interferes with the modules ability to keep executing from the SPI flash.  They're not routed to NodeMCU pins, probably for that reason.  So there's the answer to that.
Differences
@@ -70,7 +70,7 @@
 // The standard pin configuration.
 #ifndef ARDUINO_HOODLOADER2

-#define RESET     10 // Use pin 10 to reset the target rather than SS
+#define RESET     SS // Use pin 10 to reset the target rather than SS
 #define LED_HB    9
 #define LED_ERR   8
 #define LED_PMODE 7
@@ -216,15 +216,17 @@

 #endif

 void setup() {

   SERIAL.begin(BAUDRATE);

+#if 0
   pinMode(LED_PMODE, OUTPUT);
   pulse(LED_PMODE, 2);
   pinMode(LED_ERR, OUTPUT);
   pulse(LED_ERR, 2);
   pinMode(LED_HB, OUTPUT);
   pulse(LED_HB, 2);
+#endif

 }

@@ -276,6 +278,7 @@
 }

 void loop(void) {
+#if 0
   // is pmode active?
   if (pmode) {
     digitalWrite(LED_PMODE, HIGH);
@@ -291,6 +294,7 @@

   // light the heartbeat LED
   heartbeat();
+#endif
   if (SERIAL.available()) {
     avrisp();
   }

NodeMCU to ATTiny85 ISP Wiring
The board is wired to the ATTiny85 as follows:
NODEMCU 3.3V -> ATTINY85 PIN 8
NODEMCU GND  -> ATTINY85 PIN 4
NODEMCU D5   -> ATTINY85 PIN 7
NODEMCU D6   -> ATTINY85 PIN 6
NODEMCU D7   -> ATTINY85 PIN 5
NODEMCU D8   -> ATTINY85 PIN 1

On the NodeMCU you'll find all 6 of these together on the right.
Verifying AVRDUDE functioning
avrdude -P /dev/ttyUSB0 -c stk500v1 -b 19200 -p attiny85

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e930b (probably t85)

avrdude: safemode: Fuses OK (E:FF, H:DF, L:71)

avrdude done.  Thank you.

I've been playing with this chip, so don't be surprised that I don't have the same fuse values you have.

Thanks a lot!
Commenting the LED parts in the code made the diffrence.

Good deal.  I'd considered just putting only that, but wanted to make it a little more complete.  To be clear, changing the pin definitions for the leds to non-problematic pins would also work.  I may edit it later to to suggest and, maybe add a picture of the wiring if I get around to making a clean picture.


text:
What can I do to optimise this code?
I have optimised it as much as I feel I can and want to know what suggestions you have that could make it more efficient etc.
Note: I know the array goes on forever :)
volatile uint16_t IRCode[]={340,171,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,64,21,64,21,1556,340,86,21,3654}; // ProntoHex to uint16_t delete first 4 array numbers.
volatile uint16_t MicrosPassed;
volatile uint8_t Array_Seq;
uint8_t State;

void setup() {
  Config(); // Config sketch will set working settings for different microcontrollers.
  SendIRCode();
}

void loop() {

}

void SendIRCode() {
  switch(State) {
    case 1:
      TCCR1A&=63; // Opposite of case 0 -193 = 63
      State=0;
      break;

    case 0:
      TCCR1A|=192;
      State=1;
      break;
  }
}

void Config() {
  DDRB|=10;
  ICR1=416;
  OCR1A=9983;
  TCCR1A=2;
  TCCR1B=24;
  TCCR1B|=1;
  TIMSK1=1;
}

ISR(TIMER1_OVF_vect) {
  MicrosPassed++;
  if(MicrosPassed==IRCode[Array_Seq]) {
    SendIRCode();
    MicrosPassed=0;
    Array_Seq++;
       }
}

IRCode[], MicrosPassed, and Array_Seq are only used in the ISR; you could declare them as static in the ISR, IRCode[] could also be const, and no need to declare them as volatile because only the ISR reads/writes them. No idea if this will help the compiler optimising for speed, though.

For what to do you want to optimize? Clean code? Or some meaning of "speed" (which speed)?

convert array to actual bits .. 0 is 21, 21 ... 1 is 21, 64 ... s is  340, 17 - start ... and so on .... the array would be { s, 0, 0, 0, 1, 0 ......} ... you could even store bytes, instead of separate bits

Maybe fix the problem @chrisl mentioned before optimizing your code.

As hinted by chrisl in a comment, there are various criteria you may
want to optimize for: speed, size, readability... Judging from the
current state of this sketch, I would say that your first goal at this
point should be to optimize for readability.
The hardest think to make sense of are most of the plain numbers. When
setting registers that are bit fields, do not use decimal values: use
either hexadecimal or binary. Or, better yet, use the names of the bits.
The avr-libc defines those names, as well as the macro
_BV(bit_position), which expands to (1 << bit_position) and is meant
to be used with those names:
void Config() {
  DDRB   |= _BV(PB1) | _BV(PB3);  // PB1 and PB3 as output
  ICR1    =  416;        // timer period = 417 cycles
  OCR1A   = 9983;        // ???
  TCCR1A  = _BV(WGM11);  // mode 14: fast PWM, TOP = ICR1
  TCCR1B  = _BV(WGM12) | _BV(WGM13);  // ...ditto
  TCCR1B |= _BV(CS10);   // clock @ F_CPU
  TIMSK1  = _BV(TOIE1);  // enable TIMER1_OVF interrupt
}

Granted, the bit names are somewhat obscure, but they do make the
program easier to read if you have the datasheet nearby. I do like to
have comments that make the code understandable even without reading the
datasheet.
Note that evaluating those expressions does not make the program any
slower, as they are evaluated at compile time.
When a variable is used in a single function, it is better to define it
in that function. Keeping the definition close to where the variable is
used makes the code more “local” and thus easier to read. Since you want
some of those variables to remember their values across invocations of
the function, give them the static qualifier.
You may not need to optimize this program for speed. There is, however,
a low hanging fruit here: remove the volatile keywords. This keyword
is meant to explicitly disable some compiler optimizations that are
unsafe when a variable is shared between the interrupt and non-interrupt
contexts. None of the variable you use needs this.
If I understood correctly, the function SendIRCode() just toggles a
couple of bits in TCCR1A. You can simplify it to this:
void SendIRCode() {
  TCCR1A ^= _BV(COM1A0) | _BV(COM1A1);  // toggle PWM output on OC1A
}

Finally, there is I believe a bug in this sketch. The variable
Array_Seq is continuously incremented and never reset. The program
will then end up reading past the end of the IRCode array.


text:
Arduino Create and Raspi I2C
I'm trying to communicate via I2C on the Raspi, programming it with the Arduino Create Web Editor.  I have enabled I2C on the pi, made sure /dev/i2c-1 exists.  The pi can see the device (just a simple LCD for now) via the command line on the pi itself.
I'm getting the error "no I2C device available for Wire10".  I'm wired to SDA1/SCL1 (pins 3 and 5).  I have previously tested the display and the code on an UNO and it works fine.
Please help!  I saw someone had this issue before and simply said "I fixed it" but didn't provide an explanation.
Thanks!  (Code below for reference)
/* I2C LCD with Arduino example code. More info: https://www.makerguides.com */

// Include the libraries:
// LiquidCrystal_I2C.h: https://github.com/johnrickman/LiquidCrystal_I2C
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD

// Wiring: SDA pin is connected to A4 and SCL pin to A5.
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.

void setup() {
  // Initiate the LCD:
  lcd.init();
  lcd.backlight();
}

void loop() {
  // Print 'Hello World!' on the first line of the LCD:
  lcd.setCursor(0, 0); // Set the cursor on the first column and first row.
  lcd.print("Hello Worlds!"); // Print the string "Hello World!"
  lcd.setCursor(2, 1); //Set the cursor on the third column and the second row (counting starts at 0!).
  lcd.print("LCD tutorial");
}

There is some missing information. When you say: "I'm getting error" no I2C device... Where error is displayed? On RPi, Arduino IDE or what? What are conditions? What is connected and when? Uno? Display? What display? What is running on RPi? Another: When you saw someone having similar problem: provide a link, maybe someone can elaborate from there.

Here is the link o the original topic with the error: https://forum.arduino.cc/index.php?topic=560075.0, the error was on the arduino web IDE monitor, its an LCD display (Not sure of the exact model I will provide it when im able to get it) connected to the PI over i2c (gpio 2 and 3 from https://pinout.xyz/) That code posted is whats running on the pi.

did you run the I2C scanner sketch?

Yes i did and was not able to see anything with it. (Link to LCD: https://www.amazon.ca/WayinTop-Display-Interface-Adapter-Arduino/dp/B07TXGD3WS/ref=asc_df_B07TXGD3WS/?tag=googlemobshop-20&linkCode=df0&hvadid=341851109660&hvpos=&hvnetw=g&hvrand=11539534944715973135&hvpone=&hvptwo=&hvqmt=&hvdev=m&hvdvcmdl=&hvlocint=&hvlocphy=1002441&hvtargid=pla-910497129813&psc=1"


text:
Timer with Webserver ESP8285
this is my first Project on an ESP.
I found a Code for a coffee-grinder-timer, which is programmed for a ESP8266, but unfortunately meanwhile the Sonoff changed to the ESP8285 with internal Flash.
I presume this is the reason for a memory problem. By default the times are according to the code 1000ms and 2000ms, but on the WebPage are the following times are displayed:

Singleshot: 16711680ms
Doubleshot: 807611680ms

Beside this problem I can't change these values by pressing the save-button.
what is my mistake?
// Libraries
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <TTBOUNCE.h>
#include <EEPROM.h>
extern "C" {
#include "user_interface.h"
}

//======SERVER PART======================================================
const char* ssid     = "SSID";
const char* password = "password";
ESP8266WebServer server ( 80 );
char htmlResponse[3000];
//======LOKALER PART======================================================
os_timer_t myTimer;
bool tickOccured;
bool timerrunning;
int RelaisPin = 13;                 // GPIO13 Blaue LED auf dem Sonoff
TTBOUNCE b = TTBOUNCE(0);

int time_ss = 1000;
int time_ds = 2000;

void handleRoot() {

  snprintf ( htmlResponse, 3000,
"<!DOCTYPE html>\
\
  \
    <meta charset=\"utf-8\">\
    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
  \
  \

Zeiten für Singleshot und Doubleshot
\

Singleshot: %d% ms
\
          <input type='text' name='date_ss' id='date_ss' size=2 autofocus> ms \

Doubleshot: %d% ms
\
          <input type='text' name='date_ds' id='date_ds' size=2 autofocus> ms \

\

<button id=\"save_button\">Save</button>\

\
    \
    \
  \
",

time_ss,
time_ds
);

   server.send ( 200, "text/html", htmlResponse );

}

void handleSave() {
  if (server.arg("ss")!= ""){
    Serial.println("Singleshot: " + server.arg("ss"));
    time_ss = server.arg("ss").toInt();
    eeWriteInt(0, server.arg("ss").toInt());
  }
    if (server.arg("ds")!= ""){
    Serial.println("Doubleshot: " + server.arg("ds"));
    time_ds = server.arg("ds").toInt();
    eeWriteInt(4, server.arg("ds").toInt());
  }

}

// start of timerCallback
void timerCallback(void *pArg) {
Serial.println("Tick OccurredCB");
      tickOccured = true;
}

void setup() {
//======SERVER PART======================================================
  // Start serial
  Serial.begin(115200);
  delay(100);
WiFi.mode(WIFI_STA);
  // Connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

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

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

  server.on ( "/", handleRoot );
  server.on ("/save", handleSave);

  server.begin();
  Serial.println ( "HTTP server started" );
//======LOKALER PART======================================================
  os_timer_setfn(&myTimer, timerCallback, NULL);
  pinMode(RelaisPin, OUTPUT);       // GPIO13 als Ausgang definieren
  b.attachClick(click);         //attach the click method to the click event
  b.attachDoubleClick(doubleClick);//attach the double click method to the double click event
  b.attachPress(press);        //attach the press method to the press event
  delay(50);
  digitalWrite(RelaisPin, HIGH);  // turn LED ON
  tickOccured = false;
  timerrunning = false;
   EEPROM.begin(8);  //Initialize EEPROM
   time_ss = eeGetInt(0);
   time_ds = eeGetInt(4);
}

void loop() {
//======SERVER PART======================================================
  server.handleClient();
//======LOKALER PART======================================================
  b.update();
  delay(10);

   if (tickOccured == true)
 {
    Serial.println("Timer ausgelaufen");
    tickOccured = false;
    digitalWrite(RelaisPin, HIGH);
    os_timer_disarm(&myTimer);
    timerrunning = false;
 }

 yield();  // or delay(0);
}

void click(){
  if (!timerrunning)
  {
    Serial.println("Clicked");
    digitalWrite(RelaisPin, LOW);  // turn LED ON
    os_timer_arm(&myTimer, time_ss, false);
    timerrunning = true;
  }
  else
    {
    Serial.println("ABORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    tickOccured = false;
    digitalWrite(RelaisPin, HIGH);
    os_timer_disarm(&myTimer);
    timerrunning = false;
    }
}

void doubleClick(){
    if (!timerrunning)
  {
    Serial.println("DoubleClicked");
    digitalWrite(RelaisPin, LOW);  // turn LED ON
    os_timer_arm(&myTimer, time_ds, false);
    timerrunning = true;
  }
    else
    {
    Serial.println("ABORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    tickOccured = false;
    digitalWrite(RelaisPin, HIGH);
    os_timer_disarm(&myTimer);
    timerrunning = false;
    }
}

void press(){
  if (!timerrunning)
  {
    Serial.println("long_Clicked");
    digitalWrite(RelaisPin, LOW);  // turn LED ON
    os_timer_arm(&myTimer, time_ds-time_ss, false);
    timerrunning = true;
  }
 else
    {
    Serial.println("ABORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    tickOccured = false;
    digitalWrite(RelaisPin, HIGH);
    os_timer_disarm(&myTimer);
    timerrunning = false;
    }
}

 void eeWriteInt(int pos, int val) {
    byte* p = (byte*) &val;
    EEPROM.write(pos, *p);
    EEPROM.write(pos + 1, *(p + 1));
    EEPROM.write(pos + 2, *(p + 2));
    EEPROM.write(pos + 3, *(p + 3));
    EEPROM.commit();
}

int eeGetInt(int pos) {
  int val;
  byte* p = (byte*) &val;
  *p        = EEPROM.read(pos);
  *(p + 1)  = EEPROM.read(pos + 1);
  *(p + 2)  = EEPROM.read(pos + 2);
  *(p + 3)  = EEPROM.read(pos + 3);
  return val;
}

what problem are you facing? ... what are you trying to do?

I would start by changing %d% to %d

You “found code” where? Are you certain the code was working? You mention a “memory problem”. What do you mean by that? In my experience, programatically there is almost no difference between an ESP8285 and an ESP8266 besides the difference in available flash memory, which I don’t think is the problem here. Why are you mentioning Sonoff?

@jsotola: I want to program a timer for my coffee-grinder, on which I can adjust the grinding duration via WLAN.

My timer is at the moment not changeable and set to weird values
@StarCat: I found the code on Kaffee-Netz:
https://www.kaffee-netz.de/threads/demoka-m203-timerumbau-und-totraum-minimierung.117220/
and it is meant to be working on a ESP8266.
My Memory problem is, that the durations of the single-and the  doubleshot are not changeable and the default values are extremely high and not according to the code 1000 and 2000ms.
Thanks in advance

@ Juraj: thanks, since I changed this, I am able to change the values at the first boot after flashing. But afterwards I cant change the values anymore. Pressing the save butten doesnt show any effect.

Try removing the location.reload(); call - your browser may be reloading the page before the AJAX GET can complete. Also you should wrap your Javascript in a jQuery $(document).ready() handler - you can Google it for more details.

At least one problem is this:

Singleshot: %d% ms
\

If you want a literal percent sign, you would need to double it, a form of escaping:

Singleshot: %d%% ms
\

It's not entirely clear how this implementation of snprintf handles %<space>, but experiments here show that it isn't being forgiving and merely interpreting it as %%.
In C and C++ and by proxy "arduino", adjacent string literals are concatenated at compile time into one logical string literal, so you can do that rather than \, which you may find cleaner.
It should also be possible to just .print the chunks of your payload to the stream rather than to cobble together one large string as a payload.


text:
Sync of Time Library and RTClib
Trying to understand the two libraries and setSyncProvider(RTC.now).
Using Arduino Uno with Adafruit ChronoDot.  Aduino IDE 1.8.13.
The code below is simply to understand what is happening.
I am getting surprising results which means I do not understand what the libraries are doing.
What I think I am telling it to do:

Set time RTC to 05:10:30
Set Time Library to 09:27:05
In Loop, printing Library time (hour, minute, seconds)
In Loop, printing RTC time (now.hour, now.minute, now.second)
Every 5 seconds sync the Time Library to the RTC.
This is not what it is doing.
The output from serial prints is at the bottom.

Question 1:  Why does Time Library time  hour() minute() second() change from 9:27:9 to 12:43:44 after first sync and then from 12:43:48 to 19:1:20 after second sync, then reseting to  19:1:20 after each subsequent sync?
Question 2:  After the Sync, why is Time Library hour(), minute() and second() not set to RTC values of now.hour(), now.minute() and now.second()?
#include "RTClib.h"
#include <Wire.h>
#include <TimeLib.h>

RTC_DS1307 RTC;
unsigned long LastSyncTime = 0;    //will control when it syncs just to understand

time_t time_provider()

{
    return RTC.now().unixtime();
}

void setup() {
Serial.begin(9600);
Wire.begin();  //sets up the I2C
RTC.begin();   //initializes the I2C to the RTC

//  Set the RTC Time to 5:10:30 Nov 3 2020
RTC.adjust(DateTime(2020,11,3,5,10,30));

//Set Arduino Time Library different than RTC time 9:27:05 so see how sync works
setTime(9, 27, 05, 4, 07, 2015);

}

void loop() {

//Sync time every 5 seconds
if ((millis() - LastSyncTime) > 5000)
  {
  Serial.println("+++++   Sync  ++++++++");
  setSyncProvider(RTC.now);  //sets Time Library to RTC time: hour() set to RTC now.hour (?)
  LastSyncTime = millis();

   }

DateTime now = RTC.now();  // gets RTC time into now Object

//Print Time Lib Times
Serial.print("hour:       ");
Serial.print(hour());
Serial.println();
Serial.print("minute:     ");
Serial.print(minute());
Serial.println();
Serial.print("seconds:    ");
Serial.print(second());
Serial.println();
Serial.println();

//Print RTC time
Serial.print("now.hour:   ");
Serial.print(now.hour());
Serial.println();
Serial.print("now.minute: ");
Serial.print(now.minute());
Serial.println();
Serial.print("now.second: ");
Serial.print(now.second());
Serial.println();
Serial.println("______________________");

delay(1000);
}

OUTPUT
hour:       9
minute:     27
seconds:    8
now.hour:   5
now.minute: 10
now.second: 33
hour:       9
minute:     27
seconds:    9
now.hour:   5
now.minute: 10
now.second: 34
+++++   Sync  ++++++++
hour:       12
minute:     43
seconds:    44
now.hour:   5
now.minute: 10
now.second: 35
hour:       12
minute:     43
seconds:    45
now.hour:   5
now.minute: 10
now.second: 36
hour:       12
minute:     43
seconds:    46
now.hour:   5
now.minute: 10
now.second: 37
hour:       12
minute:     43
seconds:    47
now.hour:   5
now.minute: 10
now.second: 38
hour:       12
minute:     43
seconds:    48
now.hour:   5
now.minute: 10
now.second: 39
+++++   Sync  ++++++++
hour:       19
minute:     1
seconds:    20
now.hour:   5
now.minute: 10
now.second: 40
hour:       19
minute:     1
seconds:    21
now.hour:   5
now.minute: 10
now.second: 41
hour:       19
minute:     1
seconds:    22
now.hour:   5
now.minute: 10
now.second: 42
hour:       19
minute:     1
seconds:    23
now.hour:   5
now.minute: 10
now.second: 43
hour:       19
minute:     1
seconds:    24
now.hour:   5
now.minute: 10
now.second: 44
+++++   Sync  ++++++++
hour:       19
minute:     1
seconds:    20
now.hour:   5
now.minute: 10
now.second: 45
hour:       19
minute:     1
seconds:    21
now.hour:   5
now.minute: 10
now.second: 46
hour:       19
minute:     1
seconds:    22
now.hour:   5
now.minute: 10
now.second: 47
hour:       19
minute:     1
seconds:    23
now.hour:   5
now.minute: 10
now.second: 48
hour:       19
minute:     1
seconds:    24
now.hour:   5
now.minute: 10
now.second: 49
+++++   Sync  ++++++++
hour:       19
minute:     1
seconds:    20
now.hour:   5
now.minute: 10
now.second: 50
hour:       19
minute:     1
seconds:    21
now.hour:   5
now.minute: 10
now.second: 51
hour:       19
minute:     1
seconds:    22
now.hour:   5
now.minute: 10
now.second: 52
hour:       19
minute:     1
seconds:    23
now.hour:   5
now.minute: 10
now.second: 53

−1, as you visibly did not pay attention to an answer to your previous question. I already explained why setSyncProvider(RTC.now) is incorrect and can only result in the Time library giving you garbage.

@EdgarBonet - Sorry I did use your previous information and it did work. Copy paste error here from older code. Thanks for your help and  patience.

Why does Time Library time hour() minute() second() change from 9:27:9 to 12:43:44 after first sync and then from 12:43:48 to 19:1:20 after second sync, then reseting to 19:1:20 after each subsequent sync?

Because:

You keep calling setSyncProvider(). The whole point of the sync system is that you should only call that once to set the sync provider and then it syncs itself automatically.
You are setting the sync provider to a function that returns an object. The sync provider needs a function that returns an unsigned long (time_t).

Your code should be:
setSyncProvider(time_provider);

And it should only be called once from inside setup.

Question 2: After the Sync, why is Time Library hour(), minute() and second() not set to RTC values of now.hour(), now.minute() and now.second()?

Because of all the things I stated above and were also told in your last question.


text:
Use normal TFT Shield with SD as a Nextion Display
I have a normal Elegoo TFT 2.8" display shield that also had an SD reader. I am trying to use it as a Nextion display. I want to do this because the Nextion tool allows you to make very nice looking sophisticated graphics and I wanted to do the same. Is there any possibility? Maybe some interpreter library?

why not? .... find a library that can display full screen graphics ... also a library that can overlay png images ... png overlay would need to be aware of transparency in the images

Can you suggest me some? I can't seem to find any.

search for Elegoo TFT 2.8" display ... find out what contoller is used ... then search for the controller

what do you mean by controller

the lcd module has a control chip that the arduino communicates with ... it understands high level commands ... there is no direct connection between the arduino and the lcd

No, you can't.
Nextion displays contain their own microcontroller with their own closed-source firmware on them.  You need that firmware to have a clue what is in Nextion files, and only Nextion have that firmware.
While it may be possible to reverse engineer Nextion display data and write your own software to interpret it, it would be a huge job with little to no real-world benefit.

You cannot use a 2.8" TFT as a Nextion Display. Two are seperate things
Nextion Display is an HMI. You can configure prebuilt menus and graphics without coding.
The 2.8" TFT is a generic display module. It prints data according to the commands it receives. The user has to prepare the data to be printed. It can read data from an sd card, but the user program has to issue the commands for it.
Nextion displays use a generic display like the 2.8" TFT, an onboard controller with custom firmware running on it.


text:
How can you turn off the LEDs on a SparkFun AS7265x Spectral Triad (Spectroscopy Sensor)?
I'm a newbie to program an Arduino but I need to turn off a LED from a external Spectroscopy Sensor.
This is the Sensor:

There are three LEDs on this sensor and they're turned on automatically when the Arduino is plugged in. Can someone perhaps explain in general how to address a LED mounted on something like that ?

it communicates over I2C (a.k.a. Wire or TwoWire). find a library, read the doc

@Juraj the leds communicate over i2c? I don't think they can be disabled, at least not via the bus because the IC on the top dorsn't look like a (suitable) uC to me.

void enableBulb(uint8_t device); void setBulbCurrent(uint8_t current, uint8_t device);

https://learn.sparkfun.com/tutorials/spectral-triad-as7265x-hookup-guide/all

Example 2 - Controlling the onboard LEDs

@SimSon, find a library, read the doc. why to guess?

@Juraj you're right. Now after you added a link to the datasheet, I see there are actually 5 leds on that board...

Thanks it worked :)


text:
If and while statements not working
The second and third while and if are not working but the first while and if do work. Am I doing something wrong?
#include <DFMiniMp3.h>

int sw1 = 3;
int sw2 = 4;
int sw3 = 5;

class Mp3Notify
{
  public:
    static void OnError(uint16_t errorCode)
    {
      // see DfMp3_Error for code meaning
      Serial.println();
      Serial.print("Com Error ");
      Serial.println(errorCode);
    }

    static void OnPlayFinished(uint16_t globalTrack)
    {
      Serial.println();
      Serial.print("Play finished for #");
      Serial.println(globalTrack);
    }

    static void OnCardOnline(uint16_t code)
    {
      Serial.println();
      Serial.print("Card online ");
      Serial.println(code);
    }

    static void OnCardInserted(uint16_t code)
    {
      Serial.println();
      Serial.print("Card inserted ");
      Serial.println(code);
    }

    static void OnCardRemoved(uint16_t code)
    {
      Serial.println();
      Serial.print("Card removed ");
      Serial.println(code);
    }
};
DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial); //Create the UART connection to the module

void setup()
{

  //3 push buttons with pullups
  pinMode(sw1, INPUT); //Define each button as input with pullup
  pinMode(sw2, INPUT);
  pinMode(sw3, INPUT);

  digitalWrite (sw1, HIGH); //12 Votls supply set to off state
  digitalWrite (sw2, HIGH); //5 Votls supply set to off state
  digitalWrite (sw3, HIGH); //3 Votls supply set to off state

  Serial.begin(9600);
  mp3.begin(); //Start communication with the DFplayer module
  uint16_t volume = mp3.getVolume(); //Get actual volume
  mp3.setVolume(30); //Set new volum (max is 30)
  uint16_t count = mp3.getTotalTrackCount(); //Get the total tracks on the SD card in case we want to sue this later...
}

//just a fucntion that we use to create delays in "ms"
//without using the delay() function
void waitMilliseconds(uint16_t msWait)
{
  uint32_t start = millis();

  while ((millis() - start) < msWait)
  {
    // calling mp3.loop() periodically allows for notifications
    // to be handled without interrupts
    mp3.loop();
    delay(1);
  }
}

void loop()
{

  if (digitalRead(sw1) == LOW)
  {
    mp3.playMp3FolderTrack(1); // Play audio track 0001
    waitMilliseconds(5000); // 1s of delay
    while (digitalRead(sw1) == HIGH); // do nothing until state changes

  }

  if (digitalRead(sw2) == LOW)
  {
    mp3.playMp3FolderTrack(2); // Play audio track 0002
    waitMilliseconds(5000); // 1s of delay

    while (digitalRead(sw2) == HIGH); // do nothing until state changes

  }

  if (digitalRead(sw3) == LOW)
  {
    mp3.playMp3FolderTrack(3); // Play audio track 0002
    waitMilliseconds(5000); // 1s of delay

    while (digitalRead(sw3) == HIGH); // do nothing until state changes
  }
}

Am I doing something wrong? - if the alternative is that while/if statements do not work, then sure, you're doing something wrong. Please format your code properly and someone will help you find the mistake.

@SimSon, from the basic concept it looks fine. I need someone to help me with this.

Thanks for formating the code. The code just behaves differently than you expect, but those statements definitely work. What makes you believe they don't? Please add your observations and expectations into the question.

@SimSon, After "void loop" I have 3 "if" statements. The first one works, but not the second and not the third. If I changed the order of "if" statements then just the first work works. it doesn't matter which one of "if" statements are placed after first "if" statement but the after the first statement others doesn't work.

After pressing sw1, the while (digitalRead(sw1) == HIGH); line just makes it sits there without continuing with the rest of the code until you press sw1 again.

You should substitute the mp3 stuff with serial prints in each if clause and while loop to debug this.

@ocrdu, yes that is fine. but the second "if" statement doesn't function.

@ocrdu actually no. After execution enters any of the if statements, the while loop is meaningless if the button state hasn't changed

@Sim-Son They are push buttons that change state on release, and there's a delay that gives plenty of time for that release.

Does sw2 work if you haven't pushed sw1 at all since the last reset?

Maybe you better have a look how to read a button properly. The loop is executed so fast that reading a button like that won't give any good results anyway. You want to detect when the button changes its state, not if it is in a certain state. You're also better off using non-blocking code and avoiding delays like in the BlinkWithoutDelay example. If you keep several buttons pressed and release them randomly, you'll see that the 2. and 3. ifs are executes as well.

@ocrdu, no. Sw2 and sw3 don't work. If I change the order to sw2, sw3, sw3. Now the sw2 works. If I change the order to sw3, sw2, sw1 then sw3 works. I keep pressing all the buttons, but only the first "if" statement works and not others.

@ocrdu yes, you're right. Actually, after the while loop 1 has finished, the corresponding if statement is re-entered immediately on the next loop iteration unless button 2 or 3 is pressed.

Don't keep pressing all the buttons, reset the Arduino and only press sw2. Does sw2 work then?

@ocrdu, no, not working. Just the first if statement works.

How do you know if you only pressed sw2 after reset? Comment out the delays and the while loops. Do all buttons work then?

@ocrdu, 1- Power supply is off. 2- now power supply turned on. 3- non of switches connected. 3- switch number one held down. 4- MP3 played. 5- sw1 released. 6- sw2 pressed. 6- nothing happens.
7- sw1 pressed and released to see if it needs reset.
8- sw2 pressed, released, held down > nothing happens.
10- if the the sw2 code moved above sw1 "if" statement then sw2 works.

After pressing sw1, the first if works. After releasing sw1 (it's a push button), the line while (digitalRead(sw1) == HIGH); will make the code just sit there forever without continuing with the rest of the code until you press sw1 again, which will be caught by the first if unless you release 'sw1' inhumanly fast.
So, once you have pressed and released sw1, the rest of the code with the next two ifs will never run.

your last statement looks right, but somehow it can't figure out the problem.
If I held the sw1 down and press the sw2 then sw2 start working. Now only sw2 functions sw1 not working. The switching locks to sw2. but when I reset everything it goes back to sw1.

The while loops block the execution. Maybe it will work as you intended if you remove them and make the delays a bit shorter.

I use a DFmini player. It works well if the button is press and release. But in my case, the button will need to be held down. the problem with holding the button down is that the MP3 get played over and over. I want it to play only for once if the pin is high and or button is held down for a long time. If i remove the "while" then it will play over and over again. does not stop.

If you use a blocking delay, no button will respond during the delay time, and only repeat after the delay time. Or, debounce the buttons (you can look that up) and use a long debounce time, basically debouncing the push button and the human too.


text:
Output from LM35 temperature sensor varies wildly
I've seen other posts on this board which related to output from the LM35 sensor, but mine seem to be more 'extreme' than anything else I've seen.
I've connected the pins as is commonly suggested - left hand to 5v, middle A0, and right to GRN and used the folowing code
const int sensorPin = A0;

float sensorValue;
float voltageOut;

float temperatureC;
float temperatureF;

void setup() {

pinMode(sensorPin, INPUT);
Serial.begin(9600);

}

void loop() {

  sensorValue = analogRead(sensorPin);
  voltageOut = (sensorValue * 5000) / 1024;
  temperatureC = voltageOut / 10;

  Serial.print(sensorValue);
  Serial.print("\n");
  //Serial.print(temperatureC);
  //Serial.print("\n");

  delay(10000);
}

I commented out the temperature printing lines to avoid the error being in the conversion.
Leaving it run for a while I get the following
756.00
0.00
27.00
7.00
16.00
64.00
0.00
0.00
0.00
6.00
82.00
20.00
10.00
3.00
38.00
0.00
73.00
0.00
78.00
68.00
0.00
80.00
0.00
2.00
29.00
48.00
10.00
0.00
23.00
64.00
27.00
0.00
79.00
0.00
0.00
56.00
60.00
9.00
0.00
15.00
82.00
2.00
2.00
40.00
76.00
18.00
43.00
17.00
74.00
49.00
21.00
14.00
0.00
74.00
0.00
3.00
81.00
3.00
55.00
20.00
0.00
41.00
72.00
40.00
0.00
54.00
27.00

Our house is fairly stable in temperature, and the sensor is in a location out of anything which could drastically alter the temperature.
If anybody can suggest a reason for this I'd be grateful.

Nothing obviously bad with the code. Try replacing the LM35 with a potentiometer (pretty much same connections - one side to VCC, other side to ground, middle to A0) or just a voltage divider and see if the code works.

Thanks for the great piece of contructive thinking! I put a potentiometer onto it and it was steady as a rock, which makes me think my problem is therefore some really, really, shoddy LM35s.

Nothing wrong with your code, how do you define left hand when you holding the chip? bottom view or top view? Assuming you means TO-92 packaging.

not the problem now, but change sensorValue * 5000 to sensorValue * 5000L

Assuming the LM35 is fine you probably habe faulty connections. Most probably mixed up top/bottom view of the sensor or a connection is unreliable.

Ihcheung - 'left hand' with the writing towards me :-)
Juraj - thanks, when I get the connections sorted I'll try that
Sim Son - I'm suspecting the sensors to be honest, they were supercheap ones. I've got a different brand on order which I suspect will improve things.


text:
NodeMCU ESP8266 burnt. What have I done fundamentally wrong here?
So my setup is:
A 12v DR7-12 battery is providing the power for the board through a DC buck converter set to 3.3V connected to the 3.3V pin of the esp8266.
I then am using pins D5 and D6 to control an L298N motor driver, which has it's 12V connected to the battery (not through the board), it's ground to the battery and the IN1 and IN2 pins connected to the D5 and D6 pins.
I've ended up with three dead ESP8266 boards, they heat up and become unresponsive but as far as I know, I'm not putting any power through the board am I? What am I doing wrong?!

possibly because of no ground connection between ESP8266 and motor driver

So the ground pin of the board is connected to the buck converter and then the ground of the battery and the L298N is connected to the ground of the battery as well. Do I need to connect the ground of the L298N directly to the ground of the board as well or in place of?

it should be ok as long as the buck converter output ground is the same as the battery ground ... also, never disconnect the motor driver ground if the battery positive is still connected

Please set up a proper regulated 3.3V src before burning more (capacitors are always good and a vreg > buck).  The L298N can be pretty aggressive on its current needs so check that from the 3.3v src before using the esp in the middle.

When things get hot that is because current is flowing, in your case it appears to be to much. Voltage in itself will not do it in but if allowed to push current past the input protection diodes you can fry it very easily.  The input protection diodes are connected to VCC and Ground so the current is pushed into one of those rails, to much voltage pushes it into VCC and can mess up anything else connected to the VCC as well. You need to determine what part is getting hot, if it is the regulator you may be able to replace it. When in doubt insert resistors and measure voltages.

@Abel as the OP said, the L298N gets its power directly from the battery (12V), not from the buck converter. I aggree that the OP should check if there are regulated 3.3V at the output of the regulater before connecting anything!

So the ground pin of the board is connected to the buck converter and then the ground of the battery and the L298N is connected to the ground of the battery as well - just to make sure: is the buck converter's ground connected to the battery ground? In general, all grounds need to be connected!

@Gil from my understanding the OP is working with the bare esp8266 module rather than a nodeMCU. So the regulator is an external part anyway...

OOPS since he stated he is using pins D5 and D6 I assumed it was on a board. However my statement was on a chip level. I should have noted that some junctions can burn up and not warm the chip because they are small. In his case since it is getting warm typically it would be protection device on the chip or simply a breakdown of a junction which will still cause current to flow and get hot.

Thank you very much all for your detailed responses. You were right, I hadn't connected the ground on the output of the buck converter to the other grounds. So the esp8266 was only connected to the buck converter and the L298N was connected the ground of the battery. When I connected all the grounds together, I haven't had a problem. Why is this needed? Do you always tie all the grounds together?


text:
Max7219 7-segment display not working
when I connect VCC pin to the 5V and GND to the GND on the Arduino MEGA, then sometimes the display glows and sometimes it doesn't. It kinda looks like some contacts are bad because it starts to work mostly when I move it somehow, but I'm sure the problem is not in contacts as they defintely touch.
I also measured voltage on the display and it showed correctly ~5V.
Where could be the problem? Thanks
//Edit
I am using those displays to build simple autopilot panel for MSFS20 using MobiFlight. There is not any code, you just have to define what pins you connected and that's it. But even if it turns on, then all the leds stay on.
There might be a problem since I soldered the pins into the display so I could damage the board, it's a cheap one from China. Is there a way how to test if it's a board problem?

just because the two components touch, it does not mean that there is an electric connection ... corrosion on component leads can have insulating quality ... the 5 V reading is meaningless for a bad connection ... you would read 5 V if nothing was conected to the power pins

Well I have a 3 of these displays and they all behave same

I read 5V on the display, not on the arduino

you are not understanding .. a reading of 5 V is not an indication of the component fitness ... a burned out light bulb still has full voltage at its base

it sounds like the serial data line may have a problem

Oh I see, what can I do then?

@Elayer213 Sorry, currently we cannot really help you. We can just guess, because you didn't gave much information. Please show your circuit and also show, how you have connected everything (as jsotola wrote, touching doesn't mean good connection, especially if data should run over that connection). Please also show the code in your question. You can edit it and add all these information


text:
Multi-array number generation
This part of my project is very hard for my brain to wrap around and comprehend. But basically I just need to go through every combination. For example:
If I have an array with 255 variables and I need to bruteforce all the combinations by 30's (0, 30, 60, 90) How would I go about doing that in a decently compact form? It's really brain hurting please help a noob out <3
Note: I'm making a universal IR Remote but if by chance I don't have the code then I can just change the mode to brute force it.
volatile uint16_t IRCode[]={384,171,43,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,64,21,64}; // ProntoHex to uint16_t delete first 4 array numbers.
volatile uint16_t MicrosPassed;
volatile uint8_t ArraySeq;
uint8_t LEDState;
uint8_t SetMode=0;

void setup() {
  Config();
  SendIRCode();
}

void loop() {

}

void SendIRCode() {
  if(LEDState==1) {
    TCCR1A&=63;
    LEDState=0;
  } else {
    TCCR1A|=192;
    LEDState=1;
  }
}

void Config() {
  DDRB|=10;
  ICR1=416;
  OCR1A=9983;
  TCCR1A=2;
  TCCR1B=24;
  TCCR1B|=1;
  TIMSK1=1;
}

ISR(TIMER1_OVF_vect) {
  MicrosPassed++;
  if(MicrosPassed==IRCode[ArraySeq]) {
    SendIRCode();
    MicrosPassed=0;
    ArraySeq++;
       }
}

this is a general programming question that is not arduino specific

examine the use of for loops

@jstola it is 100% arduino-uno specific. Config() is for arduino-uno made in the arduino ide. random() is a arduino function. If I did config() on anything but the uno it would most likely not work.

@fman122: your Config function is plain AVR C code. The only Arduino flavor is the fact that you have a setup and loop function rather than a main (or some other entry point) - and you're not using any Arduino functions in there either.

@Mat well I mean if you read the post instead of arguing I was planning on using a arduino function called random(). That's why I mentioned it. Why does everyone try to delete other peoples questions :| I've seen so many great questions on here and people always close them for stupid reasons and assume things about the post even if they are obvious. Also again if I did my specific sketch I would not be able to run it on anything other than a arduino. It makes literally no sense to go to any other forum. Arduino doesn't contain all of c/c++ so it would be dumb to go to another forum asking abou

infrared communication on a arduino uno on a forum about electronics, or programming. But I sha'll try that and see what result I get and update you. ;) HINT: (They will either close it or tell me to go to the arduino stack exchange).

What do you mean by "all the combinations by 30's"? Do you mean any possible combination of 30 elements out of the 255?

Not sure why you doing this? there are library exist that you could use, or learn from. You may want to take a look at Arduino-IRremote which was based on a c-library long existed even before Arduino was invented. Take a look at the IRsendRawDemo example, and the library source code.

In my opinion the question is on topic. It asks for Arduino solution of a problem. and then chrisl's and hcheung's comments apply

@chrisl I meant by counting by 20's. So 20,40,60. I found that you can skio microseconds and just jump and it will most likely work.

@hcheung 1. I get a better grasp learning something through analysis and the inner workings. 2. the project I am working towards can't have a single bug. So I'm keep it simple barebones and tight. Not even an emp will be able to mess with the electronics.

You still didn't really explain what combinations you want to go through. What does counting by 20s mean here (and why now 20s, not 30s like in your question)? Do you want to create an array, where multiples of 20 are randomly stored?


text:
How do I Upload a Program via Serial Port to an Optiboot_X-Enabled TinyAVR-0/1 Microcontroller using the Command Line?
Background
In 2019, Microchip acquired Atmel and released several new AVR microcontrollers, including the Tiny-0 and Tiny-1 Series. On these mircocontrollers, traditional Atmel ICSP programming was not supported. Instead, they feature a new one-wire programming interface called Unified Programming and Debug Interface (UPDI). The new hardware also made existing TTL-serial bootloader programming obsolete. Thus, one must use a native UPDI programmer to work with these microcontrollers, such as pyupdi.
However, Optiboot's developers have subsquently developed a new version of the bootloader called Optiboot_X and implemented the STK500 programming protocol on these new microcontrollers, allowing one to program these microcontrollers using the traditional TTL-serial bootloader approach, and it appears that the Arduino community has already supported them for a while, with MegaCoreX and megaTinyCore, which was good news to me. Nevertheless, it seems that there's little resource beyond these prepackaged Arduino cores, in particular, there's almost no documentation on how to program them manually from the commandline.
What I've already done
I designed a custom AVR development board based on the Atmel ATTiny1604 microcontroller, which is a member of the new Tiny-0 family. Due to technical considerations, it must be programmed via the serial port using the bootloader similar to a traditional Arduino, not UPDI (UPDI is only used to burn the bootloader).
To achieve this goal, I installed the latest version of binutils, GCC and an experimental patch to avr-libc, so the compiler is able to generate code targeting my microcontroller. Then, I compiled my personal Optiboot_X bootloader.
$ git clone https://github.com/Optiboot/optiboot.git
$ cd optiboot/optiboot/bootloaders/optiboot
$ make -f Makefile.mega0 optiboot_attiny1604.hex UARTTX=A1 TIMEOUT=8 LED=A7 BAUD_RATE=57600 LED_START_FLASHES=10

Using Compiler at: /home/user/code/optiboot/optiboot/bootloaders/optiboot/avr-gcc
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax  -DWDTTIME=8  -DLED_START_FLASHES=10  -DLED=A7   -DUARTTX=A1 -DBAUD_RATE=57600       -Wl,-section-start=.text=0 -Wl,--section-start=.application=0x200 -Wl,--section-start=.version=0x1fe -Wl,--relax -nostartfiles -nostdlib  -mmcu=attiny1604 -o optiboot_attiny1604.elf optiboot_x.c
avr-size optiboot_attiny1604.elf
   text    data     bss     dec     hex filename
    494       9       0     503     1f7 optiboot_attiny1604.elf
avr-objdump -S  optiboot_attiny1604.elf > optiboot_attiny1604.lst
avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_attiny1604.elf optiboot_attiny1604.hex

Then I uploaded the Optiboot_X bootloader to the ATTiny1604 microcontroller via UPDI, using pyupdi.
# set fuse BOOTEND
$ pyupdi -d tiny1604 -c /dev/ttyUSB0 -fs 8:0x02

# burn Optiboot_X
$ pyupdi -d tiny1604 -c /dev/ttyUSB0 -f optiboot_attiny1604.hex

# reset
$ pyupdi -d tiny1604 -c /dev/ttyUSB0 -r

After burning the Optiboot_X via UPDI, I was able to see 10 pulses during power-on at A7 on my oscilloscope, indicating that Optiboot_X was alive.
Note: Technically the installation is not complete yet. Since UPDI and /RESET share the same pin, UPDI must be permanently disabled via fuse to allow programming via bootloader, but it means a nonfunctional bootloader can brick the chip. I decided to manually reset the chip by power cycling the board for now.
Next, I wrote a test program.
$ cat blink.c

#define F_CPU 20000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
    PORTB.DIRSET = 0b00000001;

    while(1) {
        PORTB.OUTSET = 0b00000001;
        _delay_ms(500);
        PORTB.OUTCLR = 0b00000001;
        _delay_ms(500);
    }
}

And I compiled it.
$ make
avr-gcc -mmcu=attiny1604 -Wall -Os -o blink.elf blink.c
avr-objcopy -j .text -j .data -j .rodata -O ihex blink.elf blink.hex

Question
Now what? How do I upload blink.hex to the Optiboot_X on the microcontroller?
On a traditional Arduino, the command is something like...
$ avrdude -C/etc/avrdude/avrdude.conf -v -patmega328p \
  -carduino -P/dev/ttyUSB0 -b38400 -D -Uflash:w:blink.hex:i

But this is not an ATMega328P and there's nearly zero documentation on the web, I have a lot of questions and I'm not sure how to proceed.
To begin with, in man avrdude, there's no mention of any Tiny0 or Tiny1 devices. What should the -p argument be? Also, do I need to use a patched version of avrdude? Do I need a customized avrdude.conf? If so, where can I find them?

Since you're using optiboot avrdude shouldn't care what the chip is.

After poking around in the git repository for a while, I've solved the problem. To work with these new TinyAVR-0/1 microcontrollers, a new version of avrdude is needed. Since avrdude hasn't made a stable release yet, it's necessary to build a new avrdude from source from SVN.
$ svn co https://svn.savannah.nongnu.org/svn/avrdude/trunk avrdude
$ cd avrdude/avrdude
$ ./bootstrap
$ mkdir build && cd build
$ ../configure
$ make
$ make install

After installation, /usr/local/bin/avrdude and /usr/local/etc/avrdude.conf should be available. One can see that a bunch of new TinyAVR parts have been added...
$ avrdude -p?

Valid parts are:
  [...]
  t10      = ATtiny10
  t11      = ATtiny11
  t12      = ATtiny12
  t13      = ATtiny13
  t15      = ATtiny15
  t1604    = ATtiny1604
  t1606    = ATtiny1606
  t1607    = ATtiny1607
  t1614    = ATtiny1614
  t1616    = ATtiny1616
  t1617    = ATtiny1617
  t1634    = ATtiny1634
  t20      = ATtiny20
  t202     = ATtiny202
  t204     = ATtiny204
  t212     = ATtiny212
  t214     = ATtiny214
  t2313    = ATtiny2313
  t24      = ATtiny24
  t25      = ATtiny25
  t26      = ATtiny26
  t261     = ATtiny261
  t28      = ATtiny28
  t3214    = ATtiny3214
  t3216    = ATtiny3216
  t3217    = ATtiny3217
  t4       = ATtiny4
  t40      = ATtiny40
  t402     = ATtiny402
  t404     = ATtiny404
  t406     = ATtiny406
  t412     = ATtiny412
  t414     = ATtiny414
  t416     = ATtiny416
  t417     = ATtiny417
  t4313    = ATtiny4313
  t43u     = ATtiny43u
  t44      = ATtiny44
  t441     = ATtiny441
  t45      = ATtiny45
  t461     = ATtiny461
  t5       = ATtiny5
  t804     = ATtiny804
  t806     = ATtiny806
  t807     = ATtiny807
  t814     = ATtiny814
  t816     = ATtiny816
  t817     = ATtiny817
  t84      = ATtiny84
  t841     = ATtiny841
  t85      = ATtiny85
  t861     = ATtiny861
  t88      = ATtiny88
  t9       = ATtiny9
  [...]

To program the ATTiny1604, simply run...
$ avrdude -C/usr/local/etc/avrdude.conf -v -pt1604 \
  -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:blink.hex:i

Don't forget to modify the -b57600 argument to match the baud of your Optiboot_X build.
Lesson learned: When RTFM is impossible, use the source, Luke!
Potential Problems
avrdude: verification error; content mismatch
It's possible that avrdude successfully establishes communication with the board via the serial port, reads the correct device signature, then attempts to upload a program, but ultimately fails verification.
$ avrdude -v -pattiny1604 -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:blink.hex:i

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9425 (probably t1604)
avrdude: reading input file "blink.hex"
avrdude: writing flash (204 bytes):

Writing | ################################################## | 100% 0.06s

avrdude: 204 bytes of flash written
avrdude: verifying flash memory against blink.hex:
avrdude: load data flash data from input file blink.hex:
avrdude: input file blink.hex contains 204 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.06s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x01 != 0x0c
avrdude: verification error; content mismatch

Solution: In TinyAVR 0/1, the bootloader is located at the beginning of the flash memory, occupies the first 512 bytes. When compiling the program to be uploaded via the bootloader, the correct 512-byte text section offset must be specified. Otherwise, avrdude will attempt to program from 0x00, which is impossible, because it's the location of the bootloader. Upon readback, instead of your program, avrdude reads the bootloader, which triggers the verification failure in question (it's worth noticing that 0x01, the first mismatched byte that triggers verification failure, is actually the first byte in the Optiboot_X binary code).
Instead of using...
avr-gcc -mmcu=attiny1604 -Wall -Os -o blink.elf blink.c

Recompile your program with `
avr-gcc -mmcu=attiny1604 -Wall -Os -o blink.elf blink.c \
-Wl,--section-start=.text=0x200

avr-objcopy -j .text -j .data -j .rodata -O ihex blink.elf blink.hex

And reupload it.
$ avrdude -v -pattiny1604 -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:blink.hex:i

avrdude: Device signature = 0x1e9425 (probably t1604)
avrdude: reading input file "blink.hex"
avrdude: writing flash (716 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 716 bytes of flash written
avrdude: verifying flash memory against blink.hex:
avrdude: load data flash data from input file blink.hex:
avrdude: input file blink.hex contains 716 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 716 bytes of flash verified

avrdude: safemode: Fuses OK (E:FF, H:FF, L:FF)

avrdude done.  Thank you.

avrdude: programmer type jtagice3_updi not found
It's possible that avrdude reports the following error...
/usr/bin/avrdude -C/usr/local/etc/avrdude.conf -v -pattiny1604 -carduino -P/dev/ttyUSB0 -b38400 -D -Uflash:w:blink.hex:i

avrdude: Version 6.3, compiled on Jul 24 2019 at 00:00:00
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/usr/local/etc/avrdude.conf"
avrdude: error at "/usr/local/etc/avrdude.conf:1091: programmer type jtagice3_updi not found
avrdude: error reading system wide configuration file "/usr/local/etc/avrdude.conf"

Solution: You are trying to run an old version of avrdude with a new configuration file. Make sure the avrdude executable you are running is actually the up-to-date version compiled from the upstream SVN repository.


text:
device signature 0x000000 when burning bootloader
I receive this message: "device signature 0x000000" when a try to burn the bootloader on a atmega328p-au (SMD) inserted on PCB
i am using arduino uno as isp i already uploaded the ArduinoISP sketch and i check "Arduino as ISP" as programmer  with "arduino nano" as board
i do not know what is the problem i tried to check the ISP wiring with the arduino uno and everything is alright
what i noticed is that when i remove the GND wire attached to ISP the pin13 of the arduino lights up when i connect it it lights off i do not know what to do
here is the full schematic
Thank you for helping me

Not necessary related, but what the D4 for? it make your 7805 ground 0.6v higher than the ground.

If all the lights go out on the Arduino when you plug it in, it sounds like a short circuit...

On an unrelated note: where are all your decoupling capacitors?

@Majenko Can you explain me please why the short circuit happens and how to fix it ?

Your schematic looks ok, so it may be your PCB where the problem lies.

@Majenko you are absolutely right i fixed my bootloader problem and i was able to burn the sketch when i power 3 to 4 LEDS every thing seems to be fine but when i power on all the leds  they start blinking so quick so you are right there is a short circuit happening can you help me please ?

Take some high resolution photographs of your PCB with good lighting.

@Majenko Here are the pictures

@Majenko
https://ibb.co/b1qh2rx
https://ibb.co/n3hthH7
https://ibb.co/42SdNYY
Thank you for helping me

Looks ok on first inspection, but you do have some quite tight clearances there. Check for shorts with a DMM

@Majenko should the tight clearances  makes a problem ?

@Majenko i will check using DMM as you told me to and i will keep you on update in the mean while please let me know if you noticed anything wrong thank you very much again

Tight clearances can cause problems with the etching.

if so can you suggest me a solution ?

@Majenko i did a test and it worked what i did is i supplied the circuit with independent 5v coming out from arduino (vcc5v & gnd) and the 12v was wired to all the LEDS only so i eliminated the role of 7805 and every thing seems to work perfect i think the D4(B5819W) seems to make the problem i do not know why this is happening  any suggestions ?

@Majenko can you please help

@Majenko you said : <<If all the lights go out on the Arduino when you plug it in, it sounds like a short circuit>> can you please explain to me why and how to fix this because it is happening :(

Did you ever find the solution? I'm stuck as well.


text:
ESP32: best way to embed certificates
I'm using the Arduino framework on an ESP32 based board. The board has an SD card slot, but I'm not going to use it.
Anyway, I need to store somewhere the certificates. To the the firmware I've just hardcoded them into the code:
const char *rootCABuff = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB\n" \
...
"hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq\n" \
"-----END CERTIFICATE-----\n";

const char certificateBuff[] = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIDWTCCAkGgAwIBAgIUZXjPNnJFXMntXOki9BT+QmDFciUwDQYJKoZIhvcNAQEL\n" \
...
"gGXtqlgPnenkZPTaBr9c8o+WjgQXFLM+Jwnw3/53dUI9zBcybTaptI63o3Ct\n" \
"-----END CERTIFICATE-----\n";

const char privateKeyBuff[] = \
"-----BEGIN RSA PRIVATE KEY-----\n" \
"MIIEpAIBAAKCAQEAuuKsFy98/xsJclnWo0d+qm8KImLEILB64BbH7WaYi3NnznLg\n" \
...
"uHfBLQQDrA0HDRvYpAUNw/b2H4dpUK/nGM4FFVMP7V8RM2t2923nhQ==\n" \
"-----END RSA PRIVATE KEY-----\n";

Of course this is not suitable for production where each unit will have a different set of certificates.
So wonder what is the best way to store them.
The obviously idea is into flash. So I tried to enhance my settings class, based upon the Preferences library. In the official documentation I read:

String values are currently limited to 4000 bytes. This includes the null terminator. Blob values are limited to 508000 bytes or 97.6% of the partition size - 4000 bytes, whichever is lower.

But if I do something like this:
Preferences prefs;
prefs.begin("settings", false);
Serial.println(prefs.freeEntries());

it return 460, even if I still have plenty of flash:
Flash: [=======   ]  73.8% (used 967234 bytes from 1310720 bytes)

Is there another library more suitable to store such a data that can be used with Preferences?

Hi mate, you could also use spiffs memory, check here, it may help you: https://diyprojects.io/esp32-get-started-spiff-library-read-write-modify-files/

I don't know this libraries but "freeEntries" does not look like something that returns a size in bytes. Looks like it is telling you how many more values you can store. (Similar to max number of files that some filesystems have, not total available free space.)

You don't need any library. How many certs you intend to store? For ESP32, any variable that declared as const is stored in flash memory, and internally it does not have to copy the data from flash to RAM but uses the Flash MMU to map the memory segments into either IRAM or normal RAM, so it doesn't take up your ESP32 RAM. Alternatively, you could stored it in SPIFFS or FS as a file.

@hcheung Sorry I explained it wrong. I need to store only those certificates. The problem is I cannot change the code every time a program a new board! So I'm going to "download" the data via serial line, and save it into the flash at run-time.

@Mat, got it. I'm going to give it a try to see if I can actually save them like my other preferences.

@k.Cyborg, good advice. I will try spiffs hoping it can be used together the other stuff.

I don't know what you need that Preferences thing for, but I would use SPIFFS/FAT anyway. Simply store the certificate in a file in flash and read that file when you need it. The required space is no problem as you can choose the size for file system in the partition table and also you can upload the file (there is a plugin in the arduino IDE for this purpose) after flashing the firmware, so having different certificates on individual devices is no problem.
I saw that you tagged the question with 'eeprom': the esp has no eeprom but emulates it with a blob in flash, so using any flash library is just as fine. The esp also supports wear-leveling, which makes using flash an even better option as the dedicated eeprom-partition, which was used in an older version of the sdk, would wear out orherwise. The "eeprom" is just there to be consistent with the use of other arduino's eeproms.

Yeah, I've just tried it and it's very handy! Just a clarification: I'm using PlatformIO inside Visual Studio Code and I only found a way to put the desired files into a data folder to be uploaded. Is there something better? Because I will need to replace the files for each unit...

You can use the sdk's bare features, nsmely the tools mkspiffs and esptool.py to create the flash binary and to upload it. See this anser: https://arduino.stackexchange.com/a/51581/38721


text:
What happen to the counter value if I do not input the statement (if previous state!=current state)
I refer to the code from this page: http://www.toddholoubek.com/classes/pcomp/?page_id=58 :
int ledPin = 13; // choose the pin for the LED
int switchPin =2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int previousState = 0;

void setup() {
  pinMode(ledPin, OUTPUT); // declare LED as output
  pinMode(switchPin, INPUT); // declare pushbutton as input
  Serial.begin(9600);
}

void loop() {
  val = digitalRead(switchPin); // read input value
  if (val == HIGH) { // check if the input is HIGH (button released)
    digitalWrite(ledPin, HIGH); // turn LED on
    currentState = 1;
  }
  else {
    digitalWrite(ledPin, LOW); // turn LED off
    currentState = 0;
  }
  if(currentState != previousState) {
    if(currentState == 1) {
      counter = counter + 1;
      Serial.println(counter);
    }
  }
  previousState = currentState;
  delay(250);
}

I do not have the Arduino device so couldn't test the result currently but am Interested to know if I omitted this line:
if(currentState != previousState)

, using the command line
if(currentState == 1) {
counter = counter + 1;

only and lets say I using a FS-V21 fiber optic sensor to count the quantity of products of 1m long each and on a conveyer belt of speed 0.1m/s so the stat will be true of t=1/0.1=10second for each product.
Will the counter value increase one unit only for each product (happen on the transition edge only), or increase indefinitely in the 10 second duration?

Because of the line
delay(250);

towards the end of the loop() function it will count up once every quarter of a second all the time the "state" is 1.
That means over a 10 second period it will count 40 objects.

No, it will increment as long as there is a product and at the frequency your loop runs at. So, when the light is interrupted, it will count several objects within a second.
The line you want to ommit is very essential, it makes the sketch only detect edges rather than levels.


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

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

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

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

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

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

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

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

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

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

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

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

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

float getTemp(void);

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

   // Open console
   Serial.begin(115200);

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

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

      delay(1000L);
   }

}

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

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

void loop(void)
{
   ;
}


text:
What happens, memory-wise, when I call a function from another function?
I'm inspecting where the memory is used in an application which runs on Arduino. To my surprise, there are several locations where 100 to 200 bytes are consumed by simply calling a function. Example:
void Dispatcher::processCommand() {
    ...
    displayMemory();
    this->process(this->instruction);
}

void Dispatcher::process(const Instruction &instruction) {
    displayMemory();
    if (instruction.length > 0) {
        ...
        return;
    }

    ErrorResponse::componentNotFound(instruction).output(this->serial);
    TerminationResponse(instruction.commandId, 0xFF).output(this->serial);
}

The first call to displayMemory() will report that there is 351 bytes left. The second one will tell that only 159 bytes remain (that is, 192 bytes less).
If I alter the body of the process function, the difference between the two memory reports vary. For instance, if I remove the two last lines, the difference drops from 192 bytes to 12 bytes.
I don't understand why this happens. I was thinking that between the moment I'm ready to call a function and a moment when the function starts, the memory should be used exclusively by the additional element in the call stack (the aforementioned 12 bytes maybe?) and the copying of the parameters passed by value (none here). Why is this not the case? What really happens under the hood?

The clue is in those last two lines:
    ErrorResponse::componentNotFound(instruction).output(this->serial);
    TerminationResponse(instruction.commandId, 0xFF).output(this->serial);

Let's tear them apart and see what they actually do.
ErrorResponse::componentNotFound(instruction).output(this->serial);

Call the static function componentNotFound with your instruction, then take the object that is returned, and call the output() method on it passing this->serial as a parameter.
The hint there is take the object that is returned.
componentNotFound() returns an object. That object has to be stored somewhere. That "somewhere" is on the stack.  And stack space is allocated during the function preamble.  That's the bit of code that runs at the start of the function allocating stack, pushing registers to the stack, etc.
The same happens in the second line:
TerminationResponse(instruction.commandId, 0xFF).output(this->serial);

Create a new TerminationResponse object and call the output method.
All that goes on the stack.
It's not the calling of the function that is using the memory, it's what the function is doing that is using the memory.

A function's data-memory space is reserved on the stack when the function is called, and returned when the function returns. If that function1 calls another, function2, then function1's space remains on the stack and more space is reserved for function2 for the duration of its execution. When function2 returns to function1, function2's memory is released, and finally, when function1 returns, its memory is released.
Now in a little more detail:
When you call function1, the arguments you pass it are put on the stack. When control actually passes to function1, the instruction address following the call, where function1 should eventually return to, is put on the stack. If function1 needs data temporary data space (automatic variables), space for those is put on the stack. (Ditto for function2, if one is called from function 1; and so on.)
When each of those functions returns, their automatic data space (just the space, not the data!) and the return address are removed from the stack; the caller removes the space for the arguments it had pushed, and execution resumes immediately following the call.
The difference in usage you're seeing depending on the presence or absence of the last two lines of Dispatcher::process(), is the memory (arguments+return address+automatic data) used by those two functions.


text:
File created, but not logging data
I am starting using Arduino and have very little to none experience coding. However, I have managed to code and understand how it works.
The problem that I have is that I am unable to log (record) data from the three sensors attached (Adafruit Anemometers). All of them work properly; the data file is created. However, there is no data (or time reference) being written on the file.
When I verify the code, it's approved...Therefore, it should work, right?.=/
Then, I uploaded code.
I am using an Arduino uno with an SD Logger shield (Data Logging Shield v1.0, from Deek-Robot(TM)), which uses a DS1307 RTC.
All comments are more than welcome!
Thanks in Advance
#include "SD.h"
#include <Wire.h>
#include "RTClib.h"

// A simple data logger for the Arduino analog pins
#define LOG_INTERVAL  60000 // mills between entries
#define ECHO_TO_SERIAL   0 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the digital pins that connect to the LEDs
#define redLEDpin 3
#define greenLEDpin 4

// The analog pins that connect to the sensors
#define Anemometer0           // analog 0
#define Anemometer1           // analog 1
#define Anemometer2           // analog 2

RTC_DS1307 RTC; // define the Real Time Clock object

//Setup Variables of Anemometers

//Anemometer0
const int sensorPin0 = A0; //Defines the pin that the anemometer output is connected to
int sensorValue0 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage0 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed0 = 0; // Wind speed in meters per second (m/s)

//Anemometer1
const int sensorPin1 = A1; //Defines the pin that the anemometer output is connected to
int sensorValue1 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage1 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed1 = 0; // Wind speed in meters per second (m/s)

//Anemometer2
const int sensorPin2 = A2; //Defines the pin that the anemometer output is connected to
int sensorValue2 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage2 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed2 = 0; // Wind speed in meters per second (m/s)

float voltageConversionConstant = .004882814; //This constant maps the value provided from the analog read function,
//which ranges from 0 to 1023, to actual voltage, which ranges from 0V to 5V
int sensorDelay = 1000; //Delay between sensor readings, measured in milliseconds (ms)

//Anemometer Technical Variables
//The following variables correspond to the anemometer sold by Adafruit but could be modified to fit other anemometers.

float voltageMin = .4; // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax = 2.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging file
File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);

  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);

  while(1);
}

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  Serial.println();

#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");

  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE);
      break;  // leave the loop!
    }
  }

  if (! logfile) {
    error("couldnt create file");
  }

  Serial.print("Logging to: ");
  Serial.println(filename);

  Wire.begin();
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }

  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);

   // If you want to set the aref to something other than 5v
  //analogReference(EXTERNAL);
}

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

  DateTime now;

  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));

  digitalWrite(greenLEDpin, HIGH);

  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");
#endif

  // fetch the time
  now = RTC.now();
  // log time
//logfile.print(); // seconds since 2000
  logfile.print(", ");
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);

#if ECHO_TO_SERIAL
  Serial.print(now.get()); // seconds since 2000
  Serial.print(", ");
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL

//Anemometer0
const int sensorPin0 = A0; //Defines the pin that the anemometer output is connected to
int sensorValue0 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage0 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed0 = 0; // Wind speed in meters per second (m/s)

//Anemometer1
const int sensorPin1 = A1; //Defines the pin that the anemometer output is connected to
int sensorValue1 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage1 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed1 = 0; // Wind speed in meters per second (m/s)

//Anemometer2
const int sensorPin2 = A2; //Defines the pin that the anemometer output is connected to
int sensorValue2 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage2 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed2 = 0; // Wind speed in meters per second (m/s)

float voltageConversionConstant = .004882814; //This constant maps the value provided from the analog read function,
//which ranges from 0 to 1023, to actual voltage, which ranges from 0V to 5V
int sensorDelay = 1000; //Delay between sensor readings, measured in milliseconds (ms)

//Anemometer Technical Variables
//The following variables correspond to the anemometer sold by Adafruit but could be modified to fit other anemometers.

float voltageMin = .4; // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax = 2.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage

  logfile.print(", ");
  logfile.print(A0);
  logfile.print(", ");
  logfile.print(A1);
  logfile.print(",");
  logfile.println(A2);

#if ECHO_TO_SERIAL
  Serial.print(", ");
  Serial.print(Anemometer0);
  Serial.print(", ");
  Serial.print(Anemometer1);
  Serial.print(",");
  Serial.println(Anemometer2);
#endif //ECHO_TO_SERIAL

  digitalWrite(greenLEDpin, LOW);
}
´´´

You "verified", yes. But did you "upload"?

you don't open the file if it exists

@Juraj That bit of code is to create a new file with sequential numbering. It will find the first file that doesn't exist in LOGGER00.CSV to LOGGER99.CSV and open that.

Yes @Majenko, the code was uploaded correctly to the board. But I haven't mentioned that in the written explanation, thanks for pointing that out. Should the file contain some data and date/time?

I suspect you aren't giving it enough time to flush the data to the SD card and it's only in the buffer. You should call logfile.flush(); after each iteration.

Did you make a copy paste error, when putting the code in the question? You have a part in loop() where you again define the global variables like sensorPin0

Your delay statements seems really weird to me. Why are you doing this? If you want to read at a specific interval, you should use millis() like in the BlinkWithoutDelay example and avoid delay() completely

@chris|, yes... I made an error. Thanks for noticing!

Thanks for all your help. I managed to log data in the SD card including date and time. The new code is the following:
#include <SPI.h>
#include <SD.h>
#include "RTClib.h"

RTC_DS1307 rtc; // create local instances of library class objects

DateTime time;

File dataFile;

const int chipSelect = 10;

// Anemometer at 0.15 magl

const int sensorPinA0 = A0; //Defines the pin that the anemometer output is connected to
int sensorValue0 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage0 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float WindSpeed0 = 0; // Wind speed in meters per second (m/s)

float voltageConversionConstant0 = .0048828125; //This constant maps the value provided from the analog read function, which ranges from 0 to 1024, to actual voltage, which ranges from 0V to 5V
// hence, this value corresponds to 5.00V/1024. Check https://forum.allaboutcircuits.com/threads/why-adc-1024-is-correct-and-adc-1023-is-just-plain-wrong.80018/
int sensorDelay0 = 60000; //Delay between sensor readings, measured in milliseconds (ms)

//Anemometer Technical Variables
//The following variables correspond to the anemometer sold by Adafruit but could be modified to fit other anemometers.

float voltageMin0 = .4; // Mininum output voltage from anemometer in mV.
float windSpeedMin0 = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax0 = 2.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax0 = 32; // Wind speed in meters/sec corresponding to maximum voltage

// Anemometer at 0.5 magl

const int sensorPinA1 = A1; //Defines the pin that the anemometer output is connected to
int sensorValue1 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage1 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float WindSpeed1 = 0; // Wind speed in meters per second (m/s)

float voltageConversionConstant1 = .0048828125; //This constant maps the value provided from the analog read function, which ranges from 0 to 1024, to actual voltage, which ranges from 0V to 5V
// hence, this value corresponds to 5.00V/1024. Check https://forum.allaboutcircuits.com/threads/why-adc-1024-is-correct-and-adc-1023-is-just-plain-wrong.80018/
int sensorDelay1 = 1000; //Delay between sensor readings, measured in milliseconds (ms)

//Anemometer Technical Variables
//The following variables correspond to the anemometer sold by Adafruit but could be modified to fit other anemometers.

float voltageMin1 = .4; // Mininum output voltage from anemometer in mV.
float windSpeedMin1 = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax1 = 2.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax1 = 32; // Wind speed in meters/sec corresponding to maximum voltage

// Anemometer at 1.2 magl

const int sensorPinA2 = A2; //Defines the pin that the anemometer output is connected to
int sensorValue2 = 0; //Variable stores the value direct from the analog pin
float sensorVoltage2 = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float WindSpeed2 = 0; // Wind speed in meters per second (m/s)

float voltageConversionConstant2 = .0048828125; //This constant maps the value provided from the analog read function, which ranges from 0 to 1024, to actual voltage, which ranges from 0V to 5V
// hence, this value corresponds to 5.00V/1024. Check https://forum.allaboutcircuits.com/threads/why-adc-1024-is-correct-and-adc-1023-is-just-plain-wrong.80018/
int sensorDelay2 = 60000; //Delay between sensor readings, measured in milliseconds (ms)

//Anemometer Technical Variables
//The following variables correspond to the anemometer sold by Adafruit but could be modified to fit other anemometers.

float voltageMin2 = .4; // Mininum output voltage from anemometer in mV.
float windSpeedMin2 = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax2 = 2.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax2 = 32; // Wind speed in meters/sec corresponding to maximum voltage

void setup() {
 Serial.begin(9600);
 while (!Serial) {;} // wait for serial port to connect.
 Serial.print("Initializing SD card...");
 if (!SD.begin(chipSelect)) {
 Serial.println("Card failed, or not present");
 while (1); // loop forever
 }
 Serial.println("Have SD card");
 rtc.begin();
}

void loop() {

sensorValue0 = analogRead(A0); //Get a value between 0 and 1023 from the analog pin connected to the anemometer
sensorValue1 = analogRead(A1); //Get a value between 0 and 1023 from the analog pin connected to the anemometer
sensorValue2 = analogRead(A2); //Get a value between 0 and 1023 from the analog pin connected to the anemometer

sensorVoltage0 = sensorValue0 * voltageConversionConstant0; //Convert sensor value to actual voltage
sensorVoltage1 = sensorValue1 * voltageConversionConstant1; //Convert sensor value to actual voltage
sensorVoltage2 = sensorValue2 * voltageConversionConstant2; //Convert sensor value to actual voltage

//Convert voltage value to wind speed using range of max and min voltages and wind speed for the anemometer
if (sensorVoltage0 <= voltageMin0){
WindSpeed0 = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
}

else {
  WindSpeed0 = (sensorVoltage0 - voltageMin0)*windSpeedMax0/(voltageMax0 - voltageMin0); //For voltages above minimum value, use the linear relationship to calculate wind speed on A0.
    }

if (sensorVoltage1 <= voltageMin1){
WindSpeed1 = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
}

else {
  WindSpeed1 = (sensorVoltage1 - voltageMin1)*windSpeedMax1/(voltageMax1 - voltageMin1); //For voltages above minimum value, use the linear relationship to calculate wind speed on A1.
    }

if (sensorVoltage2 <= voltageMin2){
WindSpeed2 = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
}

else {
  WindSpeed2 = (sensorVoltage2 - voltageMin2)*windSpeedMax2/(voltageMax2 - voltageMin2); //For voltages above minimum value, use the linear relationship to calculate wind speed on A2.
    }

 time = rtc.now(); // Read RTC
 String dataString = ""; // Assemble data

log:
 dataString = time.timestamp(DateTime::TIMESTAMP_DATE);
 dataString += ", ";
 dataString += time.timestamp(DateTime::TIMESTAMP_TIME);
 dataString += ", ";
 dataString += String(sensorVoltage0);
 dataString += ", ";
 dataString += String(WindSpeed0);
 dataString += ", ";
 dataString += String(sensorVoltage1);
 dataString += ", ";
 dataString += String(WindSpeed1);
 dataString += ", ";
 dataString += String(sensorVoltage2);
 dataString += ", ";
 dataString  += String(WindSpeed2);
 dataFile = SD.open("Speedlog.txt", FILE_WRITE);
 if (dataFile) { // Write to logfile

 dataFile.println(dataString);
 dataFile.close();
 Serial.println(dataString);
 delay(1000); // pause for one second between sensor logs
 }
 else {
 Serial.println("error opening datalog.txt");
 }
}

You shouldn't use a String, and you don't need to because you can just write all the bits to the file without concatenating them first. If you must, you should remove String dataString = ""; from the loop and add it as a global at the top; it may help a bit with keeping your heap intact, but it's better to avoid String altogether.


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);
    }
}