body:
I have this TFT:

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

Now, the problem is, I will not use this as a shield (i.e. I will not just put it on top of an Arduino Uno). I will use it with an ESP8266 (NodeMCU). I want to know how to wire them up together. There is [this website][2] (and a few more that say the same way). But the problem is I cannot find `SDI/MOSI` or `SDD/MISO` on the TFT above.

  [1]: https://i.stack.imgur.com/9Dxot.jpg
  [2]: http://www.nihamkin.com/2016/03/04/connecting-esp8266-with-ili9341-tft-display/

title: mcufriend 2.4 TFT with ESP8266

Answers: 2

body:
You have an 8-bit parallel interface TFT display. It requires 13 GPIO pins - D0-D7 plus reset, chip select, read, write and register select. You can forego the "read" signal and tie it high to save a pin. You can probably do the same with the reset signal, meaning you need a minimum of 11 pins.

I am not sure the NodeMCU has that many available, does it? (maybe it does, I don't have one to hand right now), so you may want to try getting it going with an SPI or I2C IO expander (though slowly).

And then of course you have to find the right library for the chip on the display (there's a few it could be - I have seen at least 3 different ones on the same, or similar, carrier PCB) that works with the NodeMCU.

body: SD_DI is the MOSI, and SD_DO is the MISO. According to the datasheet.


body:
I'm working on a project where I use two microcontrollers: an AtTiny44 (20MHz ext clock) and an AtTiny85 (8MHz internal).

What I'm trying to achieve is an I2C communication between the 85 and the 44, with the 44 acting as master and the 85 as slave, then transmit the data read from both of them to a PC with FDTI cable using softwareSerial.

I started with writing the AtTiny85 code:

       #include <TinyWireS.h>
       #define ADC3 A3

       void setup() {
          TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network
          TinyWireS.onRequest(requestEvent);
          pinMode(4,OUTPUT);
          digitalWrite(4,HIGH);
          pinMode(ADC3,INPUT_PULLUP);
       }

       void loop() {
          // This needs to be here
          TinyWireS_stop_check();
       }

       // Gets called when the ATtiny receives an i2c request
       void requestEvent() {
         int val=analogRead(ADC3);
         byte valLow = val & 0xff;
         byte valHigh = (val >> 8);
         TinyWireS.send(valHigh);
         TinyWireS.send(valLow);
       }

With this I am able to send the data read from an adc (A3 pin) to an Arduino as 2 bytes

The Arduino code:

      #include <Wire.h>

      int check=0;

      void setup() {
         Wire.begin();        // join i2c bus (address optional for master)
         Serial.begin(9600);  // start serial for output
      }

      void loop() {
          Wire.requestFrom(8, 2);    // request 2 bytes from slave device #8

          while (Wire.available()&&check<2) { // slave may send less than
                                              // requested
            int c = Wire.read(); // receive a byte as int
            check++;
            int d = Wire.read();
            check++;
            int number = d | c << 8; //convert two bytes as int
            Serial.println(number);
         }
         check=0;
         delay(500);
       }

Maybe the `check` variable is useless, but it's not a problem, because I'm getting the right reading on serial monitor.

I then moved to the AtTiny44; I have an onboard thermistor, and I need to print on softwareSerial the value read from this and the value read from the AtTiny85 board.

This is the code, using TinyWireM:

      #include <TinyWireM.h>
      #include <USI_TWI_Master.h>
      #include <SoftwareSerial.h>

      SoftwareSerial mySerial(0, 1); // RX, TX

      int adc = 2;
      int check=0;

      void setup() {
        pinMode(1, OUTPUT);
        pinMode(0, INPUT);
        pinMode(4,INPUT_PULLUP);
        pinMode(6,INPUT_PULLUP);
        pinMode(7, OUTPUT);
        pinMode(adc, INPUT);
        mySerial.begin(9600);
        TinyWireM.begin();        // join i2c bus (address optional for master)
        while (!mySerial) {
          ;
        }
        mySerial.println("Serial comm started");
        digitalWrite(7, HIGH);
        delay(1000);
        digitalWrite(7, LOW);
     }

     void loop() {
       mySerial.println((int)analogRead(adc));
       TinyWireM.requestFrom(8, 2);    // request 2 bytes from slave device #8
       while (TinyWireM.available()&&check<2) { // slave may send less than
                                                // requested
       digitalWrite(7, HIGH);
       int c = TinyWireM.receive(); // receive a byte as character
       check++;
       int d = TinyWireM.receive();
       check++;
       int number = d | c << 8;
       mySerial.println(number);
       }
     check=0;
     delay(500);
     }

The softwareSerial is working good (I get to write the ADC data from the 44) but I can't find where the problem on I2C is (on console monitor `mySerial.println(number)` sends out 0).

What I excluded so far: connections error, clock skew (the clocks are distant between them), pull-up on I2c bus (they are high in both devices)

title: AtTiny44 and AtTiny 85 communication

Answers: 1

body:
> the 85 as slave

writing a slave, especially an i2c slave, isn't for the faint of heart. typically you use a state machine to help handle that.

one great example is the one presented by nxp in old LPC210x datasheet. AVRs share the same i2c hardware so it is immensely portable to the avr.


body:
I want to make a very small 7-hour timer circuit that can turn on a relay after 7 hours. I am trying to make the first prototype with an Arduino Nano but I can't understand how to program it for such purpose. So please help me out.

Once I make a prototype in Arduino then I was thinking to make a small one  using an ATtiny13. Can I use an ATtiny13 for such purpose?

title: Making a 7-hour timer-based relay

Answers: 2

body:
> cant understand how to program it for such purpose so please help me out

it is fairly easy to approach such questions:

1) you can program any?

2) can you program this mcu to blink an led?

3) can you program this mcu to do short time counting?

4) can you program this mcu to do long time counting?

what you help helps you the most depends on your  answers to those questions.

body:
The question is whether its a one shot triggering ON the relay after 7 hours and thereafter you always leave it ON or its some periodic process where every 7 hours, you want the relay to trigger ON and OFF alternatively. Presuming the latter, this can be done in 2 ways:

1) Configure a hardware timer interrupt to call a small function every second and increment a variable within that function. So after 1 hour your variables value must be 3600, therefore after 7 hours it will be 25,200. Once the variable is equal to 25200, you can ON the relay and reset the variable to 0. Factors such as the number of hardware timers and its resolution differs from one MCU to another.

2) Use a Real Time Clock like the DS1307 for this purpose and save you hardware timers for performing some other time critical operations.

Hope this helps!.


body:
I am new to Arduino and trying to do some basic tasks. I want a micro servo to rotate but it's not working, only slightly virbating when I launch a sketch. Below on the photos is how it is all assembled: I have a jumpwires connected to GND, 5V and #8 ports just as in the tutorial. I use micro servo SG-90 and Funduino UNO. Does anybody have any ideas what might the problem be? Here is also the sketch.

    #include <Servo.h>

    Servo servo;

    void setup() {
      // put your setup code here, to run once:
    servo.attach(8);
    }

    void loop() {
       // put your main code here, to run repeatedly:
    servo.write(0);
    delay(2000);
    servo.write(90);
    delay(2000);
    }

[![enter image description here][1]][1]
  [1]: https://i.stack.imgur.com/WygeG.jpg

title: Micro servo is not working with Arduino UNO

Answers: 1

body:
You should not power a servo from a USB port.

However, your most glaring problem is that you have entirely mis-wired the connections, such that no wire is going to the correct place.

Servo connections are in the order of `Ground` - `Power` - `Signal`, usually with a dark color for ground and a redder one for power.  Connector shells aren't standardized between brands, but within one there may be keying to prevent reverse installation.

It would appear that on your servo, `ground` is brown, `power` red, and `signal` orange.

Pull out all three wires and start over; also you'd do well to use a dark color for the ground, as you appear to have mixed up the power and ground as well as the signal.


body:
I am trying to write a function that takes integer values as an input and gives an array as an output. I have tried the following code but it doesn't show the output result in the serial monitor:

    int *phi (int cur,int vol,int t) {
      int z[4];
      z[0]=1;
      z[1]=cur;
      z[2]=vol;
      z[3]=t;
    //z=cur+vol+t;
      return z;
    }

    void setup() {
      // put your setup code here, to run once:

    }

    void loop() {

    int result;
    result=phi(1,2,5);
    Serial.begin(9600);
    Serial.print(result);

    }

title: How can I define integer inputs to a function and get array as an output?

Answers: 2

body:
It appears you have created an array which only has scope with in the method "phi".

In practical terms, the array "z" is a local variable declared inside of the method and, as such, will likely end up in temporary RAM.  When the method has completed, the RAM reserved for that method's local variables is released and is available for other purposes.

To fix this you could make "z" a static or you could give "z" global scope.

body:
Defining the array in phi() returns a pointer to unassigned memory - it is no longer reserved once phi() returns. The next function call or interrupt (which you have no control over) will likely clobber the data.

A better choice would be to define `z` in the caller (loop() in this case) as an uninitialized array and pass it to phi() to fill and return. This is the more usual case, as it:

 - avoids using globals,
 - permits multiple calls to the function without clobbering previously returned data (you would pass different arrays in this case), and
 - it avoids statically defined arrays that may not be needed after the caller returns, in a memory-starved environment (this may not be applicable if loop() is the caller).

In short, it gives the calling function the greatest flexibility, while committing the least amount of memory.


body:
I need to measure (and record changes over a short time) the angle of a lever at a sub-degree resolution (The fulcrum can be the sensor) using an Arduino.

I've looked at rotary encoders, but even those with no detents have about 24 pulses per rotation. I need to measure only across a 90 degree arc. 24 pulses per rotation is 15 degrees per pulse. Which I guess results in a measurable resolution of 7.5 degrees!

I could add gears to increase the turns on the encoder, but that would increase the force required to move the lever.

Is there an option I'm not thinking of?

title: How do I read a sub-degree angle?

Answers: 3

body:
> Is there an option I'm not thinking of?

a ruler would be the simplest solution.

a capacitive pad could sense it as well.

a lever + a linear encoder.

...

body:
>I've looked at rotary encoders, but even those with no detents have about 24 pulses per rotation.

It sounds like you have been looking at encoders intended for user input controls.

**Optical Rotary Encoders** for machinery applications are readily available with up to several thousand pulses per revolution.  Prices vary depending on if the wheel is glass or plastic, mounting options, brand, etc.

Do be aware that especially at the high resolutions, getting the encoder disk mounted perfectly concentric to the shaft being measured in important.  You would either need to buy a a wheel which already has a bushing of the same diameter as your shaft, have access to a lathe, or have something custom made.  (This is probably a case where a 3d printer is not accurate enough)

Also keep in mind that encoder wheels are often specified in cycles per revolution; with the typical two channel read head and quadrature decoding, there will be four times as many distinct state transitions.  So a mere 300 CPR wheel would give you 1200 counts per revolution.

body:
Try a spirit level (also called bubble level) app on your phone or tablet. It can get to sub-degree accuracy, but it is relative and not absolute accuracy. If that is good enough for you, then you could buy a modern accurate **accelerometer** and average the values.
It might even be possible to have more than one accelerometer for more accuracy.

Good quality (calibrated) digital spirit levels are very accurate. They use a accelerometer.

It will measure the angle with the earth gravity, and it is sensitive for vibrations.

There are more ways to measure the angle, but it depends on the mechanical construction of the lever. For example a **IR distance sensor** for short distances at the end of the lever. Maybe a magnet and **hall sensor**. There are probably more ways to measure the angle.


body:
I'm trying to wire up a silly little keyboard using hall effect sensors and magnets in a glove. The idea being only I can use the keyboard since I'll have the glove.

 The sensors are 3 pin, (vcc, gnd, and an output that sends 5v out when a magnetic field is present. I don't have anywhere near enough pins on the teensy for all the sensors. Could I just use several port expanders? Are there issues with using 4 or 5 at once? How many keys could be pressed at a time?

Is there a better option than all those expanders?

 Also I know that this keyboard will be ugly and completely impractible to use regularly, but I thought it would fun to show off.

title: 65 hall effect sensors as switches to be used as a keyboard with a teensy

Answers: 1

body:
[**Completely rewritten answer**]
That seems fun. But why 65 keys ? with 64 keys it is easier.

You have to test the sensitivity of the hall switches with the magnets to know how far apart the keys must be. Perhaps they only work with strong magnets or perhaps a number of them are activated when the glove is near.

With hall switches, there are 65 digital signals from the sensors.
The most common way to create more digital inputs is to use shift registers. For example with the [74HC165][2]. Nick Gammon has the best [tutorial of the 74HC165 with daisy-chain][3].
There is also an example is with the [CD4021][4] and the [ShiftIn][5] function, but the 74HC165 is mostly used.
The shift registers can be daisy-chained, they are made for that.

Your AH1807 has a open-drain output. That means you need 65 pullup resistors.
It is not possible to connect all the outputs and turn them on one by one, since it requires 150ms to wake up.

Another option is using multiplexers. It can be used for analog and for digital signals. For example with four 16-to-1 multiplexers you can create 64 inputs going to 4 pins. The best [multiplexer tutorial][6] is once again written by Nick Gammon.

With four analog multiplexers of 16-to-1 you would require only 4 pullup resistors after the multiplexer. I think it is better to use a resistor per hall sensor (65 pullup resistors).

When using reed switches (those tiny glass tubes, used in house alarms), they can be set in a matrix/grid with rows and columns and the [Keypad library][1]. For example 10*7 requires 17 pins. The Keypad library allows that multiple keys are pressed at the same time.

  [1]: https://playground.arduino.cc/Code/Keypad
  [2]: https://playground.arduino.cc/Code/ShiftRegSN74HC165N
  [3]: https://www.gammon.com.au/forum/?id=11979
  [4]: https://www.arduino.cc/en/Tutorial/ShiftIn
  [5]: https://www.arduino.cc/en/Reference/ShiftIn
  [6]: https://www.gammon.com.au/forum/?id=11976


body:
I want to control a relay by reading values from MySQL. I'm using an Arduino and an Ethernet shield. So far, I can get the response from server and get the value. I just need the value `10110110`, but I get a response in the serial monitor like this:

<!-- language: none -->

    HTTP/1.1 200 OK
    Date: Sun, 02 Jul 2017 07:53:29 GMT
    Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
    X-Powered-By: PHP/5.3.1
    Content-Length: 13
    Content-Type: text/html

    <10110110>

How to remove this long response and get the value `10110110`?

title: How to read response from server using an Ethernet shield?

Answers: 1

body:
There are, obviously, a great number of ways that this can be achieved. The simple brute force way would be to have a series of `if` statements, looking for a sequence of eight consecutive `0`s and/or `1`s, and loop through the string containing the response.

Or you could loop through the response, using `strcmp()`, similar to what is described here: [how to do like a grep in a sketch?][1]

However, a more intelligent method would be to use pattern matching and regular expressions.

From [New regular expression library released][2], Nick has provided a Regexp library. It uses Lua for the expression syntax, see [string.find] [3], for more details.

I am still playing with this code, but your sketch would need something like this:

    #include <Regexp.h>
    void setup ()
    {
      Serial.begin (115200);
      Serial.println ();

      unsigned int index = 0;
      char buf [100];

      MatchState ms;
      ms.Target ("HTTP/1.1 200 OK\
    Date: Sun, 02 Jul 2017 07:53:29 GMT\
    Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1\
    X-Powered-By: PHP/5.3.1\
    Content-Length: 13\
    Content-Type: text/html\
    \
    \
    <10110110>");  // what to search

      while (true){
        char result = ms.Match ("^<([01][01][01][01][01][01][01][01])", 0);  // look for an eight bit binary digit
        if (result == REGEXP_MATCHED)
        {
          Serial.println ("-----");
          Serial.print ("Matched on: ");
          Serial.println (ms.GetMatch (buf));
          Serial.println ("Captures:");
          for (int j = 0; j < ms.level; j++)
             Serial.println (ms.GetCapture (buf, j));
          // move past matching string
          index = ms.MatchStart + ms.MatchLength;
        }  // end of match
        else
          break;  // no match or regexp error

      } // end of while

    }  // end of setup

    void loop () {}

This code assumes that you are looking for a line beginning with `<` and captures an eight digit binary thereafter - as determined by the expression within the inner `()`, in the line:

        char result = ms.Match ("^<([01][01][01][01][01][01][01][01])", 0);  // look for an eight bit binary digit

 So, it *should* output:

    -----
    Matched on: <10110110
    Captures: 10110110
    -----

Obviously, instead of just outputting the captured binary digits to the serial monitor, you need to save them for your relay control.

----------

For neatness, you could replace

     ms.Target ("HTTP/1.1 200 OK\
    Date: Sun, 02 Jul 2017 07:53:29 GMT\
    Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1\
    X-Powered-By: PHP/5.3.1\
    Content-Length: 13\
    Content-Type: text/html\
    \
    \
    <10110110>");  // what to search

with

      char * str = "HTTP/1.1 200 OK\
        Date: Sun, 02 Jul 2017 07:53:29 GMT\
        Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1\
        X-Powered-By: PHP/5.3.1\
        Content-Length: 13\
        Content-Type: text/html\
        \
        \
        <10110110>";

      ms.Target (str);

Note the use of the backslashes at the ends of the lines. I've included them here, in order to get the test sketch to compile. You probably will not need them as you would be receiving the response from the server, and not providing an example string for testing.

----------

 Here is a *working* version, along with multiple test strings (`input_str `) and example match strings (`match_str`):

    #include <Regexp.h>
    void setup ()
    {
      Serial.begin (9600);
    //  Serial.begin (115200);
      Serial.println ();

      unsigned int index = 0;
      char buf [100];

    // Simple test pair
    //  char * input_str = "RGB:123";
    //  char * match_str = "(%a)";

    // Simulated MySQL responses
    // Most basic
    //  char * input_str = "<10110110>";
    // Over two lines
    //  char * input_str = "http\\n<10110110>";
    // Full response
      char * input_str = "HTTP/1.1 200 OK\
        Date: Sun, 02 Jul 2017 07:53:29 GMT\
        Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1\
        X-Powered-By: PHP/5.3.1\
        Content-Length: 13\
        Content-Type: text/html\
        \
        \
        <10110110>";
    // Full response with newlines
    //  char * input_str = "HTTP/1.1 200 OK\\n\
        Date: Sun, 02 Jul 2017 07:53:29 GMT\\n\
        Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1\\n\
        X-Powered-By: PHP/5.3.1\\n\
        Content-Length: 13\\n\
        Content-Type: text/html\\n\
        \\n\
        \\n\
        <10110110>";
    // Shorter version of full MySQL response with newlines
    //  char * input_str = "Content-Type: text/html\\n\
        \\n\
        \\n\
        <10110110>";
    // Shorter version of full MySQL response with newlines with no preceeding spaces
    //  char * input_str = "Content-Type: text/html\\n\
    \\n\
    \\n\
    <10110110>";

    // Match strings for MySQL response, containing an eight bit binary number
    // Match at beginning of line
    //  char * match_str = "^<([01][01][01][01][01][01][01][01])";
    // Match at beginning of line with multiple newline characters
      char * match_str = "[\n]*<([01][01][01][01][01][01][01][01])";
    // Match at beginning of line with zero or one newline characters
    //  char * match_str = "[\n]?<([01][01][01][01][01][01][01][01])";
    // Match at anywhere
    //  char * match_str = "<([01][01][01][01][01][01][01][01])";

      MatchState ms;

      while (true){
        char result = ms.Match (match_str, 0);

        if (result == REGEXP_MATCHED)
        {
          Serial.println ("-----");
          Serial.print ("Matched on: ");
          Serial.println (ms.GetMatch (buf));
          Serial.println ("Captures:");
          for (int j = 0; j < ms.level; j++)
             Serial.println (ms.GetCapture (buf, j));
          // move past matching string
          index = ms.MatchStart + ms.MatchLength;
        }  // end of match
        else
          break;  // no match or regexp error

      } // end of while

    }  // end of setup

    void loop () {}

For the `match_str` line,

    char * match_str = "[\n]*<([01][01][01][01][01][01][01][01])";

you may or may not need the caret (`^`) to match at the start of the line, and the `[\n]*` or `[\n]?`. See which combination works for you.

  [1]: http://forum.arduino.cc/index.php?topic=41285.0
  [2]: https://forum.arduino.cc/index.php?topic=59917.0
  [3]: https://www.gammon.com.au/scripts/doc.php?lua=string.find


body:
I have a V2 Adafruit Gemma from the [Gemma starter pack][1], and I'm running Windows 10 Home (version 10.0.14393), on a 64-bit laptop. Following the [ Introducing Gemma guide][2] I've installed the Adafruit drivers and I'm now trying to get it to connect via USB.

After connecting, the board shows the green power LED, but not the pulsing red LED, and Windows shows the 'USB device not recognised' message.

**Tried so far**

 - I'm definitely using USB 2 ports, and I have tried it connected directly to the PC and via a USB hub.
 - I'm pretty sure the cable is working correctly (It works for exchanging data on a phone, and I've tried a few different ones).
 - Under Device Manager, the board shows as 'USB Device (Device Descriptor Request Failed)'.
 - 'Update driver software' > 'Search automatically...' reports that 'The best driver software for your device is already installed'.
 - If I do 'Update driver software' > 'Browse my computer...' and point it to the manual Adafruit driver files (available on the link to the [guide][2]), I get the same message.

Can anyone suggest anything to try? Do I need to (re)install the bootloader itself, and if so, can you point me in the direction of how I do this?

**Update**

As mentioned in the comments I have posted on Adafruit's own support forum but got absolutely nothing yet. I have also tried it on my work PC (Windows 10 Pro, 64-bit) and got exactly the same behaviour.

I'm keen to get this sorted so bounty added for anyone who can at least come up with some suggestions of what to try!

  [1]: https://www.adafruit.com/product/1657
  [2]: https://learn.adafruit.com/introducing-gemma/windows-setup

title: Adafruit Gemma unrecognised USB device on Windows 10

Answers: 1

body:
I think, you've pretty much done everything. If you could gain access to another board, and try that one you could figure out more. Otherwise your symptoms remind me of a something called an ESD (Electrostatic Discharge) caused malfunction. This basically means one of the system essential chips on the board have been fried. It is very easy to ESD a chip without protection, just walk on a carpet or put on a sweater, and than touch the chip. Chances are you were electrostaticly charged with thousands of volts. The chip does not stand a chance. To prevent this from happening, touch something made out of metal before touching the board.<br />More on ESD: [Electrostatic discharge][1]

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


body:
I have a Arduino Mega where a capacitor is 'broken off' ... I originally posted the question in the Electronics forum ([Question][1]).

One of the answers was that the capacitor is not critical. Can anyone confirm it (and consequences by not fixing it at all)? I didn't dare to turn on the Mega because of the broken capacitor.

It looks like this:

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

  [1]: https://electronics.stackexchange.com/questions/314084/is-this-solderable/314109#314109
  [2]: https://i.stack.imgur.com/oGEHR.jpg

title: Is this (loose) capacitor critical?

Answers: 1

body:
If the voltage regulator is a MC33269 as in the official Arduino Mega 2560, then you need that capacitor, or else the MC33269 might start to oscillate. Search in the datasheet of the MC33269 for the paragraph with: "The MC33269 requires an external output capacitor for stability". The board will probably still work without it, but if it does indeed start to oscillate, then it can cause trouble. This is only when powered via the power barrel jack or the VIN pin.

That capacitor does not do a lot when the Arduino Mega is powered via the USB cable. You can use it without any problem when powered via the USB.

According to the photo, you can solder it back into place. They wrote enough about that in the EESE section. Give it a try, but don't create a shortcut with too much solder.


body:
I recently was playing around with Arduino and using dfu-programmer reflashed ATMega16u2 to make the computer think it was a keyboard device.

Well, I wish to put the original Arduino firmware back on, but now dfu-programmer says the device is not present.

The Arduino is listed under `/dev/hidraw5` on Ubuntu. Typing `lsusb` gives the following output for Arduino keyboard:

    Bus 004 Device 008: ID 03eb:2042 Atmel Corp. LUFA Keyboard Demo Application

I tried erasing with the command:

    sudo dfu-programmer atmega16u2:4,8 erase

and got

    dfu-programmer: no device present.

Is there a way to target `/dev/hidraw5` using dfu-programmer? Many thanks.

title: Upload original firmware to HID Arduino

Answers: 1

body:
Very sorry!  But I actually figured this out on my own.  I needed to reset by briefly bridging the reset pin with ground near the USB connector.  Then typed

    sudo dfu-programmer atmega16u2 erase

and I'm happy again.


body:
I have interfaced a ADIS1620 sensor to the Arduino UNO using SPI.I am having a bit of trouble here to read the product ID information from the ADIS1620.According to the datasheet [here][1],

on page 11, it is said that to perform a read operation, 2 16bit transactions are to be done with a minimum stall time of 9 us. The first 16 bit consists of the register address to read from i.e. 0x5600 and the second transaction is to read the product ID information. However, I always get the read data as '0' or as '0xFFFF'.I have done the hardware interfacing as per the connections mentioned below:

    /* SPI Connections as per pg No.10 in
       the Datasheet (Note: Not using IRQ)
     */

     ADIS1620                 UNO
      (DIN)3                11 - MOSI
      (DOUT)2               12 - MISO
      (SCLK)1               13 - SCK
      (SS)4                 10 - CS
      16                    5V
      18                    GND
Below is .h file,

    #ifndef ADIS16260_H
    #define ADIS16260_H

    /* Register Addresses */
    #define LOT_ID1_ADDR          0x5200
    #define LOT_ID2_ADDR          0x5400
    #define PROD_ID_ADDR          0x5600
    #define SERIAL_NUM_ADDR       0x5800

    /* Timings */
    #define STALL_TIME_US         10

    #endif /* ADIS16260_H */

I doubt the problem is to do anything with the code as such, but still, just in case, here is the .ino file,

    /* Lib's Include */
    #include <SPI.h>

    /* Custom Lib's Include */
    #include "adis16260.h"

    /* MACRO's */
    #define CS  10

    /* Globals */
    char incomingByte;
    unsigned int prod_info_data;

    /* Definitions */
    typedef enum
    {
      LOT_ID1,
      LOT_ID2,
      PROD_ID,
      SERIAL_NUM
    } Prod_InfoT;

    /* Function Prototypes */
    void SPI_Init();
    unsigned int Get_Product_Info(Prod_InfoT get_adis16260_info);

    void setup()
    {
      Serial.begin(115200);
      SPI_Init();
      Serial.println("SPI Initialized");

    }

    void loop()
    {
      if (Serial.available() > 0)
      {
        // read the incoming byte:
        incomingByte = Serial.read();
        if (incomingByte == 'a')
        {
          prod_info_data = Get_Product_Info(PROD_ID);
          Serial.println(prod_info_data, HEX);
        }
      }
    }

    /********************************************************************************
       Function Name    : SPI_Init
       Description      : Initialize the SPI module in the MCU
       Returns          : None
     * *****************************************************************************/
    void SPI_Init()
    {
      /* configure the line as output */
      pinMode(CS, OUTPUT);

      /* Initialize the CS line to HIGH */
      digitalWrite(CS, HIGH);

      /* Initialize the SPI module--> configures the MOSI, MISO and CLOCK lines */
      SPI.begin();

      /*
        Configure the SPI bus as follows
          1. SPI bus speed  = 1 MHz
          2. Data Out     = From MSB bit ---> To LSB bit
          3. Data Mode    = SPI MODE3
      */
      SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE3));
    }

    /********************************************************************************
       Function Name    : Get_Product_Info
       Description      : Get Prod ID, Lot ID1, Lot ID2 and Serial Num.
       Returns          : None
     * *****************************************************************************/
    unsigned int Get_Product_Info(Prod_InfoT get_adis16260_info)
    {
      unsigned int get_data = 0;

      switch (get_adis16260_info)
      {
        case PROD_ID:
          Serial.println("Reading Product ID...");
          digitalWrite(CS, LOW);
          SPI.transfer16(PROD_ID_ADDR);
          digitalWrite(CS, HIGH);
          delayMicroseconds(STALL_TIME_US);
          digitalWrite(CS, LOW);
          get_data = SPI.transfer16(0x00);
          digitalWrite(CS, HIGH);
          break;

        case SERIAL_NUM:
          Serial.println("Reading Serial Number...");
          digitalWrite(CS, LOW);
          SPI.transfer16(SERIAL_NUM_ADDR);
          digitalWrite(CS, HIGH);
          delayMicroseconds(STALL_TIME_US);
          digitalWrite(CS, LOW);
          get_data = SPI.transfer16(0x00);
          digitalWrite(CS, HIGH);
          break;

        default:
          Serial.println("Invalid Arguement");
          break;
      }
      return (get_data);
    }
Edit: Added screen shot of the SPI lines:
[![enter image description here][2]][2]
Any support with this would be helpful. Thanks.

  [1]: http://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16260_16265.pdf
  [2]: https://i.stack.imgur.com/ZdPaz.png

title: Not able to read the product ID from ADIS16260 Gyroscope Sensor

Answers: 0


body: Hi i am new to Arduino and I want to know if it is possible to read the data from a sensor that it is connected to the Arduino, I am using the Arduino mega 2560, which is already working, as I have a LED which change color depending on the detection of the object and then store it in a file as txt or another normal extension.

title: Read and store data with the usb

Answers: 2

body:
I don't have experience with Processing, but probably that is what you need. It communicates through USB and with the CreateWriter function, you can create a text file.

More about Processing can be found at [Processing][1]

Also another thread at Electronics stack exchange might help:

[Related question][2]

Alternatives (also mentioned in the above thread):

- Use serial port directly with a terminal application on the PC
- Use an SD card inside the Arduino to log

  [1]: https://processing.org/
  [2]: https://electronics.stackexchange.com/questions/54/saving-arduino-sensor-data-to-a-text-file

body:
From what I understand from your question, you want to store the data displayed in the Serial monitor to a text file or something similar. As the Arduino itself cannot do this task, I used "GoBetwino" to save my data from an Arduino into a text file, from where you can export the data into Excel if you want charts and graphs. The process is fairly easy and described properly in their user manual.
https://playground.arduino.cc/Interfacing/GoBetwino


body:
I am using an Arduino Uno for my project. I use 4 digital inputs and they will be triggered by 4 different relays. I would like to save the data in a *.csv file in the format below.

For example, if any of the inputs goes high, it will save a station ID, date, time it goes ON (starts). But once the input goes low, it will save the time it goes OFF (stops) on the same line.

Kindly help to advise if my code is correct because I get too many errors when I run it.

Example table in .csv file:

    Date        Oven Station Time Start     Time Stop
    3/7/2017    Oven_P1_1    11:58    16:00
    3/7/2017    Oven_P1_2     7:30    11:00
    3/7/2017    Oven_P5_1    14:10    20:00
    4/7/2017    Oven_P5_2     01:20    7:30
    4/7/2017    Oven_P5_1     2:40    8:45
    4/7/2017    Oven_P1_2      08:05    12:00
    4/7/2017    Oven_P1_1      09:12    13:10

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

    import processing.serial.*;

    int Oven_P1_1 = 8;
    int Oven_P1_2 = 9;
    int Oven_P5_1 = 10;
    int Oven_P5_2 = 11;
    float Ovenvals [] = {0,0,0,0};

    Serial myPort;
    String val;
    Table table;

    String filename;

    void setup() {
      String portName = Serial.list()[5];
      myPort = new Serial(this, portName, 9600);
      table = new Table();
      table.addColumn("id");
      table.addColumn("year");
      table.addColumn("month");
      table.addColumn("day");
      table.addColumn("hour");
      table.addColumn("minute");
      table.addColumn("second");
      table.addColumn("Oven_P1_1");
      table.addColumn("Oven_P1_2");
      table.addColumn("Oven_P5_1");
      table.addColumn("Oven_P5_2");
    }

    void serialEvent(Serial myPort) {
      val = myPort.readStringUntil('\n');
      if (val != null) {
        val = trim(val);
        println(val);
        float Ovenvals[] =float(split(val, ','));
        TableRow newRow = table.addRow();
        newRow.setInt("id", table.lastRowIndex());
        newRow.setInt("year", year());
        newRow.setInt("month", month());
        newRow.setInt("day", day());
        newRow.setInt("hour", hour());
        newRow.setInt("minute", minute());
        newRow.setInt("second", second());
        newRow.setInt("Oven_P1_1", ovenVals[0]);
        newRow.setInt("Oven_P1_2", ovenVals[1]);
        newRow.setInt("Oven_P5_1", ovenVals[2]);
        newRow.setInt("Oven_P5_2", ovenVals[3]);
        {
          saveTable(table, "data/OvenStatus.csv");
        }
      }
    }

    void draw() {
      OvenVal[0] = digitalRead(Oven_P1_1);
      OvenVal[1] = digitalRead(Oven_P1_2);
      OvenVal[3] = digitalRead(Oven_P5_1);
      OvenVal[4] = digitalRead(Oven_P5_2);
      Serial.print(OvenVal[0]);
      Serial.print(",");
      Serial.print(OvenVal[1]);
      Serial.print(",");
      Serial.print(OvenVal[2]);
      Serial.print(",");
      Serial.print(OvenVal[3]);
      Serial.print(",");
      delay(100);
    }

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

title: Need help with my code for my project using an Arduino Uno and Processing

Answers: 1

body:
You asked for (emphasis mine):

> [...] But once the input goes low, it will save the time OFF (stop)
> **on the same line**.

That's hard. What if several other inputs have gone HIGH in the
meanwhile? You will have to somehow rewind part of the file, then add
the stop time, the add again the subsequent lines...

You probably do not want to do all this on an Arduino. Especially
considering that the Arduino has no concept of file, unless you add an
SD card and the appropriate library. And it has no concept of time of
day, unless you add an RTC and the appropriate library. I would suggest
you go the easy path:

* have the Arduino tell your computer through the Serial port whenever
  one of those inputs changes state
* write a program in your computer (with processing or whatever) that
  reads this information and formats it the way you want.

For the first part, I suggest the following:

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

    /*
     * Tell us when some pins change state.
     */

    const int CHANNELS = 4;
    const uint8_t pins[CHANNELS] = {8, 9, 10, 11};

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

    void loop()
    {
        static int states[CHANNELS];
        for (int i = 0; i < CHANNELS; i++) {
            int state = digitalRead(pins[i]);
            if (state != states[i]) {  // input changed state
                Serial.print("channel ");
                Serial.print(i);
                Serial.print(" going ");
                Serial.println(state ? "HIGH" : "LOW");
                states[i] = state;  // record new state
            }
        }
    }

The output will be something like

    channel 2 going HIGH
    channel 1 going HIGH
    channel 2 going LOW
    ...

For the second part, well, that's not an Arduino-related question
anymore!


body:
I was looking at the Arduino Nano's [schematic](http://download.arduino.org/products/NANO/Arduino Nano-Rev3.2-SCH.pdf) and noticed a resistor that seems to be pointless (RP2C on this picture).
[![Strange resistor RP2C][1]][1]
Also there is numbers 6 and 3 on it, does it mean that resistor is connected to pins 6 and 3 on FT232 or to the same pins on Atmega328?

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

title: Purpose of this resistor in Arduino Nano schematic

Answers: 2

body: It's an unused element of resistor array RP2. Both ends are grounded in order to reduce noise.

body:
The resistor is one of 4 resistors that make up an SMD resistor array, RP2. It is seen on the board here:
[![Arduino Nano underside][1]][1]

The resistor array works like this:
[![Resistor array][2]][2]

The resistor on this array is spare, so both terminals are grounded.

  [1]: https://i.stack.imgur.com/BemUn.jpg
  [2]: https://i.stack.imgur.com/FaBSm.gif


body:
I have a bunch of different dev boards for different projects. What I have been getting very confused about is what board needs what programmer from the Tools > Programmer menu.

I wish the selection had the option to be partially automated for the board selection. But it's evidently not. Part of my problem is that if you choose the wrong programmer, some boards seem to work. Others read but won't write, or will write to some spaces, but not others. Or, you might get other cryptic errors that sound a lot like failed hardware. Have a look at this message for an example:

[![Programmer Error?][1]][1]

OK, so let's say I have some random dev board. How can I know what programmer I should use? Assume the manufacturer's documentation mentions nothing about it...

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

title: How can I tell what programmer to use?

Answers: 2

body:
The clock and the timing signals and the voltage levels do not always match. And perhaps something is connected to the pins already which makes it harder for the programmer.

I use mostly the cheap USBasp version 2 (the text "version 2" is often written on the PCB). They are based on the [USBasp from Thomas Fischl][1].

Sometimes there is a timing conflict. Sometimes that can be corrected with options for avrdude or with the avrdude.conf file, sometimes I have to grab an older or newer USBasp programmer.

What do you mean by choosing the wrong programmer? If there is a programmer connected to the computer, then select that type of programmer. Do you have a programmer?

  [1]: http://www.fischl.de/usbasp/

body:
Generally the **Tools > Programmer** selection is only used for **Tools > Burn Bootloader** and **Sketch > Upload Using Programmer** and is not used for standard uploads. So for standard uploads you can set it to anything you like because it will have no effect.

The most notable exception is the Adafruit Trinket, which does [require](https://learn.adafruit.com/introducing-trinket/setting-up-with-arduino-ide) you to select **Tools > Programmer > USBTinyISP** even though you are uploading through the USB socket on the Trinket board without a separate ISP programmer.

You will also find some 3rd party hardware packages that are not written for boards with an Arduino style serial bootloader and so treat a standard upload as an "Upload Using Programmer" for the sake of convenience. Examples are [MicroCore](https://github.com/MCUdude/MicroCore) and the ["Barebones ATmega Chips (no bootloader)"](https://github.com/carlosefr/atmega) hardware package. In this case the correct Programmer menu selection is dependent on which model of ISP programmer you are using.

So regarding the question "How can I tell what programmer to use?": If you're doing a standard upload, start by assuming it doesn't matter. If that doesn't work, read the documentation!

If you're doing a **Tools > Burn Bootloader** or **Sketch > Upload Using Programmer** (or holding shift while pressing the "Upload" button) then you should select the model of the ISP programmer you're using.


body:
I have a project where I want to connect a number of SPI devices, and I'm running out of Slave Select pins (SPI) on the Arduino. So I thought that I could use something like an MCP23S17 to get additional pins and use those as SS pins, but most libraries require to pass the pins when initialising, and it seems that I can't pass the MCP's pins as a function/class argument (or can I?). For example:

    U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /*cs*/ 12, /*dc*/ 4, /*rst*/ 6);

So my question is: How can I get more SS pins? Thank you

title: How can I get additional Slave Select pins?

Answers: 3

body:
A maybe dirty solution is to change all the libraries. Everywhere the SS pin is used, instead call a function and set it yourself (by using the MCP23S17).

To make this a bit better, define a class that contains this functionality to abstract it from the changed library classes.

Example:

As initialization of the library a function or class constructor will be used, e.g.

    MCP23S17(void);

This you will use like:

    MCP23S17 my_component = MCP23S17();

You need to change this to:

    MCP23S17(int ss_pin);

And change the related code, store it in a class variable and use it everywhere in the library instead of the fixed SS pin number.

Than you can constructor your own instance by:

    MCP23S17 my_component = MCP23S17(4);

Where 4 is the SS pin number

body:
My solution would be to keep it simple. Use real pins for every SPI SS. Buy an other Arduino board with more pins if you need more pins.

What else is connected to your Arduino board ? Perhaps it is easier to reduce those pins. Almost all analog pins can be digital pins as well. You could use external ADC modules. Perhaps replacing 1-Wire or DHT11 or DTH22 with I2C sensors. Using a I2C display. There are many options to use buttons and leds with a few pins. And so on.

body:
I would suggest adding a layer of abstraction in your whole design.

Use the ESP8266 as the main system controller, then farm out sensor communications to one or more other "active" expansion devices.

Rather than just using an expander for the SS pins you are using the "expander" for all the communication.

By "expander" I basically mean some other microcontroller (maybe an ATMega328P for example) which receives an instruction to sample a sensor then goes off and gathers the data that is wanted and sends it back to the master ESP8266 controller.

How you arrange that communication is up to you, but maybe I2C would be a good way to go.  You could even make the sensor data gathering completely autonomous so that the ESP8266 just then requests the latest data from the slave(s).

It means:

* You don't have to change any libraries
* You get distributed processing, sharing the work out
* The ability to communicate with an almost infinite number of sensors


body:
I bought Feetech SCS09 smart servos (also known as SCS009 or SCS0009).

**Please note that these servos are not regular PWM servos, they are devices that communicate with board using Serial connection via device named TTLinker that converts UART to half duplex protocol. So the question is about the problem with serial communication only.**

The seller provided me Arduino library to work with the servos.

The simplest testing sketch looks as this:

    #include <SCServo.h>

    SCServo SERVO;

    void setup() {
      Serial2.begin(1000000);
      SERVO.pSerial = &Serial2;
      delay(500);
      SERVO.EnableTorque(1, 1);
      SERVO.EnableTorque(2, 1);
    }

    void loop() {
      SERVO.WritePos(1, 1023, 4000); // Servo ID:1, rotate to the position:0x2FF
      SERVO.WritePos(2, 1023, 1000); // Servo ID:2, rotate to the position:0x2FF
      delay(4000);
      SERVO.WritePos(1, 20, 3000); // Servo ID:1, rotate to the position:0x000
      SERVO.WritePos(2, 20, 1000); // Servo ID:1, rotate to the position:0x000
      delay(3000);
    }

**The code works perfectly on Arduino Mega** and allows to independently control servos.

But with Due I have problems: not all commands can be performed. So if compile the code for Due only servo ID1 works, but ID2 do not work at all.

When I add delays between commands the servos started to work

        SERVO.WritePos(1, 1023, 4000); // Servo ID:1, rotate to the position:0x2FF
        delay(10);
        SERVO.WritePos(2, 1023, 1000); // Servo ID:2, rotate to the position:0x2FF
        delay(4000);
        SERVO.WritePos(1, 20, 3000); // Servo ID:1, rotate to the position:0x000
        delay(10);
        SERVO.WritePos(2, 20, 1000); // Servo ID:1, rotate to the position:0x000
        delay(3000);

When I set delays between 1 and 9 the both servos can work but sometimes skip commands. Servos can skip 1-4 actions and then start to work again. The less delay I set the more random skips I get.

So I think here is some specialities regarding Serial connection on Arduino Due. What It can be? Why delays help to make it working?

By the way I read that Arduino Due can have problems with 1000000 baud rate and I tried different, even significntly less baud rates (for example 38400) with Arduino Due: the result is the same.

I need to explain how WritePos function works in the library

    int SCSProtocol::WritePos(u8 ID, u16 Position, u16 Time, u16 Speed)
    {
     return writePos(ID, Position, Time, Speed, INST_WRITE);
    }

    int SCSProtocol::writePos(u8 ID, u16 Position, u16 Time, u16 Speed, u8 Fun)
    {
     flushSCS();
     u8 buf[6];
     Host2SCS(buf+0, buf+1, Position);
     Host2SCS(buf+2, buf+3, Time);
     Host2SCS(buf+4, buf+5, Speed);
     writeBuf(ID, P_GOAL_POSITION_L, buf, 6, Fun);
     return Ack(ID);
    }

    void SCSProtocol::Host2SCS(u8 *DataL, u8* DataH, int Data)
    {
     if(End){
      *DataL = (Data>>8);
      *DataH = (Data&0xff);
     }else{
      *DataH = (Data>>8);
      *DataL = (Data&0xff);
     }
    }

    int SCSProtocol::Ack(u8 ID)
    {
     if(ID != 0xfe && Level){
      u8 buf[6];
      u8 Size = readSCS(buf, 6);
      if(Size!=6){
       return 0;
      }
     }
     return 1;
    }

    void SCSProtocol::writeBuf(u8 ID, u8 MemAddr, u8 *nDat, u8 nLen, u8 Fun)
    {
     u8 msgLen = 2;
     u8 bBuf[6];
     u8 CheckSum = 0;
     bBuf[0] = 0xff;
     bBuf[1] = 0xff;
     bBuf[2] = ID;
     bBuf[4] = Fun;
     if(nDat){
      msgLen += nLen + 1;
      bBuf[3] = msgLen;
      bBuf[5] = MemAddr;
      writeSCS(bBuf, 6);

     }else{
      bBuf[3] = msgLen;
      writeSCS(bBuf, 5);
     }
     CheckSum = ID + msgLen + Fun + MemAddr;
     u8 i = 0;
     if(nDat){
      for(i=0; i<nLen; i++){
       CheckSum += nDat[i];
      }
     }
     writeSCS(nDat, nLen);
     writeSCS(~CheckSum);
    }

    int SCServo::readSCS(unsigned char *nDat, int nLen)
    {
     int Size = 0;
     int ComData;
     unsigned long t_begin = millis();
     unsigned long t_user;
     while(1){
      ComData = pSerial->read();
      if(ComData!=-1){
       if(nDat){
        nDat[Size] = ComData;
       }
       Size++;
       t_begin = millis();
      }
      if(Size>=nLen){
       break;
      }
      t_user = millis() - t_begin;
      if(t_user>IOTimeOut){
       break;
      }
     }
     return Size;
    }

    int SCServo::writeSCS(unsigned char *nDat, int nLen)
    {
     if(nDat==NULL){
      return 0;
     }
     return pSerial->write(nDat, nLen);
    }

So the problem is somewhere here: **Arduino Mega works good**, but it seems like Arduino Due have no time for on of the operations.

You can see more info here:

[Servo][1]

[TTLinker device][2]

[Arduino library][3]

  [1]: http://ali.onl/Cd4 "Servo"
  [2]: http://ali.onl/Cd5
  [3]: http://ragra.ru/SCServo.zip

title: Serial write skips on Arduino Due

Answers: 1

body:
I figured out that 250000 baud rate is the only choice for the Arduino Due with these servos. Less baud rates cause skips on Arduino Mega also, so this speed is not enough for fast data transfer.

Higher baud rates work good on Mega too but cause garbage on Due.

So let's summarize: these servos with TTLinker (TXS0108E) work good with Arduino Due at 250000 only and with Arduino Mega at 250000 and higher baud rates.


body:
Actually I'm using a W5100 Hanrun HR911105A 16/02 Ethernet shield with an Arduino Uno (original).

I tried this code from the examples:

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

    // Enter a MAC address and IP address for your controller below.
    // The IP address will be dependent on your local network.
    // gateway and subnet are optional:
    byte mac[] = {
      0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
    };
    IPAddress ip(192, 168, 1, 177);
    IPAddress myDns(192,168,1, 1);
    IPAddress gateway(192, 168, 1, 1);
    IPAddress subnet(255, 255, 255, 0);
    // telnet defaults to port 23
    EthernetServer server(23);
    boolean gotAMessage = false;
    // whether or not you got a message from the client yet

    void setup() {
      Serial.begin(9600);
      // this check is only needed on the Leonardo:
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
      // start the Ethernet connection:
      Serial.println("Trying to get an IP address using DHCP");
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        // initialize the Ethernet device not using DHCP:
        Ethernet.begin(mac, ip, myDns, gateway, subnet);
      }
      // print your local IP address:
      Serial.print("My IP address: ");
      ip = Ethernet.localIP();
      for (byte thisByte = 0; thisByte < 4; thisByte++) {
        // print the value of each byte of the IP address:
        Serial.print(ip[thisByte], DEC);
        Serial.print(".");
      }
      Serial.println();
      // start listening for clients
      server.begin();
    }

    void loop() {
      // wait for a new client:
      EthernetClient client = server.available();
      // when the client sends the first byte, say hello:
      if (client) {
        if (!gotAMessage) {
          Serial.println("We have a new client");
          client.println("Hello, client!");
          gotAMessage = true;
        }
        // read the bytes incoming from the client:
        char thisChar = client.read();
        // echo the bytes back to the client:
        server.write(thisChar);
        // echo the bytes to the server as well:
        Serial.print(thisChar);
        Ethernet.maintain();
      }
    }

That code prints the following on the serial monitor:

    Trying to get an IP address using DHCP
    Failed to configure Ethernet using DHCP
    My IP address: 192.168.1.177.

So what is the problem? Why it is not connecting? I tried all the ethernet examples, but not one works. I don't know, maybe the problem is that I don't have a sticker of MAC address on the shield and I'm using the MAC address of the examples. Or maybe I'm writing the IP address wrong? Here is the data from the network connection details.

    Connection-specific DNS Suffix: zte.com.cn
    Description: Intel(R) Dual Band Wireless-AC 3165
    Physical Address: 72-57-C5-BC-66-07
    DHCP Enabled: Yes
    IPv4 Address: 192.168.1.2
    IPv4 Subnet Mask: 255.255.255.0
    IPv4 Default Gateway: 192.168.1.1
    IPv4 DHCP Server: 192.168.1.1
    IPv4 DNS Server: 192.168.1.1
    IPv4 WINS Server:
    NetBIOS over Tcpip Enabled: Yes
    Link-local IPv6 Address: fe80::b523:b9f2:b43c:6a8a
    IPv6 Default Gateway:
    IPv6 DNS Server:

My router is a ZTE model ZXHNH108N.

title: My Arduino Ethernet shield is not working

Answers: 1

body:
If your Arduino can not get an IP address, it could be because there is a problem with your code, your shield or your network.

There doesn't seem to be a problem with your code from a quick glance, so let's look at the network.

1. The cable. Are you using the right sort of cable? You should be using a Cat5e straight through cable. Cat5e is the type of cable for Ethernet, if it is plugged into the router and you didn't make it yourself, it is probably either a CAT5e or CAT6 cable, so it will be OK. There are two types of cable and they are almost impossible to tell apart, the normal sort is a "straight through" cable, which means the Transmit and Receive pins at one end go to the Transmit and Receive pins at the other end. The other sort is a "crossed" cable where the Transmit goes to the Receive, this is for connecting a computer to a computer.  Since you are plugging to a router you should have a straight cable, if in doubt test it with a working device, ie plug it into your PC.
2. DHCP - I see from your PC output DHCP is enabled on 192.168.1.1 and I guess this is your router. A DHCP server needs to know what addresses it can give out to devices, these addresses are called "the DHCP pool". If you have no more free addresses in the pool then you can't connect anymore devices. It sounds like you haven't restricted your pool, but it might be worth logging onto your router and seeing if you can see what addresses are in the pool or range.
3. MAC Filtering - For security some routers only allow certain MAC addresses to connect to the router and request a DHCP address. If you have it turned on then add your MAC address to the white list. If you don't have it turned on, don't worry.
4. Speed - I suspect that your shield has a maximum speed of 10MBs. Most modern networking equipment only supports 100/1000MBs so the shield just won't work with your router. Your router should have the numbers near the wired sockets to confirm or deny this.

If none of that works the you are going to need to see if you can read the data from the shield and see if you can work out what is going wrong. You will need a network snooper like WireShark and a _HUB_. An Ethernet switch will not work, it must be an Ethernet Hub, because switches don't rebroadcast the data on all ports. If your PC has two network cards you could set it up as a 'bridge' and you can snoop on the data as it passes across the bridge.

Sorry if some of these terms are confusing, but you should be able to Google them and get a better explanation than I can give you in the space here.

One final thought: are you running the Arduino from a battery? If so it might be worth using a mains supply, because the battery might not be able to support the Ethernet transmissions.


body:
Below is a simple `USART` code for `ARDUINO` written in `Pure C`.
But due to uknown(in reference to me) reasons, the code is not provicing desired output.

Can someone point out the error in the code.
I cannot use the `Arduino` built in function `Serial.begin` as i need to use USART receive `interrupts`.

    #include <avr/io.h>
    #define F_CPU 16000000
    #define BAUD 9600
    #include<util/setbaud.h>

    void UART_Init();

    void setup()
    {
        UART_Init();
    }

    void loop()
    {
        UART_Transmit('c');
    }

    void UART_Init()
    {
       UBRR0H = UBRRH_VALUE;
       UBRR0L = UBRRL_VALUE;
       UCSR0B = (1<<RXEN0) | (1<<TXEN0);
       UCSR0C = (3<<UCSZ00);
    }

    void UART_Transmit(unsigned char data)
    {
        while(!(UCSR0A & (1<<UDRE0)));
        UDR0 = data;
    }

title: Arduino UNO UART coding in pure C

Answers: 2

body:
Finally I figured it out.

The `UBRR0` calculation was the mistake

For making the code work for baud rate 9600, we need to set the equation as:

> UBRR0 = (F_CPU / 4 / baud - 1) / 2;

and also double the USART speed by setting :
> UCSR0A = (1<< U2X0)

I hope someone will find this information helpful.

body:
> UBRR0 = (F_CPU / 4 / baud - 1) / 2;

you probably want to check the datasheet for that.

One way to code it is to change it based on the U2X bit, like this:

 UxBRR=F_UART / ((UxCSRA & (1<<U2X0))?8:16) / baud - 1;   //generate baud rate register

So the user can change the U2X bit freely and the software will take care of it.

there is one set of uart polling and interrupt-driven routines that I use: https://github.com/dannyf00/My-MCU-Library/tree/master/UART/UARTISR/ATMega328p

they have the same user interface so can be exchanged freely.


body: This is a very basic question but I cannot find answer for this. I have a couple of Arduino Nano boards lying with me. With keen scrutinizing I found that a few chips on board where numbered as Atmega 328P-AU 1645 and some were numbered Atmega 328P-AU 1644. Can somebody please tell me the difference the number after AU makes ? I know the difference between an AU and PU chip.

title: Arduino chip family

Answers: 1

body: Looks to me like a date code: YYWW, where YY are the last two digits of the year and WW is the ISO week number.


body:
I have a pro micro and I'm running the IDE on linux.
The IDE easily recognises that my board is on /dev/ttyACM0 so i can flash programs on to it.
I am testing the following code
<!-- language-all: lang-cpp -->

    void setup()
    {
      Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
    }

    void loop()
    {
      Serial.print("Hello universe ");
    }
After I upload the code if I try to bring up the serial monitor I get this error message

> Error opening serial port '/dev/ttyACM0'. (Port busy)

  tried resetting the pro micro, rebooting the computer, tried the code
> sudo usermod -a -G dialout yourUserName as suggested [here][1]

But the problem still didn't solve. Any idea what went wrong.

Edit1:

  I noticed that when the arduino is in the bootloader mode (i.e when I press reset) lsusb shows

> Bus 004 Device 055: ID 2341:0037 Arduino SA

however, when it starts to execute the program from its memory, lsusb doesn't show that entry. but instead, shows

> Bus 004 Device 054: ID 1b4f:9206

  [1]: https://forum.arduino.cc/index.php?topic=129647.0

title: Cant open serial monitor on linux

Answers: 0


body:
Using for example 433MHz RF Receiver modules, they are connected to a digital input pin with interrupt. Looking at the most basic meaning of digital readings (e.g. 1/0, on/off, HIGH/LOW), how does the Arduino convert the signal readings to a number/string?

From my limited understanding, I'm assuming it has something to do with the (external) libraries, or it might just be that my understanding about digital readings are too limited.

title: Arduino digital pin reading string numbers

Answers: 2

body:
From the official Arduino site, See [DigitalWrite][1] :

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.

The exact definitions can be found here for reading a signal: [Constants][2]

When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to: HIGH and LOW.

**HIGH**

The meaning of HIGH (in reference to a pin) is somewhat different depending on whether a pin is set to an INPUT or OUTPUT. When a pin is configured as an INPUT with pinMode(), and read with digitalRead(), the Arduino (Atmega) will report HIGH if:

-a voltage greater than 3.0V is present at the pin (5V boards);
-a voltage greater than 2.0V is present at the pin (3.3V boards);

A pin may also be configured as an INPUT with pinMode(), and subsequently made HIGH with digitalWrite(). This will enable the internal 20K pullup resistors, which will pull up the input pin to a HIGH reading unless it is pulled LOW by external circuitry. This is how INPUT_PULLUP works and is described below in more detail.

When a pin is configured to OUTPUT with pinMode(), and set to HIGH with digitalWrite(), the pin is at:
-5 volts (5V boards);
-3.3 volts (3.3V boards);

In this state it can source current, e.g. light an LED that is connected through a series resistor to ground.

**LOW**

The meaning of LOW also has a different meaning depending on whether a pin is set to INPUT or OUTPUT. When a pin is configured as an INPUT with pinMode(), and read with digitalRead(), the Arduino (Atmega) will report LOW if:

-a voltage less than 1.5V is present at the pin (5V boards);

-a voltage less than 1.0V (Approx) is present at the pin (3.3V boards);

When a pin is configured to OUTPUT with pinMode(), and set to LOW with digitalWrite(), the pin is at 0 volts (both 5V and 3.3V boards). In this state it can sink current, e.g. light an LED that is connected through a series resistor to +5 volts (or +3.3 volts).

Probably, HIGH is 1, LOW is 0, and ON is 1, OFF is 0.
Than 1 is mapped to 5V or 3.3V depending on the Arduino and 0 is mapped to 0V.
These mappings and the definitions of HIGH/LOW/ON/OFF are in the Arduino libraries.

  [1]: https://www.arduino.cc/en/Reference/DigitalWrite
  [2]: https://www.arduino.cc/en/Reference/Constants

body:
A digital pin can only tell you if a signal is HIGH or LOW at any instant in time. That itself isn't enough to transfer data (as in a stream of 1 and 0) since it's just the state at that moment.

To transfer data you need to introduce the extra parameter of *time*. That is, the amount of time a pin is HIGH or LOW and when exactly it changes.

UART data works this way. Both ends of the connection agree on a certain time for each "bit" of data (*symbol*) and read or set the pin at the agreed rate. That is the *baud rate* of the connection. Without that pre-arranged agreement on the time there is no way one end can know what the other is saying.

Other methods involve looking not at the current state of the pin but instead looking at how and when it changes from HIGH to LOW or LOW to HIGH. One example of this is *Manchester Coding* which encodes the different bits 0 and 1 as different sequences of transitions between HIGH and LOW or LOW and HIGH.

A third method, which is what SPI and I2C use, is to employ another pin to indicate to the receiver when it should look at the pin - this is sending the *clock* to the receiver.

Fourth, you get the way IR remote controls work. These use different length pulses of HIGH/LOW to indicate a 1 or a 0. A long HIGH and short LOW could be a 1, and a short HIGH and long LOW could be a 0.


body: what is the analog reference, I know that it can be used as a voltage reference, but not exactly what  it is all about please someone help.

title: what is aref(analog reference)

Answers: 1

body:
It is the reference voltage against which all other analog voltages (analog inputs) are measured against.

By default it is the same as the chip supply voltage (5V on most Arduino boards), so the analog inputs can measure between 0 and 5V.

If you connect the AREF pin to a lower voltage, say to the 3.3V pin (for convenience) and set the analog reference to EXTERNAL, you can then measure between 0 and 3.3V.

This is good if you are measuring a smaller voltage and want to get as much resolution in the analog reading. If you leave it at 5V and are measuring only up to, say, 3.3V, you're wasting all the analog reading values between 3.3V and 5V that could go to getting you more sensitivity.


body:
I have an Arduino Uno R3 with an ATmega238 microchip. I can't upload any code to it: the green led and pin13 LED are always on (without flashing ) and the RX and TX LEDs don't flash when I upload code or press the reset button. Is the microchip malfunctioning?

And what happens when a reverse current returns to Arduino from a relay?

title: Can't upload any code to my Arduino board

Answers: 1

body:
You basically have 2 questions here.

1: Why is my Uno not uploading code.

2: How does back EMF effect a microcontroller. We'll address 2 first

When a relay module is activated, it energizes a coil to close a switch. This coil is an inductor, which is an energy storage device. When the signal to the relay tells it to turn off, your trying to de-energize the coil. Whereas before you let current run through the coil to establish a magnetic field, now you cut the current supply and let the magnetic field die out.
The problem this creates is back EMF. As [Faraday's law][1] will tell us, a change in a magnetic field causes a voltage (an EMF) in a coil. When we were charging the circuit, this was the voltage applied to the coil. When we discharge the inductor, this voltage is back EMF, and is in **the opposite direction as charging voltage**.

How does this affect your arduino? Well, it can be anything ranging from harmless to catastrophic. It may simply reset your arduino (as one I was working with did on a past project [where an occiliscope showed back EMF spikes in excess of -30V]) or it might straight-up burn the ATMega328p that acts as the Uno's brain. Or it might take out the voltage regulator, or cause a host of other problems.

The simplest fix for back EMF is to put a diode in parallel with the relay with cathode to your positive terminal and anode to your negetive terminal. This creates a short for the relay's coil to discharge through. Some better solutions (especially for sensitive digital equiptment) involve entirely isolating the relay's power supply form the rest of your circuit with an optoisolator.

Problem 1: Assuming that these problems were related to the use of a relay without the proper safeguards, you might try a few things to verify your chip is still alive. If  you have a second arduino you might try using it to [build an ISP][2], which will allow you to both reburn the bootloader and upload sketches independently of the uno's onboard usb com port programmer. If that works but the onboard programmer still does not, you may need to reflash the programmer (which I've read can also be done with an ISP, though I've never tried it.)

Hope that helps!

  [1]: https://en.wikipedia.org/wiki/Faraday's_law_of_induction
  [2]: https://www.arduino.cc/en/Tutorial/ArduinoISP


body:
I'm very new to Arduino, I'm trying to connect an air pressure Sensor without success.

I followed this tutorial:

[Arduino Air Pressure Measurement][1]

The values I'm getting are very weird and the variations when I blow in the sensor are not more than about `+/- 0.2`.

So, the tutorial does use the same model, is that why? I need something else?

Any help will be very appreciated.

  [1]: http://circuits4you.com/2016/05/13/arduino-pressure-measurement/

title: How to connect a Pressure Sensor-MPX10DP to an Arduino?

Answers: 1

body:
The MPX10DP does not have an amplifier inside. The output is the output of the internal wheatstone bridge. It is not even compensated for temperature.

This is the manufacturers page about the MPX10 series: [nxp.com MPX10 series][1].

You need an instrumentation amplifier and perhaps a temperature compensation. The INA125 is an instrumentation amplifier. It was used in the past with the Arduino a lot. Nowadays, most sensors are digital, and the bare sensors with wheatstone bridge output are not used that often anymore.

When you connect both sensor outputs to two Arduino inputs (without amplifier), then the difference is 35mV for 10kPa. The resolution is in theory 5V / 1024. The overall accuracy for two analog inputs perhaps 9 bits, then you can measure the 10kPa in 3.5 steps (about 2 or 3 kPa resolution).
If you seriously want to use this specific sensor, and don't want to use extra hardware, then you might have a look at [my question about the differential mode and gain][2] that is possible with the Arduino Mega 2560 and Leonardo.

Or you could buy a pressure sensor with 0...5V output, that can be connected to the Arduino analog input. The tutorial you mentioned uses the MPX5010. That sensor has a amplifier inside and is temperature compensated. They are reliable and ratiometric with the 5V, therefor super easy to use. With a lot of averaging in the code, you can get a high (relative) accuracy.

  [1]: http://www.nxp.com/products/sensors/pressure-sensors/differential-gauge-up-to-10-kpa/differential-and-gauge-uncompensated-pressure-sensor-0-to-10kpa:MPXx10
  [2]: https://arduino.stackexchange.com/questions/39211/library-to-set-internal-analog-gain-of-the-arduino


body:
I built a custom arduino based board (speciffically based off of Sparkfun's Pro Micro 3.3V 8Mhz and their Qduino mini boards) that uses the ATMega32u4-RC.

The board I built integrated an acceleromter (LSM6DS3) and a micro-SD card holder, and eleminated any uneeded GPIO. (This is basically a datalogger board for the LSM6DS3 accelerometer). It also inlcudes a usb-powered LIPO charging circuit, which is copied from the qduino mini.

A picture of the board I built,  with power LED indicating life.
[![My Board][1]][1]

The problem I am experiencing is that, after apparently sucessfull upload of the bootloader (I've tried the bootloader for the qduino mini, promicro 3.3v 8Mhz, even the Leonardo), my computer will not reconize the board. I've exauhsted all the information about driver installation from the sources for the boards my board is based on, and still can't make windows recognize my custom board.

Specifically, I've tried using a multitude of signed and unsigned drivers (on Windows 10 and 7), and can not get windows to pick anything other than usbfilt.sys as the driver.

Any advice would be greatly appreciated!

Edit: Added Eagle Schematic below

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

  [1]: https://i.stack.imgur.com/MDRyd.jpg
  [2]: https://i.stack.imgur.com/Z8I1o.png

title: Custom board with ATMega32u4 having USB issues

Answers: 1

body:
As Chris Stratton pointed out, I neglected to include the 1uF capacitor on UCap. This is absolutely necessary on a 3.3v board for the board to communicate with USB properly.

 Thanks!


body:
# My Goal #

Have Arduino read audio output from a TRS stereo audio cable (coming from a computer, smartphone, etc.). *As motivation for this use-case*, once some audio data (depending on the sample rate) have been stored in a buffer, the Arduino will perform an FFT on the buffered data. The power contained in the FFT is mapped to the red, green, and blue frequency-bands of visible light to determine the color of an LED strip.

# My Set-up #

The obvious first step was to connect a [Right-Angle 3.5mm Stereo Plug to Pigtail Cable][1] to the Arduino. As is commonplace, this cable has a **T**ip, **R**ing, and **S**leeve connector; Adafruit labels the black wire as ground (sleeve). They further label the red wire as "left channel live" (tip) and the white wire as "right channel live" (ring), if I can trust [Wikipedia][2]:

> Stereo sockets commonly provide two such NC contacts, one for the **tip (left channel live)** and one for the **ring or collar (right channel live)**.

# My Question #

So, I've plugged the red wire into the `A0` pin and the white wire into the `A1` pin. However, I'm unsure of how to sample the actual audio signal from these analog pins.

I don't believe the `analogRead()` function solves the whole problem - it only converts a voltage reading at the pin into a value between 0 and 1023. Presumably, if I knew the bit rate (i.e., sample rate) & of each packet in the transmitted audio signal, I'd be able to construct signal from that. **Is it possible to extract the original audio's waveform from a simple voltage signal?** If not, what approach would enable the Arduino to read audio data from an audio cable?

*Note:* For those wondering, I have indeed heeded the advice from this [Electronics SE answer][3] to attach a DC-blocking/DC-bias circuit to the signal source before driving it into an analog pin on the Arduino.

  [1]: https://www.adafruit.com/product/1700
  [2]: https://en.wikipedia.org/wiki/Phone_connector_(audio)#Switch_contacts
  [3]: https://electronics.stackexchange.com/a/5321

title: Read Audio Data in Real-time over 3.5mm Stereo Cable

Answers: 2

body:
Simply, YES: it is possible to reconstruct the waveform from the sampled signal. There are entire 400 level college courses on this subject, in fact, but it is rather simple to implement. However, you should study the FFT algorithm you plan to use a little more closely, as it actually requires a discreet time (sampled) input.

Some background: The audio signal you are getting from the TRS cable is continuous, but was recreated from discreet samples (unless your using a tape deck) by using reconstruction theory. The basic idea is this: you take a continuous train of discreet values (the sample points of the sound you want to make), then you multiply each one by a sinusoidal rectangle function (called a sinc, if you want to look it up), which basically takes your discrete values and makes them analog. The frequencies of the sampled signal will probably be 44.1 or 96kHz, although the signal you actually get is analog.

Now, the FFT!
The FFT itself is a discrete time function, meaning that it is designed to use sampled data (for instance, of vector of values read from `analogread()` once every T seconds, where T=1/f, f being your sampling frequency). I should warn you, unless you're planning on using a library someone else already made, the FFT is a complicated beast! It's not impossible to use--in fact once you understand it, it's really quite beautiful--just be aware there is a lot of circle-based math and opaque optimization.

So, again in short, yes, **you can reconstruct a signal from its sample, but you don't need to!**

Note: there may be more information on what you're trying to do on the Signal processing SE as well.

Hope that helps!

**EDIT ADDITION:**

In response to the comments, I very much agree that most lower level arduinos (assuming uno or similar) is not the ideal chip. *However*, there is a way around your sampling problem. Whether your processor can handle the higher sampling rate is questionable, but we'll address that momentarily.

Q: How to get a higher sample rate out a 10kHz max ADC.
A: Double up. Or triple up, or quadrupile up, etc.
The basic idea is, if you have one ADC reading channel 1 of a signal nT seconds (T being period = 1/10kHz and n being a discrete set of integers = 0,1,2,3...), then you can have a second ADC reading the signal every nT+(T/2) seconds. Then, you populate your data vector as DATA=[ADC1(0*T),ADC2(0*T+T/2),ADC1(1*T),ADC2(1*T+T/2),...] and so on. This **effectively doubles your sampling rate**. If you want to sample at ~40Hz, you use 4 ADC channels. The real question is how high do you need to go. By Nyqist's Theorem, you need a sampling freequency >= to twice of the highest frequency you expect to be present in your signal. In most recorded sounds this never above 18kHz. So, you do this with 4 ADC channels offset from each other by a quarter period, and you have a high enough sample rate.

Q: What if I can't process the data with an FFT that fast?
A: Never fear! Discrete time filters and power integration are here! (okay, that was a bit corny).
A much less processor intensive method of frequency band power estimation would be to implement band-pass filters in your software (which can work with *very little* overhead processor-wise) and then average the power output of each filter.

Again, hope this addition helps! But as another commenter pointed out, what you want to due may be much easier with a different chip. And as I will point out, moving the filtering and power integration to external op-amp circuits would be an equally simpler option, eliminating the entire sampling problem!

body:
**The middle path**

Build the simple op-amp (or whatever) 70s-era color organ, but without all the LEDs. Then basically feed the organ's LED-driving lines into the Arduino's ADCs. Sampling that pre-processed/summarized data, you can define a wide variety of RGB interactions without complicated math or an EE background. The timing requirements will be well-within the Arduino's reach, unlike computing FFTs or other "difficult" processes. Besides, old/new hybrids are cool!


body:
I'm trying to implement charlieplexing with bit angle modulation on my Arduino Micro, and for that I need to use the internal timers.

Which timers of the Atmega32u4 are unused by the standard firmware? Ideally I'd like to use either Timer1 or Timer3 as they have the highest resolution.

title: Which Timer can I use on the Arduino/Genuino Micro?

Answers: 1

body:
Only Timer0 is used for millis and micros, just as with the Arduino Uno and Mega 2560.

Timer0 is used in "[wiring.c][1]".
That same file is used for the Uno, Mega 2560, Leonardo and Micro. The differences for the Leonardo is the pin numbers in "[pins_arduino.h][2]".

If you don't use PWM output with analogWrite, then you can use all of the other timers. The timers are set to certain values in the function init (also in wiring.c). But you can ignore that if you never use analogWrite.

  [1]: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/wiring.c
  [2]: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/variants/leonardo/pins_arduino.h


body:
I am wondering why after pressing the reset button on my Arduino, the latest program loaded runs but only after about 5seconds. The same thing happen when I run my arduino from the computer using the Arduino 1.6.9 software.

Is there any way to make this delay shorter?

Thanks,
IF

title: Pressing reset button restarts program only seconds latter

Answers: 2

body:
The first thing that happens when you apply power to a board or press reset, is the bootloader executes. That waits for a short time to accept a new sketch over the serial port. If nothing arrives it terminates and executes the existing sketch.

On the Uno that delay is only 2 seconds. However on the Leonardo the delay is much longer (around 5-8 seconds) owing to how the serial port is implemented: it has to allow time for the host computer to re-enumerate the USB device after a reset, and that takes a second or two.

If you don't want that delay you will need to remove the bootloader (i.e., ignore it) and program the board through a hardware programmer and the ICSP pins (which will disable the bootloader for you). You lose the convenience of programming through the USB connection though.

Alternatively choose a different board that doesn't have such a delay for the bootloader - one that uses a different programming method.

body: Having had the same issue , I recently found out that the Leonardo/Micro jumps directly into the user application when it is powered up, either by inserting a USB cable connected to a cellphone charger i.e power only USB , or by connecting external power via the RAW power input.  So, if you need a quick restart after reset, just cut and reconnect the power supply.


body:
I am trying to use my Arduino Nano to program my Generic ESP-01 Module. I want to use the module to control an RGB LED Light Strip but am not having much success, only errors....

These are my connections:

Esp-01 -------------------------------------------------- Arduino Nano

 TX <------------------------------------------------------> TX

RX <-----------------------------------------------------> RX

VCC <----------------------------------------------------> 3.3v

CH_PD <------------------------------------------------> 3.3v

GND <---------------------------------------------------> GND

[![My Connections][1]][1]

I have also grounded my reset pin on my Arduino and when programming I ground the GPIO0 on the ESP-01 to enter flash mode. Not too sure if this would cause a problem but just wanted to note that my Arduino Nano is a clone and runs on the CH340G USB drivers not FTDI. It successfully uploads the program with the Arduino IDE but not much after that. I have also tried uploading the Blink program and the CheckFlashConfig program but the same error on startup.

Here is the error:

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

    load 0x4010f000, len 1384, room 16
    tail 8
    chksum 0x2d
    csum 0x2d
    v09f0c112
    ~ld
I also decoded the stack that I sometimes get with ESP Exception Decoder:

    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x402177a8: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104bd3: wdt_feed at ?? line ?
    0x40104bb4: wdt_feed at ?? line ?
    0x40104bcd: wdt_feed at ?? line ?
    0x40104bca: wdt_feed at ?? line ?
    0x4022bea0: cal_rf_ana_gain at ?? line ?
    0x40228690: tx_cap_init at ?? line ?
    0x4022d4cd: ram_rfcal_pwrctrl at ?? line ?
    0x4022d37c: ram_rfcal_pwrctrl at ?? line ?
    0x4022be18: cal_rf_ana_gain at ?? line ?
    0x4022be3d: cal_rf_ana_gain at ?? line ?
    0x4022be9c: cal_rf_ana_gain at ?? line ?
    0x40228689: tx_cap_init at ?? line ?
    0x40228690: tx_cap_init at ?? line ?
    0x4022a600: chip_v6_initialize_bb at ?? line ?
    0x40226237: phy_init at ?? line ?
    0x40105eae: register_phy_ops at ?? line ?
    0x4022b3b2: register_chipv6_phy at ?? line ?
    0x4021a93e: wifi_station_set_default_hostname at ?? line ?
    0x40201b39: __wrap_register_chipv6_phy at /Users/privitec/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_phy.c line 261
    0x4022f660: sleep_reset_analog_rtcreg_8266 at ?? line ?
    0x4010564a: spi_flash_read at ?? line ?
    0x402174c3: rijndaelKeySetupEnc at ?? line ?
    0x40217b3c: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40217b17: user_uart_wait_tx_fifo_empty at ?? line ?
    0x40104e90: wdt_feed at ?? line ?
Your help would be greatly appreciated.

**Update:**
I have tried reinstalling AT firmware version 0.9.2.2 with esptool. Again it successfully detects the ESP-01 and programs it. I still get the same error (sometimes instead of getting boot mode:(3,6) I get boot mode:(3,7)) when powering up and I have tried to input `AT` into the Serial Monitor and I get no response.

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

title: Can upload programs to ESP8266 with Arduino Nano but not run them

Answers: 0


body:
I'm doing a project where in I'm using Arduino Due to measure the time difference of arrival of signals to four piezoelectric sensors. The piezo sensors where glued on a board and we want to localize the source of taps on the boards based from the TDOA of the vibration to the piezos.

Originally, we are using interrupts to raise flags once we have detected the signals (basically, we've set a threshold on the piezo voltage to say that we've 'detected' a signal) but that seems susceptible to noises especially when the environment has loud noises (music, voices on microphones, etc.).

So what we think as a solution is to perform signal processing. However, to do this, we need to measure the voltage of the incoming signal using the ADC.

So far, my target is to make the performance of this approach comparable to that of the one where we are using interrupts. As of now, the new approach is super sensitive to the difference on the taps giving it a high POE.

As I understand it, the main difference between the two approach is that the interrupt approach has a microsecond difference between counts making the difference of the taps to about 10 to 30 microsecond. However, the Analog approach has a 20 microsecond difference between each sample for each channel, making the count difference 20 second also. Even a count difference would make it 20 us.

Is there anyway to make this time faster? I know the ADC needs time to convert and push the data to the appropriate registers but I'm just trying to find ways to make this faster. I've read on the datasheet of the Due MCU that it has 14 ADC channels plus a temp sensor at the 15th. Maybe a way of doing this could be to reduce the number of channels? I don't know how.

Are there any way to make the ADC conversion of the Arduino Due faster?

title: How to speed up Due ADC

Answers: 4

body:
Yes, there is a possibility to configure `ADC` to run faster, as it can handle `1Msps`. For four `ADC` channels it means `250ksps` each (with `1us` time difference between samples). It's not possible with Arduino wrappers as they are way too slow and also waits for conversion end. You have to configure it directly in MCUs registers, so start with `SAM3X8` datasheet.

In short: free running mode, sequenced readings like: `0 1 2 3`, with interrupt on 4th sample, interrupt handler and some processing.

body:
> difference between each sample for each channel,

That's way too slow for any mcu made since the 1980s.

Look into the datasheet and compare it via your code to see where you can pick up the speed. Typically there is a clock prescaler for the adc that you can change.

In general, the fastest would be continuous adc into dma. If you need to add multiple channels turn on scanning.

body:
//Configure ADC
PMC->PMC_WPMR &= ~(PMC_WPMR_WPEN);    //Disable the Write Protect Mode
PMC->PMC_PCER1 |= PMC_PCER1_PID37;    //Enable ADC Peripheral Clock

PIOA->PIO_PDR |= PIO_PDR_P16;         //Disable PIO Controller

ADC->ADC_WPMR &= ~(ADC_WPMR_WPEN);    //Disable the Write Protect Mode
ADC->ADC_CHER |= ADC_CHER_CH7;        //Enable A0 pin
ADC->ADC_MR = 0;
//ADC->ADC_MR = ADC_MR_PRESCAL(2);    //ADC Clock set to 16MHz
ADC->ADC_MR = ADC_MR_PRESCAL(4);      //ADC Clock set to 8MHz
ADC->ADC_MR |= ADC_MR_TRACKTIM(3);
ADC->ADC_MR |= ADC_MR_STARTUP_SUT8;
ADC->ADC_EMR = 0;

//read ADC output
ADC->ADC_CR |= ADC_CR_START;           //Software Trigger
uint32_t adc_read = ADC->ADC_CDR[7];

you can change the parameters of prescaler to get the required speed

body:
You can set the ADC in freerun mode to get results as fast as they can be read.

Use [adc_configure_trigger][1] for this.

    adc_configure_trigger(ADC, ADC_TRIG_SW, ADC_MR_FREERUN_ON);

To enable freerun on the ADC or to configure as needed. No need anymore to set registers.

There was a bug with this function before if called more than once, but it is now fixed.
https://github.com/arduino/Arduino/issues/1819

  [1]: http://asf.atmel.com/docs/latest/sam.drivers.adc.adc_threshold_wakeup_example.arduino_due_x/html/group__sam__drivers__adc__group.html


body:
In my recent project, I am working with serial data. Till now, I'm able to receive data and display on LCD. Now, suddenly I can't get any serial data. Nothing display on LCD.

My incoming string is:

    {"Action":"ONE","TPS":"0.40","MAP":"0.95","LOAD":"14"}

And my code is below:

    #include<LiquidCrystal.h>

    LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

    String response = "";
    bool begin = false;

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

    void loop()
    {

      while(Serial.available() || !begin)
      {
        char in = Serial.read();

        if (in == '{')
        {
          begin = true;
        }

        if(begin)
        {
          response += (in);
        }

        if(in == '}')
        {
            break;
        }
        delay(1);
      }

      lcd.setCursor(0, 0);
      lcd.print(response);
    }

title: How to store incoming serial string in arduino?

Answers: 2

body:
Actually I can see what I think may be an issue with your code.

     while(Serial.available() || !begin)

This isn't right.  If there is no data available in the serial buffer but the first `{` hasn't been seen then go and read the non-existent data anyway?

Rather than try and explain what I mean in multiple comments I have put it all together and this is what I think your loop should be this:

    /// This is un-compiled code, so you might have to fix some little issues.
    /// bool begin = false;         // True when the initial { has been seen

    void loop()
    {
      while (finished == false)
      {
        if (Serial.available())
        {
          const char in = Serial.read();
          if (in == '{')
          {
            response = "";  // Blank the string
            begin = true;
          }
          if (begin)
          {
            response += (in); // Only write if within the {}
          }
          if (in == '}')
          {
            begin = false;   // Prevent any chars between } and { leaking through.
            lcd.setCursor(0, 0);
            lcd.print(response);
          }
        }
        delay(1);
      }

      delay(500); // Not sure what will happen if you send multiple {} to the LCD too fast.
    }

body: I just switch from Arduino UNO to Arduino MEGA. And everything works fine. I know this is not a proper answer but I want to know why this happens. I don't understand why this happens? Can anyone explain me?


body:
Im trying out the code found [here][1] , let me quote the section of code that bothers me.

    // set pin numbers for switch, joystick axes, and LED:
    const int switchPin = 2;      // switch to turn on and off mouse control
    const int mouseButton = 3;    // input pin for the mouse pushButton
    const int xAxis = A0;         // joystick X axis
    const int yAxis = A1;         // joystick Y axis
    const int ledPin = 5;         // Mouse control LED
xAxis is a variable that is defined as an integer , however, it is being assigned a character(A0), How is this possible? I tried to compile and run the code and everything works well. I'm quite surprised!

  [1]: https://www.arduino.cc/en/Tutorial/JoystickMouseControl

title: character input for an integer variable?

Answers: 2

body:
A0 and A1 are not characters or what you mean probably: strings.
Because it would be written as "A0" and "A1".
The types of A0 and A1 are probably integers or another numeric type.

However, these are probably defined as (constant) integers, e.g.:

    const int A0 = 100;
    const int A1 = 101;

(note 100 and 101 are random numbers)

or defined by a macro. e.g.:

    #define A0  100
    #define A1  101

So the variables A0 and A1 are actually integers (or assigned as numeric values by a define).

body:
The clue is this comment:

    // set pin numbers for switch, joystick axes, and LED:

and the fact that xAxis is declared a `const int`. Because the declaration promises that this variable will not (must not) be changed once it has been initialized, it will not be assigned any memory at run time. The compiler will treat it much like the macro:

    #define xAxis A0

and do a compile-time replacement of `xAxis` with A0, wherever xAxis appears.

`A0` is an analog channel, defined in the board-specific Arduino libraries to the Arduino pin# corresponding to it.

It is a somewhat recent idiom in C and C++ - since the inclusion of "const" in the language - to use "const int" declarations for this purpose instead of "#define" statements. The intent is the same.


body:
I am using [OmniVision OV7076 camera (without FIFO)][1] with Arduino Uno.
[![Camera][2]][2]
So I want to use Github code provided in [ArduCAM repository][3]. They have provided [OV7076 FIFO version][4] straightaway but it is using more memory.

I have used computer nerd code (provided in this tutorial [Instructables OV7076 camera][5]) and the camera had worked.

But I want to use the ArduCAM repository. It would be nice if any one could provided link for the guide or can give a little walk-through.

In the ArduCAM repository, they have make an ArduCAM class which have many methods. Thus we get rid of initialisation provided in [computernerd][5] code.

I want to use functions of the class directly. But i am unable to understand which method can be used for ov7076 camera. If you could write a starter code it would be very helpful.

  [1]: https://www.voti.nl/docs/OV7670.pdf
  [2]: https://i.stack.imgur.com/6nUlz.jpg
  [3]: http://github.com/ArduCAM/Arduino
  [4]: http://github.com/ArduCAM/Arduino/tree/master/OV7670FIFO
  [5]: http://www.instructables.com/id/OV7670-Without-FIFO-Very-Simple-Framecapture-With-/

title: Using ArduCam library for Ov7076 camera

Answers: 0