body:
I would suggest using different software serial libraries and pins.  To apply [this answer](https://arduino.stackexchange.com/questions/26240#26277), I would suggest this configuration:

* Connect your RS232 device to pins 0 & 1 and use `Serial`
* Connect your GSM device to pins 8 & 9 and use `AltSoftSerial` (it must use those pins).

If you do not send anything *to* the RS232 device, you can still use `Serial` for debug statements.  Don't even connect the TX pin to the RS232 device.  You will have to disconnect the RX pin to upload new sketches over USB.  Or, if the RS232 device receives formatted commands, it would ignore debug statments that don't look like commands.  This has the added benefit that the Serial Monitor window will display the commands you do send to the RS232 device.

If you *really* need to use 3 serial ports, you will have to use this configuration:

* Use `Serial` for whatever
* Connect the RS232 or GSM device to pins 8 & 9 and use `AltSoftSerial`
* Connect the other device to any two pins and use my [NeoSWSerial](https://github.com/SlashDevin/NeoSWSerial).

`AltSoftSerial` is more efficient at transmitting than `NeoSWSerial`, so use `AltSoftSerial` for the device to which you send the most data.  `NeoSWSerial` is limited to baud rates 9600, 19200 and 38400, so that may be a consideration.

`SoftwareSerial` is a terrible choice, because it disables interrupts for long periods of time, it can only listen to one port at a time, and it cannot transmit and receive at the same time.

`AltSoftSerial` and `NeoSWSerial` do not have these limitations, and they can co-exist to give you 2 extra serial ports.  You should also be aware the `NeoSWSerial` disables interrupts while transmitting (not receiving).  `AltSoftSerial` uses one of the TIMER resources, while `NeoSWSerial` simply uses the `millis()` timer.

### ADDENDUM

To answer your original question about using the `EnableInterrupt` library at the same time as a software serial library:

If you are using the first configuration above, `AltSoftSerial` will not conflict with `EnableInterrupt`.

If you are using the second configuration, `NeoSWSerial` **will** conflict with `EnableInterrupt`.  For this possibility, `NeoSWSerial` has an option to disable using all the Pin Change Interrupt ISRs.  Uncomment [this line](https://github.com/SlashDevin/NeoSWSerial/blob/master/src/NeoSWSerial.h#L108) and call the NeoSWSerial::rxISR from the appropriate `enableInterrupt()` callback function:

    #include <NeoSWSerial.h>
    NeoSWSerial oneDevice( RX_PIN, TX_PIN );

    void myISR()
    {
      NeoSWSerial::rxISR( *portInputRegister( digitalPinToPort( RX_PIN ) ) );
    }

    void setup()
    {
      enableInterrupt( RX_PIN, myISR, CHANGE );
    }

This puts `EnableInterrupt` in charge of the ISRs.  If you want to try `NeoSWSerial`, it is available from the Arduino IDE Library Manager, under the menu **Sketch -> Include Library -> Manage Libraries**.


sender: user

message:
What datatype is the names of the analog inputs?

I am writing a code for an automatic garden, and for this, I will use an array of sensors. I want to represent each plant as a class, and so one of the private variables will then be the sensorID, the name of the input on the analog inputs. But these are called 'A0' 'A1' and so forth, so I am wondering what datatype they are?

    class Plant{
    private:
    String name;
    ??? sensorId;
    ...
    public:
    readSensor(??? sensorId);
    ...
    };

I want to standardize this so I don't have to physically write 'A0' or 'A1' each time I need to read the sensor.

sender: assistant

body:
They're `uint8_t`:

    static const uint8_t A0 = 14;
    static const uint8_t A1 = 15;
    static const uint8_t A2 = 16;
    static const uint8_t A3 = 17;
    static const uint8_t A4 = 18;
    static const uint8_t A5 = 19;
    static const uint8_t A6 = 20;
    static const uint8_t A7 = 21;

Those are defined in the `pins_arduino.h` file in the board's variant folder.


message:
Countdown sometime stop

I've made a game with 3 countdowns and 1 global countdown.

 - When we start, the global one, go from 45:00 to 00:00.

 - The 1 go from 15:00 to 00:00 and if it reach 00:00:

 - The 2 start and go from 15:00 to 00:00 and it if reach 00:00:

 - The 3 start and go from 15:00 to 00:00

If you win little game, you can stop a countdown and start the next. If you win the 3 games, you stop the 3 countdown and the global too.

But sometime, my 2nd countdown stop itself, sometime at 13:58 or 10:54…

Is it possible that the **millis()** cause that bug ? Do you have an idea to improve my code and fix that ?

Fun fact : Sometime countdowns go from 01 to 60 instead of 00 to 59……

Sorry for my english, i'm not native speaker.

    //14-06-17 Correctifs LED
    //10-06-17 Correctif Jeu 1

    #include "musical_notes.h"
    #include "TM1637.h"
    #include "SevenSegmentTM1637.h"
    #include "OnewireKeypad.h"
    #include "Password.h"

    SevenSegmentTM1637    displaya(4, 5);
    SevenSegmentTM1637    displayb(6, 7);
    SevenSegmentTM1637    displayc(8, 9);
    SevenSegmentTM1637    displayd(50, 51);

    TM1637 tm1637a(50, 51); //TIMER GLOBAL 45
    TM1637 tm1637b(4, 5); //TIMER 1 15
    TM1637 tm1637c(6, 7); //TIMER 2 15
    TM1637 tm1637d(8, 9); //TIMER 3 15

    char KEYS[] = {
      '1', '4', '7', '*',
      '2', '5', '8', '0',
      '3', '6', '9', '#',
      'A', 'B', 'C', 'D'
    };
    OnewireKeypad <Print, 16 > KP(Serial, KEYS, 4, 4, A0, 4700, 1000, ExtremePrec );
    Password password = Password( "8751" );

    //PREMIER JEU
    int checkbranche = 23;
    int checkbrancheb = 22;
    int checkbranchec = 24;
    int state = HIGH;
    int reading;
    int readingb;
    int readingc;
    int previous = LOW;
    int previousb = LOW;

    int readingstart;
    int checkstart = A1;

    int speakerPin = 52;
    int runOPEN = 0;
    int runJEU1 = 0;
    int runJEU2 = 0;
    int runJEU3 = 0;
    int runFAILGLOBAL = 0;

    int winJEU1 = 0;
    int winJEU2 = 0;
    int winJEU3 = 0;
    int winGLOBAL = 0;
    int looseGLOBAL = 0;

    int LED_jeu1_V = 30;
    int LED_jeu1_R = 31;
    int LED_jeu2_V = 33;
    int LED_jeu2_R = 32;
    int LED_jeu3_V = 35;
    int LED_jeu3_R = 34;

    int LED_jglobal1 = 36;
    int LED_jglobal2 = 37;
    int LED_jglobal3 = 38;
    int LED_jglobal4 = 39;

    int runcode = 0;

    int second=0, minute=45, hour=0; // déclarer des variables de temps
    int second1=0, minute1=15, hour1=0; // déclarer des variables de temps
    int second2=0, minute2=15, hour2=0; // déclarer des variables de temps
    int second3=0, minute3=15, hour3=0; // déclarer des variables de temps
    long previousTime = 0;//détient temps précédent en ms
    long previousTime1 = 0;//détient temps précédent en ms
    long previousTime2 = 0;//détient temps précédent en ms
    long previousTime3 = 0;//détient temps précédent en ms
    long previousDelay = 0;//détient temps précédent en ms depuis buzzer était actif
    long previousDelay1 = 0;//détient temps précédent en ms depuis buzzer était actif
    long previousDelay2 = 0;//détient temps précédent en ms depuis buzzer était actif
    long previousDelay3 = 0;//détient temps précédent en ms depuis buzzer était actif
    long interval = 60000;//60 secondes de retard
    long interval1 = 60000;//60 secondes de retard
    long interval2 = 60000;//60 secondes de retard
    long interval3 = 60000;//60 secondes de retard

    int dismentel1 = 0; int fail1 = 0;
    int dismentel2 = 0; int fail2 = 0;
    int dismentel3 = 0; int fail3 = 0;
    int dismentel4 = 0; int fail4 = 0;

    char hour_str[4]; // Pour Convertir int en char
    char minute_str[4]; // Pour Convertir int en char
    char second_str[4]; // Pour Convertir int en char
    char timeInt_str[0];  // Pour Convertir int en char

    int accessgame = 3; //Activation de led quand les minutes arrivent à 3

    unsigned char halfsecond=0;

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

      KP.SetHoldTime(3000);
      KP.SetKeypadVoltage(5.0);
      KP.ShowRange();

       displaya.begin();
       displayb.begin();
       displayc.begin();
       displayd.begin();

       tm1637a.set(4);
       tm1637a.init();
       tm1637a.point(POINT_ON);

       tm1637b.set(4);
       tm1637b.init();
       tm1637b.point(POINT_ON);

       tm1637c.set(4);
       tm1637c.init();
       tm1637c.point(POINT_ON);

       tm1637d.set(4);
       tm1637d.init();
       tm1637d.point(POINT_ON);

       pinMode(checkbranche, INPUT);
       pinMode(checkbrancheb, INPUT);
       pinMode(checkbranchec, INPUT);
       pinMode(checkstart, INPUT);
       pinMode(speakerPin, OUTPUT);

       pinMode(LED_jeu1_V, OUTPUT);
       pinMode(LED_jeu1_R, OUTPUT);
       pinMode(LED_jeu2_V, OUTPUT);
       pinMode(LED_jeu2_R, OUTPUT);
       pinMode(LED_jeu3_V, OUTPUT);
       pinMode(LED_jeu3_R, OUTPUT);

       pinMode(LED_jglobal1, OUTPUT);
       pinMode(LED_jglobal2, OUTPUT);
       pinMode(LED_jglobal3, OUTPUT);
       pinMode(LED_jglobal4, OUTPUT);

       delay(1000);

    };

    // run loop (forever)
    void loop() {

    readingstart = digitalRead(checkstart);
    reading = digitalRead(checkbranche);
    readingb = digitalRead(checkbrancheb);
    readingc = digitalRead(checkbranchec);

    if (runcode < 1) {
    Serial.println("WHAT");

          if (readingstart == HIGH) {

            for (; runOPEN < 1; runOPEN++) {
              uhoh();
             }

        countdown();

    Serial.print(halfsecond);
    Serial.println(" ");

      if (dismentel1 == 1) {digitalWrite(LED_jglobal1, HIGH);} else {digitalWrite(LED_jglobal1, LOW);}
      if (dismentel2 == 1) {digitalWrite(LED_jglobal2, HIGH);} else {digitalWrite(LED_jglobal2, LOW);}
      if (dismentel3 == 1) {digitalWrite(LED_jglobal3, HIGH);} else {digitalWrite(LED_jglobal3, LOW);}
      if (dismentel4 == 1) {digitalWrite(LED_jglobal4, HIGH);} else {digitalWrite(LED_jglobal4, LOW);}

    // GESTION DU JEU 1 //
      if (reading == LOW) {  //REVISION 1 HIGH -> LOW
          countdown1();

          if (second1 > 0 && minute1 >= 0) {
              int8_t timeDisp1[4];
              timeDisp1[0] = minute1 / 10;
              timeDisp1[1] = minute1 % 10;
              timeDisp1[2] = second1 / 10;
              timeDisp1[3] = second1 % 10;
              tm1637b.display(timeDisp1);

          if (minute1 < accessgame) {
            digitalWrite(LED_jeu1_V, LOW);
            digitalWrite(LED_jeu1_R, HIGH);
          } else {
            digitalWrite(LED_jeu1_V, HIGH);
            digitalWrite(LED_jeu1_R, LOW);
          }

              dismentel1 = 0;

          } else {
              displaya.print("FAIL");
                digitalWrite(LED_jeu1_V, HIGH);
                digitalWrite(LED_jeu1_R, LOW);
                for (; runJEU1 < 1; runJEU1++) {
                  squeak();
                }
               fail1 = 1;
          }

      } else {
          displaya.print("--5-");
          digitalWrite(LED_jeu1_V, LOW);
          digitalWrite(LED_jeu1_R, HIGH);
          for (; winJEU1 < 1; winJEU1++) {
            wingame();
           }
           dismentel1 = 1;
      }

    // GESTION DU JEU 1 //

    // GESTION DU JEU 2 //
      if (readingb == HIGH) {
        dismentel2 = 1;
      }

      if ((dismentel1 == 1 or fail1 == 1) && dismentel2 == 0) {
        countdown2();

        if (second2 > 0 && minute2 >= 0) {
          int8_t timeDisp2[4];
          timeDisp2[0] = minute2 / 10;
          timeDisp2[1] = minute2 % 10;
          timeDisp2[2] = second2 / 10;
          timeDisp2[3] = second2 % 10;
          tm1637c.display(timeDisp2);
          if (minute2 < accessgame) {
            digitalWrite(LED_jeu2_V, LOW);
            digitalWrite(LED_jeu2_R, HIGH);
          } else {
            digitalWrite(LED_jeu2_V, HIGH);
            digitalWrite(LED_jeu2_R, LOW);
          }
          dismentel2 = 0;
        } else {
            displayb.print("FAIL");
              digitalWrite(LED_jeu2_V, HIGH);
              digitalWrite(LED_jeu2_R, LOW);
              for (; runJEU2 < 1; runJEU2++) {
                squeak();
              }
             fail2 = 1;
        }

      } else if ((dismentel1 == 1 or fail1 == 1)  && dismentel2 == 1){
          displayb.print("-7--");
          digitalWrite(LED_jeu2_V, LOW);
          digitalWrite(LED_jeu2_R, HIGH);
          for (; winJEU2 < 1; winJEU2++) {
            wingame();
           }
           dismentel2 = 1;
      } else {
        displayb.print("----");
          digitalWrite(LED_jeu2_V, HIGH);
          digitalWrite(LED_jeu2_R, HIGH);
          }

    // GESTION DU JEU 2 //

    // GESTION DU JEU 3 //

      if (readingc == HIGH) {
        dismentel3 = 1;
      }

      if ((dismentel2 == 1 or fail2 == 1) && dismentel3 == 0) {
        countdown3();

        if (second3 > 0 && minute3 >= 0) {
          int8_t timeDisp3[4];
          timeDisp3[0] = minute3 / 10;
          timeDisp3[1] = minute3 % 10;
          timeDisp3[2] = second3 / 10;
          timeDisp3[3] = second3 % 10;
          tm1637d.display(timeDisp3);
          if (minute3 < accessgame) {
            digitalWrite(LED_jeu3_V, LOW);
            digitalWrite(LED_jeu3_R, HIGH);
          } else {
            digitalWrite(LED_jeu3_V, HIGH);
            digitalWrite(LED_jeu3_R, LOW);
          }
          dismentel3 = 0;
        } else {
            displayc.print("FAIL");
              digitalWrite(LED_jeu3_V, HIGH);
              digitalWrite(LED_jeu3_R, LOW);
              for (; runJEU3 < 1; runJEU3++) {
                squeak();
              }
             fail3 = 1;
        }

      } else if ((dismentel2 == 1 or fail2 == 1)  && dismentel3 == 1){
          displayc.print("---1");
          digitalWrite(LED_jeu3_V, LOW);
          digitalWrite(LED_jeu3_R, HIGH);
          for (; winJEU3 < 1; winJEU3++) {
            wingame();
           }
           dismentel3 = 1;
      } else {
        displayc.print("----");
          digitalWrite(LED_jeu3_V, HIGH);
          digitalWrite(LED_jeu3_R, HIGH);
          }

          } else {

    second=0; minute=45; hour=0; // déclarer des variables de temps
    second1=0; minute1=15; hour1=0; // déclarer des variables de temps
    second2=0; minute2=15; hour2=0; // déclarer des variables de temps
    second3=0; minute3=15; hour3=0; // déclarer des variables de temps
    previousTime = 0;//détient temps précédent en ms
    previousTime1 = 0;//détient temps précédent en ms
    previousTime2 = 0;//détient temps précédent en ms
    previousTime3 = 0;//détient temps précédent en ms
    previousDelay = 0;//détient temps précédent en ms depuis buzzer était actif
    previousDelay1 = 0;//détient temps précédent en ms depuis buzzer était actif
    previousDelay2 = 0;//détient temps précédent en ms depuis buzzer était actif
    previousDelay3 = 0;//détient temps précédent en ms depuis buzzer était actif
    interval = 60000;//60 secondes de retard
    interval1 = 60000;//60 secondes de retard
    interval2 = 60000;//60 secondes de retard
    interval3 = 60000;//60 secondes de retard
    runOPEN = 0;
    dismentel1 = 0; fail1 = 0;
    dismentel2 = 0; fail2 = 0;
    dismentel3 = 0; fail3 = 0;
    dismentel4 = 0; fail4 = 0;
        displaya.print("-   ");
        displayd.print("-   ");

          }

    }

    // GESTION DU JEU 3 //

    // VALIDATION GLOBALE PAR DIGICODE //
      char Key;
      byte KState = KP.Key_State();

      if (KState == PRESSED) {
        if ( Key = KP.Getkey() ) {
          Serial << "Pressed: " << Key << "\n";
          switch (Key) {
            case '*': checkPassword(); break;
            case '#': password.reset(); break;
            default: password.append(Key);
          }
        }
      }
      else if (KState == HELD) {
        Serial << "Key:" << KP.Getkey() << " being held\n";
      }
    // VALIDATION GLOBALE PAR DIGICODE //

    };

    void beep (int speakerPin, float noteFrequency, long noteDuration)
    {
      int x;
      // Convert the frequency to microseconds
      float microsecondsPerWave = 1000000/noteFrequency;
      // Calculate how many HIGH/LOW cycles there are per millisecond
      float millisecondsPerCycle = 1000/(microsecondsPerWave * 2);
      // Multiply noteDuration * number or cycles per millisecond
      float loopTime = noteDuration * millisecondsPerCycle;
      // Play the note for the calculated loopTime.
      for (x=0;x<loopTime;x++)
              {
                  digitalWrite(speakerPin,HIGH);
                  delayMicroseconds(microsecondsPerWave);
                  digitalWrite(speakerPin,LOW);
                  delayMicroseconds(microsecondsPerWave);
              }
    }

    void waka() {
      for (int i=1000; i<3000; i=i*1.05) {
        beep(speakerPin,i,10);
      }
      delay(100);
      for (int i=2000; i>1000; i=i*.95) {
        beep(speakerPin,i,10);
      }
        for (int i=1000; i<3000; i=i*1.05) {
        beep(speakerPin,i,10);
      }
      delay(100);
      for (int i=2000; i>1000; i=i*.95) {
        beep(speakerPin,i,10);
      }
        for (int i=1000; i<3000; i=i*1.05) {
        beep(speakerPin,i,10);
      }
      delay(100);
      for (int i=2000; i>1000; i=i*.95) {
        beep(speakerPin,i,10);
      }
        for (int i=1000; i<3000; i=i*1.05) {
        beep(speakerPin,i,10);
      }
      delay(100);

                beep(speakerPin, note_Bb5,300); //B b
              delay(50);
              beep(speakerPin, note_C6,300); //C
              delay(50);
              beep(speakerPin, note_Ab5,300); //A b
              delay(50);
              beep(speakerPin, note_Ab4,300); //A b
              delay(50);
              beep(speakerPin, note_Eb5,500); //E b
              delay(500);
    }

    void squeak() {
    //  for (int i=100; i<5000; i=i*1.45) {
    //    beep(speakerPin,i,60);
    //  }
    //  delay(10);
      for (int i=3500; i>10; i=i/1.15) {
        beep(speakerPin,i,60);
      }
    }
    void wingame() {
      for (int i=100; i<5000; i=i*1.45) {
        beep(speakerPin,i,60);
      }

    }

    void uhoh() {
      for (int i=1000; i<2000; i=i*1.10) {
        beep(speakerPin,i,10);
      }
      delay(50);
      for (int i=1000; i>500; i=i*.90) {
        beep(speakerPin,i,10);
      }
      delay(50);
      for (int i=1000; i<2000; i=i*1.10) {
        beep(speakerPin,i,10);
      }
      delay(50);
      for (int i=1000; i>500; i=i*.90) {
        beep(speakerPin,i,10);
      }
      delay(50);
        for (int i=1000; i<2000; i=i*1.10) {
        beep(speakerPin,i,10);
      }
      delay(50);
      for (int i=1000; i>500; i=i*.90) {
        beep(speakerPin,i,10);
      }
      delay(50);
        for (int i=1000; i<2000; i=i*1.10) {
        beep(speakerPin,i,10);
      }
      delay(50);
      for (int i=1000; i>500; i=i*.90) {
        beep(speakerPin,i,10);
      }
      delay(50);
        for (int i=1000; i<5000; i=i*1.05) {
        beep(speakerPin,i,10);
      }
     delay(300);

      for (int i=1000; i<3000; i=i*1.03) {
        beep(speakerPin,i,10);
      }
      for (int i=3000; i>1000; i=i*.97) {
        beep(speakerPin,i,10);
      }
    }

    void checkPassword()
    {
      if (password.evaluate()) {
        Serial.println("Success");
        runcode = 1;
        displayd.print(" YOU");
        displayd.print(" YOU");
        displaya.print(" ARE");
        displaya.print(" ARE");
        displayb.print(" THE");
        displayb.print(" THE");
        displayc.print("BEST");
        displayc.print("BEST");
        digitalWrite(LED_jglobal4, HIGH);

        for (; winGLOBAL < 1; winGLOBAL++) {
          waka();
         }
        password.reset();
      } else {
        Serial.println("Wrong");
        password.reset();

        for (; looseGLOBAL < 1; looseGLOBAL++) {
        squeak();
        looseGLOBAL = 0;
        }

      }
    }
    /**********************************************************************
     *                        GLOBAL                                      *
     **********************************************************************/
    void countdown(){

     static unsigned long lastTick = 0; // mettre en place une variable locale pour maintenir la dernière fois que nous décrémentés une seconde
      static unsigned long currentMillis = 0;
      // (variables statiques sont initialisées une fois et conservent leurs valeurs entre les appels de fonction)
      // diminuer à une seconde tous 1000 millisecondes
      if (second > 0) {
        if (millis() - lastTick >= 1000) {
          lastTick = millis();
          second--;

          int8_t timeDisp[4];
          timeDisp[0] = minute / 10;
          timeDisp[1] = minute % 10;
          timeDisp[2] = second / 10;
          timeDisp[3] = second % 10;
          tm1637a.display(timeDisp);
          tm1637a.point(POINT_ON);

        }
      } else {
           displayd.print("FAIL");
          for (; runFAILGLOBAL < 1; runFAILGLOBAL++) {
              squeak();
          }
      }
     // décrémenter une minute toutes les 60 secondes
      if (minute > 0) {
        if (second <= 0) {
          minute--;
          second = 60; // remettre les secondes à 60
        }
      }
      // décrémenter une heure tous les 60 minutes
      if (hour > 0) {
        if (minute <= 0) {
          hour--;
          minute = 60; // réinitialiser minutes à 60
        }//closes if
      }//closes if

      //le code ci-dessous bips de la sirène une fois par minute.
      currentMillis = millis();
      if (currentMillis - previousTime > interval)
      {
        previousTime = currentMillis;
        previousDelay = currentMillis;
      }

      if (currentMillis - previousDelay > 100) {//100ms durée de chirp
      }
    } //close countdown();

    /**********************************************************************
     *                        JEU1                                        *
     **********************************************************************/
    void countdown1(){

     static unsigned long lastTick1 = 0; // mettre en place une variable locale pour maintenir la dernière fois que nous décrémentés une seconde
      static unsigned long currentMillis1 = 0;
      // (variables statiques sont initialisées une fois et conservent leurs valeurs entre les appels de fonction)
      // diminuer à une seconde tous 1000 millisecondes
      if (second1 > 0) {
        if (millis() - lastTick1 >= 1000) {
          lastTick1 = millis();
          second1--;

        }
      }
     // décrémenter une minute toutes les 60 secondes
      if (minute1 > 0) {
        if (second1 <= 0) {
          minute1--;
          second1 = 60; // remettre les secondes à 60
        }
      }
      // décrémenter une heure tous les 60 minutes
      if (hour1 > 0) {
        if (minute1 <= 0) {
          hour1--;
          minute1 = 60; // réinitialiser minutes à 60
        }//closes if
      }//closes if

      //le code ci-dessous bips de la sirène une fois par minute.
      currentMillis1 = millis();
      if (currentMillis1 - previousTime1 > interval1)
      {
        previousTime1 = currentMillis1;
        previousDelay1 = currentMillis1;
      }

      if (currentMillis1 - previousDelay1 > 100) {//100ms durée de chirp
      }

    } //close countdown1();

    /**********************************************************************
     *                        JEU2                                        *
     **********************************************************************/
    void countdown2(){

     static unsigned long lastTick2 = 0; // mettre en place une variable locale pour maintenir la dernière fois que nous décrémentés une seconde
      static unsigned long currentMillis2 = 0;
      // (variables statiques sont initialisées une fois et conservent leurs valeurs entre les appels de fonction)
      // diminuer à une seconde tous 1000 millisecondes
      if (second2 > 0) {
        if (millis() - lastTick2 >= 1000) {
          lastTick2 = millis();
          second2--;
        }
      }
     // décrémenter une minute toutes les 60 secondes
      if (minute2 > 0) {
        if (second2 <= 0) {
          minute2--;
          second2 = 60; // remettre les secondes à 60
        }
      }
      // décrémenter une heure tous les 60 minutes
      if (hour2 > 0) {
        if (minute2 <= 0) {
          hour2--;
          minute2 = 60; // réinitialiser minutes à 60
        }//closes if
      }//closes if

      //le code ci-dessous bips de la sirène une fois par minute.
      currentMillis2 = millis();
      if (currentMillis2 - previousTime2 > interval1)
      {
        previousTime2 = currentMillis2;
        previousDelay2 = currentMillis2;
      }

      if (currentMillis2 - previousDelay2 > 100) {//100ms durée de chirp
      }

    } //close countdown2();

    /**********************************************************************
     *                        JEU3                                        *
     **********************************************************************/
    void countdown3(){

     static unsigned long lastTick3 = 0; // mettre en place une variable locale pour maintenir la dernière fois que nous décrémentés une seconde
      static unsigned long currentMillis3 = 0;
      // (variables statiques sont initialisées une fois et conservent leurs valeurs entre les appels de fonction)
      // diminuer à une seconde tous 1000 millisecondes
      if (second3 > 0) {
        if (millis() - lastTick3 >= 1000) {
          lastTick3 = millis();
          second3--;

        }
      }
     // décrémenter une minute toutes les 60 secondes
      if (minute3 > 0) {
        if (second3 <= 0) {
          minute3--;
          second3 = 60; // remettre les secondes à 60
        }
      }
      // décrémenter une heure tous les 60 minutes
      if (hour3 > 0) {
        if (minute3 <= 0) {
          hour3--;
          minute3 = 60; // réinitialiser minutes à 60
        }//closes if
      }//closes if

      //le code ci-dessous bips de la sirène une fois par minute.
      currentMillis3 = millis();
      if (currentMillis3 - previousTime3 > interval1)
      {
        previousTime3 = currentMillis3;
        previousDelay3 = currentMillis3;
      }

      if (currentMillis3 - previousDelay3 > 100) {//100ms durée de chirp
      }
    } //close countdown2();

body:
That code is a mess. I'm sure you can refactor a lot of it. To get you started here's a C++ class you can use as a countdown timer. I just whipped this up, but it should work. <strike>However, it does not handle the case where `millis()` overflows (after about 50 days).</strike>

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

    class Countdown {
    public:
        const uint32_t ms_per_hour = 60l * 60l * 1000l;
        const uint32_t ms_per_minute = 60l * 1000l;
        const uint32_t ms_per_second = 1000l;

        // Constructor
        Countdown(int hours, int minutes, int seconds) {
            duration = hours * ms_per_hour +
                       minutes * ms_per_minute  +
                       seconds * ms_per_second ;
            started = false;
            finished = false;
        }
        // Call this to start the countdown
        void start() {
            started = true;
            finished = false;
            start_time = millis();
        }

        // Stop the timer
        void stop() {
            finished = true;
        }

        // Is timer running?
        bool is_running() {
            return started == true && finished == false;
        }

        // Call this to check if the countdown is finished
        bool times_up() {
            if (finished) return true;
            else if (!started) return false;
            if (elapsed_time() >= duration) {
                finished = true;
                return true;
            }
            return false;
        }

        // Returns a string representation of how much time has passed
        const char * get_elapsed(const char *format="hh:mm:ss") {
            return ms_to_string(format, elapsed_time());
        }
        // Returns a string representation of how much time is left
        const char * get_remaining(const char *format="hh:mm:ss") {
            return ms_to_string(format, duration - elapsed_time());
        }

        // Returns an array of decimal digits for display of time passed
        const char * get_digits_elapsed(const char *format="mmss") {
            return ms_to_digits(format, elapsed_time());
        }
        // Returns an array of decimal digits for display of time remaining
        const char * get_digits_remaining(const char *format="mmss") {
            return ms_to_digits(format, duration - elapsed_time());
        }

    protected:
        unsigned long elapsed_time() {
            return millis() - start_time;
        }

        bool started, finished;
        uint32_t duration, start_time;
        char buffer[32];

        char * ms_to_digits(const char *format, uint32_t ms) {
            uint16_t hours = ms / ms_per_hour;
            ms %= ms_per_hour;
            uint16_t minutes = ms / ms_per_minute;
            ms %= ms_per_minute;
            uint16_t seconds= ms / ms_per_second;

            int index = 0;
            for (int i = 0; 0 != format[i]; i++) {
                if ('h' == format[i] || 'm' == format[i] || 's' == format[i]) {
                    uint16_t val = 'h' == format[i] ? hours : ('m' == format[i] ? minutes : seconds);
                    if (format[i] == format[i+1]) {
                        buffer[index++] = (char)(val / 10);
                        i += 1;
                    }
                    buffer[index++] = char(val % 10);
                }
            }
            return buffer;
        }

        char * ms_to_string(const char *format, uint32_t ms) {
            uint16_t hours = ms / ms_per_hour;
            ms %= ms_per_hour;
            uint16_t minutes = ms / ms_per_minute;
            ms %= ms_per_minute;
            uint16_t seconds= ms / ms_per_second;

            buffer[0] = 0;
            int index = 0;
            for (int i = 0; 0 != format[i]; i++) {
                if ('h' == format[i] || 'm' == format[i] || 's' == format[i]) {
                    uint16_t val = 'h' == format[i] ? hours : ('m' == format[i] ? minutes : seconds);
                    if (format[i] == format[i+1]) {
                        index += sprintf(&buffer[index], "d", val);
                        i += 1;
                    }
                    else {
                      index += sprintf(&buffer[index], "%d", val);
                    }
                }
                else {
                    buffer[index++] = format[i];
                }
            }
            buffer[index] = '\0';
            return buffer;
        }
    };

To use it, you would create 3 objects:

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

    Countdown cd1(0, 45, 0);  // 45 minutes
    Countdown cd2(0, 15, 0);  // 15 minutes
    Countdown cd3(0, 15, 0);  // 15 minutes

Then, start #1 in setup:

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

    void setup() {
        cd1.start();
    }

And in loop:

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

    void loop() {
        if (cd3.times_up()) {
           // game over
        }
        else if (cd2.times_up()) {
            // 2nd timer expired, do something
            if (!cd3.is_running()) cd3.start();  // Start #3
            // update display
            tm1637d.display(c3.get_digits_remaining());
        }
        else if (cd1.times_up()) {
            // 1st timer expired, do something
            if (!cd2.is_running()) cd2.start();  // Start #2
            // update display
            tm1637c.display(c2.get_digits_remaining());
        }
        else {
            // update display
            tm1637b.display(c1.get_digits_remaining());
        }
    }


message:
compiler says I have to declare my hexidacimal I try to compare

#include <IRremote.h>

    int RECV_PIN = 11; // IR Receiver - Arduino Pin Number 11
    IRrecv irrecv(RECV_PIN);
    decode_results results;

    int led = 12;

    void setup() {
      pinMode(led, OUTPUT);
      digitalWrite(led, LOW);
      Serial.begin(9600);
      irrecv.enableIRIn(); // Start the receiver
    }

    void loop() {
      if(irrecv.decode(&results)) //this checks to see if a code has been received
    {
        if(results.value == FF6897) //if the button press equals the hex value FF6897
        {
            digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
            delay(1000);               // wait for a second
            digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
            delay(1000);               // wait for a second//do something useful here
        }
        irrecv.resume(); //receive the next value
    }
      }

The issue is in the second if in the void loop the error I get is

> exit status 1 'FF6897' was not declared in this scope

why does he do this? Why doesnt it just accept my IRcode for comparison.

body:
Nothing here that hasn't been covered in comments already but just putting it in the form of an answer to save digging...

How is the compiler supposed to know that a number is hex rather than decimal?

Sure 1234beef is obviously hex but what about 12345678? Is that hex or decimal?

You need some method for the compiler to know.

You also need some way for the compiler to know if something is a number or a variable. Take the code `if (x == deadbeef) {...}` is `deadbeef` a hex number or a variable name?

C uses a very simple convention. If it starts with a number it's a number, if it starts with a letter it's a variable. This is why variable names can contain numbers but can't start with them.

If an integer starts with an 0 e.g. 0123 then it's in octal.

If an integer starts with 0x e.g. 0x123 then it's in hex.

If an integer starts with something other than a 0 e.g. 123 then its in decimal.

e.g.

    printf("123 = %d\r\n0x123 = %d\r\n0123 = %d\r\n", 123 , 0x123 , 0123);

 returns

    123 = 123
    0x123 = 291
    0123 = 83

This convention, especially the 0x prefix for hexadecimal, is very widely used in other programming languages.


message:
How to interface OV5640 to Arduino Mega using Embedded C?

I am trying to interface a OV5640 camera module to Arduino Mega 2560 in Eclipse IDE using C language . However I am not able to figure out the registers that need to be initialised , for the camera to start capturing pictures .

There are Arduino libraries to deal with setup and image transfer , however I do not wish to use them . I would like to code in C , without using any library . I just need to know which registers need to be accessed and modified to get the camera working .

For reference - I am trying to create a CCTV based system that will record picture based on intruder presence . The entire project is written in C language without any libraries .

Data sheet for OV5640 -https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf

Take a look in this link to get an idea about the kind of program it'll be.
https://arduino.stackexchange.com/questions/38515/how-to-get-38-khz-clock-from-timer-0-2-in-arduino-mega-2560

body:
[Arducam][1] gives you all the info you need on the necessary register settings. The register values for each color space and resolution are defined in this [header][2] while the initialization sequence, image format selection and image capture process among other stuff, are implemented [here][3] and documented if you look closely at the variable names and compiler directives.

**EDIT: More details**

Lines 327 - 372 contain the relevant initialization sequence for this specific camera. For instance, assuming you want JPG images, line 335 marks the start of the needed settings:

    delay(100);
    wrSensorReg16_8(0x3103, 0x11);
    wrSensorReg16_8(0x3008, 0x82); delay(100);
    wrSensorRegs16_8(OV5640YUV_Sensor_Dvp_Init); delay(500);
    wrSensorRegs16_8(OV5640_JPEG_QSXGA);
    wrSensorRegs16_8(OV5640_QSXGA2QVGA);
    wrSensorReg16_8(0x4407, 0x0C);  # assuming you arent using the Arducam shield or OV5640 5MP Plus

What `wrSensorReg16_8` does is pretty obvious: write the 8-bit 2nd argument into the register specified in the 16-bit 1st argument. `wrSensorRegs16_8` merely does the same thing for multiple register-value pairs passed into it. `OV5640YUV_Sensor_Dvp_Init`, `OV5640_JPEG_QSXGA` and `OV5640_QSXGA2QVGA` are all structs defined in the header I mentioned earlier; they contain the rest of the register-value pairs you need to know about. Ultimately, these settings should give you 320x240 JPEG, I think.

You can't use the `start_capture` method since you don't have the ArduCAM FIFO so you'll have to start grabbing frames yourself (and buffering them somewhere very quickly; transmitting the bytes as you read them is out of the question) by paying attention to VSYNC, HREF and PCLK. Look at the timing diagrams in the datasheet. I assume you'll only be taking frames occasionally since a Mega won't do for video. If you're very lucky, you'll get a nice image on your first try but on the whole, be ready to spend serious time studying the datasheet, ArduCAM code and other 0V5640-related code on the web or just go with the OV7670 which has more examples/tutorials.

  [1]: https://github.com/ArduCAM/Arduino/blob/master/ArduCAM
  [2]: https://github.com/ArduCAM/Arduino/blob/master/ArduCAM/ov5640_regs.h
  [3]: https://github.com/ArduCAM/Arduino/blob/master/ArduCAM/ArduCAM.cpp


message:
Multiple IDE instances

I recently moved all in for Linux and have no intentions of going back to Windows, but programming for Arduino is a little annoying as I cannot find a way to have multiple instances.

In Windows you create individual shortcuts for several Arduino IDE instances. When you launch these from the desktop they are autonomous, meaning you can set a board/port combination for each one.

I have yet to find a way to do that in Ubuntu. Is there some form of isolation I can use? I tried using workspaces but they all still see just the one setting.

I do not want to have a bunch of VMs and switch from one to the other unless that is the only option left.

Is there some way I can emulate the Windows autonomous shortcut approach in Ubuntu?

body:
There is nothing special about it, it just works.

I strongly suggest to remove everything that is Arduino related from the repositories and have a minimal Java environment installed.

It is no problem to have a gcc build environment together with Arduino though. Even a gcc-avr build environment from the repositories is no problem. But don't install any Arduino or Java-rxtx from the repositories.

You can download the linux version and unpack it in a folder.
Go to that folder where you unpacked the Arduino files and right-click on the 'arduino' file to create a shortcut. Move that shortcut to your Desktop.
Depending on the flavor of Ubuntu that you have, you can also create a starter and fill in the whole path of the 'arduino' file.

Then you can start the Arduino IDE, and just click/activate that shortcut or starter again for another instance of the Arduino IDE. They will work independent of each other. You have to set the right board for each instance of course. A third one or more is also possible.

If you have trouble with shortcuts or starters, then you can even open a terminal and go to the unpacked files, type "./arduino" to start it. Open an other terminal (or new 'tab' in the terminal) and do the same.

You don't have to makes copies of the Arduino files, you don't have to make multiple shortcuts or starters. Just start a new instance by activating the shortcut or starter once more.

I recommend to use only the newest version (at the moment 1.8.3). But if you need to run an older version then you can download and unpack older versions in seperate folders. Be careful that you can not run different versions of the IDE at the same time. The Arduino IDE before 1.6.x differs too much from 1.8.x. All of them share the same ~/.arduino15 folder with settings and downloaded files, which can cause trouble when running a new version, then an older version and then a newer version again.


body:
Use [UECIDE][1]. It does everything Arduino IDE does, can have multiple instances running out of the box, and projects/libraries are 100% compatibles.

You get a nice standard interface, with a project, edit and output panes.

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

IDE can be extended with plugins:

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

[Download][4] it from the same site. You have versions for Windows, Mac and Linux:

> Linux files
>
> To run on 64-bit Linux you may need extra libraries installed. These
> are for the compilers, not for UECIDE, some of which only come in a
> 32-bit flavour. Possible libraries include the i386 version of libc6.
>
>     uecide-0.8.9-pre17_all.deb
>     uecide-0.8.9-pre17-linux.zip

As UECIDE follow follow strictly the rules for project/directory organization as standard Arduino IDE, libraries and projects are compatibles. You can use Arduino IDE and UECIDE on the same project without harm.

I used Arduino IDE at first, and later slowly migrate to UECIDE, keping both for a while, but right now I keep Arduino IDE only as a backup.

@Majenko is the mantainer. Shy guy, doesn't promote himself.

  [1]: http://uecide.org
  [2]: https://i.stack.imgur.com/Ysvpg.png
  [3]: https://i.stack.imgur.com/umjUw.png
  [4]: http://uecide.org/download.php


message:
Turning on many (30) leds arduino mega

I´m new working with Arduino. Right now I have a project thar requires to turn on 30 LEDs at the same time with an Arduino Mega. The problem is that it would exceed the max current that the chip can tolerate.

It is possible to do this by turning on one LED at the time, very fast?

If it is, any clue on the code to achieve that will be apreciated.

Thank you very much

P.S.: I know there are components to expand the quantity of pins that work like that, but the idea is to avoid using one.

body:
This page explains that the ATmega2560 could drive up to 800mA: [Arduino Playground: Arduino Pin Current Limitations][1]
There are limitations for groups of pins, so you have to be careful.
The 800mA is a lot in my opinion. I wonder how hot the chip will become.

What kind of leds do you use ? Normal 20mA leds ? Or is 10mA leds also possible ? 30*20mA = 600mA, but 30*10mA is only 300mA. The 300mA seems a lot safer to me.

With Charlieplexing the leds are not 'on' all the time. However, with the Arduino Mega 2560 you have enough pins, and you could just lower the current through the leds.
Turning them on for a short time (without Charlieplexing) is the same as turning them continuous on with a lower current.

The most common way to drive 30 leds is with a led strip. For example a led strip with neopixels. That led strip has to be powered seperately.

My advice is to lower the current for the leds to 10mA and hope that the ATmega2560 doesn't get too hot.

[ADDED] 300mA is still a lot. Start with 5mA per led for a total of 150mA when they all are on at the same time. Many modern and good quality leds are bright at 5mA.

  [1]: https://playground.arduino.cc/Main/ArduinoPinCurrentLimitations


body:
Use external drivers, like a transistor.

If you have to tie them to the avr, use large or larger current limiting resistors. Or to multiplex so only some of them are on at a given time.


body:
Use the MAX7919. It is a driver for multiples leds. It lets you output up to 64 leds at a high enough brightness.

https://playground.arduino.cc/Main/LEDMatrix

Its usually made to drive LED matrices or 7-segments LEDs.


message:
Using chipKIT WiFi Shield with an Arduino

I'm beginning with Arduino and I have to make two of them communicate via WiFi. I'm going to implement the examples for a WiFi Client and WiFi Server in their [tutorials page][1].

The problem is I only have one Arduino WiFi Shield which is working fine. But I also have a [chipKIT WiFi Shield][2].

My question is: Can I use this other shield to do what I want with one of my Arduinos (I have Uno, Mega and Due) and how? Because I've plugged the shield and I've uploaded the code but it didn't seem to work.

  [1]: https://www.arduino.cc/en/Tutorial
  [2]: http://store.digilentinc.com/chipkit-wifi-shield-add-on-board/

body:
No, you can't. The only libraries available for the chipKIT WiFi Shield are written specifically for the chipKIT boards.

Also, how have you plugged the board into an Arduino? The chipKIT WiFi Shield has Digilent's own header layout with a double row of headers where the Arduino only has a single row. Half the pins won't be plugged into anything.


message:
Diffrence between running once and infinite

const int ledPin = 12;

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

    void loop(){
        if (Serial.available()) {
            light(Serial.read() – '0');
        }
        delay(500);
    }

    void light(int n){
        for (int i = 0; i < n; i++) {
            digitalWrite(ledPin, HIGH);
            delay(100);
            digitalWrite(ledPin, LOW);
            delay(100);
        }
    }

by [Oscar Liang][1]

awesome little piece of code which taught me how to setup connection by serial. yet one part I don't understand fully. Why does this line:

> light(Serial.read() – '0');

make the code run once,
and this line an infinite times.

> light(Serial.read());

has this something to do with binary? I don't get why subtracting the string 0 would run the code once.

Thanks in Advance!

  [1]: https://oscarliang.com/connect-raspberry-pi-and-arduino-usb-cable/

body:
Serial.read() -'0'

Such code is often used to convert a character to a digit (e.g. int).

Like if the character is '2', than '2' - '0' = ascii 50 - ascii 48 = 2

However, if you use

    Serial.read()

the value will be 50 instead of 2.... maybe looping 50 times (or 48 to 58, for values 0 to 9) will give you the impression it runs infinite?


message:
Optimizing ext. SPI ADC for speed and verify the speed

So I have a project where I will be using an Arduino Leonardo and an external ADC (AD7980) to run a 16-bit (18bit) conversion and transmit it to the Arduino and then out on USB as fast as possible.

The AD7980 can run up to 1 MSPS, and I know I cannot reach that with the ATmega32U4 - but I want to know how to optimize my code for running it as fast as possible and how to measure it.

Right now my code is:

    #include <SPI.h>

    int CNV= 11; //Convert on pin 11
    int Slaveselect=8;
    int adcValue;
    byte highByte;
    byte lowByte;

    void setup() {
      Serial.begin(115200);
      SPI.begin();
      SPI.setClockDivider(SPI_CLOCK_DIV2 ); // 8 MHz rate
      SPI.setBitOrder(MSBFIRST);
      pinMode(Slaveselect, OUTPUT);
      pinMode(CNV, OUTPUT);
    }

    void loop() {
      digitalWrite(Slaveselect,HIGH);
      // SS always high to use 3 Wire mode without busy indicator
      digitalWrite(CNV,LOW);
      digitalWrite(13,LOW);
      digitalWrite(CNV,HIGH);//starts conversion
      digitalWrite(13, HIGH);
      digitalWrite(CNV,LOW); //starts to transmit MSB on data line
      digitalWrite(13,LOW);
      highByte = SPI.transfer(0x00);
      lowByte = SPI.transfer(0x00);
      adcValue = highByte << 8;
      adcValue = adcValue | lowByte;
      Serial.print("analog value =");
      Serial.println(adcValue);
      Serial.print('\n');
    }

The datasheet for the ADC can be found here: [Datasheet][1]

  [1]: http://www.analog.com/media/en/technical-documentation/data-sheets/AD7980.pdf

body:
1. Don't use `digitalWrite()`.
2. Don't use `delay()`.
3. Don't flood your Serial connection with useless junk ("analog value =")

You may also consider using lower level SPI operations instead of the SPI library, which is completely blocking and slows you down. At least consider the use of `SPI.transfer16(...)` which is more efficient than two `SPI.transfer(...)` calls.


body:
For fast possible speed, use spi transmission buffer and spi interrupt. The concept is that once there is at least free space in the buffer, it interrupts and you load the next byte into the buffer.

That's assuming that dma isn't available.

Short of that, don't use arduino GPIO functions - they are like 100x slower than that's possible. And use a usartt isr to  manage transmission.


message:
Trying to turn off fading RGB LED after 30 secs

I am trying to get something to work so that an RGB LED fades through the color spectrum, and when a button is pressed some music plays.
That is not the problem.
Assume I am using any loop that functions can be called at any time in.
I am trying to make it so that if the button is not pressed for a certain amount of time, say 30 seconds, the light stops fading through the color spectrum and when the button is pressed in this 'sleep mode', first the light starts fading, and then the next press plays the music.
I am aware this could be done somehow with millis();, but how would I approach this?
I am using an Arduino Uno.

body:
Here is a little snippet of logic that you can implement in your code :

    if(millis() - getOutOfSleepTime >= 30000) {
        activateSleepMode();
        while(!buttonPress);
        getOutOfSleepMode();
        getOutOfSleepTime = millis();
    }

    if(buttonPress)
        activateSleepMode();


message:
Issue with code for SDA/SCL TC9548A Multiplexer and HMC5883L sensors

This is my first time posting on this forum, so I hope my question is appropriate here. My team is working with the Adafruit TCA9548A 1-to-8 I2C Multiplexer Breakout board to try and read from six HMC5883L Breakout sensors, and I am in the process of trying to look at their code to solve a problem. For some reason, code does not run at all unless you comment out a certain line in the code. Once it is commented out, the code runs as expected.

Now, we have to initialize it in setup(), but the statement tcaselect(0) statement was commented out so it doesn't initialize the 0th sensor in setup(). We can keep the other part, the if(mag0.begin()) statement, and it works as expected. However, if we uncomment out tcaselect(0) in setup, the entire code crashes, and all we see are 'HM' in the display window. A very basic schematic is shown below:

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

<!-- End schematic -->

I ran some tests with my team, and when all six HMC5883Ls and the single TCA9548 multiplexer were connected on the same breadboard according to the schematic, they worked when tcaselect(0) in setup() was not commented out. Next, we had an apparatus to hold the six sensors, and we had it connected with long lengths of wire, the same as the schematic. We hooked it up to the same breadboard, and the code would not run unless tcaselect(0) in setup was commented out. This seems strange to me that they would work when connected on the breadboard, but when spread out and connected to the breadboard via long wires, they would not work unless that code was commented out.

https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout?view=all

https://learn.adafruit.com/adafruit-hmc5883l-breakout-triple-axis-magnetometer-compass-sensor/overview

EDIT: Someone mentioned that wires might have problems with the SDA/SCL bus, so the wires that we're using are 4-pin ribbon cables, 2.54 mm pitch. A very rough schematic of the container that we're using is shown below:

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

<!-- End schematic -->

Sorry for the roughness. It's the best I can do to show how the container is assembled. There's an 8x8 in. box where the components are stored, so the sensors go from various locations in the apparatus to the center box where the Pi, Arduino, and breadboard are placed. The nodes in the schematic represent the locations of the sensors. Given the rough dimensions, the longest distance for one of the sensors is around 56.8 inches (or approx. 1.45 meters) accounting for some extra wiring.

Code:

    #include <Wire.h>
    #include <Adafruit_Sensor.h>
    #include <Adafruit_HMC5883_U.h>

    #define TCAADDR 0x70

    /* Assign a unique ID to this sensor at the same time */
    Adafruit_HMC5883_Unified mag0 = Adafruit_HMC5883_Unified(0);
    Adafruit_HMC5883_Unified mag1 = Adafruit_HMC5883_Unified(1);
    Adafruit_HMC5883_Unified mag2 = Adafruit_HMC5883_Unified(2);
    Adafruit_HMC5883_Unified mag3 = Adafruit_HMC5883_Unified(3);
    Adafruit_HMC5883_Unified mag4 = Adafruit_HMC5883_Unified(4);
    Adafruit_HMC5883_Unified mag5 = Adafruit_HMC5883_Unified(5);

    //Display details of sensor here
    void displaySensorDetails(Adafruit_HMC5883_Unified *mag){
      sensor_t sensor;
      mag->getSensor(&sensor);
      Serial.println("------------------------------------");
      Serial.print  ("Sensor:       "); Serial.println(sensor.name);
      Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
      Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
      Serial.print  ("Max Value:    "); Serial.print(sensor.max_value);         Serial.println(" uT");
      Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" uT");
      Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" uT");
      Serial.println("------------------------------------");
      Serial.println("");
      delay(500);
    }

    //Given sensor i, select and write to it
    void tcaselect(uint8_t i) {
      if (i > 7) return;
      Wire.beginTransmission(TCAADDR);
      Wire.write(1 << i);
      Wire.endTransmission();
    }

        void setup() {
      Serial.begin(9600);
      /* Initialise the 0st sensor */
       //tcaselect(0);
       if(!mag0.begin())  {
        /* There was a problem detecting the HMC5883 ... check your connections */
        Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");
       }

      /* Initialise Sensors 1-6 */
      tcaselect(1);  if(!mag1.begin()) {  Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");  }
      tcaselect(2);  if(!mag2.begin())  {  Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");  }
      tcaselect(3);  if(!mag3.begin())  {  Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");  }
      tcaselect(4);  if(!mag4.begin())  {  Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");  }
      tcaselect(5);  if(!mag5.begin())  {  Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");  }

    }

    void loop() {
      /* Get a new sensor event */
      sensors_event_t event0;  sensors_event_t event1;
      sensors_event_t event2;  sensors_event_t event3;
      sensors_event_t event4;  sensors_event_t event5;

      tcaselect(0);  mag0.getEvent(&event0);  tcaselect(1);  mag1.getEvent(&event1);
      tcaselect(2);  mag2.getEvent(&event2);  tcaselect(3);  mag3.getEvent(&event3);
      tcaselect(4);  mag4.getEvent(&event4);  tcaselect(5);  mag5.getEvent(&event5);

      /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
      Serial.print(event1.magnetic.x); Serial.print("  ");
      Serial.print(event1.magnetic.y); Serial.print("  ");
      Serial.print(event1.magnetic.z); Serial.print("  ");

      Serial.print(event2.magnetic.x);   Serial.print("  ");
      Serial.print(event2.magnetic.y);   Serial.print("  ");
      Serial.print(event2.magnetic.z + 37); Serial.print("  ");

      Serial.print(event3.magnetic.x); Serial.print("  ");
      Serial.print(event3.magnetic.y); Serial.print("  ");
      Serial.print(event3.magnetic.z); Serial.print("  ");

      Serial.print(event4.magnetic.x); Serial.print("  ");
      Serial.print(event4.magnetic.y); Serial.print("  ");
      Serial.print(event4.magnetic.z + 37); Serial.print("  ");

      Serial.print(event5.magnetic.x); Serial.print("  ");
      Serial.print(event5.magnetic.y); Serial.print("  ");
      Serial.print(event5.magnetic.z); Serial.print("  ");

      delay(500);
    }

EDIT: Big news, I tried using only two sensors and 1.5m cables and adding 10k pullup resistors from VCC to SDL/SCA on the respective sensors; with these changes, they seem to work even with tcaselect(0) not commented out in setup, though I only used two sensors rather than six. The HMC5883L sensor breakout board contains 10k pullup resistors already, so with another 10k resistor per line, it would make it 5k. Would this value be too much, or is it fine? I looked at the datasheet of the sensor itself, but I can't find anything on what value the input impedance would be for SCL/SDA.

Also, on another related note, one of my sensors had wires crossed deliberately, so SCL and SDA are separated by GND and VCC in the cable. I'm still running tests to see if I need to do this, but is it recommended to do so even if it is not necessary for correct operation? Someone mentioned that having SCL/SDA next to each other would be bad if they cause problems with crosstalk/interference.

body:
I'm sure you have, but have you connected the grounds together?

Have you tried 1 sensor on SD/C0 and then moving it to SD/C1 it should stop working, so the fault has to be with SD/C0.

Looking at your code, is there a reason you haven't initialised sensor 0?

     /* Initialise Sensors 1-6 */

So it looks to me as the fault is caused by you not calling `begin()` on `mag0`


body:
Try bumping the empty to the last slot and changing your for loop to only iterate the first 7.

Serial prints along the way help debugging


message:
Unable to load programs onto Arduino Pro Mini Using FTDI?

I'm pretty new to this, so forgive me if I get some things wrong. I am working with a piece of equipment that uses an Arduino Pro Mini. When I first got to it, I realized that some of the code was incorrect and wanted to fix it. Unfortunately, my Pro Mini is soldered into the board with the labels and pins down, so the only accessible pins are the top six, and even those aren't labeled. The reset button is also upside down. I tried using a FT232H FTDI
hooked up (using a pinout because of the aforementioned no labels)

D0-> TX

D1-> RX

which I was told should work, but when I plug in the micro-usb into the FT232H and try to upload the sketch, it gives me the error

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

and also blinks green but has a constant red light (from what I can see from looking under the board). Because this Pro Mini controls my equipment, I'm wary of doing anything too intense. Any ideas of how to fix this without breaking my apparatus?

**Update!**
I changed the pinning, and the IDE told me that it uploaded, but it still won't run the program! Help!

body:
Same problem faced. Try out many times with proper connection but no success. After that, I found one unique and simple solution. I use Arduino Uno instead of FTDI. Follow below step, your problem will definitely solve.

 1. First, remove Arduino Uno's IC means ATMEGA 328P-PU.
 2. Now, do connection as shown in below figure.

[![Uno Connect with Pro mini][1]][1]

Connections are like:

    Arduino Uno(Without Chip)     Arduino Mini Pro

              RX                         RX
              TX                         TX
              +5V                        Vcc
              GND                        GND
             RESET                  RST(RESET PIN)

 3. Now, plug your Arduino Uno to your computer and open your Arduino IDE.

 4. Now, an open sketch which one you want to upload. Now, go to `Tools` and select board in which you want to upload code. Below, show in the figure.

[![Select your board][2]][2]

 5. Now, upload your program. It will definitely work.

I hope it will help you.

  [1]: https://i.stack.imgur.com/si2SB.png
  [2]: https://i.stack.imgur.com/zt7RY.png


message:
Can't open "COM1" on Linux with Trinket Pro

At work, on a Ubuntu 14.04 system, I can access my Trinket Pro without any difficulty whatsoever.

At home, using either Linux Mint or Ubuntu across two laptops, I can not communicate with the device no matter what I try.

I have the correct board selected, the correct processor, and trying to use USBTiny ISP.

Currently, I'm getting:

    avrdude: ser_open(): can't open device "COM1": No such file or directory
    An error occurred while uploading the sketch

It's really getting frustrating having to take my devices to work just to upload a sketch, and I've been banging my head for over a week and a half. My UNO R3 boards work without issue on the same laptops.

Here's what `dmesg` says:

    [  863.471315] usb 1-1.1: Product: USBtiny
    [  863.471316] usb 1-1.1: Manufacturer: Adafruit
    [  876.438778] usb 1-1.1: USB disconnect, device number 12
    [  880.921492] usb 2-1: new low-speed USB device number 5 using xhci_hcd
    [  881.092152] usb 2-1: New USB device found, idVendor=1781, idProduct=0c9f
    [  881.092157] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    [  881.092161] usb 2-1: Product: USBtiny
    [  881.092163] usb 2-1: Manufacturer: Adafruit
    [ 1004.305143] usb 2-1: USB disconnect, device number 5
    [ 1019.935505] usb 2-1: new low-speed USB device number 6 using xhci_hcd
    [ 1020.106524] usb 2-1: New USB device found, idVendor=1781, idProduct=0c9f
    [ 1020.106530] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    [ 1020.106533] usb 2-1: Product: USBtiny
    [ 1020.106536] usb 2-1: Manufacturer: Adafruit

I am running IDE version 1.8.3, with `sudo`, the exact same way I'm doing at the office.

Can someone please advise on what I'm missing here? Windows is not an option; I haven't used it in many years. I'd just like to figure out what's wrong.

I do have an FTDI connector, but didn't have much luck with it either, and to be honest, don't want to use it as I just want to plug the Trinket in, and upload.

Update: I've tried both USB2 and USB3 ports repeatedly with the same results.

body:
    [  881.092161] usb 2-1: Product: USBtiny
    [  881.092163] usb 2-1: Manufacturer: Adafruit
    [ 1004.305143] usb 2-1: USB disconnect, device number 5
    [ 1019.935505] usb 2-1: new low-speed USB device number 6 using xhci_hcd
    [ 1020.106524] usb 2-1: New USB device found, idVendor=1781, idProduct=0c9f

The **USB Tiny ISP** device which this logs shows being connected to your system **is not a USB serial device**.  Therefore, it will not have any `/dev/ttyXXX` device associated with it.  Instead it should be used with the `-c usbtiny` argument to `avrdude`.

Adafruit documents their products fairly well, and this is no exception.  The Linux section of the user guide is at [https://learn.adafruit.com/usbtinyisp/avrdude#for-linux][1]

That guide goes on to explain that you will typically need to create a **udev rule** to allow an ordinary user account to access the device.  Depending on Linux installation, typical contents might be

    SUBSYSTEM=="usb", SYSFS{idVendor}=="1781", SYSFS{idProduct}=="0c9f", GROUP="users", MODE="0666"

or

    SUBSYSTEM=="usb", SYSFS{idVendor}=="1781", SYSFS{idProduct}=="0c9f", GROUP="adm", MODE="0666"

The above linked guide will more comprehensively explain how all of this works.

Note that the above pertains to the **USB Tiny ISP** *programmer* shown in your dmesg output.  According to the [Adafruit page on the Trinket Pro][2], the **Trinket Pro** "bootloader looks just like a USBtinyISP" therefore, you would talk to it in the same way as the USB Tiny ISP that your system reports finding, ie, *without* using a `/dev/ttyXXX` device, but rather by specifying `-c usbtiny` in the avrdude command line, or using an Arduino IDE board configuration which does so.

Your error message suggests that `avrdude` is *not* being run with the correct command line options.  You may want to turn on verbose mode to see what is being run - it would especially helpful if you did that on both the working and the non-working Linux systems.

  [1]: https://learn.adafruit.com/usbtinyisp/avrdude#for-linux
  [2]: https://learn.adafruit.com/introducing-pro-trinket/starting-the-bootloader


body:
So, in the end, although Chris' answer didn't directly lead me to the solution, by delving through his links, I eventually ended up at a page that suggested using the `Sketch->Upload Using Programmer` feature.

That corrected the issue both as `root` and my normal Linux user account, without any other changes necessary. I find it odd that it isn't required on my work PC, but I digress. It works on both, so I'm pleased.


message:
Problem with using multi-node nRF24l01+ with Arduinos

I have 3 nodes in my system. One `centralNode` and two sensor nodes (`right` and `left`).
Sensor nodes transmit data to the `centralNode` and receive from it.
`centralNode` may transmit to both nodes and receive from them.

I'm using an Arduino nano for central node and Uno and Mega for sensor nodes. I'm using nRF24's base module (with regulators and caps and all) but one node does not have base module (Although I've given it a descent 3.3 V and bypass caps).

**Here is my problem:**
**1-** It seems the centralNode can't detect which nodes data it is receiving. I can **sometimes** get it to work using different delays for sensorNodes but again, on reset it messes up the data.
How can I detect which data's reading the centralNode is receiving?

**2-** How can I use radio.available(??)
I've put 0, 1 , 2 and pipe addresses in ?? but it does not work (prints garbage data)
[radio.available's API][1]

Here are the codes:
`centralNode:`

    /*
       Testing multi-node functionality of nRF24l01+
       This is centralNode code

       BOM
       1 Arduino Nano centralNode
       1 Ardiuno Uno rightSensorNode
       1 Arduino Mega leftSensorNode
       3 nRF24l01+
    */

    #include <SPI.h>
    #include "RF24.h"
    #include <printf.h>

    #define CEpin 6
    #define CSpin 7

    RF24 radio(CEpin, CSpin);
    byte addresses [][6] = {"1Node", "2Node", "3Node"};

    int rightNodeCount = 0;
    int leftNodeCount = 0;
    void setup() {
      Serial.begin(115200);
      Serial.println(F("This is the central node"));
      printf_begin();
      radio.begin();
      radio.setPALevel(RF24_PA_MAX);

      radio.openWritingPipe(addresses[0]);
      radio.openReadingPipe(1, addresses[1]);
      radio.openReadingPipe(2, addresses[2]);
      radio.startListening();
      radio.printDetails();
    }

    void loop() {
      if (radio.available()) {
        radio.read(&rightNodeCount, sizeof(rightNodeCount));
        radio.read(&leftNodeCount, sizeof(leftNodeCount));
      }
      //  if (radio.available(1)) {
      //    radio.read(&leftNodeCount, sizeof(leftNodeCount));
      //  }
      Serial.println("centralNode is reporting:");
      Serial.print("centralNode address : ");
      Serial.println((char *)addresses[0]);

      Serial.print("rightNode address : ");
      Serial.println((char *)addresses[1]);
      Serial.print("rightNodeCount = ");
      Serial.println(rightNodeCount);

      Serial.print("leftNode address : ");
      Serial.println((char *)addresses[2]);
      Serial.print("leftNodeCount = ");
      Serial.println(leftNodeCount);

      Serial.println("---END OF REPORT---\n\n\n\n");
      delay(500);
    }

 rightSensorNode:

    /*
       Testing multi-node functionality of nRF24l01+
       This is rightSensorNode code

       BOM
       1 Arduino Nano centralNode
       1 Ardiuno Uno rightSensorNode
       1 Arduino Mega leftSensorNode
       3 nRF24l01+
    */

    #include <SPI.h>
    #include "RF24.h"
    #include <printf.h>

    #define CEpin 7
    #define CSpin 8

    RF24 radio(CEpin, CSpin);
    byte addresses [][6] = {"1Node", "2Node", "3Node"};

    int rightNodeCount = 0;
    void setup() {
      Serial.begin(115200);
      Serial.println(F("This is the right node"));
      printf_begin();

      radio.begin();
      radio.setPALevel(RF24_PA_MAX);

      radio.openWritingPipe(addresses[1])

      radio.printDetails();

    }

    void loop() {
      rightNodeCount++;
      Serial.println("Sending data to centralNode");
      Serial.print("rightNode address : ");
      Serial.println((char *)addresses[1]);
      Serial.print("rightNodeCount = ");
      Serial.println(rightNodeCount);
      radio.write(&rightNodeCount, sizeof(rightNodeCount));

      Serial.println("---END OF REPORT---\n\n\n\n");
      delay(1000);
    }

leftSensorNode:

    /*
       Testing multi-node functionality of nRF24l01+
       This is leftSensorNode code

       BOM
       1 Arduino Nano centralNode
       1 Ardiuno Uno rightSensorNode
       1 Arduino Mega leftSensorNode
       3 nRF24l01+
    */

    #include <SPI.h>
    #include "RF24.h"
    #include <printf.h>

    #define CEpin 7
    #define CSpin 8

    RF24 radio(CEpin, CSpin);

    byte addresses [][6] = {"1Node", "2Node", "3Node"};

    int leftNodeCount = 0;
    void setup() {
      Serial.begin(115200);
      Serial.println(F("This is the left node"));
      printf_begin();

      radio.begin();
      radio.setPALevel(RF24_PA_MAX);

      radio.openWritingPipe(addresses[2]);

      radio.printDetails();

    }

    void loop() {
      leftNodeCount++;
      Serial.println("Sending data to centralNode");
      Serial.print("leftNode address : ");
      Serial.println((char *)addresses[2]);
      Serial.print("leftNodeCount = ");
      Serial.println(leftNodeCount);
      radio.write(&leftNodeCount, sizeof(leftNodeCount));

      Serial.println("---END OF REPORT---\n\n\n\n");
      delay(1000);
    }

  [1]: http://tmrh20.github.io/RF24/classRF24.html#a127105eb7a3b351cfe777c1cec50627a

body:
Each sensor point should send its address to the central point and this is how the central point knows the source of the message. Then after the central point receives a message, after `if (radio.available())` command receive the data just once (not twice) and then use another if statement to determine which sensor has sent a message (by reading the sent address) and then print.

pseudo code:

    if (radio.available())
    {
        radio.read(&RXbuffer, sizeof(RXbuffer));
        if(RXbuffer.address == sensor1_address)
        {
            print "this is sensor 1"
            print RXbuffer.address;
            print RXbuffer.data;
        }
        else if(RXbuffer.address == sensor2_address)
        {
            print "this is sensor 2"
            print RXbuffer.address;
            print RXbuffer.data;
        }
    }

In your code (inside `if (radio.available())`) you are trying to receive rightNodeCount and lefteNodeCount eventhough at that time just one of them was received.

**EDIT:**

It seems that RF24 uses dedicated pipes to know the source of the information. The following code should work:

pseudo code:

    unsigned char pipe_num;

    if (radio.available(&pipe_num))
    {
        radio.read(&data, sizeof(data));

        if(pipe_num == 1)
        {
            print "this is sensor 1";
            print data;
        }
        else if (pipe_num == 2)
        {
            print "this is sensor 2";
            print data;
        }
    }


message:
Unable to flash Arduino when TXD pin of HC-6 Bluetooth module is connected to Arduino RXD pin?

I get the following error:

> Flashing with command:C:/Users/home/.arduino-create/arduino/avrdude/6.3.0-arduino9/bin/avrdude.exe -CC:/Users/home/.arduino-create/arduino/avrdude/6.3.0-arduino9/etc/avrdude.conf -q -q -patmega328p -carduino -PCOM4 -b57600 -D -Uflash:w:C:/Users/home/AppData/Local/Temp/arduino-create-agent051272951/sketch_jun10a.hex:i
>
> avrdude: stk500_recv(): programmer is not responding
>
> avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x48

body:
Most* Arduino devices are flashed through a bootloader which communicates over the serial pins. If you've connected another device to those pins, that communication may fail. You may need to disconnect the device while you flash the Arduino.

(*: The exceptions are the 32u4-based devices, like the Leonardo and Micro. These communicate directly over USB.)


message:
Write your own program to control Arduino Uno

Is it possible to write a program to control the Arduino Uno, without using
the Arduino IDE?

body:
I assume you mean the Arduino IDE?

Yes there are many options, for example plugins for Eclipse or Microsoft Visual Studio.

[This link][1] show others like:

- CodeBender
- Electron
- Stino
- GEdit
- Komodo

Personally use normally the default Arduino IDE, but I don't like the fact you can use just a few files before it does not fit In the top bar, so than I use the Visual Studio plugin VisualMicro.

  [1]: https://www.intorobotics.com/alternatives-standard-arduino-ide-one-choose/


body:
Most of the time I wrote code for arduino on codeblocks.

The other times on sublime text.

So the answer is yes.


body:
You can program the Arduino hardware without using the Arduino IDE. Using *avr-gcc* and a handful of other tools, including *make* and *avrdude*, you can compile and download to the target Aduino hardware. You can even dispense with the Arduino bootloader, and program the hardware using the common ICSP interface. To do this, you need a hardware programmer, but [you can make another Arduino into one][1] very easily. Using this method frees up the space used by the bootloader for your own code. Naturally, you use the editor of your choice. For a bit of a taste, have a look at the [Adafruit page on programming a trinket][2] (technically not an Arduino, but the methods still apply).

  [1]: https://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduinoisp
  [2]: https://learn.adafruit.com/introducing-trinket/starting-the-bootloader?view=all#programming-with-avrdude


message:
No ports available

Heyy everyone!!! I have just started working on arduino uno board and for the first week it was working fine but yesterday when I plugged in the usb cable the port option in IDE turned gray(showing no ports).
I tried to update drivers by following commands as given on  forum but arduino.inf file was not there under the drivers folder.
Also mega 16u2 ic on my board gets hot as soon as I connect it with usb . Tx and Rx LEDs are constantly glowing and 13 pin led  glows just for a short time then goes off.
It would be of great help if someone can solve my problem:)

body:
>Also mega 16u2 ic on my board gets hot as soon as I connect it with usb .

Your board is electrically damaged and must either be replaced or be repaired by someone able to change out one or more failed surface mount components.

The time of those able to do so is commercially priced above the value of this board, so generally it would only be repaired by someone able to do so themselves, where time spent on a hobby project doesn't necessarily have the same economic value as time spent on paying work.


message:
ESP8266 cannot read POST parameters

I'm working on a simple REST server. I made method to handle `http://<esp8266_IP>/test`. The GET method works like a charm and I got the response. Then I tried to send a POST with a JSON data (I used PostMan) but I cannot read anything.

Searching online I read ESP8266 library cannot parse JSON and in that case I can found plain text into `server.arg("plain")`. I tried that but no success

How can I read the data into the POST method?
<!-- language-all: lang-cpp -->

    ESP8266WebServer server(80);
    ...

    void handleTest()
    {
     if (server.method() == HTTP_GET)
     {
      ...
     }
     else if (server.method() == HTTP_POST)
     {
      String message = "POST\nHeaders:\n";
      for (uint8_t i = 0; i < server.headers(); i++)
      {
       message += server.headerName(i) + ": " + server.header(i) + "\n";
      }
      message += "\nRequest params:\n";
      for (uint8_t i = 0; i < server.args(); i++){
       message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
      }
      server.send(202, "text/plain", message);
     }
    }
    ...
    void setup()
    {
     WiFi.begin(ssid, password);
     Serial.println("");

     // Wait for connection
     while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
     }

     if (MDNS.begin("esp8266")) {
      Serial.println(F("[Server] MDNS responder started"));
     }

     server.on("/test", handleTest);
    }

body:
Instead of using below in `handleTest()`

    else if (server.method() == HTTP_POST)

try using below in `setup()`

    server.on("/test", POST, handleTest);


message:
Arduino as a real device to computer

Suppose we have a computer mouse , now when we connect it to a computer then  computer understands it is a mouse which is been connected to it. Same thing happens for keyboard and many other devices. As per my understanding, the mouse has a microcontroller and a TTL serial converter which is programmed a certain way that enable computer's default mouse driver to understand the instructions coming from the connected device.

Let me to talk about one of my projects where I build a device driver for my own device. Like arduino send serial instructions to a port say COM3 and the driver which is a java program reads those instructions and performs accordingly.

As we all know that the arduino library provides support for Mouse and keyboard which works fine. Mouse operations are performed without a custom driver.

Now what I want is when arduino connects to a computer it gets detected as a Joystick or as a pendrive or something like that.

I go through different header files of mouse and keyboard which are present in arduino library but those are very complex and without proper documentation hard to understand.

Can you tell me where I could find study materiel regarding the existing library? Arduino website provides documentations only on different methods not on how it works.

Or if I think of building my own library then how I should start?

One more thing where I can find the information regarding the protocols that a conventional device like mouse, keyboard, pendrive, CD-ROM follows during communication (like the code or the algorithm that is burn into the microcontroller of the device) ?

I know it is a out of the box question but still if you help me, I will be grateful to you.

body:
> As per my understanding, the mouse has a microcontroller and a TTL serial converter which is programmed a certain way that enable computer's default mouse driver to understand the instructions coming from the connected device.

No, the mouse's microcontroller *is* a USB device.

> Like arduino send serial instructions to a port say COM3 and the driver which is a java program reads those instructions and performs accordingly.

No, that is the *application* you are talking about. The driver is what you install in Windows to make COM3 appear (that is, in any version of Windows *before* windows 10. Every other operating system, and Windows 10, has the driver built in already).

> Now what I want is when arduino connects to a computer it gets detected as a Joystick or as a pendrive or something like that.

There is no support for that in the Arduino API.

> I go through different header files of mouse and keyboard which are present in arduino library but those are very complex and without proper documentation hard to understand.

Even with proper documentation and understanding of how USB works it's hard to understand.

> Can you tell me where I could find study materiel regarding the existing library? Arduino website provides documentations only on different methods not on how it works.
>
> Or if I think of building my own library then how I should start?

Don't. Trying to do what you want without an in-depth understanding of how USB works is nigh on impossible.  I understand how USB works and struggle with writing USB driver code for microcontrollers.

Instead invest in a device that already does what you want (such as a [Teensy 3.x](https://www.pjrc.com/teensy/)), or move away from Arduino and use a professional environment with professional tools and examples to work with.

> One more thing where I can find the information regarding the protocols that a conventional device like mouse, keyboard, pendrive, CD-ROM follows during communication (like the code or the algorithm that is burn into the microcontroller of the device) ?

From the USB Implementer's Forum Inc.

* http://www.usb.org/developers/docs/devclass_docs/

> Mouse or pendrive have a special type of microcontroller which are capable of direct communication to pc ? if so then is their any programmable microcontroller in market?

Yes, and there are plenty. Any of the Arduino boards based around the ATMega32U4 (such as the Leonardo) are that kind of microcontroller. The "serial" interface chip on the Uno is that kind of microcontroller (it is capable of being reprogrammed so it looks like a completely different device, and if you google around you will find people that have done it).

> What is the difference between actual driver and my java program which reads COM port?

The driver is what *makes* the COM port. Your program is what *uses* the COM port.

    [USB device]---->[USB)- Driver -(COM3]<-----[Your program]


message:
Pins are not switching

I am trying to make pins 13, 12, 10 and 9 to switch between high and low. That is, when pin 13 is high, pin 12 should be low, then pin 10 should be high and pin 9 should be low.

Code:

     unsigned char driver[4] ={13, 12, 10, 9};
     String mystring = "";
     void setup() {
       // put your setup code here, to run once:
       Serial.begin(9600);
       for(int i = 0; i < 4; i++){
         pinMode(driver[i], OUTPUT);
       }
     }

     void backward(){
       digitalWrite(driver[0], HIGH);
       digitalWrite(driver[1], LOW);
       digitalWrite(driver[2], HIGH);
       digitalWrite(driver[3], LOW);
     }

     void forward(){
       digitalWrite(driver[0], LOW);
       digitalWrite(driver[1], HIGH);
       digitalWrite(driver[2], LOW);
       digitalWrite(driver[3], HIGH);
     }

     void STOP(){
       digitalWrite(driver[0], LOW);
       digitalWrite(driver[1], LOW);
       digitalWrite(driver[2], LOW);
       digitalWrite(driver[3], LOW);
     }

     void loop() {
       // put your main code here, to run repeatedly:
       while(Serial.available()){
         delay(10);
         char mychar = Serial.read();
         if(mychar == '\0')
           break;
         mystring += mychar;
       }

       if(mystring == "F" || mystring == "f"){
         forward();
         mystring = "";
         Serial.println("moving forward!");
       }

       else if(mystring == "B" || mystring == "b"){
         backward();
         mystring = "";
         Serial.println("moving backward!");
       }

       else if(mystring == "S" || mystring == "s"){
         STOP();
         mystring = "";
         Serial.println("stopped!");
       }

       else
         mystring = "";
       }

When I test it, there is no switching, that is when moving backward, pin 13 is high throughout, pin 12 is low throughout, pin 10 is high throughout, and pin 9 is low throughout

body:
What line ending are you using in your IDE? Because if it is other than 'no line ending', you are also sending a new line, carriage return or both. Those control caracter get included in mystring.

Better to be safe and filter out control caracter. Try this:

    String mystring = "";

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

    void loop() {

      while (Serial.available()) {
        delay(10);
        char mychar = Serial.read();
        if (mychar == '\0')
          break;

        if (isAlpha(mychar)) {
          //  Doesn't include control caracters in mystring
          mystring += mychar;
        }
      }

      if (mystring != "") {
        Serial.print("***"); Serial.print(mystring); Serial.println("***");
        if (mystring == "F") {
          Serial.println("mystring is equal to 'F'");
        } else {
          Serial.println("mystring is not equal to 'F'");
        }
        mystring = "";
      }
    }


message:
RadioHead Library custom configuration for RFM96 LoRa

I have a pair of Adafruit RFM96W LoRa Transceiver Breakouts and want to use them with the RadioHead library.

My pair of radios works if I use the example sketches from the adafruit tutorial, but I want to change their default configuration.

From the Datasheet of RFM96:
> For maximum flexibility the user may
> decide on the spread spectrum modulation **bandwidth (BW)**,
> **spreading factor (SF)** and **error correction rate (CR)**.

I want to configure the BF, SF and CR. I also want to be sure that the radios are working with the LoRa Modulation and that CRC is enabled.
And how to set Header-Settings?

I did find the method rf.setModemConfig() which gives the capability to change the configuration to library-pre-defined ones, which is not what I want. I want to try different combinations of settings.

I did find the method rf.setModemRegisters() but I did not understand how to use it.

Any solution is welcome.

body:
Parameter in RH_RF95.h

    const RH_RF95::ModemConfig myProfile =  {
      RH_RF95_BW_62_5KHZ | RH_RF95_CODING_RATE_4_5,
      RH_RF95_SPREADING_FACTOR_1024CPS};

    rf95.setModemRegisters(&myProfile);


message:
How do I pull up D1-D6 using 10k ohm resistors?

I'm using push buttons to control CR servos (button1=turn CW; button2=turn CCW). How do I pull up D1-D6 and what does that do exactly? I can't find a tutorial that explains it well enough how to use the resistors.

body:
Typical Atmel AVR inputs can “float” when left open, that is, may drift high or low.  The idea of a pullup or pulldown resistor is to give an otherwise-open input a definite value – high if pulled up, low if pulled down.

The values of pullup and pulldown resistor values are a tradeoff:   You can use high values to minimize the current that a sensor device must overcome when it switches values, and to minimize power loss in a battery-powered device.  Or you can use low values to get faster switching when you release the input.

There are built-in pullup resistors on most AVR inputs.  (But A6 and A7 on some models of ATmega328's don't have pullups.)  To use a built-in pullup, initialize the input pin with (for example) `pinMode(mypin, INPUT_PULLUP)` instead of `pinMode(mypin, INPUT)`.

To sense the state of a simple normally-open switch, you would connect one side of the switch to an input, and the other side to ground.  Initialize the pin to be a pulled-up input: eg, `pinMode(mypin, INPUT_PULLUP)`.  Regard the switch as not-pushed when `digitalRead()` shows `HIGH`, and  pushed when it shows `LOW`.

If you really want to use external pullup resistors, connect the switch as above – one side to ground, one side to a pin – and connect a resistor between +5 V and the pin.  That is, one end of a resistor and one side of a switch will connect to the input pin.  In this case, use either `INPUT` or `INPUT_PULLUP` as the `pinMode` setting; it makes no big difference because the internal pullup resistor has a fairly high value, eg 40 KΩ.


message:
Setting ESP8266-01 up with AT commands

I am facing for the first time with the ESP8266-01 module, so sorry if will write any stupid things.

I bought [this][1] module and I wanted to check its parameters through AT commands. Following some guide and wiring schemas found on the web I finally hook the ESP8266 up with an Arduino Uno (as in the picture below. The resistors are 220ohm each and the capacitor is 100uF) in order to print out to the serial monitor the AT commands and responses.

I uploaded the following code to Arduino Uno:

    #include <SoftwareSerial.h>
    SoftwareSerial esp8266(6, 7);

    void setup() {
      // Open serial communications and wait for port to open:
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }

      Serial.println("Started");

      // set the data rate for the SoftwareSerial port
      esp8266.begin(57600);
      esp8266.write("AT\r\n");
    }

    void loop() {
      if (esp8266.available()) {
        Serial.write(esp8266.read());
      }

      if (Serial.available()) {
        esp8266.write(Serial.read());
      }
    }

But when I open the serial monitor (with both NL and CR selected and baud rate set to 9600) **I got no response**!!
If I try to send simple AT or AT+GMR commands, it returns to me nothing or random characters.

Does anyone please could tell me what I am doing wrong?

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

  [1]: https://www.sparkfun.com/products/13678
  [2]: https://i.stack.imgur.com/YrNUy.png

body:
We faced similar problems when using ESP8266 for the first time, Following approach to the problem was fruitful

1. ESP8266 is 3.3v compatible so to avoid problems make a simple adaptor circuit to make it compatible with 5v Arduino ([find details here][1])

2. First thing you need to do is check and confirm if you are able to communicate with your ESP module, you can use any USB to TTL interface and connect ESP Module directly with your computer/laptop. ([explained in detail here][2])

3. Use ESP8266 configuration utility, it will speed up the ESP Module setup and help get the desired product develop faster. ([explained in detail here][3])

Hope it helps.

  [1]: http://absaransari.com/2018/01/25/how-to-power-esp8266-from-5v-supply/
  [2]: http://absaransari.com/2018/01/26/connecting-esp8266-wifi-mobile-with-computer-using-pl2303/
  [3]: http://absaransari.com/2018/01/27/esp8266-wifi-module-configuration-utility/


message:
Shift Register 74HC595 circuit working weirdly

I built the circuit from the arduino ShiftOut tutorial, but it is not working as expected. I made a simulation model and that one isn't working either.
[![Simulation I built][1]][1]

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

The code I used is from the tutorial:

    // SH_CP; 11
    const int clockPin = 9;
    // DS; 15
    const int dataPin = 8;
    // ST_CP; 12
    const int latchPin = 10;

    void setup() {
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin, OUTPUT);
      pinMode(latchPin, OUTPUT);

      Serial.begin(9600);
      Serial.println("reset");
    }

    void loop() {
      for (int number = 0; number < 256; number++) {
        Serial.println(number);
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, MSBFIRST, number);
        digitalWrite(latchPin, HIGH);
        delay(500);
      }
    }
Any idea as to what's wrong?

body:
I presume that you are referring to [this tutorial](https://www.arduino.cc/en/Tutorial/ShiftOut "Serial to Parallel Shifting-Out with a 74HC595"), and [this code](https://www.arduino.cc/en/Tutorial/ShftOut11).

The `clockPin` of Arduino should be connected to pin 11(SH_CP) of 595, `dataPin` to pin 14(DS), and `latchPin` to pin 12(ST_CP).

Swap the values of `clockPin` and `latchPin` in your code, and you should be good to go.

    // SH_CP; 11
    const int clockPin = 10;
    // DS; 14 (not 15)
    const int dataPin = 8;
    // ST_CP; 12
    const int latchPin = 9;


message:
Serial source code

`Serial` is documented on the Reference pages, but seems to receive special treatment (no need to include header), and there does not seem to be any file with the Source code.

`Stream` is the base class for `Serial` and inherits from the Print class.

There is source for `Stream.h`

`LiquidCrystal_I2C` also inherits from the Print class, and I was planning to write code which outputs to either `LiquidCrystal_I2C` or `Serial`; there are many options, but I was looking for `Serial` to explore its inner workings.

body:
`Serial` is an *instance* of the `HardwareSerial` class.  It is defined in `HardwareSerial0.cpp`:

    #if defined(UBRRH) && defined(UBRRL)
      HardwareSerial Serial(&UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR);
    #else
      HardwareSerial Serial(&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0);
    #endif

`HardwareSerial` is a child of `Stream` as defined in `HardwareSerial.h`:

    class HardwareSerial : public Stream
    {
        ....
    };

`Stream` is a child of `Print` as defined in `Stream.h`:

    class Stream : public Print
    {
        ....
    };

`Print` is a top-level class with no inheritance.

`Serial` is *not* a class. It is an *instance* of a class. That is, it's an object that has been *constructed* from the class definition. Anything you access member functions of using a `.` is an *instance* of a class (aka an *object*) not a class itself. Anything you access member functions with `::` is a class using *static* member functions.

Examples:

    Serial.println(); // Call the println() function in the Serial object
    Wire.beginTransmission(0x34); // Call the beginTransmission function in the Wire object
    Foo::bar(); // Call the static function bar() in the Foo class.


message:
Power supply to L293D motor driver

I am new to Arduino. I'm making a line-following bot. I need to power my L293D module. I know that I can supply 9/12V directly with a battery but I am not sure whether I can supply 5V directly from the 5V pin of the Arduino or I have to use something like an IC 7805.

I am confused because I read that the L293D can cause currents up to 600 mA but the max current for an Arduino Uno pin is only 50mA. This question might seem too novice but it would be of great help if someone could explain me about this or the concept in general.

Thanks in advance.

body:
Check the [L293x datasheet](http://www.ti.com/lit/ds/symlink/l293.pdf#page=5 "L293x Quadruple Half-H Drivers").

The L293D IC has two power supply pins. Pin 16, VCC1, is to power the IC itself, ei., its internal logic. Pin 8, VCC2, is to power the motors.

The maximum logic current (ICC1 MAX) drawn by the driver IC at pin 16 is 60mA. Thus, provided you do not have other things connected to the Arduino that can take the current draw above the limit, it is safe to connect VCC1 of the driver IC directly to the Arduino's 5V pin.

The [maximum current you can draw](https://electronics.stackexchange.com/questions/67092/how-much-current-can-i-draw-from-the-arduinos-pins) from the 5V pin is around 400 mA, or 900 mA, when the Arduino is powered by an external power adapter.

The maximum current sourced or sinked by each driver input pin (xA) is 100 μA, and by enable pins (EN), it is 10μA, which is well within the limit of the Arduino digital pins, 40mA (**not** 50 mA!). So you can also safely connect Ax and EN directly to the Arduino.

Coming to the last point, the maximum power current supply by driver outputs (xY) is 600 mA. You cannot source or sink more than 600 mA from the 1Y, 2Y, 3Y and 4Y pins. All of this current will be drawn from pin 8 (VCC2), which is connected to the power supply for the motors, which can be a 9V battery. Note that ICC2 MAX is 1.2 mA. Thus, if the supply voltage of the motors is 5V, you must use another voltage source, like 7805 and not the 5V pin of the Arduino to provide VCC2.

To summarize,

* You can connect pin 16 of L293D to Arduino's 5V pin.
* You can connect pins 1, 2, 7, 9, 10, 15 of L293D to Arduino's digital pins.
* You **cannot** connect pin 8 of L293D to Arduino's 5V pin.