body:
Stumbled upon this weirdest behavior, from time to time, my Arduino (UNO) runs gode really slow.

Searching this issue didn't clarify anything, most people have problems with IDE itself. My issue is related to actual board.

Heres a sample of my flow:

 - I compile & upload my sketch, all good
 - first initiation of program on the board seems to be "fast"
 - when I start to "animate" the neopixels it goes 3-4 times slower than it should
 - I'll touch the board, and animation goes fast again.

[Here's a clip of that, at the end you'll see the "slowness"][1]

* Test environment:
[![enter image description here][3]][3]

* Live environment:
[![enter image description here][4]][4]

The Touching part, is almost like if I "add" static electricity from my finger to the board, it wakes up and behaves normally.

For you who are curious about (non related) what animation I'm doing on neopixels, I'm turning on 15 pixels from 0 to 54. Like a "slide effect".
(I'm not using delay, only a delay(30) in the loop, rest of the delays are based on `millis()`)

Is there any general info / explanation that would explain this behavior, like in electronics, arduino boards specifically ?

EDIT: I should also add, when printing logs into serial monitor, that slowness also affects the  outputs... they appear as "slow" as the pixels flow. When all works normally, I see pixels change and logs 50 times per second (roughly), but in this slow motion, I see pixels change and logs around 20 times per second.  Taking out the `Serial` entirely from the code doesn't seem to have effect.

Code:

    #include <Adafruit_NeoPixel.h>
    #include <avr/power.h>
    #define LEFT_BLINK_IN 2
    #define RIGHT_BLINK_IN 3
    #define PIN           6
    #define NUMPIXELS     54
    Adafruit_NeoPixel     leftLight = Adafruit_NeoPixel(NUMPIXELS, 6, NEO_GRB + NEO_KHZ800);
    Adafruit_NeoPixel     rightLight = Adafruit_NeoPixel(NUMPIXELS, 10, NEO_GRB + NEO_KHZ800);
    int leftBlinkCount   = 0;
    int rightBlinkCount  = 0;
    int PIXELTOSHOW      = 20;
    bool OEM_RIGHT_ON    = false;
    bool OEM_LEFT_ON     = false;
    int R_PIXEL          = -1;
    int L_PIXEL          = -1;
    int G_PIXEL          = -1;
    int D_PIXEL          = -1;
    char LAST_COMMAND;
    bool DRL_ON         = false;
    int DRL_STARTPIXEL  = 35;
    uint32_t COLOR_YEL = rightLight.Color(240, 120, 0);
    uint32_t COLOR_RED = rightLight.Color(255, 0, 0);
    uint32_t COLOR_BLU = rightLight.Color(0, 0, 255);
    uint32_t COLOR_NON = rightLight.Color(0, 0, 0);
    uint32_t COLOR_WHI = rightLight.Color(255, 255, 255);

    unsigned long rightPrevMillis = 0;
    unsigned long leftPrevMillis = 0;
    unsigned long generalPrevMillis = 0;
    const long PIXEL_SWITCH_INTERVAL = 5;

    int DRL_RESETER_LEFT = 0;
    int DRL_RESETER_RIGHT = 0;

    void welcome()
    {
      int totalPixels = (NUMPIXELS + PIXELTOSHOW);
      while (G_PIXEL < totalPixels) {
        unsigned long leftCurrentMillis = millis();
        if (leftCurrentMillis - leftPrevMillis >= 12) {
          leftLight.setPixelColor(totalPixels - G_PIXEL, COLOR_WHI);
          rightLight.setPixelColor(totalPixels - G_PIXEL, COLOR_WHI);
          if (G_PIXEL >= 10) {
            leftLight.setPixelColor(totalPixels - G_PIXEL + PIXELTOSHOW , COLOR_NON);
            rightLight.setPixelColor(totalPixels - G_PIXEL + PIXELTOSHOW , COLOR_NON);
          }
          leftLight.show();
          rightLight.show();
          G_PIXEL++;
          leftPrevMillis = leftCurrentMillis;
        }
      }
      G_PIXEL = 0;
      while (G_PIXEL < totalPixels) {
        unsigned long leftCurrentMillis = millis();
        if (leftCurrentMillis - leftPrevMillis >= 12) {
          leftLight.setPixelColor(G_PIXEL, COLOR_WHI);
          rightLight.setPixelColor(G_PIXEL, COLOR_WHI);
          if (G_PIXEL >= 10) {
            leftLight.setPixelColor(G_PIXEL - PIXELTOSHOW, COLOR_NON);
            rightLight.setPixelColor(G_PIXEL - PIXELTOSHOW, COLOR_NON);
          }
          leftLight.show();
          rightLight.show();
          G_PIXEL++;
          leftPrevMillis = leftCurrentMillis;
        }
      }
    }

    void blinkRight()
    {

      //slidePixels(rightBlinkCount, R_PIXEL, rightLight);
      if (rightBlinkCount > 0 && R_PIXEL > -1)
      {
          //Serial.println("RIGHT "+String(rightBlinkCount));
        LAST_COMMAND = ' ';
        unsigned long rightCurrentMillis = millis();
        if (rightCurrentMillis - rightPrevMillis >= PIXEL_SWITCH_INTERVAL) {
          rightLight.setPixelColor(R_PIXEL, COLOR_YEL);
          if (R_PIXEL >= PIXELTOSHOW)
          {
            rightLight.setPixelColor(R_PIXEL - PIXELTOSHOW, COLOR_NON);
            if (G_PIXEL > -1 && DRL_ON == false) {
              leftLight.setPixelColor(R_PIXEL - PIXELTOSHOW, COLOR_NON);
            }
          }
          leftLight.show();
          rightLight.show();
          R_PIXEL++;
          rightPrevMillis = rightCurrentMillis;
        }
        if ( R_PIXEL >= (NUMPIXELS + PIXELTOSHOW)) {
          rightBlinkCount--;
          if ( rightBlinkCount > -1 ) {
            R_PIXEL = DRL_RESETER_RIGHT = 0;
          } else {
            L_PIXEL = G_PIXEL = -1;
          }
          if(DRL_ON){
            D_PIXEL=DRL_STARTPIXEL;
          }
        }
      }

      }

      void blinkLeft() {
      //  slidePixels(leftBlinkCount, L_PIXEL, leftLight);

        if (leftBlinkCount > 0 && L_PIXEL > -1)
      {
              //Serial.println("left  "+String(rightBlinkCount));
        LAST_COMMAND = ' ';
        unsigned long leftCurrentMillis = millis();
        if (leftCurrentMillis - leftPrevMillis >= PIXEL_SWITCH_INTERVAL) {
          leftLight.setPixelColor(L_PIXEL, COLOR_YEL);
          if (L_PIXEL >= PIXELTOSHOW)
          {
            Serial.print(" "+String(L_PIXEL));
            leftLight.setPixelColor(L_PIXEL - PIXELTOSHOW, COLOR_NON);
            if (G_PIXEL > -1 && DRL_ON == false) {
              rightLight.setPixelColor(L_PIXEL - PIXELTOSHOW, COLOR_NON);

            }
          }
          rightLight.show();
          leftLight.show();
          L_PIXEL++;
          leftPrevMillis = leftCurrentMillis;
        }
        if ( L_PIXEL >= (NUMPIXELS + PIXELTOSHOW) ) {
          leftBlinkCount--;
          Serial.println("Count "+leftBlinkCount);
          if ( leftBlinkCount > -1 ) {
            L_PIXEL = DRL_RESETER_LEFT = 0;
          } else {
            L_PIXEL = G_PIXEL = -1;
          }
          if(DRL_ON){
            D_PIXEL=DRL_STARTPIXEL;
          }
        }
      }

    }

    /*void slidePixels(int &blinkCount, int &blinkPixel, Adafruit_NeoPixel &sideLight){
      if (blinkCount > 0 && blinkPixel > -1)
      {
        LAST_COMMAND = ' ';
        unsigned long leftCurrentMillis = millis();
        if (leftCurrentMillis - leftPrevMillis >= PIXEL_SWITCH_INTERVAL) {
          sideLight.setPixelColor(blinkPixel, COLOR_YEL);
          if (blinkPixel >= PIXELTOSHOW)
          {
            if(G_PIXEL>-1){
              rightLight.setPixelColor(blinkPixel - PIXELTOSHOW, COLOR_NON);
              leftLight.setPixelColor(blinkPixel - PIXELTOSHOW, COLOR_NON);
            }
          }
          rightLight.show();
          leftLight.show();
          blinkPixel++;
          leftPrevMillis = leftCurrentMillis;
        }
        if ( blinkPixel >= (NUMPIXELS + PIXELTOSHOW) ) {
          blinkCount--;
          if ( blinkCount > -1 ) {
            blinkPixel = 0;
          } else {
            blinkPixel = -1;
            if(DRL_ON){
              G_PIXEL = -1;
            }
          }
        }
      }
    }*/

    int switchRB = 0; // 0 = red, 1 = blue
    void slideBlueRed() {
      unsigned long currentMillis = millis();
      if (currentMillis - generalPrevMillis >= 100) {
        if (switchRB == 0) {
          leftLight.setPixelColor(G_PIXEL, COLOR_RED);
          rightLight.setPixelColor(G_PIXEL, COLOR_RED);
        } else {
          leftLight.setPixelColor(G_PIXEL, COLOR_BLU);
          rightLight.setPixelColor(G_PIXEL, COLOR_BLU);
        }
        if (G_PIXEL >= 10) {
          leftLight.setPixelColor(G_PIXEL - PIXELTOSHOW, COLOR_NON);
          rightLight.setPixelColor(G_PIXEL - PIXELTOSHOW, COLOR_NON);
        }
        leftLight.show();
        rightLight.show();
        G_PIXEL++;
        generalPrevMillis = currentMillis;
      }
    }

    void drlLight(){

      unsigned long currentMillis = millis();
      if (D_PIXEL < NUMPIXELS) {
        leftLight.setPixelColor(NUMPIXELS-DRL_RESETER_LEFT, DRL_ON == true ? COLOR_WHI : COLOR_NON);
        rightLight.setPixelColor(NUMPIXELS-DRL_RESETER_RIGHT, DRL_ON == true ? COLOR_WHI : COLOR_NON);
        rightLight.setBrightness(128);
        leftLight.setBrightness(128);
        rightLight.show();
        leftLight.show();
        D_PIXEL++;
       //x //Serial.println(String(DRL_RESETER_LEFT) + " "+ String(NUMPIXELS - DRL_STARTPIXEL));
        if(DRL_RESETER_LEFT+1 < (NUMPIXELS - DRL_STARTPIXEL)){
          DRL_RESETER_LEFT++;
        }
        if(DRL_RESETER_RIGHT+1 < (NUMPIXELS - DRL_STARTPIXEL)){
          DRL_RESETER_RIGHT++;
        }
        generalPrevMillis = currentMillis;
      }

    }

    void setup() {
      Serial.begin(115200);
      leftLight.begin();
      rightLight.begin();
      pinMode(LEFT_BLINK_IN, INPUT);
      pinMode(RIGHT_BLINK_IN, INPUT);
      delay(50);
      welcome();
    }

    void loop() {

      if (digitalRead(LEFT_BLINK_IN) == HIGH) {
        if ( OEM_LEFT_ON == false ) {
          OEM_LEFT_ON = true;
          leftBlinkCount++;
          //Serial.println("LEFT "+String(leftBlinkCount));
          if (leftBlinkCount == 1) {
            L_PIXEL = 0;
          }
        }
      } else {
        OEM_LEFT_ON = false;
      }

      if (digitalRead(RIGHT_BLINK_IN) == HIGH) {
        if ( OEM_RIGHT_ON == false ) {
          OEM_RIGHT_ON = true;
          rightBlinkCount++;

          if (rightBlinkCount == 1) {
            R_PIXEL = 0;
          }
        }
      } else {
        OEM_RIGHT_ON = false;
      }

      if(DRL_ON && leftBlinkCount < 1 && rightBlinkCount < 1){
        drlLight();
      }

      blinkRight();
      blinkLeft();
      if(rightBlinkCount < 1 || leftBlinkCount < 1){
        delay(30);
        switch (LAST_COMMAND) {
          case 'q':
          case '?': {
            for ( int gp = 0; gp < NUMPIXELS + PIXELTOSHOW; gp++) {
              leftLight.setPixelColor(gp, COLOR_NON);
              rightLight.setPixelColor(gp, COLOR_NON);
            }
            leftLight.show();
            rightLight.show();
            G_PIXEL = -1;
            break;
          }
          case 's': {
            slideBlueRed();
            //Serial.println("bluuu");
            if (G_PIXEL >= NUMPIXELS ) {
              G_PIXEL = -1;
              switchRB = switchRB == 0 ? 1 : 0;
            }
            break;
          }
          case 'w': {
            welcome();
            if (G_PIXEL >= NUMPIXELS + PIXELTOSHOW) {
              G_PIXEL = -1;
            }
            break;
          }
          case 'd': {
            if(DRL_ON==false){
              D_PIXEL = DRL_STARTPIXEL;
              DRL_ON = true;
              LAST_COMMAND = '-';
            }else{
              D_PIXEL = 0;
              DRL_ON = false;
            }
            break;
          }
        }
        if (Serial.available()) {
          LAST_COMMAND = '-';
          while (Serial.available()) {
            char command = Serial.read();
            G_PIXEL=-1;
            LAST_COMMAND = command;
          }
        }
      }
    }

  [1]: https://www.youtube.com/watch?v=B-7562YRjLU
  [3]: https://i.stack.imgur.com/9HW7S.png
  [4]: https://i.stack.imgur.com/bAezE.png

title: Arduino code (on board) runs really slow

Answers: 2

body:
This kind of behavior is almost always caused by floating digital input pins. "floating" means not connected to either power or ground, so their voltage is free to float. These input puts have very high impedance (typically less than 1uA of leakage current), so bringing a charged object near them is more enough to change their state.

Probably the easiest way to nail down (and sometimes fix) this problem is to enable the pull-up resistors on the digital inputs.

In you program, this could be as easy changing the mode on the digital input pins from `INPUT` to `INPUT-PULLUP`...

    void setup() {
      Serial.begin(115200);
      leftLight.begin();
      rightLight.begin();
      pinMode(LEFT_BLINK_IN, INPUT_PULLUP );
      pinMode(RIGHT_BLINK_IN, INPUT_PULLUP );
      delay(50);
      welcome();
    }

This will almost certainly eliminate the intermittent behavior you are seeing.

What you end up with might not be what you want (you might want the pin to dault to 0 when not connected), in which case you can add an external pull-down resistor or change the software to work with default pull-up.

body:
Now, 3 years later, I found the actual source of your problem. I had a similar problem so I'm posting here for others to find this solution.

The problem is that the NeoPixel library disables ALL interrupts during the time it spends sending the pixel data. The millis() function is dependent on interrupts. It works by incrementing a counter once every millisecond, based on a interrupt, called from a hardware timer. If you disable all interrupts then the counter will not be incremented for the duration.

The NeoPixel library needs to disable them because NeoPixels need very accurate timing of the signals, and you'd suffer from visible intermittent glitches if not.

The millis() counter drops about 30 microseconds per a RGB pixel, or 40 microseconds for a RGBW pixel. You have 54 RGB pixels in your led strip. 54*0,030 = 1,62 ms. Which means that there's 1,62 milliseconds between each of your millis() updates. I.e. it updates too slow.

Your unstable button must've simply caused nonstop neopixel updates, due to some logic in your code.

There's no easy fix for this, but a few specialized alternative or companion libraries exist that use very device-specific peripherals to work around it. For example, you could use one of the hardware timers to measure the time spent sending NeoPixel data, and then manually go in and update the millis() counter accordingly when done. This requires hacking the NeoPixel library and reading the datasheets for your specific Arduino processor.


body:
I am creating a program that turns on and off an led. When two buttons are considered "high". But there is a twist, The first button needs to stay "high" until the second button is pressed and the led turns on. Here is my code so far.

    // Boolean logic for Button Switch
    boolean currentState = LOW;    //stroage for current button state
    boolean lastState = LOW;      //storage for last button state
    boolean ifcondState = LOW;    //storage for the current state of the ifturn  (off/on)

    // set pin numbers:
    const int buttonPinA = 3;     // the number of the pushbutton pin
    const int buttonPin1 = 4;     // the number of the pushbutton pin
    const int ledPin =  13;      // the number of the LED pin
    const int ifcond =  12;      // the number of the ifcond pin
    const int ifturn =  11;      // the number of the ifturn pin

    // variables will change:
    int buttonStateA = 0;         // variable for reading the pushbutton status
    int buttonState1 = 0;         // variable for reading the pushbutton status
    int buttonStateIf = 0;         // variable for reading the If Condition status

    void setup() {
    //initialize Serial connection
    Serial.begin(9600);
    // initialize the LED pin as an output:
    pinMode(ledPin, OUTPUT);
    // initialize the pushbutton pin as an input:
    pinMode(buttonPinA, INPUT);
    // initialize the pushbutton pin as an input:
    pinMode(buttonPin1, INPUT);
    // If Condictional Pin
    pinMode(ifcond, OUTPUT);
    // If Turnon Pin
    pinMode(ifturn, INPUT);

    }

    void loop() {
      // read the state of the pushbutton values:
      currentState = digitalRead(buttonPinA);
      buttonState1 = digitalRead(buttonPin1);
      buttonStateIf = digitalRead(ifturn);

      // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH:
      if (currentState == HIGH && lastState == LOW){    //  if button has just been pressed
        Serial.println("pressed");
        //delay(1);

        //toggle the state of the ifcond
        if (ifcondState == HIGH){
          digitalWrite(ifcond, LOW);
          ifcondState = LOW;
        }
        else {
          digitalWrite(ifcond, HIGH);
          ifcondState = HIGH;
        }
      }
      lastState = currentState;

      if (ifturn == HIGH && buttonState1 == HIGH) {
        digitalWrite(ledPin, HIGH);
      }
      else ();
      digitalWrite(ledPin, LOW);
    }

I have Pin 12 (ifcond) And pin 11(ifturn) Jumped together. Pin 12 acts like a button to pin 11, When it goes high pin 11 reads the change.

The code works like this, When ButtonpinA goes high  pin 12 goes high and stays high until the next button push. This is the part that doesn't work Pin 11 should read if pin 12 if high or not. If it reads high and Button1 is also high it should turn on ledpin which it does not.

I am sorry for any confusion Thanks

title: Buttons and LED

Answers: 1

body:
    if (ifturn == HIGH && buttonState1 == HIGH) {
      digitalWrite(ledPin, HIGH);
    }
    else ();
    digitalWrite(ledPin, LOW);

I think you have made a small mistake here.

What you are saying there is "If both these inputs are high then turn on the LED - otherwise don't do anything", and immediately after that "Turn off the LED".

So the LED is turned on when they are both high, and immediately turned off again, so fast you never see the LED lighting up at all.

I think what you meant to have was:

    if (ifturn == HIGH && buttonState1 == HIGH) {
      digitalWrite(ledPin, HIGH);
    } else {
      digitalWrite(ledPin, LOW);
    }

That way it will turn the LED on if both are HIGH, otherwise it will turn the LED off *only if the test for both being high fails*.


body:
So I've been browsing around for a whole looking for a good microcontroller that's super small. So far the smallest one I found was an Arduino Nano. But before I go buying it, there are some questions I have about it.

1. Is Bluetooth compatible with it and if so where would I get the Bluetooth code?
2. Is there anything smaller than it that's Bluetooth compatible?
3. Would an Arduino Nano (Or the device in the question above) be able to play sounds?

title: Would Arduino Nano be good for Bluetooth + Sound

Answers: 1

body:
There are [Bluetooth boards][1] and chips that you can connect to a Nano.

You can play sounds with a Nano. Crudely with PWM and a direct connection, for finely with an external digital-to-analog converter.

But if super-smallness is what you are after, there may be better options.

The [Blue Bean][2] is a complete  BLE microcontroller on a single board that is smaller than a Nano+board.

If you want even smaller, you could get something like the new Cypress EZ-BLE module...

[![enter image description here][3]][3]
http://www.cypress.com/products/ez-ble-module-bluetooth-smart

It is a complete programmable BLE system on a tiny module. It is hard to imagine anything smaller than that!

  [1]: https://www.adafruit.com/products/1588
  [2]: http://www.makershed.com/products/lightblue-bean-bluetooth-4-0
  [3]: https://i.stack.imgur.com/mlfYc.jpg


body:
I am using the following setup on my Arduino UNO to measure cpu fan RPMs:

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

The code is set to bring the trigger pin for each transistor high when it is checking that fan's RPM and FreqMeasure.h is then used to check the frequency of the signal on pin 8 which is then translated to RPM and sent to the LCD display.

I am experiencing reading issues and suspect that the signal is remaining on the measuring bus during the subsequent reads, however before revamping my code I simply wonder:

Is my circuit logic sturdy? I am just getting my feet back under me with microprocessors and have always found transistors to be a tricky subject, thanks in advance for your help!

If you'd like to see more info all can be found on [GitHub.](https://github.com/msashlee/fanMon/)

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

title: Transistors to switch monitor inputs

Answers: 1

body:
I have [simulated your circuit](http://www.falstad.com/circuit/circuitjs.html?cct=$+1+0.000005+10.20027730826997+50+5+43
R+240+160+208+160+0+2+721+6+6+0+0.5
g+288+176+288+208+0
f+240+160+288+160+0+1.5
R+432+80+432+48+0+0+40+5+0+0+0.5
r+432+80+432+144+0+10000
t+336+96+336+144+0+1+-4.999999997500001+-0.0000049995+100
w+288+144+320+144+0
w+352+144+432+144+0
w+432+144+496+144+0
r+336+96+160+96+0+10000
r+336+240+160+240+0+10000
L+160+240+128+240+0+0+false+5+0
w+352+288+432+288+0
w+288+288+320+288+0
t+336+240+336+288+0+1+-4.999999997500001+-0.0000049995+100
f+240+304+288+304+0+1.5
g+288+320+288+352+0
R+240+304+208+304+0+2+382+6+6+0+0.5
w+432+144+432+288+0
L+160+96+128+96+0+0+false+5+0
p+496+240+496+144+0
g+496+240+496+256+0
o+20+64+0+558+5+0.00009765625+0+-1
) and it seems sound enough to me.

It is a little confusing having the transistors there though.  I would prefer to convert the three open drain outputs to logic level outputs (each having its own pullup resistor) then use a digital 3:1 MUX (or discrete logic gates) to select the signal to sample.


body:
I am familiar with using PWM on Arduino and have done so with simple 3-pin interfaces: e.g. PWM, DIR (direction) and GND pins. Choose a direction with DIR, set speed with PWM in software (0 - 255), simple stuff.

But this board I'm buying seems different:

http://www.ebay.com/itm/DC-43A-Double-BTS7960B-Stepper-Motor-Driver-H-Bridge-PWM-for-Arduino-Smart-Car-/141485439094

There seems to be 6 control pins:

`R_IS, R_EN, RPWM, L_IS, L_EN, LPWM`

But from what I understand this board would only be used for controlling one motor bidirectionally, so why is there a distinction between left and right?

So how would I go about using this motor driver board in a similar way to my `PWM, DIR, GND` boards that I've used before to control the motor direction and speed?

Thanks!

title: How to connect this motor driver board to Arduino to drive bidirectional motor?

Answers: 1

body:
I guess you have used DC Motor for your earlier cases? Or Step Motor with a logic on the stepper controllers?

Here you have two H Bridges which drives one Step Motor. So as I understand it, you have two PWM Inputs, one for each output channel to the coil windings of the stepper motor. Like an encoder signal you can set the direction with setting one pwm before the other. So the step motor is controlled via unipolar stepping.

For further help you need to say which motor you want to use with this card. But first I would look at the different stepping modes (unipolar and the two bipolar and maybe microstepping).

Greets


body:
I bought today an Arduino Uno R3, and I'm looking forward to make it an HID device. I have seen many projects using a serial USB type B port. As I want to build a little gamepad, I would like to use the smaller USB mini type B port to achieve similar results. Looking it up did not seem to bring significant results.

Am I missing anything? Do I have to use a serial port similar to the one used by Arduino or can I reproduce the project using the aforementioned port?

title: USB mini type B port on Arduino Uno

Answers: 2

body:
It sounds like you are going to be attempting software "bit-banged" USB.  That, while possible, is severely frowned upon, especially when you have the resources to do it properly at your fingertips.

In answer to your question, yes, you can use a USB mini B connector.  It is no different to a USB B connector except it is much smaller and contains one extra pin - USBID - which you can completely ignore (it's only used on USB On-The-Go devices).

USB is quite a heavy protocol to do in pure software - it won't leave much "room" for you to do much else.  Better would be to re-program the ATMega16U2 chip that is used for the current USB interface.  You will need some form of hardware programmer for it - you can use another Arduino Uno, and once done you won't be able to directly program the ATMega328P chip through the USB, so you would need some other method for connecting that (external USB serial adapter cable, or another Arduino), but the ATMega16U2 chip is specifically designed to work with the USB.  Offloading the USB portion of your project onto that chip and using the serial interface that is already wired up to communicate commands and instructions to/from the ATMega328P would be a much more powerful (and reliable) system.  There's plenty of tutorials and links around to show you how to reprogram that chip.

body:
As an alternative to Majenko's suggestion you can implement Virtual USB as described at [Virtual USB Keyboard](http://www.practicalarduino.com/projects/virtual-usb-keyboard). You just need:

* 3 resistors
* 2 zener diodes
* a bit of wire
* a suitable USB socket

The advantage is you haven't modified your Uno's USB chip (the ATMega16U2) so you can continue to upload sketches in the normal way.

The disadvantage is that the software USB may be more flaky than a hardware-implemented one.

Personally I don't like reprogramming my ATMega16U2 because I may as well have used one of the chips with a ATmega32U4 chip on it in the first place (like the Micro) which is designed for easy reprogramming.


body:
I've asked another question in electronics about what to use to compare 2 input voltages, the answer was to use comparators.

Digging around a bit, turns out most of the comparators outputs are pull-up, which makes it quite difficult to translate (probably due lack of general electronics knowledge, self-learned) and I'm not able to distinguish from maker's PDFs which comparators have pull-up or pull-down outputs.
I've figured PD comparators illustrate in PDF a resistor right after the output... but many illustrations I've seen doesn't clarify PD / PU, or I'm just missig that.

But my question is, are there any PD comparators (well known) where it's output can be connected to the digital pins or arduino (while those are defined as INPUT mode)?

I appreciate any guidance on this topic.

Just a side note, I want to switch on a led, when ever external source is at 12V and turn that same led off when it's below 11.5V...

title: Comparators for digital input mode

Answers: 2

body:
You can't put 12 volts into a Uno input pin in any case.

You could run it into a [voltage divider](https://en.wikipedia.org/wiki/Voltage_divider) and divide it down to somewhere on the range 0 to 5 V, and then do an analogRead to see exactly (or almost exactly) what the resulting voltage is.

I don't really see where comparators come into it in this particular case. I mean, you could use a comparator to turn the LED on, but then where does the Arduino come into it?

---

> I've actually tried with voltage divider, I went pretty high on my resistors, taking the 12V source and hooked in 4x1M resistors but the 12V never came down significantly.

You need a voltage divider like this:

[![Voltage divider][1]][1]

Those values give you 4 V on the Arduino pin if there is 12 V on the input.

Vout = (R2 / (R1 + R2) ) * Vin

So:

    (1000 / 3000) * 12V = 4V

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

body:
Many comparators come with open collector output. OC output means, it can pull down a potential, but cannot generate a voltage higher than ground.

If you have a high impedance input like your Arduino has, and you connect a OC output to it, nothing will happen unless you add a pullup resistor providing a positive voltage. Otherwise there won't be a closed electric circuit where any measurable voltages can be generatet.

Lucky you: Arduino input pins can generate a positive voltage by providing an internal pullup resistor. Read the documentation on input pins and pin direction to make use of this. This way you can connect an open collector output to your input pin without additional components.

But beware: This doesn't work with a comparator with a pullup output (I guess these are rather rare). In this case you have to provide an additional pulldown resistor to ground.

Caveat: You can use a comparator with totem pole or tristate output without pullup or down as long as its output swing does not exceed maximum allowable voltages of the input pin. I.e. you cannot connect a comparator supplied with 15 V and a totem pole output to the input of an arduino, because the high level will exceed 5 volts (I assume an Arduino Uno).

Now. How to learn from a datasheet, if the output is pulldown, pullup, totempole or tristate?
If a device features a pulldown stage, you will find a value for something called "Output Sink Current" in the section "electrical characteristics". For a pulldown stage this will likely be named "Output source current". A tristate output will be denominated somewhere in the datasheet for sure, because this is an extra feature.

Have a look at lm339!


body:
I build a simple HTTP GET request by SIM900. Here is it:

    -----1-----
    AT+CSQ

    +CSQ: 25,0

    OK

    -----2-----
    AT+CGATT?

    +CGATT: 1

    OK

    -----3-----
    AT+SAPBR=3,1,"CONTYPE","GPRS"

    OK

    -----4-----
    AT+SAPBR=3,1,"APN","indosatgprs"

    OK

    -----5-----
    AT+SAPBR=1,1

    OK

    -----6-----
    AT+HTTPINIT

    ERROR

    -----6.1-----
    AT+HTTPPARA="CID",1

    OK

    -----7-----
    AT+HTTPPARA="URL","http://www.minimalsites.com"

    OK

    -----8-----
    AT+HTTPACTION=0

    OK

    -----9-----
    AT+HTTPREAD

    OK

    -----10-----
    AT+HTTPTERM

    ERROR

    +HTTPACTION:0,200,1240

    -----10.0-----
    AT+SAPBR=0,1

    OK

The step 9 AT+HTTPREAD I supposed to see some html from http://www.minimalsites.com. But i dont see anything, What wrong with me?

title: SIM900 AT command HTTP GET request not show the web page

Answers: 4

body: Check Your Connection Try Pinging the IP of Your Arduino and INstead of Using the AT commands use this library its easier and Nice https://github.com/amcewen/HttpClient

body:
From what I can see in your results, it seems `AT+HTTPINIT` returned an error. This means the HTTP service wasn't even successfully activated. So there's no way the commands you issued later would have been successful. From the AT command manual, AT+HTTPINIT is necessary before you can do any HTTP-related stuff.
You need to run the command `AT+CGATT=1` to attach GPRS, even if your query shows its value is already 1.
It could also be that your APN requires authentication, using a username and password. So once you find out the username and password authorized by 'indosatgprs' (customer care?), you can use them in the following commands.

        AT+SAPBR=3,1,"USER","Enter the username here"
        AT+SAPBR=3,1,"PWD","Enter password"

Both commands should return OK if successful. To view all the parameters you have set, you can use `AT+SAPBR=4,1`. If all the parameters are satisfactory, and you have sufficient airtime in the SIM, then you can attempt `AT+HTTPINIT`. Only if this command returns OK, should you proceed to run `AT+HTTPPARA`-related commands.

body:
You have to wait after `AT+HTTPACTION=0` for a while until you see something like `+HTTPACTION:0,200,1240`

Then continue to `AT+HTTPREAD`, you will see the result.

Finally, terminate HTTP.

body:
after days fighting with asynchronous and limit serial buffer size (64Bytes). I found this one.

this link help me out, it uses the standard library SoftwareSerial and my big txt file 1100 bytes or my html file (5814bytes)  are  download again & again with no issue!!

https://www.youtube.com/watch?v=cpgQOmQwUL8&t=1263s
http://www.iforce2d.net/sketches/gsm_HTTPGet.zip
nb: I change it to AltSoftSerial, no problem neither.
Thanks iforce2d

ps: you can also use the "ModuleSerial-master" library, but I need to save the space for other code (which already uses 74% of 2KB RAM) so I stick to AltSoftSerial which already found in my sketch


body:
Could someone help me how to output the numbers from 1 to 10 via Serial, without having to write out each command by hand?

Below is my sketch - I need it concise instead of a long sketch:

    #include <Streaming.h
    //setup
    void setup() {
     Serial. begin(9600);//The faster the better
    }//Close the sertup

    //main loop
    void loop() {

      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(1) << endl;
      delay(1000);
      Serial<< _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(2) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(3) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(4) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(5) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(6) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(7) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(8) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(9) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(10) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(11) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(12) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(13) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(14) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(15) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(16) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(17) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(18) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(19) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(20) << endl;
       delay(1000);
      while(1){}//freeze the main loop

    }

title: How I can print several numbers via Serial with very few lines of code?

Answers: 3

body:
*[This replaces my earlier answer, and addresses information added to the question.]*

You apparently want a sketch that outputs 1, 2, 3 ... 100 to serial output, where each number string is embedded within a control sequence.

Here are two ways.  The first program outputs the sequence once, using ordinary Arduino `Serial.write()`, `Serial.print()` and `Serial.println()` statements:

Program 1.  Output 1, 2, 3 ... 100 once

    void setup() {
      Serial.begin(9600);
      for (int j=1; j<=100; ++j) {
        Serial.write(27); // Send escape character
        Serial.print("[2J"); // Send erase-screen command
        Serial.print("\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t");
        Serial.println(j); // Send j in decimal format
        delay(1000);
      }
    }
    void loop() {}

The other program will output the sequence repeatedly.  It uses the `Streaming.h` library, but in a  rational manner; for example, instead of quoting every character separately like the program in the photo, it quotes character sequences in strings.  Note, Esc [2J is an [ANSI escape code sequence](https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes) that erases the screen it is directed to, if the screen device is ANSI compliant.

Program 2.  Output 1, 2, 3 ... 100 repeatedly

    #include <Streaming.h> // or "Streaming.h" if appropriate
    byte j=0;
    void setup() {
      Serial.begin(9600);
    }
    void loop() {
      ++j;
      // Send Esc [2J which will erase screen
      Serial << _BYTE(27) << "[2J";
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << j;
      if (j >= 100) j=0;
      delay(1000);
    }

body:
<!-- language-all: lang-C++ -->

Ah, a challenge!

> I have to write from 1 to 100, and I don't want to repeat it all 100 times

Your question did not make that clear. Anyway:

    int main () {
      Serial.begin (9600);
      for (int i = 1; i <= 100; i++)
        Serial.println (i);
      while (true);
      }

You can probably make it shorter at the expense of readability.

    int main(){Serial.begin(9600);for(int i=1;i<=100;i++)Serial.println(i);while(1);}

body:
Fixing the typos in your original code, so that it should probably read:

    #include <Streaming.h>

    //setup
    void setup() {
     Serial.begin(9600);  //The faster the better
    }   //Close the setup

    //main loop
    void loop() {
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(1) << endl;
      delay(1000);
      Serial<< _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(2) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(3) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(4) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(5) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(6) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(7) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(8) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(9) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(10) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(11) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(12) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(13) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(14) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(15) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(16) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(17) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(18) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(19) << endl;
      delay(1000);
      Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
      Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
      Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(20) << endl;
      delay(1000);
      while(1){} //freeze the main loop
    }

Then condensing the *cursor positioning* lines, gives:

    #include <Streaming.h>

    //setup
    void setup() {
     Serial.begin(9600);  //The faster the better
    }   //Close the setup

    //main loop
    void loop() {
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(1) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(2) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(3) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(4) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(5) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(6) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(7) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(8) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(9) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(10) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(11) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(12) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(13) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(14) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(15) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(16) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(17) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(18) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(19) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
      Serial << "\t\t\t\t\t" << _DEC(20) << endl;
      delay(1000);
      while(1){} //freeze the main loop
    }

Then joining the two *cursor positioning* lines, gives:

    #include <Streaming.h>

    //setup
    void setup() {
     Serial.begin(9600);  //The faster the better
    }   //Close the setup

    //main loop
    void loop() {
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(1) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(2) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(3) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(4) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(5) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(6) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(7) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(8) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(9) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(10) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(11) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(12) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(13) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(14) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(15) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(16) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(17) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(18) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(19) << endl;
      delay(1000);
      Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
      Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(20) << endl;
      delay(1000);
      while(1){} //freeze the main loop
    }

Then putting each repeated line in a `for` loop, and adding a *Maximum Count* `const` variable, gives:

    #include <Streaming.h>

    const int MaxCount = 20;

    //setup
    void setup() {
     Serial.begin(9600);  //The faster the better
    }   //Close the setup

    //main loop
    void loop() {
      for (int n = 1; n < 20; n++) {
        Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
        Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(n) << endl;
        delay(1000);
      }

      while(1){} //freeze the main loop
    }

However, [jwpat7's answer][1] is much better, and [Nick's answer][2] is the shortest.

  [1]: https://arduino.stackexchange.com/questions/16122/how-i-can-make-serial-output-print-short#answer-16123
  [2]: https://arduino.stackexchange.com/questions/16122/how-i-can-make-serial-output-print-short#answer-16124


body:
I have a `String content=""` and if I put an HTTP request like this:

    client.println("GET /api/actions?parking_id=39 HTTP/1.1");
    client.println("Host: ramp-rampcontrol.rhcloud.com");
    client.println("Connection: close");
    client.println();

the output I get is:

     [{"action_id":35,"action_type":"up","parking_id":39,"user_id":17,"ramp":"exit","created_at":"2015-07-10 18:02:40","updated_at":"2015-07-10 18:02:40"},{"action_id":41,"action_type":"up","parking_id":39,"user_id":17,"ramp":"entry","created_at":"2015-08-16 20:50:14","updated_at":"2015-08-16 20:50:14"},{"action_id":42,"action_type":"down","parking_id":39,"user_id":17,"ramp":"entry","created_at":"2015-08-16 20:50:21","updated_at":"2015-08-16 20:50:21"},{"action_id":43,"action_type":"down","parking_id":39,"user_id":17,"ramp":"exit","created_at":"2015-08-16 20:50:22","updated_at":"2015-08-16 20:50:22"}]

The little parser I created is this:

    while(client.available()) {
     char c = client.read();
        if(c == '{'){
          begin1 = true;
        }

      if (begin1) {
        content += c;
       }

      if (c == '}') {
          break;
        }
     }

Is it possible to store only the first action in JSON output, because the actions are updated, and if the number of chars extends 256 than I get errors while working with the `String content`?

title: GET the first result in HTTP request

Answers: 1

body:
Your question is not clear to me. First of all does your parser get the whole response? And second by first action do you mean "action_id":35"?
If both are true then your solution is simple.

First you separate every comma ", " and put in a string array then you further split each index by ":" so the first part is the name "action_id" and the second is the value "35". I hope that helps . You can look up the split function, it's easy.

But if the above is not what you needed then I am afraid you *cannot* get only the first response, because that has to do with the server itself.

Here is a solution, do try it.

I found an [easier solution][1]. Follow the example and replace the content and fields with your response content and you will be done in minutes.

  [1]: https://github.com/bblanchon/ArduinoJson


body:
I'm new to Arduino so this may be a really silly doubt but I'm not finding an explanation for it anywhere online. I first uploaded this code (to blink 5 LEDs) on my Arduino Uno :

     void setup(){
     pinMode(12, OUTPUT);
     pinMode(11, OUTPUT);
     pinMode(10, OUTPUT);
     pinMode(9, OUTPUT);
     pinMode(8, OUTPUT);
    }

    void loop(){
    digitalWrite(12, HIGH);
    delay(1000);
    digitalWrite(12, LOW);
    delay(1000);
    digitalWrite(11, HIGH);
    delay(1000);
    digitalWrite(11, LOW);
    delay(1000);
    digitalWrite(10, HIGH);
    delay(1000);
    digitalWrite(10, LOW);
    delay(1000);
    digitalWrite(9, HIGH);
    delay(1000);
    digitalWrite(9, LOW);
    delay(1000);
    digitalWrite(8, HIGH);
    delay(1000);
    digitalWrite(8, LOW);
    delay(1000);
    }

The 5 LEDs glowed brightly. But when I uploaded the following code (using an if statement to reduce the size of the previous one), the LEDs glowed dimly.

    int LEDpin = 13;
    void setup(){
    pinMode(LEDpin, OUTPUT);
    }

    void loop(){
    digitalWrite(LEDpin, HIGH);
    delay(1000);
    digitalWrite(LEDpin,LOW);
    delay(1000);
    if(LEDpin >= 8){
    LEDpin--;
    } else {
      LEDpin = 8;
      }
    }
Also, when I just typed the `if` statement without the `else` part, nothing happened after the LED at pin 8 had glowed on and off. Can someone please tell me why the LEDs glowed dimly in the second one and why nothing glowed after LED 8 when I skipped the `else` part?

title: Unexpected behaviour of blinking LED code

Answers: 3

body:
The problem with your code is that:

**you have not initialised all the LED pins as output**. Only pin 13 is initialised as output.

So, initialise all the pins to output. A correct code would look like this:

    int LEDpin = 13;
    void setup(){
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    }

    void loop(){
    digitalWrite(LEDpin, HIGH);
    delay(1000);
    digitalWrite(LEDpin,LOW);
    delay(1000);
    if(LEDpin >= 8){
    LEDpin--;
    } else {
      LEDpin = 12;
      }
    }

body:
As Abhishek Jain explained, the pin's need to be initialised for OUTPUT.

However there is another error.

The code in `loop()` counts down to 8, once, flashing the LEDs, **but** then only lights an LED on pin 8 because it always goes through the `else` which maintains LEDpin's value as 8. LEDpin needs to be reset to 12, after it passes 8.

Better code might be

    int LEDpin = 12;
    void setup(){
      pinMode(8, OUTPUT);
      pinMode(9, OUTPUT);
      pinMode(10, OUTPUT);
      pinMode(11, OUTPUT);
      pinMode(12, OUTPUT);
    }

    void loop(){
      digitalWrite(LEDpin, HIGH);
      delay(1000);
      digitalWrite(LEDpin,LOW);
      delay(1000);
      if(LEDpin >= 8){
        LEDpin--;
      } else {
        LEDpin = 12;   // <---- start with the first LED again
      }
    }

For what its worth, I wouldn't do the code this way. I would write something using for loops, like:

    const int firstLED = 8;
    const int lastLED = 12;
    int LEDpin;

    void setup() {
      for (LEDpin = firstLED; LEDpin <= lastLED; ++LEDpin) {
         pinMode(LEDpin, OUTPUT);
      }
    }

    void loop() {
      for (LEDpin = firstLED; LEDpin <= lastLED; ++LEDpin) {
        digitalWrite(LEDpin, HIGH);
        delay(1000);
        digitalWrite(LEDpin,LOW);
        delay(1000);
      }
    }

body:
As Abhishek mentioned in his answer is correct, but the better way is to use for loops while dealing with many led's.

Let's say you have led's connected from pin 2 to 8.

    int pin = 2;
    void setup()
    {
       for (Pin = 2; Pin < 8; Pin++)
       {
         pinMode(Pin, OUTPUT);
       }
    }
    void loop()
    {
       for (int Pin = 2; Pin < 8; Pin++)
       {
         digitalWrite(Pin, HIGH);
         delay(1000);
         digitalWrite(Pin, LOW);
         delay(1000);
        }
    }


body:
In the following code from an Arduino sketch will it run the first "for" statement before enacting the second "for" statement. Also how does it know go run the first stamens again? Will it continue to run till both statements are true?

    for(int r = 0; r < 8; r++){
        for(int c = 0; c < 8; c++){
            lc.setLed(0, r, c, HIGH);
        }
    }

title: How do nested for loops work?

Answers: 2

body:
What you have there is a nested loop. The first `for` statement runs 8 times, incrementing `r` from 0 to 7. For *each* of those 8 iterations the second `for` statement runs, incrementing `c` from 0 to 7. Thus the `setLed` statement is executed 64 times.

> Will it continue to run till both statements are true?

Yes. Unless you have a `break` or `return` statement somewhere in the part of the code you haven't shown.

Strictly-speaking, a *statement* does not become true. They will run while the test inside the `for` remains true (both tests).

This is standard C++ or C programming. You may wish to consult a C tutorial if you find this sort of thing puzzling.

body:
A `for` statement repeats everything between `{` and `}`, (or just the next line if there is no `{` and `}` a certain number of times.  It's not as simple as you might at first think, but it makes more sense if you write it out as a `while` loop explicitly.

For instance, `for (a; b; c) { ... }` could be re-written as:

    a;
    while (b) {
        c;
    }

So if you had:

    for (int i = 0; i < 100; i++) {
        Serial.println(i);
    }

it could be re-written as:

    int i = 0;
    while (i < 100) {
        Serial.println(i);
        i++;
    }

The two mean exactly the same thing.  A `for` has the three elements - initializer, comparison and iterator.  The initializer is run before the loop starts, the comparison is used to work out when the loop should finish, and the iterator is used to move through each iteration of the loop.

To re-write your specific example:

    for(int r = 0; r < 8; r++){
        for(int c = 0; c < 8; c++){
            lc.setLed(0, r, c, HIGH);
        }
    }

You would end up with:

    int r = 0;
    while (r < 8) {
        int c = 0;
        while (c < 8) {
            lc.setLed(0, r, c, HIGH);
            c++;
        }
        r++;
    }

Now, if we were to do away with the loops altogether and write it all out longhand, what would it look like?  Well, let's start with the inner `c` loop.  That loops from 0 to 7 (while less than 8), so replacing that loop with 8 discrete calls to the function replacing `c` each time would end up with:

    int r = 0;
    while (r < 8) {
        lc.setLed(0, r, 0, HIGH);
        lc.setLed(0, r, 1, HIGH);
        lc.setLed(0, r, 2, HIGH);
        lc.setLed(0, r, 3, HIGH);
        lc.setLed(0, r, 4, HIGH);
        lc.setLed(0, r, 5, HIGH);
        lc.setLed(0, r, 6, HIGH);
        lc.setLed(0, r, 7, HIGH);
        r++;
    }

We could take it a step further and *unroll* the outer `r` loop.  A subset of what you would end up with would be like this (note, I have skipped a lot of the middle ones):

    lc.setLed(0, 0, 0, HIGH);
    lc.setLed(0, 0, 1, HIGH);
    lc.setLed(0, 0, 2, HIGH);
    lc.setLed(0, 0, 3, HIGH);
    lc.setLed(0, 0, 4, HIGH);
    lc.setLed(0, 0, 5, HIGH);
    lc.setLed(0, 0, 6, HIGH);
    lc.setLed(0, 0, 7, HIGH);
    lc.setLed(0, 1, 0, HIGH);
    lc.setLed(0, 1, 1, HIGH);
    ... skipped a lot ...
    lc.setLed(0, 6, 6, HIGH);
    lc.setLed(0, 6, 7, HIGH);
    lc.setLed(0, 7, 0, HIGH);
    lc.setLed(0, 7, 1, HIGH);
    lc.setLed(0, 7, 2, HIGH);
    lc.setLed(0, 7, 3, HIGH);
    lc.setLed(0, 7, 4, HIGH);
    lc.setLed(0, 7, 5, HIGH);
    lc.setLed(0, 7, 6, HIGH);
    lc.setLed(0, 7, 7, HIGH);

There would, of course, be 8 × 8 = 64 entries in there.

`for` loops can be used in lots of other fun ways too.  It's not just a simple "run this X number of times".  For instance, you can loop through a C string until you reach the NULL character at the end of the string:

    for (char *p = str; *p != 0; p++) {
        ... do something with *p
    }

You can iterate through the entries in a linked list:

    for (struct mylist *scan = myListHead; scan; scan = scan->next) {
        ... do something to scan->whatever ...
    }

You can even embed functions in there:

    for (char c = 0; c != '\n'; c = Serial.read()) {
        ... Do something with character `c` until `c` is a line feed ...
    }

As you can see `for` is an incredibly powerful and flexible tool that is often overlooked in favour of the more explicit `while`.


body:
Is possible the communication between several Arduinos to one serial port in the PC ?

<!-- language-all: lang-C++ -->

If I have ARD_A, ARD_B,... ARD_Z running with some code like this

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

    void loop()
    {
        while (Serial.available() > 0)
        {
           String stringID = Serial.read()
           int nFound = stringID.indexOf("@ARD_01");
                        // ---> Id is unique for each arduino
           if ( nFound > 0 )
              Serial.print("this is @ARD_01 responding sending some data");
         }
    }

And in the pc there is an exe sending a string:

    "@ARD_01 I want your data"
       process the data
    "@ARD_02 I want your data"
       process the data
    "@ARD_03 I want your data"
       process the data

title: serial communication between several arduinos to pc

Answers: 1

body:
Not directly, no.  A PC's serial port - either a "real" one or a USB one, can only communicate with one device.

The Arduino, though, is a USB device, so you can just plug them all into a USB hub or a bunch of hubs - each one will get its own COM port.  Managing all those COM ports can be kind of tricky though, especially when you have a lot of devices.

Another option, one that is more widely used when you want to communicate with a lot of *slave* devices from one *master* device is to use a *multidrop* network.  RS-485 is the most popular of these.  It allows you to connect many slave devices to one set of serial wires and the master sends instructions to a slave, and the slave may respond with data and information on request.

RS-485 requires special hardware to interface normal TTL level RS-232 (UART) ports to the bus.

You can read more about RS-485 here: https://en.wikipedia.org/wiki/RS-485


body: Is it possible to have the NRF24 module on an Arduino Mini transmitting to an NRF24 with SMA antenna on a Mega?  In that case, would the antenna on the Mega help pickup the signal of the transmitting Arduino Mini?

title: NRF24 Mixing with/without antenna

Answers: 1

body:
Yes, and yes.

A module without an antenna is exactly the same as a module with an antenna, it's just that the antenna is part of the PCB. Yes, the module with the antenna will have more sensitivity (able to receive fainter signals) as well as more transmitting power.

The same is true of the modules with the power amplifier.  They again have even more sensitivity and transmitting power.

It is quite common to have a single powerful transceiver with power amplifier and antenna as a base station and then smaller modules as the remote slave devices.  Especially if you couple the base station with a suitable parabolic or uni-directional high gain antenna to point directly at where the slave devices are.


body:
I've written a script in Python which sends data through the PC's Bluetooth to HC-06 on Arduino.

`state` is an integer from 0 to 1000 (it is controlled through the potentiometer).

<!-- language: c -->

    ...
    gaugeSocket.send(str(state))
    ...

I can't get the right character-to-integer conversion on Arduino (from HC-06 serial).

Arduino code:

<!-- language: c -->

    SoftwareSerial mySerial(10, 11); // RX, TX
    char buf[2];
    int i=0;
    int data;
    int ledPin = 9;

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

    void loop() {
      if (mySerial.available()) {
        for(;i<2;){
          buf = mySerial.read();
          i++;
        }
        i = 0;
        Serial.print(buf);
        data = atoi(buf);
      }
        analogWrite(ledPin, data/10); //To see how code behaves on LED
    }

Serial print gives me this (if I turn potentiometer from 0 to 1000):

> 0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(60(1ÿ(00(16(0ÿ(23(0ÿ(30(0ÿ(3ÿ(60(43(0ÿ(49(0ÿ(53(0ÿ(5ÿ(90(69(0ÿ(88(0ÿ(10(00(10(00(10(

What am I missing? Is it because I'm sending it as a string? Or is my buffer not the correct size?

title: HC-06 data receiving

Answers: 3

body:
Use `itoa` instead of `str`.

`str` just converts the byte to an ASCII character. So `48` will become `'0'`, `195` will become `'ÿ'`, and `191` will become `'('`.

body:
Here is your main problem:

    if (mySerial.available()) {
        for(;i < 2;){
            buf = mySerial.read();
            i++;
        }
    ....

There you are saying "If there is at least one character available in the buffer then read lots of characters from the buffer".

*You can't read characters that aren't there yet.*

So your stream of data is interspersed with the integer `-1` which means "I don't have any data to read!"

I explain it all here: http://hacking.majenko.co.uk/reading-serial-on-the-arduino

By the way - character -1 looks like this: ÿ

You are sending your data as text.  That means, to send the value 348 you are first sending the byte representation of the ASCII character "3", which is the decimal byte value 51.  Then you send the byte representation of the ASCII character "4", which is the decimal value 52, and finally you send the byte representation of the ASCII character "8", which is the decimal value 56.

You look to see if there is one byte available (if(mySerial.available())) and then read that byte into "buf" and increment "i" (by the way, "i" is never reset to 0 - your whole loop strategy is completely wrong, but that's a completely different issue).  You then read a second character and assign that to buf instead.

So if you have the character "3" in the serial buffer you then place that in "buf".  You then read whatever is next in the buffer, which 9 times out of 10 will be nothing, so `read()` returns -1.  So you just assign that to "buf" instead, replacing the "3" that was in there before.

But "buf" is a character array, and you are assigning a character to the whole array, which makes absolutely no sense (does the code even compile as you have shown it?).

Basically your whole reading routine is completely wrong and can never work no matter how much tweaking and advising we do.

The link I provided above describes not only how you should do the reading on the Arduino, but also how you should do the sending from the other end.  It is vitally important that you send something that says "This is the end of the number I am sending" so that the Arduino knows where one number ends and the next starts.  Normally that is done, when sending a textual representation of the number like this, by adding a line feed and/or carriage return at the end of your number.  So instead of sending "348" you send "248\n".

The Arduino then checks to see if there is one character available, and then it adds *just that one* character to the end of the buffer.  If, and only  if, that character is the *delimiting* character then you can take the buffer and translate it into an actual number and reset your buffer to be empty ready to receive the next number.

The link above has good example code showing you exactly how to do that.

body: I think you should check your baud rates. A mismatch in baud rates usually makes that symbol get printed on the screen.


body:
The main idea is to create trigger which can be switched on by touching 2 plates on opposite walls. And these should be performed by few peoples holding each other hands.

Obviously human body has big resistance so I couldn't just connect these plates to ground and to one of Arduino pins.

There is a toy that do almost what I what ([see it there][1]). But I haven't found any information about how to create it by myself.
Do you have any ideas how to create it?

  [1]: http://www.stevespanglerscience.com/energy-stick.html

title: Human circuit trigger

Answers: 3

body:
You can do it with an Arduino !
Use any of the ADC pins
There will be change in the ADC i/p when there is some resistance b/w the pins !
Try both
+ve > (people) > ADC
-ve > (people) > ADC
Just do some trials and probably will notice the change in ADC pin outputs .
If you want to make  it more sensitive
Add a high resistance to the ADC pin
if you are giving +ve to touch plates add a resistance from ground to that ADC pin

body:
The idea is intriguing, but you are not limited to use electricity.
You could experiment with some other type of signal. Sound, for example.
That would be safer.

body:
I just tried it (using my own method), and I got it working with very good sensitivity (should be fine for two people) using a TIP102 Darlington transistor and some resistors. Here is what I did:
[![enter image description here][1]][1]

R1, the 1M pulldown resistor on the first pin of the Darlington is necessary to keep the light off when nobody is touching the wires. Without this, the light will turn on and off frantically.

R2, the 1k resistor keeps the Arduino from draining too much current (since that would be bad for the pin) in the case that your A0 is in OUTPUT mode and set to LOW.

R3 keeps the LED (or in my case, an AC relay connected to an actual light) from draining too much current from the Arduino. Note: The LED leads may be backward (reverse polarity) in the provided diagram.

Here is the code:

    // I release this code under the standard MIT licence;
    // (in addition to whatever StackExchange implies);

    const short triggerThreshold = 10;// Lower is more sensitive;

    void setup() {
      pinMode(A0, INPUT);
      pinMode(A5, OUTPUT);
      digitalWrite(A5, LOW);
      delay(1);
    }

    void loop() {
      short value = analogRead(A0);
      digitalWrite(A5, (value > triggerThreshold) ? HIGH : LOW);
      delayMicroseconds(10000);// 10ms;
    }

Note the `triggerThreshold` setting in the code. If you want more sensitivity, try changing the 10 to a 5. I just tried it, and it becomes *extremely* sensitive, yet it still appears to reliably stay off when I don't touch it. Naturally if you use large plates for touching, electrostatic in the air could set it off, so you may need to change this number to be higher to make it less sensitive, depending on your setup.

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


body:
I'm trying to use the watchdog timer to prevent the atmel from being stuck in a loop.

Right now, I have the watchdog timer in System Reset Mode, with a 8sec timer. I reset the timer in every loop while the system is active. But when it goes to sleep, it cannot clear the timer and the whole system resets. Essentially, the system sleeps > System Reset every 8 sec > goes back to sleep.

While this works, I initialize a lot of other hardware with the atmel, and doing it every 8 second seems like a waste of resources.

I want to use the watchdog interrupt somehow only to wake the system up briefly and stop the full system reset. Only if it's truly stuck, it will do a full system reboot. But i'm not sure how the ISR will work or how to reset the timer or toggle.

Here a basic rundown of what I was thinking about.

    ISR(wdt_timer)
    {
        how to stop the full system reboot?
        how to make the interrupt start again?
    }
    ISR(button_press)
    {
          gotoSleep=0;
    }

    void watchdog_init()
    {
     /* Reset the wdt. */
      wdt_reset(); //from wdt.h

      /* In order to change WDE or the prescaler, we need to
       * set WDCE (This will allow updates for 4 clock cycles).
       */
      WDTCSR |= (1<<WDCE) | (1<<WDE);

      /* set new watchdog timeout prescaler value */
      WDTCSR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */

      /* Enable the WD interrupt (note both interrupt and reset). */
      WDTCSR |= (1<<WDIE) | (1<<WDE);
    }

    void main ()
    {
        watchdog_init();
        //and initialize all the other hardware and power supply

        while (true) //no need to step out of this loop
        {
            reset_watchdog();

            //
            //main program
            //

            if(go_to_sleep=1)  //command received through serial
            gotoSleep();

            //wake up here

        }

    }

title: Atmega168 Watchdog timer

Answers: 1

body:
Each time the watchdog interrupt triggers, WDIE is reset. You will need to set it again in the loop if you want to continue capturing the interrupt rather than resetting the system.

Also, consider using `<avr/wdt.h>` and `<avr/sleep.h>` to handle (most of) the watchdog and sleep functionality.

    EMPTY_INTERRUPT(WDT_vect);

    void main ()
    {
        watchdog_init();
        set_sleep_mode(SLEEP_MODE_STANDBY);
        //and initialize all the other hardware and power supply

        while (true) //no need to step out of this loop
        {
            wdt_reset()

            //
            //main program
            //

            if(go_to_sleep=1)  //command received through serial
            {
                sleep_enable();
                sleep_cpu();
                sleep_disable();
                WDTCSR |= _BV(WDIE);
            }
        }
    }


body:
I am trying to integrate two different Arduino Ethernet libraries, EtherShield and UIPEthernet in one sketch.

EtherShield library is used to control LEDs via Android mobile application. While UIPEthernet is used to control the same LEDs via Web Server.

Both codes run perfectly when they're uploaded individually. But I need them to run in a single sketch. So I combined them in one sketch. That's where my problem is. They're not running smoothly anymore. My mobile app can only turn one LED off then the app will crash. Accessing my Arduino's web server gives me error as well (but before it is really, really working T.T)

Help me, please.
This is my code

    // ========== UIPEthernet library
    #include <Dhcp.h>
    #include <Dns.h>
    #include <ethernet_comp.h>
    #include <UIPClient.h>
    #include <UIPEthernet.h>
    #include <UIPServer.h>
    #include <UIPUdp.h>

    // ========== EtherShield library
    #include "EtherShield.h"
    #include "ETHER_28J60.h"

    // ========== MOBILE
    //static uint8_t mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
    //static uint8_t ip[4] = {192, 168, 15, 97};
    static uint16_t port = 80;

    ETHER_28J60 e;

    // ========== WEB
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    byte ip[] = { 192, 168, 15, 97 };
    byte gateway[] = { 192, 168, 15, 1 };
    byte subnet[] = { 255, 255, 255, 0 };

    String inString = String(35);

    int i;  // Used for looping
    String Room;

    int pin[] = { 0, 2, 3, 4, 5 }; // Lock pin num 0 in array is not used
    int numOfRooms = 4; // Number of rooms
    String value[] = { "OPEN", "OPEN", "OPEN", "OPEN", "OPEN" }; // Startup all rooms are closed

    EthernetServer server(port);
    String data;

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

      // ========== MOBILE
      e.setup(mac, ip, port);

      // ========== WEB
      Ethernet.begin(mac, ip, gateway, subnet);
      server.begin();

      // Set pin mode
      for (int j = 1; j < (numOfRooms + 1); j++)
      {
        pinMode(pin[j], OUTPUT);
      }

      Serial.println("\n[ WEB + MOBILE ]\n");
      Serial.println("Serial READY");
      Serial.println("Ethernet READY");
      Serial.println("Server READY\n");
    }

    void loop()
    {
      webModule();
      mobileAppModule();
    }

    void mobileAppModule()
    {
    char* params;
    if (params = e.serviceRequest())
    {

      //ROOM 311
      if (strcmp(params, "?cmd=1") == 0)
      {
            digitalWrite(pin[1], HIGH);
            Serial.println("ROOM311 is OPEN\n");
      }
      if (strcmp(params, "?cmd=2") == 0)
      {
            digitalWrite(pin[1], LOW);
            Serial.println("ROOM311 is CLOSE\n");
      }

      //ROOM 312
      if (strcmp(params, "?cmd=3") == 0)
      {
            digitalWrite(pin[2], HIGH);
            Serial.println("ROOM312 is OPEN\n");
      }
      if (strcmp(params, "?cmd=4") == 0)
      {
            digitalWrite(pin[2], LOW);
            Serial.println("ROOM312 is CLOSE\n");
      }

      //ROOM 313
      if (strcmp(params, "?cmd=5") == 0)
      {
            digitalWrite(pin[3], HIGH);
            Serial.println("ROOM313 is OPEN\n");
      }
      if (strcmp(params, "?cmd=6") == 0)
      {
            digitalWrite(pin[3], LOW);
            Serial.println("ROOM313 is CLOSE\n");
      }

      //ROOM 314
      if (strcmp(params, "?cmd=7") == 0)
      {
            digitalWrite(pin[4], HIGH);
            Serial.println("ROOM314 is OPEN\n");
      }
      if (strcmp(params, "?cmd=8") == 0)
      {
            digitalWrite(pin[4], LOW);
            Serial.println("ROOM314 is CLOSE\n");
      }

      //
      if (strcmp(params, "?cmd=9") == 0)
      {
            digitalWrite(pin[1], LOW);
            digitalWrite(pin[2], LOW);
            digitalWrite(pin[3], LOW);
            digitalWrite(pin[4], LOW);
            Serial.println("All rooms are now CLOSED\n");
      }

      e.respond();
      }
    }

    void webModule()
    {
         EthernetClient client = server.available();

     if (client)
     {
     // An HTTP request ends with a blank line
     boolean current_line_is_blank = true;

     while (client.connected())
     {
      if (client.available())
      {
        char c = client.read();
        // If users have gotten to the end of the line (received a newline
        // character) and the line is blank, the HTTP request has ended,
        // so users can send a reply

        if (inString.length() < 35)
        {
          inString.concat(c);
        }

        if (c == '\n' && current_line_is_blank)
        {

          // Send a standard HTTP response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.println("");

          client.println("<title>CONTROL PANEL</title>");

          client.println("");

          client.println("
POLYTECHNIC UNIVERSITY OF THE PHILIPPINES
COLLEGE OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
COMPUTER ENGINEERING LABORATORY
");
          client.println("

");
          client.println("

");
          client.println("
");
          client.println("

CONTROL PANEL

");

          client.println("<form method=get>");

          for (i = 1; i < (numOfRooms + 1) ; i++)
          {
            Room = String("ROOM") + (i + 310);

            if (inString.indexOf(Room + "=OPEN") > 0 || inString.indexOf("All=OPEN") > 0)
            {
              Serial.println("\n" + Room + " is OPEN");
              digitalWrite(pin[i], HIGH);
              value[i] = "CLOSE";
            }
            else if (inString.indexOf(Room + "=CLOSE") > 0 || inString.indexOf("All=CLOSE") > 0)
            {
              Serial.println("\n" + Room + " is CLOSE");
              digitalWrite(pin[i], LOW);
              value[i] = "OPEN";
            }

            client.println("
" + Room + "     <input type='submit' name=" + Room + " value=" + value[i] + " style='height: 50px; width:100px;' />

");
          }

          client.println("

All <input type='submit' name='All' value='OPEN' style='height: 50px; width:100px;' />    <input type='submit' name='All' value='CLOSE' style='height: 50px; width:100px;' />");
          client.println("</form>");

          for (i = 1; i < (numOfRooms + 1); i++)
          {
            if (value[i] == "ON")
            {
              i = i + 310;
              client.println("

Room " + String(i + 310) + " is OPEN
");
            }
            else if (value[i] == "OFF")
            {
              client.println("

Room " + String(i + 310) + " is CLOSE");
            }
          }
          client.println("
");
          client.println("
");
          client.println("");
          break;
        }

        if (c == '\n')
        {
          // we're starting a new line
          current_line_is_blank = true;
        }
        else if (c != '\r')
        {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    }

        // give the web browser time to receive the data
        delay(1);
        inString = "";
        client.stop();
        }
    }

MOBILE means code for Arduino-Android
WEB means the code for Web Server

title: Integrating two Arduino Ethernet libraries in one sketch

Answers: 1

body:
You can't.

 1. The code has both libraries trying to run on the same port which is not allowed (in fact you couldn't even do that on a computer). You could try setting one to one port and the other to another port, but that might not work because...
 2. These libraries most likely are both expecting to be the only code accessing the hardware and they will step over each other and cause problems. Sharing hardware between different pieces of code is an advanced programming topic not suited for beginners and would involve rewriting significant portions of these libraries.

The best course of action is to either re-implement your app functionality to use the UIPEthernet Library, or re-implement the webpage using the EtherShield library. You should be able to do this because your app interface is supplying parameters (e.g the "?cmd=" part) and the webpage is not. You should be able to set it up so that if it has "?cmd=" in the request, it should perform the command, otherwise it should return the webpage.


body:
I posted a couple weeks ago about having a GSM error. I moved past it and the code seemed to be working on my GSM module (I think a SIMCOM). But then I needed to create some more systems and out of a total of 8 GSM modules, my code and setup only work on two of them - despite the fact that they should be identical and from the same supplier.

The following code (thanks to [this genius post][1]) works without error to send and receive SMS on two of the boards:

    #include <SoftwareSerial.h>
    char inchar; // Will hold the incoming character from the GSM shield
    SoftwareSerial SIM900 = SoftwareSerial(2,3);

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

    void initializeGSM() {
      SIM900.begin(19200);
      Serial.println("Turned on");
      SIM900.print("ATEO\r");
      Response();
      SIM900.print("AT\r");
      delay(1000);
      Response();
      SIM900.println("AT+CMGF=1\r");  // set SMS mode to text
      Response();
      delay(1000);
      SIM900.println("AT+CNMI=1,2,0,0,0\r");
      delay(100);
      Response();
      delay(5000);  // give time to log on to network.
      Serial.println("Ready...");
    }

    void Response() {
      int count = 0;
      delay(1000);
      Serial.println(SIM900.available());
      while(1) {
        if(SIM900.available()) {
          char data =SIM900.read();
          if(data == 'K'){Serial.println("OK");break;}
          if(data == 'R'){Serial.println("GSM Not Working");break;}
        }
        count++;
        if(count == 100){Serial.println("GSM not Found");break;}
      }
    }

    void loop() {
      RecSMS();
      delay(2000);
    }

    void RecSMS(){...}

So again, the above code works to set up the module on 2 modules. On the other 6, it simply hangs during the `Response()` call. `SIM900.available()` returns 0 and then says "GSM Not Found." So I tried to initialize the TX pin during setup as:

    digitalWrite(2, LOW);

Which then gives me a promising `SIM900.available()` value of about 63, which corresponds to what a confirmation would be. However, when I print the "data" variable containing the byte read off the GSM module/SIM card, I get a couple bits of garbage like the following output:

[![Garbage output from printing the data char during the Response function][2]][2]

Has anyone experienced this problem and knows a way to properly initialize the GSM module?

  [1]: http://www.theengineeringprojects.com/2015/02/receive-sms-commands-using-sim900-arduino.html
  [2]: https://i.stack.imgur.com/iWlsl.png

title: Why are some of my GSM modules not taking commands?

Answers: 1

body:
I am owner of this blog whose link you shared, so first of all, I am felling happy that you got something out of it. Now secondly, this code you got from my post is incomplete.

You need to buy that one in order to get the complete code. The code I designed is using AT commands but the above code which you have mixed with your own code is using the Arduino library that's why it's not giving the correct results.

So, either use the complete code from my website or use the Arduino library code only because it has the commands for checking the response, you don't need to use my code to get the response.


body:
I have been struggling with a LCD for 6 hours straight - I've had many problems including random characters showing up, and this time (not quite sure what changed, I tried so many things) as soon as I instantiate a LiquidCrystal object the Arduino stops sending on the Serial port. On the following code, commenting the instantiation of lcd makes "Starting" and "Printing" appear in the serial terminal - otherwise nothing is displayed. Either way, the LCD is desperately blank (black spaces on the entire first line, and I tuned the contrast when random characters were displayed).
<!-- language-all: lang-cpp -->

    // include the library code:
    #include <LiquidCrystal.h>

    // initialize the library with the numbers of the interface pins
    //RS EN D4 D5 D6 D7
    //LiquidCrystal lcd(2, 3, 4, 5, 9, A5);
    //RW to GND, VSS to GND, VCC to 5V, V0 to wiper of 5V-to-GND 10k potentiometer

    void setup() {
      Serial.begin(9600);
      Serial.println("Starting");
      //lcd.begin(16, 2);
    }

    void loop() {
      //lcd.setCursor(0, 1);
      //lcd.print(millis() / 1000);
      Serial.println("Printing");
    }

I'm using this [Arduino Pro Mini][1], and this [LCD][2]. Note that on the Arduino, pins 10 11 12 and 13 are used for a SD (which works), and 6 7 8 are used for a RS232 driver (which is disabled).

Honestly I'm sending a message in a bottle, I'm out of ideas...

The wiring is as explained in the code, I checked it 5 times and it is matching. There is a 10k pot on GND-VO-5V of the LCD, and I haven't wired the backlight.

**Edit1:** With the LCD active (all lines uncommented) I probed all LCD pins with a 'scope and when it is triggered in Normal, I can see that they all have a pulse every time the LCD is updated (I added a delay in the loop to make it more obvious). HOWEVER pins 9 and A5 take much longer than the others to get back to a high state, around 3 microseconds. Why? It might explain why the LCD doesn't work, but I don't see how it can explain the apparent freeze.

**Edit2:** Okay, I desoldered pins 9 and A5 and placed the wires on pins A2 A3 instead. The square waves are all square now, and the Serial works - no idea why. And back to square 1, as the LCD prints random characters now...

  [1]: http://hobbycomponents.com/boards/140-arduino-compatible-5v-pro-mini-?search_query=pro mini&results=53
  [2]: http://uk.farnell.com/midas/mc21605h6w-sptly/lcd-2x16-stn-led-b-l-blk-on-y/dp/2342641

title: Serial does not work when LiquidCrystal library is used

Answers: 0


body:
I am trying to pass the input from one pin to another pin as output. Effectively I want to create a blind passthrough. The end goal is to connect two Arduinos and a series of test points together like the diagram below. I want Arduino B to shuffle which test points are connected to which pins on Arduino A on startup.

    +-----------+       +-----------+     +-------------+
    |           |       |           |     |             |
    | Arduino A <-------> Arduino B <-----> Test Points |
    |           |       |           |     |             |
    +-----------+       +-----------+     +-------------+

I figure one way to do this is to poll the input pins in the loop() and then change the output pins accordingly but I would prefer if the voltage changes just passed right through without it affecting timing.

**Update:**
For some clarification:

 - All signaling is digital
 - I'm looking to "route" around 10-12 test points to Arduino A ideally but 6 at a minimum

title: Passing the input from one pin to another as output without polling?

Answers: 4

body: No Arduino is capable of doing this. You need to be looking at a crossbar/crosspoint/matrix switch IC instead.

body:
You could use an analog multiplexer such as the 74HC4051 (8 channels) or the 74HC4067 (16 channels) like this:

[![74HC4051 multiplexer][1]][1]

Arduino B could alter the multiplex selector (A/B/C) pins to route the signal from the test points to a specific pin on Arduino A. If you are wanting to see the result of the signal on a different pin then a second multiplexer would be required (ie. one to send data to a pin, the second to see the result on a different pin).

I have a post about the [74HC4051 multiplexer / demultiplexer](http://www.gammon.com.au/forum/?id=11976) which gives more details about using it.

When I tested it I found only about a 5 ns delay in timing:

[![Multiplexer timing][2]][2]

Ignacio's answer about a crossbar switch sounds like a more elaborate form of multiplexer. Personally I haven't used one of them.

  [1]: https://i.stack.imgur.com/FmwtJ.png
  [2]: https://i.stack.imgur.com/CShlX.png

body:
You can reduce latency by using interrupts to detect input changes instead of polling in loop(), if you're dead set on using an Arduino instead of adding switching hardware (as suggested in other answers).

See [attachInterrupt()](http://www.arduino.cc/en/Reference/AttachInterrupt) for details, and beware that different Arduino models differ greatly in how many pins support interrupts.

Alternately, you can speed up the polling approach by using [direct port access](http://www.arduino.cc/en/Reference/PortManipulation) (e.g., PORTB and PORTD registers) instead of the simpler Arduino read and write functions.  This will bypass some wrapper code and also let you manipulate multiple pins in parallel.

body: Because this is digital I would like to add a third option in addition to Ignacio's and Nick's great suggestions. Use a logic device such as an FPGA or CPLD. This will require some extra knowledge and set up to get it working, but it is well suited for the functionality you are looking for.


body:
I've been struggling with my LCD for hours, and after solving more different issues than I can remember, I'm out of ideas for this one.

My LCD is showing random characters, see the picture below (the last character blinks, some characters change and over time there are slowly more and more characters). I'm starting to wonder if the LCD I chose has a driver compatible with the LiquidCrystal library, what do you think? If so what can I do to avoid buying another one?

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

Here is the code:

<!-- language: c -->

    // include the library code:
    #include <LiquidCrystal.h>

    // initialize the library with the numbers of the interface pins
    //RS EN D4 D5 D6 D7
    LiquidCrystal lcd(2, 3, 4, 5, A2, A3);
    //RW to GND, VSS to GND, VCC to 5V, V0 to wiper of 5V-to-GND 10k potentiometer

    void setup() {
      Serial.begin(9600);
      Serial.println("Starting");
      lcd.begin(16, 2);
    }

    void loop() {
      lcd.setCursor(0, 1);
      lcd.print(millis() / 1000);
      Serial.println("Printing");
      delay(1000);
    }

I'm using this [Arduino][2] and this [LCD][3]. Note that I'm using pins 10,11,12,13 for a SD (which works) and 6 7 8 for a MAX232 (which is disabled).

Any ideas?

  [1]: https://i.stack.imgur.com/DYED4.jpg
  [2]: http://hobbycomponents.com/boards/140-arduino-compatible-5v-pro-mini-?search_query=pro mini&results=53
  [3]: http://uk.farnell.com/midas/mc21605h6w-sptly/lcd-2x16-stn-led-b-l-blk-on-y/dp/2342641

title: Why does my LCD display random characters?

Answers: 1

body:
It could be because "millis()/1000" generates a "number", and not the "string" (or "char"). Try to add ",DEC" in your lcd.print(), something like "millis()/1000,DEC" to convert it to "decimal". Generally, it depends on the library, how they implement this function.

Good luck,

Mike