body:
I have set up 2 DHT22 sensors and 2 BMP280 sensors with an Arduino Uno SMD R3 board. The DHTs are working fine and are outputting correct temperature and humidity values to the Serial monitor. The BMPs are connected via I2C and do not.
I assigned the standard address (0x77) to one of them, and set the other to 0x76 by placing a jumper between GND and SDO. However, in the Serial output, both devices are detected and connected (this is checked in the `loop()` by using the Wire library), but only one of them (0x77) shows up with the correct pressure and temperature. The other address is recognized, but it seems not to be able to transmit data.
There are already pullups on the SCL and SDA lines to the +5V terminal.
Both BMP280 sensors work, by reversing their position, it is still address 0x77 that works, however, once I change the jumper, neither works. Might this be simply an issue with the breadboard or is there an address conflict somehow? Also, I have tried several values for the pullup resistors (4.7 kOhm, 10kOhm and 140kOhm), they all seem to have the same effect.

The output looks like this:

    Found address: 118 (0x76)
    Found address: 119 (0x77)
    Found 2 device(s).
    DHT22_1: hum1 = 28.00 %, temp1 = 24.80 C
    DHT22_2: hum2 = 24.80 %, temp2 = 24.70 C
    BMP280_0x77: t_77 = 25.83 Cp_77 = 100039.43 Pa
    BMP280_0x76: t_76 = 0.00 Cp_76 = 0.00 Pa

and I used the following code:

    #include <DHT.h>
    #include <Wire.h>
    #include <Adafruit_Sensor.h>
    #include <Adafruit_BMP280.h>

    // Constants
    #define DHTPIN_1 5     // pin for data
    #define DHTPIN_2 4
    #define DHTTYPE DHT22   // what type of sensor: DHT 22  (AM2302)

    DHT dht1(DHTPIN_1, DHTTYPE); // initializes sensor
    DHT dht2(DHTPIN_2, DHTTYPE); // initializes sensor

    Adafruit_BMP280 bm77; // I2C
    Adafruit_BMP280 bm76(0x76); // I2C

    // Variables
    int chk;
    float hum1;  // stores humidity
    float temp1; // stores temperature
    float hum2;  // stores humidity
    float temp2; // stores temperature

    // --- Setup --- //
    void setup()
    {
      delay(1000);
      Serial.begin(9600);
      dht1.begin();
      dht2.begin();
      bm77.begin();
      delay(500);
      bm76.begin();
    }

    void loop()
    {
      byte count = 0;
      Wire.begin();
      for (byte i = 1; i < 120; i++)
      {
        Wire.beginTransmission (i);
        if (Wire.endTransmission () == 0)
          {
          Serial.print ("Found address: ");
          Serial.print (i, DEC);
          Serial.print (" (0x");
          Serial.print (i, HEX);
          Serial.println (")");
          count++;
          delay (1);  // maybe unneeded?
          } // end of good response
      } // end of for loop
      Serial.print ("Found ");
      Serial.print (count, DEC);
      Serial.println (" device(s).");

      hum1 = dht1.readHumidity(); // reads and stores hum
      temp1= dht1.readTemperature(); // reads and stores temp
      hum2 = dht2.readHumidity(); // reads and stores hum
      temp2= dht2.readTemperature(); // reads and stores temp
      // serial output commands

      delay(2000); // reading needs to be delayed by at least 2000ms
      Serial.print("DHT22_1: ");
      Serial.print("hum1 = ");
      Serial.print(hum1);
      Serial.print(" %, temp1 = ");
      Serial.print(temp1);
      Serial.println(" C");

      Serial.print("DHT22_2: ");
      Serial.print("hum2 = ");
      Serial.print(hum2);
      Serial.print(" %, temp2 = ");
      Serial.print(temp2);
      Serial.println(" C");
      delay(500);
      Serial.print("BMP280_0x77: ");
      Serial.print("t_77 = ");
      Serial.print(bm77.readTemperature());
      Serial.print(" C");
      Serial.print("p_77 = ");
      Serial.print(bm77.readPressure());
      Serial.println(" Pa");
      delay(500);
      Serial.print("BMP280_0x76: ");
      Serial.print("t_76 = ");
      Serial.print(bm76.readTemperature());
      Serial.print(" C");
      Serial.print("p_76 = ");
      Serial.print(bm76.readPressure());
      Serial.println(" Pa");

      Serial.println();

    }

The setup I used. red = +5V, black = GND, green = SCL, blue = SDA, yellow = DHT data lines, white = jumper between GND and SDO. Pictured is a different model of the BMP series, but in my case, I used the BMP280 and did not connect the other connectors. Edit: seems to be missing in the diagram, but of course, the positive and ground terminal are connected to the breadboard.

[![breadboard][1]][1]

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

title: Second I2C address not accepted

Answers: 1

body:
According to the datasheet:

> SDA and SCL are not pure open drain. Both pads contain ESD protection diodes to VDDIO and GND. As the devices  does  not  perform  clock  stretching,  the  SCL  structure  is  a  high-Z  input  without  drain capability.

I'm not sure if this affects the operation with two together as you have them, but I must say that your debugging seems very thorough. :)

The words "without  drain capability" are a bit worrying. There is a [thread on the Adafruit forum](https://forums.adafruit.com/viewtopic.php?f=22&t=90509) about this, where they suggest an [I2C multiplexer](https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout/overview).

On [my page about I2C](http://www.gammon.com.au/i2c) I have a schematic and code for a simple multiplexer using the CD4051 multiplexer chip (reply #11).

The schematic is this:

[![Multiplexed I2C][1]][1]

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


body:
I want to drive numerous chips (L9823, TLC5925, ADG1414, MCP23S08) from an Arduino Micro as well as read input from analog pins connected to momentary buttons, toggles, potentiometers and such. The chips and input controls will be on various boards connected to the Arduino using ribbon cables.

The current idea is to have two sets of 8 pin FFC connectors with the following pins:

    FFC digital "bus" conductors:
    --
    SCLK
    VL
    SDI
    RST
    SDO
    LE3
    LE2
    LE1

The clock, VL (5V), SDI and SDO will be shared by both connectors but I still need 6 latches (which can also be commandeered for an interrupt or analog input) and 2 reset pins. This will allow me to run up to 3 types of chips per connector (minus latches used for something else).

I will also have a third 8-conductor FFC connector for 7 analog inputs (the eighth conductor is 5V analog ref).

So my question is, does anyone see any holes in this strategy? I don't think I'm going to try to even breadboard something like this. PCB fab is so easy now (and the first run is always wrong anyway) so I'm just going to make the boards and go from there.

So I just need to settle on what pins to use. Here is a diagram of the Arduino Micro:

[![Arduino Micro][1]][1]

So the connectors could use pins:

    Connector 1 - Digital I/O:
    --
    SCLK SCK
    VL   5V
    SDI  MOSI
    RST  11
    SDO  MISO
    LE3  A8
    LE2  A7
    LE1  SS

    Connector 2 - Digital I/O:
    --
    SCLK SCK
    VL   5V
    SDI  MOSI
    RST  13
    SDO  MISO
    LE3  A9
    LE2  7 (Arduino INT)
    LE1  5

    Connector 3 - Analog Inputs:

    5V
    A0
    A1
    A2
    A3
    A4
    A5
    A6

A10 and A11 are reserved for other purposes as well.

Does this look ok?

UPDATE 1:

I have updated the text of this question to consider many of the great comments. The changes include:

 1. Share MISO and MOSI
    between connectors. Not sure why I thought I needed to use separate
    ports for the different connectors. SLCK, MISO and MOSI should
    indeed be shared by both connectors.
 2. Moved 5V to be in between
    SCK and MISO and moved RST to be in between MISO and MOSI. The idea
    is that the low impedance of these lines will shield from capacitive
    crosstalk described by Majenko. The connectors are 1mm pitch which
    isn't terribly small so hopefully this will not be an issue. It does
    make routing a little harder since the data pins tend to be next to
    each other but the same bus is going to connect to multiple boards
    in a daisy chain fashion so capacitive crosstalk could definitely be
    an issue. Fortuntely things don't have to run really fast since
    everything is ultimately for interfacing with humans who are
    relatively slow.

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

title: Driving numerous chips from 2 separate SPI connectors w/ Arduino Micro

Answers: 2

body: The MOSI (Master Out Slave In) and MISO (Master In Slave Out) will be much better for your SPI pins. Your SDI (Slave Digital In iirc) will equate to MOSI and your SDO (Slave Digital Out iirc) will equate to MISO. Those are the hardware SPI pins and will be much better than trying to emulate SPI in software.

body:
The micro only has one SPI bus. It is SCK/MISO/MOSI. You may *want* a second one, but you don't *have* one.  You can't magic one up out of thin air.

You *could* emulate one in pure software (bit-banging) but it won't be anywhere near as efficient as using a real hardware one.

Why do you feel you need to have two independent buses anyway? What are you wanting to achieve that you can't achieve with a single shared bus? That same bus can quite happily appear on multiple connectors.

One thing to note with your strategy: Ribbon connectors and SPI don't mix well together.  There is a lot of crosstalk and capacitance in a ribbon cable that high speed serial communication really doesn't like.  If I had to use ribbon cable for SPI communication for anything longer than a couple of inches I would use twice as many connections and interleave ground between each signal.  That is what the ribbon cables for later IDE drives in PCs used to get higher speed, more reliable, communication down ribbon cables.


body:
I have bought a 7" LCD (`TFT01-7`) and a shield to make it work with arduino mega (http://www.elecfreaks.com/store/lcd-tft01-mega-shield-v10-p-214.html), but when I upload my code to the arduino and plug my LCD to the shield the arduino get overheated and the LCD lose power and I don't know why even when I power my arduino with external 9V 2A adapter, I even tried uploading an example from the library but it does the same, I used to work with the same code and the same shield but with 5" LCD `ITDB50` and I didn't have this problem before, how can I fix this?

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

  [1]: http://www.elecfreaks.com/wiki/index.php?title=7.0"_Width_800*480_TFT_LCD_Module
  [2]: https://i.stack.imgur.com/qVrWA.png

title: arduino mega overheat when connected to TFT 7" and TFT shield

Answers: 1

body:
7" LCDs need a lot of current. They need it for the back light.

That current comes from the 5V pin.  That 5V pin is supplied by a linear regulator that has limited current capacity.  As you draw more current it gets hotter and hotter and eventually shuts down.

You will need to power your LCD screen with another external 5V source. The best solution may be a powerful (2A) phone charger (USB) which you then plug direct into the USB port of the board thus bypassing the weak regulator.


body:
I want to have a define from my sketch be picked up by a library.
Here is a similar question for references: https://arduino.stackexchange.com/questions/21931/using-define-and-multiple-classes

I have a CI server that compiles my arduino sketchs on commmit. It pulls all my personal libs from an other repository and compiles the sketch using arduino-builder.

Now i want it to also make a debug build. (Some of my library's have debugstatments in them i enable using a #define debugsomething.

Is there any way i can get the compiler to pickup the #define in the sketch or am i better off making a very complex build script that modifies the headers between builds?

title: Visibility of #define between sketch and library

Answers: 1

body:
You need a common place that the building of all the places can get the definition from.

That isn't the sketch. The sketch is one of the things that would have to look at that common place.

That can either be a single shared header that everything else (that needs it) includes, or it can be a `-D` flag added to the compilation command.

For instance, adding:

    -DDEBUG=1

to your compilation command is the same as adding

    #define DEBUG 1

to every single file you compile.


body:
I'm using the code off of the sparkfun website HX711 hookup guide (https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide#arduino-code) to attempt to create a scale.

Currently I have output data of weight in the serial monitor - is there an easy way to then graph this data with regards to time? I've spent an hour fooling around with Processing and googling, but haven't had any luck.

Thanks!

title: Graphing force sensor data routed through HX711?

Answers: 1

body: Include the Time library in your sketch, then print the time and your sensor output as a comma separated list. Your output to the serial monitor can then be written to .csv file using PuTTY, which you will need to download in order to collect data (I used online tutorials to figure out writing to a file with PuTTY). Once in a .csv, you can open the file in Excel to graph the data.


body:
I am working with STPM10 energy metering chip (evaluation board) and I want to read the data from 8 internal registers of the chip each containing 32 bits. [![This is the 8 internal registers of the chip][1]][1]

The datasheet of the STPM10 chip suggested to have a simplex synchronous SPI where the MOSI of the Arduino is not connected to any pin on the energy chip. Instead they provided a timing diagram to switch from reading and writing on the energy chip.

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

  [1]: https://i.stack.imgur.com/guhxa.jpg
  [2]: https://i.stack.imgur.com/pkw7h.jpg

After the t5, datasheet stated that we should apply 32 serial clocks per data record and up to 8 data records can be read this way. My problem is how to apply 32 serial clocks to the chip.  Is the Serial clock on the Arduino SPI automatically activated after `SPI.begin()` ? If not, how can I start the serial clock? By the way, this is the code I've written:

    #include <SPI.h>

    SPISettings settingA(32000000, LSBFIRST, SPI_MODE0);
    const byte SYN = 8;
    void setup() {
      Serial.begin(9600);
      pinMode(SYN,OUTPUT);
     /*Initializes the SPI bus by setting SCK, MOSI and SS to outputs
      Pulling SCK, and MOSI low, and SS high */
      SPI.begin();
      SPI.beginTransaction(settingA);

      }

    void loop() {
      //0----->t1
      digitalWrite(SS,HIGH);
      digitalWrite(SYN,HIGH);
      delay(500);
      //t1----->t2
      digitalWrite(SYN,LOW);
      delayMicroseconds(1000);
      //t2----->t3
      digitalWrite(SYN,HIGH);
       delayMicroseconds(0.035);
      //t3----->t4
      digitalWrite(SS, LOW);
      delayMicroseconds(0.035);
      //t4----->t5
      digitalWrite(SYN, LOW);
      delayMicroseconds(0.035);
      //t5---->t6
      digitalWrite(SYN, HIGH);
      delayMicroseconds(0.035);

      byte d1 = SPI.transfer(0x00);
      byte d2 = SPI.transfer(0x00);
      byte d3 = SPI.transfer(0x00);
      byte d4 = SPI.transfer(0x00);
      byte d5 = SPI.transfer(0x00);
      byte d6 = SPI.transfer(0x00);
      byte d7 = SPI.transfer(0x00);
      byte d8 = SPI.transfer(0x00);
      byte d9 = SPI.transfer(0x00);
      byte d10 = SPI.transfer(0x00);
      byte d11 = SPI.transfer(0x00);
      byte d12 = SPI.transfer(0x00);
      byte d13 = SPI.transfer(0x00);
      byte d14 = SPI.transfer(0x00);
      byte d15 = SPI.transfer(0x00);
      byte d16 = SPI.transfer(0x00);
      byte d17 = SPI.transfer(0x00);
      byte d18 = SPI.transfer(0x00);
      byte d19 = SPI.transfer(0x00);
      byte d20 = SPI.transfer(0x00);
      byte d21 = SPI.transfer(0x00);
      byte d22 = SPI.transfer(0x00);
      byte d23 = SPI.transfer(0x00);
      byte d24 = SPI.transfer(0x00);
      byte d25 = SPI.transfer(0x00);
      byte d26 = SPI.transfer(0x00);
      byte d27 = SPI.transfer(0x00);
      byte d28 = SPI.transfer(0x00);
      byte d29 = SPI.transfer(0x00);
      byte d30 = SPI.transfer(0x00);
      byte d31 = SPI.transfer(0x00);
      byte d32 = SPI.transfer(0x00);

      digitalWrite(SS,HIGH);
      digitalWrite(SYN,HIGH);
      delay(499);

      Serial.println(String(d4,BIN) + " " + String(d3,BIN) + " " +  String(d2,BIN) + " " +  String(d1,DEC));
      Serial.println(String(d8,BIN) + " " + String(d7,BIN) + " " +  String(d6,BIN) + " " +  String(d5,BIN));
      Serial.println(String(d12,BIN) + " " + String(d11,BIN) + " " +  String(d10,BIN) + " " +  String(d9,BIN));
      Serial.println(String(d16,BIN) + " " + String(d15,BIN) + " " +  String(d14,BIN) + " " +  String(d13,BIN));
      Serial.println(String(d20,BIN) + " " + String(d19,BIN) + " " +  String(d18,BIN) + " " +  String(d17,BIN));
      Serial.println(String(d24,BIN) + " " + String(d23,BIN) + " " +  String(d22,BIN) + " " +  String(d21,BIN));
      Serial.println(String(d28,BIN) + " " + String(d27,BIN) + " " +  String(d26,BIN) + " " +  String(d25,BIN));
      Serial.println(String(d32,BIN) + " " + String(d31,BIN) + " " +  String(d30,BIN) + " " +  String(d29,BIN));
      Serial.println(" ");

title: STPM10 using Arduino SPI communication

Answers: 2

body:
The STPM10 specification describes a SPI bus unlike any I have seen.  Apparently the STPM10 "SYN" line controls the direction of the "SDA" line.  As far as I know, there is no "SYN" line in a SPI bus.  As such I do not think a normal Arduino SPI library will talk to an STPM10.

A normal single port (MOSI and MISO combined) SPI slave would automatically switch between reading and writing bits.  When interfacing with a two port master (such as an Arduino) a resistor is used between the MISO and MOSI nets.

This is the best image I could find.  Ignore the chip names.  And substitute MOSI for SDO and MISO for SDI.  Note there is no "SYN" line in this SPI bus.

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

I'm showing this diagram as it appears the STPM10 is using a single line for both input and output data.

Because of the missing "SYN" line I do not think you can even use the SPI hardware in the Arduino's Atmel processor.  I think your only option is to create a SPI driver from scratch only using software.

I see where STMicroelectronics offers an evaluation software package that talks to the STPM10.  Guessing, it looks like they wrote it in National Instruments Lab View.  If you could get the source code for that it may provide hints on writing your own STPM10 driver.

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

body:
Like the datasheet says, its best if you implement writing in software and use the hardware SPI for reading. The steps for writing to the registers are as follows:

> 1. disable the SPI peripheral;
2. set MISO, SCLK and SS to be output;
3. set the pin which is connected to SYN to be output high;
4. activate SCS first and then SYN;
5. activate SCL;
6. apply a bit value to SDA and deactivate SCL;
7. repeat the last two steps seven times to complete one byte transfer;
8. repeat the last three steps for any remaining byte transfer;
9. deactivate SYN and the SCS;
10. enable again the SPI module;

In Arduino-speak:

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

    #define SCS 4  // define your own CS to have better control

    void setup(){
      pinMode(SS, OUTPUT);  //needed to use the SPI

      pinMode(SCS, OUTPUT);  // set SCS and SYN as output
      pinMode(SYN, OUTPUT);
      digitalWrite(SCS, HIGH);  // idle state
      digitalWrite(SYN, HIGH);
      SPI.beginTransaction(SPISettings(32000000, MSBFIRST, SPI_MODE3)) // mode 3, max read clock is 32mhz
    }

    void write_reg(byte addr, byte val){
      val = (val << 7) | (addr << 1);  // 6-bit addresses!
      SPI.end();  // disable SPI
      pinMode(MISO, OUTPUT);
      digitalWrite(SYN, HIGH);
      delayMicroseconds(10);

      digitalWrite(SCS, LOW);  // assert SCS and SYN
      digitalWrite(SYN, LOW);
      for (int i = 0; i < 8; i++){  // shift out a byte
        delayMicroseconds(10);
        digitalWrite(SCK, LOW);  // max clock is 100kHz
        digitalWrite(MISO, (val & 0x80) ? HIGH : LOW);
        delayMicroseconds(10);
        digitalWrite(SCK, HIGH);
        val <<= 1;
      }

      digitalWrite(SYN, HIGH); // deassert SCS and SYN
      digitalWrite(SCS, HIGH);

      SPI.beginTransaction(SPISettings(32000000, MSBFIRST, SPI_MODE3)); //restart SPI
    }

For reading, you use the hardware SPI like this:

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

    void read_regs(uint32_t data[], uint8_t len){  // an array to hold register data is passed
      digitalWrite(SYN, LOW);  // latching operation
      digitalWrite(SCS, LOW);
      digitalWrite(SYN, HIGH);

      uint32_t val = 0;
      for (int i = 0; i < len; i++){  // read the 8 32-bit registers into the array
        val = SPI.transfer(0);  // your 32 serial clocks
        val |= (uint32_t)SPI.transfer(0) << 8;
        val |= (uint32_t)SPI.transfer(0) << 16;
        val |= (uint32_t)SPI.transfer(0) << 24;
        data[i] = val;
      }

      digitalWrite(SCS, HIGH);  // deassert SCS
    }

    // Use the functions this way:

    uint32_t reg_data[8];  // array to hold read data, max is 8

    void loop(){
      write_reg(47, 1);  // set config bit 47
      read_regs(reg_data, 8);  // read all reg data into array

      for (int i = 0; i < 8; i++)
        Serial.println(reg_data[i], HEX);
    }

The connections are:

    Arduino MISO = SDA
    Arduino SCK = SCL
    Arduino D4 = SCS
    Arduino D5 = SYN

Each call of `SPI.transfer()` yields 8 serial clocks i.e. a clock for each bit, so 32 serial clocks is merely 4 `SPI.transfer()` calls. Your code is actually producing 32 x 8 = 256 serial clocks. I suggest you read up on SPI.

I didn't include some of the delays in the datasheet because `digitalWrite()` on an Uno takes about 5us which is more than enough for this case. Of course, the code is untested so...I've done most of your work already, almost feels like I should be getting paid or something...


body:
I'm building a [word clock][1] and its a grid of 20x20 letters, each with its own LED (I know, its absurd for just a clock). I've recently got the LED's on a strip. Its the WS2812B type, just like the neopixels. There are 3 rolls of 5m strips and a single 1m strip. When I tried to power the 1m strip, everything worked perfectly and all looked quite lovely. But when I tried the 5m strip (just one of them), this happened: https://www.dropbox.com/s/5w1lok6wa7dfvzd/IMG_0046.MOV.mov?dl=0

If you didn't see the video I recorded of it, for a second or two after powering the arduino (uno) on, it works as expected but not long after it all stops the colors and fades to red, sometimes it just instantly jumps to it, like the second time in the video. I don't know what happened but all I can guess is that the arduino is not able to power the strip properly. Any ideas on what I should do to be able to power a total of 16m of these strips?

  [1]: https://www.google.co.nz/search?q=word clock&safe=active&hl=en&biw=1920&bih=1089&site=webhp&tbm=isch&tbo=u&source=univ&sa=X&sqi=2&ved=0ahUKEwistvr-qbPMAhWIFJQKHTd6D4sQsAQIGQ

title: Arduino struggling to power a large LED strip

Answers: 2

body:
WS2812 use around 1mA when they are off. So that's already 400mA with no LED lighted. USB can supply around 500mA. So you only have 100mA available.

Each led package has three colored leds inside; Red, Green and Blue. Every color will use around 20mA when fully turned on.

So you can only turn on 5 colors at full brightness at 500mA.

Using a 2.5A supply you could go up to 105 colors, or 35 leds full white.

This would be more than enough for a word-clock, as most leds will be off.

body:
You're trying to power a consumer which draws more current than the arduino could provide.

To fix this, you need an transistor and a ~5V battery (e.g. 4.8V NiMh, or a stronger batteries plus suitable resistors, to not burn out the leds)

Look at this (awesome paint) shematic to understand the principle.
The arduino will switch the transistor through S2 which then closes the circuit.
Through S1, the arduino can set the LEDs values.

Note that for savety, you should also set a diode between S1 and the LEDs, so the battery cannot burn out your arduino, if the LED strip is cheap made.

The reason why the behavior at your setup differs might be because of a capacitor on the arduino which works similar to a batterie (With extreme little capacity).
The capacitor might provide enough power to run the LEDs for a very short periode. After discharging, the capacitor needs some time to recharge and thus it may vary in effect.

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

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


body:
I have two arduinos (one uno and another nano) with NRF24L0 modules attached to both and they are communicating between each other. All good.

However, I have a load of different ones and have switched them with the working receivers to test them but they just refuse to work despite the pinouts being correct.

Does the pinout vary between manufacturers or something else perhaps? What really perplexes me is that some of the modules I've tried are brand new (just taken out of the antistatic)

I have followed https://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/

Any help would be really appriciated. Thanks

title: NRF24L0 wireless modules

Answers: 1

body:
I was having the same kind of problems (even with new modules) when supplying them by mistake with 5v instead of 3,3V. It even happened that the system was working fine for days after the communication problems due to wrong power supply started to appear.

Also many people have reported similar problems(sometimes communicating, sometimes not) with this module due to poor built-in decoupling especially when using relatively long cables between arduino and module. Just to make sure, put a decoupling capacitor near the module's power and ground pins.

(this is more of a comment but I cannot comment due to reputation.)


body:
Actually, i would like to control   12 motors of AX-12 using Arduino .. I could control just 2 motors. However when i send a command to the 12 motors they don't move and one or 2 of them move randomly!

 could you please help me to find solution of that ???

note :

I am using an external power with 12 Volts and 5 amp maximum

title: Controlling dynamixel AX12 by Arduino

Answers: 0


body:
I have a shield with a SIM for `GSM/GPRS` communications and `GPS module`.
As visible in top-left corner its name is "SIM908-C EVB v1.0 designed by UNV".

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

I found some basic information on Arduino forum but they are discordant about baud rate so I tried different configuration: [https://forum.arduino.cc/index.php?topic=302982.0][2]

I tried to use several libraries (such as `sim900` or `tinyGPS`) for GPRS communication or simply for getting GPS position, but without results. Shield not respond to serial commands at any baud rate.

Connections that I used:

    shield <--> aruino mega
    GPRS TXD <--> D2
    GPRS RXD <--> D3
    GPS TXD <--> D4
    GPS RXD <--> D5
    GND <--> GND
    5V <--> VCC_MCU

Obviously I set D2..D5 in library according to TX/RX pins on shield.

I also tried with a simply code to send AT commands and... no results again.
Here is the code:
<!-- language-all: lang-cpp -->

    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(2,3);

    void setup() {
        Serial.begin(115200);
        Serial.println("Begin");
        mySerial.begin(115200);
    }

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

Shield seems to be well powered and connected to SGM net. Infact:

- power led: is on

- ring led: is on

- net status: blinks one time in three seconds

Has someone used this shield? What is a good library to use?
Every help is very appreciated.

  [1]: https://i.stack.imgur.com/ZGKlT.jpg
  [2]: https://forum.arduino.cc/index.php?topic=302982.0

title: How to use SIM908-C BY UNV shield

Answers: 0


body:
Currently, I am using a Bluetooth shield, HC-05, which is working perfectly but there are two problems:

 - Only one person can connect to Bluetooth  at a time.
 - I have to be in a specific place to be able to control the lights.

I want to be able to control everything from anywhere in the world. I've thought about using an Ethernet Shield, but I'd prefer using a Wifi Shield if it can do the task.

title: Will I be able to control stuff from anywhere in the world if I use a wifi shield like ESP8266?

Answers: 4

body:
The WiFi shield connects your Arduino to your local network. What you then do with that network is entirely up to you.

Yes, it is possible.

Is it easy, though? Well, if you have to ask the question then for you it won't be easy. You have to know how networks work for a start. Routing, port forwarding, client-server models, etc.

body:
answer on your comment on Majenko's answer:
(cannot comment due to reputation)

 * build a simple web server on your device and make sure it is accessible from a local network node (e.g. a PC).To do this open from a web browser the page `ip:port` where `ip` is the ip assigned to arduino (usually from your router's DHCP service) and `port` is the port which your web server listens to. This is configured in your arduino code. For an arduino Wifi shield you can find a tutorial for this step [here](https://www.arduino.cc/en/Tutorial/WiFiWebServer)
 * Now you have to set up port forwarding. This means that when somebody from the internet sends a request on your router, the router will forward this request on your arduino and not on another node on your local network. The nodes on your local network are individually recognized by their IP address. Port forwarding is configured per port, so you must set up port forwarding from a specific in-port to a specific ip,local-port combination. For example if your arduino has been assigned ip 192.168.2.10 and your web server listens on port 80, you can forward all requests from port 8080 to 192.168.2.10:80. This means that every request comes from the internet on port 8080 on your router (internet side) will be forwarded on your local node on ip 192.168.2.10 and port 80. Note that for simplicity in-port and out-port can be the same and they usually are. Port forwarding is configured in your router's menu and the exact procedure is different for every modem. Your best bet is to search google for your modem's model + `port forwarding`. If you succesfully configure this, then you will be able to load web server's page from a node outside your local network by visiting ip:port where `ip` is your router's internet ip and port is the aforementioned in-port. A simple page to see your internet ip is [this](http://checkip.dyndns.org/).

These are basically the main steps to have access from internet. Further improvements could be:

 * solving dynamic IP issue (in order to access your arduino, you have to know your router's internet ip which can change by your ISP anytime. Buying a static IP or setting up a dynamic DNS solves this issue)

 * turning your web server to _non web_ server (more advanced topic).

body:
If you haven't already, take a look at [Blynk.cc][1]'s website. Blynk provides a (drag-and-drop configurable!) smartphone/tablet app and a number of skeleton programs for many platforms and interfaces including, of course, the Arduinos.

In brief, your Arduino program can report data to their server, and the smartphone app can read and display that, as well as send control signals back to your board. They make it simple to accomplish basic things and quite easy to expand it to do more. The ESP8266 is a good choice for a web interface, especially if you're using an Arduino Uno or other Atmega328p-based platform, because it takes about the least amount of the MCU's limited resources of any of the compatible network interfaces.

Because your Arduino program will be configured as a network client you will avoid the hassles and potential security issues of configuring your local network to allow access to internal server from outside. The Arduino sketch opens an outboud connection to their server, just as a web-browser would, so you won't need to "poke holes" in your router's firewall to let in your client and anyone else that wants to mess with your stuff.

(Note: I have no connection with them, but I think they have a strong platform for Internet of Things hobbyists and I use their stuff.)

Update:
Blynk supports Arduino WiFi, WiFi 101, CC3000, and ESP8266 w/original (AT) firmware. This device (Atmega328p with ESP8266) is logging temperatures from 3 DS18b20 thermo sensors to Blynk as I type this:

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

  [1]: http://www.blynk.cc/
  [2]: https://i.stack.imgur.com/AO7tk.jpg

body:
It is definitely possible to control anywhere from the World where internet is available.

As @forivaras noted, there are a few accidental complexities involved in the network setup. It is nothing specific to Arduino, these come from the fact how Internet works nowadays.

For start, I suggest using an ESP8266 module (instead of any other solution), which is connecting to a readily available 3rd party server (such as dweet.io and visualize with freeboard.io, or Adafruit IO, or IFTTT).

In fact, you don't need the Arduino at all. The ESP8266 is a way more powerful than an Arduino, and yuu can program it as if it would be an Arduino plus Wifi.

So the hardware comes for less than $10, and you can find ready made howtos on the web such as:
https://learn.adafruit.com/home-automation-in-the-cloud-with-the-esp8266-and-adafruit-io/introduction

This ensures a smooth start! Have fun :)


body:
I am in need of a sentinel value to use to assign to a double variable initially.
0 or -1 won't work because these values are valid values in my computation and I need a value that will stand out.

Possible choices are:

 1. Maximum double value
 2. Minimum double value
 3. NAN (I would also need a method to check is_nan as well)

How can I accomplish this in the Arduino language?

title: Max double value or NAN as a sentinel value?

Answers: 1

body:
This is a matter of personal preference. I like NAN because it is almost
always obvious it cannot be a valid value.

You can test for the value being NAN with
[`isnan()`](http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html#ga468be9ed380771eca5a18e812b2470d4).


body:
I'm making a basic "door open" detector that, when a door is opened, it turns on an LED and then sounds an alarm via a piezo.

This is controlled via a 5v Adafruit Trinket.

Is a 9v battery the correct thing to power this with, if the goal is to change batteries as infrequently as possible?

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

Here's the code, incase that's relevant.

<!-- language: c -->

    #include <elapsedMillis.h>
    elapsedMillis timeElapsed;

    const int switchPin = 2;
    const int ledPin = 1;
    const int piezoPin = 0;
    const uint32_t openLength = 5 * 1000L; // X seconds
    int notes[] = {862,294,730};

    void setup() {
      pinMode(switchPin, INPUT);
      pinMode(ledPin, OUTPUT);
      pinMode(piezoPin, OUTPUT);
      digitalWrite(switchPin, HIGH);
    }

    void loop() {
      if(digitalRead(switchPin) == LOW){
        digitalWrite(ledPin, LOW);
        timeElapsed = 0;
      } else {
        digitalWrite(ledPin, HIGH);

        if (timeElapsed > openLength){
          for (int n = 0; n < 200 ; n++){
            beep(notes[random(0,2)]);

            if(digitalRead(switchPin) == LOW){ break; }
          }
        }
      }
    }

    void beep(int delayAmount)
    {
      for (uint16_t t = 0; t < 30*1000/2; t += delayAmount)
      {
        digitalWrite(piezoPin,HIGH);
        delayMicroseconds(delayAmount);
        digitalWrite(piezoPin,LOW);
        delayMicroseconds(delayAmount);
      }
    }

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

**UPDATE:** I had a 9V plugged in to this for about 3 days before it used all the power in 9V. Is that an issue w/ voltage on the battery (i.e. I should be using AA's instead of a 9V)? Or does that point largely to some other inefficiency w/ the code or hardware?

title: Is a 9v battery appropriate for a piezo and 1 LED?

Answers: 2

body:
A couple things to note:

- Get rid of the PWR LED on the Trinket so it's not always drawing current.
- Sleep the MCU whenever possible, only waking on interrupts.
- Converting 9V to 5V with an LDO (in this case, the MIC5225) implies a 55% efficiency, _max_, which isn't great. But at least the LDO has a low ground current.

Also, ask yourself if you really need a micro for this task.

If you want a ballpark for runtime, find the capacity of your battery, estimate your current draw, and see what your upper bound on runtime is.

body:
You can power the Trinket (ATTiny85) from as little as 2.7 volt. So you could power it by connecting 2 (or 3) AA-batteries directly to the 5V pin.

Using a 9V battery means you would "throw away" 4 of the 9 Volts to get 5Volt. So you'd waste almost half of the capacity of the battery.

Also a 9V battery only has around 500mAh, where as an AA battery has 2500mAh.


body:
I am trying to replace a device which used a FTDI chip (http://www.ftdichip.com/Drivers/D2XX.htm) to get USB to serial. I need some more code on the chip, so I want to use an arduino mega 2560 instead. However, there is quite a lot of software which talks to the FTDI-based solution, some of which is not maintained by myself.

Can I write a program for arduino mega which makes it look to the PC software like I am still a FTDI chip? I am somewhat concerned, because the FTDI requires special drivers, so any software will try to use this driver to connect to the arduino, which does not have a chip that is native to the d2xx driver.

Best,
Alex

PS: If I am not mistaken, arduino used those FTDI chips in the past, but switched to ATmega8u2 for arduino UNO, and to ATmega16U2 for arduino mega 2560.

title: Can d2xx connect to an arduino mega 250?

Answers: 0


body: I am trying to use a DS1307 (from Sparkfun, [BOB-12708](https://www.sparkfun.com/products/12708)) with an Arduino Leonardo. I have connected the SDA, SCL, GND, and 5V pins from the RTC to the Arduino. However, with a CC3000 WiFi shield on the Arduino, the I2C bus hangs. Specifically, `Wire.endtransmission()` hangs, called by `rtc.isrunning()`. I have confirmed that it works properly on the same Arduino without the WiFi shield. I am using the ds1307 RTClib example for testing it.

title: DS1307 RTC not working with CC3000 WiFi shield (I2C bus hangs)

Answers: 1

body:
It could be that the CC3000 interrupts are affecting the Wire library's behaviour since the latter is interrupt-driven itself.
Try disabling the CC3000 IRQ before calling `rtc.isrunning()` or any other RTC functions. First `#include "ccspi.h"` in your sketch. Then place `WlanInterruptDisable()` before any `RTClib` function call, and then `WlanInterruptEnable()` after the RTC function returns.

Even if this works, it may affect the functionality of the CC3000, since it increases the chances of missed interrupts. You can search for DS1307 libraries that employ SoftwareI2C instead such as [this one][1]. They should be better able to recover from the CC3000 interrupts.

  [1]: https://github.com/kamermans/SoftDS1307RTC


body:
I just bought a new Intel Edison and flashed the newest Yocto 3.0 image. I uploaded an Arduino program from the Arduino ide which just constantly prints out numbers to serial.

After uploading the code, it works. After I unplug it and plug it back in and wait 2 minutes for it to power on, I open the serial connection and the Edison does nothing like I never uploaded anything.

After some research I found it is a problem with the firmware version 2.5 so I tried 2.1. I tried 2.1 and it still doesn't work. Am I doing anything wrong?

I am using the mini-breakout.

title: Intel Edison Program Deleted After Power Off

Answers: 1

body: I'm having a bunch of problems like this.  I went back to 2.1, and that works, but your sketch can't have any code that uses Serial.  Serial1 is fine, but not Serial, or else the board hangs and your sketch won't autorun when you aren't connected via USB during reset.


body:
I'm trying to make a basic calculator with the Serial monitor but it doesn't seem to work.

    int a;
    int b;
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
    }

    void loop() {
      // put your main code here, to run repeatedly:
      if (Serial.available()) {
        Serial.println("First Number: ");
        a = Serial.read();
        Serial.println("Second Number: ");
        b = Serial.read();
        Serial.println(a + b);
      }
    }

title: Simple Calculator

Answers: 1

body:
[Serial.read()][1] reads in only the first byte of the data from the serial.This is not what we want, We everything that the user has entered to be treated as an Integer and then read it into the variables. You should use [Serial.parseInt()][2] for the job.

See the modified program below:

    int a;
    int b;
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
    }

    void loop() {
      Serial.println("Enter the First number");
      while(!Serial.available()); // wait till the user has entered something
      a = Serial.parseInt(); // treat what the user has entered as an Integer and read the whole number
      Serial.println("Enter the second number");
      while(!Serial.available());
      b = Serial.parseInt();
      Serial.println(a+b); // Print the sum
    }

  [1]: https://www.arduino.cc/en/Serial/Read
  [2]: https://www.arduino.cc/en/Serial/ParseInt


body:
This is a mini project of mine, which is to be implemented in another.
Here, I'm trying to make arduino output numbers in the serial window based on the diff. buttons pressed(there are four of them in my case).
What I want:

 - the initial array is 0000.
 - if I press button one, then button three, the array should be 1010
 - if I press button one two times, and button 4 three  times, the
   resultant array should be 2003......and so on.you might have got what
   I'm trying to do here.   the problem is , all I'm getting is 0000,
   ALL THE TIME.

My code is below, and I'm a newbie, so any corrections(+advice?) given would be greatly appreciated.
(Also I don't know where to print the output :P I did it in `loop()` so it keeps on printing it :P)

    CODE:

    //the buttons:

    const int b1=8;
    const int b2=9;
    const int b3=10;
    const int b4=11;
    //variables to store previous button press and currend button press , used to eliminate switch bouncing
    boolean pb1=LOW;
    boolean cb1=LOW;

    boolean pb2=LOW;
    boolean cb2=LOW;

    boolean pb3=LOW;
    boolean cb3=LOW;

    boolean pb4=LOW;
    boolean cb4=LOW;

    //variables to store numbers:

    int w=0;
    int x=0;
    int y=0;
    int z=0;

    int var_array [4]={w,x,y,z};

    void setup() {
      // put your setup code here, to run once:
      pinMode(b1,INPUT);
      pinMode(b2,INPUT);
      pinMode(b3,INPUT);
      pinMode(b4,INPUT);

     Serial.begin(9600);

    }

    boolean debounce1(boolean last)
    {
       boolean current=digitalRead(b1);
      if(last != current)
      {
          delay(5);
        }
          current=digitalRead(b1);
          return current;
      }

    boolean debounce2(boolean last)
    {
       boolean current=digitalRead(b2);
      if(last != current)
      {
          delay(5);
        }
          current=digitalRead(b2);
          return current;
      }

      boolean debounce3(boolean last)
    {
       boolean current=digitalRead(b3);
      if(last != current)
      {
          delay(5);
        }
          current=digitalRead(b3);
          return current;
      }

      boolean debounce4(boolean last)
    {
       boolean current=digitalRead(b4);
      if(last != current)
      {
          delay(5);
        }
          current=digitalRead(b4);
          return current;
      }

    void loop() {
      // put your main code here, to run repeatedly:
      cb1=debounce1(pb1);
      cb2=debounce2(pb2);
      cb3=debounce3(pb3);
      cb4=debounce4(pb4);

         if (pb1==LOW&&cb1==HIGH)
       {
          w++;
        }
        pb1=cb1;

        if (pb2==LOW&&cb2==HIGH)
       {
          x++;
        }
        pb2=cb2;

        if (pb3==LOW&&cb3==HIGH)
       {
          y++;
        }
        pb3=cb3;

        if (pb4==LOW&&cb4==HIGH)
       {
          z++;
        }
        pb4=cb4;

    for(int i=0;i<4;i++)
    Serial.print(var_array[i]);

    Serial.println();

    delay(500);

    }

title: Error in using buttons to input numbers!

Answers: 1

body:
In your C program all the variables including the array occupy their own space in memory.  In the line "int var_array [4]={w,x,y,z};" all you did was create 4 more variables (elements of the array var_array) in memory and initialized them to the values found in variables (w, x, y & z) in a different part of memory.  So when you incremented the variables in memory pointed to by the names w, x, y and z... you did nothing to the variables in memory pointed to by the elements of the var_array.

For example, in this program:

    main()
    {
     int w=0;
     int x=1;
     int y=2;
     int z=3;

     int var_array [4]={w,x,y,z};

     printf("w %d x %d y %d z %d\n",w,x,y,z);
     printf("var_array %d %d %d %d\n", var_array[0],var_array[1],var_array[2],var_array[3]);

     w += 1;
     x += 2;
     y += 4;
     z += 5;

     printf("w %d x %d y %d z %d\n",w,x,y,z);
     printf("var_array %d %d %d %d\n", var_array[0],var_array[1],var_array[2],var_array[3]);
    }

The output is this:

    w 0 x 1 y 2 z 3
    var_array 0 1 2 3
    w 1 x 3 y 6 z 8
    var_array 0 1 2 3

Notice how the array values do not change.

If you really want to do this, you need to make the array var_array an array of pointers and point each element to each variable (w, x, y & z).

For example:

    main()
    {
     int w=0;
     int x=1;
     int y=2;
     int z=3;

     int * var_array [4]={&w,&x,&y,&z};

     printf("w %d x %d y %d z %d\n",w,x,y,z);
     printf("var_array %d %d %d %d\n", *var_array[0],*var_array[1],*var_array[2],*var_array[3]);

     w += 1;
     x += 2;
     y += 4;
     z += 5;

     printf("w %d x %d y %d z %d\n",w,x,y,z);
     printf("var_array %d %d %d %d\n", *var_array[0],*var_array[1],*var_array[2],*var_array[3]);
    }

Now produces this output:

    w 0 x 1 y 2 z 3
    var_array 0 1 2 3
    w 1 x 3 y 6 z 8
    var_array 1 3 6 8


body:
I'm trying to use the FHT librairy from (http://wiki.openmusiclabs.com/wiki/ArduinoFHT). I used the example code provided on the link, which is the following :

    #include <FHT.h> // include the library

    #define LIN_OUT8  1
    #define FFT_N     64

    void setup()
    {
      /*Turn off timer0 for lower jitter -
        delay() and millis() killed*/
      TIMSK0 = 0;
      /*set the adc to free running mode*/
      ADCSRA = 0xe5;
      /*use adc0*/
      ADMUX = 0x40;
      /*turn off the digital input for adc0*/
      DIDR0 = 0x01;

      Serial.begin(115200);

    }

    void loop()
    {
      while(1)
      { // reduces jitter
        cli();  // UDRE interrupt slows this way down on arduino1.0
        for (int i = 0 ; i < FHT_N ; i++)
        { // save 256 samples
          while(!(ADCSRA & 0x10)); // wait for adc to be ready
          ADCSRA = 0xf5; // restart adc
          byte m = ADCL; // fetch adc data
          byte j = ADCH;
          int k = (j << 8) | m; // form into an int
          k -= 0x0200; // form into a signed int
          k <<= 6; // form into a 16b signed int
          fht_input[i] = k; // put real data into even bins
        }
        fht_window(); // window the data for better frequency response
        fht_reorder(); // reorder the data before doing the fft
        fht_run(); // process the data in the fft
        fht_mag_lin8(); // take the output of the fft
        sei();
        Serial.write(255);
        fht_lin_ou8[0];
        Serial.write(fht_lin_out8, FHT_N/2);
      }
    }

But I get the following error:
`fht_lin_ou8' was not declared in this scope`

I canot resolve this probleme, ans help would be appreciate

title: FHT doesn't work with the example code

Answers: 1

body:
May be you should try to replace :

> fht_lin_ou8[0];

with :

fht_lin_out8[0];


body:
I have written the following code for a project comprising an ultrasonic
distance sensor, a buzzer and a few buttons. When the distance is less
than 60 cm, the buzzer rings and stops only when the appropriate
passcode is pressed.

When I try to compile it, I get:

> exit status 1
> Error compiling for board Arduino/Genuino Uno.

This does not give the **reason** for the compilation failure.

My code is below, any help would be appreciated.

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

    #include<NewPing.h>

    int r;
    boolean ctr;

    #define TRIGGER_PIN  10  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN     9  // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

    //the buttons:

    const int SPEAKER=8;

    const int b1=4;
    const int b2=5;
    const int b3=6;
    const int b4=7;
    //variables to store previous button press and currend button press , used to eliminate switch bouncing
    boolean pb1=LOW;
    boolean cb1=LOW;

    boolean pb2=LOW;
    boolean cb2=LOW;

    boolean pb3=LOW;
    boolean cb3=LOW;

    boolean pb4=LOW;
    boolean cb4=LOW;

    //variables to store numbers:

    int w=0;
    int x=0;
    int y=0;
    int z=0;

    void setup() {
      // put your setup code here, to run once:
      pinMode(b1,INPUT);
      pinMode(b2,INPUT);
      pinMode(b3,INPUT);
      pinMode(b4,INPUT);

     Serial.begin(9600);

    }

    boolean debounce1(boolean last1)
    {
       boolean current1=digitalRead(b1);
      if(last1 != current1)
      {
           delay(5);
        }
          current1=digitalRead(b1);
          return current1;
      }

    boolean debounce2(boolean last2)
    {
       boolean current2=digitalRead(b2);
      if(last2 != current2)
      {
          delay(5);
        }
          current2=digitalRead(b2);
          return current2;
      }

      boolean debounce3(boolean last3)
    {
        boolean current3=digitalRead(b3);
      if(last3 != current3)
      {
          delay(5);
        }
          current3=digitalRead(b3);
          return current3;
      }

      boolean debounce4(boolean last4)
    {
       boolean current4=digitalRead(b4);
      if(last4 != current4)
      {
          delay(5);
        }
          current4=digitalRead(b4);
          return current4;
      }

    boolean distance(int o)
    {
      boolean control;
      if (o<60)
        control=true;
        return control;
      }

    void loop() {
      // put your main code here, to run repeatedly:
      cb1=debounce1(pb1);
      cb2=debounce2(pb2);
      cb3=debounce3(pb3);
      cb4=debounce4(pb4);

         if (pb1==LOW&&cb1==HIGH)
       {
          w++;
        }
        pb1=cb1;

        if (pb2==LOW&&cb2==HIGH)
       {
          x++;
        }
        pb2=cb2;

        if (pb3==LOW&&cb3==HIGH)
       {
          y++;
        }
        pb3=cb3;

        if (pb4==LOW&&cb4==HIGH)
       {
          z++;
        }
        pb4=cb4;

        delay(50);
        unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds   (uS).

        Serial.print(uS / US_ROUNDTRIP_CM);
        Serial.print(" ");
         int r=uS / US_ROUNDTRIP_CM;

         ctr=distance(r);

      if(ctr==true)
        tone(SPEAKER,1000);

    Serial.print(w);
    Serial.print(x);
    Serial.print(y);
    Serial.print(z);

    Serial.println();

    delay(100);
    if(w==1&&x==3&&y==3&&z==1)
      noTone(SPEAKER);

    }

title: Compilation fails with non-explicit error message

Answers: 1

body:
There is a reason. There is always a reason. You may just have to scroll back in the output panel to see it.

    Tone.cpp:536: multiple definition of `__vector_7'
    NewPing/NewPing.cpp:284: first defined here
    collect2: error: ld returned 1 exit status

In this case it is that you are using `NewPing.h` and `tone()`.  Both of them use the same timer.

You can't use both `tone()` and the `NewPing.h` library together without first making one of them use a different timer or no timer at all.  The easiest is the `NewPing.h` library. As it says in the header file:

    #define TIMER_ENABLED true      // Set to "false" to disable the timer ISR (if getting "__vector_7" compile errors set this to false). Default=true

So edit that header file and set `true` to `false` for that line and it should start working.


body: How can I include `mysql.h` library in IDE of Arduino to connect Arduino to mysql database by using GSM shield?

title: How can I connect mysql with Arduino using GSMshield

Answers: 2

body:
You can't. Arduino is too small to run `libmysqlclient` directly. There are few other solutions:

 1. You can expose your database using REST API and call that.
 2. Change hardware platform to Raspberry Pi - it runs full Linux system
 3. Run your app on PC and call Arduino using some RPC library

body: You can turn on GPRS data connection on your GSM shield and perform HTTP GET or POST request to the web page script (for example PHP script), which in turn will access the MySQL database (write or read DB records). It is easier than implementing REST API.


body:
I was working with my arduino clone and that was working well till last night.
I was trying to add l298p motor shield and after a few times of testing without any achievement, my PC suddenly did not recognize the arduino.
The device status in device manager is :

    Windows has stopped this device because it has reported problems. (Code 43)
    A request for the USB device descriptor failed.

What should I do now??
My OS is windows 8.1

title: Arduino Clone - A request for the USB device descriptor failed

Answers: 2

body:
You have a cheap Chinese clone with a CH340T USB interface chip.

These are notoriously bad chips. It will have died.

You can fix it (temporarily) by replacing the CH340T with another - though it's anyone's guess how long that'll last.

You can also continue using your board as it is now by either programming the chip directly through ICSP or keep using the bootloader but via an external USB to TTL Serial adapter connected to pins 0/1 + RESET (via a capacitor to DTR) as if it were a "breadboard" Arduino.

That's the price you pay for buying cheap Chinese clones. They may seem like a good idea at the time, but unless you are willing to treat them very much as a throw-away item they are not always the value they appear.

Next time buy a genuine Arduino or an Arduino compatible from a reputable manufacturer.

body:
**Solution for semi-bricked Pro Micro/mini-Leonardo clones:**

The OP's question is ambiguous to as the exact Arduino device in question. My answer applies to the "Pro Micro" or "mini-Leonardo" since these Clones usually use the default Leonardo boot loader, not the modified Sparkfun version.

Note the the Pro Micro doesn't use an external serial to USB chip at all. So the "CH340T USB" argument doesn't apply here. The USB is directly wired to the ATMEGA chip in this case as it has built-in USB 2.0 support.

I've made two projects with these: I gutted an old keypad replaced with a Pro Micro Clone and turned it into a extended keyboard so I could get F13 to F24 keys plus some others, then a custom game foot controller (to 'Q' and 'E' lean in FPS shooters).

Problem, I went to update my Foot controller sketch and after over a year later I forgot my Arduino IDE settings. This time I must have used the wrong setting like "Sparkfun Pro Micro" 3.3.v 8Mhz when your clone is probably like mine a 5v 16Mhz model.
When I uploaded the sketch it failed and apparently corrupted the program Flash header or something.
The original code was still running (on pedal press my LED lit up) but the device now showed up as "..missing USB device descriptor.." type message in the Windows device manager.

Fear not, it's probably recoverable like it was for me.
First of all realize you DON'T set in the Arduino IDE the board to "Spark Fun Pro Micro", simply set it to the default "Arduino Leonardo".
That's the right board setting for these clones. The Sparkfun bootloader IS different, as it says on their site. If you uploaded their bootloader then it might work but that's an experiment for another time.

Now you will need to add a reset button to the right hand side of your board (with the micro USB plug pointing up). The pins are next to each other and are clearly labeled.
I found a mini-switch just right to fit into the header pins from my parts box. In a pinch you can probably solder two small insulated stripped wires as a makeshift switch, but it might make the following step harder which is timing related.

If you plug your Clone Micro back in, notice if you press the switch the Clone Micro will show back up as a Arduino Leonardo on a COM port for about 8 seconds, then fall back to the bad USB ID thing again.

Now in your Arduino IDE create a NEW sketch. Which will create a minimal program that you'll need to restore your Clone back to working order.
Hit the reset switch again and quickly in your IDE preset the "port" to the COM port that shows up. Don't worry it will remember it after the device falls back again.

Now comes the hard part. Unlike a real Sparkfun Micro you can't double tap the reset button for extra time, you only get the 8 seconds period.
In the IDE click the "Upload" button, wait about a second, then hit your reset button.
If all goes well, you will see the typical flashing programming LED success lights and you will have restored your Clone Micro! This might take a few tries depending on your timing.
The thing is to press your reset button slightly after you click the Upload button (or CTRL-U) else you will miss the time frame of the special bootloader reset phase.

Basically this is the directions given here, with a little more details:
https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide#troubleshooting-and-faq

----------------------------------------------------------------------------------------
The OP got some opinionated and pretty toxic responses for an open-source hardware device. Some common sense notes on the morality and ethics of buying Chinese clone devices:

First of all, at least this is not nearly as bad a situation of the Chinese fake chips, arguably the real scourge of the Electronics parts world.

Without spending too much time on the legal ramifications and not being a lawyer, it looks like most of the Sparkfun stuff is CC licensed. Although doubtful the license if for their original or modified software/firmware.

From the Arduino site:
"Arduino is an open-source hardware and software company". So the clones are apparently not illegal to buy in the USA (if this is the country of contention).

The reason a lot of people buy the clones is you can buy around three or more of them for the same price of just one Sparkfun Micro.
I've been an electronic hobbyist since the late 70's and part of the equation for me is getting a few extras because there is always that chance I'll fry something despite double if not triple checking my wiring.
I can make a project plus have some spares for the next time.

I wouldn't use it in anything mission critical, but so far the Clone has been working fine for me as a hobbyist.

These things being said, I'm a big fan of Sparkfun. They are a relatively small USA company that makes fun innovative products with helpful Youtube "how too" videos, etc. I'm all for supporting them.


body:
I'm trying to make a line following robot for my students, the problem is that I have not done any calculations (I don't know how).

The motor can't move the robot unless I connect it directly to the 9 V power supply, but when i connect the other compenents(arduino) in parralel to the same 9v powersuply the motor doesn't get enough current when put on the floor so it just freeze's.

Where do you think should i start ?

The transistor I used is: NPN C1815
the motor is a brushed dc motor
[![schematic line following robot][1]][1]

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

  [1]: https://i.stack.imgur.com/7D1eU.png
  [2]: https://i.stack.imgur.com/Nezrr.jpg

title: Low current in a motor used in a line following robot

Answers: 1

body:
Due to only a tiny amount of gearing (what is it - 2:1? 3:1? something like that) your motor is operating near the stall point unless it is able to pick up enough speed (at which point it would smash into the nearest wall and pulverise itself).

Consequently it is drawing far more current from the battery than you'd like.  And that is, without the Arduino connected, about all the puny little PP3 battery can provide.  Add the Arduino etc into the mix and you are over-stepping your current budget by enough to mean the motor cannot start turning (the 1A stall current).

So what to do? Well, two options:

* Use a bigger battery.
* Increase the gearing of the motor.
* (my personal recommendation) Do both.

Increasing the gearing of the motor will decrease maximum output speed, increase the torque, and most importantly, decrease the start-up current. The whole load on the motor will be reduced making it much easier to start.

By increasing the power of the battery (use a 2S or 3S Li-Ion depending on what your motor's voltage limits are) you have a much bigger current budget to play with.


body:
Is there any way to get the current Git tag/commit identifier into an Arduino sketch binary?

For normal desktop program development, you can pull some tricks with the Makefile (as pointed out in [this StackExchange answer](https://stackoverflow.com/a/6526504/1480315)). However, there is no Makefile for an Arduino sketch. Right?

I could make a batch file that I run before every compile, but there is the very real possibility I will forget to run it, and incorrect version information is worse than no version information.

At the moment, I am using the preprocessor macros `__DATE__` and `__TIME__` to try and identify what version is running on the board. This works, but tracking backwards from a compile date/time to a source control commit is more guesswork than anything.

title: Include Git tag (or SVN revision) in Arduino sketch?

Answers: 7

body:
I'm not sure what the commit ID would prove. I use git for source control for my Arduino sketches, but a particular upload might be halfway between the previous commit and the next one. That is, the code on the board might not match any particular commit.

The date/time would at least identify approximately where in the commit stream the code is.

A possibility would be to run a cron job that periodically (say, every minute) updates a .h file with the current commit ID from the branch, and include that in the sketch.

body:
If you want to do Makefile-like tricks, one possibility is to use a
Makefile-based workflow instead of the Arduino IDE. There are a few
generic Arduino Makefiles floating around the Web. One quite popular is
[Sudar Muthu's Arduino
Makefile](https://github.com/sudar/Arduino-Makefile). With it, you just
write a small per-project Makefile that sets a few variables and then
includes the generic Makefile. There is one limitation with this
approach though: the Arduino IDE normally modifies your .ino file before
submitting it to the compiler, in two ways:

1. It #includes <Arduino.h>
2. It writes prototypes near the beginning of the program for every
   function you define.

Sudar Muthu's Makefile does include Arduino.h (it does not touch your
code, using instead the `-include` gcc option), but it does _not_ write
the function prototypes for you. It is thus not 100% compatible with the
Arduino IDE.

Another possibility would be to completely write yourself a Makefile
that calls [Arduino
Builder](https://github.com/arduino/arduino-builder). This should be
100% compatible with the IDE.

body:
I struggled with Arduino (ESP32) versioning also.
To make it somewhat more practical and less error prone I made some scripts to assist this process.

Using these scripts is as easy as adding them to your sketch folder and adding

    #include "gitTagVersion.h"
    ...
    Serial.println( sketchVersion );

to your Arduino sketch.
That is all that is needed.

The output in the example above will be something like v1.0.0-3-gab3fb04.
<br>That breaks down to tag `v1.0.0`, we had `3` commits since that tag, at commit `ab3fb04`.

HOW TO INSTALL AND USE?

There are 2 scripts involved, the first script is a replacement for the Arduino  Verify button.
Save it as verify.sh:

    echo "const char * sketchVersion = \"$(git describe --tags --always --dirty)\";" > gitTagVersion.h
    ~/arduino-1.8.5/arduino --verify test.ino
    rm gitTagVersion.h

And the second script replaces the Upload button.
Save it as upload.sh:

    echo "const char * sketchVersion = \"$(git describe --tags --always --dirty)\";" > gitTagVersion.h
    ~/arduino-1.8.5/arduino --upload test.ino --pref custom_DebugLevel=esp32_none
    rm gitTagVersion.h

Some things to note about these scripts:

 - The scripts REPLACE the buttons.
   You won’t be able to use the buttons anymore, as these buttons don’t
   generate the necessary version info from git.

   Using them will result in this error:

   >  fatal error: gitTagVersion.h:    No such file or directory

 - The scripts are hardcoded to use Arduino 1.8.5 and have to be updated
   if you update your Arduino IDE.

 - These script only work in Linux with a vanilla Arduino install.

 - If you use Windows, or are on a Mac the scripts will not work.

 - To change the debug output (using the LOGx_ESP macros) on ESP32
   builds, change the custom_DebugLevel in the Upload script to
   esp32_xxxx, where xxxx is none, info, error, debug or verbose.

I posted this also on my [blog][1] and [esp32.com][2]

  [1]: http://wasietsmet.nl/arduino/add-git-tag-and-version-number-to-an-arduino-sketch/
  [2]: https://esp32.com/viewtopic.php?f=19&t=5213

body:
Inspired by Cellie's answer, I investigated further and found a similar
method that can be implemented using the regular interface of the
Arduino IDE.

It appears that GitHub user Wackerbarth, while facing the very same
problem, opened [an issue on the Arduino bug tracker][issue]:

> It would be very useful to be able to add a recipe to the platform
> specification that is executed at the start of the build process.
> (pre-build)
>
> In particular, my use case is to generate version strings which will
> be incorporated in the Rom image based on information extracted from a
> SCM repository.

He went on to submit [a pull request][PR] for adding “hooks” to the
build process, which made it to release 1.6.2. See the documentation on
these [Pre and post build hooks][hooks doc].

Here is how you can use this feature for including git commit
information into your program (tested on Arduino 1.8.5 / Ubuntu 16.04):

1. Save the following file under the name `make-git-version`, somewhere
   in your `PATH`, and make it executable:

<!-- language: lang-sh -->

    #!/bin/bash

    # Go to the source directory.
    [ -n "$1" ] && cd "$1" || exit 1

    # Build a version string with git.
    version=$(git describe --tags --always --dirty 2> /dev/null)

    # If this is not a git repository, fallback to the compilation date.
    [ -n "$version" ] || version=$(date -I)

    # Save this in git-version.h.
    echo "#define GIT_VERSION \"$version\"" > $2/sketch/git-version.h

2. Locate the file named `platform.txt` in the Arduino installation
   directory (currently in `arduino-1.8.5/hardware/arduino/avr` for the
   AVR boards). In the same directory, create a file named
   `platform.local.txt` with the following content:

<!-- language: lang-none -->

    recipe.hooks.sketch.prebuild.1.pattern=make-git-version "{build.source.path}" "{build.path}"

3. In your sketch, include `"git-version.h"` and use it like so:

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

    #include "git-version.h"

    void setup() {
      Serial.begin(9600);
      Serial.println("This is version " GIT_VERSION);
    }

4. Create an empty file in your sketch directory named `git-version.h`.

Note that the `git-version.h` in the current directory is only needed
for the first compilation. The real `git-version.h` will be in the
temporary build directory.

[issue]: https://github.com/arduino/Arduino/issues/2732
[PR]: https://github.com/arduino/Arduino/pull/2738
[hooks doc]: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#pre-and-post-build-hooks-since-ide-165

body:
If you're using Platformio, add this in platformio.ini file

    build_flags =
        !echo '-D GIT_VERSION=\\"'$(git rev-parse HEAD)'\\"'

And use it like this:

    Serial.printf("Firmware version: %s\n", GIT_VERSION);

Check out relevant docs:
http://docs.platformio.org/en/latest/projectconf/section_env_build.html#dynamic-build-flags

body:
Inspired by Edgar's Bash script, I wrote a Windows **Batch** script do almost the same in adition to copying HEX file from the temp build directory to the project directory and insert commit hash, date, branch name and tag to it's name. I wrote a short article on [how to use GIT to manage firmware versions][1].

    :: How to use:
    :: Add this file to you Arduino project directory and add the following line to platform.txt from Arduino core files
    :: recipe.hooks.sketch.prebuild.1.pattern = {build.source.path}\fw_ver.bat GIT {build.path} {build.source.path}
    :: recipe.hooks.objcopy.postobjcopy.2.pattern = {build.source.path}\fw_ver.bat SAVE {build.path} {build.source.path}

    @echo off

    :: arg1 -> "GIT" print version, commit number, brnach name and commit date , "SAVE" copy the .hex file from temp build directory to project directory
    set arg1=%1
    :: arg2 -> path to temp build directory
    set arg2=%2
    :: arg3 -> path to project source files
    set arg3=%3

    cd %arg3%

    FOR /F "tokens=* USEBACKQ" %%F IN (`git describe --match^=NeVeRmAtCh --always --abbrev^=7`) DO (
    SET commit=%%F
    )

    FOR /F "tokens=* USEBACKQ" %%F IN (`git show -s --format^=%� --date^=format:%%y_%%m_%%d %commit%`) DO (
    SET date=%%F
    )

    FOR /F "tokens=* USEBACKQ" %%F IN (`git rev-parse --abbrev-ref HEAD`) DO (
    SET branch=%%F
    )

    FOR /F "tokens=* USEBACKQ" %%F IN (`git describe --abbrev^=0`) DO (
    SET ver=%%F
    )
    ::Export to version.h
    ECHO #define FW_VER "%ver%" > version.h
    ECHO #define COMMIT_NUMBER "%commit%" >> version.h
    ECHO #define COMMIT_DATE "�te%" >> version.h
    ECHO #define COMMIT_BRANCH "%branch%" >> version.h

    IF "%arg1%"=="GIT" (
    @echo on
    @echo version:%ver% Commit:%commit% Branch:%branch% Date:�te%
    @echo off
    )
    IF "%arg1%"=="SAVE" (
    @echo on
    @echo Save fw_%ver%_%branch%_�te%_%commit%.hex to %arg3%
    COPY "%arg2%\fw.ino.hex" "fw_%ver%_%branch%_�te%_%commit%.hex"
    )

  [1]: https://atadiat.com/en/e-how-to-use-git-to-manage-firmware-versions/

body:
I met the same problem and based on the previous answers I wrote this [script][1] for Arduino IDE. I'm using it successfully on different OSs for many months to now. In the repository, you can find the instructions to install it.

  [1]: https://github.com/fabiuz7/git-describe-arduino


body:
I want to start programming with the Arduino Uno, but I don't know where to start or what a good start is. I can program a bit in c#, but I red that you have to program in c++.

Any idea's where to start?

Thanks!

title: I want to begin with arduino programming

Answers: 3

body:
Welcome to the world of Arduino. You can start by going directly to the Arduino Site -> [Learning & tutorials][1]. Also the internet full of 100's, if not 1000's of information and tutorials.

  [1]: http://www.arduino.cc/en/Guide/HomePage

body:
You can purchase some great starter kits too:

They're easy to search for, here's a few that popped up right away:

http://www.arduino.cc/en/Main/ArduinoStarterKit

http://www.amazon.com/Kuman-Project-Complete-Starter-breadboard/dp/B016D5KUHS/

And here's one that I own, and I've recommended to other people:

http://www.microcenter.com/product/458578/Arduino_Compatible_Maker_Kit_with_LCD_Display

If you have a microcenter or radio shack or Fry's in your area, they all stock a variety of different starter kits.

body:
The other suggestions are great.
If you want to make a more "academic" approach, I can recommend two courses on [Coursera][1]:

 - [The Arduino Platform and C Programming][2]
 - [Interfacing with the Arduino][3]

I've followed and completed these 2 courses, and I think they were great fun. They give a light-weight introducton to the Arduino, with only a little time consumption needed.

  [1]: http://www.coursera.org
  [2]: https://www.coursera.org/learn/arduino-platform/
  [3]: https://www.coursera.org/learn/interface-with-arduino


body:
I am working on esp8266 module with arduino uno board.  This is my program.

 #include <SoftwareSerial.h>

 #define DEBUG true

 SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
         // This means that you need to connect the TX line from the esp to the Arduino's pin 2
         // and the RX line from the esp to the Arduino's pin 3
 void setup()
 {
   Serial.begin(9600);
   esp8266.begin(9600); // your esp's baud rate might be different
    Serial.print("START");
   pinMode(11,OUTPUT);
   digitalWrite(11,LOW);

   pinMode(12,OUTPUT);
   digitalWrite(12,LOW);

   pinMode(13,OUTPUT);
   digitalWrite(13,LOW);

   sendData("AT+RST\r\n",2000,DEBUG); // reset module
   sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point
   sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
   sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
   sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
 }

 void loop()
 {
   if(esp8266.available()) // check if the esp is sending a message
   {

  if(esp8266.find("+IPD,"))
  {
   delay(1000); // wait for the serial buffer to fill up (read all the serial data)
   // get the connection id so that we can then disconnect
   int connectionId = esp8266.read()-48; // subtract 48 because the read() function returns
              // the ASCII decimal value and 0 (the first decimal number) starts at 48

   esp8266.find("pin="); // advance cursor to "pin="

   int pinNumber = (esp8266.read()-48)*10; // get first number i.e. if the pin 13 then the 1st number is 1, then multiply to get 10
   pinNumber += (esp8266.read()-48); // get second number, i.e. if the pin number is 13 then the 2nd number is 3, then add to the first number

   digitalWrite(pinNumber, !digitalRead(pinNumber)); // toggle pin

   // make close command
   String closeCommand = "AT+CIPCLOSE=";
   closeCommand+=connectionId; // append connection id
   closeCommand+="\r\n";

   sendData(closeCommand,1000,DEBUG); // close connection
  }
   }
 }

 /*
 * Name: sendData
 * Description: Function used to send data to ESP8266.
 * Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
 * Returns: The response from the esp8266 (if there is a reponse)
 */
 String sendData(String command, const int timeout, boolean debug)
 {
  String response = "";

  Serial.println(esp8266.print(command)); // send the read character to the esp8266

  long int time = millis();
  while( (time+timeout) > millis())
  {

    while(esp8266.available())
    {
   Serial.print("Coming");

   // The esp has data so display its output to the serial window
   char c = esp8266.read(); // read the next character.
   response+=c;
    }
  }

  if(debug)
  {
    Serial.print(response);
  }

  return response;
 }

the problem is  i am not getting any output from esp module but arduino is transmitting the data.  power supply for esp is given by 3.3v regulator (LD3.3)feeding 12v from arduino power supply adapter  to regulator input .
TX esp to rx arduino
arduino tx to esp rx by voltage divider (R1=1k and R2=1.8k)
esp gnd  to arduino gnd
chpd and esp vin are 3.3v from regulator
Can anyone tell me where the problem is ?

title: Esp 8266 doesn't reply to AT commands

Answers: 1

body:
Try powering the ESP from an external 3.3V power supply if possible - some people say the Arduino 3.3V regulator may not provide enough power for it (it is quite power hungry at startup).

Another option worth trying is to put a 100uF capacitor between ESP VCC and GND. Put some small delay at the beginning of your `setup()` function if you do that just in case.

Also, there are several pins you need to pull UP: CH_PD, RESET, GPIO0. If you have GPIO15 broken out (depends on the board), pull it to ground. I have also noticed the ESP won't boot properly if GPIO2 is LOW - either leave it floating or pull it up.

[Here][1] is a picture you can use as a guide

Of course, you should make sure the ESP is flashed with the AT commands firmware (they usually are) and your baud rate is correct. If you don't know - try 9600, 57600, 115200.

If you have a USB to TTL converter, it might be better (easier) to test your setup using it, without Arduino. Any serial terminal program (including Arduino IDE Serial Monitor) will be fine. Just make sure you send both CR and LF for new lines. If you send "AT" and receive "OK" your wiring is correct, if you don't - it is not.

  [1]: https://github.com/esp8266/Arduino/blob/master/doc/ESP_improved_stability.png


body:
My quite new Nano clone (ATmega328P + CH340G) suddenly stopped working. Plugging it in with USB did not light up the LED(s) nor did it get detected by my machine. I looked it up, and found some how-to's (such as this one: [Repair Arduino Nano (no power on USB)][1]), which suggested at least some diagnostics.

So I plugged the Nano in to a 5V breadboard power source using the Vin and GND pins, and the power LED lights up, but connecting via USB cable to my machine does not detect it.

So then I used some of the methods mentioned in the link, and used just a normal jumper cable (without soldering) to check if that could magically make it detectable by my machine. No luck. I tried bypassing the voltage regulator by "jumping" over it, and the power LED gets brighter, and "pin 13" LED flashes for just an instant. The same occurs if I "jump" the voltage regulator all the way to either end of what I am guessing is the "Schottky diode".

In all cases, still nothing in terms of being detected by my computer. The cable is fine because I tested with another nano clone, and it gets detected right away.

So, how do I properly diagnose what is going on here? Specifically how do I fix my poor board? How do I find which component is in need of replacing?

----------
Update:

I found some online guides on how to have another Arduino board talk to this one over [SoftwareSerial][2] and found that I could get some data flowing through. However, the text was garbled, such that, for example if I was expecting it to say:

> "Please enter some input"

It might read instead:

> "Ulease XYZter some [][]put"

Often with the same characters being garbled in the same way. I tested the Schottky diode the way it was suggested in the video (with some guessing as to the multimeter setting I had to use was, since I have a different model than the one in the video), and it seems the diode is fine. So at this point I am guessing it is the ch340g chip that is toasty, either that, or the ATmega chip itself, which I don't know, but that sounds less likely.

So, could it be that it is the CH340G chip, since I get no power over USB, and the TX/RX over serial is being interfered with? Is there anything else I can do to figure out if it is the CH340G that's damaged before I go about trying to replace it?

  [1]: http://www.instructables.com/id/Repair-Arduino-Nano-no-power-on-USB-1/
  [2]: https://www.arduino.cc/en/Tutorial/SoftwareSerialExample

title: Nano clone not working over USB, no data, no power, but can power via Vin (CH340 chip? schottky diode?)

Answers: 1

body:
Either you have a cable problem or that board is just not working well.

What you call the CH340 chip - when they go bad you get power but NO communications, in my experience.  You can test voltages at the various points like 5V, 3.3V, etc., to see if it getting power.  If it is and you're still not communicating, then if it were me it would go on the shelf for the kids to see.

It no longer can trusted.

Rather than troubleshooting the board it would be worth getting another to compare with.

And if you have more than one cable on hand, try them and see if there are any differences.

But my prediction is that a new board will work and this one will continue to not work.


body:
Good day.

I have successfully built and tested an Arduino-on-breadboard about 2 days ago.

The device is rather straight forward, I have added a voltage divider and an LED to indicate power.

The schematics are as follows:
[![enter image description here][1]][1]

And this is a picture of the actual board:
[![enter image description here][2]][2]

I am using an ATMega328P-PU as a Microcontroller chip.

I uploaded quite a few sketches on the board and all seemed to work well. I was trying to upload a sketch yesterday but I got:
 **"avrdude: Yikes! invalid device signature"**.

I rebooted the computer, rebuilt the entire board again, and tried once again to load a sketch using Arduino as ISP. The message changed again to:

**avrdude: Expected signature for ATmega328P is 1E 95 0F
         Double check chip, or use -F to override this check.
Wrong microcontroller found.  Did you select the right board from the Tools > Board menu?**

I did a search online and I have found many forums suggesting that I change the avrdude.conf file parameters to different signatures "Although these are mainly targeted at people using ATMega328-PU, not ATMega328P-PU" but this also did not help.

I tried burning the bootloader again but I still get the same error message.

I tried to find a way to "retrieve" the chip signature, but I didn't.

I know that there is a chance that I have bricked the chip somehow, but how do I know for sure? and is there anyway that one can use and Arduino as a tool to retrieve the chip signature or verify if the chip itself is dead?

Thank You

  [1]: https://i.stack.imgur.com/xKaet.png
  [2]: https://i.stack.imgur.com/VCtKq.jpg

title: Using Arduino UNO to retrieve ATMega328P-PU chip signature

Answers: 3

body:
There is a nice explanation [here][1] about Atmel chip signatures.

It sounds like you already know this, so for others looking for help:

*It says that there are different signatures in the Atmel chips you mention.  That you can over ride the Avrdude program using an "-F" switch.  Or you can change the Avrdude configurations to use the "other" Atmel chip (however, the consequences if any were unknown by the author).*

This may be an obvious step, but double check to make sure the IDE's target board settings are correct.

You may also want to check the communications between the programmer and the target.  You might look into dropping the speed.  But the better way is to scope the lines to see if data is being sent to the target and if the target is talking back.  From that you can infer if the problems is a bad connection or if the chip has been damaged.

If you want to dig further using software tools you could look into driving Avrdude for your self.  There is a easy to read tutorial [here][2] and what appears to be an everything you wanted to know and more document [here][3].

In the 1st tutorial (from ladyada.net) we see a test which they purposely try the wrong signature:

> Just for kicks try running this command avrdude -c usbtiny -p atmega8
> -U flash:w:test_leds.hex

[![enter image description here][4]][4]

> You'll see that it stops at step 2, once the signature is different
> than the expected one it stops. This is because code that is compiled
> for an attiny2313 wont run on an atmega8 (this is true of most
> microcontrollers, the .hex files are not cross compatible)

But more interestingly, Avrdude prints out the signature read back from the target!  So, if you run the same test, you could tell if Avrdude is able to communicate at all with the target.  That is, you may see all zeros or all ones or even an alternate message from Avrdude. Which could be an indication that the target is not talking.

  [1]: http://www.instructables.com/id/Bootload-an-ATmega328/step6/ATmega328-PU-workaround/
  [2]: http://www.ladyada.net/learn/avr/avrdude.html
  [3]: http://www.atmel.com/webdoc/AVRLibcReferenceManual/using_avrprog.html
  [4]: https://i.stack.imgur.com/grqDr.jpg

body:
More than a year down the road, I learned a few things, and I am answering my own question so that if anyone faces the problem I faced (and I know how stressful it is) can give this a go. It may help.

One of the most interesting things I have learned is Mr. Nick Gammon's (Someone have actually called him *Mr. Arduino*) wonderful collection of sketches designed to do exactly this sort of thing.

If you ever need to find out what is the signature of your ATMega328 (or any arduino micro controller chip for this matter, visit [this site](http://www.gammon.com.au/forum/?id=11633).

The main reason I asked the question was to "un-brick" my ATMega328s, and I have actually done some thing wrong that to this day I can not figure out that resulted in 4 chips giving the error in the question. Just when I was about to give up, I found [this link](http://www.gammon.com.au/bootloader) from Mr Gammon's website which sorted out the problem in 3 out of the 4 ATMegas, the fourth I am keeping to test a high voltage programmer in the future.

Thank you.

body:
when you try to change the signature there are 2 areas where the code 1E 95 0F is displayed. If you try changing the signature in the wrong position, then will it show the error message 'microcontroller not found'. I did the same mistake once. I would suggest you rely on the find option in the Edit menu and search for the code.
Edit > Find > Search 1E 95 0F > ( opt for 'down') search next.


body:
*EDIT: My original question was a bit "off" since the Arduino Nano I was using appeared to be faulty. This edited question is based on my other Arduino Nano which is working.*

When I plug my Arduino into the PC, it keeps blinking it's LED until I open the Serial Monitor.

After opening the serial monitor the Arduino will start to execute my code.

How can I get my Arduino to "not wait on a connection", or simply put, start whenever it receives power.

I believe it's the bootloader which somehow doesn't time-out (I'm not sure if that's how the bootloader works).

The code below (though I don't see why this would make it hang until a connection):

    void setup() {
      // put your setup code here, to run once:
      Serial.begin(256000);
      Serial.write("Restart");
      pinMode(13, OUTPUT);
      digitalWrite(13, HIGH);
    }

    void loop() {
      // put your main code here, to run repeatedly:
      if (Serial.available() > 0) {
        incomingByte = Serial.read();

        // say what you got:
        startSend();
        Serial.print("I received: ");
        Serial.println(incomingByte, DEC);
        stopSend();
      }else{
        startSend();
        Serial.println("I'm still standing");
        stopSend();
        delay(400);
      }
    }

(Code is only for testing purposes)

title: How to not wait for USB to become active?

Answers: 1

body:
After you post your code this answer may not apply.  But, guessing, you may benefit from changing your code from:

    loop()
    {
     data = Serial.read();
     // Do other sutff
    }

To something like this:

    loop()
    {
     if(Serial.available() > 1)
     {
      data = Serial.read();
     }
     // Do other stuff
    }


body:
I have the following structure:

    struct inst_t {
        const char *s1;
        const char *s2;
    };

I'd like to initialize a constant array of this structure like this where all the strings are `PROGMEM`'ed:

    const char START[] PROGMEM = "START";
    const char ATZ[] PROGMEM = "ATZ";
    const char ATE0[] PROGMEM = "ATE0";
    const char OK[] PROGMEM = "OK";

    static inst_t insts[] = {
        { START,      NULL },
        { ATZ,        OK },
        { ATE0,       OK }
    };

You can see there is a lot of duplication here though. Is there anyway way I can inline the `PROGMEM` strings directly into this array initialization without separately declaring each string as being in `PROGMEM`?

title: Possible to "inline" PROGMEM strings into a structure array initialization?

Answers: 1

body:
If the strings are similar size you can, like this:

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

    const int NUMBER_OF_ELEMENTS = 10;

    typedef struct {
       char description [12];
    } descriptionType;

    const descriptionType descriptions [NUMBER_OF_ELEMENTS] PROGMEM = {
     { "Furnace on" },
     { "Furnace off" },
     { "Set clock" },
     { "Pump on" },
     { "Pump off" },
     { "Password:" },
     { "Accepted" },
     { "Rejected" },
     { "Fault" },
     { "Service rqd" },
     };

    void setup ()
      {
      Serial.begin (115200);
      Serial.println ();

      for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
        {
        // make a copy of the current one
        descriptionType oneItem;
        memcpy_P (&oneItem, &descriptions [i], sizeof oneItem);

        Serial.println (oneItem.description);
        }   // end of for loop

      }  // end of setup

    void loop () { }

---

This is a bit wasteful of program memory, because you need to allow for the largest string (your example had them all similar sizes) but what you *save* is not needing a two-byte pointer for each string, so if they are all similar lengths, it will take about the same memory.

See [my page about PROGMEM](http://www.gammon.com.au/progmem).


body:
I'm building a tic tac toe board for my kids where tapping on a plexiglass surface in any one of the 9 squares would light it up.

What are some ways I can pull off making each of those 9 squares touch sensitive?

Doesn't need to be anything fancy, but the kicker is that it can't be something attached directly to the plexiglass surface (as that'd obscure the LED light underneath).

Current thinking is [buy a sheet of this pressure-sensitive conductive material][1] and cut it in to squares, then somehow transfer pressure form the plexiglass down to the square on the bottom of the box, but I may be overcomplicating it.

  [1]: https://www.adafruit.com/products/1361

title: Ways to implement touch sensitive surface?

Answers: 1

body:
Transparent touch sensitive surfaces are usually based on parasitic capacitance like on an iPhone.  While you can buy loose glass touch surfaces, it is difficult to use such devices if not already attached to an LCD.  The same is true for the much cheaper resistive touch surfaces like on a Newton.

If you are already using LEDs, I would suggest investigating using the LED to detect the light from the reflection of a finger.  I found people talking about this [here][1], [here][2] and [here][3].

I believe this is a still from a video that someone else made using this technique:

[![enter image description here][4]][4]

For your tic tac toe box I could see touching a location for X's or for O's.  Then touching 1 of 9 boxes you would want to place the symbol in.

Added later...

As @Gerben pointed out there are other options.  I like solving hardware problems in software.  And reversing the potential on an LED then sampling the voltage over time is a snap to implement on many modern embedded processors.

If you are open to hardware solutions, microchip.com makes a [chip][5] which projects an electrical field in front of a PCB for 3 dimensional gesture recognition.  However, the PCB layout is touchy.

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

Also, there are gesture sensors that (probably) use IR radiation to track movement.  [Here's one][7] that supposedly does X Y & Z as well as sense colors.  And it sounds like there is already an [Arduino library][8] written for some simple gestures. Looks like there's a [YouTube video][9] as well.

  [1]: http://www.thebox.myzen.co.uk/Workshop/LED_Sensing.html
  [2]: http://www.bitartist.org/2008/10/led-used-as-touchinput-sensor.html
  [3]: http://makezine.com/projects/make-36-boards/how-to-use-leds-to-detect-light/
  [4]: https://i.stack.imgur.com/5gtt1.jpg
  [5]: http://www.microchip.com/wwwproducts/en/MGC3030
  [6]: https://i.stack.imgur.com/2NRFu.jpg
  [7]: https://www.sparkfun.com/products/12787
  [8]: https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor/tree/V_H1.0_L1.4.1
  [9]: https://youtu.be/A3QRyixnEl8