body:
I'm making a project and i'm trying to send bits from an Arduino to another Arduino with the digital pins. So my setup are 2 Arduino's connected with a jumper.
I connected the grounds and they have both a different power supply.
Now I tried this set-up and as soon as I connect the output pin to the input pin from the other Arduino the voltage lowers from 5V to 2.6V so we can't detect our bits.
Anybody an idea how to solve this problem?

Thanks in advance!

Kind regards,
Manu

title: Connect the output of an Arduino to the input from another Arduino

Answers: 5

body:
I would suggest sticking a transistor in between - use a layout like http://en.wikipedia.org/wiki/Transistor#/media/File:Transistor_Simple_Circuit_Diagram_with_NPN_Labels.svg (from the wiki page on transistor).

Note that Vout should be connected to the input pin on one arduino, and Vin should connect, via a resistor, to the output pin on the other arduino.

Just to confirm, the labels are reversed from what you will expect them to be.

The 2 resistors can be anything > 1kOhm.

This still depends on the common ground.

Note that common ground may not be a good idea if they are generated from the same power source - I've found ground from two USB ports on the same laptop to be at different levels, so current will flow out from one port, and in the other, probably damaging the laptop, if the two grounds are connected.

body: As you are trying to communicate with two arduinos I will suggest you to use some sort of standard communication protocol such as Two wire interface or I2c. There is the Wire.h library you can use and it has also a reference on the main Arduino site. If you have different necessity and want to carry on with you're methods you need to specify in more depth the connections you have made. As for now I can guess that the output is being connected to ground or some sort of load and that might be the reason you are seeing a drop out of voltage. But it might be also the case that you're output pin is changing so fast that the multimeter is not capable of reading the high state correctly

body:
As Harry mentioned better to use some communication lines like UART or I2C or SPI.
If you dont have them available then use digital i/os but make sure their pull up and pull down resistors are correctly configured. If it is input just set as pull up and for output set as output pin.
Regards,
Pathik

body:
First of all, I cannot say if your protocol will work or not since I don't have the details. However, switching protocols will give you the same result. Also, you do not need a transistor for this usage.

The solution is to connect the grounds of the different power sources. Since voltage is relative, having the grounds disconnected will lead one device to think that the voltage is higher/lower than the other one thinks (they have different reference point).

body:
Are you sure one pins is configured as input? If one would be output high and the other output low you basically get a short circuit: from Vcc through the top FET of the high output, through the wire to the other Arduino, and into the lower FET of the low output, and back to ground.
If the short circuit were perfect the voltage would drop to zero, but both FETs have a non-zero resistance, which makes them a voltage divider.

One way to protect your Arduino against this (such a short circuit does damage the I/O circuits!) is to place a 1 kΩ series resistor between the pins. Since an input pin won't draw any current there won't be a voltage drop across the resistor either.

I wouldn't use Harry's I2C, because it's probably too complicated for your needs. (I don't know what data you want to exchange). A simple connection is the UART: one transmit line and one receive line. It's true that the UART is used for the USB communication, but that connection goes via a set of resistors, so that another controller using the bus should be able to override the USB's signals.

If you have a long distance between the Arduino's you'll want RS232 level shifters.


body:
I could define myself as a "nerdy cyclist", so while my interest in Arduino is steadily growing (have not bought or used yet), my first idea for a project would be:

 1. Instrument a bicycle with some sensors (accelerometer, reed switch, etc) and an Arduino;
 2. Ride long distances (that is, four hours or more, sometimes non-stop);
 3. When at home, download some sort of "data file" (from SD card, I think);
 4. Analyze results with Python/Matlab/whatever.

So my questions:

 - Is any model of Arduino suitable for this purpose?
 - What is the expected sample rate vs number of channels? 100Hz per channel would be excellent for my purposes, for example.
 - Can I keep incrementally saving to SD "forever" (that is, while battery and card space are available)?

title: Possibilities and limitations for onboard data acquisition

Answers: 2

body:
First of all your idea project is feasible. And to answer to your questions:

 1. There is no right Arduino for your project simply because theoretically every Arduino board can do the job. But as you said it has to be portable you might use Arduino nano/mini or even Uno if you have enough room or space.

 2. The acquisition rate depends on the on the type of sensor you have. So if you have let's say one analog reading you can use the built in function in Arduino which is capable of making about 10000 readings at time. So if you have multiple outs you can easily for the calculation. There are also sensors which has a digital output in this case in order to read your value you communicate with Tue sensor board through Two wire interface or I2C communication interface, for this there is a library you can use. Usually the speed at which this communication work s very high, at 100kHz( if I'm not wrong).

 3.Yes you can save data on the SD card until you don't exceed the memory or the battery doesn't die.

I have a suggestion for your project, as you're going to acquire some sort of data and then analyze it on your computer, do less calculations on your Arduino board and let the PC handle the hard work.

Useful links:

 - Reference to the two wire communication: http://arduino.cc/en/reference/wire
 - Reference to the SD card reading on Arduino: http://arduino.cc/en/Reference/SD

body:
Another idea -
I believe if you are making electronics you must be using some smart phone?
If I am correct why don't u utilize your smart phone with Arduino?
1) Connect sensors to Arduino
2) Use Bluetooth or WiFi shield
3) Store data locally until memory available
4) Transfer to your phone or to web via phone network every hour or 5 hours.
This will make battery consumption less and also make device Compaq.

Regards,
Pathik SHAH


body:
Alright, so I have an Atmel 93C66, http://www.atmel.com/Images/doc0172Z.pdf Datasheet and I'm wanting to read whatever is in it.

I copied the following code from this thread http://forum.arduino.cc/index.php?topic=96411.0 and made some changes to it, mainly I deleted the part where it writes:

    //difining pins for eeprom
    int CLOCK =4;
    int DATA_OUT =3;
    int DATA_IN = 2;
    int CHIP_SEL =5;

    int low =0;     //low address

    byte READ  = 0b1100;                //read instruction

    void setup(){

      pinMode(CLOCK ,OUTPUT);
      pinMode(DATA_OUT ,OUTPUT);
      pinMode(DATA_IN ,INPUT);
      pinMode(CHIP_SEL ,OUTPUT);
      digitalWrite(CHIP_SEL ,LOW);
      digitalWrite(CLOCK, LOW);
      Serial.begin(9600);
    }

    void loop()
    {

      for (int i=0;i<=511;i++)
      {
        digitalWrite(CHIP_SEL ,HIGH);
        shiftOut(DATA_OUT,CLOCK,MSBFIRST,READ); //sending READ instruction
        shiftOut(DATA_OUT,CLOCK,MSBFIRST,low);   //sending low address
        byte incoming = shiftIn(DATA_IN,CLOCK,MSBFIRST); //receiving data
        digitalWrite(CHIP_SEL ,LOW);

        Serial.print(low);
        Serial.print("/t");
        Serial.print(incoming, BIN);
        Serial.print("/t");
        Serial.print(incoming, HEX);
        Serial.println():

        low++;       //incrementing low address

      }
      while(1);
    }

What I'm trying to understand is:

In the 93C66 datasheet page 5, table 6, it says that to read the contents of memory I need to send SB 1, OPCODE 10, and memory address, which I don't know exactly how to do, but I guess the chip wants a 110 (or a HIGH, HIGH, LOW signal) plus memory address (variable “low”=0). The SB and OP CODE are similar to the BYTE variable READ in the code above, but this variable has an extra 0 (1100). I tested the code with 110 and I get different incoming data. I also thought if BYTE is 8 bits then why not make the BYTE variable READ 11000000, but it changes the incoming data. So now I don't really know how exactly to send SB 1 and OP CODE 10. Need help with that.

Also, as you can see I'm printing the variable "low" and the variable "incoming" (in Binary and Hex) on one line, I thought it would be printing 1 bit per line, but it prints varying amounts of bits. Sometimes it would print 4 bits, 6 bits, or 8 bits, as in 1110, 11111111, 111100. I thought the line `byte incoming = shiftIn(DATA_IN,CLOCK,MSBFIRST);`
would get filled with 8 bits all the time, so when I Serial.print() it would have 8 bits, but it's not happening, why?

Also I thought the shifting in of the bits into the variable "incoming" occurs once in the for loop, or is there an inner loop in shiftIn()? I ask because I first made the for loop go for i=<4095, since there are 4096 bits in this EEPROM, but the increment of I doesn’t match the amount of bits I’m getting on each Serial.print() line.
i.e. I would get something like this:

    1 10111111 BF

I thought it would be getting something like this. (I’m thinking the shiftIn() of the 1st bit at address 0 happens when i=0, then 2nd bits gets shiftIn() when i=1, and so forth)

    1 1
    2 1
    3 0
    4 1
    Etc, etc

How is shiftIn() shiftinf in the bits into the BYTE variable?

Thanks and sorry if it’s so many questions.

title: Trying to understand bitbanging, shiftIn(), reading EEPROM

Answers: 1

body:
OK I know this is a little late, but for other readers having the same problem, here's a sketch I wrote to read a 93c46 when I had to dump the EEPROM from a car radio. I've deliberately not included the EWEN instruction anywhere as the last thing I wanted to do was accidentally write to the EEPROM.

The key is the modified shiftOut routine which adds a parameter specifying how many bits you want to shift out.

To adapt sketch for other 93c packages, change the number of 16bit words at start of loop{} and number of address bits in 2nd call to myshiftOut.

If your package has an ORG pin, tie it to Vcc.

Hope this helps someone...

    /*
    Arduino Uno sketch to dump a 93c46 EEPROM in 16 bit mode.  Metalbanana 12/9/16, with thanks to raint.
    Easily modified for other 93c series parts. Note many 93c46 from autos are 'rotated' pinout,
    i.e. those with a T following part no. e.g. 'TEM8':

    1=NC    8=ORG
    2=Vcc   7=GND
    3=CS    6=DO
    4=SK    5=DI

    so check pcb for Vcc and GND locations with a meter first! An Arduino ProtoShield is ideal to mount IC
    as it has a SOIC pad (Note: you can't use the mini breadboard at same time as it covers one set of headers).
    Standard shiftOut is not suitable as it sends 8 bits, our addresses are 6 bits,
    instructions are 3 bits so sketch uses a modified shiftOut called myshiftOut.
    */

    // define pins for eeprom
    const int CHIP_SEL = 8;  // to CS
    const int CLOCK = 9;     // to SK
    const int DATA_IN = 10;  // to DO
    const int DATA_OUT = 11; // to DI

    const byte READ  = B110;                //read instruction

    bool debug = 0;

    void myshiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val, uint8_t bits)
    {
      for (int i = 0; i < bits; i++)  {
        if (bitOrder == LSBFIRST) {
          digitalWrite(dataPin, !!(val & (1 << i)));
          if (debug)Serial.print(!!(val & (1 << i)));
        }
        else
        {
          digitalWrite(dataPin, !!(val & (1 << (bits - 1 - i))));
          if (debug)Serial.print(!!(val & (1 << (bits - 1 - i))));
        }
        digitalWrite(clockPin, HIGH);
        digitalWrite(clockPin, LOW);
      }
    }

    void setup() {
      pinMode(CHIP_SEL, OUTPUT);
      pinMode(CLOCK, OUTPUT);
      pinMode(DATA_OUT, OUTPUT);
      pinMode(DATA_IN, INPUT_PULLUP);

      Serial.begin(9600);
      Serial.println("\n\n");
    }

    void loop()
    {
      for (int addr = 0; addr < 64; addr++) // 64 words for 93c46
      {
        // print address at start of each line
        if (addr % 8 == 0) {
          Serial.println();
          if (addr < 8) Serial.print("0");
          Serial.print(addr * 2, HEX);
          Serial.print(": ");
        }

        digitalWrite(CHIP_SEL, HIGH);
        myshiftOut(DATA_OUT, CLOCK, MSBFIRST, READ, 3); //send READ instruction
        myshiftOut(DATA_OUT, CLOCK, MSBFIRST, addr, 6); //send address, 6 bits for 93c46

        digitalWrite(CLOCK, LOW); // recommended in language reference
        byte incomingH = shiftIn(DATA_IN, CLOCK, MSBFIRST); //receive high byte
        byte incomingL = shiftIn(DATA_IN, CLOCK, MSBFIRST); //receive low byte

        // reverse byte order & print
        if (incomingL < 16) Serial.print("0");
        Serial.print(incomingL, HEX);
        Serial.print(" ");
        if (incomingH < 16) Serial.print("0");
        Serial.print(incomingH, HEX);
        Serial.print(" ");

        digitalWrite(CHIP_SEL, LOW);
      }

      while (1);
    }


body:
Experiencing that Mega 2560 uploading problem. Tried updating the IDE, worked for a while but symptoms went back. Now i want to reprogram that chip.

I'm asking this question cuz hardware ain't free and shipping is not instant.

I don't have a programmer. So we already know that we can program an arduino board with another arduino board as a programmer. However i just have a Duemilanove available. Will this work? Please do not answer if you're not sure.

title: Reprogram Arduino Mega 2560 using Duemilanove?

Answers: 1

body:
Yes it is possible.

You can follow this tutorial: http://www.gammon.com.au/forum/?id=11635
The uno is basically the same as the Duemilanove


body:
I wired ESP-05 to my usb-to-ttl as images below.

I connected it to USB #2 port, and my computer seems not knowing this.
![enter image description here][1]

I also tried to send "AT+RST" through Realterm but, it didn't work neither.

![enter image description here][2]

![enter image description here][3]

![enter image description here][4]

  [1]: https://i.stack.imgur.com/xRnbb.png
  [2]: https://i.stack.imgur.com/Ujhz5.jpg
  [3]: https://i.stack.imgur.com/9Ogin.jpg
  [4]: https://i.stack.imgur.com/gSEYz.png

title: My Computer Doesn't Realize ESP8266 ESP-05 is Connected or not

Answers: 0


body:
I have an Arduino Uno board.  I have seen how it is possible to program external AVR's through the Arduino Uno board, for instance an ATtiny. But I'm starting with c for atmel µc and I just want to program Atmel328's through the Arduino hardware, and being able to use the arduino pins for outputs etc.

So my question is, can I use the Arduino Uno board together with avrdude and avr-gcc to program the on-board atmel328 in C? And thus being able to use the Arduino pins for output and input?

title: Use Arduino Uno to program the on-board Atmega328 in C

Answers: 2

body:
Yes, the Uno is designed to be very simple to program. The only extra hardware you need is a USB cable to connect it to your computer.

If you're completely new to this then the simplest way to start is by following the official "[Getting Started][1]" guide. Note that the section on drivers is particularly important.

The guide explains how to use the official [Arduino IDE][2] for programming the microcontroller. It automatically handles compiling and uploading your code via gcc and avrdude. It's technically configured to compile as C++ code, but plain C code should be fine too.

I don't recommend that IDE for long-term use though as it's really only aimed at beginners (it has a number of limitations and other problems). Using the command-line tools directly is certainly possible if you'd prefer that. However, you may also like to consider [alternative IDEs][3] which have support for Arduino plug-ins.

  [1]: http://arduino.cc/en/Guide/HomePage
  [2]: http://arduino.cc/en/Main/Software
  [3]: https://arduino.stackexchange.com/questions/40/what-are-the-other-ides-for-arduino

body:
You're question is not so clear.
But from what I understood you are asking if you can program the Atmega328 with c using low level instruction and by setting manually all the registers in order to use IO ports of atmega. If that's what you're asking I will suggest you to use you're arduino ide to program the Atmega using register names as shown on the official datasheet. Doing so you can start learn the internal parts of the micro and at the same time you can avoid buying an external programmer. But if really want to load you're program or hex file you have to buy an external programmer.
I hope that helped

PS if you are using the arduino ide and writing manually the registers remember not to set incorrectly the configuration registers because that will make you're Atmega useless and you will need to buy an external programmer.

Edit:
For better understanding you can refer to this link.
[Programming arduino in c][1]

  [1]: https://balau82.wordpress.com/2011/03/29/programming-arduino-uno-in-pure-c/


body:
I am attempting to use SPI communication between a Master Arduino Mega 2560, and standalone Slave Arduino Unos (4, to be exact).

**The intention** is for the Unos to do some trivial work and produce one byte of data that the Master will take from it, whenever needed. They produce this byte very quickly, and the SPDR is updated with a holding variable (a byte) when the slave is interrupted. The Slaves do not take data from the Master.

The standalone platforms are working 100% (doing the work without problem), and using a single Slave to perform the work, create the byte of data, and have a Master take that data from it, is also working 100%.

**The issue** When all four slaves are connected (all being powered from the Master), all sharing the MISO, MOSI, and SCK lines, each with its own unique SS line, I am getting xFF for my data byte (garbage data) from the primary slave. I am using the default Mode 0, and the SCK lines are tied to ground via a 0.1uF capacitor (to smooth the clock signal)... All other SPI lines are wired directly.

The other three slaves are floating their MISO lines (third state), and the Master has all four SS lines as outputs, and all are pulled HIGH in the Master setup. The primary slave I am attempting to communicate with is SS connected to the main SS on the Master (pin 53 on a Mega). I pull the pin LOW, grab the byte from the Slave, and then pull the line HIGH... still garbage.. but only when all four slaves are 'hooked up', like I said, it works fine with one Master, one Slave.

Anyone have thoughts as to what I could be neglecting, missing, etc??

----

Here is the slave schematic. What you can't see is that VCC and AVCC are tied to the 5V line from the 10-pin header (the connection to the master).

![schematic](https://i.stack.imgur.com/eCtpa.png)

The external power supply I am currently using is added in parallel to the 5V/Grnd you see in the schematic. The power supply has a max current draw at 5V of 10A, so I'm pretty confident that power is not my issue now, unless I have missed something.

I just realized that the imgur image is hard to see, here is a cut-away that should be clearer.

![schematic](https://i.stack.imgur.com/dPaoy.png)

title: Slaving multiple Arduinos via SPI

Answers: 1

body:
> the SCK lines are tied to ground via a 0.1uF capacitor (to smooth the clock signal)

Get rid of that for a start.

> The other three slaves are floating their MISO lines (third state)

That's your problem. They should all be outputs. From the datasheet:

> When the SPI is configured as a Slave, the Slave Select (SS) pin is always input. When SS is held low, the SPI is activated, and MISO becomes an output if configured so by the user. All other pins are inputs. When SS is driven high, all pins are inputs, and the SPI is passive, which means that it will not receive incoming data. Note that the SPI logic will be reset once the SS pin is driven high.

As you can see from that, you should configure all the MISO pins as outputs. However the SPI hardware will turn them into inputs if SS is high. Thus only one slave (the one you set MISO as an output) is capable of responding at present.

You should probably set them as outputs **after** turning on SPI slave mode. eg.

      // turn on SPI in slave mode
      SPCR |= bit (SPE);

      // have to send on master in, *slave out*
      pinMode (MISO, OUTPUT);


body:
I'm using I2C and the Arduino Library (Wire) to communicate between two Arduinos, and my code isn't working. It's supposed to read in an int from the slave, write a value to the slave, then read back that value. I'm expecting "0 4", but i keep getting "0 0". Does this mean that the slave isn't registering the write?

Master code:

<!-- language: lang-cpp -->

    #include <Wire.h>

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

    void ffsis()
    {
      //request i
      Wire.requestFrom(2, 1);
      int i = Wire.read();
      Serial.print(i);

      //send n seed
      Wire.beginTransmission(2);
      Wire.write(12);
      Wire.endTransmission();

      Serial.print(" ");

      //request n
      Wire.requestFrom(2, 1);
      int n = Wire.read();
      Serial.print(n);
    }

    void loop()
    {
      delay(100);
    }

Slave code:

<!-- language: lang-cpp -->

    #include <Wire.h>

    void setup()
    {
      Wire.begin(2);
      Wire.onRequest(requestEvents);
      Wire.onReceive(receiveEvents);
    }

    void loop(){}

    int n = 0;

    void requestEvents()
    {
      Wire.write(n);
    }

    void receiveEvents(int howMany)
    {
      int n = wire.read();
    }

title: Using I2C: Master Reader and Writer

Answers: 2

body:
Since you have
int n
in the receiveEvents function, you're making a new local variable, not using the global n variable.

body:
>   int n = wire.read();

"Wire" should be capitalized.

Amplifying on Ken's reply, you have two variables called "n", **and** the global one should be declared **volatile**. Also, I2C deals in bytes, not ints, so preferably do this:

    #include <Wire.h>

    void setup()
    {
      Wire.begin(2);
      Wire.onRequest(requestEvents);
      Wire.onReceive(receiveEvents);
    }

    void loop(){}

    volatile byte n = 0;

    void requestEvents()
    {
      Wire.write(n);
    }

    void receiveEvents(int howMany)
    {
      n = Wire.read();
    }

In addition, the address 2 is a *reserved address*.

> Address 0 is reserved as a "broadcast" address, addresses 1 to 7 are reserved for other purposes, and addresses 120 to 127 are reserved for future use.

You should choose an address in the range 8 to 119.

### Reference

* [I2C - Two-Wire Peripheral Interface - for Arduino](http://www.gammon.com.au/i2c)
* [Official I2C specification](http://www.nxp.com/documents/user_manual/UM10204.pdf)


body:
I am working in an interactive project in displaying texts in POV which people can click to generate different texts automatically.

I wrote a String to store the text first, but it seems cannot display it.
Then I change the code to use `char*` to store the text, but it still does not work.

Can anybody help to solve this problem....?

    char* myStrings[] = {
      "a", "c", "d", "f",
      "b", "e", "v", "B", "C"];

[![Error][1]][1]

The code:

    loop(){

      //xbee
      // potVal = analogueRead(potPin);
      // xbee.println(potVal);
      for (int t=0; i<sizeof(myStrings)-1; i++) {
        displayChar(myStrings[i];
      }
      for (int i=0;i<7; i++)
        digitalWrite(leds[i],LOW);
      delay(10);

[![Screenshot of sketch][2]][2]

  [1]: https://i.stack.imgur.com/7I1Td.png
  [2]: https://i.stack.imgur.com/69vso.png

title: How to Display data from Strings?

Answers: 2

body: Like the error message says, each entry is a `char*`. Convert it to an array of characters instead.

body:
First thing, in C++ (or C) a character in single quotes is just a single lone character, but any characters in double quotes is a string literal. for example `"hello"` is a `const char[6]` containing the characters `'w'`,`'o'`,`'r'`,`'l'`,`'d'`,`'\0'`. That extra `'\0'` is the null terminator that makes an array of chars into a c-string.

Your code is making a variable

    char* myStrings[] = { "a", "c", ... };

This is an array of `char*`, which means each element is a `char*`, which in turn means each element is a full string (in your case each has 2 characters).

You want an array of single characters, which means you either drop the `*` in `char*`, or drop the `[]` in `myStrings[]`, and use either an array of single characters `{'a','b',...}`, or a single string literal `"acdfbevBC"`. Any of these lines will work in your code:

    const char * myStrings = "acdfbevBC";
    char myStrings[] = "acdfbevBC";
    char myStrings[] = { 'a', 'c', 'd', ... 'C', '\0'};

If you never plan to print `myStrings` as a unified string, you can leave off the `'\0'`, the null terminator is there so functions that you pass it to know when it stops without you having to explicitly pass how long the string is.

Also, the first line is `const char *` because you should never overwrite a string literal. `char myStrings[]` is fine without const because the compiler is using the literal to initialize an array that gets its own place in memory, not making `myStrings` point into a separate cache of string literals.

Check out [cpp reference's details here][1] for more details on string literals.

  [1]: http://en.cppreference.com/w/cpp/language/string_literal


body:
On a new Mac (running OS X 10.10) with Java 7 or 8 already installed (for other development), how can I run the Arduino 1.0.6 IDE (which seems to be required for the LightBlue Bean BLE Arduino device), which seems to require using a very old Java 6 installer from Apple?

Is there a way to install multiple versions of Java without breaking any of them?  Or is there a way to use the Arduino 1.0.x IDE with a newer version of Java?

Or should I re-ask this question over at the apple.stackexchange.com site?

title: How to run Arduino 1.0.6 on OS X 10.10 with Java 7 or 8 already installed

Answers: 0


body:
I am trying to connect my Android smartphone with my Arduino Uno by sending a NDEF message to my phone.
I know that the MIME type for bluetooth is application/vnd.bluetooth.ep.oob but in my PN532 library I don't know what's the right prefix.

You can see prefixes here : https://github.com/Seeed-Studio/PN532/blob/master/PN532/PN532.h#L66

Thank you

title: Don's NDEF library and bluetooth

Answers: 0


body:
Linkit One is a board based in Arduino by mediatek.
I am trying to connect a rfid reader with it [link][1]
I am trying from past 3 days to get it working, checked my code wiring but nothing seems to get it working.
The reader is perfectly working because i tested it on raspberryPi and it worked flawlessly.
In my linkit board i am able to detect the reader but card is not getting scanned.
I am using this library [GitHub][2]
and my code is fairly simple one

    #include <SPI.h>
    #include <MFRC522.h>
    #define RST_PIN 9 //
    #define SS_PIN 10 //
    MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
    void setup() {
    Serial.begin(9600); // Initialize serial communications with the PC
    while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin(); // Init SPI bus
    mfrc522.PCD_Init(); // Init MFRC522
    ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
    }
    void loop() {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
    }
    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
    }
    // Dump debug info about the card; PICC_HaltA() is automatically called
    mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
    }
    void ShowReaderDetails() {
    // Get the MFRC522 software version
    byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
    Serial.print(F("MFRC522 Software Version: 0x"));
    Serial.print(v, HEX);
    if (v == 0x91)
    Serial.print(F(" = v1.0"));
    else if (v == 0x92)
    Serial.print(F(" = v2.0"));
    else
    Serial.print(F(" (unknown)"));
    Serial.println("");
    // When 0x00 or 0xFF is returned, communication probably failed
    if ((v == 0x00) || (v == 0xFF)) {
    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
    }
    }

This program in theory should detet reader and when card is scanned should display the UID.

I am getting msg that my card is v2, so its detecting the reader but not reading the card.
![enter image description here][3]

  [1]: http://www.ebay.com/itm/Mifare-RC522-Card-Read-Antenna-RF-Module-RFID-Reader-IC-Card-Proximity-Module-/261268585155?pt=LH_DefaultDomain_0&hash=item3cd4d23ac3
  [2]: https://github.com/miguelbalboa/rfid
  [3]: https://i.stack.imgur.com/CUH1h.png

title: Linkit One- Connect rc522 rfid with linkit one

Answers: 2

body:
my friend, i have some problems with version 2.0 trying to read some cards. i think that the problem when  u cant read the card is this version . i have both version 1.0 and 2.0, version 1.0 detect all card type, and 2.0 some not.
for me is a big problem because, here in argentina i only found version 2.0. maybe change on library some.

body:
This link worked for me:

http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt

Found it in a forum:

> Please have a look at this ino file
> http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt
> this ino file works with my reader  but this rc522 library does not
> https://github.com/miguelbalboa/rfid  I want to know the difference as
> i was not able to spot any, one works and another does not.
>
> Please let me know if there is any editing to be done so to get
> https://github.com/miguelbalboa/rfid this working


body:
I'm trying to send 3 ints in the range of 0-180 from Python to the Arduino Uno device using pySerial (py3K). I have managed to send 1 int by using python's struct lib (not sure if it's the best or fastest way but it works).

However I'm failing to send more than 1 and every example online seems to stop at 1.

Here's the simplified code. The task is to send servo0-servo4 to the Arduino and apply those values to the corresponding servos.

Python Code

<!-- language-all: lang-python -->

    import serial
    import struct
    import time

    bge.arduino = serial.Serial('/dev/ttyACM0', 9600)

    # let it initialize
    time.sleep(2)

    # send the first int in binary format
    bge.arduino.write(struct.pack('>B', 45))

Arduino code

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

    #include <Servo.h>
    Servo servo0;
    Servo servo1;
    Servo servo2;

    void setup(){
      Serial.begin(9600);
      servo0.attach(3);
      servo1.attach(5);
      servo2.attach(6);
    }

    void loop(){
      if(Serial.available()){
        int message = Serial.read();
        // control the servo
        servo0.write(message);
      }
    }

title: Send multiple int values from Python to Arduino using pySerial

Answers: 2

body:
I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

    # write to arduino as raw binary
    bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

    #include <Servo.h>

    Servo servo0;
    Servo servo1;
    Servo servo2;

    // create array
    int incoming[2];

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

      servo0.attach(3);
      servo1.attach(5);
      servo2.attach(6);
    }

    void loop(){
      while(Serial.available() >= 3){
        // fill array
        for (int i = 0; i < 3; i++){
          incoming[i] = Serial.read();
        }
        // use the values
        servo0.write(incoming[0]);
        servo1.write(incoming[1]);
        servo2.write(incoming[2]);
      }
    }

body:
    void loop(){
      if(Serial.available() >= 3){
        // fill array
        for (int i = 0; i < 3; i++){
          incoming[i] = Serial.read();
        }
        // use the values
        servo0.write(incoming[0]);
        servo1.write(incoming[1]);
        servo2.write(incoming[2]);
      }
    }


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

Brief - I am using two arduino Uno's. One acts as a master and the other as slave using Arduino IDE.  Below is the Master Code:

    // Taken from Nick Gammon's Forum//

    #include "SPI.h"
    #include"pin_arduino.h"
    int ss = 10;
    void setup()
      {
        pinMode(ss,OUTPUT);
        Serial.begin(9600);
        Serial.println();
        digitalWrite(ss,HIGH);
        SPI.begin();
        SPI.setClockDivider(SPI_CLOCK_DIV8);
       }
    byte transferAndWait(const byte what)
     {
       byte a = SPI.transfer(what);
       delayMicroseconds(20);
       return a;
     }
    void loop()
     {
       byte a,b,c;
       digitalWrite(ss,LOW);
       transferAndWait('a');
    a = transferAndWait(17);
    b =  transferAndWait(33);
    c = transferAndWait(0);
    digitalWrite(ss,HIGH);
    Serial.println(a,DEC);
    Serial.println(b,DEC);
    Serial.println(c,DEC);
    delay(1000);
     }

Before I go into the details of the results I obtained and the problem, below is the Slave code:

    //Taken from Nick Gammon's Forum//

    #include "SPI.h"
    #include "pins_arduino.h"
    int slave = 10;
    int miso = 11;
    byte c = 0;
    void setup()
      {
        pinMode(miso,OUTPUT);
        pinMode(slave,INPUT);
        Serial.begin(9600);
        SPR|= BV_(SPE);
        SPR|= BV_(SPIE);
     }
    ISR(SPI_STC_vect)
     {
       c = SPDR;
      switch(c)
        {
          case 0:
          SPDR = 0;
          break;

         case 'a':
         SPDR = c + 15;
         break;
       }
      }
      void loop(void)
       {
         if(digitalRead(slave)==HIGH)
         c = 0;
       }

My Results : After dumping the master and slave codes into their respective arduino uno's, then when I open the serial monitor of the master code, It displays the number 17, 33, 0 and the same goes with the slave, meaning that the data is being sent to the slave and received back successfully, and hence I presume the SPI bus is working properly!. But why isn't the add operation happening?

Problem: Now the problem is, when the command 'a' is sent from the master to the slave, the slave has to interpret this 'a' command as Addition command and perform the addition of a number 15 to the incoming byte from the master as shown in the slave code, and return the results to the master, which should display the addition results in the  masters serial monitor. I am having problem performing this task and looking forward to suggestions on how to test or where I am doing wrong or make changes to the code or methods in order to get this working. I am expecting answers relevant to the below codes and method.

title: Not able to receive the operation results from the slave after the command being sent by Master - SPI

Answers: 2

body:
    ISR(SPI_STC_vect);  <-- Reason 1.
     {
       byte c = SPDR;
      switch(command)   <-- Reason 2.
        {                      |
          case 0:              |
          command = c;  <------┘
          SPDR = 0;
          break;

         case 'a':
         SPDR = c + 15;
         break;
       }
      void loop(void)   <--- Reason 3.
       {
         if(digitalRead(slave)==HIGH)
         command = 0;
       }

The slave code is not going to work, for various reasons.

Reason 1:
This is a declaration of a function. Not an implementation.
The ";" is badly misplaced here.

Reason 2: You're switching on a value "command" but it's only changed after executing the case/command?

Reason 3: The loop function is still part of the previous function?
The "{" below the ISR(SPI... isn't closed right. (With another "}")

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

Since I wrote that example, I'll try to answer this. First I tested with the code from [my page about SPI](http://www.gammon.com.au/spi).

---

## SPI Master

This is the master:

    #include <SPI.h>

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

      digitalWrite(SS, HIGH);  // ensure SS stays high for now

      // Put SCK, MOSI, SS pins into output mode
      // also put SCK, MOSI into LOW state, and SS into HIGH state.
      // Then put SPI hardware into Master mode and turn SPI on
      SPI.begin ();

      // Slow down the master a bit
      SPI.setClockDivider(SPI_CLOCK_DIV8);

    }  // end of setup

    byte transferAndWait (const byte what)
    {
      byte a = SPI.transfer (what);
      delayMicroseconds (20);
      return a;
    } // end of transferAndWait

    void loop (void)
    {

      byte a, b, c, d;

      // enable Slave Select
      digitalWrite(SS, LOW);

      transferAndWait ('a');  // add command
      transferAndWait (10);
      a = transferAndWait (17);
      b = transferAndWait (33);
      c = transferAndWait (42);
      d = transferAndWait (0);

      // disable Slave Select
      digitalWrite(SS, HIGH);

      Serial.println ("Adding results:");
      Serial.println (a, DEC);
      Serial.println (b, DEC);
      Serial.println (c, DEC);
      Serial.println (d, DEC);

      // enable Slave Select
      digitalWrite(SS, LOW);

      transferAndWait ('s');  // subtract command
      transferAndWait (10);
      a = transferAndWait (17);
      b = transferAndWait (33);
      c = transferAndWait (42);
      d = transferAndWait (0);

      // disable Slave Select
      digitalWrite(SS, HIGH);

      Serial.println ("Subtracting results:");
      Serial.println (a, DEC);
      Serial.println (b, DEC);
      Serial.println (c, DEC);
      Serial.println (d, DEC);

      delay (1000);  // 1 second delay
    }  // end of loop

---

## SPI Slave

And this is the slave:

    // what to do with incoming data
    volatile byte command = 0;

    void setup (void)
    {

      // have to send on master in, *slave out*
      pinMode(MISO, OUTPUT);

      // turn on SPI in slave mode
      SPCR |= _BV(SPE);

      // turn on interrupts
      SPCR |= _BV(SPIE);

    }  // end of setup

    // SPI interrupt routine
    ISR (SPI_STC_vect)
    {
      byte c = SPDR;

      switch (command)
      {
      // no command? then this is the command
      case 0:
        command = c;
        SPDR = 0;
        break;

      // add to incoming byte, return result
      case 'a':
        SPDR = c + 15;  // add 15
        break;

      // subtract from incoming byte, return result
      case 's':
        SPDR = c - 8;  // subtract 8
        break;

      } // end of switch

    }  // end of interrupt service routine (ISR) SPI_STC_vect

    void loop (void)
    {

      // if SPI not active, clear current command
      if (digitalRead (SS) == HIGH)
        command = 0;
    }  // end of loop

---

## Test results

Testing gave the expected results:

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

    Adding results:
    25
    32
    48
    57
    Subtracting results:
    2
    9
    25
    34

---

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

So, what is different in your code?

Your slave ISR:

    ISR(SPI_STC_vect)
     {
       c = SPDR;
      switch(c)
        {
          case 0:
          SPDR = 0;
          break;

         case 'a':
         SPDR = c + 15;
         break;
       }
      }

This isn't quite the same, is it? In my code you get the command in one session (one interrupt) and what to use it for in another one.

Hence I had this:

      byte c = SPDR;

      switch (command)
      {
      // no command? then this is the command
      case 0:
        command = c;
        SPDR = 0;
        break;

Sending a "command" of zero clears the current command. So the sequence being sent is like this:

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

    0    <-- start a new command
    command  (ie. 'a' or 's')
    22   <-- what to add to
    33   <-- what to add to
    44
    55

Perhaps confusingly, I didn't send in that order, because I knew that the command would be zero initially<sup>(1)</sup>, so I actually sent:

    command  (ie. 'a' or 's')
    22   <-- what to add to
    33   <-- what to add to
    44
    55
    0    <-- start a new command

There would be other ways of achieving this, but the fact is you changed the way the slave interpreted the incoming data.

---

1. I knew it would be zero because the slave sets the command to zero in the main loop if SS is not asserted.


body:
A few years ago I programmed AVR ATmega8 with AVR studio by USB isp programmer.
I was using C language. Now I would like to use arduino(C++) langauge and my external USB isp programmer. Is it possible?

title: use arduino IDE for USB isp programmer

Answers: 3

body: If you want to use arduino IDE to program the atmega328 you don't need a USB ISP programmer. The only thing you have to do is load the arduino bootloader on the atmega328 in order to program it through the arduino IDE. In the ide you can program the board with c++. But if you want to program the atmega328 through you're USB ISP programmer (assuming it is capable of programming the Atmega 328) you have to use other IDE in which you can program in c++ and produce an hex file that can be burned on the chip through you're  programmer on the atmega328.

body: The programmers supported by the Arduino IDE are listed under `Tools` | `Programmer`. In order to upload your sketch using the programmer either Shift-click the upload button, select `File` | `Upload Using Programmer`, or press CtrlShiftU.

body: The Arduino IDE compiles and outputs standard Intel HEX format files that are compatible with (nearly?) all programmers. If you enable detailed logging in the preferences panel you can find out which directory the IDE is building your code in and if the IDE does not include specific support for your programmer you can then locate the .hex file and upload it using the tool you are familiar with. The projects are typically built in a `build.*` subdirectory under %TEMP% (or /tmp on unix).


body:
I'm trying to control motors by Arduino, from my laptop. I'm using MATLAB to send over packets of data, i.e. 'x=100,y=150,z=200' My scheme was to send this packet to Arduino, and have Arduino extract the numerical values from the string, since the positions of the numbers will always be consistent. I found a code from Arduino forum, written by PaulS, but I can't figure out why it wouldn't move into 'if (xbee.available())' portion of the code. The code is attached below:
<!-- language-all: lang-cpp -->

    #include <SoftwareSerial.h>
    #define SOP '<'
    #define EOP '>'

    SoftwareSerial XBee(2, 3); // RX, TX
    int test = 0;
    bool started = false;
    bool ended = false;

    char inData[20];
    byte index;
    char inChar;

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

    void loop()
    {
      // Read all serial data available, as fast as possible
      while(Serial.available() > 0)
      {
        if (XBee.available())
        {
          char inChar = XBee.read();
         }
        if(inChar == SOP)
        {
           index = 0;
           inData[index] = '\0';
           Serial.print(inData);
           started = true;
           ended = false;
        }
        else if(inChar == EOP)
        {
           Serial.print(inChar);
           ended = true;
           break;
        }
        else
        {
          if(index < 19)
          {
            inData[index] = inChar;
            Serial.print(inData);
            index++;
            inData[index] = '\0';
          }
        }
      }

      // We are here either because all pending serial
      // data has been read OR because an end of
      // packet marker arrived. Which is it?
      if(started && ended)
      {
        // The end of packet marker arrived. Process the packet
        Serial.println(inData);
        // Reset for the next packet
        started = false;
        ended = false;
        index = 0;
        inData[index] = '\0';
      }
    }

title: Using XBEE from my laptop, I want to assign multiple values in the Arduino

Answers: 0


body:
when I upload the code to my leonardo board it just stuck on uploading, like this:![enter image description here][1]

  [1]: https://i.stack.imgur.com/vyXxF.png
could someone help me with this?

title: Pixy Pet Robot stuck on uploading code

Answers: 0


body:
I am having some strange issue. I am using Linkit One board, which is a based on Arduino.

I am using rfid reader RC522 which is cheapest and most common.

I cant get its official library get it work. I tried to search for problem or differences but nothing help. I am looking for some to take a fresh look because its been 4 days and i am stuck.

Not Working [https://github.com/miguelbalboa/rfid][1]

Working (this is full ino in single file) [http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt][2]

  [1]: https://github.com/miguelbalboa/rfid
  [2]: http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt

title: RFID library issue

Answers: 0


body:
I am trying to call a HTTP GET using my Arduino via SIM900A.

When I run the commands manually via the USB port, I am able to get the commands to run. Now, when I put the same sequence on arduino, the `setup()` is called repeatedly after the `sendATcommand(httpAuthCommand, "OK", 2000);`. Looks like a reset issue.

I read, this link to put all my code into `loop` to avoid the `setup()` reset issue. But seems like this is did not fix the issue.

I have debugged it to this one change.

**This Works**

    char httpAuthCommand[] = "AT+HTTPPARA=\"URL\",\"http://www.m2msupport.net/m2msupport/http_get_test.php\"" ;

**This Does Not work**

    char httpAuthCommand[] = "AT+HTTPPARA=\"URL\",\"http://1.1.1.1:8080/mytomcatservice/mypath/mycommand/Request?identity=+1234567890&identityType=1\"" ;

I debugged this a bit more, it does not work when I add `?identity=+0123456789&identityType=1` to the httpAuthCommand. Something crazy while sending parameters ??

**In loop()**

    sendATcommand(httpAuthCommand, "OK", 2000);

**sendATcommand method**

    int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

        uint8_t x=0,  answer=0;
        char response[100];
        unsigned long previous;
        memset(response, '\0', 100);    // Initialice the string
        delay(100);
        while( Serial.available() > 0) Serial.read();    // Clean the input buffer
        Serial.println(ATcommand);    // Send the AT command
        x = 0;
        previous = millis();
        // this loop waits for the answer
        do{
            // if there are data in the UART input buffer, reads it and checks for the asnwer
            if(Serial.available() != 0){
                response[x] = Serial.read();
                x++;
                // check if the desired answer is in the response of the module
                if (strstr(response, expected_answer) != NULL)
                {
                    answer = 1;
                }
            }
        // Waits for the asnwer with time out
        }while((answer == 0) && ((millis() - previous) < timeout));

        return answer;
    }

Raw commands work on Chrome

>http://www.m2msupport.net/m2msupport/http_get_test.php

>http://1.1.1.1:8080/mytomcatservice/mypath/mycommand/Request?identity=+918177900460&identityType=1

**My Guess**

I am missing some escape sequence characters in the command (especially in the parameters section `?identity=+0123456789&identityType=1`).

title: setup() resets from loop, when I add parameters to http get `?identity=+0123456789&identityType=1`

Answers: 2

body:
 "Something crazy while sending parameters ??"

Possibly your power supply is to weak so 5V drops low and the processor resets when the transmitter sends a message.

body:
Could you have exceeded the rather limited RAM?
First experiment: Replace the added string with "xxx....x". If you have the same problem, then it's not the contents of the string but its length.
Second experiment (or jump straight to this one): [Compile your strings in flash][1] instead of in RAM. Note this will only help if you have a number of them, since your code will have to copy each one to RAM (at run-time) in order to use it, taking up some of the space you had saved. If there is only one string moved to flash, your code will need a temporary buffer of equal size (though only during the actual print call). A possible way around this is to break up the long string into a number of short ones, put all of them in flash, then print them sequentially at run time. That will need a buffer only as large as your largest substring. The cost will be increased use of flash, both for string storage and for the extra number of print calls; and slightly slower execution (probably not an issue).

This may be telling you that you need a more capable processor (one with more RAM space) or that you need to start getting creative about fitting your application into the one you've got.

  [1]: http://www.arduino.cc/en/Serial/Print


body:
I executed the following steps in order to burn a bootloader into an  AVR328P-PU chip I acquired on ebay.

 1. I have set up AVR328P-PU on a breadboard as described here: http://arduino.cc/en/main/standalone

 2. I have uploaded the ArduinoISP sketch into Arduion Uno.

 3. Connected the wires in a way described here http://arduino.cc/en/Tutorial/ArduinoToBreadboard ( the setup with external clock)
 4. Chose "Tools -> Programmer -> Arduion as ISP" in the IDE.

 5. Chose "Burn Bootloader" from the IDE.

 6. Got and error ` avrdude: Yikes!  Invalid device signature.`, noticed that I connected the wires in the wrong order.

 7. Fixed the wired, but still got the error:

avrdude: Version 6.0.1

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

         Using Port                    : COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.06s

    avrdude: Device signature = 0x000000 (retrying)

    Reading | ################################################## | 100% 0.05s

    avrdude: Device signature = 0x000000 (retrying)

    Error while burning bootloader.
    Reading | ################################################## | 100% 0.07s

    avrdude: Device signature = 0x000000
    avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

    avrdude done.  Thank you.

![Breadboard + Arduino][1]

![Breadboard Close-Up][2]

# My questions
1. I understand that this can be caused by poor breadboard quality. How can I test this hypothesis before buying new breadboard?

2. Could the wrong wiring from step 5 ruin the chip?

  [1]: https://i.stack.imgur.com/2hTrr.jpg
  [2]: https://i.stack.imgur.com/ReuMi.jpg

title: Problem Bootloading AVR328P-PU

Answers: 2

body:
Being from eBay, I would assume the seller "bricked" the chip beyond his/her capability to fix.  Fortunately, you know about stack exchange!

My immediate suggestion is to find, borrow or build a high-voltage programmer.  This is a special programmer that can un-brick the chip no matter what's been done to it. The concept is easy, but you need to protect the programmer's pins from the 12v reset signal.

Googling "avr high voltage programmer" gives several useful links.
I'll get the actual links when I get back to a real computer.

Ok, so life got in the way, sorry about that.
This is the one I built which worked perfectly:
[MightyOhm][1]

However hooking up the AVR to a "high voltage programmer" is well documented in the data sheets.  These should be very much similar [circuits on Google][2].

  [1]: http://mightyohm.com/blog/products/hv-rescue-shield-2-x/design-files/
  [2]: https://www.google.com/search?q=Schematic of a "High Voltage Parallel-Programmer&ie=utf-8&oe=utf-8

body:
I had this exact same problem.  It turned out that my atmega328p had the wrong fuses.  I am not sure how to solve the problem using the default ardiuino ide, however I was able to plug my ArduinoISP into a linux machine (just plug in the usb) and correctly profram the fuses on a slave atmega328p to solve the problem:

The guide here gets you started, however it missing some of the fuses:
http://heliosoph.mit-links.info/arduinoisp-reading-writing-fuses-atmega328p/

The full command to set the default fuses is something like this:

    avrdude -P /dev/ttyACM0 -b 19200 -c arduino -p m328p -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0x05:m


body:
Is it possible to use a custom bootloader, that loads and executes a main program stored for example on an SD card? The idea is to make it possible to update the Arduino remotely.

I tried this with a bootloader, which writes the program into the flash storage with a 32KB offset and then uses a function pointer with that address (0x88000) to continue execution there. The 0x80000 is as far as I am informed the address offset of the flash storage. It can be written on Due boards with this library: https://github.com/sebnil/DueFlashStorage. The problem was that this just hasn't worked, the Arduino simply stopped responding after the function pointer being executed. I would appreciate any information or hints on this topic.

title: How do I implement a userspace bootloader on Arduino Due?

Answers: 2

body: Not sure if you could get the bootloader to support SD, but I have little experience with bootloader code, so the way I would go about it would be to make the sketch load content from the SD that then affects the sketch process.

body:
The guys at [Phoenard][1] did just that with an AVR2560. They wrote [a bootloader][2] that loads and saves FLASH memory from/to the Micro-SD card. You can save HEX files on an SD card and then load one of them in the FLASH memory and run it.

  [1]: http://phoenard.com/
  [2]: https://github.com/Phoenard/Phoenboot


body:
[This page][1] says to run a shell command I need a "proxy code" running on my computer (Linux Ubuntu). What do they mean by this, and how should I make one?

  [1]: http://forum.arduino.cc/index.php?topic=38627.0

title: How can I execute a shell command?

Answers: 1

body:
I'm not familiar with the term *proxy code,* but I'm assuming that it's a piece of code on your computer that acts as a man in the middle.

You cannot directly use Arduino to run a shell command, so you'll need to create a program on your computer that listens to **[serial][1]** and then executes a command.

For the "proxy code" Python would be a good choice because of the **[pySerial library][2]** that plays nicely with Arduino. It seems [fairly easy to execute a shell command with Python][3].

As per the Arduino code, something like this would work good:

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

    loop() {
      if(state == true) {
        Serial.print('A');
      }
    }

  [1]: http://arduino.cc/en/reference/serial
  [2]: http://pyserial.sourceforge.net/
  [3]: https://stackoverflow.com/questions/89228/calling-an-external-command-in-python


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

I have a project using the RC522 RFID module with my Arduino Uno board and miguelbalboa's rfid library. The example code and every other code I find on the internet work pooling the device in order to know if there is a new card present, but I intend to work with a interrupt-driven approach. I have the proper knowledge to do the hardware/arduino part, but I'm having trouble generating an interrupt in the IRQ pin when the card is present. Have anyone succeded on this?

Edit:
Connection:
RST -> 8

SS-> 9

MOSI -> 11

MISO -> 12

SCK -> 13

IRQ -> 2

Code:

    #include <SPI.h>
    #include <MFRC522.h>
    #include <String.h>

    #define RST_PIN  8
    #define SS_PIN  9

    MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

    void setup()
    {
      Serial.begin(9600);  // Initialize serial communications with the PC
      while (!Serial);  // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
      SPI.begin();   // Init SPI bus
      mfrc522.PCD_Init();  // Init MFRC522
      mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
      mfrc522.PCD_WriteRegister(MFRC522::ComIEnReg, 0x7F); //Enable all interrupts
      mfrc522.PCD_WriteRegister(MFRC522::DivIEnReg, 0x14);
      Serial.println(F("Ready..."));
      attachInterrupt(0, isr, RISING);
    }

    void loop()
    {
    }

    void isr()
    {
      Serial.println(F("Interrupt"));
      mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
    }
Result:
I only get the "Ready..." on the Serial Monitor, no matter if there is a card present or not.

title: Using interrrupts with RC522

Answers: 3

body:
first of all, I apologize for the English, I can understand it but i use google translator to express myself in.

 I don't use arduino, It's a interesting platform (for the ide, which is apparently object oriented programming POO), but extremely limited by the hardware

Well, entering the subject, I am also developing an implementation for the MRFC522, and the datasheet does not give examples of how do it, but indicates how enable interrupts (although I have not tried ,yet)

but if I'm not wrong, the following registers are involved:

ComIEnReg--> Control register bits to enable and disable the passing of interrupt requests.

DivIEnReg--> control bits to enable and disable the passing of interrupt requests.

ComIrqReg--> register Interrupt request bits. (I think it's read only)

DivIrqReg--> register bit descriptions (I think it's read only)

I think it's just properly setting the first two should be able to generate the interrupt on the pin irq.
i don't know if the following is correct.

set ComIEnReg to --> (in binary) 0b01111111 //enables all al interrupts

set DivIEnReg to --> 0b10000100  //I don't understand complete about MFIN (bit4) and set it to 0  but i set CRCIEn to 1 (bit 2) and bit7  to 1 "pin IRQ is a standard CMOS output pin"

// the different posible configuration to DivIEnReg

- yours--> 0b00010100 -->0x14
- try 1 --> 0b00000100 -->0x04
- try 2 --> 0b10010100 -->0X94
- try 3 --> 0b10000100 -->0X84

if you manage to the module to do the interruption, it would be kind enough to comment on how you did

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

From your code:

    void isr()
    {
      Serial.println(F("Interrupt"));
      mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
    }

Do not do serial prints inside an ISR! They will eventually hang it. What you need to do is have a volatile variable (eg. a bool), set that in the ISR, and then check that in `loop`. If it changes, display it. Eg.

    volatile bool cardPresent;

    void loop()
    {
      if (cardPresent)
        {
        Serial.println(F("Interrupt"));
        mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
        cardPresent = false;
        }

    }

    void isr()
    {
      cardPresent = true;
    }

---

The other thing I would do is put a scope or logic analyzer on the IRQ pin and see if it is actually changing. It *should* trigger the interrupt if it does.

body:
I'm quite late to this party, but I was looking for a way to have the MFRC522 generate an interrupt when it detects a compatible RFID card/key fob/sticker/etc., and this is one of the hits I got from my search. I write this now for the pilgrim who follows the same breadcrumbs I have in the hopes that it will save them at least a little time.

I tried something similar to what was suggested, found that I got interrupts quite often and continuously, and looked into the situation a bit more.

The MFRC522 does not generate interrupts for card detection. The microcontroller (or microprocessor) must command it to transmit and then query it to see if there was any response. This means that the MCU cannot go into a sleep mode and get awaken by the MFRC522 when there's a card to read.  The MFRC522 does have a timer that can generate an interrupt, but the maximum period of this timer is not huge, and the timer does not control the transceiver, it's there for the convenience of the application on the MCU.

Writing 0x7F to the "ComIEnReg" means the following:

- Bit 7: IRqInv=0 - Interrupts are active high</le>
- Bit 6: TxIEn=1 - Transmitter interrupt is enabled
- Bit 5: RxIEn=1 - Receive interrupt is enabled
- Bit 4: IdleIEn=1 - Idle interrupt is enabled
- Bit 3: HiAlertIEn=1 - "High Alert" interrupt is enabled
- Bit 2: LoAlertIEn=1 - "Low Alert" interrupt is enabled
- Bit 1: ErrIEn=1 - Error interrupt is enabled
- Bit 0: TimerIEn=1 - Timer interrupt is enabled

The bits in the register "ComIrqReg" have the following meaning:

- Bit 7: Set1 - when written as 1, a bit value of 1 in bits 6-0 of the byte written set the corresponding register bit; when written as 0, bits 6-0 clear the corresponding register bit
- Bit 6: TxIRq - Set when the last bit of Tx data has been sent
- Bit 5: RxIRq - Set when the receiver detects the end of a valid data stream
- Bit 4: IdleIRq - Set when the CommandReg changes the command field to the idle command
- Bit 3: HiAlertIRq - Set when the Status1 register HiAlert bit is set
- Bit 2: LoAlertIRq - Set when the Status1 register LoAlert bit is set
- Bit 1: ErrIRq - Set when any bit in ErrorReg gets set
- Bit 0: TimerIRq - Set when the TCounterValReg decrements to zero

Writing 0x14 to the "DivIEnReg" has the following meaning:

- Bit 7: IRQPushPull=0 - IRQ is an open-drain output pin
- Bit 6: reserved=0 - no known effect
- Bit 5: reserved=0 - effect unknown
- Bit 4: MfinActEn=1 - Allow the MFIN active interrupt request to trigger IRQ
- Bit 3: reserved=0 - boundedly undefined
- Bit 2: CRCIEn=1 - Permit the "DivIrqReg" bit CRCIRq to trigger IRQ
- Bit 1: reserved=0 - do not set to 1 on pain of nothing
- Bit 0: reserved=0 - has no purpose other than to confuse

The register "DivIrqReg" corresponds to "DivIrqEn", and has the following bit definitions:

- Bit 7: Set2 - when written as 1, a bit value of 1 in bits 6-0 of the byte written set the corresponding register bit; when written as 0, bits 6-0 clear the corresponding register bit
- Bit 6: reserved - don't ask
- Bit 5: reserved - don't tell
- Bit 4: MfinActIRq - MFIN is active
- Bit 3: reserved - just leave it at zero and back away slowly
- Bit 2: CRCIRq - when 1, the CalcCRC command is active and all data is processed
- Bit 1: reserved - nothing to see here
- Bit 0: reserved - are you feeling lucky, punk?

*The above register bit definitions were cribbed from the MFRC522 datasheet from NXP, titled ["MFRC522 Standard performance MIFARE and NTAG frontend", Rev 3.9, 27-April-2016.][1]*

The library for the MFRC522 does have an interrupt example that uses a lighter weight means of polling the transceiver. see [https://github.com/miguelbalboa/rfid/tree/master/examples/MinimalInterrupt][2], but it does not provide a means of waking your host from a low-power sleep mode when someone waves their magic ring over the hidden panel by the secret door, meaning that your secret lair will need to be wired to power the reader even if it is otherwise wireless; either that, or your henchmen will be forever changing batteries.

  [1]: https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf
  [2]: https://github.com/miguelbalboa/rfid/tree/master/examples/MinimalInterrupt


body:
I am trying to send and receive data using I2C between an Arduino Uno and an ATTiny85. The Arduino Uno is using the Wire library. The ATTiny85 is using the TinyWire library and is programmed (and powered) using the Sparkfun Tiny AVR Programmer.

I am not receiving any data.

Arduino Uno I2C master code

 #include <Wire.h>

 #define SLAVE_ADDR 0x50

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

 void loop()
 {
   Wire.requestFrom(SLAVE_ADDR, 1);

   while(Wire.available())
   {
     byte byteReceived = Wire.read();
     Serial.println(byteReceived, DEC);
   }
 }

ATTiny85 I2C slave code

    #include "TinyWireS.h"

    #define SLAVE_ADDR 0x50

    void setup()
    {
      TinyWireS.begin(SLAVE_ADDR);
      TinyWireS.onRequest(requestEvent);
    }

    void loop()
    {
    }

    void requestEvent()
    {
      byte byteToSend = 23;
      TinyWireS.send(byteToSend);
    }

title: Arduino Uno (master) and ATTiny85 (slave) I2C connection not working

Answers: 2

body: I think the problem is (assuming you've got the pins straight) is that there's no time for the byte to get to the Uno.  Try `while(!Wire.available())` between `requestFrom...` and the `while(Wire.available())`

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

I modified your Uno sketch slightly to add a delay:

    #include <Wire.h>

    #define SLAVE_ADDR 0x50

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

    void loop()
    {
      Wire.requestFrom(SLAVE_ADDR, 1);

      if (Wire.available())
      {
        byte byteReceived = Wire.read();
        Serial.println(byteReceived, DEC);
      }

     delay (1000);
    }

Upon testing, it worked perfectly!

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

    23
    23
    23
    23
    23
    23
    23
    23
    23
    23
    23
    23

I suggest a wiring error. Check you have:

    Uno    ATtiny85
    --------------------
    A4      pin 5  (SDA)
    A5      pin 7  (SCL)
    +5V     pin 8
    Gnd     pin 4


body:
This is a visualization of my Arduino connections:

![enter image description here][1]

I wish to read the data using the [Capacitive sensor Library](http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense). iv'e tried the following code but variables `total1`, `total2`, `total3` always have the value `0` and i don't know what is wrong.

**My code:**

    // Import the CapacitiveSensor Library.
    #include <CapacitiveSensor.h>

    // Name the pin as led.
    #define speaker 11

    // Set the Send Pin & Receive Pin.
    CapacitiveSensor   cs_2_3 = CapacitiveSensor(2,3);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
    CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
    CapacitiveSensor   cs_2_5 = CapacitiveSensor(2,5);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
    CapacitiveSensor   cs_2_6 = CapacitiveSensor(2,6);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
    CapacitiveSensor   cs_2_7 = CapacitiveSensor(2,7);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
    CapacitiveSensor   cs_2_8 = CapacitiveSensor(2,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
    CapacitiveSensor   cs_2_9 = CapacitiveSensor(2,9);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil

    void setup()
    {
      cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example

      // Arduino start communicate with computer.
      Serial.begin(9600);
    }

    void loop()
    {
      // Set a timer.
      long start = millis();

      // Set the sensitivity of the sensors.
      long total1 =  cs_2_3.capacitiveSensor(60);
      long total2 =  cs_2_4.capacitiveSensor(60);
      long total3 =  cs_2_5.capacitiveSensor(60);
     /* long total4 =  cs_2_6.capacitiveSensor(60);
      long total5 =  cs_2_7.capacitiveSensor(60);
      long total6 =  cs_2_8.capacitiveSensor(60);
      long total7 =  cs_2_9.capacitiveSensor(60);*/

      Serial.print(millis() - start);        // check on performance in milliseconds
      Serial.print("\t");                    // tab character for debug windown spacing

      Serial.print(total1);                  // print sensor output 1
      Serial.print("\t");                    // Leave some space before print the next output
      Serial.print(total2);                  // print sensor output 2
      Serial.print("\t");                    // Leave some space before print the next output
      Serial.print(total3);                  // print sensor output 3
      Serial.print("\t");                    // Leave some space before print the next output
      Serial.print("\n");
    }

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

title: Arduino UNO capacitive sensor not working

Answers: 1

body:
As found on the [Capacitative Sensor Library page](http://playground.arduino.cc/Main/CapacitiveSensor) (emphasis added):

> + **Use a 1 megohm resistor (or less maybe) for absolute touch to activate.**
> + With a 10 megohm resistor the sensor will start to respond 4-6 inches away.
> + With a 40 megohm resistor the sensor will start to respond 12-24 inches away (dependent on the foil size). Common resistor sizes usually end at 10 megohm so you may have to solder four 10 megohm resistors end to end.
> + **One tradeoff with larger resistors is that the sensor's increased sensitivity means that it is slower. Also if the sensor is exposed metal, it is possible that the send pin will never be able to force a change in the receive (sensor) pin, and the sensor will timeout.**
> + Also experiment with small capacitors (100 pF - .01 uF) to ground, on the sense pin. They improve stability of the sensor.

The two emboldened points suggest that for a touch-piano, it would likely be advantageous to use a lower value resistor such as 1MΩ. Because the sensitivity increases as the resistor value increases, you want to use the *lowest possible* resistor value to reduce jitter & interference among your signal wires.

<hr>
Also, later on the page:

> The grounding of the Arduino board is very important in capacitive sensing. The board needs to have some connection to ground, even if this is not a low-impedance path such as a wire attached to a water pipe.

Ensure the Arduino is not run from a battery or unplugged laptop. For capacitative sensing to work, a stable ground connection is needed (via a DC plugpack or USB wall-wart is fine).

As a general note, try testing with only one capacitative connection first, then when that works, re-add the others.


body:
OS: Ubuntu 14.04
Board: Teensy 3.1 and Arduino UNO

I've ran many tests and concluded that the issue is within the Arduino IDE itself.

The issue: Instead of a smooth stream of data displaying from the serial port, the terminal displays big chunks of data periodically.

I tested it with minicom and the stream of data is smooth.

Any solutions?

title: Arduino 1.6.1 IDE with Teensyduino Serial port lag issue?

Answers: 0


body:
I've got a BlueSMIRF Silver (RN-42) Bluetooth module.
I am trying to create a basic keyboard I can play with on an iPad Air.

At the moment barely manage to get the module to pair with OSX
but only through using Bluetooth Setup Assistant and using "**Passcode Options...use a specific code**".

With this option, the module pairs, but the connection resets about every 5 seconds.

On iPad it tries to use a generate number really fast and fails straight away, being unable to connect.

I noticed there is a BlueSMIRF HID version, but from what I can tell, the hardware is the same,
just the firmware is different. I've gone through the whole [Bluetooth Data Module Command Reference & Advanced Information User’s Guide][1](pdf link) manual and from what I can gather,
even though I have Silver firmware burned onto my module, I should be able to set and use the HID profile
(from the default SPP):

> Roving Networks modules shipped with firmware version 6.11 and higher
> support the HID profile. You do not need special firmware if your
> module is running firmware 6.11 or higher.

and my module reports version as:

    Ver 6.15 04/26/2013
    (c) Roving Networks

I've also gone through the [Bluetooth HID Profile][2](pdf link) guide from Roving Networks, but the same information is present in Chapter 5 of the advanced user's guide mentioned above.

I've setup the following settings (with commands used):

 - HID Profile (`S~,6`)
 - Device discovery and pairing is set to automatic, without using GPIO6(`SM,6`)
 - HID Flag is set to Keyboard (`SH,0000`)
 - Authentication is set to open (`SA,0`)

I've also tried the inquiry scan(`SI,0800`)  and page scan(`SJ,0800`)  windows to maximum
in the hope it would increase the odds of successful pairing and made sure I rebooted the module and checked the settings again.

I have used the same module with the SPP profile just fine, but I'm still fairly new to Bluetooth
and this is the first time I try to use the HID profile.

**How can I use the BlueSMIRF Silver as a basic Bluetooth Keyboard for an iPad Air ?**

  [1]: https://dlnmh9ip6v2uc.cloudfront.net/assets/1/e/e/5/d/5217b297757b7fd3748b4567.pdf
  [2]: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Wireless/Bluetooth/RN-HID-User Guide-1.1r.pdf

title: How can I use a BlueSMIRF Silver (RN-42) as a HID Keyboard (on IOS)?

Answers: 3

body:
> I should be able to set and use the HID profile (from the default SPP)

Unfortunately, your assumption is incorrect. From the same documentation you quoted, the previous sentence says:

> To use Roving Networks’ Bluetooth HID profile, you must use a special
> build of firmware, version 6.03 or later.

Poorly phrased, this does mean that you need to have two things:

 1. A **special HID** firmware
 2. Version 6.03 or later

Your BlueSmirf Silver only complies with the second condition; it does not have the special HID firmware (also note that the Rovnix command reference does not address a specific variant of the BlueSmirf, but speaks generally about all of the variants).

The **SPP protocol** (Serial Port Profile) is used for emulating a serial cable, and functions as a substitute for the physical RS-232 connection, **but cannot stack pure HID profile on top of it**. In order for you do talk HID, you will need the HID firmware.

As a side note, the HID version comes with SPP and you can switch between the two modes interchangeably, I have been using the HID version for a while now and it works fine (including the pairing with iOS).

Another misfortune is that it does not appear that *Roving Networks* officially support any re-flashing of the BlueSmirf firmware, so unless you are willing to reverse the hardware, this is off the table as well.

body:
In the [comments on SparkFun's product page for RN-42][1], gskelly indicates there is a flag in the v6.15 firmware that allows you to switch back and forth easily:

> Actually, since this includes the v6.15 firmware, you don’t need to
> re-flash the module to switch between HID and SPP. It can now be done
> using AT commands as follows:
>
    S~,6    // Enable HID on reboot
    R,1     // Reboot
    S~,0    // Enable SPP on reboot
    R,1     // Reboot

  [1]: https://www.sparkfun.com/products/12574#comment-532f2a48ce395fee4f8b4567

body:
I know I am late to the party but for others searching this topic:

"S~,6" command does work for switching to HID profile but it requires the reboot command "R,1" otherwise it won't take.

I send these commands from the microcontroller to RN42 whilst the RN42 is in command mode, just to be clear.


body:
I am attempting to connect an Arduino Uno to a Modern Device RBB Arduino. One is the base and the other the remote. They need to set up a simple handshake to communicate an on and off condition from the remote.The hardware and software work for both the base and remote using Tera Term to simulate the opposite node. I am running Tera Term on a notebook connecting to the node through a BT dongle. In other words if I manually respond to the opposite node on the Tera Term they both operate as they should individually. When I try to get them to interact autonomously they will not handshake. The HC05s are paired and connected but the handshake data will not flow back and forth.

Remote Code:
<!-- language-all: lang-cpp -->

     int pinInt =2; //interrupt pin

     int ack = 2; //acknowledge

     void setup() {

      pinMode(3,OUTPUT); //power to bluetooth

      pinMode(pinInt,INPUT); //interrupt pin mode

    }
    // Still needs sleep and interrupt processing

      void loop() {

      delay(5000);//sim sleep remove or adjust for wake up delay

      digitalWrite(3,HIGH);//switches power to bluetooth

      delay(10000);//BT active adjust as necessary

      Serial.begin(9600);

      Serial.print('?');//send am I connected

       while(Serial.available()==0){}//idle until incoming serial

         int heatCall=digitalRead(pinInt);//read interrupt pin

         if (Serial.available() > 0) {ack = Serial.read();}//read ack

         if (ack=='1'){Serial.print(heatCall);}//send state of heatCall

      while(Serial.available()==0){}//idle until incoming serial

        if (Serial.available() > 0) {ack = Serial.read();}//read ack

        if (ack=='0'){Serial.end();digitalWrite(3,LOW);}//BT off

       //sleepNow();//put back to sleep

    }

Base Code:

    int relayPin =13; //relay pin

     char itsOn = 0; //remote calling variable

     int heatCall = 0; //state of TH135

     int ack = 2; //hand shake

      void setup() {

      pinMode(relayPin,OUTPUT); //power to relay
      Serial.begin(9600);
    }

      void loop() {

      while (Serial.available()==0);{}//idle until incoming serial

      if (Serial.available() > 0) {itsOn = Serial.read();//remote calling

        if (itsOn=='?')ack=1;Serial.print(ack);}//send connected ack

      while (Serial.available()==0);{}//idle until incoming serial

      if (Serial.available() > 0) {heatCall = Serial.read();}//incoming heatCall

        if (heatCall=='1'){digitalWrite(relayPin,HIGH);}//turn zone relay ON

         else {digitalWrite(relayPin,LOW);}//turn zone relay OFF

      delay(5000);
      ack=0;
      Serial.print(ack);//turn remote BT OFF
      }

 Is there some BT protocol that I am missing?

UPDATE: I have determined that data is being transferred from remote to base and back. The data is not the expected values.

title: HC05 to HC05 Handshake Communication

Answers: 0


body:
i am trying to send data via Labview to my arduino board using serial communication.My problem is that the arduino reads only the first byte of sent data then when i change it ,it doesn't react.
For example when i start the communication i send '0' to arduino.I sees it.but while it is running i send '1' but it doesn't behave accordingly to it.
I noticed also that the board 'sees' sometime the new value after a random period of time.

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

    char data = 'F';

    void loop()
    {
        data = Serial.read();
        delay(50);

        if (data == '0')
        {
            digitalWrite(13, HIGH);
            delay(1000);
            digitalWrite(13, LOW);
            delay(1000);
        }
        if (data == '1')
        {
            digitalWrite(13, HIGH);
            delay(4000);
            digitalWrite(13, LOW);
            delay(4000);
        }

        data = '4';
    }

title: Arduino serial communication synchronisation

Answers: 2

body:
I suspect you problem stems from the use of delay's in your code. for example,

    if (data=='1')
     {
      digitalWrite(13,HIGH);
      delay(4000);
      digitalWrite(13,LOW);
      delay(4000);
     }
Those delays prevent any computations from happening for 4 seconds each. Your arduino will not read another character after it sees a `'1'` for 8 seconds. If you send too much data in that 8 seconds to fit in the serial buffer, the extra characters are lost.

The behavior you seem to want will require separating the code that reads serial from the code that runs the output, and making sure neither section ever stops execution with delays. Your blinks will need to be timed with something else, like frequent comparisons against the current time with `millis()`

body:
JUST add the part ~
This flushes the serial buffer, which aids in error free data receiving. No need to implement the millis() protocol as you want the led to be active for that time so you do not want any data to enter the system, neither you are using interrupts service.

    Serial.readString();