Pin mapping Arduino ProMini

I have an example Code for Arduino Mega, which has the Atmega2560 as Controller onboard. In platformio.ini I have Setup for Board pro16Mhzatmega168, which is for the Arduino ProMini Board Variant I would like to use.

Per accident i forgot to replace the Pin Numbers in my Header File to that of my Arduino Board. The issue is, that I can compile the Code without any Errors or warnings, although the pins I access via pinMode do not exist at all for my Arduino Board!

Example “pinMode(53, OUTPUT);”

Digital Pin 53 is the CS Pin of SPI for Arduino Mega, but does not exist at all for Arduino ProMini or UNO. How can this work? To be honest I don’t like the Arduino way of Pin re-mapping at all, so i will replace the Arduino functions with direct Port Access. However I would like to understand, how this is working.

The way the Arduino API and the Wiring framework it’s based on are designed, they cannot check at compile-time if the specified pin number is correct.

Even at run-time, operations with invalid pin numbers are simply ignored.

Whether it has become successful due to or despite this design, I leave up to you…

1 Like

OK, thanks. However pinMode() and digitalWrite() shall use valid numbers because the functions are more or less wrappers to write DDRx and PORTx registers respectively. So e.g If I try to access digital pin 53 with above mentioned Arduino functions for a Board, which ends with Pin 19 how is it mapped? If it is ignored, as you wrote, does it mean that the complete Pin access is rejected? In this case I would expect at least a warning, or did I miss something? I think the whole behaviour is an Arduino issue and not platformio related. Regards Andreas

Where do you expect the warning to appear during run-time? There is no standard error or logging channel. It’s a small and restricted device after all.

All operations with invalid pins will not do anything (except spend a few CPU cycles). See for example the source code of pinMode of the AVR Arduino core: ArduinoCore-avr/wiring_digital.c at master · arduino/ArduinoCore-avr · GitHub

If the pin is invalid, it returns on line 35.

And the same check is repeated in each function every time it’s called.

1 Like

OK, thanks for explanation and the provided Link. I am more familiar with the pure AVR C programming rather than the Arduino C++ style…
Regards Andreas