body:
I try to create a display so that when I press the button, the counter is increased by one. The problem is only one of them light up and it is not showing the correct output, it is showing the combination of both digit (e.g. 01 showing 0, 02 showing 8). Here is my full code.

    const int a = 8;  //For displaying segment "a"
    const int b = 9;  //For displaying segment "b"
    const int c = 4;  //For displaying segment "c"
    const int d = 5;  //For displaying segment "d"
    const int e = 6;  //For displaying segment "e"
    const int f = 2;  //For displaying segment "f"
    const int g = 3;  //For displaying segment "g"
    const int D1 = 7;
    const int D2 = 13;

    bool bPress = false;
    const int IncbuttonPin = 10;

    // Variables will change:
    int buttonPushCounter = 0;   // counter for the number of button presses
    int buttonPushCounterD1 = 0;
    int buttonPushCounterD2 = 0;

    int IncbuttonState = 0;
    int lastIncbuttonState = 0;

    void setup() {
      // put your setup code here, to run once:
      pinMode(a, OUTPUT);  //A
      pinMode(b, OUTPUT);  //B
      pinMode(c, OUTPUT);  //C
      pinMode(d, OUTPUT);  //D
      pinMode(e, OUTPUT);  //E
      pinMode(f, OUTPUT);  //F
      pinMode(g, OUTPUT);  //G
      pinMode(D1, OUTPUT);
      pinMode(D2, OUTPUT);

      pinMode( IncbuttonPin , INPUT_PULLUP );
      Serial.begin(9600);

    }

    void loop() {

       IncbuttonState = digitalRead(IncbuttonPin);

       checkIncButtonPress();

      if( bPress ){
        bPress = false;
         turnOff();
         lightDigit1(buttonPushCounterD1);
         delay(5);
         lightDigit2(buttonPushCounterD2);
         delay(5);
      }
    }

    void checkIncButtonPress()
    {
       // compare the IncbuttonState to its previous state
      if (IncbuttonState != lastIncbuttonState) {
        // if the state has changed, increment the counter
        if (IncbuttonState == LOW) {
          // if the current state is HIGH then the button went from off to on:
          bPress = true;
          buttonPushCounter++;
          buttonPushCounterD1 = buttonPushCounter / 10;
          buttonPushCounterD2 = buttonPushCounter % 10;
          Serial.println("on");
          Serial.println(buttonPushCounterD1);
          Serial.println(buttonPushCounterD2);

        } else {
          // if the current state is LOW then the button went from on to off:
          Serial.println("off");
        }
        // Delay a little bit to avoid bouncing
        delay(50);
      }
      // save the current state as the last state, for next time through the loop
      lastIncbuttonState = IncbuttonState;

    }

    void lightDigit1(byte digit) {
      digitalWrite(D1, LOW);
      digitalWrite(D2, HIGH);
      displayDigit1(digit);
    }

    void lightDigit2(byte digit) {
      digitalWrite(D1, HIGH);
      digitalWrite(D2, LOW);
      displayDigit2(digit);
    }

    void displayDigit1(byte digit)
    {
     //Conditions for displaying segment a
     if(digit!=1 && digit != 4)
     digitalWrite(a,HIGH);

     //Conditions for displaying segment b
     if(digit != 5 && digit != 6)
     digitalWrite(b,HIGH);

     //Conditions for displaying segment c
     if(digit !=2)
     digitalWrite(c,HIGH);

     //Conditions for displaying segment d
     if(digit != 1 && digit !=4 && digit !=7)
     digitalWrite(d,HIGH);

     //Conditions for displaying segment e
     if(digit == 2 || digit ==6 || digit == 8 || digit==0)
     digitalWrite(e,HIGH);

     //Conditions for displaying segment f
     if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
     digitalWrite(f,HIGH);
     if (digit!=0 && digit!=1 && digit !=7)
     digitalWrite(g,HIGH);
    }

    void displayDigit2(byte digit)
    {
    // digitalWrite(D1, HIGH);
    // digitalWrite(D2, LOW);
     //Conditions for displaying segment a
     if(digit!=1 && digit != 4)
     digitalWrite(a,HIGH);

     //Conditions for displaying segment b
     if(digit != 5 && digit != 6)
     digitalWrite(b,HIGH);

     //Conditions for displaying segment c
     if(digit !=2)
     digitalWrite(c,HIGH);

     //Conditions for displaying segment d
     if(digit != 1 && digit !=4 && digit !=7)
     digitalWrite(d,HIGH);

     //Conditions for displaying segment e
     if(digit == 2 || digit ==6 || digit == 8 || digit==0)
     digitalWrite(e,HIGH);

     //Conditions for displaying segment f
     if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
     digitalWrite(f,HIGH);
     if (digit!=0 && digit!=1 && digit !=7)
     digitalWrite(g,HIGH);
    }

    void turnOff()
    {
      digitalWrite(a,LOW);
      digitalWrite(b,LOW);
      digitalWrite(c,LOW);
      digitalWrite(d,LOW);
      digitalWrite(e,LOW);
      digitalWrite(f,LOW);
      digitalWrite(g,LOW);
    }

when I remove the code

         lightDigit1(buttonPushCounterD1);
         delay(5);

It is showing the correct output, but only for 1 digit.
Anyone can help me on this? Thanks.

title: 7 segment multiple display, only display 1 digit

Answers: 1

body:
You aren't multiplexing your displays properly.

At the moment you are doing:

1. Do nothing until the button is pressed
2. Switch on display 1
3. Turn on the segments for digit 1
4. Wait 5ms
5. Switch off display 1
6. Switch on display 2
7. Turn on the segments for digit 2
8. Wait 5ms
9. Go to 1

For about 5ms you will get a brief flash on one digit, but since you don't turn off the segments you turned on for that digit they are just added to for the second digit - which you display for an extended period.

To multiplex properly you must:

* Turn off segments that are no longer used for the current display (best to turn them *all* off)
* Repeatedly display *both* digits *all the time*.

Ideally your method would be:

1. Turn off all segments
2. Turn on segments for digit 1
3. Turn on digit 1
4. Delay 5ms
5. Turn off digit 1
6. Turn off all segments
7. Turn on segments for digit 2
8. Turn on digit 2
9. Delay 5ms
10. Turn off digit 2
11. Go to 1 (usually the `loop()` handles that for you).

And *separate* to that you handle your button press and changing the value to display.

Also note the turning off of a digit *before* arranging the segments for the next digit. This prevents *ghosting* where you get a faint impression of the previous digit overlaid on the current digit.


body:
*I'm programming an Arduino Nano so I belive that this question should be qualified for this SE.*

I am trying to dim up an LED using a for loop in AVR assembly.

My problem is that the cycle is repeated twice before ending, while it is suppose to end after the first cycle.

A cycle is when the `red_loop` is repeated 256 times (to dim the led up). At that point, the value should overflow causing the variable to go back to 0. The code should stop there, but mysteriously, it does another cycle and then it stops.

Does anyone know why?

Here is my code :

    .org 0x000

    ldi r16, 0b111
    out ddrb, r16

    ldi r16, 0xff
    out portb, r16

    ldi r16, 0

    ; ff00 pin
    ; ff01 value
    ; ff02 led

    ldi r16, 0b000
    sts $ff00, r16

    ldi r16, 0
    sts $ff01, r16

    red:
     ldi r16, 0b001
     sts $ff00, r16

    red_loop:
     rcall pwm

     lds r16, $ff01
     inc r16
     sts $ff01, r16
     cpi r16, 0
     brne red_loop

    end:
     rjmp end

    pwm:
     ldi r24, 190

    pwm_pre_loop:
     ldi r17, 0

    pwm_loop:
     lds r16, $ff01
     cp r17, r16
     brge off

     cp r17, r16
     brlo on

    pwm_loop_check:
     inc r17
     cpi r17, 0
     brne pwm_loop

     inc r24

     cpi r24, 0
     brne pwm_pre_loop

     ret

    on:
     lds r16, $ff00

     sbrc r16, 0
     cbi portb, 0

     sbrc r16, 1
     cbi portb, 1

     sbrc r16, 2
     cbi portb, 2

     rjmp pwm_loop_check

    off:
     lds r16, $ff00

     sbrc r16, 0
     sbi portb, 0

     sbrc r16, 1
     sbi portb, 1

     sbrc r16, 2
     sbi portb, 2

     rjmp pwm_loop_check

title: Assembly for loop repeating 2 times when it's only suppose to do it once

Answers: 1

body:
The problem is that the register `r17`, which you use as a PWM timing
ramp, overflows twice every time you enter `pwm_pre_loop`:

* when you increments it past 127, it overflows to −128
* when you increment it past 255, it overflows to 0.

When using a counter the way you are using `r17` here, you usually have
it overflow only once per cycle: either you consider it holds a signed
number which overflows from 127 to −128, or you consider it holds an
unsigned number which overflows from 255 to 0. I guess the latter is
more common. Your code is confused about that register's signedness:

* The instruction `brge` (named “Branch if Greater or Equal (Signed)” in
  the instruction set datasheet) tests the `S` (sign flag) bit of the
  status register, which is useful for _signed_ comparisons.

* The instruction `brlo` (“Branch if Lower (Unsigned)”) tests the carry
  flag, which is used for _unsigned_ comparisons.

You should decide once on the signedness of the counter, and then use it
consistently. Since here unsigned makes more sense, you can just replace
`brge` by `brsh` (“Branch if Same or Higher (Unsigned)”).

Or better yet, remove the second test, which is redundant:

<!-- language: lang-lisp -->

    pwm_loop:
        lds r16, value
        cp r17, r16
        brsh off  ; if (r17 >= r16) goto off;
        rjmp on   ; else goto on;

Note by the way that you can name your RAM variables. And you can use
some of the other available registers instead of the RAM.


body:
I have a bit of code below, the problem is only the first 'if' statement will execute when called on. When I call on *u, q, or any of the other if statements* it will go straight to the else and not execute. Tried switching the following ifs to 'else if' but got the same result.

    #include "Arduino.h"
    #include <Adafruit_Sensor.h>
    #include <DHT.h>
    #include "DHT.h"

    DHT dht1(3, DHT11);
    DHT dht2(2, DHT11);

    void setup()
    {
      pinMode(13,OUTPUT);
      pinMode(12,OUTPUT);
      pinMode(11,OUTPUT);
      pinMode(10,OUTPUT);
      pinMode(9,OUTPUT);
      pinMode(8,OUTPUT);
      pinMode(7,OUTPUT);
      pinMode(6,OUTPUT);
      pinMode(5,OUTPUT);
      pinMode(4,OUTPUT);
      digitalWrite(13,LOW);
      digitalWrite(12,LOW);
      digitalWrite(11,LOW);
      digitalWrite(10,LOW);
      digitalWrite(9,LOW);
      digitalWrite(8,LOW);
      digitalWrite(7,LOW);
      digitalWrite(6,LOW);
      digitalWrite(5,LOW);
      digitalWrite(4,LOW);
      Serial.begin(9600);
      dht1.begin();
      dht2.begin();
    }

    void loop()
    {
      float DHT11_t = dht1.readTemperature(true);
      float DHT21_t = dht2.readTemperature(true);

      if(Serial.read() == 'u')
      {
        Serial.println();
        Serial.print(DHT11_t,1);
        Serial.println();
        Serial.print(DHT21_t,1);
        Serial.println();
      }

      if(Serial.read() == 'c')
      {
        digitalWrite(13,LOW);
        digitalWrite(12,LOW);
        digitalWrite(11,LOW);
        digitalWrite(10,LOW);
        digitalWrite(9,LOW);
        digitalWrite(8,LOW);
        digitalWrite(7,LOW);
        digitalWrite(6,LOW);
        digitalWrite(5,LOW);
        digitalWrite(4,LOW);
        Serial.print("NDX");
        Serial.println();
        Serial.print("u");
        Serial.println();
      }

      if(Serial.read() == 'q')
      {
        digitalWrite(13,HIGH);
        digitalWrite(12,HIGH);
        digitalWrite(11,HIGH);
        digitalWrite(10,HIGH);
        digitalWrite(9,HIGH);
        Serial.print("STX");
        Serial.println();
        Serial.print("u");
        delay(2000);
        Serial.print("u");
        delay(2000);
        Serial.print("u");
        delay(2000);
        Serial.print("u");
        delay(2000);
        Serial.print("u");
        delay(2000);
        digitalWrite(13,LOW);
        digitalWrite(12,LOW);
        digitalWrite(11,LOW);
        digitalWrite(10,LOW);
        digitalWrite(9,LOW);
        Serial.print("NDX");
        Serial.println();
        Serial.print("u");
        Serial.println();
      }

      if(Serial.read() == 'w')
      {
        digitalWrite(8,HIGH);
        digitalWrite(7,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(4,HIGH);
      }

      else if(Serial.read() == 'e')
      {
        digitalWrite(13,HIGH);
        digitalWrite(12,HIGH);
        digitalWrite(11,HIGH);
        digitalWrite(10,HIGH);
        digitalWrite(9,HIGH);
      }

      if(Serial.read() == 'r')
      {
        digitalWrite(8,HIGH);
        digitalWrite(7,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(4,HIGH);
      }

      if(Serial.read() == 't')
      {
        digitalWrite(13,HIGH);
        digitalWrite(12,HIGH);
        digitalWrite(11,HIGH);
        digitalWrite(10,HIGH);
        digitalWrite(9,HIGH);
        delay(30000);
        digitalWrite(13,LOW);
        digitalWrite(12,LOW);
        digitalWrite(11,LOW);
        digitalWrite(10,LOW);
        digitalWrite(9,LOW);
        delay(750);
        digitalWrite(8,HIGH);
        digitalWrite(7,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(4,HIGH);
        delay(30000);
        digitalWrite(8,LOW);
        digitalWrite(7,LOW);
        digitalWrite(6,LOW);
        digitalWrite(5,LOW);
        digitalWrite(4,LOW);
      }

      if(Serial.read() == 'y')
      {
        digitalWrite(13,HIGH);
        digitalWrite(12,HIGH);
        digitalWrite(11,HIGH);
        digitalWrite(10,HIGH);
        digitalWrite(9,HIGH);
        delay(30000);
        digitalWrite(13,LOW);
        digitalWrite(12,LOW);
        digitalWrite(11,LOW);
        digitalWrite(10,LOW);
        digitalWrite(9,LOW);
        delay(750);
        digitalWrite(8,HIGH);
        digitalWrite(7,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(4,HIGH);
        delay(30000);
        digitalWrite(8,LOW);
        digitalWrite(7,LOW);
        digitalWrite(6,LOW);
        digitalWrite(5,LOW);
        digitalWrite(4,LOW);
      }

      else
      {
        digitalWrite(13,LOW);
        digitalWrite(12,LOW);
        digitalWrite(11,LOW);
        digitalWrite(10,LOW);
        digitalWrite(9,LOW);
        digitalWrite(8,LOW);
        digitalWrite(7,LOW);
        digitalWrite(6,LOW);
        digitalWrite(5,LOW);
        digitalWrite(4,LOW);
      }

    }

title: If/Else Statements on Arduino not executing

Answers: 1

body: `Serial.read()` takes the first byte out of the serial buffer. Once it's executed, this byte is gone, so the `Serial.read()` in the next if statement will fetch the next byte (if available). What you can do is assign the result of `Serial.read()` to some variable before the first if statement, and then use that variable instead of `Serial.read()` in the if statements.


body:
I'm using a NodeMcu for my project and am running out of pins to use. I have a MFRC522 Module, IR Receiver, Buzzer and RGB LED connected. I am facing the problem that whenever I start scanning for RFID tags with the MFRC522 module, the onboard LED starts flashing very fast and the RGB LED changes to an undefined color.

I looked up the pin definitions of the NodeMcu, but couldn't quite find information on what pins I can use for this and which I can't, and why this only happens once I start up the RFID reader.

This is my wiring sketch:
[![enter image description here][1]][1]

I found [this][2] pin layout image, as well as the [datasheet][3].

The code shouldn't be really relevant since it works before starting the RFID reader, but here is the setup of the reader, just in case:

    #define SS_PIN D4   // SPI - Slave Select Pin
    #define RST_PIN D2  // SPI - Reset Pin - not actually connected

    MFRC522 mfrc522(SS_PIN, RST_PIN);

    // Initial setup for SPI and MFRC522
    bool rfidSetupCompleted = false;
    void setupReader()
    {
      SPI.begin();
      mfrc522.PCD_Init();
      rfidSetupCompleted = true;
    }

These are the pin definitions of the RGB LED:

    #define LED_BLUE D8
    #define LED_GREEN D3
    #define LED_RED D2

Any help is highly appreciated! I'm assuming I am using a pin that is used for other purposes (such as maybe D8), but I can't figure out which, and why. I did try to change up the pins and switched D0 and D8 (buzzer and one LED pin), but without luck. I also tried disconnecting each LED pin separately, but didn't learn anything from that either.

  [1]: https://i.stack.imgur.com/BnnM0.png
  [2]: https://pradeepsinghblog.files.wordpress.com/2016/04/nodemcu_pins.png?w=616
  [3]: https://cdn-shop.adafruit.com/product-files/2471/0A-ESP8266__Datasheet__EN_v4.3.pdf

title: NodeMcu pins and an RGB LED

Answers: 2

body: I fixed the issue by swapping pin D4 and D8, and then setting up the MFRC522 at the very start of the program. I originally set it up before I started using it, which caused the color to change during the first scan.

body:
SPI.begin sets io15 (D8) mode even it is not used as SS pin for your device. It is better to use io15 (D8) as slave select pin for one of the slave devices. In your case for the one device you have on SPI bus.

Pins io 0 (D3) and io 2 (D4) have on-board pull-up, because they are boot configuration pins. Set them LOW right after setting pinMode for them, to not let current to LED RGB legs.


body:
There is no compiler error but output is showing timeout error.
as per as the instruction given in
https://github.com/RobTillaart/Arduino/issues/61

it says to increase the timeout factor but i did not found the constraints which were asked to be changed.[![here is the snapshot of serial monitor][1]][1]

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

title: how to increase the delay factor of DHT11?

Answers: 1

body:
The DHT11 and DHT22 used to be cheap and easy to use humidity and temperature sensors when they were used together with an Arduino Uno.

But things have changed.

 - They are not accurate and can become totally inaccurate with certain
   gasses or fumes.
 - It turned out, that the most used DHT libraries have
   a serious bug that creates a shortcut in the datasignal.
   This was no problem with the Arduino Uno, which can output
   40 mA with a pin. The newer processors have problems with
   that shortcut.
 - In 2018 the DHT11 seems to behave differently,
   the internal controller has probably changed.
 - Because the communication with the sensors requires accurate timing,
   the interrupts are turned off temporarily. That was no problem
   with the slow Arduino Uno, but it is not normal with
   a faster processor.
 - Some libraries use a timeout with a loop or with clock cycles.
   That worked well with the Arduino Uno,
   but it is not always reliable with newer processors.

In 2018, all the DHT libraries for the ESP8266 and ESP32 have issues with the DHT11 and DHT22.

Since the sensors are not very accurate anyway, it is best to stay away from all the troubles and avoid them. There are a number of good humidity sensors with I2C interface.


body:
Ok so I've been trying to do this for quite some time now. Still couldn't get it to work. I am trying to read a ESP8266 WiFi program from a normal Arduino Uno program. I've seen some people do this:

    #include <SoftwareSerial.h>

Then

    SoftwareSerial esp8266(2,3);

Let me see a working example of this?

Thanks for everything.

title: Accessing one code using another code on RobotDyn Uno+WiFi board

Answers: 1

body:
You can't 'access code'. You can write sketches to communicate for example over Serial or SoftwareSerial. You connect the pins of Serial interfaces RX to TX and let sketch in one MCU read or parse what the sketch in other MCU sent over Serial with print or write.

The onboard connection on Uno+WiFi board is over Serial. So you can't use USB and connection to esp8266 at the same time. But you could use SoftwareSerial like other use it with esp8266, if you connect some pins (for example 6 and 7) of Uno headers to Serial of esp8266 which is accessible on the esp8266 header on the board.

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

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


body:
[![enter image description here][1]][1]I want to connect the sensors in Esp8266 after I code those using arduino uno r3. The problem is that I don't have the idea on connecting those sensors without breadboard. Thank you

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

title: How to Connect ESP8266 with ultrasonic sensor and dht11 without breadboard?

Answers: 2

body:
A diagram of the internal wiring of a breadboard is found at http://www.fiz-ix.com/2016/04/breadboard-wiring-diagram/

Image duplicated here:

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

All you need to do is make sure all the same connected points from your breadboard circuit remain connected in the same way on a perfboard or PCB.

There are several ways to make a circuit on perfboard, and [this answer][2] on electronics SE shows some examples of using solder bridges as interconnects, short uninsulated wires, and insulated "wire wrap" wires.

You can also find perfboards with the same connection layout as a breadboard for easy transfer from a breadboard-wired circuit, as shown below:

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

  [1]: https://i.stack.imgur.com/R2E2B.png
  [2]: https://electronics.stackexchange.com/questions/55236/how-to-make-traces-on-an-universal-pcb
  [3]: https://i.stack.imgur.com/TyXsZ.jpg

body: If you do not want to use a breadboard, you could solder the wires together of tie them together, so long as none of the wires which aren't supposed to be touching are touching. Or you can also use flex tape! (Don't mind my meme)


body:
There are theses 8 small pins on the Uno+WiFi board. Can someone please give me a detailed table or something on the settings of these 8 DIP switches?

I'm sorry if this question has already been answered somewhere else but I am bad at looking for stuff online.

Thanks

title: DIP switches on RobotDyn Uno+WiFi

Answers: 1

body:
There are 3 major chips on the board. Atmega 328, esp8266 and the USB converter CH340. Every device has one RX and one TX pin. But you need sometimes connect the Atmega to esp8266, sometimes connect the Atmega to computer over USB and sometimes connect the esp8266 to computer. The first 6 switches are in pairs (RX and TX) for connecting two of the 3 devices.

 - 1,2 ON all others OFF connect esp8266 to Atmega. no connection to
   computer.
 - 3,4 ON all others OFF connects Atmega to computer over USB. no
   connection to esp8266
 - 5,6 ON all others OFF connects esp8266 to computer over USB. no
   connection to Atmega

The switch 7 sets io 0 of esp8266 LOW which puts esp8266 to flashing mode at reboot. So you turn it ON with connection of esp8266 to USB (computer) to upload sketch to esp8266.


body:
PROGRESS, now I have this (WITH GREAT HELP):

    void setup() {
       Serial.begin(9600);
    // initialize digital pin 13 as an output.
    }
    uint32_t timer_start = 0;
    int timer_running = false;

    void loop()
     {
    // Get LDR information
      int sensorValue = analogRead(A0);         // read the input on analog pin 0
      float voltage = sensorValue * (5.0 / 1023.0);     // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V)
      float lux = voltage * 100;

     if (lux>150) {
        if (!timer_running) {
          // Timer is not already running, so capture the start time
          timer_start = millis();
          timer_running = true;
        }
      } else {
        if (timer_running) {
          // The timer is currently running; stop it calculate/print the run time
          timer_running = false;
          Serial.println((millis()-timer_start) / 1000.0, 3); // format however you like here

        }
      }

     }

This now tells me how many millis the gymnast is in the air, divided by 1000.0 with 3 decimals. If I start the Serial Monitor when the gymnast is in the trampoline bed, then I can get the seconds of air_time the gymnast has. Is there a way to have this script running ONLY for 10 loops?

title: nodeMCU - Millis() - Simple Counter - How long is LED on?

Answers: 1

body:
Declare a global (or static) boolean variable to keep track of whether the timer is running or not, as well as a variable to hold the start `millis()` value. When the lux drops below your threshold, subtract the current `millis()` from the start value, and you have the duration in milliseconds, which is trivial to convert to mm:ss.sss format.

Example code (not a complete sketch)

    uint32_t timer_start = 0;
    uint8_t timer_running = false;

    void loop() {
      if (lux>150) {
        if (!timer_running) {
          // Timer is not already running, so capture the start time
          timer_start = millis();
          timer_running = true;
        }
      } else {
        if (timer_running) {
          // The timer is currently running; stop it calculate/print the run time
          timer_running = false;
          Serial.print(millis()-timer_start); // format however you like here
        }
      }
    }

----------

> This now tells me how many millis the gymnast is in the air, divided
> by 1000.0 with 3 decimals. If I start the Serial Monitor when the
> gymnast is in the trampoline bed, then I can get the seconds of
> air_time the gymnast has. Is there a way to have this script running
> ONLY for 10 loops?

Certainly. If it is assumed that you want a cumulative total air-time, then you need to declare another global or static variable to hold the cumulative air-time, and you need to have another variable to keep track of how many cycles have passed.

    void setup() {
       Serial.begin(9600);
    // initialize digital pin 13 as an output.
    }
    uint32_t timer_start = 0;
    int timer_running = false;
    uint32_t total_time = 0;
    uint8_t jump_count = 0;

    void loop()
    {
    // Get LDR information
      int sensorValue = analogRead(A0);         // read the input on analog pin 0
      float voltage = sensorValue * (5.0 / 1023.0);     // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V)
      float lux = voltage * 100;

      if (jump_count<10) {
        if (lux>150) {
          if (!timer_running) {
            // Timer is not already running, so capture the start time
            timer_start = millis();
            timer_running = true;
          }
        } else {
          if (timer_running) {
            // The timer is currently running; stop it calculate/print the run time
            timer_running = false;
            // Add this-jump air time to the cumulative total:
            total_time += millis()-timer_start;
            // Increment jump_count
            jump_count++;

            Serial.println((millis()-timer_start) / 1000.0, 3); // format however you like here
          }
        }
      } else {
        // Print the total air-time for 10 jumps;
        Serial.println((total_time)) / 1000.0, 3);
      }
    }


body:
I am trying to use my Arduino UNO as a programming interface to load sketches on the Espresso Lite v2.

I followed the instructions to setup the Wifi network (long press gpio13 and the AP thing), but now I want to run code on it.

I uploaded this sketch to the UNO, [in order to allow for serial communication][1](i chose method 3):
```
void setup(){
  pinMode(0,INPUT);
  pinMode(1,INPUT);
}
void loop(){
}
```

Afterwards I configured the Arduino IDE with the necessary libraries and device manager plugins for the Espresso, so I selected "Espresso Lite 2.0" as the target board and for programmer "Arduino as ISP".

This is what my tools menu looks like:

[![tools menu screenshot][2]][2]

I connected the 3.3V, GND, TX (to TX) and RX (to RX) and RESET (to RST) headers from the Arduino UNO to the Espresso Lite holes. If I open the Serial Monitor I can see serial output so I think the connections are correct.

I tried to upload an empty sketch and i got these errors (verbose upload):
```
Sketch uses 246096 bytes (23%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27588 bytes (33%) of dynamic memory, leaving 54332 bytes for local variables. Maximum is 81920 bytes.
C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\tools\esptool\0.4.13/esptool.exe -vv -cd ck -cb 115200 -cp COM3 -ca 0x0 -cz 0x400000 -ca 0x00000 -cf C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_89/sketch_oct08a.ino.bin
esptool v0.4.13 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
 setting board to ck
 setting baudrate from 115200 to 115200
 setting port from COM1 to COM3
 setting address from 0x00000000 to 0x00000000
 setting erase size to 0x00400000
 setting serial port timeouts to 1000 ms
opening bootloader
resetting board
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
An error occurred while uploading the sketch
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 read 0, requested 1
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 serialport_receive_C0: 0D instead of C0
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 serialport_receive_C0: 45 instead of C0
resetting board
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 read 0, requested 1
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 serialport_receive_C0: 0D instead of C0
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 serialport_receive_C0: 74 instead of C0
resetting board
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 read 0, requested 1
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 serialport_receive_C0: 0D instead of C0
trying to connect
 flush start
 setting serial port timeouts to 1 ms
 setting serial port timeouts to 1000 ms
 flush complete
 espcomm_send_command: sending command header
 espcomm_send_command: sending command payload
 serialport_receive_C0: 45 instead of C0
warning: espcomm_sync failed
error: espcomm_open failed
```

This is the serial output after i tried to upload:

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

**What am I doing wrong?**

  [1]: https://oscarliang.com/use-arduino-as-usb-serial-adapter-converter/
  [2]: https://i.stack.imgur.com/T8OyN.png
  [3]: https://i.stack.imgur.com/MbInM.png

title: Using Arduino UNO for uploading a sketch to the Espresso Lite v2

Answers: 1

body:
Don't connect reset pins together.  Selecting "Arduino as ISP" is irrelevant in many ways.

Put the esp8266 into flashing mode by resetting it with io 0 LOW at reboot (hold button GPIO0 and click the RESET button). **And then Upload from IDE**. The esptool can't reset the board to flashing mode because you don't have RTS and DTS line from Uno.

Picture from manufacturers page:

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

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


body:
I'm trying to DIY about a dozen [BlinkStick][1]s (discontinued, Adafruit) pictured here

[![discontinued BlinkStick][2]][2]

I'm thinking to use a Digispark ATTINY85 to control a single RGB LED to show the status of some program running under Linux. Here is the proto board I have my eye on:

[![Digispark ATTINY85][3]][3]

I could either use a single individually addressable RGB LED with a built-in WS281X controller

[![RGB data LED][4]][4]

or a plain RGB LED with each color pin connected to a GPIO pin on the TINY85.

[![Plain RGB LED][5]][5]

This is my first Arduino project, so I'm not familiar with the best way to approach this project. I'm trying to keep the part count low as well so the serial data approach is appealing too. Has anyone done this before and can explain their setup?

---

Prior work I've found for the simple control approach:

[![enter image description here][6]][6]

[![enter image description here][7]][7]

  [1]: https://www.adafruit.com/product/1370
  [2]: https://i.stack.imgur.com/TjvAi.jpg
  [3]: https://i.stack.imgur.com/dfCik.jpg
  [4]: https://i.stack.imgur.com/HRgqm.jpg
  [5]: https://i.stack.imgur.com/NYcn3.png
  [6]: https://i.stack.imgur.com/Jjc3O.jpg
  [7]: https://i.stack.imgur.com/XOjfD.png

title: ATTINY85 with RGB LED

Answers: 1

body:
The newest blinkstick uses an addressable led, while the Adafruit kit appears to use a regular 4 pin RGB led. These are easier to get.

The digispark and the blinkstick are almost identical, but they use different pins for the USB connection. So to use the firmware for the blinkstick on the digispark, you need to change the pin numbers in [usbconfig.h](https://github.com/arvydas/blinkstick-firmware/blob/master/usbconfig.h)

    #define USB_CFG_DMINUS_BIT      3
    #define USB_CFG_DPLUS_BIT       2

PS. the pin numbers in usbconfig.h don't seem to match the [schematic](https://www.blinkstick.com/files/schematics/blinkstick/blinkstick-v1.1.pdf), so I'm not sure what's going on


body:
I have boiled this down to a very simple piece of code:

    int testKey;

    void setup() {

    Serial.begin(9600);

    }

    void loop() {

    Serial.println("Input Source ID "); //Ask me the number

    while (Serial.available()==0){ } //Wait for me to answer

    testKey = Serial.parseInt();  //Store my answer in this variable

    Serial.print("Parsed Input is ");  //Print the results on serial monitor

    Serial.println(testKey);

    }

When I run the code on my Leonardo, or Uno, I expect to have Input Source ID to be printed on the serial monitor. It remains blank (it is set to 9600 baud). If I go ahead and enter a 1, then the serial monitor starts working. However, from this point on, it seems to ask me for the ID again, and print a 0 to the serial monitor:

Parsed Input is 1

Input Source ID

Parsed Input is 0

Input Source ID

It then is waiting for me to enter a new Source ID. If I then enter a 2, this is what I get, in addition to what was already there.

Parsed Input is 1

Input Source ID

Parsed Input is 0

Input Source ID

Parsed Input is 2

Input Source ID

Parsed Input is 0

Input Source ID

My question is, why doesn't the void loop start automatically and immediately prompt me for input? Secondly, after I give it a number, it seems to run it twice, inserting a 0 into the variable. Why? This seems so straightforward, but it has me stumped. I tried some delay statements here and there, to no avail. Thanks in advance.

title: Leonardo Problem

Answers: 2

body:
This line:

    while (Serial.available()==0){ } //Wait for me to answer

Doesn't wait for you to answer, it only waits until the first character is typed. This while loop happens about a million times a second on an Uno. You can't possibly type more than one character in that microsecond. Once you type it, the clock starts ticking, because [`parseInt()`][1] uses a timeout value, so if no valid digit character is entered by the timeout, it exits. The default timeout is 1000ms (1 second).

  [1]: https://www.arduino.cc/en/Reference/ParseInt

body:
> My question is, why doesn't the void loop start automatically and immediately prompt me for input?

It does. However your serial monitor isn't open at that time and can't receive it.  Unlike the Uno the Leonardo *does not reset when you open the serial port*.

A common workaround, to make it look more like an Uno, is to add:

    while (!Serial);

in `setup()` after `Serial.begin(...)`, so that it does nothing until you open the serial terminal.

> Secondly, after I give it a number, it seems to run it twice, inserting a 0 into the variable. Why?

Simple: you're parsing the number as a number. You're then parsing a blank line as the number.

If you have the serial monitor set to send CR + LF as the line ending you get the integer terminated by CR, followed by no integer (represented by 0) followed by LF.


body:
I have the following code working correctly except for the Index portion.
I am not sure if I have the syntax correct for the hardware.  The end result I am looking for is to have the encoder reset to 0 degrees every time the index comes around (360 degrees).
I am also looking for any comments on the code as I would like the encoder output to be as accurate and efficient as possible.

Here is the code:

    // Wiring connections for my encoder:
    // Brown : VCC = 5V
    // Blue + Shield : 0V = GND
    // Black : ENCODER0PINA, Pin 20
    // White : ENCODER0PINB, Pin 17
    // Orange : ENCODER0PINI, Pin 19

    #define ENCODER0PINA         20      // this pin needs to support interrupts
    #define ENCODER0PINB         17      // no interrupt required
    #define ENCODER0PINI         19      // this pin needs to support interrupts
    #define CLOCKWISE            1       // direction constant
    #define COUNTER_CLOCKWISE    2       // direction constant

    // variables modified by interrupt handler must be declared as volatile
    volatile long encoder0Position = 0;
    volatile long interruptsReceived = 0;
    volatile byte INTFLAG1 = 0;

    // track last position so we know whether it's worth printing new output
    long previousPosition = 0;

    void setup()
    {

      // inputs
      pinMode(ENCODER0PINA, INPUT_PULLUP);
      pinMode(ENCODER0PINB, INPUT_PULLUP);
      pinMode(ENCODER0PINI, INPUT_PULLUP);

      // interrupts
      attachInterrupt(3, onInterrupt, RISING);
      attachInterrupt(4, onReset, CHANGE);

      // enable diagnostic output
      Serial.begin (9600);
      Serial.println("Ready.");
    }

    void loop()
    {
      // only display position info if has changed
      if (encoder0Position != previousPosition )
      {
        Serial.println(encoder0Position, DEC);

        previousPosition = encoder0Position;
      }
    }

    // interrupt function needs to do as little as possible
    void onInterrupt()
    {
      // read both directional inputs
      int a = digitalRead(ENCODER0PINA);
      int b = digitalRead(ENCODER0PINB);

      if (a == b )
      {
        // b is leading a (counter-clockwise)
        encoder0Position--;
        if (encoder0Position < 0)
        {
          encoder0Position = (encoder0Position + 360);
        }
      }
      else
      {
        // a is leading b (clockwise)
        encoder0Position++;
        if (encoder0Position >= 360)
        {
          encoder0Position = (encoder0Position - 360);
        }
      }

    void onReset()
    {
      // read Index input
      int i = digitalRead(ENCODER0PINI);

      if (i = 1)
      {
      encoder0Position = 0;
      }
    }

title: Optical Rotary Encoder Index issue

Answers: 1

body:
In your onReset() function you have an assignment instead of a comparison:

    if (i = 1) // This is always true
    {
    encoder0Position = 0;
    }

`i = 1` should be `i == 1`


body:
Good day.

I have a specific project need and I spent the past couple of days searching on forum, blogs, etc and I'm still not clear if that's feasible to do with Arduino or not.

I need to monitor the state of ~50 digital inputs and trigger an action when any of the pin changes either from 0 to 1 or from 1 to 0, pretty much the same as pin state interrupt works, only difference is that I need to "listen" to ~50 pins, instead of just a couple. I must be able to identify what pin triggered the action and what was the change (0->1 or 1->0).

My initial idea is to use a MEGA 2560 and have a group of 50 "if" statements on the main loop comparing the previous state or each pin (stored in individual variables) with the current one and triggering the corresponding action if something changed.

I'd like to hear from the experts here what would be a more elegant or smarter/faster way to accomplishing this.

I'm eager to receive your feedback.

Thank you.

title: How to monitor state of 50 Digital Inputs

Answers: 3

body:
The Mega 2560 appears to have 24 pin change interrupts (I haven't checked if they're all broken out on the Mega Arduino board).

A combination of as many pin change interrupts and 'manual' scanning could be quicker than scanning them all individually.

Another option would be to group as many as possible onto the same ports and use direct hardware access to looks for changes- with this you'd be able to do 8 inputs at a time. With 8 inputs on each port, you just need to have seven main checks that the port value has changed and then jump off to a handler that deals with what specific pin has changed and what action is needed.

body:
See answers in [Good solution for more interrupts on an Arduino][1]. E.g.:

Answer lhballoti:

You can use an I/O expander, for example an MCP23008 and MCP23017. They are available in SPI and I2c. Interrupts can be configured (edge-sensitive, level-sensitive) for each input.

Answer embedded.kyle:

You could use a Programmable Interrupt Controller (PIC) such as the 82C59A. It will cascade if you need more than the eight interrupts it provides. It's a bit old school but I think it will handle all of your requirements.

  [1]: https://electronics.stackexchange.com/questions/37567/good-solution-for-more-interrupts-on-an-arduino

body:
I had a project that used 16 rotary encoders and I used the MUX Shield which uses 74HC4067 analog multiplexers. They port to A0 - A3 on the shield which is fine as you can set these pins to Digital Inputs else you can get teh breakout version and connect to any input pins.
I also used a Due since ALL pins can be interrupt enabled.
Reading was a bit of a pain but worked like this...
The method is.. Continually address each input in turn in the loop or an interrupt is not detected, when an interrupt fires, address each input in turn again to find out which pin changed state.
Hope that helps.


body: I got a question regarding the ultrasound sensor (HC-SR04) connecting to the arduino. I have a project, and the space is really tight, so i will have to bend the pins of the HC-SR04. Is this okay to do, and if yes, how should i go about and do this ?

title: Bending pins of HC-SR04

Answers: 1

body:
The easiest things to do if space is a premium is to unsolder (or cut) the pins and then solder directly the wire to the corresponding spots.

Otherwise, you can also just get straight pins and replace them, You can also choose on which side of the board, as the holes are though it.

Lastly, about bending, it's doable with pliers if you want to make the pins face "forward" but depending on the quality of your pins they might break in the operation.


body:
TL;DR - I am attempting serial communication with Arduino with code that I found [here][1] and nothing gets sent over (Arduino programmed to respond, and I checked that it does with its serial monitor)

Hi there,
I was looking for a way to send information over to an Arduino Mega (2560) unit over linux serial port by C++.

I came across the following solution: [Solution][1]
I'm using this guy's code for write (I'm able to read data from the arduino) and use the same parameters (they work, as I'm able to receive data from the Ardunio).
I programmed my Arduino to send "Hi" over serial whenever it sees at least 1 bit of information, and checked it worked through the Arduino IDE Serial Monitor.

Yet when running the C++ code, the arduino doesn't respond. Do anyone might have idea why?

Full disclosure - I inserted @Lunatic999's code to a class so I can make an instance of it for my needs of the code.

    fd = open(portNameC, O_RDWR | O_NOCTTY | O_SYNC); //open port ("opens file")

Serial Parameters:

    struct termios tty;
    struct termios tty_old;
    memset (&tty, 0, sizeof tty);

    /* Error Handling */
    if ( tcgetattr ( fd, &tty ) != 0 ) {
    std::cout << "Error " << errno << " from tcgetattr: " << strerror(errno) << std::endl;
    }

    /* Save old tty parameters */
    tty_old = tty;

    /* Set Baud Rate */
    cfsetospeed (&tty, (speed_t)B9600);
    cfsetispeed (&tty, (speed_t)B9600);

    /* Setting other Port Stuff */
    tty.c_cflag  &=  ~PARENB;      // Make 8n1
    tty.c_cflag  &=  ~CSTOPB;
    tty.c_cflag  &=  ~CSIZE;
    tty.c_cflag  |=  CS8;

    tty.c_cflag  &=  ~CRTSCTS;      // no flow control
    tty.c_cc[VMIN]   =  1;            // read doesn't block
    tty.c_cc[VTIME]  =  5;            // 0.5 seconds read timeout
    tty.c_cflag  |=  CREAD | CLOCAL;   // turn on READ & ignore ctrl lines

    /* Make raw */
    cfmakeraw(&tty);

    /* Flush Port, then applies attributes */
    tcflush( fd, TCIFLUSH );
    if ( tcsetattr ( fd, TCSANOW, &tty ) != 0) {
    std::cout << "Error " << errno << " from tcsetattr" << std::endl;
    }

**Write** (this code I put inside a function which I call)

    unsigned char cmd[] = "INIT \r";
    int n_written = 0,
        spot = 0;

    do {
        n_written = write( fd, &cmd[spot], 1 );
        spot += n_written;
    } while (cmd[spot-1] != '\r' && n_written > 0);

Arduino code:

    bool dataRecieved = false;
    int ledpin = 13;

    void setup() {
    pinMode(ledpin, OUTPUT);
    digitalWrite(ledpin, HIGH);
    Serial.begin(19200);
    }

    void loop() {
      while(!dataRecieved)
      {
       digitalWrite(ledpin,HIGH);
       if (Serial.available() > 0)
       {
         dataRecieved = true;
       }
      }
      digitalWrite(ledpin,LOW);
      delay(1000);
      digitalWrite(ledpin,HIGH);
      delay(1000);
      Serial.println("hi");
    }

  [1]: https://stackoverflow.com/questions/18108932/linux-c-serial-port-reading-writing

title: No data sent over serial port in linux c++

Answers: 1

body:
The Arduino resets the moment you open the serial port.  Once reset the bootloader executes, which consumes (and discards since it's invalid) any serial data for a second or so before your sketch runs.

Because of this anything you send immediately after opening the serial port is ignored.

There are two commonly accepted "fixes" for this:

1. Delay for a pre-defined period after opening the serial port, and
2. Have the Arduino send a "READY" signal before doing anything else which your program waits for before sending.


body:
Want to create a weather station with only [GY-BME280-3.3 chip](https://www.ebay.com/itm/GY-BME280-3-3-BME280-3-3V-Atmospheric-Pressure-Sensor-Module-for-Arduino-SPI-IIC/201709070605) and [w5100 Ethernet shield](https://store.arduino.cc/usa/arduino-ethernet-shield-without-poe-module) mounted over [Arduino mega 2560 r3](https://store.arduino.cc/usa/arduino-mega-2560-rev3) but I have no previous experience with Arduino. And The Arduino will be hooked up to a router using the Ethernet shield and powered using desktop USB connection or may be with the barrel jack and I want to control it using a GNU/Linux machine. So far I am trying to follow these
https://educ8s.tv/arduino-bme280-weather-station,

https://startingelectronics.org/tutorials/arduino/modules/pressure-sensor,

http://cactus.io/projects/weather/arduino-weather-station,

but none of these is an exact match for my setup, so a little confusing as a noob. But my questions is,

How to hook up the GY-BME280-3.3 sensor to the Arduino on which the Ethernet shield is already mounted?

EDIT:
So far I have connected the first 4 pins to the pins on the Ethernet on 1->3.3v, 2->gnd, 3->A5, 4->A4  ***or***  1->3.3v, 2->gnd, 3->13, 4->11, 5->10, 6->12 but to no avail. Only 1+6->3.3v, 2->gnd, 3->21, 4->20 finds the sensor but reading is 0,0,0mb in [that case](https://i.stack.imgur.com/s8YWE.jpg) and shows reading if SparkFun BME280 library is [loaded](https://i.stack.imgur.com/dorn0.jpg).

Still the question is, if there any other pin combinations where I don't have to join 1+6 to a 3.3v, just one pin to 3.3v will be enough?

title: How to create a weather station with only GY-BME280-3.3 chip and w5100 Ethernet shield mounted over arduino mega 2560 r3

Answers: 1

body:
You must decide if you want to connect the sensor over I2C or over SPI interface. According to [datasheet of the sensor][1], at power-up pin CSB determines the interface. If CSB is pulled-down SPI is selected. CSB must be connected to VCC to select I²C interface.

On current revisions of Mega and Uno the 'standard location' of I2C pins SDA and SCL is near pin 13 after the Ground and AREF pin. Other location on Mega are pins 20 and 21. (A4 and A5 on Uno). Note that the 'standard location' pis are connected together with the 'numbered' pins, so you can't use 20 and 21 even if you connect the sensor to the standard location pins.

Pin SDO determines the I2C address of the sensor.

If you want to use SPI to connect the sensor to Mega, use SPI pins 50 to 52 and you can use pin 53 as CS (SS) pin. Ethernet shield uses pin 10 as CS for W5100 and pin 4 as CS for pin for the SD card. Note, that Ethernet shield connects to SPI bus on the ICSP header, but those are still SPI bus pins 50 to 52.

Adafruit has [a tutorial for this sensor][2] with wiring for Mega.

  [1]: https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP280-DS001-19.pdf
  [2]: https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout/arduino-test


body:
I am trying to upload information to my appspot created with Google App Engine. I am able to do it when I in my browser type:
http://myname.appspot.com/query?city=Copenhagen&temp=20&id=website
But I cannot get it to work on the ESP8266. Here is my code:

    const char* MY_URL = "http://myname.appspot.com";

    void uploadHTTP() {
     // Define the WiFi Client
     WiFiClient client;
     // Set the http Port
     const int httpPort = 80;

     // Make sure we can connect
     if (!client.connect(MY_URL, httpPort)) {
      return;
     }
     else {
      Serial.println("Connected to MY_URL");
     }

     String url = "/query?city=Copenhagen&temp=20&id=ESP8266";

     // Post to appspot
     if (client.connect(MY_URL, httpPort)) {

      // Sent HTTP POST Request
      client.println("POST " + url + " HTTP/1.1");
      Serial.println("POST " + url + " HTTP/1.1");
      client.println("Host: " + String(MY_URL));
      Serial.println("Host: " + String(MY_URL));
      client.println("User-Agent: Arduino/1.0");
      Serial.println("User-Agent: Arduino/1.0");
      client.print("Content-Length: ");
      Serial.print("Content-Length: ");
      client.println(0);
      Serial.println(0);
      client.println("Content-Type: application/x-www-form-urlencoded");
      Serial.println("Content-Type: application/x-www-form-urlencoded");
      client.println("Connection: close");
      Serial.println("Connection: close");
      }
     //Done
     Serial.println("");
     Serial.println("my HTTP done");
     Serial.println("");
    }

title: ESP8266 upload data to google cloud platform

Answers: 1

body:
Your biggest problem is that you are trying to use a website URL as a FQDN. That's not going to work.

When you connect to a remote machine you connect to the name (`myname.appspot.com`) which gets translated into an IP address for you to open a connection to.

When you use a web browser it parses the URL to extract the protocol (`http`) and the FQDN (`myname.appspot.com`) and uses the protocol to determine the port (and what language to speak) to connect to, then look up the IP address from the FQDN.

You need to drop the `http://` from your FQDN which is causing it to break (there is no host called `http://myname.appspot.com`).  The fact that you are connecting to port 80 and speaking the HTTP language implies that you are using HTTP.

To put it into more layman's terms: if you "need to call Fred to talk about going to the pub" you first look up fred's number in the phone book then call that number. Then only once he has answered do you talk about going to the pub. What you *don't* do is try and find the number to call by looking in the phone book under "talk about going to the pub with Fred". It won't be there.

If you are programming your ESP8266 directly you should consider using the much simpler bundled `ESP8266HTTPClient.h` library.


body:
![enter image description here](https://i.stack.imgur.com/3Vwyd.jpg)

How to use? ATmega328P Development Board for Arduino UNO R3 Bootloader Project DIY.

Answers: 2

body:
The purpose of this board is to flash (Arduino) bootloader to Atmega 328 chips. It has not a build in programmer, only a ICSP header to connect the programmer.

So wire it with a programmer and then chip in, ZIF close, burn bootloader, ZIF release, chip out, next chip in, ZIF close, ....

[video][1]

  [1]: https://youtu.be/Xetz1HKPRUg?t=148

body: Actually you can program with this device. Treat it as a Genuino Uno and select AVRISPmkII programmer. Used mine several times.


body:
I'm trying to develop a PID controller with Simulink as shown in the image:

![PID][1]

I'm using a PID controller to control a motor via an Arduino Uno and motor driver.

I have the PID output connected to an if statement.

- If u1 is larger than 0 then output 1 for digital output pin 2 and output 0 for digital output pin 4.
- If u1 is smaller than 0 then output 0 for digital output pin 2 and output 1 for digital output pin 4.

This changes the direction of the motor so that if the PID overshoots it will change direction. And so on for u1 is smaller than 0.

I also have the PWM signal for the speed of the actuator from 0 being the slowest and 255 as the fastest. I forgot to fix the label for it.

I keep getting an error when I try to run it. The error says that I can't run it because of having multiple digital output blocks with the same pin as shown in this image:

![Error in Simulink][2].

Is there a solution for this?

  [1]: https://i.stack.imgur.com/xSeHc.jpg
  [2]: https://i.stack.imgur.com/Oi7YW.jpg

title: How to have multiple digital outputs for the same pin on Arduino Uno and Simulink?

Answers: 1

body:
You cannot try and have two things controlling one output in two different ways. It just makes no sense.  Like trying to have two people steer a car and have one go left and the other right.

I don't quite know what you're *trying* to do, but under normal usage using a motor driver requires 3 pins (for example the common L239D). Two define the direction and a third (the EN pin on the L239D) controls the speed with PWM.


body:
I am working on a small home project 'glucose meter' via non invasive techniques. I am using four sensors like RGB color sensor, two multi-wavelength photo diodes (A & B) and temperature sensor (K-Type Thermocouple). I am using Multi Regression algorithm to estimate Glucose level in human body by calculate all four readings from sensors.

[![Multple Regression Equation][1]][1]

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

I am using ESP32 and I am saving all my sensors data in a CSV file (or text) after taking more than 20 calibration data from my family and friends. I can read this file after writing but I am facing a problem in reading all calibration data from this text/CSV file in the following particular manner.

    Y,Sensor1,Sensor2,Sensor3,Sensor4
    92,103,25,65,9875
    91,104,26,62,9805
    105,92,30,66,9600
    150,60,40,75,9233
    ...,...,...,.....

Above pattern indicates 'Y' values (Blood Sugar value mg/dl) and corresponding sensors value on that time.
I am facing problem in reading these object like:

    Y1 = 92, S1 = 103, S2 = 25, S3 = 65, S4 = 9875
    Y2 = 91, S1 = 104, S2 = 26, S3 = 62, S4 = 9805
    ....................AND so forth..............
    Y1000 = XX, S1 = XX, S2 = XX, S3 = XX, S4 = XX

Can any one help me how would I read and categorize each sensor values from the text/CSV File?

Thanks.

title: Read Multiple Sensors Data from a text file located in SD Card in Arduino/ESP32

Answers: 2

body:
Function file.[parseInt][1](), will skip non numeric characters and then parse the number stopping on non numering character. So you need only call file.parseInt() for every value in row, process the data and then loop to next row.

    Y1 = file.parseInt();
    S1 = file.parseInt();
    S2 = file.parseInt();
    S3 = file.parseInt();
    S4 = file.parseInt();

  [1]: https://www.arduino.cc/reference/en/language/functions/communication/stream/streamparseint/

body:
Let's say you want to read this line from the file.

```
92,103,25,65,9875
```

code is

```
String one_line_data = file.readStringUntill("\n");
int y,s1, s2, s3, s4;
sscanf(one_line_data.c_str(), "%d,%d,%d,%d,%d", &y, &s1, &s2, &s3, &s4);
```
this way to read the one line of data from file you can expand to multiple line based on application.


body:
I'm using FastLEDs builtin fill_rainbow function for generating a rainbow spectrum on an LED strip. The issue is, I get a random red pixel midway through the yellow region. I've tried it on 3 different Arduino nano's, and two different LED-strips. Here's the code:

    #include <FastLED.h>

    #define DATA_PIN 2
    #define NUM_LEDS 114
    CRGB leds[NUM_LEDS];

    uint8_t hue = 0;

    void setup() {
      Serial.begin(115200);
      FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);

      fill_rainbow( leds, NUM_LEDS, hue, 1);
      for(int i=0; i<NUM_LEDS; i++) {
        Serial.print(i);
        Serial.print(' ');
        Serial.print(leds[i].r);
        Serial.print(' ');
        Serial.print(leds[i].g);
        Serial.print(' ');
        Serial.println(leds[i].b);
      }

      CHSV hsv;
      CRGB rgb;
      //rgb = hsv;
    }

    void loop() {
      fill_rainbow( leds, NUM_LEDS, hue, 1);
      FastLED.show();
    }
Here pixel number 60 gets the rgb code 160, 0, 0. When it should have something like 160, 150, 0.

The strangest part of all is that I can get rid of the problem in two ways, either by uncommenting the line rgb = hsv;, or by commenting out the fill_rainbow function in the loop function. This strange behavior leads me to believe im somehow messing up a pointer or misusing a FastLED feature. Additionally the fill_rainbow function is very simple and relies on FastLEDs hsv to rgb typecasting, which is another reason to believe I'm doing something wrong.

So help me out here, am i doing something silly, or have I discovered a bug with FastLEDs hsv to rgb converter?

title: FastLED fill_rainbow - Unexpected red pixel

Answers: 2

body:
I just copied your exact code and ran it with 600 of my LEDs. I have WS2812B as well, and using the same data pin coincidentally.

I haven't experienced your red LED issue. I then ran it again on my LEDs after adding

     hue++;
at line 33.

Only problem I can see is that the last 30 LEDs at the end of the rainbow kind of flicker. Groups of 10 LEDs spontaneously flicker at once, then another 10, and so on. This could be a problem with my LEDs though because they were the cheapest one's I could find on ebay 2 years ago. The code seems to work fine for me though!

body:
It seems that this is caused by a compiler bug when compiling with the default -Os (optimize for size) option.

see Issue : [fill_rainbow() - Unexpected red pixel #668](https://github.com/FastLED/FastLED/issues/668)

A workaround is to change the optimization level to -O3 for `fill_rainbow`, ie :

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

    #pragma GCC push_options       // Disable the size optimization
    #pragma GCC optimize ("-O3")   // to prevent the “red pixel” problem
    void fill_rainbow( struct CRGB * pFirstLED, int numToFill,
                      uint8_t initialhue,
                      uint8_t deltahue )
    {
        CHSV hsv;
        hsv.hue = initialhue;
        hsv.val = 255;
        hsv.sat = 240;
        for( int i = 0; i < numToFill; i++) {
            pFirstLED[i] = hsv;
            hsv.hue += deltahue;
        }
    }
    #pragma GCC pop_options // Enable the prior optimization

You would have to edit `colorutils.cpp` (the file where `fill_rainbow` lives above) in the FastLED source in your `\libraries` directory.


body:
Here's the code:

    #include <SoftwareSerial.h>
    #define RX 6
    #define TX 5

    String AP = "...";
    String PASS = "...";

    SoftwareSerial esp8266(RX,TX);

    void setup() {
      Serial.begin(9600);
      Serial.println("Setup started");

      esp8266.begin(115200); // Change this to the factory baudrate used by ESP8266
      delay(1000);

      Serial.println("Setting BAUDRATE to 9600");
      esp8266.println("AT+IPR=9600");
      esp8266.begin(9600);
      delay(500);
      Serial.println("Setup finished");

      reset();
      connectWifi();
    }

    //reset the esp8266 module
    void reset() {
      Serial.println("Resetting...");
      esp8266.println("AT+RST");
      delay(3000);

      if (esp8266.find("OK"))
        Serial.println("Module Reset");
      else
        Serial.println("Module Reset Failed!!!");
    }

    //connect to your wifi network
    void connectWifi() {
      Serial.println("Connecting to Wifi...");
      String cmd = String("AT+CWJAP=\"") + AP + "\",\"" + PASS + "\"";
      esp8266.println(cmd);
      delay(4000);
      Serial.println("Checking Wifi...");
      int ctr=0;
      while(!(esp8266.find("OK"))) {
        if(esp8266.find("ERROR")) {
          Serial.println("Cannot connect to wifi...");
          break;
        }
        delay(50);
        ++ctr;
        if(ctr>10){
          Serial.println("Cannot connect to wifi...");
          break;
        }
      }
      Serial.println("ConnectWifi finished");
    }

The ESP8266-01S wires are as follows:

1. GND to arduino ground
2. 3v3 to arduino 3v3
3. RX to arduino pin 5
4. TX to arduino pin 6
5. EN to arduino 3v3

The thing worked for one time, and when I re-compiled and sent it again without any changes or even button presses, it stopped working. Furthermore, if I connect ESP module directly through arduino rx and tx and connect arduino reset to ground, I still don't get anything. The led on the esp is blinking during data transfers, but everything else doesn't change and I get no response at all.

title: ESP8266-01S Stopped responding after second launch

Answers: 1

body:
You need to re-flash your AI Thinker firmware. AT+IPR kills certain versions of the firmware.

Install the latest version of the firmware and use `AT+UART_DEF=9600,8,1,0,0` and `AT+UART=9600,8,1,0,0`. (The former sets the default baud rate, the latter the current baud rate).

You can read more [here](https://www.esp8266.com/viewtopic.php?f=6&t=1997).


body:
I saw that [Arduino got a CLI][1] (Command Line Interface), and my first question was "why?"  Even after reading the article, I don't see or understand its advantages.

What advantages or benefits does a CLI have for Arduino?

I haven't done much with Arduino in several years.  For example, there wasn't an Arduino SE when I was fooling around with Arduino, so I probably have an out of date context for Arduino development.

  [1]: https://www.cnx-software.com/2018/08/26/arduino-cli-arduino-command-line-interface/

title: What are the benefits or advantages of Arduino CLI?

Answers: 1

body:
Simple: you can program the Arduino without needing a GUI.

One good example: You have an Arduino connected to a Raspberry Pi built into a robot. You SSH into the Pi, edit the Arduino's program, and upload the new code. All from wherever you happen to be.

A second example: You can integrate Arduino compilation into your own software. Such as a web interface for compiling your code.  I know of one such project where the creator has made a custom website for editing their robot code and using UECIDE's CLI (which pre-dates Arduino's) to compile and upload the code to the target board.

And yes, you have an outdated context of Arduino development, as evidenced by your use of the phrase "fooling around with". Arduino is not a toy. It's a development platform and educational tool. Maybe back when you were "fooling around" with it, it was little more than a toy, but things have moved on a long long way since then. The Arduino ecosystem boasts boards with chips from every manufacturer you can imagine to fill every niche you can conceive. The API and available libraries have certainly matured.


body:
I buy a OLED as picture below, I want to use https://github.com/adafruit/Adafruit_SSD1306 to control it. But the example of https://github.com/adafruit/Adafruit_SSD1306 can't be compiled. The error as the second picture below. How should I to use this OLED ?

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

  [1]: https://i.stack.imgur.com/C7wMT.jpg
  [2]: https://i.stack.imgur.com/MymMM.jpg

title: How to use the 0.91' 128*32 OLED by arduino pro mini?

Answers: 1

body: In addition to installing the Adafruit_SSD1306 library, you also need to install the Adafruit_GFX library, which is a dependency of the SSD1306 library.


body:
I salvaged an old LCD from a calculator (Texas Instruments) and I want to interface it with a microcontroller (preferably an Arduino). I‘ve searched the whole internet but I simply can‘t find any information about this display and its driver. I am looking for a specialist who can identify this:

[![First Picture][1]][1]

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

title: LCD Identification FPC-JG00467-01B SR36

Answers: 1

body: It's most likely a custom part for which there is no public data sheet. LCDs are almost always custom-designed, and require special driver circuitry. This is especially true for such mass-produced items as calculators.


body:
Thanks in advance..

We are having esp8266-12E chip and Atmega328 connected as follows,
ESP 12 pin as Tx,13 pin as Rx && Atmega328 13pin as Rx, 12pin as Tx. Everything works fine, but while communicating via serial some low pulse is being generated. We couldn't find the issue with multimeter anyway but got it by oscilloscope signal.

When this false low pulse during communication happens Atmega328 connected pins also getting low for the same duration.

We tried using separated logic execution for ESP and Atmega and both were worked perfectly, but only during communicating via Software serial its flickers getting started.

Please help us getting this resolved.

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

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

title: ESP8266 Software serial to ATmega 328 is not properly working

Answers: 1

body:
Don't use SoftwareSerial in esp8266. Connect the 328p's SoftwareSerial pins to Serial interface pins of the esp8266. ESP8266 has second Serial interface named Serial1. It has only TX (io 2), but it is enough for debug prints.

To change the firmware or sketch in esp8266 you can use ArduinoOTA library, but you should be ready to disconnect the esp8266 Serial pins from the 328p and use them for Serial upload if the OTA upload fails.

You should use logic level converter from 5 V to 3.3 V to protect the esp8266 RX pin.


body:
So I'm playing with a TFT screen and trying to understand the colourspace encoding.  I wrote a quick `for` loop to show colours from 0 to FFFF and to print the value of colour being displayed:

    for (int q=0; q<0xFFFF; q+=0x80) {
      tft.fillScreen(q);
      tft.setCursor(0, 0); tft.println(q, HEX);
      delay(2);
    }

I was surprised to find values greater than FFFF being displayed - which suggest that `int` is more than 16 bits.  It's running on a Uno.

What has happened?

(PS I now understand RGB565 encoding, so this is off-topic)

title: int on Uno more than 16 bit?

Answers: 1

body:
I guess you're seeing some big numbers starting with FFFF...?

What you are seeing is not big numbers - it's misrepresented numbers.

You have an `int`. That's not a "16-bit number", it's a 15-bit number *plus a sign bit*.

When you print it the variable is *promoted* to a `long` and the sign bit is *extended*.

That `long` is then further mapped (cast) into an `unsigned long` to print it as hexadeximal (there is no negative in the hexadecimal representation on Arduino), and that *extended sign bit* is seen as a string of F.

For example, the value 0xABCD stored in an `int` is:

     1 010 1011 1100 1101

I broke off the first bit because that is the *sign* bit in a *signed integer*.  The actual decimal value of that is -21555.

Now when that gets cast to a long the sign extension copies the leading sign bit to all the other 16 bits to the left of it, resulting in:

    1 111 1111 1111 1111 1010 1011 1100 1101

Because of the way that *twos complement* works, that string of bits still represents -21555 in decimal.

However, cast it to `unsigned long` for printing as HEX and you can see how you would end up with some big numbers.  It would give you:

    FFFFABCD

So you can see that a 16 bit signed value can end up being printed as 8 hex digits, and all because of the way the `print()` function in the Arduino API works.

When working with unsigned values you really should be working with an unsigned variable - especially if those unsigned values (0 - 65535) fall outside the range of the signed variable type (-32768 - 32767).  Switch to using `uint16_t` and you will be able to both store and represent the values correctly.

----

You might find it useful [playing around with this site](http://www.binaryconvert.com/) to learn how different variable types represent and store the data within them as binary.


body: I am having a digital output of 24VDC and 0.5A from ABB IRC5 controller. I need to feed this digital output to the digital input of Arduino uno. How can I do that?

title: How much voltage and current can a Arduino uno digital input sink?

Answers: 4

body:
You have 2 different questions here. First one can be answered by google search, it is literally the first result.

*The Arduino Uno uses the atMEGA328 microcontroller, which has an absolute maximum rating of 40 mA source or sink per GPIO. Also, the total current through the supply or ground rails (i.e. the total of all current OP wants the GPIO pins to sink, or source) is rated to a maximum of 150 200 mA.*

And you should not apply more than 5V.

Regarding second question, Google can help again.

[![Vin is your 24V, Vout is your arduino digital input][1]][1]

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

Vin is your 24V from controller, Vout is your Arduino digital 5V input. With that established, use voltage divider formula to calculate R1 and R2 values. I hope you can do that?
That being said, I am disappointed, because I feel like you have put 0 effort into researching this.

body:
As a complement to user43648's answer, it is worth noting that:

1. According to the datasheet, the 40 mA limit “is a stress rating
   only and functional operation of the device [...] is not implied”
   beyond the maximum tested current which is 20 mA.
2. The input voltage should be at least 3 V for the pin to be
   guaranteed to read high.
3. When sensing voltage through a voltage divider, 10 kΩ is a
   somewhat typical order of magnitude for the resistors.

Given the above, I would suggest using 47 kΩ for the top resistor
and 10 kΩ for the bottom one. This should give about 4.2 V on
the input pin, which is near the middle of the appropriate range for the
pin to read `HIGH`.

body:
One common misconceptions is that the current limit of a GPIO pin applies to inputs.  It does not.

The 40mA "maximum sink" is only applicable when the pin is set to OUTPUT and is driven LOW - at which point the pin is connected to ground through a MOSFET.

* Read: [What Exactly is a GPIO Pin?](https://majenko.co.uk/blog/what-exactly-gpio-pin)

However, when the pin is in INPUT mode it is *high impedance*.  This means that it neither sinks nor sources current (apart from a very tiny *leakage current*).  The only thing that matters is the voltage.  That must:

* Never go higher than 0.3V above VCC (5.3V if powered from 5V)
* Never go lower than -0.3V
* Have logic levels that are within the thresholds of the input:
  * Below 0.3 × VCC for LOW
  * Above 0.6 × VCC for HIGH

You can connect the input to a signal that is 5V and 1,000,000 giga-amps and all will be well.

However, if you inadvertently set the pin to OUTPUT and drive it LOW there will instantly be smoke.  For this reason it is common to add a small inline resistor (maybe 100Ω-470Ω) in order to limit any current through the circuit should the pin ever be set to OUTPUT and LOW.

Another "However", though:  If you are using a voltage divider to reduce your incoming voltage to conform to the values above (as shown by @user43648 and suitable values given by @EdgarBonet) the inline resistor is pointless. The voltage divider itself will have a very high *output impedance* which massively limits the current. This impedance is like having a resistance equivalent to both the provided resistors in parallel inline with your input.

body: In addition to the potential divider I would be tempted to strap the input pin to ground with a zener diode between 4V7 and 5V1 in case the lower resistor or its solder joints fail. even with a relatively high value series resistor 24V has plenty of potential to destroy the input pin if not the entire chip. The safest method though is use an opto-isolator and keep the nasty high voltages isolated from the delicate digital level components.


body:
I am an electronics graduate and an embedded design engineer, working in this field for about two years apart from the hobby time during my graduation. I am currently working on a system that has an Atmega2560 as the core controller with an arduino bootloader, we are using an 8GB memory card to save the log data from our system and send it to our server at regular intervals of time. The system worked fine however some of them are facing issues with the writing of data, some garbage value are getting stored in the SD card. I have attached the schematic and code snippet for the same, please let me know if there is any problem with the system and how can i resolve it, please let me know if any other things are required for understanding the problem correctly.

Thank you in advance.

         SD_Initialize();
      if(!SD.exists(SDTransactionDirectory))
      {
        if(SD.mkdir(SDTransactionDirectory))
        {

        }
      }
      RTC_Date_Time();
      String FileName = SDTransactionDirectory + "/" + RTCSDDate + RTCSDTime + ".txt";
      SD_File = SD.open(FileName, FILE_WRITE);
      if(SD_File)
      {
        delay(100);
        digitalWrite(LED_SD, HIGH);
        SD_File.println(GSMData);
        SD_File.close();
      }

The SD_Initialize() is a user function:-

    void SD_Initialize()          //initialise SD card
    {
      digitalWrite(SD_EN, HIGH);
      digitalWrite(SD_CS, LOW);

      delay(500);

      if(SD.begin(SD_CS))
      {
        digitalWrite(LED_SD, HIGH);
      }
      else
      {
        digitalWrite(LED_SD, LOW);
      }
    }

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

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

The data stored in the filename is as follows:-
CLEnT|T|M008|\00Ÿûmï°]ŸëÜ£·zoòTÏæ{Œü[ŸýUô~ÛcCWY`®ÞgÙë×<;wBÄgnìÇFÿÉ=XoÎ.êžÄf·®ö¯³ç~åeÝ]1_`ÏÀyÿÌÍ?ô"zBõ¬ñ

As you can see the initial values till "M008" is fine but its garbage after that, and the CLEnt|T|M008 is the start of the string after that a lot of other parameter information is to be stored which turns out to be garbage.

title: Garbage stored in SD card

Answers: 1

body:
There are many comments, but no answer yet. This answer has only a few basic rules.

The first thing to do is to see if the problem can be replicated with a small sketch and to check the voltages.

The arduino mega 2560 works best at 5.0V, or maybe a little less. It is not reliable at 4V. When powering it with a 5V power supply, the usb connecter is the best option to power the arduino board. Powering the arduino board via the 5v pin is not advised. When a strong power supply is connected to the 5v pin, the voltage regulator can be blown.

When something is not working, fall back to something that is reliable. For example a SD module with a HC4050 to shift the voltage levels. The resistors make the signal weaker.

Make a small test sketch without the use of the String object. The more experienced someone is with arduino, the more he or she tells to avoid the String object with avr microcontrollers.

There are counterfeit SD cards. One of those might turn up in your hands someday. Beside that, not every SD card is compatible with the arduino SD library.

In your situation it is suspicious that the file system is okay, the filenames are okay, the first text is okay, but when data is written it suddenly goes wrong. That is a strong indication for a memory problem.

When data to a display or SD card is wrong, then send it also to the serial monitor. You have to know what is actually written to the SD card.


body:
I have created a custom library for local usage. I call is `ABC_node` for ESP32 and the structure is as follows:

    .
    |-- examples
    |   |-- bnoCalibStorage
    |   |   `-- bnoCalibStorage.ino
    |   |-- influxHTTP_write
    |   |   `-- influxHTTP_write.ino
    |   |-- influxPing
    |   |   `-- influxPing.ino
    |   |-- influxUDP_write
    |   |   `-- influxUDP_write.ino
    |   `-- rtcTimestamp
    |       `-- rtcTimestamp.ino
    |-- keywords.txt
    |-- library.properties
    |-- README.md
    |-- ABC_Node.cpp
    `-- ABC_Node.h

I tried following the Adafruit GitHub Repository structure where each example is placed inside a folder named after the sketch.

I am hosting this repository on a private GitLab Server. I used `git tag v1.0.0` to create a tag and from GitLab I could download the `.zip` file for the stable v1.0.0 library.

I manually extracted the files to my `<user>\Documents\Arduino\libraries` folder and renamed the folder to `ABC_Node` (since my gitlab repo is named something else)

I restarted my IDE but I could not find the library `ABC_Node` in

    Sketch\Include Library\

###`library.properties`

    name=ABC_Node
    version=1.0.0
    author=Shan Desai
    maintainer=Shan Desai
    sentence=Firmware to create InfluxDB measurements and send them via HTTP/UDP to Core
    paragraph=ABC_Node provides `String` based InfluxDB measurements which can then be sent via HTTP/UDP to a central InfluxDB instance.
    category=Data Processing, DAQ
    architecture=ESP32
    repository=https://[gitlab-address]/node-repo.git

 I followed the [Libraries Guide from Arduino on local Installation](https://www.arduino.cc/en/Guide/Libraries)
### System

Windows 10

Arduino IDE 1.8.5

title: Arduino IDE does not display examples folder from my custom library

Answers: 1

body:
Your library.properties is lacking a line.  Emulating your library with blank files and copying in your library.properties content, and running on Linux from the command line, it reports to me:

    Invalid library found in /home/matt/Arduino/libraries/ABC_Node: Missing 'url' from library

So you lack the line:

    url=https://whatever.website.you.want.to/point.to

(Or use something like `http://example.com` if you don't want one...)

I put that line in, and magically the library appears in the list.


body:
I have created my custom library with `examples` folder in them. The main header file is `ABC_Node.h`. I am referring the structure of Adafruit libraries for Arduino and in some repos under the `examples` folder I found a conflict for the inclusion of their header files.

### Example

in some repos. they use __double quotes__ (`""`) for including their header files e.g. `#include "Adafruit_SHT31.h"`
[SHT31test.ino](https://github.com/adafruit/Adafruit_SHT31/blob/master/examples/SHT31test/SHT31test.ino)

on the contrary, in their BNO055 Arduino library they use brackets (`<>`) `#include <Adafruit_BNO055.h>` [BNO055 Bunny sketch](https://github.com/adafruit/Adafruit_BNO055/blob/master/examples/bunny/bunny.ino)

I locally tested my library on the IDE and I have examples in which my library is in `#include "ABC_Node.h"` and it compiles without a problem.

Soon I wish to make the repository public and want to know if there is a standard practice for including header files for examples.

title: Standard Practice for including custom library in examples folder

Answers: 1

body:
You can use either. There is no "standard".

When using a raw C compiler there is a difference between the two as regards the order in which directories are searched for files to include, but with the Arduino that is completely irrelevant, so either can be used.

Personally I use `<...>` for libraries and `"..."` for header files that form part of the sketch.  It makes for easier identification of which is which, and conforms to the C standard of `<...>` for system-installed headers, and `"..."` for local headers.


body:
At early morning i have accidentally the error of GNOME for my OS, so I was forced reinstall my OS couse i don't have any backup for my packages and my database. i'm installed Arduino-IDE 1.8.7, Arduino AVR Boards 1.6.23 and Esp8266 Boards 2.4.2 . when i trying to upload my sketch, i get this error:

    ...
    Unable to cache built core, please tell esp8266 maintainers to follow http://goo.gl/QdCUjo
    ...

I see the link, but i cannot see where my archive variable in platform file for my cores.

    ...
    ## Create archives
    recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"
    ...

**See** my verbose [log][1] !!!.

    /home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/spiffs_api.cpp.o
    /home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/spiffs_hal.cpp.o
    /home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/time.c.o
    /home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/uart.c.o
    /home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/umm_malloc/umm_malloc.c.o
    Unable to cache built core, please tell esp8266 maintainers to follow http://goo.gl/QdCUjo
    Linking everything together...
    /home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc -CC -E -P -DVTABLES_IN_FLASH /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld.h -o /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld
    /home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc -Wl,-Map -Wl,/tmp/arduino_build_988288/tesHC139.ino.map -g -w -Os -nostdlib -Wl,--no-check-sections -u app_entry -u _printf_float -u _scanf_float -Wl,-static -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/lib -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/libc/xtensa-lx106-elf/lib -Teagle.flash.4m1m.ld -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -o /tmp/arduino_build_988288/tesHC139.ino.elf -Wl,--start-group /tmp/arduino_build_988288/sketch/tesHC139.ino.cpp.o /tmp/arduino_build_988288/libraries/SPI/SPI.cpp.o /tmp/arduino_build_988288/libraries/Adafruit_BME280_Library-master/Adafruit_BME280.cpp.o /tmp/arduino_build_988288/libraries/Wire/Wire.cpp.o /tmp/arduino_build_988288/arduino.ar -lhal -lphy -lpp -lnet80211 -llwip2 -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group -L/tmp/arduino_build_988288
    /home/praz/.arduino15/packages/esp8266/tools/esptool/0.4.13/esptool -eo /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/bootloaders/eboot/eboot.elf -bo /tmp/arduino_build_988288/tesHC139.ino.bin -bm dio -bf 40 -bz 4M -bs .text -bp 4096 -ec -eo /tmp/arduino_build_988288/tesHC139.ino.elf -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
    Using library SPI at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI
    Using library Adafruit_Sensor-master at version 1.0.2 in folder: /home/praz/Arduino/libraries/Adafruit_Sensor-master
    Using library Adafruit_BME280_Library-master at version 1.0.7 in folder: /home/praz/Arduino/libraries/Adafruit_BME280_Library-master
    Using library Wire at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/Wire
    /home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-size -A /tmp/arduino_build_988288/tesHC139.ino.elf
    Sketch uses 259408 bytes (24%) of program storage space. Maximum is 1044464 bytes.
    Global variables use 28352 bytes (34%) of dynamic memory, leaving 53568 bytes for local variables. Maximum is 81920 bytes.
    /home/praz/.arduino15/packages/esp8266/tools/esptool/0.4.13/esptool -vv -cd nodemcu -cb 115200 -cp /dev/ttyUSB0 -ca 0x00000 -cf /tmp/arduino_build_988288/tesHC139.ino.bin

I don't think so if i have permissions issue, it seems my boards is fine about my permissions.

    total 388
    drwxrwxr-x  8 praz praz   4096 Okt 11 00:14 ./
    drwxrwxr-x  3 praz praz   4096 Okt 11 00:13 ../
    -rw-rw-r--  1 praz praz 293575 Agu  3 14:19 boards.txt
    drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 bootloaders/
    drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 cores/
    -rw-rw-r--  1 praz praz    235 Agu  3 14:19 .gitmodules
    -rw-rw-r--  1 praz praz   2831 Agu  3 14:19 ISSUE_TEMPLATE.md
    -rw-rw-r--  1 praz praz    553 Agu  3 14:19 keywords.txt
    drwxrwxr-x 28 praz praz   4096 Agu  3 14:19 libraries/
    -rw-rw-r--  1 praz praz  26529 Agu  3 14:19 LICENSE
    -rw-rw-r--  1 praz praz    194 Agu  3 14:19 package.json
    -rw-rw-r--  1 praz praz   6844 Agu  3 14:19 platform.txt
    -rw-rw-r--  1 praz praz   7136 Agu  3 14:19 POLICY.md
    -rw-rw-r--  1 praz praz      0 Agu  3 14:19 programmers.txt
    -rw-rw-r--  1 praz praz   7722 Agu  3 14:19 README.md
    drwxrwxr-x  4 praz praz   4096 Agu  3 14:19 tests/
    drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 tools/
    drwxrwxr-x 25 praz praz   4096 Agu  3 14:19 variants/

**Solved**

I think when i installed Esp8266 Boards 2.4.2 latest version is fine, i uploaded my sketch and i cannot make cache to my built core, Majenko is right, my the snippet of config are difference between my [74hc139][2] issue and my [verbose log][1] issue.

when i installed fresh Esp8266 Boards using boards manager, that automatically downloads source code of esp8266 core on this [Github][3], i don't understand why my snippet of config not updated like this [commit][4]. so i updated my config of boards with copy/paste on tree links of  [Github][5], and that's works.

See my verbose below or see at [this][6] :

    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/sqrt32.c.o
    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/time.c.o
    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/uart.c.o
    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/umm_malloc/umm_malloc.c.o
    Archiving built core (caching) in: /tmp/arduino_cache_39139/core/core_8e365e854c5bfceaa27f4c371ba290d0.a
    Linking everything together...
    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -CC -E -P -DVTABLES_IN_FLASH /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld.h -o /tmp/arduino_build_979295/local.eagle.app.v6.common.ld
    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -Wl,-Map -Wl,/tmp/arduino_build_979295/tesHC139.ino.map -g -Wall -Wextra -Os -nostdlib -Wl,--no-check-sections -u app_entry -u _printf_float -u _scanf_float -Wl,-static -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/lib -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/libc/xtensa-lx106-elf/lib -Teagle.flash.4m.ld -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -o /tmp/arduino_build_979295/tesHC139.ino.elf -Wl,--start-group /tmp/arduino_build_979295/sketch/tesHC139.ino.cpp.o /tmp/arduino_build_979295/libraries/SPI/SPI.cpp.o /tmp/arduino_build_979295/libraries/Adafruit_BME280_Library-master/Adafruit_BME280.cpp.o /tmp/arduino_build_979295/libraries/Wire/Wire.cpp.o /tmp/arduino_build_979295/core/core.a -lhal -lphy -lpp -lnet80211 -llwip2-536-feat -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group -L/tmp/arduino_build_979295
    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/esptool/esptool -eo /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/bootloaders/eboot/eboot.elf -bo /tmp/arduino_build_979295/tesHC139.ino.bin -bm dio -bf 40 -bz 4M -bs .text -bp 4096 -ec -eo /tmp/arduino_build_979295/tesHC139.ino.elf -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
    Using library SPI at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI
    Using library Adafruit_Sensor-master at version 1.0.2 in folder: /home/praz/Arduino/libraries/Adafruit_Sensor-master
    Using library Adafruit_BME280_Library-master at version 1.0.7 in folder: /home/praz/Arduino/libraries/Adafruit_BME280_Library-master
    Using library Wire at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/Wire
    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-size -A /tmp/arduino_build_979295/tesHC139.ino.elf
    Sketch uses 265524 bytes (25%) of program storage space. Maximum is 1044464 bytes.
    Global variables use 28236 bytes (34%) of dynamic memory, leaving 53684 bytes for local variables. Maximum is 81920 bytes.
    /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/esptool/esptool -vv -cd nodemcu -cb 115200 -cp /dev/ttyUSB0 -ca 0x00000 -cf /tmp/arduino_build_979295/tesHC139.ino.bin

Hope anyone can solve my issue, Thanks in advance.

  [1]: http://paste.ubuntu.com/p/2n6GVkgM3m/
  [2]: https://arduino.stackexchange.com/questions/55938/how-do-i-select-sensor-using-chip-74hc138-on-wemos-d1-mini
  [3]: https://github.com/esp8266/Arduino
  [4]: https://github.com/esp8266/Arduino/commit/85e68093e94b4e5c5e711888b8b5facee1bd4f9f#diff-d638a47d1ca0e2a5585fb34c7d7fb0f9L95
  [5]: https://github.com/esp8266/Arduino/tree/85e68093e94b4e5c5e711888b8b5facee1bd4f9f
  [6]: http://paste.ubuntu.com/p/ZwKXXCd4gg/

title: My verbose appears "unable to cache built core"

Answers: 1

body:
This was fixed on the 20th August in [this commit](https://github.com/esp8266/Arduino/commit/85e68093e94b4e5c5e711888b8b5facee1bd4f9f#diff-d638a47d1ca0e2a5585fb34c7d7fb0f9L95). Make sure you have the latest version of the ESP8266 core installed. If there hasn't been a release since that fix, you can pull the github version of the config file and use that instead of the one bundled with the core.

However, it's not a fatal error - it merely means that compilation will be slower than it should be.


body:
Trying to build an arduino-based Mouse/Keyboard enhancer.  This will let me do things like press certain keyboard or mouse shortcuts on the input side, then do something custom on the output side.  For instance, this would let me add keyboard shortcuts at the hardware level instead of having to do them at the OS level.

As such, I'm looking for a board which can act both as a USB host (i.e. it can have a keyboard and mouse plugged into it) as well as one that can show up as a USB HID device to the computer it's plugged into.

The boards that I'm aware of which have something close to this are the Leonardo and chip-similar, which work to emulate a keyboard/mouse to the computer they're attached to, but which don't let you connect a keyboard/mouse to them.

So is there such a board?

title: Is there a board that can act as both a USB host and client for HID devices?

Answers: 1

body:
The TMK USB to USB converter is a thumb drive sized board with ATMega32u4 and max3421e with pass through/remapper software. It has the same functionality as a Leonardo with USB host shield.

https://geekhack.org/index.php?topic=69169.0


body:
I have a signal that fluctuates between -70mV and 50mV. How would I get the arduino to read this.. Ultimately I am trying to graph the data in real time so it looks like this.

[Positive/Negative Voltage Graph]: https://i.stack.imgur.com/a8zIE.jpg

![Positive/Negative voltage](https://i.stack.imgur.com/a8zIE.jpg)

https://i.stack.imgur.com/a8zIE.jpg

title: How would I go about measuring an analog signal on my arduino mega that has both positive and negative voltages

Answers: 2

body:
You need to amplify your signal and add 2.5V as a "virtual ground" for the amplification. This gets a little tricky, since you need a low-impedance VCC/2 source to feed the amplifier as a virtual ground.  This would require a unity-gain buffer fed from a voltage divider:

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

Now you use that to feed the amplifier:

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

The gain is set by 1+(RF/RG), or 11 in this case, giving you -0.77V to +0.55V.

There is a simpler option, though. (There is another intermediate option but the editor lost it and I can't be bothered to spend the time recreating it).

This method does come at a cost, though: it inverts the signal. The -0.07 becomes 0.07 and the 0.05 becomes -0.05, and multiplied by the gain and added to the offset:

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

Here you get a transformation from -0.07V - +0.05V to +0.7V - -0.5V.  That means that *in software* you then have to invert the value (simply subtract it from 0 after removing the DC offset).

You're basically shifting some of the complexity out of the circuitry and into the software.

Personally I use the inverting amplifier (the last circuit) because the virtual ground current is near zero, so you don't need a low impedance VCC/2 voltage source. It's also easier to create more sensible gains (like 10x) than the non-inverting amplifier, which always has 1 added to the gain.

body:
Here is my try at this: if your voltage source doesn't mind sinking
something like 150 µA, you could try something like this:

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

<!-- End schematic -->

This should map the input range [−70 mV, +50 mV] to
[0.04 V, 4.06 V].