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