I'm writing a library which controls a device using SPI bus. For the communication I need to manually toggle the chip select pin. On most Arduinos SS pin is on D10, but there are also other models where it's different like D53 on Mega. Is there a way to know where it is? Like a global #define? I would like to avoid any pin configuration parameters in my library. At least for default configuration...

  • As jantje answered (he beat me by a couple of seconds :P ) just use SS; in the files pins_arduino.h (folder \hardware\arduino\avr\variants\your variant) you can see them all. BUT I highly discourage you to use it in your code. You can use it as a default value, but give the user the possibility to change it (otherwise he won't be able to attach two different SPI devices, for instance)
    – frarugi87
    Feb 29, 2016 at 15:12
  • Welcome to Arduino SE Gamadril! About your question, SS pin can be any pin as that pin just needs to be toggled, no high speed data transfer is done with that pin.
    – Avamander
    Feb 29, 2016 at 15:19

2 Answers 2


Yes there are. They are defined in pins_arduino.h Below the pins for the yun.

// Map SPI port to 'new' pins D14..D17
static const uint8_t SS   = 17;
static const uint8_t MOSI = 16;
static const uint8_t MISO = 14;
static const uint8_t SCK  = 15;

Use SS MOSI MISO and SCK in your code

  • you was some seconds faster, so get your point :)
    – Gamadril
    Feb 29, 2016 at 15:38

This is defined in the platform variant specific file pins_arduino.h in the variants folder (\hardware\arduino\avr\variants). Each platform variant (standard, mega, leonardo etc) gets their pin definitions set here. For instance the mega:

static const uint8_t SS   = 53;
static const uint8_t MOSI = 51;
static const uint8_t MISO = 50;
static const uint8_t SCK  = 52;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.