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?
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.
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);
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.
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?
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