Need more pins for project - SPI unused and rewriteable?

Hello all,

I have an arduino ethernet and I need 8 digital pins. From the arduino website, it states that pins 10-13 are used for SPI, 4 is used for SD, 2 is used for W5100, and 0 and 1 are used for TX and RX.
This leaves me with 6 pins left.

My question is, since I am not using SPI, can I set those pins to digital outputs and use them like any other digital pin? My thought is yes since I am not calling the SPI library.

Matt

The Ethernet functionality uses SPI. Do you already use the analog inputs? If not, they can be configured as digital I/Os too.

Pylon,

Thanks for the heads up. Looks like I'm keeping the SPI library in my code then :stuck_out_tongue:

I only have 3 of the 6 analog pins used. How do I go about setting the analog as a digital pin?

Matt

How do I go about setting the analog as a digital pin?

Just use pinMode() to set the correct direction, then digitalRead() or digitalWrite() to read/write to/from it. It's best use and most portable to use the A0, A1, etc. place holders for the pin numbers.

So I can do something like

pinMode(A0, input);
digitalWrite(A0, HIGH);

without declaring A0 to be something?

Matt

ukeri:
So I can do something like

pinMode(A0, input);
digitalWrite(A0, HIGH);

without declaring A0 to be something?

Matt

Yes, though I hope you realize that all that will do is enable the internal pullup since you set it as an INPUT. digitalWrite would normally be used for an OUTPUT.

A0 to A5 = D14 to D19, can declare them way also.

Long story short, I'm trying to set up the analog pins over ethernet and all im sending is pin number (arduino is server). I want to control a camera with 2 switches, high on SW1 camera zooms out, high on SW2 camera zooms in.

That being said, I am sending analog pin number to the arduino code. Does this work?
pinnum is set from an incomming packet.

//sets the pin
pinMode(pinnum+14, 0);
//writes the pin
digitalWrite(pinnum, 1);

I believe in the pinMode, the 0 means output and in digitalWrite the 1 means high. Is this correct?

Matt

Yes. Well, except for calling pinnum+14 to set it up and not the same when writing, but I assume that is a typo.

And yes about 0 and 1, but why not just use INPUT,OUTPUT and HIGH,LOW? It doesn't use anymore space in code and makes it easier to read.

//sets the pin
pinMode(pinNum+14, OUTPUT);
//writes the pin
digitalWrite(pinNum+14, pinState);

That would make a pinNum of 0 control A0, pinNum of 5 would control A5. And pinState would set it to either HIGH or LOW as you designate. Though if the pin is always going to be an OUTPUT, I would put that part in the setup, personally.

I'm with Retroplayer, use

pinMode(pinX, INPUT); // or OUTPUT, on INPUT_PULLUP to have internal pullup enabled.

I am working with LIFA (Labview for arduino) to communicate over eathernet instead of serial. I am trying to reuse as much code as possible because I am not proficient with labview or arduino. Basically, I'm doing this way to stay consistant with the code I already have.

That being said, a 15 byte packet is being sent to the arduino and one of the bytes is output/input. Instead of creating an if..else.. statement, I am just using the NI code which I know sets the input/output correctly.

Thank you for the help, I got everything working :smiley:
Matt