text:
Get time as 24 hour format from RTC
I have a DS3231 RTC module.
I would like to get the time from the RTC as 24 hour format not 12 hour. The library that I'm using requires that I pass in 2 Boolean values into Clock.getHour(), however changing these values does not change the returned time format.
Code;
/*
DS3231_test.pde
Eric Ayars
4/11

Test/demo of read routines for a DS3231 RTC.

Turn on the serial monitor after loading this to check if things are
working as they should.

*/

#include <DS3231.h>
#include <Wire.h>

DS3231 clock;
bool century = false;
bool h12Flag;
bool pmFlag;
byte alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits;
bool alarmDy, alarmH12Flag, alarmPmFlag;

void setup() {
    // Start the I2C interface
    Wire.begin();

    // Start the serial interface
    Serial.begin(57600);
}

void loop() {
    // send what's going on to the serial monitor.

    // Start with the year
    Serial.print("2");
    if (century) {          // Won't need this for 89 years.
        Serial.print("1");
    } else {
        Serial.print("0");
    }
    Serial.print(clock.getYear(), DEC);
    Serial.print(' ');

    // then the month
    Serial.print(clock.getMonth(century), DEC);
    Serial.print(" ");

    // then the date
    Serial.print(clock.getDate(), DEC);
    Serial.print(" ");

    // and the day of the week
    Serial.print(clock.getDoW(), DEC);
    Serial.print(" ");

    // Finally the hour, minute, and second
    Serial.print(clock.getHour(h12Flag, pmFlag), DEC);
    Serial.print(" ");
    Serial.print(clock.getMinute(), DEC);
    Serial.print(" ");
    Serial.print(clock.getSecond(), DEC);

    // Add AM/PM indicator
    if (h12Flag) {
        if (pmFlag) {
            Serial.print(" PM ");
        } else {
            Serial.print(" AM ");
        }
    } else {
        Serial.print(" 24h ");
    }

    // Display the temperature
    Serial.print("T=");
    Serial.print(clock.getTemperature(), 2);

    // Tell whether the time is (likely to be) valid
    if (clock.oscillatorCheck()) {
        Serial.print(" O+");
    } else {
        Serial.print(" O-");
    }

    // Indicate whether an alarm went off
    if (clock.checkIfAlarm(1)) {
        Serial.print(" A1!");
    }

    if (clock.checkIfAlarm(2)) {
        Serial.print(" A2!");
    }

    // New line on display
    Serial.println();

    // Display Alarm 1 information
    Serial.print("Alarm 1: ");
    clock.getA1Time(alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits, alarmDy, alarmH12Flag, alarmPmFlag);
    Serial.print(alarmDay, DEC);
    if (alarmDy) {
        Serial.print(" DoW");
    } else {
        Serial.print(" Date");
    }
    Serial.print(' ');
    Serial.print(alarmHour, DEC);
    Serial.print(' ');
    Serial.print(alarmMinute, DEC);
    Serial.print(' ');
    Serial.print(alarmSecond, DEC);
    Serial.print(' ');
    if (alarmH12Flag) {
        if (alarmPmFlag) {
            Serial.print("pm ");
        } else {
            Serial.print("am ");
        }
    }
    if (clock.checkAlarmEnabled(1)) {
        Serial.print("enabled");
    }
    Serial.println();

    // Display Alarm 2 information
    Serial.print("Alarm 2: ");
    clock.getA2Time(alarmDay, alarmHour, alarmMinute, alarmBits, alarmDy, alarmH12Flag, alarmPmFlag);
    Serial.print(alarmDay, DEC);
    if (alarmDy) {
        Serial.print(" DoW");
    } else {
        Serial.print(" Date");
    }
    Serial.print(" ");
    Serial.print(alarmHour, DEC);
    Serial.print(" ");
    Serial.print(alarmMinute, DEC);
    Serial.print(" ");
    if (alarmH12Flag) {
        if (alarmPmFlag) {
            Serial.print("pm");
        } else {
            Serial.print("am");
        }
    }
    if (clock.checkAlarmEnabled(2)) {
        Serial.print("enabled");
    }

    // display alarm bits
  Serial.println();
    Serial.print("Alarm bits: ");
    Serial.println(alarmBits, BIN);

    Serial.println();
    delay(1000);
}

How do I make this happen?

The library that I'm using requires that I pass in 2 Boolean values
into Clock.getHour(), however changing these values does not change
the returned time format.

You appear to be talking about the parameters here, which the second is for getting the current state of the AM/PM flag and configuration and not altering the kind of value you get in the return.
There's a setClockMode function you can call which will configure the chip to report in 24-hour mode.  If you call that passing in false, getHour should begin returning 24-hour time.


text:
Why is this extremely simple code not working?
I have a problem with a for loop, and Serial.print("Its Working") does not appear. Seems simple, I've done it before, now for whatever reason, its not working anymore
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

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

  for (int x = 0; x > 10; x++) {

    Serial.println("Its Working");
    delay(1000);
  }
}

The problem is:
for (int x = 0; x > 10; x++) {

That can be rewritten, in pseudo code, as:

X is zero
While X is greater than 10:

Increment X

You see the problem? X is zero. It's not greater than 10, so it never increments.
I assume you actually wanted:
for (int x = 0; x < 10; x++) {

Also be aware that your for loop will be run over and over again, so you will never see it finish.  You should add
Serial.println("Loop done");

at the end so you know it's finished.

Essentially, the for loop never starts as the first time it checks the condition, its already false, right?

@Coder9390 That is correct.

@Coder9390: You can see that for yourself by single-stepping your code with a debugger.  You'll see execution skip over the loop without ever entering the loop body.  That's your hint that you accidentally wrote a loop condition that's false on the first check.  Remember that a for loop is basically the same as part1;  / while(part2){ ...; part3; }, so like a while loop, the condition is checked before entering the loop for the first time.

@Coder9390:   Using a debugger is essential for low-level stuff where alternatives like sprinkling debug-print statements in your code aren't easy, or to help catch brain-farts where something you're assuming you got right was actually the problem.

source: Stack Exchange

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

sort: votes


text:
How to reset ESP32 after a certain duration?
I would like to reset my ESP32 from the software, how do I do it and how to make it do this at regular intervals.

Hope this helps.

uint32_t resetAfterMillis = 30000; // Reset after 30 seconds.
uint32_t lastResetWas;

void setup() {
   lastResetWas = millis();
}

void loop() {
  uint32_t now = millis();
  if (now >= lastResetWas + resetAfterMillis)
  {
      lastResetWas = now;

      // Whatever you want to do here
      ESP.restart();

  }

}

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


text:
How to set 16x2 LCD I2C display backlight?
I have 16x2 LCD display with a I2C backpack. This is the library I am using
https://drive.google.com/drive/folders/16_UqfwFm4VKWcdeJfDmHRV2Hj_IoaTai?usp=sharing
So as given in the code below, by changing variable back to a 0 or 1, I can turn on and off the backlight. However if I change the values of back to 100, or 50 the backlight does not get affected, how do I make this happen without the need of an external resistor/potentiometer and but with code.
Note that on my backpack, there is no connection between pins A and K to keep the backlight on but if I connect the two, then the backlight is turned off.
If you don't care of the above here's it summarized-
How do I control Backlight of LCD with I2C backpack through code?
Code-
#include "LiquidCrystal_PCF8574.h"
#define LCD_ADDRESS 0x27
#define LCD_ROWS 2
#define LCD_COLUMNS 16
#define SCROLL_DELAY 150
int back = 1; // 1-on, 0-off

LiquidCrystal_PCF8574 lcdI2C;

void setup(){
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);
}

void loop(){
delay(1000);
back = 0;
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);
delay(1000);
back = 1;
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);

}

You don't.  The PCF8574 is an IO expander. It doesn't have any provision for PWM. It's either on, or off.

Ok, kinda disappointing, but good to know

Can I just use analog write and connect that pin to Pin A on the lcd?

@Coder9390, if you want to do that, you should probably interpose a transistor.  The backlight current is typically more than you'd want going through an Arduino I/O pin.

....and then use PWM on the transistor right

Note that on my backpack, there is no connection between pins A and K to keep the backlight on but if I connect the two, then the backlight is turned off. -- Sounds like you're short circuiting the back light there.

No, I had my doubts but when I connect the 2 nothing happens

In the sense that the backlight turns off and nothing blows up or heats up

If there is a resistor in the circuit between the PCF and the LCD then I wouldn't expect anything bad to happen.


text:
How to program and arduino UNO via NodeMCU ESP8266?
I don't have my USB type A cable to program my UNO, I would like to program it via a NodeMCU ESP8266.
Maybe with the TX and Rx pins, I've seen people program certain versions of ESP with a UNO board.
How do I do this and is it possible?

The UNO's USB connection is little more than a USB to UART converter.  The NodeMCU's USB connection is also little more than a USB to UART converter.
With a little jiggery pokery (yes, that's a technical term) you can replace one with the other.
By keeping the NodeMCU in RESET mode (tie the EN pin low, or hold the RESET button) you can use the TX and RX pins as the output to the onboard USB to UART converter to connect to the TX and RX pins of the Arduino.
The tricky part is getting the Arduino to reset at the right time: you have to press the Arduino's RESET button at just the right time. Normally this is done by a small capacitor between the DTR signal of the USB to UART converter and the RESET pin, but you don't have access to the DTR signal, so you will have to do it manually. Timing here is everything. Press upload, and just as AVRDude starts to execute you press RESET. Having verbose compilation turned on in the IDE can help.
It may take a few attempts to get it right.

Just for clarification, as I'm a beginner... TX goes to RX and vise versa, right?

And should the target be UNO or NodeMCU?

No, TX goes to TX and RX to RX. You're mirroring the NodeMCU functions with the Arduino board. And the target is UNO, since that's what you're programming. The NodeMCU ceases to be an NodeMCU and is merely a USB to UART adaptor (like an FT232 cable).

I cannot believe my eyes, IT WORKED!

Congratulations.


text:
How to get current WiFi signal strength?
I have a LCD display where in I'm displaying a WiFi signal logo. I want to reduce the number of bars on the logo, indicating that the signal strength is dropping. I got the reducing bars on the LCD completed, I still have to find out the actual signal strength.
How do I find the signal strength of the connected network with ESP8266 based NodeMCU?

You use WiFi.RSSI():

RSSI
Return the signal strength of Wi-Fi network, that is formally called Received Signal Strength Indication (RSSI).
WiFi.RSSI()

Signal strength value is provided in dBm. The type of returned value is int32_t.
Example code:
Serial.printf("RSSI: %d dBm\n", WiFi.RSSI());

Example output:
RSSI: -68 dBm


text:
Different Counter Reading on Serial Monitor Vs .96" OLED I2C
I've cobbled some code together from reading multiple sources on the web.  Makeatronics in particular to help me get this rotary encoder code together (shout out to them).  I'm pretty close to the end, but now trying to port it over the OLED display.  Not sure what the issue is, but it doesn't miss counter steps when read on the serial monitor, but does when ported to the OLED.
I increased the clock speed to 400Khz using Wire.setClock as I saw that suggested in some other places for I2C comms.
1.) Any thoughts on how I can improve the code or hardware to get this to read without missing steps?
Hardware:

Nano (USB Powered)
White .96" OLED I2C SSD1306
HW-040 Rotary Encoder

Libraries:

Arduino WIRE
Adafruit SSD1306 Library

The Serial Monitor Code:

#define PinCLK 2
#define PinDT 3

volatile boolean turnDetected = false;
void rotarydetect() {
  turnDetected = true;
}

void setup() {
  attachInterrupt (digitalPinToInterrupt(2), rotarydetect, CHANGE);
  pinMode(PinCLK, INPUT_PULLUP);
  pinMode(PinDT, INPUT_PULLUP);
  Serial.begin(2000000);
}

void loop() {
  if(turnDetected) {
    turnDetected = false;

    static uint8_t enc_val = 0;
    static int16_t enc_count = 0;
    static int8_t lookup_table[] = {0,1,0,-1,-1,0,1,0,0,1,0,-1,-1,0,1,0};
    static long lastTimeToDebounce = 0;
    static int debounceTime = 1;
    static int enc_counter = 0;

    if((millis() - lastTimeToDebounce) > debounceTime) {

    enc_val <<= 2;
    enc_val = enc_val | ((PIND & 0b1100) >> 2);
    enc_counter = enc_counter + lookup_table[enc_val & 0b1111];

    Serial.print("Counter: ");
    Serial.println(enc_counter);
    Serial.println("");
    }
    lastTimeToDebounce = millis();
  }
}

And the OLED Code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in

#define PinCLK 2
#define PinDT 3

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

volatile boolean rotated = false;

void rotarydetect() {
  rotated = true;
}

void setup() {
  Wire.begin();
  Wire.setClock(400000);
  attachInterrupt (digitalPinToInterrupt(2), rotarydetect, CHANGE);
  pinMode(PinCLK, INPUT_PULLUP);
  pinMode(PinDT, INPUT_PULLUP);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
}

void loop() {
  if(rotated) {
    rotated = false;

    static uint8_t enc_val = 0;
    static int16_t enc_count = 0;
    static int8_t lookup_table[] = {0,1,0,-1,-1,0,1,0,0,1,0,-1,-1,0,1,0};
    static long lastTimeToDebounce = 0;
    static int debounceTime = 3;
    static int enc_counter = 0;

    if((millis() - lastTimeToDebounce) > debounceTime) {

    enc_val <<= 2;
    enc_val = enc_val | ((PIND & 0b1100) >> 2);
    enc_counter = enc_counter + lookup_table[enc_val & 0b1111];
    display.setCursor(0,0);
    display.clearDisplay();
    display.print("Counter: ");
    display.println(enc_counter);
    display.println("");
    display.display();

    }
    lastTimeToDebounce = millis();
  }
}

I also tried the LCD_1602 screen (still through the I2C module board), and more or less it has the same results.  I also switched the code from the ISR to trigger the code loop, to a polling loop that detects when the CLK pin changes state with the LCD 1602 screen.  Same array with bit shifting as above for state detection.  Same results.  I also removed the very low debouncing code altogether with the Wire.setClock(400000) same results.
Seems like this may be a I2C limitation for communication?

There is a lot more overhead in displaying a value than there is in serial output, so it may well be a combination of I2C speed and that overhead. The nano is a pretty slow processor. One thing you could do to compare them would be to use micros() to measure the length of time it takes to output the count in each case; then you'd get an estimate of how much slower the display is vs the serial port. Just store the current micros() value before the Serial or display calls, then output the difference between it and the current value to measure the microseconds output took.

Move the code related to screen clear(i.e.display.setCursor(0,0); display.clearDisplay(); display.print("Counter: ");) to setup(), you don't need to clean the screen on every loop. All you need is to set the cursor to where you want  the enc_counter to be displayed on the screen and display.println(enc_counter);.

@romkey Yeah, ~3000 microseconds for Serial.print versus ~37000 microseconds for the the I2C. I have a .96 OLED SPI that I will test and let you guys know the results.

@hcheung - The previous microsecond test I just discussed was done with the code update you suggested so that the display isn't clearing each loop.  It still lagged and missed steps unfortunately.  I'll chalk this one up to a communication speed issue.


text:
Touching a capacitive button, non-mechanically
This is not about using a capacitive button to control an Arduino; it is the opposite. I would like to "touch" a capacitive button on another conventional device. There could be a way like actually moving a finger-like stick and touch the button, but that is too much work. Can't it be done non-mechanically?
According to this page ( https://scienceline.org/2012/01/okay-but-how-do-touch-screens-actually-work/ ), "Instead, they work with anything that holds an electrical charge – including human skin.". Then, can I emulate "touching" the button by sending some small electrical current?
If so, what module/parts do I need to send such small current?

It's all about capacitance.  The micro is putting a voltage on that cap sensor and measuring how long it takes to fall or rise.  That gives a measure of capacitance.  When you put your finger you change the capacitance.  Perhaps you could put a second plate there and get the capacitance right to not trigger the button and then have a capacitor that you can switch in to make it higher and trigger it.  Not entirely sure how you'd do that, but maybe it gives you a place to start.

the button likely handles its own grounding so one question is whether you have access to that device's ground... if not for a purely isolated device, you'd need to mirror their two electrodes.  you then drive a voltage between your two (direction matters for this) to pretend to not touch or connect them to the same (both to either high or low) to simulate a touch

Check out these links: (1) https://www.youtube.com/watch?v=Ji2-2ehLCOQ
(2) https://www.youtube.com/watch?v=4ElZec033vQ (3) https://www.youtube.com/watch?v=gSifTiR_e2E (4) https://www.youtube.com/watch?v=XMZrUPBt-7M

The simply way is making a little capacitor.
Cut 2 circle with aluminium from a can and put a paper between them, then solder one one to one circle and other to the other side. One wire goes to the positive and the other to the I/O. When you set to 1 it should create a capacitive charge and "touch" de button.

"then solder one one..." do you mean "then solder one wire..."? Also, "de button" should be "the button" and "The simply way" should be "The simple way"? The typos aside, your answer would benefit from a diagram as it isn't particularly clear what you mean. "One wire goes to the positive". do you mean Vcc? If so, then what relationship does your DIY capacitor have with the capacitive button on the third-party device? How are they connected? How is the capacitive button activated?


text:
Why are the pin numbers of the diagrams and of the code different?
If I search Google for "arduino nano pin numbers", all results show that the pin number of D2 is 5. But that did not work. I searched for some sample codes, and they were 3 for D3 and 5 for D5, etc. So, in codes, the pin number for Dn is n. Then what are the numbers in these diagrams?

are you referring to the physical pin numbers of the module? ... they start at 1 and wrap around

Every chip datasheet (and also the Arduino boards) uses 2 different ways to refer to the pins:

Counting the physical pins in the order as they appear on the chosen package of the chip
Referring to the pins by their function

The first way is only for referring to specific pin positions from the outside, for example when you are building the actual circuit. This also includes special pins like Vcc, GND and Reset. Those pins cannot be referenced by the code (wouldn't make much sense). Also the microcontroller on the inside of its package doesn't know in which package it got stuck by the manufacturer. Each package has a different pin order and form factor. So this counting only makes sense in the context of placing this specific package of the chip into a circuit (like where is Vcc, where ground and where do I need to connect to that specific digital pin), but makes no sense to use for the code inside the controller.
For referring to pins from inside the controller (aka in the code) we use the function of the pins. On an Arduino you have mainly digital and analog pins, which can be controlled. So for the convenience of beginners (which are targeted by the Arduino framework) the digital and analog pins are just numbered. Those are the numbers, that are normally written only the Arduino board. So D2 means the third digital pin inside the Arduino framework. A0 is the first analog pin. Where that pin is physically located on the board isn't interesting for the code, nore does the code know the actual location. For the code its just the third digital output hardware and so on.
TL;DR: For building the circuit we must refer to pin positions (like where is Vcc, where is ground) to connect the chip/microcontroller correctly. But the internal code doesn't know, where the physical pins are located and the actual location can also depend on the packaging. So internally we use a different counting system based on the pin function. The Arduino way of counting the digital and analog pins just hides away complexity for the beginner. As reference the numbers are also printed on the Arduino board itself.

In case you want to go deeper into the rabbit hole:
Actually the microcontroller has different hardware for different functions incorporated. For example: The analog pins can be used by the ADC (Analog to Digital Converter) to measure an analog voltage. But they also each have digital input and output hardware, just like any other digital pin. Most pins of a microcontroller are multi purpose. The code has to decide, what hardware gets to be connected to the respective pins. When I use pinMode(2, OUTPUT) I tell the microcontroller to connect the third digital output hardware to its respective physical pin. When I use analogRead(A1) I tell it to connect the second analog channel of the ADC to its respective pin and read an analog voltage through the ADC.
That means, that the code only knows of the function hardware and that it can be connected to their respective pins (whichever these pins are on the outside world). The numbering in digital and analog pins is only an additional abstraction layer to hide the complexity from beginners. Actually the code controls the hardware functions via Special Function Registers (SFR). These are special pieces of memory, which are physically hardwired to the respective hardware in the microcontroller. For the digital output hardware the pins are sorted into groups of up to 8 pins. These groups are called Ports, and are numbered with characters. When you look at this pinout of the Arduino Nano, you see, that the Arduino pin D2 is also named PD2, which means PortD third pin (counting from zero up). Arduino pin D8 is also named PB0, so PortB first pin. Functions like pinMode(), digitalWrite() and digitalRead() all just manipulate the SFRs for the wanted port to set the respective pin. Refer to the Documentation on Port Manipulation for learning how to do it yourself. For beginners it is just easier to use the markings on the board - the Arduino pin number - instead of bearing with the ports and their SFRs directly.

Might be clearer to tell all four levels at the start: 1) The pin number of the breakout board, which are numbered 1-30 here  2) The Arduino name for the pin, such as D3  3) The microcontroller datasheet name for the pin, such as PA4   4) The microcontroller package pin number

The additional abstraction is not just to make life easier for beginners. As @RedGrittyBrick notes in their answer, it makes the code more portable. To a lesser degree, it's also makes the code more readable, though some may not agree. And if you're using one of the commercial boards where the pins are marked with the Arduino labels, it's certainly easier to get the wires on the right pin.

There are at least four ways of referring to pins on any Arduino board:

Board-order: Simple numeric order (1,2,3 ...) of physical location of pins on printed circuit board anticlockwise from the USB end (or some arbitrary end)
Arduino-name: Names used in Arduino source code and/or PCB silk-screen annotation (D1,D2 ... A0,A1 ...).
IC-order: Simple numeric order of corresponding pin on IC according to numbering used on manufacturers data sheet.
IC Function name: Names for functions available on pin (RESET, VCC, INT0, PB0,PB1,PB2 ...) as described in data sheet for IC.

For example:

Nano PCB Pin#
Arduino Name
ATMega328 TQFP Pin#
ATMega328 DIP Pin#
ATMega328 function

1
D13
17
19
PB5, SCK, PCINT5

2
3V3
N/A
N/A
N/A

3
REF
20
21
AREF

4
A0
23
23
PC0, ADC0, PCINT8

5
A1
24
24
PC1, ADC1, PCINT9

etc

There are lots of different Arduino and Arduino-like boards that use the ATMega328, some use different ATMega328 packages (DIP, TQFP, etc) with different pin arrangements. Many arrange the physical PCB pins differently. This is why there isn't a fixed one to one relationship and it is partly why the Arduino IDE provides for it's own simplified naming that it attempts to apply consistently and portably across a variety of different microcontrollers.

(c) PigHixx w/o permission.

Why are the pin numbers of the diagrams and of the code different?

Because the Arduino designers chose to re-use the name "pin" for the chip's programmable signal lines, despite it's more common and already existing use to mean any of the protruding external connections to the device.


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:
Programmatically-adjustable buck converter module?
LM2596 is easy to use and cheap, but I have to adjust the output voltage using a screw driver. On the web, there was a "hack" that someone posted, but that hack does not seem as clean or stable as using LM2596 as it is intended to be used, using screw driver. Is there something that is easy-to-use just like LM2596, but has some pins that can be used to dynamically adjust the output voltage using an Arduino?

Replace the pot with a digital potentiometer?

it's a lot easier to do with a linear supply; basically an npn voltage follower driven by an amplifying w/feedback opamp fed by smoothed PWM or DAC. The lm2596 isn't very clean anyway if that's your big conecrn; you would be better off with a newer offering from XLsemi, or use a linear for (by far) the best noise and stability.

@Majenko can you suggest a digipot that would actually be a suitable replacement for the analog? The affordable ones i've found have limited voltage ranges; often 5v, and we need a voltage divider here, not just a resistor, which makes it harder since specified voltage ranges are ref'd to a common ground. You can simply do the bottom half, but how to do the top half of the divider? How to control more than 0-5v output?

You could also do a design with a resistor ladder to replace the pot, shorting out various resistors with FETs or even relays, which would be very stable, but really drives up the parts count and complexity.

I've also found an cheapish ($10) SMPS module that took a pwm input to throttle the output voltage. I can't recommend it though because it bypassed feedback, and it smoked under a modest load...

The hack you described is most likely just feeding voltage from filtered PWM signal generated by microcontroller to the feedback loop of LM2596. I think you can get good enough noise performance with this approach if voltage change rate is not a concern. It all comes down to the PWM filter parameters. You can decrease noise by adjusting RC filter parameters (increasing capacitor and resistor values). It will cause increased delay in voltage change, but it will reduce the noise from PWM signal. Also, you can increase the PWM frequency by avoiding standard analogWrite which has pretty low frequency and configuring a separate timer for PWM generation.
Alternatively, if you need some specific voltages, you can replace the potentiometer with a fixed value resistor array connected in parallel and connect each resistor though separate low power MOSFET. This way, you can connect and disconnect a specific resistor which will change the total resistance of the array, changing the output voltage. It will only allow changing voltage by steps and the step size is dictated by the number of resistors, but the noise performance will be the same as using a potentiometer.


text:
Bi-directional UART communication on single data wire, possible?
The nano is inside of the house, and the pro mini is outside of the house. I want to send/receive text between them. The communication will be always nano sending text to mini, and then mini sending text to pro in response. There will be no case where mini sends text on its own first.
The line has three wires, but since I have to power the mini with that line, one is used for VCC and another is used for ground, leaving only one wire free. It this case, can I do UART communication between the two? If so, how should I connect the wire to them (including the ground)? And on the software side, how should I handle the communication? Could you give a simple code example in which nano sends "Hello" to pro mini, and then pro mini, after receiving "hello", sends "World" to nano?

The main question is the distance and the desired connection speed. You can use, for example, even two-core cable for power and some HF-modulation magic for data.
Or, you can use wires only for power and use some radio (i.e., WiFi) for data.
The radio solution is more simple and cost-effective, because it is pretty common.

https://www.pjon.org/SoftwareBitBang.php

What you want is called half-duplex. A search turned up a bunch of good articles:  https://forum.arduino.cc/t/software-serial-with-half-duplex-for-a-shared-serial-bus/112131  and http://nerdralph.blogspot.com/2014/01/avr-half-duplex-software-uart.html  You'll have to devise some handshaking so each side knows when the other is done transmitting. Have fun!

You can use that kind of "Ethernet protocol" that was used on coaxial cable ? Or used with " high frequency modem" ? Or more simple, a "circuit coupler" as in old "line telephony" ?

You can have bidirectional communication over a single wire by using
open-collector outputs. For this, you could add a circuit like this
on each side of the link:

simulate this circuit – Schematic created using CircuitLab
Here, TX is the transmit pin of the Arduino, and DATA is the data wire.
The RX pin is connected directly to the data wire and, while writing
your sketches, you should account for the fact that anything you send
will be received back by the sender as an “echo”.
This scheme will slow down your signal transitions, limiting the maximum
achievable baud rate. Start with something conservative, like
9600 bps, and lower further if it doesn't work reliably.

The "TX pin on Arduino" means the "TX1 - UART -Out" of Nano and the "RX pin" means the "RX --- 0" of Pro Mini, on the diagram above? Or is it ignoring the UART feature of Arduino completely, and use a reuglar digital output pin instead?

@DamnVegetables: This assumes you are using the hardware UART, and thus the corresponding pins. On the Nano, those pins are labeled TX1 and RX0. On the Pro Mini, they are labeled TXO and RXI.

This question likely suffers from the X Y problem.  Where the question (about software) and possible answer (centered on hardware) do not approach the solution using the same methods.
The question is essentially asking how to design a 1-wire interface over longer than normal distances. There are 1-wire Arduino libraries and 1-wire Arduino tutorials. But it is likely you will run into problems if your cable is very long.
Guessing at the distance you want to run your 3 wires (power, ground and data), this may be more an electrical engineering than a software problem.
Power:
All wires have resistance.  Using a voltage drop calculator from here we can calculate, assuming we are trying to send 5V over an 18 AWG copper wire 100 meters long to a 250mA load, an expected voltage drop of slightly over a volt.  That may cause unexpected results.

If this might be an issue, consider an alternate power source such as batteries, solar power or a second mains power adapter for the far Arduino.  It may even be considered to over drive the power lines several volts and regulate the voltage at the far end Arduino.
Data:
Reference to ground type data transmission is more susceptible to error the longer the cable run.  Several options to mitigating unexpected behavior can be made.  However switching over to a balanced pair is usually the best option.
Options:
If you are willing to power the far Arduino independently or add 1 additional data wire (either of these options will make available 2 wires for data) we can run the data portion of the cable for a good distance while mitigating noise problems associated with long communication cable runs.
Try RS485:
Consider using an RS485 hardware interface at the near and far Arduino.  RS485 interfaces can be source easily for Arduino projects (here and here are two examples) and there are Arduino RS485 software libraries which handle the communications.
The intent of the project was not disclosed in the question.  However here is an example RS485 project where connected Arduinos communicate the position of a potentiometer such that the RS485 connected Arduino at the far end can mimic the potentiometer's movements on a motor driven servo.
The keen eye may note that the above project only uses 2 wires between the two Arduinos.  This is possible because in the above project the two Arduinos are independently powered (this is not seen in the diagram on the linked to web page).  Additionally, RS485 uses a balanced pair of signals (the 2 wires) and does not need to run an additional ground between the two Arduinos as a reference to detect the difference between 1s and 0s.

This might be an XY problem and there might be a hardware solution, but if the question is "how can I make this work with 3 wires" the answer "just use 4 wires" is not helpful. Most likely the cable is already there. If punching through walls to hook up an Arduino would be acceptable OP wouldn't ask the question.

@AndreKR Yeah, the cable has already been installed (I did), and at that time, I thought I would not need bi-directional communication and 3-core cable was cheaper than 4-core cable, so I chose the former. Now, after using the system, I realised that I need a way to get the status of the remote device. I could remove the old one and install a new cable (not impossible), but it will be such a hassle, so I was looking for a way to do it with the existing wire.

Thanks. Replacing the existing 3-core cable with a 4-core cable is not impossible, but I thought if I had two free wires available for data, I could just connect two Arduino's directly using the TX/RX pins already there. You mean that using RS485 needs two free wires (other than the two for powering the remote Arduino), right? The distance is about 30 metres (=100 feet), and I do not need fast communication (even 100 bps is more than enough). The module called "TTL to RS485" seem cheap. Do you think it is better than direct connection even in my case?

@AndreKR, at the end of my answer was a 2 wire solution.  It will only work if the remote was powered by some other meas then by cable.  And RS485 will almost always out preform a return to ground reference signal.  Time and time again people who do not know that try to extend I2C and SPI only to find they can not live w/the noise.  I'll amend my answer and explain this more clearly.

@DamnVegetables, FYI, you are essentially asking how to design a 1-wire interface over longer than normal distances.  I could have just said that in my answer and point you to Arduino tutorials and libraires.  But it is likely you will run into problems if your cable is too long.  Actually, I think I'm going to put the above in my answer.  But, just to help us create a better answer ... just how long is your cable?

@DamnVegetables RS485 needs 2 wires because it is not Data/Ground, rather it is +Data/-Data kind of like USB. Also note that RS485 works best if the two data wires are twisted pair

Yes, that is correct.  And it (USB 2.0) can obtain some rather impressive speeds over a good amount of cable run.  I think USB 3 use multiple balanced pairs in a full duplex mode to obtain even higher speeds.

You could do it by using one wire for ground, one wire for nano->mini, and one wire for mini->nano.  The nano->mini wire carries both power and data.  You can keep it at some voltage above ground to provide the power and superimpose a data signal that is AC coupled off at the mini end.  Alternately, you can rectify the data to provide power if you make sure to send 01010101 whenever you don't have something else to say.

Note that an UART idles high.

An example of protocol using a single wire (besides ground, so a total of 2) for both bi-directional communication AND power: Dallas 1-wire
There are few other similar standard protocols and you are free to think about your own as long as you are willing to implement all the internals instead of using a well-written and widely used library.

While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

will it work on 30 meters long cable?


text:
Why delay of more than 64 millisecond stops the servo motor from rotating? I am not using "Servo.h" instead i am just managing the length of pulse
The code I used was this
int servo = 5;
int angle;

void setup() {

  pinMode(servo, OUTPUT);

}

void loop() {

  for (angle = 0;angle<180;angle++){

    digitalWrite(servo, HIGH);
    delayMicroseconds((angle*(11))+365);
    digitalWrite(servo,LOW);
    delay(65);
  }

  for (angle = 179;angle>0;angle--){

    digitalWrite(servo, HIGH);
    delayMicroseconds((angle*(11))+650);
    digitalWrite(servo,LOW);
    delay(65);

}
}

as u can see I have set the delay after a particular step to be 65 milliseconds but it won't work, any delay greater than 64 milliseconds do not work and the motor just stops rotating.
what is the reason for this??

Go here:  https://www.arduino.cc/reference/en/language/functions/time/delaymicroseconds/  and read the second sentence.

A servo motor doesn't just require a single pulse to send it to a specific angle. It requires a constant stream of pulses at the right frequency for it to track what the angle should be.
By sending one pulse you're just hinting where it might like to go to, then stopping. It's never going to get there, unless you keep sending those pulses fast enough.
Also if you don't send pulses then the servo will go into a "low power sleep mode" where it's not actively driving the output and it will go "floppy" where you can move the servo by hand.
Typically you need to send pulses at about 50Hz, which is one pulse every 20ms. Many servos will be more forgiving, but if you send too slowly they just won't know what to do.
If you want to be handling the pulses yourself then you need to do it in the right way.  That is:

Send a pulse of your desired length
Delay for 20ms minus your desired length
Go to 1 until your desired elapsed time has been reached.

For example:
for (angle = 0; angle<180; angle++){
  uint32_t ts = millis();
  while ((millis() - ts) < 100) { // 100ms delay
    digitalWrite(servo, HIGH);
    delayMicroseconds((angle * 11) + 650);
    digitalWrite(servo,LOW);
    delayMicroseconds(20000 - ((angle * 11) + 650));
  }
}

That won't be exact, owing to the latency of the loop instructions, but it will be close enough.


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:
using RTC for storage
I keep seeing stuff about this: https://www.arduino.cc/reference/en/libraries/rtcvars/ when looking for storage for a few variables that survive turning off and on, but then it is only on ESP8266.
The thing I am trying to understand is what it has to do with the RTC..  Other RTCs don't seem to have this arbitrary storage ability. Is the RTC in an ESP8266 nothing like any other RTC? Or is this really just some other storage on the chip? And what is the storage technology itself? If I am using an arduino uno, or just at avr chip, is there any unit I can attach that is or isn't part of an RTC with the same storage properties? Or does every RTC have this ability, and just need somebody to write the library?
According to this https://forum.arduino.cc/t/save-data-in-nonvolatile-memory/140801/2, the RTC memory of the the ESP8266 can be written to an infinite number of times, whereas an SD card will wear out if you update a value on it every second (like for a counter).
What technology is this "RTC memory" using that I can attach to my avr project?

the RTC memory of esp8266 is cleared if the module is without power. its content is preserved on reset.

oh.  I misunderstood. I thought there was a clock battery in there that kept it going. but I guess a nodemcu doesn't have a built in clock battery.  thanks.

since SD cards wear-level, and a 4gb card is as cheap as any, it would take a really really long time to wear one out just by writing a number once a second.

>>> 4000000000 / 60 / 60 / 24 / 365 126.83916666666667 good point

and I guess it'll keep writing my byte 8 bit number to the same byte until it wears out and then move on to the next one.

I just triied it ouy with a nodemcu @Juraj - you are totally correct.

Some RTC chips contain a small amount of battery-backed SRAM ("NVRAM" - Non-Volatile RAM) which you can use for whatever you like. This is just ordinary RAM which is powered by the small battery that keeps the RTC running.
Not all do, though, so check the specs for your chosen RTC chip.
For example, the DS1302 has:

31 x 8 Battery-Backed General-Purpose RAM

That's 31 bytes of storage you can use for what you like.
Conversely the DS3231 doesn't have any spare RAM at all.

Thanks.  "battery backed ram" - Now it all makes sense.  I guess it's SetMemory in https://github.com/Makuna/Rtc/blob/master/src/RtcDS1302.h

@Alex028502 Yep, and the associated GetMemory.


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:
PCA9685 - Hardware problem with diode?
I'm working on a project, where I need to run several high-torque servos. For that I bought come of these PCA9685 boards.
I hooked everything up with my arduino and connected an external 5V - max 3A power supply for driving the servos. After some succesful tests, the board seems to be broken as no servo move anymore.
With my multimeter I looked for the broken component and found the following - in front of the transistor is, in my opinion, a ten diode with label Y4 installed - At the input (right) are still 5 V, but no longer at the output and accordingly not at the V+ pins of the servo connectors.

According to the internet, a ten diode has a maximum of 300mW, which for 5V results in 60mA, which of course is less then my servos require.
Do you agree with me? Could this be the problem?
If so, do you know the "correct" PCA board that is able to power high torque servos?

Yes, I concur with your diagnosis. You can use that board fine, just don't provide the 5V to the servos from it - connect them direct to the power supply.

Newer versions of the board (based on the Adafruit design https://github.com/adafruit/Adafruit-16-Channel-PWM-Servo-Driver-PCB) replace that section with a AOD417 Mosfet. See the "reverse voltage protection" section of the schematic at the same link location. I've not had any trouble running hobby servos  from the revision C board.


text:
How can I remove the delays in this code for sweeping the servo?
I know this is probably a very asked question, but I am building a fairly basic radar type thing which sweeps left and right and uses an ultrasonic sensor to determine the distance to an object and a buzzer is set off if something is detected.
The device itself works  but I've noticed that because I have used delay() to allow the servo to complete its full movements, it is holding up the rest of the code, and as a result the buzzer and returning of the distance is extremely unresponsive and sluggish.
So far I have looked at simply returning a value whenever the motor reaches a certain step but it doesn't achieve exactly what I'm looking for, and I have looked into using millis() for timing asynchronously, but I'm struggling to wrap my head around it a bit in terms of how it will work for a servo.
My current working but sluggish code:
//Servo Stuff
#include <Servo.h>
int servoPin = 12; // Pin for interacting with servo defined
int servoStart = 0; //Starting position of servo motor
int servoEnd = 90; //End position of servo means it rotates 90 degrees
int waitTime = 1000; // Allows servo to fully rotate before moving again
int servoPos = 20; // For incrementing the position of the servo
int servoStep = 20; //amount to increment servo position by
Servo myServo; // Creates an instance of a servo object

//Ultrasonic stuff
int trigPin = 9;
int echoPin = 10;
long duration;
int distance;
int maxDistance = 329; // The max range of the ultrasonic sensor

//Buzzer stuff
int buzzerPin = 11;
int buzzerWait = 200;

void setup(){

//Attach the servo object to the pin and begin serial monitor with
// polling rate of 9600
Serial.begin(9600);
  myServo.attach(servoPin);
  pinMode(buzzerPin, OUTPUT);

    pinMode(trigPin, OUTPUT); // Trig pin set as output
    pinMode(echoPin, INPUT); // echo pin set as i
      }

    void loop()
    {

      // Moving servo
      myServo.write(servoStart); //Moves servo to the starting pos
      //delay (waitTime); //allows servo to fully move before next move
      //myServo.write(servoEnd); //Moves to end position
      //delay (waitTime); // waits before reverting back to start pos

    //myServo.write(servoStart);
    //delay(waitTime);
    //myServo.write(20);
    //delay(waitTime);
    //myServo.write(40);
    //delay(waitTime);
    //myServo.write(60);
    //delay(waitTime);

     // Using ultrasonic sensor

      // Clears the trig pin
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);

    // Sets the trigPin on HIGH state for 10 microseconds
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);

    // reads echoPin and returns the travel time of the wave in microseconds
      duration = pulseIn(echoPin, HIGH);

    // Calculating distance
      distance = duration*0.0343/2;

    //Prints the distance to the Serial Monitor
      Serial.print("Distance: ");
      Serial.println(distance);
      Serial.println(distance);

      if (distance < maxDistance) {
      digitalWrite(buzzerPin, HIGH);
      //delay(buzzerWait);
      //digitalWrite(buzzerPin,LOW);
      //delay(buzzerWait);

      }else digitalWrite(buzzerPin, LOW);

    }

Any pointers to some good resources for this would be very appreciated, thanks.

From your code it seems like you are doing all the servo movement before you read the distance and report back. A lot of code is commented out, so it's a bit difficult to follow. What I would do is something along the line of:
[...]
int servoStart=0;
int servoEnd=90;
int servoPos=0;

[...]
void setup() {
    [usual setup stuff like you do it now]
    myServo.write(servoPos);  //start at pos 0
    // Maybe a delay here to make sure we are at pos. 0
}

void loop() {
    //Switch direction if we reach end
    if (servoPos+servoStep < servoStart || servoPos+servoStep > servoEnd)
        servoStep = -servoStep;
    servoPos += servoStep;
    myServo.write(servoPos);
    //Small delay?
    //Read distance
    //Send distance to seraial
    //Buzz buzzer if needed
}

Thank you for this, works perfectly!


text:
Arduino IDE 1.8.13 won't launch properly
Recently I have been trying to install Arduino IDE 1.8.13, and I have ran into according problem.
When trying to launch Arduino IDE with ./arduino command it shows according error:
./arduino: line 35: /home/wiktor/Downloads/arduino-1.8.13/java/bin/java: No such file or directory

I have checked and java file does indeed exist.
I am using 32 bit version of Arduino IDE and 32 bit version of Linux Alpine 3.13.3.
Thanks for all answers

Note: Below, technician 274 (the original poster) commented:

It ended up working, after following alpinelinux wiki and installing
the IDE using flatpak.

Part of the problem is how confusing the message is.
No such file or directory is not actually referring to the java file.  It's referring to the ld-linux.so interpreter specified in the elf file.
If you run the file command on the java executable, you'll see output that looks like:
./java/bin/java: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.9, not stripped

If you look for /lib/ld-linux.so.2, you're going to find that you don't have one, and that's the file it's complaining about.
Alpine Linux apparently uses Musl and the java binaries were compiled for glibc, which is normal for desktop Linux.  On a typical desktop Linux system, that the java that ships with the Arduino IDE was compiled for, all kinds of executables make use of ld-linux.so.2.  On your Alpine system, you'll find they're referring to /lib/ld-musl-i386.so.1 instead.  From this vantage point, it's more of a Linux problem than an Arduino one, but I thought it might as well have something of an answer to point people toward relevant looking resources:

https://wiki.alpinelinux.org/wiki/Running_glibc_programs
https://github.com/sgerrand/alpine-pkg-glibc

You may find it's easier to replace the java interpreter, but that won't be enough, because the Avrdude and GCC binaries will also expect ld-linux.so.2.
In the end, it may be easier to just not use Alpine Linux.

It ended up working, after following alpinelinux wiki and installing the IDE using flatpak.


text:
Are there any Arduino libraries that allow you to upload data directly to PostgreSQL?
Are there any Arduino libraries that allow you to upload data directly to PostgreSQL?
I have been turning the internet upside down to answer this question but most of the information is several years old.

The only solution to this question that I could find is a GitHub repository that hasn't been touched in several years called, SimplePgSQL. Feel free to add a better answer if you are able to find something more current. More current information would be useful!
https://github.com/ethanak/SimplePgSQL

Looks like the other alternative is to use a Raspberry Pi to easily upload sensor data to a Postgresql database.


text:
Getting a Wemos D1 Mini to work with a M1 Mac
The Wemos D1 mini won't show up on the new M1 Mac. I know it's related to the drivers but I just can't find a viable solution to the problem. Has anyone solved this?

The CH340s have always been a problem with macs even before the M1. You could use a better USB UART interface instead of the built-in CH340, although I am not sure what makes actually support the M1. Maybe FT232 or PL210x would be a good bet.

program it on a different computer, and include OTA so you can update it from the mac.

I just found a solution for my TTGO board which also uses the CH340 chip, perhaps it'll work for you as well https://arduino.stackexchange.com/a/85824/53182


text:
ISR for timer on Arduino MEGA gets called only once
I am trying to write an Arduino code to blink LED using timer 4 on Arduino MEGA (atmega2560). I resetted the timer registers, and entered all the necessary values to bring to 16MHz to 1Hz (rescalar = 1024, OCR4B = 15624), then I wrote the blinking code inside the service routine block. Now when I run the program, the ISR is called only once. I saw from Youtube videos that even though the setting up of TCCR registers and TIMSK is in setup() function, it repeats indefinitely like a loop. Below is my code. Any help would be immensely appreciated. Thank you.
int led_pin = 10;
static int counter = 0;
int led_blink = 0;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(led_pin,OUTPUT);
cli();
TCCR4A = 0;
TCCR4B = 0;
TCNT4 = 0;
OCR4B = 15625;                                //set the maximum count 16MHz -> 1Hz
TCCR4B |= (1<<CS10) | (1<<CS12) | (1<<WGM12); // prescalar = 1024 , CTC(OCR3B) mode
TIMSK4 |= (1<<OCIE4B);
sei();
interrupts();
}

ISR(TIMER4_COMPB_vect)
{
  Serial.println(millis());
  led_blink = !led_blink;

}

void loop() {
  // put your main code here, to run repeatedly:
  if(led_blink == 1)
    digitalWrite(led_pin,HIGH);
}

Are you sure, that the ISR gets only called one time? With your current code the LED will only be turned on, not blinking (since you never turn it off anywhere). Do you get the Serial output in the Serial Monitor, which shows the values of millis()?

It's ok to set a variable and do the "heavy lifting" outside the ISR, but you got a bit side-tracked here. digitalWrite is very cheap, and having it in the ISR shouldn't make problems, but Serial.println is a very complex function that on itself uses timers and takes several ms to execute.

You can use uint8_t for the led_blink variable and it must be volatile. Otherwise compiler might optimize it out when it founds out it can't change. Also led_pin doesn't magically clear itself. It stays set forever if you don't write LOW to it...

Oh I am sorry, yes I forgot yo write the LED to low in else condition, but even after that I observed that the Serial.println(millis()) still worked only once. But out of luck when I tried to add values in both OCR4A and wrote the ISR for A register, it worked perfectly fine, even the Serial.println() worked. Can anybody please explain why? Also thank you for sharing your knowledge. I had no idea Serial.println() uses timers. Newbie things.

Your missing an else statement in your loop:
else
  digitalWrite(led_pin,LOW);


text:
object of "ESPAsyncWebServer" causing conflict
I have been trying to develop multi cpp project in platformio and whenever I define ESPAsyncWebServer class object with the extern in defines.h and declare it in main.cpp I am getting scarry looking error 'HTTP_DELETE' conflicts with a previous declaration But when I define ESPAsyncWebServer class object without the extern in main.cpp instead I am not getting any error. Can you help in this regard?
main.cpp:
#include "defines.h"
#include <AsyncMQTT_ESP32.h>
#include <WebServer_ESP32_W5500.h>

AsyncMqttClient mqttClient;
TimerHandle_t mqttReconnectTimer;
TimerHandle_t wifiReconnectTimer;

/* ESPAsyncWebServer */
WiFiClient clientWiFi;
AsyncWebServer serverAsyncWeb(80);
AsyncWebSocket WebSocketAsync("/ws");
/* Processors */

String prc(const String &var)
{
  return String();
}

/* Processors End */
void allAsyncWebServer()
{
  serverAsyncWeb.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
                    { request->send(SPIFFS, "/index.htm", String(), false, prc); }); /// log
}

/* allAsyncWebServer End */

/* WebSocketAsync */

void AsyncWebSocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len)
{
  switch (type)
  {
  case WS_EVT_CONNECT:
    Serial.printf("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
    break;
  case WS_EVT_DISCONNECT:
    Serial.printf("WebSocket client #%u disconnected\n", client->id());
    break;
  case WS_EVT_DATA:
    // handleWebSocketMessage(arg, data, len);
    break;
  case WS_EVT_PONG:
  case WS_EVT_ERROR:
    break;
  }
}

byte mac[][NUMBER_OF_MAC] =
{
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
  { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};

// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);

// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);

extern "C"
{
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
}

const char *PubTopic = "async-mqtt/ESP32_W5500_Pub"; // Topic to publish

// ESP32_W5500 ETH;

void connectToWifi()
{
  Serial.println("Connecting to Wi-Fi...");
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}

void connectToMqtt()
{
  Serial.println("Connecting to MQTT...");
  mqttClient.connect();
}

void WiFiEvent(WiFiEvent_t event)
{
  switch (event)
  {
#if USING_CORE_ESP32_CORE_V200_PLUS

  case ARDUINO_EVENT_WIFI_READY:
    Serial.println("WiFi ready");
    break;

  case ARDUINO_EVENT_WIFI_STA_START:
    Serial.println("WiFi STA starting");
    break;

  case ARDUINO_EVENT_WIFI_STA_CONNECTED:
    Serial.println("WiFi STA connected");
    break;

  case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
  case ARDUINO_EVENT_WIFI_STA_GOT_IP:
    Serial.println("WiFi connected");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
    connectToMqtt();
    break;

  case ARDUINO_EVENT_WIFI_STA_LOST_IP:
    Serial.println("WiFi lost IP");
    break;

  case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
    Serial.println("WiFi lost connection");
    xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
    xTimerStart(wifiReconnectTimer, 0);
    break;
#else

  case SYSTEM_EVENT_STA_GOT_IP:
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    connectToMqtt();
    break;

  case SYSTEM_EVENT_STA_DISCONNECTED:
    Serial.println("WiFi lost connection");
    xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
    xTimerStart(wifiReconnectTimer, 0);
    break;
#endif

  default:
    break;
  }
}

void ETH_event(WiFiEvent_t event)
{
  switch (event)
  {
#if USING_CORE_ESP32_CORE_V200_PLUS

  case ARDUINO_EVENT_ETH_START:
    Serial.println("ETH starting");
    break;

  case ARDUINO_EVENT_ETH_CONNECTED:
    Serial.println("ETH connected");
    break;

  case ARDUINO_EVENT_ETH_GOT_IP:
    Serial.println("ETH got IP");
    Serial.print("IP address: ");
    Serial.println(ETH.localIP());
    connectToMqtt();
    break;

  case ARDUINO_EVENT_ETH_DISCONNECTED:
    Serial.println("ETH lost connection");

    // ensure we don't reconnect to MQTT when no ETH
    xTimerStop(mqttReconnectTimer, 0);

    break;

  case ARDUINO_EVENT_ETH_STOP:
    Serial.println("ETH stops");

    // ensure we don't reconnect to MQTT when no ETH
    xTimerStop(mqttReconnectTimer, 0);

    break;
#else

  case SYSTEM_EVENT_ETH_CONNECTED:
    erial.println(F("ETH Connected"));
    break;

  case SYSTEM_EVENT_ETH_GOT_IP:
    Serial.println("ETH connected");
    Serial.println("IP address: ");
    Serial.println(ETH.localIP());
    connectToMqtt();
    break;

  case SYSTEM_EVENT_ETH_DISCONNECTED:
  case SYSTEM_EVENT_ETH_STOP:
    Serial.println("ETH lost connection");

    // ensure we don't reconnect to MQTT when no ETH
    xTimerStop(mqttReconnectTimer, 0);

    break;
#endif

  default:
    break;
  }
}

void printSeparationLine()
{
  Serial.println("************************************************");
}

void onMqttConnect(bool sessionPresent)
{
  Serial.print("Connected to MQTT broker: ");
  Serial.print(MQTT_HOST);
  Serial.print(", port: ");
  Serial.println(MQTT_PORT);
  Serial.print("PubTopic: ");
  Serial.println(PubTopic);

  printSeparationLine();
  Serial.print("Session present: ");
  Serial.println(sessionPresent);

  uint16_t packetIdSub = mqttClient.subscribe(PubTopic, 2);
  Serial.print("Subscribing at QoS 2, packetId: ");
  Serial.println(packetIdSub);

  mqttClient.publish(PubTopic, 0, true, "ESP32_W5500 Test");
  Serial.println("Publishing at QoS 0");

  uint16_t packetIdPub1 = mqttClient.publish(PubTopic, 1, true, "test 2");
  Serial.print("Publishing at QoS 1, packetId: ");
  Serial.println(packetIdPub1);

  uint16_t packetIdPub2 = mqttClient.publish(PubTopic, 2, true, "test 3");
  Serial.print("Publishing at QoS 2, packetId: ");
  Serial.println(packetIdPub2);

  printSeparationLine();
}

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
{
  (void)reason;

  Serial.println("Disconnected from MQTT.");

  if (ESP32_W5500_isConnected())
  {
    xTimerStart(mqttReconnectTimer, 0);
  }
}

void onMqttSubscribe(const uint16_t &packetId, const uint8_t &qos)
{
  Serial.println("Subscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
  Serial.print("  qos: ");
  Serial.println(qos);
}

void onMqttUnsubscribe(const uint16_t &packetId)
{
  Serial.println("Unsubscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}

void onMqttMessage(char *topic, char *payload, const AsyncMqttClientMessageProperties &properties,
                   const size_t &len, const size_t &index, const size_t &total)
{
  (void)payload;

  Serial.println("Publish received.");
  Serial.print("  topic: ");
  Serial.println(topic);
  Serial.print("  qos: ");
  Serial.println(properties.qos);
  Serial.print("  dup: ");
  Serial.println(properties.dup);
  Serial.print("  retain: ");
  Serial.println(properties.retain);
  Serial.print("  len: ");
  Serial.println(len);
  Serial.print("  index: ");
  Serial.println(index);
  Serial.print("  total: ");
  Serial.println(total);
}

void onMqttPublish(const uint16_t &packetId)
{
  Serial.println("Publish acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}

void setup()
{
  #define FORMAT_SPIFFS_IF_FAILED false
  Serial.begin(115200);
  if (!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED))
  {
    Serial.println(F("W0")); // W0: SPIFFS Mount Failed
    return;
  }

  while (!Serial && millis() < 5000)
    ;

  Serial.print("\nStarting FullyFeature_ESP32_W5500 on ");
  Serial.print(BOARD_NAME);
  Serial.println(" with " + String(SHIELD_TYPE));
  Serial.println(WEBSERVER_ESP32_W5500_VERSION);
  // Serial.println(ASYNC_MQTT_GENERIC_VERSION);

  AMQTT_LOGWARN(F("Default SPI pinout:"));
  AMQTT_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
  AMQTT_LOGWARN1(F("MOSI:"), MOSI_GPIO);
  AMQTT_LOGWARN1(F("MISO:"), MISO_GPIO);
  AMQTT_LOGWARN1(F("SCK:"), SCK_GPIO);
  AMQTT_LOGWARN1(F("CS:"), CS_GPIO);
  AMQTT_LOGWARN1(F("INT:"), INT_GPIO);
  AMQTT_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
  AMQTT_LOGWARN(F("========================="));
  wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void *)0,
                                    reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));
  mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void *)0,
                                    reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));

  WiFi.onEvent(WiFiEvent);

  mqttClient.onConnect(onMqttConnect);
  mqttClient.onDisconnect(onMqttDisconnect);
  mqttClient.onSubscribe(onMqttSubscribe);
  mqttClient.onUnsubscribe(onMqttUnsubscribe);
  mqttClient.onMessage(onMqttMessage);
  mqttClient.onPublish(onMqttPublish);

  // mqttClient.setServer(MQTT_HOST, MQTT_PORT);

  ///////////////////////////////////

  // To be called before ETH.begin()
  WiFi.onEvent(ETH_event);

  // start the ethernet connection and the server:
  // Use DHCP dynamic IP and random mac
  uint16_t index = millis() % NUMBER_OF_MAC;

  // bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
  //            int SPI_HOST, uint8_t *W5500_Mac = W5500_Default_Mac);
  // ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
  //  ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[index] );
  //  byte esp32Mac[] = WiFi.macAddress();
  Serial.print("WiFi.macAddress(): ");
  Serial.println(WiFi.macAddress());
  uint8_t baseMac[6];
  esp_read_mac(baseMac, ESP_MAC_WIFI_STA);
  // ETH.begin(MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, baseMac);
  test();
  Serial.print("index: ");
  Serial.println(index);
  Serial.print("ETH.macAddress(): ");
  Serial.println(ETH.macAddress());
  // Static IP, leave without this line to get IP via DHCP
  // bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
  // ETH.config(myIP, myGW, mySN, myDNS);

  ESP32_W5500_waitForConnect();
  connectToWifi();

  allAsyncWebServer();    // Enable ESP Asynchronous Servers
  serverAsyncWeb.begin(); // Start ESP Asynchronous Server
  /* Initiallize AsyncWebSocket */
  WebSocketAsync.onEvent(AsyncWebSocketEvent);
  serverAsyncWeb.addHandler(&WebSocketAsync);
  ///////////////////////////////////
}

void loop()
{
}

define.h:
/****************************************************************************************************************************
  defines.h
  AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support

  Based on and modified from :

  1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client)

  Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic
 ***************************************************************************************************************************************/

#ifndef defines_h
#define defines_h
#include <Arduino.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <AsyncTCP.h>
#include <Update.h>
#include <ESPmDNS.h>
#include <SPIFFS.h>

#include "Test.h"
#include <AsyncMQTT_ESP32.hpp>
#include <WebServer_ESP32_W5500.hpp>
#include "w5500/esp32_w5500.h"
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_       1
#define _ASYNC_MQTT_LOGLEVEL_               1

//////////////////////////////////////////////////////////

// Optional values to override default settings
// Don't change unless you know what you're doing
//#define ETH_SPI_HOST        SPI3_HOST
//#define SPI_CLOCK_MHZ       25

// Must connect INT to GPIOxx or not working
// #define INT_GPIO            21  //4

// #define MISO_GPIO           19
// #define MOSI_GPIO           23
// #define SCK_GPIO            18
// #define CS_GPIO             22  //5

//////////////////////////////////////////////////////////

// #include <WebServer_ESP32_W5500.h>

/////////////////////////////////////////////

// Enter a MAC address and IP address for your controller below.
extern AsyncMqttClient mqttClient;
extern TimerHandle_t mqttReconnectTimer;
extern TimerHandle_t wifiReconnectTimer;
// extern ESP32_W5500 ETH;

// // extern WiFiClient clientWiFi;
// extern AsyncWebServer serverAsyncWeb;
// extern AsyncWebSocket WebSocketAsync;

#define NUMBER_OF_MAC      20

#define WIFI_SSID         "Digisol"
#define WIFI_PASSWORD     "12345678"

#define MQTT_HOST IPAddress(192, 168, 1, 2)
// #define MQTT_HOST         "broker.emqx.io"        // Broker address
#define MQTT_PORT 1883

#endif    //defines_h

Test.h:
#ifndef Test_H
#define Test_H
void test();
#endif

Test.cpp:
#include "defines.h"
void test()
{
    uint8_t baseMac[6];
    esp_read_mac(baseMac, ESP_MAC_WIFI_STA);
    mqttClient.setServer(MQTT_HOST, MQTT_PORT);
    ETH.begin(MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, baseMac);
}

Error:
In file included from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/HTTP_Method.h:4,
                 from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:30,
                 from .pio/libdeps/esp32dev/WebServer_ESP32_W5500/src/WebServer_ESP32_W5500.hpp:33,
                 from include/defines.h:24,
                 from src/Test.cpp:1:
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:95:6: error: 'HTTP_DELETE' conflicts with a previous declaration
   XX(0,  DELETE,      DELETE)       \
      ^
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:45: note: in definition of macro 'XX'
 #define XX(num, name, string) HTTP_##name = num,
                                             ^~~
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from include/defines.h:16,
                 from src/Test.cpp:1:
.pio/libdeps/esp32dev/ESP Async WebServer/src/ESPAsyncWebServer.h:64:3: note: previous declaration 'WebRequestMethod HTTP_DELETE'
   HTTP_DELETE  = 0b00000100,
   ^~~~~~~~~~~
In file included from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/HTTP_Method.h:4,
                 from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:30,
                 from .pio/libdeps/esp32dev/WebServer_ESP32_W5500/src/WebServer_ESP32_W5500.hpp:33,
                 from include/defines.h:24,
                 from src/Test.cpp:1:
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:96:6: error: 'HTTP_GET' conflicts with a previous declaration
   XX(1,  GET,         GET)          \
      ^
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:45: note: in definition of macro 'XX'
 #define XX(num, name, string) HTTP_##name = num,
                                             ^~~
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from include/defines.h:16,
                 from src/Test.cpp:1:
.pio/libdeps/esp32dev/ESP Async WebServer/src/ESPAsyncWebServer.h:62:3: note: previous declaration 'WebRequestMethod HTTP_GET'
   HTTP_GET     = 0b00000001,
   ^~~~~~~~
In file included from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/HTTP_Method.h:4,
                 from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:30,
                 from .pio/libdeps/esp32dev/WebServer_ESP32_W5500/src/WebServer_ESP32_W5500.hpp:33,
                 from include/defines.h:24,
                 from src/Test.cpp:1:
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:97:6: error: 'HTTP_HEAD' conflicts with a previous declaration
   XX(2,  HEAD,        HEAD)         \
      ^
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:45: note: in definition of macro 'XX'
 #define XX(num, name, string) HTTP_##name = num,
                                             ^~~
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from include/defines.h:16,
                 from src/Test.cpp:1:
.pio/libdeps/esp32dev/ESP Async WebServer/src/ESPAsyncWebServer.h:67:3: note: previous declaration 'WebRequestMethod HTTP_HEAD'
   HTTP_HEAD    = 0b00100000,
   ^~~~~~~~~
In file included from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/HTTP_Method.h:4,
                 from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:30,
                 from .pio/libdeps/esp32dev/WebServer_ESP32_W5500/src/WebServer_ESP32_W5500.hpp:33,
                 from include/defines.h:24,
                 from src/Test.cpp:1:
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:98:6: error: 'HTTP_POST' conflicts with a previous declaration
   XX(3,  POST,        POST)         \
      ^
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:45: note: in definition of macro 'XX'
 #define XX(num, name, string) HTTP_##name = num,
                                             ^~~
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from include/defines.h:16,
                 from src/Test.cpp:1:
.pio/libdeps/esp32dev/ESP Async WebServer/src/ESPAsyncWebServer.h:63:3: note: previous declaration 'WebRequestMethod HTTP_POST'
   HTTP_POST    = 0b00000010,
   ^~~~~~~~~
In file included from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/HTTP_Method.h:4,
                 from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:30,
                 from .pio/libdeps/esp32dev/WebServer_ESP32_W5500/src/WebServer_ESP32_W5500.hpp:33,
                 from include/defines.h:24,
                 from src/Test.cpp:1:
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:99:6: error: 'HTTP_PUT' conflicts with a previous declaration
   XX(4,  PUT,         PUT)          \
      ^
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:45: note: in definition of macro 'XX'
 #define XX(num, name, string) HTTP_##name = num,
                                             ^~~
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from include/defines.h:16,
                 from src/Test.cpp:1:
.pio/libdeps/esp32dev/ESP Async WebServer/src/ESPAsyncWebServer.h:65:3: note: previous declaration 'WebRequestMethod HTTP_PUT'
   HTTP_PUT     = 0b00001000,
   ^~~~~~~~
In file included from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/HTTP_Method.h:4,
                 from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:30,
                 from .pio/libdeps/esp32dev/WebServer_ESP32_W5500/src/WebServer_ESP32_W5500.hpp:33,
                 from include/defines.h:24,
                 from src/Test.cpp:1:
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from include/defines.h:16,
                 from src/main.cpp:1:
.pio/libdeps/esp32dev/ESP Async WebServer/src/ESPAsyncWebServer.h:68:3: note: previous declaration 'WebRequestMethod HTTP_OPTIONS'
   HTTP_OPTIONS = 0b01000000,
   ^~~~~~~~~~~~
In file included from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/HTTP_Method.h:4,
                 from C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.h:30,
                 from .pio/libdeps/esp32dev/WebServer_ESP32_W5500/src/WebServer_ESP32_W5500.hpp:33,
                 from include/defines.h:24,
                 from src/main.cpp:1:
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:128:6: error: 'HTTP_PATCH' conflicts with a previous declaration
   XX(28, PATCH,       PATCH)        \
      ^~
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:138:45: note: in definition of macro 'XX'
 #define XX(num, name, string) HTTP_##name = num,
                                             ^~~
C:/Users/shubh/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/nghttp/port/include/http_parser.h:139:3: note: in expansion of macro 'HTTP_METHOD_MAP'
   HTTP_METHOD_MAP(XX)
   ^~~~~~~~~~~~~~~
In file included from include/defines.h:16,
                 from src/main.cpp:1:
.pio/libdeps/esp32dev/ESP Async WebServer/src/ESPAsyncWebServer.h:66:3: note: previous declaration 'WebRequestMethod HTTP_PATCH'
   HTTP_PATCH   = 0b00010000,
   ^~~~~~~~~~
Compiling .pio\build\esp32dev\liba04\AsyncMQTT_ESP32\AsyncMqttClient\Packets\ConnAckPacket.cpp.o
Compiling .pio\build\esp32dev\liba04\AsyncMQTT_ESP32\AsyncMqttClient\Packets\Out\Connect.cpp.o
*** [.pio\build\esp32dev\src\Test.cpp.o] Error 1
*** [.pio\build\esp32dev\src\main.cpp.o] Error 1
=========================== [FAILED] Took 10.22 seconds ===========================

Look at the pre-compiled code in your temp folder, in a sub-folder named something like arduino_build_513965/sketch/project_name.cpp; Arduino does a lot of code "helping" just before compilation, so it's often helpful to see the actual code that's causing the error.


text:
How does Arduino Servo.h library manage to output PWM when a Servo motor is connected to a non-PWM pin?
While learning more about Servos, the main thing i have learned is that, Servos (SG90) need PWM signal with the frequency of 50Hz. And the duty cycle of the frequency is used to rotate the angle of the motor.
I know generating PWM with variable duty cycle is possible in PWM pins using Timers but i don't understand how the arduino Servo.h library makes digital pins act like PWM too , whenever i connect the servo to any one of the digital pins of the arduino and code accordingly.
So how does Arduino 'Servo.h' Library manage to make a digital pin act like a PWM and what should the native AVR C code for this action look like?
I am trying to avoid third party libraries as much as possible and trying to learn Embedded systems thoroughly.
Please do not suggest big banging PWM method.
Thanks...

The source code for the Arduino libraries is available, just go look there to find out how it does it.

Please do not suggest big banging PWM method ... why do you say that if you do not know how the library does it?

@jsotola Sometimes people advise using alternatives when they too don't have a proper knowledge so, to them only, i would prefer not to be recommended bit banging method (alternative).

@CoderBittu you asked how the library works ... there is no recommendation to be made ... there are no alternatives ... you did not ask for suggestions about how you should do it

I believe the servo library uses one (or more depending on board architecture) inbuilt 16 bit timers (timer1 on the UNO) to produce PWM  directly on a digital pin using a low level equivalent of a digital write. The direct use of the timer prevents the use of that timer for other purposes like analogWrite().
In comparison a frequently used, more user-friendly method of producing PWM on Arduino is to use analogWrite() on designated PWM pins only.
The servo library source code is on github here.
You may have already answered your own question, as you did mention the bit-banging PWM method. That's what it looks like to me, but I'm not an expert on lower level programming.
See also: How can the Arduino Uno support up to 12 servos if it only has 6 digital PWM pins?


text:
How to pass rx/tx led outputs to a shield
I have an Arduino Uno. I am building a custom shield and was wondering how I would connect two of the LEDs on the shield to the TX / RX LEDs on the Uno. Digital pins 0 and 1 seem obvious, but after further research, it appears that they are not for this.
In better terms, I want two LEDs on my shield that replicate the TX / Rx LEDs on the Arduino Uno.
How would I do this?

The TX/RX LEDs on the Uno are not connected to the main MCU but are instead connected to the USB communication chip, be it a FTDI or ATmega16U2. You would need to solder wires to the appropriate connections on the board and then connect them to the shield in question.

If you need just indicate data on TX/RX you can make simple circuit on shield bound to TX/RX lines.

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


text:
How to connect multiple MPU-9250 IMU sensors to a single Arduino Uno?
The datasheet says the I2C bus limits itself to only two MPU-9250 sensors. How can I control multiple (>2) MPU-9250 through a single Arduino Uno? Is it possible to add another bus?
Please, help.

this has been asked mamy times ... search this website for multiple I2C

Try this one : https://forum.arduino.cc/t/two-mpu-9250-on-arduino-uno/455724

I2C is a bus, it's sole purpose is to connect multiple devices together (1 master, multiple slaves)