message:
Object composition (class uses class)

I would like to write a class which utilises another class and it´s member functions. I found out that this is object composition and read some examples of how to do it but it ither doesn´t work for me or I just don´t understand it completely. Here are parts of my code.
```
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>     // Touch library
#include <TriangleButton.h>        // TriangleButton library
```
I want to use an Adafruit_TFTLCD object and its member functions inside my own class TriangleButton. The object tft is initialised before setup.

```
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Class is part of SPFD5408_Adafruit_TFTLCD.h
```
I built the TriangleButton.h similar to this thread (https://arduino.stackexchange.com/questions/9296/use-object-of-other-class-within-class) and used a reference to the tft object.
```
/*
  TriangleButton.h - Library for for constructing and reading triangle Buttons.
*/
#ifndef TriangleButton_h
#define TriangleButton_h

#include "Arduino.h"
#include <SPFD5408_Adafruit_TFTLCD.h>

class TriangleButton
{
  public:

    TriangleButton(Adafruit_TFTLCD &tft, int16_t coordX, int16_t coordY, int16_t orientation, uint16_t size, uint16_t color) : _tft(tft){}
    boolean IsTriggered();
    void dash();
  private:

 Adafruit_TFTLCD &_tft;
    int16_t _coordX;
 int16_t _coordY;
 int16_t _orientation;
 int16_t _size;
 int16_t _color;
 int16_t _ru;
 int16_t _hc;
};

#endif
```
In the ccp. i put a coresponding constructor.
```
TriangleButton::TriangleButton(Adafruit_TFTLCD &tft, int16_t coordX, int16_t coordY, int16_t orientation, uint16_t size, uint16_t color)
:
_tft(tft)
```

Now i get the following error message:

C:\Users\Erik\Documents\Arduino\libraries\AquariumController_Library\TriangleButton.cpp:19:1: error: redefinition of 'TriangleButton::TriangleButton(Adafruit_TFTLCD&, int16_t, int16_t, int16_t, uint16_t, uint16_t)'
 TriangleButton::TriangleButton(Adafruit_TFTLCD &tft, int16_t coordX, int16_t coordY, int16_t orientation, uint16_t size, uint16_t color)
 ^~~~~~~~~~~~~~
In file included from C:\Users\Erik\Documents\Arduino\libraries\AquariumController_Library\TriangleButton.cpp:7:0:
C:\Users\Erik\Documents\Arduino\libraries\AquariumController_Library\TriangleButton.h:14:5: note: 'TriangleButton::TriangleButton(Adafruit_TFTLCD&, int16_t, int16_t, int16_t, uint16_t, uint16_t)' previously defined here
     TriangleButton(Adafruit_TFTLCD &tft, int16_t coordX, int16_t coordY, int16_t orientation, uint16_t size, uint16_t color) : _tft(tft){}
     ^~~~~~~~~~~~~~
exit status 1

I don`t understand why ther is a redefinition. Can somebody explain it to me?

body:
> error: class 'TriangleButton' does not have any field named '\_tft'

This should be self-explanatory. When you write in the constructor

> ```cpp
> _tft(tft)
> ```

It means “initialize the property `_tft` of this object with the
parameter `tft`.

It is not very clear what you mean by “object composition”. In the usual
sense, it means that object A either _is_ or _has_ an object B. In your
case, it seems like you want your `TriangleButton` to hold a _reference_
to an `Adafruit_TFTLCD`. This is not really composition, as your class
neither _is_ nor _has_ an LCD.

As an immediate solution, just add an appropriate data member to the
class:

```cpp
Adafruit_TFTLCD &_ftf;
```

Assuming that holding a reference to the LCD is really what you want for
your class, this should be enough to solve your issue.

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

**Edit**: To answer the edited question.

“Redefinition” means you are defining again something that has already
been defined before. In this case, the constructor is defined inline in
the header file:

```cpp
TriangleButton(Adafruit_TFTLCD &tft,
        int16_t coordX, int16_t coordY,
        int16_t orientation, uint16_t size, uint16_t color)
    : _tft(tft){}
```

(yes, that's a complete definition with an empty body).

And then you try to define it again in the cpp file. This is an error,
every method should be defined only once. At your choosing, it can be
either inline in the header or in the .cpp, but not both.


sender: user

message:
Wrong data receiving in my Arduino by bluetooth

I have programmed a client-server between an Arduino and my mobile app in Android. I´m using a buetooth HC-06. For the moment is a very basic code just to turn ON/OFF a led, regulate its voltage, and receive the charge of the battery.

This is my Arduino code for receiving the message:

    #include <SoftwareSerial.h>
    #include <TimerOne.h>
    SoftwareSerial hc06(2,3);

    char command;
    String string;
    boolean ledon = false;
    const byte MAX_STRING_LEN = 40;
    const int  BLINK_INTERVAL = 1000;

    char inputString[MAX_STRING_LEN];  // a string to hold incoming data

    int BatteryPin = A0;    // select the input pin for the potentiometer
    int sensorValue = 0;  // variable to store the value coming from the sensor
    float BatteryCar = 0;
    int PercentageBatt = 0;
    int intensidad = 0;
    byte strLen   = 0;                 // current length of rec'd string

    #define led 11
    void setup()
    {
      Serial.begin(9600);
      hc06.begin(9600);
      pinMode(led, OUTPUT);
      Timer1.initialize(10000); // set a timer of length 10000 microseconds (or 0.01 sec - or 1Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
      Timer1.attachInterrupt( SendVoltage );
    }
    void loop()
    {

      sensorValue = analogRead(BatteryPin);
      BatteryCar = sensorValue * (5.0 / 1023.0);
      if (hc06.available() == 0)
      {
        analogWrite(led, 0);
        delay (10);
      }
      while(hc06.available() > 0)
      {
        command = ((byte)hc06.read());
        if((command == '\n') || (command == '\r'))
        {
          command =='\0';
          break;
        }
        else if (command == 'O')
          analogWrite(led, 255);
        else
          analogWrite(led, 0);
        delay(10);
        Serial.println(command);
      }
    }

    void SendVoltage ()
    {

      PercentageBatt = (BatteryCar * 100)/4;
      hc06.println(PercentageBatt);
    }

This is the data that I´m receiving:

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/l0Jio.png

It supposed that i should only receive "O" or "F". Any suggestion??

thanks in advanced,

sender: assistant

body:
Well, after a lot of research, it seems that my main problem was that I´m receiving and sending information at the same time. And with the library Softwareserial, only 1 can be active at the same time.
I found two solutions, but to be honest I'm not complete satisfy with neither of them. However, for my application will work.

The first solution: Is to used the HardwareSerial (pin 0,1) itself, instead of using the pin 2 and 3. When I used those, it didn't have any problem. Although I decided no to used because it help me debugging my code.

The second solution: Is to decrease the frecuency of what I´m sending. For me its ok I send the data every second. So my code would be like this:

    #include <SoftwareSerial.h>
    #include <TimerOne.h>
    SoftwareSerial hc06(2,3);

    char command;
    String string;
    boolean ledon = false;
    const byte MAX_STRING_LEN = 40;
    const int  BLINK_INTERVAL = 1000;

    char inputString[MAX_STRING_LEN];  // a string to hold incoming data

    int BatteryPin = A0;    // select the input pin for the potentiometer
    int sensorValue = 0;  // variable to store the value coming from the sensor
    float BatteryCar = 0;
    int PercentageBatt = 0;
    int intensidad = 0;
    byte strLen   = 0;                 // current length of rec'd string

    #define led 11
    void setup()
    {
      Serial.begin(9600);
      hc06.begin(9600);
      pinMode(led, OUTPUT);
      Timer1.initialize(1000000);
      Timer1.attachInterrupt( SendVoltage );
    }
    void loop()
    {

      sensorValue = analogRead(BatteryPin);
      BatteryCar = sensorValue * (5.0 / 1023.0);
      if (hc06.available() == 0)
      {
        analogWrite(led, 0);
        delay (10);
      }
      while(hc06.available() > 0)
      {
        command = ((byte)hc06.read());
        if((command == '\n') || (command == '\r'))
        {
          command =='\0';
          break;
        }
        else if (command == 'O')
          analogWrite(led, 255);
        else
          analogWrite(led, 0);
        delay(10);
        Serial.println(command);
      }
    }

    void SendVoltage ()
    {

      PercentageBatt = (BatteryCar * 100)/4;
      hc06.println(PercentageBatt);
    }

I have read about [this][1] library (AltSoftSerial), but I couldn't get it work. I have usde the pin 8 and 9, but nothing.

  [1]: https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html


message:
Using esp-wroom-32 without a development board

There are lots of examples on the internet on how to build Arduino from scratch such as [IN THIS LINK][1]. I will like to do the same but with the esp32.

I have this development board:

[![enter image description here][2]][2]

And I am able to program it with the Arduino framework/IDE thanks to [THIS VIDEO][3].

-------

Now the question
-

**How can I flash my code and run it on a standalone ESP-WROOM-32 chip like this one:**

[![enter image description here][4]][4]

I do not want to use voltage regulator etc as I am planning to run it from a 3.3V battery.

Before asking this question this was my research:

1. In this video (https://www.youtube.com/watch?v=n43rHugPbTg) Hugatry does exactly what I am looking for but he does not explain what pins he is using. Moreover what happens if I connect my 5v serial to the chip? will it burn?

2. I went directly to espressif website and looked for the schematics (https://www.espressif.com/sites/default/files/documentation/esp32-wroom-32d_esp32-wroom-32u_datasheet_en.pdf). It is hard to understand I just want to do something simple.

3. This blog (http://blogs.oregonstate.edu/copaps/resources/programming-esp32-on-custom-pcb/) explains how but the pins are different than my esp-wroom-32 chip.

Looking more on the internet/youtube everyone explains how to solder it. But I haven't found a diagram that will enable me to flash it and run my code. Also will I have to burn a bootloader like with arduino?

What I am about to try is to buy a 5V to 3.3V serial converter connecting TX with RX and RX with TX. Providing 3.3V power to the 3.3V pin and connect the last cable to ground. If I try that will it work?

  [1]: https://www.arduino.cc/en/main/standalone
  [2]: https://i.stack.imgur.com/mJwJp.png
  [3]: https://www.youtube.com/watch?v=mBaS3YnqDaU
  [4]: https://i.stack.imgur.com/l2YjS.png

body:
There are programming boards available to which you can plug one of these SOCs into them. There are different boards for different types of ESP SOCs.
You can find them at popular Chinese vendors, and probably elsewhere too.

They look like this:

[![ESP32 flash burner tool][1]][1]

  [1]: https://i.stack.imgur.com/nXXQ1.jpg


body:
This is what I was looking for. The development board is not the minimum as @Majenko and @StarCat stated on their comments. This is exactly what I need as I plan to run my project from a battery. Moreover, the development board consumes a lot more energy when in sleep mode. I will even remove the LED that shows on this diagram:

[![enter image description here][1]][1]

So basically use a programming board like @KenVanHoelandt stated to program the board and then wire the esp32 like in the diagram above.

I got that diagram from this link:

https://www.14core.com/wiring-and-flashing-programming-esp-32-esp32s-with-usb-ttl-uart/

  [1]: https://i.stack.imgur.com/BbInr.png


body: You could use wireless.  First, use OTA programming (eg Elegant OTA) to burn a basic OTA uploader.  Then, in principle,  you can then upload any sketch you want so long as it ALWAYS has the basic OTA sketch included within your program.


message:
How to combine two codes in arduino?

bine

    #include <LiquidCrystal.h>
    LiquidCrystal lcd(12,11,5,4,3,2);

    #define sensor A0
    #define led 13
    #define ledd 8  // d out from mq3
    #define buz 9
    #define motor 10
    void setup()
    {
      Serial.begin(9600);
      lcd.begin(16,2);
      lcd.print("ALCOHOL MONITORING");
      lcd.setCursor(0,1);
      lcd.print(" VEHICLE SYSTEM ");
      delay(2000);
      pinMode(sensor, INPUT);
      pinMode(buz, OUTPUT);
      pinMode(led, OUTPUT);
      pinMode(ledd, OUTPUT);
      pinMode(motor, OUTPUT);
      lcd.clear();
    }

    void loop()
    {
      float adcValue=0;
      for(int i=0;i<10;i++)
      {
        float actualanalogReading =  analogRead(sensor);
        adcValue = adcValue + actualanalogReading;
        Serial.println("In loop counter >"); // logging
        Serial.print(i);
        Serial.print(" input reading : ");
        Serial.print(actualanalogReading);
        Serial.print(" cumulative input reading : ");
        Serial.print(adcValue);

        delay(10);
      }
        float v= (adcValue/10) * (3.0/1024.0);
        float mgL= 0.67 * v;
        Serial.println("");
        Serial.print("Post calculation v value >" );
        Serial.print(v);
        Serial.print(" mg/L > ");
        Serial.print(mgL);
        Serial.println("");
        Serial.print("BAC:");
        Serial.print(mgL);
        Serial.print(" mg/L");
        lcd.setCursor(0,0);
        lcd.print("BAC: ");
        lcd.print(mgL,4);
        lcd.print(" mg/L        ");
        lcd.setCursor(0,1);
        if(mgL > 0.8)
        {
          lcd.print("Drunk ENGINE OFF ");
          Serial.println("Drunk ENGINE OFF ");
          digitalWrite(buz, HIGH);
          digitalWrite(led, HIGH);
          digitalWrite(ledd, LOW);
          digitalWrite(motor, LOW);
        }
        else
        {
          lcd.print("Normal ENGINE ON ");
          Serial.println(" Normal ENGINE ON ");
          digitalWrite(buz, LOW);
          digitalWrite(led, LOW);
          digitalWrite(ledd, HIGH);
          digitalWrite(motor, HIGH);
        }

        delay(100);

    }

top code^^^
combines with this>>

    const int LED = A5;
    const int DO = 6;
    void setup() {
     Serial.begin(9600);
     pinMode(LED, OUTPUT);
     pinMode(DO, INPUT);
    }
    void loop() {
     int alarm = 0;
     float sensor_volt;
     float RS_gas;
     float ratio;
    //-Replace the name "R0" with the value of R0 in the demo of First Test -/
     float R0 = 0.10;
     int sensorValue = analogRead(A1);
     sensor_volt = ((float)sensorValue / 1024) * 5.0;
    RS_gas = (5.0 - sensor_volt) / sensor_volt; // Depend on RL on yor module
     ratio = RS_gas / R0; // ratio = RS/R0
    //------------------------------------------------------------/
     Serial.print("sensor_volt = ");
     Serial.println(sensor_volt);
     Serial.print("RS_ratio = ");
     Serial.println(RS_gas);
     Serial.print("Rs/R0 = ");
     Serial.println(ratio);
     Serial.print("\n\n");
     alarm = digitalRead(DO);
     if (alarm == 1) digitalWrite(LED, LOW);
     else if (alarm == 0) digitalWrite(LED, HIGH);
     delay(1000);
    }

body:
While I'd like to direct you to ways to set up a nice tasking system with a frame counter, your system is likely simple enough that it is unnecessary.  You can likely just replace the delay(1000); of the second program with approximately 5 calls of the first program's loop.  May you instead learn something when cleaning up the following (which is literally a copy paste with minimal changes).

~~~

#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

#define sensor A0
#define led 13
#define ledd 8  // d out from mq3
#define buz 9
#define motor 10
void setup1()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.print("ALCOHOL MONITORING");
  lcd.setCursor(0,1);
  lcd.print(" VEHICLE SYSTEM ");
  delay(2000);
  pinMode(sensor, INPUT);
  pinMode(buz, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(ledd, OUTPUT);
  pinMode(motor, OUTPUT);
  lcd.clear();
}

void loop1()
{
  float adcValue=0;
  for(int i=0;i<10;i++)
  {
    float actualanalogReading =  analogRead(sensor);
    adcValue = adcValue + actualanalogReading;
    Serial.println("In loop counter >"); // logging
    Serial.print(i);
    Serial.print(" input reading : ");
    Serial.print(actualanalogReading);
    Serial.print(" cumulative input reading : ");
    Serial.print(adcValue);

    delay(10);
  }
    float v= (adcValue/10) * (3.0/1024.0);
    float mgL= 0.67 * v;
    Serial.println("");
    Serial.print("Post calculation v value >" );
    Serial.print(v);
    Serial.print(" mg/L > ");
    Serial.print(mgL);
    Serial.println("");
    Serial.print("BAC:");
    Serial.print(mgL);
    Serial.print(" mg/L");
    lcd.setCursor(0,0);
    lcd.print("BAC: ");
    lcd.print(mgL,4);
    lcd.print(" mg/L        ");
    lcd.setCursor(0,1);
    if(mgL > 0.8)
    {
      lcd.print("Drunk ENGINE OFF ");
      Serial.println("Drunk ENGINE OFF ");
      digitalWrite(buz, HIGH);
      digitalWrite(led, HIGH);
      digitalWrite(ledd, LOW);
      digitalWrite(motor, LOW);
    }
    else
    {
      lcd.print("Normal ENGINE ON ");
      Serial.println(" Normal ENGINE ON ");
      digitalWrite(buz, LOW);
      digitalWrite(led, LOW);
      digitalWrite(ledd, HIGH);
      digitalWrite(motor, HIGH);
    }

    delay(100);

}

const int LED = A5;
const int DO = 6;
void setup() {
 setup1(); //Serial.begin(9600);
 pinMode(LED, OUTPUT);
 pinMode(DO, INPUT);
}
void loop() {
 int alarm = 0;
 float sensor_volt;
 float RS_gas;
 float ratio;
//-Replace the name "R0" with the value of R0 in the demo of First Test -/
 float R0 = 0.10;
 int sensorValue = analogRead(A1);
 sensor_volt = ((float)sensorValue / 1024) * 5.0;
RS_gas = (5.0 - sensor_volt) / sensor_volt; // Depend on RL on yor module
 ratio = RS_gas / R0; // ratio = RS/R0
//------------------------------------------------------------/
 Serial.print("sensor_volt = ");
 Serial.println(sensor_volt);
 Serial.print("RS_ratio = ");
 Serial.println(RS_gas);
 Serial.print("Rs/R0 = ");
 Serial.println(ratio);
 Serial.print("\n\n");
 alarm = digitalRead(DO);
 if (alarm == 1) digitalWrite(LED, LOW);
 else if (alarm == 0) digitalWrite(LED, HIGH);

 for(int dd = 0; dd < 5; dd++) loop1();
}

~~~


message:
Monitor two baud rates

I am using different codes which set different values of baud rate through the `Serial.begin()` function.

I have an Uno using `Serial.begin(9600)` connected to an ESP8266 ESP-01 module
```
SoftwareSerial WiFiBoard(2, 3);
WiFiBoard.begin(115200)
```

Both of them are printing and reading from Serial, but when I use Arduino IDE Serial Monitor, I'm only able to display the content of the `9600`... Am I missing a setting somewhere?

Also, when I configure both of them to use the baud rate `9600`, I still only see the Uno information

body:
Your computer can not see what is going over the WiFiBoard serial connection because that connection has nothing at all to do with the connection to your computer.

If you want your computer to see what is being received on that port you must read the data from that port then send it to your computer.

It doesn't (much) matter about the difference in baud rates (only that if one sends too much data too fast for the other to forward it you will lose some data).

It's common to use something like:

```
while (WiFiBoard.available()) {
    Serial.write(WiFiBoard.read());
}
```

That will forward anything received from the WiFi board over the serial port to the computer.


message:
AT firmware upgrade in ESP-01 using Arduino UNO R3

I need to upgrade the AT firmware in ESP-01 by using Arduino UNO R3 serial interface. Do I need to remove the Microcontroller Chip from the DIP socket before burning firmware? Does it going to affect Arduino Bootloader?

body:
> Do I need to remove the Microcontroller Chip from the DIP socket before burning firmware?

No, just connect RESET to GND to stop the MCU from running.

> Does it going to affect Arduino Bootloader?

No.


message:
How do I use lambda functions in Arduino?

I want to pass a lambda function as an argument to a method. Example:

```cpp
T reduce(const T initial, const std::function<T(T, T)> acc) {
    T value = initial;
    for (size_t i = 0; i < S; ++i) {
        value = acc(value, this->values[i]);
    }

    return value;
}

...

int sum = this->reduce(42, [](int acc, int value) { return acc + value; });
```

If I try to compile this code for Arduino, I get an obvious error:

> error: 'function' in namespace 'std' does not name a template type

How can I use a lambda function in Arduino?

body:
`std::function` is <s>not supported by the Arduino environment</s>.
(**Edit**: as mentioned by KIIV in a comment, it's supported on ARM
targets, but not on AVR.) You can, however, pass a non-capturing lambda
to a function that expects a plain function pointer. For example, given

```cpp
T reduce(const T initial, T (*acc)(T, T)) {
    T value = initial;
    for (size_t i = 0; i < S; ++i) {
        value = acc(value, this->values[i]);
    }
    return value;
}

```

You can call it as

```cpp
int sum = test.reduce(42, [](int acc, int value){ return acc + value; });
```

If you want your lambda to capture something, it would seem you are out
of luck...


message:
How to upload a sketch to an atmega328 via FTDI FT232RL UART and Arduino IDE?

I have a [sparkfun AVR Pocket Programmer][1] and have burned the bootloader and uploaded programs using "upload using programmer" via USBtinyISP. It works fantastic.

I have a sparkfun FTDI Basic (as well as another FTDI breakout) that can send and receive bytes via the Arduino IDE serial monitor.

However, I cannot upload a new sketch or modified sketch to the atmega328 via FTDI. The IDE just hangs at the upload till timeout. Here is the list of some of my troubleshooting attempts:

 1. I have tried uploading a plain bootloader, as well as a running program via the ISP programmer before attempting the FTDI.
 2. I have tried direct connecting the FTDI DTR/RTS reset to the Atmega328 pin1.
 3. I have also tried connecting the FTDI DTR/RTS reset to a one side of a 0.1uF cap, and the other side of the cap to the Atmega328 pin1. I assume the cap is to send just a reset pulse instead of a reset constant.
 4. I have tried a different brand of FTDI FT232RL chip. No difference.
 5. I have tried adding 1k resistors on the Tx and Rx lines. No difference.

Being able to program over serial is really the secret sauce that makes Arduino so much easier for beginners than a stock AVR chip. However, I have not been able to locate any detailed information on how this Arduino programming via serial really works. Also, I am not sure how the reset pin works in relation to this process. I remember something that on old Arduino boards you had to press or hold the reset when uploading, but have not be able to find any of this information either as it has been buried by time.

This [Building an Arduino on a Breadboard Article][2] and photo from that article below is a good outline of the setup I have right now. But in this configuration it seems that a sketch can not be uploaded. What do I need to add breadboard circuit in order to upload a sketch via serial? Or what procedure do I need to do with the reset button when uploading?

[![enter image description here][3]][3]

Thanks!

[Atmega328 Spec Sheet PDF][4]

  [1]: https://www.sparkfun.com/products/9825
  [2]: https://www.arduino.cc/en/Main/Standalone
  [3]: https://i.stack.imgur.com/ZcQl7m.jpg
  [4]: http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061B.pdf

body:
Answering my own question; I just got lost in the troubleshooting.

[![Upload Using Programmer != Burn Bootloader][1]][1]

Though I tested it both ways, I evidently overlapped issues, masking the core problem. Upload using programmer works great for transferring your sketch but it does **NOT** allow sketches to be uploaded via serial later. (Not sure if there is an inherent or logical reason for this, but this is what I have found by experimentation).

And like hcheung mentioned in the comments, a capacitor on the FTDI reset line is required. Connecting it directly will NOT work. I used a 0.1uF and it worked well. I have attached a couple different photos of my setup for someone following this path in the future. Note that the LED I am using has an internal resistor; a normal LED will need an 1k series resistor. Also, leaving the ISP programmer attached while uploading a sketch over serial did not seem to cause any issues.

[![atmega328 ftdi top view][2]][2]
[![ftdi setup left][3]][3]
[![ftdi setup right][4]][4]

  [1]: https://i.stack.imgur.com/mgbie.png
  [2]: https://i.stack.imgur.com/zqQdE.jpg
  [3]: https://i.stack.imgur.com/u64u0.jpg
  [4]: https://i.stack.imgur.com/bSlzP.jpg


message:
L298N motor driver and battery issues

I'm trying to build an Arduino 4WD smart car. so i connected my l298N motor driver module with my v4 shield and used a 4 x 1.5v AA batteries to try and power my 4 motors up. i connected 2 of the motors in parallel so i can use 1 L298N to power it on. initially it worked but then a few minutes later it stopped moving. i thought my connections were bad so i redid all the connections but it didn't work so i changed the battery to 9v. with this the motors worked for a few seconds then stopped but was making noise so i tried powering the motor driver with my Arduino but it didn't come on. I tried powering the motor driver module with my Arduino but the driver module didn't come on.i decided to use my bread board and l293D IC to control my motors it didn't work but the motors were making noise. I changed my motor to one that i removed from a PlayStation controller but nothing still.i did research on the internet and was advised on this tutorial (https://create.arduino.cc/projecthub/maxxlife/arduino-4wd-car-cf5fd0) to not use AA batteries but no explanation why. so i checked other tutorials and saw people using AA to control 1 or 2 motors. Why shouldn't i use AA batteries? does anyone please think they know the solution to my problem? thank you

This is how my kit looks https://www.ebay.com/itm/NEW-4WD-Robot-Smart-Car-Chassis-Kits-car-with-Speed-Encoder-for-Arduino-M26/201561877173?_trksid=p2047675.c100009.m1982&_trkparms=aid=777000&algo=ABA.MBE&ao=1&asc=36860&meid=c76077722d4348e88152fa6c7f32c005&pid=100009&rk=1&rkt=1&sd=181329341315

Also should i change my use Li-ion battery 18650 x2 instead of the 6LR61 9v battery i used

body: Rule #1 9V batteries a power supply they are NOT. In your case you are looking at small voltages for the motor power. Your choice of a driver is not the best as you will have from 1.2 to 2.4 volts across the L298 depending on the loading. This is directly from the ST data sheet. Try the TB6612FNG instead, taking advantage of the device’s use of MOSFETs. The TB6612 may be a little more expensive, but it will be clearly worth it.


body:
I give you credit for trying. In your spare time read some materials on basic
electronics. I will see if I can help but no guarantee. he motor driver you are using
has transistors as the driving element. That indicates the motor power is going
through them. Since they are transistors they have a PN junction. When voltage goes
through a silicone junction it will drop 0.7volts for each junction. If lightly
loaded sometimes less. Note: this loss is expelled as heat. You have two configured as a darlington configuration on each output. This places two junctions in series with each motor lead.  That is a total of 4 junctions yielding a drop of 4 * 0.7 = 2.8 Volts.  Subtract that from your supply before you start, that is a big hit in low voltage systems. The MOSFET will have a drop of about 0.05Volts on each side leaving you 2.7 more volts to work with. Batteries have power ratings, these are conservative:

Type Cap (mAh))  Drain(mA) -
  D    13000      200 -
  C     6000      100 -
  AA    2400       50 -
  AAA   1000       10 -
  N     650        10 -
  9     500        15 -

The battery capacity will be better with lower drain currents and shorter with higher drain current. To determine your battery life, divide the capacity by the actual load current to get the hours of life. For example: A circuit that draws 10 ma powered by a 9 volt rectangular battery will operate about 50 hours: 500 mAh /10 mA = 50 hours The cell voltage of alkaline cells steadily drops with usage from 1.54 volts to about 1 volt when discharged. The voltage is near 1.25 volts at the 50% discharge point. Alkaline cells exhibit a slightly increased capacity when warmed and the capacity drops significantly at temperatures below freezing. Mercury and silver oxide batteries have nearly twice the capacity as alkaline batteries of the same size but the current ratings are significantly lower. Alkaline batteries also have good shelf life making them ideal for home-made electronic projects. Rechargeable batteries have less capacity than primary cells Look at it like the batteries are your piggy bank. The more your take out the less you will have. The faster you take it out the quicker you are out of money.


message:
Can I run more than 2 servo motors smoothly, connecting their power to regulated limit voltage and signal wires to the digital pins of the arduino?

Now my next project is going to be about Servo Motors and for that, I don't want to buy any shield or motor driver for Servos. So I have designed a circuit, to drive 12 servos at a time without any interruptions. I haven't got any Servos yet, well my order is shipped already...Keeping that aside lets head down to the connection..

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/cvEy7.jpg

The Screenshot was taken from a circuit designed by me at tinkercad.com.

Parts:

1. HiWatt Battery (Standard 9 volts battery blue and white coloured)

2. SG90 Servo Motor
(6v 400mah max)
(Resistance of each of them is 1.4kohm, when connected power and ground of multimeter)

3. Arduino
(Required amp is 40*12)

The circuit Explanation:

1. The Orange wires of servos are signal wires connected to the pins of Arduino.
2. A 750 ohm resistor is connected to the positive terminals of each motor, from which, voltage is regulated for the motor.
3. The motor grounds have been connected to the ground of the battery.
4. Ground of Arduino has been connected to the ground terminal of the battery. So now, ground of the battery and the Arduino is same.

5. All the motors are connected in parallel connections with 750 ohm resistors at the positive terminal of each motors

So now my question is, How many servos will I be able to run when I power them parallel-ly using a standard 9 volts battery (HI-WATT, Blue and white one), if no, Which will be the best battery for doing it?

I need to run 12 Servos uninteruptedly.

Thanks for your precious time....

body:
> So now my question is, How many servos will I be able to run when I power them parallel-ly using a standard 9 volts battery (HI-WATT, Blue and white one), if no, Which will be the best battery for doing it?

Unfortunately: Zero motors with your current circuit. Maybe one motor with a better circuit and the same battery. Here is the explanation.

- You should ditch the standard 9V block battery. These batteries are made for low power applications (like IR remotes or smoke sensors) and cannot provide enough current for driving all those motors. They might be able to drive one servo, but still will be drained very fast. You should use a battery, that can provide much more current. Which battery you choose also depends on your other requirements. A series of AA alkaline batteries can give you enough current. Or you can directly buy a LiIon or LiPo rechargeable battery (including a fitting charger board). They can provide way enough current.

- You cannot just use simple resistors as voltage regulators. That just doesn't work for loads, that can draw a changing amount of current (like a motor).
    - The voltage, that the motor gets, depends on the current, that the motor draws. When the motors stands still, it will draw very little current. Thus the motor is getting the full 9V in that case. As the drawn current rises, the voltage will go down, until the motor gets not enough voltage to operate correctly.
    - The resistor of 750 Ohm restricts the current draw of the motor. Even when we (for the sake of calculation) treat the motor as a short circuit, the maximum current through the resistor with 9V will be only 12mA, so way way lower than the 400mA, that you stated in your question. You won't be able to move the motor much with that little current.
    - Even if you used a smaller value, you need to be careful with the current. I guess you are using standard resistors there, which typically have a power limit of about 0.25W. These are meant for rather low current circuits. With the 400mA @ 6V, that your motors need, you are in the region of 2.4W (that is not necessary the power for the resistor, just a value for you to see the relation). You can easily burn away a little resistor that way. When you need a resistor with a higher power limit, you need to buy one, which can handle it (and these are typically multiple times the size of a standard "signal" resistor and still can get very hot, when used in the realm of their power limit).

    Instead you should buy a proper voltage regulator. At that current, buy a switching buck regulator, as they are way more efficient than linear regulators. Which regulator you need to buy also depends on the voltage of the battery, that you choose. Be sure to buy a regulator, that can provide significantly more current, than we need in total for your circuit. This is important, because regulators are typically described with a maximum current, at which they already need extra measures for cooling. When you stay well below that, you can avoid thinking about fitting cooling for it.

---

> So , will it control the motors as good as 16 channel servo drivers?

Yes, it can. Though you need to think about how you are controlling the servos on the Arduino. The standard `Servo` library supports up to 12 servos with one timer. When you can change the library to use 2 Timers for supporting more servos, then you have it. You could also try to search for other libraries, which support more servos, or write your own library. I would say, using the driver would be simpler. The driver does not switch the power for the servos. It has a chip, which can output 16 servo control signals and is controllable over an interface like I2C or SPI.

If you want to use such a driver is up to you. You might find it more important to have as few electronic parts as possible.


message:
Is it possible to send 2 or more o/p signal at the same time?

I wanted run two motors using Cytron MDD10A Dual Channel motor driver. So my concern is based on execution of code that is done line by line, in that case when I'm driving two motors will this delay in output signal at the PWM pins make a difference in nature of performance i.e. for example a car wheel, in case there is such delay it'll cause one wheel to rotate prior to another which is not desired. If yes, how do I rectify the same.
I also wanted to know when I use the delay function does it cause the delay in execution of the previous line or reads the upcoming line upon some 'x' seconds of delay?

Thank you for your help.

edit: code sample:

```cpp
void FWD() {       // to move forward
    digitalWrite(m1, HIGH);  // motor 1 ON
    digitalWrite(m2, HIGH);  // motor 2 ON
    analogWrite(tm1, 225);   // tm1 assigned to a PWM pin
    analogWrite(tm2, 225);   // tm2 assigned to another PWM pin
}
```

in the above function I wish to run both analogWrite at the same time as I'm not sure how will it affect the output? I wish for the motors to start at the same time.

body: I don’t think your fear is founded.  Yes technically one motor starts after the other but the amount of time would be a few microseconds at most.   For perspective it takes you about 200,000 microseconds to blink your eye.  You will not be able to tell.  They will appear to start at exactly the same time.  You would need some very sophisticated high speed cameras to see the difference in timing.  It wouldn’t affect how your car moves.


body:
Technically, it is possible to start two PWM outputs at the exact same
time on an Uno or Nano. If they are both controlled by the same timer,
you just have to update the corresponding control register _once_ with
the relevant bits set to enable both channels. For example, you could
start outputs 5 and 6 simultaneously, as both are on Timer 0:

```c++
OCR0A   = value;  // set the duty cycle on OC0A = digital 6
OCR0B   = value;  // set the duty cycle on OC0B = digital 5
TCCR0A |= _BV(COM0A1) | _BV(COM0B1);  // enable both outputs
```

If the outputs are on different timers, it is a bit more tricky. Timers
0 and 1 can be synchronized by clearing their shared prescaler with the
Timer/Counter Synchronization mode active. I do not think there is a
simple way to synchronize Timer 2 with any of the others.

All this is highly hardware-dependent, and not supported at all by the
Arduino core library. Thus, if you want to apply any of this, you will
have to study [the datasheet][328p], and poke directly into the I/O
registers of the microcontroller.

But then, as Delta\_G clearly points out in his answer, all this is
irrelevant to motor control. Motors are mechanical devices that have
significant inertia. They take time to speed up and slow down. Just to
give you a sense of scale, PWM outputs 3, 9, 10 and 11 deliver a square
wave with a period of 2.04 ms. Yes, those are _milliseconds_, and
this is too short for the motors to significantly change their speed
within one period. Contrast this with the handful of _microseconds_,
that the call to `analogWrite()` will take.

[328p]: http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061B.pdf


message:
Failed to boot VL53L0X: VL53L0X Error: -6

I am using a VL53L0X sensor in my project.
It was working fine when suddenly it started to show failed to boot error.
I tried debugging but of no use. I ran I2C scanner sketch and it detected the sensor at 0x29.

I get the following error -

```
23:38:27.797 -> Adafruit VL53L0X test
23:38:27.830 -> VL53L0X Info:
23:38:27.830 -> Device Name: VL53L0X ES1 or later, Type: VL53L0X, ID: VL53L0CBV0DH/1$1
23:38:27.830 -> Rev Major: 1, Minor: 1
23:38:27.864 -> VL53L0X: StaticInit
23:38:27.932 -> VL53L0X: PerformRefSpadManagement
23:38:27.932 -> refSpadCount = 2226323456, isApertureSpads = 92
23:38:27.932 -> VL53L0X Error: -6
23:38:27.932 -> Failed to boot VL53L0X

```

This is the code I used (its the example code with just 0x29 and true passed in begin function for verbose output):

```
#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

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

  // wait until serial port opens for native USB devices
  while (! Serial) {
    delay(1);
  }

  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin(0x29,true)) {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }
  // power
  Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
}

void loop() {
  VL53L0X_RangingMeasurementData_t measure;

  Serial.print("Reading a measurement... ");
  lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  } else {
    Serial.println(" out of range ");
  }

  delay(100);
}
```

I am using an Arduino nano -
following are the connections

ARDUINO->VL53L0X\
   3v3->Vin\
   GND->GND\
   A4->SDA\
   A5->SCL

I have rechecked the connection and voltages the sensor does receive 3v3 and gnd.

I need help with this asap.

Thanks in advance :)

body:
From the [VL53L0X API documentation][1] The error shows up as

    #define VL53L0X_ERROR_RANGE_ERROR   ((VL53L0X_Error) -6)

Not very helpful, but maybe you still have the factory protective cover installed?

Also, IMHO the Adafruit library is a bit buggy.  I now use the Pololu library (among other things, the Pololu library allows usage of the WIRE1, WIRE2, & WIRE3 hardware I2C busses.

27 September 2020 Update: On the Adafruit technical support forum, I did a search for 'VL53L0X ERROR'.  There were several thread mentioning ERROR -6 issues, but most of them were due to poor or missing solder on the VL53L0X header pins.  Could that be your problem?

  [1]: https://documentation.help/VL53L0X-API/group__VL53L0X__define__Error__group.html#gab1bcfe4c791fa91012ccf489a260430a


body: Since it sort of worked before I am assuming it is connected correctly. However you failed to mention pull up resistors on the I2C bus. If they are not there or to weak that could cause what you are seeing.


body:
I was facing same issue, now my problem is solved here.

This problem mostly occurs when we apply a power supply to the MCU that has capacitors at its output. This type of power supply's rising voltage is like you can see the image:

[![enter image description here][1]][1]

If you look at the data sheets of MCUs, you see that most MCUs can work at 1.8V to 5.5V. Here the rising voltage is slow; the MCU starts working at 1.8V and send signals to VL53L0x, but the sensor doesn't work at 1.8V.

So, what you need to do is add some delay (first power supply gets stable then start communication with sensor) in your code to avoid this issue. Do not add delay in the loop; it will affect the working of the MCU, where exactly you need to add delay. Code modifications are in the video below:

https://youtu.be/QEiNbTB8nNE

or you just can search on Youtube: How to fix VL53L0X error

  [1]: https://i.stack.imgur.com/zie4B.png


body:
I found a new possible solution to this problem, as I spent 2 days to solve it, I feel that I need to share it with you guys. I also could find the sensor through i2C scanner, but could not initialize it.

Here is the summary of solutions:

 1. *Powering problem 1*: **add a 50ms delay in the setup function** (before the sensor init, obviously). This way, the Vin will have time enough to reach the level needed by the sensor, as explained in a previous message (ocrdu)
 2. *Powering problem 2*: This sensor demands more than others, normally the **5V pin of your board will do it better than the 3v3**. If there are many sensors connected at the same time, **disconnect all of them to check whether they are using the power our vl53l0x needs**.
 3. *Powering problem 3*: If you feed it with an external source, **unify grounds with the board**, don't forget it
 4. *SCL - SDA weak signals*: **add a pullup (2k2 - 4k7 from each channel to vin)**, this way the signals will perform better, that could be the problem
 5. *Soldering problem*: **Make sure that each header pin is well soldered**. I've found many cases of poor soldering. The tiny pads don't help. It is advisable to check continuity with a multimeter between the headers and the pads where they should be connected
 6. *XSHUT not pulled up*: My problem, this was that AZDelivery board says that it has a pull up in XSHUT (which works like an enable). But it could either be false, or badly implemented. **Xshut needs to be high, 3v3/5v**, otherwise, the sensor won't work. Bridge the XSHUT to Vin or implement a pull up and the problem will be solved.

 - **I am using adafruit's library 1.1.2, and it works, with pullups, without pullups, connected to 5V and also connected to 3V3, with the
   50ms delay, and connecting XSHUT to high (3V3 / Vin)**
 - **My board is vl53l0x from AZDelivery (5€ amazon)**
 - **I have tested the sensor with arduino nano and with ESP32, both work fine**

Hope you guys find this useful <3

[esp32] [sensor] [i2c] [boot] [error]


message:
How to use d0 and d1 pins of arduino uno (Others) as a digital output when I don't want to use Serial

I have searched this topic almost everywhere also got different results that couldn't satisfy me

My new project is a 4x4 LED cube

Of which

Will contain 4 Rows and each Row will contain 16 LEDs

So, I need to use all the digital pins 0-15 as digital output.

And other pins 16-20 for grounding.

But the problem is, this project needs d0 and d1 pin to be connected as a digital output pin. (Not Serial communication)

In some places I have seen that Experts saying

>1. If you want to use Serial communication, then you can't use them.

>2. You can't use it while your arduino is connected to PC.

>3. You Can't do this ,as this may harm the device

>4. You must turn off serial connection first.

OK, reading this, I got confused, I don't need to use any serial connection (console and others) in this LED cube project so I tried to turn off serial connection by not writing the code below.

    Serial.begin(9600);

So, will that free those d0 and d1 pins as digital for me ? Or USB connection is also considered as a serial connection?

So, how can I do it? And will doing it really harm my board?

body:
If you don't use the serial port, pins 0 and 1 are regular I/O pins.
It's just as simple as that.

> If you want to use Serial communication, then you can't use them.

Correct.

> You can't use it while your arduino is connected to PC.

Wrong. You can keep the USB cable connected as a power supply. You will
not be able to use it for communication though.

> You Can't do this, as this may harm the device

What is “this”? The device can be harmed if you drive too much current
to/from an I/O pin, irrespective of whether it's a pin that could be
used for serial communication.

> You must turn off serial connection first.

Only if you did turn it on before. If you never enable `Serial`, you
don't have to do anything more.


body:
The bootloader always turns UART0 on upon the loading of the code to your Arudino Nano.
So at the end of the day pins D0 and D1 are used for their alternate functions as a UART receiver and transmitter without you doing so in your code.

Copy the following code to whatever your sketch or C program to disable the UART0 module before you initalize pins d0 and d1 as digital IO, then you can set the two pins as digital I/Os as usual and they will work perfectly.

    UCSR0B &= ~(1<<3);
    UCSR0B &= ~(1<<4);


message:
Why we are using client.flush() in the program code ,when we connect Esp8266 with internet or web server?

I am using Esp8266 Wifi modular (12-E) for controlling a led through the access of wifi/webserver.
I have written code in Arduino ide taking various references from the google.In the code, I didn't understand the client.flush(), why we are using this method? In google, I have searched about many explanations, I got common to explain which I don't understand till yet.
**"Waits for the transmission of outgoing serial data to complete."**
I didn't get till yet. can anyone explain to me in simple terms?

 /

    / Wait until the client sends some data

      Serial.println("new client");

      while(!client.available()){

        delay(1);

      }

      // Read the first line of the request

      String request = client.readStringUntil('\r');

      Serial.println(request);

      client.flush();

body:
This is most likely related to the *old* usage of `.flush()` from pre IDE version 1.0.0.

In those old versions `.flush()` would erase any pending data in the reception buffer. It was the equivalent of:

```
while (client.available()) {
    client.read();
}
```

Now though it's used to ensure that all data has been sent before doing anything else. In this situation it's completely meaningless.


message:
Analog Read dummy file

Can we use just a analog Read without storing it

i hear it it a good practice to take two reads

for better accuracy

example:

    // Read extra analog inputs
        for (int i = 0; i < 8; i++)
    {
        // Read analog pin to nothing.
            analogRead(i]); // analog-read is not writing to anything
    }

    // Read the analog inputs
    for (int i = 0; i < length; i++)
    {
        // Write the state of the analog pin to the response buffer.
        slave.writeRegisterToBuffer(i, analogRead(analog_pins[address + i]));
    }

body:
how about this ?

    // Read the analog inputs
    for (int i = 0; i < length; i++)
    {
        analogRead(analog_pins[address + i]); // for pre read

        // Write the state of the analog pin to the response buffer.
        slave.writeRegisterToBuffer(i, analogRead(analog_pins[address + i]));
    }


message:
How to use PWM with DRV8870?

I'm using Arduino nano and I'm struggling working with the DRV8870 IC on PWM mode.
When I use ```analogWrite(_pin, duty_cycle);``` the motor makes weird noises.
I thought it's because of the PWM frequency so I tried to change it using
```TCCR1B = TCCR1B & B11111000 | B00000011;``` but it didn't work out.

Texas Instruments wrote this in their pdf:
"When using PWM, switching between driving and braking typically works best. For example, to drive a motor forward with 50% of the maximum RPM, IN1 = 1 and IN2 = 0 during the driving period, and IN1 = 1 and IN2 = 1 during the other period."

[drv8870_pdf][1]

  [1]: https://www.ti.com/lit/ds/symlink/drv8870.pdf?ts=1600699731799&ref_url=https%3A%2F%2Fwww.google.com%2F

body:
analogWrite(_pin, duty_cycle) will work properly only on pins that support PWM. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs. Check the following link to find yours:
https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/


message:
Arduino Nano and 0.96 i2c oled screen not working

[![My wiring][1]][1]When I try to scan the i2c address it stays stuck on "i2c Address Scanner" which is the first line of the code.
My screen is connected with VCC-5V, GND-GND, SCL- 4.7K resistor->A5, SDA- 4.7K resistor->A4.
Nothing displays on screen, and I even tried without the resistors. I also tried with some 10K resistors and same result.
>Here in the picture you can see how I connected the screen to the nano. SDA-A4, SCL-A5, VCC-5V, GND-GND.

  [1]: https://i.stack.imgur.com/nNvCs.jpg

body: From what I am reading it is not properly connected.  You are getting what I would expect. ACL of the device goes directly to A5 and a pull up resistor to +5. Same thing with SCL, connected directly, both need pull ups. You did not state what it is connected to. If there is nothing connected you will get nothing. Also the old wire library did not support timeout so you could hang indefinitely.


message:
How to determine what resistor value to use for LED strip

I'm trying to use an ESP8266 powered by my computer through USB cable to control a WS2812B LED strip. I've read online that you're supposed to put a resistor before the data channel to help prevent noise but I'm struggling to figure out what the resistor value should be.

I've figured out so far that the LED strip will use a MAXIMUM of 25.8W and that the Vin pin that is powering the LED strip is outputting 5V. I also plan on putting a 470uF capacitor across power and ground.

body:
It seems like people generally just use a resistor around 300 - 500 ohms so I'll just use a 500 ohm resistor. Answer found on [another thread][1]. And [here as well][2].

  [1]: https://forum.arduino.cc/index.php?topic=554642.0
  [2]: https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices


body:
The majority of the time adding a resistor to the data line is completely pointless.  It only has an effect if the Arduino and the first WS2812B chip are connected over a long cable. By "long" I'm talking meters, not centimeters. The length of the strip of LEDs is irrelevant as each LED generates a fresh signal to send to the next LED. It's only the length of cable *between the Arduino and the LED strip that matters*.

If that is long you can get "ringing" and reflections of the signal through poorly matched impedances. The resistor is there to absorb some of those reflections and reduce the ringing by increasing the impedance of the Arduino's output.

What is a good value? Well, that's hard to say, since it's dependent on the length and type of cable in use. Too low a value and it will do nothing. Too high a value and it will "round off" your signal too much and you'll lose data. A typically chosen value that fits many situations is 220Ω.

But of course for short connections it's irrelevant and you shouldn't add a resistor.


message:
How to capture the compilaton output to a text file in Windows?

I am trying to capture the verbose output of the compilation to get it into a text file. I am using the IDE 1.8.12 running on Windows 10. I have tried looking for a right mouse button context menu, CTRL-C doesn't work, and finally in desperation, the CMD.exe trick of hitting the Enter key after selecting text.

I also went to the build folder in appdata/local/temp/arduino_build_nnnnn but there's nothing like that there.

There is a topic already about this but it refers to the Linux IDE which can be launched from the command line. It turns out that it's somewhat the same on Windows.

body:
The post [Capturing avrdude command in IDE][1] gave me the clue. Under Windows the file

`C:\Program Files (x86)\Arduino\arduino_debug.exe`

can have its output redirected to files same as a shell command.

In the CMD.exe DOS box, I executed:

`C:\Program Files (x86)\Arduino>arduino_debug.exe >\temp\logfile.txt 2>\temp\errfile.txt`

and the regular log stuff went to logfile and the errors and warnings went to errfile.

There's enough material in those two files to hurt yourself.

  [1]: https://arduino.stackexchange.com/questions/31110/capturing-avrdude-command-in-ide


message:
How much current can arduino ground absorb?

I am currently working on an LED 4x4 cube, so here is my pre planned circuit diagram.

https://easyeda.com/editor-mobile/#id=ffca9f3303f242a185b950b0bee4fa29|

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/lrFuS.png

1. I am to connect 220ohm to each positive terminals.(16)

2. I am to use 4 transistors(2n2222) for 4 negative layers of which, collector terminal will be connected to the negative terminal layers , base will be connected to 4 analog pins through 1k ohm, and emitter to be connected to the GND pin of arduino. Using transistor as a switch.

Can my studio ground get damaged if connected directly without a resistor.

If no?

Is there any way to make it?

Explanation with circuit diagram will highly be preferred...

Thanks for your precious time...

body: You are asking the wrong question. It does not matter how much current the arduino ground can adsorb, it was designed for what it needs not what other devices may need. What you want to do is connect all the grounds at the power supply (please tell me you are not using the arduino 5v for this). You might look as MOSFETs as you will have a lower voltage drop and much easier to drive.


body: No your gnd won't get damaged if you source current through it. If u need explanation let me know


message:
Sim800L does not send SMS messages in a row

I created a project with sim800l that comes and stores 5 phone numbers in eeprom memory and then when a sensor is triggered, it sms all the numbers and then calls the first one.
But the module does not send an SMS to everyone and only sends an SMS to the first number and then nothing else and then calls. The problem is not that the numbers are not read correctly, because when sending the text message, I said, show the number in the monitor series and it will show correctly. It is not a problem not to send a text message request because I also connected a usb to ttl module to the tx rx module and saw that it comes for all numbers and at sends the at command correctly.
```

#include <EEPROM.h>
#include <SoftwareSerial.h>

#define SIM800RX 7 //D7 - SIM800L RX PIN
#define SIM800TX 8 //D8 - SIM800L TX PIN

#define SENSOR1SMSTEXT "Fire error" //Sensor 1 SMS Text
#define SENSOR2SMSTEXT "Theft error" //Sensor 2 SMS Text

SoftwareSerial SIM800(SIM800RX, SIM800TX);

String readSerial(String txt) {
  SIM800.flush();
  if (SIM800.readString() != "") {
    while (SIM800.readString() != "") {}
  }
  String text = "";
  if (txt != "") {
    SIM800.println(txt);
    int timeout = 0;
    while  (!SIM800.available() && timeout < 12000) {
      delay(1);
      timeout++;
    }
    if (SIM800.available()) {
      text = SIM800.readString();
    }
  }
  return text;
}

void readSerialOK(String txt) {
  while (readSerial(txt).indexOf("OK") == -1) {
    delay(700);
  }
}

void configSim800L() {
  readSerialOK("AT");
  delay(200);
  readSerialOK("AT+CMGF=1");
  delay(200);
  readSerialOK("AT+CNMI=1,2,0,0,0");
  delay(200);
  readSerialOK("AT+CMGDA=\"DEL ALL\"");
  delay(200);
  readSerialOK("AT+CSMP=17,167,0,0");
  delay(200);
}

void SendTextSMS(String num, String sms) {
  SIM800.print("AT+CMGS=\"");
  SIM800.print(num);
  SIM800.println("\"");
  delay(150);
  SIM800.print(sms);
  SIM800.write(26);
  delay(700);
  Serial.println("");
  Serial.print("Send SMS to:");
  Serial.print(num);
  Serial.print(":");
  Serial.println(sms);
}

bool checkPhone(String phone) {
  if (phone.substring(0, 2) == "09" && phone.length() == 11) {
    return true;
  } else {
    return false;
  }
}

void WriteEEPROM(byte part, String val) {
  int start_addw = part * 16;
  int w_len = val.length();
  EEPROM.write(start_addw, w_len + 1);
  int end_w = start_addw + w_len;
  byte len = 0;
  for (int i = start_addw + 1; i < end_w + 1; i++) {
    EEPROM.write(i, int(val[len]));
    len++;
  }
  len = 0;
  EEPROM.commit();
}

String ReadEEPROM(byte part) {
  int start_addr = part * 16;
  String str;
  int ch;
  int r_len = EEPROM.read(start_addr);
  int end_r = start_addr + r_len;
  for (int i = start_addr + 1; i < end_r; i++) {
    ch = EEPROM.read(i);
    str += char(ch);
  }
  if (checkPhone(str) == false) {
    str = "";
  }
  return str;
}

void ClearEEPROM(byte part) {
  int start_addw = part * 16;
  int w_len = 11;
  EEPROM.write(start_addw, 0);
  int end_w = start_addw + w_len;
  byte len = 0;
  for (int i = start_addw + 1; i < end_w + 1; i++) {
    EEPROM.write(i, 0);
    len++;
  }
  len = 0;
  EEPROM.commit();
}

void SendSMS(String sms) {
  String num1 = ReadEEPROM(1);
  String num2 = ReadEEPROM(2);
  String num3 = ReadEEPROM(3);
  String num4 = ReadEEPROM(4);
  String num5 = ReadEEPROM(5);
  if (num1 != "") {
    SendTextSMS(num1, sms);
  }
  if (num2 != "") {
    SendTextSMS(num2, sms);
  }
  if (num3 != "") {
    SendTextSMS(num3, sms);
  }
  if (num4 != "") {
    SendTextSMS(num4, sms);
  }
  if (num5 != "") {
    SendTextSMS(num5, sms);
  }
}

void Call() {
  String call = "";
  String num1 = ReadEEPROM(1);
  String num2 = ReadEEPROM(2);
  String num3 = ReadEEPROM(3);
  String num4 = ReadEEPROM(4);
  String num5 = ReadEEPROM(5);
  if (num1 != "") {
    call = num1;
  } else if (num2 != "") {
    call = num2;
  } else if (num3 != "") {
    call = num3;
  } else if (num4 != "") {
    call = num4;
  } else if (num5 != "") {
    call = num5;
  }
  Serial.println("");
  Serial.print("Call to:");
  Serial.print(call);
  if (call != "") {
    readSerialOK("ATD"+call+";");
    delay(300);
  }
}

void trigSensor1() {
  SendSMS(SENSOR1SMSTEXT);
  Call();
}

void trigSensor2() {
  SendSMS(SENSOR2SMSTEXT);
  Call();
}

void setup() {
  SIM800.begin(9600);
  Serial.begin(9600);
  EEPROM.begin(512);
  pinMode(IN1, INPUT_PULLUP);
  pinMode(IN2, INPUT);
  pinMode(SSS, OUTPUT);
  digitalWrite(SSS, LOW);
  while (readSerial("AT+COPS?").indexOf("+COPS: 0,0,\"") == -1) {
    delay(700);
  }
  configSim800L();
  digitalWrite(SSS, HIGH);
}

void loop() {
  if (digitalRead(IN1) == LOW) {
      trigSensor1();
  }
  if (digitalRead(IN2) == HIGH) {
      trigSensor2();
  }
}
```
Thanks if friends have experience in this area tell me.

Thanks in advance.

body:
I find error:
```
void SendTextSMS(String num, String sms) {
  SIM800.print("AT+CMGS=\"");
  SIM800.print(num);
  SIM800.println("\"");
  delay(150);
  SIM800.print(sms);
  SIM800.write(26);
  delay(3000);
  Serial.println("");
  Serial.print("Send SMS to:");
  Serial.print(num);
  Serial.print(":");
  Serial.println(sms);
}
```
i replaced delay with 3000ms the error solved.


message:
MAX30100 not working

I am unable to get the MAX30100 sensor to work\
It keeps throwing the following error:

```
16:06:32.936 -> Initializing...
16:06:32.936 -> MAX30105 was not found. Please check wiring/power.
```

I am using the Sparkfun library Example sketch "Example5_HeartRate"

As far as I understand the breakout board for the MAX30100 is a bit buggy -
By which I mean the internal pullup resistors are connected to 1.8V for some reason instead of 5V

I have used MAX30100 before and had faced the same issue. However, after scouring the internet for hours  I found this helpful article: https://reedpaper.wordpress.com/2018/08/22/pulse-oximeter-max30100-max30102-how-to-fix-wrong-board/

I want to use another MAX30100 sensor and have followed the above article again and have done the said changes to my sensor which resulted in the board being detected at address 0x57 when I run the i2c scanner. However, unlike the previous time, the Example sketch did not run as expected.

I even tried this solution:
https://github.com/oxullo/Arduino-MAX30100/issues/51#issuecomment-391193292

But kept receiving the same error message.

The pin connections are:
ARDUINO -> MAX30100/MAX300102\
3V3     ->    VIN\
SDA (A4)->    SDA\
SCL (A5)->    SCL\
GND     ->    GND

I need help asap.
Thank you in advance!

I hope the links mentioned are helpful for someone else.

body:
Check out this [link][1]. I guess it will work I had the same MAX30100 module what i did was removed those 4.7k resistors mounted through hole resistors on breadboard and pull-uped them using 5V and it was working fine for me

  [1]: https://www.teachmemicro.com/max30100-arduino-heart-rate-sensor/


body:
I had similar trouble with a cheap board (RCWL-0531). Used the same “[How to fix wrong board][1]” fix you mentioned (pictured).[![enter image description here][2]][2] Which worked ... sort of ... Achieved terrible sensing stability (both HR and O2). I read the comments in the sample code about Uno boards (which I had started out on) having insufficient capacity to handle the full sample data, so migrated to ESP32. Still not great.  Gave up and bought a [Sparkfun MAX30105][3], still connected to an ESP32 and OLED display. Immediately a different experience, much higher quality but I don't know why. I have some "still to-do" ideas to investigate the [MAX30102_by_RF][4] library and also to use a more capable processor (e.g., Due) to see if the signal processing capability can be cranked up. Hope this helps - you're not alone.

  [1]: https://reedpaper.wordpress.com/2018/08/22/pulse-oximeter-max30100-max30102-how-to-fix-wrong-board/
  [2]: https://i.stack.imgur.com/6mYPn.jpg
  [3]: https://www.sparkfun.com/products/14045?_ga=2.199602030.152842805.1598007752-
  [4]: https://github.com/aromring/MAX30102_by_RF


body:
This video might help you, in this video, an Indian guy explained the issue in detail with the help of the max30100 sensor schematic diagram, and solved it in two ways.
https://youtu.be/ZqdmA4NAqb0


message:
How to calculating requirements of power supply for a project

I am starting with electronics and been working with Arduino for some time now. I did some basic LED and servo motor project and was hoping to jump into making an obstacle-avoidance car. I used **4** AA batteries to make it, but the voltage was too low, as the motors were not moving. Then I knew about the volt requirements and all that. I also tried with a 9v alkaline battery, but it didn't help much.

Here are the electrical parts I used:

 1. Arduino
 2. Ultrasonic sensor
 3. 4 toy motor
 4. 1 hobby servo motor
 5. Motor driver shield L293D
 6. Battery

These are the operating voltages that I know of:

 1. Arduino = 7 to 12 v
 2. Hobby servo motor =  3.0V~ 7.2V
 3. Toy motor = 3v ~ 12v dc; has a No load current 40 - 80 mA

Because AA batteries are of 1.5v and are in series, it has 6v, and I am assuming that was the reason it was not working as expected. What I am confused about is, how do I choose a battery or power supply to be specific.

Please forgive me for asking such a noob question. Since 1 Arduino + 4 toy motor  + 1 hobby servo motor = 7v + 4 x 12v + 7v = 62 v, but I checked and I couldn't find battery that is above 15v. I surely don't understand how to pick a power supply. Could you please help me out on how to calculate and choose the right battery/power supply? Also, what to look for if for example, I want to run it for a minimum of 10 minutes?

body: A power supply a 9V battery is not. Since you are using batteries the L293D is a very poor choice for a driver, it uses silicon transistors which I believe are in a darlington configuration which will cause a voltage drop of from 1.4 to 2.8 volt on the motor.  The 4 (or more) AA batteries will work but use a MOSFET bridge. You can always use a small SEPIC (Buck/Boost) converter to power it, that will keep the voltage constant until the batteries are exhausted. Set it to about 9V and power the arduino via the VIN input for more filtering. You will need a way of measuring voltage. You will lose less power with the converter then you are losing in your current driver.


message:
No programmers available for this board - Programming ESP32 Cam with Ardunio IDE

This is my first time working with ESP32 Cam boards.
I have followed the instructions as given in this site [https://technoreview85.com/how-to-program-esp-32-cam-using-arduino-uno-board/][1]
However my IDE doesn't display any programmers for this board.

[![Problem!][2]][2]

Couldn't find any details about this in google. I just want to know how I could fix this problem(i.e. get the programmers listed).
Thanks in advance.

  [1]: https://technoreview85.com/how-to-program-esp-32-cam-using-arduino-uno-board/
  [2]: https://i.stack.imgur.com/5DLPE.png

body:
There are no programmers for ESP32. It only accepts Serial upload over bootloader.

Versions of IDE before 1.8.13 displayed programmers for all board support packages, that is why a programmer could be selected. Now only programmers for package of the selected board are available. But programmers are used only with the "Burn bootloader" or "Upload with programmer" commands, not with standard Serial upload over bootloader.


body: The older version of Arduino IDE. 1.8.12 worked.


message:
Arduino timer interrupts for PID

I'm working on a robotics project where an arduino nano is acting as the motion controller. I'm trying to use a trapezoidal motion profile generator and PID loop to follow that profile, but I found out the motion was quite jerky and I assumed it's because both the motion profile and the PID run at the same speed (10ms loop using timer interrupt library)

    #include <TimerOne.h>
    void setup() {
      Timer1.initialize(10000);
      Timer1.attachInterrupt(Compute);
    }

now I want to use two seperate loops, one running at the same 10ms interval for the profile generation and one running at 1ms for the PID (I'm not sure if the motors can actually act that quickly, but I can adjust the timings a bit), this way the PID has about 10 loops to get to the desired position accurately, reducing the jerky motion.

I'm not sure how I can set up two different interrupts using that library or by setting the flags like TCCR0A to generate the desired interrupt timers.

Here's the actual "Compute" function in case it's relevant (there are some bugs regarding the direction and it's using two different methods for generating the profile, also I'm changing it so don't think it matters, but just in case it does, I posted it)

    void Compute(){
      int dir;
      if (setPoint > target){
        dir = 1;
      } else if (setPoint < target){
        dir = -1;
      }
      if (mode == 1) {
        target += v*dir;
        if (abs(setPoint - target) <= turningPoint){
          v -= acceleration;
        } else {
          if (v < maxV){
            v += acceleration;
          }
        }
        if (abs(target) >= abs(setPoint)){
          target = setPoint;
          mode = 0;
          v = 0;
          Serial.println("Finished!");
        }
        #ifdef DEBUG
          printDebug();
        #endif
      } else if (mode ==2){
        target += v*dir;
        if (phase == 1 and v < reachableV){
          v += acceleration;
          if (v >= reachableV){
            phase = 3;
            v = reachableV;
          }
        } else if (phase == 3){
          v -= acceleration;
          if (v <= 0){
            target = setPoint;
            mode = 0;
            v = 0;
            phase = 0;
            Serial.println("Finished!");
          }
        }
        #ifdef DEBUG
          printDebug();
        #endif
      }
      error = target- pos;
    /////////////////////////////////////////////////
      PID_P = kp * error;
      if (PID_P > outMax) PID_P = outMax;
      if (PID_P < outMin) PID_P = outMin;
    /////////////////////////////////////////////////
      if (abs(error) < 50){
        PID_I += ki * error * sampleTime;
      } else {
        PID_I *= 0.8;
      }
    /////////////////////////////////////////////////
      PID_D = kd * (pos - lastPos) / sampleTime;
      if (PID_D > outMax) PID_D = outMax;
      if (PID_D < outMin) PID_D = outMin;
    /////////////////////////////////////////////////
      output = PID_P - PID_D + PID_I;
      if (output > outMax) output = outMax;
      if (output < outMin) output = outMin;
    /////////////////////////////////////////////////
      lastPos = pos;
      if (output < 0){
        digitalWrite(DIR,1);
      } else {
        digitalWrite(DIR,0);
      }
      analogWrite(PWM,abs(output));
    /////////////////////////////////////////////////
    }

p.s: I'm most likly going to use the PID library instead of trying to write my own like I currently have the code.

body:
Just use a single 1ms timer interrupt and count them. Every 10 interrupts do both things.

    void interruptHandler() {
       counter++;

       // do things that happen every 1ms

       if(counter == 10) {
          // do things that happen every 10ms
          counter = 0;
       }
    }


message:
RGB LED using potentiometer and push button

I'm currently working on an assignment which has to turn on an RGB LED using a potentiometer and button. The problem I currently have is that the button is supposed to change the color I want the LED to display (presses one time: red (pin9), again green (pin10), again blue (pin11)). As I'm changing through the ports with the potentiometer, the potentiometer will read it with as analogWrite. For example, if I move the potentiometer all the way to the left and press the button the LED will display red and move it back all the way to 0 and press the button twice the LED will stay red (do nothing). If I press it one more time it will turn off. Another example, I turn on red again, then use green and turn off blue using the potentiometer and button giving me orange. How do I make it so to accomplish all of this while using both and combining colors?

**THIS IS A HW QUESTION AND NOT ASKING FOR A WHOLE SOLUTION BUT RATHER WHERE TO START BECAUSE I ALREADY GOT STUCK AND WANT TO RESTART PER SE**

Edit:I solved my doubt! Thanks for the help!

body:
You method sound a bit more complicated that it needs to. What I would do is have the button switch between three colors, and have the potentiometer change the brightness of the currently selected color.

For example, when first starting up, the red led is selected. Turning the potentiometer changes the brightness of the red led (in real time). Let's say you turn it 50%, so the red led is at 50% brightness. When you're happy with that, you press the button, and now green is selected. (Since the potentiometer is still at 50% from the red, the green led will immediately turn on at 50% brightness.) You can then turn the pot to change the brightness of the green led. Let's say you turn it all the way of to 0%. Then press the button to select the blue led. Turn it to 100% and the combined color would be a dark purple. Press the button again to select red again.

Here is some proof of concept code:

```lang-cpp

byte selectedColor = 0; // 0:red, 1:green, 2:blue
byte oldButtonState = HIGH;

void loop() {
  byte buttonState = digitalRead(buttonPin); // read the button
  if( buttonState==LOW && oldButtonState==HIGH ) // see if the button is pressed, but wasn't pressed the last time
  {
    selectedColor++; // to to next color
    if( selectedColor==3 )
      selectedColor = 0;// after blue, go back to red
  }
  oldButtonState = buttonState; // remember the buttons state for the next loop

  int brightness = map(analogRead(potPin), 0, 1023, 0, 255);

  if( selectedColor==0 )
    analogWrite(redPin, brightness);
  else if( selectedColor==0 )
    analogWrite(greenPin, brightness);
  else
    analogWrite(bluePin, brightness);
}
```

PS I left out the pinMode stuff in the `setup`.

PPS make sure the led leads are connected to PWM pin on the Arduino (they have a `~` next to them on the PCB).


message:
ATMega328 functions, but will not output to any pins

## Problem: ##
ATMega328 Refuses to digitalWrite() to any pins, I can upload and run sketches using the board UNO from the ide on the 328 and can confirm it is working using the serial monitor (see code).

I am using [this][1] FTDI module.

## Board Manager -- UNO works, but ATMega328 Doesn't ##
[![Tools Menu][2]][2]

**By using the UNO board under board manager, I am capable of writing sketches and communicating with the 328 just fine. <b>
But when I use the ATMega328 at 5.5V,16Mhz I receive the following error.**

             Using Port                    : COM3

             Using Programmer              : arduino

             Overriding Baud Rate          : 57600

    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xe0

    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe0

    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0

    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe0

    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00

    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0

    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe0

    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

    avrdude done.  Thank you.

## Code & Serial Monitor "Proving" it works ##
I have tried every usable PWM and other pins to attempt to output using LED's, buzzers and even other Arduino's to read inputs but none of the pins will output high when requested.

I believe that Arduino IDE is attempting to compile my code for the UNO and those pins do not work on the ATMega328 but this could be completely incorrect and someone please correct me if this is a wrong assumption.

Lastly, I have been able to use the SCL and SCA pins to communicate with an I2C LED shield.

Does anyone know why I cannot write sketch to the ATMega328 using the FTDI and my configuration.
Posted Below are images and very rough Fritzing schematics of how I am setup.

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

    void loop() {
      Serial.println("TICK");
      digitalWrite(5,HIGH);
      delay(1000);
      digitalWrite(5,LOW);
      }

[![serial monitor][3]][3]

## My Breadboard ##
[![ATMega328][4]][4]
## Fritzing Schematic ##
[![Fritzing Schematic][5]][5]

  [1]: https://www.amazon.com/gp/product/B00IJXZQ7C/ref=ppx_yo_dt_b_asin_title_o07_s00?ie=UTF8&psc=1
  [2]: https://i.stack.imgur.com/USeEe.png
  [3]: https://i.stack.imgur.com/9McVN.png
  [4]: https://i.stack.imgur.com/DhcLh.jpg
  [5]: https://i.stack.imgur.com/aiCew.png

body:
This may not be your only problem, but you need a second delay.

<!-- language: lang-c++ -->

    void loop() {
      Serial.println("TICK");
      digitalWrite(5,HIGH);
      delay(1000);
      digitalWrite(5,LOW);
      delay(1000);    // LOW for a second as well
      }

Otherwise you will not be able to see the LOW part, because it will be really quick.

---

> I believe that Arduino IDE is attempting to compile my code for the UNO and those pins do not work on the ATMega328

The Uno has an Atmega328 on it, and I usually compile for the Uno when uploading to a custom board, so this is not the issue.


body: How old is your chip, or the bootloader on it? Most chips sold (with bootloaders preloaded) - and bootloaders available to upload - for the last several years at least, have uploaded at 115200 baud.


body:
In combination with Nick Gammon's answer above, I was not aware that the physical pin numbers are different from the digital pin numbers used in the sketch. I resolved my issue by referring to this digital pin map.

[![Digital Pin Map][1]][1]

  [1]: https://i.stack.imgur.com/CVRUw.png


message:
Using ESP32 Cam internal RAM

I am new to the ESP32 series of boards.I powered up my ESP32 Cam board using the Vcc pin supplying about 7.4V using two 18650 batteries only to find out later that was a completely incorrect way to power up the board.

Now I cannot get my board to flash. I am guessing that the SPI SRAM on my board is burnt because when I measure the Vcc at the SPI SRAM chip it doesn't read 3.3V as its supposed to.

Also there is continuity between the ground and Vcc of the SPI SRAM chip. And it heats up excessively when powered up using 5V.

However I read in the documents that the ESP32 has a few bytes of internal RAM in it.

I was planning to use the ESP32 Cam as an IP Camera for one of my projects.
I want to know if its possible to desolder the SPI SRAM chip (IPS1704) and somehow use the internal ram to get my job done or else if I have to buy a new board.

Thanks in advance

body:
If there is continuity between 3.3V and GND your board is dead. Most likely (from my experience) the ESD protection diode on the ESP module is fried which leaves you no chance to repair it. Even if you could remove the shielding to change the diode, you have no chance to find out which components are damaged. Considering the cost of the whole device, repairing it doesn't seem to be worth the effort.

For your understanding:
  - reading less than 3.3V on the external RAM means you would also read the same voltage at the ESP's Vcc. It's not an indicator for the RAM being dead
  - the ESP32 has plenty of internal ram (some hundreds of kB remain for use of your sketch after subtracting what the RTOS uses)
  - the ESP32 (**chip**) has no internal flash, so there is always an external flash on the ESP **module**
  - the ESPcam has an additional SPI RAM assembled **externaly to the module**. The internal RAM is by far too small to do any useful image processing at any desired resolution, so using only the internal RAM does not work


message:
Bluetooth module vs wireless module Arduino

My main question is, what is the main difference between HC-05 Bluetooth module and NRF24L0 wireless module?

Which should I buy?

Which makes these 2 modules different than each other?

Which one should I use in remote control arduino projects?

Which one is made for what purpose?

body:
NRF24L01+ module is a RF module and HC-05 is an Bluetooth module

It depends on the application you want to perform and what suits best for your application

nrf24l01+ is a great module but it can have issues if you want long distance communication also if you want to increase the distance then there is a module which comes with an antenna

On the other hand It seems that Hc-05 offers 10m range theoretically but according to one the arduino forum [link][1] its 15m when in line of sight but if there is some obstacle than it falls drastically

What is the distance you want to cover from the remote control it will specify which best suits you

  [1]: https://forum.arduino.cc/index.php?topic=236324.0


body:
> what is the main difference between HC-05 Bluetooth module and NRF24L0 wireless module?

The main difference is the protocol they use. While some attempts have been made with varying success to get the nRF24L01+ to emulate Bluetooth it is not designed for that. You can only really get rudimentary beacon mode working and that only partially.

nRF24L01+ modules can only communicate with other nRF24L01+ modules. They use their own proprietary protocol that is incompatible with any other system. That's not to say they're bad - they're great modules, and the same RF core and protocol is used in many many other devices by Nordic that are used all over the place - the most notable of which is wireless keyboards and mice.

The HC-05 though is a Bluetooth module which is designed to talk to anything else that also talks Bluetooth - such as your phone or computer. It presents an "SSP" profile and gives "master" mode operation to emulate a serial port connection between your Arduino and any other device that knows about Bluetooth and SSP.

The biggest difference in how they work though is when it comes to connecting devices together. Bluetooth devices have to be "paired" before they will communicate. nRF24L01+ devices don't. This means that getting Bluetooth devices to talk to each other takes a certain amount of time and effort, but nRF24L01+ devices are ready to go the moment they are powered on. It's then just down to your software to set up addresses and such to target the communication.

For Arduino-to-Arduino communication the nRF24L01+ is far less trouble as you set everything simply in your code. There are "LNA+PA" variant boards available that include an amplifier and antenna for longer range communication (I have had 300m+ out of those quite happily).

If you want to communicate with anything else, like your phone or computer, then you will want Bluetooth. Otherwise you will have to add an nRF24L01+ to your computer or phone through USB and (probably) another Arduino, which just gets messy.


message:
digitalwrite() HIGH for arduino

How too know whether digitalwrite(HIGH, pin_number) sets the voltage to 5 volts or 3.3 volts. I am yet to purchase arduino uno. I want digital pin voltage to be 5 volts. I am aware that thereis a pin already have 5 volts but I want to know only about the voltage output at digital pins.

Sorry if question is too silly. I am not very knowledgable in Electronics.

body: When you use `digitalWrite(pin_Number,HIGH);` this sets the output pin to 5 V but still if you want to check the voltage you can you a digital multi meter set its knob to DC voltage and connect its positive to the pin and the ground pin to ground and the voltage will be displayed on the multi meter


body:
Different boards operate internally at different voltages. This is dictated by the main chip on the board.  That main internal operating voltage is also the voltage at which the IO pins operate.

Most "old" Arduino boards operate at 5V.  This includes, but is not limited to:

* Arduino UNO
* Arduino Mini
* Arduino Leonardo

Newer more powerful boards, many made by other companies, operate at 3.3V. Again, this includes such boards as:

* Arduino DUE
* Arduino MKR1000
* Teensy boards (v3.0+)
* chipKIT boards
* ESP8266 & ESP32 boards

Some boards come in variants that give either voltage - the most notable being the Pro Mini boards from Sparkfun.  These come in both 5V and 3.3V variants and it is important to pick the right board for your needs.

In general, though:

* If it's 8-bit and runs on an ATMega chip it's likely 5V unless otherwise stated
* All 32-bit boards will be 3.3V unless otherwise stated.


message:
External RAM (23LC1024) and external Flash (W25Q64JVSSIQ) with Sparkfun SAMD21

i'm trying to extend the capabilities of the Sparkfun SAMD21. My question is, which pins do I have to share? I mean, I understand that MISO, MOSI and SCK are shared, but CS connects each to a different pin, am I correct?

My schematics:

[![Schematics][1]][1]

  [1]: https://i.stack.imgur.com/PvBRW.png

I connect my CS_RAM to the D10(PA18 on SAMD21).
and i connect my CS_FLASH to the D6(PA20 on SAMD21)

body: You are correct, MISO, MOSI and SCK are common to all the SPI devices. Be sure they are all set up for clock polarity etc. The CS\ line is the select line. If the device is not selected it does not matter what goes on with MISO, MOSI and SCK. There are chips such as the 74HC138 that will give you chip selects with just a few additional pins. 1 pin gives you 2 selects 2=4 and 3 gives you 8 selects.


message:
How to burn the bootloader and upload sketches on ATmega328P U (specifically this model)?

Recently I started to learn embedded electronics and C/C++ and for a couple of days I tried and I am still trying to burn a new ATMega328P U bought from Aliexpress. From what I know new ATMega328P's come with bootloader included, but after I wired everything up and connected the FTDI FT232RL to load the sketch (wiring is completely right after many many hours of checking on the internet for a dozen of pictures), I get errors like "programmer is not responding" in case of sketch upload and "error while burning the bootloader" or "Yikes, signature bla bla". I don't think the FTDI is the problem since the Arduino IDE recognizes it as COM7 on my PC. Now here's my question: is my atmega328p u broken or have I missed something during the process of both (trying to) burn(ing) the bootloader and upload(ing) the blink sketch? (I have also tried uploading the board programmer from Nick Gammon on my arduino Uno and the burning the bootloader AND followed the instructions from arduino.cc "from arduino to microcontroller on a breadboard"). If you need pictures of some sort, I'll provide them

body: IT WORKED, FINALLY. I followed this tutorial: https://www.electronics-lab.com/project/installing-the-arduino-bootloader-on-the-atmega328p-microcontroller/, followed exactly as it is explained, made the connections (nothing more, nothing less; I even removed the LED on pin 19 and its resistor) and to my surprise... the bootloader was actually loaded and the sketches were uploading just by using the FTDI. Thank you a lot for your help and information and I hope someday I'll pass this knowledge to someone who will be in the spot I was until now. Have a great time and love ya all


message:
Why does controlling power with a transistor interfere with MHZ19B's serial communication?

I've been trying to turn off an MHZ19B (datasheet and teardown photos: [revspace.nl/MH-Z19B][1]). I've used an Arduino, NPN, PNP transistors and mosfets as well as the diagram below for connecting the sensor to an ESP32. In all cases, PWM communication works great! I can power off the sensor, turn it back on, and values derived from PWM communication are as expected. However when I connect the Rx and Tx lines (to software serial Tx and Rx pins respectively on Uno pins A0 A1 or ESP32 pins 32 33) they spit out gibberish and the PWM signal also suffers hiccups.

Otherwise, without any kind of logic power control, the MHZ19B works great and can communicate with anything via UART, even my PC usb port via FTDI.

I added resistors to the Rx and Tx lines so the voltage on them doesn't exceed Vcc. I tried 1n4007 diodes (they're the only ones I have; no Schottky diodes either). I tried an NPN equivalent optocoupler. I also tried powering the sensor from my breadboard. I don't own an oscilloscope :(

My High School teacher said to just use PWM, but as I searched for a solution to this error, I noticed hundreds of others have this exact same problem with all sorts of different sensors and loads with ICs; no one has come up with a general solution.

I've been obsessing with this for weeks and if anyone can help or can recommend a book about sensor schematics I would really appreciate it. Thanks!
[![MHZ19B and ESP32 attempt at deep sleep][2]][2]

  [1]: https://revspace.nl/MH-Z19B
  [2]: https://i.stack.imgur.com/jFoQZ.png

body: Just guessing but I suggest you use a level translator. Also when you power off the sensor the serial output should go to ground disabling that channel.  Check your voltages and put a bypass cap on the transistor for the sensor. You can use a simple P channel Logic Level fet,only a 50 ohm resistor in the gate to prevent oscillation.  Your output will now be active low instead of active high. If you stay with transistors make R2 & R3 510 ohm so you have enough drive for the transistor and be sure it is NOT a darlington device, if it is you will not have enough voltage for the sensor.


body:
When troubleshooting a problem like this, try 'cutting the world in half' before doing anything else.  In this case, replace the entire circuit with a manual switch (or a wire) and manually power and de-power the sensor.  If you still have the problem, then the circuit is irrelevant to the solution.  If the problem goes away, then the circuit IS the problem.

Once this experiment has been performed, then 'cut the world in half' again, working on the 'half' that is the problem. Repeat until only one component is left.


message:
problems with Blue Pill (stm32f103c8t6) direct register manipulation

I'm trying to access registers but I keep getting the "was not declared in this scope" error message.
I'm currently using the STM32F1xx boards from http://dan.drown.org/stm32duino/package_STM32duino_index.json

The board package does not seam to recognize any of the registers from the reference manual, mostly trying to access the ADC registers such as 'ADC_CR2'. Does anyone know where I can find the register names which works in the Arduino IDE?

body:
you need to use something like this:

    ADC1->CR2 = ... ;
note 2 things:

 - you need to use `ADC1`, `ADC2` ... to access the registers. not just `ADC`.
 - you need to use arrow (->) operator to access the registers

and you may need to include the header file, something like this :

    #include <stm32f030x6.h>
find the proper header file for your MCU. (it's not the same as stm32f1xx, but if proper definitions are made somewhere, it may also work)


message:
Servo motor analog vs digital and AC vs DC

I am little confused with servo motor terminology.

Q1. AC servo motor requires AC power source ?
Q2. DC servo motor requires DC power source ?

If answer to above 2 questions are YES then what does analog servo motor means.

Q3. Can I use arduino uno to control analog RC servo motor ?

body:
> Q1. AC servo motor requires AC power source ? Q2. DC servo motor requires DC power source ?

Yes. It's all down to the kind of motor that is used in the servo - an AC synchronous motor (often with VFD), a small DC brushed motor (the most common RC type) or a brushless DC motor.

> Q3. Can I use arduino uno to control analog RC servo motor ?

Yes. That's precisely what the bundled `Servo.h` library is for. All the Arduino servo examples you will find online use analog RC servo motors.

The name "analog" though for those motors is not really 100% correct. They are driven by a PWM signal where the duty cycle is used to control the angle. The signal itself is 100% digital. The "analog" component comes in the form of the duty cycle of the signal.


message:
How to use ADC interrupt on STM32 blue pill

I'm currently using the STM32F1xx boards from http://dan.drown.org/stm32duino/package_STM32duino_index.json
To program my blue pill but I can’t find how to write the interrupt for the ADC. I’ve set the registers to output an interrupt when it finishes but I can’t find how to write the code for the interrupt.

I’ve tried the ”ISR(ADC_vect)” function which works for arduino, but the compiler is complaining that ”ISR” is not recognized. I’ve tried to look for the documentation for the STM32duino, but the little I could find didn’t even mention the ADC or any interrupt routines. I’ve searched though the STM32duino forum without any luck. If anyone knows how to solve this or where to find information about interrupt code for the STM32 boards I would be very happy :)

body:
first you need to enable the interrupt (I don't know if the stm32 wrapper for arduino does it or not):

    NVIC_EnableIRQ(ADC1_IRQn);

then you have to write ISR as gerben said:

    extern "C" void ADC1_IRQHandler()
    {
        //clear ADC flag
    }

`extern "C"` because [as far as I know] the arduino projects are C++.


body:
I couldn't find the function being called directly, but there's a good example explaining how to attach interrupts to the ADC which works well: https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F1/libraries/STM32ADC/examples/SingleConversionInterrupt/SingleConversionInterrupt.ino

If anyone knows the actual function being called directly that would be great to add on here, but until then this example does what I need and will hopefully help others having the same problem.


body:
As you already found, the function to override is `__irq_adc()` defined weakly [here][1] and bound to the interrupt vector table [here][2].

If you've defined it and it's not working, it's probably because you got rid of the `attachInterrupt()` call entirely, which does more than just assign an interrupt handler; it also enables the interrupt for that ADC. So:

    myADC.calibrate();
    myADC.setSampleRate(ADC_SMPR_1_5);
    adc_enable_irq(ADC1, ADC_EOC);
    myADC.setPins(&pin, 1);

    extern "C" void __irq_adc() {
    // handle the interrupt
    // make sure to check statuses and clear flags as shown in the default handler
    }

Not sure if the `extern "C"` will be needed, probably will be, you'll have to check and find out.

  [1]: https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F1/cores/maple/libmaple/adc_f1.c
  [2]: https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F1/cores/maple/libmaple/stm32f1/performance/vector_table.S


message:
Are breadboads available in EasyEDA?

So far I have been using TinkerCAD which has them but I am unable to find them on EasyEDA Library. Are connectors supposed to do the same thing? I get this empty rectangle in the EasyEDA library which I am unable to make sense of.

body:
EasyEDA is not designed for diy prototypes like TinkerCAD is.  EasyEDA's purpose is to simulate electronic circuits and design circuit boards for those circuit designs.  Because of this they don't have a breadboard object because there would be no point in having one, since you can just connect virtual wires in the schematic mode and wire traces in the board design mode.

Furthermore, it doesn't support simulating a full Arduino board with code.


message:
How to control baby swing?

I am starting an intresting DIY project of baby swing. My son is 3 month old and we have swing made with ropes in our house where he sleeps. I am looking for any electronic component controlled with arduino to swing it in controlled manner. I thought of servo motor but not sure how will it work. Any suggestions please ?

swing is similer to below

![enter image description here](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQxJJQRRn9jSZGtQgLkEXp0FxeivQYfkbtIug&usqp=CAU)

body: A simple DC motor would work. you have to pulse it in the right moment. for finding out the *right moment* and the pulse length (you don't want to push it so hard !) you need a simple accelerometer sensor to measure acceleration in specific axis.


message:
How do I recover a beetle where I loaded a program that was too large and overwrote the bootloader?

I'm doing on-target unit testing for an industrialized application and my test code is too large to fit everything on the board at the same time. I'm using the Sloeber toolset to develop, and I put something on the board that was over 28K, and the programming failed. Now the beetle does not show up as a serial port, and not even when pushing the reset pins, which I've had to do a number of times in the past.
If I overwrote the bootloader, which seems likely, is there a way to recover it? Do I need to reprogram the bootloader on a Beetle board? I haven't found any way to do that with a Beetle...

Thanks!

body:
I don't know the Sloeber toolset, but it seems very unlikely, that it really has overwritten the bootloader. When programming via USB, it is actually the bootloader, which writes the program into the flash memory. So that would mean, that the bootloader had overwritten itself, only because a too large program. Not sure, if this is even possible.

Anyway, you can utilize an ICSP/ISP programmer (or another Arduino, if you don't have one) to burn the bootloader onto the chip again. Google for Arduino ISP to get instructions for it, there are plenty of tutorials.

You need to connect the correct pins on the Beetle with the ISP programmer. According to [this site][1], you should find the ICSP pads at the back of the board (the group of 6 pins in 2 rows). Through these pins you can burn the bootloader.

If that doesn't work either, the problem lies somewhere else. As I already stated, overwriting the bootloader because a program is too big for the MCU should not happen and it is highly unlikely, that this is really your problem. You might have damaged something on your board, though we cannot tell that from the description. So you could just try to burn the bootloader and see what happens.

  [1]: https://wiki.dfrobot.com/Beetle_SKU_DFR0282


body:
Use double reset to activate the bootloader. The LED will pulse while it waits for upload.

The board doesn't show up on USB because USB is handled by the sketch on MCU with native USB. If the sketch doesn't run it doesn't handle the USB.

The bootloader is protected by fuses.

(This happen to me with Sloeber a few days ago.)


message:
Hand position sensor

What is the simplest way to get an alarm sound when a human raise hands up.
Assuming he is wearing a sensor or whatever as a watch or ring.

body:
A tilt sensor, can be used as what you are trying to say, whenever someone (who wore it) raise his hand or move it, will trigger an alarm.

If you want to carry your alarm with you then...
 You can use arduino nano or micro with a sensor and buzzer connected to it to just place it in gloves or watches etc.