text:
How do I read a sub-degree angle?
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?

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.

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.

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.
...


text:
65 hall effect sensors as switches to be used as a keyboard with a teensy
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.

I just asked a similar question. It sound like if you used a matrix with output legs in a line tied to a shared Arduino pin, any triggered sensor in the line will drop the whole thing LOW so you could scan rows/cols to figure out what's pressed. Instead of powering rows one by one and paying the 150ms penalty mentioned by @Jot below, you route all rows/columns to digital input with INPUT_PULLUP and read them that way. Hope that helps!

Hmm that sounds way better than my current workaround. I would assume I could just use diodes to avoid ghosting? Also in this configuration there needs only be one pin per cop and one per row right?

Also, is the input_pullup really needed if the pins are already pulled up by the resistor?

I don't think so, as long as they are pulled up. My understanding is that INPUT_PULLUP is just a convenience (not requiring extra components). Now that you ask, I think I ran across a post/comment somewhere suggesting physical resistors vs. INPUT_PULLUP, but I don't recall the reasoning at the moment.

[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. Nick Gammon has the best tutorial of the 74HC165 with daisy-chain.
There is also an example is with the CD4021 and the ShiftIn 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 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. For example 10*7 requires 17 pins. The Keypad library allows that multiple keys are pressed at the same time.

I've seen that tutorial and read a little bit on using a matrix for keyboards. If I'm not mistaken, with a physical switch, it pulls the columns to low and rows to high and has 2 connectors one for rows and one for columns. The sensor I have only has one output leg so all my columns and rows would be connected to the same output leg right?

Oops, I might have made a big mistake. I was thinking about reed switches. Can you tell the type of the hall switches ? Perhaps I will remove my answer.

This is the sensor in question. https://www.digikey.com/product-detail/en/diodes-incorporated/AH1807-P-B/AH1807-P-B-ND/3829348

Wow, thanks for the detailed response. It doesn't have to be 65, I can get it to 64 I'm sure. I'll read both of those tutorials and see which one works best. I'll see if I can find some Reed switches to play with too, that way I could use some of the existing firmware for keyboards.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
How to read response from server using an Ethernet shield?
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:
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?

@ChrisStratton - With respect, please review the edits, to see who made what changes. This was a suggested edit, made by someone else, that I reviewed, accepted and improved the edit. Should I have rejected the edit?

@Golckz Could you please provide more information. Tell us about the specifics. Make sure your question is clear.

What code have you used? Could you post it? What is the specific command that you use to request the value from the database?

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 0s and/or 1s, 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?
However, a more intelligent method would be to use pattern matching and regular expressions.
From New regular expression library released, Nick has provided a Regexp library. It uses Lua for the expression syntax, see string.find, 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.

This is far more complicated than needed.  Review the HTTP protocol, and what it says about body vs header.

OK @ChrisStratton, thanks for your input. Maybe you would like to post your own answer, with your solution?

I think it is a really great answer. you could utilize this response for a wide range of similar problems, and there is a great amount of detail.

@jOh, Thanks. Yes, it is a most versatile library

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Adafruit Gemma unrecognised USB device on Windows 10
I have a V2 Adafruit Gemma from the Gemma starter pack, and I'm running Windows 10 Home (version 10.0.14393), on a 64-bit laptop. Following the  Introducing Gemma guide 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), 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!

"USB Device (Device Descriptor Request Failed)" tends to indicate that the speed select resistor has been seen, but actual USB signalling failed.  This could be any number of problems.  The Gemma doesn't use a legitimate USB interface, but a rough approximation in software running on the ATtiny.  So it could be a compatibility issue, a lack of appropriate software loaded, or a bad board.   Given you've already tried with and without a hub, you should probably pursue this with Adafruit on their own support forums.

Yes I've posted on the Adafruit forums too and I've tried with and without the hub as above. I appreciate the message is vague but that's exactly my problem, I'm not sure where to go from there.

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.More on ESD: Electrostatic discharge


text:
Is this (loose) capacitor critical?
I have a Arduino Mega where a capacitor is 'broken off' ... I originally posted the question in the Electronics forum (Question).
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:

You should probably leave the question on EESE where you originally asked it.  You'll get far more credible circuit engineering advice there than here.

Ok ... I thought it would be more Arduino related.

@ChrisStratton I think it's fine if he leaves this question here. We would probably send him over to you all anyways because it's a question related to an Arduino product and something that is viable to an Arduino system. We would probably tell Michel to check the datasheets.

@KingDuken - it's not a question about using an Arduino as a "product", rather it's a question about the detailed requirements of a particular regulator circuit.  So it really belongs on EESE, not here.  Additionally, this is effectively a cross-site duplicate, something that isn't allowed.

@ChrisStratton Understood. Thanks for clarifying

@Downvoter, can you instead of downvoting all my posts, explain WHY you downvoted, so I may improve the post.

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.

Thanks ... eventually I want to use a Mega it with a barrel jack, but I will keep this one for only USB purposes (that's fine for me). I will get a replacement anyway and having a 'test' Mega is always convenient.

Good. What about moving over to 3.3V faster processors ? Like the Arduino Due and Arduino Zero or M0 ?

I don't understand your remark ... why would I move to 3.3V faster processors? Actually I would like, but I don't want to put all 'new' things in at once (I already am new to Arduino Uno, electronics in general, RF, microcrontrollers, opto-couplers, (S)RAM etc).

Well, the Uno and Mega are still very useful, but they are slowly fading out in the coming years. It is moving towards 3.3V processors with more memory. Most sensors are 3.3V and a SD memory card is 3.3V and so on. The Raspberry Pi is also 3.3V.

I already found out that ... I ordered 23LC1024 (128 KB SRAMs) which work on +5 V but +3.3 V is easier too find, and for my RFs (nRF24L01s) I bought breakout boards for +5 -> 3.3 V (same as for WIFI which I just bought for trying).
But I don't feel confident (yet) to use directly 3.3V directly. And for SD I bought an entire shield since the cheap 'breakout' board did not work that well (maybe for the same reason)


text:
Upload original firmware to HID Arduino
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.

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.


text:
Not able to read the product ID from ADIS16260 Gyroscope Sensor
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,
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:

Any support with this would be helpful. Thanks.

Does you code return the serial number?

@Code Gorilla, I have tried reading the serial number as well, the same issue happens i.e. Reads 0 or 0xFFFF.

Good, that means its not a fault with the device.  Should the first param of SPISettings be 1 million or 100,000?   I've never used SPI, but doesn't the SPI object handle the CS pin?

@CodeGorilla, the SPI bus speed is set to 100 KHz i.e. 100000. No, the chip select line needs to be handled manually.

Reading all 0xFFFF suggests the gryo is not driving MISO, either as it is not operational or has not received a valid read command or been selected.  You need to show the wiring of your gyro chip.  Who soldered the QFN?  QFN's are notorious for having metalizations look connected when they actually are not.  For your software, do you have another SPI peripheral you can run a quick test against?  Investing in a scope or even a cheap USB fifo based logic analyzer will be very useful for investigating this type of problem.

@ChrisStratton, while reading,  most of the time I receive '0' and sometimes in between I receive '0xFFFF'(So it means that the gyro is responding with a 0x00? and sometimes 0xFFFF due to some connection issues??), need to check this. The QFN was soldered by a hardware engineer. I have a USB logic analyzer, I will prob the signals and check if the SPI lines are working fine.

Sounds like you need to get that hardware engineer involved.  Both bus traffic analysis, and inspecting the QFN fillets under high magnification from an angle would be appropriate (I usually raise the microscope so I can hold the board in my hand and tilt it to the best angle)

@ChrisStratton, unfortunately the hardware engineer had left 2 months ago. Between, I guess the SPI signals look good, what do you think? (have attached the image). Before concluding for a hardware check to my boss, I want to make sure that there's nothing wrong being done on the firmware side. And, do I need to do a full fledge timing analysis w.r.t the timing requirements that needs to be met for the ADIS16260?

Try putting a pullup resistor on MISO so you can see if it is undriven or stuck.  Check the data sheet for the gyro - many chips will clock out some sort of status word even from the first byte of SPI access.  If you can find any other SPI peripheral, it may be worth experimenting with that and trying to adapt your software to it, as in so doing you may realize some oversight.  Finally there are other gyros out there pre-soldered on modules with Arduino libraries already in existence - if you get really stuck maybe you can use one of those, at least until you get a hardware engineer.

@ChrisStratton, just to get it right, you mean to say that I need to test the Arduino UNO's SPI interface with another device that uses SPI interface? or a different MCU itself  SPI to communicate with the Gyro?

I was proposing you use another SPI peripheral to gain some hands-on experience and validate (an adapted version of) your SPI code.  But trying another MCU with the gyro could be an option too, if you have something that is a substantially different implementation.


text:
Read and store data with the usb
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.

You need to edit this question to be more specific about what you are asking.  A typical Arduino can report data back to a USB host such as a PC (typically actually through a serial port like channel, although the transport is USB), however at least the ATmega-based ones are unable to act as hosts themselves, which means that they cannot directly write data to a USB device such as a flash drive.

That's correct.  I use Arduinos of many flavors to write data out their serial port, and have a Python program on  the PC side waiting for data on /dev/ttyUSB0 (for example).  That works fine.  Please take the tour at https://arduino.stackexchange.com/Tour then come back and edit this question to be more specifically about the Arduino.  You are welcome here.  But this question is in danger of being closed as-is.

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
Also another thread at Electronics stack exchange might help:
Related question
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

Thanks I would want to do that with the serial port directly with a terminal application as putty or the Arduino serial monitor.

Than just copy the content to a text file.

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


text:
Need help with my code for my project using an Arduino Uno and Processing
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

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);
}

Better if you ask a particular problem rather than "too many error when we run"

Thanks for the response. I've edited my code and run it again. Error shows: OvenVals cannot be resolved to a variable.

Grinds teeth What you have is not referred to as "codes." You have posted your program code.  "Codes" are the things you enter into a numeric keypad lock to open a door.  "Code" is the text you write that is compiled to be made into the binary file that becomes your firmware.

C is case-sensitive.  You have defined a variable array "Ovenvals[]", but try to use "OvenVals[]" - those are two different arrays.

Doesn't look like an Arduino sketch to me. What libraries are you using?

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:
/*
 * 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!

Thanks Edgar for the enlightenment. Would you be able to help me how to save those output to .csv file or txt file on my computer?

@Bong: No, but that could be a legitimate question on stackoverflow.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Purpose of this resistor in Arduino Nano schematic
I was looking at the Arduino Nano's schematic and noticed a resistor that seems to be pointless (RP2C on this picture).

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?

I have very limited electric knowledge.. I seen on some circuits a small capacitor between VCC and GND (pins 6 and 3), but never a resistor without any other component in between.

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

I get it now, thanks! And numbers represent pins of the resistor array.

What noise are you talking about?

https://en.wikipedia.org/wiki/Johnson%E2%80%93Nyquist_noise

@IgnacioVazquez-Abrams, for better clarity: I think what you mean to say is: "Because this resistor in the array is unused, both ends are grounded in order to reduce noise." Right?

The resistor is one of 4 resistors that make up an SMD resistor array, RP2. It is seen on the board here:

The resistor array works like this:

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

Can you please provide me any link regarding this resistor array,mine got faulty.I need to replace it!

The marking says 102 so that means each resistor in the array is 1k ohms. The size looks like a 1206 package. Digikey: https://www.digikey.com/product-detail/en/panasonic-electronic-components/EXB-V8V102JV/Y4102CT-ND/155159, RS/Allied: http://au.rs-online.com/web/p/array-resistors/5225406/, Farnel/Newark/Element14: http://au.element14.com/vishay/cra06p0831k00jta/resistor-resistor-array-1kohm/dp/1886553

Best answer: this part you said is key for my understanding: "The resistor on this array is spare, so both terminals are grounded."

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
How can I tell what programmer to use?
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:

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...

I'm voting to close this question as off-topic because the question arrises from a fundamental misunderstanding - as explained below, the programmer selection is not applicable in the ordinary case, and where needed would depend on the physical programmer purchased, not the target board.

I'm voting to leave open because this is a common cause of confusion for beginners and is very much on topic for Arduino Stack Exchange.

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 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 and the "Barebones ATmega Chips (no bootloader)" 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.

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.
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?

The programmer is on the dev board For example: An Arduino Uno R3 uses the "AVRISP MKII" from the menu. The Adafruit trinket uses "USBTiny". And yes, I think it is confusing that I might have to select a programmer for a development board that doesn't share the same name. Maybe I just need to write all the variations down, and look it up when I start having trouble.

What dev board ? The Arduino Uno uses the usb connector and can upload a sketch when it has a bootloader. How does the programmer come into that ?

If you pick the wrong one, it does work.

If you don't have a programmer, the selection in the menu for the programmer does not matter. You can upload a sketch via het usb cable to the Arduino Uno. You only need to select the Arduino board and the serial port.

Thats not concurrent with what I am experiencing.

The selection of the programmer is only used with 'upload with programmer' or when burning the bootloader. If you experience something else, then something is very wrong. I have never heard that it influenced the normal upload. If you make a fresh install of the newest Arduino IDE on an other computer without extra cores (for example by Adafruit), then it should work in a normal way.


text:
How can I get additional Slave Select pins?
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

The problem with your plan is... how do you arrange to only have one SS pin active at once? You turn one of the expander pins on - that SS is then active. However you need a different SS active to turn it off again. You have a bit of a catch-22 situation: you need to turn off the SS pin in order to turn off the SS pin. The only reliable way is to have a second SPI bus that controls the expander.

True. What if I use the i2c MCP23017 though? In which case the SS pins would be controlled through i2c... That's my current scenario, but it doesn't solve the issue of putting the MCP's pins into library function calls.

That would fix it - basically using a second bus (and changing the protocol but that's irrelevant).

And how would I pass the SS pins on an MCP23017 as arguments to the libraries after that?

You wouldn't. Not without lots of nasty hacks.

If you're using an Uno or similar, have you looked at a Mega? It has more Digital Outputs but you'd want to confirm the SPI library supports the additional Mega outputs (I've never used one personally).

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

I assume you're right and this is the best solution, but I would prefer to have only one controller chip. Otherwise it means I have to write 2 programs, one for the ESP8266 and one for the sensor communication controller. Is there any way to avoid that?

Use a bigger controller with more pins. It is very common to build a system with multiple controllers in it.

Ok, assuming I use something like an ATMega328P, how would I update its firmware then if it is merely a slave of the ESP8266?

The same way you would in any other situation. Just because it is connected to an esp8266 makes no difference.

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.

I'm actually using an ESP8266 (in the arduino environment), so my pins are rather limited.

The ESP32 has solved all the disadvantages of the ESP8266. For example the Sparkfun Thing https://learn.sparkfun.com/tutorials/esp32-thing-hookup-guide has 32 pins.

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

That is a possibility, but a bit of a difficult one and not very efficient. I mean if any library upgrades, I have an issue...

Yes completely true, it's quite dirty to change libraries anyway (but a literal ' solution' ) ... on the other hand, if you change the libraries and make the SS pins flexible everybody can use it (and it could be the new 'default' libraries). Actually I don't understand why people making libraries do not implement flexible pin assignments anyway directly from the start.

Can you give me an example of what that could look like?

I updated my answer

I saw. I'm trying to understand it.


text:
Serial write skips on Arduino Due
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
TTLinker device
Arduino library

Please tell the name of the seller, give a link to your servo motors, give a link to the library that you use and to TTLinked. We would like to look into the hardware and library that you use, but then we have to know what you have.

I added links to my post, you can check, thanx

This is a tough problem. The TTLinker uses 5V signals, and the Due uses 3.3V signals, so you do need indeed a level converter. Can the level converter do 5V to 5V ? to try the Mega board via the level converter ? Do you use a fast logic level converter ? or a weak slow open drain level converter for I2C ? The way you describe the problem is most likely a software problem. The Arduino Due uses 32-bits integers, and the Mega 16-bits. However, I can't find a problem with 32 versus 16 in the library. With a logic analyzer you can get more information and get a little closer to the problem.

I have no experience of the Due, but I have just noticed that Tx0 has a higher max output current (15mA) than Tx1 (3mA), could that be having an affect?

Jot, I use this level converter http://ali.onl/CdL based on TXS0108E, I will try it with Mega to figure out whether it is the converter problem or not

I just connected the TTLinker directly without the level convereter. It work but with the same bug. So the level converter is not needed and it is definitely not a cause of the bug

@SergeyKravchenko I do not agree too much with your last sentence. I checked the Vih of the TTLinker and the Voh of the Due. The TTLinker I found states that the interface is a 74HC126D, powered at 5V. With these data, the Vih seems to be around 3.5V; your 3.3V powered due will never be able to reach this. Moreover the output voltage from the TTLinker is again 5V, and the Due is NOT 5V tolerant. So use the converter every time you attach it to the Due. Then, please show us the schematic you used (TXSs should have one side lower than the other, IIRC)

@fragugi87, I just tried it myself and saw the action in work by my own eyes:) to make it working I supplied TTLinker from Arduino Due 3.3V output, not 5V... moreover 74HC126D can work at 2-6V, it is written in the datasheet, so there is nothing strange... but the bug still exists: I can get proper working only with delays between commands

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.


text:
My Arduino Ethernet shield is not working
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%14
IPv6 Default Gateway:
IPv6 DNS Server:

My router is a ZTE model ZXHNH108N.

Are you using the right sort of cable, Cat5e straight through, not crossed.  DHCP seems enabled of the router, so do you have any spare addresses in your pool?  Do you use mac address filtering?  It looks like your router can't/won't give the board an address rather than there being anything wrong with the shield.

No i don't make anything from that because I don't know what is that . May be if you discuss it to me we can solve it . Actually i don't know if there is any permission i should make from the router every thing here is on its difficult  . And i don't know what is the filtring of the mac address

Your doomed then! :)  Hopefully the answer clears things up for you.

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.

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.
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.
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.
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.


text:
Arduino UNO UART coding in pure C
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;
}

Compiled as an Arduino sketch, your code runs like a charm on my Uno. How did you compile it?

@EdgarBonet I did compiled it on Arduino IDE . There was no error in the code. But after uploading to the board the output received is not as expected.

What kind of output did you expect? I see a long stream of "ccccccccccccccccccccccc...", and that's what I expect from reading the code.

@EdgarBonet I too expect that only. But am not getting it.In my serial monitor, I get only square boxes

At 115200 baud rate, the correct output is received. But for 9600, the output is square boxes.

Is this a real Uno clocked at 16 MHz? Could you post the generated elf somewhere?

@EdgarBonet I am using an Arduino clone clocked at 16Mhz. elf file: link

I can't download that without opening a Dropbox account, which I won't do.

suggest a good alternative please.

@EdgarBonet elf file

i am stuck in the same problem...not able to use arduino serial functions .....while using uart receive interrupt.....
have you got the solution?

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.

util/setbaud.h defines USE_2X to 0 or 1 depending on whether the U2X bit is needed. Then you can UCSRA |= (USE_2X << U2X);.

@EdgarBonet Thanks for the help man. It works like a charm.

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.


text:
Arduino chip family
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.

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.

I hope it has got nothing to do with functionality and is only a sort of batch number.

They were made one week apart. That is the only difference.


text:
Cant open serial monitor on linux
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

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

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

Modem manager. Every time.

I tried changing the USB cable. IT doesn't seem to be the cause . also check out the edit1.

To expand on Majenko's comment, try sudo apt-get purge modemmanager.

Thankyou Edgar Bonet your solution worked. Will you please write it as a solution, also please explain why modemmanager gave the problem. wouldnt uninstalling modemmanager trouble other apps that use it?

This solution worked for me too. I could upload sketches to my arduino via a sparkfun FTDI connector (FT231X) but could not use the serial monitor.


text:
Arduino digital pin reading string numbers
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.

I don't know about RF Receivers, but most sensors I know uses some form of digital protocol to comunicate with Arduino, so you need a library for that specific protocol (like I2C or SPI). I think there is, however, a pH sensor that is just output a voltage that you read with an analog pin.

From the official Arduino site, See DigitalWrite :
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
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.

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.

In other words, the receiver sends the data in binary (1s and 0s) to the Arduino? (and the library converts it to string code)


text:
what is aref(analog reference)
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.

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.

When the EXTERNAL is not selected, the first analogWrite selects the internal voltage reference. That voltage can be measured at the AREF pin with a multimeter. The Arduino Uno has inside the chip a voltage reference of 1.1V, that can be useful when the 5V is not exactly 5.0V, for example when the Uno is powered via the usb cable. Reference: https://www.arduino.cc/en/Reference/AnalogReference

@Jot You mean analogRead, not analogWrite ...

Oops, sorry, yes I ment analogRead.


text:
Can't upload any code to my Arduino board
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?

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 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, 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!

Thank very much your answer relay very useful i well try to build an ISP and tell what happened if you have no problem .

Sorry but what happened when ISP doesn't work ?

If ISP isn't working (double check your ISP hookup circuit because it is easy to mess up--I've done that myself a few times) then its time to look at replacing the ATMega328p chip. If you have one of the boards with DIP chip, this is as simple as pulling out the old one and dropping in a new one. If you have the smd version, you'll have to re solder it.
You might also, if you have multimeter handy, probe the different parts of the power system and make sure that that is all working okay before you go thru the hassle of getting a new ATMega328p.


text:
How to connect a Pressure Sensor-MPX10DP to an Arduino?
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
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.

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.
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 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.


text:
Custom board with ATMega32u4 having USB issues
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.

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

First thing you should check is if Windows sees a USB VID/PID for this device, and if so if they are as expected.  If not, instead of loading the bootloader with ISP load a simple program that flashes and LED or something and make sure the chip runs, then re-check all of your USB wiring.

I uploaded a blink sketch via my ISP (sparkfun's avr pocket programmer) and it worked just fine.
The device instance path under properties shows the following: USB\VID_0000&PID_0002\5&173CBDFC&0&1
I'm fairly certain thes are not what it should be showing.
Also, USB wiring should work. It's the same as the pro-micro and qduino mini and it's on a PCB, so...I'm not sure what else to check as far as that goes.

Glad to hear the ATmega runs.  The VID/PID are obviously wrong, so if you're sure you loaded a suitable bootloader it's probably time to include the schematic in your post and carefully check all the soldering.

Don't know that it is definitively causative of your problem, but seems like you may have forgotten the 1uF capacitor between UCap and Ground.

That was it! Apparently UCap is needed for the 3.3V board to talk with 5-volt USB system. Thanks A TON! That really saved my sanity there!

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!


text:
Read Audio Data in Real-time over 3.5mm Stereo Cable
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 to the Arduino. As is commonplace, this cable has a Tip, Ring, and Sleeve 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:

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 to attach a DC-blocking/DC-bias circuit to the signal source before driving it into an analog pin on the Arduino.

While not impossible, an ATmega based Arduino is a relatively non-optimal choice for this project.  With three output colors, you can probably do more optimal mapping than an FFT - it sort of sounds like you're trying to imitate an old op-amp "color organ"

@ChrisStratton I've never heard of an op-amp color organ. Three output channels*, so that could be any number of colors depending on the intensity of each channel. Could expand on what makes the Arduino non-optimal (what should I do to make it better)? Processing power / resource constraints are hard to fix for any microcontroller.

The ATmega has a very slow, limited resolution ADC, little memory, and slow processing compared to even cheaper modern alternative MCUs.  You really should spend some time researching color organs.  You have only 3 color controls, so if you are going to do color mixing, you are going to need to define some algorithm to map frequency components to color mixes.  It will probably be easiest to play with that on a PC, reading audio files and running it through your evolving algorithm until you are showing satisfactorily pretty colors on the screen.  Only then worry about the MCU.

@ChrisStratton I see where you're going with color organs. It seems like a color organ takes the average the power over three selected frequency sub-bands in the acoustic range & dim a red, blue, or green light based on those average powers. I'm doing the same thing, except for an RGB LED strip has a R, G, and B channel. So simply, if I supply three PWM signals generated according to those average powers, the R, G, and B channels mix at the LED and produce some other color (for instance, bright white if all channels are provided with the same PWM signal).

@dda - please don't make edits which decrease the quality of a post.  The original version was superior to yours, and so has been restored.

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!

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!

The real problem at hand is: how do I sample the analog audio signal at the analog pin at 44.1 or 96 kHz? Because the ADC has a maximum sampling frequency of 10 kHz. At the moment, the key seems to be something called an "interrupt call" on a timer (this page seems to explain that, but I haven't wrapped my head around what it's doing yet). I'm having trouble identifying where the sample rate is being scaled up, though...

@VladislavMartin - you can do slightly better, but an ATmega is neither intended nor able to sample high fidelity audio.  You'll have to pick a different part if you really want to do that.

No.  The ATmega's ADC is multiplexed.  Using multiple channels doesn't make it faster, because it's not 4 ADC's, it's 1 ADC dividing its capabilities to cover 4 inputs in turn.  That idea only works on parts that have multiple ADC's - but many of those are already fast enough for Audio when using just one.

@ChrisStratton Are you sure it's not able to sample audio? I'm writing up an answer that uses Timer1 for interrupt handling to effectively increase the ADC's sample rate. According to Atmel doc, this is perfectly acceptable: "Recommended maximum ADC clock frequency
is limited by the internal DAC in the conversion circuitry. For optimum performance, the ADC clock should not exceed 200kHz. However, frequencies up to 1MHz do not reduce the ADC resolution significantly."


text:
Which Timer can I use on the Arduino/Genuino Micro?
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.

You are using those timers to generate periodic calls so the simplest would work. Aka the use of a 16 bit timers adds no value.

Only Timer0 is used for millis and micros, just as with the Arduino Uno and Mega 2560.
Timer0 is used in "wiring.c".
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".
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.


text:
Pressing reset button restarts program only seconds latter
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

(1) Might “about 5 seconds” be only a second or two?  That is, did you measure the delay with a timepiece, or just estimate it offhand? (2) If this occurs with only one sketch, please edit your question to include a Minimal, Complete, and Verifiable copy of the sketch, so we can identify the programming error that is causing the problem. (3) If it happens with several different unrelated sketches,  please edit your question to include a list of them.

A few seconds sounds like normal and I don't think you can reduce the time.  If you explain why you want it to be quicker it might be possible for someone to suggest a much quicker alterative.

The bootloader has to run for a few seconds before your sketch does. If you don't want that then delete the bootloader and use a hardware programmer.

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.

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.


text:
Can upload programs to ESP8266 with Arduino Nano but not run them
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

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.

you need to go rx-tx, tx-rx...

Already tried... Still no luck.

I believe it has a program mode and a run mode (it has on some other ESP versions). You could Google around on that a little

I know that grounding GPIO0 puts it into flashing mode. I have also tried other combinations pulling other pins high and low but nothing has worked.

Possible duplicate of ESP8266 proper power circuit for avoid reset issue in that until the improper use of the Arduino's 50 mA rated 3.3v regulator to power the ESP's up to ~170 mA current requirement is corrected, it's not worth considering anything else.

you need to go rx-tx, tx-rx Actually in this case the Nano is only being used as a USB-serial adapter to directly program the ESP8266 and so RX-RX, TX-TX is the correct wiring.

I have tried to input AT into the Arduino IDE and I get no response. When you upload to the ESP8266 via the Arduino IDE the AT firmware is overwritten. "input AT into the Arduino IDE" is a very imprecise statement. Do you mean the Serial Monitor? Please make a better effort with your questions, otherwise they will be closed.

Sorry, yes I mean the serial monitor and this is even after erasing the ESP-01 then flashing AT firmware back to it with esptool.

I'd also say putting 5V (TX) into a 3.3V (RX) such as ESP-*-s might not be the best idea. Please use a level converter. The opposite is okay as 3.3V is detected as HIGH on an Arduino.

I have tried using a voltage divider with a 1k resistor and a 2.2k resistor but it makes no difference.