body:
**Start button doesn't respond correctly, i can't figure out whats wrong with the code ? pls help**,

this code is for 24 second and 14 second countdown timers in a same unit

comes with three physical push buttons

1. start/pause
2. reset
3. shift (Arduino pin 8 as shift button)

both 1 and 2 uses arduino pin 2 and 3 for interrupts,
by pressing reset counter sets for 24 second timer and shift+reset will set the timer for 14 seconds and by pressing start button will start the countdown and press again will pause the timer,

to display it uses two seven segment displays with 74LS47 Binery code decoder

here is the code
```
//Declaring and Initializing Variables
int p4 = 4;
int p5 = 5;
int p6 = 6;
int p7 = 7;
int p9 = 9;
int p10 = 10;
int Buzzer = 12;
boolean Standby = true;
unsigned long newTime, oldTime = 0;
const long timeDelay = 1000;
volatile int Num1 = 0;
volatile int Num2 = 0;
volatile int Zero = 0;
volatile byte Press = 0;
volatile boolean Ready = false;
volatile boolean Shifter = false;
volatile int Shift = 8;

void setup() {
  pinMode(Shift, INPUT);//Shift pin button
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

  pinMode(9, OUTPUT);//FirstDigit
  pinMode(10, OUTPUT);//SecondDigit

  pinMode(12, OUTPUT);//Buzzer
  attachInterrupt(0, Starting, HIGH);
  attachInterrupt(1, ReStarting, RISING);
  digitalWrite(12, LOW); //Set it LOW first
}

void refresh() {
  SecondDigit();
  FirstDigit();
}

void Starting() {
  //Running and Stopping here
  if (Ready == false) {
    Press = 0;
  }

  Press++;
  if (Press >= 4) Press = 2;
} //End of Starting

void ReStarting() {
  //Restart sequence
  Zero = 0;
  if (Press == 0) {
    Num2 = 2;
    Num1 = 4;
    Ready = true;
    Press = 1;

  }

  if (digitalRead(Shift) == HIGH) Shifter = true;

  if (Shifter == false) {
    if (Zero == 3)Press = 1;
    Num1 = 4;
    Num2 = 2;
    Zero = 0;
    Ready = true;
    Press = Press;
  }
  else {
    if (Press == 2) {
      if ((Num1 + (Num2 * 10)) < 14) {
        Num1 = 4;
        Num2 = 1;
        Zero = 1;
        Ready = true;
        Press = 2;
      }
    }
    else {
      if (Press == 1 || Press == 3) {
        //Uncomment the next line to disable the 14 seconds reset if time is greater than 14 seconds
        if ((Num1 + (Num2 * 10)) < 14) {
          Num1 = 4;
          Num2 = 1;
          Zero = 1;
          Ready = true;
          Press = 1;
        }
      }
    }
  }
}//End of ReStarting

void Display() {
  if (Press == 2) {
    if (Zero <= 3) {
      Num1--;
      if (Num1 == 0)Zero++;
      if (Num1 == -1) {
        Num1 = 9;
        if (Num2 > 0)Num2--;

      }
    }
  }
  for (int Transition = 0; Transition < 500; Transition++) {
    FirstDigit();
    SecondDigit();
    if (Ready == true) {

      if (Zero == 3)BuzzMaker();
    }
  }
} //End of Display

void FirstDigit() {
  //Display 4 BCD digits of Number in First LED Segment
  digitalWrite(10, LOW);
  digitalWrite(9, HIGH);
  if (digitalRead(Shift) == HIGH) Shifter = true;
  digitalWrite(4, bitRead(Num1, 0));
  digitalWrite(5, bitRead(Num1, 1));
  digitalWrite(6, bitRead(Num1, 2));
  digitalWrite(7, bitRead(Num1, 3));
  delay(1);
  Shifter = false;
} //End of FirstDigit

void SecondDigit() {
  //Display 4 BCD digits of Number in Second LED Segment
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  if (digitalRead(Shift) == HIGH) Shifter = true;
  digitalWrite(4, bitRead(Num2, 0));
  digitalWrite(5, bitRead(Num2, 1));
  digitalWrite(6, bitRead(Num2, 2));
  digitalWrite(7, bitRead(Num2, 3));
  delay(1);
  Shifter = false;
} //End of SecondDigit

void BuzzMaker() {
  //Configuring Buzzer frequency and setting go with the counting numerals
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(12, HIGH);

  delay(1000);
  digitalWrite(12, LOW);
  delay(200);
  digitalWrite(12, HIGH);

  delay(500);
  digitalWrite(12, LOW);

  Press = 2;
  Zero = 0;
  Ready = true;
  Shifter = false;
}//End of BuzzMaker

void loop() {
  if (Press == 0)refresh;
  refresh();
  newTime = millis();
  if ((newTime - oldTime) >= timeDelay) {
    oldTime = newTime;

    if (Num2 == 0 && Num1 == 0 && Press == 2) {

      Press = 1;
    }

    //Here we are going to access each case with each different routine by case
    switch (Press) {

      case 0://Initial

        Display();
        break;

      case 1://Stop - Displaying 24 but still not yet running

        Display();
        break;

      case 2://Running

        Display();
        // PlayTime();
        break;

    }
  }//End of millis() condition

} //End of main loop function
```

title: 24/14 second countdown timer or shot clock for basket ball start/stop button doesn't respond well

Answers: 0


body: Can I program a GSM module to accept a specific type of Sim card to be ready by the module? If so please post something that can give me an Idea of how do it. Generally I want to lock the GSM module to accept a given brand of sim card to be detected in the Module but I do not know if its possible. I will be glad for any help offered by anyone on the platform. I will be glad for any help

title: Checking Specific Brand SIM card Type Available in GSM module

Answers: 0


body:
I am trying to implement a web server in ESP8266 that will handle simple HTTP GET requests by initiating an operation (e.g. move a stepper motor to the requested position) and return a response when the operation is finished (i.e. when the motor has reached the target position). This may take a few seconds, but during that time  the main loop should run normally so that both the TCP stack can work and the stepper library can actually move the motor (it works in the background). This means I cannot wait for the operation to complete within the handler. I have to start the operation in the handler, return without sending back a response and when the operation is done (i can poll for that in the main loop) then send the response.

I have been looking at https://github.com/me-no-dev/ESPAsyncWebServer but I'm not sure if such a scenario is supported. Has anynone done anything similar? Is it even possible?

One solution I was thinking was to store the request in a global variable (or queue) before exiting the handler and use it when the operation finishes. But will the request survive outside of the handler? And is it even possible to send the response outside the handler?

title: Delayed response from web server

Answers: 0


body:
I have recently purchased an Arduino Nano from the main site, but it did not come with a USB cable for programming it. I have also checked out the Arduino site and there was no reference for what type of cable I needed. I saw that there was a USB 2.0 CABLE TYPE A/B on the site but I'm not sure that it is the one that I require.

Does anyone know which cable I should buy? Thank you in advance!

Edit: To clarify, I checked out the Arduino Store https://store.arduino.cc/usa/

title: What kind of USB cable do I need for my Arduino NANO 33 BLE W/ HEADERS?

Answers: 0


body:
I'm currently getting started with Arduino, so I do not have very much knowledge.
In this project I have a receiver and a transmitter with 2 buttons.
So, I'd like to switch something to on, when I press the A button. If A is pressed longer I'd like something else to happen.
Same thing goes on with the B button, but for some reasons, when I long press A, then B gets triggered and I have no clue why...

Btw. this code is not purely made by me, but copied and edited for my use.
If anyone could help me I'd be very happy :)

code:

    //ButtonAEvents

    long prevA = 0;
    long prevB = 0;
    int buttonStateA = 0; // 0 = not pressed   --- 1 = long pressed --- 2 short pressed
    int buttonStateB = 0; // 0 = not pressed   --- 1 = long pressed --- 2 short pressed
    int ButtonAPin = 2;
    int ButtonBPin = 3;
    int DURATION_A_IN_MILLIS = 1000;
    int DURATION_B_IN_MILLIS = 1000;

    //ONE TIME SETUP

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

    //LOOP BEGIN

    void loop()
    {

        //BUTTON A CHECK
        buttonStateA = 0;
        if (digitalRead(ButtonAPin)) {
            prevA = millis();
            buttonStateA = 1;
            while ((millis() - prevA) <= DURATION_A_IN_MILLIS) {
                if (!(digitalRead(ButtonAPin))) {
                    buttonStateA = 2;
                    break;
                }
            }
        }

        if (!buttonStateA) {
            // Nothin pressed
        }
        else if (buttonStateA == 1) {
            //LONG PRESS

            Serial.println("LongpressA");
            digitalWrite(A1, HIGH);
            delay(100);
        }
        else if (buttonStateA == 2) {
            //SHORT PRESS
            digitalWrite(A1, HIGH);
            Serial.println("ShortpressA");
            delay(100);
        }

        //BUTTON B CHECK
        buttonStateB = 0;
        if (digitalRead(ButtonBPin)) {
            prevB = millis();
            buttonStateB = 1;
            while ((millis() - prevB) <= DURATION_B_IN_MILLIS) {
                if (!(digitalRead(ButtonBPin))) {
                    buttonStateB = 2;
                    break;
                }
            }
        }

        if (!buttonStateB) {
            // Nothin pressed
        }
        else if (buttonStateB == 1) {
            //SHORT PRESS

            Serial.println("LongpressB");
            delay(100);
        }
        else if (buttonStateB == 2) {
            //LONG PRESS
            digitalWrite(A1, LOW);
            Serial.println("ShortpressB");
            delay(100);
        }
    }

title: Weird Arduino Code Problem

Answers: 1

body:
Not sure if this is just an academic exercise on your part to learn (which is totally cool), but if you're just trying to move forward and get something working you may consider one of the many excellent button libraries out there for Arduino.

I recently used a library called [ButtonKing][1] that allowed me to do some very sophisticated menu interactions on a MKR1010 with a display and single button interface.  There are several other libraries out there as well that take care of debouncing, long clicks, double clicks, etc.

  [1]: https://github.com/TanPitch/ButtonKing


body:
I have already made a diagram using a motor controller. I want to use only one power supply to feed arduino and motors. I want to use MDD10 dual motor driver.

The details of the actuators each one is:

Input voltage: 12VDC,
Max Load: 750N(168.607lbs),
Stroke Length: 16 inch,
Travel Speed: 12mm/s,
Duty Cyle: 25%,
Current: 5A.

The power supply is 12V, 10A.

Could you please check if it is ok, or which would be the best solution?

Some of my concerns are:

Be sure if the feed of 12 volts for the motors, and 5 volts for Arduino are correct and can live together as shown.

Be sure if the wiring for the Arduino, driver and motors is correct since it looks kind of simple.
[![enter image description here][1]][1]
I want to know if this is the natural approach by doing it with a voltage regulator to feed the Arduino and with 12V 10A power supply to feed the motors, or if there are other, better options to make the circuit feed only using one power supply (12V, 10A).

MDD10 Datasheet Link: https://www.robotshop.com/media/files/content/c/cyt/pdf/cytron-10a-7-30v-dual-channel-dc-motor-driver-shield-datasheet.pdf

Thanks in advance

**UPDATE**

I have increased power supply to 13A, also changed the linear voltage regulator (7805) to a switching voltage regulator (OKI-78SR-5), what do you think about this approach?
[![enter image description here][2]][2]
Or I should try with the 12V DC Vin of Arduino(I understand that it works with a linear voltage regulator)? Being this option, it could be maybe with a voltage pre-regulation stage(for example from 12V to 9V) or maybe connecting directly to the jack.
[![enter image description here][3]][3]
Thanks, Best Regards.

  [1]: https://i.stack.imgur.com/NWAj9.png
  [2]: https://i.stack.imgur.com/7SEjM.png
  [3]: https://i.stack.imgur.com/RocBT.png

title: Feeding microcontroller and linear actuators (motors) with the same power supply

Answers: 2

body:
Your approach looks reasonable, but you don't have enough power. The motors will draw 10A, which is the full output of your power supply/battery. That doesn't leave any left over for your Arduino system.

You should have a high enough capacity power supply/battery for your total peak power requirement plus a little margin (say 10%-20%) The Arduino and all the other electronics on it might draw another 1/2 amp, so 10.5 total. Add 20% margin to that and you get 10.5 * 1.2, or about 12.6 A.

(When you drive a power supply up to its upper limit its output voltage can start to sag. By having a buffer it doesn't have to work as hard.)

One advantage you have in your circuit is that you're feeding unregulated 12V to your motors, and then feeding 12 into your Arduino's voltage regulator. That way even if the 12V supply droops to 10V under maximum load, the voltage regulator will still be able to maintain a clean 5V supply to your MCU.

Also note that you could feed 12V into the Arduino's V in and use its built-in voltage regulator. As long as don't draw a lot of current out of its 5V line the built-in regulator could manage the 5V voltage regulation itself. If you need ≥500 mA, though, you might want to use an external buck converter (or a high capacity linear regulator with a good heat sink.)

body:
First of all I would look to see if the two motors will actually run at the same time.
If not then the 10A power supply, is fine.
If they do run together, for how long? (you mention 25% duty cycle), power supplies usually have a over capability for a short period of time, and batteries will supply more current but at a slightly reduced voltage, so if going slightly slower isn't an issue then this would be fine.
Then there is the question of do they really use all 5Amps, I very much suspect not, unless you are fully loading the actuator(750N), they prob run at 2-3 amps at most.
Secondly
Circuit protection, fuses or thermal shutdown links for the motors is required, better still instant overcurrent protection for them set at 1.2x nominal current.
Do some worst case tests and measure the current, set the protection to 1.2 x this.
Remember if there is an issue the supply voltage will start to drop, its now that the micro will suffer if the voltage dips too much and you have no protection/sensing.

So suspect the power supply is more than ok.


body:
I was trying to setup a web server with Arduino and ESP32, without using the ESP32 libraries.
Currently I'm able to display a webpage(a form with single submit button) from the server, with only using AT commands.

But how can I receive GET/POST requests send buy the form fields?

In the [WebServer.h][1] library this is done by the method

        server.on("/actionPage", HTTP_GET, []() {
            server.sendHeader("Connection", "close");
            server.send(200, "text/html", "This is actionPage");
        })
I was wondering if there is a way to do this without libraries, I searched a lot, but didn't found a solution for this..

Thanks in advance!

  [1]: https://github.com/espressif/arduino-esp32/blob/master/libraries/WebServer/src/WebServer.h

title: How to implement server.on() without any libraries?

Answers: 0


body:
i am a beginner.
About my problem, there is an "invalid conversion' error in the swap(goal_positionall)

    #include <DynamixelWorkbench.h>

    #define Device_Name ""
    #define BAUDRATE 57600
    #define DXL_ID_1  1
    #define DXL_ID_2  2
    #define DXL_ID_3  3
    #define DXL_ID_4  4
    #define DXL_ID_5  5
    DynamixelWorkbench dxl_wb;

    int32_t goal_positionall[3][5] ={{0, 1024, 2048, 3072, 4080},
                                     {0,1000,0,3000,0},
                                     {1000,1000,500,700,2048}};

    const uint8_t handler_index = 0;

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

          const char *log;
          bool result = false;

          uint16_t model_number = 0;
          uint8_t dxl_id[5] = {DXL_ID_1, DXL_ID_2, DXL_ID_3, DXL_ID_4,DXL_ID_5};

          result = dxl_wb.init(Device_Name, BAUDRATE, &log); //To initialize the
    motor
          if (result == false)
          {
            Serial.println(log);
            Serial.println("Failed to init");
          }
          else
          {
            Serial.print("Succeeded to init : ");
            Serial.println(BAUDRATE);
          }

          for (int X = 0; X < 5; X++) //To do the actions 5 time
          {
            result = dxl_wb.ping(dxl_id[X], &model_number, &log); //Ping the 5 motors
            if (result == false)
            {
              Serial.println(log);
              Serial.println("Failed to ping");
            }
            else
            {
              Serial.println("Succeeded to ping");
              Serial.print("id : ");
              Serial.print(dxl_id[X]);
              Serial.print(" model_number : ");
              Serial.println(model_number);
            }

            result = dxl_wb.jointMode(dxl_id[X], 0, 0, &log);  //Change joint mode for 5 motors
            if (result == false)
            {
              Serial.println(log);
              Serial.println("Failed to change joint mode");
            }
            else
            {
              Serial.println("Succeed to change joint mode");
            }
          }

          result = dxl_wb.addSyncWriteHandler(dxl_id[0], "Goal_Position", &log); //Add Sync write handler
          if (result == false)
          {
            Serial.println(log);
            Serial.println("Failed to add sync write handler");
          }

        }

        void loop()
        {
          const char *log;
          bool result = false;

          result = dxl_wb.syncWrite(handler_index, &goal_positionall[0][0], &log);
          if (result == false)
          {
            Serial.println(log);
            Serial.println("Failed to sync write position");
          }

          delay(1000);

          swap(goal_positionall);
        }

    void swap (  int32_t **array[][5] )
        {
          int32_t tmp = array[0][5];
          array[0][5] = array[1][5];
          array[1][5] = array[2][5];
          array[2][5] = tmp;

        }

title: How to use void swap with multi-dimensional array to control motor with openCR board

Answers: 0


body:
If I want to add two numbers and print the output on LCD

    char answer[8];
    float a=5.1,b=3.2,c;
    c=a+b;
     dtostrf(c,8,3,answer);//convert float to ASCII to print it on LCD
    for(i=0;i<8;i++) Lcd8_Write_Char(answer[i]);

What is the required memory space to execute this program?

title: about required memory size in ATmega32 to execute a certain program

Answers: 0


body: I want to make an Ardunio based project in which I want to stream live video from camera (which is connected to Arduino borad ) to my Android app via WiFi and send back actions/control signals from my android app to Arduino to controller servo motor which are connected to Arduino board. Right now I only have Arduino mega with me. What else components are going to be required?

title: Stream video from camera to mobile and send control signal back from mobile to Arduino via WiFi

Answers: 1

body:
You need good MPU with enough buffer size and nand size for such an intense process

Search esp modules

Thanks.


body: I have an NS-RAW CPGPS and I am trying to get GPS Data using an arduino. Do I just use the serial to get the data out of it and just convert and extract the data to what I need?

title: Trying to get pseudorange data out of NS-RAW GPS

Answers: 0


body:
I would like to add leds to each button switch in the first code, The first code sends midi messages to a DAW I would like it to also turn on a led as an indicator light. The switch needs to turn the light on if off and off if on. The second code is an example that does this, it works well with one button. I would like to have the 3 buttons on pins 0, 1, 2 and the leds on pins 3, 4, and 5.
<!-- language-all: lang-cpp -->

    #include <Bounce.h>

    const int channel = 1;
    Bounce button0 = Bounce(0, 5);
    Bounce button1 = Bounce(1, 5);
    Bounce button2 = Bounce(2, 5);

    void setup() {
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
    }
    void loop() {
      button0.update();
      button1.update();
      button2.update();

      if (button0.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      if (button2.fallingEdge()) {
        usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4
      }

      if (button0.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);// 60 = C4
      }
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
      }
      if (button2.risingEdge()) {
        usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4
      }
      while (usbMIDI.read()) {
      }
    }

Second sketch:

    /*********************
    Simple toggle switch
    Created by: P.Agiakatsikas
    *********************/

    int button = 0;
    int led = 13;
    int status = false;

    void setup(){
      pinMode(led, OUTPUT);
      pinMode(button, INPUT_PULLUP); // set the internal pull up resistor, unpressed button is HIGH
    }

    void loop(){
    //a) if the button is not pressed the false status is reversed by !status and the LED turns on
    //b) if the button is pressed the true status is reveresed by !status and the LED turns off

    if (digitalRead(button) == true) {
      status = !status;
      digitalWrite(led, status);
    } while(digitalRead(button) == true);
      delay(50); // keeps a small delay
    }

title: How to add indicator lights to button sketch

Answers: 1

body:
I'd suggest creating an array of MIDI button structs. For each entry you'd have a button object, an LED pin, and a BOOL to track the state of thate button.

Write a function that loops through the array of structs, checks the state of each one, and does the work to play/stop the notes and toggle the LED states based on the state of each button.


body:
How do I use the Arduino IDE to upload the last compiled code? I don't want to have to wait 2 minutes to upload compiled code when there are no changes. It's a big codebase where I frequently make one or two small changes and have some issue with my MCU or USB cables. Frequently the controller on my boards are damaged due to some overcurrent issue because of the high-heat nature of **3d printing**. So having to wait an extra 2-5 minutes every time I experiment with this unacceptable.

 Obviously, there is a keyboard shortcut to do this that I'm unaware of. Because otherwise this would add hours to development.

Please tell me how I can get Arduino-IDE to just 'upload without compiling' my sketch.

title: How to upload already compiled code when no changes were made?

Answers: 2

body:
You can upload hex file to your board from command line without Arduino IDE.

To get the hex file, use in Arduino IDE in menu the command "Export compiled binary". It will save the hex file next to the ino file.

I assume your board in printer has AVR MCU. Then you can use avrdude from command line to upload the hex file again and again without any compilation.

The avrdude command on Windows is (if started from the sketch's folder):

    %LOCALAPPDATA%\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -C%LOCALAPPDATA%\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -PCOM11 -b115200 -D -Uflash:w:Blink.ino.hex:i

The command line is for the Blink sketch and for AVC boards package 1.6.21

body:
This is what I have done.  In the arduino IDE settings panel, turn on the "Show verbose output during compile and upload". This way whenever you are doing verify and upload you can see all the command that Arduino has performed. Now after you hit Verify or Upload it, you can copy the last command before the upload, such as

"/Users/fang/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" "-C/Users/fang/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega32u4 -cavr109 "-P/dev/cu.usbmodem21101" -b57600 -D "-Uflash:w:/private/var/folders/xb/4609zdjx4tn3bv_6jh2nym_r0000gn/T/arduino/sketches/7972D54945A751059BF3114D2057C2B6/sketch_aug4c.ino.hex:i"

Now, when you need to upload without compiling again, just paste this line to the Terminal, it'll do the rest for you. Essentially you can see Arduino IDE is just a wrapper around these commands.

**Update:**

I also found another way which is kinda of different but more effective. If you happen to use Visual Studio Code, you can also try the PlatformIO plugin which can compile and upload code separately, I wrote an article about it here, https://windmaomao.medium.com/use-platformio-to-write-arduino-code-3c957c4e58b5


body:
I'm new to Arduino but I'm an experienced programmer. I'm wondering if there are any common functions for reporting errors in Arduino programs? For example, in JavaScript we have the alert() function, or on Unix you can write a message to standard error and exit.

Ideally, if the serial port is available then an error message would be printed there, or if there is an LED then maybe we should blink it. This would need to be configurable based on what the programmer wants to do with available hardware.

Looking the example sketches, error reporting seems pretty horrible. I'm wondering if any libraries handle this better?

title: Are there any standard ways of reporting a runtime error?

Answers: 1

body:
As pointed out by Majenko in a comment, you can hardly define a standard
facility for error reporting when you don't know what kind of I/O
hardware will be available on any particular project. Printing to the
serial port is the most common method though, as it tends to always be
available during the development phase, while the Arduino is tethered to
the development computer. I personally tend to just do something like
```c++
Serial.println(F("Error: the warp field coil is busted."));
```
and be consistent with the error prefix, so that a program receiving
this can tell it's an error by matching the line against `/^Error: /`.

While it is OK for user code, reporting errors through `Serial` is
certainly _not_ a good practice for library code. Alas, it is done way
too often in Arduino libraries. I've seen at least one library (don't
remember which one) that allows the user to provide a reference to a
`Print` object (defaulting to `Serial`) to be used for this purpose.
This is way better, as it allows the user to handle the error messages
any way she chooses. It is also very easy to turn off the error
reporting altogether by implementing a do-nothing `Print`, which would
be a `/dev/null` of sorts.

Note that the avr-libc [allows you to print to `stderr`][stdio], as long
as you have first implemented `stderr->put`... While this method is the
closest you can get to the standards you are used to, it may not be
portable to non-AVR Arduinos. And it is worth noting that we tend to
avoid the `printf()` family of functions on Arduinos, as they tend to be
quite large compared to the `print()` and `println()` methods.

[stdio]: https://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html


body:
I have connected an arduino serial port to my PC and monitoring the output in realterm. I am trying to print:
CR
11.98,123,3520,01CRLF

But it is resulting with some delay. First
CR
1
Is printed. After sometime, say 0.25sec, the rest of the data (1.98,123,3520,01CRLF) is received. Finally its shown like
CR
11.98,123,3520,01CRLF

Why is there a delay between CR1 and the rest of the characters when printing using a single serial print!?

Serial.print("\r11.98," +string1+","+string2+",01"\r\n);

string1 & string2 hold data values from 2 separate sensors.

title: Serial data printing slowly

Answers: 0


body:
In PlatformIO while creating a project , in the board selection there is no ESP-12F in the boards. While there is ESP-12E. I can flash ESP-12F while choosing ESP-12E from the boards without any flashing issue. But there are some runtime issues, the one that I noticed is the LED doesn't blink when flashed from PlatformIO , but works fine, when flashed using Arduino IDE using the same code.
So there may be some difference in the configurations.

> C:\Users\USER\\.platformio\platforms\espressif8266\boards

In this directory I found the esp-12e board which is a JSON format.

    {
      "build": {
        "core": "esp8266",
        "extra_flags": "-DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_ESP12",
        "f_cpu": "80000000L",
        "f_flash": "40000000L",
        "flash_mode": "dio",
        "ldscript": "eagle.flash.4m1m.ld",
        "mcu": "esp8266",
        "variant": "nodemcu"
      },
      "connectivity": [
        "wifi"
      ],
      "frameworks": [
        "arduino",
        "simba",
        "esp8266-rtos-sdk",
        "esp8266-nonos-sdk"
      ],
      "name": "Espressif ESP8266 ESP-12E",
      "upload": {
        "maximum_ram_size": 81920,
        "maximum_size": 4194304,
        "require_upload_port": true,
        "resetmethod": "nodemcu",
        "speed": 115200
      },
      "url": "http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family",
      "vendor": "Espressif"
    }

How do I add ESP-12F to the PlatformIO boards and flashing without any issue.

title: How do I use PlatformIO to flash ESP-12F (ESP8266MOD)

Answers: 1

body:
At the PlatformIO community I asked the same question, and [pfeerick ](https://community.platformio.org/u/pfeerick) suggested to add a build flag.

> It’s most likely the onboard LED is on GPIO2, not GPIO1 so try adding
>
> **build_flags = -D LED_BUILTIN=2** to your **platformio.ini** … hopefully that
> kicks in before the **pins_arduino.h** defintion.

But It didn't did the trick.
And the compiler throws a bunch of warnings.
What I did to make it work is to ignore **LED_BUILTIN** constant and use 2 instead.

    #include <Arduino.h>
    void setup() {
     pinMode(2, OUTPUT);
    }

    void loop()
    {
      digitalWrite(2,LOW);
      delay(200);
      digitalWrite(2,HIGH);
      delay(200);
    }


body:
The program is supposed to take photo and store the picture into the SD card with the timestamp.

My Program Code:
<!-- language-all: lang-cpp -->

    #include <SdFat.h>
    #include <Adafruit_VC0706.h>
    #include <SPI.h>
    #include<JPEGDecoder.h>
    #include <SoftwareSerial.h>
    #include <RTClib.h>
    #include <Wire.h>
    #include <SD.h>

    #define SD_CS D8    //For NodeMCU Kit Set version 1
    #define DS3231_ADDRESS  0x68  ///< I2C address for DS3231

    SoftwareSerial mySerial (D4, D3); //D4-RX, D3 TX For NodeMCU Kit Set version 1
    Adafruit_VC0706 cam = Adafruit_VC0706(&mySerial);
    File myFile;  // test file
    RTC_DS3231 RTC;  // define the Real Time Clock object

    char timestamp[30];
    char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    void setup()
    {
      pinMode(SD_CS, OUTPUT);

      Serial.begin(115200);
      Wire.begin ( D1, D2); //D1=SDA D2=SCL
      if (!SD.begin(SD_CS))
      {
        Serial.println("SD card is not inserted");
        return;
      }

      Serial.println("SD Card Present");

      // Try to locate the camera
      if (cam.begin()) {
        Serial.println("Camera Found:");
      } else {
        Serial.println("No camera found?");
        return;
      }

      if (!RTC.begin()) {
        Serial.println("RTC failed");
        while (1);
      }

      snapshot();
      //  ESP.deepSleep(0);  //deep sleep mode until RESET pin is connected to a LOW signal
    }

    void loop() {

    }
    //------------------------------------------------------------------------------
    void snapshot() {
      // Set the picture size - you can choose one of 640x480, 320x240 or 160x120

      cam.setImageSize(VC0706_320x240);        // medium

      //cam.setImageSize(VC0706_160x120);          // small

      // You can read the size back from the camera (optional, but maybe useful?)
      uint8_t imgsize = cam.getImageSize();
      Serial.print("Image size: ");
      Serial.println(imgsize);
      // Serial.println("640x480");
      Serial.println("320x240");
      // Serial.println("160x120");

      Serial.println("Snap");
      delay(2500);

      if (!cam.takePicture())
      {
        Serial.println("Failed to snap!");
      }
      else
      {
        Serial.println("Picture taken!");
      }
      // Create an image with the name IMGxxxx.JPG
      char filename[13];
      strcpy(filename, "IMG0001.JPG");
      for (int i = 1; i < 10000; i++) {
        filename[3] = '0' + i / 1000;
        filename[4] = '0' + i % 1000 / 10;
        filename[5] = '0' + i % 100 / 10;
        filename[6] = '0' + i % 10;
        // create if does not exist, do not open existing, write, sync after write
        if (! SD.exists(filename)) {
          break;
        }

      }
      // Open the file for writing
      File imgFile = SD.open(filename, FILE_WRITE);
      SdFile::dateTimeCallback(dateTime); //Timestamp for file
      // Get the size of the image (frame) taken
      uint16_t jpglen = cam.frameLength();
      Serial.print("Storing ");
      Serial.print(jpglen, DEC);
      Serial.print(" byte image.");

      int32_t time = millis();
      //pinMode(D8, OUTPUT);
      byte wCount = 0; // For counting # of writes
      while (jpglen > 0) {
        // read 32 bytes at a time;
        uint8_t *buffer;
        uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
        buffer = cam.readPicture(bytesToRead);
        imgFile.write(buffer, bytesToRead);
        if (++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up
          Serial.print('.');
          wCount = 0;
        }
        //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
        jpglen -= bytesToRead;
      }
      imgFile.close();

      time = millis() - time;
      Serial.println("done!");
      Serial.print(time); Serial.println(" ms elapsed");
      Serial.println("Storing Time in Textfile");
      myFile = SD.open("DATES.txt", FILE_WRITE);
      DateTime now = RTC.now();
      myFile.print(filename);
      myFile.print(' ');
      myFile.print(now.year(), DEC);
      myFile.print('/');
      myFile.print(now.month(), DEC);
      myFile.print('/');
      myFile.print(now.day(), DEC);
      myFile.print(" (");
      myFile.print(daysOfTheWeek[now.dayOfTheWeek()]);
      myFile.print(") ");
      myFile.print(now.hour(), DEC);
      myFile.print(':');
      myFile.print(now.minute(), DEC);
      myFile.print(':');
      myFile.print(now.second(), DEC);
      myFile.println();
      myFile.close();
      Serial.println("Done");
    }
    //------------------------------------------------------------------------------
    // call back for file timestamps
    void dateTime(uint16_t* date, uint16_t* time) {
      DateTime now = RTC.now();
      sprintf(timestamp, "d:d:d -/-/- \n", now.hour(), now.minute(), now.second(), now.month(), now.day(), now.year() - 2000);
      // return date using FAT_DATE macro to format fields
      *date = FAT_DATE(now.year(), now.month(), now.day());

      // return time using FAT_TIME macro to format fields
      *time = FAT_TIME(now.hour(), now.minute(), now.second());
    }
    //------------------------------------------------------------------------------

The error message is too long so I can only copy paste some parts which I think might be relevant:

        In file included from C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SD\src/SD.h:25:0,

                         from C:\Users\ACER\Documents\Arduino\libraries\JPEGDecoder-master\src/JPEGDecoder.h:56,

                         from C:\Users\ACER\Desktop\Arduino IDE\Snapshot NodeMCU with RTC\Snapshot_NodeMCU___RTC\Snapshot_NodeMCU___RTC.ino:4:

        C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:190:5: error: 'sdfat' does not name a type

             sdfat::SdFat* getFs()

             ^

        C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:215:5: error: 'sdfat' does not name a type

             sdfat::SdFat _fs;

             ^

        C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h: In member function 'virtual bool sdfs::SDFSImpl::exists(const char*)':

        C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:98:27: error: '_fs' was not declared in this scope

                 return _mounted ? _fs.exists(path) : false;

                                   ^

        C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h: In member function 'virtual bool sdfs::SDFSImpl::rename(const char*, const char*)':

        C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:104:27: error: '_fs' was not declared in this scope

                 return _mounted ? _fs.rename(pathFrom, pathTo) : false;

                                   ^

        C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h: In member function 'virtual bool sdfs::SDFSImpl::info(fs::FSInfo&)':

        C:\Users\ACER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SDFS\src/SDFS.h:113:26: error: '_fs' was not declared in this scope

                 info.blockSize = _fs.vol()->blocksPerCluster() * 512;

    reference to 'File' is ambiguous

        //There are a lot of '???' not declared in this scope and 'sdfat' does not name a type error.

At first, there was a different error that states that SdFile::dateTimeCallback(dateTime); is not declared. After doing some research online, I tried to install SdFat library [here][1] to see if it helps
and after installing I got more error as shown above.
How can I solve these errors?

  [1]: https://github.com/greiman/SdFat

title: reference to 'File' is ambiguous. Why am I getting this error?

Answers: 0


body:
    String getAPIData()
    {
      char res_buffer[450];
      int numdata = inet.httpGET("myserver.com", 80, "/call.php?id=1&q=1&code=1001", res_buffer, 450);
      String result = String(res_buffer);
      Serial.println(result);
      Serial.println(numdata);
      return result;
    }
Output on Serial:

    15:52:07.208 ->
    15:52:07.208 -> 393

But, When I print the buffer by loop I got the below output:

    HTTP/1.1 200 OK
    Date: Mon, 16 Sep 2019 06:28:59 GMT
    Server: Apache
    X-Powered-By: PHP/7.2.20
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate
    Pragma: no-cache
    Set-Cookie: PHPSESSID=5b21eeac22dcf61f2e4d2efd579d437c; path=/
    Upgrade: h2,h2c
    Connection: Upgrade, close
    Vary: Accept-Encoding,User-Agent
    Content-Type: text/html; charset=UTF-8

    -1
I am not sure why the char buffer is not converting to String in Arduino UNO.

Any known issues ? Please suggest if any correction required.

title: char buffer to String in Arduino UNO

Answers: 1

body:
Do not use String. And especially do not use String in the way you are using it.

You can read more about why not [here](https://majenko.co.uk/blog/evils-arduino-strings).

Instead stick to just using `char*` buffers.

The correct way of doing what you want is to define the buffer outside your function and then pass that buffer to the function to be populated:

    int getAPIData(char *buf, int maxlen) {
      return inet.httpGET("myserver.com", 80, "/call.php?id=1&q=1&code=1001", buf, maxlen);
    }

Then you call it with:

    char *my_buffer[450];
    getAPIData(my_buffer, 450);
    Serial.println(my_buffer);


body:
I am trying to collect data from the arduino into a SD card for the first time, so I bought the adapter at my local electronics/arduino shop. However, I could not find an explanation as to what each pin does, and the other adapters that I have seen online have different pins, so I am not sure what to do with the pins (except for the obvious ones, GND and VCC)
[![enter image description here][1]][1]

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

The order of pins is as follows:
CD, DO, GND, SCK, VCC, DI, CS.

Could you help me figure out what they mean and where to plug them into my arduino?

title: What do these pins mean? Where should I plug them in?

Answers: 4

body:
This is called the SPI interface (See [Serial Peripheral Interface, Wikipedia][1]. The pin names typically used for SPI are:

- GND : Power Ground
- VCC : Power input
- CS : Chipselect
- SCK/SCLK (SD-Clock): SPI Clock
- MOSI (SD-DI, DI) : SPI Master out Slave in
- MISO (SD-DO, DO) : SPI Master in Slave out
- CD: Card Detect (see comment of rollinger below (thanks).

  [1]: https://nl.wikipedia.org/wiki/Serial_Peripheral_Interface

On an Arduino Uno the SPI pins are:

- CS – digital 10; this can be in principle any pin
- SCK – digital 13
- MOSI – digital 11
- MISO – digital 12

body:
 - CS = Chip select
 - DI = Data In (MOSI)
 -      VCC
 -      SCK = Serial Clock
 -      GND
 -      DO = Data Out (MISO)
 -      CD (not sure what it stands for, but this pin isn't used when connecting to an Arduino. I think it's used for faster transfers.)

Note that SD card run at 3.3Volt, not 5V. Also the input pins of the SD can't handle 5Volt signals. So you need to convert the 5V signals coming out of the UNO to 3.3V before connecting to the SD card.

body:
CD could be one of two things:

a) a simple mechanical switch on the socket, usually used for Card Detect.  Measure from the pin to Gnd and see if contact is open/closed when a card is plugged in.

b) the fifth IO pin to a uSD card.  See the chart on the middle of this data sheet

https://www.molex.com/pdm_docs/sd/472192021_sd.pdf

You will see there are 4 data lines for parallel operation (Dat0, Dat1, Dat2, and CD/Dat3), and the Clock and Command (CMD) pin.   Arduino uses serial operation over the SPI bus tho, so in this case CD is likely card detect from what appears to be a mechanical lever switch at the bottom of the socket.

This drawing shows how the pins are used
http://www.dotmana.com/weblog/wp-content/uploads/izQKT.png

body:
Your question's been well answered, but I just wanna point out, when you get the library code that lets you access the SD card, there will probably be instructions on what pins to wire up where. That's nearly always the case. Particularly since this one uses the SPI pins.

There's also loads of instruction websites that would take you through it. The cheap Chinese stuff is nearly always copies of designs from the West, as seen on popular websites. So the instructions usually apply. Arduino is bloody great! Good luck in your adventure.


body: I updated and uploaded some code on another computer that got wiped and didn't send the new code to my current computer, the updated code is still on the board but I don't have access to it. How do I get it back?

title: How do I extract code from an arduino?

Answers: 3

body:
The short answer: You don't.

With enough know-how, you could probably extract the executable binary from the Arduino, but the source code is not installed on the device. You would need to run a decompiler on the binary. (Or read the machine code directly.) The output of a decompiler is usually pretty ugly however, and will look quite different from the original source-code. It won't have meaningful variable names, class names, or function names, and the code structure will likely be a little different than the original source code.

## EDIT:

As mckenzm pointed out in his answer, you could download the binary image from your Arduino, and then copy it onto another Arduino, but all that would let you do is to make an exact copy of the program. You wouldn't be able to modify it at all.

body:
You never can get the actual code back ... by reading the flash you might be able to get the executable/runtime code, but this doesn't look at all similar as your code, although it's functionally the same.

For example, all function names, all variable names will be just numbers (or non recognizable names), and all C statements are converted in machine language instructions, probably so many, you will need much knowledge to find out which instructions belong to which (original) C statements.

body:
  1. You read the contents of flash and save it to a file. It can then be re-flashed if your need is not to edit, but duplicate.

    * This reads all flash, including the bootloader, and also PROGMEM data.

  2. Use avr-objdump (or similar) to disassemble the instructions.

    * Again, PROGMEM data is going to be interpreted as opcodes, and may not be valid opcodes.

    * You may want to dump the fuses as well, for redirected vectors and such.

  3. Use pattern analysis to recognise source patterns as compiled. Then iteratively compile and compare fragments.

This is harder than is looks, whilst most Arduino code is very simple, the libraries can be be wild and woolly. At least the hex file is human readable, but little endian.

It might be easier to "walk through" the assembly and perform a translation of the perceived behaviour. OK for 10 instructions, but harder for 16K of them.

You will also need the Atmel/Microchip *def.inc files for the MPU component enumerations so that you know your DDRB from you DDRC a good disasembler should know.

You can do this well enough for Blink, and recognise stack pointer initialization.

It is much easier without a bootloader, as booting should jump to main and main can start at 0 other than after the vectors.

Of course lock bits will ruin your day, and it may just be better for character to code it again.


body:
Actually I'm trying to get the values from esp32 server webpage. Suppose there is a web page containing some text box fields, user has to enter some details in it and this details I want to be print on serial monitor.

And didn't get any solution regarding that. Though it is working with ESPAsyncWebServer.h library, that i found here -- > [https://randomnerdtutorials.com/esp32-esp8266-input-data-html-form/][1]

  [1]: https://randomnerdtutorials.com/esp32-esp8266-input-data-html-form/

but I want to do this task with webserver.h library, for some reason I don't want to use ESPAsyncWebServer.h library.. Hope you all guys can understand what I'm trying to ask and say. Thank You.

title: how to get text box values from webserver of esp32 and print them in to serial monitor by using <webserver.h> library

Answers: 0


body:
I have a 16GB SD card which is formated with FAT32. I'm trying to run the example codes presented for SD in Arduino. The SD card is inserted in the data logging shield and the CS pin in this shield is connected to pin 10.
I first tried the Cardinfo example and this is the result:
[![Serial Output of Cardinfo][1]][1]

The SD card is not empty, there exist a few files in it but this example was unable to show this files.
I then tried the example ReadWrite and the code freezes on line SD.begin(10).
I have no Idea where this problem is coming from.

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

title: SD card example freezes at line SD.begin() what should I do?

Answers: 2

body:
I had the same problem when I used a big SD card, maybe because some cards have a more modern format.

If you have smaller / older cards, try them and see if those work; than you rule out it is not a circuit/connection problem.

body:
I found another SD with 16GB capacity, and fortunately it worked. So the problem was because of the SD but I don't know what was the exact problem. I post the photo of this SD cards.

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

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


body:
I'm using pulseIn on an ESP32 for measuring a frequency between 500 Hz and 10 KHz. I measure both the HIGH and the LOW time, as all simple examples suggest. 95% of the time the result is correct, but sometimes pulseIn returns 0. It can happen on the HIGH or the LOW measure. I'm using GPIO27, which should not be a problem. On a digital scope the signal is very steady and clean.The code is very basic.
<!-- language-all: lang-cpp -->

    const int pulsePin = 27; // Input signal connected to Pin 12 of Arduino

    unsigned long Htime;
    unsigned long Ltime;
    unsigned long Ttime;
    float Frequency; // Calculated Frequency

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

    void loop() {
      Htime=pulseIn(pulsePin,HIGH);
      delay(10);
      Ltime=pulseIn(pulsePin,LOW);
      Ttime=Htime+Ltime;
      Serial.print(Htime);
      Serial.print(", ");
      Serial.println(Ltime);
      delay(100);
    }

The output looks like below:

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

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

Of course I can add code to ignore measurements with a 0 result, but any ideas on why they appear?

title: pulseIn on ESP32 return 0 regularly

Answers: 0


body:
I have been looking for over 2 hours now and just cant get it figured out. Im very confused as to how to do this. The solution I thought I found was to use HTTP POST. But I just cant get it to work. To be honest i'm guessing this should be very simple. Im using the variable

    sensorValue = analogRead(0);

And then want to sent that Variable to my Webserver with the ip 172.20.10.5

Then I wish to save this variable into an array on my Webserver. I am sorry for this request I of course looked at least on 20 diffrent sites and questions and cant find a solution.
<!-- language-all: lang-cpp -->

    #include <SPI.h>
    #include <Ethernet.h>
    #include "ESP8266WiFi.h"

    IPAddress server(172,20,10,5);
     if(client.connect(server, 80)) {
      client.println("POST /Raum1 HTTP/1.1");
      client.println("Host: 172.20.10.5");
      client.println("User-Agent: Arduino/1.0");
      client.println("Connection: close");
      client.print("Content-Length: ");
      client.println(sensorValue.length());
      client.println();
      client.println(sensorValue);
    }
    void setup(){
    Serial.begin(9600);                            // sets the serial port to 9600
      WiFi.begin("iPad von Tobias", "12345678");  //Connect to the WiFi network

      while (WiFi.status() != WL_CONNECTED) {  //Wait for connection

        delay(500);
        Serial.println("Waiting to connect…");

      }

      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());  //Print the local IP
     }

    //byte server[] = {172, 20, 10, 5}; //IP
    void loop(){
    sensorValue = analogRead(0);       // read analog input pin 0
    Serial.print("AirQuality=");
    Serial.print(sensorValue, DEC);               // prints the value read
    Serial.println(" PPM");
    delay(1000);

This is my current code on the ESP8266 I have the sensor on. The error im getting the most is: "client" has not been definied in this context.
I had the HTTP POST in the loop, out of the loop, in the setup, it just doesn't work. I tried diffrent methods to write the IPAddress which didnt help either. I also do not know how to then save that Data on the Webserver. They are connected over WIFI. Maybe the http way is completly wrong?. I can't find anything for this.

I would most likely have it look like this but this doenst work either.

    #include <SPI.h>
    #include <Ethernet.h>
    #include "ESP8266WiFi.h"
    int sensorValue;

    void setup(){
    Serial.begin(9600);                            // sets the serial port to 9600#
    WiFi.begin("iPad von Tobias", "12345678");  //Connect to the WiFi network

      while (WiFi.status() != WL_CONNECTED) {  //Wait for connection

        delay(500);
        Serial.println("Waiting to connect…");

      }

      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());  //Print the local IP
     }

     IPAddress server(172,20,10,5);
     client.connect(server, 80)
    void loop(){sensorValue = analogRead(0);       // read analog input pin 0
    Serial.print("AirQuality=");
    Serial.print(sensorValue, DEC);               // prints the value read
    Serial.println(" PPM");
    delay(1000);
      client.println("POST /Api/AddParking/3 HTTP/1.1");
      client.println("Host: 172.20.10.5");
      client.println("User-Agent: Arduino/1.0");
      client.println("Connection: close");
      client.print("Content-Length: ");
      client.println(sensorValue.length());
      client.println();
      client.println(sensorValue);
    }

Thank you for your help, I dont need a direct solution if you can point me to literatur that will help me solve this problem.

title: How do I send Sensor Data from one Arduino to another Arduino that is a Webserver to post it?

Answers: 1

body: If found that you can also use UDP to do what I want.


body: Is there way to wirelessly connect a arduino drone‘s camera and stream to a set device from 10 km away?

title: Is there way to wirelessly connect a arduino drone‘s camera?

Answers: 2

body: Most (commonly available) RF links' communication distance is more limited than that (10 Km). If your flying locations are within a cell service area, a cell radio aboard the drone will probably give you the most universally available connection. Note that your streaming rate may vary with the location and cell congestion at that particular time, and may sometimes be limited, especially for video.

body: You could try using the most common solution for streaming low latency drone video, called FPV. You basically connect an AV video output from a camera to a transmitter and use a receiver on the ground to receive the AV video. After this you can connect it to any AV display (or a usb AV decoder if you want to use a computer) and you'll get an almost real time video feed of what is happening on your drone. To get long range you would need to buy a powerful transmitter, good receiver and decent antennas for bout of them. You can find different configurations for different ranges online.


body:
I am trying DigiMouse library for attiny85 Digispark board.

It allows to emulate the mouse quite well.
However, I also need to know the current cursor position. Is there a way to get it?

title: Current mouse pointer position with Digispark attiny85

Answers: 1

body:
There is no way for a mouse of any kind (especially not one as minimal as DigiMouse.h) to know the current cursor position - USB just doesn't provide that kind of facility.

Instead you need to implement an "absolute" mouse (aka a "tablet").  However DigiMouse doesn't implement such a facility. So you would have to implement your own tablet driver.

A normal mouse sends a "delta" for the position. That is, a difference in position from whatever the current position is.  An absolute mouse, or tablet, sends the position on the screen as a proportion of some maximum set of dimensions.  Ideally that would be the same dimensions as your screen, but doesn't have to be.

The main differences between DigiMouse and whatever you would implement for a DigiTablet would be the "HID Report Descriptor". This defines what the data that is sent means and how the computer should interpret it.


body:
I am new to the Arduino world and it seems that this simple problem is keeping me at the start line.

- I use the Generic ESP8266 Module as Board
- In my sketch I just write:

<!-- language-all: lang-cpp -->

    #include < ESP8266WiFi.h >
    void setup(){}
    void loop(){}

The <b>ERROR</b> is :

BearSSLHelpers.h:148:34: error: 'virtual const unsigned char* BearSSL::HashSHA256::oid()' marked override, but does not override

     virtual const unsigned char *oid() override;

                                  ^
How am I going to solve that? Any help is appreciated.

title: #include <ESP8266WiFi.h> Error with WiFiClientSecureBearSSL.h

Answers: 1

body:
You installed the latest git version of the ESP8266WiFi library into your libraries folder and this version is not compatible with the 2.5.2 version of the esp82666 Arduino core.

The ESP8266WiFi library is part of the esp8266 boards package. It should not be installed separately. Delete the library from your libraries folder.


body:
I'm frustrated I feel like I am 90% there but my computer will not recognize the ATtiny167. Here i9s the list of things I have completed/tried using Windows 10 and Arduino 1.8.6;

                      1) Installed Driver USB Bootloader is complete
                      2) Device Management I see the device
                      3) Arduino Sketch select 16.5 MHz board in parameters
                      4) Led on the board flashes sound beeps and stops flashing
                      5) "Device not recognized"
                      6) I have rebooted many times. I deleted everything and started over again with same
                          results
                      7) Used a 3rd party software to look at my USB ports it see the device
                       I have tried more than one device as well

             I'm stuck at this point. I've tried running example programs however the device is not recognized.

Any suggestions?

title: ATtiny167 Device not recognized

Answers: 1

body:
If Digispark Pro clone is not recognized, you can try to use/upload .ino programs via ArduinoISP.

note use in File -> Preferences -> Additional Boards Manager URLs:
http://drazzy.com/package_drazzy.com_index.json
instead:
http://digistump.com/package_digistump_index.json

(The first is AttinyCore by Spence Konde, the second is the normal Digistump AVR Boards)

Then selected Tools -> Boards Manager, and Find AttinyCore -> (Wait and Install).

Now you can upload File -> Example -> ArduinoISP on your Arduino connected in ISP mode with your ATtiny167.

Now select ATtiny167 Board, 16Mhz (External) and write bootloader with your Arduino connected in same manner ISP mode with your ATtiny167.

And now upload any .ino file for ATtiny167 in the same manner with your Arduino connected in ISP mode with your ATtiny167.


body:
I am facing problem with ESP32. I use basic example for WiFiClient and making request to my server. The problem is that the response should be 15000 bytes long, but very often I got only 2750 or less.

    char buffer[15000];
    while (client.available()) {
      char c = client.read();
      buffer[i++] = c;
    }
    Serial.println(i);

title: ESP32 WiFiClient request missing response

Answers: 1

body:
You are assuming that all 15000 bytes are available all the time.

They won't be.

Instead of "while available read something" you need to "While not enough has been read, then if available read something".

When reading from (assuming) HTTP you first need to read and interpret the headers (the lines before a single blank line).  One of these will be the "Content-Length:" header, which will tell you exactly how many bytes are in the body of the response. Then you use that to read the right number of bytes from the body.

So the sequence is:

1. Read line by line for the headers interpreting the ones you need to, until:
2. You receive a single blank line
3. Read the data byte-wise until you have read the number of bytes indicated in the Content-Length header.

If you aren't reading from an HTTP server and you are certain that the data is exactly 15000 bytes in length then you need to skip to point 3 above. Never assume that all the data is there. If there is data then read it, and repeat until you have totalled 15000 bytes.


body:
I am trying to do Arduino to ESP8266 communication, but I am not able to send data to esp8266. However I can receive data from esp8266.

Here if my Arduino code:
<!-- language-all: lang-cpp -->

    #include <SoftwareSerial.h>
    SoftwareSerial ESPserial(0, 1); // RX | TX

    void setup()
    {
      Serial.begin(115200);     // communication with the host computer
      // Start the software serial for communication with the ESP8266
      ESPserial.begin(9600);

      Serial.println("Enter 1 to turn led high & 2 to turn led low.");
    }
    // the loop function runs over and over again forever
    void loop() {
      // listen for communication from the ESP8266 and then write it to the serial monitor
      if ( ESPserial.available() )   {
        Serial.write( ESPserial.read() );
      }

      // listen for user input and send it to the ESP8266
      if ( Serial.available() )       {
        ESPserial.write( Serial.read() );
      }

    }

Here is esp8266 code:

    void setup()
    {
      Serial.begin(9600);     // communication with the host computer
      // Start the software serial for communication with the ESP8266
      // initialize digital pin LED_BUILTIN as an output.
      pinMode(LED_BUILTIN, OUTPUT);
    }
    // the loop function runs over and over again forever
    void loop() {
      Serial.println("ESP -- Hello");
      delay(1000);
      // listen for user input and send it to the ESP8266
      if ( Serial.available() )  {

        int ledState = Serial.parseInt();
        if (ledState == 1) {
          digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
          Serial.println("ESP Led On\n");
        }
        if (ledState == 2) {
          digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
          Serial.println("ESP Led Off\n");
        }
      }
    }

Once I upload both sketches, then I can see it terminal " ESP -- Hello " keep printing comming from esp8266 but when I enter 1 or 2, its not sent to esp8266 due to which I never see "ESP led on/off" messages , so correct me guys what mistake I am making.

title: how to do Arduino to esp8266 communication

Answers: 1

body: using SoftSerial on the hardware serial isn't working on Arduino properly as sometime data receive and sometime not with garbage added so Using digital pins  other  2, & 3  other than hardware serial resolved the issue.


body:
I am planning on making my own custom PCB of a SAMD21 board. I would like to ask if anyone has experience uploading arduino bootloader on a [J-link Mini][1] although adafruit has a [guide][2] on this device, its not uploading a arduino bootloader.

On a related note which pins should I connect it to my SAMD21 chip ?

  [1]: https://www.mouser.com/ProductDetail/Segger-Microcontroller/80891?qs=sGAEpiMZZMve4/bfQkoj%2BGJy0Rcfgzx64YhEx8e9g/U=
  [2]: https://learn.adafruit.com/assets/69849

<!-- Trick -->

title: How to burn arduino bootloader on SAMD21 chips using J-Link mini

Answers: 1

body: The Atmel EDBG would work for Arduino Zero since that has the EDBG chip. With Jlink, you can use Atmel Studio. Once the Jlink is connected to the chip via the 10 pin SWD header, goto the programmer option in Atmel Studio, select the chip and programmer and burn your firmware with the selected programmer. You can follow a tutorial [here](https://learn.adafruit.com/how-to-program-samd-bootloaders/programming-the-bootloader-with-atmel-studio) which walks through it.


body:
I want to write my data on google sheets using ESP 01 and Arduino Nano.
So I copied code from some website I don't remember the website "how to send data on a local server" and modified it a bit.
But it is directly sending the data to the local server only.

Please help me to call Pushing box API and write on Google Sheets.

Here is my current code:

#include<SoftwareSerial.h>

SoftwareSerial comm(12,11); //setting Tx and Rx pins

String server=""; //variable for sending data to webpage
boolean No_IP=false; //variable to check for ip Address
String IP=""; //variable to store ip Address
char temp1='0';

int a=0;
int b=0;

void setup()
{
Serial.begin(9600);
comm.begin(9600);
wifi_init();
Serial.println("System Ready..");
}

void loop()
{
b=0;
Serial.println("Refresh Page");
while(b<1000)
{
b++;
while(comm.available())
{
if(comm.find("0,CONNECT"))
{
Serial.println("Starting");
sendToServer();
Serial.println("Finished");
delay(1000);
}
}
delay(1);
}
}

void findIp(int time1) //check for the availability of IP Address
{
int time2=millis();
while(time2+time1>millis())
{
while(comm.available()>0)
{
if(comm.find("IP has been read"))
{
No_IP=true;
}
}
}
}

void showIP()//Display the IP Address
{
IP="";
char ch=0;
while(1)
{
comm.println("AT+CIFSR");
while(comm.available()>0)
{
if(comm.find("STAIP,"))
{
delay(1000);
Serial.print("IP Address:");
while(comm.available()>0)
{
ch=comm.read();
if(ch=='+')
break;
IP+=ch;
}
}
if(ch=='+')
break;
}
if(ch=='+')
break;
delay(1000);
}
Serial.print(IP);
Serial.print("Port:");
Serial.println(80);
}

void establishConnection(String command, int timeOut) //Define the process for sending AT commands to module
{
int q=0;
while(1)
{
Serial.println(command);
comm.println(command);
while(comm.available())
{
if(comm.find("OK"))
q=8;
}
delay(timeOut);
if(q>5)
break;
q++;
}
if(q==8)
Serial.println("OK");
else
Serial.println("Error");
}

void wifi_init() //send AT commands to module
{
establishConnection("AT",100);
delay(1000);
establishConnection("AT+CWMODE=3",100);
delay(1000);
establishConnection("AT+CWQAP",100);
delay(1000);
establishConnection("AT+RST",5000);
delay(1000);

Serial.println("Connecting Wifi....");
establishConnection("AT+CWJAP=\"Leobotics\",\"leobotics123\"",7000); //provide your WiFi username and password here
delay(2000);
Serial.println("Wifi Connected");
showIP();
establishConnection("AT+CIPMUX=1",100);
establishConnection("AT+CIPSERVER=1,80",100);
}

void sendData(String server1)//send data to module
{
int p=0;
while(1)
{
unsigned int l=server1.length();
Serial.print("AT+CIPSEND=0,");
comm.print("AT+CIPSEND=0,");
Serial.println(l+2);
comm.println(l+2);
delay(100);
Serial.println(server1);
comm.println(server1);
}
}
void sendToServer()//send data to webpage
{
//String aquib = "http://busgetbeast.in";
sendData("http://api.pushingbox.com/pushingbox?devid=vBDFF4154ABE4F6F&humidityData=33&celData=44&fehrData=111&hicData=22&hifData=77");
      sendData(" HTTP/1.1");
      sendData("Host: ");
      sendData("api.pushingbox.com");
      sendData("User-Agent: ESP8266/1.0");
      sendData("Connection: close");
    // sendData();
delay(5000);
comm.println("AT+CIPCLOSE=0");
}

title: ESP 01 calling Pushing Box API

Answers: 0


body:
I am facing the same issue with my motor driver. Initially I ran the code and connected the L298N with Arduino and it worked fine. At that time motors were running absolutely fine. But when I ran it sometimes later then the motors are not running. However the motors are getting power but I think thy are getting very less power from the Motor Driver.

I directly ran motors from Arduino +5V pin and the motors were running fine. Is there something wrong with my L298N motor driver?

One more thing I checked the power for all the pins for L298N motor Driver and all pins are working fine.

Here is my complete program:
<!-- language-all: lang-cpp -->

    const int MOTOR_RIGHT = 1;
    const int MOTOR_LEFT =  2;
    const int MR_CONTROL_PIN_A = 8;
    const int MR_CONTROL_PIN_B = 9;
    const int ML_CONTROL_PIN_A = 10;
    const int ML_CONTROL_PIN_B = 11;

    void setup() {
      // These two pins will act as output pin

      pinMode(MR_CONTROL_PIN_A,OUTPUT);
      pinMode(MR_CONTROL_PIN_B,OUTPUT);
      pinMode(ML_CONTROL_PIN_A,OUTPUT);
      pinMode(ML_CONTROL_PIN_B,OUTPUT);
      Serial.begin(4800);

    }

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

      forward(MOTOR_RIGHT);
      forward(MOTOR_LEFT);
      delay(5000);
      stopMotor(MOTOR_RIGHT);
      stopMotor(MOTOR_LEFT);
      delay(1000);
      backward(MOTOR_RIGHT);
      backward(MOTOR_LEFT);
      delay(5000);
      stopMotor(MOTOR_RIGHT);
      stopMotor(MOTOR_LEFT);
      delay(1000);

    }
    /////////////////////////////////////////////////////////////////////
    //Forward

      void forward(int motorNo)
      {

      Serial.print("\r\n Forward : ");
      Serial.print(motorNo);

      switch(motorNo)
      {
        case MOTOR_RIGHT:
        digitalWrite(MR_CONTROL_PIN_A,HIGH);
        digitalWrite(MR_CONTROL_PIN_B,LOW);
        break;

        case MOTOR_LEFT:
        digitalWrite(ML_CONTROL_PIN_A,HIGH);
        digitalWrite(ML_CONTROL_PIN_B,LOW);
        break;

      default:
        Serial.print("\r\n Error :Invalid Motor No ");
        Serial.print(motorNo);
       }
      }

    //////////////////////////////////////////////////////////////////////
      void backward(int motorNo)
      {
       Serial.print("\r\n Backward : ");
       Serial.print(motorNo);
      switch(motorNo)
      {
        case MOTOR_RIGHT:
        digitalWrite(MR_CONTROL_PIN_A,LOW);
        digitalWrite(MR_CONTROL_PIN_B,HIGH);
        break;

        case MOTOR_LEFT:
        digitalWrite(ML_CONTROL_PIN_A,LOW);
        digitalWrite(ML_CONTROL_PIN_B,HIGH);
        break;

      default:
        Serial.print("\r\n Error :Invalid Motor No : ");
        Serial.print(motorNo);
       }

      }

    ///////////////////////////////////////////////////////////////////////
      void stopMotor(int motorNo)
      {
       Serial.print("\r\n STOP : ");
       Serial.print(motorNo);
      switch(motorNo)
      {
        case MOTOR_RIGHT:
        digitalWrite(MR_CONTROL_PIN_A,HIGH);
        digitalWrite(MR_CONTROL_PIN_B,HIGH);
        break;

        case MOTOR_LEFT:
        digitalWrite(ML_CONTROL_PIN_A,LOW);
        digitalWrite(ML_CONTROL_PIN_B,LOW);
        break;

      default:
        Serial.print("\r\n Error :Invalid Motor No : ");
        Serial.print(motorNo);
       }

      }

Is there something wrong with my L298N ? How can I test it?

title: L298N motor driver issue

Answers: 2

body:
The specified minimum voltage for the motors is **2.5 volts higher than the logic supply**.

You need to use a separate supply for the motor that is higher than the logic power.

body: 9 volt batteries have very low capacity. That could be the cause of your problem. Replace the battery with a power supply with higher capacity. Or other bigger batteries that add up to around 9 volts.


body:
I wish to blink all the strip. In the code below it just blink the first LED, how can I fix it?

Code:

    #include <Adafruit_NeoPixel.h>

    #define PIN 6
    #define NUM_LEDS 24

    Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

    void setup() {
      strip.begin();
      strip.show();
    }

    void loop() {
      strip.setPixelColor(0, 255, 255, 255);
      strip.show();
      delay(1000);
      strip.setPixelColor(0, 0, 0, 0);
      strip.show();
      delay(1000);
    }

title: Blink Adafruit_NeoPixel

Answers: 1

body:
The first argument of `setPixelColor` is is the number of the led. In your case 0, so the first led.

Instead use a `for` loop to set all the leds from 0 until (excluding) 24 (which is stored in `NUM_LEDS`).

    void loop()
    {
      for (int led = 0; led < NUM_LEDS ; led++)
      {
        strip.setPixelColor(led, 255, 255, 255);
      }
      strip.show();
      delay(1000);

      for (int led = 0; led < NUM_LEDS ; led++)
      {
        strip.setPixelColor(led, 255, 255, 255);
      }
      strip.show();
      delay(1000);

To make the code better (shorter, but more important more maintainable, and reducing code duplication), create a separate function:

    void loop()
    {
      setLeds(255);
      setLeds(0);
    }

    void setLeds(int intensity)
    {
      for (int led = 0; led < NUM_LEDS ; led++)
      {
        strip.setPixelColor(led, intensity, intensity, intensity);
      }

      strip.show();
      delay(1000);
    }


body:
I am just starting with Arduino and my first project consists in switching a LED light with Arduino.

I know a relay must be use to control AC high voltage device (i.e. 240V), however, as my LED seems to be powered by DC 7V voltage (7V - 0.43A written on the power supply which is integrated within the outlet, so I can only access the low voltage wire), I am wondering how to control such a device.

Do I still need a relay or the Arduino can handle this on its own?

title: Turn on/off low current device (LED) with Arduino

Answers: 2

body:
Use a power MOSFET transistor. This one from Sparkfun is an example: https://www.sparkfun.com/products/10213

If you use a relay you will probably need transistor and a separate power supply to drive the relay coils anyway, and will also need a [**flyback diode**][1] to protect the control circuit of the relay from the "back EMF" of the relay coils.

**DO NOT** try to drive relay coils directly from an Arduino digital pin. It will almost certainly fry the Arduino pin, and might destroy the entire Arduino.

A MOSFET transistor like the one I linked can be controlled directly from an Arduino GPIO line, and can switch DC loads of up to 60V and 30A.

  [1]: https://en.wikipedia.org/wiki/Flyback_diode

body:
No You can easily achieve this by using a NPN Transistor....

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/iMHlR.png)

<!-- End schematic -->

You can use BC548 NPN transistor for this is..

But make sure that ground of both emitter and arduino should be same....


body:
Greeting! I am finding it difficult setting up a pin change interrupt on an arm board ( I am using Arduino due). I found a sample online which I have used but I discovered that when ever an interrupt occurs on a particular pin, it tends to pick up noise from other pins (i.e it prints the state of other pins which didn't get an interrupt) even after appropriate de-bouncing of the signal. For that reason it is quite difficult to carry out appropriate decision with the result am getting. Please I need a code example on how to set of pin change interrupt on Arduino Due for me to continue with my final year project. its very urgent, thanks in anticipation.
Code as Follows:

```c++
#include <ArduinoJson.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

#define DEBOUNCE_TIME 50L

#define interruptPin3 3
//#define interruptPin4 4

byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(172, 168, 1, XXX);
IPAddress server(172, 168, 1, XXX);

EthernetClient ethClient;
PubSubClient mqttClient(ethClient);

char data2[700];
void reconnect() {
  // Loop until we're reconnected
    while (!mqttClient.connected())
    {
   SerialUSB.println("Attempting MQTT connection...");

    if (mqttClient.connect("arduinoClient")) {
       SerialUSB.println("Now connected!");
    } else {
      SerialUSB.println("Failed! Please wait for reconnection ...");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

//ISR Flags
volatile bool ISR_DEACTIVATED = false;
volatile bool display_int_time = false;

bool debounce_started = false;
unsigned long Isr_debounce_pin_timer;

volatile bool initializationFlag = false;
volatile bool pinVoltStatus = HIGH;
volatile bool lastVoltStatus=LOW;
String pinStatusValue="HIGH";

volatile int interruptPinDigitalPin;

void PinsInitialization() {

  pinMode(interruptPin3, INPUT);
  attachInterrupt(digitalPinToInterrupt(interruptPin3), Pin3ChangeInterrupt, CHANGE);
}

void setup()
{
  SerialUSB.begin(9600);
  while (!SerialUSB) continue;
  mqttClient.setServer(server, 11883);

  Ethernet.begin(mac, ip);
  // Allow the hardware to sort itself out
  delay(1500);
  reconnect();

  ISR_DEACTIVATED = false;
  display_int_time = false;
  initializationFlag = false;

  PinsInitialization();
}

void getPinStatus()
{
   bool pinStatus;
    pinStatus = digitalRead(interruptPinDigitalPin);
    if(pinStatus == LOW)
    {
      pinStatusValue = "LOW";
      pinVoltStatus = LOW;
    }else{
      pinStatusValue = "HIGH";
      pinVoltStatus = HIGH;
    }
}

void Pin3ChangeInterrupt()
{
  if(!ISR_DEACTIVATED)
  {
    interruptPinDigitalPin = interruptPin3;
    ISR_DEACTIVATED = true;
    display_int_time = true;
  }
}

//Returns TRUE if pin is stable at desired state, FALSE if bouncing or other state
bool debounce(const int debounce_pin, const bool state, unsigned long &state_latch_start)
{
  static bool current_state;

  // Read the required pin
  current_state = digitalRead(interruptPinDigitalPin);

  if ((!debounce_started) && (current_state == state)) {

      state_latch_start = millis();
      debounce_started = true;
  }

  if (debounce_started && (current_state != state))

      debounce_started = false;

  if (debounce_started && (current_state == state) && (((unsigned long)(millis() - state_latch_start)) >= DEBOUNCE_TIME))
  {
    debounce_started = false;
    // report back that all is goood.
    return(true);
  }

  //Either the pin is at the wrong level, or is still bouncing. Try again later!
  return(false);
}

void messageToPublish(String digitalPinNumber, String voltageStatus)
{
  StaticJsonDocument<200> doc;

    doc["digitalPin"] = digitalPinNumber;
    doc["voltStatus"] = voltageStatus;

    String payload = doc.as<String>();
    payload.toCharArray(data2, (payload.length() + 1));
    mqttClient.publish("interruptTopic", data2);
    SerialUSB.println((String)digitalPinNumber+ ":"+(String) voltageStatus);
}

void loop()
{
  //This runs every time an interrupt occurs
  if (display_int_time)
  {
    detachInterrupt(interruptPinDigitalPin);
    //Done with interrupt stuff. Clear the interrupt flag
    getPinStatus();
  }

   //Debounce for the ISR routine in main loop
    if (ISR_DEACTIVATED)
    {//Wait until the pin settles LOW to reactivate the ISR
      bool debounceStatus = debounce(interruptPinDigitalPin, pinVoltStatus, Isr_debounce_pin_timer);
      if(debounceStatus)
      {
        if (initializationFlag == false)
        {
          ISR_DEACTIVATED = false;
          initializationFlag = true;
        }else
        {

           if(interruptPinDigitalPin == interruptPin3)
          {
            attachInterrupt(digitalPinToInterrupt(interruptPin3), Pin3ChangeInterrupt, CHANGE);
            messageToPublish("Pin3", pinStatusValue);
          }
          display_int_time = false;
          ISR_DEACTIVATED = false;
        }
      }

    }
}
```

title: pin change interrupt on arduino Due

Answers: 0


body:
I uploaded the ArduinoISP sketch to an Arduino Nano to use it as a programmer for other chips.

It worked successfully to program an ATtiny45, I did the usual wiring between them, and added a 10uF between RST and GND of the Nano. Everything worked.

Now I'd like to program a standalone ATmega328p with the Nano, I did the usual wiring as well (see this [tutorial](http://www.martyncurrey.com/arduino-nano-as-an-isp-programmer/)), as well as this 10uF cap.

But it does't work:

>
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

The reason might be because this 328p comes from an Arduino Uno, probably configured to be ext-clocked by a crystal. Whereas I don't have any crystal here and wanted to clock the 328p with the internal clock.

**Question: how can I restore the 328p to factory default / internal clock, if I don't have a crystal?**

Or what other reason can this error be?

Edit: a solution is found here: https://arduino.stackexchange.com/questions/68779/change-the-fuses-of-an-arduino-uno-can-an-arduino-uno-change-its-own-fuses

title: Using an Arduino Nano to program (as ISP) a standalone 328p

Answers: 2

body:
You can temporarily put it in an UNO. Don't connect this UNO via USB, but use jumper wires to connect the ISP pins plus the power pins to the other Arduino that you are using as an ISP programmer. (You could also use the (2x3) ISP header on the UNO if that's more convenient.)

Or, you could use a high voltage programmer.

Or get/desolder a crystal from some junk electronics. Exact frequency doesn't matter that much. I think somewhere between 1 Mhz and 16 Mhz would work.

You can then reset the fuses, so it doesn't need a crystal.

body:
That error basically says the bootloader you are trying to burn does not *appear* to be for that device.  This could be due to corruption or (more likely in your case) harvesting and reconfiguring the hardware.

If the error does not appear when you try to load the bootloader for the Uno (original device you harvested it from for those harvesting from other configurations), you will know it is the latter.

Either way, you can try to -f it by running avrdude to burn the bootloader via command line (as it says).  I've successfully saved  stuff with a corrupt bootloader this way although i've never found it worth the hassle to harvest and reconfigure- if you pulled it off the uno, surely you can stitch it to a clock.

If your clock is off by a bit, you may just need to get lucky over several attempts :)


body:
I am just trying to use an ultrasonic sensor with a buzzer but the buzzer doesn't respond to my code. I mean it doesn't make any sound. I tested it to check if by sending 5 volts to it, it will make a sound.. and it did... but using this code below... for some reason, it doesn't make any sound....

    #include <NewPing.h>
    #define TRIGGER_PIN 11
    #define  ECHO_PIN 12
    #define buzzer 13

    NewPing sonar1 (TRIGGER_PIN, ECHO_PIN);

    long inches1;
    int sound = 250;

    void setup (){

      Serial.begin (9600);

      pinMode (TRIGGER_PIN, OUTPUT);
      pinMode (ECHO_PIN, INPUT);
      pinMode (buzzer, OUTPUT);

    }

    void loop () {

      inches1 = sonar1.ping_in();
       if (inches1 <= 5 ){
     //   sound = 250;
        tone(buzzer, 1000); // Send 1KHz sound signal...
        delay(1000);        // ...for 1 sec
        noTone(buzzer);     // Stop sound...
        delay(1000);
        Serial.print (inches1);
        Serial.print ('\n');
       }
      delay (200);
    }

title: exit status 1 error compiling for board arduino/Genuino Uno when tone code is used

Answers: 1

body:
If you have a look at the complete error message you will see that there is a collision between the libraries **NewPing** and **Tone**.

    Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

    Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

    (.text+0x0): multiple definition of `__vector_7'

    libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Error compiling for board Arduino/Genuino Uno.


body:
My thought was to use a magnetic reed switch to turn on the arduino.  But how do I keep it running if the magnet is moved?  The idea is that the application will determine when it is ok to shut off the power to the arduino.

I don't want any power usage when the system is dormant since it could be weeks between magnetic triggers.

Doug

title: How can I make my arduino start when a magnet is sensed, and stay running until the application determines it was to shut down

Answers: 3

body: Put your Arduino into deep sleep and attach an interrupt to a pin that is monitoring your reed switch. Once triggered it can run your code before deep sleeping again

body:
The [LowPower][1] library will help you to minimize the amount of power used by putting the Arduino to sleep. The Arduino will awaken once the magnetic reed switch triggers it, then you can execute some code before it goes back to sleep again.

There is an [example sketch][2] that may work for you:
<!-- language-all: lang-cpp -->

    // **** INCLUDES *****
    #include "LowPower.h"

    // Use pin 2 as wake up pin
    const int wakeUpPin = 2;

    void wakeUp()
    {
        // Just a handler for the pin interrupt.
    }

    void setup()
    {
        // Configure wake up pin as input.
        // This will consumes few uA of current.
        pinMode(wakeUpPin, INPUT);
    }

    void loop()
    {
        // Allow wake up pin to trigger interrupt on low.
        attachInterrupt(0, wakeUp, LOW);

        // Enter power down state with ADC and BOD module disabled.
        // Wake up when wake up pin is low.
        LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

        // Disable external pin interrupt on wake up pin.
        detachInterrupt(0);

        // Do something here
        // Example: Read sensor, data logging, data transmission.
    }

  [1]: https://github.com/rocketscream/Low-Power
  [2]: https://github.com/rocketscream/Low-Power/blob/master/Examples/powerDownWakeExternalInterrupt/powerDownWakeExternalInterrupt.ino

body:
You can connect a power MOSFET in parallel to the reed switch, that is controlled by the Arduino:

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/SN0Ee.png)

<!-- End schematic -->

The Arduino powers up, when the reed switch is activated. Then you can activate (drive HIGH) the pin connected to the MOSFET, so that the Arduino is still provided with the needed power through the MOSFET, if the reed switch turns off. If the correct time comes to turn the Arduino off, you can release the digital pin (drive LOW or high impedance/input), so that it get's pulled to low. That will deactivate the MOSFET, which cuts the power off the Arduino.


body:
For now, I'm using an Arduino Uno alone including its 328p (no other external chip to program).

I would like to **change its fuses to internal 8 Mhz clock** (because then I'll move the 328p out of the Arduino Uno), and for simplicity I'd like to do it from Arduino IDE.

Here is what I tried:

* I created a new entry in boards.txt copy-pasted from Uno, [fuses modified](http://www.engbedded.com/fusecalc), like this:

        atmega328p.name=Atmega328p
        atmega328p.upload.tool=avrdude
        atmega328p.upload.protocol=arduino
        atmega328p.upload.maximum_size=32256
        atmega328p.upload.maximum_data_size=2048
        atmega328p.upload.speed=115200

        atmega328p.bootloader.tool=avrdude
        atmega328p.bootloader.low_fuses=0x62
        atmega328p.bootloader.high_fuses=0xD9
        atmega328p.bootloader.extended_fuses=0xFF
        atmega328p.bootloader.unlock_bits=0x3F
        atmega328p.bootloader.lock_bits=0x0F
        atmega328p.bootloader.file=optiboot/optiboot_atmega328.hex

        atmega328p.build.mcu=atmega328p
        atmega328p.build.f_cpu=8000000L
        atmega328p.build.board=AVR_UNO
        atmega328p.build.core=arduino
        atmega328p.build.variant=standard

* I selected this board in *Tools > Board: Atmega328p*

* I tried to *Upload* any sketch (and not *Upload with programmer* since I have no other chip connected to the Arduino Uno), hoping it would modify the fuses during the (successful) *Upload* process.

**I think it didn't work (when I move the 328p outside of the Uno it doesn't work).**

**How can I change the fuses for an Arduino Uno directly from Arduino IDE, to enable internal 8 Mhz clock?**

____

PS: "Tools > Burn Bootloader" does not succeed, but I think this is normal, since there is just the Arduino Uno, and no other chip / nothing to use as a "Programmer":

> avrdude: stk500_recv(): programmer is not responding
> avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x03

title: Change the fuses of an Arduino Uno (can an Arduino Uno change its own fuses?)

Answers: 3

body: You need a programmer to burn fuses.  If you have another arduino then you can use the Arduino as ISP example sketch in the IDE.  You can't burn fuses just using the USB cable like you upload code with.  The only reason that can talk to the chip at all is because there is another chip to convert it to serial and a bootloader on the 328P to allow it to upload code via serial.

body:
As mentioned in the other answer, it seems that it's not possible for an Arduino Uno to change *its own fuses*.

So here is how I did:

* I used a Nano (loaded with "Arduino as ISP") as programmer for the Uno with this classical wiring (except that in my case, the left board, the programmer, is a Nano):

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

* I added this to `boards.txt` (source [here](https://forum.arduino.cc/index.php?topic=308347.msg2149945#msg2149945)):

        ##############################################################
        atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)
        atmega328bb.upload.protocol=arduino
        atmega328bb.upload.maximum_size=30720
        atmega328bb.upload.maximum_data_size=2048
        atmega328bb.upload.speed=57600
        atmega328bb.upload.tool=avrdude
        atmega328bb.bootloader.tool=arduino:avrdude
        atmega328bb.bootloader.low_fuses=0xE2
        atmega328bb.bootloader.high_fuses=0xDA
        atmega328bb.bootloader.extended_fuses=0x05
        atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
        atmega328bb.bootloader.unlock_bits=0x3F
        atmega328bb.bootloader.lock_bits=0x0F
        atmega328bb.build.mcu=atmega328p
        atmega328bb.build.f_cpu=8000000L
        atmega328bb.build.core=arduino
        atmega328bb.build.variant=standard
        atmega328bb.build.board=AVR_BARE

* I used *"Programmer: Arduino as ISP"*, then *"Burn bootloader"* then *"Upload with programmer"* with any sketch.

* Then the fuses are programmed to Internal 8 Mhz, and we can take the ATmega328p out of the Uno and move it on a breadboard! Working now :)

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

body:
This is technically possible, but tricky.

First you'd have to wire up the Arduino with some jumpers in such a way that the 328P can use its ICSP header to reprogram the 16U2/8U2 via that chips own header. With the right custom firmware in place you could then re-wire the board so that the 16U2 changes the fuses of the 328P upon boot and reuploads the firmware before switching into its usual function. Then it's just a matter of having the 328P reprogram the 16U2 with the original DFU firmware, and presto! An Arduino that changed its own fuses!

If you just need to change the fuses without a ICSP programmer then that can be done by just [programming the 16U2 chip directly through its USB port](https://welldoneblog.fedevel.com/2015/04/13/how-to-flash-arduino-bootloader-without-a-programmer/) (although technically that doesn't qualify as the Uno "programming itself").


body:
Yesterday I was working on Arduino based bluetooth car. I was using adafruit motor shield v1. Arduino and shield were on same power supply(11v li-ion cell battery). Every thing was fine. I decided to add some leds to my car. I connected two leds with 5v on shield pins(leds were in series and were multi-colored so 5v was okay). It worked for sometime but later it stopped working. Green led on arduino was on while other were off. I disconnected shield and supplied arduino from dc jack, same result. Then I connected arduino with usb cable then everything was fine. Now it works because I supply arduino from usb and shield is working too either from usb supply or external supply. What could possibly go wrong?

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

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

title: can't power up arduino from dc jack

Answers: 1

body:
It would appear that the output of the power regulator pin has been vaporized.

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

From the Arduino R3 schematic we see this part as U1 which is an NCP1117ST50T3G power regulator.  [Here][2] is that data sheet for that part. From that data sheet we see the physical image of the part.

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

It appears that pin 2 has been vaporized.  If we look at the schematic of the Arduino R3 we see where pin 2 supplies the regulated power to the rest of the Arduino board and likely any connected electronics.  Note the red "X" indicating the vaporized pin 2.

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

The schematic and the data sheet both indicate the regulator's TAB is also an output.  If true it is difficult to explain why pin 2 vaporized.  Perhaps this particular version of the regulator does not use the TAB as an output.  Or perhaps the Arduino R3 PCB and schematic do not agree.

Added later...

There has been a comment that U1 (the NCP1117ST50T3G power regulator) may sometimes be manufactured with out the center pin.  Still, if you can power the Arduino R3 using the USB port and unable to power the Arduino R3 using power through the barrel jack, the likely suspects are U1 and D1.  However, to be sure, you would have to check the voltage before D1 and after U1.

  [1]: https://i.stack.imgur.com/GaiuA.png
  [2]: https://www.onsemi.com/pub/Collateral/NCP1117-D.PDF
  [3]: https://i.stack.imgur.com/KB8Nf.png
  [4]: https://i.stack.imgur.com/GmMl8.png