text:
Why do I keep blowing up Nanos when I solder them?
I have blown up 2 Arduino Nanos and I'm trying to figure out what I'm doing wrong.
In both cases, I was powering the boards with a 16V supply (I know this is high, but the regulator datasheet says it is good to 25V, and the regulator was not damaged). I unplug the supply and USB cable and then start soldering to one of the pins (A6). When I plug the board back in, the L LED does not flash, indicating the bootloader has been erased. The POW light is on and I still measure 5V, indicating the regulator is working. When I connect the board to my PC, the serial port pops up just fine. But when I try to upload a sketch, the IDE times out and says it cannot communicate with the board.
I attempted to reprogram the bootloader using a raspberry pi but avrdude also says it cannot find the device either. It looks like the microcontroller is blown.
My iron tip is grounded, so my best guess is some residual power in the supply travels through the microcontroller to my iron and shorts something out. But this seems unlikely seeing as A6 is an input and grounding it should be just fine even when the supply is fully on.
Any ideas what I could be doing wrong? FYI, I am cross-posting this on the Arduino forums.

What circuit are you soldering the Nanos to and are you using the Vin pin correctly? Have you tested this configuration on a breadboard? Cross-posting to what other StackExchange sites?

http://forum.arduino.cc/index.php?topic=680237

If your nano is a cheap chinese clone then it could die just by you looking at it wrong.

Check your soldering temperature and that you are not overheating the microcontroller, or any other component on the board.  Also check your flux.  Some types are more conductive than others and you will need to take care cleaning with isopropanol.

Thanks. The configuration works fine until the soldering event. Yes, it's a clone; maybe that is the issue. I am not overheating the microcontroller; the point where I'm soldering is pretty far from it. I am cleaning the flux.

"when the supply is fully on"  do you solder while the circuit is powered?!

No. I unplug the supply and USB before soldering.

something else is at play here .... please post a couple of clear, well lit pictures of the soldered board ... top and bottom views ... board should fill most of the picture

My advice would be not to solder directly to the Nano pins.  Instead, use the appropriately sized DIL socket, and solder to the pins of that instead.   Then plug in the Nano once the soldering is complete.

the OP would probably have to solder the headers to the board first


text:
Java Errors thrown by Ardunio IDE when attempting to open serial monitor
I am only getting this error on one of my Windows 10 PC's.   On another windows 10 PC and Mac, the board (Mega 2560) is working fine.
Any hellp or advice on this would be appreciated.
THE PROBLEM
After uploading the sketch and then attempting to open the serial monitor, Java error messages (shown below) are displayed in the information window in the IDE.  The serial monitor fails to open.  Other sketches that do not use the serial monitor work fine.
ANYTHING UNUSUAL ABOUT THIS PC?
The only thing that is perhaps unusual about this PC is that Serial Ports COM1: AND COM2: are real RS432 hardware serial ports.
The Ardunio IDE connects to the board via USB Serial Port COM5:
REMEDIES TRIED SO FAR

Uninstalled and reinstalled the software (including purging Arduino settings in Documents\ folder
Trying the board on other PC's / MAC (to verify that it is not a faulty board).  Tests confirm that board itself is fine

THE ERROR MESSAGES

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2
    at processing.app.AbstractMonitor.(AbstractMonitor.java:68)
    at processing.app.AbstractTextMonitor.(AbstractTextMonitor.java:53)
    at processing.app.SerialMonitor.(SerialMonitor.java:42)
    at cc.arduino.packages.MonitorFactory.newMonitor(MonitorFactory.java:49)
    at processing.app.Editor.handleSerial(Editor.java:2193)
    at processing.app.Editor.lambda$buildToolsMenu$17(Editor.java:723)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:842)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)
    at java.awt.Component.processMouseEvent(Component.java:6539)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6304)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

What version of the IDE are you using, and how did you install it?

Try running the ArduinoIDE as Administrator, test the com port to use with a terninal program like PUTTY.

The version of the IDE that I am using, on both windows PC's is 1.8.12 (Windows Store Version 1.8.33.0). The software was obtained by going directly to the Arduino.cc downloads page which then redirected me to the Windows Store.   Both Windows PC's are 64 Bit, and I log into both using my Microsoft Account.   I tried using Putty as suggested, but that just bleeped when trying to communicate with any serial port, even the ones connected to my Chess board with the RS432 interface.   The Chessboard still works fine. For the time being, I will just use the other PC for the Arduino.

Just as an experiment, I downloaded one of the 'nighly releases' directly from the Arduino site.  And, guess what - it works! Bit of a mystery why the same Windows Store version works on one of my PC's and not the other but, for the teim ebing, problem solved.

source: Stack Exchange

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

sort: votes


text:
Receiving garbage value when sending a Json object from Arduino Uno to NodeMCU using SoftwareSerial
I am trying to send a Json Object from Arduino UNO to NodeMCU using SoftwareSerial. I am using Arduino IDE. I am getting garbage value on Serial monitor of NodeMCU. Tried it with different garbage values, couldn't receive data from Arduino UNO. Below is the code. PLease help. Thank you in advance. I haven't made a common ground. I have referred this webpage here.
Arduino UNO code:
    #include <SoftwareSerial.h>
    #include <ArduinoJson.h>
    SoftwareSerial s(5,6);

    void setup() {
    s.begin(9600);
    }

    void loop() {
     StaticJsonBuffer<1000> jsonBuffer;
     JsonObject& root = jsonBuffer.createObject();
      root["data1"] = 100;
      root["data2"] = 200;
      if(s.available()>0)
      {
       root.printTo(s);
      }
    }

NodeMCU code:
    #include <SoftwareSerial.h>
    SoftwareSerial s(D6,D5);
    #include <ArduinoJson.h>

    void setup() {
      // Initialize Serial port
      Serial.begin(9600);
      s.begin(9600);
      while (!Serial) continue;

    }

    void loop() {
      StaticJsonBuffer<1000> jsonBuffer;
      JsonObject& root = jsonBuffer.parseObject(s);
      if (root == JsonObject::invalid())
        return;

      Serial.println("JSON received and parsed");
      root.prettyPrintTo(Serial);
      Serial.print("Data 1 ");
      Serial.println("");
      int data1=root["data1"];
      Serial.print(data1);
      Serial.print("   Data 2 ");
      int data2=root["data2"];
      Serial.print(data2);
      Serial.println("");
      Serial.println("---------------------xxxxx--------------------");

    }

I haven't made a common ground. -- they maybe you should? https://majenko.co.uk/blog/importance-sharing-grounds

I tried making common ground too, same result

The problem with ArduinoJson.h is that it doesn't ensure robust and reliable transfer over UART serial.
Instead, you should use SerialTransfer.h to automatically packetize and parse your data for inter-Arduino communication without the headace.The library is installable through the Arduino IDE and includes many examples.
Here are the library's features:

This library:

can be downloaded via the Arduino IDE's Libraries Manager (search "SerialTransfer.h")
works with "software-serial" libraries
is non blocking
uses packet delimiters
uses consistent overhead byte stuffing
uses CRC-8 (Polynomial 0x9B with lookup table)
allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 254 bytes)
can transfer bytes, ints, floats, and even structs!!

Example TX Arduino Sketch:
#include "SerialTransfer.h"

SerialTransfer myTransfer;

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

void loop()
{
  char buff[] = "hi";

  myTransfer.txObj(buff, sizeof(buff));
  myTransfer.sendData(sizeof(buff));
  delay(100);
}

Example RX Arduino Sketch:
#include "SerialTransfer.h"

SerialTransfer myTransfer;

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

void loop()
{
  if(myTransfer.available())
  {
    char buff[40];

    myTransfer.rxObj(buff, sizeof(buff));

    Serial.println("New Data: ");
    Serial.write(buff, sizeof(buff));
    Serial.println();
  }
  else if(myTransfer.status < 0)
  {
    Serial.print("ERROR: ");

    if(myTransfer.status == -1)
      Serial.println(F("CRC_ERROR"));
    else if(myTransfer.status == -2)
      Serial.println(F("PAYLOAD_ERROR"));
    else if(myTransfer.status == -3)
      Serial.println(F("STOP_BYTE_ERROR"));
  }
}

Thank you so much. It solved my problem. The transmission is proper now.

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


text:
C3 not declared in this scope when running MIDI example code
I'm trying to run the MIDI example from Arduino.CC in Arduino Studio.
I am using an Arduino Leonardo, which has USB HID capabilities. I have installed the library as mentioned:

When I press the compile or upload button, it says:
'D3' was not declared in this scope

What's wrong? How do I fix this?

the error happens when the source code is being compiled .... the upload is not attempted ... upload only happens when the code compiles without errors

The pitches for the notes are taken from pitchToNote.h. In there you can see definitions for the notes like:
#define pitchC3  48

It seems that the names were changed from C3 to pitchC3.
I am not 100% sure, but my guess is that this was done to avoid conflicts between the note A3 and the analog input A3 (and silimar).
So, in line 25 of the example code, add pitch for all notes:
const byte notePitches[NUM_BUTTONS] = {pitchC3, pitchD3, pitchE3, pitchF3, pitchG3, pitchA3, pitchB3};


text:
Why can't I use 3V output of arduino pro mini?
I have an Arduino pro mini and I tested digital write of an pin and it is 3.2V and then I connected it to a 3V motor, but when I connected the motor to it, The voltage drops under 0.2 Volt, Can any one describe the science behind voltage drop ?
I know I've better use a transistor and separate the motor power but, what you should do when you have a single 3V power source? and I know there are some motor driver chips, but is it possible to keep it simple?

Science behind this? It's either some big motor or you forgot to make that pin an output, and pullup is even weaker than push-pull driver. Look for terms like Voltage source, ideal voltage source and loaded voltage source. (+ info from answers)

NEVER drive a motor directly from an Arduino IO pin.  You will kill the Arduino.
It's not a question of voltage, it's a question of current, and that is where the transistor comes in.  If you have a 3.3V Arduino (as it sounds like you have) then you may be able to drive the motor using the 3.3V output of the Arduino (VCC pin? Not sure with that model) and a transistor. That is the simplest arrangement.

simulate this circuit – Schematic created using CircuitLab

Using that circuit is a bad idea. (not the part about never trying to drive a motor directly from a GPIO pin. That part is true.) At the very least you'll need a flyback diode across the motor to prevent reverse EMF from damaging the transistor. Another problem is that the 3.3V output  from most Arduinos is VERY low current - and quite unlikely to be enough to drive a motor. It might overheat the voltage regulator, or cause the 3.3V line on the Arduino to droop

@DuncanC Good call on the flyback diode. I forgot that. But you are wrong about the 3.3V. On old Arduinos where the 3.3V was provided by the FT232 chip it was limited to 50mA. Now it's in the order of hundreds of mA - and on a 3.3V board it will be many more.  But I did qualify it with may be able to.

@DuncanC That's CircuitLab's symbol for a schottky. It wants to be a schottky, not a normal diode, so it switches into reverse faster.

@DuncanC By the way - for the 3.3V, ignore the specs on the Arduino website. Those haven't been updated since the R1, and it has gone through many revisions since then.

And anyway, for the Pro Micro 3.3V it uses the MIC6219 which can provide 500mA peak.

About the bipolar transistor - the voltage drop starts around 1.4V (depends on Ice current and also on base current/h21e), so it can be little bit too much for 3.3V (at least 3V motor won't run at full speed)

I would normally use a FET. But I doubt the OP could get his head around that. So confusing the poor little ardueenies with pedantry.

What is the current rating of your motor? What type of Arduino are you using, and how much current does it say it can provide from the 3.3V line? The bottom line is this: The voltage regulator will adjust it's output to keep the 3.3V line at 3.3V up to it's current limit. If you draw more current than that, the voltage will start to drop, and/or the voltage regulator will start to overheat.

He already said it was a pro mini. I have already given the specs of the regulator on there.

I can't find anything on the part number MIC6219. What is it's sustained current rating? And isn't that with a good heatsink attached? Arduino boards don't usually have any heatsinks on their  voltage regulators, which GREATLY reduces the sustained power you can draw from them without overheating them.

@DuncanC That was a typo - it should be the MIC5219... http://ww1.microchip.com/downloads/en/DeviceDoc/MIC5219-500mA-Peak-Output-LDO-Regulator-DS20006021A.pdf

You can drive the motor from the same 3v supply that powers your Arduino (assuming the supply can deliver enough current for both). What you can't do is power the motor through the Arduino, neither from a pin, nor from its on-board voltage-regulator. And especially don't try to use a 5v Arduino's 3v pin to drive it. Their 3v regulators provide only a limited amount of current.
If you try to drive a motor through the Arduino and it needs too much current, you risk frying the Arduino. If you supply the motor from the same power supply but not through the Arduino, and the motor takes too much current, the worst that will happen is the supply voltage will fall and Arduino will shut down.


text:
IR Remote with Arduino
I want to build a remote with Arduino Nano. I have viewed many tutorials in the web, but I don't have the IR Receiver (TSOP1740). Is there any way to use Jjust an IR Led as the receiver?

When you want the Ardiuno to be the remote, why do you need a receiver on it? A normal renote (like for a TV) only sends, it does not receive

I need the receiver to record the signal sent by the remote. Then the recorder signal will be plaayed when the equivalent button on the arduino remote is pressed.

If using the $0.10 1838 Chinese IR receivers, they require different timing than the expensive ones. They work great with this modified library, however: https://github.com/ElectricRCAircraftGuy/IRLib

No, you can't use just an IR LED as the receiver.  While it is true that an IR LED can also be an IR receiver the voltages it generates are really really small. So you would need an amplification circuit. On top of that the TSOP1740 includes a band-pass filter to isolate the carrier frequency of the transmitted signal from the background light, which you would also need to implement.
So yes, while you could use an IR LED as a receiver, you need a large amount of support circuitry with it (which takes expertise not relevant to this website) to get it to do anything useful.

I know, the TSOP1740 has an internal amplifier, but I only have an UA741, aand am afraid that if I use that for amplification, the signal will be heavily distorted. Nevermind, I will just look up my TV model and search for the remote signals

I don't know...I think I might actually be able to make a plain IR LED, with no support circuitry or external amplifier, read an IR signal. I think this is one of those cases where with enough knowledge you can use software to make up for missing hardware, and I think it just may be possible. For the sake of this question it's out of the question, but I just might make this a challenge I'm willing to take on one of these days. I have some ideas, but I suspect I could use capacitive touch digital pin sensing to time for loop counts as a means of reading the signals, then digitally filter.

Related: https://www.instructables.com/id/Arduino-Use-LED-as-a-light-sensor/

If you could sample the incoming signal from the LED fast enough you could then pass it through a biquad band-pass filter to isolate the right carrier frequency then either pass it through a biquad low-shelf filter to recover the signal or arrange for simple OOK detection. It is something that could be done in software, but I'd not want to do it on an Arduino, instead choosing something that has an FPU or DSP built into it.

You could make a remote without a receiver.  It would require knowing what signals to send.  The receiver is to essentially help in training your arduino by letting it detect the signal from an already working remote and then replay it on the LED.
You can't make a receiver with JUST an LED. (Majenko's got this one covered).


text:
SD card with arduino UNO
I am trying to use a micro SD card in order to store data sent from an arduino UNO.
My setup consists of:

Arduino UNO (5V logic), powered directly from USB cable
Digilent Full-sized SD Card Slot
Simple microSD to SD adapter
Transcend 4GB microSD card SDHC
TXB104 Logic Level Converter
USB-powered PSU, that provides both the 3.3Volts and the 5Volts

The above components are connected as mentioned below:
Pins 1 to 4 of the Digilent SD module are driven to the 3.3Voltage side of the logic level converter. Also the SD module is powered with 3.3Volts. The 4 signals (SS, MOSI, MISO, SCK) are then taken from the 5Volt side of the logic level converter and are driven to the arduino UNO pins 10, 11, 12 and 13 respectively. Also, all the components have a common ground. The card is formatted to FAT32 using the SD card Formatter from sdcard.org.
In the arduino, I upload the SdInfo sketch of the Sdfat library. The result I get is the following:

Let me know if I can provide any more info.

I doubt the SDHC card is supported.
I don't have the same card slot reader, however, mine only worked with 'old' SD cards, not SDHC, SDXC etc.
So try an old one to see if it works (at least you rule out this option).


text:
I'm trying to control a servo with a push of a button but its not working HELP
I'm new to Arduino and I'm following this tutorial: https://www.youtube.com/watch?v=T2HMJiy9b_I   but the problem is the servo just keeps moving back and forwards on it own and the button is doing nothing when pressed please help.
Code:
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
#define servoPin 3 //~
#define pushButtonPin 2

int angle =90;    // initial angle  for servo
int angleStep =5;
const int minAngle = 50;
const int maxAngle = 110;

int buttonPushed =0;

void setup() {
  // Servo button demo by Robojax.com
  Serial.begin(9600);          //  setup serial
  myservo.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  pinMode(pushButtonPin,INPUT_PULLUP);
   Serial.println("Robojax Servo Button ");
}

void loop() {
  if(digitalRead(pushButtonPin) == LOW){
    buttonPushed = 1;
  }
   if( buttonPushed ){
  // change the angle for next time through the loop:
  angle = angle + angleStep;

    // reverse the direction of the moving at the ends of the angle:
    if (angle <= minAngle || angle >= maxAngle) {
      angleStep = -angleStep;
       buttonPushed = 0;
    }
    myservo.write(angle); // move the servo to desired angle
      Serial.print("Moved to: ");
      Serial.print(angle);   // print the angle
      Serial.println(" degree");
  delay(100); // waits for the servo to get there
   }

}

I posted the code:https://robojax.com/learn/arduino/?vid=robojax_Servo_PB2_move_one_direction. I need help with the code so when the button is pressed the servo will rotate 0 to 180 degrees and stop but the button is unresponsive and the servo just keeps moving back and forth

Edit your question. Select all of the code, and tap the {} code formatting button. Your code is unreadable as posted.

ok how about now

Once you push the button once and buttonPushed becomes 1 the servo will move forever because nothing ever sets buttonPushed back to 0.  You need an else there to set it back to 0.

sorry, but I don't really know how to do that. :(

Also you should use a pull down resistor if not already doing so.

Actually that code sets buttonPushed to 0 when the angle reaches one of the limits. From that code I would expect the servo to move to one of it's limits and stop if you pressed the button for a very short time. As long as you hold the button down I would expect the servo to keep moving back and forth.

The button appears to be wired through the pin to ground, and using INPUT_PULLUP mode on the pin. That should work. As long as you hold down the button, the servo should move back and forth. When you let go of the button it should stop almost immediately (within 1/10th of a second.)

i posted some code that shows how to detect the button being pressed at the moment that you press it, but it does not keep detecting a button press if you hold the button .... https://arduino.stackexchange.com/questions/74876/restart-sequence-of-neopixel-stick-with-a-push-button-at-any-time/74949#74949

if it start shaking on it own. it might be electrical problem.
How you power the system?

This condition below is never met because a boolean comparison is implied :
if( buttonPushed ){

and buttonPushed is declared as :
int buttonPushed =0;

A proper comparison should be OK :
if( buttonPushed == 1)
{
   // Do something
}

Also the buttons need proper debouncing or the push event will have undetectable results :
https://dduino.blogspot.com/2012/03/arduino-button-debouncing.html

C++ will treat any non-zero value as true and 0 as false.  It is perfectly legal to use an int inside an if statement in this way.   If you would like I can post demonstration code to prove it.  It not great coding style, but it won't cause any failure.

An if statement works with integers!

Mea culpa you are right :
https://www.arduino.cc/reference/en/language/variables/constants/constants/


text:
Arduino PID controller for Triac
I am designing a new soldering station which will use a 24 V ac soldering iron.
I started to make some research and I designed a few steps of the soldering station. I will use a 24Vac/100VA toroidal transformer. I will use a 24V/50W soldering iron with K type thermocouple. For the thermocouple I will use a LM358 amplifier. Please have a look at the attached schematic and code. The code is not ready yet and I need some help in making the connection between the PID library and output in the code.
The voltage on the soldering iron looks like: https://ibb.co/CMF1gQ0
If I rotate the pot, nothing happens on the screen of the scope.
https://ibb.co/vdDRmnJ
I wrote a few lines of code but I don't know how to make the connection between the PID library functions and the interruption function and the other variables in my code.
Please have a look at the code and at the schematic and tell me what you think...
I am waiting for your help.
#include <PID_v1.h>

int AC_LOAD = 1;    // Output to Opto Triac pin
double set_value = 0;
double input = 0;
double output = 0;

PID aaa_PID(&input, &output, &set_value, 1, 0.05, 0.25, DIRECT);

void setup()
{
  aaa_PID.SetOutputLimits(0, 128);
  aaa_PID.SetMode(AUTOMATIC);
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # from the table above
}

//the interrupt function must take no parameters and return nothing
void zero_crosss_int()  //function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
  int dimtime = (75*output);    // For 60Hz =>65
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  int in = analogRead(A0);
  input = map(in, 0, 550, 25, 400);
  set_value = set_point;
  aaa_PID.Compute();

}

Seems legit to me, though you might want to disable the interrupt while executing myPID.Compute(), since you can get garbled data in your interrupt, when it happens while the Output variable gets assigned. What exactly is your problem with the code?

the problem is that I don't know if I correctly wrote the zero_cross_int() function and I don't know where is the relationship between the output of the PID calculations and the output waveform of the Arduino. I meant in the zero_cross_int() function the read value should be the one from the zero crossing detector or the one from the potentiometer ?

It is not clear to me, what you mean. You changed your code again. Now you are reading a second analog input in the interrupt. Why? With your old code the logic was the following: analogread the potentiometer for the setpoint, calculate output of PID, use PID for driving the triac signal. Only missing was the reading of the input for the PID (since you are creating a soldering station, here you would have to measure the temperature) and assigning it to Input. The additional analogRead in the new code is meaningless (you don't use the value anywhere)

I modified the code again: A1 input is for the potentiometer and A0 is for the temperature sensor.

I have tried the code above and I am stuck at the potentiometer. I checked it in particular and it is working. But when I am rotating the knob, then nothing happens. I only see on the oscilloscope this waveforms: https://ibb.co/mBBnmk3

I need some help in making the connection between the PID library and
  output in the code

PID calculates the value of output and it is used in int dimtime = (75*output);.
The aaa_PID object gets the reference to variable output with & so when the PID algorithm sets the output value it sets the value of this variable in your sketch.
output should be volatile double output = 0; because it is used in interrupt.
EDIT 2:
I hope you wired the zero crossing detector to pin 2, because that is the pin for external interrupt 0. And don't use pin 1 for Triac, it is wired to USB chip too.
EDIT:
Your code stays too long in interrupt. You exit the interrupt only in the time after firing the TRIAC and the next zero crossing.
In this Arduino SE answer I offer two sketches which demonstrate Triac control. This is one of them:
#include <TimerOne.h>

const byte INTERRUPT_PIN = 2;
const byte TRIAC_PIN = 4;
const byte TRIAC_PULSE_MICROS = 30;

const int FADE_MAX = 9800;
const int FADE_MIN = 2000;

volatile bool triacOn;
volatile int period = FADE_MIN; // microseconds cut out from AC pulse

int fadeAmount = 10;

void zeroCrossing() {
  triacOn = false; // triac tuns off self at zero crossing
  Timer1.setPeriod(period); // to call triacPulse() after off period
}

void triacPulse() {
  if (triacOn) { // stop pulse
    digitalWrite(TRIAC_PIN, LOW);
    Timer1.stop();
  } else { // start pulse
    digitalWrite(TRIAC_PIN, HIGH);
    triacOn = true;
    Timer1.setPeriod(TRIAC_PULSE_MICROS);
  }
}

void setup() {
  pinMode(TRIAC_PIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), zeroCrossing, RISING);
  Timer1.initialize();
  Timer1.attachInterrupt(triacPulse);
}

void loop() {
  period = period + fadeAmount;
  if (period <= FADE_MIN || period >= FADE_MAX) {
    fadeAmount = -fadeAmount;
  }
  delay(25);
}

the other uses direct registers access o AVR.
EDIT 3: mike's oscilloscope output of the sketch above: https://www.youtube.com/watch?v=dnfy_EsPlVI
EDIT 4: the PID outputs high values for high power and small values for lower power. but the Triac period is the off time. so the period should be something like period = 11000 - (75 * output)
here are the input and output values of mike's code based on this answer (blue is temperature, red is output for the Triac period):

The PID control gets smoother over time as it finetunes its parameters,
but I think a simple PID has some problems with the sine relation between the output (time) and the resulting heating power.

Comments are not for extended discussion; this conversation has been moved to chat.

I see several issues here.
The most serious is in the wiring of the Arduino. The first argument of
attachInterrupt() is an interrupt number. On the Uno, “interrupt 0” is
wired to the pin “digital 2”. This is where you should connect the
output of the zero-crossing detector (ZERO_OUT).
Then, as noticed by Juraj, there is the issue of the interrupt handler
taking too long to execute. This is generally considered bad practice,
and it has some negative consequences on the working of the Arduino core
like, e.g., the millis() function will be completely off. I do not
think, however, that this is a serious issue for you. There is one
single time-critical bit in your program, which is the generation of the
triac trigger pulses. You really do not care about millis() or any
other time-related things. Thus, at least for the initial version of the
program, I would not care too much, and just let the interrupt handler
delay as needed.
The third issue has been noted by chrisl in a comment: there is a race
condition with both the main program and the interrupt handler accessing
the same output variable. Race conditions are a nasty kind of bug
because usually things work fine “most of the time” and then fail at
unexpected times. I would not recommend, however, to run
myPID.Compute() with interrupts disabled: that may throw off the
timing of your triac pulses. Instead, compute the delay required by the
interrupt, save it to a temporary variable, then copy it to a variable
shared with the handler. Only the copy needs to be done with interrupts
disabled, and that takes only a handful of CPU cycles:
// Variable used by zero_crosss_int().
// Do not forget the `volatile' qualifier.
volatile int dimtime;

void loop() {
    // PID and associated computations.
    set_value = map(analogRead(A1), 0, 1023, 150, 400);
    input = map(analogRead(A0), 0, 550, 25, 400);
    aaa_PID.Compute();
    int tmp_dim_time = 75*output;

    // Critical section executed with interrupts disabled.
    noInterrupts();
    dimtime = tmp_dim_time;
    interrupts();
}

Edit: If things do not work, you should try to debug piece by piece.
Sending debug messages to the serial port should help, although serial
communication is likely to be significantly slowed down by the
long-running interrupt handler. As an alternative, you can use the triac
control pulses as a debug aid, maybe with the heating element unplugged.
For example:

In loop(), set dimtime to a value proportional to set_value.
Turn the pot and look at the FIRING_PULSE signal. Does the pulse
width vary proportionally to the pot position? Is it in sync with the
Vin zero-crossings?
Set dimtime proportional to input. Heat the thermocouple by some
external means. Does FIRING_PULSE vary as expected?
Set dimtime proportional to output, but keep the heating element
unplugged. How does the pulse change as you move the pot or heat the
thermocouple?

I added the code into my program and I run it, but on the scope screen appears something like this: https://www.youtube.com/watch?v=rAK9ounINAQ , and the heating of the soldering iron does not stop. As the temperature increases, the voltage on the soldering iron heater also increases...

@mike_mike: did you fix the wiring?

Yes, the “interrupt 0” is wired to the pin “digital 2”, as you said.

@mike_mike: Are you sure the PID parameters are sensible for your system? How did you tune them?

The PID parameters are from another soldering station, which used a mosfet instead of a triac.


text:
Does MFRC522 module read all 13.56 MHz RFID tags?
Hello everyone. Does MFRC522 module read all 13.56 MHz RFID tags?
Or there are different types of the 13.56 MHz tags that the MFRC522 module reads only one type of them?

The second sentence of the datasheet: The MFRC522 supports all variants of the MIFARE Mini, MIFARE 1K, MIFARE 4K, MIFARE Ultralight, MIFARE DESFire EV1 and MIFARE Plus RF identification protocols.

Thanks a lot...


text:
What does []() argument in function mean?
I am working in ESP8266 AsyncWebserver library and have been using this [](parameter) as an argument to some functions as shown below but does not really know what it means. Being a neophyte I am curious to know what does this convention means, its functionalities and how to use it. Hopefully experts here would help me with this.

server.on("/page",HTTP_GET,[](AsyncWebServerRequest * request){
    some code....;
    request->getParam("Param1")->value();
});

That is called a lambda expression and it's a way of including the content of a function as a parameter anonymously instead of writing an actual function and using the name of it.
It's shorthand for:
void myCallback(AsyncWebServerRequest * request) {
    // some code....;
    request->getParam("Param1")->value();
}

// ...

server.on("/page", HTTP_GET, myCallback);

It does have a few benefits over traditional functions at the expense of readability, such as the ability to "capture" local variables from the surrounding scope.

Thanks Mr.@Majenko, I will look further about this topic. So in the above example instead of creating a new function as a callback they used lambda function on the go to use locally within the function scope itself Am I right. Im just curious to know  can we use the variables declared in server.on function inside the lambda

All is explained in the link. But any variable that is defined within the function that server.on appears in can be "captured" by placing it between the [...], so you can then use it from within the lambda expression itself.

Thanks Mr.@Majenko thats useful

More generally, the lambda is actually shorthand for a class declaration somewhere in the enclosing scope, struct unnamed_lambda_helper { /* captured local variables are data members of this class */ auto operator()(/* arguments here */) -> /* return type here, if specified */ { /* body here */ } };, and then the expression creates an instance of this class.

Is it C++ only?

@PeterMortensen It is a C++11 feature (meaning older compilers may not support it).  Of course, other languages do have their own version of this.  To the best of my knowledge, C does not.

Thanks @CortAmmon


text:
Why doesn't OTA work with the Ai-Thinker ESP32-CAM board?
I have working code on an Ai-Thinker ESP32-CAM board, programming over serial.
I would like to reprogram using OTA, but adding in the functionality from the BasicOTA sketch (which I have done on various other boards successfully) fails when OTA programming is attempted, the board reboots following an abort() and a stack trace is generated.
The invaluable ESP32 exception decoder shows the fault occurs from checking if memory location is safe to write.
Normally, I would choose a partition option which includes OTA, but the Ai-Thinker board doesn't have this option in the IDE

The boards.txt file configures what can be configured in the Arduino IDE for each board.
On my installation, this is found at
C:\Users\MyUser\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\boards.txt
I found the section esp32cam.name=AI Thinker ESP32-CAM and changed the lines:
esp32cam.upload.maximum_size=3145728
esp32cam.build.partitions=huge_app

to
esp32cam.upload.maximum_size=1966080
esp32cam.build.partitions=min_spiffs

The various options are detailed in the same file with keys named esp32.menu.PartitionScheme., and for some boards these options are configurable be the user. To add this, remove (or comment out with a # character) the two lines found above so they look like:
# esp32cam.upload.maximum_size=3145728
# esp32cam.build.partitions=huge_app

and add the required menu selections for your application- e.g.
esp32cam.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS)
esp32cam.menu.PartitionScheme.huge_app.build.partitions=huge_app
esp32cam.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
esp32cam.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
esp32cam.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
esp32cam.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080

After making any changes to boards.txt, restart the Arduino IDE for the change to take effect. Note that these changes (and any changes to the installation) may be overwritten by any future upgrades or library updates, so note your changes so they can be easily reapplied.
Alternatively, add the menu lines to boards.local.txt, introduced in Arduino 1.6.6 so they should persist during updates. In this case, no change needs to be made to boards.txt, as the boards.local.txt entries override those in boards.txt. I haven't tested this, hopefully it works across library updates and IDE upgrades.

You do not have to go through the hassle with editing the boards.txt if you want to have OTA only if you do not need it or you want a custom partition scheme.
That said the OTA partition is always what is left so e.g. Med Spiffs App 1.9MB, Spiffs 190KB means 1.9 MB OTA partiton.The caveat is if you want to OTA a 1.8 MB App with 1 MB Spiffs that will NOT work. The OTA file has to be around 100kb (from experience) smaller than the availabe OTA partition. If you want to update APP and SPIFFS thats a topic on its own. So before editing your boards.txt check the following:

App (uncompressed) is OTA space + ~100KB
your OTA routine runs stable with/in small apps
no connection problems during upload and
proper OTA error handling in your code
for initial testing attach no hardware to the board.
If using the unmodified camera example or a custom on with face recognition you will fail with OTA because this is to big (~3MB APP!)
OTA routines (incl wifi libs) take ~800 kB for basic OTA

As I use AIThinker32cam modules in various scenarios I know what you are through ;-)

Enclosed two custom board definitions (with no OTA) as there is no predefined (ESP32 core 1.04) in C:\Users\YOUR_USERNAME\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\boards.txt just copy and paste into the section (search for esp32AiThinkerCam.menu.PartitionScheme :
esp32AiThinkerCam.menu.PartitionScheme.noota_3g=1MB APP/3MB SPIFFS (No OTA)
esp32AiThinkerCam.menu.PartitionScheme.noota_3g.build.partitions=noota_3g
esp32AiThinkerCam.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576
esp32AiThinkerCam.menu.PartitionScheme.no_ota=2MB APP/2MB SPIFFS (No OTA)
esp32AiThinkerCam.menu.PartitionScheme.no_ota.build.partitions=no_ota
esp32AiThinkerCam.menu.PartitionScheme.no_ota.upload.maximum_size=2097152

and the "magic unlocker" is the noota_3g.csv found in C:\Users\YOUR_USERNAME\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\tools\partitions,there the partition scheme isdefined. If you want to change that for custom partitions please ask a new question.EDIT
Enclosed acomplete boards.txt part for AI-Thinker just replace the complete existing part with this amd you have a bunch of new options - all tested in production with ESP32 core 1.04. (without custom partition schemes):
##############################################################

esp32AiThinkerCam.name=ESP32 AI Thinker Cam

esp32AiThinkerCam.upload.tool=esptool_py
esp32AiThinkerCam.upload.maximum_size=1310720
esp32AiThinkerCam.upload.maximum_data_size=327680
esp32AiThinkerCam.upload.wait_for_upload_port=true

esp32AiThinkerCam.serial.disableDTR=true
esp32AiThinkerCam.serial.disableRTS=true

esp32AiThinkerCam.build.mcu=esp32
esp32AiThinkerCam.build.core=esp32
esp32AiThinkerCam.build.variant=esp32
esp32AiThinkerCam.build.board=ESP32_DEV

esp32AiThinkerCam.build.f_cpu=240000000L
esp32AiThinkerCam.build.flash_size=4MB
esp32AiThinkerCam.build.flash_freq=40m
esp32AiThinkerCam.build.flash_mode=dio
esp32AiThinkerCam.build.boot=dio

esp32AiThinkerCam.menu.CPUFreq.240=240MHz (WiFi/BT)
esp32AiThinkerCam.menu.CPUFreq.240.build.f_cpu=240000000L
esp32AiThinkerCam.menu.CPUFreq.160=160MHz (WiFi/BT)
esp32AiThinkerCam.menu.CPUFreq.160.build.f_cpu=160000000L
esp32AiThinkerCam.menu.CPUFreq.80=80MHz (WiFi/BT)
esp32AiThinkerCam.menu.CPUFreq.80.build.f_cpu=80000000L

esp32AiThinkerCam.build.partitions=default
esp32AiThinkerCam.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue
esp32AiThinkerCam.menu.PartitionScheme.default=Default 1.2MB APP/1.5MB SPIFFS (OTA)
esp32AiThinkerCam.menu.PartitionScheme.default.build.partitions=default
esp32AiThinkerCam.menu.PartitionScheme.defaultffat=Default FATFS 1.2MB APP/1.5MB FATFS (OTA)
esp32AiThinkerCam.menu.PartitionScheme.defaultffat.build.partitions=default_ffat
esp32AiThinkerCam.menu.PartitionScheme.noota_3g=1MB APP/3MB SPIFFS (No OTA)
esp32AiThinkerCam.menu.PartitionScheme.noota_3g.build.partitions=noota_3g
esp32AiThinkerCam.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576
esp32AiThinkerCam.menu.PartitionScheme.no_ota=2MB APP/2MB SPIFFS (No OTA)
esp32AiThinkerCam.menu.PartitionScheme.no_ota.build.partitions=no_ota
esp32AiThinkerCam.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
esp32AiThinkerCam.menu.PartitionScheme.huge_app=3MB APP/1MB SPIFFS (No OTA)
esp32AiThinkerCam.menu.PartitionScheme.huge_app.build.partitions=huge_app
esp32AiThinkerCam.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
esp32AiThinkerCam.menu.PartitionScheme.noota_ffat=2MB APP/2MB FATFS (No OTA)
esp32AiThinkerCam.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat
esp32AiThinkerCam.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152
esp32AiThinkerCam.menu.PartitionScheme.noota_3gffat=1MB APP/3MB FATFS (No OTA)
esp32AiThinkerCam.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat
esp32AiThinkerCam.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576
esp32AiThinkerCam.menu.PartitionScheme.minimal=Min SPIFFS 1.3MB APP/700KB SPIFFS (OTA)
esp32AiThinkerCam.menu.PartitionScheme.minimal.build.partitions=minimal
esp32AiThinkerCam.menu.PartitionScheme.min_spiffs=Med SPIFFS 1.9MB APP/190KB SPIFFS (OTA)
esp32AiThinkerCam.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
esp32AiThinkerCam.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080

esp32AiThinkerCam.menu.FlashMode.qio=QIO
esp32AiThinkerCam.menu.FlashMode.qio.build.flash_mode=dio
esp32AiThinkerCam.menu.FlashMode.qio.build.boot=qio
esp32AiThinkerCam.menu.FlashMode.dio=DIO
esp32AiThinkerCam.menu.FlashMode.dio.build.flash_mode=dio
esp32AiThinkerCam.menu.FlashMode.dio.build.boot=dio
esp32AiThinkerCam.menu.FlashMode.qout=QOUT
esp32AiThinkerCam.menu.FlashMode.qout.build.flash_mode=dout
esp32AiThinkerCam.menu.FlashMode.qout.build.boot=qout
esp32AiThinkerCam.menu.FlashMode.dout=DOUT
esp32AiThinkerCam.menu.FlashMode.dout.build.flash_mode=dout
esp32AiThinkerCam.menu.FlashMode.dout.build.boot=dout

esp32AiThinkerCam.menu.FlashFreq.80=80MHz
esp32AiThinkerCam.menu.FlashFreq.80.build.flash_freq=80m
esp32AiThinkerCam.menu.FlashFreq.40=40MHz
esp32AiThinkerCam.menu.FlashFreq.40.build.flash_freq=40m

esp32AiThinkerCam.menu.UploadSpeed.921600=921600
esp32AiThinkerCam.menu.UploadSpeed.921600.upload.speed=921600
esp32AiThinkerCam.menu.UploadSpeed.115200=115200
esp32AiThinkerCam.menu.UploadSpeed.115200.upload.speed=115200
esp32AiThinkerCam.menu.UploadSpeed.256000.windows=256000
esp32AiThinkerCam.menu.UploadSpeed.256000.upload.speed=256000
esp32AiThinkerCam.menu.UploadSpeed.230400.windows.upload.speed=256000
esp32AiThinkerCam.menu.UploadSpeed.230400=230400
esp32AiThinkerCam.menu.UploadSpeed.230400.upload.speed=230400
esp32AiThinkerCam.menu.UploadSpeed.460800.linux=460800
esp32AiThinkerCam.menu.UploadSpeed.460800.macosx=460800
esp32AiThinkerCam.menu.UploadSpeed.460800.upload.speed=460800
esp32AiThinkerCam.menu.UploadSpeed.512000.windows=512000
esp32AiThinkerCam.menu.UploadSpeed.512000.upload.speed=512000

esp32AiThinkerCam.menu.DebugLevel.none=None
esp32AiThinkerCam.menu.DebugLevel.none.build.code_debug=0
esp32AiThinkerCam.menu.DebugLevel.error=Error
esp32AiThinkerCam.menu.DebugLevel.error.build.code_debug=1
esp32AiThinkerCam.menu.DebugLevel.warn=Warn
esp32AiThinkerCam.menu.DebugLevel.warn.build.code_debug=2
esp32AiThinkerCam.menu.DebugLevel.info=Info
esp32AiThinkerCam.menu.DebugLevel.info.build.code_debug=3
esp32AiThinkerCam.menu.DebugLevel.debug=Debug
esp32AiThinkerCam.menu.DebugLevel.debug.build.code_debug=4
esp32AiThinkerCam.menu.DebugLevel.verbose=Verbose
esp32AiThinkerCam.menu.DebugLevel.verbose.build.code_debug=5

Thanks for the extra information, +1 for the detail. However the originally set huge_app setting for this board doesn't seem to leave any space for OTA (3MB app). I am using a small SPIFFS partition but that doesn't change the setting in boards.txt.

As I wrote the huge App 3MB can not be OTAed - there is nospace left toOTA you can use max 1.8MB APP or get a board with 8MB PSRAM - thats a hardware limitation not a software - try with  med asgiven in y text - if your App is larger reduce it or no OTA

huge_app is the fixed default for this board in the supplied boards.txt, which doesn't allow OTA as we both agree. It doesn't have a configurable option to choose min_spiffs, that's what I add below, maybe this is different from your installed esp32 boards.txt?

Sorry for the misunderstanding - choose ESP32 Wrover Module and use it for the Ai Thinker32Cam to flash, if you want to have an own menu copy the new part I posted above to your boards txt

Thanks for clarifying, I didn't know the Wrover and Ai-Thinker boards were interchangeable for programming, so that would be an alternative workaround in this case. Note for others who may be following - camera pinouts are different between the Wrover and Ai-Thinker modules (see camera_pins.h in the CameraWebServer example).

Using the ESP32 Wrover Module worked for me thanks. The pin definitions are inline in the app so no problem with those.

As stated in the comments by @Codebreaker007 using the ESP32 Wrover Module works and if you put the pin definitions inline in the app there isn't a problem
#define CAMERA_MODEL_AI_THINKER

#if defined(CAMERA_MODEL_AI_THINKER)
  #define PWDN_GPIO_NUM     32
  #define RESET_GPIO_NUM    -1
  #define XCLK_GPIO_NUM      0
  #define SIOD_GPIO_NUM     26
  #define SIOC_GPIO_NUM     27

  #define Y9_GPIO_NUM       35
  #define Y8_GPIO_NUM       34
  #define Y7_GPIO_NUM       39
  #define Y6_GPIO_NUM       36
  #define Y5_GPIO_NUM       21
  #define Y4_GPIO_NUM       19
  #define Y3_GPIO_NUM       18
  #define Y2_GPIO_NUM        5
  #define VSYNC_GPIO_NUM    25
  #define HREF_GPIO_NUM     23
  #define PCLK_GPIO_NUM     22
#else
  #error "Camera model not selected"
#endif

Here.
Download this working ESP32-CAM sketch zip file with working OTA uploading:
"Working_ESP32_CameraWebServer_V2_with_OTA"
at
https://github.com/wjsanek/wjsanek.git
Make sure you read the simple "READ ME FIRST" file in the zip after unzipping.
This sketch overcomes any "file to big" or other OTA sketch uploading problems with this crumby, tempremental ESP32-CAM board (the $5 ESP8266 NodeMCU is better but the Arducam camera for it costs $23).
The ESP32-CAM board does not like to transmit very far.

OTA Requires you to partition your ESP32 with two sets of space for your program (ota_0 and ota_1 partitions) - during the OTA process, the unused one gets updated, and will be the next one that boots up.
This means that there's no room left for the camera (most camera driver libraries store the image in SPIFFS) to store the image data (OV2640 is 1622x1200 pixels, which is 1946400 bytes) because the only available partition schemes with OTA in Arduino IDE is 1.9mb program with 0.19mb (190kb) SPIFFs, which is 10-times-not-enough space to store camera images in.
the wjsanek project in here looks interesting - they're using one of the OTA partitions as the SPIFF for the camera. Very clever.


text:
Pushbutton and switch case
I am developing a project for my college.
PROJECT OUTLINE:
There are 3 sensors (Temp., Accelerometer & Humidity) will read the respective parameters continuously. in between if I press 'PushButton1' for 2 seconds  the Arduino must enter into programming mode.
The programming mode has 6 Switch cases. Each case gets selected one after one on the even of 'PushButton1' gets pressed for short time.
Also if I press 'PushButton1' again for 2 seconds in Programming mode the Arduino should come out of the programming mode.
PROBLEM:
In my current sketch I have to press 'PushButton1' for 2 seconds in Programming Mode for 2 seconds to change the case. Also I don't understand how to get out of the Switch Case loop.
The sketch is attached with this topic.
const int btn = 2;
const int ledPin =  13;
int selector = 0;
boolean  volatile wait = false;
const unsigned long event=2000;
unsigned long a=0;
unsigned long b=0;
unsigned long c=0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(btn, INPUT);
attachInterrupt(digitalPinToInterrupt(btn),decoder,CHANGE);
}

void loop()
{
  while(wait) {  }
  if (digitalRead(btn) == LOW) {
    a = millis();
  }
  else
  {
    b = millis();
    c=b-a;
    Serial.println(c);
        if (c>=event)
            {
              doSwitchStatement();
              selector++;
              if (selector >6)
                  {
                  selector = 0;
                  delay(500);
                  }
            }
  }
  wait = true;
  interrupts();

}

void decoder()
{
  noInterrupts();
  wait = false;
}

void doSwitchStatement()
{
  switch(selector)
  {
  case 0:
    Serial.println("Case 0");
    break;

  case 1:
    Serial.println("Case 1");
    break;

  case 2:
   Serial.println("Case 2");
    break;

  case 3:
   Serial.println("Case 3");
     break;

  case 4:
   Serial.println("Case 4");
    break;

  case 5:
  Serial.println("Case 5");
    break;

  case 6:
  Serial.println("Case 6");
    break;

  }
}

Using a blocking while statement on your loop and an interrupt is an ugly way to accomplish what you are trying to do. Your implementation will freeze the app in that while(wait) loop except when the button state changes, meaning you can't do anything else but respond to button state changes.

Where is your code to read and display the sensor values?

I would do it as a simple state without the blocking while
define two bools
bool buttonPress = false;
bool inMenu = false;

and add it to the loop.To differentiate between different press lengths you need to define them. There is nothing like an "automatic" short press recognition. Also use variables which are "speaking" making it easier to read code for others.
const unsigned long buttonPressLong = 2000;  // 2 seconds
const unsigned long buttonPressShort = 250;  // 0.25 secondis feasable
const unsigned long buttonPressDebounce = 50;
// debouncing for too short presse Thanks Edgar Bonet
unsigned long buttonPressStart = 0;

The program below does what you want (tested on my uno test lab). As Edgar Bonet commented before you should also debounce the button (look it up in WiKi) to exclude unwanted effects The times I use are practical on my hardware, so you could play around by looking at the serial monitor.
const int btn = 2;
const int ledPin =  13;
int selector = 0;
const unsigned long buttonPressLong = 2000;  // 2 seconds
const unsigned long buttonPressShort = 250;  // 0.25 secondis feasable
const unsigned long buttonPressDebounce = 50;  // debouncing for too short presse Thanks Edgar Bonet
unsigned long buttonPressStart = 0;

bool buttonPress = false;
bool inMenu = false;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(btn, INPUT);
  }

void loop() {
  if (digitalRead(btn) == LOW && !buttonPress ) {
    buttonPressStart = millis();
    buttonPress = true;
  }
  // The routine is only triggered if a previous pressing took place, otherwise it's ignored
  else if (digitalRead(btn) == HIGH && buttonPress) {
    if (millis() - buttonPressStart > buttonPressLong && millis() - buttonPressStart > buttonPressDebounce && inMenu) {
      Serial.print("Long press: ");
      Serial.println(millis() - buttonPressStart);
      buttonPress = false;
      inMenu = false;
    }
    if (millis() - buttonPressStart < buttonPressShort && millis() - buttonPressStart > buttonPressDebounce && !inMenu) {
      Serial.print("First short press ");
      inMenu = true;
    }
    if (millis() - buttonPressStart < buttonPressShort && millis() - buttonPressStart > buttonPressDebounce && inMenu) {
      Serial.print("Short press: ");
      Serial.println(millis() - buttonPressStart);
      doSwitchStatement();
      selector++;
      if (selector > 6) {
        selector = 0;
        delay(500);
      }
      buttonPress = false;
    }
  }
  // Here you could do other stuff as it is non blocking
}
doSwitchStatement(){...}// Stays the same as yours

Look at the code used as it is non blocking (of course there is room for improvement) but as a starter for your further experiments ...

Thanks a lot for such a great help. I am putting my entire Project theme again.

Please mark as accepted and thanks for the feedback


text:
how to get live view of esp32cam at remote sever using ssh tunneling?
I have found many projects involving esp32cam, but in all projects video is being seen on local server only.For its of no use.As for a home security project user can view the video at remote location like MI robotic camera.
Also i do not want any port forwarding or tunneling service from a third party like www.nabto.com, www.ngrok.com etc.

You will need something local to the ESP32CAM that can do the SSH tunnelling. Maybe a Raspberry Pi. Everything else is just networking and routing and port forwarding. Nothing about that affects the ESP32 in any way.

If you're feeling adventurous there's an attempt to turn an ESP32 into an SSH server here, though you'd probably have to implement a whole lot more to do port forwarding.

did you post this duplicate? ... https://electronics.stackexchange.com/questions/495797/how-can-i-make-a-project-in-which-using-esp32cam-i-can-see-live-video-at-remote


text:
USB control panel with endless turn knobs
I understand that some arduinos are capable of presenting themselves as a USB HID device to a PC.
I would like to use one to build a custom input controller that lets me read maybe 8 or so turn knobs that can infinitely turn left and right.
I am new to Arduino, but have cross-compiled avr binaries before.
Which arduino would be a good choice for this? And any additional parts that would help?
The end product would look like a MIDI mix panel, but it shouldn’t talk MIDI, just USB HID (to a linux PC.)
Note: there is an expensive, and out of stock, device that is similar to what I have in mind called MIDI Fighter Twister, pictured below, to get an idea.

Any with a native USB interface. Look for ATMega32U4 based ones. All the rest is about interfacing and that depends how many encoders you have and how they interface.

Options for the Arduino you have:

Get an Arduino supporting HID drivers (e.g. 32u4 based boards, Due /Zero/ Arduino Leonardo/ Micro or Pro Micro/ M0)
You use this library it supports UNO/MEGA/Leonardo/(Pro)Micro/ any 8u2/16u2/at90usb8/162/32u2/32u4 compatible boards and some more

Then you have to "just" code the communication between your programm and the HID driver -> pretty standard serial/usb stuff.
The parts (knobs) you seek could be rotary encoders, which have no fixed zero point, endless rotation and need 2 input pins per encoder (except GND or optional push function). The signals a rotary encoder produces (and what can be handled by libraries) are based on a 2-bit gray code available on 2 digital data signal lines.
So when choosing whatever Arduino make sure you have enough (usable) I/O ports for the number of encoders and possible additional parts (status led/s or similar, I2C LCD display)


text:
Multiplication operator with or without braces
I have written a simple calculator program for an LCD keypad shield. It works fine except for the multiplication case. It gives me zero. However, I have noticed that when I enclose the expression num1 * num2 in parenthesis it does work. Why is that so?
#include <LiquidCrystal.h>

LiquidCrystal lcd (8, 9, 4, 5, 6, 7);

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
}

void loop() {

  float ans = 0;

  lcd.print("Starting Calc");
  delay(500);

  lcd.clear();
  lcd.print("Enter 1st Num");
  while (Serial.available() == 0) {}
  float num1 = Serial.parseFloat();

  lcd.clear();
  lcd.print("Enter 2nd Num");
  while (Serial.available () == 0) {}
  float num2 = Serial.parseFloat();

  lcd.clear();
  lcd.print("Enter Operator");
  lcd.setCursor(0, 1);
  lcd.print(" R+, U*, D/, L- ");
  int val = analogRead(A0);

  while (val > 1000) {
    val = analogRead(A0);
  }

  if (val == 0) { // addition
    ans = num1 + num2;
  }

  if (val >= 97 && val <= 98) { // multiplication
    ans = num1 * num2;
  }

  if (val >= 253 && val <= 254) { // division
    ans = num1 / num2;
  }

  if (val >= 407 && val <= 408) { // subtraction
    ans = num1 - num2;
  }

    lcd.clear();
    lcd.print("Answer is = ");
    lcd.print(ans);
    delay(2000);
}

Modified Code
#include <LiquidCrystal.h>

LiquidCrystal lcd (8, 9, 4, 5, 6, 7);

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
}

void loop() {

  float ans = 0.0;

  lcd.print("Starting Calc");
  delay(500);

  lcd.clear();
  lcd.print("Enter 1st Num");
  while (Serial.available() == 0) {}
  float num1 = Serial.parseFloat();

  lcd.clear();
  lcd.print("Enter 2nd Num");
  while (Serial.available () == 0) {}
  float num2 = Serial.parseFloat();

  lcd.clear();
  lcd.print("Enter Operator");
  lcd.setCursor(0, 1);
  lcd.print(" R+, U*, D/, L- ");

  // here we split our logic.. first repeatedly read input value until valid operator read
  // secondly we perform the arithmetic operation accordingly

  char input = ' '; // space = no operator read so far
  int val;

  do {
    val = analogRead(A0);
    // see how if statements are written concisely for readability
    // if only one statement after condition you can skip curly brackets
    if (val == 0) input = '+';
    if (val >= 97 && val <= 98) input = '*';
    if (val >= 253 && val <= 254) input = '/';
    if (val >= 407 && val <= 408) input = '-';
  } while (input == ' ');

  Serial.println(input);
  Serial.println(num1);
  Serial.println(num2);
  delay(1000);

  // perform arithmetic operation
    switch (val) { // not written in a standard way but very readable
      case '+': ans = num1 + num2; break;
      case '-': ans = num1 - num2; break;
      case '*': ans = num1 * num2; break;
      case '/': ans = num1 / num2; break;
    }

  lcd.clear();
  lcd.print("Answer = ");
  lcd.print(ans);
  delay(2000);
}

I think you're looking in the wrong place. The brackets make no difference. Instead you should be looking at your usage of parseFloat.

I also don't think that brackets don't make a difference. However, I don't see any problem with my usage of parseFloat. It seems to work for other operations. Do you see an issue here?

The parentheses should definitely make no difference. My guess is that
what you saw was just a coincidence. The analog ranges you have defined
are extremely narrow. Any instability in the circuit can throw your
readings out of the expected ranges. If you get a reading that does not
fit in any of those ranges, none of the if conditions will evaluate to
true, and you end up with the result being zero, as this is how you
initialized the variable ans.
I suggest two changes to your program:

Make the ranges wider
Repeatedly read the analog input until you get a valid reading.

To illustrate the second item, here is a code snippet that splits the
logic of you if chain in two parts: first read the operator
(repeatedly until we get a valid reading), then perform the operation:
// Read the operator.
char op = ' ';  // space = no operator read so far
do {
    int val = analogRead(A0);
    if (val == 0) op = '+';
    if (val >= 97 && val <= 98) op = '*';
    if (val >= 253 && val <= 254) op = '/';
    if (val >= 407 && val <= 408) op = '-';
} while (op == ' ');

// Perform the operation.
switch (op) {
    case '+': ans = num1 + num2; break;
    case '*': ans = num1 * num2; break;
    case '/': ans = num1 / num2; break;
    case '-': ans = num1 - num2; break;
}

Thanks a lot for your clear explanation. I fully agree that I was getting 0 occasionally due to circuit instability. I didn't know about do... while loops but now I do :) The program should have worked now but mysteriously the "ans" variable is not being updated by switch case. I tried it with if statements but it also doesn't work. I wonder what's causing this? P.s. I have uploaded the modified code in the original post.

@Zaffresky: Oops, my bad! The switch should be done on the selected operator, not on the analog value. I just edited the answer.

Bingo. It works nicely :) Thanks


text:
How to use HC-05 to recieve data?
I am trying to control an led with a bluetooth module, but it is not working with an if else condition.
When I use this code I found on the internet the led blinks when I send the string from an android app:
    void setup() {
    Serial.begin(9600);
     pinMode(13, OUTPUT); // put your setup code here, to run once:
     }

    void loop() {
      // put your main code here, to run repeatedly:
     if(Serial.available()>0)
       {
          char data= Serial.read(); // reading the data received from the bluetooth module
          switch(data)
          {
            case 'a': digitalWrite(13, HIGH);break; // when a is pressed on the app on your smart phone
            case 'd': digitalWrite(13, LOW);break; // when d is pressed on the app on your smart phone
            default : break;
          }
          Serial.println(data);
       }
       delay(50);
    }

Where as when I use this code that I made myself the code compiles and uploads but the serial does not recieve values and the led does not change state when the strings are sent from the app, can someone help me identify why?:
    void setup() {
    Serial.begin(9600);
     pinMode(13, OUTPUT);
     }

    void loop() {
     if(Serial.available()>0)
       {
          char data= Serial.read();
          if (data == 'a')
          {
            digitalWrite(13, HIGH);
          }
          else if (data == 'b')
          {
            digitalWrite(13, LOW);
          }
          Serial.println(data);
       }
       delay(50);
    }

Thank You

are you certain that something does not print ..... it may be a space or tab or carriage return or newline ....... print the ascii value of data

@jsotola Yes, I am certain nothing prints when I use the if else conditon, but the led on the HC-05 blinks just as I send the data, so I am sure the connection is not at fault.


text:
Saving Power :: Reducing Power Consumption
For Arduino Nano 33 IoT, I want to turn off everything except Bluetooth and Wireless since I don't use them.
My question please: Can I switch off / deactivate the IMU sensors completely? If yes, How please?


text:
Serial.println using too much memory (not Strings)
I want to feed thousands of analog vibration sensor readings into an array as fast as possible, and then analyze them. Here is my sketch:
const int pSensor1 = A0;
const int aSize=10000;

int a[aSize];

void setup()
{
  pinMode(pSensor1, INPUT);
  Serial.begin(9600);
}

void loop()
{
  for (int i = 0; i < aSize; i++) a[i] = analogRead(pSensor1);

  int RMS = 0;
  for (int i = 0; i < aSize; i++) RMS += pow(a[i], 2);
  RMS = sqrt(RMS/aSize);

  Serial.println("Hello");
}

This compiles and runs fine. My problem arises when I try to change the last line to:
Serial.println(RMS);
I get the error:

Arduino: 1.8.12 (Windows 10), Board: "Arduino Nano, ATmega328P"
Sketch uses 3270 bytes (10%) of program storage space. Maximum is
  30720 bytes. Global variables use 20188 bytes (985%) of dynamic
  memory, leaving -18140 bytes for local variables. Maximum is 2048
  bytes. data section exceeds available space in board Not enough
  memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for
  tips on reducing your footprint. Error compiling for board Arduino
  Nano.

Why does attempting to Serial print a single floating point variable use 985% of dynamic memory?

Probably if you don't print them then the compiler sees that array is never used for anything so it gets optimized away.  It sees that it is useless code that doesn't affect anything and simply removes it.  Once you print it then it actually has to be included in the compiled code.
Think about this.  The Arduino you are using has 2000 bytes of memory.  One int takes 2 bytes.  You want 10,000 of them.  That's 20,000 bytes of memory.  20,000 bytes will never ever fit into 2,000 bytes.  You need to choose a more reasonable number of samples.

That makes sense, thank you.

Re “You need to choose a more reasonable number of samples”: 10,000 is a perfectly reasonable number of samples for an Arduino Nano. However, storing the samples before computing the RMS value is not reasonable.

OK, maybe I should have said that differently.


text:
Read the respiration data to Arduino serial console
Currently working with ADS1292rShield library.
Is there any way to read the value of the respiration and heart rate without using the Protocentral GUI. Printing DataPacketHeader to the console just results in corrupted ASCII.
DataPacketHeader[9] = s32DaqVals[0];            // 4 bytes Respiration data
DataPacketHeader[10] = s32DaqVals[0]>>8;
DataPacketHeader[11] = s32DaqVals[0]>>16;
DataPacketHeader[12] = s32DaqVals[0]>>24;

    for(i=0; i<15; i++)
    {
      Serial.write(i);
      Serial.write(DataPacketHeader[i]);     // transmit the data over USB
    }

Here is the output below of the Arduino serial monitor, is there any way to make sense of the data or how it is converted to a readable integer on the GUI?
⸮ < 0 p s | ` r I @ @ 9     ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ < 2 $ & O ` q ` 8 0 ! > ⸮ ⸮ ⸮ ⸮ ⸮  ! 8 ! | H a @  9 $  ! ⸮ 8 B x  ⸮ ⸮ ⸮ ⸮  y a ` p  f ⸮ ⸮ ⸮ ⸮ ⸮ 1 b N p ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ " D ` ` ` p
 ! ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ 0 ⸮ ' # 3 @ O ` D B @ @ ! ⸮ ⸮ ⸮ ⸮ ⸮ 0    a F ⸮ ⸮ ⸮ ⸮ ⸮ ⸮ " x p $ 0 ⸮

examine the four bytes as a 32 bit number

@jsotola I don't think the printout is corrupted because it is displaying valid data when the USB serial data is sent to the Protocentral GUI. I will try to group together the 4 bytes as a 32 bit integer.

the GUI is created using processing .... https://processing.org/ ... you can examine the sketch code and you can even rewrite the code for your own use

You are not printing the data, you are writing it. That is a difference. The packet format is binary, so you cannot get human readable data by writing. And jsotola is probably right. The data most likely consists of a 4 byte value.


text:
Control of 3 LEDs over Bluetooth using MIT App Inventor
As per title, I have 3 LEDs connected to an Uno. Also connected is an HC-05.
edit: forgot to add a question, my bad.  Is there any glaring major issues in this code that I've overlooked?  Not looking for anyone to write my code for me, just want to understand what I messed up and an idea of how to fix.
const int RED=2;
const int BLUE=4;
const int GREEN=6;

String inputString;
String buttonId;

char junk;

void setup() {
  Serial.begin(9600);
  pinMode(RED, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(GREEN, OUTPUT);
  digitalWrite(RED,LOW);
  digitalWrite(BLUE,LOW);
  digitalWrite(GREEN,LOW);
}

void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters coming on serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0)
    { junk = Serial.read() ; }
    if(inputString == "r_on"){      // control red led
      digitalWrite(RED, HIGH);
    }else if(inputString == "r_off"){
      digitalWrite(RED, LOW);
    }
    inputString = "";
    if(inputString == "b_on"){      // control blue led
      digitalWrite(BLUE, HIGH);
    }else if(inputString == "b_off"){
      digitalWrite(BLUE, LOW);
    }
    inputString = "";
    if(inputString == "g_on"){      // control green led
      digitalWrite(GREEN, HIGH);
    }else if(inputString == "g_off"){
      digitalWrite(GREEN, LOW);
    }
    inputString = "";
  }
}

Picture of my App inventor block program in imgur link below
https://i.stack.imgur.com/F6jBq.jpg

Was there a question to go with this?

I see a huge bug in the beginning where you are throwing away data without knowing what it is.  But I don't know if that's what you're asking about.  Reading data is way faster than it arrives, so if you send "r_on" that first available will be true when the 'r' gets there.  Nothing else has made it yet so it exits.  Now you got a chance that maybe when the '_' gets there its on the first available call, but that might happen right before it gets there and then the second one catches it and throws it away.  Now we play the same russian roulette game with the 'o' and the 'n'.

In the end you don't know which characters you got and which ones you threw away.  Throwing away serial data or "clearing the buffer" as noobs like to say is almost never a good idea.  There shouldn't be junk in there unless you put it there.  There's no reason to throw it away.  Just don't send it if you don't want it.

So, the code just throws away the string before it can even reach the if statements? Or am I misunderstanding?

The one that says junk=Serial.read() and then you don't do anything with junk.  That is throwing away data.  You don't know that junk was a good character or a bad character.  You seem to think that when the first if statement catches that it will read the whole entire string.  But there's no guarantee that the whole string has arrived yet.  You're at 9600 baud (why so slow?) so there's about a millisecond between characters.  In that time your loop function can repeat hundreds of times.  It's not going to sit in that while loop waiting for the whole message to get there.

And whenever a character does arrive, you're playing Russian roulette with it.  Maybe it arrives after the first if statement runs but before the second one.  In that case it will be read into the junk variable and never used.


text:
Bluetooth multithreading
I'm using my Arduino to make a speaker-like device. Instead of sound, it receives the beat of the song, thus the data comes in an array of floats. Each item in the array is a timestamp, an LED is turned on based on that value.
For example, [0.01,0.53] means sleep 0.01s, turn on LED, pop off 0.01, sleep 0.53 seconds, turn on LED.
I have two questions:
1)How can I receive data and pop off data at the same time? I'm thinking I can send maybe 10 items for the Arduino to buffer at one time, and repeat that until the whole action is done. The popping off action is time sensitive, so I can't do it sequentially. How can I run both functions at once? Are arduinos capable of multithreading?
2)I'm using an arduino with BLE and sending over the data using serial.read() from an iPhone. and the device only allows 18 bytes to be sent over at one time and it is very slow. What other methods can I use? I need to send 18 bytes from my iPhone, wait 2 seconds, then send it again otherwise the arduino treats it as one single send and the other values are not sent over.
3)Is there a better way of doing all of this that I'm missing?
Thank you very much.

The arduino keeps time in microseconds.  You can't have fractional microseconds.  It only lets you have integer microseconds.  floats are inherently inaccurate.  They simply cannot hold many values exactly, they're just approximations.  Using floats here is not good.  You should be using unsigned long variables instead and keeping time in milliseconds instead of seconds.  That will greatly improve performance once you get it done and also make your work easier.

Arduino can't multithread, but you can certainly have code that is constantly switching back and forth checking each thing once every few microseconds.  You just have to write your code to do things in short chunks.  It's called "non-blocking" code.  Look that up.

Answer to #2:  It really depends on what exactly you're using.  That doesn't sound like a normal limitation.  It has to be an issue with either the module you have or the software you're using somewhere.  You have to share all those kinds of details if you really want help.

Answer #3.  You haven't really explained the end goal or what you want to actually accomplish.  Are you blinking lights to the beat or something?  Either way, there is probably a better way to do it.

What exactly do you mean when you say "pop off"?

why do you need to transmit a float? ... a beat is more along the lines of a single bit data

@Delta_G Didn't know that about floats. Thanks! I will change it. 2) I'm using Beetle BLE. I've read from multiple threads that BLE has a packet limit. Am I wrong? How do I go about increasing this value? 3) Yeah that is what I'm trying to do. The timestamps of the beats are stored in an array on the iPhone and it is sent over to the Arduino over BLE, which is then supposed to light up LEDs based on that time. By pop off I mean removing an element from the array.

@jsotola I'm transmitting timestamps of every beat of a song in an array. How would a beat be transmitted as a single bit?

a pulse in realtime

Why would you send timestamps of every single beat?  They're beats.  They're rhythmic.  You don't need that much information to convey what to do.  A start time, a rate, and a number of beats or a stop time.

@Delta_G I'm looking for precision. Some songs have different bpm in different parts of the song.

Yes, so you send a new BPM marker and change the beat.  You still don't have to send a timestamp for every beat.  Unless the drummer really really sucks you only need to send something at most every few measures.

@Delta_G That's a solution I guess. It would certainly make my job a lot easier. However, the device is meant to be a learning tool for beginner dancers/ musicians so if possible I'd still like to make it as precise as possible. I'll look up non blocking functions, and if that doesn't work use the bpm marker method. Thanks for your help!

This is a trap nobies fall into a lot.  You say, "as precise as possible".  So in computers you have to put a number to everything.  There's no such thing as absolute precision here.  At the very least there will be some small time difference between the audio player and the clock on the Arduino.  In reality it takes 200ms for a human to blink their eye.  Think about how fast that is.  So when we talk about something being off by 20 or 50 milliseconds, that is an amount of time that is completely imperceptible to humans in most situations.  You and I are talking microseconds.

So many people fall into the trap of trying to get something to be absolutely perfectly at the same time when such a thing is a physical impossibility.  If a professional drummer were behind the scenes hitting buttons to blink the lights with the beat you'd have timing discrepancies on the order of tens or even 100 milliseconds and everyone in the room would call it exact.  When you are dealing with timing and measurement in computers, you have to start thinking about what precision is really necessary.

@Delta_G Huh, I've never thought of it that way before. Makes a lot of sense.


text:
Uploading arduino code to race drone flight controller
I am working on VTOL aircraft and currently I am looking for some good board as flight controller (FC). I could made it by myself, but it requests lot of time. I was thinking about one of fpv drone FC (I have avaiable this one:
https://www.banggood.com/cs/Original-Airbot-Omnibus-F4-Pro-V3-Flight-controller-SD-5V-3A-BEC-OSD-Current-Sensor-LC-Filter-p-1319177.html?gmcCountry=CZ&currency=CZK&createTmp=1&utm_source=googleshopping&utm_medium=cpc_bgs&utm_content=lijing&utm_campaign=ssc-cz-cs-all-newcustom-ncv80-1118&gclid=CjwKCAjwqJ_1BRBZEiwAv73uwEgBJQ1B3dcKvZJZy2lR5-wN-XC150Ybn0kZObpUQbgkbvKiN_fY5BoCCVEQAvD_BwE&cur_warehouse=CN
This board has very small dimensions and it has already everything I need. The problem is that it is made for softwares like betaflight etc. It uses STM32 F405 so I tried to add STM 32 support for arduino (https://github.com/stm32duino/Arduino_Core_STM32) and upload arduino code in it.
I had to install stm32 cube programmer and because this board is not one of arduino boards I have to build the code for different board with same processor (FEATHER_F405). Because of it I have to change board pinout in this file (C:\Users\\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\variants\FEATHER_F405). I checked if are those pins correct (in code I command to those pins to be High and then Low while I was measuring them with multimeter). So all the pins are correct. I was able to blik the onboard LED and beep the buzzer. The only problem I have is serial communication. I tried to send some Strings to computer via serial port, but I didnt received any data. Here is sample code that I used:
#include <SoftwareSerial.h>

#define LED 4 //PB_5   //Inverted (High => LED ON)
#define BUZZ 3 //PB_4

#define _RX1 D0 //PA_10
#define _TX1 D1 //PA_9

//#define D_P 35 //PA_11
//#define D_M 36 //PA_12

//SoftwareSerial mySerial(_RX1, _TX1); // RX, TX
HardwareSerial  hwSerial_1(_RX1, _TX1);   // RX, TX

void setup() {

  hwSerial_1.begin(9600);
 //mySerial.begin(9600);

  pinMode(LED,OUTPUT);
  pinMode(BUZZ,OUTPUT);

  //pinMode(_RX1,OUTPUT);
  //pinMode(_TX1,OUTPUT);

  //pinMode(D_P,OUTPUT);
  //pinMode(D_M,OUTPUT);
}

void loop() {

  digitalWrite(LED, HIGH);
  /*
  digitalWrite(_RX1, HIGH);
  digitalWrite(_TX1, HIGH);
  digitalWrite(D_P, HIGH);
  digitalWrite(D_M, HIGH);*/

  delay(1000);

  digitalWrite(LED, LOW);
  /*
  digitalWrite(_RX1, LOW);
  digitalWrite(_TX1, LOW);
  digitalWrite(D_P, LOW);
  digitalWrite(D_M, LOW);*/

  delay(1000);

  digitalWrite(BUZZ, HIGH);
  delay(100);
  digitalWrite(BUZZ, LOW);
  delay(1000);

  hwSerial_1.println("HelloWorld");
  //mySerial.println("HelloWorld");

}

I tried to run serial communication via USB and via UART1 (I used USB/ TTL conventer -> FT232), but non of these works. I also tried to use software serial and hardware serial library, but it didnt helped.
Do you have any advices how to make serial communication work?

Sorry for answering this late to this problem but I stumbled on the very same issue. After many hours of debugging, here is what I've found:

The default serial (e.g. the serial that you will use through the object Serial) is actually what is labelled RX3 and TX3 on the board and is mapped like so:

RX3 -> PB_11
TX3 -> PB_10

Serial6 is connected through an inverter (5v becomes 0v and vice versa) and can be used as an SBUS line. Serial 6 is mapped like so:

RX6 -> PC_7
TX6 -> PC_6

Serial1 is mapped like so:

RX1 -> PA_10
TX1 -> PA_9
however, PA_10 and PA_11 are not used as UARTs on the FEATHER board. In order to enable them, you can edit the file hardware/stm32/2.3.0/variants/STM32F4xx/F405RGT_F415RGT/PeripheralPins_FEATHER_F405.c.

In the array PinMap_UART_TX (line 178), uncomment the line regarding the pin PA_9 and comment the line regarding the pin PB_6.
In the array PinMap_UART_RX (line 193), uncomment the line regarding the pin PA_10 and comment the line regarding the pin PB_7.

However, if you try to read from this uart you will probably receive garbage data because the Feather F405 board uses a 12MHz external oscillator, when the omnibus F4 uses a 8MHz clock. To fix this, you can go to the files that define the Feather F405 : hardware/stm32/2.3.0/variants/STM32F4xx/F405RGT_F415RGT/variant_FEATHER_F405.h line 178 you will read : #define HSE_VALUE 12000000U. This has to be changed into : #define HSE_VALUE 8000000U.


text:
How to store firmware configuration or image in source-control?
I'm writing an Arduino application in C/C++ and I'm storing my source code in Github.
However, to make my code runnable, I have had to install multiple libraries through the Arduino desktop tool like this:

And I have had to update the firmware and certificates through the Arduino desktop tool like this:

How can I store these firmware updates, library changes and certificates in source control? Is there a binary image I can download and check in? Better yet, is there some plain-text source file that I can check-in to derive such a binary?

For libraries only add comment next to #include with version number and author's name if the library is in Library Manager or the download location if it is not in Manager.
Example:
#include <MemoryFree.h> // https://github.com/mpflaga/Arduino-MemoryFree
#include <Ethernet.h> // Ethernet 2.00

Put NINA firmware version in some comment at the top of the main sketch file. The firmware is part of the Arduino boards package so no need to store it in your repo. If you modified the firmware, publish source code in your fork of the official repository and there you can then release the binary too.
Put public certificate keys and similar files in sketch folder in subfolder called extras or data.
And write a README file for your repository.


text:
Can I connect 220V AC supply to Node MCU (or any arduino)pin D1 and D3 while node MCDU is power off?
Can I connect 220V AC supply to node MCU pin D1 and D3 while node MCDU is power off?

Are you trying to kill yourself? 220V can be fatal. Go and talk to a qualified electrician before you do anything more.

Short answer: HELL no. You should not connect AC supply lines to any low voltage pins, under any circumstances. The insulation on the wires is not sufficient for that voltage, and it would pose a serious risk of fatal injury. Oh by the way, it would fry your Arduino, but that is not important compared to killing anybody who touched anything connected to the Arudino.

No, never! 220V is way way way too much for a microcontroller. The Uno runs on 5V, the ESP8266 on 3.3V. You should never connect any more voltage than that to the microcontroller. Also you must not connect a negative voltage to the microcontroller pins.
Besides the voltage difference: You should also not connect a voltage to the pins of a microcontroller, while the microcontroller itself is turned off (meaning that it does not have the necessary supply voltage). In that case a parasite current would run through the clamping diodes, which powers the microncontroller, until the diodes get blown.

As an important side note: Don't do anything with mains power (like 220V AC), until you really know, what you are doing!!! One error and it can kill you !!!


text:
hello,i have an problem with my arduino with an lcd
i've totally done everything i could,but when i run my arduino uno with my 16*2 lcd (with i2c) . it has a higher brightness on the top and a lower one in the bottom. ive even tried putting example codes but my arduino totally freaks out, starting to change it's backlight . i cant even use lcd.print . i had tried just to adjust my lcd with a ldr , this is the code:
    // Include Wire Library for I2C
#include <Wire.h>
// Include NewLiquidCrystal Library for I2C
#include <LiquidCrystal_I2C.h>
int ldr;
int sensor=0;
int lcdb=5;

// Define LCD pinout
const int  en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;

// Define I2C Address - change if reqiuired
const int i2c_addr = 0x3F;

LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);

void setup()
{

  // Set display type as 16 char, 2 rows
  lcd.begin(16,2);
  Serial.begin(9600);
  lcd.setCursor(0,1);
  lcd.print("hello world");
  lcd.setCursor(0,0);
  delay(1000);
  lcd.print("hello world");

}
void loop()
{
  int ldr=analogRead(sensor);
  ldr=map(ldr, 0, 1023, 0,255);
  delay(1000);
  analogWrite(lcdb,ldr);

}

Please also provide a wiring diagram, so that we can see, how everything is connected

What library are you using, because LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE); doesn't make sense for the library I found. Also the code seems to imply the backlight is connected to pin 3 on the I2C device, but also to pin 5 of the UNO.

i used the new liquidcrystal library


text:
Put Arduino in DFU mode (no RST pin)
The instructions to put the Arduino into DFU say I should shortcut briefly the 2 leftmost ICSP headers next to the USB port.

But my board does not have them. Does anybody know what are the right headers or if it is at all possible to set my board into DFU mode?

It has a CH340G usb serial adapter, which cannot be reprogrammed and has no DFU mode.
If you are looking for DFU mode because it's not detecting correctly and you think it's because the 16u2 isn't programmed correctly, the problem is probably that you need to install the CH340G drivers, not the normal Arduino drivers.
If you are looking for DFU mode for some project that requires custom firmware on the CH340G, that board is not usable for that project, you will need to get a faithful clone of the Uno, which has the 16u2, not the CH340G based ones
EDIT
If you want to use your Arduino as a HID device you need the DFU mode
If you use this library which supports UNO/MEGA/Leonardo/(Pro)Micro/ any 8u2/16u2/at90usb8/162/32u2/32u4 compatible board and some more BUT you need an 16u2 chip

I guess no HID on than one then. Thanks.

See my edit - NO

This board doesn't use as USB adapter an ATMega16u2 with Arduino firmware. It uses a simple USB chip CH340. So you can't put it in DFU mode to upload a firmware.


text:
What does a tilde (~) mean as annotation for a data pin?
When I examine the datasheet for the Arduino Micro (couldn't find the Pro Micro on their site, btw) then I see some data pins annotated with a ~ character, and some are not.
For instance, D9 has a ~ annotation, D8 does not.
What does this annotation mean?

It means the pin can be a PWM output for use with analogWrite().


text:
DHT11 and Liquidcrystal setting cursor issue
lcd_key = read_LCD_buttons();
float temp = dht.readTemperature();
delay(1000);
// lcd.setCursor(0,0);

if(temp < 0) {
    lcd.print(temp);
}

if(temp >= 0.00 || temp <= 5.00) {
    lcd.setCursor(0,6);
    lcd.print(temp);
    delay(100);
}

Here I got simple code about reading temperature from DHT sensor and lcd but when I raise or lower the DHT's temperature the lcd's cursor always printing my data from 0,0.
I want that when the temperature between 0-5 celcius it shall write data on 0,6 in lcd screen but this code not working.
Thank you for answers.

review the setcutsor() command

I have a feeling you may be using invalid coordinates.
0, 6 means Column 0, Row 6, but most LCDs don't have 6 rows.  Instead I think you want 6, 0 for Column 6, row 0.

I guess it because you use
if(temp >= 0.00 || temp <= 5.00){ // writes over 0 OR under 5 which will always be true for all values measured

and not
if(temp >= 0.00 && temp <= 5.00){   // writes over 0 AND under 5 which you want

the logic error in the OP's code causes temp to always print at (0,6)


text:
writing mqtt payload to spiffs file
I'm trying to write the payload of a MQTT message into a file in the SPIFFS file system of my esp32 board. I've tried this:
if(file.print((long)payload)) {
   Serial.println("File was written");
}else {
   Serial.println("File write failed");
}

payload is a byte* and file was opened in the setup() function like:
File file;
if(!SPIFFS.exists("/testfile")){
  file = SPIFFS.open("/testfile", "r+");
}

I always get an error when writing to it telling me that the file write failed. Is this the correct approach for what I'm trying to accomplish?

Use file.write(payload, length); for byte array. length should be the count of payload bytes, not the size of the payload array.
print and write return the count of bytes written. It is not meaningful to use the return value as boolean.

Open the file in the loop or the subroutine, but not in setup as file is then a local var to setup
In your code it should be
file = SPIFFS.open("/testfile", "a"); // a ... append

a      Open for appending (writing at end of file).  The file is
         created if it does not exist.  The stream is positioned at the
         end of the file.

r+   positions stream at the beginning of the file
and to get lines you can afterwards analyze you should use
if(file){
   file.println("Your MQTT payload");
   Serial.println("File was written");
   file.close();
} else {
    Serial.println("File write failed");
}

and do not forget to close after the operation.
EDIT
As reaction to the comments here a "clean solution" as a function:
bool writeLog(const char fileName[],  char payloadMqtt[]) {
  File logFile = SPIFFS.open(fileName, "a");
  if (!logFile)  {
        Serial.println("logFile open failed");
    return false;
  }
  else {
    //Write data to file
    Serial.println("writing Data to logFile");
    logFile.print(payloadMqtt);
    logFile.close();
    return true;
  }
}

You call it with:
writeLog("/myfilepath", payload);

and can also be used like
if (writeLog("/myfilepath", payload)) Serial.println("Log save success");
else Serial.println("Log save failure");

Hope this helps to understand the nature of SPIFFS/LittleFS/SD operations

Sorry, I put FIle file; outside the setup(), but I open it inside. And it doesn't make much sense to me to open the file inside the loop. Also, my problem is that payload is a byte array so I guess I need a casting to write that into the file

You should only open before writing and close after writing, we are on a MCU not a full scale OS. Look into the lib spiffs_api.h/cpp to see what open means for your memory (aside from unwanted errors andother probs) . If your payload is a char array you just use file.println(payload)