body:
I am working on a proof-of-concept ADC to "explode" what's inside of an ADC chip for teaching purposes.

Currently, I have a sketch that uses a push-button to act as a clock-pulse that counts up (1, 2, 3, 4, ...) for every positive edge using the attachInterrupt() function.

The sketch works great to view the data in the serial monitor.

I am pairing the Arduino (Teensy 3.2) with a Raspberry Pi configured to read data off the Serial line to a text box.

After a good bit of troubleshooting it appears that the `attachInterrupt()` function corrupts the Serial buffer with garbage for every interrupt. For instance, if I use

    Serial1.flush();
    Serial1.begin(115200);

immediately after the interrupt and *then* send out my data using `Serial.println()` I get my expected decimal value at my output. However, without these lines I just get unicode garbage at my Serial output. See full "fixed" sketch code below:

My question is: why is this happening? I should not need to restart Serial every iteration of the clock.

    #define HWSERIAL Serial1

    const int numBits = 12;             //Number of bits in ADC (resolution)
    const int comparatorPin = 14;       //Pin number of comparator out
    const int clockPin = 15;            //Pin number of external clock (square wave) input; expecting clock with 50% duty-cycle
    volatile int comparatorState = 0;   //Is comparator high or low?
    volatile bool clockState = 0;       //Is clock high or low?
    volatile int masterCount = 0;       //Our master count
    volatile bool isSameVal = false;    //Is the value of the master count the same value as last cycle?

    int outVal = 0;

    int masterBinCount[12];     //Array to store binary value of the master count
    byte outputPins[12];        //Array to store the numbers associated with the output pin numbers
    int maxValue = 0;           //Initialize max counter value to zero

    void setup() {
      Serial.begin(115200);       //Begin Serial transmission
      HWSERIAL.begin(115200, SERIAL_8N1);
      HWSERIAL.flush();
      delay(2000);

      defineOutPins(outputPins);  //Assign pin numbers for output pins

      pinMode(14, INPUT);   //Comparator Pin
      pinMode(15, INPUT);   //Clock-in pin

      maxValue = pow(2, numBits);   //Set max counter value to max bit resolution. Ex. for 12 bits --> 4096
    }

    void loop() {
      attachInterrupt(clockPin, doOnClock, RISING);   //When clock is on a positive-edge execute doOnClock function

      HWSERIAL.flush();
      HWSERIAL.begin(115200);

      if(isSameVal == false) {    //If the master count is NOT the same as the last cycle
        convertDecToBin();        //Convert the master count (dec) to binary
        binaryToPins();           //Send the binary value (via digitalWrite) to output pins
      }
      else {
        //Do nothing
      }
      delay(1000);
    }

    void defineOutPins(byte pinNos[]) {   //Assign pin numbers to parallel binary out: Teensy 3.2 pin #0 --> #11
      for(byte i = 0; i < numBits; i++) {
        pinNos[i] = {i};      //Assign current pin this value
        pinMode(i, OUTPUT);   //Define pins as outputs
      }
    }

    void doOnClock() {
      comparatorState = digitalRead(comparatorPin);   //Check comparator state

      if(comparatorState >= 0.5) {            //Check if positive clock pulse
        if(masterCount == (maxValue - 1)) {   //Check if current count value is at "ceiling"
          //Do nothing
        }
        else {            //Else increment count up
          masterCount++;
        }
      }
      else if(comparatorState < 0.5) {    //Check if negative clock pulse
        if(masterCount == 0) {            //Check if current count value is at "floor"
          //Do nothing
        }
        else {
          masterCount--;    //Else decrment count down
        }
      }

      isSameVal = false;    //Set "finished" counting for this clock-pulse
    }

    void convertDecToBin() {
      for(int j = 0; j < numBits; j++) {
        int tempCnt = bitRead(masterCount, j);
        masterBinCount[numBits - (j+1)] = tempCnt;    //Populate the master binary count array in "reverse" order starting with the LSB at the highest array index
      }
    }

    void binaryToPins() {
      for(int e = 0; e < numBits; e++) {
        //digitalWrite(outputPins[e], masterBinCount[e]);   //Write our master binary value to output pins
        //Serial.print(masterBinCount[e]);                    //THIS LINE IS FOR TROUBLESHOOTING!!
      }
      isSameVal = true;       //Tell program we wrote the master count to the pins for this clock cycle

      outVal = masterCount;

      Serial.println(outVal);
      HWSERIAL.println(outVal);

      //Serial.print(" decimal: ");   //THIS LINE IS FOR TROUBLESHOOTING!!
      //Serial.print(masterCount);    //THIS LINE IS FOR TROUBLESHOOTING!!
      //Serial.println("");           //THIS LINE IS FOR TROUBLESHOOTING!!
    }

title: attachInterrupt() corrupting Serial buffer requiring Serial restart

Answers: 1

body:
I believe your issue is with initializing `HWSERIAL.begin(115200);` in `void loop`. I created this simple sketch to verify this. Firstly, I commented out the second initialization of `Serial.begin`, and you can see I was getting a perfect output to the serial monitor. Then I uncommented the line, re-uploaded the code to the Arduino, and you can see it didn't even make it through one print before it sent a bunch of garbled junk and effectively froze my serial port.

Remove `HWSERIAL.begin(115200);` from `void loop` and only set it in `void setup`.

Hope this helps!

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

    void loop()
    {
      Serial.begin(115200);
      Serial.print("Test");
      Serial.print(" - ");
      Serial.println(millis());
    }

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

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


body:
i dont have any idea about this problem. can anyone help me how to fix this?

    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266HTTPClient.h>
    const char *ssid = "NUS";
    const char *password = "s006";
    int lo=16.3441;
    int la=80.5243;
    const char *host = "http://smshorizon.co.in";
    void setup() {
       delay(1000);
       Serial.begin(115200);
       Serial.println("Start");
       WiFi.mode(WIFI_OFF);
       delay(1000);
       Serial.println("Status");
       WiFi.mode(WIFI_STA);
       Serial.println("Begin...");
       WiFi.begin(ssid, password);
       Serial.println("");
       Serial.print("Connecting");
       while (WiFi.status() != WL_CONNECTED) {
           delay(500);
           Serial.print(".");
        }
       Serial.println("");
       Serial.print("Connected to ");
       Serial.println(ssid);
       Serial.print("IP address: ");

       Serial.println(WiFi.localIP());
     }
     void loop() {

      }
Sometimes it shows boot mode(1,0)

title: what is this ets Jan 8 2013,rst cause:4, boot mode:(1,7)

Answers: 0


body: I am trying to connect a mfrc522 module with nodemcu. I have tried all tutorials available in youtube. Everytime it shows firmware version: 0x89 (unknown}.

title: Rfid module on nodemcu

Answers: 0


body:
I am trying to use a NodeMCU as a station to connect to a webserver, however, the WiFiClient connect function always returns 0 for no reason. I am able to connect the NodeMCU to my home WiFi, but it just cannot connect to any server (either with IP address or with URL).

If anyone is interested, the following is the testing code (I did not include the libraries intentionally for the clearness of the code).

    int status = WL_IDLE_STATUS;
    IPAddress server(74,125,115,105);  // Google

    // Initialize the client library
    WiFiClient client;

    void setup() {
      Serial.begin(9600);
      WiFi.mode(WIFI_STA);
      Serial.println("Connecting to AP specified during programming");
      WiFi.begin("mySSID", "myPassword");
      while (WiFi.status() != WL_CONNECTED) {delay(500); Serial.print("."); }
      Serial.print("\r\nWiFi connected IP address: ");
      Serial.println(WiFi.localIP());
      Serial.println();
    }

    void loop() {
      Serial.println(client.connect(server,80));
    }

title: ESP8266 WiFiClient connection always returns 0

Answers: 0


body:
Is there anyway to generate a ramp input from an Arduino Uno? A visual depiction of the pulse I am looking for is as follows:
[![Ramp Input][1]][1]

With other microcontrollers, I was able to use their in-built DACs, however I am aware that the Arduino UNO doesn't have any? Is there a way using PWM or analogWrite to output these type of pulses? I'm new to Arduino programming, so I'm a bit unsure. However my next guess would be to use an R-2R ladder to output this type of pulse?

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

title: Generate a ramp input with an Arduino Uno

Answers: 2

body:
By "ramp", it seems that you mean a square wave with sloping rather than vertical edges between + and -.  Can you clarify the question further: do the sloping parts need to be linear?

Direct synthesis of the waveform could be done using the digital output ports and an R2R ladder, as suggested in the comments.  Each PWM timer output of the AVR can control output of 2 digital pins and definitely with a timing precision better than 1 microsecond.  If high voltage resolution is needed, this method may not be able to produce the result you want.

Other possible solutions:

 - The waveform as plotted in the original post looks like a truncated sine wave.  Such a waveform could be made by clipping a sine wave with an operational amplifier.  For the sine wave connect the Arduino to a DDS module such as AD9850/1.

 - Use an external digital-to-analog converter, [e.g. MCP48x2][1]

 - Use an Arduino Zero or other 32-bit microcontroller (e.g. ARM STM32).  These microcontrollers have a true analog output pin, but it's not bipolar.

  [1]: http://ww1.microchip.com/downloads/en/devicedoc/20002249b.pdf

body:
A RC filter will create a slow slewrate.

<!-- 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/MHmk0.png)

<!-- End schematic -->

The circuit creates this signal:
[![enter image description here][1]][1]

A slow rising signal and a fast falling signal can be created with an extra transistor (the signal will be inverted).

<!-- 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/gPYKr.png)

<!-- End schematic -->

For a linear rising and falling edge, a resistor network with a few digital pins is a simple solution. I think it can be created with an opamp circuit as well, but there are also special chips called "slew rate limiter".

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


body:
There are plenty of projects that connect an OmniVision camera, such as ov7670 , to an Arduino.

A good example would be:
https://www.scribd.com/document/356160003/Beginning-Arduino-Ov7670-Camera-Development

Now, let's say I want to connect 2 of those.

The problem with these cameras is that they require 17 IOs, which is a lot.

They are are:

- 1 power - cannot be shared
- 1 external clock (XCLK)
- 2 I2C lines (DATA, CLK)
- 8 data lines (D0:D7)
- 3 sync lines (PCLK, VSYNC, HREF)
- 2 control lines (RESET , PWD)

(Image attached below)

So, assuming I'm only powering 1 camera at a time, by giving each camera its own power IO, can all other IOs of both cameras be shared? at least some of them? (even if some intermediary simple HW is required)

Thanks!

[![][1]][1]

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

title: several cameras share data lines

Answers: 0


body:
I have developed a circuit to process the PMT pulse output. For the testing, I need an artificial signal which is similar to the PMT pulse. How can I use `AnalogWrite()` to create such type of signal?

[![Attached image show the waveform of PMT Pulse][1]][1]

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

title: How can I create an analog signal which is similar to PMT (Photo Multiplier Tube) pulse using analog write?

Answers: 2

body:
Short answer: You can't.

The Arduino can't do analog output at all, much less matching a specific analog waveform of ≈40ns duration.

PWM on the Arduino simulates **constant** analog voltages using square wave pulses of variable duty cycle. It has no support for creating analog waveforms of any type, much less ones with such a short duration.

**EDIT**

As mentioned in this thread: https://arduino.stackexchange.com/questions/62816/generate-a-ramp-input-with-an-arduino-uno

You could use a resistor ladder to create a roll-your-own DAC, and then use direct port register manipulation (not digitalWrite) to set the pins controlling your resistor ladder and get a crude approximation of your waveform.

**Edit #2**

There is no way you'll be able to generate nanosecond scale waveforms with a normal Arduino. It just isn't fast enough.

body:
I doubt very much AVR-based Arduinos could do that.

SAMD21-based Arduinos do have a DAC, but their conversion time is about 2.85 μs. Their timer/counters can be clocked at 96 MHz, so about 10.5 ns/tick, but would yield a square pulse (that may or may not degenerate into what you need 8-).

Overall, I don't think an Arduino is the right tool for the job. Maybe something like the (very fast) Teensy 4.0 could do it, but I don't know much about those.


body:
I am currently using Arduino Mega to use a LED matrix and a NRF24L01 transceiver.

for LED matrix, I use MD_MAX72xx library. While for the transceiver I use the RF24 library.

I am already able to interface Arduino using two different LED matrix, and two matrix board is already using the SPI.

But when I try to add the RF24 library, and radio.begin(); the LED matrix isn't working properly anymore.

Here is my whole code:

    #include <MD_MAX72xx.h>
    #include <SPI.h>
    #include <Servo.h>

    #include <nRF24L01.h>
    #include <RF24.h>

    #define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }

    #define BUF_SIZE      75  // text buffer size
    #define CHAR_SPACING  3   // pixels between characters
    #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
    #define MAX_DEVICES 4

    const int buzzer_pin = 26;
    const int servo_pin = 28;

    unsigned long buzz_time;
    unsigned long sys_time;
    String buzz_type = "off";
    int buzz_count = 0;
    char charr[50];

    Servo myservo;

    RF24 radio(30, 32); // CE, CSN
    const byte address[6] = "GLN71";
    //const byte address[5] = {'R','x','A','A','A'};

    struct LineDefinition
    {
      MD_MAX72XX  mx;
      char    message[BUF_SIZE];
      boolean newMessageAvailable;    // true if new message arrived
    };

    struct LineDefinition  Line[] =
    {
      { MD_MAX72XX(HARDWARE_TYPE, 51, 52, 53, MAX_DEVICES), "MAX", true },
      { MD_MAX72XX(HARDWARE_TYPE, 51, 52,  49, MAX_DEVICES), "MAX", true }
    };

    #define MAX_LINES   (sizeof(Line)/sizeof(LineDefinition))

    void printText(uint8_t lineID, uint8_t modStart, uint8_t modEnd, char *pMsg)
    // Print the text string to the LED matrix modules specified.
    // Message area is padded with blank columns after printing.
    {
      uint8_t   state = 0;
      uint8_t   curLen;
      uint16_t  showLen;
      uint8_t   cBuf[8];
      int16_t   col = ((modEnd + 1) * COL_SIZE) - 1;

      Line[lineID].mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);

      do     // finite state machine to print the characters in the space available
      {
        switch(state)
        {
          case 0: // Load the next character from the font table
            // if we reached end of message, reset the message pointer
            if (*pMsg == '\0')
            {
              showLen = col - (modEnd * COL_SIZE);  // padding characters
              state = 2;
              break;
            }

            // retrieve the next character form the font file
            showLen = Line[lineID].mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
            curLen = 0;
            state++;
            // !! deliberately fall through to next state to start displaying

          case 1: // display the next part of the character
            Line[lineID].mx.setColumn(col--, cBuf[curLen++]);

            // done with font character, now display the space between chars
            if (curLen == showLen)
            {
              showLen = CHAR_SPACING;
              state = 2;
            }
            break;

          case 2: // initialize state for displaying empty columns
            curLen = 0;
            state++;
            // fall through

          case 3: // display inter-character spacing or end of message padding (blank columns)
            Line[lineID].mx.setColumn(col--, 0);
            curLen++;
            if (curLen == showLen)
              state = 0;
            break;

          default:
            col = -1;   // this definitely ends the do loop
        }
      } while (col >= (modStart * COL_SIZE));

      Line[lineID].mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
    }

    void buzz_start(){
        buzz_count = 5;
        buzz_time = millis();
    }

    void buzz_call(){
      if(buzz_count > 0){
        if(millis() >= buzz_time){
          if(buzz_type == "off"){
            tone(buzzer_pin, 1000);
            buzz_type = "on";
          }else{
            noTone(buzzer_pin);
            buzz_type = "off";
            buzz_count--;
          }
          buzz_time = millis() + 300;
        }
      }
    }

    void setup()
    {
      Serial.begin(57600);
      pinMode(buzzer_pin, OUTPUT);

      myservo.attach(servo_pin);

      tone(buzzer_pin, 1000);
      Serial.println("BEGIN");

      for (uint8_t i=0; i<MAX_LINES; i++){
        Line[i].mx.begin();
      }

      radio.begin();
      radio.openReadingPipe(20, address);
      radio.setPALevel(RF24_250KBPS);
      radio.startListening();

      String charrr = "STOP";
      charrr.toCharArray(charr, 50);
      printText(1, 0, MAX_DEVICES-1, charr);

      myservo.write(90);
      delay(500);
      myservo.write(180);

      noTone(buzzer_pin);
      sys_time = millis();
    }

    int counter = 10;
    int disp = 0;
    void loop()
    {
      String charrr = String(counter);
      charrr.toCharArray(charr, 50);
      printText(0, 0, MAX_DEVICES-1, charr);
      if(counter == 0){
        counter = 9;
        if(disp == 0){
         disp = 1;
         String charrr = "  GO";
         charrr.toCharArray(charr, 50);
         printText(1, 0, MAX_DEVICES-1, charr);
         myservo.write(90);
         buzz_start();
        }else{
         disp = 0;
         String charrr = "STOP";
         charrr.toCharArray(charr, 50);
         printText(1, 0, MAX_DEVICES-1, charr);
         buzz_start();
         myservo.write(180);
        }
      }
      if(millis() >= sys_time){
        counter--;
        sys_time = millis() + 1000;
      }

      buzz_call();

    }

I think the problem here is not connection, but with the initalization of the RF24, and radio.begin();

title: Problem with SPI when using rf24 NRF24L01 transceiver with LED matrix MD_MAX72xx

Answers: 1

body:
I looked into the source code of the MD_MAX72XX library. The constructor with SPI pins starts software SPI.

Use the `MD_MAX72XX::MD_MAX72XX(moduleType_t mod, uint8_t csPin, uint8_t numDevices):` constructor to work with SPI hardware/library with all devices.

    struct LineDefinition  Line[] =
    {
      { MD_MAX72XX(HARDWARE_TYPE, 53, MAX_DEVICES), "MAX", true },
      { MD_MAX72XX(HARDWARE_TYPE, 49, MAX_DEVICES), "MAX", true }
    };

Or if the MD_MAX72XX worked for you with software SPI, then use some other pins then hardware SPI pins to make hardware SPI free for the NRF24L01.

    struct LineDefinition  Line[] =
    {
      { MD_MAX72XX(HARDWARE_TYPE, SW_SPI_SI, SW_SPI_CLK, MAX1_CS, MAX_DEVICES), "MAX", true },
      { MD_MAX72XX(HARDWARE_TYPE, SW_SPI_SI, SW_SPI_CLK, MAX2_CS, MAX_DEVICES), "MAX", true }
    };


body:
    #define TIM2_EN() (TIMSK2 = 0x02)
    #define TIM2_DIS() (TIMSK2 = 0x00)

    //HEART SENSOR
    // Include Libraries
    #include "Arduino.h"

    class PulseSensor
    {
    public:
      static void begin(int pulsePin);

      static volatile int BPM;           // used to hold the pulse rate
      static volatile int Signal;        // holds the incoming raw data
      static volatile int IBI;           // holds the time between beats, must be seeded!
      static volatile boolean QS;        // becomes true when Arduoino finds a beat.
    };

    // Pin Definitions
    #define HEARTPULSE_PIN_SIG  A0

    // Global variables and defines

    // object initialization
    PulseSensor heartpulse;

    volatile int rate[10];                        // array to hold last ten IBI values
    volatile unsigned long sampleCounter = 0;     // used to determine pulse timing
    volatile unsigned long lastBeatTime = 0;      // used to find IBI
    volatile int P =512;                          // used to find peak in pulse wave, seeded
    volatile int T = 512;                         // used to find trough in pulse wave, seeded
    volatile int thresh = 512;                    // used to find instant moment of heart beat, seeded
    volatile int amp = 100;                       // used to hold amplitude of pulse waveform, seeded
    volatile boolean firstBeat = true;            // used to seed rate array so we startup with reasonable BPM
    volatile boolean secondBeat = false;          // used to seed rate array so we startup with reasonable BPM
    volatile boolean Pulse = false;               // true when pulse wave is high, false when it's low
    volatile int pulsePin;

    volatile int PulseSensor::IBI = 600;          // holds the time between beats, must be seeded!
    volatile int PulseSensor::BPM;                // used to hold the pulse rate
    volatile int PulseSensor::Signal;             // holds the incoming raw data
    volatile boolean PulseSensor::QS = false;     // becomes true when Arduino finds a beat

    void PulseSensor::begin(int pPin)
    {
      pinMode(pulsePin, INPUT);
      pulsePin = pPin;

      // Initializes Timer1 to throw an interrupt every 2ms.
      TCCR1A = 0x00;
      TCCR1B = 0x0C;  // CTC (Compare match mode) and ClockIO/256
      OCR1A = 0x7C;   // 2 ms
      TIMSK1 = 0x02;
      sei();             // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
    }

    // THIS IS THE TIMER 1 INTERRUPT SERVICE ROUTINE.
    // Timer 1 makes sure that we take a reading every 2 miliseconds
    ISR(TIMER1_COMPA_vect)
    {                         // triggered when Timer1 counts to 124
      cli();                                      // disable interrupts while we do this
      PulseSensor::Signal = analogRead(pulsePin);              // read the Pulse Sensor
      sampleCounter += 2;                         // keep track of the time in ms with this variable
      int N = sampleCounter - lastBeatTime;       // monitor the time since the last beat to avoid noise

      //  find the peak and trough of the pulse wave
      if(PulseSensor::Signal < thresh && N > (PulseSensor::IBI/5)*3){       // avoid dichrotic noise by waiting 3/5 of last IBI
        if (PulseSensor::Signal < T){                        // T is the trough
          T = PulseSensor::Signal;                         // keep track of lowest point in pulse wave
        }
      }

      if(PulseSensor::Signal > thresh && PulseSensor::Signal > P){          // thresh condition helps avoid noise
        P = PulseSensor::Signal;                             // P is the peak
      }                                        // keep track of highest point in pulse wave

      //  NOW IT'S TIME TO LOOK FOR THE HEART BEAT
      // signal surges up in value every time there is a pulse
      if (N > 250){                                   // avoid high frequency noise
        if ( (PulseSensor::Signal > thresh) && (Pulse == false) && (N > (PulseSensor::IBI/5)*3) )
        {
          Pulse = true;                               // set the Pulse flag when we think there is a pulse
          PulseSensor::IBI = sampleCounter - lastBeatTime;         // measure time between beats in mS
          lastBeatTime = sampleCounter;               // keep track of time for next pulse

          if(secondBeat){                        // if this is the second beat, if secondBeat == TRUE
            secondBeat = false;                  // clear secondBeat flag
            for(int i=0; i<=9; i++){             // seed the running total to get a realisitic BPM at startup
              rate[i] = PulseSensor::IBI;
            }
          }

          if(firstBeat){                         // if it's the first time we found a beat, if firstBeat == TRUE
            firstBeat = false;                   // clear firstBeat flag
            secondBeat = true;                   // set the second beat flag
            sei();                               // enable interrupts again
            return;                              // IBI value is unreliable so discard it
          }

          // keep a running total of the last 10 IBI values
          word runningTotal = 0;                  // clear the runningTotal variable

          for(int i=0; i<=8; i++){                // shift data in the rate array
            rate[i] = rate[i+1];                  // and drop the oldest IBI value
            runningTotal += rate[i];              // add up the 9 oldest IBI values
          }

          rate[9] = PulseSensor::IBI;                          // add the latest IBI to the rate array
          runningTotal += rate[9];                // add the latest IBI to runningTotal
          runningTotal /= 10;                     // average the last 10 IBI values
          PulseSensor::BPM = 60000/runningTotal;               // how many beats can fit into a minute? that's BPM!
          PulseSensor::QS = true;                              // set Quantified Self flag
          // QS FLAG IS NOT CLEARED INSIDE THIS ISR
        }
      }

      if (PulseSensor::Signal < thresh && Pulse == true){   // when the values are going down, the beat is over
        Pulse = false;                         // reset the Pulse flag so we can do it again
        amp = P - T;                           // get amplitude of the pulse wave
        thresh = amp/2 + T;                    // set thresh at 50% of the amplitude
        P = thresh;                            // reset these for next time
        T = thresh;
      }

      if (N > 2500){                           // if 2.5 seconds go by without a beat
        thresh = 512;                          // set thresh default
        P = 512;                               // set P default
        T = 512;                               // set T default
        lastBeatTime = sampleCounter;          // bring the lastBeatTime up to date
        firstBeat = true;                      // set these to avoid noise
        secondBeat = false;                    // when we get the heartbeat back
      }

      sei();                                   // enable interrupts when youre done!
    } // end isr

    //LDR SENSOR
    int sensorPin = A1; // select the input pin for LDR
    int sensorValue = 0; // variable to store the value coming from the sensor

    //LCD
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

    //DHT
    #include "dht.h"
    int dht_apin = 2;
    dht DHT;

    //HEART RATE SENSOR
    unsigned long current_time,start_time=0;
    int BPM,Interval;

    void setup(){

      Serial.begin(115200);
      heartpulse.begin(HEARTPULSE_PIN_SIG);
      delay(1500);
      lcd.init();          // initialize the lcd
      lcd.backlight();
      lcd.print("  INITIALISING");
      delay(2500);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print(" CHECKING HEART");
      lcd.setCursor(0,1);
      lcd.print(" RATE NOW......");
      delay(2000);
      lcd.clear();
    }

    void loop() {

      current_time = millis();
      if ( current_time-start_time < 30000 )  {
        BPM = heartpulse.BPM;
        Interval = heartpulse.IBI;
        lcd.print(" SYNCHRONIZING  ");
        lcd.setCursor(0,1);
        lcd.print("   BEATS:");
        lcd.print(BPM);
        lcd.clear();
      } else  {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("BEATS PER MINUTE");
        lcd.setCursor(6,1);
        lcd.print(BPM);
        Serial.print(BPM);
        Serial.println('b');
        delay(4000);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" BEAT INTERVAL  ");
        lcd.setCursor(7,1);
        lcd.print(Interval);
        Serial.print(Interval);
        Serial.println('p');
        delay(4000);
        TIM2_DIS(); //Enable TIMER2 Interrupt
        DHT.read11(dht_apin);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("    HUMIDITY    ");
        lcd.setCursor(6,1);
        lcd.print(DHT.humidity);
        lcd.print("%");
        Serial.print(DHT.humidity);
        Serial.println('h');
        delay(4000);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("  TEMPERATURE  ");
        lcd.setCursor(5,1);
        lcd.print(DHT.temperature);
        lcd.print("C");
        Serial.print(DHT.temperature);
        Serial.println('t');
        TIM2_EN(); //Disable TIMER2 Interrupt
        delay(4000);
        sensorValue = analogRead(sensorPin); // read the value from the sensor
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("LIGHT INTENSITY");
        lcd.setCursor(7,1);
        lcd.print(sensorValue);
        Serial.print(sensorValue);
        Serial.println('l');
        delay(4000);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" CHECKING HEART");
        lcd.setCursor(0,1);
        lcd.print(" RATE NOW......");
        delay(2000);
        lcd.clear();
        start_time = millis();
      }
    }

I am trying to run LDR,PULSE AND DHT11 sensor together. DHT11 was not giving out readings along with pulse sensor before so I searched stack exchange and found out this solution.

> https://arduino.stackexchange.com/questions/21489/dht11-and-pulse-sensor-incompatibility

But now the problem is Arduino gets stuck at the line when I disable timer 2 interupt -

    TIM2_EN(); //Disable TIMER2 Interrupt

Any solution?

title: Arduino stuck when I disable Timer 2 Interrupt

Answers: 0


body: I have implemented an HC-SR04 distance sensor using an Arduino.  After power up, the sensor operates well when objects are within range of the sensor.  However, if the distance to be measured exceeds the maximum (about 15 feet) distance, the sensor times out (which is what I expect).  However, after a time-out and with the distance between the object and the sensor in range, the Echo pin fails to be set low after a trigger pulse is generated.  The only way to fix this condition is to power down the sensor and power it back up again.  (I have verified the state of the Echo pin by using an oscilloscope.)

title: HC-SR04 Echo Pin Fails To Go Low After Trigger Pulse

Answers: 1

body: After many hours of research, I discovered that the problem is related to the fact that there is (apparently) a well-known bug in the HC-SR04 which is a Chinese clone of a Devantech SRF04.  I replaced the HC-SR04 with an SRF04 and the problem was solved.  Now, the ECHO pin always goes low after a trigger and after a time-out (i.e. the object is beyond the maximum measurement distance).


body:
When ever flame is detected sms will be send this is what i am doing,but the  flame and smoke sensor works awesome when they are tested seperately(Without Esp8266) when they are integrated with Esp8266 they are not at all responding to the flame or smoke . I have tested flame Sensor with serial monitor the values are 150,148,147,......
When it is tested without Esp8266 it has given 1000,996.....(Without Flame)
52,64,38.....(With Flame )

[![Wifi Connection to Arduino][1]][1]

  [1]: https://i.stack.imgur.com/6p7UK.png
Flame sensor Connections:
VCC : 5V
GND : GND
D0 : 7`

    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266HTTPClient.h>

    const char *ssid = "NUS_006";
    const char *password = "shankar006";
    int flame=7;
    void setup() {
        delay(1000);
        pinMode(flame,INPUT);
        Serial.begin(115200);
        WiFi.mode(WIFI_OFF);
        delay(1000);
        WiFi.mode(WIFI_STA);
        WiFi.begin(ssid, password);
        Serial.println("");
        Serial.print("Connecting");
        while (WiFi.status() != WL_CONNECTED) {
               delay(500);
               Serial.print(".");
        }
        Serial.println("");
        Serial.print("Connected to ");
        Serial.println(ssid);
        Serial.print("IP address: ");
        Serial.println(WiFi.localIP());
    }

    void loop()
    {
      Serial.print("Flame= ");
      Serial.println(digitalRead(flame));
      delay(3000);
    }

title: Flame sensor and MQ2 sensor not working with Esp8266?

Answers: 0


body:
By playing with some examples I found the following construct:

`void Show(int nav = 0) // -1 top, 1 bottom`

and I wondered what effect it has to initialize the handover parameters in the function declarations, I never noticed such an construct consciously.

So I made a small demo:

    #include <M5Stack.h> //necessary for my board
      int a;
      int b;
      int c;

    int addFunction(int x = 3, int y = 3){
      int result;
      result = x + y;
      return result;
    }

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

      // testcase 1
      a = 1;
      b = 2;
      c = addFunction(a, b);
      Serial.println("testcase 1:");
      Serial.println((String)a + " + " + b + " = " + c);

       // testcase 2
      a = 1;
      b = 2;
      c = addFunction();
      Serial.println("testcase 2:");
      Serial.println((String)a + " + " + b + " = " + c);

       // testcase 3
      a = 1;
      b = 2;
      c = addFunction(a);
      Serial.println("testcase 3:");
      Serial.println((String)a + " + " + b + " = " + c);
    }

    void loop() {
    }

The output was:

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

So I learnd:

 - if you hand over parameters, the initialization is ignored, if you call the function without handing over paramters, the functions works with the init values.

 - if you handover only one parameter it will be assigned to the first in the declaration.

**Question:**

Is there a syntax possible to only call the function with the second parameter, so that for the first paramter the intialized value of the declaration is used? Spoken for this example with a = 1, b = 2 you only handover b and the expected result would be 5.

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

title: Initializing variables of a function

Answers: 2

body:
This is (unfortunately) not an Arduino question. It is actually about the syntax of C++ which is a rather complex language.

The mechanism you have discovered is called **default arguments**. The function prototype or definition may contain the default values of the arguments. As this is a list the default values are restricted from right to left. It is not possible to use a default parameter for argument to the left of a given argument. The order is strictly right to left.

    f(int x = 0, int y = 1, int z = 2)

    f(1,2,3) binds x = 1, y = 2, z = 3
    f(1,2) equals f(1,2,2) binds x = 1, y = 2, z = 2
    f(1) equals f(1,1,2) binds x = 1, y = 1, z = 2
    f() equals f(0,1,2) binds x = 0, y = 1, z = 2

There is a syntax for struct initialization (aka aggregate initialization) in C++ that allows naming of struct field values. This type of naming is not allowed for function calls.

Please read https://en.cppreference.com/w/cpp/language/default_arguments, https://en.cppreference.com/w/cpp/language/aggregate_initialization and https://en.cppreference.com/w/cpp/utility/functional/bind for more details. And a good C++ book.

There are languages that allow default arguments and named parameters e.g. C#, Python, Ruby and Smalltalk. Please see https://en.wikipedia.org/wiki/Named_parameter.

Cheers!

(Update)

Below is a rewrite of @VE7JRO Add function class using cast operator to perform the evaluation:

    class Add
    {
    public:
      Add(int x, int y) : m_x(x), m_y(y) {}
      operator int() { return m_x + m_y; }
      void x(int x) { m_x = x; }
      void y(int y) { m_y = y; }
      int print(Print& outp) {
        int res;
        res = outp.print(F("Add(x="));
        res += outp.print(m_x);
        res += outp.print(F(",y="));
        res += outp.print(m_y);
        res += outp.print(F(")"));
        return res;
      }
    private:
      int m_x, m_y;
    };

    Add func(1,2);

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

      func.print(Serial);
      Serial.print(F("="));
      Serial.println(func);

      func.x(12);
      func.print(Serial);
      Serial.print(F("="));
      Serial.println(func);

      func.y(13);
      func.print(Serial);
      Serial.print(F("="));
      Serial.println(func);
    }

    void loop() {
    }

body:
If your function is inside a class, you can set either variable, both variables or use the defaults.

    class Add{

        int a, b;

      public:

        Add(): a(1), b(2){}

        int AddTwoIntegers(){
          return a + b;
        }

        void SetInt1(int int1){
          a = int1;
        }

        void SetInt2(int int2){
          b = int2;
        }

    };

    Add Test1;

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

      Serial.print("Test default values = ");
      Serial.println(Test1.AddTwoIntegers());

      Test1.SetInt2(4);
      Serial.print("Set b = 4 then add to a = ");
      Serial.println(Test1.AddTwoIntegers());
    }

    void loop(){}


body:
[![enter image description here][1]][1]I was recently experimenting with 20x4 lcd display with my Arduino Mega board. The connections which I followed are shown in the picture attached. I am very much sure about the connections and code written in the Arduino IDE. Everything is compiled and uploaded properly on my board. ***However the problem I found is the 20x4 lcd display only shows two alternate block lines and nothing else!*** To resolve this I tried following things:

1. I made sure multiple times the hard wire connections between Arduino and display and found all are as per requirement.
2. I made sure the proper coding with initialization.
3. I tried changing the value of 10KOhm pot in order to control the contrast setting of lcd.
4. I made sure about connecting the R/W pin of lcd to ground.
5. I tried replacing the lcd display with another same unit.

With above troubleshooting the problem still persists. Can anybody will suggest what could be the issue?

Suggestions are highly appreciated!
Thanks and regards,
VK

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

title: 20x4 lcd display problems

Answers: 0


body:
I really need your help. I use VisualStudio and PlatformIo I still get this error:
    > Linking .pioenvs\esp12e\firmware.elf
    > .pioenvs\esp12e\src\main.cpp.o:(.data.DebugX+0x0): multiple definition of `DebugX'
    > .pioenvs\esp12e\src\customFunctions.cpp.o:(.data.DebugX+0x0): first defined here
    > collect2.exe: error: ld returned 1 exit status
    > *** [.pioenvs\esp12e\firmware.elf] Error 1

I use header guards in my file, so I do not understand why is this part of code redeclared. I had to miss some elementary in cpp programming but I still can't get it to work.

Copy of my project:
https://bitbucket.org/fires/programingtesting/src/master/ESP8266/cpp/RedefinedError/

main.cpp
```
    #include <Arduino.h>;
    #include "../include/defines.h"
    //#include "../include/customFunctions.h"
    // Time
    uint32_t mTimeToSec = 0;
    uint32_t mTimeSeconds = 0;
    void setup() {
    etc. etc. etc.
```

customFunction.h
```
    #pragma once
    #ifndef CUSTOMFUNCTIONS_H
    #define CUSTOMFUNCTIONS_H
    void connectWiFi();
    void initializeOTA();
    #endif
```

defines.h
```
    #pragma once
    #ifndef DEFINES_H
    #define DEFINES_H
    #include <jled.h>
    #define BowlingLed 5
    #define StatekLed 4
    int DebugX = 1;
    #endif
```

Thanks for the help, I read many articles and many issues but I still do not understand why DebugX is redefined if it is in header guard.

title: Multiple definitions of "xxxx"

Answers: 1

body:
Included files are included before compilation, really replacing the #include with the content of the file.

If you write `int DebugX = 1;` you define a variable. And it is defined in every source file which includes it. Then the linker finds it in more then one unit and ends with "multiple definitions" error.

The variable must be defined only in one compilation unit (.c, .cpp). For example in your case customFunctions.cpp. To make it available in other source files put `extern int DebugX;` into the .h file.


body:
I am driving motors for my line-follower project . The circuit schematic is given below [![Circuit schematic][1]][1]

  [1]: https://i.stack.imgur.com/7bVmC.jpg
The power source is a 11.1V 2200mAh 25C Lipo . Practically the cells give 11.5-12V. I used a switching buck regulator to step down the voltage. However , when i run my robot on track after few seconds,the arduino tends to reset and run again. This problem typically arises when i drive the motors at higher PWM(above 180 on analogWrite function). Since i use PID, limiting the PWM means i have to drive at lower speeds which i do not want.

I am providing links for the items i used for my circuit:

  1. [buck converter](https://www.amazon.in/LM2596S-Converter-Module-Supply-1-23V-30V/dp/B0784PYZ97/);

  2. [motor driver](https://www.amazon.in/Generic-E_14013096-Tb6612Fng-Arduino-Microcontroller/dp/B01DAA6GMC/);

  3. [IR sensor module](https://www.amazon.in/Products-Channel-Analogue-Digital-Follower/dp/B07GXL5L7J/);

  4. [DC motors](https://www.amazon.in/Invento-Kg-cm-Shaft-Torque-Geared/dp/B07CKMFYDG/).

The sensor array draws 150mA at peak. Any suggestions as to where the problem might lie would be of great help. Thank you .

EDIT 1: Changed the input voltage Vin to 7.9V through the buck converter .
        The problem still persists .

title: Why is Arduino resetting while driving motors?

Answers: 5

body: The VIN pin goes to a 5V voltage regulator on the Arduino and needs at least about 7V minimum to work properly.  If you want to supply 5V to an Arduino do it either on the 5V pin or via the USB connector.  The VIN pin should receive 7V to 12V.

body:
Resetting is due either to a software bug or voltage sag, and since it correlates with driving the motors harder, it's almost certainly the latter. You probably suspected as much since you mentioned the current draw of the sensor array. A quick experiment - disconnecting the sensors (and possibly a software patch to keep the robot running straight, without them) might help you discover the reason.

Each chip and each of its pin drivers has a current budget. It would be a good idea to look at the max current spec of the Atmega2560 and its pin drivers, and any other current specs mentioned in the datasheet, and make sure you're not trying to run it out of spec. The buck converter will have a limit, too, so make sure you're within its spec. If the output regulation of the buck converter is good enough, you can regulate it to 5v and bypass the Mega's on board regulator, for another saving.

body: One major drawback to working with motors is the large amounts of electrical noise they produce. This noise can interfere with your sensors and can even impair your microcontroller by causing voltage dips on your regulated power line. Large enough voltage dips can corrupt the data in microcontroller registers or cause the microcontroller to reset. You can avoid this problem by soldering capacitors along your motor terminals. Use 1µF ceramic capacitors for example

body:
You should either feed the 5.5v from the buck converter to the 5v pin of the arduino, or the 11.5v to the Vin.
The arduino board contains its own 5v converter (and a 3.3v but that's not in question here). That takes the voltage of the Vin pin and converts it to 5v for the board to use. This regulated 5 v is available on the 5v pin for your sensors for example.

You can also power it directly on the 5v pin, but that requires regulated 5v. This is also how it is powered through USB which supplied regulated 5 v.

The 5.5 v from your buck should be fine for this, by you don't need it. Put the "raw" 11.5 to the Vin pin.

body:
This is the common issue when trying to connect power and digital circuits together. Probably, when motor starts, there is a short-time voltage drop in **Vin** due to high motor start current. Consider to use Schottky diode and capacitor to protect digital power circuit from transitional currents.[![enter image description here][1]][1]

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


body:
Having board esp32 devkit v1, to get started with arduino ide (installed recommended boards for esp32) I marked board as`DOIT ESP32 DEVKIT V1` (as no other options as like `ESP32 DEVKIT V1` ) so upload gets this error

        esptool.py v2.6
    Serial port COM3
    Traceback (most recent call last):
    File "esptool.py", line 2959, in <module>
    File "esptool.py", line 2952, in _main
    File "esptool.py", line 2652, in main
    File "esptool.py", line 222, in __init__
    File "site-packages\serial\__init__.py", line 88, in serial_for_url
    File "site-packages\serial\serialwin32.py", line 62, in open
    serial.serialutil.SerialException: could not open port 'COM3': WindowsError(31, 'A device attached to the system is not functioning.')
    Failed to execute script esptool
    the selected serial port Failed to execute script esptool
     does not exist or your board is not connected

so how do I upload my programs?
I would be highly obliged if you could please help me solve this problem.
Thank you.

title: WindowsError(31, 'A device attached to the system is not functioning.') in arduino

Answers: 1

body: I got this error.  Then switching USB ports fixed the problem.  Showed up on COM3 in either place. I just switched from a built-in USB port to on off a hub, and it started working.


body:
I have 6 5V solenoids connected to an Arduino Uno, each of them with a TIP120 transistor, diode and resistor. Exactly like https://core-electronics.com.au/tutorials/solenoid-control-with-arduino.html but 6 times. I'm using a 9V battery connected to the DC input, as well as USB input to my PC.

Now the problem is that if I activate 5 or 6 solenoids at once, the Arduino seems to get interrupted / lose all power for a second (disconnect sound from the PC and no activity). I've tested them one by one and everything works, but I can activate at most 4 solenoids at once.

What am I missing? Do I need more power?

title: Arduino Uno with 6x 5V solenoids + 9V battery - Not enough power?

Answers: 3

body:
>I'm using a 9V battery connected to the DC input

Well, there's your problem. Those 9V PP3 batteries are barely enough to power the Arduino by itself. Add anything like motors and solenoids and you're going to have problems. Big problems.

Ditch the PP3 battery. It's only suitable for very low current devices, like smoke alarms. For anything more you need at least multiple series AA batteries.

Also the solenoids must be powered direct from your power source (or through their own regulator if needed), since the Arduino's on-board regulator will go into thermal shutdown quite quickly with 9V in and a large current draw.

body: Another possibility is to use latching solenoids controlled by an H-bridge so that they only need power to turn on or turn off. However, I don't know if they are available for your application. When I looked into latching irrigation valves they were much more expensive than simple solenoid valves.

body: You're experiencing a lack of available current. When the solenoids are operating, the system is trying to draw more current than the battery can provide, so what happens instead is the voltage starts to drop. (I can't remember exactly why this happens right now). When this happens the arduinos power supply detects an under-voltage condition and shuts down, but as soon as it shuts down the current draw tanks and the voltage rises again causing the system to restart. Essentially, the answer to this is to provide your system with a larger current source and the problem should go away.


body:
Using the delay function inside of an ISR is frowned upon when programming in an Arduino. The general response to solve this desire is to design the program to delay in a more cleanly way outside of the interrupt.

My question is simply why. Why does putting a delay() inside of an ISR cause wonky behavior with the Arduino. Whats going on under the hood?

title: Arduino delay inside of an Interrupt

Answers: 3

body:
Because a delay inside an interrupt causes that interrupt and other (lower priority) interrupts not to execute anymore until the delay is over.

Assume in an ISR you handle the incoming bytes from a UART. If you add a delay in the ISR, and the buffer of the UART gets full, it will overflow and you miss bytes.

body:
> Why is putting a delay() inside of an ISR cause wonky behavior with the Arduino. Whats going on under the hood?

The first problem is that delay() is a busy loop monitoring millis(). The value that millis() returns will not change inside an ISR as interrupts are turned off inside an ISR; this is why ISRs must be as short and fast as possible, or they will interfere with other interupts

So if you call delay() within an ISR your poor AVR is now deadlocked! It is waiting for something to happen that can now never happen.

A second problem is that if your ISR takes too long, you can miss other interrupts; millis() and micros() can miss ticks and become inaccurate!

body:
This is an addition to esoterik's answer.

Most of the times, that people try to use `delay()` inside an ISR it is a poor design choice to even use it in a general way, that will lead to the described problems (waiting forever or missing other interrupts). `delay()` is a simple function mainly for beginners with very simple programs. It is a simple starting point. Mostly the use of it in any program is not a good choice, since you are busy waiting without being able to do something else (like responding to user input). There are better ways, involving `millis()` itself, that keep your program extendable (so that, if you want to add a functionality, this will not be blocked by the first part of the code). And when your program reaches the complexity of using own ISRs, you should avoid `delay()`, unless you really know, what you are doing.

IMO at some (rather early) point, every Arduino programmer has to learn how to use `millis()` to do timed code execution. You can look at the `BlinkWithoutDelay` example, that comes with the Arduino IDE.


body:
I did some prototyping with arduino nano in breadboard. And then after i done with the design, I was gonna implement it in a printed pcb so i need to remove the nano from breadboard. And this is when the disaster happened.

The board is kinda hard to pull by hand, so i use a long-thin screwdriver in the gutter to pull the nano up (just like i did many times to dip ICs with no problem). And successfully detached the nano from breadboard and also broke the tantalum under the nano in the process. So the question is:

1. How do you usually remove the nano board from breadboard safely? And
2. The tantalum i broke is 4.7uF smd. I can't find any 4.7uF tantalum in nearby shops, but i have electrolyte caps rated 4.7uF 16v. Can i use it for replacement?

title: How to safely remove arduino nano from breadboard?

Answers: 2

body: I also had the same problem but what I had done was, I pressed the breadboard with my leg and used my all fingers to grip the nano and pulled it with my full force and then it is done. And no parts were damaged and id you lost any part you can search on https://octopart.com/ .

body:
> How do you usually remove the nano board from breadboard safely? And

If you can't remove it by hand (grip it lengthwise and ease up each end with your finger / thumb levering against the breadboard) then you need a lever. The best is a plastic spudger, such as this:

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

The plastic will flex rather than damage the Arduino. Using a screwdriver can, as you have noticed, damage the Arduino.

> The tantalum i broke is 4.7uF smd. I can't find any 4.7uF tantalum in nearby shops, but i have electrolyte caps rated 4.7uF 16v. Can i use it for replacement?

Sure. All that is, is a reservoir capacitor on the USB input. The value isn't super-critical, as long as the voltage is above 5V. It's not, strictly speaking, even needed. You can just remove it completely and clean up the pads to ensure there's no shorts. The board should still work fine.

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


body:
I have a [adafruit rbg 16x2 lcd with shield kit][1] and am trying to connect it to an arduino uno. The only thing is the assembly instructions have the lcd basically using every pin on the arduino, even tho it says its not for connections. Since we are using many of the pins already on the board, can I wire it to the board without soldering it to every pin, essentially only wiring to the few necessary pins?

Sorry, I am very new at this. Thank you for the help.

EDIT: Was essentially looking for the follwing diagram. Thanks to all!
[![enter image description here][2]][2]

  [1]: https://learn.adafruit.com/rgb-lcd-shield
  [2]: https://i.stack.imgur.com/b2vgu.png

title: Adafruit RGB LCD w/ Shield kit connection to arduino uno?

Answers: 1

body:
The idea of shields is that they (in theory) can be stackable.
(In practice they are usually not)
This means that technically you can do this:

[![stack of shields][1]][1]

That's why by design every shield connects to every Arduino pin but uses only some of them. That way shield is mechanically well attached to the Arduino, and can pass "unused" pins to the shield above it.

Your shield is designed to be always "on top" so I think it only connects to some pins just for mechanical support. Technically the LDC screen needs only 6 pins and 1 pin per button.

EDIT:
I read now that the shield you got uses only 2 pins and communicates using I2C bus (which is perfect) so I'm 100% sure that it's designed to be on top of the stack and work together with other shields and uses extra pins for mechanical support.

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


body:
Ardiuno Mega 2560

I have a legacy PCB that connects PORTA, pins = {22, 23, 24, 25, 26, 27, 28, 29} to the PWM input of a set of actuators. The accompanying code made use of an interupt service routine to generate PWM signals. This in turn caused all sorts of other problems for the system.

So, I would like to leverage the Mega's internal counters & use the PWM available on pins = {2, 3, 4, 5, 6, 7, 8, 9} & use the `analogWrite()` function. At present there is nothing else connected to these pins but access is limited.

Before I go down the route of redesigning the PCB I was wondering if it was possible to replicate the outputs of pins {2, 3, 4, 5, 6, 7, 8, 9} to pins {22, 23, 24, 25, 26, 27, 28, 29}?

title: Replicate output of pwm pin on another output pin?

Answers: 1

body:
As Jot wrote, you cannot simply route a signal from pin to pin inside the chip/Arduino. So - unless you redesign the PCP, which would be the cleanest way, or use jumper wires, which is not so clean - you are down to using software PWM. There are also libraries for this, if you don't want to write this yourself, for example the [SoftPWM library][1]. These libraries have their own limits, especially in frequency. Be sure to check, if they fit your needs.

  [1]: https://github.com/bhagman/SoftPWM


body:
Im using **ESP12E DevKit v2** (esp8266 wifi module) board for controlling relays and displaying DHT22 temp,humidity on web server. It runs smoothly but after while i always get a watchdog timer reset. (If i have serial monitor opened up it happens quicker)

I tried adding more delays, yield function, removing serial prints that i use for debugging but nothing helps.
I think it can be caused because my website is being refreshed every 1sec, because i want to display current time and most recent temp,humidity and this was the easiest way to do it. But this WDT reset problem appeared just recently after i added more code and functionality to my site.

Could anyone have a look at my code and give me some advice on what could help or cause the problem?

**Arduino code:**

    // Including the needed libraries
    #include <ESP8266WiFi.h>
    #include <DHT.h>
    #include <NTPClient.h>
    #include <WiFiUdp.h>
    #define DHTTYPE DHT22 // Defining DHT sensor type

    // Network details
    const char* ssid = "Connection1";
    const char* password = "pass";

    // Define NTP Client to get time
    WiFiUDP ntpUDP;
    NTPClient timeClient(ntpUDP);

    // Set web server port number to 80
    WiFiServer server(80);

    // Variable to store the HTTP request
    String header;

    // Decode HTTP GET value
    String valueString = "0";
    int pos1 = 0;
    int pos2 = 0;

    // Variables to store the current output state
    String relay0State = "on";
    String relay1State = "off";
    String relay2State = "off";
    String brightness = "0";

    // Variables to save date and time
    String formattedDate;
    String dayStamp;
    String timeStamp;

    // Variables assigned to pins
    const int relay0 = 16;
    const int relay1 = 5;
    const int relay2 = 4;
    const int DHT1Pin = 0;
    const int DHT2Pin = 2;

    // Initialize DHT sensors
    DHT dht1(DHT1Pin, DHTTYPE);
    DHT dht2(DHT2Pin, DHTTYPE);

    void setup() {
      Serial.begin(115200);
      // Initialize the output variables as outputs
      pinMode(relay0, OUTPUT);
      pinMode(relay1, OUTPUT);
      pinMode(relay2, OUTPUT);
      // Set outputs to LOW
      digitalWrite(relay0, LOW);
      digitalWrite(relay1, LOW);
      digitalWrite(relay2, LOW);

      dht1.begin();
      dht2.begin();

      // Connect to Wi-Fi network with SSID and password
      Serial.print("Connecting to ");
      Serial.println(ssid);
      WiFi.begin(ssid, password);
      delay(3000);
      while (WiFi.status() != WL_CONNECTED) {
        delay(300);
        Serial.print(".");
      }

      // Print local IP address and start web server
      Serial.println("");
      Serial.println("WiFi CONNECTED with IP: ");
      Serial.println(WiFi.localIP());
      server.begin();

      // Initialize a NTPClient to get time
      timeClient.begin();
      // Setting offset time in seconds to adjust for current timezone -> GMT +1 = 3600
      timeClient.setTimeOffset(3600);
    }
    void loop(){
      WiFiClient client = server.available();   // Listen for incoming clients

       while(!timeClient.update()) {
        timeClient.forceUpdate();
      }
      // The formattedDate comes with the following format 2018-05-28T16:00:13Z
      formattedDate = timeClient.getFormattedDate();
      // Extract date
      int splitT = formattedDate.indexOf("T");
      dayStamp = formattedDate.substring(0, splitT);
      // Extract time
      timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);

      if (client) {
        Serial.println("NEW CLIENT");          // Printing a message out in the serial port, if a new client connects
        String currentLine = "";                // String to hold incoming data from the client
        while (client.connected()) {            // loop while the client's connected
          if (client.available()) {             // if there's bytes to read from the client,
            char c = client.read();             // read a byte, then
            //Serial.write(c);                    // print it out the serial monitor
            header += c;
            if (c == '\n') {                    // if the byte is a newline character
              // if the current line is blank, you got two newline characters in a row.
              // that's the end of the client HTTP request, so send a response:
              if (currentLine.length() == 0) {
                // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
                // and a content-type so the client knows what's coming, then a blank line:
                client.println("HTTP/1.1 200 OK");
                client.println("Content-type:text/html");
                client.println("Connection: close");
                client.println();

                // Turns the PINs on and off
              if (header.indexOf("GET /0/on") >= 0) {
                  relay0State = "on";
                  digitalWrite(relay0, HIGH);
                } else if (header.indexOf("GET /0/off") >= 0) {
                  relay0State = "off";
                  digitalWrite(relay0, LOW);
                } else if (header.indexOf("GET /1/on") >= 0) {
                  relay1State = "on";
                  digitalWrite(relay1, HIGH);
                } else if (header.indexOf("GET /1/off") >= 0) {
                  relay1State = "off";
                  digitalWrite(relay1, LOW);
                } else if (header.indexOf("GET /2/on") >= 0) {
                  relay2State = "on";
                  brightness = "75";
                  digitalWrite(relay2, 191);
                } else if (header.indexOf("GET /2/off") >= 0) {
                  relay2State = "off";
                  brightness = "0";
                  digitalWrite(relay2, 0);
                }

                // Read humidity
                float h1 = dht1.readHumidity();
                float h2 = dht2.readHumidity();
                // Read temperature as Celsius (the default)
                float t1 = dht1.readTemperature();
                float t2 = dht2.readTemperature();
                // Read temperature as Fahrenheit (isFahrenheit = true)
                float f1 = dht1.readTemperature(true);
                float f2 = dht2.readTemperature(true);

                // Calculating average temp and humidity from DHT22 sensors
                float temperature = (t1 + t2)/2;
                float temperaturef = (f1 + f2)/2;
                float humidity = (h1 + h2)/2;

                // Display the HTML web page
                client.println("<!DOCTYPE html>");
                client.println("<meta http-equiv=\"refresh\" content=\"1\" name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
                client.println("");
                client.println("<title>Smart TERA</title>  ");
                client.println("

Smart TERA

");
                client.println(timeStamp);
                client.println(" / " + dayStamp);
                client.println("

Temperature: ");
                client.println(temperature);
                client.println("℃ /  ");
                client.println(temperaturef);
                client.println("℉

Humidity: ");
                client.println(humidity);
                client.println("%

Light Brightness:  %
 <input class=\"slider\" type=\"range\" min=\"0\" max=\"100\" step=\"25\" value="+brightness+" id=\"myRange\">");
                client.println("
");

                if(header.indexOf("GET /?value=")>=0) {
                    pos1 = header.indexOf('=');
                    pos2 = header.indexOf('&');
                    valueString = header.substring(pos1+1, pos2);
                    if(valueString == "0" ){
                      relay2State = "off";
                      brightness = "0";
                      digitalWrite(relay2, 0);
                    } else if (valueString == "25"){
                      relay2State = "on";
                      brightness = "25";
                      digitalWrite(relay2, 64);
                    } else if (valueString == "50"){
                      relay2State = "on";
                      brightness = "50";
                      digitalWrite(relay2, 128);
                    } else if (valueString == "75"){
                      relay2State = "on";
                      brightness = "75";
                      digitalWrite(relay2, 192);
                    } else if (valueString == "100"){
                      relay2State = "on";
                      brightness = "100";
                     digitalWrite(relay2, 255);
                    }
               }
                // Display current state, and ON/OFF buttons for controlling relays
                client.println("
Rock Heater - State " + relay0State + "
");
                // If the relay0State is off, it displays the ON button
                if (relay0State=="off") {
                  client.println("
<button class=\"button\">ON</button>
");
                } else {
                  client.println("
<button class=\"button button2\">OFF</button>
");
                }

                client.println("
Humidifier - State " + relay1State + "
");
                if (relay1State=="off") {
                  client.println("
<button class=\"button\">ON</button>
");
                } else {
                  client.println("
<button class=\"button button2\">OFF</button>
");
                }

                client.println("
Light - State " + relay2State + "
");
                if (relay2State=="off") {
                  client.println("
<button class=\"button\">ON</button>
");
                } else {
                  client.println("
<button class=\"button button2\">OFF</button>
");
                }
                client.println("
 ");

                // The HTTP response ends with another blank line
                client.println();
                yield();
                // Break out of the while loop
                break;
              } else { // if you got a newline, then clear currentLine
                currentLine = "";
              }
            } else if (c != '\r') {  // if you got anything else but a carriage return character,
              currentLine += c;      // add it to the end of the currentLine
            }
          } yield();
        }
        // Clear the header variable and close the connection
        header = "";
        client.stop();
        Serial.println("CLIENT DISCONNECTED");
       }
    }

**Error message:**

    Soft WDT reset

    >>>stack>>>

    ctx: sys
    sp: 3fffed40 end: 3fffffb0 offset: 01b0
    3fffeef0:  3ffee990 0abd1a53 60000600 00000001
    3fffef00:  00000000 3ffed9d8 00000000 00000000
    3fffef10:  4022cf78 3ffed9d8 3ffee990 60000600
    3fffef20:  4022f8c1 3ffed9d8 3ffee990 0abd1a53
    3fffef30:  4022f906 3fffdab0 00000000 3fffdcb0
    3fffef40:  3ffee9b8 3fffdab0 00000000 40205d0f
    3fffef50:  40000f49 40000f49 3fffdab0 40000f49
    3fffef60:  40000e19 40001878 00000002 00000000
    3fffef70:  3fffff10 aa55aa55 000000b4 401048e4
    3fffef80:  401048ea 00000002 00000000 3315d4f6
    3fffef90:  4010000d 0c060f10 1427fd57 49e0d507
    3fffefa0:  40100a84 3fffef3c 40100a31 3ffffe88
    3fffefb0:  3fffffc0 00000000 00000000 feefeffe
    3fffefc0:  feefeffe feefeffe feefeffe feefeffe
    3fffefd0:  feefeffe feefeffe feefeffe feefeffe
    3fffefe0:  feefeffe feefeffe feefeffe feefeffe
    3fffeff0:  feefeffe feefeffe feefeffe feefeffe
    3ffff000:  feefeffe feefeffe feefeffe feefeffe
    3ffff010:  feefeffe feefeffe feefeffe feefeffe
    3ffff020:  feefeffe feefeffe feefeffe feefeffe
    3ffff030:  feefeffe feefeffe feefeffe feefeffe
    3ffff040:  feefeffe feefeffe feefeffe feefeffe
    3ffff050:  feefeffe feefeffe feefeffe feefeffe
    3ffff060:  feefeffe feefeffe feefeffe feefeffe
    3ffff070:  feefeffe feefeffe feefeffe feefeffe
    3ffff080:  feefeffe feefeffe feefeffe feefeffe
    3ffff090:  feefeffe feefeffe feefeffe feefeffe
    3ffff0a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff0b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff0c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff0d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff0e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff0f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff100:  feefeffe feefeffe feefeffe feefeffe
    3ffff110:  feefeffe feefeffe feefeffe feefeffe
    3ffff120:  feefeffe feefeffe feefeffe feefeffe
    3ffff130:  feefeffe feefeffe feefeffe feefeffe
    3ffff140:  feefeffe feefeffe feefeffe feefeffe
    3ffff150:  feefeffe feefeffe feefeffe feefeffe
    3ffff160:  feefeffe feefeffe feefeffe feefeffe
    3ffff170:  feefeffe feefeffe feefeffe feefeffe
    3ffff180:  feefeffe feefeffe feefeffe feefeffe
    3ffff190:  feefeffe feefeffe feefeffe feefeffe
    3ffff1a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff1b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff1c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff1d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff1e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff1f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff200:  feefeffe feefeffe feefeffe feefeffe
    3ffff210:  feefeffe feefeffe feefeffe feefeffe
    3ffff220:  feefeffe feefeffe feefeffe feefeffe
    3ffff230:  feefeffe feefeffe feefeffe feefeffe
    3ffff240:  feefeffe feefeffe feefeffe feefeffe
    3ffff250:  feefeffe feefeffe feefeffe feefeffe
    3ffff260:  feefeffe feefeffe feefeffe feefeffe
    3ffff270:  feefeffe feefeffe feefeffe feefeffe
    3ffff280:  feefeffe feefeffe feefeffe feefeffe
    3ffff290:  feefeffe feefeffe feefeffe feefeffe
    3ffff2a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff2b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff2c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff2d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff2e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff2f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff300:  feefeffe feefeffe feefeffe feefeffe
    3ffff310:  feefeffe feefeffe feefeffe feefeffe
    3ffff320:  feefeffe feefeffe feefeffe feefeffe
    3ffff330:  feefeffe feefeffe feefeffe feefeffe
    3ffff340:  feefeffe feefeffe feefeffe feefeffe
    3ffff350:  feefeffe feefeffe feefeffe feefeffe
    3ffff360:  feefeffe feefeffe feefeffe feefeffe
    3ffff370:  feefeffe feefeffe feefeffe feefeffe
    3ffff380:  feefeffe feefeffe feefeffe feefeffe
    3ffff390:  feefeffe feefeffe feefeffe feefeffe
    3ffff3a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff3b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff3c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff3d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff3e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff3f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff400:  feefeffe feefeffe feefeffe feefeffe
    3ffff410:  feefeffe feefeffe feefeffe feefeffe
    3ffff420:  feefeffe feefeffe feefeffe feefeffe
    3ffff430:  feefeffe feefeffe feefeffe feefeffe
    3ffff440:  feefeffe feefeffe feefeffe feefeffe
    3ffff450:  feefeffe feefeffe feefeffe feefeffe
    3ffff460:  feefeffe feefeffe feefeffe feefeffe
    3ffff470:  feefeffe feefeffe feefeffe feefeffe
    3ffff480:  feefeffe feefeffe feefeffe feefeffe
    3ffff490:  feefeffe feefeffe feefeffe feefeffe
    3ffff4a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff4b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff4c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff4d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff4e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff4f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff500:  feefeffe feefeffe feefeffe feefeffe
    3ffff510:  feefeffe feefeffe feefeffe feefeffe
    3ffff520:  feefeffe feefeffe feefeffe feefeffe
    3ffff530:  feefeffe feefeffe feefeffe feefeffe
    3ffff540:  feefeffe feefeffe feefeffe feefeffe
    3ffff550:  feefeffe feefeffe feefeffe feefeffe
    3ffff560:  feefeffe feefeffe feefeffe feefeffe
    3ffff570:  feefeffe feefeffe feefeffe feefeffe
    3ffff580:  feefeffe feefeffe feefeffe feefeffe
    3ffff590:  feefeffe feefeffe feefeffe feefeffe
    3ffff5a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff5b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff5c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff5d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff5e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff5f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff600:  feefeffe feefeffe feefeffe feefeffe
    3ffff610:  feefeffe feefeffe feefeffe feefeffe
    3ffff620:  feefeffe feefeffe feefeffe feefeffe
    3ffff630:  feefeffe feefeffe feefeffe feefeffe
    3ffff640:  feefeffe feefeffe feefeffe feefeffe
    3ffff650:  feefeffe feefeffe feefeffe feefeffe
    3ffff660:  feefeffe feefeffe feefeffe feefeffe
    3ffff670:  feefeffe feefeffe feefeffe feefeffe
    3ffff680:  feefeffe feefeffe feefeffe feefeffe
    3ffff690:  feefeffe feefeffe feefeffe feefeffe
    3ffff6a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff6b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff6c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff6d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff6e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff6f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff700:  feefeffe feefeffe feefeffe feefeffe
    3ffff710:  feefeffe feefeffe feefeffe feefeffe
    3ffff720:  feefeffe feefeffe feefeffe feefeffe
    3ffff730:  feefeffe feefeffe feefeffe feefeffe
    3ffff740:  feefeffe feefeffe feefeffe feefeffe
    3ffff750:  feefeffe feefeffe feefeffe feefeffe
    3ffff760:  feefeffe feefeffe feefeffe feefeffe
    3ffff770:  feefeffe feefeffe feefeffe feefeffe
    3ffff780:  feefeffe feefeffe feefeffe feefeffe
    3ffff790:  feefeffe feefeffe feefeffe feefeffe
    3ffff7a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff7b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff7c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff7d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff7e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff7f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff800:  feefeffe feefeffe feefeffe feefeffe
    3ffff810:  feefeffe feefeffe feefeffe feefeffe
    3ffff820:  feefeffe feefeffe feefeffe feefeffe
    3ffff830:  feefeffe feefeffe feefeffe feefeffe
    3ffff840:  feefeffe feefeffe feefeffe feefeffe
    3ffff850:  feefeffe feefeffe feefeffe feefeffe
    3ffff860:  feefeffe feefeffe feefeffe feefeffe
    3ffff870:  feefeffe feefeffe feefeffe feefeffe
    3ffff880:  feefeffe feefeffe feefeffe feefeffe
    3ffff890:  feefeffe feefeffe feefeffe feefeffe
    3ffff8a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff8b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff8c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff8d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff8e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff8f0:  feefeffe feefeffe feefeffe feefeffe
    3ffff900:  feefeffe feefeffe feefeffe feefeffe
    3ffff910:  feefeffe feefeffe feefeffe feefeffe
    3ffff920:  feefeffe feefeffe feefeffe feefeffe
    3ffff930:  feefeffe feefeffe feefeffe feefeffe
    3ffff940:  feefeffe feefeffe feefeffe feefeffe
    3ffff950:  feefeffe feefeffe feefeffe feefeffe
    3ffff960:  feefeffe feefeffe feefeffe feefeffe
    3ffff970:  feefeffe feefeffe feefeffe feefeffe
    3ffff980:  feefeffe feefeffe feefeffe feefeffe
    3ffff990:  feefeffe feefeffe feefeffe feefeffe
    3ffff9a0:  feefeffe feefeffe feefeffe feefeffe
    3ffff9b0:  feefeffe feefeffe feefeffe feefeffe
    3ffff9c0:  feefeffe feefeffe feefeffe feefeffe
    3ffff9d0:  feefeffe feefeffe feefeffe feefeffe
    3ffff9e0:  feefeffe feefeffe feefeffe feefeffe
    3ffff9f0:  feefeffe feefeffe feefeffe feefeffe
    3ffffa00:  feefeffe feefeffe feefeffe feefeffe
    3ffffa10:  feefeffe feefeffe feefeffe feefeffe
    3ffffa20:  feefeffe feefeffe feefeffe feefeffe
    3ffffa30:  feefeffe feefeffe feefeffe feefeffe
    3ffffa40:  feefeffe feefeffe feefeffe feefeffe
    3ffffa50:  feefeffe feefeffe feefeffe feefeffe
    3ffffa60:  feefeffe feefeffe feefeffe feefeffe
    3ffffa70:  feefeffe feefeffe feefeffe feefeffe
    3ffffa80:  feefeffe feefeffe feefeffe feefeffe
    3ffffa90:  feefeffe feefeffe feefeffe feefeffe
    3ffffaa0:  feefeffe feefeffe feefeffe feefeffe
    3ffffab0:  feefeffe feefeffe feefeffe feefeffe
    3ffffac0:  feefeffe feefeffe feefeffe feefeffe
    3ffffad0:  feefeffe feefeffe feefeffe feefeffe
    3ffffae0:  00000000 00000000 00000020 401013da
    3ffffaf0:  3ffe9680 401047c0 3fff0154 000000fd
    3ffffb00:  00000001 401039e3 3ffed800 3ffed848
    3ffffb10:  40103e46 00000000 00000020 401013da
    3ffffb20:  00000005 00000000 00000020 401013da
    3ffffb30:  00000000 00000000 00000020 401013da
    3ffffb40:  3ffe9680 401047c0 3fff0154 00000000
    3ffffb50:  00000001 401039e3 3ffed800 401022c2
    3ffffb60:  40103e46 00000000 00000000 401022c2
    3ffffb70:  40103729 00040000 7fffffff 00000000
    3ffffb80:  00000022 40103726 00040000 00000000
    3ffffb90:  00000000 00000000 0000001f 401050bd
    3ffffba0:  4000050c 00080000 00002000 4000050c
    3ffffbb0:  40229838 00000030 0000001b ffffffff
    3ffffbc0:  40229836 00000023 00000020 00000005
    3ffffbd0:  3ffe95b4 00000020 3ffe951c 00000000
    3ffffbe0:  00000005 3ffe9514 00000001 3ffecdc8
    3ffffbf0:  3ffef854 00000001 3fff0a30 00000030
    3ffffc00:  3ffe9685 401047db 3ffed110 3ffee2a8
    3ffffc10:  00000000 00000000 00000020 000000fa
    3ffffc20:  00000004 00000000 00000020 401013da
    3ffffc30:  3ffe9684 401047a6 3ffecdc8 401013da
    3ffffc40:  00000005 00000000 00000020 401013da
    3ffffc50:  3ffe9685 401047db 3ffed110 3ffed800
    3ffffc60:  401020f1 3ffed110 3ffed800 000000f4
    3ffffc70:  00007fff 06460509 402296d3 00000001
    3ffffc80:  ffffffff 00000000 3ffe97d1 00000008
    3ffffc90:  40229722 3ffecdf0 3ffef854 00000001
    3ffffca0:  4022982e 3ffecdf0 3ffef854 3ffecdf0
    3ffffcb0:  00000005 00000005 00000008 3fff1250
    3ffffcc0:  3ffe9682 402287df 3ffecdf0 3fff0a68
    3ffffcd0:  00000000 4021ba8b 3ffee2a8 00000022
    3ffffce0:  00000000 00000002 00000000 3ffecdf0
    3ffffcf0:  3fff126a 40104e63 3fff0a68 3ffeffe4
    3ffffd00:  3fff1234 0000002f 00013880 00000001
    3ffffd10:  00000004 4020ddc9 3ffef218 3ffeffe4
    3ffffd20:  3fff126a 0000023f 00000001 3ffeef98
    3ffffd30:  00000000 3ffeef98 4216cccd 00000000
    3ffffd40:  3ffef644 3ffef60c 3fff1234 4020e04b
    3ffffd50:  4000dd1f 3ffef60c 3fff1234 4020e43c
    3ffffd60:  3ffef490 4bc6a7f0 12b020c4 00000000
    3ffffd70:  00000000 00000000 4bc6a7f0 3ffef494
    3ffffd80:  3ffef644 00000000 3ffef60c 40215b14
    3ffffd90:  00000000 3ffee968 019672ab 00000000
    3ffffda0:  00000000 3fff1234 3ffef1b8 00000000
    3ffffdb0:  3ffee990 3ffef1b8 3ffe8510 3fff1234
    3ffffdc0:  3fff1234 3fff0868 3ffef60c 40215d18
    3ffffdd0:  40100000 3ffeef98 00000000 401001cd
    3ffffde0:  3fff1278 3fff0868 3ffef60c 40216730
    3ffffdf0:  3fff0864 402171fc 00000010 401007f4
    3ffffe00:  00000014 3fff0864 000000ff 00000000
    3ffffe10:  00000006 3ffef580 00000284 401007f4
    3ffffe20:  00000055 00000218 3fff0864 3fff0864
    3ffffe30:  3fff07fc 3ffef60c 3fff0b2c 40216778
    3ffffe40:  00000000 4bc6a7f0 676c8b43 00000000
    3ffffe50:  00000000 00000000 4bc6a7f0 00000000
    3ffffe60:  3ffef1dc 000003ef 4010014c 0002bef4
    3ffffe70:  00000000 4bc6a7f0 79db22d0 00000000
    3ffffe80:  032cca97 00000000 3ffe8510 00000000
    3ffffe90:  00000003 3ffe9238 40205d54 3fffefa0
    3ffffea0:  00000003 00000000 3fff05c4 40203a0b
    3ffffeb0:  0328466c 00000000 3fff05c4 40203a5d
    3ffffec0:  00000002 3ffe9235 40205d54 4216cccd
    3ffffed0:  3fffff50 00000000 3fffff50 40205355
    3ffffee0:  3ffe9238 00000000 3fff05c4 40203a5d
    3ffffef0:  0000000d 00000000 7ff80000 402055ca
    3fffff00:  00000002 00000000 3fffff50 40205355
    3fffff10:  3ffe9235 429ab852 3fffff50 4216cccd
    3fffff20:  7fc00000 429ab852 3fffff50 40205714
    3fffff30:  7fc00000 429ab852 3fffff50 40205731
    3fffff40:  7fc00000 429ab852 7fc00000 402029d7
    3fffff50:  40206478 00000000 00001388 4020e7a7
    3fffff60:  00000000 3fff05c4 00000000 00000000
    3fffff70:  00000000 3fff0a8c 0000007f 00000000
    3fffff80:  7fc00000 41c9999a 3ffef0f8 402025a4
    3fffff90:  00000000 00000000 00000001 3ffef160
    3fffffa0:  3fffdad0 00000000 3ffef130 40205e00
    <<<stack<<<

     ets Jan  8 2013,rst cause:2, boot mode:(1,6)

     ets Jan  8 2013,rst cause:4, boot mode:(1,6)

    wdt reset

**EspExceptionDecoder stack trace:**
  [![stacktrace][1]][1]

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

title: Cant get rid of Soft WDT reset using ESP8266

Answers: 0


body:
Hello people from StackExchange,

I'm new to Arduino and driving stepper motors in general; please excuse me for my limited knowledge on the subject. I've been doing research for a few hours already, looking into powering stepper motors and the Arduino, though I've gotten conflicting information regarding my problem.

My problem, or well question if you will, is as follows:
The circuit I need, simplified, contains an Arduino, a stepper motor driver (DRV8825), a NEMA17 5kg.cm stepper motor and a 12V battery pack (yet to be decided what kind of pack, though it will be 12V). Do I need another, lower voltage, battery pack?

After looking into how to power stepper motors using the Arduino online, I found several sites instructing me how to do so. All of the sites had the same circuit I would use, only the motor was different. Here is one of the circuits:

[![Circuit from LastMinuteEngineers, note it only has a single power supply][1]][1]

As you can see, it only has a single power supply (with capacitor to catch voltage peaks). I understand most of the circuit, though one question remains: why exactly is there only one power supply being shown here, is it because the Arduino can get its power from the driver? (You can see the pin descriptions in the second image below) Or do they simply not show the (5v) power supply for the Arduino?

The thing I want to know, is whether this circuit would function without an external power supply for the Arduino or not? And if not, would connecting the Arduino to the power supply via the VIN pin work? That would be nice, as it would offer a simple way of fixing the problem instead of getting a separate power source. Connecting the Arduino through USB wouldn't work for my project, as it can't have any wires coming from it. It needs to be completely mobile.

For comparison, here is a circuit that does show the Arduino with an external power source:

[![Circuit that does have an external power source][2]][2]

I'm a first years mechanical engineering student, hence my little knowledge on Arduino's and stepper motors.

Thanks in advance.

  [1]: https://i.stack.imgur.com/s6R4B.png
  [2]: https://i.stack.imgur.com/laViw.jpg

title: Powering an Arduino directly from a motor driver (DRV8825) or external power source?

Answers: 1

body:
> why exactly is there only one power supply being shown here, is it because the Arduino can get its power from the driver?

No. It is assumed that you will provide the power to the Arduino yourself - either through the USB connection to the computer, or through the barrel jack.

> The thing I want to know, is whether this circuit would function without an external power supply for the Arduino or not?

No. The Arduino requires power to be provided.

> And if not, would connecting the Arduino to the power supply via the VIN pin work?

Yes, but it's not ideal.  At 12V the power wasted by the on-board linear voltage regulator will be proportionally high.  As long as all that is being powered is the Arduino itself that shouldn't be too bad, but if you try to draw any significant current either out of the 5V pin or through multiple IO pins (for example to drive lots of LEDs) then it will overheat and potentially shut down.

A more ideal arrangement would be to connect a 5V switching regulator to the 12V battery and use that to power the Arduino either through the 5V pin or the USB connector. Personally, I use cheap UBEC modules from RC model suppliers. They are small, low-cost, and very easy to wire up.


body:
My arduino is connected to ultrasonic sensor and I am trying to read the value from it. When I tried running "tail -f > /dev/ttyACM0" my arduino is sending some weird characters that I am not able to decode[![enter image description here][1]][1]

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

title: Getting weird characters from Arduino

Answers: 2

body:
It would seem you failed to configure the port on the Linux side. By
default, it is configured to who-knows-what baud rate, and to a “cooked”
mode where the data is preprocessed by the kernel driver. You want
instead to set it to the correct baud rate and to “raw” mode. The `stty`
(meaning, “set terminal”) command does this:

    stty -F /dev/ttyACM0 raw 9600

Replace 9600 with whatever baud rate your Arduino is using.

If you Arduino program attempts to read the serial port, it will see the
echo of the characters it sends. In that case you probably want to
disable this echo also:

    stty -F /dev/ttyACM0 raw -echo 9600

body:
Most likely this is incorrect baud rate. You can try with a program dedicated to serial ports, my personal choice is picocom but it can by minicom or any other:

    $ picocom -b 9600 /dev/ttyACM0

The `-b` parameter is used for specifying the baud rate, depending on the sketch it can be something else than 9600, the most common ones are: 9600, 14400, 19200, 28800, 38400, 57600

Another solution is to configure the `/dev/ttyACM0` with correct baud rate using `stty`:

    stty -F /dev/ttyACM0 9600 cs8 -cstopb -parenb

This will configure the serial port to 9600 bps, 8 bits, 1 stop bit, no parity, and allow the `tail` command to read it correctly, if the communication parameters match what the arduino is sending


body:
Can this relay found here:

https://www.adafruit.com/product/2895

Be used with an Arduino Mega? The description given seems to specify that you should hook it up to their dedicated 'Featherwing Board' but it's the only relay available on their site. Looking at the pins it has it seems it should hook up to an Arduino with no problems. Has anyone here had the chance to use this relay with an Arduino microcontroller? I asked them about this on their forum but I haven't received a reply yet.

PS: I want to use it to connect a 'Strobe Siren 12VDC' and the relay I was looking to get is out of stock at my local shop.

https://store.nerokas.co.ke/index.php?route=product/product&product_id=1398
https://store.nerokas.co.ke/index.php?route=product/product&product_id=1679

title: Can the 'Adafruit Non-Latching Mini Relay FeatherWing' be used with an Arduino microcontroller such as an Arduino Mega 2560?

Answers: 2

body:
Yes.

There's not a lot more to be said really.

It's a relay, and they provide a MOSFET and associated circuitry to drive it cleanly.

Just connect power and ground to the Arduino, along with the "Signal" pin to the GPIO pin of your choice, and away you go.

Note that the relay is a 3.3V relay, so you must power it by the 3.3V pin, not the 5V pin.

body:
That is a 3.3V device. you'll need to give it a separate 3.3V power input, and it needs much higher current at 3.3V than the Arduino can supply.

 I don't know if you can feed it a 5V logic signal or not. (If it needs 3.3 V control signals as well, and it's current needs are modest you could step down the voltage from an Arduino 5V digital output to 3.3 with a simple voltage divider circuit.)

You'd be better off getting a 5V relay. If you do a Google search on "Arduino Relay" you'll find tons of them. You can get 1 relay, 2 relay, 4 relay, and more on a board. Many have optical isolation to make sure the relay coils don't add noise to the logic lines.

In general it's a good idea to use a separate power supply for the relay, or at least use a power supply with plenty of current to spare, and add filtering capacitors between the 5V rail and ground right next to both the relay and the Arduino. These capacitors serve to filter out variations in voltage as the relay coils are powered on and off.

(Even "digital" relays draw a large amount of current from their power source when they first turn on, and abruptly *stop* drawing current when they turn off, which introduces a lot of noise on the power line. "Naked" relays need "flyback diodes" to avoid reverse currents that will destroy transistors, but the "digital ready" relays I'm talking about have those built in.)

Here is one such relay I found from Googling "Arduino relay".

https://vetco.net/products/single-relay-module-for-arduino?gclid=EAIaIQobChMI8Ye70K-e4QIVBkSGCh2EBgEiEAQYAyABEgIxpvD_BwE


body:
[EDIT] it seems like this has to do with my laptop's firewall settings rather than anything wrong with the ESP8266 [/EDIT]

I have a webserver on my laptop. When I do this on my ESP8266 (after the wifi has been connected)

    while(!client.connect(laptop,port)) {
       Serial.println("Connecting...");
       delay(1000);
    }

It loops forever. However, if I manually ping my ESP from my laptop, I initially get this

    Pinging 192.168.1.7 with 32 bytes of data:
    Request timed out.
    Reply from 192.168.1.7: bytes=32 time=4ms TTL=255

And as soon as this happens, the ESP gets connected to the laptop, and all works fine.

So it seems to me like the client.connect is preventing the ESP from even registering to the network, and the pinging is somehow waking it up.

title: client.connect() failing unless I ping my ESP

Answers: 0


body:
I have 2 ESC (electronic speed controller) which control these brushless motors: [Hobbyking Donkey ST3511 Brushless Motor][1]

I would like to make them work with a poentiometer, under arduino.

I have a program but it only works with one engine. Here is the program :

    #include <Servo.h>//Using servo library to control ESC

    Servo esc;
    Servo esc2;
    //Creating a servo class with name as esc

    void setup()

    {

    esc.attach(9); //Specify the esc signal pin,Here as D8

    esc.writeMicroseconds(1000); //initialize the signal to 1000

    Serial.begin(9600);

    esc2.attach(9); //Specify the esc signal pin,Here as D8

    esc2.writeMicroseconds(1000); //initialize the signal to 1000

    Serial.begin(9600);

    }

    void loop()

    {

    int val; //Creating a variable val

    val= analogRead(A0); //Read input from analog pin a0 and store in val

    val= map(val, 0, 1023,1000,2000); //mapping val to minimum and maximum(Change if needed)

    esc.writeMicroseconds(val); //using val as the signal to esc
    esc2.writeMicroseconds(val);
    }

I did not find help on the internet, thank you in advance.

  [1]: https://hobbyking.com/en_us/hobbyking-donkey-st3511-810kv-brushless-power-system-combo.html?gclid=CjwKCAjwm-fkBRBBEiwA966fZNUs_Lq5O0I9nkySMYFtYdEYreK2LXFlR0XGbOV2MIj9oXWXFvWRkxoCAhEQAvD_BwE&gclsrc=aw.ds&___store=en_us

title: Control 2 ESC with a potentiometer with arduino

Answers: 1

body:
If you want one potentiometer to handle BOTH ESCs' speed, you could use this code:

    //Using servo library to control ESC
    #include <Servo.h>

    //Starting the servos
    Servo esc1;
    Servo esc2;

    void setup() {
        esc1.attach(9); // Use a PWM pin to the Servo, in this case 9
        esc1.writeMicroseconds(1000); //initialize the signal to 1000
        esc2.attach(10); // Pick another PWM to the other, in this case 10
        esc2.writeMicroseconds(1000); //initialize the signal to 1000

        Serial.begin(9600);
    }

    void loop() {
        int val; //Creating a variable val
        val= analogRead(A0); //Read input from analog pin a0 and store in val
        val= map(val, 0, 1023,1000,2000); //mapping val to minimum and maximum(analogRead's goes from 0-1023 and analogWrite's goes from 0-255, check your servo's specs)
        esc1.writeMicroseconds(val); // write to the first ESC
        esc2.writeMicroseconds(val); // write to the second ESC
        delay(100); // We usually set a small delay to avoid excessive readings or over-heating, but thats optional...
    }

If you need to use two potentiometers, one for each ESC, then you would have to start another variable to read the 2nd pot value and use it to write on the 2nd ESC, simple as that! :)


body:
I have this code

    #include <Ticker.h>  //Ticker Library
    Ticker blinker;
    /* ... */

    //blinker.attach(1, []() { digitalWrite(LED,!digitalRead(LED)); }
    while(!client.connect(laptop,port)) {
       Serial.println("Connecting...");
       delay(1000);
    }

Which works fine, tries connecting, then eventually connects.

If I uncomment the line attaching to this 'blinker' Ticker, then I get a crash right after the first 'Connecting...' print. When I look at the stack trace, it mentions that the crash happens during the delay(1000) in my while loop (which is presumably the moment when the program yields and the blinker can do some work)

Is there anything I can do to make this timer work better?

title: Is Ticker.h really safe to use?

Answers: 1

body:
**Update**: the original question mentioned timers, so this answer is for a hardware timer interrupt handler. It doesn't apply to `Ticker`, which is what the question is now about.

The callback that you attach to `blinker` will be called as an interrupt handler, so it's important to make sure it's already loaded into executable instruction memory (iRAM) on the ESP8266. When you pass anonymous function inline to `blinker.attach()` it won't tagged to be stored in iRAM.

Try this instead:

    void ICACHE_RAM_ATTR blinker_handler(){
        digitalWrite(LED,!(digitalRead(LED)));  //Toggle LED Pin
    }

    ...

    blinker.attach(1, blinker_handler);

`ICACHE_RAM_ATTR` tells the system to keep the code in the instruction RAM. There's not a lot of iRAM (32Kbytes) so you don't want to do this too often, but it's important for interrupt handlers (another reason to keep them short and sweet).


body:
I encountered an odd problem with my Uno, it works completely fine through USB on the PC or when powered by a power bank, but as soon as I connect it on a 9v battery it just freaks out. I have a relay connected to it that is connected to a switch, works fine, but on the battery it keeps turning on and off super fast, like so fast that the relay doesn't even show it's doing it, I noticed because of the noise it makes. I even tried to slow it down with a delay but nothing changed.

Anyone have any idea why the battery would make this happen?

title: Powering Uno with 9v battery makes it "freak out"

Answers: 2

body: Not enough current available from the battery, relays take quite a lot. As soon as the relay tries to switch the voltage drops and the Uno resets due to brownout (low voltage)

body: It's actually not just the relay that takes up a lot of current. The 9V-port on your arduino uno is actually not meant for a 9V block, because the arduino uno needs a higher current than your 9V block can deliver. You can put 6 1.5V battery cells (AA batteries) in series, they will deliver the current you'll need.


body:
I get this error trying to upload `avrdude: stk500v2_ReceiveMessage(): timeout`

It is Robotdyn Mega 2560 PRO MINI and a Robotdyn CH340 which I have connected like this: [![enter image description here][1]][1]

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

I installed the CH340 drivers from here https://sparks.gogo.co.nz/ch340.html and I can see it in the device manager.
Connecting the Mega 2560 Pro Mini lights up the `L` and `On` LED but when pressing upload (testing with simple examples as Blink) I get the error and neither RX or TX lights up.

I have tried everything I can think of. What am I doing wrong?

I have confirmed that it is connected to the correct COM-port and I use these settings:

    Board: Arduino/Genuino Mega or Mega 2560
    Processor: ATMega2560 (Mega 2560)

I have also tried many different USB-cables, short and long, and USB 2.0 and USB 3.0 ports. I use Windows 10 64-bit.

title: Cannot upload to Robotdyn Mega 2560 PRO MINI?

Answers: 1

body:
Try placing a 100nf capacitor on RST. That is usually required on an FTDI programmer.

See Edgar's post - https://arduino.stackexchange.com/users/47431/edgar


body:
I just make a simple circuit with uno and breadboard ,that connected 4 LED and 4 IR sensor. The arduino program is simple that makes the light on or off with the determination of IR sensors .

However my computer cannot find the USB COM when it connects the 5v and GND.
Hence, I plug out the 5v and GND that connect to the breadboard .The computer can recognize COM 4 then . I successfully upload the program after this .

Now , when I connect the computer and UNO to give battery to UNO , no battery passed (because the computer cannot detect the USB COM) .The lights of IR sensor aren't on .How to tackle the problem?

# It failed to  give battery with external battery too unless I plug out the 5v and GND

This is my simple program:

    int irPin1 = 2;
    int ledPin1 = 13;
    int irPin2 = 3;
    int ledPin2 = 11;
    int irPin3 = 4;
    int ledPin3 = 9;
    int irPin4 = 5;
    int ledPin4 = 7;
    int serialSpeed = 9600;

    void setup() {
      // put your setup code here, to run once:
      pinMode(irPin1,INPUT);
      pinMode(irPin2,INPUT);
      pinMode(irPin3,INPUT);
      pinMode(irPin4,INPUT);
      pinMode(ledPin1,OUTPUT);
      pinMode(ledPin2,OUTPUT);
      pinMode(ledPin3,OUTPUT);
      pinMode(ledPin4,OUTPUT);
      Serial.begin(serialSpeed);
    }

    void loop() {
      // put your main code here, to run repeatedly:
      int reading1 = digitalRead(irPin1);
      int reading2 = digitalRead(irPin2);
      int reading3 = digitalRead(irPin3);
      int reading4 = digitalRead(irPin4);
      digitalWrite(ledPin1,reading1);
      digitalWrite(ledPin2,reading2);
      digitalWrite(ledPin3,reading3);
      digitalWrite(ledPin4,reading4);
      String output = "{\"1\":" + (String)reading1 + ",\"2\":" + (String)reading2 + ",\"3\":" + (String)reading3 + ",\"4\":" + (String)reading4 + "}";
    //  String output = "{\"" + (String)reading1 + "\",\"" + (String)reading2 + "\",\"" + (String)reading3 + "\",\"" + (String)reading4 + "\"}";
      Serial.println(output);
      delay(100);
    }

> My Arduino circuit:
>
>  UNO 5v to breadboard 5v
>
>UNO GND to breadboard GND
>
> 1st set: IR :5v GND
>  from breadboard , pin from UNO
>
> 2nd set: IR :5v GND from breadboard ,
>  pin from UNO
>
> 3rd set: IR :5v GND from breadboard , pin from UNO
>
> 4th
>  set: IR :5v GND from breadboard , pin from UNO

title: Cannot give battery through USB cable

Answers: 0