body:
Hello Stack Exchange Community!

For an arduino project I am working on, I modify the SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 to support DSSCircuit's I2C Master Library (https://github.com/DSSCircuits/I2C-Master-Library). This is to combat the known issue of arduino's Wire library to often get hung up while trying to run the EndTransmission function, and it works some of the time. Code was from Stack Exchange community (https://arduino.stackexchange.com/questions/18023/modifying-arduino-imu-library-to-rely-on-dsscircuits-i2c-master-library).

    #include <I2C.h>
    #include "FIMU_ADXL345.h"

    ADXL345 acc = ADXL345();
    int x=0,  y=0, z=0;
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      I2c.begin();
      delay(100);
      acc.init(ADXL345_ADDR_ALT_LOW);
      delay(100);
      Serial.print("Is ACC OK?: ");
      Serial.println(acc.status);
      Serial.print("Any Error code?: ");
      Serial.println(acc.error_code);
      Serial.println("********Print all register current values********");
      acc.printAllRegister();
      Serial.println("********END register print******");
      Serial.println(acc.getRate());
    }

    void loop() {
      // put your main code here, to run repeatedly:
      acc.readAccel(&x,&y,&z);
      Serial.print(x);
      Serial.print('\t');
      Serial.print(y);
      Serial.print('\t');
      Serial.println(z);
      delay(500);
    }

Also, the SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 libraries must be modified from using Wire.h to I2C.h .

    // Writes val to address register on device
    void ADXL345::writeTo(byte address, byte val) {
      I2c.write((uint8_t) _dev_address, (uint8_t) address, (uint8_t) val);
    }

    // Reads num bytes starting from address register on device in to _buff array
    void ADXL345::readFrom(byte address, int num, byte _buff[]) {
      I2c.read((uint8_t) _dev_address, (uint8_t) address, (uint8_t) num);  // request 6 bytes from device
      if(I2c.available() != num){  // device may send less than requested (abnormal)
        status = ADXL345_ERROR;
        error_code = ADXL345_READ_ERROR;
      }

      int i = 0;
      while(I2c.available())
      {
        _buff[i] = I2c.receive();    // receive a byte
        i++;
      }
    }

I'm using an arduino shield, and it prevents me from uploading the code at the same time as the shield is on. My best guess is that the shield is continually triggering the device to restart in a way that does not harm performance but harms upload of code.

    Sketch uses 8,244 bytes (25%) of program storage space. Maximum is 32,256 bytes.
    Global variables use 600 bytes (29%) of dynamic memory, leaving 1,448 bytes for local variables. Maximum is 2,048 bytes.
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
    Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

When I open the serial port and let it run for a few seconds, it shows no current register values, and returns 0 for x y -- as expected.

    Is ACC OK?: 1
    Any Error code?: 0
    ********Print all register current values********
    0x00: B00000000
    0x1D: B00000000
    0x1E: B00000000
    0x1F: B00000000
    0x20: B00000000
    0x21: B00000000
    0x22: B00000000
    0x23: B00000000
    0x24: B00000000
    0x25: B00000000
    0x26: B00000000
    0x27: B00000000
    0x28: B00000000
    0x29: B00000000
    0x2A: B00000000
    0x2B: B00000000
    0x2C: B00000000
    0x2D: B00000000
    0x2E: B00000000
    0x2F: B00000000
    0x30: B00000000
    0x31: B00000000
    0x32: B00000000
    0x33: B00000000
    0x34: B00000000
    0x35: B00000000
    0x36: B00000000
    0x37: B00000000
    0x38: B00000000
    0x39: B00000000
    ********END register print******
    0.10
    0 0 0
    0 0 0
    0 0 0
    0 0 0
    0 0 0
    0 0 0
    0 0 0

Problem is, when the arduino shield is put on during serial transmission the loop will stop, and the device will stop outputting any information to serial even if the shield is taken off. This also usually disallows the uploading of new code even if the shield is off, and the only solution I've found to sometimes work is waiting a few minutes, disconnecting the arduino from computer to kill its power source, and restart the arduino IDE.

Can someone help me understand why this happens?

Thanks Community!
John Doe

title: Using arduino shield seems to break serial.print and uploading new code?

Answers: 0


body:
How do you install an Arduino library so it's only available for a specific project?

Say I have a codebase located at /myproject, and I want to install libraries at /myproject/lib/somelib. I can't find how to make `arduino myproject.ino` find the libraries under ./lib.

Googling "installing Arduino libraries" only finds me examples of [installing libraries globally][1] (and through the GUI no less), which is horrible practice and guarantees version conflicts.

When I used `ino`, it supported a local ./lib directory, but I can't find any equivalent feature in `arduino`.

  [1]: https://www.arduino.cc/en/Guide/Libraries

title: How to install a library for a single project

Answers: 2

body:
You want to switch to my [UECIDE](http://uecide.org/beta) for that functionality. You can then place libraries inside a folder called *libraries* in your sketch folder.

You also get the benefits of a much improved IDE :)

body:
I ended up switching to [ano][1], which supports a local `lib` directory.

  [1]: https://github.com/scottdarch/Arturo


body: I am using an ATtiny85 for making a smart watch. Bluetooth module HC-05 with ATtiny85 pins PB3->TX, PB4->RX and it works. Secondly I have connected a 0.96" OLED on PB0 (SDA) and PB2 (SCL) and this is also working perfectly. But once I combine both things, it doesn't work.

title: ATtiny85 + HC-05 + Oled = smart watch

Answers: 0


body:
I know that I can connect an ESP8266 with an Arduino Uno at pins 0 and 1, which is Rx and Tx, and enter commands manually in the serial monitor the commands to test it.

I had tried to use software serial and altserial to connect an ESP8266 to other pins, but it was error prone at sometimes.

My question is that how to use an automated program to control an ESP8266 when I connect the ESP8266 with an Arduino Uno at pins 0 and 1.

Sample code would be helpful.

Edit: I have added a simple program to blink led when it get response but it is not working. could you look at it too?

    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      delay(3000);
      pinMode(12,OUTPUT);

    }

    void loop() {
      // put your main code here, to run repeatedly:
      digitalWrite(12,LOW);
      delay(2000);
      Serial.println("AT");
      if(Serial.available())
      {
        digitalWrite(12,HIGH);

        while(Serial.available())
        {
          char c=Serial.read();
        }

        delay(2000);
      }

    }

title: How to program ESP8266 with Arduino Uno pins 0 and 1?

Answers: 2

body:
The problem with using pins 0 and 1 is that they are also used to communicate with the PC for both serial monitoring *and* programming.

If you attach an ESP8266 to pins 0 and 1 chances are you will fail when uploading a new sketch - you will have to disconnect the ESP8266 every time you need to upload a new sketch - that is why most people use SoftwareSerial.

Also if you are using pins 0 and 1 for the ESP8266 you cannot then also use the serial monitor to see what is going on with your program and thus be able to debug it when it's not working.

If you're OK with both those caveats then by all means go ahead and use pins 0 and 1.  You use it in exactly the same way as using SoftwareSerial but you don't need to define an object first - you just use the pre-defined Serial object.

One important thing to remember with the ESP8266 is that the default firmware's AT command interface is ropey as hell.  It's most likely that which is tripping you up not your SoftwareSerial.  You have to get the timing right with it from what I remember - always impose a 1 second delay after sending each command - it's the delay that terminates the command, not a carriage return (although I think a CR is also needed). Maybe later versions have been improved since, but that's one really good reason to directly program the ESP8266 and implement your own protocol for communicating.  My [ICSC](https://github.com/MajenkoLibraries/ICSC) library is a good candidate for communicating between the two - it runs on both the ESP8266 and the Arduino.

body:
You need to use Arduino IDE serial Monitor Window for ESP8266 setup instead of using TTL or Serial Converters. I successfully Setup My ESP8266 Module by using just Arduino Nano and Arduino IDE Serial Monitor.

        #include <SoftwareSerial.h>
    SoftwareSerial softSerial(3, 2); // RX, TX

    void setup()
    {
      uint32_t baud = 9600;
      Serial.begin(baud);
      softSerial.begin(baud);
      Serial.print("SETUP!! @");
      Serial.println(baud);
    }

    void loop()
    {
        while(softSerial.available() > 0)
        {
          char a = softSerial.read();
          if(a == '\0')
            continue;
          if(a != '\r' && a != '\n' && (a < 32))
            continue;
          Serial.print(a);
        }

        while(Serial.available() > 0)
        {
          char a = Serial.read();
          Serial.write(a);
          softSerial.write(a);
        }
    }

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

[Necessary AT Commands][2]

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

  [1]: https://i.stack.imgur.com/fpMc4.png
  [2]: http://www.electronicslovers.com/2017/11/learn-how-to-setup-wifi-module-esp8266.html
  [3]: https://i.stack.imgur.com/kC9lh.png


body:
I have an Arduino Uno whose LED, which is connected to  pin 13, is not turning off and it always stays on, and it annoys me.

[![Arduino UNO][1]][1]

Touching any exposed pins turns off the LED after removing my hands from the pins it turns back on *slowly*.

However it works perfectly with the programs. This program does turn the LED off and it stays that way while the program is running.

    void loop() {
      digitalWrite(13, LOW);
    }

When I upload other programs that don't use pin 13 then it stays on again. How can I fix this?

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

title: Arduino in-built LED is not turning off

Answers: 2

body:
If you don't tell it to turn off, it behaves "as it wants". If you don't write a 0 on its pin, how can you force it to stay shut down?

If you want it to be in an off state, force it: in your setup function write

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

No need to refresh it every loop, just in the setup.

body: You could try to actually remove the LED with a soldering pen... I haven't tried it however, so you could end up disabling pin 13 (or worst).


body:
I have an arduino uno which is powered by batteries. I have 6 AA-Batteries (1,5V each) connected to Vin and GND.

Thats cool because I don't have any cables and works pretty good.
The reason I need 6 AA batteries is, that I have a SIM900-module connected to my arduino uno. My USB Port (5V and 500mA) and my standard external power supply (9V and 1A) doesn't deliver enough current for the SIM900. But with the batteries the SIM900 gets enough power (current).

But there is the problem, that the batteries get sucked empty pretty fast and i don't want to exchange them every day. :-)

I searched for an power supply which can deliver 3A with 9V and found [one][1]. But i'm not sure if the arduino uno can handle that input via the on-board power-jack? The reason I want a 3A power supply is, that some users on the internet say that the sim900 sometimes uses more than the maximum current written in the documentation (which is 2A).

I'm an electronic noob.

So is there a risk if I try to use the 9V-3A power supply?
Does the arduino only pull the power it needs? So when it needs only 900mA, it only takes 900mA even if the power supply can deliver 3A?
As far as I know, it should work, because the batteries deliver as much current as the arduino (ad sim900) needs. So the batteries don't have an ampere limit, right?

  [1]: http://www.amazon.de/gp/product/B00V336QHY?keywords=arduino 9v 4A&qid=1448900022&ref_=sr_1_fkmr2_1&sr=8-1-fkmr2

title: arduino uno external power supply

Answers: 1

body:
The Arduino itself has a limit of about 800mA. That is imposed by the voltage regulator that converts the incoming voltage to 5V.

If you need more than 800mA then you need to provide your own regulated 5V power source and feed it in to the 5V pin (not VIN).

Suitable power sources are mobile phone chargers (*modern USB ones*).  They generally come in multiples of amps.

And to answer your theory question - the current is the *maximum* that the supply can provide. It's the voltage that is *fixed* and the current varies depending on the *load*.


body:
I need to reduce the SPI clock speed of the Arduino Due down to about 100 kHz. Unfortunately my hardware doesn't support higher speeds.

With the current maximum divider of 255, I can only reach a speed of still 320 kHz (SPI.setClockDivider(10, 255);).

Of course I could use a software SPI, but I'm still interested in using the build-in hardware. A possible solution could be to lower the overall clock speed of 84 MHz. Any idea how to achieve this?

title: Arduino Due SPI speed reduction

Answers: 1

body:
You can try using the SPISettings interface:

    SPISettings settings(100000, MSBFIRST, SPI_MODE0);

    SPI.beginTransaction(settings);
    ... do your stuff ...
    SPI.endTransaction();


body:
How can I write the bootloader and sketch code to an Arduino through the ISP and then write the sketch code again using the Arduino IDE later?

Currently, I can write the bootloader through the ISP and then write the sketch through the Arduino IDE.  This works just like normal.

I can also write the bootloader and sketch through the ISP.  The code runs like normal, but I can't load a new version of the sketch through the Arduino IDE.  It just timesout.

Here's what the IDE says when it attempts to upload the program:

    avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

             Using Port                    : COM5
             Using Programmer              : wiring
             Overriding Baud Rate          : 115200
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_getsync(): timeout communicating with programmer

The Arduino IDE creates two hex files after compiling the sketch: one is just the compiled sketch (Sketch.ino.hex) and the other is the compiled sketch with the bootloader code appended to the end (Sketch.ino.with_bootloader.hex).  So, I feel like this should be possible because Arduino produces the file for me.

title: burn arduino bootloader and compiled sketch at same time

Answers: 3

body:
If you program via ISP, it erases the boot loader, because you do not need it. The whole point of the boot loader is to allow programming over USB. So if you want to use the normal Arduino USB input to program, burn the bootloader and then do not use the ISP.

Note my knowledge of this dates back to older arduino ~1.0 software, it is possible modifications have been made, but the above should still be true. If you have an ISP you do not need the bootloader at all.

body:
Normally (using the IDE via the serial/USB interface) the bootloader is retained, and the bootloader itself replaces the main code.

If you do ICSP programming then the first thing the programmer has to do is erase the entire chip (including the bootloader). Now nothing is stopping you putting the bootloader back as part of the programming sequence (it would add to the programming time slightly).

As Chris Stratton suggests, this is basically combining the .hex file for the sketch, and the .hex file for the bootloader. I'm not sure that literally concatenating them would work because there are a couple of other "record types" in the .hex file which might confuse the programmer if they were encountered twice - in particular the "end of file" record type.

However a strategy along these lines should give you a file that could be uploaded and put the bootloader back:

* Take the .hex file from the compiler, and copy up to, but excluding, the "end of file" record to a temporary file.
* Append the desired bootloader .hex file (including the "end of file" line).
* Program the chip with the resulting file.

For larger chips (like the Atmega2560) you would need to be cautious about handling the "extended segment address" record because that sets the high-order byte of the address to be programmed.

The hex file format, as documented in my [programmer sketch](http://www.gammon.com.au/uploader) is:

    Line format:

      :nnaaaatt(data)ss

      Where:
      :      = a colon

      (All of below in hex format)

      nn     = length of data part
      aaaa   = address (eg. where to write data)
      tt     = transaction type
               00 = data
               01 = end of file
               02 = extended segment address (changes high-order byte of the address)
               03 = start segment address *
               04 = linear address *
               05 = start linear address *
      (data) = variable length data
      ss     = sumcheck

                * We don't use these

body:
I belive what you want to do is program a Arduino by ISP and retain the bootloader, I have done this on occasion by first loading the bootloader onto a chip, then upload the Arduino *sketch*, then i use the ISP programmer to read the whole flash back into hex file.

This hex file is then used to program the rest of the chips for production. (If you feel this takes too much time, it is possible to strip the hex file down, but that might be a bit complicated)


body:
I'm looking to buy my first arduino kit. However I have a concern.

If my Arduino Mega is bought from one manufacturer, then can I buy shields or other parts from other manufacturers? Are there any incompatibility issues

Thanks!

title: Buying Arduino Parts Different Manufacturers

Answers: 1

body:
Of course you can. In just the same way that you can buy a car from one manufacturer and bumper stickers from another.

That's the whole point of the Arduino platform - mix and match to make things -just like LEGO®.


body:
I have servo (TowerPro sg90) connected to 32 servo controller ([this one][1]) through UART interface (RX-TX, GND-GND).
Seller provide documentation how to connect and control my servos, but it isn't work.

Servo work if I connect it indirectly to Arduino. Controller indicate that it is working too (photo below - red led).

I already try different servos. Also try use provided software to control servos from pc through Mac/PC. But it's interface is unreadable for me. I tried different options but servos not responding.

Sketch code below (from sellers examples):

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

    void loop() {
      Serial.print("#3P500T2000\r\n");
      delay(2000);
      Serial.print("#3P1500T2000\r\n");
      delay(3000);
      Serial.print("#3P2500T2000\r\n");
      delay(2000);
      Serial.print("#3P1500T2000\r\n");
      delay(2000);
    }

Photo of my connections:

[![arduino-duamilanovo+32-servo-controller+servo][2]][2]

Sorry if it post duplicate some, but I cannot google this problem.

  [1]: http://www.aliexpress.com/item/New-Version-32-Channel-Robot-Servo-Control-Board-Servo-Motor-Controller-PS2-Wireless-Control-USB-UART/32272674301.html
  [2]: https://i.stack.imgur.com/Verqy.jpg

title: Cannot control servos through 32-servo-controller on Aurduino Duamilanove

Answers: 1

body:
There is one connection missing - the one that powers the servo and board.

At the moment your servo board is getting a small amount of power through the RX pin - **disconnect it immediately, you are damaging it**.

You need to provide +5V to the +5V terminal block, and also a suitable voltage (+5V should do) to the VCC on the terminal block.


body:
I am trying to get values for two ping sensors, but am not getting any returns, can someone help me edit my code?

# Code

    void setup()
    {
      Serial.begin(9600);
      pingRange(2);
      pingRange(3);
    }

    void loop(){
    }

      long pingRange (int pingPin)

    {
      pinMode(pingPin, OUTPUT);
      digitalWrite(pingPin, LOW);
      delayMicroseconds(2);
      digitalWrite(pingPin, HIGH);
      delayMicroseconds(5);
      digitalWrite(pingPin, LOW);
      pinMode(pingPin, INPUT);
      return microsecondsToCentimeters(pulseIn(pingPin, HIGH));
    }

    long microsecondsToCentimeters(long microseconds)
    {
      // The speed of sound is 340 m/s or 29 microseconds per centimeter.
      // The ping travels out and back, so to find the distance of the
      // object we take half of the distance travelled.
      return microseconds / 29 / 2;
    }

title: Using 2 PING Senors at Once

Answers: 1

body:
There's one part of your code conspicuous by its absence:

    pingRange(2);
    pingRange(3);

You're calling the functions, but you're not doing anything with the returned value.  I think you meant to print that value to the serial interface...

    Serial.println(pingRange(2));
    Serial.println(pingRange(3));


body:
The RS485 master-slave communication library on Nick Gammon's page http://www.gammon.com.au/Arduino/RS485_protocol.zip is working for me OK, but on the same hardware wiring is not working for the non-blocking library http://www.gammon.com.au/Arduino/RS485_non_blocking.zip.

I can not find information about the connection of MAX485 on Arduino for non-block version. Is MAX485/RS485 from HW serial (ie Rx=0 and Tx=1)?

If so, how can a slave on the same line at the same time receive from master the message "hello world" and print it to the serial monitor?
Thank you for the explanation.

When I added the SoftwareSerial library into Nick's example for non-blocking, so it works, but is it still a non-blocking?

    //Master:
    #include <RS485_non_blocking.h>
    #include <SoftwareSerial.h>
    const byte ENABLE_PIN = 4;
    SoftwareSerial mySerial(2,3); //RX = 2 TX = 3

    size_t fWrite (const byte what) {
      return mySerial.write (what);
    }

    RS485 myChannel (NULL, NULL, fWrite, 0);

    void setup () {
      Serial.begin (9600);
      mySerial.begin (28800);
      myChannel.begin ();

      pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
    }  // end of setup

    const byte msg [] = "Hello world";

    void loop () {
      digitalWrite (ENABLE_PIN, HIGH);  // enable sending
      myChannel.sendMsg (msg, sizeof (msg));
      digitalWrite (ENABLE_PIN, LOW);  // disable sending
      delay (1000);
    }  // end of loop

    //Slave:
    #include <RS485_non_blocking.h>
    #include <SoftwareSerial.h>
    const byte ENABLE_PIN = 4;
    SoftwareSerial mySerial(2,3); //RX = 2 TX = 3

    int fAvailable () {
      return mySerial.available ();
    }

    int fRead() {
      return mySerial.read ();
    }

    RS485 myChannel (fRead, fAvailable, NULL, 20);

    void setup() {
      Serial.begin(9600);
      mySerial.begin(28800);
      myChannel.begin();
      pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
    }  // end of setup

    void loop() {
      if (myChannel.update()) {
        Serial.write (myChannel.getData(), myChannel.getLength());
        Serial.println();
      }
    }  // end of loop

Regards, Vava
(Sorry for my English... :-)

title: Serial: What is different between Gammon's RS485 (blocking) and RS485 "non blocking" libraries?

Answers: 2

body:
The hardware connection should be the same, as blocking vs non-blocking is referring to how you handle the incoming data packets.

Don't quote me on this, but generally, blocking vs non-blocking refers to the use of `delay()` or similar, which will block anything else from running while that function is being executed.

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

Reference page: <http://www.gammon.com.au/forum/?id=11428>

---

The blocking library is intended where you want to wait for incoming data, and are prepared to do nothing else while it arrives. There is also a timeout parameter which lets the code proceed if nothing happens for a specified number of milliseconds.

The non-blocking library is intended for where you need to do other things (like control motors, or read switches) at the same time you are receiving data. For that situation you call an `update` function periodically which assembles the incoming packet, byte-by-byte if necessary.

When the data is fully received the `update` returns true, and you can process the packet.

---

> If so, how can a slave on the same line at the same time receive from master the message "hello world" and print it to the serial monitor?

As I stated above in neither case do you receive and print "at the same time", however the non-blocking one does not simply wait until all the data has arrived.

---

Example code from the linked page:

    void loop ()
      {
      if (myChannel.update ())  // returns true when packet fully received
        {
        Serial.write (myChannel.getData (), myChannel.getLength ());
        Serial.println ();
        }

      // do other things while waiting

      }  // end of loop

---

>  If in example for non-blocking libraries is the same wiring as in the example of blocking library, where is (in non-blocking example) definition of RX(=2) and TX(=3) pins?

The hardware is the same.

---

> there is limitation for use - only pins which supports change interrupts.

Of course. If the underlying protocol is SoftwareSerial then the usual limitations apply (that is for the Rx pin).


body:
I am looking at Adafruit to purchase some LED strips for a mod for my computer case, and want to power it with an Arduino.

I am looking at the Uno, but the Mega looks good too.  I hear the Uno is good because if the chip fries, you can just replace it easier than the Mega's chip.  I did hear that the Uno chip had issues, but that was a 2013 post.

Anyways, I am essentially looking to connect about a foot of 144 leds/m to the front of my case, and connect that to the Arduino.  I will then be lining the inside of my case with about 12-15" per side (x4 sides) of 60 leds/m so I wanted to connect that to another part of the Arduino.

I read that each led takes something like 6mA or 60mA each, so that is what we should watch for.  I was trying to search for this question that others asked, but people were looking to connect a lot of strips, and needed relays and whatnot, so I wanted to make sure the Arduino itself could power about 1.5 to 2 meters of Led strips in at least 2 different strip configs (or whatever you want to call them).

I also am curious if there will be an issue programming each strip setup or, if it just is a little more work to get it setup?

Since this is a computer cause led setup, I'm not sure if I should go USB power, or a wall charger?  What is the recommended approach for something like this?

I will definitely be reading up more tutorials and all that important stuff, but I want to buy the stuff now since I realized there's a cyber Monday deal going on, so I don't want to miss out...

Any help is appreciated, thank you!

title: How many LED Strips can we connect to an Arduino Uno? Is there a way to connect 1-3 meters worth without needing extra parts (relays)?

Answers: 3

body:
Yes, the current draw is the main factor here.  That's not really an Arduino issue though, as I will enlighten you about later on when I talk power supplies.

**I assume, since you don't mention what the LEDs are, that you are talking about strips of WS2812 "NeoPixel" LEDs (the ones where you can control the colour of each and every individual LED).**

I would recommend keeping all the LEDs as one single strip.  That doesn't mean you can cut the strip into segments, just join the ends to each other using wire in one chain.  That way you just have one chain to deal with in the Arduino.  Running multiple chains can be somewhat more resource hungry and I'm not even sure it's possible on an Arduino.  So keep it all as one long chain split into chunks and re-joined with wire.

Now for power.  Your computer has a big powerful power supply in it.  That gives a very good regulated 5V supply with many many amps available.  More than enough to run hundreds of LEDs.  By all means run the Arduino from USB (makes for easy programming - inspect your motherboard, it may well have an internal USB connector that would be ideal (I know mine has).  And then run the LEDs themselves off the +5V direct from the computer's power supply.  A spare hard drive power connector could be good for that.

body:
The important thing to understand here is that there are two things going on:

1. Powering the LEDs – that's the big power draw and it makes a ton of sense to do that off of the computer power supply.

1. Controlling the LEDs – that'a a very small load, using one (NeoPixel et al.) or two (DotStar et al.) pins on the Arduino. So there is no need to do anything fancy, you should have more than enough drive in the Arduino pin(s) to handle the LED control.

You might want to take a look at the [FastLED][1] library (or head directly to the [GitHub repo][2]) it explicitly support multiple strands of LEDs (and interchangeably supports a whole slew of LED type including NeoPixels and DotStars. I think, but haven't tried, you could support multiple strands of NeoPixels by creating several instances and giving each instance its own pin.

DotStars come (if you get a "finished" end) with a connector that has all four wires (Vcc, Gnd, data, and clock) as well as two additional wires for "bulk" power. But if you don't get a finished end you would just solder to the pads that are at each cut point. You probably want to power the strip(s) in parallel – feeding them from each end so that the LEDs at the end don't see too much of a voltage drop.

[1]: http://fastled.io
[2]: https://github.com/fastled/fastled

body:
The other answers you have here cover the points well, just to offer my $0.02.

# Using a wall adapter
It's really not necessary to use a separate wall adapter and you'd be adding another layer of complexity unnecessarily. So don't bother. Also with a wall adapter you would have to consider grounding it to the computer's power supply, not necessarily an issue, but not required if you use internal power.

# Powering your LEDs
your computers power supply is more than capable of handling EVERYTHING you've mentioned (unless you're already maxing it out, which I doubt).

Just make sure that you're powering the LEDs directly from the computer's power supply, and not from the (arduino) board itself, since that 5v is limited to 500mA from the USB connector, and definitely don't drive the main power from a data pin (I'm sure you know that—but just in case :P)

If you do split the strip (running two strips shouldn't be a problem) be sure to provide power where ever you can, ie each end, even in the middle. It will aid in providing even power throughout the strip.

# Powering the Arduino
I'd be running the Arduino off it as well, either grab a header cable off the board that has an end you could plug into your arduino and mount it inside, or feed a USB cable through the back and use one of the extra external USB ports. A bonus of running it outside would be you could physically reset the board by unplugging it :) or simply turning it off by doing the same.


body:
I have a project where I would like to control a countdown clock using a remote with:

Arduino Uno R3 Development Board

Funduino Uno Protoshield Board

[Freetronics Dot Matrix Display Connector][1]

[Arduino IR Reciever][2]

Both the DMDCon and the IR use digital pin 11. Can these two share the pin 11 or is there a workaround of sorts?

  [1]: http://cdn.shopify.com/s/files/1/0045/8932/files/DMDCON_DMDConnector.pdf?100730
  [2]: https://arduino-info.wikispaces.com/IR-RemoteControl

title: Using digital pin 11 for DMDCon and IR remote

Answers: 1

body: The workaround would be to configure the https://github.com/shirriff/Arduino-IRremote library referenced in your question to any available digital input.


body:
I'm currently trying to log data from a GPS shield onto a microSD card using a Sparkfun microSD shield. All my code will compile, but when I open the serial monitor the microSD will initialize, but then the log file itself won't be able to be opened. I have formatted the card and reset all the shields and the Arduino itself multiple times, but nothing seems to work.

When I upload the example sketch used to show the functionality of the data logging, provided in the SD.h library by Sparkfun, everything will function properly and it will be able to open the file correctly. I used this file to give me information on how to format my code, so it is very similar.

One thing that I think may be causing the issue is the size of my code. When uploaded, the code uses 80% of total memory and 84% of dynamic. I tried commenting out a lot of the code to see if more free memory would give a different result, but still got the same error.

Any help would be awesome, and thank you in advance! I've included my code below.

    // Include FONA, Watchdog, SD card and declare pins
    #include "SoftwareSerial.h"
    #include "Adafruit_FONA.h"
    #include "Adafruit_SleepyDog.h"
    #include "SPI.h"
    #include "SD.h"

    #define FONA_RX 2 //Reset pin
    #define FONA_TX 3 //FONA serial TX pin
    #define FONA_RST 4 //FONA serial RX pin

    //Include software serial
    SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
    SoftwareSerial *fonaSerial = &fonaSS;

    Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

    const int chipSelect = 8;

    File dataFile = SD.open("data.log", FILE_WRITE);

    //Set strings to hold all the data
      String Lat = "";
      String Long = "";
      String KPH = "";
      String Head = "";
      String Alt = "";

      float latitude, longitude, speed_kph, heading, altitude;

    //Set integers for the data
      int GPSlat = latitude;
      int GPSlong = longitude;
      int GPSkph = speed_kph;
      int GPShead = heading;
      int GPSalt = altitude;

    //Set counter and phone number for location messaging
      int Log_Counter = 0;

    // Halt function called when an error occurs.  Will print an error and stop execution while
    // doing a fast blink of the LED.  If the watchdog is enabled it will reset after 10 seconds.
    //void halt(const __FlashStringHelper *error) {
    //  Serial.println(error);
    //}

    //uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); //

    //uint8_t type; //

    void setup() {
      while (!Serial);

      //Initialize serial output
      Serial.begin(115200);
      Serial.println(F("Team Space Bread GPS - Zero-G-luten"));

      //Initialize SD card, then check if card is present
      Serial.print(F("Initializing SD card..."));
      pinMode(SS, OUTPUT);
      digitalWrite(SS, HIGH);
      if (!SD.begin(chipSelect)) {
        Serial.println(F("Card failed or is not present"));
        while (1);
      }
      Serial.println("Card initialized");

      //Open file to log data to
      if (! dataFile) {
        Serial.println(F("Error opening log file"));
        while (1);
      }

      //Initialize FONA module
      Serial.println(F("Initializing FONA.... (may take a couple seconds)"));
      fonaSerial->begin(4800);
      if (!fona.begin(*fonaSerial)) {
      // halt(F("Couldn't find FONA"));
      }
      fonaSS.println("AT+CMEE=2");
      Serial.println(F("FONA is functioning swimmingly"));

      //Enable watchdog timer; if code hangs and will not connect to GPS, WDT will run out after 10 seconds
      //and reset the code
      Watchdog.enable(10000);
      Watchdog.reset();

      //Wait for FONA to connect to cell network
      Serial.println(F("Checking for network..."));
      while (fona.getNetworkStatus() != 1) {
       delay(500);
      }

      //Enable GPS
      Watchdog.reset();
      Serial.println(F("Enabling GPS"));
      fona.enableGPS(true);
      delay(2000);
      Watchdog.reset();
      if (!fona.enableGPS(true)) {
      // halt(F("Failed to turn GPS on, resetting..."));
      }
      Serial.println(F("GPS connection successful"));

      // Start the GPRS data connection.
      Watchdog.reset();
      Serial.println(F("Enabling GPRS"));
      fona.enableGPRS(true);
      delay(2000);
      Watchdog.reset();
      if (!fona.enableGPRS(true)) {
      //  halt(F("Failed to turn GPRS on, resetting..."));
      }
      Serial.println(F("Connected to cellular"));

      //Wait a bit for connection to stabilize
      Watchdog.reset();
      delay(5000);

    }

    void loop() {
    //Reset Watchdog at start of loop - everything must work in less than 10 seconds!
     Watchdog.reset();

    // Grab a GPS reading.

      bool gpsFix = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);

    //Define strings as data intergers
      Lat += String(GPSlat);
      Long += String(GPSlong);
      KPH += String(GPSkph);
      Head += String(GPShead);
      Alt += String(GPSalt);
    //Print all data onto SD card
      dataFile.print("GPS lat: ");
      dataFile.println(Lat);
      dataFile.print("GPS long: ");
      dataFile.println(Long);
      dataFile.print("GPS speed KPH: ");
      dataFile.println(KPH);
      dataFile.print("GPS heading: ");
      dataFile.println(Head);
      dataFile.print("GPS altitude: ");
      dataFile.println(Alt);
      dataFile.print(" ");

    //Flush file to save data onto card
      dataFile.flush();

    //Every loop, add 1 to Log_Counter. When Log_Counter==180 (every 15 minutes), send SMS to number with location
      Log_Counter++;
      if (Log_Counter==180) {
    //There has to be a more elegant way to do this, but ¯\_(ツ)_/¯

    //Buffer for location and phone number
      char LocationBuffer[48];
    //  char SendTo[16];

    //Make latitude and longitude into one string
      String(Location) = Lat+=Long+=Alt ;

    //Set phone number to text to
    //  String(PhoneNumber) = "18143803250";
                           //^^^^This^^^^ is where you put the number to send the location to every 15 minutes

    //Location string to char that will be able to send
      Location.toCharArray(LocationBuffer, sizeof(LocationBuffer));

    ////Set phone number to char
    //  PhoneNumber.toCharArray(SendTo, sizeof(SendTo));

    //Send SMS w/ location
    fona.sendSMS("18143803250", LocationBuffer);
    }

    //Take mesaurement every 5 seconds
      delay(5000);
    }

title: Sparkfun MicroSD shield cannot open log file

Answers: 0


body:
I have 2 Xbee S1 models, 2 Arduino Wireless Proto Shields, 2 Arduino Megas, and an Xbee Explorer and am trying to make one Arduino Trigger another Arduino to send a pulse, I have tried to set up many tutorials on youtube and digi, but still cannot get it to work.

Can someone walk me through the steps for setup?

title: XBEE S1 Wireless Connection

Answers: 0


body:
As the title says there are many different wall chargers to choose from.

12v, 9v, 5v, with different mA amounts...

The starter kit on Adafruit's website mentions to get the 9V 1000mA switching power adapter, so I'm curious if that's what we should get?

here is the link to all of them.

There are regular wall adapters, and these big power supplies...

http://www.adafruit.com/search?q=switching+power+adapter&b=1

I'm just looking to run some LED Strip lights from the arduino and power some joystick buttons, some rotary encoder/knobs, and a keypad to work the LED lights

Thoughts?

Thanks!

title: Looking at Adafruit's website I'm confused which wallcharger I should get

Answers: 2

body:
This website looks like a pretty official answer for you.
http://playground.arduino.cc/Learning/WhatAdapter

> Since you'll probably be connecting other things to the Arduino (LEDs, LCDs, servos) you should get an adapter that can supply at least 500mA, or even 1000 mA (1 ampère). That way you can be sure you have enough juice to make each component of the circuit function reliably.

And

>  The Arduino's on-board regulator can actually handle up to 20V or more, so you can actually use an adapter that puts out 20V DC. The reasons you don't want to do that are twofold: you'll lose most of that voltage in heat, which is terribly inefficient. Secondly, the nice 9V pin on the Arduino board will actually be putting out 20V or so, which could lead to potential disaster when you connect something expensive to what you thought was the 9V pin. Our advice is to stick with the 9V or 12V DC adapter.

body:
Your Arduino Uno will use 35 to 50 mA at 5V.  The  “joystick buttons, some rotary encoder/knobs, and a keypad” will draw a small amount of current, probably between 1 and 10 mA.  Thus, power for the Uno and your controls will be well under 100 mA and can be supplied via USB without any problem.  (Also see: *[How to get more than 100mA from a USB port](https://electronics.stackexchange.com/q/5498)*.)

If your Uno enumerates and negotiates to get 500 mA via USB, you might have 450 mA available out of the +5V pin.  However, in some cases if you need more than a few dozen mA to power other devices, it will make sense to get a separate 5V supply for them.  (Eg, if the devices drag down the +5V and cause the Uno to reset, or if the devices are electrically noisy, like motors, RC servos, relays, solenoids.)  Also, note that [thread #70450](http://forum.arduino.cc/index.php?topic=70450.0) at forum.arduino.cc says you can draw 650 mA (or 3.25 W of power) when the Uno is powered via its DC power jack.

If your LED string has up to 6 or 7 WS2812B equivalents, you can power it from the Uno's 5V.  Here is the all-lights-on, full-brightness calculation for six of them:  6 WS2812Bs x 3 LEDs per WS8211 x 21 mA per LED = 378 mA.  For seven:  7 x 3 x 21 mA = 441 mA, which is out there on the edge.

For longer LED strings, figure on a little over 3 W of power for every 10 WS2812B equivalents.  (Calculation: 5 volts x 10  WS2812Bs x 3 LEDs per WS2812B x 21 max mA per LED = 3150 mW = 3.15 W.)  For example, get a 10 W (2 A x 5 V) or greater 5V power supply for a meter of 30- WS2812B-per-meter LED strip, etc.  This power supply will connect directly to the LED strip's power connectors.  The ground from the LED strip will connect to the Uno's ground, to establish a signal reference point.

Note, the absolute max voltage rating for a WS2812B, according to its datasheet, is 5.3 V, so use a supply whose voltage does not exceed 5.3 V.  The absolute min voltage rating is 3.5 V; they will work ok on 3.7 V LIPO batteries, but 3V3 power is out of spec for a WS2812B.

As mentioned in a previous question, if your LED strip is being installed inside a desktop PC, the PC's power supply will have lots of 5 V power available, and you can hook on to one of the red +5V wires and black Gnd wires from its supply to power the LEDs, either while powering the Uno itself from USB power or while using the same +5V to power the Uno as the LEDs.


body:
I think I broke my Arduino Uno as I was playing with it. I connected an ultrasonic range finder to it and uploaded a sketch to it. It was working fine until I accidentally touched the ICSP headers for the USB interface (the pins near the USB port). Now,everything is still working but my computer cannot detect it and it does not show up in the device manager or the IDE. Please tell me if it is broken and how to fix it.

BTW, I just bought it and just started using it after another Arduino had the same problem.

title: Is my Arduino Uno broken?

Answers: 1

body:
> Please tell me if it is broken and how to fix it.

See https://arduino.stackexchange.com/questions/13292/have-i-bricked-my-arduino-uno-problems-with-uploading-to-board

Those tips may also help with fixing problems with your Mega (if you ever have them). ;)


body:
I don't know how I can connect an MP503 sensor to my Arduino.

Please help.

[![enter image description here][1]][1]
http://eleparts.co.kr/data/design/product_file/SENSOR/gas/MP503 (Ver1.4) - Manual.pdf

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

title: How can I connect the MP503 to an Arduino Uno (Smoke, Alcohol Sensor)?

Answers: 1

body:
Ok, first of all I doubt you will be able to get a lot of measurements with that. Because... I know that kind of sensors and you will quickly get tired of it.

Anyway, you have to connect

1. pin 1 to +5V
2. pin 2 to ground
3. pin 3 to +5V
4. pin 4 to a resistor towards ground. Value has to be determined.

To chose the value, you have to try. Change resistor values until, in fresh air, the voltage you can sense across the resistor is approx 1V. I think it is arount 10k, but you'll have to try

Chosen the resistor, you have to simply attach the node between pin 4 and the resistor to an analog input and then read the voltage.

Now you have to calibrate the sensor. Put it in a fixed-concentration gas and measure the voltage: `nCalib = analogRead(sensorPin);`.

Then, when you need to measure the concentration, you just have to read the voltage again with `nMeas = analogRead(sensorPin);`. The factor Rs/Ro can be calculated with the formula

    Rs_over_Ro = nCalib / (1024 - nCalib) * (1024 - nMeas) / nMeas;

Once you have the factor, look at the graph in figure 3 to get the concentration:

[![figure 3: sensitivity for Mp503][1]][1]

As I told you, I think you will quickly get tired of it, but this is how to use it.

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


body:
I have a Arduino Uno which is looping over Serial.println("$testmessage"). Connected to this is a USB cable that i have cut and soldered male jumper leads to . I need to receive this message ("$testmessage") from the Uno using this USB cable without using the leosticks usb connector. After receiving the correct messgae from the Uno i plan to use Serial to send data from the leostick to my pc.

I'm stuck trying to figure out how to receive this message from the Uno.

Currently the the USB 5v and ground is connected to the leosticks 5V, GND pins. The Uno powers on and the the tx led is flashing every 100 milliseconds.

Can i just plug the green and white wires from the USB cable into D0&D1 and except it to work?

(Uno plugs into usb cable in the image)
https://i.stack.imgur.com/M0kbb.jpg

title: Leostick Receiving message from Uno using USB jumpers cables

Answers: 2

body: I don't think this has any chance of working. You can't use USB to interface between the two devices, as the Leostick can't work as USB host. Your best bet is to use (software) serial.

body:
While USB *is* a serial protocol, it's a completely different serial protocol than the RS-232-style logic-level serial protocol that the Serial library supports.  So the approach mentioned in the question has no logical chance of working.

  Also, the USB electrical signal is differential (double-ended, or line-to-line, rather than single-ended, or line-to-ground).  So the mentioned approach has no electrical chance of working.

What may work is to wire from Tx on the Uno to Rxd1 on the Leostick, and from Rx to Txd1, unless that conflicts with the Leostick's USB-Serial link.


body:
I’m trying to make a string of 300 Christmas tree lights where the colour of each of the lights is entirely controllable by my own code. I am a programmer so that side of things is the easy part as far as I’m concerned.

My researches so far have led me (no pun intended) to WS2811s driven by an Arduino. I prefer the look of these to the flat Adafruit-type ones. I don’t own an Arduino yet but have been dipping my toe into this site for quite a while now so am beginning to understand the basics.

I’ve established that I will need to have a fairly hefty 5volt power supply for the LEDs but that the Arduino itself can then run happily on its own USB supply.

Some of the things I’ve read seem to imply that the Arduino will struggle to process my program and supply the data to 300 LEDs at the same time, but it’s not clear what the problem will be. I assume each LED will continue to glow with the same colour until it receives the data for its next colour and the code for “Fire!” which then prompts all of them to switch to their next colour. Is this wrong?

I realise that 3 bytes per LED for 300 LEDs is a fair amount of data to keep having to send up the wire. I will also be having an array in the program to keep track of all 300 colour values.

Will this work? Can you offer any advice that might mean I don’t hit a brick wall somewhere when putting all this together?

title: Newbie and string of 300 WS2811s

Answers: 1

body:
I don't think you'll have any problems. The LED's have a data rate of 800kbps, so you can theoretically push out 110 frames per second if your Arduino does nothing but transmit data. If you keep the routine that updates the colors fairly efficient then you'll have nothing to worry about.

Note that the array storing the colors would take up 900 bytes of memory, leaving you with only 1100 bytes for everything else your program would need to store (which should be fine).


body:
I need to send one transmission and record multiple distances with 4 receivers, but everytime I use more than 2 receivers, the serial data does not print. What can I do?

P.S. I'm using 5 SRF-02 Sensors, 1 transmitter and 4 receivers all via I2C.

<!-- language: c -->

    #include <Wire.h>

    #define cmdByte 0x00                                 // Command byte
    #define rangeByte 0x02                             // Byte for start of ranging data

    byte highByte = 0x00;                                // Stores high byte from ranging
    byte lowByte = 0x00;                                // Stored low byte from ranging
    int range = 0;
    int rangeData;

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

    void loop() {
       D0_1= getRange(0x70, 0x71);
       Serial.println(D0_1);
       D0_2= getRange(0x70, 0x72);
       Serial.println(D0_2);
       D0_3= getRange(0x70, 0x73);
       Serial.println(D0_3);
       D0_4= getRange(0x70, 0x74);
       Serial.println(D0_4);
    }

     int getRange (uint8_t send_address, uint8_t rec_address)
     {
      Wire.beginTransmission(rec_address);
      Wire.write((uint8_t)cmdByte);
      Wire.write((uint8_t)0x56);
      Wire.endTransmission();

      Wire.beginTransmission(send_address);             // Start communticating with SRF02
      Wire.write((uint8_t)cmdByte);                         // Send Command Byte
      Wire.write((uint8_t)0x5C);        // Transmit an 8 cycle 40khz burst - no ranging takes place
      Wire.endTransmission();

      delay(80);                                                           // Wait for ranging to be complete

      Wire.beginTransmission(rec_address);       // start communicating with SRFmodule
      Wire.write((uint8_t)rangeByte);                 // Call the register for start of ranging data
      Wire.endTransmission();

      Wire.requestFrom(rec_address, 2);            // Request 2 bytes from SRF module

      while(Wire.available() < 2);                    // Wait for data to arrive
      highByte = Wire.read();                           // Get high byte
      lowByte = Wire.read();                           // Get low byte

      range = (highByte << 8 ) + lowByte;              // Put them together

     delay(120);

     return(range);                                                    // Returns Range
     }

title: Too many Bytes Using Ultrasonic Sensors

Answers: 0


body:
I am having a problem with my Arduino freezing after a small amount of time. I'm using an RTC DS1307 breakout to keep track of the time and display the time on an LCD. It displays hours, minutes and seconds (updated every second).

Then I have 25V which is supplied by a transformer and connected to a set of LEDs through a [CAT4101][1] constant-current sink LED driver. The Arduino board is powered by a 2amp USB transformer.

At a set time, the timer should set off the process to dim the lights.

Everything is working well if I set the lights to dim within a few minutes. However, if I leave the board on for more than 10-15 minutes then everything seems to freeze (i.e. the time on the LCD stops being updated and stays stuck at the moment it froze).

I originally thought it could have been something to do with my code. But I then skimmed everything down to the bare essential and just uploaded the code necessary to update the time on the LCD. And even in this case it freezes.

The only way I managed to avoid things freezing was to disconnect the CAT4101 pin 1 from Arduino's PWM and disconnect pin 2 from Arduino's 5V.

What could be causing this issue?

CAT4101

    pin 1 = connected to Arduino PWM
    pin 2 = connected to +5v
    pin 3 = connected to ground
    pin 4 = connected to ground with 2kOhm resistor
    pin 5 = connected to LED cathode

**UPDATE**

Code below (I have stripped down the code by removing any additional functions and leaving only the bare code which is leading the application to crash).
<!-- language-all: lang-cpp -->

    #include <Wire.h>
    #include <RTClib.h>
    #include <LiquidCrystal.h>

    RTC_DS1307 rtc;
    DateTime now;
    LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);

    void setup() {
      Wire.begin();
      rtc.begin();
      lcd.begin(16,2);

     if (!rtc.isrunning()) {
        Serial.println("RTC is NOT running!");
        // following line sets the RTC to the date & time this sketch was compiled
        rtc.adjust(DateTime(__DATE__, __TIME__)); // time = hh:mm:ss format, e.g. 06:01:01
      }

      lcd.clear();
    }

    void loop() {
      now = rtc.now();
      updateDisplay();
    }

    void updateDisplay(){
     int h = now.hour(); // Get the hours right now and store them in an integer called h
     int m = now.minute(); // Get the minutes right now and store them in an integer called m
     int s = now.second(); // Get the seconds right now and store them in an integer called s

     lcd.setCursor(0, 0); // Set the cursor at the column zero, upper row...
     lcd.print(" The time is: "); // ...with spaces to clear characters from setting alarm.
     lcd.setCursor(4, 1); // Move the cursor to column four, lower row
     if (h<10){   // Add a zero, if necessary, as above
      lcd.print(0);
     }
     lcd.print(h);   // Display the current hour
     lcd.setCursor(6, 1); // Move to the next column
     lcd.print(":");  // And print the colon
     lcd.setCursor(7, 1); // Move to the next column
     if (m<10){   // Add a zero, if necessary, as above
      lcd.print(0);
     }
     lcd.print(m);   // Display the current minute
     lcd.setCursor(9, 1); // Move to the next column
     lcd.print(":");  // And print the colon
     lcd.setCursor(10, 1); // Move to the next column
     if (s<10){   // Add a zero, if necessary, as above
      lcd.print(0);
     }
     lcd.print(s);   // Display the current second
    }

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

  [1]: http://www.onsemi.com/pub_link/Collateral/CAT4101-D.PDF
  [2]: https://i.stack.imgur.com/WPClR.png

title: Arduino is freezing after 10-15 minutes

Answers: 1

body:
I would add a `delay(100);` to the bottom of your loop()

I'm betting even odds that solves it.


body:
I am currently working on a camera platform based on the MT9D111 module from Micron. The first thing to do is to write the configuration to the numerous registers of the chip which is done via an i2C connection.

I adapted the code from [here][1] for testing this with an Arduino Uno. 3.3V supply and 8MHz clock are also provided by the Arduino.

Everything seems to work fine, but there are some odds which I don't know the reason for.

So here is the code (I just added the soft reset sequence according to the Developers Guide):

    const int freqOutputPin = 9;   // OC1A output pin for ATmega328 boards

    #define TMR1 0

    #include <Wire.h>
    #include <avr/io.h>
    #include <util/delay.h>
    //#include <TimerOne.h>
    #include <avr/interrupt.h>

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

      TCCR1B |= (1 << CS10);  //selecting prescaler 0b001 (Tclk/1)
      TCCR1B &= ~((1 << CS12) | (1 << CS11)); // turn off CS12 and CS11 bits
      TCCR1A |= ((1 << WGM11) | (1 << WGM10)); //Configure timer 1 for TOP mode (with TOP = OCR1A)
      TCCR1B |= ((1 << WGM13) | (1 << WGM12));
      TCCR1A |= (1 << COM1A0); // Enable timer 1 Compare Output channel A in toggle mode
      TCCR1A &= ~(1 << COM1A1);
      TCNT1 = 0;
      OCR1A = TMR1;

      delay(500);  //Initial delay
      Wire.begin(); // join i2c bus as master
      Serial.begin(9600);
      Serial.println("MT9D111 Camera Module + Arduino");
      Serial.println("Read and Write 16-bit register value example");
      Serial.println("*  Read expected value = 0x1519 from Register 0x00");
      Serial.println("*  Write value = 0xA5F0 to Register 0x20:1");
      Serial.println();
      init1(); //execute code just 1 time
    }

    void loop() {
    }

    void init1() {
      int16_t a;

      delay(500);  //wait until start
      Serial.print("Soft reset first");
      Serial.println();
      soft_reset();//do a soft reset at startup

     //***************Configuration here!****************//
      Serial.print("Read result from register 0x00");
      a = read_reg(0);
      Serial.println();
      Serial.print("0x");
      Serial.println(a, HEX);  //print result
      Serial.println();
      Serial.print("Read original data from register 0x0a, should be 11");
      Serial.println();
      a = read_reg(10);
      Serial.print("0x");
      Serial.println(a, HEX);  //print result
      Serial.println();

      //Enable this part for writing register
      //Some example reads and writes follow
      Serial.print("Writing 0xA5F0 in register 0x20:1");
      Serial.println();
      write_reg(32, 1, 165, 240);
      Serial.print("Read new value from register 0x20:1");
      Serial.println();
      a = read_reg(32);
      Serial.print("0x");
      Serial.println(a, HEX);  //print result
      Serial.println();
      Serial.print("Writing 0xA1F3 in register 0x20:1");
      Serial.println();
      write_reg(32, 1, 161, 243);
      Serial.print("Read new value from register 0x20:1");
      Serial.println();
      a = read_reg(32);
      Serial.print("0x");
      Serial.println(a, HEX);  //print result
      Serial.println();
    }

    //Write 2Byte register
    void write_reg(int reg_address, int page, int data_msb, int data_lsb) {
      delay(5);  //5ms
      Wire.beginTransmission(93); // transmit to device 93, Camera Module
      Wire.write(240);   //page register address
      Wire.write(0);
      Wire.write(page);   //select page 0/1/2
      Wire.endTransmission(1);    // stop transmitting
      Wire.beginTransmission(93); // transmit to device 93, Camera Module
      Wire.write(reg_address);   //register address 8bit, decimal
      Wire.write(data_msb);  //msbyte
      Wire.write(data_lsb);  //lsbyte
      Wire.endTransmission(1);    // stop transmitting
    }

    //read 2Byte register
    //be careful about selected register page
    int16_t read_reg(int reg_address) {
      int16_t err;
      delay(5);  //5ms
      Wire.beginTransmission(93); // transmit to device 93, Camera Module
      Wire.write(reg_address);   //register address 8bit, decimal
      err = Wire.endTransmission(1);    // stop transmitting
      Serial.println(err);
      Wire.requestFrom(93, 2, 1); //request value form device 93, 2 bytes with stop bit
      int16_t result = ((Wire.read() << 8) | Wire.read());  //read 16 bits
      return result;
    }

    //Perform Soft reset, required at startup
    void soft_reset(){
      write_reg(101, 0, 160, 0);//write registers according to dev guide
      write_reg(195, 1, 5, 1);
      write_reg(13, 0, 0, 33);
      delay(5);
      write_reg(13, 0, 0, 0);
      delay(5);//wait for i2c to be ready again
    }

Running this code gives me the following result on the serial monitor:

[![Serial Monitor][2]][2]

So here are the questions:

 1. Do you have any ideas why I get an extra FFFF when reading a register after writing it? (underlined in blue)
 2. Why are there some extra zeros in the output? (marked in yellow)

  [1]: https://hackaday.io/project/6386-usensecam/log/20618-checking-mt9d111-communication
  [2]: https://i.stack.imgur.com/8j3Tr.png

title: I2C connection with MT9D111 camera module, strange results after writing registers via i2C

Answers: 1

body:
The `0` comes from your code:

    Serial.println(err);

It's printing the error code. 0, hence no error.

As for the extra `FFFF` I'd say it's because you are using signed integers. Change your `a` declaration to `uint16_t` and see if that fixes it.


body:
I have a new DS1307 (original, not a Chinese rip off), with a new battery. It is working great, but when I turn the Arduino off (it is currently connected to laptop) and then turn it back on, it resets the time.

The line that sets the time is (in setup part of code):

    setDS1307time(30, 42, 21, 4, 26, 11, 14);

So, when the Arduino gets the power back it runs the program again and it overrides the correct current time.

How can I avoid this?

title: Arduino RTC - getting the time from RTC after the power is cut off

Answers: 2

body:
Without knowing the DS1307 well, I think there are two options:

1. Make the setting of the clock a UI function (you should probably do this in any case since you will want users to have the ability to set the clock). The user would have to initiate the action (and put in the time to set) so there would be no problems the clock getting reset inappropriately, or

1. Do a check for sanity of the clock before you run that line. You might be able to do that through the clock API (e.g., make a call to check the time, or to get the clock status and see if it makes sense) or you could do it by storing the clock status in nonvolatile memory. The very worst case would be that you store the time of last boot and check that it seems reasonable (e.g., the time you get from the RTC is after the last boot and is within reason – say no more than a month or a year ago). If the time is too far off to feel confident you could issue a "check time" warning.

If you have a network connection using NTP as well as the RTC would be a very smart option. NTP can hold the time within a few milliseconds. The RTC would then provide you with protection against a network outage.

If you are using the Arduino to manage scheduled events one thing you'll want to think about is events that are scheduled in a moment of time that is either "skipped" as you advance the clock or that "repeats" if you set the clock back. One way to handle that is to never "jump" time, but to always just speed it up or slow it down.

body:
If setup() runs, it is because the system has been restarted. It could becuase the reset button was pushed, or it could be due to a power-cycle. But either way, the code will start over completely. So you could

 1. Deal with restart issues in setup() as it will only be called once per session (unless you call it in your own code); or

 2. Make a variable `static boolean PowerCycled = true;` and clear it once your code has dealt with its re-start issues. After a restart, the initialzed data will get reloaded, including `PowerCycled` with it's initial value of `true` restored.


body:
so for about the last 8.5 hours (almost non-stop) I have been trying to figure out one issue and I have exhausted every search I could possibly think of.

I'm building a puzzle that requires 5 RFID readers on the 1 Arduino, but for the sake of testing i've only been using 2.

Both readers work independantly, I can read out the UIDs of the little cards, which is all I need to do, but as soon as I make them share the MISO line, it simply stops printing anything out. I have no idea why.

Both readers have a common external 3.3v power supply and ground, they share all other lines but have an individual Slave Select. For testing I put both of their MISO cables into a breadboard which then leads into the Arduino on PIN 12, but it will only print out the UID when only ONE cable is plugged into the breadboard.

So is there something special I need to do to make this work? Is there a reason why the readers sharing a MISO line would break it? Even if i don't initialise one of them, just for the fact that it's plugged in still breaks it. I have tried setting one to HIGH and one to LOW, both to LOW, both to HIGH, nothing changes it.

Also, something else kind of confusing to me, it's meant to be active LOW to activate the SS, but when only 1 is plugged into the MISO line, it doesn't seem to matter which state it's in, it always prints...

I did a little bit of testing on my sketch just a moment ago and realised that when both are plugged into the MISO, the sketch will not progress past this line (which is also the first line in the loop)

    if ( ! mfrc522_2.PICC_IsNewCardPresent())
            return;

I know everything else is working because it works when there is nothing else plugged into the MISO line, but I need it to work when all the others are plugged in too.

Please please please, if you have any idea, let me know.

I'm using the MFRC522 Library

EDIT:

This is basically the setup i'm using:
[![enter image description here][1]][1]

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

I'm not using any voltage translators or shifters, everything is 5v from the arduino except for the power to the readers which is coming from an external 3.3v supply like mentions previously.

I'm pretty certain that this is the datasheet for the RC522 i'm using, though i'm not sure if it's V1 or V2, but given the differences between them I don't think it matters:

http://www.nxp.com/documents/data_sheet/MFRC522.pdf

I don't know if they are able to share MISO lines like someone below said, I just assumed I could?

title: Issue sharing MISO with multiple RC522 RFID Readers

Answers: 3

body:
Looking at the [datasheet for the MFR522][1], it is not clear that it even supports multidrop SPI. It does not mention anything about the state of the SPI output pins when the chip is not selected. It also mentions that the chip uses the slave select line to detect what communication mode to use upon startup, but does not mention anything about how the chip will react to changes on that pin after startup.

Considering this, along with the fact to your library also does not seem to support connections to multiple MFR522, my guess is that this chip only supports a 1-to-1 SPI link.

Further, the SPI Timing characteristics in the datasheet specify how lon gthe SS (called NSS) must be high before communication can begin, but does not specify how long after SS goes low that the MISO goes tri-state, which would be an important thing to know if the chip did support multidrop SPI.

This is all backed up by the behavior you are seeing. If both chips are driving the MISO line simultaneously, then communication will not be possible when both are connected.

To support multiple MFR522 connections, you could possibly...

1. Use a multiplexing buffer to only enable SPI lines to one chip at a time. Downside is you would need Extra hardware, but upside is that you could probably use existing library intact by selecting the desired MFR522 before making the linrary calls.

2. Connect each MFR522 to different GPIO pins on the Arduino and bit bang the SPI to each chip independently. Upside is that you don't need any extra hardware and you potentially have a lot of flexibility on how you access the MFR522's. Downside is you will have to retrofit this bit-banged SPI into the library or use (or write) a different library.

I've seen this question come up many times over the years, so if you do choose option #2, please publish your code so others can use it!

# An Experiment

I'd propose you do this to find out if your chips are compatible with multi-drop SPI...

1. Power up your system with a RC522 reader.
2. Check and make sure it works.
1. Disconnect the SS and MISO lines from the RC522 so they are no longer connected to the Arduino (or anything else). Leave the RC522 powered up - if it resets it might loose the auto-detected SPI configuration.
2. Use a jumper to connect the SS line to ground.
3. Connect the MISO line to ground with a 1K ohm resistor.
4. Use a multimeter to check the voltage on the MISO line.
5. Connect the MISO line to Vcc with the 1K ohm resistor.
6. Use a multimeter to check the voltage on the MISO line.
7. Connect the SS line to Vcc.
8. Repeat steps 3-6.

Report back the table of the 4 voltage readings you got and we should have our answer!

  [1]: http://www.nxp.com/documents/data_sheet/MFRC522.pdf

body:
I am joining this conversation VERY late, however maybe my answer can help someone who is just now looking into this.

I was able to get SEVEN RC522 readers working on one Arduino! My solution was very similar to your idea, except instead of the SS pin, I used the MISO pin.

[![Unique MISO diagram][1]][1]

If you look into how the pins work, all of them are outputs going from the master (Arduino) to the slaves (RC522), EXCEPT for the MISO pin which is an input going from the slaves to the master.

So I gave each RC522 scanner it's own MISO pin on the Arduino, and the rest of the pins were shared with all the scanners.

To get it working with the code, the simplest solution I found was to initialize a new RFID using the corresponding MISO pin each time I wanted to read from one of the RC522s.

This worked for the Arduino because you can set several of the digital pins as MISOs, however I haven't figured out how to get this working on a Raspberry Pi yet (without using a multiplexer) because the Pi has a few specific pins that are used for MISO.

I was using the old Sunfounder library. At the bottom of this page (http://wiki.sunfounder.cc/index.php?title=Mifare_RC522_Module_RFID_Reader), if you download the "RFID-RC522_test_experiment" zip file it will have the library included. Just copy and paste the RFID1 folder into your Arduino Library folder. Here is a simple tutorial for that library: https://www.sunfounder.com/learn/RFID_kit_V1_for_Arduino/lesson-29-rfid-entrance-guard-system-rfid-kit-v1-0-for-arduino.html

Here is some example code. It is pretty ugly but it worked.

    void checkRFID(int i){
      if(i==0){
        rfid.begin(2,4,5,7,3,6);
      }
      if(i==1){
        rfid.begin(2,4,5,8,3,6);
      }
      if(i==2){
        rfid.begin(2,4,5,9,3,6);
      }
      if(i==3){
        rfid.begin(2,4,5,10,3,6);
      }
      if(i==4){
        rfid.begin(2,4,5,11,3,6);
      }
      if(i==5){
        rfid.begin(2,4,5,12,3,6);
      }
      if(i==6){
        rfid.begin(2,4,5,13,3,6);
      }
      delay(100);
      rfid.init();
      uchar status;
      uchar str[MAX_LEN];
      // Search card, return card types
      status = rfid.request(PICC_REQIDL, str);
      if (status != MI_OK)
      {
        return;
      }
      // Show card type
      rfid.showCardType(str);
      //Prevent conflict, return the 4 bytes Serial number of the card
      status = rfid.anticoll(str);
      if (status == MI_OK)
      {
        memcpy(serNum, str, 5);
        rfid.showCardID(serNum);//show the card ID
        Serial.println();
        Serial.println();
      }
      delay(100);
      rfid.halt(); //command the card into sleep mode
    }

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

body:
I do not know if every module has a pull-up resistance in sck and mosi if that is the case, it could be that for every module connected over teh lines the resistance gets lower. so maybe the module can not drop the voltage so there is no comunication. check with a multimeter the resistance between Vcc and MOSI it has to be around 4.7k generally.
hope this could help.


body:
My Due webserver was working perfectly fine for months when connected to Linux via the native port.

But when connected to Windows 10 via the native port, if the Arduino webserver is idle for about 5 minutes (when no client calls a webpage), then there is a strange 5-10 second delay before the webpage is able to load. This delay doesn't happen when connected to the webserver via the programming port.

It almost seems like maybe Windows is putting the port to sleep when it notices an idle delay, and then it has to wait for the port to wake up before it can call the webpage.

On the Windows "Power Settings" I set the computer to never go to sleep, and also in the Power "Advanced Settings" I disabled the USB "selective suspend".

Do you have any ideas why there would be this strange delay only on Windows and only when connected via the native port?

----------
**ADDITIONS:** I made a simplified example that reproduces the problem on my machine. I wonder if anyone can see any problems with this code.

First, the python code. Note that if the python script is never run, there are no delays on the Arduino webserver, and everything works as expected.

    import serial, sys

    SERIALPORT = "COM5" # Change this to your serial port!

    # Set up serial port
    try:
      ser = serial.Serial(SERIALPORT, 115200, timeout=0)
    except serial.SerialException:
      sys.exit()

    ser.write("Hello World")
    print("Hello World")

    ser.close()

And below is the simplified Arduino code. It's just a simple webserver that serves a page that has a "reload" button that reloads the page. You can hit "reload" as many times as you want, and the program never freezes. But if you run the python code above and then try to reload the page, there is a long delay (anywhere between 10-60 seconds by my current estimate).

If you comment out all of the "SerialUSB.print" lines that are anywhere in the loop (in this simplified case, there's only 1 line at: "SerialUSB.println (data);" in the processData function), then the webpage never freezes, even if you run the python code frequently.

In my real-world example, my python code was running once a minute, causing random freezes. If I stopped the python code from running, then there were no more freezes on the webpage. I ended up commenting out all of my SerialUSB.print statements that were in the loop, and that way I could have the python code running on schedule, and my program had full functionality (except for the loss of SerialUSB.print).

    #include <Ethernet.h>

    byte mac[] = {
      0x04, 0xBA, 0xB0, 0xCC, 0xDF, 0x04
    };
    EthernetServer server(80);
    EthernetClient client;

    const byte MAX_INPUT = 25; //for processIncomingByte

    void setup ()
    {
      SerialUSB.begin (115200);
      Ethernet.begin(mac);
      SerialUSB.print("server is at ");
      SerialUSB.println(Ethernet.localIP());
    }  // end of setup

    bool processIncomingByte (const byte inByte)
    {
      static char input_line [MAX_INPUT];
      static unsigned int input_pos = 0;
      switch (inByte)
      {
        case '\n':   // end of text
          input_line [input_pos] = 0;  // terminating null byte
          if (input_pos == 0)
            return true;   // got blank line
          // terminator reached! process input_line here ...
          processData (input_line);
          // reset buffer for next time
          input_pos = 0;
          break;
        case '\r':   // discard carriage return
          break;
        default:
          // keep adding if not full ... allow for terminating null byte
          if (input_pos < (MAX_INPUT - 1)) input_line [input_pos++] = inByte;
          break;
      }  // end of switch
      return false;    // don't have a blank line yet
    } // end of processIncomingByteWeb

    void processData (const char * data)
    { //Note: since there are no GET requests in this simple example, I removed the parts for processing GET.
      SerialUSB.println (data);
      if (strlen (data) < 4)
        return;
    }  // end of processDataWeb

    void loop ()
    {
      client = server.available();
      if (client) {
        boolean done = false;
        while (client.connected() && !done)
        {
          while (client.available () > 0 && !done)
            done = processIncomingByte (client.read ());
        }  // end of while client connected

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.print("");
          client.print("Reload");
          delay(10); client.stop();
      }
    }  // end of loop

This is not technically a problem for me anymore, except for having had to comment out all my "SerialUSB.print" statements. But I am interested in learning what is causing this strange behavior.

Note: the "processIncomingByte" and "processData" functions are mainly from Mr. Gammon's writings and tutorials, and they are working flawlessly for me in 2 other Arduino webservers I have running. I wanted to note this because if I had written the functions myself, then obviously they would require much more scrutiny.

title: On Arduino Due webserver, there is a 5 second delay on Windows, only when connected via native port

Answers: 1

body:
This is speculation as it may be nearly impossible for any given person to simulate your network (for example, not only the version of Windows you are running but all the drivers installed and hardware specific to your Ethernet interface ... to only mention a few variables).

Consider using a [network monitor][1] to capture all communications set out by the Windows computer.  Consider the Windows computer occasionally failing your network.  Consider the delay you experience may be the time it takes for Windows to recover from what it thinks is a bad network.

The observation is that Windows sends out many autonomous messages over a new network in a "discovery" mode.  The suspicion is that the lack of response to some or all of these messages will result in Windows failing a network.

Windows does have ways of reporting the status of networks that vary with the version of Windows. But these methods (menus) can be frustrating to use as they don't appear to update often enough to reflect the true behavior of traffic coming out of the Windows computer.

Regardless, test if the state of the network is always good.  Also, test if connecting equipment Windows might expect on a functioning network (for example, a router with a DHCP server) improves the response time.  This, as an effort / test to determine if Windows is more responsive while connected to a healthy / active network.

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


body:
I'd like to use my Teensy 3.1 to send MIDI Show Control messages using USB MIDI in order to control an ETC Nomad system. These are different from standard NoteOn, NoteOff, ProgramChange, etc. commands, but as far as I can tell they are not supported by the standard library.

Is there any way I can send these messages directly (using lower level commands), as seen [here][1], or does anyone know of a library that supports this? Google has, unusually, not been much help.

  [1]: http://www.mymidiremotes.com/home/?page_id=46

title: Teensy MIDI Show Control

Answers: 1

body:
According to the [documentation](https://www.pjrc.com/teensy/td_midi.html), SysEx messages are sent like any other messages:

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

    array[0] = 0xf0;
    array[1] = 0x7f;
    array[2] = 0x7f;
    array[3] = 0x02;
    array[4] = 0x7f;
    array[5] = 0x01;
    array[6] = 0xf7;
    usbMIDI.sendSysEx(7, array);


body:
Is it possible to register a class instance member function with Arduino's [Wire.OnReceive][1]?

I'm trying to make my code object-oriented, and want a specific non-static class function to handle I2C data, but if I'm reading [this thread][2] correctly, `onReceive` is incompatible with classes since it only accepts a function pointer, which won't store context.

  [1]: https://www.arduino.cc/en/Reference/WireOnReceive
  [2]: http://forum.arduino.cc/index.php?topic=116685.0

title: Using a class instance with Wire.onReceive

Answers: 1

body:
A non-static class member function has an implicit `ClassName *this` parameter inserted as the first parameter in the parameter list.

Because the function prototype required for `Wire.onReceive()` does not have that parameter specified in its parameter list a non-static member function is not compatible with it.

The same goes for `attachInterrupt()` and anything else that takes a function pointer.


body:
sorry if I sound incompetent, but I know nothing about coding. I have a group project where I must sort various balls into different tracks. The final issue I have is that I must use an arduino for this portion. However, none of us know how to program, and the only experience we have is from doing the lessons from adafruit (copy and paste written code).

What I am attempting to do is attach a paddle to the tip of a high torque servo motor. I will then automatically feed the servo signals, ranging from 0 to 5. Each signal tells which position for the servo to turn to. Could anyone please help guide me in how to write this code? I was thinking of using
[this][1] guide for my motor. However it uses a POT. My project must be completely automated. The positons also are all within 180*.

Thank you!

  [1]: https://learn.adafruit.com/adafruit-arduino-lesson-14-servo-motors/overview

title: Making Servo Motor Automatically Move Based on Input

Answers: 1

body:
So you have a "number" and you want to set the servo to some angle. The logic is very simple:

* If number is 0 then set angle to 90
* If number is 1 then set angle to 45

etc.

How you "get" the number hasn't been specified, so I will assume you just have an integer with a value between 0 and 5 inclusive.

Setting a servo's angle is as simple as *writing* that angle to the servo:

    servo.write(45); // Set the angle to 45 degrees

So how do you join the two together?  Well, there's three different ways that spring to mind.

1. A string of `if` statements
2. A [switch](http://hacking.majenko.co.uk/time-to-make-a-switch) construct
3. An array

The first one is just like the bullet points above, just written as C:

    if (number == 0) servo.write(90);
    if (number == 1) servo.write(45);
    ... etc ...

The second method is very similar but can be more efficient when you know you only ever select one item from a list of options.  Read this to see how: http://hacking.majenko.co.uk/time-to-make-a-switch

The third option, the array, is especially good when you have a lot of options to manage and they are all the same result with a different value:

    const int angles[6] = {90, 45, 315, 0, 0, 0};

    // ... later ...
    servo.write(angles[number]);


body:
I am designing a home automation project. I want to control different home appliances through GSM. I am designing it in such a way that each apparatus is connected to an Arduino and bluetooth module. There is a master unit with Arduino, Bluetooth and GSM modules. When the user sends a message, the GSM receives it and communicates via Bluetooth to the corresponding Bluetooth module and Arduino.

Is it possible to communicate between two Bluetooth modules of two Arduinos? Is there a better solution?

title: Communication between two Bluetooth modules of two Arduinos

Answers: 3

body: I'm not sure how many bluetooth devices can be connected to your smartphone. But if you use smartphone, the you can eliminate the master Arduino. But as I said, it still depends on the number of devices you'd like to control. This is supposed to go in the comment section.

body:
How about little smart WiFi boards (such as [Red Bear WiFi Micro] or something similar), which are connected at your local home network? You can configure your own dyndns service or use a existing and built a web home appliances or web service for your own mobile application. In general please take care of security aspects, so that your home can not be manipulated...
[Red Bear WiFi Micro]:http://redbear.cc/wifi-micro/

body:
You connect your different sensors or devices to many slave arduinos and each slave arduino has its own bluwtooth module that send the data to Master Arduino that contains the Bluetooth and GSM Module.

And yes you can connect max 7 bluetooth devices to 1 Bluetooth module at a time so in that manner you can connect 7 slave devices to Master Arduino


body:
Actually I'm not good at English ;-) trying to ask to you. please understand me :)

I needed connect SD card Shield and TFT LCD Screen to Arduino Micro.

successfully finished compile at source code but when i connect MISO together

it doesn't work. only SS pin is connected separate Pin's to Micro

How can i make it work together to Micro..

i've checked each device perfectly work at Micro

Plese Help me!!

Regards and Thanks

title: multiple connection with ISP Pin at Arduino Micro

Answers: 1

body:
Each SPI device must have a separate device/slave select pin. The device must disconnect (high impedance state) when not selected. The SD shield will have a level shifter. It may not correctly disconnect from MISO.

Depending on what libraries you are using you might also need to check that they set the SPI hardware attributes correctly (clock, mode, etc).

For more help please post code and references to the shields and libraries.

Cheers!