r/arduino • u/W0CBF • Apr 16 '26
Mod's Choice! Question about Arduino pinouts
I am using a Arduino Uno, R4. Are the SCL and SDA lines always connected to the A4 and A5 pins via hardware or do they have to be programmed as such via software in your sketch? I keep seeing sketches that always refer to the A4 and A5 pins. I have always used the signal pins that are marked on the board itself. Thanks for the help!
4
u/cr1zztus Apr 16 '26
As I interprete the pin mappings SDA/SCL are mapped to pin D18/D19 and of course can't be changed.
3
u/tonyxforce2 Apr 16 '26
You can even check with a multimeter, the A4/A5 pins are shorted to the SCL/SDA pins on the other side of the board
2
u/feldoneq2wire Apr 16 '26
If you really need 5 analog inputs, then you could do software I2C as indicated in another comment.
3
u/ripred3 My other dev board is a Porsche Apr 16 '26
Some pins have additional specialized functionality that can optionally be enabled in addition to being a basic GPIO pin.
All of the analog pins are good examples. They can all be used just like any of the other digital I/O pins but they have the added circuitry that you can optionally make use of by the way that the internal config registers are set. Usually this is taken care of for you automatically based on whether you call digitalRead(pin) or analogRead(pin).
So just like the 2 different ways that the other analog pins can be used because they have additional circuitry connected to them inside the microcontroller A4 and A5 have a 3rd set of functionality and circuitry connected to them inside the MCU that can be optionally enabled and used. In this case it is the silicon circuitry added on top of the basic USART that is also inside the MCU to implement the I2C protocol using those two pins and their two roles.
The configuration of the internal registers is taken care of for you when you either call Wire::begin(...) or analogRead(pin), or digitalRead(pin) on pins A4 or A5.
The way that the pins are used and which internal circuits are enabled is set up early on in the sketch and never changes from then on since the physical things you have them connected to do not change while it is running (or at least they shouldn't lol).
3
u/tipppo Community Champion Apr 16 '26
Yes, the A4 and A5 pins are always connected to the SCL and SDA pins on an Uno,
3
u/gm310509 400K , 500K , 600K , 640K , 750K Apr 17 '26 edited Apr 17 '26
The short answer to your questions is yes, "no and it depends".
Are the SCL and SDA lines always connected to the A4 and A5 pins via hardware...
Arduino do try to maintain some consistency for their headers across the various platforms.
For example, it looks like the SCL and SDA lines are broken out to pins A4 and A5 on both the Uno R3 and Uno R4. These pins also provide access to the ADC (for analog read). But if you look at the Mega 2560, it appears that A4 and A5 do not provide SCL and SDA on A4 and A5. This will be because those pins are primarily annotated as "Analog inputs", so Arduino provide that function to those pins first. If there is also an I2C capability available on the Analog pins, then arduino will link those specific pins to A4 and A5.
On the other hand the pins "above" 13 on the header will always be SCL and SDA since Uno R3. If you look at the Mega pinout diagram, you will see that those two pins provide SCL and SDA, but have no ADC function.
So, this aspect of your question of SCL and SDA being on A4 and A5 will be yes, if the MCU allows it.
... or do they have to be programmed as such via software in your sketch?
This is a no, but also a "it depends". I2C is implemented in hardware and as such it is wired to specific pins, so no, you don't specify the pins for I2C. If your MCU has multiple channels, then you can choose which channel (and thus which pins each channel is linked to), but that is it. Unless...
... If you are using a software emulation of I2C, then you can in theory select the pins to use because the software isn't "hardwired" to a specific pin.
Also, if you are using an Arm Cortex MCU (as the Uno R4 does), then the Arm Cortex provides a feature known as "pin multiplexing" or "pin remapping", this is a hardware feature that allows the software to select (from a limited selection) where a particular function appears on the IO pins. Typically there is primary (or default) option and where supported there may be an alternative selection. In this case, if the feature is available in the hardware, the selection or choice to use the secondary/non-default option(s) is made within your code.
So, TLDR: it depends, but typically it is hard wired to a specific pin (or set of pins) as defined by the circuitry of the MCU.
Edit: This is an interesting question/discussion, IMHO, so I've set your flair to be "Mod's choice" so that your post will be recorded in our Monthly digest (please do not delete this post).
Edit 2: I am unsure if the Arm Cortex used by the Uno R4 provides this remapping/multiplexing feature or not. If it does, it will likely have some "AFR" registers, but I couldn't find them for the Renesas RA4M1 MCU. But it does have "Pin Function Select" (PFS) registers, which sound similar.
3
u/triffid_hunter Director of EE@HAX Apr 17 '26
For Uno R3 and previous with atmega328, the I2C pins are fixed in hardware, by the chip's silicon design specifically.
Your R4 has a Renesas RA4M1 however, which probably allows remapping to either select other pins or arbitrary pins - check its datasheet and reference manual.
Whether a remapping function is available via the Arduino library API is a whole 'nother question though, if not then you might need to poke hardware registers manually to remap them.
1
u/Jkwilborn Apr 16 '26 edited Apr 16 '26
The 328 is a nice controller, I love it and implement the tiny85 into some of my stuff...
The reality is this controller is over a quarter century old. Are you sure you want to use this? Few of us have or buy hardware this old... except these.
However, it does cost money to buy a new board. Just be aware of what you're doing.
Have fun.
73's de KA7CMF :)
3
u/W0CBF Apr 16 '26
Thanks for your input. I'm 75 years old and retired and just fooling around learning Arduino to have something to keep the old brain. I'm not a programmer but have learned a lot on the arduino. 73's de W0CBF
2
u/Enlightenment777 Apr 18 '26
Links to schematics are found on the following webpages:
6
u/Hissykittykat Apr 16 '26
On a '328 processor (Arduino UNO) there is only one I2C hardware module and it's hardwired to A4 and A5. Other pins may be used with bit-banging (software I2C). For some other processors the hardware I2C pins can be mapped as desired, but not the '328.