Digital pins Yun vs Uno

Hello,

I have an external circuit that uses the digital pins 2 and 3 of the Arduino. I said Arduino because connecting the circuit to these two pins of the Arduino Uno, everything is working fine and the Serial Monitor prints the correct result, while, if I plug it to my Yun, nothing happens. Actually, with the Serial monitor opened, when I plug off the the two wires from the Yun's pins, the Serial monitor prints something interpreted as 0.

I don't know if I expressed well myself but it is like if the pins are blocked and they react only when the signal is not there anymore (when I plug off the wires).

Why do I experience this different behavior between the Yun and the Uno?

There should be no difference between the Uno and Yun using pins 2 and 3 as digital I/O pins. If you are using only those pins, and just using digitalRead/digitalWrite, it should work.

What other pins are being used? Are you using the Wire library to send I2C commands!? While there are dedicated SCL/SDA pins on both platforms, they are duplicated on regular pins as well, but they are not the same pins:

  • On the Uno, the signals are duplicated on A4 and A5.
  • On the Yun, the signals are duplicated on 2 and 3.

So, if you are using the dedicated SCL/SDA pins in addition to 2 and 3, that would work on the auto, but not the Yun.

Off the top of my head, that's the only explanation I can come up with. More information about your circuit is needed, including how it uses pins 2 and 3, and what other pins it may use.

Thanks for your reply.

You were right and I used only the dedicated SDA/SCL pins of the Yun and it is working.

But then, how can I use pin 2 and 3 as interrupt pins?

mridolfi: But then, how can I use pin 2 and 3 as interrupt pins?

You can't. You can use them as I2C pins, or interrupt pins, but not both.

Look at the Reference page for attachInterrupt() and note the pins for:

  • Micro, Leonardo, other 32u4-based: 0, 1, 2, 3, 7

Then note the other functions for those pins:

  • Pins 0 and 1: dedicated for serial Bridge communications with the Linux processor
  • Pins 2 and 3: also used for I2C communications
  • Pin 7: can be used as a handshaking line between the '32U4 and Linux processors, but this is not normally enabled so the pin is available for general use.

I assume you are using the communications to the Linux processor, or you wouldn't be using the Yun. So pins 0 and 1 are out. You are using I2C, so pins 2 and 3 are out. That leaves pin 7 as your only available choice.

Not enough pins: the universal bane of small microcontrollers...

Thanks, you've been very clear.

@ShapeShifter

While there are dedicated SCL/SDA pins on both platforms, they are duplicated on regular pins as well, but they are not the same pins: On the Uno, the signals are duplicated on A4 and A5. On the Yun, the signals are duplicated on 2 and 3.

Can I change this behaviour on the Yun? I mean, can I somehow duplicate the SCL/SDA signals on different pins instead of pin 2 and 3?

mridolfi: Can I change this behaviour on the Yun? I mean, can I somehow duplicate the SCL/SDA signals on different pins instead of pin 2 and 3?

Only by bit-banging the interface using direct GPIO control. It can get complicated, and is usually slow, depending on how you do the I/O and what tricks you can come up with to optimize the code. For example, this code uses direct port bit manipulation rather than the much slower (but easier) digitalWrite() calls, and that will improve speed, but it is sure to be slower and more complicated that the dedicated hardware and Wire library. (I can't speak to the validity/quality of that code, I simply noticed it as a link from the Wikipedia bit-banging article.)