text:
"Done uploading" but Uno still running old sketch
So, this is my first experience, I bought new original Uno, trying write some code there and it stuck in running only one sketch.
Tools->Boards is ok, Tools->Ports is ok.
I try created new sketch from File->Examples->01. Basics->Blink and it uploaded successfully, but Uno still running old code and sending to Serial Monitor data (from empty A0, where was potentiometer)
I tried reinstall Arduino App, trying on Windows, tried with only power (just 12v round port, without USB) and it still launch old sketch.
When I plug Uno to Mac or Windows it immediately start spaming to Serial Monitor same data.
Clicking, pressing, holding "reset" button with plug or unplug on smth else doesn't work.
==============
Here is my last code, which "stuck" on Uno right now:
const int myPin = A0;

void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  int sensorValue = analogRead(myPin);
  // Serial.print("Sensor value: ");
  Serial.println(sensorValue);

}

And proof that upload success:

Here is code of Blink from examples:
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

And proof that upload success:

Here is my Uno without anything but with lighted TX port when I plug it into Mac/Windows (you can see that L/13 bulb light darker than should and I don't know why):

And here is unstoppable spaming in Serial Monitor by sketch from first code:
01:57:24.874 -> 430
01:57:24.874 -> 420
01:57:24.874 -> 425
01:57:24.874 -> 435
01:57:24.874 -> 424
01:57:24.874 -> 425
01:57:24.907 -> 425
01:57:24.907 -> 434
01:57:24.907 -> 422
01:57:24.907 -> 425
01:57:24.907 -> 425
01:57:24.907 -> 433
01:57:24.940 -> 420
01:57:24.940 -> 424
01:57:24.940 -> 423
01:57:24.940 -> 431
01:57:24.940 -> 417
01:57:24.940 -> 423
01:57:24.940 -> 422
01:57:24.973 -> 429
01:57:24.973 -> 415
01:57:24.973 -> 421
01:57:24.973 -> 422
01:57:24.973 -> 424
01:57:24.973 -> 416
01:57:25.005 -> 421
01:57:25.005 -> 428
01:57:25.005 -> 421
01:57:25.005 -> 419
01:57:25.005 -> 418
01:57:25.005 -> 426
01:57:25.036 -> 415
01:57:25.036 -> 417
01:57:25.036 -> 417
01:57:25.036 -> 424
01:57:25.036 -> 411
01:57:25.036 -> 416
01:57:25.036 -> 416
01:57:25.069 -> 424
01:57:25.069 -> 410
01:57:25.069 -> 416
01:57:25.069 -> 416
01:57:25.069 -> 423
01:57:25.069 -> 407
01:57:25.101 -> 415

===========
UPD:
On IDE v. 1.8.19 I got this
Arduino: 1.8.19 (Mac OS X), Board: "Arduino Uno"

Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
An error occurred while uploading the sketch
avrdude: verification error, first mismatch at byte 0x0002
         0x5d != 0x5c
avrdude: verification error; content mismatch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

With checked show verbose during compilation and upload I got more:
Arduino: 1.8.19 (Mac OS X), Board: "Arduino Uno"

/private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/hardware -hardware /Users/mr_belogub/Library/Arduino15/packages -tools /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/tools-builder -tools /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/mr_belogub/Library/Arduino15/packages -built-in-libraries /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/libraries -libraries /Users/mr_belogub/Documents/Arduino/libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10819 -build-path /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559 -warnings=none -build-cache /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_cache_275921 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.arduinoOTA.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -verbose /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/examples/01.Basics/Blink/Blink.ino
/private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/hardware -hardware /Users/mr_belogub/Library/Arduino15/packages -tools /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/tools-builder -tools /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/mr_belogub/Library/Arduino15/packages -built-in-libraries /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/libraries -libraries /Users/mr_belogub/Documents/Arduino/libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10819 -build-path /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559 -warnings=none -build-cache /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_cache_275921 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.arduinoOTA.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -verbose /private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/examples/01.Basics/Blink/Blink.ino
Using board 'uno' from platform in folder: /Users/mr_belogub/Library/Arduino15/packages/arduino/hardware/avr/1.8.6
Using core 'arduino' from platform in folder: /Users/mr_belogub/Library/Arduino15/packages/arduino/hardware/avr/1.8.6
Detecting libraries used...
/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/mr_belogub/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I/Users/mr_belogub/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/standard /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/sketch/Blink.ino.cpp -o /dev/null
Generating function prototypes...
/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/mr_belogub/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I/Users/mr_belogub/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/standard /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/sketch/Blink.ino.cpp -o /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/preproc/ctags_target_for_gcc_minus_e.cpp
/private/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/AppTranslocation/9AA61328-BD81-4800-BA6D-7F5DD6005876/d/Arduino.app/Contents/Java/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/mr_belogub/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I/Users/mr_belogub/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/standard /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/sketch/Blink.ino.cpp -o /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/sketch/Blink.ino.cpp.o
Compiling libraries...
Compiling core...
Using precompiled core: /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_cache_275921/core/core_arduino_avr_uno_7dc84736bec69d7a3f526b3465643c6f.a
Linking everything together...
/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.elf /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/sketch/Blink.ino.cpp.o /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/../arduino_cache_275921/core/core_arduino_avr_uno_7dc84736bec69d7a3f526b3465643c6f.a -L/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559 -lm
/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.elf /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.eep
/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -R .eeprom /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.elf /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex
/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-size -A /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.elf
Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -P/dev/cu.usbmodem1101 -b115200 -D -Uflash:w:/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex:i

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/mr_belogub/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/Users/mr_belogub/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbmodem1101
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "/var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex"
avrdude: writing flash (924 bytes):

Writing | ################################################## | 100% 0.13s

avrdude: 924 bytes of flash written
avrdude: verifying flash memory against /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex:
avrdude: load data flash data from input file /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex:
avrdude: input file /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex contains 924 bytes
avrdude: reading on-chip flash data:

An error occurred while uploading the sketch
Reading | ################################################## | 100% 0.13s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0002
         0x5d != 0x5c
avrdude: verification error; content mismatch

avrdude done.  Thank you.

@jsotola I thing it strange coz it have not only code and output but more additional info, but ok, i removed and paste like text

if you have additional info that cannot be added any other way than a picture, then it is ok to add a picture

Are you sure the upload was successful? Did you really click "Upload", and not "Check"? I doubt that, because the old sketch still runs, and there can only be one sketch on an Arduino. You might want to repeat the upload and [edit] your question to show us the resulting log of the upload.

@thebusybee yeah, I'm sure, in question was a screenshots but jsotola ask me to remove it.
Now I back screenshots, is it that you ask?

Since I don't hat IDE 2, I cannot say for sure, but I'd expect a preference to show verbose compiler and upload logs. Please enable that and copy the log as text into your question. A popup message is no log. -- Do you have more than one Arduino? If so, are both connected?

@thebusybee I again updated question, added more info in the end

OK, now we see: "avrdude: verification error". The upload was not successful. The next step is to look for similar questions here on SE/Arduino. Please add your findings to the question and tell us why they don't help you.

So, my solution is: burn new bootloader
I bought:
USBASP ISP-AVR V2 (Programmer) - 139 UAH / 3.65 USD
10pin to 6pin connector - 22 UAH / 0.58 USD
(cable was with programmer)

I connect programmer to cable with 10pin female, other 10pin female to 10pin/6pin connector, connector to 6 alone pins on Arduino, Arduino to PC
Install drivers, via IDE choose Tools->Burn Bootloader
And voilà!

It looks like your upload failed:
avrdude: verifying flash memory against /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex:
avrdude: load data flash data from input file /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex:
avrdude: input file /var/folders/g4/0ddwtmhx3y97b4nm8m2ns88c0000gn/T/arduino_build_275559/Blink.ino.hex contains 924 bytes
avrdude: reading on-chip flash data:

An error occurred while uploading the sketch
Reading | ################################################## | 100% 0.13s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0002
         0x5d != 0x5c
avrdude: verification error; content mismatch

This was possibly related to your first sketch outputting to serial constantly. In future I suggest building in a delay before sending data constantly to serial (eg. delay(500)).
Burning a new bootloader removed the problem sketch.
Instead you could have held down the Reset button until the uploading started, and then released it. That would stop the original sketch from running.

authors: Сергей Белогуб


text:
Shared memory space for locally defined buffers?
Within a class I have a method that is using a basic char buffer to print some data, something like
char buffer[64];
sprintf(buffer, "%s: some text: %u, %u, %u %u", string_var, u_var1, u_var2, u_var3, u_var4);
Serial.println(buffer);

All variables are defined locally to that method within the class.
For the moment I have commented out the Serial.println(buffer), as it is part of precompiler debugging section. I know that this buffer is not being printed from this location. The buffer is still being loaded with data but is NOT being printed.
In my main code I have another function using a similar format, but the buffer has a different name.
char json_buffer[256];
Serial.println(json_buffer);

again all defined locally, NOT globally.
Now this serial print line is printing the contents of the first char buffer[64], UNLESS I create it with a null termination from the off, like:
char json_buffer[256] ={"\n"};

Why is this happening? is it a memory leak? buffer overflow? I have tried increasing the size of each buffer, for example the first buffer I have tried with 512 characters size, and the 2nd with 512 also, but no matter what I try the contents of the first buffer are being printed when I print the 2nd one.
Just looking for an explanation and a robust way of preventing this. Thanks!
Full code is at:
https://github.com/practable/refrigeration/tree/dev/fw/refrigerationFirmware
But is a fairly extensive program

Why would you want to print a non-initialized buffer?

Perhaps if you post all of your code, and not just a few snippets.

@EdgarBonet If I sprintf the content I want to be in that buffer, it also prints out the contents of the first buffer infront of the string I actually wanted to be in there, I eliminated that extra step during debugging and found that the unexpected behaviour was still present.

@NickGammon The entire code is 7 pages long, I have posted the excerpt I feel is relevent to this issue. The entire program can be found at https://github.com/practable/refrigeration/tree/dev/fw/refrigerationFirmware
I will edit the question to contain this.

If your code is a bit too long, post instead a Minimal, Reproducible Example showing the problem.

From your linked code this doesn't look valid to me:
sprintf(json_buffer, "%s%s", json_buffer, json_footer);

It looks like you are trying to append json_footer to json_buffer, however the sprintf will start writing to the start of json_buffer, discarding what is already there. I suggest you use strcat instead.
You are doing that a lot, and there is a possibility of a race condition, where, in the process of writing to json_buffer in that invalid way, the sprintf gets out of control and writes much more than it should.

Just as a complement to Nick Gammon's answer: if you want to build the
JSON string using sprintf(), you should keep track of the current
position of the end of the string (the \0 that terminates it): that's
where you should write the next bit, thus that's the pointer you will
provide to sprintf().
Also, you may want to use snprintf() instead, just to make sure you
never overflow your buffer.
Here is an example of building a string by multiple calls to
snprintf(), while keeping track of the current writing position:
char *build_json() {
    static char buffer[620];
    char *end = buffer + sizeof buffer;  // end of buffer
    char *p = buffer;                    // current writing position

    p += snprintf(p, end-p, "{\n");
    p += snprintf(p, end-p, "  \"timestamp\": %d,\n", 1704391201);
    p += snprintf(p, end-p, "  \"valves\": {\n");
    p += snprintf(p, end-p, "    \"V1\": %d,\n", rand() % 2);
    p += snprintf(p, end-p, "    \"V2\": %d\n", rand() % 2);
    p += snprintf(p, end-p, "  },\n");
    p += snprintf(p, end-p, "  \"relays\": {\n");
    p += snprintf(p, end-p, "    \"foo\": %d,\n", rand() % 2);
    p += snprintf(p, end-p, "    \"bar\": %d\n", rand() % 2);
    p += snprintf(p, end-p, "  }\n");
    p += snprintf(p, end-p, "}\n");
    return buffer;
}

Automatic variables live on the stack for the duration of the block in which they were created - probably the whole of each of those functions. They are not automatically initialized, but merely considered to be in use for the durations of execution of each function.
So the likely answer is that buffer and json_buffer overlap, at least to some degree. In that case, since you didn't initialize 'json_buffer', whatever will be printed from it is whatever data was previously left in the memory area it now occupies. We can't see your code, to say definitively, but since this scenario can describe exactly what your are seeing, I'd say it is highly likely the right explanation.

Just looking for an explanation and a robust way of preventing this.

Easy, peasy: Don't use the contents of uninitialized variables; always initialize them before use.

For the not-yet-initiated the terms might be not that clear.

"To initialize" generally means to write a value into a variable by some means.
"To use" generally means to read from the variable.

The programming language here is C++, which roughly works like this:

A non-static (dynamic) variable local to a function or method is not initialized without an explicit initialization or assignment:
/* ... */ {
    int not_initialized;
    int initialized = 23;
    int written_to; // here uninitialized
    written_to = 42; // now "initialized"
}

A static variable without explicit initialization is default-initialized:
static int default_initialized; // = 0; by the standard's specification

This is independent of the scope of the variable. It can live inside any function or method, or outside at unit level.
A global variable without explicit initialization is default-initialized:
// outside any function or method
int default_initialized; // = 0; by the standard's specification

With this in mind, it makes no sense to initialize dynamic variables and to write into them (what some consider as "to use") without an intermediate usage (reading it). Some compilers can even warn about that code smell:
/* ... */ {
    int initialized = 0;
    // other code without access to "initialized"
    initialized = 2024; // second write
                        // Strange, why not initialize it directly?
                        // Or did the programmer forget something in between?
}

If your compiler optimizes well, it might remove the initialization.

I was seeing the same behaviour when I was initialising the json_buffer variable by sprintf'ing some data into it, the unexpected string from the other buffer was being printed out ahead of the new data

@ImogenWren Please edit your question and provide a minimal, complete and reproducible example of the issue. I will not wade through your big source on some external web site. You can start by removing parts that are not relevant, until just about 10 to 20 lines of code are left.

source: Stack Exchange

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

sort: votes


text:
LED control with a string variable
I would like to control three LEDs with a string variable using an Arduino Mega.
I have connected the three LEDs to pins 10, 11 and 12 of the Arduino.
If my string equals Red, the red LED should turn on. If my string equals Yellow, the yellow LED should turn on. If my string equals Green, the green LED should turn on.
I wrote the following program, and I expect the following: When I type Red, I expect the Red LED to turn on, and so on for the others. But no LED turns on.
You can check the following video: https://www.youtube.com/watch?v=MAnAc_t0OrM&t=1583s
int redPin=10, yellowPin=11, greenPin=12;

String my_Color;
String msg1="Which LED do you want to turn ON?";
String msg2="Red, Yellow or Green?";
String msg3="You chose LED:";

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  Serial.println(msg1);
  Serial.println(msg2);
  while(Serial.available()==0) {}
  my_Color=Serial.readString();
  Serial.print(msg3 );
  Serial.println(my_Color);
  Serial.println('Red', BIN);
  Serial.println('my_Color',BIN);
  if(my_Color == "Red") {
    Serial.print("Red True");
    digitalWrite(redPin,HIGH);
    digitalWrite(yellowPin,LOW);
    digitalWrite(greenPin,LOW);
  }
  if(my_Color=="Yellow") {
    digitalWrite(redPin,LOW);
    digitalWrite(yellowPin,HIGH);
    digitalWrite(greenPin,LOW);
  }
  if(my_Color=="Green") {
    digitalWrite(redPin,LOW);
    digitalWrite(yellowPin,LOW);
    digitalWrite(greenPin,HIGH);
  }
}

Could anyone check the sketch and correct me?

This question originated on electronics.stackexchange.com, copying my answer from there: There are three main areas where your system may be failing: the LEDs, the string input, and the logic evaluations. Right now it's a black box - you enter some input, and you don't see an output. But you have no idea where the system is failing between those two points. You should first narrow down to find which one the problem is. This is very good practice for learning how to debug systems in general.
Start with the string input. After you read in the string from Serial, print it back out. Verify that it matches what you entered. (I expect this to be the problem. Like I said in my comment, your string is probably being read in as "Red\r \n ". Print the string twice, and if it prints "Red" twice with a line break in between, than that is your problem. You need to run my_Color.trim() to fix that.)
Then, check the logic evaluations. Add a Serial.print() command with some string in it after each if evaluation. If your program prints out the string after you enter a valid LED color, than you know that your code is executing correctly. If not, there is some difference between the my_color String and the String you are checking it against.
Thereafter, if it is still not working then the problem is with the LEDs. I don't have your circuit so I can't tell you what to debug there.

The program works as it is expected when I used the trim() function. Could you please explain to me why it needs the trim() function in this case ?

@learndesign: In the description of the video you linked to, there is a big warning written in all caps: “GUYS MAKE SURE YOUR SERIAL MONITOR IS SET TO 'NO LINE ENDING'!!!”. Does that ring a bell?

@learndesign there are certain special characters associated with the String data type. Two such characters are "\n" and "\r". When the '' and 'r' or 'n' are next to each other in a string, they actually correspond to a line break (cursor moves down a line) and a carriage return (cursor moves all the way to the left of the current line). For a lot of serial monitors, when you enter a string, it automatically appends "\r\n" onto the end of the string, possibly with whitespace as well. Since "Red \r\n" != "Red", your if statements were never triggering. The trim() function removes that for you.

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


text:
Arduino interrupt for serial data on digital pin, that is too large for the serial buffer
I am using an Arduino Nano in combination with a NEO 6m GPS module. The GPS module is sending data, consisting of a few hundred chars, every second. Since I am communicating with my PC over the integrated serial RX and TX pins of the Arduino, I cannot use them for the sensor without being able to display anything sent from the Arduino on my PC. I am using the SoftwareSerial library to mark two digital pins as my new RX and TX to communicate with the GPS sensor.
The problem is that I have to actively listen to the RX pin at the moment the data is incoming, because otherwise data will be lost, since it's too much to be placed into the serial buffer completely. But on the other hand: I don't want to actively wait for the digital pin to receive data, so I would be in time to read it. It would be best handled with an interrupt every time the digital RX pin starts to receive data. But I read that SoftwareSerial is not compatible with this kind of interrupt, since it has a built-in interrupt itself everytime new data arrives to save it onto the buffer.
This is what I have tried:
#include <SoftwareSerial.h>

// The serial connection to the GPS module
SoftwareSerial ss(4, 3);
String serialString;

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

  //Interrupts when a transmission begin in the RX-Pin is recognized
  attachInterrupt(digitalPinToInterrupt(4), readGpsSerialData, CHANGE);
}

void loop() {
  //processing data that takes too long to check frequently enough if data is being transmitted at the moment
  Serial.println("In Loop");
  delay(1000);
}

//Read all the incomming data once transmission started
void readGpsSerialData() {
  String serialString = "";
  while (ss.available() > 0) {
    char serialChar = ss.read();
    serialString += serialChar;
  }
  lastGpsString = serialString;
  Serial.print("Data from Interrupt: ");Serial.println(lastGpsString);
}

I think the problem is that my interrupt activates, not just once when the transmission starts, but every time the RX digital value changes (so a lot of times in the transmission). A data RDY value would be nice for this interrupt trigger but the GPS module does not have one.

I guess the delay in loop stands for some other complex code that takes long to execute? I would try to get to a non-blocking coding style, so that you can check for serial data with higher frequency. Without knowing what this complex code is, we cannot advice at that.

Or you could increase the buffer size by editing the SoftwareSerial library. Though I would argue, that this is not a good solution, since it makes your code less portable (you would need to use that modified library everywhere you want to compile the code)

Does it really take longer than 1 second to run your loop code?  Perhaps that should be optimized and then this wouldn't be a problem.

You can use the hardware serial port both for reading from the GPS and for writing to the PC. You will not be able to also read from the PC though.

Thanks, timemage - I'd busted an edit. Corrected here:   Following on to @EdgarBonet's suggestion, you could swap the roles of Serial and SoftwareSerial. Then you'd have one channel dedicated to the PC and the other, faster one, dedicated to the GPS. You'd still need to make your code non-blocking to prevent dropped characters on either channel, and you'd want to service each channel more frequently (just for collecting the input, not necessarily processing it), for the same reason.

@EdgarBonet Interesting aspect, but wouldn't this just cause the data to "pass-trough" from the Arduino RX pin to the USB port, basically bypassing the Arduino completely?

@PMF: No, the PC does not see the data coming to the Arduino's RX. It only sees what comes out of the Arduino's TX, i.e. what you Serial.print().

GPS is a really slow communication, it communicates in 9600bps and data only available once in every second. Any MCU running at much slower than an Arduino Uno running at 16MHz should be able to handle it, with a small rx buffer. If there is a problem, it is because of the user code implementation.
You didn't mention which Arduino board you are using. Arduino's implementation of attachInterrupt() function has quite limited digital pins that you could attach an interrupt to it. See the documentation. Even it can handle interrupt on pin4, the CHANGE means that it would be triggered in every single bit change, which is really unnecessary.
Secondly, there are a few "do and don't" for setting up an interrupt callback function, it all come down to "keep it short and simple", to have a while..loop and Serial print within an interrupt callback is one of those things that should be avoid, for that I suggest to read Nick Gammon's Interrupts.
There is a misunderstanding of "actively listen" of RX. The Serial.available() is a function that behave like an onEvent() callback internally, so it is non-block by simply doing a checking with if(Serial.available(), it will only blocking by putting it in a while loop. Furthermore, Serial.available() only turn from 0 to 1 when a full byte is received.
I'd suggest to not using interrupt, and make the following changes. This should provide plenty of time for handling other communication while receive GPS data stream.
#include <SoftwareSerial.h>

// The serial connection to the GPS module
SoftwareSerial ss(4, 3);

void setup() {
  Serial.begin(9600);   // change baudrate to 115200 to improve performance
  ss.begin(9600);
}

void loop() {
  String serialString = "";

  // this code block only execute when a character is fully received
  if (ss.available() > 0) {
    char serialChar = ss.read();
    serialString += serialChar;
    // only print the string when the `\n` is received (i.e. full GPS string)
    if (serialChar == '\n') {
      Serial.println(serialString);
    }
  }

  // there are plenty of time to handle the rest of the communication with the PC here
}

There are 2 aspects here.
The first is that the continuous flow of NMEA data is not THAT important. When you are ready to read, you can discard any pending input, ie flush the buffer, and start reading from the next $ onwards.
You can also limit the number of NMEA verbs displayed (there are commands to do that), so that less information is sent to Serial.
The second aspect is that most GPS modules send data at 9,600 bauds, which is quite slow, and every second (that's what the PPS pin is for). So you read data, store the lines in a buffer, and parse the buffer. Rinse and repeat. Even an Arduino Uno should be good enough. And as I said, if there's too much data, discard and start reading again.

To avoid a buffer overflow, I would recommend increasing the communication speed on the PC side. You can easily set Serial.begin(115200); or even higher, as the comment in your code suggests. The PC and also the Arduino work just fine with that. That will make sure you can send out all the input from the GPS receiver much faster than new data comes in, so you shouldn't loose anything. Just make sure that you use the same value on the Arduino and the PC.


text:
Construct Strings with UTF-8 characters from data
I am printing some ASCII art to the Serial monitor from Arduino UNO, with some success. However, using string literals uses more memory than I would like. I wanted to try constructing the strings/chars from other data types so that I can manipulate the data and print the ascii art without storing it in string literals.
However, I have found that there seems to be no way to print UTF-8 characters other than from a string literal. Is this the case? Is there no way to construct a string containing characters that have numeric values that are too big for char?
As an example, to print "▓" works fine as a String literal but, it seams, no other way.
Serial.println("▓");                         // works fine
Serial.println('▓');                         // char can't store value
Serial.println(String('▓'));                 // char can't store value
Serial.println(0x2593);                      // just prints the numeric value
Serial.println((char)0x2593);                // char can't store value
Serial.println((wchar_t)0x2593);             // doesn't work
Serial.println(String(0x2593));              // doesn't work
Serial.println(String((wchar_t)0x2593));     // doesn't work

Similarily with write() instead of print():
Serial.write("▓");                  // Works fine
Serial.write('▓');                  // char can't store value
Serial.write(0x2593);               // just prints the numeric value
Serial.write((char)0x2593);         // char can't store value
Serial.write((wchar_t)0x2593);      // doesn't work

I also tried deriving new component strings from a string literal using substring() and charAt(). Neither works. Both produce � in the output.
String((char)65) constructs the string "A" from the numeric value 65. Neither String((char)0x2593) nor String((wchar_t)0x2593) produce the desired results. Is there a way to construct a string from numeric values that are too big to store in 'char'?

try Serial.println("\u2593");

I would try printing  byte arrays that contain the UTF-8 serialisation, not the numeric code point.  For example \xe2 ,\x96, \x93 instead of \u2593

As you have noticed, Serial doesn't know how to deal with wchar_t.
If you are building your strings algorithmically from Unicode code
points, you need to convert those code points to UTF-8 for printing. I
am not aware of any built-in function that does that. You may want to
search the library manager for a library providing this functionality.
Alternatively, you could write the conversion yourself: it is not that
complicated. For example, here is a function that converts any code
point from the BMP (i.e. < 216) to an UTF-8 string:
// A BMP multi-byte character, with terminating NUL byte.
struct Mbchar {
    char utf8[4];
};

// Convert a wide character to UTF-8. Only works within the BMP.
Mbchar wchar_to_utf8(wchar_t c) {
    Mbchar result;
    if (c < 128) {               // 0xxx.xxxx
        result.utf8[0] = c;
        result.utf8[1] = 0;
    } else if (c < 2048) {       // 110x.xxxx 10xx.xxxx
        result.utf8[0] = 0xc0 | (c >> 6);
        result.utf8[1] = 0x80 | (c & 0x3f);
        result.utf8[2] = 0;
    } else {                     // 1110.xxxx 10xx.xxxx 10xx.xxxx
        result.utf8[0] = 0xe0 | (c >> 12);
        result.utf8[1] = 0x80 | (c >> 6 & 0x3f);
        result.utf8[2] = 0x80 | (c & 0x3f);
        result.utf8[3] = 0;
    }
    return result;
}

Keep in mind that, depending on the Arduino you are using, wchar_t may
not support characters outside the BMP. The AVR-based Arduinos
definitively don't.
This function can be used like this:
Serial.println(wchar_to_utf8(0x2593).utf8);  // prints “▓”

Might be worth adding that their '▓' usage will not produce a wchar_t type, it'll just produce some useless char value. They'd need L'▓' which they should be able to use in conjunction with your code in Serial.println(wchar_to_utf8(L'▓').utf8);


text:
Smoke coming out of Arduino Uno R4 Minima
My Arduino Uno R4 Minima started smoking after connecting to a computer. I disconnected it and visually checked it and I saw this bubble as shown on this photo.

Can I recover my Uno from this to still use it or do I have to throw it away?

Was anything else connected?

Can the computer still talk to the board? If not, then it's probably dead. You could repair it by replacing the IC, if you are handy with a hot air gun. If not, I still wouldn't throw it away, it might be useful for parts.

did you place the board on top of something metallic?

did you power the board with an external power supply connected  to the barrel jack?

The marked IC is burnt. You should complain to the seller and claim warranty. if it is still within the warranty period. If you are very skilled at soldering. You can try to replace the IC.

If the OP damaged it through misuse then why would the seller be liable?

That's  the buck-converter that connects to the external power supply.
The board should still work when powered by the USB cable.
Remove R11 to isolate the blown circuit if you like.
https://docs.arduino.cc/resources/schematics/ABX00080-schematics.pdf


text:
Arduino uno r3 and wt901c ttl sensor to make compass and inclinometer
Currently I'm only able to read the raw data values from the wt901c ttl sensor.
How to convert the raw data to make a tilt compensated compass and inclinometer?

I'd suggest you concentrate on a single one of it's outputs and learn to convert that into something you consider "useable" - probably a conversion from the binary output into more familiar physical units. Each output will be one of a duple or a triple, so once you have converted one axis of one of the physical, you can easily convert the other 2. Then move on to another of the device's physical measurements and do the same; learn to convert one axis, then apply what you learned to the other axes.

I looked and did not find a opensource project for an Arduino and wt901c. That leaves reading the wt901c specifications and coding up a solution for your self. 2. Every magnetometer I have seen requires calibration. Depending on what you need it can be short and inaccurate or math / physically-intensive and accurate. 3. Using a gyroscope meas you accept dead reckoning errors and know how to deal w/them. 4. Most accelerometers can be used w/little calibration. 5. The accurate relation between orthogonal sensors is more important then calibrating them to match a particular unit of measure.

I took the liberty and added a real question to your post ... if you disagree with the change, then please edit your post ... your original question, do anyone know?, was a useless yes/no question


text:
Disable verification of certification SSL A7670SA
I have the code below and it doesn't work with my URL. I receive a

715(Handshake Failed)

This code below works normally, but with my API it doesn't work.
I'm using a A7670SA with Arduino Mega 2560.
My API is on Heroku and uses an Automated Certificate Management by Heroku, that uses the Let's Encrypt.
String sendATCommand(String command, String expectedResponse = "", unsigned long timeout = 5000) {
  Serial1.println(command);
  Serial.println("Command send: " + command);

  unsigned long startTime = millis();

  String response = "";

  while (millis() - startTime < timeout) {
    if (Serial1.available() > 0) {
      char c = Serial1.read();
      response += c;
    }
  }

  response.replace(command, "");

  Serial.println(response);

  delay(500);
  return response;
}

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

  delay(1000);

  Serial1.begin(115200);

  sendATCommand("AT", "OK");

  sendATCommand("AT+CGREG?");
  sendATCommand("AT+CGDCONT=1,\"IP\",\"claro.com.br\"", "OK");

  sendATCommand("AT+HTTPINIT");  // Iniciar ambiente HTTP

  sendATCommand("AT+HTTPPARA=\"URL\",\"https://httpbin.org/\"");

  sendATCommand("AT+HTTPACTION=0", "OK", 1000);

  sendATCommand("AT+HTTPREAD?");

  sendATCommand("AT+HTTPTERM", "OK");
}

void loop() {}

what is your specific question?


text:
5 Pin button to tell Continuous Servo to run for certain amount of time
I'm working with a 5 pin dome button, trying to get that to tell the motor to spin for a certain amount of time when it is pressed then stop until it is pressed again, where it would then run for the same amount of time. It's my first time doing anything with arduinos, wiring and coding. I have gotten the button to light up but I have no clue how to have it make the servo motor run once it's pressed. Can anyone advise on how to wire all of this up, along with some advice on the code? It's a school project, would be extremely helpful since my professor doesn't really have any interest in helping here. Thanks!
Using a red dome button (5 pin from Sparkfun.com), Arduino R3, continuous servo motor, and a mini breadboard

Hi, your question is currently not very specific. Have you searched the web foe something like "arduino read button tutorial" or "arduino servo tutorial" to learn how each part of your project can work individually? If yes, please explain where exactly you had problems understanding which tutorial. Also: please also provide a link to the buttons sparkfun product page, so that we can be sure we are talking about the same product

the button does not control the servo, the Arduino controls the servo ... the button only tells the Arduino that you pressed it ... it is the program that resoonds to the button press in some desired way


text:
ATtiny85 wireless transmitter using NRF24L01
I have an ATtiny85 microcontroller wireless transmitter to an Arduino Nano  receiver using the wireless module NRF24L01.
These are the sketches and wiring for both and the result is nothing in the serial monitor of the receiver (Nano board).
I'm using the Arduino Uno as an ISP programmer to upload the sketch to the ATtiny85 MCU.
I have updated the code and now the Nano (receiver) keeps disconnecting and connecting again and again... with the message "failed to connect!" in the serial monitor and there is no output for the sizeof(text).
Code:
Receiver Nano:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9,10);

const byte address[6] = "00001";

void setup() {
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.startListening();
  Serial.begin(9600);
  Serial.println("Started!");
}

void loop() {

  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(sizeof(text));
    Serial.println(text);
  } else {
    Serial.println("Failed To Connect!!");
  }
}

ATtiny85 transmitter code:
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//create an RF24 object
RF24 radio(3, 4);  // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";

void setup() {
  radio.begin();

  //set the address
  radio.openWritingPipe(address);

  // Set module as transmitter
  radio.stopListening();
}

void loop() {
  // Send message to receiver
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));

  delay(1000);
}

Wiring:
**Attiny85 ====>> nrf24l01**

D3/PB3   =====> CE

D4/PB4   =====> CNS

D2/PB2   =====> SCK

D1/PB1   =====> MOSI

D0/PB0   =====> MISO

VCC      =====> 3V BATTERY

GND      =====> 3V BATTERY GND

**Arduino nano ===> nrf24l01**

D9      =====>   CE

D10     =====>   CNS

D11     =====>   MOSI

D12     =====>   MISO

D13     =====>   SCK

VCC     =====>   3V3

GND     =====>   GND

do basic debugging ... serial.print a message,  like "start",  inside setup() ... does it show on serial monitor?

in loop() print the value of sizeof(text)

connecting again with the message (faild to connect!) in the serial monitor ... your post says that nothing is printed in the serial monitor

this site is not a forum ... please  do not add info in comments


text:
Why does the ADC report 0 in this sketch?
This sketch always reports 0 for the ADC reading.
I think this is going to turn out to be something silly, but I cannot find the source. I've reviewed the sketch ADC lines carefully and they seem right, so maybe the problem with the physical connections or how I'm trying to report the ADC output or the order in which tasks are executed.  The capture_FID() etc functions are based on the example in Section 9.2.4 of Norman Dunbar's book, Arduino Software Internals.  The only difference is the position of ADCSRA |= (1 << ADEN); which I moved to right after the power up based on this answer.  That did not make a difference.

void init();
void setup() {
  Serial.begin(115200);
  capture_FID();
}
void loop() {
}

void capture_FID() {

  volatile uint16_t ADC_output = 0;  // max value 65536

  config_ADC();
  start_ADC();
  for (int i = 1; i <= 5; i++) {
    Serial.print("\ti = ");
    Serial.print(i);
    Serial.print(" value = ");
    Serial.println(ADC_output);
  }
  stop_ADC();
}

// ADC Configuration
void config_ADC() {
  Serial.println("Configuring the ADC...");
  PRR &= ~(1 << PRADC);                                            // power up the ADC
  ADCSRA |= (1 << ADEN);                                           // enable ADC
  ADCSRA = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);             // slow the clock
  ADMUX = (0 << REFS1) | (1 << REFS0);                             // use 5 V internal reference
  ADMUX &= ~(1 << ADLAR);                                          // right-align the 10 bit output in 2 byte/16 bit space
  ADMUX |= (0 << MUX3) | (0 << MUX2) | (0 << MUX1) | (0 << MUX0);  // multiplexer input; use A0
  DIDR0 |= (1 << ADC0D);                                           // disable digital input to pin A0
  ADCSRA |= (1 << ADIE);                                           // set interupt to notify data is available for further use
  ADCSRA |= (1 << ADATE);                                          // auto-trigger on
  ADCSRB = 0;                                                      // free-running mode
  delay(20);                                                       // wait for voltage to settle
}

// Start the ADC = start acquiring data
void start_ADC() {
  Serial.println("Starting the ADC...");
  ADCSRA |= (1 << ADSC);
}

// Stop the ADC = stop acquiring data
void stop_ADC() {
  Serial.println("Stopping the ADC...");
  ADCSRA |= (0 << ADSC);
}

ISR(ADC_vect) {
  volatile uint16_t ADC_output;  // max value 32767
  ADC_output = ADCW;
}

Hardware:

Arduino R3
0.1 uF cap across GND and AREF
PicoScope function generator is supplying a 500 Hz, 500 mV, 1 V offset signal; the negative output is wired to GND on the Arduino, the positive output is wired to A0.
A sketch that doesn't involve free-running and auto-triggering that I found on Nick Gammon's site works fine, so the board appears to be fine.  This also implies the hardware connections and scope settings are fine.

You have two different variables named ADC_output:

one which is local to capture_FID(), and is always zero (it is never
assigned another value)
one local to ISR(ADC_vect), which is set but never used.

You should use only one such variable.
There are also a handful more problems in this code:

capture_FID() prints multiple times the same result, without
checking that new data has arrived
access to ADC_output outside the ISR is not protected in a critical
section
the ADC register is called ADC, not ADCW.
ADCSRA |= (0 << ADSC) is a no-op
there is no point in declaring init()
probably more, I did not read it thoroughly…

Ah, so my limited experience with C is the problem. Let me poke around a bit.  Thank you.


text:
Adafruit Datalogger and Bluefruit LE issues
I'm having issues using the Adafruit Bluefruit LE shield at the same time as the Adafruit Datalogger shield. I can use either shield independently without issue. When I stack the two, I can talk with the SD card and the RTC on the datalogger, however, the Bluefruit fails all communication.
The Bluefruit is powered and I can connect to it via Bluetooth, however, it does not communicate with the Arduino at all.
I'm assuming there is a conflict over SPI, but I can't figure out the root cause. The SD chip select is 10. The Bluefruit chip select is 8. I have put 100 kΩ pullup resistors on both chip select pins, but that did not resolve the issue.
I've tried shield specific example sketches to remove coding / memory issues as a cause. These sketches work great until the shields are stacked. Once stacked, the Bluefruit loses all communication with the Arduino.


text:
How does the serial monitor know where a string terminates when we use Serial.print instead of Serial.println?
EDIT: I thought I had to parse the things coming into the program but the speed it is running at makes it indistinguishable to the eye that the word is being printed piecewise.
I am trying to create a serial monitor in rust using the serialport crate. I am using the following modification of blink code on the uno to test it:
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.print("HIGH");
  delay(700);
  digitalWrite(LED_BUILTIN, LOW);
  Serial.print("LOW");
  delay(700);
}

with println, I am thinking of just concatenating the received buffers and printing on receiving nl or cr. The serial monitor is doing a pretty good job with how it is able to discern a string if a has ended without NL or CR on running the code. How is it doing that? Here is my code right now:
use std::time::Duration;
use serialport;

fn main() {
    let open_port_config = serialport::new("/dev/cu.usbmodem1201", 9600).timeout(Duration::from_secs(10));
    let open_port_result = open_port_config.open();

    let mut port = match open_port_result {
                    Ok(res) => res,
                    Err(_) => panic!("Couldn't open the port")
                };

    println!("Data bits: {}", port.data_bits().unwrap());
    println!("Flow control: {}", port.flow_control().unwrap());
    println!("Parity: {}", port.parity().unwrap());
    println!("Stop bits: {}", port.stop_bits().unwrap());

    loop {
        let mut serial_buf: [u8; 8] = [0; 8];
        port.read(&mut serial_buf[..]).expect("Found No data");
        let output = String::from_utf8(serial_buf.to_vec()).unwrap();
        println!("{:?},{:?}: {}", serial_buf, output.trim_matches('\0'), output);
    }
}

You could experiment with delays shorter than 700 ms, and see at what point the serial monitor starts concatenating messages together.

@EdgarBonet I am not really able to clearly make out if messages are being concatenated as I lower the delay. I think I caught a stutter here and there but it looks as though it is printing the entire word / string at one go.

It is unclear to me, what you mean with discerning strings. The Serial Monitor just reads the byte data from the serial port and outputs it in a textbox. It doesn't know of individual strings, just bytes. What exactly is your problem with your current code?

please copy the content of serial monitor and paste it into your question ... no screenshots

the serial monitor should not be adding characters that are not received ... it is not a parser, so it has no knowledge of human meaning of received data ... the answer to your title question is it does not know

The answer is: It does not know. Or, if you want to look at it in a different way: Timing and chance.
You simply never stumbled upon the case that you read the serial buffer on the PC side in the exact moment when the Arduino is in the middle of writing to it. That special case would be where you read and empty the buffer and output "HI" (followed by newline, because you add it in your code) on your serial monitor; then, during the next loop in your rust code, the remaining characters would be read, outputting "GH".
I'd say that you've been lucky that it always worked so far.
The better way would be to always use println on the Arduinos side; and on the PCs side: the rust function to "read until newline" from a serial connection (I'm guessing it exists because it does exist in other standard libraries; I never worked with rust before). This way, you'll have in-band signalling for "the next data block begins HERE".

If you are building a serial monitor, you are not in control of how it will be used. Some users will fail to systematically add line terminators.


text:
Problem converting a sketch from SPIFFS to LittleFS - no matching function for call error
I'm playing with a tutorial from this DroneBot Workshop YouTube (excellent video presentation by the way on WiFi manager for newbies). I am working with a NodeMCU ESP8266.
The example code was written for SPIFFS. If I use the LittleFS library instead, and whether I define SPIFFS to LittleFS at the start or manually replace all references to SPIFFS with LittleFS, this line will not compile:
if (LittleFS.begin(false) || LittleFS.begin(true))

It gives this error message:
no matching function for call to 'fs::FS::begin(bool)'

Any suggestions as to what I'm missing or need to change?
His original example code which won't compile is below. I'm guessing I'm missing something simple but I'mnot sure what.
I probably should have added that I have commented out the include SPIFFS, added include LittleFS.H
I still have FS.h included in libraries and not sure if that is contributing to the issue. Is there an equivalent replacement for FS.h that comes about with LitteFS that I should be including?
/*
  WiFiManager with saved textboxes Demo
  wfm-text-save-demo.ino
  Saves data in JSON file on ESP32
  Uses SPIFFS

  DroneBot Workshop 2022
  https://dronebotworkshop.com

  Functions based upon sketch by Brian Lough
  https://github.com/witnessmenow/ESP32-WiFi-Manager-Examples
*/

#define ESP_DRD_USE_SPIFFS true

// Include Libraries

// WiFi Library
#include <WiFi.h>
// File System Library
#include <FS.h>
// SPI Flash Syetem Library
#include <SPIFFS.h>
// WiFiManager Library
#include <WiFiManager.h>
// Arduino JSON library
#include <ArduinoJson.h>

// JSON configuration file
#define JSON_CONFIG_FILE "/test_config.json"

// Flag for saving data
bool shouldSaveConfig = false;

// Variables to hold data from custom textboxes
char testString[50] = "test value";
int testNumber = 1234;

// Define WiFiManager Object
WiFiManager wm;

void saveConfigFile()
// Save Config in JSON format
{
  Serial.println(F("Saving configuration..."));

  // Create a JSON document
  StaticJsonDocument<512> json;
  json["testString"] = testString;
  json["testNumber"] = testNumber;

  // Open config file
  File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w");
  if (!configFile)
  {
    // Error, file did not open
    Serial.println("failed to open config file for writing");
  }

  // Serialize JSON data to write to file
  serializeJsonPretty(json, Serial);
  if (serializeJson(json, configFile) == 0)
  {
    // Error writing file
    Serial.println(F("Failed to write to file"));
  }
  // Close file
  configFile.close();
}

bool loadConfigFile()
// Load existing configuration file
{
  // Uncomment if we need to format filesystem
  // SPIFFS.format();

  // Read configuration from FS json
  Serial.println("Mounting File System...");

  // May need to make it begin(true) first time you are using SPIFFS
  if (SPIFFS.begin(false) || SPIFFS.begin(true))
  {
    Serial.println("mounted file system");
    if (SPIFFS.exists(JSON_CONFIG_FILE))
    {
      // The file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r");
      if (configFile)
      {
        Serial.println("Opened configuration file");
        StaticJsonDocument<512> json;
        DeserializationError error = deserializeJson(json, configFile);
        serializeJsonPretty(json, Serial);
        if (!error)
        {
          Serial.println("Parsing JSON");

          strcpy(testString, json["testString"]);
          testNumber = json["testNumber"].as<int>();

          return true;
        }
        else
        {
          // Error loading JSON data
          Serial.println("Failed to load json config");
        }
      }
    }
  }
  else
  {
    // Error mounting file system
    Serial.println("Failed to mount FS");
  }

  return false;
}

void saveConfigCallback()
// Callback notifying us of the need to save configuration
{
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

void configModeCallback(WiFiManager *myWiFiManager)
// Called when config mode launched
{
  Serial.println("Entered Configuration Mode");

  Serial.print("Config SSID: ");
  Serial.println(myWiFiManager->getConfigPortalSSID());

  Serial.print("Config IP Address: ");
  Serial.println(WiFi.softAPIP());
}

void setup()
{
  // Change to true when testing to force configuration every time we run
  bool forceConfig = false;

  bool spiffsSetup = loadConfigFile();
  if (!spiffsSetup)
  {
    Serial.println(F("Forcing config mode as there is no saved config"));
    forceConfig = true;
  }

  // Explicitly set WiFi mode
  WiFi.mode(WIFI_STA);

  // Setup Serial monitor
  Serial.begin(115200);
  delay(10);

  // Reset settings (only for development)
  wm.resetSettings();

  // Set config save notify callback
  wm.setSaveConfigCallback(saveConfigCallback);

  // Set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
  wm.setAPCallback(configModeCallback);

  // Custom elements

  // Text box (String) - 50 characters maximum
  WiFiManagerParameter custom_text_box("key_text", "Enter your string here", testString, 50);

  // Need to convert numerical input to string to display the default value.
  char convertedValue[6];
  sprintf(convertedValue, "%d", testNumber);

  // Text box (Number) - 7 characters maximum
  WiFiManagerParameter custom_text_box_num("key_num", "Enter your number here", convertedValue, 7);

  // Add all defined parameters
  wm.addParameter(&custom_text_box);
  wm.addParameter(&custom_text_box_num);

  if (forceConfig)
    // Run if we need a configuration
  {
    if (!wm.startConfigPortal("NEWTEST_AP", "password"))
    {
      Serial.println("failed to connect and hit timeout");
      delay(3000);
      //reset and try again, or maybe put it to deep sleep
      ESP.restart();
      delay(5000);
    }
  }
  else
  {
    if (!wm.autoConnect("NEWTEST_AP", "password"))
    {
      Serial.println("failed to connect and hit timeout");
      delay(3000);
      // if we still have not connected restart and try all over again
      ESP.restart();
      delay(5000);
    }
  }

  // If we get here, we are connected to the WiFi

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

  // Lets deal with the user config values

  // Copy the string value
  strncpy(testString, custom_text_box.getValue(), sizeof(testString));
  Serial.print("testString: ");
  Serial.println(testString);

  //Convert the number value
  testNumber = atoi(custom_text_box_num.getValue());
  Serial.print("testNumber: ");
  Serial.println(testNumber);

  // Save the custom parameters to FS
  if (shouldSaveConfig)
  {
    saveConfigFile();
  }
}

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

have you looked at LittleFS example code?

The LittleFS library shows the begin function with some other parameters. That is probably, why the compiler complains about not knowing that function. There is no begin method in LittleFS with just one boolean as parameter. Please try calling the begin function like in the libraries examples

I encountered the same issue. I made the following changes to the code.

Commented out this line:

  //x  if (SPIFFS.begin(false) || SPIFFS.begin(true))

Replaced the commented out line with this line:

  SPIFFS.begin();

Then commented out the "else" portion of the code in that block:

  //x  else
  //x  {
  //x    // Error mounting file system
  //x    Serial.println("Failed to mount FS");
  //x  }

So basically you eliminate the true/false test and always execute the code, not really sure why you would not want execute the code anyway.
Note:
I also used LittleFS to make it simple so I used the following include and define:
#include "LittleFS"
#define SPIFFS LittleFS

One final thing, I ran this on an ESP8266 mini D1 clone so I also changed the
#include <WiFi.h>

To
#include <ESP8266WiFi.h>


text:
ESP32: nRF24L01 receives no data
Using two, nRF24L01 with two, ESP32 DEVKIT V1. Trying to setup RF24 Library example, "Getting Started". Able to transmit on both nodes, however, there is no payload received when switching to receive while transmitting on both nodes.
SPI pins used:
MOSI = GPIO23,
MISO = GPIO19,
SCK  = GPIO18,
CE   = GPIO21,
CSN  = GPIO5,
IRQ  = No connection,
Vcc  = 5.0 V using piggyback adapter with 3.3 V regulator,
GND  = Ground.
Are the SPI pins used correctly for the ESP32 DEVKIT V1?
<script src="https://gist.github.com/Tech500/b57d4d356baaec48adc41196117c02aa.js"></script>
nRF24L01 Project for use with ESP32 DEVKIT V1
Details.txt
//Getting Started exammple:  Details Radio_0 and Radio_1.

RF24/examples/GettingStarted
Which radio is this? Enter '0' or '1'. Defaults to '0'
radioNumber = 0
*** PRESS 'T' to begin transmitting to the other node
SPI Frequency       = 10 Mhz
Channel         = 76 (~ 2476 MHz)
Model           = nRF24L01+
RF Data Rate        = 1 MBPS
RF Power Amplifier  = PA_LOW
RF Low Noise Amplifier  = Enabled
CRC Length      = 16 bits
Address Length      = 5 bytes
Static Payload Length   = 4 bytes
Auto Retry Delay    = 1500 microseconds
Auto Retry Attempts = 15 maximum
Packets lost on
    current channel = 0
Retry attempts made for
    last transmission   = 0
Multicast       = Disabled
Custom ACK Payload  = Disabled
Dynamic Payloads    = Disabled
Auto Acknowledgment = Disabled
Primary Mode        = TX
TX address      = 0x65646f4e31
pipe 0 ( open ) bound   = 0x65646f4e31
pipe 1 ( open ) bound   = 0x65646f4e32
pipe 2 (closed) bound   = 0xc3
pipe 3 (closed) bound   = 0xc4
pipe 4 (closed) bound   = 0xc5
pipe 5 (closed) bound   = 0xc6

-------------------------------------

radioNumber = 1
*** PRESS 'T' to begin transmitting to the other node
SPI Frequency       = 10 Mhz
Channel         = 76 (~ 2476 MHz)
Model           = nRF24L01+
RF Data Rate        = 1 MBPS
RF Power Amplifier  = PA_LOW
RF Low Noise Amplifier  = Enabled
CRC Length      = 16 bits
Address Length      = 5 bytes
Static Payload Length   = 4 bytes
Auto Retry Delay    = 1500 microseconds
Auto Retry Attempts = 15 maximum
Packets lost on
    current channel = 0
Retry attempts made for
    last transmission   = 0
Multicast       = Disabled
Custom ACK Payload  = Disabled
Dynamic Payloads    = Disabled
Auto Acknowledgment = Disabled
Primary Mode        = RX
TX address      = 0x65646f4e32
pipe 0 (closed) bound   = 0x65646f4e32
pipe 1 ( open ) bound   = 0x65646f4e31
pipe 2 (closed) bound   = 0xc3
pipe 3 (closed) bound   = 0xc4
pipe 4 (closed) bound   = 0xc5
pipe 5 (closed) bound   = 0xc6
Radio_0.ino

RF24 Library example "Getting Started":
/*
 * See documentation at https://nRF24.github.io/RF24
 * See License information at root directory of this library
 * Author: Brendan Doherty (2bndy5)
 */

/**
 * A simple example of sending data from 1 nRF24L01 transceiver to another.
 *
 * This example was written to be used on 2 devices acting as "nodes".
 * Use the Serial Monitor to change each node's behavior.
 *
 *  TX Code --Radio 0
 */

/*
  Coded for a ESP32 DEVKIT V1 board type to make use of a pair of
  nRF24L01+ 2.4 GHz. Transceivers
  SPI Pins used MOSI = 23, CE = 21, MSIO = 19, SCK = 18, CSN = 4
  This code is for Radio 0.
  William Lucid
*/

#include <SPI.h>
#include "printf.h"
#include "RF24.h"

#define CE_PIN 21
#define CSN_PIN 5

// instantiate an object for the nRF24L01 transceiver
RF24 radio(CE_PIN, CSN_PIN);

// Let these addresses be used for the pair
uint8_t address[][6] = { "1Node", "2Node" };
// It is very helpful to think of an address as a path instead of as
// an identifying device destination

// to use different addresses on a pair of radios, we need a variable to
// uniquely identify which address this radio will use to transmit
bool radioNumber = 0;  // 0 uses address[0] to transmit, 1 uses address[1] to transmit

// Used to control whether this node is sending or receiving
bool role = true;  // true = TX role, false = RX role

// For this example, we'll be using a payload containing
// a single float number that will be incremented
// on every successful transmission
float payload = 0.0;

void setup() {

  Serial.begin(115200);
  while (!Serial) {
    // some boards need to wait to ensure access to serial over USB
  }

  pinMode(CE_PIN, OUTPUT);
  pinMode(CSN_PIN, OUTPUT);

  // initialize the transceiver on the SPI bus
  if (!radio.begin()) {
    Serial.println(F("radio hardware is not responding!!"));
    while (1) {}  // hold in infinite loop
  }

  //radio.setAutoAck(false);

  // print example's introductory prompt
  Serial.println(F("RF24/examples/GettingStarted"));

  // To set the radioNumber via the Serial monitor on startup
  Serial.println(F("Which radio is this? Enter '0' or '1'. Defaults to '0'"));
  while (!Serial.available()) {
    // wait for user input
  }
  char input = Serial.parseInt();
  radioNumber = input == 1;
  Serial.print(F("radioNumber = "));
  Serial.println((int)radioNumber);

  // role variable is hardcoded to RX behavior, inform the user of this
  Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));

  // Set the PA Level low to try preventing power supply related problems
  // because these examples are likely run with nodes in close proximity to
  // each other.
  radio.setPALevel(RF24_PA_LOW);  // RF24_PA_MAX is default.

  // save on transmission time by setting the radio to only transmit the
  // number of bytes we need to transmit a float
  radio.setPayloadSize(sizeof(payload));  // float datatype occupies 4 bytes

  // set the TX address of the RX node into the TX pipe
  radio.openWritingPipe(address[radioNumber]);  // always uses pipe 0

  // set the RX address of the TX node into a RX pipe
  radio.openReadingPipe(1, address[!radioNumber]);  // using pipe 1

  // additional setup specific to the node's role
  if (role) {
    radio.stopListening();  // put radio in TX mode
  } else {
    radio.startListening();  // put radio in RX mode
  }

  // For debugging info
  printf_begin();  // needed only once for printing details
  // radio.printDetails();       // (smaller) function that prints raw register values
  radio.printPrettyDetails();  // (larger) function that prints human readable data

}  // setup

void loop() {
  if (role) {
    // This device is a TX node

    unsigned long start_timer = micros();               // start the timer
    bool report = radio.write(&payload, sizeof(float)); // transmit & save the report
    unsigned long end_timer = micros();                 // end the timer

    if (report) {
      Serial.print(F("Transmission successful! "));  // payload was delivered
      Serial.print(F("Time to transmit = "));
      Serial.print(end_timer - start_timer);  // print the timer result
      Serial.print(F(" us. Sent: "));
      Serial.println(payload);  // print payload sent
      payload += 0.01;          // increment float payload
    } else {
      Serial.println(F("Transmission failed or timed out"));  // payload was not delivered
    }

    // to make this example readable in the serial monitor
    delay(1000);  // slow transmissions down by 1 second

  } else {
    // This device is a RX node

    uint8_t pipe;
    if (radio.available(&pipe)) {              // is there a payload? get the pipe number that recieved it
      uint8_t bytes = radio.getPayloadSize();  // get the size of the payload
      radio.read(&payload, bytes);             // fetch payload from FIFO
      Serial.print(F("Received "));
      Serial.print(bytes);  // print the size of the payload
      Serial.print(F(" bytes on pipe "));
      Serial.print(pipe);  // print the pipe number
      Serial.print(F(": "));
      Serial.println(payload);  // print the payload's value
    }
  }  // role

  if (Serial.available()) {
    // change the role via the serial monitor

    char c = toupper(Serial.read());
    if (c == 'T' && !role) {
      // Become the TX node

      role = true;
      Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
      radio.stopListening();

    } else if (c == 'R' && role) {
      // Become the RX node

      role = false;
      Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
      radio.startListening();
    }
  }

}  // loop

Radio_1.ino:
/*
 * See documentation at https://nRF24.github.io/RF24
 * See License information at root directory of this library
 * Author: Brendan Doherty (2bndy5)
 */

/**
 * A simple example of sending data from 1 nRF24L01 transceiver to another.
 *
 * This example was written to be used on 2 devices acting as "nodes".
 * Use the Serial Monitor to change each node's behavior.
 */

 /*
  Coded for a ESP32 DEVKIT V1 board type to make use of a pair of
  nRF24L01+ 2.4 GHz. Transceivers
  SPI Pins used MOSI = 23, CE = 21, MSIO = 19, SCK = 18, CSN = 4
  This code is for Radio 1.

*/

#include <SPI.h>
#include "printf.h"
#include "RF24.h"

#define CE_PIN  21
#define CSN_PIN  5

// instantiate an object for the nRF24L01 transceiver
RF24 radio(CE_PIN, CSN_PIN);

// Let these addresses be used for the pair
uint8_t address[][6] = { "1Node", "2Node" };
// It is very helpful to think of an address as a path instead of as
// an identifying device destination

// to use different addresses on a pair of radios, we need a variable to
// uniquely identify which address this radio will use to transmit
bool radioNumber = 1;  // 0 uses address[0] to transmit, 1 uses address[1] to transmit

// Used to control whether this node is sending or receiving
bool role = false;  // true = TX role, false = RX role

// For this example, we'll be using a payload containing
// a single float number that will be incremented
// on every successful transmission
float payload = 0.0;

void setup() {

  Serial.begin(115200);
  while (!Serial) {
    // some boards need to wait to ensure access to serial over USB
  }

  pinMode(CE_PIN, OUTPUT);
  pinMode(CSN_PIN, OUTPUT);

  // initialize the transceiver on the SPI bus
  if (!radio.begin()) {
    Serial.println(F("radio hardware is not responding!!"));
    while (1) {}  // hold in infinite loop
  }

  radio.setAutoAck(false);

  // print example's introductory prompt
  Serial.println(F("RF24/examples/GettingStarted"));

  // To set the radioNumber via the Serial monitor on startup
  Serial.println(F("Which radio is this? Enter '0' or '1'. Defaults to '0'"));
  while (!Serial.available()) {
    // wait for user input
  }
  char input = Serial.parseInt();
  radioNumber = input == 1;
  Serial.print(F("radioNumber = "));
  Serial.println((int)radioNumber);

  // role variable is hardcoded to RX behavior, inform the user of this
  Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));

  // Set the PA Level low to try preventing power supply related problems
  // because these examples are likely run with nodes in close proximity to
  // each other.
  radio.setPALevel(RF24_PA_LOW);  // RF24_PA_MAX is default.

  // save on transmission time by setting the radio to only transmit the
  // number of bytes we need to transmit a float
  radio.setPayloadSize(sizeof(payload));  // float datatype occupies 4 bytes

  // set the TX address of the RX node into the TX pipe
  radio.openWritingPipe(address[radioNumber]);  // always uses pipe 0

  // set the RX address of the TX node into a RX pipe
  radio.openReadingPipe(1, address[!radioNumber]);  // using pipe 1

  // additional setup specific to the node's role
  if (role) {
    radio.stopListening();  // put radio in TX mode
  } else {
    radio.startListening();  // put radio in RX mode
  }

  // For debugging info
  printf_begin();             // needed only once for printing details
  // radio.printDetails();       // (smaller) function that prints raw register values
  radio.printPrettyDetails(); // (larger) function that prints human readable data

}  // setup

void loop() {

  if (role) {
    // This device is a TX node

    unsigned long start_timer = micros();                // start the timer
    bool report = radio.write(&payload, sizeof(float));  // transmit & save the report
    unsigned long end_timer = micros();                  // end the timer

    if (report) {
      Serial.print(F("Transmission successful! "));  // payload was delivered
      Serial.print(F("Time to transmit = "));
      Serial.print(end_timer - start_timer);  // print the timer result
      Serial.print(F(" us. Sent: "));
      Serial.println(payload);  // print payload sent
      payload += 0.01;          // increment float payload
    } else {
      Serial.println(F("Transmission failed or timed out"));  // payload was not delivered
    }

    // to make this example readable in the serial monitor
    delay(1000);  // slow transmissions down by 1 second

  } else {
    // This device is a RX node

    uint8_t pipe;
    if (radio.available(&pipe)) {              // is there a payload? get the pipe number that recieved it
      uint8_t bytes = radio.getPayloadSize();  // get the size of the payload
      radio.read(&payload, bytes);             // fetch payload from FIFO
      Serial.print(F("Received "));
      Serial.print(bytes);  // print the size of the payload
      Serial.print(F(" bytes on pipe "));
      Serial.print(pipe);  // print the pipe number
      Serial.print(F(": "));
      Serial.println(payload);  // print the payload's value
    }
  }  // role

  if (Serial.available()) {
    // change the role via the serial monitor

    char c = toupper(Serial.read());
    if (c == 'T' && !role) {
      // Become the TX node

      role = true;
      Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
      radio.stopListening();

    } else if (c == 'R' && role) {
      // Become the RX node

      role = false;
      Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
      radio.startListening();
    }
  }

}  // loop

Video confirming transmission; both radios

SPI pins are correct for ESP32 DEVKIT V1; I have it both transmitting and receiving now.
I swapped out all Dupont wiring longer than 10 cm, changed the channel with the radio.setChannel function to 125 on both transmitter and receiver, and added a 100 μF, 16 V electrolytic capacitor between the 5 V rail and ground.
Transmission successful! Time to transmit = 403 us. Sent: 5.96
Transmission successful! Time to transmit = 403 us. Sent: 5.97
Transmission successful! Time to transmit = 403 us. Sent: 5.98
Transmission successful! Time to transmit = 403 us. Sent: 5.99
Transmission successful! Time to transmit = 403 us. Sent: 6.00
Transmission successful! Time to transmit = 403 us. Sent: 6.01
Transmission successful! Time to transmit = 403 us. Sent: 6.02
Transmission successful! Time to transmit = 403 us. Sent: 6.03
Transmission successful! Time to transmit = 403 us. Sent: 6.04

Received 4 bytes on pipe 1: 6.25
Received 4 bytes on pipe 1: 6.26
Received 4 bytes on pipe 1: 6.27
Received 4 bytes on pipe 1: 6.28
Received 4 bytes on pipe 1: 6.29
Received 4 bytes on pipe 1: 6.30

Code Gists for nRF24L01, transmit and receive radios


text:
Can Vin of ESP handle many voltage sensors and relays?
My project is Charging Battery via Solar and Piezoelectric sensor while also getting the Realtime  Voltage of the Battery, Capacitor, and Solar.
I want to use Vin as the source to get 5V because ESP8266 NodeMCU only has 3.3V output.
As the diagram shows, can it power 3 Voltage sensors and 2 Relays?
or should i use an external power source?
Ps: The solar is the 'normally closed'

I don't see how your layout would work, as there + terminal of your battery isn't really connected to anything except the voltage sensor.

Vin is for powering the ESP via the onboard voltage regulator which converts Vin to 3.3V for the ESP. It's not a source of 5V unless connected via USB.


text:
I can't connect a microSD card
I can’t connect a microSD card to either the Arduino or the ESP32. It needs to be connected to the ESP32; I just tested it on the Arduino to see if it works at all.
Equipment: ESP32 devkit v1, Arduino Nano, MicroSD card adapter, MicroSD card SanDisk 64gb eXFat.
Software: Arduino IDE, library SdFat (version: 2.2.2). The sketch is an example from the sdfat library - (sdinfo).
Connection to pin: SD adapter pin - CS, SCK, MOSI, MISO, VCC, GND
Arduino to SD Adapter - (CS, D10) (SCK, D13) (MOSI, D11) (MISO, D12) (VCC, +5V) (GND, GND)
ESP32 to SD Adapter - (CS, D27) (SCK, D14) (MOSI, D12) (MISO, D13) (VCC, VIN) (GND, GND)
Result ESP32:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac

Result Arduino:
SdFat version: 2.2.2

Assuming the SD is the only SPI device.
Edit DISABLE_CS_PIN to disable an SPI device.

Assuming the SD chip select pin is: 10
Edit SD_CS_PIN to change the SD chip select pin.

type any character to start

These are the full port monitor results.

Found out what's wrong

Common for connecting to any equipment

SdFat doesn't work for me, I still don't understand what's wrong with this library
so it's better to use standard SD library

Common for connecting to any equipment

SD card (no name, SDHC, 32 GB)
Formatting an Sd card for an SD library (possibly for SdFat) should be in Fat32 with a msdos partition table
I found the answer here (https://forum.arduino.cc/t/yet-another-sd-initialization-fail/286017)
Due to an incorrect partition table, my card could not be read

ESP32 pin connection
ESP32 to MicroSD Adapter - (CS , D5) (SCK , D18) (MOSI , D23) (MISO , D19) (VCC , VIN) (GND , GND)

Arduino Pin Connection
Arduino to MicroSD Adapter - (CS , D4) (SCK , D13) (MOSI , D11) (MISO , D12) (VCC , +5V) (GND , GND)


text:
Why does an ESP01 WiFi module reset when it's connected to a DC motor/water pump?
When I connect an ESP01 WiFi module and water pump in a parallel circuit to an Arduino Uno's 5 V pin, the ESP01 stops working.
The ESP01's built-in LED starts blinking chaotically and the serial monitor outputs trash logs like these:
`��PA���PCA��B��PCA��B�Z-
T���B�������|��B��P�

�D  �'�VB������P�

 �`

Note that I don't connect the ESP01 to WiFi: I just power it on and observe its behavior, so the ESP-01 shouldn't consume peak voltage and current.

Water pump parameters:
Voltage: 3-5 V DC
Current: 100-200 mA

ESP-01S parameters:
Voltage: 3 V to 3.6 V
Current: 70-170 mA

Arduino Uno parameters connected via USB to my laptop:
Voltage: 5 V
Current: 500 mA

Circuit diagram:

I know that an ESP01 shouldn't operate on 5 V and that a voltage regulator should be used, but I omitted it for test purposes and example simplicity.

the battery is drawn upside down ... the power supply may he getting overloaded... measure the voltage with the circuit powered on

You omitted a voltage regulator for test purposes? The abs. max. supply voltage for the ESP-01s is 3.6 V, and I/O is 3.3 V. Using 5 V will likely kill it. Also, the water pump needs a flyback diode. It would be a good idea to supply the water pump from a separate power supply, and not from the Uno's 5 V pin.

You supply your ESP-01 with a more than 50% higher voltage than it was designed for and you wonder why it doesn't work?

Use 74880 baud in the serial monitor. Use Serial.begin(74880); in your sketch to match. Odds are your trash logs will become more comprehensible then.

Thank you all for taking the time to help me solve my problem. Hi, @jsotola. My bad I fixed the battery diagram. I measured the voltage when the water pump and esp01 are powered and it's 4.77V. Without the water pump its 4.9V

Hi, @StarCat, in my initial test I used a voltage regulator but the result was the same. At the moment I power on the water pump the ESP01 stops working.

You say "in a parallel circuit to the Arduino's 5V pin".  Does the power to the motor come from the 5V pin of the Arduino?

@timemage baud rate it's 74880. Usually, when ESP01 works logs are readable but when I turn on the water pump and ESP01 reset/freeze then these trash logs show up.

@Delta_G, yes. The 5V pin of the Arduino powers up the water pump and the ESP01.

You shouldn't power a motor from the Arduino 5V pin.  The Arduino is NOT a power supply.  It can give 5V for logic circuits, but it can't supply current for a motor.  You may have already damaged your board.  Motors need their own power.  Look at some reputable tutorials on driving motors with Arduino.

When the motor starts it pulls too much current and sags the voltage on your board.  This causes your problem.

"I know that an ESP01 shouldn't operate on 5 V and a voltage regulator must be used, but I omitted it for test purposes and example simplicity."  -- How does it simplify the test to do something that you know will make the test fail?  Ok, I see.  You know the test will fail, that's actually pretty simple.

@Delta_G thanks I understand that I'll need separate power supply for the water pump.

The abs. max. supply voltage for the ESP-01s is 3.6 V; leaving out the voltage regulator and using 5 V for its power supply will likely have killed or at least damaged it.
Also, the water pump needs a flyback diode, and it would be a good idea to supply the water pump from a separate power supply, and not from the Uno's 5 V pin; the motor's (start-up) current may be more than the Uno can handle, and the motor will introduce noise in the wrong places.
The quoted 200 mA is the running current of the pump motor; start-up current will be about equal to the stall current and much higher. This will drop the voltage and crash the ESP01.
You may want to google something like "powering water pump from arduino start up current" and read about how it should be done; you're not the first with this problem.

Hi, @ocrdu  in my initial test I use voltage regulator to power the esp01 with 3.3V, flyback diode to handle voltage spike from the water pump, capacitors to handle changes in voltage, noise and to make the circuit more stable. Also I use transistor as a switch to turn on/off the water pump. Then the problem with the esp01 came and I found out that it's when the water pump is turned on. So I removed all other parts and for the test simplicity I left only the water pump and esp01.  In both ways the result is the same and esp01 freezes and stops working when the water pump is turned on.

For me it's not an option to use separate power supply to the water pump I want all to be powered from one place (Arduino Uno or li-on battery). As my understanding in parallel circuits the voltage across each of the components is the same and the total current is the sum of the currents flowing through each component. So 5V should be enough to power 3.3V eps01 and 3-5V water pump. And current should be enough too. Because Arduino Uno current is 500mA, esp01 is 170mA and the pump 200mA. Am I getting it right?

What is the pump's start-up current? Does the 5 V supply drop at the moment the motor starts? Did you have a look at the 5 V supply with an oscilloscope while the motor is running?

Start-up current is 200mA I got the pump from here.
Yes, usually voltage is 4.9V when I power on the pump voltage drops to 4.77V.
Unfortunately I don't have oscilloscope yet

200 mA is the pump's running current; at the moment it starts it will pull much more than that for an instant, hence start-up current aka stall current. Did you measure this initial current and the voltage drop at the moment the pump starts? You will find this current is higher than what the Arduino can provide. In general, you should supply a motor from a separate power supply, and not from an Arduino's 5 V pin.


text:
ATTiny85 pin definitions
I have been tearing my hair out on and off for two weeks trying to figure out pin definitions for the ATTiny85 in PlatformIO. My wiring is basically this:

My sketch:
#include <Arduino.h>
#include <avr/io.h>

#define WIPER PB2

void setup()
{
  pinMode(WIPER, INPUT);
}

void loop()
{
  int wiper_raw = analogRead(WIPER);
  int wiper = map(wiper_raw, 13, 1024, 0, 255);
  // show the actual value, probably not relevant to the question

  delay(100);
}

(Showing the actual value is done by sending the mapped value over to a neopixel stick on the red channel, so basically turning the knob turns the stick from all the way off to brighter and brighter output of red.) The pot is connected to what should be physical pin 3, also known as PB4, also known as Arduino Pin 4, also known as ADC2, etc etc. (Using https://nerdytechy.com/wp-content/uploads/2021/01/attiny85-guide-pinout.png as a guide but it's not any different from any other pinout listing I've seen.)
In the sketch I'm referencing PB2, which VSCode tells me evaluates to 2. That's physical pin 7. When I plugged the pot signal pin into pin 7, I got no response when manipulating the dial. So I started plugging it into all the other pins (except VCC, GND, and RESET) and the very last one I tried, pin 3, was the one that reacted to the changes on the pot.
No pinout guide I've ever seen lists PB2 on physical pin 3. What am I doing wrong?

The very image you are linking to shows PB4 on physical pin 3.

Right. What I'm saying though is that the code has PB2 but the pot is responding on pin 3. The code that you see there works with the wiring that you see, even though it shouldn't because if the pin definitions were right, that green wire should be connected next to VCC, not GND.

The macros such as PB2 are defined in the avr-libc for accessing the
bits of the raw I/O ports, with statements such as
PORTB |= _BV(PB2);  // set PB2 as HIGH

They do not uniquely identify as pin: if you have more than one port
(say, on an Uno), both PB2 and PC2 are equal to 2.
If you use the Arduino core functions, you should not use these macros.
Instead, use the plain numbers 0, 1... with digitalRead() and
digitalWrite(), and the macros A0, A1... with analogRead().
Alternatively, with analogRead(), you can use the raw analog pin
numbers 0, 1, which are interpreted as synonyms of A0, A1...
Writing something like
analogRead(PB2);

is confusing, because you are using the avr-libc macro PB2 in the
wrong context. Furthermore, since this is the same as analogRead(2);,
the Arduino core interprets it as equivalent to
analogRead(A2);

As the pinout image shows, Arduino pin A2 is the same as ADC2, PB4 and
physical pin 3.

Perfect, that did it. So basically in the pinout image I linked above, I should have been using the blue "Arduino Pin" labels (ie. "4/A2"). Changed the code to use A2 and it worked just fine. Thanks!


text:
Unable to connect to SHT4x sensor probe through I2C bus
Error trying to execute serialNumber(): ReceK on transmit of address
Error trying to execute serialNumber(): Received NACK on transmit of address
Error trying to execute measureHighPrecision(): Received NACz��trnsmit of ad���Error trying to execute serialNumber(): Received NACK on transmit of address
Error trying to execute measureHighPrecision(): Received NACK on transmit of address
Error trying to execute measureHighPrecision(): Received NACK on transmit of address

This is the error I receive when I try to connect my probe to my Arduino Uno.
I have soldered jumper wires to my probe to use with my microcontroller. The humidity probe is an SHT40 Sensirion probe. The code is the example usage code you find when you install the Sensirion SHT4x library.
 /*
 * Copyright (c) 2021, Sensirion AG
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of Sensirion AG nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <Arduino.h>
#include <SensirionI2CSht4x.h>
#include <Wire.h>

SensirionI2CSht4x sht4x;

void setup() {

    Serial.begin(115200);
    while (!Serial) {
        delay(100);
    }

    Wire.begin();

    uint16_t error;
    char errorMessage[256];

    sht4x.begin(Wire);

    uint32_t serialNumber;
    error = sht4x.serialNumber(serialNumber);
    if (error) {
        Serial.print("Error trying to execute serialNumber(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    } else {
        Serial.print("Serial Number: ");
        Serial.println(serialNumber);
    }
}

void loop() {
    uint16_t error;
    char errorMessage[256];

    delay(1000);

    float temperature;
    float humidity;
    error = sht4x.measureHighPrecision(temperature, humidity);
    if (error) {
        Serial.print("Error trying to execute measureHighPrecision(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    } else {
        Serial.print("Temperature:");
        Serial.print(temperature);
        Serial.print("\t");
        Serial.print("Humidity:");
        Serial.println(humidity);
    }
}

The soldered wires move a bit, but they are all still in contact and strongly intact.

Have you tried the I2C Scanner sketch? That can show, if there is at least a device found on the bus (and its address)

Do you have the requisite pull-up resistors for your I2C bus?  The Arduinos internal pull-ups aren't strong enough.


text:
Why do I need to connect a potentiometer to a +5V source in 1602 tutorial?
I'm getting starter with the Arduino and I'm going through the classic tutorial, it says to connect the VO to a pot's wiper, and pot itself to +5v and ground, so I did.
I tuned it and it worked, but then I thought, why do I need a pot if I don't plan to move it from this value? Why don't I just replace it with a resistor? But I'm still very new to electronics, Ohm's law, etc, and I got confused.
Why do I need to connect a potentiometer to +5v source, if the resistor between VO and the GND will do? I unplugged the +5v from the pot and it still worked. I had to adjust the position, but it works just fine without it, so my question is, if it works without, why all tutorials tell us to connect it to a +5v?

VO controls the contrast of the LCD, which is quite temperature-dependent.
You can get away with a fixed resistor between VO and GND because of the built-in resistor between VCC and VO, producing a voltage divider.
In many cases you can also use a direct connection between VO and GND, resulting in a voltage of zero at VO.
However, be aware that the contrast changes if the ambient temperature leaves your "comfy zone". Depending on where you want to use the LCD, you need to check that out "in the field."

I may be wording my question unclear but what I am actually interested in is why most tutorials say to comnnect a VCC to a +5 as opposed to leave it disconnected, it works either way so what might be a benefit of connecting it to the Vcc

@YouCare I don't understand what you mean by "comnnect a VCC to a +5". would you mind to elaborate? I thought we were talking about V0.

why do I need to connect, a potentiometer to +5v source, if the resistor between VO and the GND will do?

That's because the 1602 board itself (usually) has a resistor between VO and VCC. So to make voltage divider you only need to add one extra resistor from VO to Gnd (ca. 1-2K probably).
So, yes, you can go with only one resistor (or with the pot disconnected from VCC) if the board already has another resistor pre-soldered.