Using SDA and SCL as inputs

Hey guys,

I am fairly new to this so apologies if I ask some stupid questions!

I am building a robotic car thing as a little project and have hit a little bump in the road (metaphorically that is). Given that I have a motor shield on top of my arduino UNO clone I only have 4 pins left. These being the SDA and SCL pins on the one side, and a 5V and an apparently empty pin on the other side.

If I want to have a radio receiver as an input to the arduino, can I use the SDA and SCL pins? Otherwise do I have any other options?

Thanks all,
Henry

You can use SDA and SCL as general purpose input or output pins, including analog input on an Uno.

Only if you need to communicate with an I2C device do they become dedicated, and then only if you use the I2C hardware.

Thanks! How would I refer to them in my code?

A4 and A5

Or D18, D19.
By radio receiver, you mean like a 433 MHz receiver? Or an Xbee?

It is a 433MHz Receiver, could you possibly give me an example of a line of code about it? Or somewhere that might offer a good explanation. I've had a look around and can't quite find much about it.

It depends on which exact pins you want to use.

If you truly mean the i2c pins, then the best way to refer to them is as SDA and SCL.
That way it works for any board vs just an UNO.

So if you have a R3 or a leonardo, or mega that has the SDA and SCL header pins up by the USB connector,
the code will always use those pins.

However, if you want to refer to the header pins down towards the opposite corner of the board from the i2c pins, where the analog pins are, then use A4 and A5.
That way you will always get those two pins.

Remember that pin mappings are different for each board type so it is always best to use a symbol when available to ensure that you always get the physical pin you want. This is particularly important for the pins like i2c or the analog pins where the mapping to the digital pin numbers are quite different between boards.

Because of this, I would not recommend using the arduino digital pin number since depending on the type of arduino, (you may change it at some point), you may or may not get specific physical pins you want.

To use them, use the names as the pin in the API calls:

pinMode(A5, INPUT);
val = digitalRead(A5);

pinMode(SCL, INPUT);
val = digitalRead(SCL);

--- bill

henryaverill:
Thanks! How would I refer to them in my code?

As AWOL said A4 & A5, but note that these pin connections are the IDENTICAL pins to analogue inputs 4 & 5, if you are using those already then you do not get to use SDA and SCL as separate inputs.

Chances are the pins you see labeled “SDA” and “SCL” are electrically identical to the A4/A5 pins. They are not separate, freely available pins. They are just a different location of the same pins for ease of use in some setups.

INTP:
Chances are the pins you see labeled “SDA” and “SCL” are electrically identical to the A4/A5 pins. They are not separate, freely available pins. They are just a different location of the same pins for ease of use in some setups.

If it is an UNO board, then it is guaranteed as SDA and SCL are A4 and A5.

— bill

Which Motor Shield you used? it may cover all the pins but not use all the pins.
you need to know which pins the Motor Shield used.


you can use Proto Shield to connect to other unuse pins.

I would recommend the VirtualWire library to use the pins for RF, assuming you are not using I2C or A4/A5 or D18/D19 in your project already.
http://www.airspayce.com/mikem/arduino/VirtualWire/

Just a note on pin mapping:

On a Mega the SCL and SDA pins are different from A4/A5, and also different from D18/19. That's why the proper names should be used for every pin, and connections according to the labels on the board.

Right… so if I have a motor shield that connects to all of the pins aside from SDA and SCL how can I get a radio receiver to act as an input to the arduino?

BillHo:
Which Motor Shield you used? it may cover all the pins but not use all the pins.
you need to know which pins the Motor Shield used.


you can use Proto Shield to connect to other unuse pins.

L293D shield, Adafruit V1 I believe. Which ones wouldn't be used?

DrDiettrich:
Just a note on pin mapping:

On a Mega the SCL and SDA pins are different from A4/A5, and also different from D18/19. That's why the proper names should be used for every pin, and connections according to the labels on the board.

henryaverill:
I have a motor shield on top of my arduino UNO clone

henryaverill:
L293D shield, Adafruit V1 I believe. Which ones wouldn't be used?

If you look at the Schematics,


it used only
D3 PWM2B
D4 DIR CLK
D5 PWM0B
D6 PWM0A
D7 DIR EN
D8 DIR SER
D9 PWM1A
D10 PWM1B
D11 PWM2A
D12 DIR LATCH

so D2, D13 and A0 to A5 was not use.

Thank you very much! I couldn't find the schematics online so had to sit there with a multimeter and take measurements!