I am fairly new to Arduinology so bear with me, please. My first real project is going very well, except for the eternal problem of "not enough I/O pins."
I am using i2c, so Wire is enabled in my sketch. I am using the SDA and SCL pins on the Leonardo digital header (near the reset button).
I have read in various places that i2c commandeers digital pins 2 and 3 as well -- or that pins 2 and 3 are the default pins for i2c and the SDA/SCL header sockets are just patched into pins 2 and 3. I am afraid to use pins 2 and 3 now, because Wire is enabled and I don't want to fry anything or mess up my i2c communication (which so far is perfect).
I am really short of pins and wanting to use D2 and D3, so... can someone unconfuse me about the relationship between SDA, SCL and D2 and D3... do I really lose pins 2 and 3 when I enable Wire?
Use a multimeter and confirm for yourself whether they are connected or not.
What are your IO pins doing? Maybe you use 3 pins to control some daisy chained shift register and free up 5 IO pins.
The schematic on the Leonardo products page would indicate they are connected, as the pins are named D2/SDA and D3/SCL.
You can also use the MISO, MOSI, and SCK pins on the ICSP header. I don't know what they are called in the Arduino pin mapping.
"SPI: on the ICSP header. These pins support SPI communication using the SPI library. Note that the SPI pins are not connected to any of the digital I/O pins as they are on the Uno, They are only available on the ICSP connector. "
Forgive my n00by ignorance... am not an EE and barely qualify as an Arduinologist... but are you saying that if I am not using SPI in my sketch, I can use the SPI header pins as generic digital I/O pins? that would be great news!
I found this reference immediately
There are four more digital pins. The Uno has 14 digital pins: D0-D13. The Leonardo has 18: D0-D17. The extra pins have been mapped to the ICSP header. Their mappings are:
D14 – MISO – PB3
D15 – SCK – PB1
D16 – MOSI – PB2
D17 – SS – PB0
Pin D17 (SS) does not have a corresponding pin on the ICSP header, nor anywhere on the board.
So it sounds like I can use e.g. "pinMode(MISO,INPUT_PULLUP)" & make use of these "spare" pins?
Yippee. I know that shift registers and muxes are in my future, but I'm not quite ready to tackle them yet (still pretty thrilled when LEDs turn on and off). Always grateful when the experts have the patience to clarify what should be obvious, but isn't to the complete amateur.
"So it sounds like I can use e.g. "pinMode(MISO,INPUT_PULLUP)" & make use of these "spare" pins?"
Yes. Maybe not the name MISO, but 14. Try it, see what works.
Or perhaps
byte pin14 = 14;
and then
pinMode(pin14, INPUT_PULLUP );