text:
esp8266 Arduino error : esptool.FatalError: Failed to write compressed data to flash after seq 1 (result was C100)
i have simple circuit for controlling the dc motor by bjt BC869 like this:

and this code:
/*
  ESP8266 Blink by Simon Peter
  Blink the blue LED on the ESP-01 module
  This example code is in the public domain

  The blue LED on the ESP-01 module is connected to GPIO1
  (which is also the TXD pin; so we cannot use Serial.print() at the same time)

  Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/
#define dd 1
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
   pinMode(dd, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
  // but actually the LED is on; this is because
  // it is active low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);
//  loop1() ;// Wait for two seconds (to demonstrate the active low LED)
}
void loop1() {
  digitalWrite(dd, LOW);   // Turn the LED on (Note that LOW is the voltage level
  // but actually the LED is on; this is because
  // it is active low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(dd, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

it was working days before but it stopped from working by connecting to prototype circuit by breadboard, but after connecting to this circuit it programmed for two  or three times and after that it showing this error:

Executable segment sizes:
IROM   : 227612          - code in flash         (default or ICACHE_FLASH_ATTR)
IRAM   : 26768   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...)
DATA   : 1252  )         - initialized variables (global, static) in RAM/HEAP
RODATA : 672   ) / 81920 - constants             (global, static) in RAM/HEAP
BSS    : 24880 )         - zeroed variables      (global, static) in RAM/HEAP
Sketch uses 256304 bytes (26%) of program storage space. Maximum is 958448 bytes.
Global variables use 26804 bytes (32%) of dynamic memory, leaving 55116 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port /dev/ttyUSB1
Connecting........_____....._____.
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: d8:bf:c0:ff:6f:30
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0340
Compressed 260464 bytes to 190649...
Writing at 0x00004000... (16 %)Traceback (most recent call last):
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/upload.py", line 65, in <module>
    esptool.main(cmdline)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 2938, in main
    operation_func(esp, args)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 2374, in write_flash
    esp.flash_defl_block(block, seq, timeout=DEFAULT_TIMEOUT * ratio * 2)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 104, in inner
    return func(*args, **kwargs)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 672, in flash_defl_block
    self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 379, in check_command
    raise FatalError.WithResult('Failed to %s' % op_description, status_bytes)
esptool.FatalError: Failed to write compressed data to flash after seq 1 (result was C100)
esptool.FatalError: Failed to write compressed data to flash after seq 1 (result was C100)

So i have seen some suggestion like changing the USB port and dont worked for me, so i like to know why this happened and how could be solved ( by flashing the esp8266 or ...)
Update:
I have tried by the comment suggestion this code :
void setup() {}
void loop() {}
And get again that error:
Executable segment sizes:
IROM   : 227372          - code in flash         (default or ICACHE_FLASH_ATTR)
IRAM   : 26360   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...)
DATA   : 1252  )         - initialized variables (global, static) in RAM/HEAP
RODATA : 672   ) / 81920 - constants             (global, static) in RAM/HEAP
BSS    : 24848 )         - zeroed variables      (global, static) in RAM/HEAP
Sketch uses 255656 bytes (24%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26772 bytes (32%) of dynamic memory, leaving 55148 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port /dev/ttyUSB1
Connecting........_____.
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: d8:bf:c0:ff:6f:30
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 259808 bytes to 190257...
Writing at 0x00004000... (16 %)Traceback (most recent call last):
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/upload.py", line 65, in <module>
    esptool.main(cmdline)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 2938, in main
    operation_func(esp, args)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 2374, in write_flash
    esp.flash_defl_block(block, seq, timeout=DEFAULT_TIMEOUT * ratio * 2)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 104, in inner
    return func(*args, **kwargs)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 672, in flash_defl_block
    self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
  File "/home/so/snap/arduino/41/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 379, in check_command
    raise FatalError.WithResult('Failed to %s' % op_description, status_bytes)
esptool.FatalError: Failed to write compressed data to flash after seq 1 (result was C100)
esptool.FatalError: Failed to write compressed data to flash after seq 1 (result was C100)

Thanks.

with problems like this, you should always start with minimal sketch void setup() {} void loop() {}  .... the sketch is probably irrelevant and only clutters up the post .... also remove all of the external hardware

i have done that but not solved!

Does it work when disconnecting the NodeMCU from the breadboard so that there are no externally connected components anymore?

I have had that error when the internal capacitance of the ESP32 module isn't enough by itself to run the module properly. You should add a 10uF capacitor across the 3.3V and GND pins on the module (direct on the module, not the PCB pins).

it was working days before but it stopped from working by connecting to prototype circuit by breadboard, so ...


text:
How can I assign the value of a char array to a uint8_t array?
I have a char array variable that has a value.
I need to send this value through LoRa. The library I use for the LoRa implementation accepts an array of uint8_t. How can I pass the value of a char[] to a uint8_t[] variable (and the opposite)?
if (Udp.parsePacket()) {
  int udp_received = Udp.available();
  char udp_buffer[udp_received + 1];
  Udp.read(udp_buffer, udp_received);
  udp_buffer[udp_received] = '\0';

  uint8_t udp_to_lora[] = "???";
  rf95.send(udp_to_lora, sizeof(udp_to_lora));
  rf95.waitPacketSent();

}

I need to pass the udp_buffer to uint8_t udp_to_lora[].

I don't have a compiler at hand, but you can cast the array  as a char and uint8_t are similar in size:
rf95.send((char*) udp_to_lora, sizeof(udp_to_lora));

How could it be so easy? Thanks! But help me understand. What's the purpose of the dereference asterisk in this cast?

Same the other way round: rf95.send((uint8_t*)udp_buffer, udp_received);

a char is a character, a char * is a POINTER to a character. However, an array of characters is the same, as it points to the first character of a text.

"What's the purpose of the dereference asterisk in this cast?" It's in the context. In a type specification (which a cast is) the '*' is part of the type, where it means "pointer to". In a value, it is the dereference operator and means "the value of what [thing] points to", or more literally, "the value contained in the memory location(s) whose address is the value of [thing]". Locations is plural because Arduino memory, being byte addressable, most variables are multi-byte.

dereference is *a

source: Stack Exchange

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

sort: votes


text:
Global variable changes its value when loop starts again
I have a problem with the global variable calibrationValue. It is initially set with the correct value and is also displayed correctly in the output. As soon as the loop function is restarted, the value of the variable is wrong, although it is not rewritten. Can someone help me please?
The following values are printed in the image:

new AI value
wrong calibrationValue (!)
sumOfValues (needed for calculation of calibrationValue) correct
numValues (needed for calculation of calibrationValue) correct
Text and calibrationValue (correct!)

    int op_mode_Pin = 7;                      // Digital input Pin which transmittes the op_mode_Ardui
    int op_mode_Ardui;                        // Operator Mode of Arduino
    int returnValue1 = 12;                    // First digital return value for transmitting box weight
    int returnValue2 = 13;                    // Second digital return value for transmitting box weight

    int sensorPin = A0;                       // Select the input pin for the potentiometer
    long weightValue = 0;                     // Variable to store the value from the sensor
    long calibrationValue = 0;                // Value which is filled in calibration progress
    int numValues = 50;                       // Number of taken values for calculating an average
    int thresBoxWeight = 300;                 // Weight for separating heavy and light boxes

    unsigned long sumOfValues;                // Sum of the taken values
    unsigned long aveOfValues;                // Average of the values

    char stringBuffer[30];                    // Buffer for combining string and variables

    void setup() {
      // Initiate serial communication to screen
      Serial.begin(9600);

      // Initiate some variables
      //weightValue = 0;
      //calibrationValue = 0;
      //numValues = 50;
      //thresBoxWeight = 300;

      // Set the Input Pins for op_mode_Ardui
      pinMode(op_mode_Pin, INPUT);            // sets the digital pin 7 as input

      // Set the Output Pins for Box declaration
      pinMode(returnValue1, OUTPUT);          // sets the digital pin 12 as output
      pinMode(returnValue2, OUTPUT);          // sets the digital pin 13 as output

    }

    void loop() {
      Serial.println(analogRead(sensorPin));
      Serial.println(calibrationValue);
      // Reset of Sum and Average variables for next cycle
      sumOfValues = 0;
      aveOfValues = 0;
      op_mode_Ardui = digitalRead(op_mode_Pin);

      if (op_mode_Ardui == HIGH){
        for (int i=0; i<numValues; i++){
          weightValue = analogRead(sensorPin);                                                  // read the value from the sensor
          sumOfValues = sumOfValues + weightValue;                                              // Build the sum of all values
        }
        Serial.println(sumOfValues);
        Serial.println(numValues);

        calibrationValue = sumOfValues / numValues;
        sprintf(stringBuffer, "Calibration accomplished with value: %d", calibrationValue);     // Combine text and variable to output
        Serial.println(stringBuffer);                                                           // print text and variable to screen
        delay(3000);
      }
    }

This:
sprintf(stringBuffer, "Calibration accomplished with value: %d", calibrationValue);

is a buffer overflow: the function sprintf() is writing a 40-byte
string into a 30-byte buffer. Whatever happens to lie in memory right
after the buffer will be overwritten by sprintf(). Apparently this
happened to be calibrationValue. You should use
snprintf() rather that sprintf(), as the former is designed to
prevent this kind of overflows.
Or better yet, stick with Serial.print[ln]():
Serial.print("Calibration accomplished with value: ");
Serial.println(calibrationValue);

Edit: You may notice that 13108 is the same as 0x3334, which on a
little endian architecture is stored in memory as 0x34 0x33. These are
the ASCII codes for "43", which is part of what sprintf() wrote past
the end of the buffer.

it's interesting that the buffer overflow in stringBuffer overwrites a variable defined further up in the file. In most compilers your globals get allocated in memory roughly in the order you declare them. (Optimizing compilers on 32 and 64 bit platforms might do some re-ordering to make variable sized structures fit in less memory while honoring word/longword/double alignment, but most Arduinos are 8 bit devices where there's no such thing as word alignment.)

It worked. I never thought that an overflow could affect global variables. Thank you.

On a real mode machine like an Arduino, a buffer overflow stomps whatever is in RAM. Global variables, data on the heap, whatever. And there's nothing stopping it.

@DuncanC: I don't know how the linker decides on the allocation order. I tried compiling the OP's code with avr-g++ 7.3.0, as shipped with the Arduino IDE 1.8.13, and the .bss section contains timer0_fract, timer0_millis, timer0_overflow_count, stringBuffer, sumOfValues, calibrationValue and Serial, in this order. If I remove -flto from the compiler's command line, I get a different allocation starting with stringBuffer, aveOfValues (which was optimized out with -flto), sumOfValues, calibrationValue

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


text:
Powering Arduino and L293D with the same Power Supply
I am relatively new to Arduino and plan to power an Arduino and an L293D Motor Driver with the same 9V power supply as in the diagram below.
I tried to simulate this with Tinkercad, but it seems like Tinkercad always powers the Arduino with an extra USB Cable, so I can't test it with only 1 power supply.
Would the 9V battery power both the Arduino and the L293D in this example?

Don't use one of the little rectangular 9V "transistor batteries". Those don't provide enough current to power a motor for very long at all (probably single-digit minutes) before they are discharged.

I don't see any problem. You used the Vin for 9V, and shared grounds.
I suggest using a bypass capacitor (typically 0.1 uF) for the L293D VCC, but I don't have experience with using a L293D.
Also, you need to check if the battery can deliver enough current for both motors and the Arduino.


text:
using a switch case with a 5-position switch and serial output
I'm trying to get started on developing a menu system for my LCD1602. I have a Parallax 5-position switch (up,down,left,right,center) and I would like to interface the two.
I've been trying to get some code working but I'm kind of lost. I don't have a lot of recent experience with Arduino and could use some advice. I realize that there is a version of the 1602 that comes with a keypad integrated into the circuit but I don't have that model. I have a plain-jane screen and a separate 5-position switch.
I'm also aware that the easiest way to accomplish what I desire is with a resistor network and mapping the ADC values. However, I don't want to make an analog switch, I want to make a digital switch.
Is there any way I can take the pins and put them into an array and then translate that into a switch case statement?
I've tried several different ideas and nothing seems to be working. Forgive the example code, it's hacked together.
below is my code
*/

// constants won't change. They're used here to set pin numbers:
char buttonChar1 = 'a';     // the number of the pushbutton pin
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
const int buttonPin5 = 6;
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int pinsArray[5] = {2, 3, 4, 5, 6};
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(buttonPin5, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1) == 2;
  buttonState2 = digitalRead(buttonPin2) == 3;
  buttonState3 = digitalRead(buttonPin3) == 4;
  buttonState4 = digitalRead(buttonPin4) == 5;
  buttonState5 = digitalRead(buttonPin5) == 6;
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:

  switch (pinsArray[5]) {
    case 2:    //
      digitalWrite(ledPin, HIGH);
      Serial.println("button1");
      break;
    case 3:     //
      digitalWrite(ledPin, HIGH);
      Serial.println("dim");
      break;
    case 4:    //
      Serial.println("medium");
      break;
    case 5:    //
      Serial.println("bright");
      break;
  }
  }

When you want to perform actions in response to button presses, you
should take care of reacting to the signal edges rather than levels.
In other words, you perform the action only when the signal changes from
LOW to HIGH, not every time you see it HIGH.
You should also read about button bounce, and either implement your own
debouncing or use an existing library. Below is an example using
Bounce2, but there are other options:
#include <Bounce2.h>

const uint8_t pinDim    = 3;
const uint8_t pinMedium = 4;
const uint8_t pinBright = 5;

Bounce buttonDim, buttonMedium, buttonBright;

void setup() {
    buttonDim.attach(pinDim, INPUT);
    buttonMedium.attach(pinMedium, INPUT);
    buttonBright.attach(pinBright, INPUT);
}

void loop() {
    buttonDim.update();
    buttonMedium.update();
    buttonBright.update();

    if (buttonDim.rose()) {
        Serial.println("dim");
    }
    if (buttonMedium.rose()) {
        Serial.println("Medium");
    }
    if (buttonBright.rose()) {
        Serial.println("bright");
    }
}

You could also, as suggested in Michel Keijzers' answer, use arrays for
the pins and Bounce objects. While these would help streamline the
calls to attach() and update(), they will not help with the meaty
part of the code, i.e. reacting to the presses. There, I would prefer
the button to have descriptive names.

I'm not sure debouncing is really important here ... it seems the menu items are 'dim' bright', 'medium' ... so it does not matter if a button is seen two or twenty times (the result will be still dim or bright). It matters when it is used to increment/decrement or doing an action where the number of button presses matter.

@MichelKeijzers: It makes a difference for the serial output. Admittedly, this may not be an important functionality...

Upvoted ... you are right ... however, I thought the Serial.println was only for debugging purposes.

Next time align your code with ctrl-K (after selecting).
And yes, you can heavily optimize your code (for maintainability) using arrays:
Instead of
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
const int buttonPin5 = 6;

use
const int buttonPins[] = { 2, 3, 4, 5, 6 };

In software engineering it's normal to start with index 0 (such as an array index).
For the button states:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;

you can use
boolean buttonStates[5];
for (uint8_t buttonIndex = 0; buttonindex < 5; buttonIndex++)
{
    buttonStates[buttonIndex]= false;
}

Instead of setting the pin modes:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
Use a for loop:
for (uint8_t buttonIndex = 0; buttonindex < 5; buttonIndex++)
{
   pinMode(buttonPins[buttonIndex], INPUT);
}

You can combine the two for loops above with one.
To read the button states:
buttonState1 = digitalRead(buttonPin1) == 2;
buttonState2 = digitalRead(buttonPin2) == 3;
buttonState3 = digitalRead(buttonPin3) == 4;
buttonState4 = digitalRead(buttonPin4) == 5;
buttonState5 = digitalRead(buttonPin5) == 6;

Use
for (uint8_t buttonIndex = 0; buttonindex < 5; buttonIndex++)
{
   buttonStates[buttonIndex] = digitalRead(buttonPins[buttonIndex]) == buttonPinds[buttonIndex]) ? true : false;
}

For the switch, I think you need to keep it as it differs per pin.
And instead of using the value 5 use e.g.:
const uint8_t NR_OF_BUTTONS = 5;

and use the NR_OF_BUTTONS constant everywhere.
Note: I don't have a compiler at hand, so forgive me for any possible compiler errors.
Also, instead of multiple arrays (each of length NR_OF_BUTTONS), you can use an array of a struct which contain the pin number and state, but this is maybe beyond the scope of your programming knowledge. The use of arrays is already a huge improvement.

Michael has already given you some excellent advice on how to clean up your code.
Your switch statement does not make much sense. You're switching based on an out-of-range index into an array of constants.
Once you've read the states of all your buttons as outlined by Michael, your loop needs to decide what to do about the state of each switch.
Is this a joystick style switch, where the user can only engage one direction at a time? Or is it possible to press 2 switches at once?
If it's a diamond arrangement of 5 switches with a switch in the middle, the user could press any combination of switches at the same time.
I'd suggest code like this:
void loop() {
    if buttonStates[0] == HIGH {
       //code to handle button 0 (pin 2) being pressed
    }

    if buttonStates[1] == HIGH {
       //code to handle button 0 (pin 3) being pressed
    }
    //And so on for the rest of your switches.
}

Upvoted for giving an 'actual'  solution.

Edgar's point about detecting a CHANGE of switch state is a good one, as is his point that you'll need to debounce your buttons. In my projects I created something similar to the Bounce class. My buttons can either be edge sensitive or state sensitive.

I'm not sure debouncing is really important here ... it seems the menu items are 'dim' bright', 'medium' ... so it does not matter if a button is seen two or twenty times (the result will be still dim or bright). It matters when it is used to increment/decrement or doing an action where the number of button presses matter.


text:
stm8tool is not available for you operating system (ubuntu OS)
I have tried to  add STM8 to arduino by this instruction :
but i have this error:

also my system is :
so@so-notebook:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

Also googled the :
stm8tool is not available for you operating system
but don't find any result to solve ...
Update:
based of comments :
so@so-notebook:~$ uname -a
Linux so-notebook 5.6.9-050609-generic #202005051753 SMP Tue May 5 22:00:17 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Thanks.

Please also post the output of uname -a

All seems fine on 20.04 to me... The content of the json file looks fine too.


text:
Nodemcu v3 - Power supply via VU pin?
I want to control two hitec hs55 micro servos via a Nodemcu v3. These need at least 4.8 V power supply acc to data sheet.
Specs:
Hs-55 micro servo:
Voltage range: 4.8-6 V
Current Drain - no-load (4.8V): 150 mA
Pulse Amplitude: 3-5V
NodeMCU (v3):
From what I found it seems like it can "reliably supply 600 mA".
3.3V pins (standard)
5 V (pin VU), Directly connected from the USB (?)
From what I understand it is generally a good idea to supply power to servos separately, otherwise the board can be damaged. Is this also the case here or would it be OK to connect the supplies to the servos from the VU pin? I'm thinking that there is a possibility it could be ok since it is directly connected to the USB.
For the signals I will use the normal GPIO pins.
Thank you in advance :-)

I'm not sure about the nodeMCU, but most AVR-based Arduino boards won't draw more than 500 mA from the USB port.

Supplying the servo from the USB is generally okay, but if it works or not depends on the USB host you use.
The data you mention is not relevant, though:

150mA are valid under no load, when there is a load the servo will sink more current
600mA probably refers to the onboard linear regulator which provides the 3.3V for the ESP. Depending on what the ESP has to do, it may require those 600mA on itsown and the connected circuit.

You can simply try what you suggested, it won't harm the nodeMCU. If it doesn't work the reason is probably the USB host not being able to provide the required current (a fast-charge usb wall charger should work).

Thank you, would you say it should be ok also to use this solution for a project where it will be installed for a longer period? If the USB is really connected directly to the VU port I guess this should also be ok. I can't find any electric diagram confirming this however. Yes I will try with that then! If I understand correctly a high max Ampere on the USB charger is OK as the servo motors will only use as much current as they need. One more question, what is the difference between the standard 3.3 V supply and this VU-supply that makes the 3.3 V to be bad for using as a supply?

The circuit diagram of a NodeMCU shows that there's a schottky diode between Vusb (the voltage input supplied by USB) and the Vin pin. This has the effect of reducing the approximate 5V voltage supplied by your typical USB jack/outlet/cable to something slightly lower. In my case, the apple USB charger adapter provides 5.1V but this gets reduced to 4.76V on the Vin pin. This Vin voltage is also quite noisy. I don't know if that will affect your servos. I've run one NodeMCU from the Vin pin of another NodeMCU pin without any trouble.
The schottky diode in the NodeMCU is a 1n5819/SS14/S4(SOD_323). I'm not certain, but if this is the correct datasheet, it says it can supply 1 amp, which sounds like enough. If I were you, I'd try and see if I could get power directly from the USB source rather than taking it off the NodeMCU pin. It might work off the pin, though. Try and make sure you get a USB that supplies at least 5.1V, though. It's going to be close.
EDIT: I would also add that the NodeMCU will be drawing power, too. If you are drawing 300mA with your servos and 100-150mA with your nodeMCU, that's cutting it pretty close for most USB power sources. A Macbook, for example, can only supply 500mA via a USB port. This article says a NodeMCU can consume up to 400mA under some circumstances.
Generally speaking, I've been told that it's a bad idea to use GPIO pins to drive anything that draws a significant amount of power. I'm thinking you should maybe consider using some kind of servo driver or relay or something.

"I've been told that it's a bad idea to use GPIO pins to drive anything that draws a significant amount of power."  This is imperative. Most Arduino boards have a recommended limit of 20 mA of sourced or sunk current on any GPIO line, and a peak limit of 40 mA. If you execeed 40 mA you will likely destroy either that GPIO pin or the entire board. You CANNOT power a servo directly from a GPIO line.

Thank you for the answer with much good and detailed information! However my nodemcu is the v3 (lolin) which has a VU pin (reserved in v2) that I want to power the servos with - not the VIN. This is a pin which I believe is directly connected to the microUSB voltage in, and thus should be possible to send enough Ampere through, also without loosing so much voltage. I have however not been able to find a electric diagram for this v3...

@Jmalecki as I mentioned in my post, trying to draw 300mA for servos plus the current for the MCU is probably asking a lot of many USB outputs. Those adapters that come with an iPhone these days can supply an amp, but a lot of USB ports on computers would max out at 500mA.


text:
Connecting an arbitrary number of pins to pin holes without soldering?
I want to avoid soldering for health reasons. I have no well-ventilated open area in my apartment. For a board/modules that have no pins but only holes, how can I connect pins to the holes without soldering?
For certain popular hardware like Raspberry Pi Zero, there seems to be something called "hammer header"

but the problem is those have a fixed, pre-determined number of pins, not individual pins. So, if a hardware has 5 holes instead of 20 holes, that thing cannot be used. Is there a hammer header for a single pin? So that if the hardware has 5 holes I would just use 5 of them. I have searched the Internet, but no result. Also, the "hammer header" itself seems to be rare. I could not find a single online store in my country that sells it.
Some existing answer mentioned "Pomona minigrabber", but that thing seems to be temporary. That is, I cannot move the device (it looks that it will fall off). So, that is probably not the answer I want.
A secondary, less-important question, but if I installed hammer pin headers (seems like one has to hit it with an actual hammer to install it), can I un-install (remove) the headers?

Do you have a medical condition that precludes soldering, or are you just under the impression that the (few) fumes are dangerous in some way?

The working principle behind those hammer heads might be cold welding. If that's the case they will form an atomic bond with the holes and they can't be removed without damage. I also can't understand your concerns about soldering. Just make those few solder joints outside if you are really scared. You can also use flux-less solder and colophony as a flux. Colophony is completely natural...

@Majenko According to my research, the fume from the coating of the wire seems to stuck in the lung once inhaled and accumulated, causing asthma or other diseases. ( https://www.asthma.org.uk/advice/understanding-asthma/types/occupational-asthma/ "Electronics and assembly industries expose people to irritants from fumes from rosin-based solder flux.") So, if possible I want to avoid it.

Do you have asthma? Rosin only causes minor irritation in people who are already susceptible. And they don't actually know if it's the rosin at all (rosin is a food additive and perfectly safe for ingestion). And soldering headers has no wire coating... I have been soldering for over 30 years in enclosed spaces with no noticeable effects. If you are that paranoid just get a Hakko FA-400.

@Majenko No, I do not have asthma. But a popular YouTube video said that the effect is cumulative and the symptoms may not appear for years until they do ( https://youtu.be/EGdlM48eDbA?t=108 ). I had search for solder wire that has no flux or soldering without flux, etc, but I could not find any result, so I thought all solder wires had that coating.

Never believe anything you see on social media!!! Soldering is perfectly safe. If it weren't all electronic engineers would be dead.

Do you have a exhaust fan in the bathroom or kitchen that vents to the outside of the building? Perhaps a piece of flexible dryer vent piping could be connected to the outside of the fan housing then be used to remove the fumes/gasses. Alternate solutions: https://electronics.stackexchange.com/questions/161139/which-are-the-safety-recommendations-for-soldering

Maybe if you spend all day every day soldering and breathing fumes.  A small exposure from a hobby project isn’t going to hurt you.  STOP getting your science from YouTube.  They’ll let any idiot say anything they want there.  It’s not a reliable source.

If you are too afraid, electronics may be the wrong hobby for you :D ...sry

Rosin fumes are not toxic. Rosin is edible. It's used as a food additive. Rosin fumes can be an irritant (and only an irritant) to people with underlying breathing issues. They are far less harmful than an open fire in your living room, or walking along a pavement next to a busy road.

@VE7JRO I have a kitchen hood, of course, but I suspected that if I use it for soldering, bad substances from soldering might stick to the hood and might fall from the hood to foods when I cook next time.

@SimSon It is more like a necessity than a hobby, because I often cannot find an off-the-shelf electronic product that does what I want to do. Most existing products are dumb. For example, I cannot find an existing product that can switch between multiple 3.5mm audio jacks that can be controlled by an API.

"Electronics and assembly industries" refers to factory work constantly soldering pre-arranged parts, 15 welds/min is common, often 10 hours a day 6 days a week. In other words, one week of factory soldering (50k+ joins) is about the same as a lifetime of hobby soldering. You could use solder paste and a spare toaster oven run outside if paranoid. You might also be able to spot-weld small wires to gold through holes, but you'd have to be very very careful and precise.

"Bad substances from the soldering" will not fall from the hood into your food. Many devices are also available w/ pre-soldered headers. The likely reason there aren't any USB-/WiFi-controlled 3.5mm audio-jack-only switchers is because essentially nobody needs that.

Here's an older answer that is related that may offer some help: https://electronics.stackexchange.com/questions/249140/how-can-i-make-connection-on-pcb-circuit-board-holes-without-solder-for-proto

As you already have seen, there are not many options to contact such boards without soldering, because they are meant to be soldered. Those hammer headers are an option. When you find a seller for your country, it should also have these in different sizes/numbers of pins.
Though contacting the board with the pins is not the only problem, you may face. As long as you are experimenting, the typical breadboard is often enough. But when you want to make something more permanent, reliable, current thirsty or noise sensitive, a breadboard is a bad choice. In that case you would also need to solder. Soldering is just a very integral part of electronics.

As others have wrote in the comments, I would also consider soldering as a hobbyist as safe, especially, when you take some precautions. A "well ventilated area" can be a simple room with the window open and a small fan directed to the working place, so that the fumes don't directly go up your nose. That is already a very big improvement, which is also rather cheap. That's also about what the woman does in the video, that you linked. And washing your hands after soldering is also a good measure. (I'm doing soldering the described way for about 15 years now, without any health issues)
In the video, that you linked, they say, that the fumes are toxic and their effect adds up. Letting aside, that they don't back it up with any data and I cannot either, they also don't talk about the amount of solder work, that they consider here. As an electronics beginner you most likely will just solder very rarely for getting pin headers on boards or maybe contacting a motor. The main work most likely will still be done on the breadboard. So here the exposure is so small, that you don't need to consider more than the above safety measures. These will also last rather long, as you get more profound in electronics. And when keeping up that hobby, you maybe wanna invest in a more professional filter system, as you are doing more solder work.
Doing electronics while being that scared of soldering will not be much fun. For the start you might get away by only buying presoldered boards. But very fast you will run against walls with this. Not a good start for a beginner.
But in the end it's your own decision. You have all right to be afraid of solder fumes, though that just might disqualify electronics as a hobby for you.

if I installed hammer pin headers (seems like one has to hit it with an actual hammer to install it), can I un-install (remove) the headers?

That depends on the pin headers, but most likely no. You would need physical force to get them off. And the pads on a PCB are not very strong. They are made to be soldered, not for tearing the pins off without any damage. But why would you want to remove the headers? You only very rarely solder wires directly to the board for connecting with other parts. Either you solder it onto another PCB (where the pin headers come in handy), or you use a female header on a PCB or a cable for making the connection temporary. For example all my small Arduinos get pin headers soldered to them, so I can put them onto my own PCBs via female headers on the PCB. With that I can also disconnect or replace the Arduino if I need to.

I placed the arduino on a breadboard with the pins on the breadboard 1 pinhole further apart than it 'should' be, this way you can press the arduino down and the arduino will fasten itself in place.

I do not know who downvoted this but this is actually quite an interesting idea. So, you put two unsoldered pin headers on the breadboard but one-hole-width wider, and use the tension of the pins when you put the Arduino's holes on those holes.  PS: It may be better to embed the image in the answer itself, not as a link.

Why not get a fume extractor, there are all types, some even have filters. Simply do a google search for "fume extractor", on my first try I got 587,000 hits. The price is all all over the map even for the same model.

I had a problem where a sensor I bought came with holes and the pins not attached. I do not have any soldering skills and searched for a solution. I ended up wrapping tinfoil around each of the small pins to increas their diameter and jamed it in the sensor's holes. As far as I can tell, it is working. It is a bit tidious and is clearly not a long term solution but ended up working at least to test my sensor and set it up.
I couldn't find any solution online without having to buy something else so here you go, if any one is looking for a quick solution with house hold items. Hope it can help any one in need.
(make sure the tinfoil is not in contact with other pins or other metalic part of your sensor as it could cause shorts.... be careful not to damage your devices :) )


text:
SPI communications with an Yost Labs IMU
I am pairing an Arduino UNO with a Yost Labs 3-Space Sensor Nano, the user manual for said sensor can be found here and the user manual for the sensor family here (kinda confusing, Yost Lab's documentation contradicts itself IMO)
This is my code, pretty straight forward (although this is my first time working with SPI). I am 100% sure the wiring is correct, and I have attached a diagram of my wiring here. The logic voltage converter I am using is this
I believe that as per the user manual, this should successfully return 3 floats in 4 bytes each, corresponding to the filtered euler angles of pitch, yaw, and roll. However, all I am reading is bytes full of 0xFF (or 11111111 in binary) which I believe corresponds to null / no command.
Are there any visible errors in my code?
#include <SPI.h>

SPISettings settings(6000000, MSBFIRST, SPI_MODE0 ); //variable to hold SPI settings
//Set Slave Select, MOSI, MISO, CLK
const int CSN = 10;
const int SI = 11;
const int SO = 12;
const int CLK = 13;

// Needed to convert the bytes from SPI to float
union u_types {
   byte b[4];
   float fval;
} data[3];  // Create 3 unions, one for each euler angle

void setup() {
 //Set Pin Modes
 pinMode(CSN, OUTPUT);
 pinMode(SI, OUTPUT);
 pinMode(SO, INPUT);
 pinMode(CLK, OUTPUT);
 //Set Slave Select High to Start i.e disable chip
 digitalWrite(CSN, HIGH);
 //Initialize SPI
 SPI.begin();
 //pour a bowl of serial
 Serial.begin(9600);
}

//function to transfer commands through SPI
byte transferByte(byte byteToWrite) {

 byte Result = 0x00;
 digitalWrite(CSN,LOW);
 delay(1);
 Result = SPI.transfer(byteToWrite);
 delay(1);
 digitalWrite(CSN,HIGH);
 return Result;
}

//function to swap endian
void endianSwap(byte temp[4]) {
 byte myTemp = temp[0];
 temp[0] = temp[3];
 temp[3] = myTemp;
 myTemp = temp[1];
 temp[1] = temp[2];
 temp[2] = myTemp;
}

void loop() {
 SPI.beginTransaction(settings);

 // Clear the internal data buffer on the IMU
 byte result = transferByte(0x01);
     Serial.print("Cleared internal buffer. Result: "),Serial.println(result);

 // Send start of packet:
 result = transferByte(0xF6);
      Serial.print("Send start of packet. Result: "),Serial.println(result);

 // Send command (tared euler angles)
 result = transferByte(0x01);
      Serial.print("Send commmand 0x01. Result: "),Serial.println(result);

 // Get status of device:
 result = transferByte(0xFF);
      Serial.print("Status of device. Result: "),Serial.println(result);

 while (result != 0x01) {  // Repeat until device is Ready
   delay(1);
   result = transferByte(0xFF);
   Serial.print("Status of device. Result: "),Serial.println(result);
 }

 // Get the 12 bytes of return data from the device:
 for (int ii=0; ii<3; ii++) {
   for (int jj=0; jj<4; jj++) {
     data[ii].b[jj] =  transferByte(0xFF);
     delay(1);
   }
 }

 SPI.endTransaction();

 for( int mm=0; mm<3; mm++) {
   endianSwap(data[mm].b);
 }

 Serial.print("fval 1:"), Serial.println(data[0].fval);
 Serial.print("fval 2:"), Serial.println(data[1].fval);
 Serial.print("fval 3:"), Serial.println(data[2].fval);

 delay(3000);
}

Please don't post the same question twice https://arduino.stackexchange.com/questions/76891/spi-communications-with-an-imu. If you have additional information, edit your post to add the information.

You almost certainly shouldn't raise CSN after each byte, only after the entire packet.
Although the data sheet is not explicit the chip select is usually used to frame an entire command. As it is at the moment it keeps starting a new transaction.
I like the comment in the data sheet that "...the 3-Space Sensor will not work properly in outer space or on planets with no magnetic field".

I've tried moving the CSN raise around and no luck, where would you put it? Intuitively, I would do CSN low and the start of the void loop, and high right at the end.

It should go low before the first command byte of a packet and be raised after the last data is received. The data sheet is very difficult to understand, they mention sending 0x69 to read SPI data but no reference to that elsewhere. Have you tried using one of the other modes of data transfer - serial ASCII would be the easiest to debug.

just tried low before the first command byte and raised after the last data is received, did not work. have not tried ASCII (I also have 0 experience with that)


text:
Arduino blocks when serving web pages
I have an Arduino sketch that serves an HTML web page using the standard Ethernet library (https://github.com/arduino-libraries/Ethernet) and the Ethernet Web Server library (https://github.com/khoih-prog/EthernetWebServer). I am serving HTML stored directly in the Arduino memory. The processor is the ARM Cortex M0+. Here is an extract from the code I am using:
#include <Ethernet.h>
#include <EthernetWebServer.h>

#define webpage "Big HTML string"

EthernetWebServer webServer;
void setup()
{
  SerialUSB.begin(9600);

  Ethernet.begin(settings.macAddress, settings.ipAddress, settings.ipAddressDns, settings.ipAddressGateway, settings.ipAddressSubnet); // 'settings' is a struct declared elsewhere
  webServer = EthernetWebServer(settings.portHttp);

  webServer.on("/login", [&webServer]{ // /login handler
    webServer.send(200, "text/html", webpage);
  });
}

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

When I refresh the page (send GET request) more than 9 times or so the Arduino freezes. I have checked by placing SerialUSB.println() inside the code and it seems to stop before even entering the "/login handler" callback.
Does anyone know the cause or at least how to solve this?

the EthernetWebServer library is very new. create an issue in the GitHub repository


text:
pinout for stm32duino with bluepill
I am running the blinking LED program with stm32duino, and an STM32.  By trial and error, and a bit of debugging, I have worked out the following:

pin C13 blinks as well as the built in LED
(except my external LED is on the built-in LED is off)
the constant LED_BUILTIN equals 17

I found this pinout: https://stm32duinoforum.com/forum/wordpress/wp-content/uploads/2016/07/The-Generic-STM32F103-Pinout-Diagram.pdf

But it says nothing about C13 being pin 17.
Does anybody know where to look to find out where the arduino pins line up to the codes on the board?

In the source code. Look around for the variants in the source code (on github?) and find where the pinouts are. I can't tell you what file to look in, because all cores are different.

regarding your external LED ... read the notice about the pins with the warning symbol (yellow triangle with an exclamation mark)

OK if this helps anybody, they give you constants for every pin that look like PC14 for the one that says C14, so you don't need to worry about the integers that they assign to the pins.
I mean there are constants named for the yellow boxes on the above diagram.


text:
AccelStepper library advanced codes!
I was trying to find out how this library can run multiple stepper motors at the same time, and I saw this important function called...
void AccelStepper::setOutputPins(uint8_t mask)
{
    uint8_t numpins = 2;
    if (_interface == FULL4WIRE || _interface == HALF4WIRE)
    numpins = 4;
    else if (_interface == FULL3WIRE || _interface == HALF3WIRE)
    numpins = 3;
    uint8_t i;
    for (i = 0; i < numpins; i++)
    digitalWrite(_pin[i], (mask & (1 << i)) ? (HIGH ^ _pinInverted[i]) : (LOW ^ _pinInverted[i]));
}

why is it using uint8_t? and what is a mask? and Is this line:
digitalWrite(_pin[i], (mask & (1 << i)) ? (HIGH ^ _pinInverted[i]) : (LOW ^ _pinInverted[i]));

sending a step signal to multiple stepper?

How to use multiple steppers depends on your needs. You can sinply define multiple AccelStepper objects and call their run method sequentially. Or you can use the multistepper class, which is also a part of the AccelStepper library

I need to edit the library to get what I want... I want to get feedback of my motors, show encoder real time data on serial monitor... try and test different control methods... I have to know how these codes work.

So your question is not about running multiple steppers, but about understanding that function?

Exactly. I have used the library... I want to customize it.

The setOutputPins() function sets the pins for a pulse for a single stepper. Depending on the used stepper motor a different number of pins has to be set (normal stepper drivers have 2 pins, the ULN2003 and its siblings have 4) in a different way. For that the function first determines the number of pins to use via the _interface member variable of the class.
The mask parameter contains the states of the pins. Each bit represents one pin. If the corresponding bit is set to 1, the pin will be set to an active state. If not, it will be set to an inactive state. Normally an active state (like I have called it here) is HIGH, an inactive state is LOW. But when working with different stepper drivers, some pins might work with an inverted logic. Thus the value (LOW or HIGH) is inverted, if the pin is marked as inverted in the _pinInverted array. This logic is in the line
digitalWrite(_pin[i], (mask & (1 << i)) ? (HIGH ^ _pinInverted[i]) : (LOW ^ _pinInverted[i]));

The idiom condition ? expression : expression represents an embedded if condition. If the condition evaluates to true, the first expression is used, else the second expression. With mask & (1 << i) we are checking, if the ith bit in mask is set. If yes, we use the next expression: HIGH ^ _pinInverted[i]. Here the ^ bitwise XOR operator is used to invert the value, if _pinInverted[i] is set to 1 (and thus marked the pin as inverted). If _pinInverted[i] is zero, the value will stay as it is. The handling of the LOW value is similar.
For understanding that better, you might want to read more about bitwise operators, if you haven't already done so.

why is it [the mask parameter] using uint8_t?

uint8_t is the smallest type, that could be used: 1 byte. As each bit represents one pin, and the library supports steppers with up to 4 pins, only 4 bits are needed at max. Thus using the smallest type with 8 bits is sufficient.

Is this line sending a step signal to multiple stepper?

No, it is setting the pins of a single stepper motor. Each instance of the AccelStepper class represents a single stepper motor. Thus every function in it also only talks to one single motor. You haven't really explained, how you want to add the feedback functionality. But you should not change the AccelStepper class to handle multiple motors. That does not make sense to me. Each motor has to be controlled individually and this class is there to capsule the work behind that. Thats the idea behind making a class for this.
I guess you want to drive multiple motors, each with it's own feedback loop. So then you first need to change the AccelStepper class for supporting that feedback loop. How this is done depends very much on your type of feedback loop. Also the setOutputPins() method is not a good place for that. It is a very low level function. You need to start further up in the call chain, maybe in the step() method or the runSpeed() method (this really depends on how you want to handle the feedback). Also you need to write methods to set up and handle the encoders input. You may need to configure timers and/or interrupts for reading them correctly.
For then supporting multiple stepper motors, you could still look into the MultiStepper class. You could change it to fit with your changes in AccelStepper or write your own wrapping class. That mostly depends on how you want the multiple steppers to behave.


text:
Sending minimal data between two Arduinos far away from each other
Problem: I need to send small integer numbers (single-digit numbers suffices) between two arduinos located approximately 50-60m away from each other.
The connection must be made through cables. I have read that the mentioned distance is too long for using serial communication. I do not care if the method is not fast, delays up to one or two seconds are ok for this. If it helps: the devices (Arduino UNO or similar) will run not  yet written codes for a simple alarm system (with no cameras/images).

Question: What is a good way to this?

My efforts: I thought a couple of alternatives to solve this problem. Both involve the use of PWM signals sent from a device A to another B.

One of them requires some DAC in A  and read the analog input in B. The values read are then mapped to the small integer lists. I found some disadvantages with this approach:

Increment of hardware complexity and cost. Although I have read that the digital to analog conversion can be made with cheap capacitors I would have many problems to acquire them because of the lock-down of my country.
Probably I will need to  do many test to set up the mapping procedure  due to voltage drop.

The second is just read the digital input in B many times during a fixed period (e.g. 0.1 or 1 second) and average the values that were read in that period. My bet is that the devices are not synchronized and then the average (times 1023) in such longs periods would be close to the value sent by analogWrite(somepin, value). Finally, the accepted value would be the closest value in alist of acceptable values.
Example: For passing one of the numbers 0,1,2 or 3 the A device will output 0, 341, 682 or 1023, respectively. Eg. for passing "1" A will do analogWrite(somepinA, 341). B will read int lecture = digitalRead(somepinB) and get the time average of lecture for some time period. After multiplication by 1023 it could return something like "312". Then, it must find the value in [0, 341, 682,1023] closest to 280 (341) and map to 1.

Even if they were synchronized some way, I think that I could send 0 or 1 using random numbers or digitalWrite(somepinA) (Is it possible? Advantages? Disadvantages?)

I'm a novice in this field so I do not known if there is something wrong with my approach. I would also appreciate if a better alternative is proposed.
Thanks in advance.

RS485 RS485 RS485

you can use 10 levels of current, which unlike voltage, is the same on both ends.

@dandavis, I am not sure what you mean, sorry.

look into "4-20ma" reading for example. it's used over very long distances. in a loop, current is the same everywhere, so if the sensor provides a current instead of a voltage, you can read that current far away. the simplest is to read the drop over a known resistor. Even the on-board ADC should be able to distinguish 10 stable voltage levels. Then you need to turn sensor voltage to current, using a ready-made driver, or a simple opamp circuit.

one of the answers at  https://diy.stackexchange.com/questions/197992/re-writing-a-router-into-the-main-control-panel gave me an idea to use a modem ...   google arduino fsk modem module

also, check out https://www.pjon.org/SoftwareBitBang.php

RS-485 is best (you can buy some modules for this from Adafruit, Amazon, eBay, etc), but you can use the built-in hardware RS-232 serial UARTs from each on pins 0 and 1 so long as the baud rate is really really low. The lower the baud rate, the longer the range can be because lower baud rates reject noise better (and the longer the cable, the worse the noise, since the longer the cable the more it acts like an antenna and an inductor and a capacitor). Here are some rough estimates of how far you can transfer regular-logic-level unbalanced RS-232 signals:

Source:
https://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/serial-distance.html
If this trend continues, you should be able to get like 120m at 1200 bps (baud), 240m at 600 bps, 480m at 300 bps, etc. maybe even up to > 1000m at 50 bps. I don't think the trend will continue like that, and we are using 5V TTL logic (signal voltage) levels here instead of RS-232's +/- 12V or so, so our logic levels are much worse and will have less range, so just use 50 baud and give it a shot:
// do on each Arduino
Serial.begin(50); // 50 baud = 10 bytes/sec throughput rate; see below

Note that for 8-N-1 serial communication baud rate, which is the default on Arduino, there are 10 bits per byte sent over the wire. This is because there is "one start bit, the eight data bits, and the one stop bit" for every 8-bit byte sent. That's an effective throughput data rate of 80%. This means a baud rate of 50 bps (bits per second) only can transmit 50/10 = 5 bytes per second. That's it! That's suuuuuper slow, but if it's fast enough for your application, it's fast enough!
I hypothesize 5V TTL twisted quad RS-232 communication between two Arduinos would have a maximum range at 50 baud of about 1000m/(24V span for regular RS-232 / 5V span for 5V TTL logic RS-232) = 208m. Just a crude guestimate. Please report back any findings you get from your experiments. I'd like to hear about it.
Assuming that this all does work, it would also be useful to start increasing the baud rate on each device until the data starts getting corrupted. Back off on the baud rate a little, and that's your maximum baud rate. Take that maximum baud rate and divide by 2 or 3, and that's your maximum "safe" baud rate perhaps. If you need throughput that is as high as possible, then that's what I'd do. Ex: maybe in your case 50 baud works just fine, so you increase it. At 1000 baud you start seeing corrupted data, so you back off to 800. At that point you no longer see corrupted data. So, divide that by 2 or 3 and you get a maximum "safe" baud for your setup of perhaps 800/3 = 267 to 800/2 = 400.
Try using a twisted quad cable (wires are twisted together in groups of 4) to reduce noise and increase range, and set the baud rates on each Arduino to like 50. You will need 3 wires connected between the Arduinos:

GND to GND
Tx to Rx
Rx to Tx

Power them each separately with ungrounded power supplies.
Communicate via Serial.write() and Serial.read() (so long as Serial.available() shows some data is available in the read buffer).
More on balanced vs unbalanced lines, and why I recommend "twisted quad" wire:
Normally, RS-232 is considered to be an unbalanced line transimission system. This means the impedance in the transmission wire is not equal to the impedance in the return wire, which would be a common ground between the sender and receiver, in conjunction with (in parallel with) an Earth ground through the building wiring and/or actually through the Earth...literally, the dirt you walk on. By powering each Arduino with an ungrounded power supply, such as a 2-prong power supply, however, which is common, there is no Earth ground connected to the Arduino. Furthermore, by only having a single transmission line active at any moment between two Arduinos, you have just balanced the transmission between them. Now, the out path is a single Tx signal from one Arduino to the other, and the return path has matching impedance, as it is your single, common GND wire between the two Arduinos. You now have balanced line RS-232 TTL logic level transmission between the two Arduinos. Balanced line transmission can have improved noise rejection and range by using a twisted pair between the two lines. In this case, however, there are 3 lines: Tx --> Rx, Rx --> Tx, and Gnd --> Gnd. So, you should use twisted quad wire, which means 4 wires at once are twisted together. Connect all 3 lines to the same twisted quad bundle. Again, remember, this assumes only one Arduino is transmitting at a time on one single wire in one single direction at a time (so as to not negate your return current through the GND line when transmitting on two lines, one in each direction, or double your return current through the GND line when transmitting on two lines each in the same direction [assuming you had multiple UARTS on each device]), thereby this usage creates a balanced line system since they also aren't truly grounded through a 3-prong grounded power supply. If these 2 requirements are met (1 Arduino transmits at a time, and at least one of them is not grounded to the building wiring), use twisted quad wire, as the system is balanced line communication. If it is not the case, because you are transmitting from each Arduino to the other at exactly the same time, or because both (not one) Arduinos are grounded to the building, thereby offering an alternative return path through the building ground wiring, then twisted quad cable will not benefit you, and you should use regular untwisted wiring.
Having said all that, experimentation is the real boss here. Try it out. if I didn't have twisted quad wire I'd try twisted pair, and if I didn't have twisted pair, I'd try untwisted wire.
Regarding your approach about using PWM to produce an analog output to be read by the receiving end:
Using PWM to produce an analog voltage to be read by the receiving end is an interesting approach. Without filtering, I think what you'd be doing is producing tremendous noise, however, literally producing electromagnetic radiation (think like low frequency radio or TV waves or something), where this huge 60m wire is your broadcasting antenna. If you put a 20k~50k resistor right at the sending end, however, and a 1uF capacitor right at the receiving end, however, to filter this PWM into an analog output immediately at the sending end, I think it would then eliminate your antenna effect where you are broadcasting something, and work much better, but still be highly susceptible to external noise influencing it. Give it a shot, but I suspect a simple set of digital pins to set HIGH or LOW on different pins to match different states would be much much much better than any analog signal at those lengths, with a 50 baud serial signal being the next best for signal-to-noise thereafter.
So, in order of best to worst signal-to-noise ratio (SNR):

differential pair (referenced to each other) digital HIGH/LOW values to represent states, which you update very slowly
RS-485 differential pair serial transmission
Note: for all of the following really low-speed digital signal sending scenarios, you might try it with the low-pass filter shown in the schematic below too, as it may help reject noise.
single-ended (referenced to GND) digital HIGH/LOW values to represent states, which you update very slowly
super low-speed SPI (including bit-banging it); ie: declare any digital pin a CLOCK_PIN, and any other digital pin a DATA_PIN. Set a clock pin LOW, set a data pin HIGH, set the clock pin HIGH. The clock transition tells the receiver (you have to code this up) to read the data pin, so you just read a 1 bit. Set the data pin LOW, set the clock pin LOW. The clock transition tells the receiver to read the data pin, so you just read a 0 bit. Leave the data pin low, set the clock pin HIGH again. You just sent another 0 bit, etc etc. Send data like this really slowly. It will work at great lengths--even better than asynchronous serial since it's synchronous.
asynchronous serial (+/- 12V true RS-232) at 100 baud
asynchronous serial (+/- 12V true RS-232) at 50 baud
asynchronous serial (5V TTL RS-232) at 50 baud
asynchronous serial (3V TTL RS-232) at 50 baud
analog value filtered with resistor and capacitor low-pass RC filter; update: I'd try this filtering layout for sending analog values via PWM (see schematic below, but use the higher resistor value I describe in my bullets underneath the schematic, rather than the lower value I show in the schematic); the filter may also be beneficial to help filter noise when doing low-speed digital communication too, so give it a shot in your 50-baud rate serial setup above too:

Send with analogWrite() (PWM); receive with analogRead().
Report back on this too please. I'm very curious if it would work.

unfiltered PWM---square wave antenna broadcasting who knows what--could result in an interesting broadcasting system for you. Add a transistor and you could really amp up the power and broadcast some interesting signals out! Get some good high power going here (1W~10W+) and maybe even get the government to find out who's jamming GPS and cellular? I don't know: could be interesting!

Schematic of low-pass RC filter to reduce noise between the two Arduinos when sending really low-speed digital signals (better), or slowly-changing analog signals (worse) between the two sides:

simulate this circuit – Schematic created using CircuitLab

For filtering the digital signals (ex: 5V TTL pseudo-RS232 serial at 50 to 100 baud):

Use 470 Ohms for each resistor, as shown above.
This results in a cutoff freq of 847 Hz, so stay below ~169 baud (cutoff_freq/5 = 847Hz/5 = 169 or so) for digital signal sending through this filter.

For filtering analog signals sent via analogWrite():

Since most Arduino pins have a PWM Frequency of 490 Hz, we need a cutoff frequency of ~490Hz/10 = 49Hz or lower to cleanly filter out the PWM frequency and result in a true analog output.
Using the calculator linked-to below, that means you should use R values of at least 10k each, which results in a cutoff freq. of 40 Hz. You can use 20k resistors each too, for a cutoff freq. of about 20 Hz.

To increase cutoff frequency to allow higher baud rates, decrease either R or C or both.
For a cutoff frequency calculator, see: https://electronicbase.net/low-pass-filter-calculator/#rc-low-pass-calculator --> "RC Low Pass Filter Calculator" --> enter, for example, 940 Ohms (470 x 2) as the resistor value and 0.2uF (0.1uF x 2) as the capacitor value to see that the resulting cutoff frequency for this low-pass filter is 846.57 Hz.

I'm no filter expert, but this is what I'd try. If someone sees some glaring errors in this filter or ways to improve it, please comment below the answer.
Extras:
Here's the Bode plot for the above series filter I show except with a 1k resistor and 0.1uF (100nF) capacitor followed by the same thing again. The purple line is the voltage we care about. Source: godfreyl, here.

The cutoff frequency here is 398Hz, which is where the -3db drop occurs, which corresponds to the half power and 70.7% voltage attenuation point. (sqrt(0.50) = 0.707, so 0.707^2 = 0.5)). You can read more about cutoff frequency here.

Additional reading:

https://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/serial-distance.html
Google search for "is rs232 balanced?"
https://www.idc-online.com/technical_references/pdfs/data_communications/tutorial_2.pdf
http://www.iec-usa.com/Browse05/DTBALUN.html
https://en.wikipedia.org/wiki/Signal-to-noise_ratio

twisted pair for TTL?

Well, no: I misspoke. I should have said "twisted quad" wire. I've updated my answer and provided detailed justification for that recommendation.

Just a point of terminology: “5V TTL” and “RS-232” are incompatible terms; a link can be either but not both at the same time. The built-in hardware UART is 5V TTL, therefore not RS-232.

I'm trying to convey the information that it is asynchronous serial, following the exact bit patterns and protocol described in RS-232, except only the logic levels are different. "5V TTL" says nothing about the protocol, it means only "5V logic levels." You can have "5V TTL SPI", "5V TTL I2C", "5V TTL Dalls One-Wire", "3V TTL SPI", "5V or 3V TTL you-name-it", but "5V TTL RS-232", though technically inaccurate as you state, is the most accurate and informative representation of the setup in my opinion, because it describes the voltage, hardware, and protocol in 3 words.

I've had a problem with these terms for years, because of these discrepancies, so I'm choosing to say it in the most informative (and as accurate as is possible while being informative) way. "5V TTL" overrides the logic level portion of the RS-232 specification. In your experience, is there a better way to say it, while still conveying the exact protocol and bit information, just at a different logic level?

I tend to use “asynchronous serial”, or just “UART”, although the latter refers to the hardware port. For example: “you can use the built-in hardware UART”, “I hypothesize 5V TTL twisted quad serial communication [...]” (at this point it is already clear it's from the UART), “5V span for 5V TTL asynchronous serial”. Then it could be that some people don't know what those terms mean...

Asynchronous serial isn't a bad way to say it, but it's still more ambiguous than the way I said it. There are many forms of asynchronous serial, and RS-232 protocol is only one of them. Any communication protocol that runs without a shared clock or auto-clocking from the data rate is asynchronous. Again, in my wording, saying "RS-232" narrows this down to just one form of asynchronous serial protocol, and I "override" the default voltage levels for it by explicitly stating "5V TTL", where again, just "TTL" isn't enough either. Anyway, "asynchronous serial" is fine too, just less specific.

+1 Thank you for your very enlightening explanation! I read it carefully and also I read the linked contents. The approach I will follow depend heavily on the local product availability and prices. I could not find the twisted quad wire in my country (at least in "our eBay"). I think I will go for the RS-485 but  I'll also do some tests with RS-232, just to play around. I am curious about your opinion about if the method I suggested could work (even if it's not the best choice) or if it has any major misconceptions.

I addressed your PWM question just now in the bottom of my answer. Report back please if you try my recommended approach. I'm very curious about it now. Just remember, sending square waves down a long line is...a wireless broadcasting antenna. The lower the frequency, the longer the antenna needs to be to broadcast properly. Has to do with matching the frequency and the wavelength to the speed of light and the antenna length or something like that to get a good wireless signal broadcasted. So, you'd need to filter it to try NOT to broadcast wireless signals that way.

I just expanded my signal-to-noise ratio list from 3 to 10 items. This answer just keeps growing.

@user1420303, a UTP cable used for networks has 4 twisted pairs. I am sure you can buy RS485 adapters for Arduino. don't waste time attempting to make the UART work on long cable.

It appears the easiest would be to use a simple CAN transceiver on each end, one set to transmit and the other to receive. You did not mention bidirectional communications although both Physical layers suggested below will support that quite easily. The electrical characteristics of the CAN bus cable restrict the cable length according to the selected bit rate. You can use cabling up to 250 meters with the baud rate of 250 kbit/s. The maximum bus length with a bit rate of 10 kbit/s is 1 km, and the shortest with 1 Mbit/s is 40 meters.
Another approach would be to used RS485. RS485 is popular for inexpensive local networks, multidrop communication links and long haul data transfer over distances of up to 4,000 feet. The use of a balanced line means RS485 has excellent noise rejection and is ideal for industrial and commercial applications. Note these typically are driven with Async signals from a uart or similar device. Software serial would work great and leave the onboard serial port for debugging. the Async communications does the syncing automatically, nothing for you to do, just keep the baud rates the same.

The CAN protocol seems significantly more complex than the typical UART (async serial) over RS-485, and the Arduino has no hardware support for it. Or are you suggesting to do UART over the physical layer of CAN?

Great you have it. Use the physical layer but what you send on it is up to you. I believe in your case it will be a simple 1 way transmission to a slave. The baud rate you use is whatever you like and is convenient. I generally run software serial at 9600 baud and my terminal at 115200 that way the terminal can get whatever is sent without flooding. Have fun and let us know how it works out.


text:
multiple working modes for motors
with this sketch i can independently control 4 dc motors cw, ccw, and rotating each of them until the hall sensor related to it detects an magnetic field. what im trying to do now is to create a mode of operation in wich:just pressing button "nine", and first motor starts rotating until its hall sensor detects a magnetic field, after five seconds, the second motor acts the same and so on, ather the fourth motor, after 5 seconds, the first motor starts again. i spent like 5 hours trying but still cant do it. maybe for a pro its not that big deal cose its my first serious Arduino project.
#include <TLE94112.h>
#include <Tle94112Motor.h>
#include <IRremote.h>

#define unu 0x1
#define doi 0x2
#define trei 0x3
#define patru 0x4
#define sound 0x55
#define picture 0x54
#define feature 0x50
#define install 0x52
#define cinci 0x5
#define sase 0x6
#define sapte 0x7
#define opt 0x8
#define tv 0x63
#define av 0x56
#define e 0x60
#define eo 0x42

int RECV_PIN = 2;
int hallSensorPin1 = 3;
int hallSensorPin2 = 4;
int hallSensorPin3 = 5;
int hallSensorPin4 = 6;
int state1;
int oldState1 = 1;
int runMode1 = 0;
int state2;
int oldState2 = 1;
int runMode2 = 0;
int state3;
int oldState3 = 1;
int runMode3 = 0;
int state4;
int oldState4 = 1;
int runMode4 = 0;

Tle94112 controller = Tle94112();
Tle94112Motor motor1(controller);
Tle94112Motor motor2(controller);
Tle94112Motor motor3(controller);
Tle94112Motor motor4(controller);

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{ irrecv.enableIRIn();
  controller.begin();

  motor1.connect(motor1.HIGHSIDE, controller.TLE_HB1);
  motor1.connect(motor1.LOWSIDE, controller.TLE_HB2);
  motor1.setPwm(motor1.HIGHSIDE, controller.TLE_PWM2);
  motor1.setPwmFreq(motor1.HIGHSIDE, controller.TLE_FREQ200HZ);

  motor2.connect(motor2.LOWSIDE, controller.TLE_HB3);
  motor2.connect(motor2.HIGHSIDE, controller.TLE_HB4);
  motor2.setPwm(motor2.HIGHSIDE, controller.TLE_PWM2);
  motor2.setPwmFreq(motor2.HIGHSIDE, controller.TLE_FREQ200HZ);

  motor3.connect(motor3.HIGHSIDE, controller.TLE_HB5);
  motor3.connect(motor3.LOWSIDE, controller.TLE_HB6);
  motor3.setPwm(motor3.HIGHSIDE, controller.TLE_PWM2);
  motor3.setPwmFreq(motor3.HIGHSIDE, controller.TLE_FREQ200HZ);

  motor4.connect(motor4.LOWSIDE, controller.TLE_HB7);
  motor4.connect(motor4.HIGHSIDE, controller.TLE_HB8);
  motor4.setPwm(motor4.HIGHSIDE, controller.TLE_PWM2);
  motor4.setPwmFreq(motor4.HIGHSIDE, controller.TLE_FREQ200HZ);

  motor1.begin();
  motor2.begin();
  motor3.begin();
  motor4.begin();
}
void loop()
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();

    if (results.value == unu || results.value == 0x801 || results.value == 0x2049) {
      motor1.start(63);
      runMode1 = 0;
    }
    if (results.value == cinci || results.value == 0x805 || results.value == 0x2053) {
      motor1.start(-63);
      runMode1 = 0;
    }
    if (results.value == tv || results.value == 0x63 || results.value == 0x2111 || results.value == 0x83F || results.value == 0x3F) {
      motor1.coast();
      runMode1 = 0;
    }
    if (results.value == sound || results.value == 0x55 || results.value == 0x2103 || results.value == 0x837 || results.value == 0x37) {
      motor1.start(63);
      runMode1 = 1;
    }
    if (results.value == doi || results.value == 0x802 || results.value == 0x2050) {
      motor2.start(63);
      runMode2 = 0;
    }
    if (results.value == sase || results.value == 0x806 || results.value == 0x2054) {
      motor2.start(-63);
      runMode2 = 0;
    }
    if (results.value == av || results.value == 0x56 || results.value == 0x2104 || results.value == 0x838 || results.value == 0x38) {
      motor2.coast();
      runMode2 = 0;
    }
    if (results.value == picture || results.value == 0x54 || results.value == 0x2102 || results.value == 0x836 || results.value == 0x36) {
      motor2.start(63);
      runMode2 = 1;
    }
    if (results.value == trei || results.value == 0x803 || results.value == 0x2051) {
      motor3.start(63);
      runMode3 = 0;
    }
    if (results.value == sapte || results.value == 0x807 || results.value == 0x2055) {
      motor3.start(-63);
      runMode3 = 0;
    }
    if (results.value == e || results.value == 0x60 || results.value == 0x2108 || results.value == 0x83C || results.value == 0x3C) {
      motor3.coast();
      runMode3 = 0;
    }
   if(results.value==feature||results.value==0x50||results.value==0x2098||results.value==0x832||results.value==0x32){
      motor3.start(63);
      runMode3 = 1;
    }
    if (results.value == patru || results.value == 0x804 || results.value == 0x2052) {
      motor4.start(63);
      runMode4 = 0;
    }
    if (results.value == opt || results.value == 0x808 || results.value == 0x2056) {
      motor4.start(-63);
      runMode4 = 0;
    }
    if (results.value == eo || results.value == 0x42 || results.value == 0x2090 || results.value == 0x82A || results.value == 0x2A) {
      motor4.coast();
      runMode4 = 0;
    }
    if (results.value == install || results.value == 0x52 || results.value == 0x2100 || results.value == 0x834 || results.value == 0x34) {
      motor4.start(63);
      runMode4 = 1;
    }
  }
  state1 = digitalRead(hallSensorPin1);

  if (state1 == HIGH) {
    oldState1 = 1;
  }
  if (state1 == LOW && oldState1 == 1 && runMode1 == 1) {
    motor1.coast();
    oldState1 = 0;
  }
state2 = digitalRead(hallSensorPin2);

  if (state2 == HIGH) {
    oldState2 = 1;
  }
  if (state2 == LOW && oldState2 == 1 && runMode2 == 1) {
    motor2.coast();
    oldState2 = 0;
  }

  state3 = digitalRead(hallSensorPin3);

  if (state3 == HIGH) {
    oldState3 = 1;
  }
  if (state3 == LOW && oldState3 == 1 && runMode3 == 1) {
    motor3.coast();
    oldState3 = 0;
  }
  state4 = digitalRead(hallSensorPin4);

  if (state4 == HIGH) {
    oldState4 = 1;
  }
  if (state4 == LOW && oldState4 == 1 && runMode4 == 1) {
    motor4.coast();
    oldState4 = 0;
  }
}

what problem are you having? ... unable to detect 9 being pressed? ... something else? ... we are not going to spend time guessing what you are observing

Timed things are normally done with the millis() or micros() function, like in the BlinkWithoutDelay example. There are tons of tutorials out there about that. For writing code for multiple modes, you should look into the structure of an FSM (Finite State Machine). That is a simple but powerful concept, also often described on the web. I have also once written a longer answer about FSMs here, with diagrams and all. Understanding that concept will really help you


text:
Arduino I2C external 32Kb fram data organization
Hey guys I am a noob when it comes to data structures and storing types of data, I have been recently working on a project where I needed to store long term data for later retrieval. I decided to buy a Adafruit 10$ 32kb i2c fram Which works, it can store a byte Of data per address which I can successfully do, I can also read those bytes on any address no problem.
One issue I first came across was storing floats into the chip which only took bytes, After googling I managed to spit a float using a union successfully and also storing those in a 4 byte array. Now I did this with 3 different float values which means every 4 bytes stored is basically one split float value.
The second issue is how do I retrieve this data in an organized way and also as a float. I found out you can use a union to do the opposite as well. But how do I tell my code to read every 4 bytes and convert back to float?
Is there a system that can allow me to store data in a structured way using the arduino? Like a time stamped data using an external rtc? Such that when I click retrieve it will print that data in an organized fashion.

It is unclear to me, where exactly the problem lies. Reading all 4 bytes, that you need for your float, means just reading 4 bytes sequentially. Depending on how your FRAM does communication, you could maybe do that in one single reading transmission. You can easily write the read data into a union and then read the float from it. That's just exactly the opposite way of splitting the float up. And surely, you could save a timestamp with each float, but why? The FRAM is just a piece of sequential data storage, just like any other memory. Do you want a filesystem here?

It'll be easier if you use a struct, not a union. Store all the data you want to preserve in a struct, then cast a pointer to it to be a byte pointer and just treat it as an array of bytes and read and write those bytes to the FRAM.
The union you were using explicitly did the same thing, but it's not easy to scale to multiple items.
Some caveats about what you can safely keep in the struct:

do not store pointers in it. A char array is fine because the entire array will take up space in the struct. A char * is not because all you'll save is the value of the pointer, not what it points at.

do not store objects (like String) in it. You don't know (and shouldn't know) how the object is composed internally. If need to use objects, they should have serialize and deserialize methods which would store or restore the contents of an object into an array of bytes which you could then store or restore with the FRAM.

Also remember that the C/C++ sizeof function (used below) tells you the size of thing at compile-time. So if you use it on a struct it will tell you the number of bytes it takes to store the struct. If you use it on a char *, it will tell you the number of bytes in a pointer to a char, not the number of bytes in the C string that the char * points at. If you use it on an object - like String str; sizeof(str); - it will tell you how many bytes it takes to store the String object, which will include the length of the string it stores.
Psuedo-code follows. There are more compact ways to write this; I'm aiming for clarity here.
#include <Arduino.h>

struct program_data {
  float first_thing;
  unsigned long second_thing;
  char third_thing[55];
  char fourth_thing;
  uint16_t fifth_thing;
} data;

void save_data(struct program_data *data_ptr) {
  byte *ptr = (byte *)data_ptr;

  for(size_t i = 0; i < sizeof(struct program_data); i++)
    store_byte_in_fram(ptr[i], i);
}

void restore_data(struct program_data *data_ptr) {
  byte *ptr = (byte *)data_ptr;

  for(size_t i = 0; i < sizeof(struct program_data); i++)
    retrieve_byte_from_fram(ptr[i], i);
}

// call when you want to save your data
  save_data(&data);

// call when you want to restore your data
  restore_data(&data);

Dude you are incredible, first off thank you for replying. Second this was so easy to understand! Thank you dude I will try it out and tell you.

I have an external RTC that I want to add to it so that every 5 or 10 seconds it will save the struct of values and a time associated with it. Would this overwrite A specific sector or can it shift leaving the previous data?

Good question. RTCs usually use battery-backed static RAM where it wouldn't matter if it's overwriting the same addresses. It really depends on the system and the interface to it, though. If you're addressing memory directly then writing to the same address should be the same place in memory.

Small concern. That approach might fail if it is not granted that the structure is packed

@brtiberio why do you think that would be a problem?


text:
Is it possible using a hc-05 bluetooth module as master and pair it to a hc-06 module?
I have configured a hc-05 bluetooth module as master and a hc-06 module as slave an since the LED on the hc-05 is blinking in a 2s delay they should be paired but no matter what I do I can't send data between the two Arduinos.
Here is the code for the slave
(I use the example code from the EasyTransfer module github repo: https://github.com/madsci1016/Arduino-EasyTransfer):
    #include <Wire.h>
    #include <EasyTransferI2C.h>

    //create object
    EasyTransferI2C ET;

    struct RECEIVE_DATA_STRUCTURE{
      //put your variable definitions here for the data you want to receive
      //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
      int16_t blinks;
      int16_t pause;
    };

    //give a name to the group of data
    RECEIVE_DATA_STRUCTURE mydata;

    //define slave i2c address
    #define I2C_SLAVE_ADDRESS 9

    void setup(){
      Wire.begin(I2C_SLAVE_ADDRESS);
      //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
      ET.begin(details(mydata), &Wire);
      //define handler function on receiving data
      Wire.onReceive(receive);

      pinMode(13, OUTPUT);

    }

    void loop() {
      //check and see if a data packet has come in.
      if(ET.receiveData()){
        //this is how you access the variables. [name of the group].[variable name]
        //since we have data, we will blink it out.
        for(int i = mydata.blinks; i>0; i--){
          digitalWrite(13, HIGH);
          delay(mydata.pause * 100);
          digitalWrite(13, LOW);
          delay(mydata.pause * 100);
        }
      }
    }

    void receive(int numBytes)

here is the code for the master:
#include <Wire.h>
#include <EasyTransferI2C.h>

//create object
EasyTransferI2C ET;

struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int16_t blinks;
  int16_t pause;
};

//give a name to the group of data
SEND_DATA_STRUCTURE mydata;

//define slave i2c address
#define I2C_SLAVE_ADDRESS 9

void setup(){
  Wire.begin();
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ET.begin(details(mydata), &Wire);

  pinMode(13, OUTPUT);

  randomSeed(analogRead(0));

}

void loop(){
  //this is how you access the variables. [name of the group].[variable name]
  mydata.blinks = random(5);
  mydata.pause = random(5);
  //send the data
  ET.sendData(I2C_SLAVE_ADDRESS);

  //Just for fun, we will blink it out too
   for(int i = mydata.blinks; i>0; i--){
      digitalWrite(13, HIGH);
      delay(mydata.pause * 100);
      digitalWrite(13, LOW);
      delay(mydata.pause * 100);
    }

  delay(5000);
}


text:
I need an example of how to send AT COMMANDS to SIm7000E GPS+LTE module from ESP32 and reading those response in Serial monitor
Actually I need to make HTTPS post request using SIM7000 and ESP32 but the available libraries don't have a function for HTTPS post request, I wanna make this request using AT Commands. I need a example code to send AT Commands to sim7000e using esp32 hardware serial or software serial whichever is the best.
I am using the botlectics library but it has function only for HTTP GET/POST not HTTPS. I am looking for HTTPS request using Sim7000. As there is no function for HTTPS in botletics I thought of sending AT Commands using hardware serial from esp32 to SIM7000 . For example,
HardwareSerial mySerial(1) ,
mySerial.begin(9600,Serial_8N1,13,12)
And I have connected SIM7000 TX RX with esp32 GPIO 13,12.
then I send AT commands like
mySerial.print("AT+HTTPINIT\r");
And I connect FTDI to UOR AND UOT of esp32 which makes Serial.... So no anything done with Serial is with esp32 and writing to mySerial means Sim7000.
I have done this before but with arduino and GSM module through Software Serial and it worked fine.
I think I am missing something in case of ESP32 and Sim7000. In which I need help.

You mean you have already done a HTTPS POST on the Sim7000 using an Arduino? Sound like that to me. The AT commands are the same, irrelevant, if they are sent by an Arduino or an ESP

See there's a difference between http post request and https post request right. I used botletics Adaruitfona library for Sim7000 and it has a function for HTTP post request but not the HTTPS post request.  Now I wanna make HTTPS post request with AT commands because there's no function in that library I stated above. I am new to this world and I am facing issues sending AT Commands to SIM7000 from esp32. It was fine when I used software serial for GSM module and arduino but I am not able to do it with esp32 and sim7000. Regarding this I need help.

Hi @VanshSethi , I read SIM7500/7600/7800 shall work with SSL/HTTPS. Check here: https://simcom.ee/documents/SIM7X00/SIM7500_SIM7600_SIM7800%20Series_SSL_AT%20Command%20Manual_V1.00.pdf

The AT+HTTPINITcommand suite can't be used for HTTPS, you need to use the AT+SHCONF suite. See this Gist for a walkthrough


text:
How I can send data information without work WiFi to LCD?
Hi everyone I am beginning learn coding and the second language English. I have small project I use Arduino uno , esp8266 , dht11 , lcd I2C and use blynk app in my project I have the code and work probably when WiFi ON but I have question How I can get the information data from dht to lcd without open the WiFi. Now I get information ( Temp and humidity ) on LCD when WiFi ON only. How I can make Temp and humidity display on LCD with and without WiFi.
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
char auth[] = "*******************************";
char ssid[] = "***********";
char pass[] = "*********";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // TX, RX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  EspSerial.begin(ESP8266_BAUD);
  Blynk.begin(auth, wifi, ssid, pass);
  dht.begin();
}

void loop()
{
  LCD();
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  Blynk.virtualWrite(V1, t);
  Blynk.virtualWrite(V2, h);
}
void LCD()
{
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" ******************");
  lcd.setCursor(3, 1);
  lcd.print("TEMP: ");
  lcd.print(t);
  lcd.setCursor(3, 2);
  lcd.print("HUM : ");
  lcd.print(h);
}

you just read the tenperarure and humidity and then display the values on the lcd ... why would you need wifi?

because use as IOT by Blynk

So take the code that writes to the lcd out of the function that is called by your timer and simply call it from loop.  Use the blink without delay style of timing with millis to make it happen at one second intervals.  There are thousands of tutorials on how to handle timing on Arduino without blynk.

Thanks dear,,, You can help me more for this because I don't have idea

Start with a simple example that just prints the values from the DHT11 and work your way up from there. The code you included does some very strange and unnecessary things and I do not recommend you re-use it. Where did this code come from?

Thanks I try to make the code easy but still the same problem to display on LCD without WiFi On

I´m working with a nano v3 (clone) and a esp-01 as wifi shield to send data from sensors like dht11, a DS18B20 and a light sensor based on ldr from an hidroponic system and controls a water pump and 1 water heater with a 2 relay module. I use Blynk app to read this data because I don't want to go see an lcd outside the house. So my sketch do somethings similar to yours and others not, obviously. But I´ve got the same problem. I´ll like to run my sketch without need to be connected to blynk like in case I´ve lost connection for some how. I noticed that in your sketch there are some things that

Blynk.connected() returns true when hardware is connected to Blynk Server, so you can guard Blynk code with
if( Blynk.connected() ){
  // do Blynk things here
}

// Update the LCD anywhere outside of the above "if" statement.


text:
If the code used for Arduino can be embedded into a permanent , callable memory, is there a way to create an OS for Arduino that runs on call?
This thought came into my mind on thinking about smartwatches.
Although those I saw on YouTube are really good, they don't seem to provide a real experience of a real smartwatch - one that has an OS embedded in it. If some code in Arduino C/c++ can be compiled into some binary code that works on being called from the flash memory (where the main program resides), is there a possibility that we will be able to make an OS for Arduino ?

see Wear OS https://wearos.google.com

Sure, but you have a very small footprint in which to write this OS.  You only have a very small amount of memory in which to store that code.  So it will have to be a very small OS with very little functionality.

An AVR-based Arduino is a poor choice for writing an "OS" in the modern sense. It's just too resource constrained. It doesn't have enough RAM, it doesn't have enough flash memory, it's too slow, it doesn't have protected memory or paging, it doesn't have video display, it doesn't have a file system, and on and on.
If you look at an Apple II, something like Apple DOS or ProDos gives you an idea of the sort of thing you can do (minus the video output.)
If you want to develop something like a smart watch an ARM processor is a much better choice. It packs a lot more performance into a small package. You might pick an ARM based Arduino, but you would be fighting against the lack of an OS, the lack of preemptive multi-tasking, etc.
As an alternative, a Raspberry Pi has just about everything you need. It doesn't have as many hardware interfacing options as an Arduino, but a LOT more processing power. Likewise, UNIX is a better choice as the basis for the OS for such a device. It is a protected memory OS that is made to run on relatively modest hardware.

If anything an ARM will have more hardware interfacing options as it has more modern peripherals and protocols embedded in it.

Sorry, I was conflating ARM with Raspberry Pi. I edited my answer to treat ARM-based Arduinos sepereately from Pis.


text:
Store & retrieve parameters after sketch update
I have a Generic code for some IOT devices which vary in some parameters ( lets say it is only its MQTT name and subscriptions).
Since I use OTA to update sketch, I'm looking for a way to A) write those parameters into the ESP32/ ESP8266 FS, and B) They will survive an update.
My only solution come into mind is using an SD card which does not get erased after OTA, and I'm looking for a way doing it not involving SD or external memory.
Guy

You say "not involving ... external memory".  Does that include (adding another) I2C devices such as EEPROMs?

@st2000 some are flashed Sonoff’s and some are nodeMcu’s so I rather keep it simple and not change hardware.

There are tutorials on this which infer they are using this library.  But that library's readme says the library has been depreciated. Further, it is not clear how or if the emulated EEPROM storage remains in the same location after updating the application (aka sketch). This is an interesting question.  Does Sonoff already do this?  Maybe looking into that project will provide answers.

@st2000 perhaps writing to a certain location...?

FS is not erased by sketch OTA. and EEPROM emulation library is OK too.

Checking, people have been telling me they have been updating sketches using the eeprom library and it continues to work across updates.  @Guy.D, I think the eeprom library uses address starting from zero or 1.  So likely relative, not absolute addressing.  But I only looked at some example code.

There is no need for an SD card.
You can write all relevant parameters into a file in SPIFFS (e.g. json if you like) before starting the OTA update. During initialization you read the file and set the parameters accordingly.
SPIFFS does not get erased when doing an update (at least that's true for the OTA library that I'm using). If it does get erased in your case, there probably is an option in the OTA lib to disable flash erase, just like there is the same option when uploading a sketch via serial.

Can I upload a data file using OTA, once for each device and after uploading the sketch especially after OTA’s, will it remain?

@Guy.D You probably only need to upload the file once when you initially upload the sketch (you can use the data upload tool in the arduino IDE for this purpose). After that, the file remains in spiffs for ever and can be updated whenever you make an OTA update. Otherwise, there are many ways how you can upload this file: you can download it from your server and save it in SPIFFS, you could also send it to the ESP (which then would be a server) and write it to SPIFFS. The file really doesn't have much to do with the OTA, because it is stored in a completely different flash partition.

@Guy.D ...but yes, it will remain there. That's how I deal with persistent user data, which obviously must not be overwritten by a firmware update.


text:
How to wire L293D chip to a nodeMCU?
How do I wire an L293D motor controller chip to a nodeMCU?
I have tried to follow the instructions from this tutorial: lastminuteengineers.com
One problem. I don't have a 5v pin?
Are there any alternative ways to wire this?
All of the other tutorials i see, only say to use a special other motor driver board with an L293D embedded in it, and with extras connected to the board.

why would you need a 5 V pin? ... you can't power the L293D from the nodeMCU anyway

Yeah. can you wire Vcc1 and Gnd (pin 5) (L293D Breakout) on the L293D to an external source, and not the NodeMCU?

I figured it out. I am putting a logic level converter On the 3v pin to step it up to 5v


text:
Fastest Communication from NodeMCU to Arduino Nano
For one of my projects, I need to transmit data from NodeMCU to my Arduino Nano, in real time, I used S-Bus, but it quite unsatisfies me, as, slight latency is taking place.
I am transmitting a JSON file, with 4 signed 16 bit integeres.
Now,I need to know, what is the fastest and most reliable way to transmit data from NodeMCU to an Arduino Nano. Any detailed description, or even suggestion will be very much helpful. Thanks in advance !

what does the Nano do, what the NodeMcu can't do by itself?

What do you mean with "slight latency" exactly? And what S Bus library did you use? As the library, that I have found uses UART underneath, so with interface did you use at which baud rate?and do you really need to transmit JSON? using a binary protocol wiuld be way faster

If it comes to speed and reliability you have to choose an interface that is handled in hardware on both sides. For the arduino nano you have the following options (nodeMCU supports all of them):

UART:

not very fast (order of 10kbit/s), but it's full-duplex (asynchronous communication in both directions)
implementation is trivial due to Serial.h
long distance (order of meters)

I2C:

not very fast either (order of 100kbit/s), but not full-duplex
implementation is straight forward because both slave and master are implemented in arduino library
only over short distance (order of cm)

SPI:

quite fast (>1Mbit/s), full-duplex
implementation might require some experience (as far as I know, slave mode is not supported by SPI.h)
long distance (order of meters)

Which of those is the best option still depends on your specific requirements, but personally I like SPI very much because it is very fast and stable.

SPI is full duplex. All of those protocols can reach into the megabits-per-second (with the exception of UART if using SoftwareSerial.h which has an upper limit of about 9600 baud).

@Majenko you're right about SPI being full duplex, I will edit my answer. But I doubt that you are able to run either UART or I2C in the order of Mbit/s reliably on an atmega328. Also SPI might work at >10Mbit/s, I just made conservative estimations

Sure you can run it reliably at Mbaud. Why wouldn't you be able to? The fact that it's an 8-bit MCU doesn't mean that the hardware peripherals are slow too. It's more a question of if you can process the data you have received fast enough for Mbaud to make any real-world sense. As long as the baud rate error percentage at both ends of the connection are within tolerable amounts (which can just mean selecting the right baud rate to run at) you can go into the 1-4Mbaud range. The 16MHz clock speed limits your upper end more than anything else.